diff --git a/Box/Main.cpp b/Box/Main.cpp index 8477f23be580417bd3e78a715618e400cb582fec..4568ae3f3e86613fe6f4425e8ea71f35ddfb5c0c 100644 --- a/Box/Main.cpp +++ b/Box/Main.cpp @@ -1,4 +1,4 @@ -// $Id: Main.cpp,v 1.26 2003-02-18 05:50:04 geuzaine Exp $ +// $Id: Main.cpp,v 1.27 2003-03-01 22:36:36 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -43,17 +43,18 @@ #include "CommandLine.h" #include "MinMax.h" -char yyname[256]; -int yyerrorstate; -Context_T CTX ; -Mesh M, *THEM=NULL, *LOCAL=NULL; +char yyname[256]; +int yyerrorstate; +Context_T CTX; +Mesh M, *THEM = NULL, *LOCAL = NULL; // Print some help/info messages -void Info (int level, char *arg0){ - switch(level){ - case 0 : - if(ParUtil::Instance()->master()){ +void Info(int level, char *arg0) +{ + switch (level) { + case 0: + if(ParUtil::Instance()->master()) { fprintf(stderr, "%s\n", gmsh_progname); fprintf(stderr, "%s\n", gmsh_copyright); Print_Usage(arg0); @@ -61,13 +62,13 @@ void Info (int level, char *arg0){ ParUtil::Instance()->Exit(); case 1: if(ParUtil::Instance()->master()) - fprintf(stderr, "%d.%d.%d\n", GMSH_MAJOR_VERSION, GMSH_MINOR_VERSION, - GMSH_PATCH_VERSION); + fprintf(stderr, "%d.%d.%d\n", GMSH_MAJOR_VERSION, GMSH_MINOR_VERSION, + GMSH_PATCH_VERSION); ParUtil::Instance()->Exit(); case 2: - if(ParUtil::Instance()->master()){ - fprintf(stderr, "%s%d.%d.%d\n", gmsh_version, GMSH_MAJOR_VERSION, - GMSH_MINOR_VERSION, GMSH_PATCH_VERSION); + if(ParUtil::Instance()->master()) { + fprintf(stderr, "%s%d.%d.%d\n", gmsh_version, GMSH_MAJOR_VERSION, + GMSH_MINOR_VERSION, GMSH_PATCH_VERSION); fprintf(stderr, "%s\n", gmsh_os); fprintf(stderr, "%s\n", gmsh_date); fprintf(stderr, "%s\n", gmsh_host); @@ -76,39 +77,41 @@ void Info (int level, char *arg0){ fprintf(stderr, "%s\n", gmsh_email); } ParUtil::Instance()->Exit(); - default : + default: break; } } // Main routine for the batch (black box) version -int main(int argc, char *argv[]){ - int i, nbf; +int main(int argc, char *argv[]) +{ + int i, nbf; - ParUtil::Instance()->init(argc,argv); + ParUtil::Instance()->init(argc, argv); Init_Options(0); - if(argc < 2) Info(0,argv[0]); + if(argc < 2) + Info(0, argv[0]); Get_Options(argc, argv, &nbf); - M.Vertices = NULL ; - M.VertexEdges = NULL ; - M.Simplexes = NULL ; - M.Points = NULL ; - M.Curves = NULL ; - M.SurfaceLoops = NULL ; - M.EdgeLoops = NULL ; - M.Surfaces = NULL ; - M.Volumes = NULL ; - M.PhysicalGroups = NULL ; - M.Metric = NULL ; - - signal(SIGINT, Signal); + M.Vertices = NULL; + M.VertexEdges = NULL; + M.Simplexes = NULL; + M.Points = NULL; + M.Curves = NULL; + M.SurfaceLoops = NULL; + M.EdgeLoops = NULL; + M.Surfaces = NULL; + M.Volumes = NULL; + M.PhysicalGroups = NULL; + M.Metric = NULL; + + signal(SIGINT, Signal); signal(SIGSEGV, Signal); - signal(SIGFPE, Signal); + signal(SIGFPE, Signal); if(CTX.default_plugins) GMSH_PluginManager::Instance()->RegisterDefaultPlugins(); @@ -118,28 +121,31 @@ int main(int argc, char *argv[]){ OpenProblem(CTX.filename); if(yyerrorstate) ParUtil::Instance()->Abort(); - else{ - for(i=1;i<nbf;i++) MergeProblem(TheFileNameTab[i]); - if(TheBgmFileName){ + else { + for(i = 1; i < nbf; i++) + MergeProblem(TheFileNameTab[i]); + if(TheBgmFileName) { MergeProblem(TheBgmFileName); if(List_Nbr(CTX.post.list)) - BGMWithView((Post_View*)List_Pointer(CTX.post.list, List_Nbr(CTX.post.list)-1)); + BGMWithView((Post_View *) + List_Pointer(CTX.post.list, List_Nbr(CTX.post.list) - 1)); else - fprintf(stderr, ERROR_STR "Invalid background mesh (no view)\n"); exit(1); + fprintf(stderr, ERROR_STR "Invalid background mesh (no view)\n"); + exit(1); } - if(CTX.batch > 0){ + if(CTX.batch > 0) { mai3d(THEM, CTX.batch); - Print_Mesh(THEM,CTX.output_filename,CTX.mesh.format); + Print_Mesh(THEM, CTX.output_filename, CTX.mesh.format); } else Print_Geo(THEM, CTX.output_filename); if(CTX.mesh.histogram) Print_Histogram(THEM->Histogram[0]); - ParUtil::Instance()->Barrier(__LINE__,__FILE__); + ParUtil::Instance()->Barrier(__LINE__, __FILE__); ParUtil::Instance()->Exit(); return 1; } - ParUtil::Instance()->Barrier(__LINE__,__FILE__); + ParUtil::Instance()->Barrier(__LINE__, __FILE__); ParUtil::Instance()->Exit(); return 1; } @@ -147,99 +153,117 @@ int main(int argc, char *argv[]){ // Handle signals. We should not use Msg functions in these... -void Signal (int sig_num){ - - switch (sig_num){ - case SIGSEGV : Msg(FATAL, "Segmentation violation (invalid memory reference)"); break; - case SIGFPE : Msg(FATAL, "Floating point exception (division by zero?)"); break; - case SIGINT : Msg(FATAL, "Interrupt (generated from terminal special char)"); break; - default : Msg(FATAL, "Unknown signal"); break; +void Signal(int sig_num) +{ + switch (sig_num) { + case SIGSEGV: + Msg(FATAL, "Segmentation violation (invalid memory reference)"); + break; + case SIGFPE: + Msg(FATAL, "Floating point exception (division by zero?)"); + break; + case SIGINT: + Msg(FATAL, "Interrupt (generated from terminal special char)"); + break; + default: + Msg(FATAL, "Unknown signal"); + break; } } // General purpose message routine -void Msg(int level, char *fmt, ...){ - va_list args; - int abort=0; +void Msg(int level, char *fmt, ...) +{ + va_list args; + int abort = 0; - va_start (args, fmt); + va_start(args, fmt); - switch(level){ + switch (level) { - case DIRECT : - if(CTX.verbosity >=2 && ParUtil::Instance()->master()) { - vfprintf(stdout, fmt, args); fprintf(stdout, "\n"); + case DIRECT: + if(CTX.verbosity >= 2 && ParUtil::Instance()->master()) { + vfprintf(stdout, fmt, args); + fprintf(stdout, "\n"); } break; - case FATAL : - case FATAL1 : - case FATAL2 : - case FATAL3 : - fprintf(stderr,"On processor %d : ", ParUtil::Instance()->rank()); + case FATAL: + case FATAL1: + case FATAL2: + case FATAL3: + fprintf(stderr, "On processor %d : ", ParUtil::Instance()->rank()); fprintf(stderr, FATAL_STR); - vfprintf(stderr, fmt, args); fprintf(stderr, "\n"); - abort = 1 ; - break ; - - case GERROR : - case GERROR1 : - case GERROR2 : - case GERROR3 : - fprintf(stderr,"On processor %d : ", ParUtil::Instance()->rank()); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); + abort = 1; + break; + + case GERROR: + case GERROR1: + case GERROR2: + case GERROR3: + fprintf(stderr, "On processor %d : ", ParUtil::Instance()->rank()); fprintf(stderr, ERROR_STR); - vfprintf(stderr, fmt, args); fprintf(stderr, "\n"); - break ; - - case WARNING : - case WARNING1 : - case WARNING2 : - case WARNING3 : - if(CTX.verbosity >= 1){ - fprintf(stderr,"On processor %d : ", ParUtil::Instance()->rank()); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); + break; + + case WARNING: + case WARNING1: + case WARNING2: + case WARNING3: + if(CTX.verbosity >= 1) { + fprintf(stderr, "On processor %d : ", ParUtil::Instance()->rank()); fprintf(stderr, WARNING_STR); - vfprintf(stderr, fmt,args); fprintf(stderr, "\n"); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); } break; - case DEBUG : - case DEBUG1 : - case DEBUG2 : - case DEBUG3 : - if(CTX.verbosity >= 3 && ParUtil::Instance()->master()){ + case DEBUG: + case DEBUG1: + case DEBUG2: + case DEBUG3: + if(CTX.verbosity >= 3 && ParUtil::Instance()->master()) { fprintf(stderr, DEBUG_STR); - vfprintf(stderr, fmt, args); fprintf(stderr, "\n"); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); } break; - default : - if(CTX.verbosity >= 1 && ParUtil::Instance()->master()){ + default: + if(CTX.verbosity >= 1 && ParUtil::Instance()->master()) { fprintf(stderr, INFO_STR); - vfprintf(stderr, fmt, args); fprintf(stderr, "\n"); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); } break; } - va_end (args); + va_end(args); - if(abort) exit(1); + if(abort) + exit(1); } // CPU time computation -void GetResources(long *s, long *us, long *mem){ +void GetResources(long *s, long *us, long *mem) +{ static struct rusage r; - getrusage(RUSAGE_SELF,&r); - *s = (long)r.ru_utime.tv_sec ; - *us = (long)r.ru_utime.tv_usec ; - *mem = (long)r.ru_maxrss ; + getrusage(RUSAGE_SELF, &r); + *s = (long)r.ru_utime.tv_sec; + *us = (long)r.ru_utime.tv_usec; + *mem = (long)r.ru_maxrss; } -double Cpu(void){ +double Cpu(void) +{ long s, us, mem; GetResources(&s, &us, &mem); - return (double)s + (double)us/1.e6 ; + return (double)s + (double)us / 1.e6; } diff --git a/Common/ColorTable.cpp b/Common/ColorTable.cpp index 6371f10b0ef39764569f04223360d49d72e4731e..60d6ab2b6263df0b8a126dc9555501dd49e3c23a 100644 --- a/Common/ColorTable.cpp +++ b/Common/ColorTable.cpp @@ -1,4 +1,4 @@ -// $Id: ColorTable.cpp,v 1.14 2003-01-23 20:19:17 geuzaine Exp $ +// $Id: ColorTable.cpp,v 1.15 2003-03-01 22:36:36 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -27,21 +27,21 @@ #include "ColorTable.h" #include "Context.h" -extern Context_T CTX ; - -void ColorTable_InitParam(int number, GmshColorTable *ct, - int rgb_flag, int alpha_flag){ +extern Context_T CTX; +void ColorTable_InitParam(int number, GmshColorTable * ct, + int rgb_flag, int alpha_flag) +{ ct->ipar[COLORTABLE_NUMBER] = number; if(rgb_flag) { - ct->ipar[COLORTABLE_INVERT] = 0; - ct->ipar[COLORTABLE_SWAP] = 0; - ct->ipar[COLORTABLE_ROTATE] = 0; + ct->ipar[COLORTABLE_INVERT] = 0; + ct->ipar[COLORTABLE_SWAP] = 0; + ct->ipar[COLORTABLE_ROTATE] = 0; - ct->fpar[COLORTABLE_CURVE] = 0.0; - ct->fpar[COLORTABLE_BIAS] = 0.0; - ct->fpar[COLORTABLE_BETA] = 0.0; + ct->fpar[COLORTABLE_CURVE] = 0.0; + ct->fpar[COLORTABLE_BIAS] = 0.0; + ct->fpar[COLORTABLE_BETA] = 0.0; } if(alpha_flag) { ct->fpar[COLORTABLE_ALPHAPOW] = 1.; @@ -50,221 +50,288 @@ void ColorTable_InitParam(int number, GmshColorTable *ct, } -void ColorTable_Recompute(GmshColorTable *ct, int rgb_flag, int alpha_flag){ +void ColorTable_Recompute(GmshColorTable * ct, int rgb_flag, int alpha_flag) +{ float curve, bias; double gamma; - int i,r,g,b,a,rotate; - float s,t; - - ct->ipar[COLORTABLE_CHANGED] = 1 ; + int i, r, g, b, a, rotate; + float s, t; + + ct->ipar[COLORTABLE_CHANGED] = 1; - bias = ct->fpar[COLORTABLE_BIAS]; - curve = ct->fpar[COLORTABLE_CURVE]; + bias = ct->fpar[COLORTABLE_BIAS]; + curve = ct->fpar[COLORTABLE_CURVE]; rotate = ct->ipar[COLORTABLE_ROTATE]; - for (i=0 ; i<ct->size ; i++) { + for(i = 0; i < ct->size; i++) { - if(ct->size>1){ - if(i+rotate<0) - s = (float) (i+rotate+ct->size) / (float) (ct->size-1); - else if(i+rotate>ct->size-1) - s = (float) (i+rotate-ct->size) / (float) (ct->size-1); + if(ct->size > 1) { + if(i + rotate < 0) + s = (float)(i + rotate + ct->size) / (float)(ct->size - 1); + else if(i + rotate > ct->size - 1) + s = (float)(i + rotate - ct->size) / (float)(ct->size - 1); else - s = (float) (i+rotate) / (float) (ct->size-1); + s = (float)(i + rotate) / (float)(ct->size - 1); } else s = 0.; - if(ct->ipar[COLORTABLE_SWAP]) s = 1.0 - s; - - if (rgb_flag) { + if(ct->ipar[COLORTABLE_SWAP]) + s = 1.0 - s; + + if(rgb_flag) { - switch(ct->ipar[COLORTABLE_NUMBER]){ - case 1 : // vis5d - t = (curve+1.4) * (s - (1.+bias)/2.); - r = (int)( 128.0 + 127.0 * atan( 7.0*t ) / 1.57 ); - g = (int)( 128.0 + 127.0 * (2 * exp(-7*t*t) - 1) ); - b = (int)( 128.0 + 127.0 * atan( -7.0*t ) / 1.57 ); + switch (ct->ipar[COLORTABLE_NUMBER]) { + case 1: // vis5d + t = (curve + 1.4) * (s - (1. + bias) / 2.); + r = (int)(128.0 + 127.0 * atan(7.0 * t) / 1.57); + g = (int)(128.0 + 127.0 * (2 * exp(-7 * t * t) - 1)); + b = (int)(128.0 + 127.0 * atan(-7.0 * t) / 1.57); break; - case 2: // samcef - if (s-bias<=0.00){ - r = 0 ; g = 0 ; b = 255 ; + case 2: // samcef + if(s - bias <= 0.00) { + r = 0; + g = 0; + b = 255; } - else if(s-bias<=0.40){ - r = 0 ; g = (int)((s-bias)*637.5) ; b = (int)(255.-(s-bias)*637.5) ; + else if(s - bias <= 0.40) { + r = 0; + g = (int)((s - bias) * 637.5); + b = (int)(255. - (s - bias) * 637.5); } - else if(s-bias<=0.60){ - r = (int)(1275.*(s-bias-0.4)) ; g = 255 ; b = 0 ; + else if(s - bias <= 0.60) { + r = (int)(1275. * (s - bias - 0.4)); + g = 255; + b = 0; } - else if(s-bias<=1.00){ - r = 255 ; g = (int)(255.-637.5*(s-bias-0.6)) ; b = 0 ; + else if(s - bias <= 1.00) { + r = 255; + g = (int)(255. - 637.5 * (s - bias - 0.6)); + b = 0; } else { - r = 255 ; g = 0 ; b = 0 ; + r = 255; + g = 0; + b = 0; } break; - case 3: // rainbow (matlab, etc.) - if (s-bias<=0.00) { - r = 0 ; g = 0 ; b = 255 ; + case 3: // rainbow (matlab, etc.) + if(s - bias <= 0.00) { + r = 0; + g = 0; + b = 255; } - else if(s-bias<=0.25+curve){ - curve = (curve == -0.25)? -0.26 : curve; - r = 0 ; g = (int)((s-bias)*(255./(0.25+curve))) ; b = 255 ; + else if(s - bias <= 0.25 + curve) { + curve = (curve == -0.25) ? -0.26 : curve; + r = 0; + g = (int)((s - bias) * (255. / (0.25 + curve))); + b = 255; } - else if(s-bias<=0.50) { - curve = (curve == 0.25)? 0.26 : curve; - r = 0 ; g = 255 ; - b = (int)(255.-(255./(0.25-curve))*(s-bias-0.25-curve)); + else if(s - bias <= 0.50) { + curve = (curve == 0.25) ? 0.26 : curve; + r = 0; + g = 255; + b = + (int)(255. - (255. / (0.25 - curve)) * (s - bias - 0.25 - curve)); } - else if(s-bias<=0.75-curve){ - curve = (curve == 0.25)? 0.26 : curve; - r = (int)((s-bias-0.5)*(255./(0.25-curve))); g = 255 ; b = 0 ; + else if(s - bias <= 0.75 - curve) { + curve = (curve == 0.25) ? 0.26 : curve; + r = (int)((s - bias - 0.5) * (255. / (0.25 - curve))); + g = 255; + b = 0; } - else if(s-bias<=1.00) { - curve = (curve == -0.25)? -0.26 : curve; - r = 255; g = (int)(255.-(255./(0.25+curve))*(s-bias-0.75+curve)) ; b = 0 ; + else if(s - bias <= 1.00) { + curve = (curve == -0.25) ? -0.26 : curve; + r = 255; + g = + (int)(255. - (255. / (0.25 + curve)) * (s - bias - 0.75 + curve)); + b = 0; } - else { - r = 255 ; g = 0 ; b = 0 ; + else { + r = 255; + g = 0; + b = 0; } break; - case 4: // darkblue-red-yellow-white + case 4: // darkblue-red-yellow-white #define myfct(a,b,c,d) ((a)+\ (b)*(s-bias)+\ (c)*(s-bias)*(s-bias)+\ (d)*(s-bias)*(s-bias)*(s-bias)) #define clamp(x) x = (x)<0?0:((x)>255?255:(x)) - r = (int)(255. * myfct(-0.0506169, 2.81633, -1.87033, 0.0524573) ); - g = (int)(255. * myfct(0.0485868, -1.26109, 6.3074, -4.12498) ); - b = (int)(255. * myfct(0.364662, 1.50814, -7.36756, 6.51847 ) ); - clamp(r); clamp(g); clamp(b); + r = (int)(255. * myfct(-0.0506169, 2.81633, -1.87033, 0.0524573)); + g = (int)(255. * myfct(0.0485868, -1.26109, 6.3074, -4.12498)); + b = (int)(255. * myfct(0.364662, 1.50814, -7.36756, 6.51847)); + clamp(r); + clamp(g); + clamp(b); #undef myfct #undef clamp break; - case 5: // grayscale - if (s-bias<=0.00){ r = g = b = 0 ; } - else if (s-bias<=1.00){ r = g = b = (int)(255*(s-bias)); } - else { r = g = b = 255 ; } + case 5: // grayscale + if(s - bias <= 0.00) { + r = g = b = 0; + } + else if(s - bias <= 1.00) { + r = g = b = (int)(255 * (s - bias)); + } + else { + r = g = b = 255; + } break; - case 6: // monochrome - r = g = b = 0 ; + case 6: // monochrome + r = g = b = 0; break; - case 7: // rainbow modified to add black and white , from EMC2000 - if (s-bias<=0.00) { - r = 0 ; g = 0 ; b = 0 ; + case 7: // rainbow modified to add black and white , from EMC2000 + if(s - bias <= 0.00) { + r = 0; + g = 0; + b = 0; + } + else if(s - bias <= 0.2) { + r = (int)(57 * (1 - 100 * ((s - bias) - 0.1) * ((s - bias) - 0.1))); + g = 0; + b = (int)((s - bias) * (255. / 0.2)); } - else if(s-bias<=0.2){ - r = (int)(57*(1-100*((s-bias)-0.1)*((s-bias)-0.1))) ; g = 0 ; - b = (int)((s-bias)*(255./0.2)) ; + else if(s - bias <= 0.3624) { + r = 0; + g = (int)((s - bias - 0.2) * (255. / 0.1624)); + b = 255; } - else if(s-bias<=0.3624){ - r = 0 ; g = (int)((s-bias-0.2)*(255./0.1624)) ; b = 255 ; + else if(s - bias <= 0.50) { + r = 0; + g = 255; + b = (int)(255. - (255. / 0.1376) * (s - bias - 0.3624)); } - else if(s-bias<=0.50) { - r = 0 ; g = 255 ; b = (int)(255.-(255./0.1376)*(s-bias-0.3624)); + else if(s - bias <= 0.6376) { + r = (int)((s - bias - 0.5) * (255. / 0.1376)); + g = 255; + b = 0; } - else if(s-bias<=0.6376){ - r = (int)((s-bias-0.5)*(255./0.1376)) ; g = 255 ; b = 0 ; + else if(s - bias <= 0.8) { + r = 255; + g = (int)(255. - (255. / 0.1624) * (s - bias - 0.6376)); + b = 0; } - else if(s-bias<=0.8) { - r = 255; g = (int)(255.-(255./0.1624)*(s-bias-0.6376)) ; b = 0 ; + else if(s - bias <= 1.0) { + r = 255; + g = (int)((255. / 0.2) * (s - bias - 0.8)); + b = + (int)(-3187.66 * (s - bias) * (s - bias) + 7012.76 * (s - bias) - + 3570.61); } - else if(s-bias<=1.0) { - r = 255; g = (int)((255./0.2)*(s-bias-0.8)) ; - b = (int)(-3187.66*(s-bias)*(s-bias)+7012.76*(s-bias)-3570.61) ; - } - else { - r = 255 ; g = 255 ; b = 255 ; + else { + r = 255; + g = 255; + b = 255; } break; case 8: // grayscale, without white default: - if (s-bias<=0.00){ r = g = b = 0 ; } - else if (s-bias<=1.00){ r = g = b = (int)(220*(s-bias)); } - else { r = g = b = 220 ; } + if(s - bias <= 0.00) { + r = g = b = 0; + } + else if(s - bias <= 1.00) { + r = g = b = (int)(220 * (s - bias)); + } + else { + r = g = b = 220; + } break; } - if(ct->fpar[COLORTABLE_BETA]){ + if(ct->fpar[COLORTABLE_BETA]) { if(ct->fpar[COLORTABLE_BETA] > 0.0) gamma = 1. - ct->fpar[COLORTABLE_BETA]; - else - gamma = 1./(1.001 + ct->fpar[COLORTABLE_BETA]); // beta is thresholded to [-1,1] - r = (int)( 255. * pow((double)r/255.,gamma) ); - g = (int)( 255. * pow((double)g/255.,gamma) ); - b = (int)( 255. * pow((double)b/255.,gamma) ); + else + gamma = 1. / (1.001 + ct->fpar[COLORTABLE_BETA]); // beta is thresholded to [-1,1] + r = (int)(255. * pow((double)r / 255., gamma)); + g = (int)(255. * pow((double)g / 255., gamma)); + b = (int)(255. * pow((double)b / 255., gamma)); } - if(ct->ipar[COLORTABLE_INVERT]){ - r = 255-r ; - g = 255-g ; - b = 255-b ; + if(ct->ipar[COLORTABLE_INVERT]) { + r = 255 - r; + g = 255 - g; + b = 255 - b; } } else { - r = UNPACK_RED( ct->table[i] ); - g = UNPACK_GREEN( ct->table[i] ); - b = UNPACK_BLUE( ct->table[i] ); + r = UNPACK_RED(ct->table[i]); + g = UNPACK_GREEN(ct->table[i]); + b = UNPACK_BLUE(ct->table[i]); } - - if (alpha_flag) { - a = (int)( ct->fpar[COLORTABLE_ALPHAVAL] * - ct->fpar[COLORTABLE_ALPHAPOW] ); + + if(alpha_flag) { + a = (int)(ct->fpar[COLORTABLE_ALPHAVAL] * + ct->fpar[COLORTABLE_ALPHAPOW]); } else { - a = UNPACK_ALPHA( ct->table[i] ); + a = UNPACK_ALPHA(ct->table[i]); } - - ct->table[i] = PACK_COLOR( r, g, b, a ); + + ct->table[i] = PACK_COLOR(r, g, b, a); } - + } static GmshColorTable clip; -void ColorTable_Copy(GmshColorTable *ct){ +void ColorTable_Copy(GmshColorTable * ct) +{ clip.size = ct->size; memcpy(clip.table, ct->table, ct->size * sizeof(unsigned int)); - memcpy(clip.ipar, ct->ipar, COLORTABLE_NBMAX_PARAM * sizeof(int)); - memcpy(clip.fpar, ct->fpar, COLORTABLE_NBMAX_PARAM * sizeof(float)); + memcpy(clip.ipar, ct->ipar, COLORTABLE_NBMAX_PARAM * sizeof(int)); + memcpy(clip.fpar, ct->fpar, COLORTABLE_NBMAX_PARAM * sizeof(float)); } -void ColorTable_Paste(GmshColorTable *ct){ +void ColorTable_Paste(GmshColorTable * ct) +{ ct->size = clip.size; memcpy(ct->table, clip.table, clip.size * sizeof(unsigned int)); - memcpy(ct->ipar, clip.ipar, COLORTABLE_NBMAX_PARAM * sizeof(int)); - memcpy(ct->fpar, clip.fpar, COLORTABLE_NBMAX_PARAM * sizeof(float)); + memcpy(ct->ipar, clip.ipar, COLORTABLE_NBMAX_PARAM * sizeof(int)); + memcpy(ct->fpar, clip.fpar, COLORTABLE_NBMAX_PARAM * sizeof(float)); } -void ColorTable_Print(GmshColorTable *ct, FILE *fp){ - int i, r, g, b, a; - char tmp1[1024],tmp2[1024]; +void ColorTable_Print(GmshColorTable * ct, FILE * fp) +{ + int i, r, g, b, a; + char tmp1[1024], tmp2[1024]; strcpy(tmp1, ""); - for (i=0;i<ct->size;i++) { - r = UNPACK_RED( ct->table[i] ); - g = UNPACK_GREEN( ct->table[i] ); - b = UNPACK_BLUE( ct->table[i] ); - a = UNPACK_ALPHA( ct->table[i] ); - if(i && !(i%4)){ - if(fp) fprintf(fp, "%s\n", tmp1); else Msg(DIRECT, tmp1); + for(i = 0; i < ct->size; i++) { + r = UNPACK_RED(ct->table[i]); + g = UNPACK_GREEN(ct->table[i]); + b = UNPACK_BLUE(ct->table[i]); + a = UNPACK_ALPHA(ct->table[i]); + if(i && !(i % 4)) { + if(fp) + fprintf(fp, "%s\n", tmp1); + else + Msg(DIRECT, tmp1); strcpy(tmp1, ""); } sprintf(tmp2, "{%d, %d, %d, %d}", r, g, b, a); strcat(tmp1, tmp2); - if(i!=ct->size-1) strcat(tmp1, ", "); + if(i != ct->size - 1) + strcat(tmp1, ", "); } - if(fp) fprintf(fp, "%s\n", tmp1); else Msg(DIRECT, tmp1); + if(fp) + fprintf(fp, "%s\n", tmp1); + else + Msg(DIRECT, tmp1); } -int ColorTable_IsAlpha(GmshColorTable *ct){ +int ColorTable_IsAlpha(GmshColorTable * ct) +{ int i, a; - for (i=0;i<ct->size;i++) { - a = UNPACK_ALPHA( ct->table[i] ); - if(a<255) return 1; + for(i = 0; i < ct->size; i++) { + a = UNPACK_ALPHA(ct->table[i]); + if(a < 255) + return 1; } return 0; } diff --git a/Common/CommandLine.cpp b/Common/CommandLine.cpp index 6caa4f24ecdc56033fd71bf093007e341a850577..f4d872e6d703bcc7c14f8f5a79515a7247e2d739 100644 --- a/Common/CommandLine.cpp +++ b/Common/CommandLine.cpp @@ -1,4 +1,4 @@ -// $Id: CommandLine.cpp,v 1.8 2003-02-25 16:49:36 geuzaine Exp $ +// $Id: CommandLine.cpp,v 1.9 2003-03-01 22:36:36 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -33,16 +33,16 @@ #include "Parser.h" #if !defined(GMSH_MAJOR_VERSION) -#error -#error Common/GmshVersion.h is not up-to-date. +#error +#error Common/GmshVersion.h is not up-to-date. #error Please run 'make tag'. #error #endif -extern Context_T CTX; +extern Context_T CTX; -char *TheFileNameTab[MAX_OPEN_FILES]; -char *TheBgmFileName=NULL, *TheOptString=NULL; +char *TheFileNameTab[MAX_OPEN_FILES]; +char *TheBgmFileName = NULL, *TheOptString = NULL; // *INDENT-OFF* @@ -110,256 +110,282 @@ void Print_Usage(char *name){ // *INDENT-ON* -void Get_Options (int argc, char *argv[], int *nbfiles) { - int i=1; +void Get_Options(int argc, char *argv[], int *nbfiles) +{ + int i = 1; - // Parse session and option files + // This symbol context is local to option parsing (the symbols will + // not interfere with subsequent OpenFiles) - InitSymbols(); //this symbol context is local to option parsing (the - //symbols will not interfere with subsequent OpenFiles) + InitSymbols(); - ParseFile(CTX.sessionrc_filename,1); - ParseFile(CTX.optionsrc_filename,1); + // Parse session and option files + + ParseFile(CTX.sessionrc_filename, 1); + ParseFile(CTX.optionsrc_filename, 1); // Get command line options - TheFileNameTab[0] = CTX.default_filename ; + TheFileNameTab[0] = CTX.default_filename; *nbfiles = 0; - - while (i < argc) { - - if (argv[i][0] == '-') { - - if(!strcmp(argv[i]+1, "string")){ - i++; - if(argv[i]!=NULL) TheOptString = argv[i++]; - else{ + + while(i < argc) { + + if(argv[i][0] == '-') { + + if(!strcmp(argv[i] + 1, "string")) { + i++; + if(argv[i] != NULL) + TheOptString = argv[i++]; + else { fprintf(stderr, ERROR_STR "Missing string\n"); exit(1); - } + } } - else if(!strcmp(argv[i]+1, "a")){ - CTX.initial_context = 0; i++; + else if(!strcmp(argv[i] + 1, "a")) { + CTX.initial_context = 0; + i++; } - else if(!strcmp(argv[i]+1, "g")){ - CTX.initial_context = 1; i++; + else if(!strcmp(argv[i] + 1, "g")) { + CTX.initial_context = 1; + i++; } - else if(!strcmp(argv[i]+1, "m")){ - CTX.initial_context = 2; i++; + else if(!strcmp(argv[i] + 1, "m")) { + CTX.initial_context = 2; + i++; } - else if(!strcmp(argv[i]+1, "s")){ - CTX.initial_context = 3; i++; + else if(!strcmp(argv[i] + 1, "s")) { + CTX.initial_context = 3; + i++; } - else if(!strcmp(argv[i]+1, "p")){ - CTX.initial_context = 4; i++; + else if(!strcmp(argv[i] + 1, "p")) { + CTX.initial_context = 4; + i++; } - else if(!strcmp(argv[i]+1, "0")){ - CTX.batch = -1; i++; + else if(!strcmp(argv[i] + 1, "0")) { + CTX.batch = -1; + i++; } - else if(!strcmp(argv[i]+1, "1")){ - CTX.batch = 1; i++; + else if(!strcmp(argv[i] + 1, "1")) { + CTX.batch = 1; + i++; } - else if(!strcmp(argv[i]+1, "2")){ - CTX.batch = 2; i++; + else if(!strcmp(argv[i] + 1, "2")) { + CTX.batch = 2; + i++; } - else if(!strcmp(argv[i]+1, "3")){ - CTX.batch = 3; i++; + else if(!strcmp(argv[i] + 1, "3")) { + CTX.batch = 3; + i++; } - else if(!strcmp(argv[i]+1, "saveall")){ - CTX.mesh.save_all = 1; i++; + else if(!strcmp(argv[i] + 1, "saveall")) { + CTX.mesh.save_all = 1; + i++; } - else if(!strcmp(argv[i]+1, "extrude")){ //old extrusion mesh generator - CTX.mesh.oldxtrude = 1; i++; + else if(!strcmp(argv[i] + 1, "extrude")) { //old extrusion mesh generator + CTX.mesh.oldxtrude = 1; + i++; } - else if(!strcmp(argv[i]+1, "recombine")){ //old extrusion mesh generator - CTX.mesh.oldxtrude_recombine = 1; i++; + else if(!strcmp(argv[i] + 1, "recombine")) { //old extrusion mesh generator + CTX.mesh.oldxtrude_recombine = 1; + i++; } - else if(!strcmp(argv[i]+1, "dupli")){ - CTX.mesh.check_duplicates = 1; i++; + else if(!strcmp(argv[i] + 1, "dupli")) { + CTX.mesh.check_duplicates = 1; + i++; } - else if(!strcmp(argv[i]+1, "histogram")){ - CTX.mesh.histogram = 1; i++; + else if(!strcmp(argv[i] + 1, "histogram")) { + CTX.mesh.histogram = 1; + i++; } - else if(!strcmp(argv[i]+1, "option")){ + else if(!strcmp(argv[i] + 1, "option")) { i++; - if(argv[i] != NULL) ParseFile(argv[i++],1); - else { + if(argv[i] != NULL) + ParseFile(argv[i++], 1); + else { fprintf(stderr, ERROR_STR "Missing file name\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "o")){ + else if(!strcmp(argv[i] + 1, "o")) { i++; - if(argv[i] != NULL) CTX.output_filename = argv[i++]; - else { + if(argv[i] != NULL) + CTX.output_filename = argv[i++]; + else { fprintf(stderr, ERROR_STR "Missing file name\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "bgm")){ + else if(!strcmp(argv[i] + 1, "bgm")) { i++; - if(argv[i] != NULL) TheBgmFileName = argv[i++]; - else { + if(argv[i] != NULL) + TheBgmFileName = argv[i++]; + else { fprintf(stderr, ERROR_STR "Missing file name\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "constrain")){ - CTX.mesh.constrained_bgmesh = 1; i++; - } - else if(!strcmp(argv[i]+1, "convert")){ - i++; - CTX.terminal = 1; - if(argv[i] && argv[i+1]){ - ParseFile(argv[i],0); - if(List_Nbr(CTX.post.list)) - WriteView(1,(Post_View*)List_Pointer(CTX.post.list, 0),argv[i+1]); - else - fprintf(stderr, ERROR_STR "No view to convert\n"); - } - else - fprintf(stderr, "Usage: %s -convert view.ascii view.binary\n", argv[0]); - exit(1); - } - else if(!strcmp(argv[i]+1, "old")){ - CTX.geom.old_circle = 1; i++; - } - else if(!strcmp(argv[i]+1, "initial")){ - i++; - if(argv[i]!=NULL) CTX.mesh.initial_only = atoi(argv[i++]); - else { + else if(!strcmp(argv[i] + 1, "constrain")) { + CTX.mesh.constrained_bgmesh = 1; + i++; + } + else if(!strcmp(argv[i] + 1, "convert")) { + i++; + CTX.terminal = 1; + if(argv[i] && argv[i + 1]) { + ParseFile(argv[i], 0); + if(List_Nbr(CTX.post.list)) + WriteView(1, (Post_View *) List_Pointer(CTX.post.list, 0), + argv[i + 1]); + else + fprintf(stderr, ERROR_STR "No view to convert\n"); + } + else + fprintf(stderr, "Usage: %s -convert view.ascii view.binary\n", + argv[0]); + exit(1); + } + else if(!strcmp(argv[i] + 1, "old")) { + CTX.geom.old_circle = 1; + i++; + } + else if(!strcmp(argv[i] + 1, "initial")) { + i++; + if(argv[i] != NULL) + CTX.mesh.initial_only = atoi(argv[i++]); + else { fprintf(stderr, ERROR_STR "Missing number\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "quality")){ + else if(!strcmp(argv[i] + 1, "quality")) { i++; - if(argv[i]!=NULL) CTX.mesh.quality = atof(argv[i++]); - else { + if(argv[i] != NULL) + CTX.mesh.quality = atof(argv[i++]); + else { fprintf(stderr, ERROR_STR "Missing number\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "scale")){ + else if(!strcmp(argv[i] + 1, "scale")) { i++; - if(argv[i]!=NULL) CTX.geom.scaling_factor = atof(argv[i++]); - else { + if(argv[i] != NULL) + CTX.geom.scaling_factor = atof(argv[i++]); + else { fprintf(stderr, ERROR_STR "Missing number\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "meshscale")){ + else if(!strcmp(argv[i] + 1, "meshscale")) { i++; - if(argv[i]!=NULL) CTX.mesh.scaling_factor = atof(argv[i++]); - else { + if(argv[i] != NULL) + CTX.mesh.scaling_factor = atof(argv[i++]); + else { fprintf(stderr, ERROR_STR "Missing number\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "rand")){ + else if(!strcmp(argv[i] + 1, "rand")) { i++; - if(argv[i]!=NULL) CTX.mesh.rand_factor = atof(argv[i++]); - else { + if(argv[i] != NULL) + CTX.mesh.rand_factor = atof(argv[i++]); + else { fprintf(stderr, ERROR_STR "Missing number\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "clscale")){ + else if(!strcmp(argv[i] + 1, "clscale")) { i++; - if(argv[i]!=NULL){ + if(argv[i] != NULL) { CTX.mesh.lc_factor = atof(argv[i++]); - if(CTX.mesh.lc_factor <= 0.0){ - fprintf(stderr, ERROR_STR + if(CTX.mesh.lc_factor <= 0.0) { + fprintf(stderr, ERROR_STR "Characteristic length factor must be > 0\n"); exit(1); } } - else { + else { fprintf(stderr, ERROR_STR "Missing number\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "smooth")){ + else if(!strcmp(argv[i] + 1, "smooth")) { i++; - if(argv[i]!=NULL) CTX.mesh.nb_smoothing = atoi(argv[i++]); - else{ + if(argv[i] != NULL) + CTX.mesh.nb_smoothing = atoi(argv[i++]); + else { fprintf(stderr, ERROR_STR "Missing number\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "degree")){ + else if(!strcmp(argv[i] + 1, "degree")) { i++; - if(argv[i]!=NULL) + if(argv[i] != NULL) opt_mesh_degree(0, GMSH_SET, atof(argv[i++])); - else { + else { fprintf(stderr, ERROR_STR "Missing number\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "format") || - !strcmp(argv[i]+1, "f")){ + else if(!strcmp(argv[i] + 1, "format") || !strcmp(argv[i] + 1, "f")) { i++; - if(argv[i]!=NULL){ - if(!strcmp(argv[i],"msh") || - !strcmp(argv[i],"MSH") || - !strcmp(argv[i],"gmsh")){ - CTX.mesh.format = FORMAT_MSH ; + if(argv[i] != NULL) { + if(!strcmp(argv[i], "msh") || + !strcmp(argv[i], "MSH") || !strcmp(argv[i], "gmsh")) { + CTX.mesh.format = FORMAT_MSH; } - else if(!strcmp(argv[i],"unv") || - !strcmp(argv[i],"UNV") || - !strcmp(argv[i],"ideas")){ - CTX.mesh.format = FORMAT_UNV ; + else if(!strcmp(argv[i], "unv") || + !strcmp(argv[i], "UNV") || !strcmp(argv[i], "ideas")) { + CTX.mesh.format = FORMAT_UNV; } - else if(!strcmp(argv[i],"gref") || - !strcmp(argv[i],"GREF") || - !strcmp(argv[i],"Gref")){ - CTX.mesh.format = FORMAT_GREF ; + else if(!strcmp(argv[i], "gref") || + !strcmp(argv[i], "GREF") || !strcmp(argv[i], "Gref")) { + CTX.mesh.format = FORMAT_GREF; } - else{ + else { fprintf(stderr, ERROR_STR "Unknown mesh format\n"); exit(1); } i++; } - else { + else { fprintf(stderr, ERROR_STR "Missing format\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "algo")){ + else if(!strcmp(argv[i] + 1, "algo")) { i++; - if(argv[i]!=NULL){ - if(!strncmp(argv[i],"iso",3)) - CTX.mesh.algo = DELAUNAY_ISO ; - else if(!strncmp(argv[i],"tri",3)) - CTX.mesh.algo = DELAUNAY_SHEWCHUK ; - else if(!strncmp(argv[i],"aniso",5)) - CTX.mesh.algo = DELAUNAY_ANISO ; - else{ + if(argv[i] != NULL) { + if(!strncmp(argv[i], "iso", 3)) + CTX.mesh.algo = DELAUNAY_ISO; + else if(!strncmp(argv[i], "tri", 3)) + CTX.mesh.algo = DELAUNAY_SHEWCHUK; + else if(!strncmp(argv[i], "aniso", 5)) + CTX.mesh.algo = DELAUNAY_ANISO; + else { fprintf(stderr, ERROR_STR "Unknown mesh algorithm\n"); exit(1); } i++; } - else { + else { fprintf(stderr, ERROR_STR "Missing algorithm\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "version") || - !strcmp(argv[i]+1, "-version")){ - fprintf(stderr, "%d.%d.%d\n", GMSH_MAJOR_VERSION, GMSH_MINOR_VERSION, - GMSH_PATCH_VERSION); + else if(!strcmp(argv[i] + 1, "version") || + !strcmp(argv[i] + 1, "-version")) { + fprintf(stderr, "%d.%d.%d\n", GMSH_MAJOR_VERSION, GMSH_MINOR_VERSION, + GMSH_PATCH_VERSION); exit(1); } - else if(!strcmp(argv[i]+1, "info") || - !strcmp(argv[i]+1, "-info")){ - fprintf(stderr, "%s%d.%d.%d\n", gmsh_version, GMSH_MAJOR_VERSION, - GMSH_MINOR_VERSION, GMSH_PATCH_VERSION); + else if(!strcmp(argv[i] + 1, "info") || !strcmp(argv[i] + 1, "-info")) { + fprintf(stderr, "%s%d.%d.%d\n", gmsh_version, GMSH_MAJOR_VERSION, + GMSH_MINOR_VERSION, GMSH_PATCH_VERSION); fprintf(stderr, "%s\n", gmsh_os); #if defined(HAVE_FLTK) - fprintf(stderr, "%sFLTK %d.%d.%d\n", gmsh_gui, FL_MAJOR_VERSION, - FL_MINOR_VERSION, FL_PATCH_VERSION); + fprintf(stderr, "%sFLTK %d.%d.%d\n", gmsh_gui, FL_MAJOR_VERSION, + FL_MINOR_VERSION, FL_PATCH_VERSION); #else fprintf(stderr, "%snone\n", gmsh_gui); #endif @@ -368,166 +394,187 @@ void Get_Options (int argc, char *argv[], int *nbfiles) { fprintf(stderr, "%s\n", gmsh_packager); fprintf(stderr, "%s\n", gmsh_url); fprintf(stderr, "%s\n", gmsh_email); - exit(1) ; + exit(1); } - else if(!strcmp(argv[i]+1, "help") || - !strcmp(argv[i]+1, "-help")){ + else if(!strcmp(argv[i] + 1, "help") || !strcmp(argv[i] + 1, "-help")) { fprintf(stderr, "%s\n", gmsh_progname); fprintf(stderr, "%s\n", gmsh_copyright); - CTX.terminal = 1 ; + CTX.terminal = 1; Print_Usage(argv[0]); exit(1); } - else if(!strcmp(argv[i]+1, "v")){ + else if(!strcmp(argv[i] + 1, "v")) { i++; - if(argv[i]!=NULL) CTX.verbosity = atoi(argv[i++]); - else { + if(argv[i] != NULL) + CTX.verbosity = atoi(argv[i++]); + else { fprintf(stderr, ERROR_STR "Missing number\n"); exit(1); } } #if defined(HAVE_FLTK) - else if(!strcmp(argv[i]+1, "noterm")){ - CTX.terminal = 0; i++; + else if(!strcmp(argv[i] + 1, "noterm")) { + CTX.terminal = 0; + i++; } - else if(!strcmp(argv[i]+1, "term")){ - CTX.terminal = 1; i++; + else if(!strcmp(argv[i] + 1, "term")) { + CTX.terminal = 1; + i++; } - else if(!strcmp(argv[i]+1, "alpha")){ - CTX.alpha = 1; i++; + else if(!strcmp(argv[i] + 1, "alpha")) { + CTX.alpha = 1; + i++; } - else if(!strcmp(argv[i]+1, "notrack")){ - CTX.useTrackball = 0; i++; + else if(!strcmp(argv[i] + 1, "notrack")) { + CTX.useTrackball = 0; + i++; } - else if(!strcmp(argv[i]+1, "dual")){ - CTX.mesh.dual = 1; i++; + else if(!strcmp(argv[i] + 1, "dual")) { + CTX.mesh.dual = 1; + i++; } - else if(!strcmp(argv[i]+1, "interactive")){ - CTX.mesh.interactive = 1; i++; + else if(!strcmp(argv[i] + 1, "interactive")) { + CTX.mesh.interactive = 1; + i++; } - else if(!strcmp(argv[i]+1, "noview")){ - opt_view_visible(0, GMSH_SET, 0); i++; + else if(!strcmp(argv[i] + 1, "noview")) { + opt_view_visible(0, GMSH_SET, 0); + i++; } - else if(!strcmp(argv[i]+1, "plugin")){ - opt_general_default_plugins(0, GMSH_SET, 1); i++; + else if(!strcmp(argv[i] + 1, "plugin")) { + opt_general_default_plugins(0, GMSH_SET, 1); + i++; } - else if(!strcmp(argv[i]+1, "noplugin")){ - opt_general_default_plugins(0, GMSH_SET, 0); i++; + else if(!strcmp(argv[i] + 1, "noplugin")) { + opt_general_default_plugins(0, GMSH_SET, 0); + i++; } - else if(!strcmp(argv[i]+1, "link")){ - i++ ; - if(argv[i]!=NULL) - CTX.post.link = atoi(argv[i++]); - else{ + else if(!strcmp(argv[i] + 1, "link")) { + i++; + if(argv[i] != NULL) + CTX.post.link = atoi(argv[i++]); + else { fprintf(stderr, ERROR_STR "Missing number\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "fill")){ - opt_view_intervals_type(0, GMSH_SET, DRAW_POST_CONTINUOUS) ; i++; + else if(!strcmp(argv[i] + 1, "fill")) { + opt_view_intervals_type(0, GMSH_SET, DRAW_POST_CONTINUOUS); + i++; } - else if(!strcmp(argv[i]+1, "smoothview")){ - CTX.post.smooth=1; i++; + else if(!strcmp(argv[i] + 1, "smoothview")) { + CTX.post.smooth = 1; + i++; } - else if(!strcmp(argv[i]+1, "nbiso")){ - i++ ; - if(argv[i]!=NULL) - opt_view_nb_iso(0, GMSH_SET, atoi(argv[i++])); - else{ + else if(!strcmp(argv[i] + 1, "nbiso")) { + i++; + if(argv[i] != NULL) + opt_view_nb_iso(0, GMSH_SET, atoi(argv[i++])); + else { fprintf(stderr, ERROR_STR "Missing number\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "command") || - !strcmp(argv[i]+1, "c")){ - CTX.command_win = 1; i++; + else if(!strcmp(argv[i] + 1, "command") || !strcmp(argv[i] + 1, "c")) { + CTX.command_win = 1; + i++; } - else if(!strcmp(argv[i]+1, "nocommand") || - !strcmp(argv[i]+1, "noc")){ - CTX.command_win = 0; i++; + else if(!strcmp(argv[i] + 1, "nocommand") || + !strcmp(argv[i] + 1, "noc")) { + CTX.command_win = 0; + i++; } - else if(!strcmp(argv[i]+1, "overlay") || - !strcmp(argv[i]+1, "ov")){ - CTX.overlay = 1; i++; + else if(!strcmp(argv[i] + 1, "overlay") || !strcmp(argv[i] + 1, "ov")) { + CTX.overlay = 1; + i++; } - else if(!strcmp(argv[i]+1, "nooverlay") || - !strcmp(argv[i]+1, "noov")){ - CTX.overlay = CTX.geom.highlight = 0; i++; + else if(!strcmp(argv[i] + 1, "nooverlay") || + !strcmp(argv[i] + 1, "noov")) { + CTX.overlay = CTX.geom.highlight = 0; + i++; } - else if(!strcmp(argv[i]+1, "hh")){ - CTX.overlay = 0 ; CTX.geom.highlight = 1; i++; + else if(!strcmp(argv[i] + 1, "hh")) { + CTX.overlay = 0; + CTX.geom.highlight = 1; + i++; } - else if(!strcmp(argv[i]+1, "perspective") || - !strcmp(argv[i]+1, "p")){ - CTX.ortho = 0; i++; + else if(!strcmp(argv[i] + 1, "perspective") || + !strcmp(argv[i] + 1, "p")) { + CTX.ortho = 0; + i++; } - else if(!strcmp(argv[i]+1, "ortho") || - !strcmp(argv[i]+1, "o")){ - CTX.ortho = 0; i++; + else if(!strcmp(argv[i] + 1, "ortho") || !strcmp(argv[i] + 1, "o")) { + CTX.ortho = 0; + i++; } - else if(!strcmp(argv[i]+1, "threads")){ - CTX.threads = 1; i++; + else if(!strcmp(argv[i] + 1, "threads")) { + CTX.threads = 1; + i++; } - else if(!strcmp(argv[i]+1, "nothreads")){ - CTX.threads = 0; i++; + else if(!strcmp(argv[i] + 1, "nothreads")) { + CTX.threads = 0; + i++; } - else if(!strcmp(argv[i]+1, "db")){ - CTX.db = 1; i++; + else if(!strcmp(argv[i] + 1, "db")) { + CTX.db = 1; + i++; } - else if(!strcmp(argv[i]+1, "nodb")){ - CTX.db = 0; CTX.geom.highlight = 0; i++; + else if(!strcmp(argv[i] + 1, "nodb")) { + CTX.db = 0; + CTX.geom.highlight = 0; + i++; } - else if(!strcmp(argv[i]+1, "dl")){ - CTX.post.display_lists = 1; i++; + else if(!strcmp(argv[i] + 1, "dl")) { + CTX.post.display_lists = 1; + i++; } - else if(!strcmp(argv[i]+1, "nodl")){ - CTX.post.display_lists = 0; i++; + else if(!strcmp(argv[i] + 1, "nodl")) { + CTX.post.display_lists = 0; + i++; } - else if(!strcmp(argv[i]+1, "fontsize")){ + else if(!strcmp(argv[i] + 1, "fontsize")) { i++; - if(argv[i]!=NULL){ - CTX.fontsize = atoi(argv[i]); + if(argv[i] != NULL) { + CTX.fontsize = atoi(argv[i]); i++; - } - else { + } + else { fprintf(stderr, ERROR_STR "Missing number\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "theme")){ + else if(!strcmp(argv[i] + 1, "theme")) { i++; - if(argv[i]!=NULL){ - CTX.theme = argv[i]; + if(argv[i] != NULL) { + CTX.theme = argv[i]; i++; - } - else { + } + else { fprintf(stderr, ERROR_STR "Missing argument\n"); exit(1); } } - else if(!strcmp(argv[i]+1, "display")){ + else if(!strcmp(argv[i] + 1, "display")) { i++; - if(argv[i]!=NULL){ - CTX.display = argv[i]; + if(argv[i] != NULL) { + CTX.display = argv[i]; i++; - } - else { + } + else { fprintf(stderr, ERROR_STR "Missing argument\n"); exit(1); } } #endif - - - else{ + else { #if defined(__APPLE__) - // The Mac Finder launches programs with special command line - // arguments: just ignore them (and don't exit!) + // The Mac Finder launches programs with special command line + // arguments: just ignore them (and don't exit!) fprintf(stderr, "Unknown option '%s'\n", argv[i]); - i++; + i++; #else fprintf(stderr, "Unknown option '%s'\n", argv[i]); - CTX.terminal = 1 ; + CTX.terminal = 1; Print_Usage(argv[0]); exit(1); #endif @@ -536,8 +583,8 @@ void Get_Options (int argc, char *argv[], int *nbfiles) { else { if(*nbfiles < MAX_OPEN_FILES) - TheFileNameTab[(*nbfiles)++] = argv[i++]; - else{ + TheFileNameTab[(*nbfiles)++] = argv[i++]; + else { fprintf(stderr, ERROR_STR "Too many input files\n"); exit(1); } @@ -546,6 +593,4 @@ void Get_Options (int argc, char *argv[], int *nbfiles) { } strncpy(CTX.filename, TheFileNameTab[0], 255); - } - diff --git a/Common/Context.cpp b/Common/Context.cpp index 6f5bb7f629a9e23fa90c50e1877ecb9a65e4968d..d70d7ff1a43f6bb4087cf4beb1787334e48306cc 100644 --- a/Common/Context.cpp +++ b/Common/Context.cpp @@ -1,4 +1,4 @@ -// $Id: Context.cpp,v 1.47 2003-02-12 20:27:12 geuzaine Exp $ +// $Id: Context.cpp,v 1.48 2003-03-01 22:36:36 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -51,10 +51,11 @@ */ -void Context_T::buildRotmatrix(void){ +void Context_T::buildRotmatrix(void) +{ double x, y, z; - if(useTrackball){ + if(useTrackball) { build_rotmatrix(rot, quaternion); #if defined(HAVE_FLTK) @@ -65,74 +66,76 @@ void Context_T::buildRotmatrix(void){ set_r(1, 0.); set_r(2, 0.); /* - double x=0., y=0., z=0. - - y = asin(rot[2][0]) ; y = Pi - asin(rot[2][0]) ; // choix ??? - - if(fabs(y) != Pi/2.){ - if(rot[2][2]*cos(y) > 0.) x = atan2(-rot[2][1],rot[2][2]); - else x = atan2(-rot[2][1],rot[2][2]) + Pi; - if(rot[0][0]*cos(y) > 0.) z = atan2(-rot[1][0],rot[0][0]); - else z = atan2(-rot[1][0],rot[0][0]) + Pi; - } - set_r(0, x * 180./Pi); - set_r(1, y * 180./Pi); - set_r(2, z * 180./Pi); - */ + double x=0., y=0., z=0. + + y = asin(rot[2][0]) ; y = Pi - asin(rot[2][0]) ; // choix ??? + + if(fabs(y) != Pi/2.){ + if(rot[2][2]*cos(y) > 0.) x = atan2(-rot[2][1],rot[2][2]); + else x = atan2(-rot[2][1],rot[2][2]) + Pi; + if(rot[0][0]*cos(y) > 0.) z = atan2(-rot[1][0],rot[0][0]); + else z = atan2(-rot[1][0],rot[0][0]) + Pi; + } + set_r(0, x * 180./Pi); + set_r(1, y * 180./Pi); + set_r(2, z * 180./Pi); + */ /* - double r0, r1, r2; - - r1 = atan2(-rot[0][2],sqrt(rot[1][2]*rot[1][2] + rot[2][2]*rot[2][2])); - - double c = cos(r1); - if(c != 0.0){ - r0 = atan2(rot[1][2]/c,rot[2][2]/c) ; - r2 = atan2(-rot[1][0]/c,rot[0][0]/c) ; - r0 *= 180./(Pi); - r2 *= 180./(Pi); - } - set_r(0, r0); - set_r(1, r1 * 180./(Pi)); // lazyyyyyy - set_r(2, r2); - */ + double r0, r1, r2; + + r1 = atan2(-rot[0][2],sqrt(rot[1][2]*rot[1][2] + rot[2][2]*rot[2][2])); + + double c = cos(r1); + if(c != 0.0){ + r0 = atan2(rot[1][2]/c,rot[2][2]/c) ; + r2 = atan2(-rot[1][0]/c,rot[0][0]/c) ; + r0 *= 180./(Pi); + r2 *= 180./(Pi); + } + set_r(0, r0); + set_r(1, r1 * 180./(Pi)); // lazyyyyyy + set_r(2, r2); + */ #endif } - else{ + else { x = r[0] * Pi / 180.; y = r[1] * Pi / 180.; z = r[2] * Pi / 180.; - rot[0][0] = cos(y)*cos(z) ; - rot[0][1] = sin(x)*sin(y)*cos(z)+cos(x)*sin(z); - rot[0][2] = -cos(x)*sin(y)*cos(z)+sin(x)*sin(z); + rot[0][0] = cos(y) * cos(z); + rot[0][1] = sin(x) * sin(y) * cos(z) + cos(x) * sin(z); + rot[0][2] = -cos(x) * sin(y) * cos(z) + sin(x) * sin(z); rot[0][3] = 0.0; - rot[1][0] = -cos(y)*sin(z); - rot[1][1] = -sin(x)*sin(y)*sin(z)+cos(x)*cos(z); - rot[1][2] = cos(x)*sin(y)*sin(z)+sin(x)*cos(z); + rot[1][0] = -cos(y) * sin(z); + rot[1][1] = -sin(x) * sin(y) * sin(z) + cos(x) * cos(z); + rot[1][2] = cos(x) * sin(y) * sin(z) + sin(x) * cos(z); rot[1][3] = 0.0; - + rot[2][0] = sin(y); - rot[2][1] = -sin(x)*cos(y); - rot[2][2] = cos(x)*cos(y); + rot[2][1] = -sin(x) * cos(y); + rot[2][2] = cos(x) * cos(y); rot[2][3] = 0.0; - rot[3][0] = 0.0 ; - rot[3][1] = 0.0 ; - rot[3][2] = 0.0 ; - rot[3][3] = 1.0 ; + rot[3][0] = 0.0; + rot[3][1] = 0.0; + rot[3][2] = 0.0; + rot[3][3] = 1.0; } } -void Context_T::addQuaternion (float p1x, float p1y, float p2x, float p2y){ +void Context_T::addQuaternion(float p1x, float p1y, float p2x, float p2y) +{ float quat[4]; - trackball(quat,p1x,p1y,p2x,p2y); - add_quats(quat, quaternion, quaternion); + trackball(quat, p1x, p1y, p2x, p2y); + add_quats(quat, quaternion, quaternion); } -void Context_T::setQuaternion (float q0, float q1, float q2, float q3){ +void Context_T::setQuaternion(float q0, float q1, float q2, float q3) +{ quaternion[0] = q0; quaternion[1] = q1; quaternion[2] = q2; diff --git a/Common/Options.cpp b/Common/Options.cpp index c1230bd8719c9b4f5572468bfb1196f2c83957cf..ceae8b794c6e302827759f8771bcce731f9e3454 100644 --- a/Common/Options.cpp +++ b/Common/Options.cpp @@ -1,4 +1,4 @@ -// $Id: Options.cpp,v 1.100 2003-02-12 20:27:12 geuzaine Exp $ +// $Id: Options.cpp,v 1.101 2003-03-01 22:36:36 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -27,19 +27,20 @@ #include "Context.h" #include "Options.h" -extern Context_T CTX ; +extern Context_T CTX; #if defined(HAVE_FLTK) #include "Solvers.h" #include "GUI.h" -extern GUI *WID ; +extern GUI *WID; #endif -extern Post_View *Post_ViewReference; +extern Post_View *Post_ViewReference; // General routines -void Init_Options_Safe(int num){ +void Init_Options_Safe(int num) +{ Post_ViewReference->CT.size = 255; Post_ViewReference->CT.ipar[COLORTABLE_MODE] = COLORTABLE_RGB; ColorTable_InitParam(1, &Post_ViewReference->CT, 1, 1); @@ -73,73 +74,81 @@ void Init_Options_Safe(int num){ Set_DefaultColorOptions(num, PrintOptions_Color, CTX.color_scheme); } -void Init_Options(int num){ +void Init_Options(int num) +{ char *tmp; // Home directory -#if !defined(WIN32) // Some WinNT systems have bad HOME variables... - if((tmp = getenv("HOME"))) strcpy(CTX.home_dir, tmp); - else +#if !defined(WIN32) // Some WinNT systems have bad HOME variables... + if((tmp = getenv("HOME"))) + strcpy(CTX.home_dir, tmp); + else #endif - if((tmp = getenv("TMP"))) strcpy(CTX.home_dir, tmp); - else if((tmp = getenv("TEMP"))) strcpy(CTX.home_dir, tmp); - else strcpy(CTX.home_dir, ""); + if((tmp = getenv("TMP"))) + strcpy(CTX.home_dir, tmp); + else if((tmp = getenv("TEMP"))) + strcpy(CTX.home_dir, tmp); + else + strcpy(CTX.home_dir, ""); - if(strlen(CTX.home_dir)) strcat(CTX.home_dir, "/"); + if(strlen(CTX.home_dir)) + strcat(CTX.home_dir, "/"); // Reference view storing default options - Post_ViewReference = (Post_View*)Malloc(sizeof(Post_View)) ; + Post_ViewReference = (Post_View *) Malloc(sizeof(Post_View)); Init_Options_Safe(num); // The following defaults cannot be set by the user - CTX.batch = 0 ; - CTX.mesh.initial_only = 0 ; - CTX.output_filename = NULL ; - CTX.expose = 0 ; - CTX.lc = 1.0 ; - CTX.viewport[0] = CTX.viewport[1] = 0 ; - CTX.min[0] = CTX.min[1] = CTX.min[2] = 0.0 ; - CTX.max[0] = CTX.max[1] = CTX.max[2] = 1.0 ; - CTX.range[0] = CTX.range[1] = CTX.range[2] = 1.0 ; - CTX.vxmin = CTX.vymin = CTX.vxmax = CTX.vymax = 0. ; - CTX.render_mode = GMSH_RENDER ; - CTX.pixel_equiv_x = CTX.pixel_equiv_y = 0. ; - CTX.geom.vis_type = 0 ; - CTX.geom.level = ELEMENTARY ; - CTX.mesh.vis_type = 0 ; - CTX.mesh.draw = 1 ; - CTX.post.draw = 1 ; - CTX.post.list = NULL ; - CTX.post.force_num = 0 ; + CTX.batch = 0; + CTX.mesh.initial_only = 0; + CTX.output_filename = NULL; + CTX.expose = 0; + CTX.lc = 1.0; + CTX.viewport[0] = CTX.viewport[1] = 0; + CTX.min[0] = CTX.min[1] = CTX.min[2] = 0.0; + CTX.max[0] = CTX.max[1] = CTX.max[2] = 1.0; + CTX.range[0] = CTX.range[1] = CTX.range[2] = 1.0; + CTX.vxmin = CTX.vymin = CTX.vxmax = CTX.vymax = 0.; + CTX.render_mode = GMSH_RENDER; + CTX.pixel_equiv_x = CTX.pixel_equiv_y = 0.; + CTX.geom.vis_type = 0; + CTX.geom.level = ELEMENTARY; + CTX.mesh.vis_type = 0; + CTX.mesh.draw = 1; + CTX.post.draw = 1; + CTX.post.list = NULL; + CTX.post.force_num = 0; CTX.print.gl_fonts = 1; - CTX.threads_lock = 0 ; //very primitive locking during mesh generation - CTX.mesh.histogram = 0 ; - CTX.mesh.oldxtrude = CTX.mesh.oldxtrude_recombine = 0; //old extrusion mesh generator - CTX.mesh.check_duplicates = 0; //check for duplicate nodes in Read_Mesh + CTX.threads_lock = 0; //very primitive locking during mesh generation + CTX.mesh.histogram = 0; + CTX.mesh.oldxtrude = CTX.mesh.oldxtrude_recombine = 0; //old extrusion mesh generator + CTX.mesh.check_duplicates = 0; //check for duplicate nodes in Read_Mesh } -void ReInit_Options(int num){ +void ReInit_Options(int num) +{ + // horrible trick so that the opt_view_XXX will act on the reference view List_T *l = CTX.post.list; - CTX.post.list=NULL; // horrible trick so that the opt_view_XXX will - // act on the reference view + CTX.post.list = NULL; Init_Options_Safe(num); CTX.post.list = l; - for(int i=0; i<List_Nbr(CTX.post.list) ; i++){ - Post_View *v = (Post_View*)List_Pointer(CTX.post.list,i); + for(int i = 0; i < List_Nbr(CTX.post.list); i++) { + Post_View *v = (Post_View *) List_Pointer(CTX.post.list, i); CopyViewOptions(Post_ViewReference, v); } } -void Init_Options_GUI(int num){ +void Init_Options_GUI(int num) +{ Set_StringOptions_GUI(num, GeneralOptions_String); Set_StringOptions_GUI(num, GeometryOptions_String); Set_StringOptions_GUI(num, MeshOptions_String); Set_StringOptions_GUI(num, SolverOptions_String); Set_StringOptions_GUI(num, PostProcessingOptions_String); Set_StringOptions_GUI(num, PrintOptions_String); - + Set_NumberOptions_GUI(num, GeneralOptions_Number); Set_NumberOptions_GUI(num, GeometryOptions_Number); Set_NumberOptions_GUI(num, MeshOptions_Number); @@ -155,36 +164,39 @@ void Init_Options_GUI(int num){ Set_ColorOptions_GUI(num, PrintOptions_Color); } -void Print_OptionCategory(int level, char *cat, FILE *file){ - if(level & GMSH_SESSIONRC) return ; - if(file){ +void Print_OptionCategory(int level, char *cat, FILE * file) +{ + if(level & GMSH_SESSIONRC) + return; + if(file) { fprintf(file, "//\n"); fprintf(file, "// %s\n", cat); fprintf(file, "//\n"); } - else{ + else { Msg(DIRECT, "//"); Msg(DIRECT, "// %s", cat); Msg(DIRECT, "//"); } } -void Print_Options(int num, int level, char *filename){ +void Print_Options(int num, int level, char *filename) +{ FILE *file; char tmp[256]; - int i ; - - if(filename){ - file = fopen(filename,"w"); - if(!file){ + int i; + + if(filename) { + file = fopen(filename, "w"); + if(!file) { Msg(GERROR, "Unable to open file '%s'", filename); return; } } else - file = NULL ; + file = NULL; - if((level & GMSH_SESSIONRC) && file){ + if((level & GMSH_SESSIONRC) && file) { fprintf(file, "// Gmsh Session File\n"); fprintf(file, "//\n"); fprintf(file, "// This file takes session specific info (that is info\n"); @@ -196,7 +208,7 @@ void Print_Options(int num, int level, char *filename){ fprintf(file, "//\n"); } - if((level & GMSH_OPTIONSRC) && file){ + if((level & GMSH_OPTIONSRC) && file) { fprintf(file, "// Gmsh Option File\n"); fprintf(file, "//\n"); fprintf(file, "// This file takes configuration options (preferences) that\n"); @@ -238,14 +250,17 @@ void Print_Options(int num, int level, char *filename){ Print_ColorOptions(num, level, SolverOptions_Color, "Solver.", file); Print_OptionCategory(level, "Post-processing options (strings)", file); - Print_StringOptions(num, level, PostProcessingOptions_String, "PostProcessing.", file); + Print_StringOptions(num, level, PostProcessingOptions_String, + "PostProcessing.", file); Print_OptionCategory(level, "Post-processing options (numbers)", file); - Print_NumberOptions(num, level, PostProcessingOptions_Number, "PostProcessing.", file); + Print_NumberOptions(num, level, PostProcessingOptions_Number, + "PostProcessing.", file); Print_OptionCategory(level, "Post-processing options (colors)", file); - Print_ColorOptions(num, level, PostProcessingOptions_Color, "PostProcessing.", file); + Print_ColorOptions(num, level, PostProcessingOptions_Color, + "PostProcessing.", file); - if(level & GMSH_FULLRC){ - for(i=0; i<List_Nbr(CTX.post.list) ; i++){ + if(level & GMSH_FULLRC) { + for(i = 0; i < List_Nbr(CTX.post.list); i++) { sprintf(tmp, "View[%d].", i); Print_OptionCategory(level, "View options (strings)", file); Print_StringOptions(i, level, ViewOptions_String, tmp, file); @@ -257,7 +272,7 @@ void Print_Options(int num, int level, char *filename){ Print_ColorTable(i, tmp, file); } } - else if(level & GMSH_OPTIONSRC){ + else if(level & GMSH_OPTIONSRC) { Print_OptionCategory(level, "View options (strings)", file); Print_StringOptions(num, level, ViewOptions_String, "View.", file); Print_OptionCategory(level, "View options (numbers)", file); @@ -274,8 +289,8 @@ void Print_Options(int num, int level, char *filename){ Print_OptionCategory(level, "Print options (colors)", file); Print_ColorOptions(num, level, PrintOptions_Color, "Print.", file); - if(filename){ - if((level & GMSH_OPTIONSRC) || (level & GMSH_FULLRC)){ + if(filename) { + if((level & GMSH_OPTIONSRC) || (level & GMSH_FULLRC)) { Msg(INFO, "Options output complete '%s'", filename); Msg(STATUS2, "Wrote '%s'", filename); } @@ -285,50 +300,68 @@ void Print_Options(int num, int level, char *filename){ // General routines for string options -StringXString * Get_StringOptionCategory(char * cat){ - if (!strcmp(cat,"General")) return GeneralOptions_String ; - else if(!strcmp(cat,"Geometry")) return GeometryOptions_String ; - else if(!strcmp(cat,"Mesh")) return MeshOptions_String ; - else if(!strcmp(cat,"Solver")) return SolverOptions_String ; - else if(!strcmp(cat,"PostProcessing")) return PostProcessingOptions_String ; - else if(!strcmp(cat,"View")) return ViewOptions_String ; - else if(!strcmp(cat,"Print")) return PrintOptions_String ; - else return NULL ; +StringXString *Get_StringOptionCategory(char *cat) +{ + if(!strcmp(cat, "General")) + return GeneralOptions_String; + else if(!strcmp(cat, "Geometry")) + return GeometryOptions_String; + else if(!strcmp(cat, "Mesh")) + return MeshOptions_String; + else if(!strcmp(cat, "Solver")) + return SolverOptions_String; + else if(!strcmp(cat, "PostProcessing")) + return PostProcessingOptions_String; + else if(!strcmp(cat, "View")) + return ViewOptions_String; + else if(!strcmp(cat, "Print")) + return PrintOptions_String; + else + return NULL; } -void Set_DefaultStringOptions(int num, StringXString s[]){ +void Set_DefaultStringOptions(int num, StringXString s[]) +{ int i = 0; - while(s[i].str){ - s[i].function(num, GMSH_SET, s[i].def) ; + while(s[i].str) { + s[i].function(num, GMSH_SET, s[i].def); i++; } } -void Set_StringOptions_GUI(int num, StringXString s[]){ +void Set_StringOptions_GUI(int num, StringXString s[]) +{ int i = 0; - while(s[i].str){ - s[i].function(num, GMSH_GUI, 0) ; + while(s[i].str) { + s[i].function(num, GMSH_GUI, 0); i++; } } -void * Get_StringOption(char *str, StringXString s[]){ +void *Get_StringOption(char *str, StringXString s[]) +{ int i = 0; - while ((s[i].str != NULL) && (strcmp(s[i].str, str))) i++ ; + while((s[i].str != NULL) && (strcmp(s[i].str, str))) + i++; if(!s[i].str) return NULL; else - return (void*)s[i].function; + return (void *)s[i].function; } -void Print_StringOptions(int num, int level, StringXString s[], char *prefix, FILE *file){ +void Print_StringOptions(int num, int level, StringXString s[], char *prefix, + FILE * file) +{ int i = 0; char tmp[1024]; - while(s[i].str){ - if(s[i].level & level){ - sprintf(tmp, "%s%s = \"%s\"; // %s", prefix, - s[i].str, s[i].function(num, GMSH_GET, NULL), s[i].help) ; - if(file) fprintf(file, "%s\n", tmp); else Msg(DIRECT, "%s", tmp); + while(s[i].str) { + if(s[i].level & level) { + sprintf(tmp, "%s%s = \"%s\"; // %s", prefix, + s[i].str, s[i].function(num, GMSH_GET, NULL), s[i].help); + if(file) + fprintf(file, "%s\n", tmp); + else + Msg(DIRECT, "%s", tmp); } i++; } @@ -336,52 +369,70 @@ void Print_StringOptions(int num, int level, StringXString s[], char *prefix, FI // General routines for numeric options -StringXNumber * Get_NumberOptionCategory(char * cat){ - if (!strcmp(cat,"General")) return GeneralOptions_Number ; - else if(!strcmp(cat,"Geometry")) return GeometryOptions_Number ; - else if(!strcmp(cat,"Mesh")) return MeshOptions_Number ; - else if(!strcmp(cat,"Solver")) return SolverOptions_Number ; - else if(!strcmp(cat,"PostProcessing")) return PostProcessingOptions_Number ; - else if(!strcmp(cat,"View")) return ViewOptions_Number ; - else if(!strcmp(cat,"Print")) return PrintOptions_Number ; - else return NULL ; +StringXNumber *Get_NumberOptionCategory(char *cat) +{ + if(!strcmp(cat, "General")) + return GeneralOptions_Number; + else if(!strcmp(cat, "Geometry")) + return GeometryOptions_Number; + else if(!strcmp(cat, "Mesh")) + return MeshOptions_Number; + else if(!strcmp(cat, "Solver")) + return SolverOptions_Number; + else if(!strcmp(cat, "PostProcessing")) + return PostProcessingOptions_Number; + else if(!strcmp(cat, "View")) + return ViewOptions_Number; + else if(!strcmp(cat, "Print")) + return PrintOptions_Number; + else + return NULL; } -void Set_DefaultNumberOptions(int num, StringXNumber s[]){ +void Set_DefaultNumberOptions(int num, StringXNumber s[]) +{ int i = 0; - while(s[i].str){ - s[i].function(num, GMSH_SET, s[i].def) ; + while(s[i].str) { + s[i].function(num, GMSH_SET, s[i].def); i++; } } -void Set_NumberOptions_GUI(int num, StringXNumber s[]){ +void Set_NumberOptions_GUI(int num, StringXNumber s[]) +{ int i = 0; - while(s[i].str){ - s[i].function(num, GMSH_GUI, 0) ; - i++ ; + while(s[i].str) { + s[i].function(num, GMSH_GUI, 0); + i++; } } -void * Get_NumberOption(char *str, StringXNumber s[]){ +void *Get_NumberOption(char *str, StringXNumber s[]) +{ int i = 0; - while ((s[i].str != NULL) && (strcmp(s[i].str, str))) i++ ; + while((s[i].str != NULL) && (strcmp(s[i].str, str))) + i++; if(!s[i].str) return NULL; - else{ - return (void*)s[i].function; + else { + return (void *)s[i].function; } } -void Print_NumberOptions(int num, int level, StringXNumber s[], char *prefix, FILE *file){ +void Print_NumberOptions(int num, int level, StringXNumber s[], char *prefix, + FILE * file) +{ int i = 0; char tmp[1024]; - while(s[i].str){ - if(s[i].level & level){ - sprintf(tmp, "%s%s = %.16g; // %s", prefix, - s[i].str, s[i].function(num, GMSH_GET, 0), s[i].help); - if(file) fprintf(file, "%s\n", tmp); else Msg(DIRECT, tmp); + while(s[i].str) { + if(s[i].level & level) { + sprintf(tmp, "%s%s = %.16g; // %s", prefix, + s[i].str, s[i].function(num, GMSH_GET, 0), s[i].help); + if(file) + fprintf(file, "%s\n", tmp); + else + Msg(DIRECT, tmp); } i++; } @@ -389,84 +440,103 @@ void Print_NumberOptions(int num, int level, StringXNumber s[], char *prefix, FI // General routines for color options -StringXColor * Get_ColorOptionCategory(char * cat){ - if (!strcmp(cat,"General")) return GeneralOptions_Color ; - else if(!strcmp(cat,"Geometry")) return GeometryOptions_Color ; - else if(!strcmp(cat,"Mesh")) return MeshOptions_Color ; - else if(!strcmp(cat,"Solver")) return SolverOptions_Color ; - else if(!strcmp(cat,"PostProcessing")) return PostProcessingOptions_Color ; - else if(!strcmp(cat,"View")) return ViewOptions_Color ; - else if(!strcmp(cat,"Print")) return PrintOptions_Color ; - else return NULL ; +StringXColor *Get_ColorOptionCategory(char *cat) +{ + if(!strcmp(cat, "General")) + return GeneralOptions_Color; + else if(!strcmp(cat, "Geometry")) + return GeometryOptions_Color; + else if(!strcmp(cat, "Mesh")) + return MeshOptions_Color; + else if(!strcmp(cat, "Solver")) + return SolverOptions_Color; + else if(!strcmp(cat, "PostProcessing")) + return PostProcessingOptions_Color; + else if(!strcmp(cat, "View")) + return ViewOptions_Color; + else if(!strcmp(cat, "Print")) + return PrintOptions_Color; + else + return NULL; } -void Set_DefaultColorOptions(int num, StringXColor s[], int scheme){ +void Set_DefaultColorOptions(int num, StringXColor s[], int scheme) +{ int i = 0; - switch(scheme){ - case 0 : - while(s[i].str){ - s[i].function(num, GMSH_SET, s[i].def1) ; + switch (scheme) { + case 0: + while(s[i].str) { + s[i].function(num, GMSH_SET, s[i].def1); i++; } break; - case 1 : - while(s[i].str){ - s[i].function(num, GMSH_SET, s[i].def2) ; + case 1: + while(s[i].str) { + s[i].function(num, GMSH_SET, s[i].def2); i++; } break; - case 2 : - while(s[i].str){ - s[i].function(num, GMSH_SET, s[i].def3) ; + case 2: + while(s[i].str) { + s[i].function(num, GMSH_SET, s[i].def3); i++; } break; } } -void Set_ColorOptions_GUI(int num, StringXColor s[]){ +void Set_ColorOptions_GUI(int num, StringXColor s[]) +{ int i = 0; - while(s[i].str){ - s[i].function(num, GMSH_GUI, 0) ; + while(s[i].str) { + s[i].function(num, GMSH_GUI, 0); i++; } } -void * Get_ColorOption(char *str, StringXColor s[]) { +void *Get_ColorOption(char *str, StringXColor s[]) +{ int i = 0; - while ((s[i].str != NULL) && (strcmp(s[i].str, str))) i++ ; + while((s[i].str != NULL) && (strcmp(s[i].str, str))) + i++; if(!s[i].str) return NULL; else - return (void*)s[i].function; + return (void *)s[i].function; } -void Print_ColorOptions(int num, int level, StringXColor s[], char *prefix, FILE *file){ +void Print_ColorOptions(int num, int level, StringXColor s[], char *prefix, + FILE * file) +{ int i = 0; char tmp[1024]; - while(s[i].str){ - if(s[i].level & level){ - sprintf(tmp, "%sColor.%s = {%d,%d,%d}; // %s", - prefix, s[i].str, - UNPACK_RED (s[i].function(num, GMSH_GET, 0)), - UNPACK_GREEN(s[i].function(num, GMSH_GET, 0)), - UNPACK_BLUE (s[i].function(num, GMSH_GET, 0)), - s[i].help); - if(file) fprintf(file, "%s\n", tmp); else Msg(DIRECT, tmp); + while(s[i].str) { + if(s[i].level & level) { + sprintf(tmp, "%sColor.%s = {%d,%d,%d}; // %s", + prefix, s[i].str, + UNPACK_RED(s[i].function(num, GMSH_GET, 0)), + UNPACK_GREEN(s[i].function(num, GMSH_GET, 0)), + UNPACK_BLUE(s[i].function(num, GMSH_GET, 0)), s[i].help); + if(file) + fprintf(file, "%s\n", tmp); + else + Msg(DIRECT, tmp); } i++; } } -int Get_ColorForString(StringX4Int SX4I[], int alpha, - char * str, int * FlagError) { - int i = 0 ; - while ((SX4I[i].str != NULL) && (strcmp(SX4I[i].str, str))) i++ ; - *FlagError = (SX4I[i].str == NULL)? 1 : 0 ; +int Get_ColorForString(StringX4Int SX4I[], int alpha, + char *str, int *FlagError) +{ + int i = 0; + while((SX4I[i].str != NULL) && (strcmp(SX4I[i].str, str))) + i++; + *FlagError = (SX4I[i].str == NULL) ? 1 : 0; if(alpha > 0) - return PACK_COLOR(SX4I[i].int1,SX4I[i].int2,SX4I[i].int3,alpha) ; + return PACK_COLOR(SX4I[i].int1, SX4I[i].int2, SX4I[i].int3, alpha); else - return PACK_COLOR(SX4I[i].int1,SX4I[i].int2,SX4I[i].int3,SX4I[i].int4) ; + return PACK_COLOR(SX4I[i].int1, SX4I[i].int2, SX4I[i].int3, SX4I[i].int4); } @@ -486,44 +556,59 @@ int Get_ColorForString(StringX4Int SX4I[], int alpha, } \ } -char * opt_general_display(OPT_ARGS_STR){ - if(action & GMSH_SET) CTX.display = val; +char *opt_general_display(OPT_ARGS_STR) +{ + if(action & GMSH_SET) + CTX.display = val; return CTX.display; } -char * opt_general_default_filename(OPT_ARGS_STR){ - if(action & GMSH_SET) CTX.default_filename = val; + +char *opt_general_default_filename(OPT_ARGS_STR) +{ + if(action & GMSH_SET) + CTX.default_filename = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) WID->gen_input[0]->value(CTX.default_filename); #endif return CTX.default_filename; } -char * opt_general_tmp_filename(OPT_ARGS_STR){ - if(action & GMSH_SET) CTX.tmp_filename = val; + +char *opt_general_tmp_filename(OPT_ARGS_STR) +{ + if(action & GMSH_SET) + CTX.tmp_filename = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) WID->gen_input[1]->value(CTX.tmp_filename); #endif return CTX.tmp_filename; } -char * opt_general_error_filename(OPT_ARGS_STR){ - if(action & GMSH_SET) CTX.error_filename = val; + +char *opt_general_error_filename(OPT_ARGS_STR) +{ + if(action & GMSH_SET) + CTX.error_filename = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) WID->gen_input[2]->value(CTX.error_filename); #endif return CTX.error_filename; } -char * opt_general_session_filename(OPT_ARGS_STR){ - if(action & GMSH_SET){ + +char *opt_general_session_filename(OPT_ARGS_STR) +{ + if(action & GMSH_SET) { CTX.session_filename = val; strcpy(CTX.sessionrc_filename, CTX.home_dir); strcat(CTX.sessionrc_filename, CTX.session_filename); } return CTX.session_filename; } -char * opt_general_options_filename(OPT_ARGS_STR){ - if(action & GMSH_SET){ + +char *opt_general_options_filename(OPT_ARGS_STR) +{ + if(action & GMSH_SET) { CTX.options_filename = val; strcpy(CTX.optionsrc_filename, CTX.home_dir); strcat(CTX.optionsrc_filename, CTX.options_filename); @@ -534,22 +619,30 @@ char * opt_general_options_filename(OPT_ARGS_STR){ #endif return CTX.options_filename; } -char * opt_general_editor(OPT_ARGS_STR){ - if(action & GMSH_SET) CTX.editor = val; + +char *opt_general_editor(OPT_ARGS_STR) +{ + if(action & GMSH_SET) + CTX.editor = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) WID->gen_input[4]->value(CTX.editor); #endif return CTX.editor; } -char * opt_general_theme(OPT_ARGS_STR){ - if(action & GMSH_SET) CTX.theme = val; + +char *opt_general_theme(OPT_ARGS_STR) +{ + if(action & GMSH_SET) + CTX.theme = val; return CTX.theme; } -char * opt_solver_name(OPT_ARGS_STR){ +char *opt_solver_name(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].name, val); + if(action & GMSH_SET) + strcpy(SINFO[num].name, val); if(WID && (action & GMSH_GUI)) WID->solver[num].window->label(SINFO[num].name); return SINFO[num].name; @@ -557,15 +650,37 @@ char * opt_solver_name(OPT_ARGS_STR){ return "undefined"; #endif } -char * opt_solver_name0(OPT_ARGS_STR){ return opt_solver_name(0,action,val); } -char * opt_solver_name1(OPT_ARGS_STR){ return opt_solver_name(1,action,val); } -char * opt_solver_name2(OPT_ARGS_STR){ return opt_solver_name(2,action,val); } -char * opt_solver_name3(OPT_ARGS_STR){ return opt_solver_name(3,action,val); } -char * opt_solver_name4(OPT_ARGS_STR){ return opt_solver_name(4,action,val); } -char * opt_solver_executable(OPT_ARGS_STR){ +char *opt_solver_name0(OPT_ARGS_STR) +{ + return opt_solver_name(0, action, val); +} + +char *opt_solver_name1(OPT_ARGS_STR) +{ + return opt_solver_name(1, action, val); +} + +char *opt_solver_name2(OPT_ARGS_STR) +{ + return opt_solver_name(2, action, val); +} + +char *opt_solver_name3(OPT_ARGS_STR) +{ + return opt_solver_name(3, action, val); +} + +char *opt_solver_name4(OPT_ARGS_STR) +{ + return opt_solver_name(4, action, val); +} + +char *opt_solver_executable(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].executable_name, val); + if(action & GMSH_SET) + strcpy(SINFO[num].executable_name, val); if(WID && (action & GMSH_GUI)) WID->solver[num].input[2]->value(SINFO[num].executable_name); return SINFO[num].executable_name; @@ -573,57 +688,145 @@ char * opt_solver_executable(OPT_ARGS_STR){ return "undefined"; #endif } -char * opt_solver_executable0(OPT_ARGS_STR){ return opt_solver_executable(0,action,val); } -char * opt_solver_executable1(OPT_ARGS_STR){ return opt_solver_executable(1,action,val); } -char * opt_solver_executable2(OPT_ARGS_STR){ return opt_solver_executable(2,action,val); } -char * opt_solver_executable3(OPT_ARGS_STR){ return opt_solver_executable(3,action,val); } -char * opt_solver_executable4(OPT_ARGS_STR){ return opt_solver_executable(4,action,val); } -char * opt_solver_help(OPT_ARGS_STR){ +char *opt_solver_executable0(OPT_ARGS_STR) +{ + return opt_solver_executable(0, action, val); +} + +char *opt_solver_executable1(OPT_ARGS_STR) +{ + return opt_solver_executable(1, action, val); +} + +char *opt_solver_executable2(OPT_ARGS_STR) +{ + return opt_solver_executable(2, action, val); +} + +char *opt_solver_executable3(OPT_ARGS_STR) +{ + return opt_solver_executable(3, action, val); +} + +char *opt_solver_executable4(OPT_ARGS_STR) +{ + return opt_solver_executable(4, action, val); +} + +char *opt_solver_help(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) SINFO[num].help = val; + if(action & GMSH_SET) + SINFO[num].help = val; return SINFO[num].help; #else return "undefined"; #endif } -char * opt_solver_help0(OPT_ARGS_STR){ return opt_solver_help(0,action,val); } -char * opt_solver_help1(OPT_ARGS_STR){ return opt_solver_help(1,action,val); } -char * opt_solver_help2(OPT_ARGS_STR){ return opt_solver_help(2,action,val); } -char * opt_solver_help3(OPT_ARGS_STR){ return opt_solver_help(3,action,val); } -char * opt_solver_help4(OPT_ARGS_STR){ return opt_solver_help(4,action,val); } -char * opt_solver_extension(OPT_ARGS_STR){ +char *opt_solver_help0(OPT_ARGS_STR) +{ + return opt_solver_help(0, action, val); +} + +char *opt_solver_help1(OPT_ARGS_STR) +{ + return opt_solver_help(1, action, val); +} + +char *opt_solver_help2(OPT_ARGS_STR) +{ + return opt_solver_help(2, action, val); +} + +char *opt_solver_help3(OPT_ARGS_STR) +{ + return opt_solver_help(3, action, val); +} + +char *opt_solver_help4(OPT_ARGS_STR) +{ + return opt_solver_help(4, action, val); +} + +char *opt_solver_extension(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].extension, val); + if(action & GMSH_SET) + strcpy(SINFO[num].extension, val); return SINFO[num].extension; #else return "undefined"; #endif } -char * opt_solver_extension0(OPT_ARGS_STR){ return opt_solver_extension(0,action,val); } -char * opt_solver_extension1(OPT_ARGS_STR){ return opt_solver_extension(1,action,val); } -char * opt_solver_extension2(OPT_ARGS_STR){ return opt_solver_extension(2,action,val); } -char * opt_solver_extension3(OPT_ARGS_STR){ return opt_solver_extension(3,action,val); } -char * opt_solver_extension4(OPT_ARGS_STR){ return opt_solver_extension(4,action,val); } -char * opt_solver_mesh_name(OPT_ARGS_STR){ +char *opt_solver_extension0(OPT_ARGS_STR) +{ + return opt_solver_extension(0, action, val); +} + +char *opt_solver_extension1(OPT_ARGS_STR) +{ + return opt_solver_extension(1, action, val); +} + +char *opt_solver_extension2(OPT_ARGS_STR) +{ + return opt_solver_extension(2, action, val); +} + +char *opt_solver_extension3(OPT_ARGS_STR) +{ + return opt_solver_extension(3, action, val); +} + +char *opt_solver_extension4(OPT_ARGS_STR) +{ + return opt_solver_extension(4, action, val); +} + +char *opt_solver_mesh_name(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].mesh_name, val); + if(action & GMSH_SET) + strcpy(SINFO[num].mesh_name, val); return SINFO[num].mesh_name; #else return "undefined"; #endif } -char * opt_solver_mesh_name0(OPT_ARGS_STR){ return opt_solver_mesh_name(0,action,val); } -char * opt_solver_mesh_name1(OPT_ARGS_STR){ return opt_solver_mesh_name(1,action,val); } -char * opt_solver_mesh_name2(OPT_ARGS_STR){ return opt_solver_mesh_name(2,action,val); } -char * opt_solver_mesh_name3(OPT_ARGS_STR){ return opt_solver_mesh_name(3,action,val); } -char * opt_solver_mesh_name4(OPT_ARGS_STR){ return opt_solver_mesh_name(4,action,val); } -char * opt_solver_mesh_command(OPT_ARGS_STR){ +char *opt_solver_mesh_name0(OPT_ARGS_STR) +{ + return opt_solver_mesh_name(0, action, val); +} + +char *opt_solver_mesh_name1(OPT_ARGS_STR) +{ + return opt_solver_mesh_name(1, action, val); +} + +char *opt_solver_mesh_name2(OPT_ARGS_STR) +{ + return opt_solver_mesh_name(2, action, val); +} + +char *opt_solver_mesh_name3(OPT_ARGS_STR) +{ + return opt_solver_mesh_name(3, action, val); +} + +char *opt_solver_mesh_name4(OPT_ARGS_STR) +{ + return opt_solver_mesh_name(4, action, val); +} + +char *opt_solver_mesh_command(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].mesh_command, val); + if(action & GMSH_SET) + strcpy(SINFO[num].mesh_command, val); if(WID && (action & GMSH_GUI)) WID->solver[num].input[1]->value(SINFO[num].mesh_name); return SINFO[num].mesh_command; @@ -631,258 +834,633 @@ char * opt_solver_mesh_command(OPT_ARGS_STR){ return "undefined"; #endif } -char * opt_solver_mesh_command0(OPT_ARGS_STR){ return opt_solver_mesh_command(0,action,val); } -char * opt_solver_mesh_command1(OPT_ARGS_STR){ return opt_solver_mesh_command(1,action,val); } -char * opt_solver_mesh_command2(OPT_ARGS_STR){ return opt_solver_mesh_command(2,action,val); } -char * opt_solver_mesh_command3(OPT_ARGS_STR){ return opt_solver_mesh_command(3,action,val); } -char * opt_solver_mesh_command4(OPT_ARGS_STR){ return opt_solver_mesh_command(4,action,val); } -char * opt_solver_option_command(OPT_ARGS_STR){ +char *opt_solver_mesh_command0(OPT_ARGS_STR) +{ + return opt_solver_mesh_command(0, action, val); +} + +char *opt_solver_mesh_command1(OPT_ARGS_STR) +{ + return opt_solver_mesh_command(1, action, val); +} + +char *opt_solver_mesh_command2(OPT_ARGS_STR) +{ + return opt_solver_mesh_command(2, action, val); +} + +char *opt_solver_mesh_command3(OPT_ARGS_STR) +{ + return opt_solver_mesh_command(3, action, val); +} + +char *opt_solver_mesh_command4(OPT_ARGS_STR) +{ + return opt_solver_mesh_command(4, action, val); +} + +char *opt_solver_option_command(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].option_command, val); + if(action & GMSH_SET) + strcpy(SINFO[num].option_command, val); return SINFO[num].option_command; #else return "undefined"; #endif } -char * opt_solver_option_command0(OPT_ARGS_STR){ return opt_solver_option_command(0,action,val); } -char * opt_solver_option_command1(OPT_ARGS_STR){ return opt_solver_option_command(1,action,val); } -char * opt_solver_option_command2(OPT_ARGS_STR){ return opt_solver_option_command(2,action,val); } -char * opt_solver_option_command3(OPT_ARGS_STR){ return opt_solver_option_command(3,action,val); } -char * opt_solver_option_command4(OPT_ARGS_STR){ return opt_solver_option_command(4,action,val); } -char * opt_solver_first_option(OPT_ARGS_STR){ +char *opt_solver_option_command0(OPT_ARGS_STR) +{ + return opt_solver_option_command(0, action, val); +} + +char *opt_solver_option_command1(OPT_ARGS_STR) +{ + return opt_solver_option_command(1, action, val); +} + +char *opt_solver_option_command2(OPT_ARGS_STR) +{ + return opt_solver_option_command(2, action, val); +} + +char *opt_solver_option_command3(OPT_ARGS_STR) +{ + return opt_solver_option_command(3, action, val); +} + +char *opt_solver_option_command4(OPT_ARGS_STR) +{ + return opt_solver_option_command(4, action, val); +} + +char *opt_solver_first_option(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].option_name[0], val); + if(action & GMSH_SET) + strcpy(SINFO[num].option_name[0], val); return SINFO[num].option_name[0]; #else return "undefined"; #endif } -char * opt_solver_first_option0(OPT_ARGS_STR){ return opt_solver_first_option(0,action,val); } -char * opt_solver_first_option1(OPT_ARGS_STR){ return opt_solver_first_option(1,action,val); } -char * opt_solver_first_option2(OPT_ARGS_STR){ return opt_solver_first_option(2,action,val); } -char * opt_solver_first_option3(OPT_ARGS_STR){ return opt_solver_first_option(3,action,val); } -char * opt_solver_first_option4(OPT_ARGS_STR){ return opt_solver_first_option(4,action,val); } -char * opt_solver_second_option(OPT_ARGS_STR){ +char *opt_solver_first_option0(OPT_ARGS_STR) +{ + return opt_solver_first_option(0, action, val); +} + +char *opt_solver_first_option1(OPT_ARGS_STR) +{ + return opt_solver_first_option(1, action, val); +} + +char *opt_solver_first_option2(OPT_ARGS_STR) +{ + return opt_solver_first_option(2, action, val); +} + +char *opt_solver_first_option3(OPT_ARGS_STR) +{ + return opt_solver_first_option(3, action, val); +} + +char *opt_solver_first_option4(OPT_ARGS_STR) +{ + return opt_solver_first_option(4, action, val); +} + +char *opt_solver_second_option(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].option_name[1], val); + if(action & GMSH_SET) + strcpy(SINFO[num].option_name[1], val); return SINFO[num].option_name[1]; #else return "undefined"; #endif } -char * opt_solver_second_option0(OPT_ARGS_STR){ return opt_solver_second_option(0,action,val); } -char * opt_solver_second_option1(OPT_ARGS_STR){ return opt_solver_second_option(1,action,val); } -char * opt_solver_second_option2(OPT_ARGS_STR){ return opt_solver_second_option(2,action,val); } -char * opt_solver_second_option3(OPT_ARGS_STR){ return opt_solver_second_option(3,action,val); } -char * opt_solver_second_option4(OPT_ARGS_STR){ return opt_solver_second_option(4,action,val); } -char * opt_solver_third_option(OPT_ARGS_STR){ +char *opt_solver_second_option0(OPT_ARGS_STR) +{ + return opt_solver_second_option(0, action, val); +} + +char *opt_solver_second_option1(OPT_ARGS_STR) +{ + return opt_solver_second_option(1, action, val); +} + +char *opt_solver_second_option2(OPT_ARGS_STR) +{ + return opt_solver_second_option(2, action, val); +} + +char *opt_solver_second_option3(OPT_ARGS_STR) +{ + return opt_solver_second_option(3, action, val); +} + +char *opt_solver_second_option4(OPT_ARGS_STR) +{ + return opt_solver_second_option(4, action, val); +} + +char *opt_solver_third_option(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].option_name[2], val); + if(action & GMSH_SET) + strcpy(SINFO[num].option_name[2], val); return SINFO[num].option_name[2]; #else return "undefined"; #endif } -char * opt_solver_third_option0(OPT_ARGS_STR){ return opt_solver_third_option(0,action,val); } -char * opt_solver_third_option1(OPT_ARGS_STR){ return opt_solver_third_option(1,action,val); } -char * opt_solver_third_option2(OPT_ARGS_STR){ return opt_solver_third_option(2,action,val); } -char * opt_solver_third_option3(OPT_ARGS_STR){ return opt_solver_third_option(3,action,val); } -char * opt_solver_third_option4(OPT_ARGS_STR){ return opt_solver_third_option(4,action,val); } -char * opt_solver_fourth_option(OPT_ARGS_STR){ +char *opt_solver_third_option0(OPT_ARGS_STR) +{ + return opt_solver_third_option(0, action, val); +} + +char *opt_solver_third_option1(OPT_ARGS_STR) +{ + return opt_solver_third_option(1, action, val); +} + +char *opt_solver_third_option2(OPT_ARGS_STR) +{ + return opt_solver_third_option(2, action, val); +} + +char *opt_solver_third_option3(OPT_ARGS_STR) +{ + return opt_solver_third_option(3, action, val); +} + +char *opt_solver_third_option4(OPT_ARGS_STR) +{ + return opt_solver_third_option(4, action, val); +} + +char *opt_solver_fourth_option(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].option_name[3], val); + if(action & GMSH_SET) + strcpy(SINFO[num].option_name[3], val); return SINFO[num].option_name[3]; #else return "undefined"; #endif } -char * opt_solver_fourth_option0(OPT_ARGS_STR){ return opt_solver_fourth_option(0,action,val); } -char * opt_solver_fourth_option1(OPT_ARGS_STR){ return opt_solver_fourth_option(1,action,val); } -char * opt_solver_fourth_option2(OPT_ARGS_STR){ return opt_solver_fourth_option(2,action,val); } -char * opt_solver_fourth_option3(OPT_ARGS_STR){ return opt_solver_fourth_option(3,action,val); } -char * opt_solver_fourth_option4(OPT_ARGS_STR){ return opt_solver_fourth_option(4,action,val); } -char * opt_solver_fifth_option(OPT_ARGS_STR){ +char *opt_solver_fourth_option0(OPT_ARGS_STR) +{ + return opt_solver_fourth_option(0, action, val); +} + +char *opt_solver_fourth_option1(OPT_ARGS_STR) +{ + return opt_solver_fourth_option(1, action, val); +} + +char *opt_solver_fourth_option2(OPT_ARGS_STR) +{ + return opt_solver_fourth_option(2, action, val); +} + +char *opt_solver_fourth_option3(OPT_ARGS_STR) +{ + return opt_solver_fourth_option(3, action, val); +} + +char *opt_solver_fourth_option4(OPT_ARGS_STR) +{ + return opt_solver_fourth_option(4, action, val); +} + +char *opt_solver_fifth_option(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].option_name[4], val); + if(action & GMSH_SET) + strcpy(SINFO[num].option_name[4], val); return SINFO[num].option_name[4]; #else return "undefined"; #endif } -char * opt_solver_fifth_option0(OPT_ARGS_STR){ return opt_solver_fifth_option(0,action,val); } -char * opt_solver_fifth_option1(OPT_ARGS_STR){ return opt_solver_fifth_option(1,action,val); } -char * opt_solver_fifth_option2(OPT_ARGS_STR){ return opt_solver_fifth_option(2,action,val); } -char * opt_solver_fifth_option3(OPT_ARGS_STR){ return opt_solver_fifth_option(3,action,val); } -char * opt_solver_fifth_option4(OPT_ARGS_STR){ return opt_solver_fifth_option(4,action,val); } -char * opt_solver_first_button(OPT_ARGS_STR){ +char *opt_solver_fifth_option0(OPT_ARGS_STR) +{ + return opt_solver_fifth_option(0, action, val); +} + +char *opt_solver_fifth_option1(OPT_ARGS_STR) +{ + return opt_solver_fifth_option(1, action, val); +} + +char *opt_solver_fifth_option2(OPT_ARGS_STR) +{ + return opt_solver_fifth_option(2, action, val); +} + +char *opt_solver_fifth_option3(OPT_ARGS_STR) +{ + return opt_solver_fifth_option(3, action, val); +} + +char *opt_solver_fifth_option4(OPT_ARGS_STR) +{ + return opt_solver_fifth_option(4, action, val); +} + +char *opt_solver_first_button(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].button_name[0], val); + if(action & GMSH_SET) + strcpy(SINFO[num].button_name[0], val); return SINFO[num].button_name[0]; #else return "undefined"; #endif } -char * opt_solver_first_button0(OPT_ARGS_STR){ return opt_solver_first_button(0,action,val); } -char * opt_solver_first_button1(OPT_ARGS_STR){ return opt_solver_first_button(1,action,val); } -char * opt_solver_first_button2(OPT_ARGS_STR){ return opt_solver_first_button(2,action,val); } -char * opt_solver_first_button3(OPT_ARGS_STR){ return opt_solver_first_button(3,action,val); } -char * opt_solver_first_button4(OPT_ARGS_STR){ return opt_solver_first_button(4,action,val); } -char * opt_solver_first_button_command(OPT_ARGS_STR){ +char *opt_solver_first_button0(OPT_ARGS_STR) +{ + return opt_solver_first_button(0, action, val); +} + +char *opt_solver_first_button1(OPT_ARGS_STR) +{ + return opt_solver_first_button(1, action, val); +} + +char *opt_solver_first_button2(OPT_ARGS_STR) +{ + return opt_solver_first_button(2, action, val); +} + +char *opt_solver_first_button3(OPT_ARGS_STR) +{ + return opt_solver_first_button(3, action, val); +} + +char *opt_solver_first_button4(OPT_ARGS_STR) +{ + return opt_solver_first_button(4, action, val); +} + +char *opt_solver_first_button_command(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].button_command[0], val); + if(action & GMSH_SET) + strcpy(SINFO[num].button_command[0], val); return SINFO[num].button_command[0]; #else return "undefined"; #endif } -char * opt_solver_first_button_command0(OPT_ARGS_STR){ return opt_solver_first_button_command(0,action,val); } -char * opt_solver_first_button_command1(OPT_ARGS_STR){ return opt_solver_first_button_command(1,action,val); } -char * opt_solver_first_button_command2(OPT_ARGS_STR){ return opt_solver_first_button_command(2,action,val); } -char * opt_solver_first_button_command3(OPT_ARGS_STR){ return opt_solver_first_button_command(3,action,val); } -char * opt_solver_first_button_command4(OPT_ARGS_STR){ return opt_solver_first_button_command(4,action,val); } -char * opt_solver_second_button(OPT_ARGS_STR){ +char *opt_solver_first_button_command0(OPT_ARGS_STR) +{ + return opt_solver_first_button_command(0, action, val); +} + +char *opt_solver_first_button_command1(OPT_ARGS_STR) +{ + return opt_solver_first_button_command(1, action, val); +} + +char *opt_solver_first_button_command2(OPT_ARGS_STR) +{ + return opt_solver_first_button_command(2, action, val); +} + +char *opt_solver_first_button_command3(OPT_ARGS_STR) +{ + return opt_solver_first_button_command(3, action, val); +} + +char *opt_solver_first_button_command4(OPT_ARGS_STR) +{ + return opt_solver_first_button_command(4, action, val); +} + +char *opt_solver_second_button(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].button_name[1], val); + if(action & GMSH_SET) + strcpy(SINFO[num].button_name[1], val); return SINFO[num].button_name[1]; #else return "undefined"; #endif } -char * opt_solver_second_button0(OPT_ARGS_STR){ return opt_solver_second_button(0,action,val); } -char * opt_solver_second_button1(OPT_ARGS_STR){ return opt_solver_second_button(1,action,val); } -char * opt_solver_second_button2(OPT_ARGS_STR){ return opt_solver_second_button(2,action,val); } -char * opt_solver_second_button3(OPT_ARGS_STR){ return opt_solver_second_button(3,action,val); } -char * opt_solver_second_button4(OPT_ARGS_STR){ return opt_solver_second_button(4,action,val); } -char * opt_solver_second_button_command(OPT_ARGS_STR){ +char *opt_solver_second_button0(OPT_ARGS_STR) +{ + return opt_solver_second_button(0, action, val); +} + +char *opt_solver_second_button1(OPT_ARGS_STR) +{ + return opt_solver_second_button(1, action, val); +} + +char *opt_solver_second_button2(OPT_ARGS_STR) +{ + return opt_solver_second_button(2, action, val); +} + +char *opt_solver_second_button3(OPT_ARGS_STR) +{ + return opt_solver_second_button(3, action, val); +} + +char *opt_solver_second_button4(OPT_ARGS_STR) +{ + return opt_solver_second_button(4, action, val); +} + +char *opt_solver_second_button_command(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].button_command[1], val); + if(action & GMSH_SET) + strcpy(SINFO[num].button_command[1], val); return SINFO[num].button_command[1]; #else return "undefined"; #endif } -char * opt_solver_second_button_command0(OPT_ARGS_STR){ return opt_solver_second_button_command(0,action,val); } -char * opt_solver_second_button_command1(OPT_ARGS_STR){ return opt_solver_second_button_command(1,action,val); } -char * opt_solver_second_button_command2(OPT_ARGS_STR){ return opt_solver_second_button_command(2,action,val); } -char * opt_solver_second_button_command3(OPT_ARGS_STR){ return opt_solver_second_button_command(3,action,val); } -char * opt_solver_second_button_command4(OPT_ARGS_STR){ return opt_solver_second_button_command(4,action,val); } -char * opt_solver_third_button(OPT_ARGS_STR){ +char *opt_solver_second_button_command0(OPT_ARGS_STR) +{ + return opt_solver_second_button_command(0, action, val); +} + +char *opt_solver_second_button_command1(OPT_ARGS_STR) +{ + return opt_solver_second_button_command(1, action, val); +} + +char *opt_solver_second_button_command2(OPT_ARGS_STR) +{ + return opt_solver_second_button_command(2, action, val); +} + +char *opt_solver_second_button_command3(OPT_ARGS_STR) +{ + return opt_solver_second_button_command(3, action, val); +} + +char *opt_solver_second_button_command4(OPT_ARGS_STR) +{ + return opt_solver_second_button_command(4, action, val); +} + +char *opt_solver_third_button(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].button_name[2], val); + if(action & GMSH_SET) + strcpy(SINFO[num].button_name[2], val); return SINFO[num].button_name[2]; #else return "undefined"; #endif } -char * opt_solver_third_button0(OPT_ARGS_STR){ return opt_solver_third_button(0,action,val); } -char * opt_solver_third_button1(OPT_ARGS_STR){ return opt_solver_third_button(1,action,val); } -char * opt_solver_third_button2(OPT_ARGS_STR){ return opt_solver_third_button(2,action,val); } -char * opt_solver_third_button3(OPT_ARGS_STR){ return opt_solver_third_button(3,action,val); } -char * opt_solver_third_button4(OPT_ARGS_STR){ return opt_solver_third_button(4,action,val); } -char * opt_solver_third_button_command(OPT_ARGS_STR){ +char *opt_solver_third_button0(OPT_ARGS_STR) +{ + return opt_solver_third_button(0, action, val); +} + +char *opt_solver_third_button1(OPT_ARGS_STR) +{ + return opt_solver_third_button(1, action, val); +} + +char *opt_solver_third_button2(OPT_ARGS_STR) +{ + return opt_solver_third_button(2, action, val); +} + +char *opt_solver_third_button3(OPT_ARGS_STR) +{ + return opt_solver_third_button(3, action, val); +} + +char *opt_solver_third_button4(OPT_ARGS_STR) +{ + return opt_solver_third_button(4, action, val); +} + +char *opt_solver_third_button_command(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].button_command[2], val); + if(action & GMSH_SET) + strcpy(SINFO[num].button_command[2], val); return SINFO[num].button_command[2]; #else return "undefined"; #endif } -char * opt_solver_third_button_command0(OPT_ARGS_STR){ return opt_solver_third_button_command(0,action,val); } -char * opt_solver_third_button_command1(OPT_ARGS_STR){ return opt_solver_third_button_command(1,action,val); } -char * opt_solver_third_button_command2(OPT_ARGS_STR){ return opt_solver_third_button_command(2,action,val); } -char * opt_solver_third_button_command3(OPT_ARGS_STR){ return opt_solver_third_button_command(3,action,val); } -char * opt_solver_third_button_command4(OPT_ARGS_STR){ return opt_solver_third_button_command(4,action,val); } -char * opt_solver_fourth_button(OPT_ARGS_STR){ +char *opt_solver_third_button_command0(OPT_ARGS_STR) +{ + return opt_solver_third_button_command(0, action, val); +} + +char *opt_solver_third_button_command1(OPT_ARGS_STR) +{ + return opt_solver_third_button_command(1, action, val); +} + +char *opt_solver_third_button_command2(OPT_ARGS_STR) +{ + return opt_solver_third_button_command(2, action, val); +} + +char *opt_solver_third_button_command3(OPT_ARGS_STR) +{ + return opt_solver_third_button_command(3, action, val); +} + +char *opt_solver_third_button_command4(OPT_ARGS_STR) +{ + return opt_solver_third_button_command(4, action, val); +} + +char *opt_solver_fourth_button(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].button_name[3], val); + if(action & GMSH_SET) + strcpy(SINFO[num].button_name[3], val); return SINFO[num].button_name[3]; #else return "undefined"; #endif } -char * opt_solver_fourth_button0(OPT_ARGS_STR){ return opt_solver_fourth_button(0,action,val); } -char * opt_solver_fourth_button1(OPT_ARGS_STR){ return opt_solver_fourth_button(1,action,val); } -char * opt_solver_fourth_button2(OPT_ARGS_STR){ return opt_solver_fourth_button(2,action,val); } -char * opt_solver_fourth_button3(OPT_ARGS_STR){ return opt_solver_fourth_button(3,action,val); } -char * opt_solver_fourth_button4(OPT_ARGS_STR){ return opt_solver_fourth_button(4,action,val); } -char * opt_solver_fourth_button_command(OPT_ARGS_STR){ +char *opt_solver_fourth_button0(OPT_ARGS_STR) +{ + return opt_solver_fourth_button(0, action, val); +} + +char *opt_solver_fourth_button1(OPT_ARGS_STR) +{ + return opt_solver_fourth_button(1, action, val); +} + +char *opt_solver_fourth_button2(OPT_ARGS_STR) +{ + return opt_solver_fourth_button(2, action, val); +} + +char *opt_solver_fourth_button3(OPT_ARGS_STR) +{ + return opt_solver_fourth_button(3, action, val); +} + +char *opt_solver_fourth_button4(OPT_ARGS_STR) +{ + return opt_solver_fourth_button(4, action, val); +} + +char *opt_solver_fourth_button_command(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].button_command[3], val); + if(action & GMSH_SET) + strcpy(SINFO[num].button_command[3], val); return SINFO[num].button_command[3]; #else return "undefined"; #endif } -char * opt_solver_fourth_button_command0(OPT_ARGS_STR){ return opt_solver_fourth_button_command(0,action,val); } -char * opt_solver_fourth_button_command1(OPT_ARGS_STR){ return opt_solver_fourth_button_command(1,action,val); } -char * opt_solver_fourth_button_command2(OPT_ARGS_STR){ return opt_solver_fourth_button_command(2,action,val); } -char * opt_solver_fourth_button_command3(OPT_ARGS_STR){ return opt_solver_fourth_button_command(3,action,val); } -char * opt_solver_fourth_button_command4(OPT_ARGS_STR){ return opt_solver_fourth_button_command(4,action,val); } -char * opt_solver_fifth_button(OPT_ARGS_STR){ +char *opt_solver_fourth_button_command0(OPT_ARGS_STR) +{ + return opt_solver_fourth_button_command(0, action, val); +} + +char *opt_solver_fourth_button_command1(OPT_ARGS_STR) +{ + return opt_solver_fourth_button_command(1, action, val); +} + +char *opt_solver_fourth_button_command2(OPT_ARGS_STR) +{ + return opt_solver_fourth_button_command(2, action, val); +} + +char *opt_solver_fourth_button_command3(OPT_ARGS_STR) +{ + return opt_solver_fourth_button_command(3, action, val); +} + +char *opt_solver_fourth_button_command4(OPT_ARGS_STR) +{ + return opt_solver_fourth_button_command(4, action, val); +} + +char *opt_solver_fifth_button(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].button_name[4], val); + if(action & GMSH_SET) + strcpy(SINFO[num].button_name[4], val); return SINFO[num].button_name[4]; #else return "undefined"; #endif } -char * opt_solver_fifth_button0(OPT_ARGS_STR){ return opt_solver_fifth_button(0,action,val); } -char * opt_solver_fifth_button1(OPT_ARGS_STR){ return opt_solver_fifth_button(1,action,val); } -char * opt_solver_fifth_button2(OPT_ARGS_STR){ return opt_solver_fifth_button(2,action,val); } -char * opt_solver_fifth_button3(OPT_ARGS_STR){ return opt_solver_fifth_button(3,action,val); } -char * opt_solver_fifth_button4(OPT_ARGS_STR){ return opt_solver_fifth_button(4,action,val); } -char * opt_solver_fifth_button_command(OPT_ARGS_STR){ +char *opt_solver_fifth_button0(OPT_ARGS_STR) +{ + return opt_solver_fifth_button(0, action, val); +} + +char *opt_solver_fifth_button1(OPT_ARGS_STR) +{ + return opt_solver_fifth_button(1, action, val); +} + +char *opt_solver_fifth_button2(OPT_ARGS_STR) +{ + return opt_solver_fifth_button(2, action, val); +} + +char *opt_solver_fifth_button3(OPT_ARGS_STR) +{ + return opt_solver_fifth_button(3, action, val); +} + +char *opt_solver_fifth_button4(OPT_ARGS_STR) +{ + return opt_solver_fifth_button(4, action, val); +} + +char *opt_solver_fifth_button_command(OPT_ARGS_STR) +{ #if defined(HAVE_FLTK) - if(action & GMSH_SET) strcpy(SINFO[num].button_command[4], val); + if(action & GMSH_SET) + strcpy(SINFO[num].button_command[4], val); return SINFO[num].button_command[4]; #else return "undefined"; #endif } -char * opt_solver_fifth_button_command0(OPT_ARGS_STR){ return opt_solver_fifth_button_command(0,action,val); } -char * opt_solver_fifth_button_command1(OPT_ARGS_STR){ return opt_solver_fifth_button_command(1,action,val); } -char * opt_solver_fifth_button_command2(OPT_ARGS_STR){ return opt_solver_fifth_button_command(2,action,val); } -char * opt_solver_fifth_button_command3(OPT_ARGS_STR){ return opt_solver_fifth_button_command(3,action,val); } -char * opt_solver_fifth_button_command4(OPT_ARGS_STR){ return opt_solver_fifth_button_command(4,action,val); } +char *opt_solver_fifth_button_command0(OPT_ARGS_STR) +{ + return opt_solver_fifth_button_command(0, action, val); +} + +char *opt_solver_fifth_button_command1(OPT_ARGS_STR) +{ + return opt_solver_fifth_button_command(1, action, val); +} + +char *opt_solver_fifth_button_command2(OPT_ARGS_STR) +{ + return opt_solver_fifth_button_command(2, action, val); +} -char * opt_view_name(OPT_ARGS_STR){ - GET_VIEW(NULL) ; - if(action & GMSH_SET){ +char *opt_solver_fifth_button_command3(OPT_ARGS_STR) +{ + return opt_solver_fifth_button_command(3, action, val); +} + +char *opt_solver_fifth_button_command4(OPT_ARGS_STR) +{ + return opt_solver_fifth_button_command(4, action, val); +} + + +char *opt_view_name(OPT_ARGS_STR) +{ + GET_VIEW(NULL); + if(action & GMSH_SET) { strcpy(v->Name, val); #if defined(HAVE_FLTK) - if(WID && num<NB_BUTT_MAX){ + if(WID && num < NB_BUTT_MAX) { WID->m_toggle_butt[num]->label(v->Name); WID->m_toggle_butt[num]->redraw(); } #endif } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && (num == WID->view_number)){ + if(WID && (action & GMSH_GUI) && (num == WID->view_number)) { WID->view_input[0]->value(v->Name); } #endif return v->Name; } -char * opt_view_format(OPT_ARGS_STR){ - GET_VIEW(NULL) ; - if(action & GMSH_SET){ + +char *opt_view_format(OPT_ARGS_STR) +{ + GET_VIEW(NULL); + if(action & GMSH_SET) { strcpy(v->Format, val); } #if defined(HAVE_FLTK) @@ -891,13 +1469,15 @@ char * opt_view_format(OPT_ARGS_STR){ #endif return v->Format; } -char * opt_view_filename(OPT_ARGS_STR){ - GET_VIEW(NULL) ; - if(action & GMSH_SET){ + +char *opt_view_filename(OPT_ARGS_STR) +{ + GET_VIEW(NULL); + if(action & GMSH_SET) { strcpy(v->FileName, val); #if defined(HAVE_FLTK) #if !((FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION == 0)) - if(WID && num<NB_BUTT_MAX){ + if(WID && num < NB_BUTT_MAX) { WID->m_toggle_butt[num]->tooltip(v->FileName); } #endif @@ -905,9 +1485,11 @@ char * opt_view_filename(OPT_ARGS_STR){ } return v->FileName; } -char * opt_view_abscissa_name(OPT_ARGS_STR){ - GET_VIEW(NULL) ; - if(action & GMSH_SET){ + +char *opt_view_abscissa_name(OPT_ARGS_STR) +{ + GET_VIEW(NULL); + if(action & GMSH_SET) { strcpy(v->AbscissaName, val); } #if defined(HAVE_FLTK) @@ -916,9 +1498,11 @@ char * opt_view_abscissa_name(OPT_ARGS_STR){ #endif return v->AbscissaName; } -char * opt_view_abscissa_format(OPT_ARGS_STR){ - GET_VIEW(NULL) ; - if(action & GMSH_SET){ + +char *opt_view_abscissa_format(OPT_ARGS_STR) +{ + GET_VIEW(NULL); + if(action & GMSH_SET) { strcpy(v->AbscissaFormat, val); } #if defined(HAVE_FLTK) @@ -929,8 +1513,10 @@ char * opt_view_abscissa_format(OPT_ARGS_STR){ } -char * opt_print_eps_font(OPT_ARGS_STR){ - if(action & GMSH_SET) CTX.print.eps_font = val; +char *opt_print_eps_font(OPT_ARGS_STR) +{ + if(action & GMSH_SET) + CTX.print.eps_font = val; return CTX.print.eps_font; } @@ -938,164 +1524,273 @@ char * opt_print_eps_font(OPT_ARGS_STR){ // Numeric option routines -double opt_general_initial_context(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.initial_context = (int)val; +double opt_general_initial_context(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.initial_context = (int)val; return CTX.initial_context; } -double opt_general_fontsize(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.fontsize = (int)val; + +double opt_general_fontsize(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.fontsize = (int)val; return CTX.fontsize; } -double opt_general_graphics_fontsize(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.gl_fontsize = (int)val; + +double opt_general_graphics_fontsize(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.gl_fontsize = (int)val; return CTX.gl_fontsize; } -double opt_general_viewport2(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.viewport[2] = (int)val; + +double opt_general_viewport2(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.viewport[2] = (int)val; return CTX.viewport[2]; } -double opt_general_viewport3(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.viewport[3] = (int)val; + +double opt_general_viewport3(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.viewport[3] = (int)val; return CTX.viewport[3]; } -double opt_general_graphics_position0(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.gl_position[0] = (int)val; + +double opt_general_graphics_position0(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.gl_position[0] = (int)val; return CTX.gl_position[0]; } -double opt_general_graphics_position1(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.gl_position[1] = (int)val; + +double opt_general_graphics_position1(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.gl_position[1] = (int)val; return CTX.gl_position[1]; } -double opt_general_menu_position0(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.position[0] = (int)val; + +double opt_general_menu_position0(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.position[0] = (int)val; return CTX.position[0]; } -double opt_general_menu_position1(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.position[1] = (int)val; + +double opt_general_menu_position1(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.position[1] = (int)val; return CTX.position[1]; } -double opt_general_message_position0(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.msg_position[0] = (int)val; + +double opt_general_message_position0(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.msg_position[0] = (int)val; return CTX.msg_position[0]; } -double opt_general_message_position1(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.msg_position[1] = (int)val; + +double opt_general_message_position1(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.msg_position[1] = (int)val; return CTX.msg_position[1]; } -double opt_general_message_size0(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.msg_size[0] = (int)val; + +double opt_general_message_size0(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.msg_size[0] = (int)val; return CTX.msg_size[0]; } -double opt_general_message_size1(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.msg_size[1] = (int)val; + +double opt_general_message_size1(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.msg_size[1] = (int)val; return CTX.msg_size[1]; } -double opt_general_option_position0(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.opt_position[0] = (int)val; + +double opt_general_option_position0(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.opt_position[0] = (int)val; return CTX.opt_position[0]; } -double opt_general_option_position1(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.opt_position[1] = (int)val; + +double opt_general_option_position1(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.opt_position[1] = (int)val; return CTX.opt_position[1]; } -double opt_general_statistics_position0(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.stat_position[0] = (int)val; + +double opt_general_statistics_position0(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.stat_position[0] = (int)val; return CTX.stat_position[0]; } -double opt_general_statistics_position1(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.stat_position[1] = (int)val; + +double opt_general_statistics_position1(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.stat_position[1] = (int)val; return CTX.stat_position[1]; } -double opt_general_visibility_position0(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.vis_position[0] = (int)val; + +double opt_general_visibility_position0(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.vis_position[0] = (int)val; return CTX.vis_position[0]; } -double opt_general_visibility_position1(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.vis_position[1] = (int)val; + +double opt_general_visibility_position1(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.vis_position[1] = (int)val; return CTX.vis_position[1]; } -double opt_general_center_windows(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.center_windows = (int)val; + +double opt_general_center_windows(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.center_windows = (int)val; return CTX.center_windows; } -double opt_general_session_save(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.session_save = (int)val; + +double opt_general_session_save(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.session_save = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) WID->gen_butt[8]->value(CTX.session_save); #endif return CTX.session_save; } -double opt_general_options_save(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.options_save = (int)val; + +double opt_general_options_save(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.options_save = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) WID->gen_butt[9]->value(CTX.options_save); #endif return CTX.options_save; } -double opt_general_confirm_overwrite(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.confirm_overwrite = (int)val; + +double opt_general_confirm_overwrite(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.confirm_overwrite = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) WID->gen_butt[14]->value(CTX.confirm_overwrite); #endif return CTX.confirm_overwrite; } -double opt_general_rotation0(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.r[0] = val; + +double opt_general_rotation0(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.r[0] = val; return CTX.r[0]; } -double opt_general_rotation1(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.r[1] = val; + +double opt_general_rotation1(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.r[1] = val; return CTX.r[1]; } -double opt_general_rotation2(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.r[2] = val; + +double opt_general_rotation2(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.r[2] = val; return CTX.r[2]; } -double opt_general_quaternion0(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.quaternion[0] = val; + +double opt_general_quaternion0(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.quaternion[0] = val; return CTX.quaternion[0]; } -double opt_general_quaternion1(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.quaternion[1] = val; + +double opt_general_quaternion1(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.quaternion[1] = val; return CTX.quaternion[1]; } -double opt_general_quaternion2(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.quaternion[2] = val; + +double opt_general_quaternion2(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.quaternion[2] = val; return CTX.quaternion[2]; } -double opt_general_quaternion3(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.quaternion[3] = val; + +double opt_general_quaternion3(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.quaternion[3] = val; return CTX.quaternion[3]; } -double opt_general_translation0(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.t[0] = val; + +double opt_general_translation0(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.t[0] = val; return CTX.t[0]; } -double opt_general_translation1(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.t[1] = val; + +double opt_general_translation1(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.t[1] = val; return CTX.t[1]; } -double opt_general_translation2(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.t[2] = val; + +double opt_general_translation2(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.t[2] = val; return CTX.t[2]; } -double opt_general_scale0(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.s[0] = val?val:1.0; + +double opt_general_scale0(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.s[0] = val ? val : 1.0; return CTX.s[0]; } -double opt_general_scale1(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.s[1] = val?val:1.0; + +double opt_general_scale1(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.s[1] = val ? val : 1.0; return CTX.s[1]; } -double opt_general_scale2(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.s[2] = val?val:1.0; + +double opt_general_scale2(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.s[2] = val ? val : 1.0; return CTX.s[2]; } -double opt_general_point_size(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_general_point_size(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.point_size = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1103,8 +1798,10 @@ double opt_general_point_size(OPT_ARGS_NUM){ #endif return CTX.point_size; } -double opt_general_line_width(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_general_line_width(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.line_width = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1112,8 +1809,10 @@ double opt_general_line_width(OPT_ARGS_NUM){ #endif return CTX.line_width; } -double opt_general_shine(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_general_shine(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.shine = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1121,8 +1820,10 @@ double opt_general_shine(OPT_ARGS_NUM){ #endif return CTX.shine; } -double opt_general_verbosity(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_general_verbosity(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.verbosity = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1130,8 +1831,10 @@ double opt_general_verbosity(OPT_ARGS_NUM){ #endif return CTX.verbosity; } -double opt_general_terminal(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_general_terminal(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.terminal = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1139,13 +1842,17 @@ double opt_general_terminal(OPT_ARGS_NUM){ #endif return CTX.terminal; } -double opt_general_tooltips(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_general_tooltips(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.tooltips = (int)val; #if defined(HAVE_FLTK) #if !((FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION == 0)) - if(CTX.tooltips) Fl_Tooltip::enable(); - else Fl_Tooltip::disable(); + if(CTX.tooltips) + Fl_Tooltip::enable(); + else + Fl_Tooltip::disable(); #endif #endif } @@ -1155,19 +1862,23 @@ double opt_general_tooltips(OPT_ARGS_NUM){ #endif return CTX.tooltips; } -double opt_general_orthographic(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_general_orthographic(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.ortho = (int)val; #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI)){ + if(WID && (action & GMSH_GUI)) { WID->gen_butt[10]->value(CTX.ortho); WID->gen_butt[11]->value(!CTX.ortho); } #endif return CTX.ortho; } -double opt_general_fast_redraw(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_general_fast_redraw(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.fast = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1175,8 +1886,10 @@ double opt_general_fast_redraw(OPT_ARGS_NUM){ #endif return CTX.fast; } -double opt_general_axes(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_general_axes(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.axes = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1184,8 +1897,10 @@ double opt_general_axes(OPT_ARGS_NUM){ #endif return CTX.axes; } -double opt_general_small_axes(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_general_small_axes(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.small_axes = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1193,33 +1908,41 @@ double opt_general_small_axes(OPT_ARGS_NUM){ #endif return CTX.small_axes; } -double opt_general_small_axes_position0(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_general_small_axes_position0(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.small_axes_pos[0] = (int)val; return CTX.small_axes_pos[0]; } -double opt_general_small_axes_position1(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_general_small_axes_position1(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.small_axes_pos[1] = (int)val; return CTX.small_axes_pos[1]; } -double opt_general_quadric_subdivisions(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_general_quadric_subdivisions(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.quadric_subdivisions = (int)val; return CTX.quadric_subdivisions; } -double opt_general_double_buffer(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_general_double_buffer(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.db = (int)val; #if defined(HAVE_FLTK) - if(WID){ - if(CTX.db){ - Msg(INFO, "Setting OpenGL visual to double buffered"); - WID->g_opengl_window->mode(FL_RGB | FL_DEPTH | FL_DOUBLE); + if(WID) { + if(CTX.db) { + Msg(INFO, "Setting OpenGL visual to double buffered"); + WID->g_opengl_window->mode(FL_RGB | FL_DEPTH | FL_DOUBLE); } - else{ - Msg(INFO, "Setting OpenGL visual to single buffered"); - WID->g_opengl_window->mode(FL_RGB | FL_DEPTH | FL_SINGLE); + else { + Msg(INFO, "Setting OpenGL visual to single buffered"); + WID->g_opengl_window->mode(FL_RGB | FL_DEPTH | FL_SINGLE); } } #endif @@ -1230,8 +1953,10 @@ double opt_general_double_buffer(OPT_ARGS_NUM){ #endif return CTX.db; } -double opt_general_alpha_blending(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_general_alpha_blending(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.alpha = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1239,10 +1964,13 @@ double opt_general_alpha_blending(OPT_ARGS_NUM){ #endif return CTX.alpha; } -double opt_general_color_scheme(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_general_color_scheme(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.color_scheme = (int)val; - if(CTX.color_scheme>2) CTX.color_scheme=0; + if(CTX.color_scheme > 2) + CTX.color_scheme = 0; Set_DefaultColorOptions(0, GeneralOptions_Color, CTX.color_scheme); Set_ColorOptions_GUI(0, GeneralOptions_Color); } @@ -1252,8 +1980,10 @@ double opt_general_color_scheme(OPT_ARGS_NUM){ #endif return CTX.color_scheme; } -double opt_general_trackball(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_general_trackball(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.useTrackball = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1261,255 +1991,427 @@ double opt_general_trackball(OPT_ARGS_NUM){ #endif return CTX.useTrackball; } -double opt_general_zoom_factor(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.zoom_factor = val; + +double opt_general_zoom_factor(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.zoom_factor = val; return CTX.zoom_factor; } -double opt_general_default_plugins(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.default_plugins = (int)val; + +double opt_general_default_plugins(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.default_plugins = (int)val; return CTX.default_plugins; } -double opt_general_clip0(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip[0] = (int)val; + +double opt_general_clip0(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip[0] = (int)val; return CTX.clip[0]; } -double opt_general_clip0a(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[0][0] = val; + +double opt_general_clip0a(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[0][0] = val; return CTX.clip_plane[0][0]; } -double opt_general_clip0b(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[0][1] = val; + +double opt_general_clip0b(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[0][1] = val; return CTX.clip_plane[0][1]; } -double opt_general_clip0c(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[0][2] = val; + +double opt_general_clip0c(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[0][2] = val; return CTX.clip_plane[0][2]; } -double opt_general_clip0d(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[0][3] = val; + +double opt_general_clip0d(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[0][3] = val; return CTX.clip_plane[0][3]; } -double opt_general_clip1(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip[1] = (int)val; + +double opt_general_clip1(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip[1] = (int)val; return CTX.clip[1]; } -double opt_general_clip1a(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[1][0] = val; + +double opt_general_clip1a(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[1][0] = val; return CTX.clip_plane[1][0]; } -double opt_general_clip1b(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[1][1] = val; + +double opt_general_clip1b(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[1][1] = val; return CTX.clip_plane[1][1]; } -double opt_general_clip1c(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[1][2] = val; + +double opt_general_clip1c(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[1][2] = val; return CTX.clip_plane[1][2]; } -double opt_general_clip1d(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[1][3] = val; + +double opt_general_clip1d(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[1][3] = val; return CTX.clip_plane[1][3]; } -double opt_general_clip2(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip[2] = (int)val; + +double opt_general_clip2(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip[2] = (int)val; return CTX.clip[2]; } -double opt_general_clip2a(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[2][0] = val; + +double opt_general_clip2a(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[2][0] = val; return CTX.clip_plane[2][0]; } -double opt_general_clip2b(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[2][1] = val; + +double opt_general_clip2b(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[2][1] = val; return CTX.clip_plane[2][1]; } -double opt_general_clip2c(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[2][2] = val; + +double opt_general_clip2c(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[2][2] = val; return CTX.clip_plane[2][2]; } -double opt_general_clip2d(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[2][3] = val; + +double opt_general_clip2d(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[2][3] = val; return CTX.clip_plane[2][3]; } -double opt_general_clip3(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip[3] = (int)val; + +double opt_general_clip3(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip[3] = (int)val; return CTX.clip[3]; } -double opt_general_clip3a(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[3][0] = val; + +double opt_general_clip3a(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[3][0] = val; return CTX.clip_plane[3][0]; } -double opt_general_clip3b(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[3][1] = val; + +double opt_general_clip3b(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[3][1] = val; return CTX.clip_plane[3][1]; } -double opt_general_clip3c(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[3][2] = val; + +double opt_general_clip3c(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[3][2] = val; return CTX.clip_plane[3][2]; } -double opt_general_clip3d(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[3][3] = val; + +double opt_general_clip3d(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[3][3] = val; return CTX.clip_plane[3][3]; } -double opt_general_clip4(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip[4] = (int)val; + +double opt_general_clip4(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip[4] = (int)val; return CTX.clip[4]; } -double opt_general_clip4a(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[4][0] = val; + +double opt_general_clip4a(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[4][0] = val; return CTX.clip_plane[4][0]; } -double opt_general_clip4b(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[4][1] = val; + +double opt_general_clip4b(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[4][1] = val; return CTX.clip_plane[4][1]; } -double opt_general_clip4c(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[4][2] = val; + +double opt_general_clip4c(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[4][2] = val; return CTX.clip_plane[4][2]; } -double opt_general_clip4d(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[4][3] = val; + +double opt_general_clip4d(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[4][3] = val; return CTX.clip_plane[4][3]; } -double opt_general_clip5(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip[5] = (int)val; + +double opt_general_clip5(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip[5] = (int)val; return CTX.clip[5]; } -double opt_general_clip5a(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[5][0] = val; + +double opt_general_clip5a(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[5][0] = val; return CTX.clip_plane[5][0]; } -double opt_general_clip5b(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[5][1] = val; + +double opt_general_clip5b(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[5][1] = val; return CTX.clip_plane[5][1]; } -double opt_general_clip5c(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[5][2] = val; + +double opt_general_clip5c(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[5][2] = val; return CTX.clip_plane[5][2]; } -double opt_general_clip5d(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.clip_plane[5][3] = val; + +double opt_general_clip5d(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.clip_plane[5][3] = val; return CTX.clip_plane[5][3]; } -double opt_general_moving_light(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.moving_light = (int)val; + +double opt_general_moving_light(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.moving_light = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) WID->gen_butt[12]->value(CTX.moving_light); #endif return CTX.moving_light; } -double opt_general_light0(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light[0] = (int)val; + +double opt_general_light0(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light[0] = (int)val; return CTX.light[0]; } -double opt_general_light00(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[0][0] = val; + +double opt_general_light00(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[0][0] = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) WID->gen_value[2]->value(CTX.light_position[0][0]); #endif return CTX.light_position[0][0]; } -double opt_general_light01(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[0][1] = val; + +double opt_general_light01(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[0][1] = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) WID->gen_value[3]->value(CTX.light_position[0][1]); #endif return CTX.light_position[0][1]; } -double opt_general_light02(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[0][2] = val; + +double opt_general_light02(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[0][2] = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) WID->gen_value[4]->value(CTX.light_position[0][2]); #endif return CTX.light_position[0][2]; } -double opt_general_light1(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light[1] = (int)val; + +double opt_general_light1(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light[1] = (int)val; return CTX.light[1]; } -double opt_general_light10(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[1][0] = val; + +double opt_general_light10(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[1][0] = val; return CTX.light_position[1][0]; } -double opt_general_light11(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[1][1] = val; + +double opt_general_light11(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[1][1] = val; return CTX.light_position[1][1]; } -double opt_general_light12(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[1][2] = val; + +double opt_general_light12(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[1][2] = val; return CTX.light_position[1][2]; } -double opt_general_light2(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light[2] = (int)val; + +double opt_general_light2(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light[2] = (int)val; return CTX.light[2]; } -double opt_general_light20(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[2][0] = val; + +double opt_general_light20(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[2][0] = val; return CTX.light_position[2][0]; } -double opt_general_light21(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[2][1] = val; + +double opt_general_light21(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[2][1] = val; return CTX.light_position[2][1]; } -double opt_general_light22(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[2][2] = val; + +double opt_general_light22(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[2][2] = val; return CTX.light_position[2][2]; } -double opt_general_light3(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light[3] = (int)val; + +double opt_general_light3(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light[3] = (int)val; return CTX.light[3]; } -double opt_general_light30(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[3][0] = val; + +double opt_general_light30(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[3][0] = val; return CTX.light_position[3][0]; } -double opt_general_light31(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[3][1] = val; + +double opt_general_light31(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[3][1] = val; return CTX.light_position[3][1]; } -double opt_general_light32(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[3][2] = val; + +double opt_general_light32(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[3][2] = val; return CTX.light_position[3][2]; } -double opt_general_light4(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light[4] = (int)val; + +double opt_general_light4(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light[4] = (int)val; return CTX.light[4]; } -double opt_general_light40(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[4][0] = val; + +double opt_general_light40(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[4][0] = val; return CTX.light_position[4][0]; } -double opt_general_light41(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[4][1] = val; + +double opt_general_light41(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[4][1] = val; return CTX.light_position[4][1]; } -double opt_general_light42(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[4][2] = val; + +double opt_general_light42(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[4][2] = val; return CTX.light_position[4][2]; } -double opt_general_light5(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light[5] = (int)val; + +double opt_general_light5(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light[5] = (int)val; return CTX.light[5]; } -double opt_general_light50(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[5][0] = val; + +double opt_general_light50(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[5][0] = val; return CTX.light_position[5][0]; } -double opt_general_light51(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[5][1] = val; + +double opt_general_light51(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[5][1] = val; return CTX.light_position[5][1]; } -double opt_general_light52(OPT_ARGS_NUM){ - if(action & GMSH_SET) CTX.light_position[5][2] = val; + +double opt_general_light52(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.light_position[5][2] = val; return CTX.light_position[5][2]; } -double opt_geometry_auto_coherence(OPT_ARGS_NUM){ - if(action & GMSH_SET) +double opt_geometry_auto_coherence(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.auto_coherence = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1517,8 +2419,10 @@ double opt_geometry_auto_coherence(OPT_ARGS_NUM){ #endif return CTX.geom.auto_coherence; } -double opt_geometry_normals(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_normals(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.normals = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1526,8 +2430,10 @@ double opt_geometry_normals(OPT_ARGS_NUM){ #endif return CTX.geom.normals; } -double opt_geometry_tangents(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_tangents(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.tangents = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1535,8 +2441,10 @@ double opt_geometry_tangents(OPT_ARGS_NUM){ #endif return CTX.geom.tangents; } -double opt_geometry_points(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_points(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.points = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1544,8 +2452,10 @@ double opt_geometry_points(OPT_ARGS_NUM){ #endif return CTX.geom.points; } -double opt_geometry_lines(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_lines(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.lines = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1553,8 +2463,10 @@ double opt_geometry_lines(OPT_ARGS_NUM){ #endif return CTX.geom.lines; } -double opt_geometry_surfaces(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_surfaces(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.surfaces = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1562,8 +2474,10 @@ double opt_geometry_surfaces(OPT_ARGS_NUM){ #endif return CTX.geom.surfaces; } -double opt_geometry_volumes(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_volumes(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.volumes = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1571,8 +2485,10 @@ double opt_geometry_volumes(OPT_ARGS_NUM){ #endif return CTX.geom.volumes; } -double opt_geometry_points_num(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_points_num(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.points_num = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1580,8 +2496,10 @@ double opt_geometry_points_num(OPT_ARGS_NUM){ #endif return CTX.geom.points_num; } -double opt_geometry_lines_num(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_lines_num(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.lines_num = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1589,8 +2507,10 @@ double opt_geometry_lines_num(OPT_ARGS_NUM){ #endif return CTX.geom.lines_num; } -double opt_geometry_surfaces_num(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_surfaces_num(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.surfaces_num = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1598,8 +2518,10 @@ double opt_geometry_surfaces_num(OPT_ARGS_NUM){ #endif return CTX.geom.surfaces_num; } -double opt_geometry_volumes_num(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_volumes_num(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.volumes_num = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1607,8 +2529,10 @@ double opt_geometry_volumes_num(OPT_ARGS_NUM){ #endif return CTX.geom.volumes_num; } -double opt_geometry_point_size(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_point_size(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.point_size = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1616,8 +2540,10 @@ double opt_geometry_point_size(OPT_ARGS_NUM){ #endif return CTX.geom.point_size; } -double opt_geometry_point_sel_size(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_point_sel_size(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.point_sel_size = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1625,19 +2551,23 @@ double opt_geometry_point_sel_size(OPT_ARGS_NUM){ #endif return CTX.geom.point_sel_size; } -double opt_geometry_point_type(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_geometry_point_type(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.geom.point_type = (int)val; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI)){ + if(WID && (action & GMSH_GUI)) { WID->geo_choice[0]->value(CTX.geom.point_type); } #endif return CTX.geom.point_type; } -double opt_geometry_line_width(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_line_width(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.line_width = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1645,68 +2575,100 @@ double opt_geometry_line_width(OPT_ARGS_NUM){ #endif return CTX.geom.line_width; } -double opt_geometry_line_sel_width(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_line_sel_width(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.line_sel_width = val; return CTX.geom.line_sel_width; } -double opt_geometry_line_type(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_geometry_line_type(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.geom.line_type = (int)val; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI)){ + if(WID && (action & GMSH_GUI)) { WID->geo_choice[1]->value(CTX.geom.line_type); } #endif return CTX.geom.line_type; } -double opt_geometry_aspect(OPT_ARGS_NUM){ - if(action & GMSH_SET){ - switch((int)val){ - case 1 : CTX.geom.hidden = 1; CTX.geom.shade = 0; break ; - case 2 : CTX.geom.hidden = 1; CTX.geom.shade = 1; break ; - default : CTX.geom.hidden = CTX.geom.shade = 0; break ; + +double opt_geometry_aspect(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { + switch ((int)val) { + case 1: + CTX.geom.hidden = 1; + CTX.geom.shade = 0; + break; + case 2: + CTX.geom.hidden = 1; + CTX.geom.shade = 1; + break; + default: + CTX.geom.hidden = CTX.geom.shade = 0; + break; } } - if(CTX.geom.hidden && !CTX.geom.shade) return 1; - else if(CTX.geom.hidden && CTX.geom.shade) return 2; - else return 0; + if(CTX.geom.hidden && !CTX.geom.shade) + return 1; + else if(CTX.geom.hidden && CTX.geom.shade) + return 2; + else + return 0; } -double opt_geometry_highlight(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_highlight(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.highlight = (int)val; return CTX.geom.highlight; } -double opt_geometry_old_circle(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_old_circle(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.old_circle = (int)val; return CTX.geom.old_circle; } -double opt_geometry_old_newreg(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_old_newreg(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.old_newreg = (int)val; return CTX.geom.old_newreg; } -double opt_geometry_circle_points(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_circle_points(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.circle_points = (int)val; return CTX.geom.circle_points; } -double opt_geometry_extrude_spline_points(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_extrude_spline_points(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.extrude_spline_points = (int)val; return CTX.geom.extrude_spline_points; } -double opt_geometry_scaling_factor(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_geometry_scaling_factor(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.geom.scaling_factor = (int)val; return CTX.geom.scaling_factor; } -double opt_geometry_color_scheme(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_geometry_color_scheme(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.geom.color_scheme = (int)val; - if(CTX.geom.color_scheme>2) CTX.geom.color_scheme=0; + if(CTX.geom.color_scheme > 2) + CTX.geom.color_scheme = 0; Set_DefaultColorOptions(0, GeometryOptions_Color, CTX.geom.color_scheme); Set_ColorOptions_GUI(0, GeometryOptions_Color); } @@ -1718,13 +2680,16 @@ double opt_geometry_color_scheme(OPT_ARGS_NUM){ } -double opt_mesh_quality(OPT_ARGS_NUM){ - if(action & GMSH_SET) +double opt_mesh_quality(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.quality = val; return CTX.mesh.quality; } -double opt_mesh_normals(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_normals(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.normals = val; CTX.mesh.changed = 1; } @@ -1734,8 +2699,10 @@ double opt_mesh_normals(OPT_ARGS_NUM){ #endif return CTX.mesh.normals; } -double opt_mesh_tangents(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_tangents(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.tangents = val; CTX.mesh.changed = 1; } @@ -1745,8 +2712,10 @@ double opt_mesh_tangents(OPT_ARGS_NUM){ #endif return CTX.mesh.tangents; } -double opt_mesh_explode(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_explode(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.explode = val; CTX.mesh.changed = 1; } @@ -1756,8 +2725,10 @@ double opt_mesh_explode(OPT_ARGS_NUM){ #endif return CTX.mesh.explode; } -double opt_mesh_scaling_factor(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_scaling_factor(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.scaling_factor = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1765,8 +2736,10 @@ double opt_mesh_scaling_factor(OPT_ARGS_NUM){ #endif return CTX.mesh.scaling_factor; } -double opt_mesh_lc_factor(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_lc_factor(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.lc_factor = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1774,8 +2747,10 @@ double opt_mesh_lc_factor(OPT_ARGS_NUM){ #endif return CTX.mesh.lc_factor; } -double opt_mesh_rand_factor(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_rand_factor(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.rand_factor = val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1783,8 +2758,10 @@ double opt_mesh_rand_factor(OPT_ARGS_NUM){ #endif return CTX.mesh.rand_factor; } -double opt_mesh_gamma_inf(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_gamma_inf(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.gamma_inf = val; CTX.mesh.changed = 1; } @@ -1794,8 +2771,10 @@ double opt_mesh_gamma_inf(OPT_ARGS_NUM){ #endif return CTX.mesh.gamma_inf; } -double opt_mesh_gamma_sup(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_gamma_sup(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.gamma_sup = val; CTX.mesh.changed = 1; } @@ -1805,8 +2784,10 @@ double opt_mesh_gamma_sup(OPT_ARGS_NUM){ #endif return CTX.mesh.gamma_sup; } -double opt_mesh_radius_inf(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_radius_inf(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.radius_inf = val; CTX.mesh.changed = 1; } @@ -1816,8 +2797,10 @@ double opt_mesh_radius_inf(OPT_ARGS_NUM){ #endif return CTX.mesh.radius_inf; } -double opt_mesh_radius_sup(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_radius_sup(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.radius_sup = val; CTX.mesh.changed = 1; } @@ -1827,8 +2810,10 @@ double opt_mesh_radius_sup(OPT_ARGS_NUM){ #endif return CTX.mesh.radius_sup; } -double opt_mesh_points(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_points(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.points = (int)val; CTX.mesh.changed = 1; } @@ -1838,8 +2823,10 @@ double opt_mesh_points(OPT_ARGS_NUM){ #endif return CTX.mesh.points; } -double opt_mesh_lines(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_lines(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.lines = (int)val; CTX.mesh.changed = 1; } @@ -1849,8 +2836,10 @@ double opt_mesh_lines(OPT_ARGS_NUM){ #endif return CTX.mesh.lines; } -double opt_mesh_surfaces(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_surfaces(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.surfaces = (int)val; CTX.mesh.changed = 1; } @@ -1860,8 +2849,10 @@ double opt_mesh_surfaces(OPT_ARGS_NUM){ #endif return CTX.mesh.surfaces; } -double opt_mesh_volumes(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_volumes(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.volumes = (int)val; CTX.mesh.changed = 1; } @@ -1871,8 +2862,10 @@ double opt_mesh_volumes(OPT_ARGS_NUM){ #endif return CTX.mesh.volumes; } -double opt_mesh_points_num(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_points_num(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.points_num = (int)val; CTX.mesh.changed = 1; } @@ -1882,8 +2875,10 @@ double opt_mesh_points_num(OPT_ARGS_NUM){ #endif return CTX.mesh.points_num; } -double opt_mesh_lines_num(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_lines_num(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.lines_num = (int)val; CTX.mesh.changed = 1; } @@ -1893,8 +2888,10 @@ double opt_mesh_lines_num(OPT_ARGS_NUM){ #endif return CTX.mesh.lines_num; } -double opt_mesh_surfaces_num(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_surfaces_num(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.surfaces_num = (int)val; CTX.mesh.changed = 1; } @@ -1904,8 +2901,10 @@ double opt_mesh_surfaces_num(OPT_ARGS_NUM){ #endif return CTX.mesh.surfaces_num; } -double opt_mesh_volumes_num(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_volumes_num(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.volumes_num = (int)val; CTX.mesh.changed = 1; } @@ -1915,8 +2914,10 @@ double opt_mesh_volumes_num(OPT_ARGS_NUM){ #endif return CTX.mesh.volumes_num; } -double opt_mesh_point_size(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_point_size(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.point_size = val; CTX.mesh.changed = 1; } @@ -1926,20 +2927,24 @@ double opt_mesh_point_size(OPT_ARGS_NUM){ #endif return CTX.mesh.point_size; } -double opt_mesh_point_type(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_point_type(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.point_type = (int)val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI)){ + if(WID && (action & GMSH_GUI)) { WID->mesh_choice[0]->value(CTX.mesh.point_type); } #endif return CTX.mesh.point_type; } -double opt_mesh_line_width(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_line_width(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.line_width = val; CTX.mesh.changed = 1; } @@ -1949,45 +2954,64 @@ double opt_mesh_line_width(OPT_ARGS_NUM){ #endif return CTX.mesh.line_width; } -double opt_mesh_line_type(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_line_type(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.line_type = (int)val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI)){ + if(WID && (action & GMSH_GUI)) { WID->mesh_choice[1]->value(CTX.mesh.line_type); } #endif return CTX.mesh.line_type; } -double opt_mesh_aspect(OPT_ARGS_NUM){ - if(action & GMSH_SET){ - switch((int)val){ - case 1 : CTX.mesh.hidden = 1; CTX.mesh.shade = 0; break ; - case 2 : CTX.mesh.hidden = 1; CTX.mesh.shade = 1; break ; - default : CTX.mesh.hidden = CTX.mesh.shade = 0; break ; + +double opt_mesh_aspect(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { + switch ((int)val) { + case 1: + CTX.mesh.hidden = 1; + CTX.mesh.shade = 0; + break; + case 2: + CTX.mesh.hidden = 1; + CTX.mesh.shade = 1; + break; + default: + CTX.mesh.hidden = CTX.mesh.shade = 0; + break; } CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI)){ + if(WID && (action & GMSH_GUI)) { WID->mesh_butt[14]->value(!CTX.mesh.hidden && !CTX.mesh.shade); WID->mesh_butt[15]->value(CTX.mesh.hidden && !CTX.mesh.shade); WID->mesh_butt[16]->value(CTX.mesh.hidden && CTX.mesh.shade); } #endif - if(CTX.mesh.hidden && !CTX.mesh.shade) return 1; - else if(CTX.mesh.hidden && CTX.mesh.shade) return 2; - else return 0; + if(CTX.mesh.hidden && !CTX.mesh.shade) + return 1; + else if(CTX.mesh.hidden && CTX.mesh.shade) + return 2; + else + return 0; } -double opt_mesh_format(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_format(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.format = (int)val; return CTX.mesh.format; } -double opt_mesh_nb_smoothing(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_nb_smoothing(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.nb_smoothing = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -1995,35 +3019,45 @@ double opt_mesh_nb_smoothing(OPT_ARGS_NUM){ #endif return CTX.mesh.nb_smoothing; } -double opt_mesh_algo(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_algo(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.algo = (int)val; #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI)){ - WID->mesh_butt[0]->value(CTX.mesh.algo==DELAUNAY_ISO); - WID->mesh_butt[1]->value(CTX.mesh.algo==DELAUNAY_SHEWCHUK); - WID->mesh_butt[2]->value(CTX.mesh.algo==DELAUNAY_ANISO); + if(WID && (action & GMSH_GUI)) { + WID->mesh_butt[0]->value(CTX.mesh.algo == DELAUNAY_ISO); + WID->mesh_butt[1]->value(CTX.mesh.algo == DELAUNAY_SHEWCHUK); + WID->mesh_butt[2]->value(CTX.mesh.algo == DELAUNAY_ANISO); } #endif return CTX.mesh.algo; } -double opt_mesh_point_insertion(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_point_insertion(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.point_insertion = (int)val; return CTX.mesh.point_insertion; } -double opt_mesh_speed_max(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_speed_max(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.speed_max = (int)val; return CTX.mesh.speed_max; } -double opt_mesh_min_circ_points(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_min_circ_points(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.min_circ_points = (int)val; return CTX.mesh.min_circ_points; } -double opt_mesh_constrained_bgmesh(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_constrained_bgmesh(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.constrained_bgmesh = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -2031,24 +3065,30 @@ double opt_mesh_constrained_bgmesh(OPT_ARGS_NUM){ #endif return CTX.mesh.constrained_bgmesh; } -double opt_mesh_degree(OPT_ARGS_NUM){ + +double opt_mesh_degree(OPT_ARGS_NUM) +{ if(action & GMSH_SET) - CTX.mesh.degree = 1; //(int)val; // INTERDIT POUR LE MOMENT !!! + CTX.mesh.degree = 1; //(int)val; // INTERDIT POUR LE MOMENT !!! #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) - WID->mesh_butt[3]->value(CTX.mesh.degree==2); + WID->mesh_butt[3]->value(CTX.mesh.degree == 2); #endif return CTX.mesh.degree; } -double opt_mesh_dual(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_dual(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.dual = (int)val; CTX.mesh.changed = 1; } return CTX.mesh.dual; } -double opt_mesh_interactive(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_interactive(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.interactive = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -2056,45 +3096,62 @@ double opt_mesh_interactive(OPT_ARGS_NUM){ #endif return CTX.mesh.interactive; } -double opt_mesh_use_cut_plane(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_use_cut_plane(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.use_cut_plane = (int)val; return CTX.mesh.use_cut_plane; } -double opt_mesh_cut_planea(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_cut_planea(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.cut_planea = val; return CTX.mesh.cut_planea; } -double opt_mesh_cut_planeb(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_cut_planeb(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.cut_planeb = val; return CTX.mesh.cut_planeb; } -double opt_mesh_cut_planec(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_cut_planec(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.cut_planec = val; return CTX.mesh.cut_planec; } -double opt_mesh_cut_planed(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_cut_planed(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.cut_planed = val; return CTX.mesh.cut_planed; } -double opt_mesh_allow_degenerated_extrude(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_allow_degenerated_extrude(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.allow_degenerated_extrude = (int)val; return CTX.mesh.allow_degenerated_extrude; } -double opt_mesh_save_all(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_mesh_save_all(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.mesh.save_all = (int)val; return CTX.mesh.save_all; } -double opt_mesh_color_scheme(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_color_scheme(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.color_scheme = (int)val; - if(CTX.mesh.color_scheme>2) CTX.mesh.color_scheme=0; + if(CTX.mesh.color_scheme > 2) + CTX.mesh.color_scheme = 0; Set_DefaultColorOptions(0, MeshOptions_Color, CTX.mesh.color_scheme); Set_ColorOptions_GUI(0, MeshOptions_Color); } @@ -2104,8 +3161,10 @@ double opt_mesh_color_scheme(OPT_ARGS_NUM){ #endif return CTX.mesh.color_scheme; } -double opt_mesh_color_carousel(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_color_carousel(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.color_carousel = (int)val; CTX.mesh.changed = 1; } @@ -2115,48 +3174,66 @@ double opt_mesh_color_carousel(OPT_ARGS_NUM){ #endif return CTX.mesh.color_carousel; } -double opt_mesh_nb_nodes(OPT_ARGS_NUM){ - double s[50]; + +double opt_mesh_nb_nodes(OPT_ARGS_NUM) +{ + double s[50]; GetStatistics(s); - return s[6]?s[6]:(s[5]?s[5]:s[4]); + return s[6] ? s[6] : (s[5] ? s[5] : s[4]); } -double opt_mesh_nb_triangles(OPT_ARGS_NUM){ - double s[50]; + +double opt_mesh_nb_triangles(OPT_ARGS_NUM) +{ + double s[50]; GetStatistics(s); - return s[7]-s[8]; + return s[7] - s[8]; } -double opt_mesh_nb_quadrangles(OPT_ARGS_NUM){ - double s[50]; + +double opt_mesh_nb_quadrangles(OPT_ARGS_NUM) +{ + double s[50]; GetStatistics(s); return s[8]; } -double opt_mesh_nb_tetrahedra(OPT_ARGS_NUM){ - double s[50]; + +double opt_mesh_nb_tetrahedra(OPT_ARGS_NUM) +{ + double s[50]; GetStatistics(s); return s[9]; } -double opt_mesh_nb_hexahedra(OPT_ARGS_NUM){ - double s[50]; + +double opt_mesh_nb_hexahedra(OPT_ARGS_NUM) +{ + double s[50]; GetStatistics(s); return s[10]; } -double opt_mesh_nb_prisms(OPT_ARGS_NUM){ - double s[50]; + +double opt_mesh_nb_prisms(OPT_ARGS_NUM) +{ + double s[50]; GetStatistics(s); return s[11]; } -double opt_mesh_nb_pyramids(OPT_ARGS_NUM){ - double s[50]; + +double opt_mesh_nb_pyramids(OPT_ARGS_NUM) +{ + double s[50]; GetStatistics(s); return s[12]; } -double opt_mesh_cpu_time(OPT_ARGS_NUM){ - double s[50]; + +double opt_mesh_cpu_time(OPT_ARGS_NUM) +{ + double s[50]; GetStatistics(s); - return s[13]+s[14]+s[15]; + return s[13] + s[14] + s[15]; } -double opt_mesh_display_lists(OPT_ARGS_NUM){ - if(action & GMSH_SET){ + +double opt_mesh_display_lists(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) { CTX.mesh.display_lists = (int)val; CTX.mesh.changed = 1; } @@ -2168,7 +3245,8 @@ double opt_mesh_display_lists(OPT_ARGS_NUM){ } -double opt_solver_client_server(OPT_ARGS_NUM){ +double opt_solver_client_server(OPT_ARGS_NUM) +{ #if defined(HAVE_FLTK) if(action & GMSH_SET) SINFO[num].client_server = (int)val; @@ -2179,13 +3257,34 @@ double opt_solver_client_server(OPT_ARGS_NUM){ return 0.; #endif } -double opt_solver_client_server0(OPT_ARGS_NUM){ return opt_solver_client_server(0,action,val); } -double opt_solver_client_server1(OPT_ARGS_NUM){ return opt_solver_client_server(1,action,val); } -double opt_solver_client_server2(OPT_ARGS_NUM){ return opt_solver_client_server(2,action,val); } -double opt_solver_client_server3(OPT_ARGS_NUM){ return opt_solver_client_server(3,action,val); } -double opt_solver_client_server4(OPT_ARGS_NUM){ return opt_solver_client_server(4,action,val); } -double opt_solver_popup_messages(OPT_ARGS_NUM){ +double opt_solver_client_server0(OPT_ARGS_NUM) +{ + return opt_solver_client_server(0, action, val); +} + +double opt_solver_client_server1(OPT_ARGS_NUM) +{ + return opt_solver_client_server(1, action, val); +} + +double opt_solver_client_server2(OPT_ARGS_NUM) +{ + return opt_solver_client_server(2, action, val); +} + +double opt_solver_client_server3(OPT_ARGS_NUM) +{ + return opt_solver_client_server(3, action, val); +} + +double opt_solver_client_server4(OPT_ARGS_NUM) +{ + return opt_solver_client_server(4, action, val); +} + +double opt_solver_popup_messages(OPT_ARGS_NUM) +{ #if defined(HAVE_FLTK) if(action & GMSH_SET) SINFO[num].popup_messages = (int)val; @@ -2196,13 +3295,34 @@ double opt_solver_popup_messages(OPT_ARGS_NUM){ return 1.; #endif } -double opt_solver_popup_messages0(OPT_ARGS_NUM){ return opt_solver_popup_messages(0,action,val); } -double opt_solver_popup_messages1(OPT_ARGS_NUM){ return opt_solver_popup_messages(1,action,val); } -double opt_solver_popup_messages2(OPT_ARGS_NUM){ return opt_solver_popup_messages(2,action,val); } -double opt_solver_popup_messages3(OPT_ARGS_NUM){ return opt_solver_popup_messages(3,action,val); } -double opt_solver_popup_messages4(OPT_ARGS_NUM){ return opt_solver_popup_messages(4,action,val); } -double opt_solver_merge_views(OPT_ARGS_NUM){ +double opt_solver_popup_messages0(OPT_ARGS_NUM) +{ + return opt_solver_popup_messages(0, action, val); +} + +double opt_solver_popup_messages1(OPT_ARGS_NUM) +{ + return opt_solver_popup_messages(1, action, val); +} + +double opt_solver_popup_messages2(OPT_ARGS_NUM) +{ + return opt_solver_popup_messages(2, action, val); +} + +double opt_solver_popup_messages3(OPT_ARGS_NUM) +{ + return opt_solver_popup_messages(3, action, val); +} + +double opt_solver_popup_messages4(OPT_ARGS_NUM) +{ + return opt_solver_popup_messages(4, action, val); +} + +double opt_solver_merge_views(OPT_ARGS_NUM) +{ #if defined(HAVE_FLTK) if(action & GMSH_SET) SINFO[num].merge_views = (int)val; @@ -2213,19 +3333,40 @@ double opt_solver_merge_views(OPT_ARGS_NUM){ return 1.; #endif } -double opt_solver_merge_views0(OPT_ARGS_NUM){ return opt_solver_merge_views(0,action,val); } -double opt_solver_merge_views1(OPT_ARGS_NUM){ return opt_solver_merge_views(1,action,val); } -double opt_solver_merge_views2(OPT_ARGS_NUM){ return opt_solver_merge_views(2,action,val); } -double opt_solver_merge_views3(OPT_ARGS_NUM){ return opt_solver_merge_views(3,action,val); } -double opt_solver_merge_views4(OPT_ARGS_NUM){ return opt_solver_merge_views(4,action,val); } -double opt_post_display_lists(OPT_ARGS_NUM){ +double opt_solver_merge_views0(OPT_ARGS_NUM) +{ + return opt_solver_merge_views(0, action, val); +} + +double opt_solver_merge_views1(OPT_ARGS_NUM) +{ + return opt_solver_merge_views(1, action, val); +} + +double opt_solver_merge_views2(OPT_ARGS_NUM) +{ + return opt_solver_merge_views(2, action, val); +} + +double opt_solver_merge_views3(OPT_ARGS_NUM) +{ + return opt_solver_merge_views(3, action, val); +} + +double opt_solver_merge_views4(OPT_ARGS_NUM) +{ + return opt_solver_merge_views(4, action, val); +} + +double opt_post_display_lists(OPT_ARGS_NUM) +{ int i; - if(action & GMSH_SET){ + if(action & GMSH_SET) { CTX.post.display_lists = (int)val; if(CTX.post.display_lists) - for(i=0 ; i<List_Nbr(CTX.post.list) ; i++) - ((Post_View*)List_Pointer_Test(CTX.post.list, i))->Changed = 1; + for(i = 0; i < List_Nbr(CTX.post.list); i++) + ((Post_View *) List_Pointer_Test(CTX.post.list, i))->Changed = 1; } #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -2233,27 +3374,33 @@ double opt_post_display_lists(OPT_ARGS_NUM){ #endif return CTX.post.display_lists; } -double opt_post_scales(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_post_scales(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.post.scales = (int)val; return CTX.post.scales; } -double opt_post_link(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_post_link(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.post.link = (int)val; #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI)){ - WID->post_butt[0]->value(CTX.post.link==0); - WID->post_butt[1]->value(CTX.post.link==1); - WID->post_butt[2]->value(CTX.post.link==2); - WID->post_butt[3]->value(CTX.post.link==3); - WID->post_butt[4]->value(CTX.post.link==4); + if(WID && (action & GMSH_GUI)) { + WID->post_butt[0]->value(CTX.post.link == 0); + WID->post_butt[1]->value(CTX.post.link == 1); + WID->post_butt[2]->value(CTX.post.link == 2); + WID->post_butt[3]->value(CTX.post.link == 3); + WID->post_butt[4]->value(CTX.post.link == 4); } #endif return CTX.post.link; } -double opt_post_smooth(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_post_smooth(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.post.smooth = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -2261,17 +3408,21 @@ double opt_post_smooth(OPT_ARGS_NUM){ #endif return CTX.post.smooth; } -double opt_post_anim_delay(OPT_ARGS_NUM){ - if(action & GMSH_SET) - CTX.post.anim_delay = (val>=0.)? val : 0. ; + +double opt_post_anim_delay(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) + CTX.post.anim_delay = (val >= 0.) ? val : 0.; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) WID->post_value[0]->value(CTX.post.anim_delay); #endif return CTX.post.anim_delay; } -double opt_post_anim_cycle(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_post_anim_cycle(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.post.anim_cycle = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI)) @@ -2281,32 +3432,37 @@ double opt_post_anim_cycle(OPT_ARGS_NUM){ #endif return CTX.post.anim_cycle; } -double opt_post_nb_views(OPT_ARGS_NUM){ + +double opt_post_nb_views(OPT_ARGS_NUM) +{ return List_Nbr(CTX.post.list); } -double opt_view_nb_timestep(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET) +double opt_view_nb_timestep(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) v->NbTimeStep = (int)val; #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI) && (num == WID->view_number)) - WID->view_value[50]->maximum(v->NbTimeStep-1); + WID->view_value[50]->maximum(v->NbTimeStep - 1); if(WID) WID->check_anim_buttons(); #endif return v->NbTimeStep; } -double opt_view_timestep(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_timestep(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->TimeStep = (int)val; - if(v->TimeStep > v->NbTimeStep-1) - v->TimeStep = 0 ; + if(v->TimeStep > v->NbTimeStep - 1) + v->TimeStep = 0; else if(v->TimeStep < 0) - v->TimeStep = v->NbTimeStep-1; + v->TimeStep = v->NbTimeStep - 1; v->Changed = 1; } #if defined(HAVE_FLTK) @@ -2315,38 +3471,46 @@ double opt_view_timestep(OPT_ARGS_NUM){ #endif return v->TimeStep; } -double opt_view_min(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_min(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Min = val; v->Changed = 1; } return v->Min; } -double opt_view_max(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_max(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Max = val; v->Changed = 1; } return v->Max; } -double opt_view_custom_min(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_custom_min(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->CustomMin = val; v->Changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && (num == WID->view_number)){ + if(WID && (action & GMSH_GUI) && (num == WID->view_number)) { WID->view_value[31]->value(v->CustomMin); } #endif return v->CustomMin; } -double opt_view_custom_max(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_custom_max(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->CustomMax = val; v->Changed = 1; } @@ -2356,9 +3520,11 @@ double opt_view_custom_max(OPT_ARGS_NUM){ #endif return v->CustomMax; } -double opt_view_offset0(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_offset0(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Offset[0] = val; v->Changed = 1; } @@ -2368,9 +3534,11 @@ double opt_view_offset0(OPT_ARGS_NUM){ #endif return v->Offset[0]; } -double opt_view_offset1(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_offset1(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Offset[1] = val; v->Changed = 1; } @@ -2380,9 +3548,11 @@ double opt_view_offset1(OPT_ARGS_NUM){ #endif return v->Offset[1]; } -double opt_view_offset2(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_offset2(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Offset[2] = val; v->Changed = 1; } @@ -2392,9 +3562,11 @@ double opt_view_offset2(OPT_ARGS_NUM){ #endif return v->Offset[2]; } -double opt_view_raise0(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_raise0(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Raise[0] = val; v->Changed = 1; } @@ -2404,9 +3576,11 @@ double opt_view_raise0(OPT_ARGS_NUM){ #endif return v->Raise[0]; } -double opt_view_raise1(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_raise1(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Raise[1] = val; v->Changed = 1; } @@ -2416,9 +3590,11 @@ double opt_view_raise1(OPT_ARGS_NUM){ #endif return v->Raise[1]; } -double opt_view_raise2(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_raise2(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Raise[2] = val; v->Changed = 1; } @@ -2428,9 +3604,11 @@ double opt_view_raise2(OPT_ARGS_NUM){ #endif return v->Raise[2]; } -double opt_view_arrow_scale(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_arrow_scale(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->ArrowScale = val; v->Changed = 1; } @@ -2440,9 +3618,11 @@ double opt_view_arrow_scale(OPT_ARGS_NUM){ #endif return v->ArrowScale; } -double opt_view_explode(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_explode(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Explode = val; v->Changed = 1; } @@ -2452,13 +3632,15 @@ double opt_view_explode(OPT_ARGS_NUM){ #endif return v->Explode; } -double opt_view_visible(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_visible(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Visible = (int)val; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && num<NB_BUTT_MAX) + if(WID && (action & GMSH_GUI) && num < NB_BUTT_MAX) WID->m_toggle_butt[num]->value(v->Visible); #endif Msg(DEBUG1, "View %d", v->Num); @@ -2468,58 +3650,71 @@ double opt_view_visible(OPT_ARGS_NUM){ Msg(DEBUG3, " -> Links %d", v->Links); return v->Visible; } -double opt_view_intervals_type(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_intervals_type(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->IntervalsType = (int)val; v->Changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && (num == WID->view_number)){ - switch(v->IntervalsType){ - case DRAW_POST_ISO: WID->view_choice[0]->value(0); break; - case DRAW_POST_DISCRETE: WID->view_choice[0]->value(1); break; - case DRAW_POST_CONTINUOUS: WID->view_choice[0]->value(2); break; - case DRAW_POST_NUMERIC: WID->view_choice[0]->value(3); break; + if(WID && (action & GMSH_GUI) && (num == WID->view_number)) { + switch (v->IntervalsType) { + case DRAW_POST_ISO: + WID->view_choice[0]->value(0); + break; + case DRAW_POST_DISCRETE: + WID->view_choice[0]->value(1); + break; + case DRAW_POST_CONTINUOUS: + WID->view_choice[0]->value(2); + break; + case DRAW_POST_NUMERIC: + WID->view_choice[0]->value(3); + break; } } #endif return v->IntervalsType; } -double opt_view_saturate_values(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ +double opt_view_saturate_values(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->SaturateValues = (int)val; v->Changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && (num == WID->view_number)){ + if(WID && (action & GMSH_GUI) && (num == WID->view_number)) { WID->view_butt[38]->value(v->SaturateValues); } #endif return v->SaturateValues; } -double opt_view_type(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ +double opt_view_type(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Type = (int)val; v->Changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && (num == WID->view_number)){ - WID->view_butt[1]->value(v->Type==DRAW_POST_3D); - WID->view_butt[2]->value(v->Type==DRAW_POST_2D_SPACE); - WID->view_butt[3]->value(v->Type==DRAW_POST_2D_TIME); + if(WID && (action & GMSH_GUI) && (num == WID->view_number)) { + WID->view_butt[1]->value(v->Type == DRAW_POST_3D); + WID->view_butt[2]->value(v->Type == DRAW_POST_2D_SPACE); + WID->view_butt[3]->value(v->Type == DRAW_POST_2D_TIME); } #endif return v->Type; } -double opt_view_position0(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ +double opt_view_position0(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Position[0] = (int)val; v->Changed = 1; } @@ -2530,9 +3725,10 @@ double opt_view_position0(OPT_ARGS_NUM){ return v->Position[0]; } -double opt_view_position1(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ +double opt_view_position1(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Position[1] = (int)val; v->Changed = 1; } @@ -2543,23 +3739,25 @@ double opt_view_position1(OPT_ARGS_NUM){ return v->Position[1]; } -double opt_view_auto_position(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ +double opt_view_auto_position(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->AutoPosition = (int)val; v->Changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && (num == WID->view_number)){ + if(WID && (action & GMSH_GUI) && (num == WID->view_number)) { WID->view_butt[7]->value(v->AutoPosition); } #endif return v->AutoPosition; } -double opt_view_size0(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ +double opt_view_size0(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Size[0] = (int)val; v->Changed = 1; } @@ -2570,9 +3768,10 @@ double opt_view_size0(OPT_ARGS_NUM){ return v->Size[0]; } -double opt_view_size1(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ +double opt_view_size1(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Size[1] = (int)val; v->Changed = 1; } @@ -2583,37 +3782,40 @@ double opt_view_size1(OPT_ARGS_NUM){ return v->Size[1]; } -double opt_view_grid(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ +double opt_view_grid(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Grid = (int)val; v->Changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && (num == WID->view_number)){ + if(WID && (action & GMSH_GUI) && (num == WID->view_number)) { WID->view_value[26]->value(v->Grid); } #endif return v->Grid; } -double opt_view_nb_abscissa(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ +double opt_view_nb_abscissa(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->NbAbscissa = (int)val; v->Changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && (num == WID->view_number)){ + if(WID && (action & GMSH_GUI) && (num == WID->view_number)) { WID->view_value[25]->value(v->NbAbscissa); } #endif return v->NbAbscissa; } -double opt_view_nb_iso(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ +double opt_view_nb_iso(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->NbIso = (int)val; v->Changed = 1; } @@ -2623,22 +3825,26 @@ double opt_view_nb_iso(OPT_ARGS_NUM){ #endif return v->NbIso; } -double opt_view_boundary(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_boundary(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Boundary = (int)val; v->Changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && (num == WID->view_number)){ + if(WID && (action & GMSH_GUI) && (num == WID->view_number)) { WID->view_value[11]->value(v->Boundary); } #endif return v->Boundary; } -double opt_view_light(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_light(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->Light = (int)val; v->Changed = 1; } @@ -2648,9 +3854,11 @@ double opt_view_light(OPT_ARGS_NUM){ #endif return v->Light; } -double opt_view_smooth_normals(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_smooth_normals(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->SmoothNormals = (int)val; v->Changed = 1; } @@ -2661,9 +3869,10 @@ double opt_view_smooth_normals(OPT_ARGS_NUM){ return v->SmoothNormals; } -double opt_view_angle_smooth_normals(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ +double opt_view_angle_smooth_normals(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->AngleSmoothNormals = val; v->Changed = 1; } @@ -2673,9 +3882,11 @@ double opt_view_angle_smooth_normals(OPT_ARGS_NUM){ #endif return v->AngleSmoothNormals; } -double opt_view_show_element(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_show_element(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->ShowElement = (int)val; v->Changed = 1; } @@ -2685,9 +3896,11 @@ double opt_view_show_element(OPT_ARGS_NUM){ #endif return v->ShowElement; } -double opt_view_show_time(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_show_time(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->ShowTime = (int)val; } #if defined(HAVE_FLTK) @@ -2696,9 +3909,11 @@ double opt_view_show_time(OPT_ARGS_NUM){ #endif return v->ShowTime; } -double opt_view_show_scale(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_show_scale(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->ShowScale = (int)val; } #if defined(HAVE_FLTK) @@ -2707,9 +3922,11 @@ double opt_view_show_scale(OPT_ARGS_NUM){ #endif return v->ShowScale; } -double opt_view_draw_strings(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_draw_strings(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->DrawStrings = (int)val; v->Changed = 1; } @@ -2719,9 +3936,11 @@ double opt_view_draw_strings(OPT_ARGS_NUM){ #endif return v->DrawStrings; } -double opt_view_draw_points(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_draw_points(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->DrawPoints = (int)val; v->Changed = 1; } @@ -2731,9 +3950,11 @@ double opt_view_draw_points(OPT_ARGS_NUM){ #endif return v->DrawPoints; } -double opt_view_draw_lines(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_draw_lines(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->DrawLines = (int)val; v->Changed = 1; } @@ -2743,9 +3964,11 @@ double opt_view_draw_lines(OPT_ARGS_NUM){ #endif return v->DrawLines; } -double opt_view_draw_triangles(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_draw_triangles(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->DrawTriangles = (int)val; v->Changed = 1; } @@ -2755,9 +3978,11 @@ double opt_view_draw_triangles(OPT_ARGS_NUM){ #endif return v->DrawTriangles; } -double opt_view_draw_quadrangles(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_draw_quadrangles(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->DrawQuadrangles = (int)val; v->Changed = 1; } @@ -2767,9 +3992,11 @@ double opt_view_draw_quadrangles(OPT_ARGS_NUM){ #endif return v->DrawQuadrangles; } -double opt_view_draw_tetrahedra(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_draw_tetrahedra(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->DrawTetrahedra = (int)val; v->Changed = 1; } @@ -2779,9 +4006,11 @@ double opt_view_draw_tetrahedra(OPT_ARGS_NUM){ #endif return v->DrawTetrahedra; } -double opt_view_draw_hexahedra(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_draw_hexahedra(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->DrawHexahedra = (int)val; v->Changed = 1; } @@ -2791,9 +4020,11 @@ double opt_view_draw_hexahedra(OPT_ARGS_NUM){ #endif return v->DrawHexahedra; } -double opt_view_draw_prisms(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_draw_prisms(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->DrawPrisms = (int)val; v->Changed = 1; } @@ -2803,9 +4034,11 @@ double opt_view_draw_prisms(OPT_ARGS_NUM){ #endif return v->DrawPrisms; } -double opt_view_draw_pyramids(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_draw_pyramids(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->DrawPyramids = (int)val; v->Changed = 1; } @@ -2815,9 +4048,11 @@ double opt_view_draw_pyramids(OPT_ARGS_NUM){ #endif return v->DrawPyramids; } -double opt_view_draw_scalars(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_draw_scalars(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->DrawScalars = (int)val; v->Changed = 1; } @@ -2827,9 +4062,11 @@ double opt_view_draw_scalars(OPT_ARGS_NUM){ #endif return v->DrawScalars; } -double opt_view_draw_vectors(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_draw_vectors(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->DrawVectors = (int)val; v->Changed = 1; } @@ -2839,9 +4076,11 @@ double opt_view_draw_vectors(OPT_ARGS_NUM){ #endif return v->DrawVectors; } -double opt_view_draw_tensors(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_draw_tensors(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->DrawTensors = (int)val; v->Changed = 1; } @@ -2851,9 +4090,11 @@ double opt_view_draw_tensors(OPT_ARGS_NUM){ #endif return v->DrawTensors; } -double opt_view_transparent_scale(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_transparent_scale(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->TransparentScale = (int)val; } #if defined(HAVE_FLTK) @@ -2862,89 +4103,125 @@ double opt_view_transparent_scale(OPT_ARGS_NUM){ #endif return v->TransparentScale; } -double opt_view_scale_type(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_scale_type(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->ScaleType = (int)val; v->Changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && (num == WID->view_number)){ - switch(v->ScaleType){ - case DRAW_POST_LINEAR: WID->view_choice[1]->value(0); break; - case DRAW_POST_LOGARITHMIC: WID->view_choice[1]->value(1); break; - case DRAW_POST_DOUBLELOGARITHMIC: WID->view_choice[1]->value(2); break; + if(WID && (action & GMSH_GUI) && (num == WID->view_number)) { + switch (v->ScaleType) { + case DRAW_POST_LINEAR: + WID->view_choice[1]->value(0); + break; + case DRAW_POST_LOGARITHMIC: + WID->view_choice[1]->value(1); + break; + case DRAW_POST_DOUBLELOGARITHMIC: + WID->view_choice[1]->value(2); + break; } } #endif return v->ScaleType; } -double opt_view_range_type(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_range_type(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->RangeType = (int)val; v->Changed = 1; } #if defined(HAVE_FLTK) if(WID && (action & GMSH_GUI) && (num == WID->view_number)) - WID->view_butt[34]->value(v->RangeType==DRAW_POST_CUSTOM); + WID->view_butt[34]->value(v->RangeType == DRAW_POST_CUSTOM); #endif return v->RangeType; } -double opt_view_tensor_type(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_tensor_type(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->TensorType = (int)val; v->Changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && (num == WID->view_number)){ - switch(v->TensorType){ - case DRAW_POST_VONMISES: WID->view_choice[4]->value(0); break; - case DRAW_POST_EIGENVECTORS: WID->view_choice[4]->value(1); break; + if(WID && (action & GMSH_GUI) && (num == WID->view_number)) { + switch (v->TensorType) { + case DRAW_POST_VONMISES: + WID->view_choice[4]->value(0); + break; + case DRAW_POST_EIGENVECTORS: + WID->view_choice[4]->value(1); + break; } } #endif return v->TensorType; } -double opt_view_arrow_type(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_arrow_type(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->ArrowType = (int)val; v->Changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && (num == WID->view_number)){ - switch(v->ArrowType){ - case DRAW_POST_SEGMENT: WID->view_choice[2]->value(0); break; - case DRAW_POST_ARROW: WID->view_choice[2]->value(1); break; - case DRAW_POST_PYRAMID: WID->view_choice[2]->value(2); break; - case DRAW_POST_CONE: WID->view_choice[2]->value(3); break; - case DRAW_POST_DISPLACEMENT: WID->view_choice[2]->value(4); break; + if(WID && (action & GMSH_GUI) && (num == WID->view_number)) { + switch (v->ArrowType) { + case DRAW_POST_SEGMENT: + WID->view_choice[2]->value(0); + break; + case DRAW_POST_ARROW: + WID->view_choice[2]->value(1); + break; + case DRAW_POST_PYRAMID: + WID->view_choice[2]->value(2); + break; + case DRAW_POST_CONE: + WID->view_choice[2]->value(3); + break; + case DRAW_POST_DISPLACEMENT: + WID->view_choice[2]->value(4); + break; } } #endif return v->ArrowType; } -double opt_view_arrow_location(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_arrow_location(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->ArrowLocation = (int)val; v->Changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && (num == WID->view_number)){ - switch(v->ArrowLocation){ - case DRAW_POST_LOCATE_COG: WID->view_choice[3]->value(0); break; - case DRAW_POST_LOCATE_VERTEX: WID->view_choice[3]->value(1); break; + if(WID && (action & GMSH_GUI) && (num == WID->view_number)) { + switch (v->ArrowLocation) { + case DRAW_POST_LOCATE_COG: + WID->view_choice[3]->value(0); + break; + case DRAW_POST_LOCATE_VERTEX: + WID->view_choice[3]->value(1); + break; } } #endif return v->ArrowLocation; } -double opt_view_point_size(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_point_size(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->PointSize = val; v->Changed = 1; } @@ -2954,9 +4231,11 @@ double opt_view_point_size(OPT_ARGS_NUM){ #endif return v->PointSize; } -double opt_view_line_width(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_line_width(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->LineWidth = val; v->Changed = 1; } @@ -2966,96 +4245,125 @@ double opt_view_line_width(OPT_ARGS_NUM){ #endif return v->LineWidth; } -double opt_view_point_type(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_point_type(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->PointType = (int)val; v->Changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && (num == WID->view_number)){ - WID->view_choice[5]->value(v->PointType?1:0); + if(WID && (action & GMSH_GUI) && (num == WID->view_number)) { + WID->view_choice[5]->value(v->PointType ? 1 : 0); } #endif return v->PointType; } -double opt_view_line_type(OPT_ARGS_NUM){ - GET_VIEW(0.) ; - if(action & GMSH_SET){ + +double opt_view_line_type(OPT_ARGS_NUM) +{ + GET_VIEW(0.); + if(action & GMSH_SET) { v->LineType = (int)val; v->Changed = 1; } #if defined(HAVE_FLTK) - if(WID && (action & GMSH_GUI) && (num == WID->view_number)){ - WID->view_choice[6]->value(v->LineType?1:0); + if(WID && (action & GMSH_GUI) && (num == WID->view_number)) { + WID->view_choice[6]->value(v->LineType ? 1 : 0); } #endif return v->LineType; } -double opt_print_format(OPT_ARGS_NUM){ - if(action & GMSH_SET) +double opt_print_format(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.print.format = (int)val; return CTX.print.format; } -double opt_print_eps_quality(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_print_eps_quality(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.print.eps_quality = (int)val; return CTX.print.eps_quality; } -double opt_print_eps_occlusion_culling(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_print_eps_occlusion_culling(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.print.eps_occlusion_culling = (int)val; return CTX.print.eps_occlusion_culling; } -double opt_print_eps_best_root(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_print_eps_best_root(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.print.eps_best_root = (int)val; return CTX.print.eps_best_root; } -double opt_print_eps_background(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_print_eps_background(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.print.eps_background = (int)val; return CTX.print.eps_background; } -double opt_print_eps_font_size(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_print_eps_font_size(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.print.eps_font_size = (int)val; return CTX.print.eps_font_size; } -double opt_print_eps_line_width_factor(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_print_eps_line_width_factor(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.print.eps_line_width_factor = val; return CTX.print.eps_line_width_factor; } -double opt_print_eps_point_size_factor(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_print_eps_point_size_factor(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.print.eps_point_size_factor = val; return CTX.print.eps_point_size_factor; } -double opt_print_jpeg_quality(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_print_jpeg_quality(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.print.jpeg_quality = (int)val; return CTX.print.jpeg_quality; } -double opt_print_gif_dither(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_print_gif_dither(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.print.gif_dither = (int)val; return CTX.print.gif_dither; } -double opt_print_gif_sort(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_print_gif_sort(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.print.gif_sort = (int)val; return CTX.print.gif_sort; } -double opt_print_gif_interlace(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_print_gif_interlace(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.print.gif_interlace = (int)val; return CTX.print.gif_interlace; } -double opt_print_gif_transparent(OPT_ARGS_NUM){ - if(action & GMSH_SET) + +double opt_print_gif_transparent(OPT_ARGS_NUM) +{ + if(action & GMSH_SET) CTX.print.gif_transparent = (int)val; return CTX.print.gif_transparent; } @@ -3080,369 +4388,410 @@ double opt_print_gif_transparent(OPT_ARGS_NUM){ #endif -unsigned int opt_general_color_background(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_general_color_background(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.bg = val; #if defined(HAVE_FLTK) - if(WID) WID->view_colorbar_window->redraw(); + if(WID) + WID->view_colorbar_window->redraw(); #endif } #if defined(HAVE_FLTK) - CCC(CTX.color.bg,WID->gen_col[0]); + CCC(CTX.color.bg, WID->gen_col[0]); #endif return CTX.color.bg; } -unsigned int opt_general_color_foreground(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_general_color_foreground(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.fg = val; #if defined(HAVE_FLTK) - CCC(CTX.color.fg,WID->gen_col[1]); + CCC(CTX.color.fg, WID->gen_col[1]); #endif return CTX.color.fg; } -unsigned int opt_general_color_text(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_general_color_text(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.text = val; #if defined(HAVE_FLTK) - CCC(CTX.color.text,WID->gen_col[2]); + CCC(CTX.color.text, WID->gen_col[2]); #endif return CTX.color.text; } -unsigned int opt_general_color_axes(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_general_color_axes(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.axes = val; #if defined(HAVE_FLTK) - CCC(CTX.color.axes,WID->gen_col[3]); + CCC(CTX.color.axes, WID->gen_col[3]); #endif return CTX.color.axes; } -unsigned int opt_general_color_small_axes(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_general_color_small_axes(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.small_axes = val; #if defined(HAVE_FLTK) - CCC(CTX.color.small_axes,WID->gen_col[4]); + CCC(CTX.color.small_axes, WID->gen_col[4]); #endif return CTX.color.small_axes; } -unsigned int opt_geometry_color_points(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_geometry_color_points(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.geom.point = val; #if defined(HAVE_FLTK) - CCC(CTX.color.geom.point,WID->geo_col[0]); + CCC(CTX.color.geom.point, WID->geo_col[0]); #endif return CTX.color.geom.point; -} -unsigned int opt_geometry_color_lines(OPT_ARGS_COL){ - if(action & GMSH_SET) +} +unsigned int opt_geometry_color_lines(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.geom.line = val; #if defined(HAVE_FLTK) - CCC(CTX.color.geom.line,WID->geo_col[1]); + CCC(CTX.color.geom.line, WID->geo_col[1]); #endif return CTX.color.geom.line; } -unsigned int opt_geometry_color_surfaces(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_geometry_color_surfaces(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.geom.surface = val; #if defined(HAVE_FLTK) - CCC(CTX.color.geom.surface,WID->geo_col[2]); + CCC(CTX.color.geom.surface, WID->geo_col[2]); #endif return CTX.color.geom.surface; } -unsigned int opt_geometry_color_volumes(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_geometry_color_volumes(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.geom.volume = val; #if defined(HAVE_FLTK) - CCC(CTX.color.geom.volume,WID->geo_col[3]); + CCC(CTX.color.geom.volume, WID->geo_col[3]); #endif return CTX.color.geom.volume; } -unsigned int opt_geometry_color_points_select(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_geometry_color_points_select(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.geom.point_sel = val; #if defined(HAVE_FLTK) - CCC(CTX.color.geom.point_sel,WID->geo_col[4]); + CCC(CTX.color.geom.point_sel, WID->geo_col[4]); #endif return CTX.color.geom.point_sel; } -unsigned int opt_geometry_color_lines_select(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_geometry_color_lines_select(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.geom.line_sel = val; #if defined(HAVE_FLTK) - CCC(CTX.color.geom.line_sel,WID->geo_col[5]); + CCC(CTX.color.geom.line_sel, WID->geo_col[5]); #endif return CTX.color.geom.line_sel; } -unsigned int opt_geometry_color_surfaces_select(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_geometry_color_surfaces_select(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.geom.surface_sel = val; #if defined(HAVE_FLTK) - CCC(CTX.color.geom.surface_sel,WID->geo_col[6]); + CCC(CTX.color.geom.surface_sel, WID->geo_col[6]); #endif return CTX.color.geom.surface_sel; } -unsigned int opt_geometry_color_volumes_select(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_geometry_color_volumes_select(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.geom.volume_sel = val; #if defined(HAVE_FLTK) - CCC(CTX.color.geom.volume_sel,WID->geo_col[7]); + CCC(CTX.color.geom.volume_sel, WID->geo_col[7]); #endif return CTX.color.geom.volume_sel; } -unsigned int opt_geometry_color_points_highlight(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_geometry_color_points_highlight(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.geom.point_hlt = val; #if defined(HAVE_FLTK) - CCC(CTX.color.geom.point_hlt,WID->geo_col[8]); + CCC(CTX.color.geom.point_hlt, WID->geo_col[8]); #endif return CTX.color.geom.point_hlt; } -unsigned int opt_geometry_color_lines_highlight(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_geometry_color_lines_highlight(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.geom.line_hlt = val; #if defined(HAVE_FLTK) - CCC(CTX.color.geom.line_hlt,WID->geo_col[9]); + CCC(CTX.color.geom.line_hlt, WID->geo_col[9]); #endif return CTX.color.geom.line_hlt; } -unsigned int opt_geometry_color_surfaces_highlight(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_geometry_color_surfaces_highlight(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.geom.surface_hlt = val; #if defined(HAVE_FLTK) - CCC(CTX.color.geom.surface_hlt,WID->geo_col[10]); + CCC(CTX.color.geom.surface_hlt, WID->geo_col[10]); #endif return CTX.color.geom.surface_hlt; } -unsigned int opt_geometry_color_volumes_highlight(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_geometry_color_volumes_highlight(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.geom.volume_hlt = val; #if defined(HAVE_FLTK) - CCC(CTX.color.geom.volume_hlt,WID->geo_col[11]); + CCC(CTX.color.geom.volume_hlt, WID->geo_col[11]); #endif return CTX.color.geom.volume_hlt; } -unsigned int opt_geometry_color_tangents(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_geometry_color_tangents(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.geom.tangents = val; #if defined(HAVE_FLTK) - CCC(CTX.color.geom.tangents,WID->geo_col[12]); + CCC(CTX.color.geom.tangents, WID->geo_col[12]); #endif return CTX.color.geom.tangents; } -unsigned int opt_geometry_color_normals(OPT_ARGS_COL){ - if(action & GMSH_SET) +unsigned int opt_geometry_color_normals(OPT_ARGS_COL) +{ + if(action & GMSH_SET) CTX.color.geom.normals = val; #if defined(HAVE_FLTK) - CCC(CTX.color.geom.normals,WID->geo_col[13]); + CCC(CTX.color.geom.normals, WID->geo_col[13]); #endif return CTX.color.geom.normals; } -unsigned int opt_mesh_color_points(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_points(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.vertex = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.vertex,WID->mesh_col[0]); + CCC(CTX.color.mesh.vertex, WID->mesh_col[0]); #endif return CTX.color.mesh.vertex; -} -unsigned int opt_mesh_color_points_supp(OPT_ARGS_COL){ - if(action & GMSH_SET){ +} +unsigned int opt_mesh_color_points_supp(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.vertex_supp = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.vertex_supp,WID->mesh_col[1]); + CCC(CTX.color.mesh.vertex_supp, WID->mesh_col[1]); #endif return CTX.color.mesh.vertex_supp; -} -unsigned int opt_mesh_color_lines(OPT_ARGS_COL){ - if(action & GMSH_SET){ +} +unsigned int opt_mesh_color_lines(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.line = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.line,WID->mesh_col[2]); + CCC(CTX.color.mesh.line, WID->mesh_col[2]); #endif return CTX.color.mesh.line; -} -unsigned int opt_mesh_color_triangles(OPT_ARGS_COL){ - if(action & GMSH_SET){ +} +unsigned int opt_mesh_color_triangles(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.triangle = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.triangle,WID->mesh_col[3]); + CCC(CTX.color.mesh.triangle, WID->mesh_col[3]); #endif return CTX.color.mesh.triangle; } -unsigned int opt_mesh_color_quadrangles(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_quadrangles(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.quadrangle = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.quadrangle,WID->mesh_col[4]); + CCC(CTX.color.mesh.quadrangle, WID->mesh_col[4]); #endif return CTX.color.mesh.quadrangle; } -unsigned int opt_mesh_color_tetrahedra(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_tetrahedra(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.tetrahedron = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.tetrahedron,WID->mesh_col[5]); + CCC(CTX.color.mesh.tetrahedron, WID->mesh_col[5]); #endif return CTX.color.mesh.tetrahedron; } -unsigned int opt_mesh_color_hexahedra(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_hexahedra(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.hexahedron = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.hexahedron,WID->mesh_col[6]); + CCC(CTX.color.mesh.hexahedron, WID->mesh_col[6]); #endif return CTX.color.mesh.hexahedron; } -unsigned int opt_mesh_color_prisms(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_prisms(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.prism = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.prism,WID->mesh_col[7]); + CCC(CTX.color.mesh.prism, WID->mesh_col[7]); #endif return CTX.color.mesh.prism; } -unsigned int opt_mesh_color_pyramid(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_pyramid(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.pyramid = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.pyramid,WID->mesh_col[8]); + CCC(CTX.color.mesh.pyramid, WID->mesh_col[8]); #endif return CTX.color.mesh.pyramid; } -unsigned int opt_mesh_color_tangents(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_tangents(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.tangents = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.tangents,WID->mesh_col[9]); + CCC(CTX.color.mesh.tangents, WID->mesh_col[9]); #endif return CTX.color.mesh.tangents; } -unsigned int opt_mesh_color_normals(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_normals(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.normals = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.normals,WID->mesh_col[10]); + CCC(CTX.color.mesh.normals, WID->mesh_col[10]); #endif return CTX.color.mesh.normals; } -unsigned int opt_mesh_color_1(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_1(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.carousel[0] = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.carousel[0],WID->mesh_col[11]); + CCC(CTX.color.mesh.carousel[0], WID->mesh_col[11]); #endif return CTX.color.mesh.carousel[0]; } -unsigned int opt_mesh_color_2(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_2(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.carousel[1] = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.carousel[1],WID->mesh_col[12]); + CCC(CTX.color.mesh.carousel[1], WID->mesh_col[12]); #endif return CTX.color.mesh.carousel[1]; } -unsigned int opt_mesh_color_3(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_3(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.carousel[2] = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.carousel[2],WID->mesh_col[13]); + CCC(CTX.color.mesh.carousel[2], WID->mesh_col[13]); #endif return CTX.color.mesh.carousel[2]; } -unsigned int opt_mesh_color_4(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_4(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.carousel[3] = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.carousel[3],WID->mesh_col[14]); + CCC(CTX.color.mesh.carousel[3], WID->mesh_col[14]); #endif return CTX.color.mesh.carousel[3]; } -unsigned int opt_mesh_color_5(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_5(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.carousel[4] = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.carousel[4],WID->mesh_col[15]); + CCC(CTX.color.mesh.carousel[4], WID->mesh_col[15]); #endif return CTX.color.mesh.carousel[4]; } -unsigned int opt_mesh_color_6(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_6(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.carousel[5] = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.carousel[5],WID->mesh_col[16]); + CCC(CTX.color.mesh.carousel[5], WID->mesh_col[16]); #endif return CTX.color.mesh.carousel[5]; } -unsigned int opt_mesh_color_7(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_7(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.carousel[6] = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.carousel[6],WID->mesh_col[17]); + CCC(CTX.color.mesh.carousel[6], WID->mesh_col[17]); #endif return CTX.color.mesh.carousel[6]; } -unsigned int opt_mesh_color_8(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_8(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.carousel[7] = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.carousel[7],WID->mesh_col[18]); + CCC(CTX.color.mesh.carousel[7], WID->mesh_col[18]); #endif return CTX.color.mesh.carousel[7]; } -unsigned int opt_mesh_color_9(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_9(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.carousel[8] = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.carousel[8],WID->mesh_col[19]); + CCC(CTX.color.mesh.carousel[8], WID->mesh_col[19]); #endif return CTX.color.mesh.carousel[8]; } -unsigned int opt_mesh_color_10(OPT_ARGS_COL){ - if(action & GMSH_SET){ +unsigned int opt_mesh_color_10(OPT_ARGS_COL) +{ + if(action & GMSH_SET) { CTX.color.mesh.carousel[9] = val; CTX.mesh.changed = 1; } #if defined(HAVE_FLTK) - CCC(CTX.color.mesh.carousel[9],WID->mesh_col[20]); + CCC(CTX.color.mesh.carousel[9], WID->mesh_col[20]); #endif return CTX.color.mesh.carousel[9]; } diff --git a/Common/Timer.cpp b/Common/Timer.cpp index b02499c4b9887034ac3e47d33b2f57a30b6d31d1..a953888946a0ca01e9cbc590a83024a90fc29a3a 100644 --- a/Common/Timer.cpp +++ b/Common/Timer.cpp @@ -1,4 +1,4 @@ -// $Id: Timer.cpp,v 1.9 2003-01-24 23:13:34 geuzaine Exp $ +// $Id: Timer.cpp,v 1.10 2003-03-01 22:36:36 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -21,7 +21,9 @@ #include <sys/time.h> #include <unistd.h> -long GetTime(){ + +long GetTime() +{ struct timeval tp; gettimeofday(&tp, (struct timezone *)0); return (long)tp.tv_sec * 1000000 + (long)tp.tv_usec; diff --git a/Common/Views.cpp b/Common/Views.cpp index 85213eee64d9d2f789130e09235440dd5866eb20..238dc0ca1a5dd8c61030a66009efd4a02523114b 100644 --- a/Common/Views.cpp +++ b/Common/Views.cpp @@ -1,4 +1,4 @@ -// $Id: Views.cpp,v 1.88 2003-02-25 16:49:36 geuzaine Exp $ +// $Id: Views.cpp,v 1.89 2003-03-01 22:36:36 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -27,42 +27,46 @@ #include "Options.h" #include "ColorTable.h" -extern Context_T CTX ; +extern Context_T CTX; #define VAL_INF 1.e200 // Static reference view -Post_View *Post_ViewReference = NULL; +Post_View *Post_ViewReference = NULL; // FIXME: the whole View interface should be rewritten in C++... -int fcmpPostViewNum(const void *v1, const void *v2){ - return (((Post_View *)v1)->Num - ((Post_View *)v2)->Num); +int fcmpPostViewNum(const void *v1, const void *v2) +{ + return (((Post_View *) v1)->Num - ((Post_View *) v2)->Num); } -int fcmpPostViewDuplicateOf(const void *v1, const void *v2){ - return (((Post_View *)v1)->DuplicateOf - ((Post_View *)v2)->DuplicateOf); +int fcmpPostViewDuplicateOf(const void *v1, const void *v2) +{ + return (((Post_View *) v1)->DuplicateOf - ((Post_View *) v2)->DuplicateOf); } -Post_View * BeginView(int allocate){ +Post_View *BeginView(int allocate) +{ Post_View vv, *v; - static int UniqueNum=0; + static int UniqueNum = 0; int i; - if(!CTX.post.list) CTX.post.list = List_Create(100,1,sizeof(Post_View)); + if(!CTX.post.list) + CTX.post.list = List_Create(100, 1, sizeof(Post_View)); - if(!CTX.post.force_num){ - vv.Num = ++UniqueNum; // each view _must_ have a unique number + if(!CTX.post.force_num) { + vv.Num = ++UniqueNum; // each view _must_ have a unique number List_Add(CTX.post.list, &vv); } - else{ - vv.Num = CTX.post.force_num; - List_Replace(CTX.post.list,&vv,fcmpPostViewNum); + else { + vv.Num = CTX.post.force_num; + List_Replace(CTX.post.list, &vv, fcmpPostViewNum); } i = List_ISearch(CTX.post.list, &vv, fcmpPostViewNum); - v = (Post_View*)List_Pointer(CTX.post.list, i); + v = (Post_View *) List_Pointer(CTX.post.list, i); v->Index = i; v->Dirty = 1; @@ -78,49 +82,49 @@ Post_View * BeginView(int allocate){ v->NbSY = v->NbVY = v->NbTY = 0; v->NbT2 = v->NbT3 = 0; - if(allocate){ + if(allocate) { v->DataSize = sizeof(double); - v->Time = List_Create(100,1000,sizeof(double)); - - v->SP = List_Create(100,1000,sizeof(double)); - v->VP = List_Create(100,1000,sizeof(double)); - v->TP = List_Create(100,1000,sizeof(double)); - - v->SL = List_Create(100,1000,sizeof(double)); - v->VL = List_Create(100,1000,sizeof(double)); - v->TL = List_Create(100,1000,sizeof(double)); - - v->ST = List_Create(100,1000,sizeof(double)); - v->VT = List_Create(100,1000,sizeof(double)); - v->TT = List_Create(100,1000,sizeof(double)); - - v->SQ = List_Create(100,1000,sizeof(double)); - v->VQ = List_Create(100,1000,sizeof(double)); - v->TQ = List_Create(100,1000,sizeof(double)); - - v->SS = List_Create(100,1000,sizeof(double)); - v->VS = List_Create(100,1000,sizeof(double)); - v->TS = List_Create(100,1000,sizeof(double)); - - v->SH = List_Create(100,1000,sizeof(double)); - v->VH = List_Create(100,1000,sizeof(double)); - v->TH = List_Create(100,1000,sizeof(double)); - - v->SI = List_Create(100,1000,sizeof(double)); - v->VI = List_Create(100,1000,sizeof(double)); - v->TI = List_Create(100,1000,sizeof(double)); - - v->SY = List_Create(100,1000,sizeof(double)); - v->VY = List_Create(100,1000,sizeof(double)); - v->TY = List_Create(100,1000,sizeof(double)); - - v->T2D = List_Create(10,100,sizeof(double)); - v->T2C = List_Create(100,1000,sizeof(char)); - v->T3D = List_Create(10,100,sizeof(double)); - v->T3C = List_Create(100,1000,sizeof(char)); + v->Time = List_Create(100, 1000, sizeof(double)); + + v->SP = List_Create(100, 1000, sizeof(double)); + v->VP = List_Create(100, 1000, sizeof(double)); + v->TP = List_Create(100, 1000, sizeof(double)); + + v->SL = List_Create(100, 1000, sizeof(double)); + v->VL = List_Create(100, 1000, sizeof(double)); + v->TL = List_Create(100, 1000, sizeof(double)); + + v->ST = List_Create(100, 1000, sizeof(double)); + v->VT = List_Create(100, 1000, sizeof(double)); + v->TT = List_Create(100, 1000, sizeof(double)); + + v->SQ = List_Create(100, 1000, sizeof(double)); + v->VQ = List_Create(100, 1000, sizeof(double)); + v->TQ = List_Create(100, 1000, sizeof(double)); + + v->SS = List_Create(100, 1000, sizeof(double)); + v->VS = List_Create(100, 1000, sizeof(double)); + v->TS = List_Create(100, 1000, sizeof(double)); + + v->SH = List_Create(100, 1000, sizeof(double)); + v->VH = List_Create(100, 1000, sizeof(double)); + v->TH = List_Create(100, 1000, sizeof(double)); + + v->SI = List_Create(100, 1000, sizeof(double)); + v->VI = List_Create(100, 1000, sizeof(double)); + v->TI = List_Create(100, 1000, sizeof(double)); + + v->SY = List_Create(100, 1000, sizeof(double)); + v->VY = List_Create(100, 1000, sizeof(double)); + v->TY = List_Create(100, 1000, sizeof(double)); + + v->T2D = List_Create(10, 100, sizeof(double)); + v->T2C = List_Create(100, 1000, sizeof(char)); + v->T3D = List_Create(10, 100, sizeof(double)); + v->T3C = List_Create(100, 1000, sizeof(char)); } - else{ + else { v->Time = NULL; v->SP = v->VP = v->TP = NULL; v->SL = v->VL = v->TL = NULL; @@ -145,100 +149,116 @@ Post_View * BeginView(int allocate){ v->normals = NULL; v->Min = VAL_INF; v->Max = -VAL_INF; - for(i=0;i<3;i++){ - v->BBox[2*i] = VAL_INF; - v->BBox[2*i+1] = -VAL_INF; + for(i = 0; i < 3; i++) { + v->BBox[2 * i] = VAL_INF; + v->BBox[2 * i + 1] = -VAL_INF; } return v; } -void Stat_Element(Post_View *v, int type, int nbnod, int N, - double *X, double *Y, double *Z, double *V){ +void Stat_Element(Post_View * v, int type, int nbnod, int N, + double *X, double *Y, double *Z, double *V) +{ int i; double l0; - switch(type){ + switch (type) { - case 0 : // scalar - if(v->Min == VAL_INF || v->Max == -VAL_INF){ + case 0: // scalar + if(v->Min == VAL_INF || v->Max == -VAL_INF) { v->Min = V[0]; v->Max = V[0]; - v->NbTimeStep = N/nbnod; + v->NbTimeStep = N / nbnod; } - else if(N/nbnod < v->NbTimeStep) - v->NbTimeStep = N/nbnod ; - - for(i=0 ; i<N ; i++){ - if(V[i] < v->Min) v->Min = V[i] ; - if(V[i] > v->Max) v->Max = V[i] ; + else if(N / nbnod < v->NbTimeStep) + v->NbTimeStep = N / nbnod; + + for(i = 0; i < N; i++) { + if(V[i] < v->Min) + v->Min = V[i]; + if(V[i] > v->Max) + v->Max = V[i]; } break; - case 1 : // vector - if(v->Min == VAL_INF || v->Max == -VAL_INF){ - l0 = sqrt(DSQR(V[0])+DSQR(V[1])+DSQR(V[2])); + case 1: // vector + if(v->Min == VAL_INF || v->Max == -VAL_INF) { + l0 = sqrt(DSQR(V[0]) + DSQR(V[1]) + DSQR(V[2])); v->Min = l0; v->Max = l0; - v->NbTimeStep = N/(3*nbnod) ; + v->NbTimeStep = N / (3 * nbnod); } - else if(N/(3*nbnod) < v->NbTimeStep) - v->NbTimeStep = N/(3*nbnod) ; - - for(i=0 ; i<N ; i+=3){ - l0 = sqrt(DSQR(V[i])+DSQR(V[i+1])+DSQR(V[i+2])); - if(l0 < v->Min) v->Min = l0 ; - if(l0 > v->Max) v->Max = l0 ; + else if(N / (3 * nbnod) < v->NbTimeStep) + v->NbTimeStep = N / (3 * nbnod); + + for(i = 0; i < N; i += 3) { + l0 = sqrt(DSQR(V[i]) + DSQR(V[i + 1]) + DSQR(V[i + 2])); + if(l0 < v->Min) + v->Min = l0; + if(l0 > v->Max) + v->Max = l0; } v->ScalarOnly = 0; break; - case 2 : // tensor - TODO! - if(v->Min == VAL_INF || v->Max == -VAL_INF){ - l0 = sqrt(DSQR(V[0])+DSQR(V[4])+DSQR(V[8])); + case 2: // tensor - TODO! + if(v->Min == VAL_INF || v->Max == -VAL_INF) { + l0 = sqrt(DSQR(V[0]) + DSQR(V[4]) + DSQR(V[8])); v->Min = l0; v->Max = l0; - v->NbTimeStep = N/(9*nbnod) ; + v->NbTimeStep = N / (9 * nbnod); } - else if(N/(9*nbnod) < v->NbTimeStep) - v->NbTimeStep = N/(9*nbnod) ; - - for(i=0 ; i<N ; i+=9){ - l0 = sqrt(DSQR(V[i])+DSQR(V[i+4])+DSQR(V[i+8])); - if(l0 < v->Min) v->Min = l0 ; - if(l0 > v->Max) v->Max = l0 ; + else if(N / (9 * nbnod) < v->NbTimeStep) + v->NbTimeStep = N / (9 * nbnod); + + for(i = 0; i < N; i += 9) { + l0 = sqrt(DSQR(V[i]) + DSQR(V[i + 4]) + DSQR(V[i + 8])); + if(l0 < v->Min) + v->Min = l0; + if(l0 > v->Max) + v->Max = l0; } v->ScalarOnly = 0; break; } - for(i=0 ; i<nbnod ; i++){ - if(X[i] < v->BBox[0]) v->BBox[0] = X[i] ; - if(X[i] > v->BBox[1]) v->BBox[1] = X[i] ; - if(Y[i] < v->BBox[2]) v->BBox[2] = Y[i] ; - if(Y[i] > v->BBox[3]) v->BBox[3] = Y[i] ; - if(Z[i] < v->BBox[4]) v->BBox[4] = Z[i] ; - if(Z[i] > v->BBox[5]) v->BBox[5] = Z[i] ; + for(i = 0; i < nbnod; i++) { + if(X[i] < v->BBox[0]) + v->BBox[0] = X[i]; + if(X[i] > v->BBox[1]) + v->BBox[1] = X[i]; + if(Y[i] < v->BBox[2]) + v->BBox[2] = Y[i]; + if(Y[i] > v->BBox[3]) + v->BBox[3] = Y[i]; + if(Z[i] < v->BBox[4]) + v->BBox[4] = Z[i]; + if(Z[i] > v->BBox[5]) + v->BBox[5] = Z[i]; } v->TextOnly = 0; } -void Stat_List(Post_View *v, List_T *listelm, int type, int nbelm, int nbnod){ +void Stat_List(Post_View * v, List_T * listelm, int type, int nbelm, + int nbnod) +{ int i, nb; - if(nbelm){ - nb = List_Nbr(listelm) / nbelm ; - for(i = 0 ; i < List_Nbr(listelm) ; i+=nb) - Stat_Element(v, type, nbnod, nb-3*nbnod, - (double*)List_Pointer_Fast(listelm,i), - (double*)List_Pointer_Fast(listelm,i+1*nbnod), - (double*)List_Pointer_Fast(listelm,i+2*nbnod), - (double*)List_Pointer_Fast(listelm,i+3*nbnod)); + if(nbelm) { + nb = List_Nbr(listelm) / nbelm; + for(i = 0; i < List_Nbr(listelm); i += nb) + Stat_Element(v, type, nbnod, nb - 3 * nbnod, + (double *)List_Pointer_Fast(listelm, i), + (double *)List_Pointer_Fast(listelm, i + 1 * nbnod), + (double *)List_Pointer_Fast(listelm, i + 2 * nbnod), + (double *)List_Pointer_Fast(listelm, i + 3 * nbnod)); } } -void EndView(Post_View *v, int add_in_gui, char *file_name, char *name){ +void EndView(Post_View * v, int add_in_gui, char *file_name, char *name) +{ int i; double d; @@ -246,66 +266,67 @@ void EndView(Post_View *v, int add_in_gui, char *file_name, char *name){ Stat_List(v, v->SP, 0, v->NbSP, 1); Stat_List(v, v->VP, 1, v->NbVP, 1); Stat_List(v, v->TP, 2, v->NbTP, 1); - - // Lines + + // Lines Stat_List(v, v->SL, 0, v->NbSL, 2); Stat_List(v, v->VL, 1, v->NbVL, 2); Stat_List(v, v->TL, 2, v->NbTL, 2); - - // Triangles + + // Triangles Stat_List(v, v->ST, 0, v->NbST, 3); Stat_List(v, v->VT, 1, v->NbVT, 3); Stat_List(v, v->TT, 2, v->NbTT, 3); - + // Quadrangles Stat_List(v, v->SQ, 0, v->NbSQ, 4); Stat_List(v, v->VQ, 1, v->NbVQ, 4); Stat_List(v, v->TQ, 2, v->NbTQ, 4); - - // Tetrahedra + + // Tetrahedra Stat_List(v, v->SS, 0, v->NbSS, 4); Stat_List(v, v->VS, 1, v->NbVS, 4); Stat_List(v, v->TS, 2, v->NbTS, 4); - - // Hexahedra + + // Hexahedra Stat_List(v, v->SH, 0, v->NbSH, 8); Stat_List(v, v->VH, 1, v->NbVH, 8); Stat_List(v, v->TH, 2, v->NbTH, 8); - - // Prisms + + // Prisms Stat_List(v, v->SI, 0, v->NbSI, 6); Stat_List(v, v->VI, 1, v->NbVI, 6); Stat_List(v, v->TI, 2, v->NbTI, 6); - - // Pyramids + + // Pyramids Stat_List(v, v->SY, 0, v->NbSY, 5); Stat_List(v, v->VY, 1, v->NbVY, 5); Stat_List(v, v->TY, 2, v->NbTY, 5); // Dummy time values if using old parsed format - if(v->Time && !List_Nbr(v->Time)){ - for(i=0 ; i<v->NbTimeStep ; i++){ + if(v->Time && !List_Nbr(v->Time)) { + for(i = 0; i < v->NbTimeStep; i++) { d = (double)i; List_Add(v->Time, &d); } } - opt_view_name(v->Index, GMSH_SET|GMSH_GUI, name); - opt_view_filename(v->Index, GMSH_SET|GMSH_GUI, file_name); + opt_view_name(v->Index, GMSH_SET | GMSH_GUI, name); + opt_view_filename(v->Index, GMSH_SET | GMSH_GUI, file_name); opt_view_nb_timestep(v->Index, GMSH_GUI, 0); - opt_view_timestep(v->Index, GMSH_SET|GMSH_GUI, v->TimeStep); - if(v->Min > v->Max){ - opt_view_min(v->Index, GMSH_SET|GMSH_GUI, 0.); - opt_view_max(v->Index, GMSH_SET|GMSH_GUI, 0.); + opt_view_timestep(v->Index, GMSH_SET | GMSH_GUI, v->TimeStep); + if(v->Min > v->Max) { + opt_view_min(v->Index, GMSH_SET | GMSH_GUI, 0.); + opt_view_max(v->Index, GMSH_SET | GMSH_GUI, 0.); } - else{ + else { opt_view_min(v->Index, GMSH_GUI, 0); opt_view_max(v->Index, GMSH_GUI, 0); } - opt_view_custom_min(v->Index, GMSH_SET|GMSH_GUI, v->Min); - opt_view_custom_max(v->Index, GMSH_SET|GMSH_GUI, v->Max); + opt_view_custom_min(v->Index, GMSH_SET | GMSH_GUI, v->Min); + opt_view_custom_max(v->Index, GMSH_SET | GMSH_GUI, v->Max); - if(CTX.post.smooth) v->smooth(); + if(CTX.post.smooth) + v->smooth(); #if defined(HAVE_FLTK) extern int AddViewInUI(int, char *, int); @@ -316,30 +337,33 @@ void EndView(Post_View *v, int add_in_gui, char *file_name, char *name){ v->Dirty = 0; //the view is complete, we may draw it } -void DuplicateView(int num, int withoptions){ - if(!CTX.post.list || num < 0 || num >= List_Nbr(CTX.post.list)) return; - DuplicateView((Post_View*)List_Pointer(CTX.post.list,num), withoptions); +void DuplicateView(int num, int withoptions) +{ + if(!CTX.post.list || num < 0 || num >= List_Nbr(CTX.post.list)) + return; + DuplicateView((Post_View *) List_Pointer(CTX.post.list, num), withoptions); } -void DuplicateView(Post_View *v1, int withoptions){ - Post_View v, *v2, *v3 ; +void DuplicateView(Post_View * v1, int withoptions) +{ + Post_View v, *v2, *v3; v2 = BeginView(0); EndView(v2, 0, v1->FileName, v1->Name); - if(!v1->DuplicateOf){ - v2->DuplicateOf = v1->Num ; - v1->Links++ ; + if(!v1->DuplicateOf) { + v2->DuplicateOf = v1->Num; + v1->Links++; } - else{ - v.Num = v1->DuplicateOf ; - if(!(v3 = (Post_View*)List_PQuery(CTX.post.list, &v, fcmpPostViewNum))){ - v2->DuplicateOf = v1->Num ; - v1->Links++ ; + else { + v.Num = v1->DuplicateOf; + if(!(v3 = (Post_View *) List_PQuery(CTX.post.list, &v, fcmpPostViewNum))) { + v2->DuplicateOf = v1->Num; + v1->Links++; } - else{ + else { v2->DuplicateOf = v3->Num; - v3->Links++ ; + v3->Links++; } } @@ -394,8 +418,9 @@ void DuplicateView(Post_View *v1, int withoptions){ v2->BBox[i] = v1->BBox[i]; // *INDENT-ON* - - if(withoptions) CopyViewOptions(v1, v2); + + if(withoptions) + CopyViewOptions(v1, v2); #if defined(HAVE_FLTK) extern int AddViewInUI(int, char *, int); @@ -403,52 +428,56 @@ void DuplicateView(Post_View *v1, int withoptions){ #endif } -bool FreeView(int num){ +bool FreeView(int num) +{ Post_View *v; - Msg(DEBUG, "Trying to free view %d",num); - - if(num < 0 || num >= List_Nbr(CTX.post.list)){ - return false ; + Msg(DEBUG, "Trying to free view %d", num); + + if(num < 0 || num >= List_Nbr(CTX.post.list)) { + return false; } - v = (Post_View*)List_Pointer(CTX.post.list, num); + v = (Post_View *) List_Pointer(CTX.post.list, num); FreeView(v); List_PSuppress(CTX.post.list, num); - Msg(INFO, "View %d deleted (%d views left)",num, List_Nbr(CTX.post.list)); + Msg(INFO, "View %d deleted (%d views left)", num, List_Nbr(CTX.post.list)); return true; } -void FreeView(Post_View *v){ - Post_View vv,*v2; +void FreeView(Post_View * v) +{ + Post_View vv, *v2; int i, numdup, free = 1; - if(v->DuplicateOf){ - vv.Num = v->DuplicateOf ; + if(v->DuplicateOf) { + vv.Num = v->DuplicateOf; Msg(DEBUG, "This view is a duplicata"); - if(!(v2 = (Post_View*)List_PQuery(CTX.post.list, &vv, fcmpPostViewNum))){ + if(!(v2 = (Post_View *) List_PQuery(CTX.post.list, &vv, fcmpPostViewNum))) { Msg(DEBUG, " -the original view is gone"); numdup = 0; - for(i=0 ; i<List_Nbr(CTX.post.list); i++) - numdup += (((Post_View*)List_Pointer(CTX.post.list, i))->DuplicateOf == v->DuplicateOf); - if(numdup == 1){ + for(i = 0; i < List_Nbr(CTX.post.list); i++) + numdup += + (((Post_View *) List_Pointer(CTX.post.list, i))->DuplicateOf == + v->DuplicateOf); + if(numdup == 1) { Msg(DEBUG, " -there are no other duplicata, so I can free"); - free = 1 ; + free = 1; } - else{ + else { Msg(DEBUG, " -there are still duplicata, so I cannot free"); - free = 0 ; + free = 0; } } - else{ + else { v2->Links--; - free = 0 ; + free = 0; Msg(DEBUG, " -the original still exists, so I cannot free"); } } - if(free && !v->Links){ + if(free && !v->Links) { Msg(DEBUG, "FREEING VIEW"); List_Delete(v->Time); // *INDENT-OFF* @@ -482,7 +511,8 @@ void FreeView(Post_View *v){ } -void CopyViewOptions(Post_View *src, Post_View *dest){ +void CopyViewOptions(Post_View * src, Post_View * dest) +{ dest->Type = src->Type; dest->Position[0] = src->Position[0]; dest->Position[1] = src->Position[1]; @@ -505,12 +535,12 @@ void CopyViewOptions(Post_View *src, Post_View *dest){ dest->Visible = src->Visible; dest->IntervalsType = src->IntervalsType; dest->SaturateValues = src->SaturateValues; - dest->Boundary = src->Boundary ; + dest->Boundary = src->Boundary; dest->NbAbscissa = src->NbAbscissa; dest->NbIso = src->NbIso; - dest->Light = src->Light ; - dest->SmoothNormals = src->SmoothNormals ; - dest->AngleSmoothNormals = src->AngleSmoothNormals ; + dest->Light = src->Light; + dest->SmoothNormals = src->SmoothNormals; + dest->AngleSmoothNormals = src->AngleSmoothNormals; dest->ShowElement = src->ShowElement; dest->ShowTime = src->ShowTime; dest->ShowScale = src->ShowScale; @@ -542,50 +572,60 @@ void CopyViewOptions(Post_View *src, Post_View *dest){ ColorTable_Paste(&dest->CT); } -GmshColorTable *Get_ColorTable(int num){ +GmshColorTable *Get_ColorTable(int num) +{ Post_View *v; if(!CTX.post.list) - v = Post_ViewReference ; + v = Post_ViewReference; else - v = (Post_View*)List_Pointer_Test(CTX.post.list, num); + v = (Post_View *) List_Pointer_Test(CTX.post.list, num); if(v) - return &v->CT ; + return &v->CT; else - return NULL ; + return NULL; } -void Print_ColorTable(int num, char *prefix, FILE *file){ +void Print_ColorTable(int num, char *prefix, FILE * file) +{ char tmp[1024]; Post_View *v; if(!CTX.post.list) - v = Post_ViewReference ; + v = Post_ViewReference; else - v = (Post_View*)List_Pointer_Test(CTX.post.list, num); - if(!v) return; + v = (Post_View *) List_Pointer_Test(CTX.post.list, num); + if(!v) + return; sprintf(tmp, "%s = {", prefix); - if(file) fprintf(file, "%s\n", tmp); else Msg(DIRECT, tmp); + if(file) + fprintf(file, "%s\n", tmp); + else + Msg(DIRECT, tmp); ColorTable_Print(&v->CT, file); sprintf(tmp, "};"); - if(file) fprintf(file, "%s\n", tmp); else Msg(DIRECT, tmp); + if(file) + fprintf(file, "%s\n", tmp); + else + Msg(DIRECT, tmp); } -Post_View *Create2DGraph(char *xname, char *yname, - int nbdata, double *x, double *y){ +Post_View *Create2DGraph(char *xname, char *yname, + int nbdata, double *x, double *y) +{ int i; - double d=0.; + double d = 0.; char filename[1024]; Post_View *v; v = BeginView(1); - for(i=0;i<nbdata;i++){ + for(i = 0; i < nbdata; i++) { List_Add(v->SP, &x[i]); List_Add(v->SP, &d); List_Add(v->SP, &d); List_Add(v->SP, &y[i]); v->NbSP++; } - sprintf(filename,"%s.pos",yname); + sprintf(filename, "%s.pos", yname); EndView(v, 1, filename, yname); v->Type = DRAW_POST_2D_SPACE; strcpy(v->AbscissaName, xname); @@ -594,106 +634,110 @@ Post_View *Create2DGraph(char *xname, char *yname, // INput/output -void ReadView(FILE *file, char *filename){ - char str[256], name[256]; - int i, nb, format, size, testone, swap, t2l, t3l; +void ReadView(FILE * file, char *filename) +{ + char str[256], name[256]; + int i, nb, format, size, testone, swap, t2l, t3l; double version; Post_View *v; - while (1) { + while(1) { - do { - fgets(str, 256, file) ; - if (feof(file)) break ; - } while (str[0] != '$') ; + do { + fgets(str, 256, file); + if(feof(file)) + break; + } while(str[0] != '$'); - if (feof(file)) break ; + if(feof(file)) + break; /* F o r m a t */ - if (!strncmp(&str[1], "PostFormat", 10)){ - fscanf(file, "%lf %d %d\n", &version, &format, &size) ; - if(version < 1.0){ - Msg(GERROR, "The version of this post-processing file is too old (%g < 1.0)", version); + if(!strncmp(&str[1], "PostFormat", 10)) { + fscanf(file, "%lf %d %d\n", &version, &format, &size); + if(version < 1.0) { + Msg(GERROR, + "The version of this post-processing file is too old (%g < 1.0)", + version); return; } if(size == sizeof(double)) - Msg(DEBUG, "Data is in double precision format (size==%d)", size); + Msg(DEBUG, "Data is in double precision format (size==%d)", size); else if(size == sizeof(float)) - Msg(DEBUG, "Data is in single precision format (size==%d)", size); - else{ - Msg(GERROR, "Unknown type of data (size = %d) in post-processing file", - size); + Msg(DEBUG, "Data is in single precision format (size==%d)", size); + else { + Msg(GERROR, + "Unknown type of data (size = %d) in post-processing file", size); return; } if(format == 0) - format = LIST_FORMAT_ASCII ; + format = LIST_FORMAT_ASCII; else if(format == 1) - format = LIST_FORMAT_BINARY ; - else{ - Msg(GERROR, "Unknown format for view"); - return ; + format = LIST_FORMAT_BINARY; + else { + Msg(GERROR, "Unknown format for view"); + return; } } /* V i e w */ - if (!strncmp(&str[1], "View", 4)) { + if(!strncmp(&str[1], "View", 4)) { v = BeginView(0); - if(version <= 1.0){ - fscanf(file, "%s %d %d %d %d %d %d %d %d %d %d %d %d %d\n", - name, &v->NbTimeStep, - &v->NbSP, &v->NbVP, &v->NbTP, - &v->NbSL, &v->NbVL, &v->NbTL, - &v->NbST, &v->NbVT, &v->NbTT, - &v->NbSS, &v->NbVS, &v->NbTS); - v->NbT2 = t2l = v->NbT3 = t3l = 0; - Msg(INFO, "Detected version <= 1.0"); + if(version <= 1.0) { + fscanf(file, "%s %d %d %d %d %d %d %d %d %d %d %d %d %d\n", + name, &v->NbTimeStep, + &v->NbSP, &v->NbVP, &v->NbTP, + &v->NbSL, &v->NbVL, &v->NbTL, + &v->NbST, &v->NbVT, &v->NbTT, &v->NbSS, &v->NbVS, &v->NbTS); + v->NbT2 = t2l = v->NbT3 = t3l = 0; + Msg(INFO, "Detected version <= 1.0"); } - else if(version == 1.1){ - fscanf(file, "%s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", - name, &v->NbTimeStep, - &v->NbSP, &v->NbVP, &v->NbTP, - &v->NbSL, &v->NbVL, &v->NbTL, - &v->NbST, &v->NbVT, &v->NbTT, - &v->NbSS, &v->NbVS, &v->NbTS, - &v->NbT2, &t2l, &v->NbT3, &t3l); - Msg(INFO, "Detected version 1.1"); + else if(version == 1.1) { + fscanf(file, + "%s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", + name, &v->NbTimeStep, &v->NbSP, &v->NbVP, &v->NbTP, &v->NbSL, + &v->NbVL, &v->NbTL, &v->NbST, &v->NbVT, &v->NbTT, &v->NbSS, + &v->NbVS, &v->NbTS, &v->NbT2, &t2l, &v->NbT3, &t3l); + Msg(INFO, "Detected version 1.1"); } - else if(version == 1.2){ - fscanf(file, "%s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d " - "%d %d %d %d %d %d %d %d %d %d %d %d %d\n", - name, &v->NbTimeStep, - &v->NbSP, &v->NbVP, &v->NbTP, - &v->NbSL, &v->NbVL, &v->NbTL, - &v->NbST, &v->NbVT, &v->NbTT, - &v->NbSQ, &v->NbVQ, &v->NbTQ, - &v->NbSS, &v->NbVS, &v->NbTS, - &v->NbSH, &v->NbVH, &v->NbTH, - &v->NbSI, &v->NbVI, &v->NbTI, - &v->NbSY, &v->NbVY, &v->NbTY, - &v->NbT2, &t2l, &v->NbT3, &t3l); - Msg(INFO, "Detected version 1.2"); + else if(version == 1.2) { + fscanf(file, "%s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d " + "%d %d %d %d %d %d %d %d %d %d %d %d %d\n", + name, &v->NbTimeStep, + &v->NbSP, &v->NbVP, &v->NbTP, + &v->NbSL, &v->NbVL, &v->NbTL, + &v->NbST, &v->NbVT, &v->NbTT, + &v->NbSQ, &v->NbVQ, &v->NbTQ, + &v->NbSS, &v->NbVS, &v->NbTS, + &v->NbSH, &v->NbVH, &v->NbTH, + &v->NbSI, &v->NbVI, &v->NbTI, + &v->NbSY, &v->NbVY, &v->NbTY, &v->NbT2, &t2l, &v->NbT3, &t3l); + Msg(INFO, "Detected version 1.2"); } - else{ - Msg(GERROR, "Unknown post-processing file format (version %g)", version); - return; + else { + Msg(GERROR, "Unknown post-processing file format (version %g)", + version); + return; } - for(i=0;i<(int)strlen(name);i++) if(name[i]=='^') name[i]=' '; - - swap = 0 ; - if(format == LIST_FORMAT_BINARY){ - fread(&testone, sizeof(int), 1, file); - if(testone != 1){ - Msg(INFO, "Swapping bytes from binary file"); - swap = 1; - } + for(i = 0; i < (int)strlen(name); i++) + if(name[i] == '^') + name[i] = ' '; + + swap = 0; + if(format == LIST_FORMAT_BINARY) { + fread(&testone, sizeof(int), 1, file); + if(testone != 1) { + Msg(INFO, "Swapping bytes from binary file"); + swap = 1; + } } - v->DataSize = size ; + v->DataSize = size; // Time values v->Time = List_CreateFromFile(v->NbTimeStep, size, file, format, swap); @@ -701,98 +745,111 @@ void ReadView(FILE *file, char *filename){ #define LL List_CreateFromFile(nb, size, file, format, swap) // Points - nb = v->NbSP ? v->NbSP * (v->NbTimeStep +3) : 0 ; v->SP = LL; - nb = v->NbVP ? v->NbVP * (v->NbTimeStep*3+3) : 0 ; v->VP = LL; - nb = v->NbTP ? v->NbTP * (v->NbTimeStep*9+3) : 0 ; v->TP = LL; + nb = v->NbSP ? v->NbSP * (v->NbTimeStep + 3) : 0; + v->SP = LL; + nb = v->NbVP ? v->NbVP * (v->NbTimeStep * 3 + 3) : 0; + v->VP = LL; + nb = v->NbTP ? v->NbTP * (v->NbTimeStep * 9 + 3) : 0; + v->TP = LL; // Lines - nb = v->NbSL ? v->NbSL * (v->NbTimeStep*2 +6) : 0 ; v->SL = LL; - nb = v->NbVL ? v->NbVL * (v->NbTimeStep*2*3+6) : 0 ; v->VL = LL; - nb = v->NbTL ? v->NbTL * (v->NbTimeStep*2*9+6) : 0 ; v->TL = LL; + nb = v->NbSL ? v->NbSL * (v->NbTimeStep * 2 + 6) : 0; + v->SL = LL; + nb = v->NbVL ? v->NbVL * (v->NbTimeStep * 2 * 3 + 6) : 0; + v->VL = LL; + nb = v->NbTL ? v->NbTL * (v->NbTimeStep * 2 * 9 + 6) : 0; + v->TL = LL; // Triangles - nb = v->NbST ? v->NbST * (v->NbTimeStep*3 +9) : 0 ; v->ST = LL; - nb = v->NbVT ? v->NbVT * (v->NbTimeStep*3*3+9) : 0 ; v->VT = LL; - nb = v->NbTT ? v->NbTT * (v->NbTimeStep*3*9+9) : 0 ; v->TT = LL; + nb = v->NbST ? v->NbST * (v->NbTimeStep * 3 + 9) : 0; + v->ST = LL; + nb = v->NbVT ? v->NbVT * (v->NbTimeStep * 3 * 3 + 9) : 0; + v->VT = LL; + nb = v->NbTT ? v->NbTT * (v->NbTimeStep * 3 * 9 + 9) : 0; + v->TT = LL; // Quadrangles - nb = v->NbSQ ? v->NbSQ * (v->NbTimeStep*4 +12) : 0 ; v->SQ = LL; - nb = v->NbVQ ? v->NbVQ * (v->NbTimeStep*4*3+12) : 0 ; v->VQ = LL; - nb = v->NbTQ ? v->NbTQ * (v->NbTimeStep*4*9+12) : 0 ; v->TQ = LL; + nb = v->NbSQ ? v->NbSQ * (v->NbTimeStep * 4 + 12) : 0; + v->SQ = LL; + nb = v->NbVQ ? v->NbVQ * (v->NbTimeStep * 4 * 3 + 12) : 0; + v->VQ = LL; + nb = v->NbTQ ? v->NbTQ * (v->NbTimeStep * 4 * 9 + 12) : 0; + v->TQ = LL; // Tetrahedra - nb = v->NbSS ? v->NbSS * (v->NbTimeStep*4 +12) : 0 ; v->SS = LL; - nb = v->NbVS ? v->NbVS * (v->NbTimeStep*4*3+12) : 0 ; v->VS = LL; - nb = v->NbTS ? v->NbTS * (v->NbTimeStep*4*9+12) : 0 ; v->TS = LL; + nb = v->NbSS ? v->NbSS * (v->NbTimeStep * 4 + 12) : 0; + v->SS = LL; + nb = v->NbVS ? v->NbVS * (v->NbTimeStep * 4 * 3 + 12) : 0; + v->VS = LL; + nb = v->NbTS ? v->NbTS * (v->NbTimeStep * 4 * 9 + 12) : 0; + v->TS = LL; // Hexahedra - nb = v->NbSH ? v->NbSH * (v->NbTimeStep*8 +24) : 0 ; v->SH = LL; - nb = v->NbVH ? v->NbVH * (v->NbTimeStep*8*3+24) : 0 ; v->VH = LL; - nb = v->NbTH ? v->NbTH * (v->NbTimeStep*8*9+24) : 0 ; v->TH = LL; + nb = v->NbSH ? v->NbSH * (v->NbTimeStep * 8 + 24) : 0; + v->SH = LL; + nb = v->NbVH ? v->NbVH * (v->NbTimeStep * 8 * 3 + 24) : 0; + v->VH = LL; + nb = v->NbTH ? v->NbTH * (v->NbTimeStep * 8 * 9 + 24) : 0; + v->TH = LL; // Prisms - nb = v->NbSI ? v->NbSI * (v->NbTimeStep*6 +18) : 0 ; v->SI = LL; - nb = v->NbVI ? v->NbVI * (v->NbTimeStep*6*3+18) : 0 ; v->VI = LL; - nb = v->NbTI ? v->NbTI * (v->NbTimeStep*6*9+18) : 0 ; v->TI = LL; + nb = v->NbSI ? v->NbSI * (v->NbTimeStep * 6 + 18) : 0; + v->SI = LL; + nb = v->NbVI ? v->NbVI * (v->NbTimeStep * 6 * 3 + 18) : 0; + v->VI = LL; + nb = v->NbTI ? v->NbTI * (v->NbTimeStep * 6 * 9 + 18) : 0; + v->TI = LL; // Pyramids - nb = v->NbSY ? v->NbSY * (v->NbTimeStep*5 +15) : 0 ; v->SY = LL; - nb = v->NbVY ? v->NbVY * (v->NbTimeStep*5*3+15) : 0 ; v->VY = LL; - nb = v->NbTY ? v->NbTY * (v->NbTimeStep*5*9+15) : 0 ; v->TY = LL; + nb = v->NbSY ? v->NbSY * (v->NbTimeStep * 5 + 15) : 0; + v->SY = LL; + nb = v->NbVY ? v->NbVY * (v->NbTimeStep * 5 * 3 + 15) : 0; + v->VY = LL; + nb = v->NbTY ? v->NbTY * (v->NbTimeStep * 5 * 9 + 15) : 0; + v->TY = LL; #undef LL // Strings - nb = v->NbT2 ? v->NbT2 * 4 : 0 ; + nb = v->NbT2 ? v->NbT2 * 4 : 0; v->T2D = List_CreateFromFile(nb, size, file, format, swap); - v->T2C = List_CreateFromFile(t2l, sizeof(char), file, format, swap); + v->T2C = List_CreateFromFile(t2l, sizeof(char), file, format, swap); - nb = v->NbT3 ? v->NbT3 * 5 : 0 ; + nb = v->NbT3 ? v->NbT3 * 5 : 0; v->T3D = List_CreateFromFile(nb, size, file, format, swap); - v->T3C = List_CreateFromFile(t3l, sizeof(char), file, format, swap); - - - Msg(DEBUG, "Read View '%s' (%d TimeSteps): %d %d %d %d %d %d %d %d %d %d %d " - "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", - name, v->NbTimeStep, - v->NbSP, v->NbVP, v->NbTP, - v->NbSL, v->NbVL, v->NbTL, - v->NbST, v->NbVT, v->NbTT, - v->NbSQ, v->NbVQ, v->NbTQ, - v->NbSS, v->NbVS, v->NbTS, - v->NbSH, v->NbVH, v->NbTH, - v->NbSI, v->NbVI, v->NbTI, - v->NbSY, v->NbVY, v->NbTY, - v->NbT2, v->NbT3); - Msg(DEBUG, "List_Nbrs: " - "SP%d VP%d TP%d " - "SL%d VL%d TL%d " - "ST%d VT%d TT%d " - "SQ%d VQ%d TQ%d " - "SS%d VS%d TS%d " - "SH%d VH%d TH%d " - "SI%d VI%d TI%d " - "SY%d VY%d TY%d " - "T2D%d T2C%d T3D%d T3C%d", - List_Nbr(v->SP), List_Nbr(v->VP), List_Nbr(v->TP), - List_Nbr(v->SL), List_Nbr(v->VL), List_Nbr(v->TL), - List_Nbr(v->ST), List_Nbr(v->VT), List_Nbr(v->TT), - List_Nbr(v->SQ), List_Nbr(v->VQ), List_Nbr(v->TQ), - List_Nbr(v->SS), List_Nbr(v->VS), List_Nbr(v->TS), - List_Nbr(v->SH), List_Nbr(v->VH), List_Nbr(v->TH), - List_Nbr(v->SI), List_Nbr(v->VI), List_Nbr(v->TI), - List_Nbr(v->SY), List_Nbr(v->VY), List_Nbr(v->TY), - List_Nbr(v->T2D), List_Nbr(v->T2C), List_Nbr(v->T3D), List_Nbr(v->T3C)); - - EndView(v, 1, filename, name); + v->T3C = List_CreateFromFile(t3l, sizeof(char), file, format, swap); + + + Msg(DEBUG, + "Read View '%s' (%d TimeSteps): %d %d %d %d %d %d %d %d %d %d %d " + "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", name, v->NbTimeStep, + v->NbSP, v->NbVP, v->NbTP, v->NbSL, v->NbVL, v->NbTL, v->NbST, + v->NbVT, v->NbTT, v->NbSQ, v->NbVQ, v->NbTQ, v->NbSS, v->NbVS, + v->NbTS, v->NbSH, v->NbVH, v->NbTH, v->NbSI, v->NbVI, v->NbTI, + v->NbSY, v->NbVY, v->NbTY, v->NbT2, v->NbT3); + Msg(DEBUG, + "List_Nbrs: " "SP%d VP%d TP%d " "SL%d VL%d TL%d " "ST%d VT%d TT%d " + "SQ%d VQ%d TQ%d " "SS%d VS%d TS%d " "SH%d VH%d TH%d " + "SI%d VI%d TI%d " "SY%d VY%d TY%d " "T2D%d T2C%d T3D%d T3C%d", + List_Nbr(v->SP), List_Nbr(v->VP), List_Nbr(v->TP), List_Nbr(v->SL), + List_Nbr(v->VL), List_Nbr(v->TL), List_Nbr(v->ST), List_Nbr(v->VT), + List_Nbr(v->TT), List_Nbr(v->SQ), List_Nbr(v->VQ), List_Nbr(v->TQ), + List_Nbr(v->SS), List_Nbr(v->VS), List_Nbr(v->TS), List_Nbr(v->SH), + List_Nbr(v->VH), List_Nbr(v->TH), List_Nbr(v->SI), List_Nbr(v->VI), + List_Nbr(v->TI), List_Nbr(v->SY), List_Nbr(v->VY), List_Nbr(v->TY), + List_Nbr(v->T2D), List_Nbr(v->T2C), List_Nbr(v->T3D), + List_Nbr(v->T3C)); + + EndView(v, 1, filename, name); } do { - fgets(str, 256, file) ; - if (feof(file)) Msg(GERROR,"Prematured end of file"); - } while (str[0] != '$') ; + fgets(str, 256, file); + if(feof(file)) + Msg(GERROR, "Prematured end of file"); + } while(str[0] != '$'); - } /* while 1 ... */ + } /* while 1 ... */ } @@ -800,14 +857,15 @@ void ReadView(FILE *file, char *filename){ // FIXME: add a format similar to the msh format (node list + simplex list) // FIXME: add a structured format -void WriteView(int Flag_BIN, Post_View *v, char *filename){ +void WriteView(int Flag_BIN, Post_View * v, char *filename) +{ FILE *file; char name[256]; - int i, f, One=1; + int i, f, One = 1; - if(filename){ - file = fopen(filename,"w"); - if(!file){ + if(filename) { + file = fopen(filename, "w"); + if(!file) { Msg(GERROR, "Unable to open file '%s'", filename); return; } @@ -815,55 +873,68 @@ void WriteView(int Flag_BIN, Post_View *v, char *filename){ else file = stdout; - fprintf(file, "$PostFormat /* Gmsh 1.2, %s */\n", Flag_BIN ? "binary" : "ascii") ; - fprintf(file, "1.2 %d %d\n", Flag_BIN, (int)sizeof(double)) ; - fprintf(file, "$EndPostFormat\n") ; + fprintf(file, "$PostFormat /* Gmsh 1.2, %s */\n", + Flag_BIN ? "binary" : "ascii"); + fprintf(file, "1.2 %d %d\n", Flag_BIN, (int)sizeof(double)); + fprintf(file, "$EndPostFormat\n"); - for(i=0;i<(int)strlen(v->Name);i++){ - if(v->Name[i]==' ') name[i]='^'; - else name[i]=v->Name[i]; + for(i = 0; i < (int)strlen(v->Name); i++) { + if(v->Name[i] == ' ') + name[i] = '^'; + else + name[i] = v->Name[i]; } - name[i]='\0'; + name[i] = '\0'; fprintf(file, "$View /* %s */\n", v->Name); fprintf(file, "%s ", name); fprintf(file, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d " - "%d %d %d %d %d %d %d %d %d %d %d %d\n", - List_Nbr(v->Time), - v->NbSP, v->NbVP, v->NbTP, v->NbSL, v->NbVL, v->NbTL, - v->NbST, v->NbVT, v->NbTT, v->NbSQ, v->NbVQ, v->NbTQ, - v->NbSS, v->NbVS, v->NbTS, v->NbSH, v->NbVH, v->NbTH, - v->NbSI, v->NbVI, v->NbTI, v->NbSY, v->NbVY, v->NbTY, - v->NbT2, List_Nbr(v->T2C), v->NbT3, List_Nbr(v->T3C)); - if(Flag_BIN){ + "%d %d %d %d %d %d %d %d %d %d %d %d\n", + List_Nbr(v->Time), + v->NbSP, v->NbVP, v->NbTP, v->NbSL, v->NbVL, v->NbTL, + v->NbST, v->NbVT, v->NbTT, v->NbSQ, v->NbVQ, v->NbTQ, + v->NbSS, v->NbVS, v->NbTS, v->NbSH, v->NbVH, v->NbTH, + v->NbSI, v->NbVI, v->NbTI, v->NbSY, v->NbVY, v->NbTY, + v->NbT2, List_Nbr(v->T2C), v->NbT3, List_Nbr(v->T3C)); + if(Flag_BIN) { f = LIST_FORMAT_BINARY; fwrite(&One, sizeof(int), 1, file); } else f = LIST_FORMAT_ASCII; - List_WriteToFile(v->Time, file, f); - List_WriteToFile(v->SP, file, f); List_WriteToFile(v->VP, file, f); + List_WriteToFile(v->Time, file, f); + List_WriteToFile(v->SP, file, f); + List_WriteToFile(v->VP, file, f); List_WriteToFile(v->TP, file, f); - List_WriteToFile(v->SL, file, f); List_WriteToFile(v->VL, file, f); + List_WriteToFile(v->SL, file, f); + List_WriteToFile(v->VL, file, f); List_WriteToFile(v->TL, file, f); - List_WriteToFile(v->ST, file, f); List_WriteToFile(v->VT, file, f); - List_WriteToFile(v->TT, file, f); - List_WriteToFile(v->SQ, file, f); List_WriteToFile(v->VQ, file, f); - List_WriteToFile(v->TQ, file, f); - List_WriteToFile(v->SS, file, f); List_WriteToFile(v->VS, file, f); + List_WriteToFile(v->ST, file, f); + List_WriteToFile(v->VT, file, f); + List_WriteToFile(v->TT, file, f); + List_WriteToFile(v->SQ, file, f); + List_WriteToFile(v->VQ, file, f); + List_WriteToFile(v->TQ, file, f); + List_WriteToFile(v->SS, file, f); + List_WriteToFile(v->VS, file, f); List_WriteToFile(v->TS, file, f); - List_WriteToFile(v->SH, file, f); List_WriteToFile(v->VH, file, f); + List_WriteToFile(v->SH, file, f); + List_WriteToFile(v->VH, file, f); List_WriteToFile(v->TH, file, f); - List_WriteToFile(v->SI, file, f); List_WriteToFile(v->VI, file, f); + List_WriteToFile(v->SI, file, f); + List_WriteToFile(v->VI, file, f); List_WriteToFile(v->TI, file, f); - List_WriteToFile(v->SY, file, f); List_WriteToFile(v->VY, file, f); + List_WriteToFile(v->SY, file, f); + List_WriteToFile(v->VY, file, f); List_WriteToFile(v->TY, file, f); - List_WriteToFile(v->T2D, file, f); List_WriteToFile(v->T2C, file, f); - List_WriteToFile(v->T3D, file, f); List_WriteToFile(v->T3C, file, f); + List_WriteToFile(v->T2D, file, f); + List_WriteToFile(v->T2C, file, f); + List_WriteToFile(v->T3D, file, f); + List_WriteToFile(v->T3C, file, f); fprintf(file, "\n"); fprintf(file, "$EndView\n"); - if(filename){ + if(filename) { Msg(INFO, "View output complete '%s'", filename); Msg(STATUS2, "Wrote '%s'", filename); fclose(file); @@ -875,265 +946,304 @@ void WriteView(int Flag_BIN, Post_View *v, char *filename){ using namespace std; -struct xyzv{ +struct xyzv +{ private: public: - double x,y,z,*vals; + double x, y, z, *vals; int nbvals; int nboccurences; static double eps; - void update (int nbVals, double *); - xyzv(double x, double y, double z); - ~xyzv(); - xyzv & operator = ( const xyzv &); - xyzv ( const xyzv &); + void update(int nbVals, double *); + xyzv(double x, double y, double z); + ~xyzv(); + xyzv & operator =(const xyzv &); + xyzv(const xyzv &); }; double xyzv::eps = 0.0; -xyzv::xyzv (double xx, double yy, double zz) - : x(xx),y(yy),z(zz),vals(0),nbvals(0),nboccurences(0){} +xyzv::xyzv(double xx, double yy, double zz) +:x(xx), y(yy), z(zz), vals(0), nbvals(0), nboccurences(0) +{ +} -xyzv::~xyzv(){ - if(vals)delete [] vals; +xyzv::~xyzv() +{ + if(vals) + delete[]vals; } -xyzv::xyzv(const xyzv &other){ +xyzv::xyzv(const xyzv & other) +{ x = other.x; y = other.y; z = other.z; nbvals = other.nbvals; nboccurences = other.nboccurences; - if(other.vals && other.nbvals){ + if(other.vals && other.nbvals) { vals = new double[other.nbvals]; - for(int i=0;i<nbvals;i++)vals[i] = other.vals[i]; + for(int i = 0; i < nbvals; i++) + vals[i] = other.vals[i]; } } -xyzv & xyzv::operator = (const xyzv &other){ - if(this != &other){ +xyzv & xyzv::operator =(const xyzv & other) +{ + if(this != &other) { x = other.x; y = other.y; z = other.z; nbvals = other.nbvals; nboccurences = other.nboccurences; - if(other.vals && other.nbvals){ + if(other.vals && other.nbvals) { vals = new double[other.nbvals]; - for(int i=0;i<nbvals;i++)vals[i] = other.vals[i]; + for(int i = 0; i < nbvals; i++) + vals[i] = other.vals[i]; } } return *this; } -void xyzv::update (int n, double *v){ +void xyzv::update(int n, double *v) +{ int i; - if(!vals){ + if(!vals) { vals = new double[n]; - for(i=0;i<n;i++)vals[i] = 0.0; + for(i = 0; i < n; i++) + vals[i] = 0.0; nbvals = n; nboccurences = 0; } - else if (nbvals != n){ + else if(nbvals != n) { throw n; } - double x1 = (double)(nboccurences)/ (double)(nboccurences + 1); - double x2 = 1./(double)(nboccurences + 1); - for(i=0;i<nbvals;i++)vals[i] = (x1 * vals[i] + x2 * v[i]); + double x1 = (double)(nboccurences) / (double)(nboccurences + 1); + double x2 = 1. / (double)(nboccurences + 1); + for(i = 0; i < nbvals; i++) + vals[i] = (x1 * vals[i] + x2 * v[i]); nboccurences++; //printf("val(%d,%f,%f,%f) = %f\n",nboccurences,x,y,z,vals[0]); } -struct lessthanxyzv{ - bool operator () (const xyzv & p2, const xyzv &p1) const{ - if( p1.x - p2.x > xyzv::eps)return true; - if( p1.x - p2.x <-xyzv::eps)return false; - if( p1.y - p2.y > xyzv::eps)return true; - if( p1.y - p2.y <-xyzv::eps)return false; - if( p1.z - p2.z > xyzv::eps)return true; - return false; +struct lessthanxyzv +{ + bool operator () (const xyzv & p2, const xyzv & p1)const + { + if(p1.x - p2.x > xyzv::eps) + return true; + if(p1.x - p2.x < -xyzv::eps) + return false; + if(p1.y - p2.y > xyzv::eps) + return true; + if(p1.y - p2.y < -xyzv::eps) + return false; + if(p1.z - p2.z > xyzv::eps) + return true; + return false; } }; -typedef set<xyzv,lessthanxyzv> mycont; +typedef set < xyzv, lessthanxyzv > mycont; typedef mycont::const_iterator iter; -class smooth_container{ -public : - mycont c; +class smooth_container +{ + public: mycont c; }; -void generate_connectivities (List_T *SS , int NbTimeStep, int nbvert, int nb, - mycont & connectivities){ - double *x,*y,*z,*v; - int i,j,k; +void generate_connectivities(List_T * SS, int NbTimeStep, int nbvert, int nb, + mycont & connectivities) +{ + double *x, *y, *z, *v; + int i, j, k; // double vals[NbTimeStep]; // sgi compiler does not allow this double *vals = new double[NbTimeStep]; - for(i = 0 ; i < List_Nbr(SS) ; i+=nb){ - x = (double*)List_Pointer_Fast(SS,i); - y = (double*)List_Pointer_Fast(SS,i+nbvert); - z = (double*)List_Pointer_Fast(SS,i+2*nbvert); - v = (double*)List_Pointer_Fast(SS,i+3*nbvert); - - for(j=0;j<nbvert;j++){ - for(k=0;k<NbTimeStep;k++)vals[k] = v[j+k*nbvert]; - xyzv xyz(x[j],y[j],z[j]); + for(i = 0; i < List_Nbr(SS); i += nb) { + x = (double *)List_Pointer_Fast(SS, i); + y = (double *)List_Pointer_Fast(SS, i + nbvert); + z = (double *)List_Pointer_Fast(SS, i + 2 * nbvert); + v = (double *)List_Pointer_Fast(SS, i + 3 * nbvert); + + for(j = 0; j < nbvert; j++) { + for(k = 0; k < NbTimeStep; k++) + vals[k] = v[j + k * nbvert]; + xyzv xyz(x[j], y[j], z[j]); iter it = connectivities.find(xyz); - if(it == connectivities.end()){ - xyz.update(NbTimeStep,vals); - connectivities.insert(xyz); + if(it == connectivities.end()) { + xyz.update(NbTimeStep, vals); + connectivities.insert(xyz); } - else{ - // a little weird ... because we know that this will not - // destroy the set ordering - xyzv *xx = (xyzv*) &(*it); - xx->update(NbTimeStep,vals); + else { + // a little weird ... because we know that this will not + // destroy the set ordering + xyzv *xx = (xyzv *) & (*it); + xx->update(NbTimeStep, vals); } } } - delete [] vals; + delete[]vals; } -void smooth_list (List_T *SS , double *min, double *max, - int NbTimeStep, int nbvert, int nb, - mycont & connectivities){ - double *x,*y,*z,*v; - int i,j,k; +void smooth_list(List_T * SS, double *min, double *max, + int NbTimeStep, int nbvert, int nb, mycont & connectivities) +{ + double *x, *y, *z, *v; + int i, j, k; *min = VAL_INF; *max = -VAL_INF; - for(i = 0 ; i < List_Nbr(SS) ; i+=nb){ - x = (double*)List_Pointer_Fast(SS,i); - y = (double*)List_Pointer_Fast(SS,i+nbvert); - z = (double*)List_Pointer_Fast(SS,i+2*nbvert); - v = (double*)List_Pointer_Fast(SS,i+3*nbvert); - for(j=0;j<nbvert;j++){ - xyzv xyz(x[j],y[j],z[j]); + for(i = 0; i < List_Nbr(SS); i += nb) { + x = (double *)List_Pointer_Fast(SS, i); + y = (double *)List_Pointer_Fast(SS, i + nbvert); + z = (double *)List_Pointer_Fast(SS, i + 2 * nbvert); + v = (double *)List_Pointer_Fast(SS, i + 3 * nbvert); + for(j = 0; j < nbvert; j++) { + xyzv xyz(x[j], y[j], z[j]); iter it = connectivities.find(xyz); - if(it != connectivities.end()){ - for(k=0;k<NbTimeStep;k++){ - v[j+k*nbvert] = (*it).vals[k]; - if(v[j+k*nbvert] < *min) *min = v[j+k*nbvert] ; - if(v[j+k*nbvert] > *max) *max = v[j+k*nbvert] ; - } + if(it != connectivities.end()) { + for(k = 0; k < NbTimeStep; k++) { + v[j + k * nbvert] = (*it).vals[k]; + if(v[j + k * nbvert] < *min) + *min = v[j + k * nbvert]; + if(v[j + k * nbvert] > *max) + *max = v[j + k * nbvert]; + } } } - } + } } -void Post_View :: smooth (){ +void Post_View::smooth() +{ xyzv::eps = CTX.lc * 1.e-8; - if(NbSL || NbST || NbSQ || NbSS || NbSH || NbSI || NbSY){ + if(NbSL || NbST || NbSQ || NbSS || NbSH || NbSI || NbSY) { mycont con; - int nbl=0, nbt=0, nbq=0, nbs=0, nbh=0, nbi=0, nby=0; - Msg(INFO,"Smoothing scalar primitives in view..."); - if(NbSL){ - nbt = List_Nbr(SL) / NbSL ; - generate_connectivities(SL , NbTimeStep, 2, nbl, con); + int nbl = 0, nbt = 0, nbq = 0, nbs = 0, nbh = 0, nbi = 0, nby = 0; + Msg(INFO, "Smoothing scalar primitives in view..."); + if(NbSL) { + nbt = List_Nbr(SL) / NbSL; + generate_connectivities(SL, NbTimeStep, 2, nbl, con); } - if(NbST){ - nbt = List_Nbr(ST) / NbST ; - generate_connectivities(ST , NbTimeStep, 3, nbt, con); + if(NbST) { + nbt = List_Nbr(ST) / NbST; + generate_connectivities(ST, NbTimeStep, 3, nbt, con); } - if(NbSQ){ - nbq = List_Nbr(SQ) / NbSQ ; - generate_connectivities(SQ , NbTimeStep, 4, nbq, con); + if(NbSQ) { + nbq = List_Nbr(SQ) / NbSQ; + generate_connectivities(SQ, NbTimeStep, 4, nbq, con); } - if(NbSS){ - nbs = List_Nbr(SS) / NbSS ; - generate_connectivities(SS , NbTimeStep, 4, nbs, con); + if(NbSS) { + nbs = List_Nbr(SS) / NbSS; + generate_connectivities(SS, NbTimeStep, 4, nbs, con); } - if(NbSH){ - nbh = List_Nbr(SH) / NbSH ; - generate_connectivities(SH , NbTimeStep, 8, nbh, con); + if(NbSH) { + nbh = List_Nbr(SH) / NbSH; + generate_connectivities(SH, NbTimeStep, 8, nbh, con); } - if(NbSI){ - nbi = List_Nbr(SI) / NbSI ; - generate_connectivities(SI , NbTimeStep, 6, nbi, con); + if(NbSI) { + nbi = List_Nbr(SI) / NbSI; + generate_connectivities(SI, NbTimeStep, 6, nbi, con); } - if(NbSY){ - nby = List_Nbr(SY) / NbSY ; - generate_connectivities(SY , NbTimeStep, 5, nby, con); + if(NbSY) { + nby = List_Nbr(SY) / NbSY; + generate_connectivities(SY, NbTimeStep, 5, nby, con); } - if(nbl) smooth_list(SL , &Min, &Max, NbTimeStep, 2, nbl, con); - if(nbt) smooth_list(ST , &Min, &Max, NbTimeStep, 3, nbt, con); - if(nbq) smooth_list(SQ , &Min, &Max, NbTimeStep, 4, nbq, con); - if(nbs) smooth_list(SS , &Min, &Max, NbTimeStep, 4, nbs, con); - if(nbh) smooth_list(SH , &Min, &Max, NbTimeStep, 8, nbh, con); - if(nbi) smooth_list(SI , &Min, &Max, NbTimeStep, 6, nbi, con); - if(nby) smooth_list(SY , &Min, &Max, NbTimeStep, 5, nby, con); - Msg(INFO,"...done"); + if(nbl) + smooth_list(SL, &Min, &Max, NbTimeStep, 2, nbl, con); + if(nbt) + smooth_list(ST, &Min, &Max, NbTimeStep, 3, nbt, con); + if(nbq) + smooth_list(SQ, &Min, &Max, NbTimeStep, 4, nbq, con); + if(nbs) + smooth_list(SS, &Min, &Max, NbTimeStep, 4, nbs, con); + if(nbh) + smooth_list(SH, &Min, &Max, NbTimeStep, 8, nbh, con); + if(nbi) + smooth_list(SI, &Min, &Max, NbTimeStep, 6, nbi, con); + if(nby) + smooth_list(SY, &Min, &Max, NbTimeStep, 5, nby, con); + Msg(INFO, "...done"); } } - + // Normal smoothing -void Post_View :: reset_normals(){ - if(normals) delete normals; - normals = 0; +void Post_View::reset_normals() +{ + if(normals) + delete normals; + normals = 0; } -void Post_View :: add_normal(double x, double y, double z, - double nx, double ny, double nz){ - if(!normals) normals = new smooth_container; +void Post_View::add_normal(double x, double y, double z, + double nx, double ny, double nz) +{ + if(!normals) + normals = new smooth_container; - double n[3] = {nx,ny,nz}; - xyzv xyz(x,y,z); + double n[3] = { nx, ny, nz }; + xyzv xyz(x, y, z); iter it = normals->c.find(xyz); - if(it == normals->c.end()){ - xyz.update(3,n); + if(it == normals->c.end()) { + xyz.update(3, n); normals->c.insert(xyz); } - else{ - xyzv *xx = (xyzv*) &(*it); - xx->update(3,n); + else { + xyzv *xx = (xyzv *) & (*it); + xx->update(3, n); } } -double get_angle (double * aa, double * bb){ - double angplan, cosc, sinc, a[3],b[3],c[3]; - if(!aa || !bb) return 0.; +double get_angle(double *aa, double *bb) +{ + double angplan, cosc, sinc, a[3], b[3], c[3]; + if(!aa || !bb) + return 0.; a[0] = aa[0]; a[1] = aa[1]; a[2] = aa[2]; b[0] = bb[0]; b[1] = bb[1]; b[2] = bb[2]; - norme (a); - norme (b); - prodve (a, b, c); - prosca (a, b, &cosc); - sinc = sqrt (c[0] * c[0] + c[1] * c[1] + c[2] * c[2]); - angplan = myatan2 (sinc, cosc); - return angplan*180./Pi; + norme(a); + norme(b); + prodve(a, b, c); + prosca(a, b, &cosc); + sinc = sqrt(c[0] * c[0] + c[1] * c[1] + c[2] * c[2]); + angplan = myatan2(sinc, cosc); + return angplan * 180. / Pi; } -bool Post_View :: get_normal(double x, double y, double z, - double &nx, double &ny, double &nz){ - if(!normals) return false; +bool Post_View::get_normal(double x, double y, double z, + double &nx, double &ny, double &nz) +{ + if(!normals) + return false; - double n[3] = {nx,ny,nz}; - xyzv xyz(x,y,z); + double n[3] = { nx, ny, nz }; + xyzv xyz(x, y, z); iter it = normals->c.find(xyz); - if(it == normals->c.end()) return false; + if(it == normals->c.end()) + return false; - double angle = get_angle ((*it).vals, n); + double angle = get_angle((*it).vals, n); - if(fabs(angle) < AngleSmoothNormals) - { - nx = (*it).vals[0]; - ny = (*it).vals[1]; - nz = (*it).vals[2]; - } + if(fabs(angle) < AngleSmoothNormals) { + nx = (*it).vals[0]; + ny = (*it).vals[1]; + nz = (*it).vals[2]; + } return true; } @@ -1141,115 +1251,121 @@ bool Post_View :: get_normal(double x, double y, double z, // Transformation static void transform(double mat[3][3], double v[3], - double *x, double *y, double *z){ - *x = mat[0][0]*v[0] + mat[0][1]*v[1] + mat[0][2]*v[2]; - *y = mat[1][0]*v[0] + mat[1][1]*v[1] + mat[1][2]*v[2]; - *z = mat[2][0]*v[0] + mat[2][1]*v[1] + mat[2][2]*v[2]; + double *x, double *y, double *z) +{ + *x = mat[0][0] * v[0] + mat[0][1] * v[1] + mat[0][2] * v[2]; + *y = mat[1][0] * v[0] + mat[1][1] * v[1] + mat[1][2] * v[2]; + *z = mat[2][0] * v[0] + mat[2][1] * v[1] + mat[2][2] * v[2]; } -static void transform_list(List_T *V , int NbTimeStep, int nbvert, - int nb, double mat[3][3]){ - double *x,*y,*z, v[3]; +static void transform_list(List_T * V, int NbTimeStep, int nbvert, + int nb, double mat[3][3]) +{ + double *x, *y, *z, v[3]; int i, j; - for(i = 0 ; i < List_Nbr(V) ; i+=nb){ - x = (double*)List_Pointer_Fast(V,i); - y = (double*)List_Pointer_Fast(V,i+nbvert); - z = (double*)List_Pointer_Fast(V,i+2*nbvert); - for(j=0; j<nbvert; j++){ + for(i = 0; i < List_Nbr(V); i += nb) { + x = (double *)List_Pointer_Fast(V, i); + y = (double *)List_Pointer_Fast(V, i + nbvert); + z = (double *)List_Pointer_Fast(V, i + 2 * nbvert); + for(j = 0; j < nbvert; j++) { v[0] = x[j]; v[1] = y[j]; v[2] = z[j]; - transform(mat,v,&x[j],&y[j],&z[j]); + transform(mat, v, &x[j], &y[j], &z[j]); } } } -void Post_View :: transform (double mat[3][3]){ +void Post_View::transform(double mat[3][3]) +{ int nb; - if(NbSP){ - nb = List_Nbr(SP) / NbSP ; + if(NbSP) { + nb = List_Nbr(SP) / NbSP; transform_list(SP, NbTimeStep, 1, nb, mat); } - if(NbSL){ - nb = List_Nbr(SL) / NbSL ; + if(NbSL) { + nb = List_Nbr(SL) / NbSL; transform_list(SL, NbTimeStep, 2, nb, mat); } - if(NbST){ - nb = List_Nbr(ST) / NbST ; + if(NbST) { + nb = List_Nbr(ST) / NbST; transform_list(ST, NbTimeStep, 3, nb, mat); } - if(NbSQ){ - nb = List_Nbr(SQ) / NbSQ ; + if(NbSQ) { + nb = List_Nbr(SQ) / NbSQ; transform_list(SQ, NbTimeStep, 4, nb, mat); } - if(NbSS){ - nb = List_Nbr(SS) / NbSS ; + if(NbSS) { + nb = List_Nbr(SS) / NbSS; transform_list(SS, NbTimeStep, 4, nb, mat); } - if(NbSH){ - nb = List_Nbr(SH) / NbSH ; + if(NbSH) { + nb = List_Nbr(SH) / NbSH; transform_list(SH, NbTimeStep, 8, nb, mat); } - if(NbSI){ - nb = List_Nbr(SI) / NbSI ; + if(NbSI) { + nb = List_Nbr(SI) / NbSI; transform_list(SI, NbTimeStep, 6, nb, mat); } - if(NbSY){ - nb = List_Nbr(SY) / NbSY ; + if(NbSY) { + nb = List_Nbr(SY) / NbSY; transform_list(SY, NbTimeStep, 5, nb, mat); } - if(NbVP){ - nb = List_Nbr(VP) / NbVP ; + if(NbVP) { + nb = List_Nbr(VP) / NbVP; transform_list(VP, NbTimeStep, 1, nb, mat); } - if(NbVL){ - nb = List_Nbr(VL) / NbVL ; + if(NbVL) { + nb = List_Nbr(VL) / NbVL; transform_list(VL, NbTimeStep, 2, nb, mat); } - if(NbVT){ - nb = List_Nbr(VT) / NbVT ; + if(NbVT) { + nb = List_Nbr(VT) / NbVT; transform_list(VT, NbTimeStep, 3, nb, mat); } - if(NbVQ){ - nb = List_Nbr(VQ) / NbVQ ; + if(NbVQ) { + nb = List_Nbr(VQ) / NbVQ; transform_list(VQ, NbTimeStep, 4, nb, mat); } - if(NbVS){ - nb = List_Nbr(VS) / NbVS ; + if(NbVS) { + nb = List_Nbr(VS) / NbVS; transform_list(VS, NbTimeStep, 4, nb, mat); } - if(NbVH){ - nb = List_Nbr(VH) / NbVH ; + if(NbVH) { + nb = List_Nbr(VH) / NbVH; transform_list(VH, NbTimeStep, 8, nb, mat); } - if(NbVI){ - nb = List_Nbr(VI) / NbVI ; + if(NbVI) { + nb = List_Nbr(VI) / NbVI; transform_list(VI, NbTimeStep, 6, nb, mat); } - if(NbVY){ - nb = List_Nbr(VY) / NbVY ; + if(NbVY) { + nb = List_Nbr(VY) / NbVY; transform_list(VY, NbTimeStep, 5, nb, mat); } } // merge lists -static void merge(List_T *a , List_T *b){ - if(!a || !b) return; - for(int i=0;i<List_Nbr(a);i++){ - List_Add(b,List_Pointer(a,i)); +static void merge(List_T * a, List_T * b) +{ + if(!a || !b) + return; + for(int i = 0; i < List_Nbr(a); i++) { + List_Add(b, List_Pointer(a, i)); } } -void MergeViews(int all){ +void MergeViews(int all) +{ Post_View *vm = BeginView(1); - for(int i=0; i<List_Nbr(CTX.post.list)-1; i++){ - Post_View *v = (Post_View*)List_Pointer(CTX.post.list, i); - if(all || v->Visible){ + for(int i = 0; i < List_Nbr(CTX.post.list) - 1; i++) { + Post_View *v = (Post_View *) List_Pointer(CTX.post.list, i); + if(all || v->Visible) { Msg(DEBUG, "Merging view %d", i); // *INDENT-OFF* merge(v->SP,vm->SP); vm->NbSP += v->NbSP; @@ -1278,11 +1394,11 @@ void MergeViews(int all){ merge(v->TY,vm->TY); vm->NbTY += v->NbTY; // *INDENT-ON* /* this more complicated: have to change the indices - merge(v->T2D,vm->T2D); - merge(v->T2C,vm->T2C); v->NbT2 += vm->NbT2; - merge(v->T3D,vm->T3D); - merge(v->T3C,vm->T3C); v->NbT2 += vm->NbT2; - */ + merge(v->T2D,vm->T2D); + merge(v->T2C,vm->T2C); v->NbT2 += vm->NbT2; + merge(v->T3D,vm->T3D); + merge(v->T3C,vm->T3C); v->NbT2 += vm->NbT2; + */ } } EndView(vm, 1, "merged.pos", "merged"); @@ -1290,10 +1406,12 @@ void MergeViews(int all){ // generic access functions -int Post_View::get_val(int list, int node, int timestep, double *value){ +int Post_View::get_val(int list, int node, int timestep, double *value) +{ return 0; } -void Post_View::add_val(int list, int node, int timestep, double value){ - +void Post_View::add_val(int list, int node, int timestep, double value) +{ + } diff --git a/DataStr/List.cpp b/DataStr/List.cpp index 368908319982a15118fec476c7fb84dba0a1bcf9..1397b110c911a314ae2ff8b0a0f97a39003a1628 100644 --- a/DataStr/List.cpp +++ b/DataStr/List.cpp @@ -1,4 +1,4 @@ -// $Id: List.cpp,v 1.24 2003-02-10 18:57:02 geuzaine Exp $ +// $Id: List.cpp,v 1.25 2003-03-01 22:36:37 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -36,424 +36,467 @@ List_T *List_Create(int n, int incr, int size) { List_T *liste; - if (n <= 0) n = 1 ; - if (incr <= 0) incr = 1; + if(n <= 0) + n = 1; + if(incr <= 0) + incr = 1; - liste = (List_T *)Malloc(sizeof(List_T)); + liste = (List_T *) Malloc(sizeof(List_T)); - liste->nmax = 0; - liste->incr = incr; - liste->size = size; - liste->n = 0; + liste->nmax = 0; + liste->incr = incr; + liste->size = size; + liste->n = 0; liste->isorder = 0; - liste->array = NULL; + liste->array = NULL; - List_Realloc(liste,n); - return(liste); + List_Realloc(liste, n); + return (liste); } -void List_Delete(List_T *liste) +void List_Delete(List_T * liste) { - if(!liste) return ; + if(!liste) + return; Free(liste->array); Free(liste); } -void List_Realloc(List_T *liste,int n) +void List_Realloc(List_T * liste, int n) { - if (n <= 0) return; + if(n <= 0) + return; - if (liste->array == NULL) { + if(liste->array == NULL) { liste->nmax = ((n - 1) / liste->incr + 1) * liste->incr; liste->array = (char *)Malloc(liste->nmax * liste->size); } - else - if (n > liste->nmax) { - liste->nmax = ((n - 1) / liste->incr + 1) * liste->incr; - liste->array = (char *)Realloc(liste->array, - liste->nmax * liste->size); - } + else if(n > liste->nmax) { + liste->nmax = ((n - 1) / liste->incr + 1) * liste->incr; + liste->array = (char *)Realloc(liste->array, liste->nmax * liste->size); + } } -void List_Add(List_T *liste, void *data) +void List_Add(List_T * liste, void *data) { liste->n++; - List_Realloc(liste,liste->n); + List_Realloc(liste, liste->n); liste->isorder = 0; - memcpy(&liste->array[(liste->n - 1) * liste->size],data,liste->size); + memcpy(&liste->array[(liste->n - 1) * liste->size], data, liste->size); } -int List_Nbr(List_T *liste) +int List_Nbr(List_T * liste) { - return (liste)? liste->n : 0 ; + return (liste) ? liste->n : 0; } -void List_Insert(List_T *liste, void *data, - int (*fcmp)(const void *a, const void *b)) +void List_Insert(List_T * liste, void *data, + int (*fcmp) (const void *a, const void *b)) { - if (List_Search(liste,data,fcmp) == 0) - List_Add(liste,data); + if(List_Search(liste, data, fcmp) == 0) + List_Add(liste, data); } -int List_Replace(List_T *liste, void *data, - int (*fcmp)(const void *a, const void *b)) +int List_Replace(List_T * liste, void *data, + int (*fcmp) (const void *a, const void *b)) { void *ptr; - if (liste->isorder != 1) List_Sort(liste,fcmp); + if(liste->isorder != 1) + List_Sort(liste, fcmp); liste->isorder = 1; - ptr = (void *) bsearch(data,liste->array,liste->n,liste->size,fcmp); - if (ptr == NULL) { - List_Add(liste,data); - return(0); + ptr = (void *)bsearch(data, liste->array, liste->n, liste->size, fcmp); + if(ptr == NULL) { + List_Add(liste, data); + return (0); } else { - memcpy(ptr,data,liste->size); + memcpy(ptr, data, liste->size); return (1); } } -void List_Read(List_T *liste, int index, void *data) +void List_Read(List_T * liste, int index, void *data) { - if ((index < 0) || (index >= liste->n)) + if((index < 0) || (index >= liste->n)) Msg(FATAL, "Wrong list index (read)"); - memcpy(data,&liste->array[index * liste->size],liste->size); + memcpy(data, &liste->array[index * liste->size], liste->size); } -void List_Write(List_T *liste, int index, void *data) +void List_Write(List_T * liste, int index, void *data) { - if ((index < 0) || (index >= liste->n)) + if((index < 0) || (index >= liste->n)) Msg(GERROR, "Wrong list index (write)"); - else{ + else { liste->isorder = 0; - memcpy(&liste->array[index * liste->size],data,liste->size); + memcpy(&liste->array[index * liste->size], data, liste->size); } } -void List_Put(List_T *liste, int index, void *data) +void List_Put(List_T * liste, int index, void *data) { - if (index < 0) + if(index < 0) Msg(GERROR, "Wrong list index (put)"); - else{ - if (index >= liste->n) { + else { + if(index >= liste->n) { liste->n = index + 1; - List_Realloc(liste,liste->n); - List_Write(liste,index,data); - } + List_Realloc(liste, liste->n); + List_Write(liste, index, data); + } else { - List_Write(liste,index,data); + List_Write(liste, index, data); } } } -void List_Pop(List_T *liste) +void List_Pop(List_T * liste) { - liste->n -- ; + liste->n--; } -void *List_Pointer(List_T *liste, int index) +void *List_Pointer(List_T * liste, int index) { - if ((index < 0) || (index >= liste->n)) + if((index < 0) || (index >= liste->n)) Msg(FATAL, "Wrong list index (pointer)"); - + liste->isorder = 0; - return(&liste->array[index * liste->size]); + return (&liste->array[index * liste->size]); } -void *List_Pointer_NoChange(List_T *liste, int index) +void *List_Pointer_NoChange(List_T * liste, int index) { - if ((index < 0) || (index >= liste->n)) + if((index < 0) || (index >= liste->n)) Msg(FATAL, "Wrong list index (pointer)"); - return(&liste->array[index * liste->size]); + return (&liste->array[index * liste->size]); } -void *List_Pointer_Fast(List_T *liste, int index) +void *List_Pointer_Fast(List_T * liste, int index) { - return(&liste->array[index * liste->size]); + return (&liste->array[index * liste->size]); } -void *List_Pointer_Test(List_T *liste, int index) +void *List_Pointer_Test(List_T * liste, int index) { - if (!liste || (index < 0) || (index >= liste->n)) + if(!liste || (index < 0) || (index >= liste->n)) return NULL; - + liste->isorder = 0; - return(&liste->array[index * liste->size]); + return (&liste->array[index * liste->size]); } -void List_Sort(List_T *liste, int (*fcmp)(const void *a, const void *b)) +void List_Sort(List_T * liste, int (*fcmp) (const void *a, const void *b)) { - qsort(liste->array,liste->n,liste->size,fcmp); + qsort(liste->array, liste->n, liste->size, fcmp); } -int List_Search(List_T *liste, void *data, - int (*fcmp)(const void *a, const void *b)) +int List_Search(List_T * liste, void *data, + int (*fcmp) (const void *a, const void *b)) { void *ptr; - if (liste->isorder != 1) { List_Sort(liste,fcmp) ; liste->isorder = 1 ; } - ptr = (void *) bsearch(data,liste->array,liste->n,liste->size,fcmp); - if (ptr == NULL) return(0); + if(liste->isorder != 1) { + List_Sort(liste, fcmp); + liste->isorder = 1; + } + ptr = (void *)bsearch(data, liste->array, liste->n, liste->size, fcmp); + if(ptr == NULL) + return (0); return (1); } -int List_ISearch(List_T *liste, void *data, - int (*fcmp)(const void *a, const void *b)) +int List_ISearch(List_T * liste, void *data, + int (*fcmp) (const void *a, const void *b)) { void *ptr; - if (liste->isorder != 1) List_Sort(liste,fcmp); + if(liste->isorder != 1) + List_Sort(liste, fcmp); liste->isorder = 1; - ptr = (void *) bsearch(data,liste->array,liste->n,liste->size,fcmp); - if (ptr == NULL) return(-1); + ptr = (void *)bsearch(data, liste->array, liste->n, liste->size, fcmp); + if(ptr == NULL) + return (-1); return (((long)ptr - (long)liste->array) / liste->size); } -int List_ISearchSeq(List_T *liste, void * data, - int (*fcmp)(const void *a, const void *b)) { - int i ; +int List_ISearchSeq(List_T * liste, void *data, + int (*fcmp) (const void *a, const void *b)) +{ + int i; - if (!liste) return -1 ; - i = 0 ; - while ((i < List_Nbr(liste)) && - fcmp(data, (void *)List_Pointer(liste, i)) ) i++ ; - if (i == List_Nbr(liste)) i = -1 ; - return i ; + if(!liste) + return -1; + i = 0; + while((i < List_Nbr(liste)) && fcmp(data, (void *)List_Pointer(liste, i))) + i++; + if(i == List_Nbr(liste)) + i = -1; + return i; } -int List_ISearchSeqPartial(List_T *liste, void * data, int i_Start, - int (*fcmp)(const void *a, const void *b)) { - int i ; +int List_ISearchSeqPartial(List_T * liste, void *data, int i_Start, + int (*fcmp) (const void *a, const void *b)) +{ + int i; - if (!liste) return -1 ; - i = i_Start ; - while ((i < List_Nbr(liste)) && - fcmp(data, (void *)List_Pointer(liste, i)) ) i++ ; - if (i == List_Nbr(liste)) i = -1 ; - return i ; + if(!liste) + return -1; + i = i_Start; + while((i < List_Nbr(liste)) && fcmp(data, (void *)List_Pointer(liste, i))) + i++; + if(i == List_Nbr(liste)) + i = -1; + return i; } -int List_Query(List_T *liste, void *data, - int (*fcmp)(const void *a, const void *b)) +int List_Query(List_T * liste, void *data, + int (*fcmp) (const void *a, const void *b)) { void *ptr; - if (liste->isorder != 1) List_Sort(liste,fcmp); + if(liste->isorder != 1) + List_Sort(liste, fcmp); liste->isorder = 1; - ptr = (void *) bsearch(data,liste->array,liste->n,liste->size,fcmp); - if (ptr == NULL) return(0); + ptr = (void *)bsearch(data, liste->array, liste->n, liste->size, fcmp); + if(ptr == NULL) + return (0); - memcpy(data,ptr,liste->size); + memcpy(data, ptr, liste->size); return (1); } void *lolofind(void *data, void *array, int n, int size, - int (*fcmp)(const void *a, const void *b) ) + int (*fcmp) (const void *a, const void *b)) { char *ptr; int i; - ptr = (char*)array; - for (i = 0; i < n; i++) { - if (fcmp(ptr,data) == 0) break; + ptr = (char *)array; + for(i = 0; i < n; i++) { + if(fcmp(ptr, data) == 0) + break; ptr += size; } - if (i < n) return(ptr); - return(NULL); + if(i < n) + return (ptr); + return (NULL); } -int List_LQuery(List_T *liste, void *data, - int (*fcmp)(const void *a, const void *b), int first) +int List_LQuery(List_T * liste, void *data, + int (*fcmp) (const void *a, const void *b), int first) { char *ptr; - - if (first == 1) { - ptr = (char *) lolofind(data,liste->array,liste->n,liste->size,fcmp); + + if(first == 1) { + ptr = (char *)lolofind(data, liste->array, liste->n, liste->size, fcmp); } else { - if (startptr != NULL) - ptr = (char *) lolofind(data,startptr,liste->n,liste->size,fcmp); + if(startptr != NULL) + ptr = (char *)lolofind(data, startptr, liste->n, liste->size, fcmp); else - return(0); + return (0); } - if (ptr == NULL) return(0); + if(ptr == NULL) + return (0); - startptr = ptr + liste->size; - if ( startptr >= ( liste->array + liste->n * liste->size)) + startptr = ptr + liste->size; + if(startptr >= (liste->array + liste->n * liste->size)) startptr = NULL; - memcpy(data,ptr,liste->size); + memcpy(data, ptr, liste->size); return (1); } -void *List_PQuery(List_T *liste, void *data, - int (*fcmp)(const void *a, const void *b)) +void *List_PQuery(List_T * liste, void *data, + int (*fcmp) (const void *a, const void *b)) { void *ptr; - if (liste->isorder != 1) List_Sort(liste,fcmp); + if(liste->isorder != 1) + List_Sort(liste, fcmp); liste->isorder = 1; - ptr = (void *) bsearch(data,liste->array,liste->n,liste->size,fcmp); - return(ptr); + ptr = (void *)bsearch(data, liste->array, liste->n, liste->size, fcmp); + return (ptr); } -int List_Suppress(List_T *liste, void *data, - int (*fcmp)(const void *a, const void *b)) +int List_Suppress(List_T * liste, void *data, + int (*fcmp) (const void *a, const void *b)) { char *ptr; int len; - - ptr = (char*)List_PQuery(liste,data,fcmp) ; - if (ptr == NULL) return(0); - + + ptr = (char *)List_PQuery(liste, data, fcmp); + if(ptr == NULL) + return (0); + liste->n--; len = liste->n - (((long)ptr - (long)liste->array) / liste->size); - if (len > 0) memmove(ptr, ptr + liste->size, len * liste->size); - return(1); + if(len > 0) + memmove(ptr, ptr + liste->size, len * liste->size); + return (1); } -int List_PSuppress(List_T *liste, int index) +int List_PSuppress(List_T * liste, int index) { char *ptr; int len; - - ptr = (char*)List_Pointer_NoChange(liste,index) ; - if (ptr == NULL) return(0); - + + ptr = (char *)List_Pointer_NoChange(liste, index); + if(ptr == NULL) + return (0); + liste->n--; len = liste->n - (((long)ptr - (long)liste->array) / liste->size); - if (len > 0) memmove(ptr, ptr + liste->size, len * liste->size); - return(1); + if(len > 0) + memmove(ptr, ptr + liste->size, len * liste->size); + return (1); } -void List_Invert(List_T *a , List_T *b) +void List_Invert(List_T * a, List_T * b) { - int i,N; + int i, N; N = List_Nbr(a); - for(i=0;i<N;i++){ - List_Add(b,List_Pointer(a,N-i-1)); + for(i = 0; i < N; i++) { + List_Add(b, List_Pointer(a, N - i - 1)); } } -void List_Reset(List_T *liste) +void List_Reset(List_T * liste) { - if(!liste) return; + if(!liste) + return; liste->n = 0; } -void List_Action(List_T *liste, void (*action)(void *data, void *dummy)) +void List_Action(List_T * liste, void (*action) (void *data, void *dummy)) { - int i,dummy; + int i, dummy; - for(i=0 ; i<List_Nbr(liste) ; i++){ - (*action)(List_Pointer_NoChange(liste,i),&dummy); + for(i = 0; i < List_Nbr(liste); i++) { + (*action) (List_Pointer_NoChange(liste, i), &dummy); } } -void List_Action_Inverse(List_T *liste, void (*action)(void *data, void *dummy)) +void List_Action_Inverse(List_T * liste, + void (*action) (void *data, void *dummy)) { - int i,dummy; + int i, dummy; - for(i=List_Nbr(liste) ; i>0 ; i--){ - (*action)(List_Pointer_NoChange(liste,i-1),&dummy); + for(i = List_Nbr(liste); i > 0; i--) { + (*action) (List_Pointer_NoChange(liste, i - 1), &dummy); } } -void List_Copy(List_T *a , List_T *b){ - int i,N; +void List_Copy(List_T * a, List_T * b) +{ + int i, N; N = List_Nbr(a); - for(i=0;i<N;i++){ - List_Add(b,List_Pointer(a,i)); + for(i = 0; i < N; i++) { + List_Add(b, List_Pointer(a, i)); } } -void swap_bytes(char *array, int size, int n){ +void swap_bytes(char *array, int size, int n) +{ int i, c; char *x, *a; - - x = (char*)Malloc(size); - for (i = 0; i < n; i++) { - a = &array[i*size]; + x = (char *)Malloc(size); + + for(i = 0; i < n; i++) { + a = &array[i * size]; memcpy(x, a, size); - for (c = 0; c < size; c++) - a[size-1-c] = x[c]; + for(c = 0; c < size; c++) + a[size - 1 - c] = x[c]; } Free(x); } -List_T *List_CreateFromFile(int n, int size, FILE *file, int format, int swap){ +List_T *List_CreateFromFile(int n, int size, FILE * file, int format, + int swap) +{ int i; List_T *liste; - if(!n) return NULL; - + if(!n) + return NULL; + liste = List_Create(n, 1, size); liste->n = n; - switch(format){ - case LIST_FORMAT_ASCII : + switch (format) { + case LIST_FORMAT_ASCII: if(size == sizeof(double)) - for(i=0;i<n;i++) fscanf(file, "%lf", (double*)&liste->array[i*size]) ; + for(i = 0; i < n; i++) + fscanf(file, "%lf", (double *)&liste->array[i * size]); else if(size == sizeof(float)) - for(i=0;i<n;i++) fscanf(file, "%f", (float*)&liste->array[i*size]) ; + for(i = 0; i < n; i++) + fscanf(file, "%f", (float *)&liste->array[i * size]); else if(size == sizeof(int)) - for(i=0;i<n;i++) fscanf(file, "%d", (int*)&liste->array[i*size]) ; - else if(size == sizeof(char)){ - for(i=0;i<n;i++){ - fscanf(file, "%c", (char*)&liste->array[i*size]) ; - if(liste->array[i*size]=='^') liste->array[i*size]='\0'; + for(i = 0; i < n; i++) + fscanf(file, "%d", (int *)&liste->array[i * size]); + else if(size == sizeof(char)) { + for(i = 0; i < n; i++) { + fscanf(file, "%c", (char *)&liste->array[i * size]); + if(liste->array[i * size] == '^') + liste->array[i * size] = '\0'; } } - else{ + else { Msg(GERROR, "Bad type of data to create list from (size = %d)", size); return NULL; } return liste; - case LIST_FORMAT_BINARY : + case LIST_FORMAT_BINARY: fread(liste->array, size, n, file); - if(swap) swap_bytes(liste->array, size, n); + if(swap) + swap_bytes(liste->array, size, n); return liste; - default : + default: Msg(GERROR, "Unknown list format"); return NULL; } } -void List_WriteToFile(List_T *liste, FILE *file, int format){ +void List_WriteToFile(List_T * liste, FILE * file, int format) +{ int i, n; - if(!(n=List_Nbr(liste))) return ; + if(!(n = List_Nbr(liste))) + return; - switch(format){ - case LIST_FORMAT_ASCII : + switch (format) { + case LIST_FORMAT_ASCII: if(liste->size == sizeof(double)) - for(i=0;i<n;i++) fprintf(file, " %.16g", *((double*)&liste->array[i*liste->size])) ; + for(i = 0; i < n; i++) + fprintf(file, " %.16g", *((double *)&liste->array[i * liste->size])); else if(liste->size == sizeof(float)) - for(i=0;i<n;i++) fprintf(file, " %.16g", *((float*)&liste->array[i*liste->size])) ; + for(i = 0; i < n; i++) + fprintf(file, " %.16g", *((float *)&liste->array[i * liste->size])); else if(liste->size == sizeof(int)) - for(i=0;i<n;i++) fprintf(file, " %d", *((int*)&liste->array[i*liste->size])) ; + for(i = 0; i < n; i++) + fprintf(file, " %d", *((int *)&liste->array[i * liste->size])); else if(liste->size == sizeof(char)) - for(i=0;i<n;i++){ - if(*((char*)&liste->array[i*liste->size]) == '\0') - fprintf(file, "^") ; - else if(*((char*)&liste->array[i*liste->size]) == '^') - fprintf(file, "_") ;//we don't allow '^' as a valid character - else - fprintf(file, "%c", *((char*)&liste->array[i*liste->size])) ; + for(i = 0; i < n; i++) { + if(*((char *)&liste->array[i * liste->size]) == '\0') + fprintf(file, "^"); + else if(*((char *)&liste->array[i * liste->size]) == '^') + fprintf(file, "_"); //we don't allow '^' as a valid character + else + fprintf(file, "%c", *((char *)&liste->array[i * liste->size])); } else - Msg(GERROR, "Bad type of data to write list to file (size = %d)", liste->size); + Msg(GERROR, "Bad type of data to write list to file (size = %d)", + liste->size); break; - case LIST_FORMAT_BINARY : + case LIST_FORMAT_BINARY: safe_fwrite(liste->array, liste->size, n, file); break; - default : + default: Msg(GERROR, "Unknown list format"); } } diff --git a/DataStr/Malloc.cpp b/DataStr/Malloc.cpp index c9360b1f3602cbd82162d083b2e4cd02d45b1015..65798e3e4dad17c863bf8d376cbba7c0c5c5d8fa 100644 --- a/DataStr/Malloc.cpp +++ b/DataStr/Malloc.cpp @@ -1,4 +1,4 @@ -// $Id: Malloc.cpp,v 1.13 2003-01-23 20:19:18 geuzaine Exp $ +// $Id: Malloc.cpp,v 1.14 2003-03-01 22:36:37 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -28,35 +28,43 @@ #include "Malloc.h" #include "Message.h" -void *Malloc(size_t size){ +void *Malloc(size_t size) +{ void *ptr; - if (!size) return(NULL); + if(!size) + return (NULL); ptr = malloc(size); - if (ptr == NULL) + if(ptr == NULL) Msg(FATAL, "Out of memory (buy some more RAM!)"); - return(ptr); + return (ptr); } -void *Calloc(size_t num, size_t size){ +void *Calloc(size_t num, size_t size) +{ void *ptr; - if (!size) return(NULL); + if(!size) + return (NULL); ptr = calloc(num, size); - if (ptr == NULL) + if(ptr == NULL) Msg(FATAL, "Out of memory (buy some more RAM!)"); - return(ptr); + return (ptr); } -void *Realloc(void *ptr, size_t size){ - if (!size) return(NULL); - ptr = realloc(ptr,size); - if (ptr == NULL) +void *Realloc(void *ptr, size_t size) +{ + if(!size) + return (NULL); + ptr = realloc(ptr, size); + if(ptr == NULL) Msg(FATAL, "Out of memory (buy some more RAM!)"); - return(ptr); + return (ptr); } -void Free(void *ptr){ - if (ptr == NULL) return; +void Free(void *ptr) +{ + if(ptr == NULL) + return; free(ptr); } diff --git a/DataStr/SafeIO.cpp b/DataStr/SafeIO.cpp index f49a3cdb3b42e8f5991b3945b69532631baa8e70..897ab58466276ece65af04493a3a07b0307f7cef 100644 --- a/DataStr/SafeIO.cpp +++ b/DataStr/SafeIO.cpp @@ -1,4 +1,4 @@ -// $Id: SafeIO.cpp,v 1.1 2003-02-10 18:57:02 geuzaine Exp $ +// $Id: SafeIO.cpp,v 1.2 2003-03-01 22:36:37 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -42,29 +42,31 @@ Bottom line: don't use safe_fprintf. */ -int safe_fprintf(FILE *stream, char *fmt, ...){ - va_list args; +int safe_fprintf(FILE * stream, char *fmt, ...) +{ + va_list args; - va_start (args, fmt); - vfprintf(stream, fmt, args); - va_end (args); + va_start(args, fmt); + vfprintf(stream, fmt, args); + va_end(args); - if(ferror(stream)){ + if(ferror(stream)) { Msg(GERROR, strerror(errno)); clearerr(stream); return 1; } - + return 0; } /* Safe fwrite routine */ -int safe_fwrite(const void *ptr, size_t size, size_t nmemb, FILE *stream){ +int safe_fwrite(const void *ptr, size_t size, size_t nmemb, FILE * stream) +{ size_t result = fwrite(ptr, size, nmemb, stream); - if(result < nmemb){ - if(result >= 0) /* Partial write */ + if(result < nmemb) { + if(result >= 0) /* Partial write */ Msg(GERROR, "Disk full"); else Msg(GERROR, strerror(errno)); diff --git a/DataStr/Tools.cpp b/DataStr/Tools.cpp index dc7ae3eaaef3aab2b6b9f33e7ff346b9e7af91e8..f0ddb878130c5eb3f5376fb18a55e5907520837a 100644 --- a/DataStr/Tools.cpp +++ b/DataStr/Tools.cpp @@ -1,4 +1,4 @@ -// $Id: Tools.cpp,v 1.8 2003-01-23 20:19:18 geuzaine Exp $ +// $Id: Tools.cpp,v 1.9 2003-03-01 22:36:37 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -25,36 +25,47 @@ // Comparison functions -int fcmp_int(const void *a, const void *b){ - return(*(int*)a - *(int*)b ); +int fcmp_int(const void *a, const void *b) +{ + return (*(int *)a - *(int *)b); } -int fcmp_absint(const void *a, const void *b){ - return( abs(*(int*)a) - abs(*(int*)b) ); +int fcmp_absint(const void *a, const void *b) +{ + return (abs(*(int *)a) - abs(*(int *)b)); } -int fcmp_double(const void *a, const void *b){ - double cmp ; - - cmp = *(double*)a - *(double*)b ; - if (cmp > 1.e-16) return 1 ; - else if (cmp < -1.e-16) return -1 ; - else return 0 ; +int fcmp_double(const void *a, const void *b) +{ + double cmp; + + cmp = *(double *)a - *(double *)b; + if(cmp > 1.e-16) + return 1; + else if(cmp < -1.e-16) + return -1; + else + return 0; } // Tree -> List transfer List_T *pListeTransfert; -void TransfereListe(void *a,void *b){ - List_Add(pListeTransfert,a); +void TransfereListe(void *a, void *b) +{ + List_Add(pListeTransfert, a); } -List_T *Tree2List(Tree_T *pTree){ + +List_T *Tree2List(Tree_T * pTree) +{ int Nb; - Nb = Tree_Nbr(pTree) ; if (Nb == 0) Nb = 1 ; - pListeTransfert = List_Create(Nb,Nb,Tree_Size(pTree)); - Tree_Action(pTree,TransfereListe); - return(pListeTransfert); + Nb = Tree_Nbr(pTree); + if(Nb == 0) + Nb = 1; + pListeTransfert = List_Create(Nb, Nb, Tree_Size(pTree)); + Tree_Action(pTree, TransfereListe); + return (pListeTransfert); } // Algebraic utilities @@ -62,57 +73,74 @@ List_T *Tree2List(Tree_T *pTree){ Tree_T *pTreeTransfert; Tree_T *pTreeTransfert2; -void DupliqueArbre(void *a,void *b){ - Tree_Add(pTreeTransfert,a); +void DupliqueArbre(void *a, void *b) +{ + Tree_Add(pTreeTransfert, a); } -Tree_T *Tree_Duplique(Tree_T *pTree){ - pTreeTransfert = Tree_Create(pTree->size,pTree->root->compar); - Tree_Action(pTree,DupliqueArbre); - return(pTreeTransfert); + +Tree_T *Tree_Duplique(Tree_T * pTree) +{ + pTreeTransfert = Tree_Create(pTree->size, pTree->root->compar); + Tree_Action(pTree, DupliqueArbre); + return (pTreeTransfert); } -void UnitArbre(void *a,void *b){ - Tree_Replace(pTreeTransfert,a); +void UnitArbre(void *a, void *b) +{ + Tree_Replace(pTreeTransfert, a); } -Tree_T *Tree_Union(Tree_T *pTreeA, Tree_T *pTreeB){ + +Tree_T *Tree_Union(Tree_T * pTreeA, Tree_T * pTreeB) +{ pTreeTransfert = Tree_Duplique(pTreeA); - Tree_Action(pTreeB,UnitArbre); - return(pTreeTransfert); + Tree_Action(pTreeB, UnitArbre); + return (pTreeTransfert); } -void Tree_Unit(Tree_T *pTreeA, Tree_T *pTreeB){ + +void Tree_Unit(Tree_T * pTreeA, Tree_T * pTreeB) +{ pTreeTransfert = pTreeA; - Tree_Action(pTreeB,UnitArbre); + Tree_Action(pTreeB, UnitArbre); } - -void SoustraitArbre(void *a,void *b){ - Tree_Suppress(pTreeTransfert,a); +void SoustraitArbre(void *a, void *b) +{ + Tree_Suppress(pTreeTransfert, a); } -Tree_T *Tree_Soustraction(Tree_T *pTreeA, Tree_T *pTreeB){ + +Tree_T *Tree_Soustraction(Tree_T * pTreeA, Tree_T * pTreeB) +{ pTreeTransfert = Tree_Duplique(pTreeA); - Tree_Action(pTreeB,SoustraitArbre); - return(pTreeTransfert); + Tree_Action(pTreeB, SoustraitArbre); + return (pTreeTransfert); } -void Tree_Soustrait(Tree_T *pTreeA, Tree_T *pTreeB){ + +void Tree_Soustrait(Tree_T * pTreeA, Tree_T * pTreeB) +{ pTreeTransfert = pTreeA; - Tree_Action(pTreeB,SoustraitArbre); + Tree_Action(pTreeB, SoustraitArbre); } - -void IntersecteArbre(void *a,void *b){ - if (Tree_Query(pTreeTransfert,a)) Tree_Add(pTreeTransfert2,a); +void IntersecteArbre(void *a, void *b) +{ + if(Tree_Query(pTreeTransfert, a)) + Tree_Add(pTreeTransfert2, a); } -Tree_T *Tree_Intersection(Tree_T *pTreeA, Tree_T *pTreeB){ + +Tree_T *Tree_Intersection(Tree_T * pTreeA, Tree_T * pTreeB) +{ pTreeTransfert = Tree_Duplique(pTreeA); - pTreeTransfert2= Tree_Create(pTreeA->size,pTreeA->root->compar); - Tree_Action(pTreeB,IntersecteArbre); + pTreeTransfert2 = Tree_Create(pTreeA->size, pTreeA->root->compar); + Tree_Action(pTreeB, IntersecteArbre); Tree_Delete(pTreeTransfert); - return(pTreeTransfert2); + return (pTreeTransfert2); } -void Tree_Intersecte(Tree_T *pTreeA, Tree_T *pTreeB){ + +void Tree_Intersecte(Tree_T * pTreeA, Tree_T * pTreeB) +{ pTreeTransfert2 = pTreeA; - pTreeTransfert = Tree_Create(pTreeA->size,pTreeA->root->compar); - Tree_Action(pTreeB,IntersecteArbre); + pTreeTransfert = Tree_Create(pTreeA->size, pTreeA->root->compar); + Tree_Action(pTreeB, IntersecteArbre); pTreeA = pTreeTransfert2; Tree_Delete(pTreeA); } diff --git a/DataStr/Tree.cpp b/DataStr/Tree.cpp index 0b8df23dc4799ee8a2d0c04ae0298951089455a5..9a03b1738cd27065f3b2f2cac714a385f460d2ab 100644 --- a/DataStr/Tree.cpp +++ b/DataStr/Tree.cpp @@ -1,4 +1,4 @@ -// $Id: Tree.cpp,v 1.12 2003-01-23 20:19:18 geuzaine Exp $ +// $Id: Tree.cpp,v 1.13 2003-03-01 22:36:37 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -26,7 +26,7 @@ #include "Tree.h" #include "Message.h" -Tree_T *Tree_Create(int size, int (*fcmp)(const void *a, const void *b)) +Tree_T *Tree_Create(int size, int (*fcmp) (const void *a, const void *b)) { Tree_T *tree; @@ -35,159 +35,174 @@ Tree_T *Tree_Create(int size, int (*fcmp)(const void *a, const void *b)) tree->size = size; tree->root = avl_init_table(fcmp); - return(tree); + return (tree); } -void Tree_Delete(Tree_T *tree) +void Tree_Delete(Tree_T * tree) { - if(!tree) return; + if(!tree) + return; avl_free_table(tree->root, Free, 0); Free(tree); } -void Tree_Add(Tree_T *tree, void *data) +void Tree_Add(Tree_T * tree, void *data) { void *ptr; - if(!tree) + if(!tree) Msg(GERROR, "Impossible to add in unallocated tree"); - else{ + else { ptr = Malloc(tree->size); - memcpy(ptr,data,tree->size); + memcpy(ptr, data, tree->size); avl_insert(tree->root, ptr, ptr); } } -void * Tree_AddP(Tree_T *tree, void *data) +void *Tree_AddP(Tree_T * tree, void *data) { void *ptr; - if(!tree) + if(!tree) Msg(FATAL, "Impossible to add in unallocated tree"); ptr = Malloc(tree->size); - memcpy(ptr,data,tree->size); + memcpy(ptr, data, tree->size); avl_insert(tree->root, ptr, ptr); - return ptr ; + return ptr; } -int Tree_Nbr(Tree_T *tree) +int Tree_Nbr(Tree_T * tree) { - if(!tree) return 0; - return(avl_count(tree->root)); + if(!tree) + return 0; + return (avl_count(tree->root)); } -void Tree_Insert(Tree_T *tree, void *data) +void Tree_Insert(Tree_T * tree, void *data) { - if (Tree_Search(tree,data) == 0) - Tree_Add(tree,data); + if(Tree_Search(tree, data) == 0) + Tree_Add(tree, data); } -int Tree_Replace(Tree_T *tree, void *data) +int Tree_Replace(Tree_T * tree, void *data) { void *ptr; int state; if(!tree) { Msg(GERROR, "Impossible to replace in unallocated tree"); - return(0); + return (0); } state = avl_lookup(tree->root, data, &ptr); - if (state == 0) { - Tree_Add(tree,data); - return(0); + if(state == 0) { + Tree_Add(tree, data); + return (0); } else { - memcpy(ptr,data,tree->size); + memcpy(ptr, data, tree->size); return (1); } } -int Tree_Search(Tree_T *tree, void *data) +int Tree_Search(Tree_T * tree, void *data) { void *ptr; - if(!tree) return 0; + if(!tree) + return 0; return (avl_lookup(tree->root, data, &ptr)); } -int Tree_Query(Tree_T *tree, void *data) +int Tree_Query(Tree_T * tree, void *data) { void *ptr; int state; - if(!tree) return 0; + if(!tree) + return 0; state = avl_lookup(tree->root, data, &ptr); - if (state == 0) return(0); + if(state == 0) + return (0); - memcpy(data,ptr,tree->size); + memcpy(data, ptr, tree->size); return (1); } -void *Tree_PQuery(Tree_T *tree, void *data) +void *Tree_PQuery(Tree_T * tree, void *data) { void *ptr; int state; - if(!tree) return 0; + if(!tree) + return 0; state = avl_lookup(tree->root, data, &ptr); - if (state == 0) return(NULL); + if(state == 0) + return (NULL); return (ptr); } -int Tree_Suppress(Tree_T *tree, void *data) +int Tree_Suppress(Tree_T * tree, void *data) { void *ptr; int state; - if(!tree) return 0; + if(!tree) + return 0; ptr = data; - state = avl_delete(tree->root, &ptr, &ptr) ; - if (state == 0) return(0); + state = avl_delete(tree->root, &ptr, &ptr); + if(state == 0) + return (0); Free(ptr); - return(1); + return (1); } -int Tree_Left(Tree_T *tree, void *data) +int Tree_Left(Tree_T * tree, void *data) { void *ptr; int state; - if(!tree) return 0; + if(!tree) + return 0; state = avl_extremum(tree->root, AVL_MOST_LEFT, &ptr); - if (state == 0) return (0); + if(state == 0) + return (0); - memcpy(data,ptr,tree->size); + memcpy(data, ptr, tree->size); return (1); } -int Tree_Right(Tree_T *tree, void *data) +int Tree_Right(Tree_T * tree, void *data) { void *ptr; int state; - if(!tree) return 0; + if(!tree) + return 0; state = avl_extremum(tree->root, AVL_MOST_RIGHT, &ptr); - if (state == 0) return (0); + if(state == 0) + return (0); - memcpy(data,ptr,tree->size); + memcpy(data, ptr, tree->size); return (1); } -int Tree_Size(Tree_T *tree) { - if(!tree) return 0; +int Tree_Size(Tree_T * tree) +{ + if(!tree) + return 0; - return(tree->size); + return (tree->size); } diff --git a/Fltk/Callbacks.cpp b/Fltk/Callbacks.cpp index 7ab4c1bbc09a0ba705c0eadc1bf2ae2cc0708abc..93a5a03ce97f2f32044a47713818a7647ed91173 100644 --- a/Fltk/Callbacks.cpp +++ b/Fltk/Callbacks.cpp @@ -1,4 +1,4 @@ -// $Id: Callbacks.cpp,v 1.165 2003-02-25 16:49:36 geuzaine Exp $ +// $Id: Callbacks.cpp,v 1.166 2003-03-01 22:36:37 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -45,9 +45,9 @@ using namespace std; #include <errno.h> -extern GUI *WID; -extern Mesh *THEM; -extern Context_T CTX; +extern GUI *WID; +extern Mesh *THEM; +extern Context_T CTX; // File chooser (re)definitions @@ -57,17 +57,23 @@ extern Context_T CTX; static char *fn = NULL; -int file_chooser(int multi, const char* message, const char* pat, int patindex){ - fn = fl_file_chooser(message,pat,NULL); - if(fn) return 1; - else return 0; +int file_chooser(int multi, const char *message, const char *pat, + int patindex) +{ + fn = fl_file_chooser(message, pat, NULL); + if(fn) + return 1; + else + return 0; } -char* file_chooser_get_name(int num){ +char *file_chooser_get_name(int num) +{ return fn; } -int file_chooser_get_filter(){ +int file_chooser_get_filter() +{ return 0; } @@ -78,20 +84,22 @@ int file_chooser_get_filter(){ static Fl_File_Chooser *fc = NULL; -int file_chooser(int multi, const char* message, const char* pat, int patindex){ +int file_chooser(int multi, const char *message, const char *pat, + int patindex) +{ static char oldfilter[1024]; Fl_File_Chooser::show_label = "Format:"; Fl_File_Chooser::all_files_label = "All files (*)"; - if (!fc) { + if(!fc) { fc = new Fl_File_Chooser(".", pat, Fl_File_Chooser::CREATE, message); strncpy(oldfilter, pat, 1024); } fc->label(message); - if(strncmp(oldfilter, pat, 1024)){ + if(strncmp(oldfilter, pat, 1024)) { strncpy(oldfilter, pat, 1024); fc->filter(pat); fc->filter_value(patindex); @@ -104,7 +112,8 @@ int file_chooser(int multi, const char* message, const char* pat, int patindex){ fc->show(); - while (fc->shown()) Fl::wait(); + while(fc->shown()) + Fl::wait(); if(fc->value()) return fc->count(); @@ -112,16 +121,18 @@ int file_chooser(int multi, const char* message, const char* pat, int patindex){ return 0; } -char* file_chooser_get_name(int num){ +char *file_chooser_get_name(int num) +{ // to get the relative path: // static char retname[1024]; // fl_filename_relative(retname, sizeof(retname), fc->value(num)); // return retname; - return (char*)fc->value(num); + return (char *)fc->value(num); } -int file_chooser_get_filter(){ +int file_chooser_get_filter() +{ return fc->filter_value(); } @@ -129,52 +140,68 @@ int file_chooser_get_filter(){ // Compatibility/local routines -int AddViewInUI(int i, char *Name, int Num){ - if(i > NB_BUTT_MAX -1) return 1; - if(WID){ +int AddViewInUI(int i, char *Name, int Num) +{ + if(i > NB_BUTT_MAX - 1) + return 1; + if(WID) { if(WID->get_context() == 3) - WID->set_context(menu_post,0); + WID->set_context(menu_post, 0); WID->reset_option_browser(); } return 0; } -int SetGlobalShortcut(int event){ +int SetGlobalShortcut(int event) +{ return WID->global_shortcuts(event); } -int SelectContour (int type, int num, List_T *Liste1){ - int k=0,ip,i; - List_T *Liste2; +int SelectContour(int type, int num, List_T * Liste1) +{ + int k = 0, ip, i; + List_T *Liste2; - Liste2 = List_Create(1,1,sizeof(int)); + Liste2 = List_Create(1, 1, sizeof(int)); - if(!List_Nbr(Liste1)){ - switch(type){ - case ENT_LINE : k = alledgeslinked (num, Liste1, (List_T*)NULL); break; - case ENT_SURFACE : k = allfaceslinked (num, Liste1, (List_T*)NULL); break; + if(!List_Nbr(Liste1)) { + switch (type) { + case ENT_LINE: + k = alledgeslinked(num, Liste1, (List_T *) NULL); + break; + case ENT_SURFACE: + k = allfaceslinked(num, Liste1, (List_T *) NULL); + break; } } - else{ + else { List_Reset(Liste2); - for(i=0;i<List_Nbr(Liste1);i++) - List_Add(Liste2,List_Pointer(Liste1,i)); + for(i = 0; i < List_Nbr(Liste1); i++) + List_Add(Liste2, List_Pointer(Liste1, i)); List_Reset(Liste1); - switch(type){ - case ENT_LINE : k = alledgeslinked (num, Liste1, Liste2); break; - case ENT_SURFACE : k = allfaceslinked (num, Liste1, Liste2); break; + switch (type) { + case ENT_LINE: + k = alledgeslinked(num, Liste1, Liste2); + break; + case ENT_SURFACE: + k = allfaceslinked(num, Liste1, Liste2); + break; } } - for(i=0;i<List_Nbr(Liste1);i++){ - List_Read(Liste1,i,&ip); - switch(type){ - case ENT_LINE : HighlightEntityNum(0,abs(ip),0,1); break ; - case ENT_SURFACE : HighlightEntityNum(0,0,abs(ip),1); break ; + for(i = 0; i < List_Nbr(Liste1); i++) { + List_Read(Liste1, i, &ip); + switch (type) { + case ENT_LINE: + HighlightEntityNum(0, abs(ip), 0, 1); + break; + case ENT_SURFACE: + HighlightEntityNum(0, 0, abs(ip), 1); + break; } } - Draw();//added July 18 2001 to overcome missing refreshes... Is this OK ? + Draw(); //added July 18 2001 to overcome missing refreshes... Is this OK ? List_Delete(Liste2); return k; } @@ -182,489 +209,602 @@ int SelectContour (int type, int num, List_T *Liste1){ // Common callbacks -void cancel_cb(CALLBACK_ARGS){ - if(data) ((Fl_Window*)data)->hide(); +void cancel_cb(CALLBACK_ARGS) +{ + if(data) + ((Fl_Window *) data)->hide(); } -void color_cb(CALLBACK_ARGS){ +void color_cb(CALLBACK_ARGS) +{ unsigned int (*fct) (int, int, unsigned int); - fct = (unsigned int (*) (int, int, unsigned int))data ; - uchar r = UNPACK_RED(fct(0,GMSH_GET,0)) ; - uchar g = UNPACK_GREEN(fct(0,GMSH_GET,0)) ; - uchar b = UNPACK_BLUE(fct(0,GMSH_GET,0)) ; - if (fl_color_chooser("Color Chooser",r,g,b)) - fct(0,GMSH_SET|GMSH_GUI,PACK_COLOR(r,g,b,255)); + fct = (unsigned int (*)(int, int, unsigned int))data; + uchar r = UNPACK_RED(fct(0, GMSH_GET, 0)); + uchar g = UNPACK_GREEN(fct(0, GMSH_GET, 0)); + uchar b = UNPACK_BLUE(fct(0, GMSH_GET, 0)); + if(fl_color_chooser("Color Chooser", r, g, b)) + fct(0, GMSH_SET | GMSH_GUI, PACK_COLOR(r, g, b, 255)); Draw(); } -void set_changed_cb(CALLBACK_ARGS){ +void set_changed_cb(CALLBACK_ARGS) +{ w->set_changed(); } // Graphical window -void status_xyz1p_cb(CALLBACK_ARGS){ - +void status_xyz1p_cb(CALLBACK_ARGS) +{ extern void set_r(int i, double val); extern void set_t(int i, double val); extern void set_s(int i, double val); - switch((long int)data){ - case 0 : + switch ((long int)data) { + case 0: if(CTX.useTrackball) - CTX.setQuaternion(0.,-1./sqrt(2.),0.,1./sqrt(2.)); - set_r(0,0.); set_r(1,90.);set_r(2,0.); - Draw(); + CTX.setQuaternion(0., -1. / sqrt(2.), 0., 1. / sqrt(2.)); + set_r(0, 0.); + set_r(1, 90.); + set_r(2, 0.); + Draw(); break; - case 1 : + case 1: if(CTX.useTrackball) - CTX.setQuaternion(1./sqrt(2.),0.,0.,1./sqrt(2.)); - set_r(0,-90.);set_r(1,0.); set_r(2,0.); - Draw(); + CTX.setQuaternion(1. / sqrt(2.), 0., 0., 1. / sqrt(2.)); + set_r(0, -90.); + set_r(1, 0.); + set_r(2, 0.); + Draw(); break; - case 2 : + case 2: if(CTX.useTrackball) - CTX.setQuaternion(0.,0.,0.,1.); - set_r(0,0.); set_r(1,0.); set_r(2,0.); - Draw(); + CTX.setQuaternion(0., 0., 0., 1.); + set_r(0, 0.); + set_r(1, 0.); + set_r(2, 0.); + Draw(); break; - case 3 : - set_t(0,0.); set_t(1,0.); set_t(2,0.); - set_s(0,1.); set_s(1,1.); set_s(2,1.); - Draw(); + case 3: + set_t(0, 0.); + set_t(1, 0.); + set_t(2, 0.); + set_s(0, 1.); + set_s(1, 1.); + set_s(2, 1.); + Draw(); break; - case 4 : - Print_Options(0,GMSH_FULLRC,NULL); + case 4: + Print_Options(0, GMSH_FULLRC, NULL); WID->create_message_window(); - break ; + break; } } -static int stop_anim, view_in_cycle=-1 ; -void ManualPlay(int time, int step){ +static int stop_anim, view_in_cycle = -1; + +void ManualPlay(int time, int step) +{ int i; - if(time){ - for(i=0 ; i<List_Nbr(CTX.post.list) ; i++) + if(time) { + for(i = 0; i < List_Nbr(CTX.post.list); i++) if(opt_view_visible(i, GMSH_GET, 0)) - opt_view_timestep(i, GMSH_SET|GMSH_GUI, opt_view_timestep(i, GMSH_GET, 0)+step); + opt_view_timestep(i, GMSH_SET | GMSH_GUI, + opt_view_timestep(i, GMSH_GET, 0) + step); } - else{//hide all views except view_in_cycle - if(step>0){ - if((view_in_cycle+=step)>=List_Nbr(CTX.post.list)) view_in_cycle=0; - for(i=0 ; i<List_Nbr(CTX.post.list) ; i+=step) - opt_view_visible(i, GMSH_SET|GMSH_GUI, (i==view_in_cycle)); + else { //hide all views except view_in_cycle + if(step > 0) { + if((view_in_cycle += step) >= List_Nbr(CTX.post.list)) + view_in_cycle = 0; + for(i = 0; i < List_Nbr(CTX.post.list); i += step) + opt_view_visible(i, GMSH_SET | GMSH_GUI, (i == view_in_cycle)); } - else{ - if((view_in_cycle+=step)<0) view_in_cycle=List_Nbr(CTX.post.list)-1; - for(i=List_Nbr(CTX.post.list)-1 ; i>=0 ; i+=step) - opt_view_visible(i, GMSH_SET|GMSH_GUI, (i==view_in_cycle)); + else { + if((view_in_cycle += step) < 0) + view_in_cycle = List_Nbr(CTX.post.list) - 1; + for(i = List_Nbr(CTX.post.list) - 1; i >= 0; i += step) + opt_view_visible(i, GMSH_SET | GMSH_GUI, (i == view_in_cycle)); } } Draw(); } -void status_play_cb(CALLBACK_ARGS){ - static long anim_time ; + +void status_play_cb(CALLBACK_ARGS) +{ + static long anim_time; WID->set_anim_buttons(0); - stop_anim = 0 ; + stop_anim = 0; anim_time = GetTime(); - while(1){ - if(stop_anim) break ; - if(GetTime() - anim_time > 1.e6*CTX.post.anim_delay){ + while(1) { + if(stop_anim) + break; + if(GetTime() - anim_time > 1.e6 * CTX.post.anim_delay) { anim_time = GetTime(); - ManualPlay(!CTX.post.anim_cycle,1); + ManualPlay(!CTX.post.anim_cycle, 1); } WID->check(); } } -void status_pause_cb(CALLBACK_ARGS){ +void status_pause_cb(CALLBACK_ARGS) +{ stop_anim = 1; WID->set_anim_buttons(1); } -void status_rewind_cb(CALLBACK_ARGS){ +void status_rewind_cb(CALLBACK_ARGS) +{ int i; - if(!CTX.post.anim_cycle){ - for(i=0 ; i<List_Nbr(CTX.post.list) ; i++) - opt_view_timestep(i, GMSH_SET|GMSH_GUI, 0); + if(!CTX.post.anim_cycle) { + for(i = 0; i < List_Nbr(CTX.post.list); i++) + opt_view_timestep(i, GMSH_SET | GMSH_GUI, 0); } - else{ + else { view_in_cycle = 0; - for(i=0 ; i<List_Nbr(CTX.post.list) ; i++) - opt_view_visible(i, GMSH_SET|GMSH_GUI, !i); + for(i = 0; i < List_Nbr(CTX.post.list); i++) + opt_view_visible(i, GMSH_SET | GMSH_GUI, !i); } Draw(); } -void status_cancel_cb(CALLBACK_ARGS){ +void status_cancel_cb(CALLBACK_ARGS) +{ + ; } // File Menu -void file_open_cb(CALLBACK_ARGS) { +void file_open_cb(CALLBACK_ARGS) +{ int n = List_Nbr(CTX.post.list); - if(file_chooser(0,"Open file", "*", 0)){ - OpenProblem(file_chooser_get_name(1)); - Draw(); + if(file_chooser(0, "Open file", "*", 0)) { + OpenProblem(file_chooser_get_name(1)); + Draw(); } if(n != List_Nbr(CTX.post.list)) WID->set_context(menu_post, 0); } -void file_merge_cb(CALLBACK_ARGS) { +void file_merge_cb(CALLBACK_ARGS) +{ int n = List_Nbr(CTX.post.list); - int f = file_chooser(1,"Merge file(s)", "*", 0); - if (f) { - for(int i=1; i<=f; i++) - MergeProblem(file_chooser_get_name(i)); - Draw(); + int f = file_chooser(1, "Merge file(s)", "*", 0); + if(f) { + for(int i = 1; i <= f; i++) + MergeProblem(file_chooser_get_name(i)); + Draw(); } if(n != List_Nbr(CTX.post.list)) WID->set_context(menu_post, 0); } -void _save_auto(char *name){ - CreateOutputFile(name, FORMAT_AUTO); +void _save_auto(char *name) +{ + CreateOutputFile(name, FORMAT_AUTO); } -void _save_geo_options(char *name){ - CreateOutputFile(name, FORMAT_OPT); +void _save_geo_options(char *name) +{ + CreateOutputFile(name, FORMAT_OPT); } -void _save_geo(char *name){ - CreateOutputFile(name, FORMAT_GEO); +void _save_geo(char *name) +{ + CreateOutputFile(name, FORMAT_GEO); } -void _save_msh(char *name){ - CreateOutputFile(name, CTX.mesh.format = FORMAT_MSH); +void _save_msh(char *name) +{ + CreateOutputFile(name, CTX.mesh.format = FORMAT_MSH); } -void _save_msh_all(char *name){ +void _save_msh_all(char *name) +{ int all = CTX.mesh.save_all; CTX.mesh.save_all = 1; - CreateOutputFile(name, CTX.mesh.format = FORMAT_MSH); + CreateOutputFile(name, CTX.mesh.format = FORMAT_MSH); CTX.mesh.save_all = all; } -void _save_gref(char *name){ - CreateOutputFile(name, CTX.mesh.format = FORMAT_GREF); +void _save_gref(char *name) +{ + CreateOutputFile(name, CTX.mesh.format = FORMAT_GREF); } -void _save_unv(char *name){ - CreateOutputFile(name, CTX.mesh.format = FORMAT_UNV); +void _save_unv(char *name) +{ + CreateOutputFile(name, CTX.mesh.format = FORMAT_UNV); } -void _save_vrml(char *name){ - CreateOutputFile(name, CTX.mesh.format = FORMAT_VRML); +void _save_vrml(char *name) +{ + CreateOutputFile(name, CTX.mesh.format = FORMAT_VRML); } -void _save_ps_simple(char *name){ +void _save_ps_simple(char *name) +{ int old = CTX.print.eps_quality; - CTX.print.eps_quality = 1; - CreateOutputFile(name, FORMAT_PS); - CTX.print.eps_quality = old; + CTX.print.eps_quality = 1; + CreateOutputFile(name, FORMAT_PS); + CTX.print.eps_quality = old; } -void _save_ps_accurate(char *name){ +void _save_ps_accurate(char *name) +{ int old = CTX.print.eps_quality; - CTX.print.eps_quality = 2; - CreateOutputFile(name, FORMAT_PS); - CTX.print.eps_quality = old; + CTX.print.eps_quality = 2; + CreateOutputFile(name, FORMAT_PS); + CTX.print.eps_quality = old; } -void _save_eps_simple(char *name){ +void _save_eps_simple(char *name) +{ int old = CTX.print.eps_quality; - CTX.print.eps_quality = 1; - CreateOutputFile(name, FORMAT_EPS); - CTX.print.eps_quality = old; + CTX.print.eps_quality = 1; + CreateOutputFile(name, FORMAT_EPS); + CTX.print.eps_quality = old; } -void _save_eps_accurate(char *name){ +void _save_eps_accurate(char *name) +{ int old = CTX.print.eps_quality; - CTX.print.eps_quality = 2; - CreateOutputFile(name, FORMAT_EPS); - CTX.print.eps_quality = old; + CTX.print.eps_quality = 2; + CreateOutputFile(name, FORMAT_EPS); + CTX.print.eps_quality = old; } -void _save_pstex_simple(char *name){ +void _save_pstex_simple(char *name) +{ int old = CTX.print.eps_quality; - CTX.print.eps_quality = 1; - CreateOutputFile(name, FORMAT_PSTEX); - CTX.print.eps_quality = old; + CTX.print.eps_quality = 1; + CreateOutputFile(name, FORMAT_PSTEX); + CTX.print.eps_quality = old; } -void _save_pstex_accurate(char *name){ +void _save_pstex_accurate(char *name) +{ int old = CTX.print.eps_quality; - CTX.print.eps_quality = 2; - CreateOutputFile(name, FORMAT_PSTEX); - CTX.print.eps_quality = old; + CTX.print.eps_quality = 2; + CreateOutputFile(name, FORMAT_PSTEX); + CTX.print.eps_quality = old; } -void _save_epstex_simple(char *name){ +void _save_epstex_simple(char *name) +{ int old = CTX.print.eps_quality; - CTX.print.eps_quality = 1; - CreateOutputFile(name, FORMAT_EPSTEX); - CTX.print.eps_quality = old; + CTX.print.eps_quality = 1; + CreateOutputFile(name, FORMAT_EPSTEX); + CTX.print.eps_quality = old; } -void _save_epstex_accurate(char *name){ +void _save_epstex_accurate(char *name) +{ int old = CTX.print.eps_quality; - CTX.print.eps_quality = 2; - CreateOutputFile(name, FORMAT_EPSTEX); - CTX.print.eps_quality = old; + CTX.print.eps_quality = 2; + CreateOutputFile(name, FORMAT_EPSTEX); + CTX.print.eps_quality = old; } -void _save_jpegtex(char *name){ - CreateOutputFile(name, FORMAT_JPEGTEX); +void _save_jpegtex(char *name) +{ + CreateOutputFile(name, FORMAT_JPEGTEX); } -void _save_tex(char *name){ - CreateOutputFile(name, FORMAT_TEX); +void _save_tex(char *name) +{ + CreateOutputFile(name, FORMAT_TEX); } -void _save_jpeg(char *name){ - CreateOutputFile(name, FORMAT_JPEG); +void _save_jpeg(char *name) +{ + CreateOutputFile(name, FORMAT_JPEG); } -void _save_gif(char *name){ +void _save_gif(char *name) +{ int dither = CTX.print.gif_dither; int transp = CTX.print.gif_transparent; CTX.print.gif_dither = 0; CTX.print.gif_transparent = 0; - CreateOutputFile(name, FORMAT_GIF); + CreateOutputFile(name, FORMAT_GIF); CTX.print.gif_dither = dither; CTX.print.gif_transparent = transp; } -void _save_gif_dithered(char *name){ +void _save_gif_dithered(char *name) +{ int dither = CTX.print.gif_dither; int transp = CTX.print.gif_transparent; - CTX.print.gif_dither = 1; - CTX.print.gif_transparent = 0; - CreateOutputFile(name, FORMAT_GIF); + CTX.print.gif_dither = 1; + CTX.print.gif_transparent = 0; + CreateOutputFile(name, FORMAT_GIF); CTX.print.gif_dither = dither; CTX.print.gif_transparent = transp; } -void _save_gif_transparent(char *name){ +void _save_gif_transparent(char *name) +{ int dither = CTX.print.gif_dither; int transp = CTX.print.gif_transparent; CTX.print.gif_dither = 0; - CTX.print.gif_transparent = 1; + CTX.print.gif_transparent = 1; CreateOutputFile(name, FORMAT_GIF); CTX.print.gif_dither = dither; CTX.print.gif_transparent = transp; } -void _save_ppm(char *name){ - CreateOutputFile(name, FORMAT_PPM); +void _save_ppm(char *name) +{ + CreateOutputFile(name, FORMAT_PPM); } -void _save_yuv(char *name){ - CreateOutputFile(name, FORMAT_YUV); +void _save_yuv(char *name) +{ + CreateOutputFile(name, FORMAT_YUV); } typedef struct{ char *pat; - void (*func)(char *name) ; + void (*func) (char *name); } patXfunc; #include <sys/types.h> #include <sys/stat.h> -void file_save_as_cb(CALLBACK_ARGS) { +void file_save_as_cb(CALLBACK_ARGS) +{ int i, nbformats; - static int patindex=0; - static char *pat=NULL; - static patXfunc formats[] ={ - { "By extension (*)", _save_auto }, - { "Gmsh options (*.opt)", _save_geo_options }, - { "Gmsh unrolled geometry (*.geo)", _save_geo }, - { "Gmsh mesh (*.msh)", _save_msh }, - { "Gmsh mesh without physicals (*.msh)", _save_msh_all }, - { "GREF mesh (*.gref)", _save_gref }, - { "I-DEAS universal mesh format (*.unv)", _save_unv }, - { "VRML surface mesh (*.wrl)", _save_vrml }, - { "GIF (*.gif)", _save_gif }, - { "GIF dithered (*.gif)", _save_gif_dithered }, - { "GIF transparent (*.gif)", _save_gif_transparent }, - { "JPEG (*.jpg)", _save_jpeg }, - { "PostScript fast (*.ps)", _save_ps_simple }, - { "PostScript accurate (*.ps)", _save_ps_accurate }, - { "Encapsulated PostScript fast (*.eps)", _save_eps_simple }, - { "Encapsulated PostScript accurate (*.eps)", _save_eps_accurate }, - { "PPM (*.ppm)", _save_ppm }, - { "LaTeX JPEG part (*.jpg)", _save_jpegtex }, - { "LaTeX EPS part fast (*.eps)", _save_epstex_simple }, - { "LaTeX EPS part accurate (*.eps)", _save_epstex_accurate }, - { "LaTeX TeX part (*.tex)", _save_tex }, - { "UCB YUV (*.yuv)", _save_yuv } + static int patindex = 0; + static char *pat = NULL; + static patXfunc formats[] = { + {"By extension (*)", _save_auto}, + {"Gmsh options (*.opt)", _save_geo_options}, + {"Gmsh unrolled geometry (*.geo)", _save_geo}, + {"Gmsh mesh (*.msh)", _save_msh}, + {"Gmsh mesh without physicals (*.msh)", _save_msh_all}, + {"GREF mesh (*.gref)", _save_gref}, + {"I-DEAS universal mesh format (*.unv)", _save_unv}, + {"VRML surface mesh (*.wrl)", _save_vrml}, + {"GIF (*.gif)", _save_gif}, + {"GIF dithered (*.gif)", _save_gif_dithered}, + {"GIF transparent (*.gif)", _save_gif_transparent}, + {"JPEG (*.jpg)", _save_jpeg}, + {"PostScript fast (*.ps)", _save_ps_simple}, + {"PostScript accurate (*.ps)", _save_ps_accurate}, + {"Encapsulated PostScript fast (*.eps)", _save_eps_simple}, + {"Encapsulated PostScript accurate (*.eps)", _save_eps_accurate}, + {"PPM (*.ppm)", _save_ppm}, + {"LaTeX JPEG part (*.jpg)", _save_jpegtex}, + {"LaTeX EPS part fast (*.eps)", _save_epstex_simple}, + {"LaTeX EPS part accurate (*.eps)", _save_epstex_accurate}, + {"LaTeX TeX part (*.tex)", _save_tex}, + {"UCB YUV (*.yuv)", _save_yuv} }; - nbformats = sizeof(formats)/sizeof(formats[0]); + nbformats = sizeof(formats) / sizeof(formats[0]); - if(!pat){ - pat = (char*)Malloc(nbformats*256*sizeof(char)); + if(!pat) { + pat = (char *)Malloc(nbformats * 256 * sizeof(char)); strcpy(pat, formats[0].pat); - for(i=1; i<nbformats; i++){ + for(i = 1; i < nbformats; i++) { strcat(pat, "\t"); strcat(pat, formats[i].pat); } } - test: +test: - if(file_chooser(0,"Save file as", pat, patindex)){ + if(file_chooser(0, "Save file as", pat, patindex)) { char *name = file_chooser_get_name(1); - if(CTX.confirm_overwrite){ + if(CTX.confirm_overwrite) { struct stat buf; if(!stat(name, &buf)) - if(fl_ask("%s already exists.\nDo you want to replace it?", name)) - goto save; - else - goto test; + if(fl_ask("%s already exists.\nDo you want to replace it?", name)) + goto save; + else + goto test; } save: i = file_chooser_get_filter(); - if(i>=0 && i<nbformats) + if(i >= 0 && i < nbformats) formats[i].func(name); - else // handle any additional automatic fltk filter + else // handle any additional automatic fltk filter _save_auto(name); - + } patindex = file_chooser_get_filter(); } -void file_save_as_auto_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save file by extension", "*", 0)) +void file_save_as_auto_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save file by extension", "*", 0)) _save_auto(file_chooser_get_name(1)); } -void file_save_as_geo_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save GEO file", "*", 0)) +void file_save_as_geo_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save GEO file", "*", 0)) _save_geo(file_chooser_get_name(1)); } -void file_save_as_geo_options_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save option file", "*", 0)) +void file_save_as_geo_options_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save option file", "*", 0)) _save_geo_options(file_chooser_get_name(1)); } -void file_save_as_msh_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save MSH file", "*", 0)) +void file_save_as_msh_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save MSH file", "*", 0)) _save_msh(file_chooser_get_name(1)); } -void file_save_as_msh_all_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save MSH file (no physicals)", "*", 0)) + +void file_save_as_msh_all_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save MSH file (no physicals)", "*", 0)) _save_msh_all(file_chooser_get_name(1)); } -void file_save_as_unv_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save UNV file", "*", 0)) + +void file_save_as_unv_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save UNV file", "*", 0)) _save_unv(file_chooser_get_name(1)); } -void file_save_as_gref_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save GREF file", "*", 0)) + +void file_save_as_gref_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save GREF file", "*", 0)) _save_gref(file_chooser_get_name(1)); } -void file_save_as_vrml_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save VRML file", "*", 0)) + +void file_save_as_vrml_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save VRML file", "*", 0)) _save_vrml(file_chooser_get_name(1)); } -void file_save_as_ps_simple_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save PS file", "*", 0)) + +void file_save_as_ps_simple_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save PS file", "*", 0)) _save_ps_simple(file_chooser_get_name(1)); } -void file_save_as_ps_accurate_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save PS file", "*", 0)) + +void file_save_as_ps_accurate_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save PS file", "*", 0)) _save_ps_accurate(file_chooser_get_name(1)); } -void file_save_as_pstex_simple_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save LaTeX file (PS part)", "*", 0)) + +void file_save_as_pstex_simple_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save LaTeX file (PS part)", "*", 0)) _save_pstex_simple(file_chooser_get_name(1)); } -void file_save_as_pstex_accurate_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save LaTeX file (PS part)", "*", 0)) + +void file_save_as_pstex_accurate_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save LaTeX file (PS part)", "*", 0)) _save_ps_accurate(file_chooser_get_name(1)); } -void file_save_as_jpegtex_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save LaTeX file (Jpeg part)", "*", 0)) + +void file_save_as_jpegtex_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save LaTeX file (Jpeg part)", "*", 0)) _save_jpegtex(file_chooser_get_name(1)); } -void file_save_as_tex_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save LaTeX file (TeX part)", "*", 0)) + +void file_save_as_tex_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save LaTeX file (TeX part)", "*", 0)) _save_tex(file_chooser_get_name(1)); } -void file_save_as_jpeg_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save JPEG file", "*", 0)) + +void file_save_as_jpeg_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save JPEG file", "*", 0)) _save_jpeg(file_chooser_get_name(1)); } -void file_save_as_gif_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save GIF file", "*", 0)) + +void file_save_as_gif_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save GIF file", "*", 0)) _save_gif(file_chooser_get_name(1)); } -void file_save_as_gif_dithered_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save GIF file", "*", 0)) + +void file_save_as_gif_dithered_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save GIF file", "*", 0)) _save_gif_dithered(file_chooser_get_name(1)); } -void file_save_as_gif_transparent_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save GIF file", "*", 0)) + +void file_save_as_gif_transparent_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save GIF file", "*", 0)) _save_gif_transparent(file_chooser_get_name(1)); } -void file_save_as_ppm_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save PPM file", "*", 0)) + +void file_save_as_ppm_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save PPM file", "*", 0)) _save_ppm(file_chooser_get_name(1)); } -void file_save_as_yuv_cb(CALLBACK_ARGS) { - if(file_chooser(0,"Save YUV file", "*", 0)) + +void file_save_as_yuv_cb(CALLBACK_ARGS) +{ + if(file_chooser(0, "Save YUV file", "*", 0)) _save_yuv(file_chooser_get_name(1)); } -void file_quit_cb(CALLBACK_ARGS) { +void file_quit_cb(CALLBACK_ARGS) +{ Exit(0); } // Option Menu -void options_cb(CALLBACK_ARGS) { +void options_cb(CALLBACK_ARGS) +{ WID->create_option_window(); } -void options_browser_cb(CALLBACK_ARGS) { - switch(WID->opt_browser->value()){ - case 0 : break; - case 1 : WID->create_general_options_window(); break; - case 2 : WID->create_geometry_options_window(); break; - case 3 : WID->create_mesh_options_window(); break; - case 4 : WID->create_solver_options_window(); break; - case 5 : WID->create_post_options_window(); break; - default : WID->create_view_options_window(WID->opt_browser->value()-6); break; +void options_browser_cb(CALLBACK_ARGS) +{ + switch (WID->opt_browser->value()) { + case 0: + break; + case 1: + WID->create_general_options_window(); + break; + case 2: + WID->create_geometry_options_window(); + break; + case 3: + WID->create_mesh_options_window(); + break; + case 4: + WID->create_solver_options_window(); + break; + case 5: + WID->create_post_options_window(); + break; + default: + WID->create_view_options_window(WID->opt_browser->value() - 6); + break; } } -void options_save_cb(CALLBACK_ARGS) { - Print_Options(0,GMSH_OPTIONSRC, CTX.optionsrc_filename); +void options_save_cb(CALLBACK_ARGS) +{ + Print_Options(0, GMSH_OPTIONSRC, CTX.optionsrc_filename); } #include <unistd.h> -void options_restore_defaults_cb(CALLBACK_ARGS) { +void options_restore_defaults_cb(CALLBACK_ARGS) +{ // not sure if we have to remove the file... unlink(CTX.sessionrc_filename); unlink(CTX.optionsrc_filename); ReInit_Options(0); Init_Options_GUI(0); - if(WID && WID->get_context() == 3) // hack to refresh the buttons - WID->set_context(menu_post,0); + if(WID && WID->get_context() == 3) // hack to refresh the buttons + WID->set_context(menu_post, 0); Draw(); } -void options_ok_cb(CALLBACK_ARGS) { - general_options_ok_cb(w,data); - geometry_options_ok_cb(w,data); - mesh_options_ok_cb(w,data); - solver_options_ok_cb(w,data); - post_options_ok_cb(w,data); - view_options_ok_cb(w, (void*)WID->view_number); +void options_ok_cb(CALLBACK_ARGS) +{ + general_options_ok_cb(w, data); + geometry_options_ok_cb(w, data); + mesh_options_ok_cb(w, data); + solver_options_ok_cb(w, data); + post_options_ok_cb(w, data); + view_options_ok_cb(w, (void *)WID->view_number); Draw(); } // General options -void general_options_cb(CALLBACK_ARGS) { +void general_options_cb(CALLBACK_ARGS) +{ WID->create_general_options_window(); } -void general_options_color_scheme_cb(CALLBACK_ARGS){ - opt_general_color_scheme(0,GMSH_SET, WID->gen_value[0]->value()); + +void general_options_color_scheme_cb(CALLBACK_ARGS) +{ + opt_general_color_scheme(0, GMSH_SET, WID->gen_value[0]->value()); Draw(); } -void general_options_ok_cb(CALLBACK_ARGS){ + +void general_options_ok_cb(CALLBACK_ARGS) +{ opt_general_axes(0, GMSH_SET, WID->gen_butt[0]->value()); opt_general_small_axes(0, GMSH_SET, WID->gen_butt[1]->value()); opt_general_fast_redraw(0, GMSH_SET, WID->gen_butt[2]->value()); if(opt_general_double_buffer(0, GMSH_GET, 0) != WID->gen_butt[3]->value()) opt_general_double_buffer(0, GMSH_SET, WID->gen_butt[3]->value()); - opt_post_display_lists(0, GMSH_SET, WID->gen_butt[4]->value());//this has to move + opt_post_display_lists(0, GMSH_SET, WID->gen_butt[4]->value()); //this has to move opt_general_alpha_blending(0, GMSH_SET, WID->gen_butt[5]->value()); opt_general_trackball(0, GMSH_SET, WID->gen_butt[6]->value()); opt_general_terminal(0, GMSH_SET, WID->gen_butt[7]->value()); @@ -686,23 +826,30 @@ void general_options_ok_cb(CALLBACK_ARGS){ opt_general_point_size(0, GMSH_SET, WID->gen_value[6]->value()); opt_general_line_width(0, GMSH_SET, WID->gen_value[7]->value()); - opt_general_default_filename(0, GMSH_SET, (char*)WID->gen_input[0]->value()); - opt_general_tmp_filename(0, GMSH_SET, (char*)WID->gen_input[1]->value()); - opt_general_error_filename(0, GMSH_SET, (char*)WID->gen_input[2]->value()); - opt_general_options_filename(0, GMSH_SET, (char*)WID->gen_input[3]->value()); - opt_general_editor(0, GMSH_SET, (char*)WID->gen_input[4]->value()); + opt_general_default_filename(0, GMSH_SET, + (char *)WID->gen_input[0]->value()); + opt_general_tmp_filename(0, GMSH_SET, (char *)WID->gen_input[1]->value()); + opt_general_error_filename(0, GMSH_SET, (char *)WID->gen_input[2]->value()); + opt_general_options_filename(0, GMSH_SET, + (char *)WID->gen_input[3]->value()); + opt_general_editor(0, GMSH_SET, (char *)WID->gen_input[4]->value()); } // Geometry options -void geometry_options_cb(CALLBACK_ARGS) { +void geometry_options_cb(CALLBACK_ARGS) +{ WID->create_geometry_options_window(); } -void geometry_options_color_scheme_cb(CALLBACK_ARGS){ - opt_geometry_color_scheme(0,GMSH_SET, WID->geo_value[2]->value()); + +void geometry_options_color_scheme_cb(CALLBACK_ARGS) +{ + opt_geometry_color_scheme(0, GMSH_SET, WID->geo_value[2]->value()); Draw(); } -void geometry_options_ok_cb(CALLBACK_ARGS) { + +void geometry_options_ok_cb(CALLBACK_ARGS) +{ opt_geometry_points(0, GMSH_SET, WID->geo_butt[0]->value()); opt_geometry_lines(0, GMSH_SET, WID->geo_butt[1]->value()); opt_geometry_surfaces(0, GMSH_SET, WID->geo_butt[2]->value()); @@ -725,19 +872,24 @@ void geometry_options_ok_cb(CALLBACK_ARGS) { // Mesh options -void mesh_options_cb(CALLBACK_ARGS) { +void mesh_options_cb(CALLBACK_ARGS) +{ WID->create_mesh_options_window(); } -void mesh_options_color_scheme_cb(CALLBACK_ARGS){ - opt_mesh_color_scheme(0,GMSH_SET, WID->mesh_value[12]->value()); + +void mesh_options_color_scheme_cb(CALLBACK_ARGS) +{ + opt_mesh_color_scheme(0, GMSH_SET, WID->mesh_value[12]->value()); Draw(); } -void mesh_options_ok_cb(CALLBACK_ARGS) { - opt_mesh_algo(0, GMSH_SET, - WID->mesh_butt[0]->value()?DELAUNAY_ISO: - WID->mesh_butt[1]->value()?DELAUNAY_SHEWCHUK: - DELAUNAY_ANISO); - opt_mesh_degree(0, GMSH_SET, WID->mesh_butt[3]->value()?2:1); + +void mesh_options_ok_cb(CALLBACK_ARGS) +{ + opt_mesh_algo(0, GMSH_SET, + WID->mesh_butt[0]->value()? DELAUNAY_ISO : + WID->mesh_butt[1]->value()? DELAUNAY_SHEWCHUK : + DELAUNAY_ANISO); + opt_mesh_degree(0, GMSH_SET, WID->mesh_butt[3]->value()? 2 : 1); opt_mesh_interactive(0, GMSH_SET, WID->mesh_butt[4]->value()); opt_mesh_constrained_bgmesh(0, GMSH_SET, WID->mesh_butt[5]->value()); opt_mesh_points(0, GMSH_SET, WID->mesh_butt[6]->value()); @@ -748,10 +900,9 @@ void mesh_options_ok_cb(CALLBACK_ARGS) { opt_mesh_lines_num(0, GMSH_SET, WID->mesh_butt[11]->value()); opt_mesh_surfaces_num(0, GMSH_SET, WID->mesh_butt[12]->value()); opt_mesh_volumes_num(0, GMSH_SET, WID->mesh_butt[13]->value()); - opt_mesh_aspect(0, GMSH_SET, - WID->mesh_butt[14]->value()?0: - WID->mesh_butt[15]->value()?1: - 2); + opt_mesh_aspect(0, GMSH_SET, + WID->mesh_butt[14]->value()? 0 : + WID->mesh_butt[15]->value()? 1 : 2); opt_mesh_color_carousel(0, GMSH_SET, WID->mesh_butt[17]->value()); opt_mesh_nb_smoothing(0, GMSH_SET, WID->mesh_value[0]->value()); @@ -763,7 +914,7 @@ void mesh_options_ok_cb(CALLBACK_ARGS) { opt_mesh_radius_inf(0, GMSH_SET, WID->mesh_value[6]->value()); opt_mesh_radius_sup(0, GMSH_SET, WID->mesh_value[7]->value()); opt_mesh_normals(0, GMSH_SET, WID->mesh_value[8]->value()); - opt_mesh_explode(0, GMSH_SET, WID->mesh_value[9]->value()); + opt_mesh_explode(0, GMSH_SET, WID->mesh_value[9]->value()); opt_mesh_tangents(0, GMSH_SET, WID->mesh_value[13]->value()); opt_mesh_point_size(0, GMSH_SET, WID->mesh_value[10]->value()); opt_mesh_line_width(0, GMSH_SET, WID->mesh_value[11]->value()); @@ -774,24 +925,29 @@ void mesh_options_ok_cb(CALLBACK_ARGS) { // Solver options -void solver_options_cb(CALLBACK_ARGS) { +void solver_options_cb(CALLBACK_ARGS) +{ WID->create_solver_options_window(); } -void solver_options_ok_cb(CALLBACK_ARGS) { + +void solver_options_ok_cb(CALLBACK_ARGS) +{ } // Post options -void post_options_cb(CALLBACK_ARGS) { +void post_options_cb(CALLBACK_ARGS) +{ WID->create_post_options_window(); } -void post_options_ok_cb(CALLBACK_ARGS) { - opt_post_link(0, GMSH_SET, - WID->post_butt[0]->value()?0: - WID->post_butt[1]->value()?1: - WID->post_butt[2]->value()?2: - WID->post_butt[3]->value()?3: - 4); + +void post_options_ok_cb(CALLBACK_ARGS) +{ + opt_post_link(0, GMSH_SET, + WID->post_butt[0]->value()? 0 : + WID->post_butt[1]->value()? 1 : + WID->post_butt[2]->value()? 2 : + WID->post_butt[3]->value()? 3 : 4); opt_post_smooth(0, GMSH_SET, WID->post_butt[5]->value()); opt_post_anim_cycle(0, GMSH_SET, WID->post_butt[6]->value()); @@ -801,100 +957,134 @@ void post_options_ok_cb(CALLBACK_ARGS) { // Statistics Menu -void statistics_cb(CALLBACK_ARGS) { +void statistics_cb(CALLBACK_ARGS) +{ WID->create_statistics_window(); } -void statistics_update_cb(CALLBACK_ARGS) { + +void statistics_update_cb(CALLBACK_ARGS) +{ WID->set_statistics(); } -void statistics_histogram_cb(CALLBACK_ARGS) { - int i, type=(long int)data; + +void statistics_histogram_cb(CALLBACK_ARGS) +{ + int i, type = (long int)data; Print_Histogram(THEM->Histogram[type]); - double *x=(double*)Malloc(NB_HISTOGRAM*sizeof(double)); - double *y=(double*)Malloc(NB_HISTOGRAM*sizeof(double)); - for(i=0;i<NB_HISTOGRAM;i++){ - x[i]=(double)(i+1)/(double)NB_HISTOGRAM; - y[i]=(double)THEM->Histogram[type][i]; + double *x = (double *)Malloc(NB_HISTOGRAM * sizeof(double)); + double *y = (double *)Malloc(NB_HISTOGRAM * sizeof(double)); + for(i = 0; i < NB_HISTOGRAM; i++) { + x[i] = (double)(i + 1) / (double)NB_HISTOGRAM; + y[i] = (double)THEM->Histogram[type][i]; } char *name; - if(type==0) name = "Gamma"; - else if(type==1) name = "Eta"; - else name = "Rho"; - Create2DGraph(name,"Elements",NB_HISTOGRAM,x,y); - Draw(); + if(type == 0) + name = "Gamma"; + else if(type == 1) + name = "Eta"; + else + name = "Rho"; + Create2DGraph(name, "Elements", NB_HISTOGRAM, x, y); + Draw(); } // Messages Menu -void message_cb(CALLBACK_ARGS) { +void message_cb(CALLBACK_ARGS) +{ WID->create_message_window(); } -void message_copy_cb(CALLBACK_ARGS) { + +void message_copy_cb(CALLBACK_ARGS) +{ #if (FL_MAJOR_VERSION == 1) && (FL_MINOR_VERSION == 0) // Fl::copy does not exist in older versions of fltk #else #define BUFFL 50000 static char buff[BUFFL]; strcpy(buff, ""); - for(int i = 1 ; i<=WID->msg_browser->size() ; i++){ - if(WID->msg_browser->selected(i)){ - const char *c=WID->msg_browser->text(i); - if(strlen(buff)+strlen(c)>BUFFL-2){ - Msg(GERROR, "Text selection too large to copy"); - break; + for(int i = 1; i <= WID->msg_browser->size(); i++) { + if(WID->msg_browser->selected(i)) { + const char *c = WID->msg_browser->text(i); + if(strlen(buff) + strlen(c) > BUFFL - 2) { + Msg(GERROR, "Text selection too large to copy"); + break; } - if(c[0]=='@') strcat(buff,&c[3]); - else strcat(buff, c); + if(c[0] == '@') + strcat(buff, &c[3]); + else + strcat(buff, c); strcat(buff, "\n"); } } Fl::copy(buff, strlen(buff), 0); #endif } -void message_clear_cb(CALLBACK_ARGS) { + +void message_clear_cb(CALLBACK_ARGS) +{ WID->msg_browser->clear(); } -void message_save_cb(CALLBACK_ARGS) { - test: - if(file_chooser(0,"Save messages", "*", 0)){ + +void message_save_cb(CALLBACK_ARGS) +{ +test: + if(file_chooser(0, "Save messages", "*", 0)) { char *name = file_chooser_get_name(1); - if(CTX.confirm_overwrite){ + if(CTX.confirm_overwrite) { struct stat buf; if(!stat(name, &buf)) - if(fl_ask("%s already exists.\nDo you want to replace it?", name)) - goto save; - else - goto test; + if(fl_ask("%s already exists.\nDo you want to replace it?", name)) + goto save; + else + goto test; } save: - WID->save_message(name); + WID->save_message(name); } } // Option Visibility Menu -#if (FL_MAJOR_VERSION == 2) // disabled for fltk 2 at the moment -void select_vis_browser(int mode){} -void visibility_cb(CALLBACK_ARGS) {} -void visibility_ok_cb(CALLBACK_ARGS) {} -void visibility_sort_cb(CALLBACK_ARGS){} -void visibility_number_cb(CALLBACK_ARGS){} +#if (FL_MAJOR_VERSION == 2) // disabled for fltk 2 at the moment +void select_vis_browser(int mode) +{ + ; +} +void visibility_cb(CALLBACK_ARGS) +{ + ; +} +void visibility_ok_cb(CALLBACK_ARGS) +{ + ; +} +void visibility_sort_cb(CALLBACK_ARGS) +{ + ; +} +void visibility_number_cb(CALLBACK_ARGS) +{ + ; +} #else -void select_vis_browser(int mode){ +void select_vis_browser(int mode) +{ int i; Entity *e; - for(i=1 ; i<=WID->vis_browser->size(); i++){ - e = (Entity*)WID->vis_browser->data(i); - if((mode == VIS_GEOM|VIS_MESH && e->Visible() == mode) || - (mode == VIS_GEOM && e->Visible() & VIS_GEOM) || - (mode == VIS_MESH && e->Visible() & VIS_MESH)) + for(i = 1; i <= WID->vis_browser->size(); i++) { + e = (Entity *) WID->vis_browser->data(i); + if((mode == VIS_GEOM | VIS_MESH && e->Visible() == mode) || + (mode == VIS_GEOM && e->Visible() & VIS_GEOM) || + (mode == VIS_MESH && e->Visible() & VIS_MESH)) WID->vis_browser->select(i); } } -void visibility_cb(CALLBACK_ARGS) { +void visibility_cb(CALLBACK_ARGS) +{ int i, type, mode; List_T *list; Entity *e; @@ -902,66 +1092,91 @@ void visibility_cb(CALLBACK_ARGS) { WID->create_visibility_window(); WID->vis_browser->clear(); - switch(WID->vis_type->value()){ - case 0 : type = ELEMENTARY; break; - default: type = PHYSICAL; break; + switch (WID->vis_type->value()) { + case 0: + type = ELEMENTARY; + break; + default: + type = PHYSICAL; + break; } - switch(WID->vis_browser_mode->value()){ - case 0 : mode = VIS_GEOM|VIS_MESH; break; - case 1 : mode = VIS_GEOM; break; - default: mode = VIS_MESH; break; + switch (WID->vis_browser_mode->value()) { + case 0: + mode = VIS_GEOM | VIS_MESH; + break; + case 1: + mode = VIS_GEOM; + break; + default: + mode = VIS_MESH; + break; } list = GetVisibilityList(type); - for(i=0 ; i<List_Nbr(list); i++){ - e = (Entity*)List_Pointer(list,i); - WID->vis_browser->add(e->BrowserLine(),e); + for(i = 0; i < List_Nbr(list); i++) { + e = (Entity *) List_Pointer(list, i); + WID->vis_browser->add(e->BrowserLine(), e); } select_vis_browser(mode); } -void visibility_ok_cb(CALLBACK_ARGS) { +void visibility_ok_cb(CALLBACK_ARGS) +{ int i, mode; Entity *e; InitVisibilityThroughPhysical(); - switch(WID->vis_type->value()){ - case 0 : ClearVisibilityList(PHYSICAL); break; - default: ClearVisibilityList(ELEMENTARY); break; - } - switch(WID->vis_browser_mode->value()){ - case 0 : mode = VIS_GEOM|VIS_MESH; break; - case 1 : mode = VIS_GEOM; break; - default: mode = VIS_MESH; break; - } - - for(i=1 ; i<=WID->vis_browser->size(); i++){ - e = (Entity*)WID->vis_browser->data(i); - if(WID->vis_browser->selected(i)){ - e->Visible(e->Visible()|mode); - } - else{ - switch(WID->vis_browser_mode->value()){ - case 0 : - e->Visible(0); - break; - case 1 : - if(e->Visible() & VIS_MESH) e->Visible(VIS_MESH); - else e->Visible(0); - break; - default : - if(e->Visible() & VIS_GEOM) e->Visible(VIS_GEOM); - else e->Visible(0); - break; + switch (WID->vis_type->value()) { + case 0: + ClearVisibilityList(PHYSICAL); + break; + default: + ClearVisibilityList(ELEMENTARY); + break; + } + switch (WID->vis_browser_mode->value()) { + case 0: + mode = VIS_GEOM | VIS_MESH; + break; + case 1: + mode = VIS_GEOM; + break; + default: + mode = VIS_MESH; + break; + } + + for(i = 1; i <= WID->vis_browser->size(); i++) { + e = (Entity *) WID->vis_browser->data(i); + if(WID->vis_browser->selected(i)) { + e->Visible(e->Visible() | mode); + } + else { + switch (WID->vis_browser_mode->value()) { + case 0: + e->Visible(0); + break; + case 1: + if(e->Visible() & VIS_MESH) + e->Visible(VIS_MESH); + else + e->Visible(0); + break; + default: + if(e->Visible() & VIS_GEOM) + e->Visible(VIS_GEOM); + else + e->Visible(0); + break; } } } - if(WID->vis_butt[0]->value()){ - for(i=1 ; i<=WID->vis_browser->size(); i++){ - e = (Entity*)WID->vis_browser->data(i); + if(WID->vis_butt[0]->value()) { + for(i = 1; i <= WID->vis_browser->size(); i++) { + e = (Entity *) WID->vis_browser->data(i); e->RecurVisible(); } select_vis_browser(mode); @@ -970,41 +1185,49 @@ void visibility_ok_cb(CALLBACK_ARGS) { Draw(); } -void visibility_sort_cb(CALLBACK_ARGS){ +void visibility_sort_cb(CALLBACK_ARGS) +{ int i, val = (long int)data, selectall; - if(!val){ - selectall=0; - for(i=1 ; i<=WID->vis_browser->size(); i++) - if(!WID->vis_browser->selected(i)){ - selectall=1; - break; + if(!val) { + selectall = 0; + for(i = 1; i <= WID->vis_browser->size(); i++) + if(!WID->vis_browser->selected(i)) { + selectall = 1; + break; } if(selectall) - for(i=1 ; i<=WID->vis_browser->size(); i++) - WID->vis_browser->select(i); + for(i = 1; i <= WID->vis_browser->size(); i++) + WID->vis_browser->select(i); else WID->vis_browser->deselect(); } - else{ + else { SetVisibilitySort(val); - visibility_cb(NULL,NULL); + visibility_cb(NULL, NULL); } } -void visibility_number_cb(CALLBACK_ARGS){ +void visibility_number_cb(CALLBACK_ARGS) +{ int pos, mode, type = WID->vis_input_mode->value(); - char *str = (char*)((Fl_Input*)w)->value(); + char *str = (char *)((Fl_Input *) w)->value(); - switch(WID->vis_browser_mode->value()){ - case 0 : mode = VIS_GEOM|VIS_MESH; break; - case 1 : mode = VIS_GEOM; break; - default: mode = VIS_MESH; break; + switch (WID->vis_browser_mode->value()) { + case 0: + mode = VIS_GEOM | VIS_MESH; + break; + case 1: + mode = VIS_GEOM; + break; + default: + mode = VIS_MESH; + break; } SetVisibilityByNumber(str, type, mode); pos = WID->vis_browser->position(); - visibility_cb(NULL,NULL); + visibility_cb(NULL, NULL); WID->vis_browser->position(pos); Draw(); @@ -1024,7 +1247,8 @@ void visibility_number_cb(CALLBACK_ARGS){ #define XX "Ctrl" #endif -void help_short_cb(CALLBACK_ARGS){ +void help_short_cb(CALLBACK_ARGS) +{ // *INDENT-OFF* Msg(DIRECT, ""); Msg(DIRECT, "Mouse:"); @@ -1105,723 +1329,929 @@ void help_short_cb(CALLBACK_ARGS){ #undef XX -void help_command_line_cb(CALLBACK_ARGS){ +void help_command_line_cb(CALLBACK_ARGS) +{ Msg(DIRECT, ""); Print_Usage("gmsh"); WID->create_message_window(); } -void help_about_cb(CALLBACK_ARGS){ + +void help_about_cb(CALLBACK_ARGS) +{ WID->create_about_window(); } // Module Menu -void mod_geometry_cb(CALLBACK_ARGS){ +void mod_geometry_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry, 0); } -void mod_mesh_cb(CALLBACK_ARGS){ + +void mod_mesh_cb(CALLBACK_ARGS) +{ WID->set_context(menu_mesh, 0); } -void mod_solver_cb(CALLBACK_ARGS){ + +void mod_solver_cb(CALLBACK_ARGS) +{ WID->set_context(menu_solver, 0); } -void mod_post_cb(CALLBACK_ARGS){ + +void mod_post_cb(CALLBACK_ARGS) +{ WID->set_context(menu_post, 0); } -void mod_back_cb(CALLBACK_ARGS){ + +void mod_back_cb(CALLBACK_ARGS) +{ WID->set_context(NULL, -1); } -void mod_forward_cb(CALLBACK_ARGS){ + +void mod_forward_cb(CALLBACK_ARGS) +{ WID->set_context(NULL, 1); } // Dynamic Geomtry Menus -void geometry_elementary_cb(CALLBACK_ARGS){ +void geometry_elementary_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_elementary, 0); } -void geometry_physical_cb(CALLBACK_ARGS){ + +void geometry_physical_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_physical, 0); } -void geometry_edit_cb(CALLBACK_ARGS){ + +void geometry_edit_cb(CALLBACK_ARGS) +{ char cmd[1000]; sprintf(cmd, CTX.editor, CTX.filename); Msg(INFO, "Starting text editor '%s'", cmd); SystemCall(cmd); -} -void geometry_reload_cb(CALLBACK_ARGS){ +} + +void geometry_reload_cb(CALLBACK_ARGS) +{ OpenProblem(CTX.filename); Draw(); -} -void geometry_elementary_add_cb(CALLBACK_ARGS){ +} + +void geometry_elementary_add_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_elementary_add, 0); } -void geometry_elementary_add_new_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_new_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_elementary_add_new, 0); } -void geometry_elementary_add_new_parameter_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_new_parameter_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(0); } -void geometry_elementary_add_new_point_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_new_point_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(1); } -static void _new_multiline(int type){ - Vertex *v; - Curve *c; - Surface *s; - int ib; +static void _new_multiline(int type) +{ + Vertex *v; + Curve *c; + Surface *s; + int ib; static int n, p[100]; - if(!opt_geometry_points(0,GMSH_GET,0)){ - opt_geometry_points(0,GMSH_SET|GMSH_GUI,1); + if(!opt_geometry_points(0, GMSH_GET, 0)) { + opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); Draw(); } n = 0; - while(1){ - Msg(STATUS3N,"Select Point ('e'=end, 'q'=quit)"); - ib = SelectEntity(ENT_POINT, &v,&c,&s); - if(ib == 1){ /* left mouse butt */ - p[n++] = v->Num; + while(1) { + Msg(STATUS3N, "Select Point ('e'=end, 'q'=quit)"); + ib = SelectEntity(ENT_POINT, &v, &c, &s); + if(ib == 1) { /* left mouse butt */ + p[n++] = v->Num; } - if (ib == -1){ /* 'e' */ + if(ib == -1) { /* 'e' */ if(n >= 2) { - switch(type){ - case 0 : add_multline(n,p,CTX.filename); break; - case 1 : add_spline(n,p,CTX.filename); break; - case 2 : add_bspline(n,p,CTX.filename); break; - case 3 : add_bezier(n,p,CTX.filename); break; - } + switch (type) { + case 0: + add_multline(n, p, CTX.filename); + break; + case 1: + add_spline(n, p, CTX.filename); + break; + case 2: + add_bspline(n, p, CTX.filename); + break; + case 3: + add_bezier(n, p, CTX.filename); + break; + } } - n=0; + n = 0; ZeroHighlight(THEM); Draw(); } - if(ib == 0){ /* 'q' */ - n=0 ; + if(ib == 0) { /* 'q' */ + n = 0; ZeroHighlight(THEM); Draw(); break; } } - Msg(STATUS3N,"Ready"); + Msg(STATUS3N, "Ready"); } -void geometry_elementary_add_new_line_cb(CALLBACK_ARGS){ +void geometry_elementary_add_new_line_cb(CALLBACK_ARGS) +{ // Disallow multiline selection at the moment, since multilines // dont't work so well... // //_new_multiline(0); // - Vertex *v; - Curve *c; - Surface *s; - int ib; + Vertex *v; + Curve *c; + Surface *s; + int ib; static int n, p[100]; - if(!opt_geometry_points(0,GMSH_GET,0)){ - opt_geometry_points(0,GMSH_SET|GMSH_GUI,1); + if(!opt_geometry_points(0, GMSH_GET, 0)) { + opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); Draw(); } - n=0; - while(1){ - if(n == 0) Msg(STATUS3N,"Select start Point ('q'=quit)"); - if(n == 1) Msg(STATUS3N,"Select end Point ('q'=quit)"); - ib = SelectEntity(ENT_POINT, &v,&c,&s); - if(ib == 1) { /* left mouse butt */ - p[n++] = v->Num; - } - if(ib == 0) { /* 'q' */ - n=0 ; + n = 0; + while(1) { + if(n == 0) + Msg(STATUS3N, "Select start Point ('q'=quit)"); + if(n == 1) + Msg(STATUS3N, "Select end Point ('q'=quit)"); + ib = SelectEntity(ENT_POINT, &v, &c, &s); + if(ib == 1) { /* left mouse butt */ + p[n++] = v->Num; + } + if(ib == 0) { /* 'q' */ + n = 0; ZeroHighlight(THEM); Draw(); break; } - if(n == 2){ - add_multline(2,p,CTX.filename); + if(n == 2) { + add_multline(2, p, CTX.filename); ZeroHighlight(THEM); Draw(); - n=0; + n = 0; } } - Msg(STATUS3N,"Ready"); + Msg(STATUS3N, "Ready"); } -void geometry_elementary_add_new_spline_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_new_spline_cb(CALLBACK_ARGS) +{ _new_multiline(1); } -void geometry_elementary_add_new_bspline_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_new_bspline_cb(CALLBACK_ARGS) +{ _new_multiline(2); } -void geometry_elementary_add_new_circle_cb(CALLBACK_ARGS){ - Vertex *v; - Curve *c; - Surface *s; - int ib; + +void geometry_elementary_add_new_circle_cb(CALLBACK_ARGS) +{ + Vertex *v; + Curve *c; + Surface *s; + int ib; static int n, p[100]; - if(!opt_geometry_points(0,GMSH_GET,0)){ - opt_geometry_points(0,GMSH_SET|GMSH_GUI,1); + if(!opt_geometry_points(0, GMSH_GET, 0)) { + opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); Draw(); } - n=0; - while(1){ - if(n == 0) Msg(STATUS3N,"Select start Point ('q'=quit)"); - if(n == 1) Msg(STATUS3N,"Select center Point ('q'=quit)"); - if(n == 2) Msg(STATUS3N,"Select end Point ('q'=quit)"); - ib = SelectEntity(ENT_POINT, &v,&c,&s); - if(ib == 1) { /* left mouse butt */ - p[n++] = v->Num; - } - if(ib == 0) { /* 'q' */ - n=0 ; + n = 0; + while(1) { + if(n == 0) + Msg(STATUS3N, "Select start Point ('q'=quit)"); + if(n == 1) + Msg(STATUS3N, "Select center Point ('q'=quit)"); + if(n == 2) + Msg(STATUS3N, "Select end Point ('q'=quit)"); + ib = SelectEntity(ENT_POINT, &v, &c, &s); + if(ib == 1) { /* left mouse butt */ + p[n++] = v->Num; + } + if(ib == 0) { /* 'q' */ + n = 0; ZeroHighlight(THEM); Draw(); break; } - if(n == 3){ - add_circ(p[0],p[1],p[2],CTX.filename); /* begin, center, end */ + if(n == 3) { + add_circ(p[0], p[1], p[2], CTX.filename); /* begin, center, end */ ZeroHighlight(THEM); Draw(); - n=0; + n = 0; } } - Msg(STATUS3N,"Ready"); + Msg(STATUS3N, "Ready"); } -void geometry_elementary_add_new_ellipse_cb(CALLBACK_ARGS){ - Vertex *v; - Curve *c; - Surface *s; - int ib; + +void geometry_elementary_add_new_ellipse_cb(CALLBACK_ARGS) +{ + Vertex *v; + Curve *c; + Surface *s; + int ib; static int n, p[100]; - if(!opt_geometry_points(0,GMSH_GET,0)){ - opt_geometry_points(0,GMSH_SET|GMSH_GUI,1); + if(!opt_geometry_points(0, GMSH_GET, 0)) { + opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); Draw(); } - n=0; - while(1){ - if(n == 0) Msg(STATUS3N,"Select start Point ('q'=quit)"); - if(n == 1) Msg(STATUS3N,"Select center Point ('q'=quit)"); - if(n == 2) Msg(STATUS3N,"Select major axis Point ('q'=quit)"); - if(n == 3) Msg(STATUS3N,"Select end Point ('q'=quit)"); - ib = SelectEntity(ENT_POINT, &v,&c,&s); - if(ib == 1) { /* left mouse butt */ - p[n++] = v->Num; - } - if(ib == 0){ /* 'q' */ - n=0 ; + n = 0; + while(1) { + if(n == 0) + Msg(STATUS3N, "Select start Point ('q'=quit)"); + if(n == 1) + Msg(STATUS3N, "Select center Point ('q'=quit)"); + if(n == 2) + Msg(STATUS3N, "Select major axis Point ('q'=quit)"); + if(n == 3) + Msg(STATUS3N, "Select end Point ('q'=quit)"); + ib = SelectEntity(ENT_POINT, &v, &c, &s); + if(ib == 1) { /* left mouse butt */ + p[n++] = v->Num; + } + if(ib == 0) { /* 'q' */ + n = 0; ZeroHighlight(THEM); Draw(); break; } - if(n == 4){ - add_ell(p[0],p[1],p[2],p[3],CTX.filename); + if(n == 4) { + add_ell(p[0], p[1], p[2], p[3], CTX.filename); ZeroHighlight(THEM); Draw(); - n=0; + n = 0; } } - Msg(STATUS3N,"Ready"); + Msg(STATUS3N, "Ready"); } -static void _new_surface_volume(int mode){ - Vertex *v; - Curve *c; - Surface *s; - int ib, type, zone; - List_T *Liste1, *Liste2; +static void _new_surface_volume(int mode) +{ + Vertex *v; + Curve *c; + Surface *s; + int ib, type, zone; + List_T *Liste1, *Liste2; + + Liste1 = List_Create(10, 10, sizeof(int)); + Liste2 = List_Create(10, 10, sizeof(int)); - Liste1 = List_Create(10,10,sizeof(int)); - Liste2 = List_Create(10,10,sizeof(int)); - - if(mode == 2){ + if(mode == 2) { type = ENT_SURFACE; - if(!opt_geometry_surfaces(0,GMSH_GET,0)){ - opt_geometry_surfaces(0,GMSH_SET|GMSH_GUI,1); + if(!opt_geometry_surfaces(0, GMSH_GET, 0)) { + opt_geometry_surfaces(0, GMSH_SET | GMSH_GUI, 1); Draw(); } } - else{ + else { type = ENT_LINE; - if(!opt_geometry_lines(0,GMSH_GET,0)){ - opt_geometry_lines(0,GMSH_SET|GMSH_GUI,1); + if(!opt_geometry_lines(0, GMSH_GET, 0)) { + opt_geometry_lines(0, GMSH_SET | GMSH_GUI, 1); Draw(); } } - - while(1){ + + while(1) { List_Reset(Liste1); List_Reset(Liste2); - - while(1) { - Msg(STATUS3N,"Select boundary ('q'=quit)"); - ib = SelectEntity(type, &v,&c,&s); - if(ib <= 0){ - ZeroHighlight(THEM); - Draw(); - goto stopall; - } - if(SelectContour (type, (type==ENT_LINE)?c->Num:s->Num, Liste1)){ - if(type==ENT_LINE) - add_loop(Liste1,CTX.filename,&zone); - else - add_vol(Liste1,CTX.filename,&zone); - List_Reset(Liste1); - List_Add(Liste2,&zone); - while(1){ - Msg(STATUS3N,"Select holes ('q'=quit)"); - ib = SelectEntity(type, &v,&c,&s); - if(ib <= 0){ - ZeroHighlight(THEM); - Draw(); - break; - } - if(SelectContour (type, (type==ENT_LINE)?c->Num:s->Num, Liste1)){ - if(type==ENT_LINE) - add_loop(Liste1,CTX.filename,&zone); - else - add_vol(Liste1,CTX.filename,&zone); - List_Reset(Liste1); - List_Add(Liste2,&zone); - } - } - if(List_Nbr(Liste2)){ - switch(mode){ - case 0 : add_surf(Liste2,CTX.filename,0,2); break; - case 1 : add_surf(Liste2,CTX.filename,0,1); break; - case 2 : add_multvol(Liste2,CTX.filename); break; - } - ZeroHighlight(THEM); - Draw(); - break; - } + + while(1) { + Msg(STATUS3N, "Select boundary ('q'=quit)"); + ib = SelectEntity(type, &v, &c, &s); + if(ib <= 0) { + ZeroHighlight(THEM); + Draw(); + goto stopall; + } + if(SelectContour(type, (type == ENT_LINE) ? c->Num : s->Num, Liste1)) { + if(type == ENT_LINE) + add_loop(Liste1, CTX.filename, &zone); + else + add_vol(Liste1, CTX.filename, &zone); + List_Reset(Liste1); + List_Add(Liste2, &zone); + while(1) { + Msg(STATUS3N, "Select holes ('q'=quit)"); + ib = SelectEntity(type, &v, &c, &s); + if(ib <= 0) { + ZeroHighlight(THEM); + Draw(); + break; + } + if(SelectContour + (type, (type == ENT_LINE) ? c->Num : s->Num, Liste1)) { + if(type == ENT_LINE) + add_loop(Liste1, CTX.filename, &zone); + else + add_vol(Liste1, CTX.filename, &zone); + List_Reset(Liste1); + List_Add(Liste2, &zone); + } + } + if(List_Nbr(Liste2)) { + switch (mode) { + case 0: + add_surf(Liste2, CTX.filename, 0, 2); + break; + case 1: + add_surf(Liste2, CTX.filename, 0, 1); + break; + case 2: + add_multvol(Liste2, CTX.filename); + break; + } + ZeroHighlight(THEM); + Draw(); + break; + } } } } - stopall : ; +stopall:; List_Delete(Liste1); List_Delete(Liste2); - Msg(STATUS3N,"Ready"); + Msg(STATUS3N, "Ready"); } -void geometry_elementary_add_new_planesurface_cb(CALLBACK_ARGS){ +void geometry_elementary_add_new_planesurface_cb(CALLBACK_ARGS) +{ _new_surface_volume(0); } -void geometry_elementary_add_new_ruledsurface_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_new_ruledsurface_cb(CALLBACK_ARGS) +{ _new_surface_volume(1); } -void geometry_elementary_add_new_volume_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_new_volume_cb(CALLBACK_ARGS) +{ _new_surface_volume(2); } -static void _transform_point_curve_surface(int transfo, int mode, char *what){ - Vertex *v; - Curve *c; - Surface *s; - int type, num=0; +static void _transform_point_curve_surface(int transfo, int mode, char *what) +{ + Vertex *v; + Curve *c; + Surface *s; + int type, num = 0; - if(!strcmp(what,"Point")) { + if(!strcmp(what, "Point")) { type = ENT_POINT; - if(!opt_geometry_points(0,GMSH_GET,0)){ - opt_geometry_points(0,GMSH_SET|GMSH_GUI,1); + if(!opt_geometry_points(0, GMSH_GET, 0)) { + opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); Draw(); } } - else if(!strcmp(what,"Line")){ - type = ENT_LINE; - if(!opt_geometry_lines(0,GMSH_GET,0)){ - opt_geometry_lines(0,GMSH_SET|GMSH_GUI,1); + else if(!strcmp(what, "Line")) { + type = ENT_LINE; + if(!opt_geometry_lines(0, GMSH_GET, 0)) { + opt_geometry_lines(0, GMSH_SET | GMSH_GUI, 1); Draw(); } } - else{ + else { type = ENT_SURFACE; - if(!opt_geometry_surfaces(0,GMSH_GET,0)){ - opt_geometry_surfaces(0,GMSH_SET|GMSH_GUI,1); + if(!opt_geometry_surfaces(0, GMSH_GET, 0)) { + opt_geometry_surfaces(0, GMSH_SET | GMSH_GUI, 1); Draw(); } } - while(1){ - Msg(STATUS3N,"Select %s ('q'=quit)", what); - if(!SelectEntity(type, &v,&c,&s)){ + while(1) { + Msg(STATUS3N, "Select %s ('q'=quit)", what); + if(!SelectEntity(type, &v, &c, &s)) { ZeroHighlight(THEM); Draw(); break; } - switch(type){ - case ENT_POINT: num = v->Num; break; - case ENT_LINE: num = c->Num; break; - case ENT_SURFACE: num = s->Num; break; + switch (type) { + case ENT_POINT: + num = v->Num; + break; + case ENT_LINE: + num = c->Num; + break; + case ENT_SURFACE: + num = s->Num; + break; } - switch(transfo){ - case 0: translate(mode,num,CTX.filename,what); break; - case 1: rotate(mode,num,CTX.filename,what); break; - case 2: dilate(mode,num,CTX.filename,what); break; - case 3: symmetry(mode,num,CTX.filename,what); break; - case 4: extrude(num,CTX.filename,what); break; - case 5: protude(num,CTX.filename,what); break; - case 6: delet(num,CTX.filename,what); break; + switch (transfo) { + case 0: + translate(mode, num, CTX.filename, what); + break; + case 1: + rotate(mode, num, CTX.filename, what); + break; + case 2: + dilate(mode, num, CTX.filename, what); + break; + case 3: + symmetry(mode, num, CTX.filename, what); + break; + case 4: + extrude(num, CTX.filename, what); + break; + case 5: + protude(num, CTX.filename, what); + break; + case 6: + delet(num, CTX.filename, what); + break; } ZeroHighlight(THEM); Draw(); } - Msg(STATUS3N,"Ready"); + Msg(STATUS3N, "Ready"); } -void geometry_elementary_add_translate_cb(CALLBACK_ARGS){ +void geometry_elementary_add_translate_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_elementary_add_translate, 0); } -void geometry_elementary_add_translate_point_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_translate_point_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(2); - _transform_point_curve_surface(0,1,"Point"); + _transform_point_curve_surface(0, 1, "Point"); } -void geometry_elementary_add_translate_curve_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_translate_curve_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(2); - _transform_point_curve_surface(0,1,"Line"); + _transform_point_curve_surface(0, 1, "Line"); } -void geometry_elementary_add_translate_surface_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_translate_surface_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(2); - _transform_point_curve_surface(0,1,"Surface"); + _transform_point_curve_surface(0, 1, "Surface"); } -void geometry_elementary_translate_cb(CALLBACK_ARGS){ + +void geometry_elementary_translate_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_elementary_translate, 0); } -void geometry_elementary_translate_point_cb(CALLBACK_ARGS){ + +void geometry_elementary_translate_point_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(2); - _transform_point_curve_surface(0,0,"Point"); + _transform_point_curve_surface(0, 0, "Point"); } -void geometry_elementary_translate_curve_cb(CALLBACK_ARGS){ + +void geometry_elementary_translate_curve_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(2); - _transform_point_curve_surface(0,0,"Line"); + _transform_point_curve_surface(0, 0, "Line"); } -void geometry_elementary_translate_surface_cb(CALLBACK_ARGS){ + +void geometry_elementary_translate_surface_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(2); - _transform_point_curve_surface(0,0,"Surface"); + _transform_point_curve_surface(0, 0, "Surface"); } -void geometry_elementary_add_rotate_cb(CALLBACK_ARGS){ +void geometry_elementary_add_rotate_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_elementary_add_rotate, 0); } -void geometry_elementary_add_rotate_point_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_rotate_point_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(3); - _transform_point_curve_surface(1,1,"Point"); + _transform_point_curve_surface(1, 1, "Point"); } -void geometry_elementary_add_rotate_curve_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_rotate_curve_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(3); - _transform_point_curve_surface(1,1,"Line"); + _transform_point_curve_surface(1, 1, "Line"); } -void geometry_elementary_add_rotate_surface_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_rotate_surface_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(3); - _transform_point_curve_surface(1,1,"Surface"); + _transform_point_curve_surface(1, 1, "Surface"); } -void geometry_elementary_rotate_cb(CALLBACK_ARGS){ + +void geometry_elementary_rotate_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_elementary_rotate, 0); } -void geometry_elementary_rotate_point_cb(CALLBACK_ARGS){ + +void geometry_elementary_rotate_point_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(3); - _transform_point_curve_surface(1,0,"Point"); + _transform_point_curve_surface(1, 0, "Point"); } -void geometry_elementary_rotate_curve_cb(CALLBACK_ARGS){ + +void geometry_elementary_rotate_curve_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(3); - _transform_point_curve_surface(1,0,"Line"); + _transform_point_curve_surface(1, 0, "Line"); } -void geometry_elementary_rotate_surface_cb(CALLBACK_ARGS){ + +void geometry_elementary_rotate_surface_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(3); - _transform_point_curve_surface(1,0,"Surface"); + _transform_point_curve_surface(1, 0, "Surface"); } -void geometry_elementary_add_scale_cb(CALLBACK_ARGS){ +void geometry_elementary_add_scale_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_elementary_add_scale, 0); } -void geometry_elementary_add_scale_point_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_scale_point_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(4); - _transform_point_curve_surface(2,1,"Point"); + _transform_point_curve_surface(2, 1, "Point"); } -void geometry_elementary_add_scale_curve_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_scale_curve_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(4); - _transform_point_curve_surface(2,1,"Line"); + _transform_point_curve_surface(2, 1, "Line"); } -void geometry_elementary_add_scale_surface_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_scale_surface_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(4); - _transform_point_curve_surface(2,1,"Surface"); + _transform_point_curve_surface(2, 1, "Surface"); } -void geometry_elementary_scale_cb(CALLBACK_ARGS){ + +void geometry_elementary_scale_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_elementary_scale, 0); } -void geometry_elementary_scale_point_cb(CALLBACK_ARGS){ + +void geometry_elementary_scale_point_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(4); - _transform_point_curve_surface(2,0,"Point"); + _transform_point_curve_surface(2, 0, "Point"); } -void geometry_elementary_scale_curve_cb(CALLBACK_ARGS){ + +void geometry_elementary_scale_curve_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(4); - _transform_point_curve_surface(2,0,"Line"); + _transform_point_curve_surface(2, 0, "Line"); } -void geometry_elementary_scale_surface_cb(CALLBACK_ARGS){ + +void geometry_elementary_scale_surface_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(4); - _transform_point_curve_surface(2,0,"Surface"); + _transform_point_curve_surface(2, 0, "Surface"); } -void geometry_elementary_add_symmetry_cb(CALLBACK_ARGS){ +void geometry_elementary_add_symmetry_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_elementary_add_symmetry, 0); } -void geometry_elementary_add_symmetry_point_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_symmetry_point_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(5); - _transform_point_curve_surface(3,1,"Point"); + _transform_point_curve_surface(3, 1, "Point"); } -void geometry_elementary_add_symmetry_curve_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_symmetry_curve_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(5); - _transform_point_curve_surface(3,1,"Line"); + _transform_point_curve_surface(3, 1, "Line"); } -void geometry_elementary_add_symmetry_surface_cb(CALLBACK_ARGS){ + +void geometry_elementary_add_symmetry_surface_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(5); - _transform_point_curve_surface(3,1,"Surface"); + _transform_point_curve_surface(3, 1, "Surface"); } -void geometry_elementary_symmetry_cb(CALLBACK_ARGS){ + +void geometry_elementary_symmetry_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_elementary_symmetry, 0); } -void geometry_elementary_symmetry_point_cb(CALLBACK_ARGS){ + +void geometry_elementary_symmetry_point_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(5); - _transform_point_curve_surface(3,0,"Point"); + _transform_point_curve_surface(3, 0, "Point"); } -void geometry_elementary_symmetry_curve_cb(CALLBACK_ARGS){ + +void geometry_elementary_symmetry_curve_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(5); - _transform_point_curve_surface(3,0,"Line"); + _transform_point_curve_surface(3, 0, "Line"); } -void geometry_elementary_symmetry_surface_cb(CALLBACK_ARGS){ + +void geometry_elementary_symmetry_surface_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(5); - _transform_point_curve_surface(3,0,"Surface"); + _transform_point_curve_surface(3, 0, "Surface"); } -void geometry_elementary_extrude_cb(CALLBACK_ARGS){ +void geometry_elementary_extrude_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_elementary_extrude, 0); } -void geometry_elementary_extrude_translate_cb(CALLBACK_ARGS){ + +void geometry_elementary_extrude_translate_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_elementary_extrude_translate, 0); } -void geometry_elementary_extrude_translate_point_cb(CALLBACK_ARGS){ + +void geometry_elementary_extrude_translate_point_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(2); - _transform_point_curve_surface(4,0,"Point"); + _transform_point_curve_surface(4, 0, "Point"); } -void geometry_elementary_extrude_translate_curve_cb(CALLBACK_ARGS){ + +void geometry_elementary_extrude_translate_curve_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(2); - _transform_point_curve_surface(4,0,"Line"); + _transform_point_curve_surface(4, 0, "Line"); } -void geometry_elementary_extrude_translate_surface_cb(CALLBACK_ARGS){ + +void geometry_elementary_extrude_translate_surface_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(2); - _transform_point_curve_surface(4,0,"Surface"); + _transform_point_curve_surface(4, 0, "Surface"); } -void geometry_elementary_extrude_rotate_cb(CALLBACK_ARGS){ + +void geometry_elementary_extrude_rotate_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_elementary_extrude_rotate, 0); } -void geometry_elementary_extrude_rotate_point_cb(CALLBACK_ARGS){ + +void geometry_elementary_extrude_rotate_point_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(3); - _transform_point_curve_surface(5,0,"Point"); + _transform_point_curve_surface(5, 0, "Point"); } -void geometry_elementary_extrude_rotate_curve_cb(CALLBACK_ARGS){ + +void geometry_elementary_extrude_rotate_curve_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(3); - _transform_point_curve_surface(5,0,"Line"); + _transform_point_curve_surface(5, 0, "Line"); } -void geometry_elementary_extrude_rotate_surface_cb(CALLBACK_ARGS){ + +void geometry_elementary_extrude_rotate_surface_cb(CALLBACK_ARGS) +{ WID->create_geometry_context_window(3); - _transform_point_curve_surface(5,0,"Surface"); + _transform_point_curve_surface(5, 0, "Surface"); } -void geometry_elementary_delete_cb(CALLBACK_ARGS){ +void geometry_elementary_delete_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_elementary_delete, 0); } -void geometry_elementary_delete_point_cb(CALLBACK_ARGS){ - _transform_point_curve_surface(6,0,"Point"); + +void geometry_elementary_delete_point_cb(CALLBACK_ARGS) +{ + _transform_point_curve_surface(6, 0, "Point"); } -void geometry_elementary_delete_curve_cb(CALLBACK_ARGS){ - _transform_point_curve_surface(6,0,"Line"); + +void geometry_elementary_delete_curve_cb(CALLBACK_ARGS) +{ + _transform_point_curve_surface(6, 0, "Line"); } -void geometry_elementary_delete_surface_cb(CALLBACK_ARGS){ - _transform_point_curve_surface(6,0,"Surface"); + +void geometry_elementary_delete_surface_cb(CALLBACK_ARGS) +{ + _transform_point_curve_surface(6, 0, "Surface"); } -static void _add_physical(char *what){ - Vertex *v; - Curve *c; - Surface *s; - int ib, type, zone; - List_T *Liste1; +static void _add_physical(char *what) +{ + Vertex *v; + Curve *c; + Surface *s; + int ib, type, zone; + List_T *Liste1; - if(!strcmp(what,"Point")){ + if(!strcmp(what, "Point")) { type = ENT_POINT; - if(!opt_geometry_points(0,GMSH_GET,0)){ - opt_geometry_points(0,GMSH_SET|GMSH_GUI,1); + if(!opt_geometry_points(0, GMSH_GET, 0)) { + opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); Draw(); } } - else if(!strcmp(what,"Line")){ - type = ENT_LINE; - if(!opt_geometry_lines(0,GMSH_GET,0)){ - opt_geometry_lines(0,GMSH_SET|GMSH_GUI,1); + else if(!strcmp(what, "Line")) { + type = ENT_LINE; + if(!opt_geometry_lines(0, GMSH_GET, 0)) { + opt_geometry_lines(0, GMSH_SET | GMSH_GUI, 1); Draw(); } } - else if(!strcmp(what,"Surface")){ + else if(!strcmp(what, "Surface")) { type = ENT_SURFACE; - if(!opt_geometry_surfaces(0,GMSH_GET,0)){ - opt_geometry_surfaces(0,GMSH_SET|GMSH_GUI,1); + if(!opt_geometry_surfaces(0, GMSH_GET, 0)) { + opt_geometry_surfaces(0, GMSH_SET | GMSH_GUI, 1); Draw(); } } - else{ + else { Msg(GERROR, "Interactive volume selection not done " - "(you will have to edit the input file manually)"); - if(!opt_geometry_volumes(0,GMSH_GET,0)){ - opt_geometry_volumes(0,GMSH_SET|GMSH_GUI,1); + "(you will have to edit the input file manually)"); + if(!opt_geometry_volumes(0, GMSH_GET, 0)) { + opt_geometry_volumes(0, GMSH_SET | GMSH_GUI, 1); Draw(); } return; } - Liste1 = List_Create(5,5,sizeof(int)); - while(1){ - Msg(STATUS3N,"Select %s ('e'=end, 'q'=quit)", what); - ib = SelectEntity(type, &v,&c,&s); - if(ib == 1){ /* left mouse */ - switch(type){ - case ENT_POINT: List_Add(Liste1, &v->Num); break; - case ENT_LINE: List_Add(Liste1, &c->Num); break; - case ENT_SURFACE: List_Add(Liste1, &s->Num); break; + Liste1 = List_Create(5, 5, sizeof(int)); + while(1) { + Msg(STATUS3N, "Select %s ('e'=end, 'q'=quit)", what); + ib = SelectEntity(type, &v, &c, &s); + if(ib == 1) { /* left mouse */ + switch (type) { + case ENT_POINT: + List_Add(Liste1, &v->Num); + break; + case ENT_LINE: + List_Add(Liste1, &c->Num); + break; + case ENT_SURFACE: + List_Add(Liste1, &s->Num); + break; } } - if(ib == -1){ /* end */ - if(List_Nbr(Liste1)){ - add_physical(Liste1,CTX.filename,type,&zone); - List_Reset(Liste1); - ZeroHighlight(THEM); - Draw(); + if(ib == -1) { /* end */ + if(List_Nbr(Liste1)) { + add_physical(Liste1, CTX.filename, type, &zone); + List_Reset(Liste1); + ZeroHighlight(THEM); + Draw(); } } - if(ib == 0){ + if(ib == 0) { ZeroHighlight(THEM); Draw(); break; } } - Msg(STATUS3N,"Ready"); + Msg(STATUS3N, "Ready"); } -void geometry_physical_add_cb(CALLBACK_ARGS){ +void geometry_physical_add_cb(CALLBACK_ARGS) +{ WID->set_context(menu_geometry_physical_add, 0); } -void geometry_physical_add_point_cb (CALLBACK_ARGS){ + +void geometry_physical_add_point_cb(CALLBACK_ARGS) +{ _add_physical("Point"); } -void geometry_physical_add_curve_cb (CALLBACK_ARGS){ + +void geometry_physical_add_curve_cb(CALLBACK_ARGS) +{ _add_physical("Line"); } -void geometry_physical_add_surface_cb (CALLBACK_ARGS){ + +void geometry_physical_add_surface_cb(CALLBACK_ARGS) +{ _add_physical("Surface"); } -void geometry_physical_add_volume_cb (CALLBACK_ARGS){ + +void geometry_physical_add_volume_cb(CALLBACK_ARGS) +{ _add_physical("Volume"); } // Dynamic Mesh Menus -void mesh_save_cb(CALLBACK_ARGS) { +void mesh_save_cb(CALLBACK_ARGS) +{ Print_Mesh(THEM, CTX.output_filename, CTX.mesh.format); } -void mesh_save_all_cb(CALLBACK_ARGS) { + +void mesh_save_all_cb(CALLBACK_ARGS) +{ int all = CTX.mesh.save_all; CTX.mesh.save_all = 1; Print_Mesh(THEM, CTX.output_filename, CTX.mesh.format); CTX.mesh.save_all = all; } -void mesh_define_cb(CALLBACK_ARGS){ + +void mesh_define_cb(CALLBACK_ARGS) +{ WID->set_context(menu_mesh_define, 0); } -void mesh_1d_cb(CALLBACK_ARGS){ - mai3d(THEM, 1); + +void mesh_1d_cb(CALLBACK_ARGS) +{ + mai3d(THEM, 1); Draw(); - Msg(STATUS3N,"Ready"); + Msg(STATUS3N, "Ready"); } -void mesh_2d_cb(CALLBACK_ARGS){ + +void mesh_2d_cb(CALLBACK_ARGS) +{ mai3d(THEM, 2); Draw(); - Msg(STATUS3N,"Ready"); -} -void mesh_3d_cb(CALLBACK_ARGS){ - mai3d(THEM, 3); + Msg(STATUS3N, "Ready"); +} + +void mesh_3d_cb(CALLBACK_ARGS) +{ + mai3d(THEM, 3); Draw(); - Msg(STATUS3N,"Ready"); -} -void mesh_define_length_cb (CALLBACK_ARGS){ - Vertex *v; - Curve *c; - Surface *s; - int ib; - static int n=0, p[100]; - - if(!opt_geometry_points(0,GMSH_GET,0)){ - opt_geometry_points(0,GMSH_SET|GMSH_GUI,1); + Msg(STATUS3N, "Ready"); +} + +void mesh_define_length_cb(CALLBACK_ARGS) +{ + Vertex *v; + Curve *c; + Surface *s; + int ib; + static int n = 0, p[100]; + + if(!opt_geometry_points(0, GMSH_GET, 0)) { + opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); Draw(); } WID->create_mesh_context_window(0); - while(1){ - Msg(STATUS3N,"Select Point ('e'=end, 'q'=quit)"); - ib = SelectEntity(ENT_POINT, &v,&c,&s); - if(ib == 1){ /* left mouse butt */ - p[n++] = v->Num; + while(1) { + Msg(STATUS3N, "Select Point ('e'=end, 'q'=quit)"); + ib = SelectEntity(ENT_POINT, &v, &c, &s); + if(ib == 1) { /* left mouse butt */ + p[n++] = v->Num; } - if (ib == -1){ /* 'e' */ + if(ib == -1) { /* 'e' */ if(n >= 1) { - add_charlength(n,p,CTX.filename); - n=0; - ZeroHighlight(THEM); - Draw(); - break; + add_charlength(n, p, CTX.filename); + n = 0; + ZeroHighlight(THEM); + Draw(); + break; } } - if(ib == 0){ /* 'q' */ - n=0 ; + if(ib == 0) { /* 'q' */ + n = 0; ZeroHighlight(THEM); Draw(); break; } } - Msg(STATUS3N,"Ready"); + Msg(STATUS3N, "Ready"); } -void mesh_define_recombine_cb (CALLBACK_ARGS){ - Vertex *v; - Curve *c; - Surface *s; - int ib; + +void mesh_define_recombine_cb(CALLBACK_ARGS) +{ + Vertex *v; + Curve *c; + Surface *s; + int ib; static int n, p[100]; - if(!opt_geometry_surfaces(0,GMSH_GET,0)){ - opt_geometry_surfaces(0,GMSH_SET|GMSH_GUI,1); + if(!opt_geometry_surfaces(0, GMSH_GET, 0)) { + opt_geometry_surfaces(0, GMSH_SET | GMSH_GUI, 1); Draw(); } - n=0; - while(1){ - Msg(STATUS3N,"Select Surface ('e'=end, 'q'=quit)"); - ib = SelectEntity(ENT_SURFACE, &v,&c,&s); - if(ib == 1){ /* left mouse butt */ - p[n++] = s->Num; + n = 0; + while(1) { + Msg(STATUS3N, "Select Surface ('e'=end, 'q'=quit)"); + ib = SelectEntity(ENT_SURFACE, &v, &c, &s); + if(ib == 1) { /* left mouse butt */ + p[n++] = s->Num; } - if (ib == -1){ /* 'e' */ + if(ib == -1) { /* 'e' */ if(n >= 1) { - add_recosurf(n,p,CTX.filename); break; + add_recosurf(n, p, CTX.filename); + break; } - n=0; + n = 0; ZeroHighlight(THEM); Draw(); } - if(ib == 0){ /* 'q' */ - n=0 ; + if(ib == 0) { /* 'q' */ + n = 0; ZeroHighlight(THEM); Draw(); break; @@ -1829,109 +2259,117 @@ void mesh_define_recombine_cb (CALLBACK_ARGS){ } Msg(STATUS3N, "Ready"); } -void mesh_define_transfinite_cb (CALLBACK_ARGS){ + +void mesh_define_transfinite_cb(CALLBACK_ARGS) +{ WID->set_context(menu_mesh_define_transfinite, 0); -} +} -static void _add_transfinite(int dim){ - Vertex *v; - Curve *c; - Surface *s; - int ib=0; +static void _add_transfinite(int dim) +{ + Vertex *v; + Curve *c; + Surface *s; + int ib = 0; static int n, p[100]; - if(!opt_geometry_points(0,GMSH_GET,0)){ - opt_geometry_points(0,GMSH_SET|GMSH_GUI,1); + if(!opt_geometry_points(0, GMSH_GET, 0)) { + opt_geometry_points(0, GMSH_SET | GMSH_GUI, 1); Draw(); } switch (dim) { - case 1 : - if(!opt_geometry_lines(0,GMSH_GET,0)){ - opt_geometry_lines(0,GMSH_SET|GMSH_GUI,1); + case 1: + if(!opt_geometry_lines(0, GMSH_GET, 0)) { + opt_geometry_lines(0, GMSH_SET | GMSH_GUI, 1); Draw(); } - break ; - case 2 : - if(!opt_geometry_surfaces(0,GMSH_GET,0)){ - opt_geometry_surfaces(0,GMSH_SET|GMSH_GUI,1); + break; + case 2: + if(!opt_geometry_surfaces(0, GMSH_GET, 0)) { + opt_geometry_surfaces(0, GMSH_SET | GMSH_GUI, 1); Draw(); } break; - case 3 : - if(!opt_geometry_volumes(0,GMSH_GET,0)){ - opt_geometry_volumes(0,GMSH_SET|GMSH_GUI,1); + case 3: + if(!opt_geometry_volumes(0, GMSH_GET, 0)) { + opt_geometry_volumes(0, GMSH_SET | GMSH_GUI, 1); Draw(); } break; } - - n=0; - while(1){ + + n = 0; + while(1) { switch (dim) { - case 1 : - Msg(STATUS3N,"Select Line ('e'=end, 'q'=quit)"); - ib = SelectEntity(ENT_LINE, &v,&c,&s); - break ; - case 2 : - Msg(STATUS3N,"Select Surface ('e'=end, 'q'=quit)"); - ib = SelectEntity(ENT_SURFACE, &v,&c,&s); + case 1: + Msg(STATUS3N, "Select Line ('e'=end, 'q'=quit)"); + ib = SelectEntity(ENT_LINE, &v, &c, &s); + break; + case 2: + Msg(STATUS3N, "Select Surface ('e'=end, 'q'=quit)"); + ib = SelectEntity(ENT_SURFACE, &v, &c, &s); break; - case 3 : + case 3: ib = 1; break; } - if(ib == 1){ /* left mouse butt */ - switch (dim) { - case 1 : p[n++] = c->Num ; break ; - case 2 : p[n++] = s->Num; // fall-through - case 3 : - while(1){ - Msg(STATUS3N,"Select Point ('e'=end, 'q'=quit)"); - ib = SelectEntity(ENT_POINT, &v,&c,&s); - if(ib == 1){ /* left mouse butt */ - p[n++] = v->Num ; - } - if (ib == -1){ /* 'e' */ - switch (dim) { - case 2 : - if(n == 3+1 || n == 4+1) - add_trsfsurf(n,p,CTX.filename); - else - Msg(STATUS2, "Wrong number of points for Transfinite Surface"); - break; - case 3 : - if(n == 6 || n == 8) - add_trsfvol(n,p,CTX.filename); - else - Msg(STATUS2, "Wrong number of points for Transfinite Volume"); - break; - } - n=0; - ZeroHighlight(THEM); - Draw(); - break; - } - if(ib == 0){ /* 'q' */ - n=0 ; - ZeroHighlight(THEM); - Draw(); - break; - } - } - break ; + if(ib == 1) { /* left mouse butt */ + switch (dim) { + case 1: + p[n++] = c->Num; + break; + case 2: + p[n++] = s->Num; // fall-through + case 3: + while(1) { + Msg(STATUS3N, "Select Point ('e'=end, 'q'=quit)"); + ib = SelectEntity(ENT_POINT, &v, &c, &s); + if(ib == 1) { /* left mouse butt */ + p[n++] = v->Num; + } + if(ib == -1) { /* 'e' */ + switch (dim) { + case 2: + if(n == 3 + 1 || n == 4 + 1) + add_trsfsurf(n, p, CTX.filename); + else + Msg(STATUS2, + "Wrong number of points for Transfinite Surface"); + break; + case 3: + if(n == 6 || n == 8) + add_trsfvol(n, p, CTX.filename); + else + Msg(STATUS2, "Wrong number of points for Transfinite Volume"); + break; + } + n = 0; + ZeroHighlight(THEM); + Draw(); + break; + } + if(ib == 0) { /* 'q' */ + n = 0; + ZeroHighlight(THEM); + Draw(); + break; + } + } + break; } } - if (ib == -1){ /* 'e' */ - if (dim == 1){ - if(n >= 1) add_trsfline(n,p,CTX.filename); + if(ib == -1) { /* 'e' */ + if(dim == 1) { + if(n >= 1) + add_trsfline(n, p, CTX.filename); } - n=0; + n = 0; ZeroHighlight(THEM); Draw(); } - if(ib == 0){ /* 'q' */ - n=0 ; + if(ib == 0) { /* 'q' */ + n = 0; ZeroHighlight(THEM); Draw(); break; @@ -1940,237 +2378,283 @@ static void _add_transfinite(int dim){ Msg(STATUS3N, "Ready"); } -void mesh_define_transfinite_line_cb(CALLBACK_ARGS){ +void mesh_define_transfinite_line_cb(CALLBACK_ARGS) +{ WID->create_mesh_context_window(1); _add_transfinite(1); } -void mesh_define_transfinite_surface_cb(CALLBACK_ARGS){ + +void mesh_define_transfinite_surface_cb(CALLBACK_ARGS) +{ _add_transfinite(2); } -void mesh_define_transfinite_volume_cb(CALLBACK_ARGS){ + +void mesh_define_transfinite_volume_cb(CALLBACK_ARGS) +{ WID->create_mesh_context_window(2); _add_transfinite(3); -} +} // Dynamic Solver Menus #include "Solvers.h" -void solver_cb(CALLBACK_ARGS){ +void solver_cb(CALLBACK_ARGS) +{ char file[256], tmp[256]; - static int init=0, first[MAXSOLVERS]; + static int init = 0, first[MAXSOLVERS]; int i, num = (int)data; - if(!init){ - for(i=0; i<MAXSOLVERS; i++) first[i] = 1; + if(!init) { + for(i = 0; i < MAXSOLVERS; i++) + first[i] = 1; init = 1; } - if(first[num]){ + if(first[num]) { first[num] = 0; - strcpy(file,CTX.base_filename); - strcat(file,SINFO[num].extension); + strcpy(file, CTX.base_filename); + strcat(file, SINFO[num].extension); WID->solver[num].input[0]->value(file); } - if(SINFO[num].nboptions){ + if(SINFO[num].nboptions) { sprintf(tmp, "%s \"%s\"", SINFO[num].option_command, - (char*)WID->solver[num].input[0]->value()); + (char *)WID->solver[num].input[0]->value()); Solver(num, tmp); } WID->create_solver_window(num); } -void solver_file_open_cb(CALLBACK_ARGS){ + +void solver_file_open_cb(CALLBACK_ARGS) +{ char tmp[256]; int num = (int)data; sprintf(tmp, "*%s", SINFO[num].extension); - if (file_chooser(0,"Open problem definition file", tmp, 0)){ + if(file_chooser(0, "Open problem definition file", tmp, 0)) { WID->solver[num].input[0]->value(file_chooser_get_name(1)); - if(SINFO[num].nboptions){ - sprintf(tmp, "%s \"%s\"", SINFO[num].option_command, file_chooser_get_name(1)); + if(SINFO[num].nboptions) { + sprintf(tmp, "%s \"%s\"", SINFO[num].option_command, + file_chooser_get_name(1)); Solver(num, tmp); } } } -void solver_file_edit_cb(CALLBACK_ARGS){ +void solver_file_edit_cb(CALLBACK_ARGS) +{ char cmd[1000]; int num = (int)data; sprintf(cmd, CTX.editor, WID->solver[num].input[0]->value()); SystemCall(cmd); } -void solver_choose_mesh_cb(CALLBACK_ARGS){ + +void solver_choose_mesh_cb(CALLBACK_ARGS) +{ int num = (int)data; - if(file_chooser(0,"Open mesh file", "*.msh", 0)) + if(file_chooser(0, "Open mesh file", "*.msh", 0)) WID->solver[num].input[1]->value(file_chooser_get_name(1)); } -int nbs(char *str){ - int i, nb=0; - for(i=0; i<(int)strlen(str)-1; i++){ - if(str[i]=='%' && str[i+1]=='s'){ - nb++; i++; +int nbs(char *str) +{ + int i, nb = 0; + for(i = 0; i < (int)strlen(str) - 1; i++) { + if(str[i] == '%' && str[i + 1] == 's') { + nb++; + i++; } } return nb; } -void solver_command_cb(CALLBACK_ARGS){ + +void solver_command_cb(CALLBACK_ARGS) +{ char tmp[256], arg[512], mesh[256], command[256]; - int num = ((int*)data)[0]; - int idx = ((int*)data)[1]; + int num = ((int *)data)[0]; + int idx = ((int *)data)[1]; int i, usedopts = 0; - if(SINFO[num].popup_messages) WID->create_message_window(); + if(SINFO[num].popup_messages) + WID->create_message_window(); - if(strlen(WID->solver[num].input[1]->value())){ + if(strlen(WID->solver[num].input[1]->value())) { sprintf(tmp, "\"%s\"", WID->solver[num].input[1]->value()); sprintf(mesh, SINFO[num].mesh_command, tmp); } - else{ + else { strcpy(mesh, ""); } //printf("num%d idx%d %s -> %d\n", - // num, idx, SINFO[num].button_command[idx], nbs(SINFO[num].button_command[idx])); + // num, idx, SINFO[num].button_command[idx], nbs(SINFO[num].button_command[idx])); - if(nbs(SINFO[num].button_command[idx])){ - for(i=0; i<idx; i++) usedopts += nbs(SINFO[num].button_command[i]); - if(usedopts > SINFO[num].nboptions){ + if(nbs(SINFO[num].button_command[idx])) { + for(i = 0; i < idx; i++) + usedopts += nbs(SINFO[num].button_command[i]); + if(usedopts > SINFO[num].nboptions) { Msg(GERROR, "Missing options to execute command"); return; } - sprintf(command, SINFO[num].button_command[idx], - SINFO[num].option[usedopts][WID->solver[num].choice[usedopts]->value()]); + sprintf(command, SINFO[num].button_command[idx], + SINFO[num].option[usedopts][WID->solver[num].choice[usedopts]-> + value()]); } - else{ + else { strcpy(command, SINFO[num].button_command[idx]); } - sprintf(arg, "\"%s\" %s %s", WID->solver[num].input[0]->value(), mesh, command); + sprintf(arg, "\"%s\" %s %s", WID->solver[num].input[0]->value(), mesh, + command); Solver(num, arg); } -void solver_kill_cb(CALLBACK_ARGS){ + +void solver_kill_cb(CALLBACK_ARGS) +{ int num = (int)data; - if(SINFO[num].pid > 0){ + if(SINFO[num].pid > 0) { kill(SINFO[num].pid, 9); Msg(INFO, "Killed %s pid %d", SINFO[num].name, SINFO[num].pid); } SINFO[num].pid = -1; } -void solver_choose_executable_cb(CALLBACK_ARGS){ + +void solver_choose_executable_cb(CALLBACK_ARGS) +{ int num = (int)data; - if(file_chooser(0,"Choose executable", + if(file_chooser(0, "Choose executable", #if defined(WIN32) - "*.exe" + "*.exe" #else "*" #endif - , 0)) + , 0)) WID->solver[num].input[2]->value(file_chooser_get_name(1)); } -void solver_ok_cb(CALLBACK_ARGS){ + +void solver_ok_cb(CALLBACK_ARGS) +{ int num = (int)data; - int retry=0; + int retry = 0; opt_solver_popup_messages(num, GMSH_SET, WID->solver[num].butt[0]->value()); opt_solver_merge_views(num, GMSH_SET, WID->solver[num].butt[1]->value()); opt_solver_client_server(num, GMSH_SET, WID->solver[num].butt[2]->value()); if(strcmp(opt_solver_executable(num, GMSH_GET, NULL), - WID->solver[num].input[2]->value())) retry=1; - opt_solver_executable(num, GMSH_SET, (char*)WID->solver[num].input[2]->value()); - if(retry) solver_cb(NULL,data); + WID->solver[num].input[2]->value())) + retry = 1; + opt_solver_executable(num, GMSH_SET, + (char *)WID->solver[num].input[2]->value()); + if(retry) + solver_cb(NULL, data); } // Dynamic Post Menus -void view_toggle_cb(CALLBACK_ARGS){ - opt_view_visible((long int)data, GMSH_SET, WID->m_toggle_butt[(long int)data]->value()); +void view_toggle_cb(CALLBACK_ARGS) +{ + opt_view_visible((long int)data, GMSH_SET, + WID->m_toggle_butt[(long int)data]->value()); Draw(); } -static int RELOAD_ALL_VIEWS = 0 ; +static int RELOAD_ALL_VIEWS = 0; -void view_reload_all_cb(CALLBACK_ARGS) { - if(!CTX.post.list) return; +void view_reload_all_cb(CALLBACK_ARGS) +{ + if(!CTX.post.list) + return; RELOAD_ALL_VIEWS = 1; - for(int i = 0 ; i<List_Nbr(CTX.post.list) ; i++) + for(int i = 0; i < List_Nbr(CTX.post.list); i++) view_reload_cb(NULL, (void *)i); RELOAD_ALL_VIEWS = 0; Draw(); } -void view_reload_visible_cb(CALLBACK_ARGS) { - if(!CTX.post.list) return; +void view_reload_visible_cb(CALLBACK_ARGS) +{ + if(!CTX.post.list) + return; RELOAD_ALL_VIEWS = 1; - for(int i = 0 ; i<List_Nbr(CTX.post.list) ; i++) + for(int i = 0; i < List_Nbr(CTX.post.list); i++) if(opt_view_visible(i, GMSH_GET, 0)) view_reload_cb(NULL, (void *)i); RELOAD_ALL_VIEWS = 0; Draw(); } -void view_reload_cb(CALLBACK_ARGS){ - Post_View tmp ; +void view_reload_cb(CALLBACK_ARGS) +{ + Post_View tmp; char filename[256]; - if(!CTX.post.list) return; + if(!CTX.post.list) + return; - Post_View *v = (Post_View*)List_Pointer(CTX.post.list,(long int)data); + Post_View *v = (Post_View *) List_Pointer(CTX.post.list, (long int)data); strcpy(filename, v->FileName); CopyViewOptions(v, &tmp); - CTX.post.force_num = v->Num ; + CTX.post.force_num = v->Num; FreeView(v); MergeProblem(filename); - CTX.post.force_num = 0 ; - - v = (Post_View*)List_Pointer(CTX.post.list,(long int)data); + CTX.post.force_num = 0; + + v = (Post_View *) List_Pointer(CTX.post.list, (long int)data); CopyViewOptions(&tmp, v); // In case the reloaded view has a different number of time steps - if(v->TimeStep > v->NbTimeStep-1) v->TimeStep = 0; + if(v->TimeStep > v->NbTimeStep - 1) + v->TimeStep = 0; if(!RELOAD_ALL_VIEWS) Draw(); } -static int REMOVE_ALL_VIEWS = 0 ; +static int REMOVE_ALL_VIEWS = 0; -void view_remove_all_cb(CALLBACK_ARGS) { - if(!CTX.post.list) return; +void view_remove_all_cb(CALLBACK_ARGS) +{ + if(!CTX.post.list) + return; REMOVE_ALL_VIEWS = 1; while(List_Nbr(CTX.post.list)) - view_remove_cb(NULL, (void*)0); + view_remove_cb(NULL, (void *)0); REMOVE_ALL_VIEWS = 0; Draw(); } -void view_remove_visible_cb(CALLBACK_ARGS) { +void view_remove_visible_cb(CALLBACK_ARGS) +{ int i; - if(!CTX.post.list) return; + if(!CTX.post.list) + return; REMOVE_ALL_VIEWS = 1; - for(i=List_Nbr(CTX.post.list)-1 ; i>=0 ; i--) + for(i = List_Nbr(CTX.post.list) - 1; i >= 0; i--) if(opt_view_visible(i, GMSH_GET, 0)) - view_remove_cb(NULL, (void*)i); + view_remove_cb(NULL, (void *)i); REMOVE_ALL_VIEWS = 0; Draw(); } -void view_remove_invisible_cb(CALLBACK_ARGS) { +void view_remove_invisible_cb(CALLBACK_ARGS) +{ int i; - if(!CTX.post.list) return; + if(!CTX.post.list) + return; REMOVE_ALL_VIEWS = 1; - for(i=List_Nbr(CTX.post.list)-1 ; i>=0 ; i--) + for(i = List_Nbr(CTX.post.list) - 1; i >= 0; i--) if(!opt_view_visible(i, GMSH_GET, 0)) - view_remove_cb(NULL, (void*)i); + view_remove_cb(NULL, (void *)i); REMOVE_ALL_VIEWS = 0; Draw(); } -void view_remove_cb(CALLBACK_ARGS){ +void view_remove_cb(CALLBACK_ARGS) +{ FreeView((long int)data); WID->check_anim_buttons(); if(WID->get_context() == 3) - WID->set_context(menu_post, 0); + WID->set_context(menu_post, 0); WID->reset_option_browser(); @@ -2178,426 +2662,502 @@ void view_remove_cb(CALLBACK_ARGS){ Draw(); } -void view_save_ascii_cb(CALLBACK_ARGS){ - test: - if(file_chooser(0,"Save view in ASCII format", "*", 0)){ +void view_save_ascii_cb(CALLBACK_ARGS) +{ +test: + if(file_chooser(0, "Save view in ASCII format", "*", 0)) { char *name = file_chooser_get_name(1); - if(CTX.confirm_overwrite){ + if(CTX.confirm_overwrite) { struct stat buf; if(!stat(name, &buf)) - if(fl_ask("%s already exists.\nDo you want to replace it?", name)) - goto save; - else - goto test; + if(fl_ask("%s already exists.\nDo you want to replace it?", name)) + goto save; + else + goto test; } save: - WriteView(0, (Post_View*)List_Pointer(CTX.post.list,(long int)data), name); + WriteView(0, (Post_View *) List_Pointer(CTX.post.list, (long int)data), + name); } } -void view_save_binary_cb(CALLBACK_ARGS){ - test: - if(file_chooser(0,"Save view in binary format", "*", 0)){ +void view_save_binary_cb(CALLBACK_ARGS) +{ +test: + if(file_chooser(0, "Save view in binary format", "*", 0)) { char *name = file_chooser_get_name(1); - if(CTX.confirm_overwrite){ + if(CTX.confirm_overwrite) { struct stat buf; if(!stat(name, &buf)) - if(fl_ask("%s already exists.\nDo you want to replace it?", name)) - goto save; - else - goto test; + if(fl_ask("%s already exists.\nDo you want to replace it?", name)) + goto save; + else + goto test; } save: - WriteView(1, (Post_View*)List_Pointer(CTX.post.list,(long int)data), name); + WriteView(1, (Post_View *) List_Pointer(CTX.post.list, (long int)data), + name); } } -void view_duplicate_cb(CALLBACK_ARGS){ - DuplicateView((long int)data,0); +void view_duplicate_cb(CALLBACK_ARGS) +{ + DuplicateView((long int)data, 0); Draw(); } -void view_duplicate_with_options_cb(CALLBACK_ARGS){ - DuplicateView((long int)data,1); + +void view_duplicate_with_options_cb(CALLBACK_ARGS) +{ + DuplicateView((long int)data, 1); Draw(); } -void view_merge_all_cb(CALLBACK_ARGS) { +void view_merge_all_cb(CALLBACK_ARGS) +{ MergeViews(1); Draw(); } -void view_merge_visible_cb(CALLBACK_ARGS) { +void view_merge_visible_cb(CALLBACK_ARGS) +{ MergeViews(0); Draw(); } -void view_applybgmesh_cb(CALLBACK_ARGS){ - Post_View *v = (Post_View*)List_Pointer(CTX.post.list,(long int)data); - if(!v->ScalarOnly || v->TextOnly){ +void view_applybgmesh_cb(CALLBACK_ARGS) +{ + Post_View *v = (Post_View *) List_Pointer(CTX.post.list, (long int)data); + if(!v->ScalarOnly || v->TextOnly) { Msg(GERROR, "Background mesh generation impossible with non-scalar view"); return; } - BGMWithView(v); + BGMWithView(v); } -void view_options_cb(CALLBACK_ARGS){ + +void view_options_cb(CALLBACK_ARGS) +{ WID->create_view_options_window((long int)data); } -void view_plugin_cb(CALLBACK_ARGS){ +void view_plugin_cb(CALLBACK_ARGS) +{ char name[256]; - std::pair<int,GMSH_Plugin*> *pair = (std::pair<int,GMSH_Plugin*>*)data; + std::pair < int, GMSH_Plugin * >*pair = + (std::pair < int, GMSH_Plugin * >*)data; int iView = pair->first; - GMSH_Post_Plugin *p = (GMSH_Post_Plugin*)pair->second; + GMSH_Post_Plugin *p = (GMSH_Post_Plugin *) pair->second; p->getName(name); - if(p->dialogBox){//Get the values from the GUI + if(p->dialogBox) { //Get the values from the GUI int n = p->getNbOptions(); - if(n > 20) Msg(GERROR,"Plugin has too many parameters"); - for(int i=0;i<n;i++){ + if(n > 20) + Msg(GERROR, "Plugin has too many parameters"); + for(int i = 0; i < n; i++) { StringXNumber *sxn; sxn = p->GetOption(i); sxn->def = p->dialogBox->view_value[i]->value(); } } - try{ - Post_View *v = (Post_View*)List_Pointer(CTX.post.list,iView); + try { + Post_View *v = (Post_View *) List_Pointer(CTX.post.list, iView); p->execute(v); Draw(); } - catch (GMSH_Plugin *err){ + catch(GMSH_Plugin * err) { p->CatchErrorMessage(name); - Msg(WARNING,"%s",name); + Msg(WARNING, "%s", name); } } -void view_options_plugin_cb(CALLBACK_ARGS){ - std::pair<int,GMSH_Plugin*> *pair = (std::pair<int,GMSH_Plugin*>*)data; +void view_options_plugin_cb(CALLBACK_ARGS) +{ + std::pair < int, GMSH_Plugin * >*pair = + (std::pair < int, GMSH_Plugin * >*)data; GMSH_Plugin *p = pair->second; - if(!p->dialogBox) p->dialogBox = WID->create_plugin_window(p); + if(!p->dialogBox) + p->dialogBox = WID->create_plugin_window(p); - p->dialogBox->run_button->callback(view_plugin_cb, (void*)pair); - p->dialogBox->main_window->show(); + p->dialogBox->run_button->callback(view_plugin_cb, (void *)pair); + p->dialogBox->main_window->show(); } -void view_options_custom_cb(CALLBACK_ARGS){ - if(WID->view_butt[34]->value()){ +void view_options_custom_cb(CALLBACK_ARGS) +{ + if(WID->view_butt[34]->value()) { WID->view_value[31]->activate(); WID->view_value[32]->activate(); } - else{ + else { WID->view_value[31]->deactivate(); WID->view_value[32]->deactivate(); } } -void view_options_timestep_cb(CALLBACK_ARGS){ +void view_options_timestep_cb(CALLBACK_ARGS) +{ int links = (int)opt_post_link(0, GMSH_GET, 0); - for(int i=0 ; i<List_Nbr(CTX.post.list) ; i++){ + for(int i = 0; i < List_Nbr(CTX.post.list); i++) { if((links == 2 || links == 4) || ((links == 1 || links == 3) && opt_view_visible(i, GMSH_GET, 0)) || - (links == 0 && i == (long int)data)){ - opt_view_timestep(i, GMSH_SET, (int)((Fl_Value_Input*)w)->value()); + (links == 0 && i == (long int)data)) { + opt_view_timestep(i, GMSH_SET, (int)((Fl_Value_Input *) w)->value()); } } Draw(); } -void view_options_timestep_decr_cb(CALLBACK_ARGS){ +void view_options_timestep_decr_cb(CALLBACK_ARGS) +{ int links = (int)opt_post_link(0, GMSH_GET, 0); - for(int i=0 ; i<List_Nbr(CTX.post.list) ; i++){ + for(int i = 0; i < List_Nbr(CTX.post.list); i++) { if((links == 2 || links == 4) || ((links == 1 || links == 3) && opt_view_visible(i, GMSH_GET, 0)) || - (links == 0 && i == (long int)data)){ - opt_view_timestep(i, GMSH_SET|GMSH_GUI, opt_view_timestep(i,GMSH_GET,0)-1); + (links == 0 && i == (long int)data)) { + opt_view_timestep(i, GMSH_SET | GMSH_GUI, + opt_view_timestep(i, GMSH_GET, 0) - 1); } } Draw(); } -void view_options_timestep_incr_cb(CALLBACK_ARGS){ + +void view_options_timestep_incr_cb(CALLBACK_ARGS) +{ int links = (int)opt_post_link(0, GMSH_GET, 0); - for(int i=0 ; i<List_Nbr(CTX.post.list) ; i++){ + for(int i = 0; i < List_Nbr(CTX.post.list); i++) { if((links == 2 || links == 4) || ((links == 1 || links == 3) && opt_view_visible(i, GMSH_GET, 0)) || - (links == 0 && i == (long int)data)){ - opt_view_timestep(i, GMSH_SET|GMSH_GUI, opt_view_timestep(i,GMSH_GET,0)+1); + (links == 0 && i == (long int)data)) { + opt_view_timestep(i, GMSH_SET | GMSH_GUI, + opt_view_timestep(i, GMSH_GET, 0) + 1); } } Draw(); } -void view_options_ok_cb(CALLBACK_ARGS){ - int i, links, force=0; +void view_options_ok_cb(CALLBACK_ARGS) +{ + int i, links, force = 0; - if((long int)data<0) return; + if((long int)data < 0) + return; links = (int)opt_post_link(0, GMSH_GET, 0); - for(i=0 ; i<List_Nbr(CTX.post.list) ; i++){ + for(i = 0; i < List_Nbr(CTX.post.list); i++) { if((links == 2 || links == 4) || ((links == 1 || links == 3) && opt_view_visible(i, GMSH_GET, 0)) || - (links == 0 && i == (long int)data)){ + (links == 0 && i == (long int)data)) { - if(links == 3 || links == 4) force = 1; + if(links == 3 || links == 4) + force = 1; // view_butts //not this one. if(WID->view_butt[34]->changed()) - opt_view_range_type(i, GMSH_SET, - WID->view_butt[34]->value()?DRAW_POST_CUSTOM: - DRAW_POST_DEFAULT); + opt_view_range_type(i, GMSH_SET, + WID->view_butt[34]->value()? DRAW_POST_CUSTOM : + DRAW_POST_DEFAULT); if(force || WID->view_butt[1]->changed() || - WID->view_butt[2]->changed() || - WID->view_butt[3]->changed()) - opt_view_type(i, GMSH_SET, - WID->view_butt[1]->value()?DRAW_POST_3D: - WID->view_butt[2]->value()?DRAW_POST_2D_SPACE: - DRAW_POST_2D_TIME); - - if(force || WID->view_choice[1]->changed()){ - int val; - switch(WID->view_choice[1]->value()){ - case 0 : val = DRAW_POST_LINEAR; break; - case 1 : val = DRAW_POST_LOGARITHMIC; break; - default : val = DRAW_POST_DOUBLELOGARITHMIC; break; - } - opt_view_scale_type(i, GMSH_SET, val); + WID->view_butt[2]->changed() || WID->view_butt[3]->changed()) + opt_view_type(i, GMSH_SET, + WID->view_butt[1]->value()? DRAW_POST_3D : + WID->view_butt[2]->value()? DRAW_POST_2D_SPACE : + DRAW_POST_2D_TIME); + + if(force || WID->view_choice[1]->changed()) { + int val; + switch (WID->view_choice[1]->value()) { + case 0: + val = DRAW_POST_LINEAR; + break; + case 1: + val = DRAW_POST_LOGARITHMIC; + break; + default: + val = DRAW_POST_DOUBLELOGARITHMIC; + break; + } + opt_view_scale_type(i, GMSH_SET, val); } if(force || WID->view_butt[38]->changed()) - opt_view_saturate_values(i, GMSH_SET, - WID->view_butt[38]->value()); - - if(force || WID->view_choice[0]->changed()){ - int val; - switch(WID->view_choice[0]->value()){ - case 0 : val = DRAW_POST_ISO; break; - case 1 : val = DRAW_POST_DISCRETE; break; - case 2 : val = DRAW_POST_CONTINUOUS; break; - default : val = DRAW_POST_NUMERIC; break; - } - opt_view_intervals_type(i, GMSH_SET, val); + opt_view_saturate_values(i, GMSH_SET, WID->view_butt[38]->value()); + + if(force || WID->view_choice[0]->changed()) { + int val; + switch (WID->view_choice[0]->value()) { + case 0: + val = DRAW_POST_ISO; + break; + case 1: + val = DRAW_POST_DISCRETE; + break; + case 2: + val = DRAW_POST_CONTINUOUS; + break; + default: + val = DRAW_POST_NUMERIC; + break; + } + opt_view_intervals_type(i, GMSH_SET, val); } - if(force || WID->view_choice[5]->changed()){ - int val; - switch(WID->view_choice[5]->value()){ - case 0 : val = 0; break; - default : val = 1; break; - } - opt_view_point_type(i, GMSH_SET, val); + if(force || WID->view_choice[5]->changed()) { + int val; + switch (WID->view_choice[5]->value()) { + case 0: + val = 0; + break; + default: + val = 1; + break; + } + opt_view_point_type(i, GMSH_SET, val); } - if(force || WID->view_choice[6]->changed()){ - int val; - switch(WID->view_choice[6]->value()){ - case 0 : val = 0; break; - default : val = 1; break; - } - opt_view_line_type(i, GMSH_SET, val); + if(force || WID->view_choice[6]->changed()) { + int val; + switch (WID->view_choice[6]->value()) { + case 0: + val = 0; + break; + default: + val = 1; + break; + } + opt_view_line_type(i, GMSH_SET, val); } - if(force || WID->view_choice[2]->changed()){ - int val; - switch(WID->view_choice[2]->value()){ - case 0 : val = DRAW_POST_SEGMENT; break; - case 1 : val = DRAW_POST_ARROW; break; - case 2 : val = DRAW_POST_PYRAMID; break; - case 3 : val = DRAW_POST_CONE; break; - default : val = DRAW_POST_DISPLACEMENT; break; - } - opt_view_arrow_type(i, GMSH_SET, val); + if(force || WID->view_choice[2]->changed()) { + int val; + switch (WID->view_choice[2]->value()) { + case 0: + val = DRAW_POST_SEGMENT; + break; + case 1: + val = DRAW_POST_ARROW; + break; + case 2: + val = DRAW_POST_PYRAMID; + break; + case 3: + val = DRAW_POST_CONE; + break; + default: + val = DRAW_POST_DISPLACEMENT; + break; + } + opt_view_arrow_type(i, GMSH_SET, val); } - if(force || WID->view_choice[3]->changed()){ - int val; - switch(WID->view_choice[3]->value()){ - case 0 : val = DRAW_POST_LOCATE_COG; break; - default : val = DRAW_POST_LOCATE_VERTEX; break; - } - opt_view_arrow_location(i, GMSH_SET, val); + if(force || WID->view_choice[3]->changed()) { + int val; + switch (WID->view_choice[3]->value()) { + case 0: + val = DRAW_POST_LOCATE_COG; + break; + default: + val = DRAW_POST_LOCATE_VERTEX; + break; + } + opt_view_arrow_location(i, GMSH_SET, val); } - if(force || WID->view_choice[4]->changed()){ - int val; - switch(WID->view_choice[4]->value()){ - case 0 : val = DRAW_POST_VONMISES; break; - default : val = DRAW_POST_EIGENVECTORS; break; - } - opt_view_tensor_type(i, GMSH_SET, val); + if(force || WID->view_choice[4]->changed()) { + int val; + switch (WID->view_choice[4]->value()) { + case 0: + val = DRAW_POST_VONMISES; + break; + default: + val = DRAW_POST_EIGENVECTORS; + break; + } + opt_view_tensor_type(i, GMSH_SET, val); } if(force || WID->view_butt[10]->changed()) - opt_view_show_element(i, GMSH_SET, WID->view_butt[10]->value()); + opt_view_show_element(i, GMSH_SET, WID->view_butt[10]->value()); if(force || WID->view_butt[4]->changed()) - opt_view_show_scale(i, GMSH_SET, WID->view_butt[4]->value()); + opt_view_show_scale(i, GMSH_SET, WID->view_butt[4]->value()); if(force || WID->view_butt[7]->changed()) - opt_view_auto_position(i, GMSH_SET, - WID->view_butt[7]->value()); + opt_view_auto_position(i, GMSH_SET, WID->view_butt[7]->value()); if(force || WID->view_butt[8]->changed()) - opt_view_show_time(i, GMSH_SET, WID->view_butt[8]->value()); + opt_view_show_time(i, GMSH_SET, WID->view_butt[8]->value()); if(force || WID->view_butt[5]->changed()) - opt_view_draw_strings(i, GMSH_SET, WID->view_butt[5]->value()); + opt_view_draw_strings(i, GMSH_SET, WID->view_butt[5]->value()); if(force || WID->view_butt[6]->changed()) - opt_view_transparent_scale(i, GMSH_SET, WID->view_butt[6]->value()); + opt_view_transparent_scale(i, GMSH_SET, WID->view_butt[6]->value()); if(force || WID->view_butt[11]->changed()) - opt_view_light(i,GMSH_SET,WID->view_butt[11]->value()); + opt_view_light(i, GMSH_SET, WID->view_butt[11]->value()); if(force || WID->view_butt[12]->changed()) - opt_view_smooth_normals(i,GMSH_SET,WID->view_butt[12]->value()); - + opt_view_smooth_normals(i, GMSH_SET, WID->view_butt[12]->value()); + if(force || WID->view_butt[13]->changed()) - opt_view_draw_points(i, GMSH_SET, WID->view_butt[13]->value()); + opt_view_draw_points(i, GMSH_SET, WID->view_butt[13]->value()); if(force || WID->view_butt[14]->changed()) - opt_view_draw_lines(i, GMSH_SET, WID->view_butt[14]->value()); + opt_view_draw_lines(i, GMSH_SET, WID->view_butt[14]->value()); if(force || WID->view_butt[15]->changed()) - opt_view_draw_triangles(i, GMSH_SET, WID->view_butt[15]->value()); + opt_view_draw_triangles(i, GMSH_SET, WID->view_butt[15]->value()); if(force || WID->view_butt[16]->changed()) - opt_view_draw_quadrangles(i, GMSH_SET, WID->view_butt[16]->value()); + opt_view_draw_quadrangles(i, GMSH_SET, WID->view_butt[16]->value()); if(force || WID->view_butt[17]->changed()) - opt_view_draw_tetrahedra(i, GMSH_SET, WID->view_butt[17]->value()); + opt_view_draw_tetrahedra(i, GMSH_SET, WID->view_butt[17]->value()); if(force || WID->view_butt[18]->changed()) - opt_view_draw_hexahedra(i, GMSH_SET, WID->view_butt[18]->value()); + opt_view_draw_hexahedra(i, GMSH_SET, WID->view_butt[18]->value()); if(force || WID->view_butt[19]->changed()) - opt_view_draw_prisms(i, GMSH_SET, WID->view_butt[19]->value()); + opt_view_draw_prisms(i, GMSH_SET, WID->view_butt[19]->value()); if(force || WID->view_butt[20]->changed()) - opt_view_draw_pyramids(i, GMSH_SET, WID->view_butt[20]->value()); + opt_view_draw_pyramids(i, GMSH_SET, WID->view_butt[20]->value()); if(force || WID->view_butt[21]->changed()) - opt_view_draw_scalars(i, GMSH_SET, WID->view_butt[21]->value()); + opt_view_draw_scalars(i, GMSH_SET, WID->view_butt[21]->value()); if(force || WID->view_butt[22]->changed()) - opt_view_draw_vectors(i, GMSH_SET, WID->view_butt[22]->value()); + opt_view_draw_vectors(i, GMSH_SET, WID->view_butt[22]->value()); if(force || WID->view_butt[23]->changed()) - opt_view_draw_tensors(i, GMSH_SET, WID->view_butt[23]->value()); + opt_view_draw_tensors(i, GMSH_SET, WID->view_butt[23]->value()); // view_values if(force || WID->view_value[31]->changed()) - opt_view_custom_min(i, GMSH_SET, WID->view_value[31]->value()); - + opt_view_custom_min(i, GMSH_SET, WID->view_value[31]->value()); + if(force || WID->view_value[32]->changed()) - opt_view_custom_max(i, GMSH_SET, WID->view_value[32]->value()); + opt_view_custom_max(i, GMSH_SET, WID->view_value[32]->value()); if(force || WID->view_value[30]->changed()) - opt_view_nb_iso(i, GMSH_SET, WID->view_value[30]->value()); + opt_view_nb_iso(i, GMSH_SET, WID->view_value[30]->value()); if(force || WID->view_value[40]->changed()) - opt_view_offset0(i, GMSH_SET, WID->view_value[40]->value()); + opt_view_offset0(i, GMSH_SET, WID->view_value[40]->value()); if(force || WID->view_value[41]->changed()) - opt_view_offset1(i, GMSH_SET, WID->view_value[41]->value()); + opt_view_offset1(i, GMSH_SET, WID->view_value[41]->value()); if(force || WID->view_value[42]->changed()) - opt_view_offset2(i, GMSH_SET, WID->view_value[42]->value()); + opt_view_offset2(i, GMSH_SET, WID->view_value[42]->value()); if(force || WID->view_value[43]->changed()) - opt_view_raise0(i, GMSH_SET, WID->view_value[43]->value()); + opt_view_raise0(i, GMSH_SET, WID->view_value[43]->value()); if(force || WID->view_value[44]->changed()) - opt_view_raise1(i, GMSH_SET, WID->view_value[44]->value()); + opt_view_raise1(i, GMSH_SET, WID->view_value[44]->value()); if(force || WID->view_value[45]->changed()) - opt_view_raise2(i, GMSH_SET, WID->view_value[45]->value()); + opt_view_raise2(i, GMSH_SET, WID->view_value[45]->value()); if(force || WID->view_value[50]->changed()) - opt_view_timestep(i, GMSH_SET, WID->view_value[50]->value()); + opt_view_timestep(i, GMSH_SET, WID->view_value[50]->value()); if(force || WID->view_value[60]->changed()) - opt_view_arrow_scale(i, GMSH_SET, WID->view_value[60]->value()); + opt_view_arrow_scale(i, GMSH_SET, WID->view_value[60]->value()); if(force || WID->view_value[61]->changed()) - opt_view_point_size(i, GMSH_SET, WID->view_value[61]->value()); + opt_view_point_size(i, GMSH_SET, WID->view_value[61]->value()); if(force || WID->view_value[62]->changed()) - opt_view_line_width(i, GMSH_SET, WID->view_value[62]->value()); + opt_view_line_width(i, GMSH_SET, WID->view_value[62]->value()); if(force || WID->view_value[11]->changed()) - opt_view_boundary(i, GMSH_SET, WID->view_value[11]->value()); + opt_view_boundary(i, GMSH_SET, WID->view_value[11]->value()); if(force || WID->view_value[12]->changed()) - opt_view_explode(i, GMSH_SET, WID->view_value[12]->value()); + opt_view_explode(i, GMSH_SET, WID->view_value[12]->value()); if(force || WID->view_value[10]->changed()) - opt_view_angle_smooth_normals(i,GMSH_SET,WID->view_value[10]->value()); + opt_view_angle_smooth_normals(i, GMSH_SET, + WID->view_value[10]->value()); if(force || WID->view_value[20]->changed()) - opt_view_position0(i,GMSH_SET,WID->view_value[20]->value()); + opt_view_position0(i, GMSH_SET, WID->view_value[20]->value()); if(force || WID->view_value[21]->changed()) - opt_view_position1(i,GMSH_SET,WID->view_value[21]->value()); + opt_view_position1(i, GMSH_SET, WID->view_value[21]->value()); if(force || WID->view_value[22]->changed()) - opt_view_size0(i,GMSH_SET,WID->view_value[22]->value()); + opt_view_size0(i, GMSH_SET, WID->view_value[22]->value()); if(force || WID->view_value[23]->changed()) - opt_view_size1(i,GMSH_SET,WID->view_value[23]->value()); + opt_view_size1(i, GMSH_SET, WID->view_value[23]->value()); if(force || WID->view_value[25]->changed()) - opt_view_nb_abscissa(i,GMSH_SET,WID->view_value[25]->value()); + opt_view_nb_abscissa(i, GMSH_SET, WID->view_value[25]->value()); if(force || WID->view_value[26]->changed()) - opt_view_grid(i,GMSH_SET,WID->view_value[26]->value()); + opt_view_grid(i, GMSH_SET, WID->view_value[26]->value()); // view_inputs - if(force || WID->view_input[0]->changed()) - opt_view_name(i, GMSH_SET, (char*)WID->view_input[0]->value()); + if(force || WID->view_input[0]->changed()) + opt_view_name(i, GMSH_SET, (char *)WID->view_input[0]->value()); if(force || WID->view_input[1]->changed()) - opt_view_format(i, GMSH_SET, (char*)WID->view_input[1]->value()); + opt_view_format(i, GMSH_SET, (char *)WID->view_input[1]->value()); if(force || WID->view_input[2]->changed()) - opt_view_abscissa_name(i, GMSH_SET, (char*)WID->view_input[2]->value()); + opt_view_abscissa_name(i, GMSH_SET, + (char *)WID->view_input[2]->value()); if(force || WID->view_input[3]->changed()) - opt_view_abscissa_format(i, GMSH_SET, (char*)WID->view_input[3]->value()); + opt_view_abscissa_format(i, GMSH_SET, + (char *)WID->view_input[3]->value()); // colorbar window - if(force || (WID->view_colorbar_window->changed() && i!=(long int)data)){ - ColorTable_Copy(&((Post_View*)List_Pointer(CTX.post.list,(long int)data))->CT); - ColorTable_Paste(&((Post_View*)List_Pointer(CTX.post.list,i))->CT); + if(force + || (WID->view_colorbar_window->changed() && i != (long int)data)) { + ColorTable_Copy(& + ((Post_View *) + List_Pointer(CTX.post.list, (long int)data))->CT); + ColorTable_Paste(&((Post_View *) List_Pointer(CTX.post.list, i))->CT); } } } // we clear all the flags - for(i=0; i<VIEW_OPT_BUTT; i++){ - if(WID->view_butt[i]) WID->view_butt[i]->clear_changed(); - if(WID->view_value[i]) WID->view_value[i]->clear_changed(); - if(WID->view_input[i]) WID->view_input[i]->clear_changed(); - if(WID->view_choice[i]) WID->view_choice[i]->clear_changed(); + for(i = 0; i < VIEW_OPT_BUTT; i++) { + if(WID->view_butt[i]) + WID->view_butt[i]->clear_changed(); + if(WID->view_value[i]) + WID->view_value[i]->clear_changed(); + if(WID->view_input[i]) + WID->view_input[i]->clear_changed(); + if(WID->view_choice[i]) + WID->view_choice[i]->clear_changed(); WID->view_colorbar_window->clear_changed(); } } // Contextual windows for geometry -void con_geometry_define_parameter_cb(CALLBACK_ARGS){ - add_param((char*)WID->context_geometry_input[0]->value(), - (char*)WID->context_geometry_input[1]->value(), - CTX.filename); +void con_geometry_define_parameter_cb(CALLBACK_ARGS) +{ + add_param((char *)WID->context_geometry_input[0]->value(), + (char *)WID->context_geometry_input[1]->value(), CTX.filename); } -void con_geometry_define_point_cb(CALLBACK_ARGS){ - strcpy(x_text, (char*)WID->context_geometry_input[2]->value()); +void con_geometry_define_point_cb(CALLBACK_ARGS) +{ + strcpy(x_text, (char *)WID->context_geometry_input[2]->value()); strcpy(y_text, WID->context_geometry_input[3]->value()); strcpy(z_text, WID->context_geometry_input[4]->value()); strcpy(l_text, WID->context_geometry_input[5]->value()); @@ -2606,13 +3166,15 @@ void con_geometry_define_point_cb(CALLBACK_ARGS){ Replot(); } -void con_geometry_define_translation_cb(CALLBACK_ARGS){ +void con_geometry_define_translation_cb(CALLBACK_ARGS) +{ strcpy(tx_text, WID->context_geometry_input[6]->value()); strcpy(ty_text, WID->context_geometry_input[7]->value()); strcpy(tz_text, WID->context_geometry_input[8]->value()); } -void con_geometry_define_rotation_cb(CALLBACK_ARGS){ +void con_geometry_define_rotation_cb(CALLBACK_ARGS) +{ strcpy(px_text, WID->context_geometry_input[9]->value()); strcpy(py_text, WID->context_geometry_input[10]->value()); strcpy(pz_text, WID->context_geometry_input[11]->value()); @@ -2622,14 +3184,16 @@ void con_geometry_define_rotation_cb(CALLBACK_ARGS){ strcpy(angle_text, WID->context_geometry_input[15]->value()); } -void con_geometry_define_scale_cb(CALLBACK_ARGS){ +void con_geometry_define_scale_cb(CALLBACK_ARGS) +{ strcpy(dx_text, WID->context_geometry_input[16]->value()); strcpy(dy_text, WID->context_geometry_input[17]->value()); strcpy(dz_text, WID->context_geometry_input[18]->value()); strcpy(df_text, WID->context_geometry_input[19]->value()); } -void con_geometry_define_symmetry_cb(CALLBACK_ARGS){ +void con_geometry_define_symmetry_cb(CALLBACK_ARGS) +{ strcpy(sa_text, WID->context_geometry_input[20]->value()); strcpy(sb_text, WID->context_geometry_input[21]->value()); strcpy(sc_text, WID->context_geometry_input[22]->value()); @@ -2639,17 +3203,20 @@ void con_geometry_define_symmetry_cb(CALLBACK_ARGS){ // Contextual windows for mesh -void con_mesh_define_length_cb(CALLBACK_ARGS){ +void con_mesh_define_length_cb(CALLBACK_ARGS) +{ strcpy(char_length_text, WID->context_mesh_input[0]->value()); } -void con_mesh_define_transfinite_line_cb(CALLBACK_ARGS){ +void con_mesh_define_transfinite_line_cb(CALLBACK_ARGS) +{ strcpy(trsf_pts_text, WID->context_mesh_input[1]->value()); - strcpy(trsf_type_text, (!WID->context_mesh_choice[0]->value()) ? "Progression" : "Bump"); + strcpy(trsf_type_text, + (!WID->context_mesh_choice[0]->value())? "Progression" : "Bump"); strcpy(trsf_typearg_text, WID->context_mesh_input[2]->value()); } -void con_mesh_define_transfinite_volume_cb(CALLBACK_ARGS){ +void con_mesh_define_transfinite_volume_cb(CALLBACK_ARGS) +{ strcpy(trsf_vol_text, WID->context_mesh_input[3]->value()); } - diff --git a/Fltk/Colorbar_Window.cpp b/Fltk/Colorbar_Window.cpp index a37765deac5d160259d3b6eed5166ae89897e879..c2fa3a504125f0510823784090760d3057712e11 100644 --- a/Fltk/Colorbar_Window.cpp +++ b/Fltk/Colorbar_Window.cpp @@ -1,4 +1,4 @@ -// $Id: Colorbar_Window.cpp,v 1.31 2003-02-25 04:02:50 geuzaine Exp $ +// $Id: Colorbar_Window.cpp,v 1.32 2003-03-01 22:36:37 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -32,7 +32,7 @@ #include "Colorbar_Window.h" #include "Context.h" -extern Context_T CTX; +extern Context_T CTX; #define UNDEFINED 0 #define EPS 1.e-10 @@ -45,271 +45,306 @@ extern Context_T CTX; // The constructor -Colorbar_Window::Colorbar_Window(int x,int y,int w,int h,const char *l) - : Fl_Window(x,y,w,h,l){ - +Colorbar_Window::Colorbar_Window(int x, int y, int w, int h, const char *l) + : Fl_Window(x, y, w, h, l) +{ ct = NULL; label = NULL; - help_flag = 1; - font_height = CTX.fontsize ; - marker_height = font_height ; - wedge_height = marker_height ; - marker_pos = 0 ; - minval = maxval = 0.0 ; + help_flag = 1; + font_height = CTX.fontsize; + marker_height = font_height; + wedge_height = marker_height; + marker_pos = 0; + minval = maxval = 0.0; } // rgb on [0, 1], sv returned on [0, 1] and h on [0, 6]. // Exception: h is returned UNDEFINED if S==0. -#define RETURN_HSV(h,s,v) {*H=h; *S=s; *V=v; return;} - -static void RGB_to_HSV(double R, double G, double B, - double *H, double *S, double *V) { - double v, x, f; - int i; - - x = DMIN(DMIN(R, G), B); - v = DMAX(DMAX(R, G), B); - if(v == x) RETURN_HSV(UNDEFINED, 0, v); - f = (R == x) ? G - B : ((G == x) ? B - R : R - G); - i = (R == x) ? 3 : ((G == x) ? 5 : 1); - RETURN_HSV(i - f /(v - x), (v - x)/v, v); -} +#define RETURN_HSV(h,s,v) {*H=h; *S=s; *V=v; return;} + +static void RGB_to_HSV(double R, double G, double B, + double *H, double *S, double *V) +{ + double v, x, f; + int i; + + x = DMIN(DMIN(R, G), B); + v = DMAX(DMAX(R, G), B); + if(v == x) + RETURN_HSV(UNDEFINED, 0, v); + f = (R == x) ? G - B : ((G == x) ? B - R : R - G); + i = (R == x) ? 3 : ((G == x) ? 5 : 1); + RETURN_HSV(i - f / (v - x), (v - x) / v, v); +} // h given on [0, 6] or UNDEFINED. s and v given on [0, 1]. // rgb each returned on [0, 1]. -#define RETURN_RGB(r,g,b) {*R=r; *G=g; *B=b; return;} +#define RETURN_RGB(r,g,b) {*R=r; *G=g; *B=b; return;} -static void HSV_to_RGB(double H, double S, double V, - double *R, double *G, double *B) { - double m, n, f; - int i; - - if (H == UNDEFINED) RETURN_RGB(V, V, V); +static void HSV_to_RGB(double H, double S, double V, + double *R, double *G, double *B) +{ + double m, n, f; + int i; + + if(H == UNDEFINED) + RETURN_RGB(V, V, V); i = (int)floor(H); - f = H - i; - if ( !(i&1) ) f = 1 - f; // if i is even - m = V * (1 - S); - n = V * (1 - S * f); - - switch (i) { - case 6: - case 0: RETURN_RGB(V, n, m); - case 1: RETURN_RGB(n, V, m); - case 2: RETURN_RGB(m, V, n); - case 3: RETURN_RGB(m, n, V); - case 4: RETURN_RGB(n, m, V); - case 5: RETURN_RGB(V, m, n); - } -} + f = H - i; + if(!(i & 1)) + f = 1 - f; // if i is even + m = V * (1 - S); + n = V * (1 - S * f); + + switch (i) { + case 6: + case 0: + RETURN_RGB(V, n, m); + case 1: + RETURN_RGB(n, V, m); + case 2: + RETURN_RGB(m, V, n); + case 3: + RETURN_RGB(m, n, V); + case 4: + RETURN_RGB(n, m, V); + case 5: + RETURN_RGB(V, m, n); + } +} // Convert window X coordinate to color table index -int Colorbar_Window::x_to_index(int x){ +int Colorbar_Window::x_to_index(int x) +{ int index; - index = (int) (x * (float) ct->size / (float)w()); - if (index<0) + index = (int)(x * (float)ct->size / (float)w()); + if(index < 0) index = 0; - else if (index >= ct->size) - index = ct->size-1; + else if(index >= ct->size) + index = ct->size - 1; return index; } // Convert color table index to window X coordinate -int Colorbar_Window::index_to_x(int index){ +int Colorbar_Window::index_to_x(int index) +{ int x; - x = (int) (index * (float)w() / (float)(ct->size-1)); - if (x >= w()) + x = (int)(index * (float)w() / (float)(ct->size - 1)); + if(x >= w()) x = w() - 1; return x; } // Convert a color intensity to a window Y coordinate -int Colorbar_Window::intensity_to_y(int intensity){ +int Colorbar_Window::intensity_to_y(int intensity) +{ int y; - y = (int) (wedge_y - intensity * (float)wedge_y/255.); - if (y < 0) + y = (int)(wedge_y - intensity * (float)wedge_y / 255.); + if(y < 0) y = 0; - else if (y >= wedge_y) + else if(y >= wedge_y) y = wedge_y - 1; return y; } // Convert a window Y coordinate to a color intensity -int Colorbar_Window::y_to_intensity(int y){ +int Colorbar_Window::y_to_intensity(int y) +{ int intensity; - intensity = (int) ((wedge_y - y) * 255. / (float)wedge_y); - if (intensity < 0) + intensity = (int)((wedge_y - y) * 255. / (float)wedge_y); + if(intensity < 0) intensity = 0; - else if (intensity > 255) + else if(intensity > 255) intensity = 255; return intensity; } // Redraw part of the Colorbar_Window (between a and b) -void Colorbar_Window::redraw_range(int a, int b){ - int i; - int x,y, px=0,py=0; - int x1, y1, x2, y2; - int intensity=0; - double H,S,V; +void Colorbar_Window::redraw_range(int a, int b) +{ + int i; + int x, y, px = 0, py = 0; + int x1, y1, x2, y2; + int intensity = 0; + double H, S, V; - make_current(); + make_current(); - if(a < 0) a = 0; - if(b >= ct->size) b = ct->size-1; + if(a < 0) + a = 0; + if(b >= ct->size) + b = ct->size - 1; - // calculate region to update - x1 = index_to_x(a); - x2 = index_to_x(b); - y1 = intensity_to_y(255); - y2 = intensity_to_y(0); + // calculate region to update + x1 = index_to_x(a); + x2 = index_to_x(b); + y1 = intensity_to_y(255); + y2 = intensity_to_y(0); - // erase region - fl_color(color_bg); - fl_rectf(x1, y1, x2-x1+1, y2-y1+1); + // erase region + fl_color(color_bg); + fl_rectf(x1, y1, x2 - x1 + 1, y2 - y1 + 1); + + // redraw region of entries in interval [a,b] + if(a > 0) + a--; + if(b < ct->size - 1) + b++; + + // draw red or hue levels + for(i = a; i <= b; i++) { + x = index_to_x(i); + if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_RGB) + intensity = UNPACK_RED(ct->table[i]); + else if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_HSV) { + RGB_to_HSV(UNPACK_RED(ct->table[i]) / 255., + UNPACK_GREEN(ct->table[i]) / 255., + UNPACK_BLUE(ct->table[i]) / 255., &H, &S, &V); + intensity = (int)(H / 6. * 255. + EPS); + } + y = intensity_to_y(intensity); + if(i != a) { + fl_color(FL_RED); + fl_line(px, py, x, y); + } + px = x; + py = y; + } - // redraw region of entries in interval [a,b] - if (a > 0) a--; - if (b < ct->size-1) b++; + // draw green or saturation levels + for(i = a; i <= b; i++) { + x = index_to_x(i); + if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_RGB) + intensity = UNPACK_GREEN(ct->table[i]); + else if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_HSV) { + RGB_to_HSV(UNPACK_RED(ct->table[i]) / 255., + UNPACK_GREEN(ct->table[i]) / 255., + UNPACK_BLUE(ct->table[i]) / 255., &H, &S, &V); + intensity = (int)(S * 255.); + } + y = intensity_to_y(intensity); + if(i != a) { + fl_color(FL_GREEN); + fl_line(px, py, x, y); + } + px = x; + py = y; + } - // draw red or hue levels - for (i=a ; i<=b ; i++) { - x = index_to_x(i); - if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_RGB) - intensity = UNPACK_RED(ct->table[i]); - else if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_HSV){ - RGB_to_HSV(UNPACK_RED (ct->table[i])/255., - UNPACK_GREEN(ct->table[i])/255., - UNPACK_BLUE (ct->table[i])/255., - &H,&S,&V); - intensity = (int)(H/6.*255.+EPS); - } - y = intensity_to_y(intensity); - if (i!=a){ - fl_color(FL_RED); - fl_line(px,py,x,y); - } - px = x; py = y; - } + // draw blue or value levels + for(i = a; i <= b; i++) { + x = index_to_x(i); + if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_RGB) + intensity = UNPACK_BLUE(ct->table[i]); + else if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_HSV) { + RGB_to_HSV(UNPACK_RED(ct->table[i]) / 255., + UNPACK_GREEN(ct->table[i]) / 255., + UNPACK_BLUE(ct->table[i]) / 255., &H, &S, &V); + intensity = (int)(V * 255.); + } + y = intensity_to_y(intensity); + if(i != a) { + fl_color(FL_BLUE); + fl_line(px, py, x, y); + } + px = x; + py = y; + } - // draw green or saturation levels - for (i=a ; i<=b ; i++) { - x = index_to_x(i); - if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_RGB) - intensity = UNPACK_GREEN(ct->table[i]); - else if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_HSV){ - RGB_to_HSV(UNPACK_RED (ct->table[i])/255., - UNPACK_GREEN(ct->table[i])/255., - UNPACK_BLUE (ct->table[i])/255., - &H,&S,&V); - intensity = (int)(S*255.); - } - y = intensity_to_y(intensity); - if (i!=a){ - fl_color(FL_GREEN); - fl_line(px,py,x,y); - } - px = x; py = y; - } + // draw alpha levels + for(i = a; i <= b; i++) { + x = index_to_x(i); + y = intensity_to_y(UNPACK_ALPHA(ct->table[i])); + if(i != a) { + fl_color(fl_contrast(FL_BLACK, color_bg)); + fl_line(px, py, x, y); + } + px = x; + py = y; + } - // draw blue or value levels - for (i=a ; i<=b ; i++) { - x = index_to_x(i); - if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_RGB) - intensity = UNPACK_BLUE(ct->table[i]); - else if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_HSV){ - RGB_to_HSV(UNPACK_RED (ct->table[i])/255., - UNPACK_GREEN(ct->table[i])/255., - UNPACK_BLUE (ct->table[i])/255., - &H,&S,&V); - intensity = (int)(V*255.); - } - y = intensity_to_y(intensity); - if (i!=a){ - fl_color(FL_BLUE); - fl_line(px,py,x,y); - } - px = x; py = y; - } - - // draw alpha levels - for (i=a ; i<=b ; i++) { - x = index_to_x(i); - y = intensity_to_y(UNPACK_ALPHA(ct->table[i])); - if (i!=a){ - fl_color(fl_contrast(FL_BLACK,color_bg)); - fl_line(px,py,x,y); - } - px = x; py = y; - } - - // draw the color bar - for (x=x1 ; x<=x2 ; x++) { - int r, g, b; - unsigned int color; - i = x_to_index(x); - color = ct->table[i]; - r = UNPACK_RED(color); - g = UNPACK_GREEN(color); - b = UNPACK_BLUE(color); - fl_color(r,g,b); - fl_line(x, wedge_y, x, wedge_y + wedge_height-1); - } - - // print colortable mode and help - fl_font(FL_HELVETICA, font_height); - fl_color(fl_contrast(FL_BLACK,color_bg)); - int xx0=10, xx1=12*font_height, yy0=10; - if (help_flag){ - i = 0; - fl_draw("1, 2, ..., 8", xx0,yy0+(i+1)*font_height); - fl_draw( "select predefined colormap", xx1,yy0+(i+1)*font_height); i++; - fl_draw("mouse1", xx0,yy0+(i+1)*font_height); - fl_draw( "draw red or hue channel", xx1,yy0+(i+1)*font_height); i++; - fl_draw("mouse2", xx0,yy0+(i+1)*font_height); - fl_draw( "draw green or saturation channel", xx1,yy0+(i+1)*font_height); i++; - fl_draw("mouse3", xx0,yy0+(i+1)*font_height); - fl_draw( "draw blue or value channel", xx1,yy0+(i+1)*font_height); i++; - fl_draw("Ctrl+mouse1", xx0,yy0+(i+1)*font_height); - fl_draw( "draw alpha channel", xx1,yy0+(i+1)*font_height); i++; - fl_draw("c, p, r", xx0,yy0+(i+1)*font_height); - fl_draw( "copy, paste or reset colormap", xx1,yy0+(i+1)*font_height); i++; - fl_draw("m", xx0,yy0+(i+1)*font_height); - fl_draw( "toggle RGB/HSV mode", xx1,yy0+(i+1)*font_height); i++; - fl_draw("left, right", xx0,yy0+(i+1)*font_height); - fl_draw( "move colormap", xx1,yy0+(i+1)*font_height); i++; - fl_draw("Ctrl+left, Ctrl+right", xx0,yy0+(i+1)*font_height); - fl_draw( "rotate colormap", xx1,yy0+(i+1)*font_height); i++; - fl_draw("up, down", xx0,yy0+(i+1)*font_height); - fl_draw( "modify color curvature", xx1,yy0+(i+1)*font_height); i++; - fl_draw("Ctrl+up, Ctrl+down", xx0,yy0+(i+1)*font_height); - fl_draw( "incr. or decr. alpha channel", xx1,yy0+(i+1)*font_height); i++; - fl_draw("i, Ctrl+i", xx0,yy0+(i+1)*font_height); - fl_draw( "invert x or y range", xx1,yy0+(i+1)*font_height); i++; - fl_draw("b, Ctrl+b", xx0,yy0+(i+1)*font_height); - fl_draw( "increase or decrease gamma", xx1,yy0+(i+1)*font_height); i++; - fl_draw("h", xx0,yy0+(i+1)*font_height); - fl_draw( "show this help message", xx1,yy0+(i+1)*font_height); i++; - } - else - if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_RGB) - fl_draw("RGB", xx0, yy0+font_height); - else if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_HSV) - fl_draw("HSV", xx0, yy0+font_height); + // draw the color bar + for(x = x1; x <= x2; x++) { + int r, g, b; + unsigned int color; + i = x_to_index(x); + color = ct->table[i]; + r = UNPACK_RED(color); + g = UNPACK_GREEN(color); + b = UNPACK_BLUE(color); + fl_color(r, g, b); + fl_line(x, wedge_y, x, wedge_y + wedge_height - 1); + } + + // print colortable mode and help + fl_font(FL_HELVETICA, font_height); + fl_color(fl_contrast(FL_BLACK, color_bg)); + int xx0 = 10, xx1 = 12 * font_height, yy0 = 10; + if(help_flag) { + i = 0; + fl_draw("1, 2, ..., 8", xx0, yy0 + (i + 1) * font_height); + fl_draw("select predefined colormap", xx1, yy0 + (i + 1) * font_height); + i++; + fl_draw("mouse1", xx0, yy0 + (i + 1) * font_height); + fl_draw("draw red or hue channel", xx1, yy0 + (i + 1) * font_height); + i++; + fl_draw("mouse2", xx0, yy0 + (i + 1) * font_height); + fl_draw("draw green or saturation channel", xx1, yy0 + (i + 1) * font_height); + i++; + fl_draw("mouse3", xx0, yy0 + (i + 1) * font_height); + fl_draw("draw blue or value channel", xx1, yy0 + (i + 1) * font_height); + i++; + fl_draw("Ctrl+mouse1", xx0, yy0 + (i + 1) * font_height); + fl_draw("draw alpha channel", xx1, yy0 + (i + 1) * font_height); + i++; + fl_draw("c, p, r", xx0, yy0 + (i + 1) * font_height); + fl_draw("copy, paste or reset colormap", xx1, yy0 + (i + 1) * font_height); + i++; + fl_draw("m", xx0, yy0 + (i + 1) * font_height); + fl_draw("toggle RGB/HSV mode", xx1, yy0 + (i + 1) * font_height); + i++; + fl_draw("left, right", xx0, yy0 + (i + 1) * font_height); + fl_draw("move colormap", xx1, yy0 + (i + 1) * font_height); + i++; + fl_draw("Ctrl+left, Ctrl+right", xx0, yy0 + (i + 1) * font_height); + fl_draw("rotate colormap", xx1, yy0 + (i + 1) * font_height); + i++; + fl_draw("up, down", xx0, yy0 + (i + 1) * font_height); + fl_draw("modify color curvature", xx1, yy0 + (i + 1) * font_height); + i++; + fl_draw("Ctrl+up, Ctrl+down", xx0, yy0 + (i + 1) * font_height); + fl_draw("incr. or decr. alpha channel", xx1, yy0 + (i + 1) * font_height); + i++; + fl_draw("i, Ctrl+i", xx0, yy0 + (i + 1) * font_height); + fl_draw("invert x or y range", xx1, yy0 + (i + 1) * font_height); + i++; + fl_draw("b, Ctrl+b", xx0, yy0 + (i + 1) * font_height); + fl_draw("increase or decrease gamma", xx1, yy0 + (i + 1) * font_height); + i++; + fl_draw("h", xx0, yy0 + (i + 1) * font_height); + fl_draw("show this help message", xx1, yy0 + (i + 1) * font_height); + i++; + } + else if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_RGB) + fl_draw("RGB", xx0, yy0 + font_height); + else if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_HSV) + fl_draw("HSV", xx0, yy0 + font_height); } // Redraw the marker and the text -void Colorbar_Window::redraw_marker(){ +void Colorbar_Window::redraw_marker() +{ int x, y0, y1; char str[50]; float val; @@ -318,43 +353,46 @@ void Colorbar_Window::redraw_marker(){ y0 = marker_y; y1 = h() - 1; - + fl_color(color_bg); - fl_rectf(0, y0, w(), y1-y0+1); - + fl_rectf(0, y0, w(), y1 - y0 + 1); + // draw marker below color wedge x = index_to_x(marker_pos); - fl_color(fl_contrast(FL_BLACK,color_bg)); - fl_line(x, marker_y, x, marker_y+marker_height); - fl_line(x, marker_y, x-3, marker_y+6); - fl_line(x, marker_y, x+3, marker_y+6); - + fl_color(fl_contrast(FL_BLACK, color_bg)); + fl_line(x, marker_y, x, marker_y + marker_height); + fl_line(x, marker_y, x - 3, marker_y + 6); + fl_line(x, marker_y, x + 3, marker_y + 6); + // draw marker value fl_font(FL_HELVETICA, font_height); - val = minval + (maxval-minval) * ((float)marker_pos/(float)(ct->size-1)); + val = + minval + (maxval - minval) * ((float)marker_pos / (float)(ct->size - 1)); sprintf(str, "%g", val); fl_draw(str, 10, label_y); } // Draw everything -void Colorbar_Window::draw(){ - if(ct){ - label_y = h() - 5; +void Colorbar_Window::draw() +{ + if(ct) { + label_y = h() - 5; marker_y = label_y - marker_height - font_height; wedge_y = marker_y - wedge_height; - color_bg = fl_color_cube(UNPACK_RED(CTX.color.bg)*FL_NUM_RED/256, - UNPACK_GREEN(CTX.color.bg)*FL_NUM_GREEN/256, - UNPACK_BLUE(CTX.color.bg)*FL_NUM_BLUE/256); - redraw_range(0, ct->size-1); + color_bg = fl_color_cube(UNPACK_RED(CTX.color.bg) * FL_NUM_RED / 256, + UNPACK_GREEN(CTX.color.bg) * FL_NUM_GREEN / 256, + UNPACK_BLUE(CTX.color.bg) * FL_NUM_BLUE / 256); + redraw_range(0, ct->size - 1); redraw_marker(); } } // Update -void Colorbar_Window::update(char *name, float min, float max, - GmshColorTable *table, int *changed){ +void Colorbar_Window::update(char *name, float min, float max, + GmshColorTable * table, int *changed) +{ label = name; ct = table; viewchanged = changed; @@ -365,145 +403,155 @@ void Colorbar_Window::update(char *name, float min, float max, // Handle -int Colorbar_Window::handle(int event){ - static int p1=0, p2=0, p3=0, p4=0; - static int pentry, move_marker; - int i, ibut, xpos, ypos, modify, entry, compute; +int Colorbar_Window::handle(int event) +{ + static int p1 = 0, p2 = 0, p3 = 0, p4 = 0; + static int pentry, move_marker; + int i, ibut, xpos, ypos, modify, entry, compute; modify = 0; compute = 0; - switch(event){ + switch (event) { - case FL_ENTER : - take_focus(); //force keyboard focus on the ColorbarWindow + case FL_ENTER: + take_focus(); //force keyboard focus on the ColorbarWindow return 1; - case FL_LEAVE : - case FL_FOCUS : - case FL_UNFOCUS : + case FL_LEAVE: + case FL_FOCUS: + case FL_UNFOCUS: return 1; - case FL_SHORTCUT : - case FL_KEYBOARD : - if(Fl::test_shortcut('0')){ - ColorTable_InitParam(0, ct, 1, 1); compute=1; + case FL_SHORTCUT: + case FL_KEYBOARD: + if(Fl::test_shortcut('0')) { + ColorTable_InitParam(0, ct, 1, 1); + compute = 1; } - else if(Fl::test_shortcut('1')){ - ColorTable_InitParam(1, ct, 1, 1); compute=1; + else if(Fl::test_shortcut('1')) { + ColorTable_InitParam(1, ct, 1, 1); + compute = 1; } - else if(Fl::test_shortcut('2')){ - ColorTable_InitParam(2, ct, 1, 1); compute=1; + else if(Fl::test_shortcut('2')) { + ColorTable_InitParam(2, ct, 1, 1); + compute = 1; } - else if(Fl::test_shortcut('3')){ - ColorTable_InitParam(3, ct, 1, 1); compute=1; + else if(Fl::test_shortcut('3')) { + ColorTable_InitParam(3, ct, 1, 1); + compute = 1; } - else if(Fl::test_shortcut('4')){ - ColorTable_InitParam(4, ct, 1, 1); compute=1; + else if(Fl::test_shortcut('4')) { + ColorTable_InitParam(4, ct, 1, 1); + compute = 1; } - else if(Fl::test_shortcut('5')){ - ColorTable_InitParam(5, ct, 1, 1); compute=1; + else if(Fl::test_shortcut('5')) { + ColorTable_InitParam(5, ct, 1, 1); + compute = 1; } - else if(Fl::test_shortcut('6')){ - ColorTable_InitParam(6, ct, 1, 1); compute=1; + else if(Fl::test_shortcut('6')) { + ColorTable_InitParam(6, ct, 1, 1); + compute = 1; } - else if(Fl::test_shortcut('7')){ - ColorTable_InitParam(7, ct, 1, 1); compute=1; + else if(Fl::test_shortcut('7')) { + ColorTable_InitParam(7, ct, 1, 1); + compute = 1; } - else if(Fl::test_shortcut('8')){ - ColorTable_InitParam(8, ct, 1, 1); compute=1; + else if(Fl::test_shortcut('8')) { + ColorTable_InitParam(8, ct, 1, 1); + compute = 1; } - else if(Fl::test_shortcut('9')){ - ColorTable_InitParam(9, ct, 1, 1); compute=1; + else if(Fl::test_shortcut('9')) { + ColorTable_InitParam(9, ct, 1, 1); + compute = 1; } - else if(Fl::test_shortcut('c')){ + else if(Fl::test_shortcut('c')) { ColorTable_Copy(ct); } - else if(Fl::test_shortcut('p')){ - ColorTable_Paste(ct); + else if(Fl::test_shortcut('p')) { + ColorTable_Paste(ct); draw(); } - else if(Fl::test_shortcut('h')){ + else if(Fl::test_shortcut('h')) { help_flag = !help_flag; draw(); } - else if(Fl::test_shortcut('r')){ - ColorTable_InitParam(ct->ipar[COLORTABLE_NUMBER], - ct, 1, 1); - compute=1; + else if(Fl::test_shortcut('r')) { + ColorTable_InitParam(ct->ipar[COLORTABLE_NUMBER], ct, 1, 1); + compute = 1; } - else if(Fl::test_shortcut('m')){ + else if(Fl::test_shortcut('m')) { if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_RGB) ct->ipar[COLORTABLE_MODE] = COLORTABLE_HSV; else ct->ipar[COLORTABLE_MODE] = COLORTABLE_RGB; - draw(); + draw(); } - else if(Fl::test_shortcut('i')){ - ct->ipar[COLORTABLE_SWAP] = !ct->ipar[COLORTABLE_SWAP]; - compute=1; + else if(Fl::test_shortcut('i')) { + ct->ipar[COLORTABLE_SWAP] = !ct->ipar[COLORTABLE_SWAP]; + compute = 1; } - else if(Fl::test_shortcut(FL_CTRL + 'i')){ - ct->ipar[COLORTABLE_INVERT] = !ct->ipar[COLORTABLE_INVERT]; - compute=1; + else if(Fl::test_shortcut(FL_CTRL + 'i')) { + ct->ipar[COLORTABLE_INVERT] = !ct->ipar[COLORTABLE_INVERT]; + compute = 1; } - else if(Fl::test_shortcut('b')){ + else if(Fl::test_shortcut('b')) { ct->fpar[COLORTABLE_BETA] += 0.05; - if(ct->fpar[COLORTABLE_BETA]>1.0) - ct->fpar[COLORTABLE_BETA] = 1.0; + if(ct->fpar[COLORTABLE_BETA] > 1.0) + ct->fpar[COLORTABLE_BETA] = 1.0; compute = 1; } - else if(Fl::test_shortcut(FL_CTRL + 'b')){ + else if(Fl::test_shortcut(FL_CTRL + 'b')) { ct->fpar[COLORTABLE_BETA] -= 0.05; - if(ct->fpar[COLORTABLE_BETA]<-1.0) - ct->fpar[COLORTABLE_BETA] = -1.0; + if(ct->fpar[COLORTABLE_BETA] < -1.0) + ct->fpar[COLORTABLE_BETA] = -1.0; compute = 1; } - else if(Fl::test_shortcut(FL_Left)){ - ct->fpar[COLORTABLE_BIAS] -= 0.05; - compute = 1; + else if(Fl::test_shortcut(FL_Left)) { + ct->fpar[COLORTABLE_BIAS] -= 0.05; + compute = 1; } - else if(Fl::test_shortcut(FL_CTRL + FL_Left)){ + else if(Fl::test_shortcut(FL_CTRL + FL_Left)) { ct->ipar[COLORTABLE_ROTATE] += 5; - if(ct->ipar[COLORTABLE_ROTATE] > ct->size-1) - ct->ipar[COLORTABLE_ROTATE] -= ct->size-1; - compute = 1; + if(ct->ipar[COLORTABLE_ROTATE] > ct->size - 1) + ct->ipar[COLORTABLE_ROTATE] -= ct->size - 1; + compute = 1; } - else if(Fl::test_shortcut(FL_Right)){ - ct->fpar[COLORTABLE_BIAS] += 0.05; + else if(Fl::test_shortcut(FL_Right)) { + ct->fpar[COLORTABLE_BIAS] += 0.05; compute = 1; } - else if(Fl::test_shortcut(FL_CTRL + FL_Right)){ + else if(Fl::test_shortcut(FL_CTRL + FL_Right)) { ct->ipar[COLORTABLE_ROTATE] -= 5; - if(ct->ipar[COLORTABLE_ROTATE] < -(ct->size-1)) - ct->ipar[COLORTABLE_ROTATE] += ct->size-1; + if(ct->ipar[COLORTABLE_ROTATE] < -(ct->size - 1)) + ct->ipar[COLORTABLE_ROTATE] += ct->size - 1; compute = 1; } - else if(Fl::test_shortcut(FL_Up)){ + else if(Fl::test_shortcut(FL_Up)) { ct->fpar[COLORTABLE_CURVE] -= 0.05; - compute = 1; + compute = 1; } - else if(Fl::test_shortcut(FL_CTRL + FL_Up)){ + else if(Fl::test_shortcut(FL_CTRL + FL_Up)) { ct->fpar[COLORTABLE_ALPHAPOW] += 0.05; - if (ct->fpar[COLORTABLE_ALPHAPOW] > 1.0) - ct->fpar[COLORTABLE_ALPHAPOW] = 1.0; - compute = 1; + if(ct->fpar[COLORTABLE_ALPHAPOW] > 1.0) + ct->fpar[COLORTABLE_ALPHAPOW] = 1.0; + compute = 1; } - else if(Fl::test_shortcut(FL_Down)){ + else if(Fl::test_shortcut(FL_Down)) { ct->fpar[COLORTABLE_CURVE] += 0.05; - compute = 1; + compute = 1; } - else if(Fl::test_shortcut(FL_CTRL + FL_Down)){ + else if(Fl::test_shortcut(FL_CTRL + FL_Down)) { ct->fpar[COLORTABLE_ALPHAPOW] -= 0.05; - if (ct->fpar[COLORTABLE_ALPHAPOW] < 0.0) - ct->fpar[COLORTABLE_ALPHAPOW] = 0.0; - compute = 1; + if(ct->fpar[COLORTABLE_ALPHAPOW] < 0.0) + ct->fpar[COLORTABLE_ALPHAPOW] = 0.0; + compute = 1; } - else{ - return Fl_Window::handle(event); + else { + return Fl_Window::handle(event); } - if(compute){ + if(compute) { ColorTable_Recompute(ct, 1, 1); draw(); *viewchanged = 1; @@ -511,44 +559,45 @@ int Colorbar_Window::handle(int event){ } return 1; - case FL_PUSH : + case FL_PUSH: ibut = Fl::event_button(); xpos = Fl::event_x(); ypos = Fl::event_y(); - if(help_flag){ + if(help_flag) { help_flag = 0; draw(); } // change color function or marker position - if (ypos < wedge_y) + if(ypos < wedge_y) move_marker = 0; else move_marker = 1; // determine which curve to modify - if (Fl::event_state(FL_CTRL)) + if(Fl::event_state(FL_CTRL)) p4 = 1; - else if(ibut == 1 && !Fl::event_state(FL_SHIFT) && !Fl::event_state(FL_ALT)) - p1 = 1 ; + else if(ibut == 1 && !Fl::event_state(FL_SHIFT) + && !Fl::event_state(FL_ALT)) + p1 = 1; else if(ibut == 2 || (ibut == 1 && Fl::event_state(FL_SHIFT))) - p2 = 1 ; + p2 = 1; else - p3 = 1 ; + p3 = 1; pentry = x_to_index(xpos); modify = 1; break; - case FL_RELEASE : + case FL_RELEASE: ibut = Fl::event_button(); xpos = Fl::event_x(); ypos = Fl::event_y(); - p1 = 0 ; - p2 = 0 ; - p3 = 0 ; + p1 = 0; + p2 = 0; + p3 = 0; p4 = 0; break; - case FL_DRAG : + case FL_DRAG: ibut = Fl::event_button(); xpos = Fl::event_x(); ypos = Fl::event_y(); @@ -558,16 +607,16 @@ int Colorbar_Window::handle(int event){ default: // don't know what to do with the event: passing it to parent return Fl_Window::handle(event); - + } // Modify one or more of the color curves - - if (modify && (p1 || p2 || p3 || p4)) { + + if(modify && (p1 || p2 || p3 || p4)) { // calculate which entry in color table to change entry = x_to_index(xpos); // update - if (move_marker) { + if(move_marker) { // changing marker position marker_pos = entry; redraw_marker(); @@ -580,62 +629,75 @@ int Colorbar_Window::handle(int event){ set_changed(); value = y_to_intensity(ypos); - - if (pentry<=entry) { - a = pentry; - b = entry; + + if(pentry <= entry) { + a = pentry; + b = entry; } else { - a = entry; - b = pentry; + a = entry; + b = pentry; } - + // update entries from 'pentry' to 'entry' - for (i=a; i<=b; i++) { - int red, green, blue, alpha; - double R,G,B,H,S,V; - - red = UNPACK_RED (ct->table[i]); - green = UNPACK_GREEN(ct->table[i]); - blue = UNPACK_BLUE (ct->table[i]); - alpha = UNPACK_ALPHA(ct->table[i]); - - if(ct->ipar[COLORTABLE_MODE]==COLORTABLE_RGB){ - if (p1) { red = value; } - if (p2) { green = value; } - if (p3) { blue = value; } - if (p4) { alpha = value; } - } - else if(ct->ipar[COLORTABLE_MODE]==COLORTABLE_HSV){ - RGB_to_HSV((double)red/255.,(double)green/255.,(double)blue/255., - &H,&S,&V); - if (p1) { H = 6.*(double)value/255.+EPS ; } - if (p2) { S = (double)value/255.; } - if (p3) { V = (double)value/255.; } - if (p4) { alpha = value; } - HSV_to_RGB(H, S, V, &R,&G,&B); - red = (int)(255 * R); - green = (int)(255 * G); - blue = (int)(255 * B); - } - - ct->table[i] = PACK_COLOR(red,green,blue,alpha); - } - + for(i = a; i <= b; i++) { + int red, green, blue, alpha; + double R, G, B, H, S, V; + + red = UNPACK_RED(ct->table[i]); + green = UNPACK_GREEN(ct->table[i]); + blue = UNPACK_BLUE(ct->table[i]); + alpha = UNPACK_ALPHA(ct->table[i]); + + if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_RGB) { + if(p1) { + red = value; + } + if(p2) { + green = value; + } + if(p3) { + blue = value; + } + if(p4) { + alpha = value; + } + } + else if(ct->ipar[COLORTABLE_MODE] == COLORTABLE_HSV) { + RGB_to_HSV((double)red / 255., (double)green / 255., + (double)blue / 255., &H, &S, &V); + if(p1) { + H = 6. * (double)value / 255. + EPS; + } + if(p2) { + S = (double)value / 255.; + } + if(p3) { + V = (double)value / 255.; + } + if(p4) { + alpha = value; + } + HSV_to_RGB(H, S, V, &R, &G, &B); + red = (int)(255 * R); + green = (int)(255 * G); + blue = (int)(255 * B); + } + + ct->table[i] = PACK_COLOR(red, green, blue, alpha); + } + // redraw the color curves - if (pentry<entry) - redraw_range(pentry-1, entry+1); + if(pentry < entry) + redraw_range(pentry - 1, entry + 1); else - redraw_range(entry-1, pentry+1); - + redraw_range(entry - 1, pentry + 1); + pentry = entry; - + } return 1; } - - return 1; + return 1; } - - diff --git a/Fltk/GUI.cpp b/Fltk/GUI.cpp index ad8292285c89bad0004cc615ec01dccbd9e99298..d1ad8f61744b07ef633ebb26565285abb88ea42e 100644 --- a/Fltk/GUI.cpp +++ b/Fltk/GUI.cpp @@ -1,4 +1,4 @@ -// $Id: GUI.cpp,v 1.228 2003-02-25 14:40:59 geuzaine Exp $ +// $Id: GUI.cpp,v 1.229 2003-03-01 22:36:37 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -67,12 +67,12 @@ #define RADIO_COLOR FL_BLACK #endif -#define IW (10*fontsize) // input field width -#define BB (6*fontsize+4) // width of a button with internal label -#define BH (2*fontsize+1) // button height +#define IW (10*fontsize) // input field width +#define BB (6*fontsize+4) // width of a button with internal label +#define BH (2*fontsize+1) // button height #define WB (5) // window border -extern Context_T CTX; +extern Context_T CTX; // Definition of the static menus @@ -149,16 +149,16 @@ Fl_Menu_Item m_module_table[] = { // Definition of the dynamic contexts -Context_Item menu_geometry[] = -{ { "0Geometry", NULL } , +Context_Item menu_geometry[] = { + { "0Geometry", NULL } , { "Elementary", (Fl_Callback *)geometry_elementary_cb } , { "Physical", (Fl_Callback *)geometry_physical_cb } , { "Edit", (Fl_Callback *)geometry_edit_cb } , { "Reload", (Fl_Callback *)geometry_reload_cb } , { NULL } }; - Context_Item menu_geometry_elementary[] = - { { "0Geometry Elementary", NULL } , + Context_Item menu_geometry_elementary[] = { + { "0Geometry Elementary", NULL } , { "Add", (Fl_Callback *)geometry_elementary_add_cb } , { "Translate", (Fl_Callback *)geometry_elementary_translate_cb } , { "Rotate", (Fl_Callback *)geometry_elementary_rotate_cb } , @@ -168,8 +168,8 @@ Context_Item menu_geometry[] = { "Delete", (Fl_Callback *)geometry_elementary_delete_cb } , { NULL } }; - Context_Item menu_geometry_elementary_add[] = - { { "0Geometry Elementary Add", NULL } , + Context_Item menu_geometry_elementary_add[] = { + { "0Geometry Elementary Add", NULL } , { "New", (Fl_Callback *)geometry_elementary_add_new_cb } , { "Translate", (Fl_Callback *)geometry_elementary_add_translate_cb } , { "Rotate", (Fl_Callback *)geometry_elementary_add_rotate_cb } , @@ -177,8 +177,8 @@ Context_Item menu_geometry[] = { "Symmetry", (Fl_Callback *)geometry_elementary_add_symmetry_cb } , { NULL } }; - Context_Item menu_geometry_elementary_add_new[] = - { { "0Geometry Elementary Add New", NULL } , + Context_Item menu_geometry_elementary_add_new[] = { + { "0Geometry Elementary Add New", NULL } , { "Parameter", (Fl_Callback *)geometry_elementary_add_new_parameter_cb } , { "Point", (Fl_Callback *)geometry_elementary_add_new_point_cb } , { "Line", (Fl_Callback *)geometry_elementary_add_new_line_cb } , @@ -191,96 +191,96 @@ Context_Item menu_geometry[] = { "Volume", (Fl_Callback *)geometry_elementary_add_new_volume_cb } , { NULL } }; - Context_Item menu_geometry_elementary_add_translate[] = - { { "0Geometry Elementary Add Translate", NULL } , + Context_Item menu_geometry_elementary_add_translate[] = { + { "0Geometry Elementary Add Translate", NULL } , { "Point", (Fl_Callback *)geometry_elementary_add_translate_point_cb } , { "Curve", (Fl_Callback *)geometry_elementary_add_translate_curve_cb } , { "Surface", (Fl_Callback *)geometry_elementary_add_translate_surface_cb } , { NULL } }; - Context_Item menu_geometry_elementary_add_rotate[] = - { { "0Geometry Elementary Add Rotate", NULL } , + Context_Item menu_geometry_elementary_add_rotate[] = { + { "0Geometry Elementary Add Rotate", NULL } , { "Point", (Fl_Callback *)geometry_elementary_add_rotate_point_cb } , { "Curve", (Fl_Callback *)geometry_elementary_add_rotate_curve_cb } , { "Surface", (Fl_Callback *)geometry_elementary_add_rotate_surface_cb } , { NULL } }; - Context_Item menu_geometry_elementary_add_scale[] = - { { "0Geometry Elementary Add Scale", NULL } , + Context_Item menu_geometry_elementary_add_scale[] = { + { "0Geometry Elementary Add Scale", NULL } , { "Point", (Fl_Callback *)geometry_elementary_add_scale_point_cb } , { "Curve", (Fl_Callback *)geometry_elementary_add_scale_curve_cb } , { "Surface", (Fl_Callback *)geometry_elementary_add_scale_surface_cb } , { NULL } }; - Context_Item menu_geometry_elementary_add_symmetry[] = - { { "0Geometry Elementary Add Symmetry", NULL } , + Context_Item menu_geometry_elementary_add_symmetry[] = { + { "0Geometry Elementary Add Symmetry", NULL } , { "Point", (Fl_Callback *)geometry_elementary_add_symmetry_point_cb } , { "Curve", (Fl_Callback *)geometry_elementary_add_symmetry_curve_cb } , { "Surface", (Fl_Callback *)geometry_elementary_add_symmetry_surface_cb } , { NULL } }; - Context_Item menu_geometry_elementary_translate[] = - { { "0Geometry Elementary Translate", NULL } , + Context_Item menu_geometry_elementary_translate[] = { + { "0Geometry Elementary Translate", NULL } , { "Point", (Fl_Callback *)geometry_elementary_translate_point_cb } , { "Curve", (Fl_Callback *)geometry_elementary_translate_curve_cb } , { "Surface", (Fl_Callback *)geometry_elementary_translate_surface_cb } , { NULL } }; - Context_Item menu_geometry_elementary_rotate[] = - { { "0Geometry Elementary Rotate", NULL } , + Context_Item menu_geometry_elementary_rotate[] = { + { "0Geometry Elementary Rotate", NULL } , { "Point", (Fl_Callback *)geometry_elementary_rotate_point_cb } , { "Curve", (Fl_Callback *)geometry_elementary_rotate_curve_cb } , { "Surface", (Fl_Callback *)geometry_elementary_rotate_surface_cb } , { NULL } }; - Context_Item menu_geometry_elementary_scale[] = - { { "0Geometry Elementary Scale", NULL } , + Context_Item menu_geometry_elementary_scale[] = { + { "0Geometry Elementary Scale", NULL } , { "Point", (Fl_Callback *)geometry_elementary_scale_point_cb } , { "Curve", (Fl_Callback *)geometry_elementary_scale_curve_cb } , { "Surface", (Fl_Callback *)geometry_elementary_scale_surface_cb } , { NULL } }; - Context_Item menu_geometry_elementary_symmetry[] = - { { "0Geometry Elementary Symmetry", NULL } , + Context_Item menu_geometry_elementary_symmetry[] = { + { "0Geometry Elementary Symmetry", NULL } , { "Point", (Fl_Callback *)geometry_elementary_symmetry_point_cb } , { "Curve", (Fl_Callback *)geometry_elementary_symmetry_curve_cb } , { "Surface", (Fl_Callback *)geometry_elementary_symmetry_surface_cb } , { NULL } }; - Context_Item menu_geometry_elementary_extrude[] = - { { "0Geometry Elementary Extrude", NULL } , + Context_Item menu_geometry_elementary_extrude[] = { + { "0Geometry Elementary Extrude", NULL } , { "Translate", (Fl_Callback *)geometry_elementary_extrude_translate_cb } , { "Rotate", (Fl_Callback *)geometry_elementary_extrude_rotate_cb } , { NULL } }; - Context_Item menu_geometry_elementary_extrude_translate[] = - { { "0Geometry Elementary Extrude Translate", NULL } , + Context_Item menu_geometry_elementary_extrude_translate[] = { + { "0Geometry Elementary Extrude Translate", NULL } , { "Point", (Fl_Callback *)geometry_elementary_extrude_translate_point_cb } , { "Curve", (Fl_Callback *)geometry_elementary_extrude_translate_curve_cb } , { "Surface", (Fl_Callback *)geometry_elementary_extrude_translate_surface_cb } , { NULL } }; - Context_Item menu_geometry_elementary_extrude_rotate[] = - { { "0Geometry Elementary Extrude Rotate", NULL } , + Context_Item menu_geometry_elementary_extrude_rotate[] = { + { "0Geometry Elementary Extrude Rotate", NULL } , { "Point", (Fl_Callback *)geometry_elementary_extrude_rotate_point_cb } , { "Curve", (Fl_Callback *)geometry_elementary_extrude_rotate_curve_cb } , { "Surface", (Fl_Callback *)geometry_elementary_extrude_rotate_surface_cb } , { NULL } }; - Context_Item menu_geometry_elementary_delete[] = - { { "0Geometry Elementary Delete", NULL } , + Context_Item menu_geometry_elementary_delete[] = { + { "0Geometry Elementary Delete", NULL } , { "Point", (Fl_Callback *)geometry_elementary_delete_point_cb } , { "Curve", (Fl_Callback *)geometry_elementary_delete_curve_cb } , { "Surface", (Fl_Callback *)geometry_elementary_delete_surface_cb } , { NULL } }; - Context_Item menu_geometry_physical[] = - { { "0Geometry Physical", NULL } , + Context_Item menu_geometry_physical[] = { + { "0Geometry Physical", NULL } , { "Add", (Fl_Callback *)geometry_physical_add_cb } , { NULL } }; - Context_Item menu_geometry_physical_add[] = - { { "0Geometry Physical Add", NULL } , + Context_Item menu_geometry_physical_add[] = { + { "0Geometry Physical Add", NULL } , { "Point", (Fl_Callback *)geometry_physical_add_point_cb } , { "Curve", (Fl_Callback *)geometry_physical_add_curve_cb } , { "Surface", (Fl_Callback *)geometry_physical_add_surface_cb } , @@ -288,8 +288,8 @@ Context_Item menu_geometry[] = { NULL } }; -Context_Item menu_mesh[] = -{ { "1Mesh", NULL } , +Context_Item menu_mesh[] = { + { "1Mesh", NULL } , { "Define", (Fl_Callback *)mesh_define_cb } , { "1D", (Fl_Callback *)mesh_1d_cb } , { "2D", (Fl_Callback *)mesh_2d_cb } , @@ -299,15 +299,15 @@ Context_Item menu_mesh[] = //{ "Save All", (Fl_Callback *)mesh_save_all_cb } , { NULL } }; - Context_Item menu_mesh_define[] = - { { "1Mesh Define", NULL } , + Context_Item menu_mesh_define[] = { + { "1Mesh Define", NULL } , { "Length", (Fl_Callback *)mesh_define_length_cb } , { "Recombine", (Fl_Callback *)mesh_define_recombine_cb } , { "Transfinite", (Fl_Callback *)mesh_define_transfinite_cb } , { NULL } }; - Context_Item menu_mesh_define_transfinite[] = - { { "1Mesh Define Transfinite", NULL } , + Context_Item menu_mesh_define_transfinite[] = { + { "1Mesh Define Transfinite", NULL } , { "Line", (Fl_Callback *)mesh_define_transfinite_line_cb } , { "Surface", (Fl_Callback *)mesh_define_transfinite_surface_cb } , { "Volume", (Fl_Callback *)mesh_define_transfinite_volume_cb } , @@ -315,18 +315,20 @@ Context_Item menu_mesh[] = }; // should create MAXSOLVERS items... -Context_Item menu_solver[] = -{ { "2Solver", NULL } , +Context_Item menu_solver[] = { + { "2Solver", NULL } , { "Solver 0", (Fl_Callback *)solver_cb , (void*)0} , { "Solver 1", (Fl_Callback *)solver_cb , (void*)1} , { "Solver 2", (Fl_Callback *)solver_cb , (void*)2} , { "Solver 3", (Fl_Callback *)solver_cb , (void*)3} , { "Solver 4", (Fl_Callback *)solver_cb , (void*)4} , - { NULL } }; + { NULL } +}; -Context_Item menu_post[] = -{ { "3Post-processing", NULL } , - { NULL } }; +Context_Item menu_post[] = { + { "3Post-processing", NULL } , + { NULL } +}; // some other reusable menus @@ -346,240 +348,261 @@ static Fl_Menu_Item menu_line_display[] = { // Definition of global shortcuts -int GUI::global_shortcuts(int event){ +int GUI::global_shortcuts(int event) +{ int i, j; // we only handle shortcuts here - if(event != FL_SHORTCUT) return 0 ; - + if(event != FL_SHORTCUT) + return 0; - if(Fl::test_shortcut(FL_SHIFT+FL_Escape) || - Fl::test_shortcut(FL_CTRL+FL_Escape) || - Fl::test_shortcut(FL_ALT+FL_Escape)){ + if(Fl::test_shortcut(FL_SHIFT + FL_Escape) || + Fl::test_shortcut(FL_CTRL + FL_Escape) || + Fl::test_shortcut(FL_ALT + FL_Escape)) { return 1; } - if(Fl::test_shortcut('0') || Fl::test_shortcut(FL_Escape)){ - geometry_reload_cb(0,0); - mod_geometry_cb(0,0); + if(Fl::test_shortcut('0') || Fl::test_shortcut(FL_Escape)) { + geometry_reload_cb(0, 0); + mod_geometry_cb(0, 0); return 1; } #if (FL_MAJOR_VERSION == 2) - else if(Fl::test_shortcut('1') || Fl::test_shortcut(FL_F(1))){ + else if(Fl::test_shortcut('1') || Fl::test_shortcut(FL_F(1))) { #else - else if(Fl::test_shortcut('1') || Fl::test_shortcut(FL_F+1)){ + else if(Fl::test_shortcut('1') || Fl::test_shortcut(FL_F + 1)) { #endif - mesh_1d_cb(0,0); - mod_mesh_cb(0,0); + mesh_1d_cb(0, 0); + mod_mesh_cb(0, 0); return 1; } #if (FL_MAJOR_VERSION == 2) - else if(Fl::test_shortcut('1') || Fl::test_shortcut(FL_F(2))){ + else if(Fl::test_shortcut('1') || Fl::test_shortcut(FL_F(2))) { #else - else if(Fl::test_shortcut('2') || Fl::test_shortcut(FL_F+2)){ + else if(Fl::test_shortcut('2') || Fl::test_shortcut(FL_F + 2)) { #endif - mesh_2d_cb(0,0); - mod_mesh_cb(0,0); + mesh_2d_cb(0, 0); + mod_mesh_cb(0, 0); return 1; } #if (FL_MAJOR_VERSION == 2) - else if(Fl::test_shortcut('1') || Fl::test_shortcut(FL_F(3))){ + else if(Fl::test_shortcut('1') || Fl::test_shortcut(FL_F(3))) { #else - else if(Fl::test_shortcut('3') || Fl::test_shortcut(FL_F+3)){ + else if(Fl::test_shortcut('3') || Fl::test_shortcut(FL_F + 3)) { #endif - mesh_3d_cb(0,0); - mod_mesh_cb(0,0); + mesh_3d_cb(0, 0); + mod_mesh_cb(0, 0); return 1; } - else if(Fl::test_shortcut('g')){ - mod_geometry_cb(0,0); + else if(Fl::test_shortcut('g')) { + mod_geometry_cb(0, 0); return 1; } - else if(Fl::test_shortcut('m')){ - mod_mesh_cb(0,0); + else if(Fl::test_shortcut('m')) { + mod_mesh_cb(0, 0); return 1; } - else if(Fl::test_shortcut('s')){ - mod_solver_cb(0,0); + else if(Fl::test_shortcut('s')) { + mod_solver_cb(0, 0); return 1; } - else if(Fl::test_shortcut('p')){ - mod_post_cb(0,0); + else if(Fl::test_shortcut('p')) { + mod_post_cb(0, 0); return 1; } - else if(Fl::test_shortcut('<')){ - mod_back_cb(0,0); + else if(Fl::test_shortcut('<')) { + mod_back_cb(0, 0); return 1; } - else if(Fl::test_shortcut('>')){ - mod_forward_cb(0,0); + else if(Fl::test_shortcut('>')) { + mod_forward_cb(0, 0); return 1; } - else if(Fl::test_shortcut('e')){ + else if(Fl::test_shortcut('e')) { end_selection = 1; - return 0; // trick: do as if we didn't use it + return 0; // trick: do as if we didn't use it } - else if(Fl::test_shortcut('q')){ + else if(Fl::test_shortcut('q')) { quit_selection = 1; - return 0; // trick: do as if we didn't use it + return 0; // trick: do as if we didn't use it } - else if(Fl::test_shortcut(FL_SHIFT+'n')){ - general_options_cb(0,0); + else if(Fl::test_shortcut(FL_SHIFT + 'n')) { + general_options_cb(0, 0); return 1; } - else if(Fl::test_shortcut(FL_SHIFT+'g')){ - geometry_options_cb(0,0); + else if(Fl::test_shortcut(FL_SHIFT + 'g')) { + geometry_options_cb(0, 0); return 1; } - else if(Fl::test_shortcut(FL_SHIFT+'m')){ - mesh_options_cb(0,0); + else if(Fl::test_shortcut(FL_SHIFT + 'm')) { + mesh_options_cb(0, 0); return 1; } - else if(Fl::test_shortcut(FL_SHIFT+'s')){ - solver_options_cb(0,0); + else if(Fl::test_shortcut(FL_SHIFT + 's')) { + solver_options_cb(0, 0); return 1; } - else if(Fl::test_shortcut(FL_SHIFT+'p')){ - post_options_cb(0,0); + else if(Fl::test_shortcut(FL_SHIFT + 'p')) { + post_options_cb(0, 0); return 1; } - else if(Fl::test_shortcut(FL_CTRL+FL_SHIFT+'d')){ - opt_post_anim_delay(0,GMSH_SET|GMSH_GUI,opt_post_anim_delay(0,GMSH_GET,0) + 0.01); + else if(Fl::test_shortcut(FL_CTRL + FL_SHIFT + 'd')) { + opt_post_anim_delay(0, GMSH_SET | GMSH_GUI, + opt_post_anim_delay(0, GMSH_GET, 0) + 0.01); return 1; } - else if(Fl::test_shortcut(FL_SHIFT+'d')){ - opt_post_anim_delay(0,GMSH_SET|GMSH_GUI,opt_post_anim_delay(0,GMSH_GET,0) - 0.01); + else if(Fl::test_shortcut(FL_SHIFT + 'd')) { + opt_post_anim_delay(0, GMSH_SET | GMSH_GUI, + opt_post_anim_delay(0, GMSH_GET, 0) - 0.01); return 1; } - else if(Fl::test_shortcut(FL_CTRL+'z')){ - g_window->iconize() ; + else if(Fl::test_shortcut(FL_CTRL + 'z')) { + g_window->iconize(); return 1; } - else if(Fl::test_shortcut(FL_ALT+'f')){ - opt_general_fast_redraw(0,GMSH_SET|GMSH_GUI,!opt_general_fast_redraw(0,GMSH_GET,0)); + else if(Fl::test_shortcut(FL_ALT + 'f')) { + opt_general_fast_redraw(0, GMSH_SET | GMSH_GUI, + !opt_general_fast_redraw(0, GMSH_GET, 0)); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+'b')){ - opt_post_scales(0,GMSH_SET|GMSH_GUI,!opt_post_scales(0,GMSH_GET,0)); + else if(Fl::test_shortcut(FL_ALT + 'b')) { + opt_post_scales(0, GMSH_SET | GMSH_GUI, !opt_post_scales(0, GMSH_GET, 0)); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+'o')){ - opt_general_orthographic(0,GMSH_SET|GMSH_GUI,!opt_general_orthographic(0,GMSH_GET,0)); + else if(Fl::test_shortcut(FL_ALT + 'o')) { + opt_general_orthographic(0, GMSH_SET | GMSH_GUI, + !opt_general_orthographic(0, GMSH_GET, 0)); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+'c')){ - opt_general_color_scheme(0,GMSH_SET|GMSH_GUI,opt_general_color_scheme(0,GMSH_GET,0)+1); - opt_geometry_color_scheme(0,GMSH_SET|GMSH_GUI,opt_geometry_color_scheme(0,GMSH_GET,0)+1); - opt_mesh_color_scheme(0,GMSH_SET|GMSH_GUI,opt_mesh_color_scheme(0,GMSH_GET,0)+1); + else if(Fl::test_shortcut(FL_ALT + 'c')) { + opt_general_color_scheme(0, GMSH_SET | GMSH_GUI, + opt_general_color_scheme(0, GMSH_GET, 0) + 1); + opt_geometry_color_scheme(0, GMSH_SET | GMSH_GUI, + opt_geometry_color_scheme(0, GMSH_GET, 0) + 1); + opt_mesh_color_scheme(0, GMSH_SET | GMSH_GUI, + opt_mesh_color_scheme(0, GMSH_GET, 0) + 1); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+'d')){ - opt_mesh_aspect(0,GMSH_SET|GMSH_GUI,opt_mesh_aspect(0,GMSH_GET,0)+1); + else if(Fl::test_shortcut(FL_ALT + 'd')) { + opt_mesh_aspect(0, GMSH_SET | GMSH_GUI, + opt_mesh_aspect(0, GMSH_GET, 0) + 1); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+'x')){ - status_xyz1p_cb(0,(void*)0); + else if(Fl::test_shortcut(FL_ALT + 'x')) { + status_xyz1p_cb(0, (void *)0); return 1; } - else if(Fl::test_shortcut(FL_ALT+'y')){ - status_xyz1p_cb(0,(void*)1); + else if(Fl::test_shortcut(FL_ALT + 'y')) { + status_xyz1p_cb(0, (void *)1); return 1; } - else if(Fl::test_shortcut(FL_ALT+'z')){ - status_xyz1p_cb(0,(void*)2); + else if(Fl::test_shortcut(FL_ALT + 'z')) { + status_xyz1p_cb(0, (void *)2); return 1; } - else if(Fl::test_shortcut(FL_ALT+FL_SHIFT+'a')){ - opt_general_axes(0,GMSH_SET|GMSH_GUI,!opt_general_axes(0,GMSH_GET,0)); + else if(Fl::test_shortcut(FL_ALT + FL_SHIFT + 'a')) { + opt_general_axes(0, GMSH_SET | GMSH_GUI, + !opt_general_axes(0, GMSH_GET, 0)); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+'a')){ - opt_general_small_axes(0,GMSH_SET|GMSH_GUI,!opt_general_small_axes(0,GMSH_GET,0)); + else if(Fl::test_shortcut(FL_ALT + 'a')) { + opt_general_small_axes(0, GMSH_SET | GMSH_GUI, + !opt_general_small_axes(0, GMSH_GET, 0)); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+'p')){ - opt_geometry_points(0,GMSH_SET|GMSH_GUI,!opt_geometry_points(0,GMSH_GET,0)); + else if(Fl::test_shortcut(FL_ALT + 'p')) { + opt_geometry_points(0, GMSH_SET | GMSH_GUI, + !opt_geometry_points(0, GMSH_GET, 0)); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+'l')){ - opt_geometry_lines(0,GMSH_SET|GMSH_GUI,!opt_geometry_lines(0,GMSH_GET,0)); + else if(Fl::test_shortcut(FL_ALT + 'l')) { + opt_geometry_lines(0, GMSH_SET | GMSH_GUI, + !opt_geometry_lines(0, GMSH_GET, 0)); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+'s')){ - opt_geometry_surfaces(0,GMSH_SET|GMSH_GUI,!opt_geometry_surfaces(0,GMSH_GET,0)); + else if(Fl::test_shortcut(FL_ALT + 's')) { + opt_geometry_surfaces(0, GMSH_SET | GMSH_GUI, + !opt_geometry_surfaces(0, GMSH_GET, 0)); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+'v')){ - opt_geometry_volumes(0,GMSH_SET|GMSH_GUI,!opt_geometry_volumes(0,GMSH_GET,0)); + else if(Fl::test_shortcut(FL_ALT + 'v')) { + opt_geometry_volumes(0, GMSH_SET | GMSH_GUI, + !opt_geometry_volumes(0, GMSH_GET, 0)); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+FL_SHIFT+'p')){ - opt_mesh_points(0,GMSH_SET|GMSH_GUI,!opt_mesh_points(0,GMSH_GET,0)); + else if(Fl::test_shortcut(FL_ALT + FL_SHIFT + 'p')) { + opt_mesh_points(0, GMSH_SET | GMSH_GUI, !opt_mesh_points(0, GMSH_GET, 0)); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+FL_SHIFT+'l')){ - opt_mesh_lines(0,GMSH_SET|GMSH_GUI,!opt_mesh_lines(0,GMSH_GET,0)); + else if(Fl::test_shortcut(FL_ALT + FL_SHIFT + 'l')) { + opt_mesh_lines(0, GMSH_SET | GMSH_GUI, !opt_mesh_lines(0, GMSH_GET, 0)); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+FL_SHIFT+'s')){ - opt_mesh_surfaces(0,GMSH_SET|GMSH_GUI,!opt_mesh_surfaces(0,GMSH_GET,0)); + else if(Fl::test_shortcut(FL_ALT + FL_SHIFT + 's')) { + opt_mesh_surfaces(0, GMSH_SET | GMSH_GUI, + !opt_mesh_surfaces(0, GMSH_GET, 0)); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+FL_SHIFT+'v')){ - opt_mesh_volumes(0,GMSH_SET|GMSH_GUI,!opt_mesh_volumes(0,GMSH_GET,0)); + else if(Fl::test_shortcut(FL_ALT + FL_SHIFT + 'v')) { + opt_mesh_volumes(0, GMSH_SET | GMSH_GUI, + !opt_mesh_volumes(0, GMSH_GET, 0)); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+'m')){ - opt_mesh_points(0,GMSH_SET|GMSH_GUI,!opt_mesh_points(0,GMSH_GET,0)); - opt_mesh_lines(0,GMSH_SET|GMSH_GUI,!opt_mesh_lines(0,GMSH_GET,0)); - opt_mesh_surfaces(0,GMSH_SET|GMSH_GUI,!opt_mesh_surfaces(0,GMSH_GET,0)); - opt_mesh_volumes(0,GMSH_SET|GMSH_GUI,!opt_mesh_volumes(0,GMSH_GET,0)); + else if(Fl::test_shortcut(FL_ALT + 'm')) { + opt_mesh_points(0, GMSH_SET | GMSH_GUI, !opt_mesh_points(0, GMSH_GET, 0)); + opt_mesh_lines(0, GMSH_SET | GMSH_GUI, !opt_mesh_lines(0, GMSH_GET, 0)); + opt_mesh_surfaces(0, GMSH_SET | GMSH_GUI, + !opt_mesh_surfaces(0, GMSH_GET, 0)); + opt_mesh_volumes(0, GMSH_SET | GMSH_GUI, + !opt_mesh_volumes(0, GMSH_GET, 0)); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+'t')){ - for(i=0 ; i<List_Nbr(CTX.post.list) ; i++){ - if(opt_view_visible(i,GMSH_GET,0)){ - j = (int)opt_view_intervals_type(i, GMSH_GET, 0); - opt_view_intervals_type(i, GMSH_SET|GMSH_GUI, - (j == DRAW_POST_ISO) ? DRAW_POST_DISCRETE : - (j == DRAW_POST_DISCRETE) ? DRAW_POST_CONTINUOUS : - DRAW_POST_ISO); + else if(Fl::test_shortcut(FL_ALT + 't')) { + for(i = 0; i < List_Nbr(CTX.post.list); i++) { + if(opt_view_visible(i, GMSH_GET, 0)) { + j = (int)opt_view_intervals_type(i, GMSH_GET, 0); + opt_view_intervals_type(i, GMSH_SET | GMSH_GUI, + (j == DRAW_POST_ISO) ? DRAW_POST_DISCRETE : + (j == + DRAW_POST_DISCRETE) ? DRAW_POST_CONTINUOUS : + DRAW_POST_ISO); } } redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+'n')){ - for(i=0 ; i<List_Nbr(CTX.post.list) ; i++) - if(opt_view_visible(i,GMSH_GET,0)) - opt_view_draw_strings(i, GMSH_SET|GMSH_GUI,!opt_view_draw_strings(i,GMSH_GET,0)); + else if(Fl::test_shortcut(FL_ALT + 'n')) { + for(i = 0; i < List_Nbr(CTX.post.list); i++) + if(opt_view_visible(i, GMSH_GET, 0)) + opt_view_draw_strings(i, GMSH_SET | GMSH_GUI, + !opt_view_draw_strings(i, GMSH_GET, 0)); redraw_opengl(); return 1; } - else if(Fl::test_shortcut(FL_ALT+'h')){ + else if(Fl::test_shortcut(FL_ALT + 'h')) { static int show = 0; - for(i=0 ; i<List_Nbr(CTX.post.list) ; i++) - opt_view_visible(i, GMSH_SET|GMSH_GUI, show); + for(i = 0; i < List_Nbr(CTX.post.list); i++) + opt_view_visible(i, GMSH_SET | GMSH_GUI, show); redraw_opengl(); show = !show; return 1; } - else if(arrow_shortcuts()){ + else if(arrow_shortcuts()) { return 1; } @@ -590,21 +613,22 @@ int GUI::global_shortcuts(int event){ // since it is used elsewhere (where we want to override widget // navigation: necessary since FLTK>=1.1) -int GUI::arrow_shortcuts(){ - if(Fl::test_shortcut(FL_Left)){ - ManualPlay(1,-1); +int GUI::arrow_shortcuts() +{ + if(Fl::test_shortcut(FL_Left)) { + ManualPlay(1, -1); return 1; } - else if(Fl::test_shortcut(FL_Right)){ - ManualPlay(1,1); + else if(Fl::test_shortcut(FL_Right)) { + ManualPlay(1, 1); return 1; } - else if(Fl::test_shortcut(FL_Up)){ - ManualPlay(0,-1); + else if(Fl::test_shortcut(FL_Up)) { + ManualPlay(0, -1); return 1; } - else if(Fl::test_shortcut(FL_Down)){ - ManualPlay(0,1); + else if(Fl::test_shortcut(FL_Down)) { + ManualPlay(0, 1); return 1; } return 0; @@ -613,7 +637,8 @@ int GUI::arrow_shortcuts(){ // The GUI constructor -GUI::GUI(int argc, char **argv) { +GUI::GUI(int argc, char **argv) +{ int i; // initialize static windows @@ -628,7 +653,8 @@ GUI::GUI(int argc, char **argv) { context_mesh_window = NULL; // set X display - if(strlen(CTX.display)) Fl::display(CTX.display); + if(strlen(CTX.display)) + Fl::display(CTX.display); // add global shortcuts Fl::add_handler(SetGlobalShortcut); @@ -645,7 +671,8 @@ GUI::GUI(int argc, char **argv) { // handle themes and tooltip font size #if !((FL_MAJOR_VERSION == 1 || FL_MAJOR_VERSION == 2) && (FL_MINOR_VERSION == 0)) - if(strlen(CTX.theme)) Fl::scheme(CTX.theme); + if(strlen(CTX.theme)) + Fl::scheme(CTX.theme); Fl_Tooltip::size(fontsize); #endif @@ -658,16 +685,18 @@ GUI::GUI(int argc, char **argv) { #if defined(WIN32) m_window->icon((char *)LoadImage(fl_display, MAKEINTRESOURCE(IDI_ICON), - IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR)); + IMAGE_ICON, 16, 16, LR_DEFAULTCOLOR)); #elif defined(__APPLE__) // Mac icons are defined in the resource fork or in the bundle #else fl_open_display(); Pixmap p1 = XCreateBitmapFromData(fl_display, DefaultRootWindow(fl_display), - gmsh32x32_bits, gmsh32x32_width, gmsh32x32_height); + gmsh32x32_bits, gmsh32x32_width, + gmsh32x32_height); Pixmap p2 = XCreateBitmapFromData(fl_display, DefaultRootWindow(fl_display), - gmsh32x32_bits, gmsh32x32_width, gmsh32x32_height); - m_window->icon((char *)p1); + gmsh32x32_bits, gmsh32x32_width, + gmsh32x32_height); + m_window->icon((char *)p1); g_window->icon((char *)p2); #endif @@ -679,7 +708,7 @@ GUI::GUI(int argc, char **argv) { create_statistics_window(); create_visibility_window(); create_about_window(); - for(i=0; i<MAXSOLVERS; i++){ + for(i = 0; i < MAXSOLVERS; i++) { solver[i].window = NULL; create_solver_window(i); } @@ -691,87 +720,93 @@ GUI::GUI(int argc, char **argv) { // Run the GUI until no window is left -void GUI::run(){ +void GUI::run() +{ Fl::run(); } // Check (now) if any pending events and run them -void GUI::check(){ +void GUI::check() +{ Fl::check(); } // Wait for any events and run them -void GUI::wait(){ +void GUI::wait() +{ Fl::wait(); } // Create the menu window -void GUI::add_post_plugins (Fl_Menu_Button *button , int iView){ - char name[256],menuname[256]; +void GUI::add_post_plugins(Fl_Menu_Button * button, int iView) +{ + char name[256], menuname[256]; for(GMSH_PluginManager::iter it = GMSH_PluginManager::Instance()->begin(); - it != GMSH_PluginManager::Instance()->end(); - ++it){ + it != GMSH_PluginManager::Instance()->end(); ++it) { GMSH_Plugin *p = (*it).second; - if(p->getType() == GMSH_Plugin::GMSH_POST_PLUGIN){ + if(p->getType() == GMSH_Plugin::GMSH_POST_PLUGIN) { p->getName(name); - std::pair<int,GMSH_Plugin*> *pair = new std::pair<int,GMSH_Plugin*>(iView,p); - sprintf(menuname,"Plugins/%s...",name); - button->add(menuname, 0,(Fl_Callback *)view_options_plugin_cb, (void*)(pair), 0); + std::pair < int, GMSH_Plugin * >*pair = + new std::pair < int, GMSH_Plugin * >(iView, p); + sprintf(menuname, "Plugins/%s...", name); + button->add(menuname, 0, (Fl_Callback *) view_options_plugin_cb, + (void *)(pair), 0); p->dialogBox = 0; } } } -void GUI::create_menu_window(int argc, char **argv){ +void GUI::create_menu_window(int argc, char **argv) +{ int i, y; - - if(m_window){ + + if(m_window) { m_window->show(1, argv); return; } - int width = 13*fontsize-fontsize/2-2 ; + int width = 13 * fontsize - fontsize / 2 - 2; - // this is the initial height: no dynamic button is shown! + // this is the initial height: no dynamic button is shown! #if defined(__APPLE__) && defined(APPLE_USE_SYS_MENU) - MH = BH+6 ; // the menu bar is not in the application! + MH = BH + 6; // the menu bar is not in the application! #else - MH = BH + BH+6 ; + MH = BH + BH + 6; #endif - m_window = new Fl_Window(width,MH,"Gmsh"); + m_window = new Fl_Window(width, MH, "Gmsh"); m_window->box(WINDOW_BOX); m_window->callback(file_quit_cb); - + #if defined(__APPLE__) && defined(APPLE_USE_SYS_MENU) - m_menu_bar = new Fl_Sys_Menu_Bar(0,0,width,BH); + m_menu_bar = new Fl_Sys_Menu_Bar(0, 0, width, BH); m_menu_bar->menu(m_menubar_table); - m_menu_bar->global(); - Fl_Box *o = new Fl_Box(0,0,width,BH+6); + m_menu_bar->global (); + Fl_Box *o = new Fl_Box(0, 0, width, BH + 6); o->box(FL_UP_BOX); y = 3; #else - m_menu_bar = new Fl_Menu_Bar(0,0,width,BH); + m_menu_bar = new Fl_Menu_Bar(0, 0, width, BH); m_menu_bar->menu(m_menubar_table); m_menu_bar->box(FL_UP_BOX); - m_menu_bar->global(); - Fl_Box *o = new Fl_Box(0,BH,width,BH+6); + m_menu_bar->global (); + Fl_Box *o = new Fl_Box(0, BH, width, BH + 6); o->box(FL_UP_BOX); y = BH + 3; #endif - m_navig_butt[0] = new Fl_Button(1,y,18,BH/2,"@#<"); + m_navig_butt[0] = new Fl_Button(1, y, 18, BH / 2, "@#<"); m_navig_butt[0]->labeltype(FL_SYMBOL_LABEL); m_navig_butt[0]->labelsize(11); m_navig_butt[0]->box(FL_FLAT_BOX); m_navig_butt[0]->selection_color(FL_WHITE); m_navig_butt[0]->callback(mod_back_cb); - - m_navig_butt[1] = new Fl_Button(1,y+BH/2,18,BH/2,"@#>"); + + m_navig_butt[1] = new Fl_Button(1, y + BH / 2, 18, BH / 2, "@#>"); m_navig_butt[1]->labeltype(FL_SYMBOL_LABEL); m_navig_butt[1]->labelsize(11); m_navig_butt[1]->box(FL_FLAT_BOX); @@ -782,23 +817,26 @@ void GUI::create_menu_window(int argc, char **argv){ m_navig_butt[0]->tooltip("Go back in menu history"); m_navig_butt[1]->tooltip("Go forward in menu history"); #endif - - m_module_butt = new Fl_Choice(19,y,width-24,BH); + + m_module_butt = new Fl_Choice(19, y, width - 24, BH); m_module_butt->menu(m_module_table); m_module_butt->box(FL_THIN_DOWN_BOX); - - y = MH ; - - for(i=0; i<NB_BUTT_MAX; i++){ - m_push_butt[i] = new Fl_Button(0,y+i*BH,width,BH); + + y = MH; + + for(i = 0; i < NB_BUTT_MAX; i++) { + m_push_butt[i] = new Fl_Button(0, y + i * BH, width, BH); m_push_butt[i]->hide(); - m_toggle_butt[i] = new Fl_Light_Button(0,y+i*BH,width-(fontsize+4),BH); - m_toggle_butt[i]->callback(view_toggle_cb, (void*)i); - m_toggle_butt[i]->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_CLIP); + m_toggle_butt[i] = + new Fl_Light_Button(0, y + i * BH, width - (fontsize + 4), BH); + m_toggle_butt[i]->callback(view_toggle_cb, (void *)i); + m_toggle_butt[i]->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP); m_toggle_butt[i]->hide(); - m_toggle2_butt[i]= new Fl_Button(width-(fontsize+4),y+i*BH,(fontsize+4),BH,"@#>"); + m_toggle2_butt[i] = + new Fl_Button(width - (fontsize + 4), y + i * BH, (fontsize + 4), BH, + "@#>"); m_toggle2_butt[i]->labeltype(FL_SYMBOL_LABEL); m_toggle2_butt[i]->labelsize(11); m_toggle2_butt[i]->align(FL_ALIGN_CENTER); @@ -807,120 +845,134 @@ void GUI::create_menu_window(int argc, char **argv){ m_toggle2_butt[i]->tooltip("Show view option menu"); #endif - m_popup_butt[i] = new Fl_Menu_Button(width-(fontsize+4),y+i*BH,(fontsize+4),BH); + m_popup_butt[i] = + new Fl_Menu_Button(width - (fontsize + 4), y + i * BH, (fontsize + 4), + BH); m_popup_butt[i]->type(Fl_Menu_Button::POPUP123); - m_popup2_butt[i] = new Fl_Menu_Button(0,y+i*BH,width-(fontsize+4),BH); + m_popup2_butt[i] = + new Fl_Menu_Button(0, y + i * BH, width - (fontsize + 4), BH); m_popup2_butt[i]->type(Fl_Menu_Button::POPUP3); - for(int j=0; j<2; j++){ + for(int j = 0; j < 2; j++) { Fl_Menu_Button *pop = j ? m_popup2_butt[i] : m_popup_butt[i]; - pop->add("Reload/View", 0, - (Fl_Callback *)view_reload_cb, (void*)i, 0); - pop->add("Reload/All views", 0, - (Fl_Callback *)view_reload_all_cb, (void*)i, 0); - pop->add("Reload/All visible views", 0, - (Fl_Callback *)view_reload_visible_cb, (void*)i, 0); - pop->add("Remove/View", FL_Delete, - (Fl_Callback *)view_remove_cb, (void*)i, 0); - pop->add("Remove/All views", 0, - (Fl_Callback *)view_remove_all_cb, (void*)i, 0); - pop->add("Remove/All visible views", 0, - (Fl_Callback *)view_remove_visible_cb, (void*)i, 0); - pop->add("Remove/All invisible views", 0, - (Fl_Callback *)view_remove_invisible_cb, (void*)i, 0); + pop->add("Reload/View", 0, + (Fl_Callback *) view_reload_cb, (void *)i, 0); + pop->add("Reload/All views", 0, + (Fl_Callback *) view_reload_all_cb, (void *)i, 0); + pop->add("Reload/All visible views", 0, + (Fl_Callback *) view_reload_visible_cb, (void *)i, 0); + pop->add("Remove/View", FL_Delete, + (Fl_Callback *) view_remove_cb, (void *)i, 0); + pop->add("Remove/All views", 0, + (Fl_Callback *) view_remove_all_cb, (void *)i, 0); + pop->add("Remove/All visible views", 0, + (Fl_Callback *) view_remove_visible_cb, (void *)i, 0); + pop->add("Remove/All invisible views", 0, + (Fl_Callback *) view_remove_invisible_cb, (void *)i, 0); pop->add("Duplicate/View without options", 0, - (Fl_Callback *)view_duplicate_cb, (void*)i, 0) ; + (Fl_Callback *) view_duplicate_cb, (void *)i, 0); pop->add("Duplicate/View with options", 0, - (Fl_Callback *)view_duplicate_with_options_cb, (void*)i, 0) ; + (Fl_Callback *) view_duplicate_with_options_cb, (void *)i, 0); pop->add("Combine/All views", 0, - (Fl_Callback *)view_merge_all_cb, (void*)i, 0) ; + (Fl_Callback *) view_merge_all_cb, (void *)i, 0); pop->add("Combine/All visible views", 0, - (Fl_Callback *)view_merge_visible_cb, (void*)i, 0) ; + (Fl_Callback *) view_merge_visible_cb, (void *)i, 0); pop->add("Save as/ASCII view...", 0, - (Fl_Callback *)view_save_ascii_cb, (void*)i, 0) ; + (Fl_Callback *) view_save_ascii_cb, (void *)i, 0); pop->add("Save as/Binary view...", 0, - (Fl_Callback *)view_save_binary_cb, (void*)i, 0) ; + (Fl_Callback *) view_save_binary_cb, (void *)i, 0); add_post_plugins(pop, i); pop->add("Apply as background mesh", 0, - (Fl_Callback *)view_applybgmesh_cb, (void*)i, FL_MENU_DIVIDER); - pop->add("Options...", 'o', - (Fl_Callback *)view_options_cb, (void*)i, 0); + (Fl_Callback *) view_applybgmesh_cb, (void *)i, + FL_MENU_DIVIDER); + pop->add("Options...", 'o', (Fl_Callback *) view_options_cb, (void *)i, + 0); pop->hide(); } } - m_window->position(CTX.position[0],CTX.position[1]); + m_window->position(CTX.position[0], CTX.position[1]); m_window->end(); - + } // Dynamically set the height of the menu window -void GUI::set_menu_size(int nb_butt){ - m_window->size(m_window->w(), MH + nb_butt*BH); +void GUI::set_menu_size(int nb_butt) +{ + m_window->size(m_window->w(), MH + nb_butt * BH); } // Dynamically set the context -void GUI::set_context(Context_Item *menu_asked, int flag){ - static int nb_back = 0, nb_forward = 0, init_context=0; +void GUI::set_context(Context_Item * menu_asked, int flag) +{ + static int nb_back = 0, nb_forward = 0, init_context = 0; static Context_Item *menu_history[NB_HISTORY_MAX]; Context_Item *menu; Post_View *v; int i; - - if(!init_context){ + + if(!init_context) { init_context = 1; - for(i=0 ; i<NB_HISTORY_MAX ; i++){ - menu_history[i] = NULL ; + for(i = 0; i < NB_HISTORY_MAX; i++) { + menu_history[i] = NULL; } } - - if(nb_back > NB_HISTORY_MAX-2) nb_back = 1; // we should do a circular list - - if(flag == -1){ - if(nb_back > 1){ + + if(nb_back > NB_HISTORY_MAX - 2) + nb_back = 1; // we should do a circular list + + if(flag == -1) { + if(nb_back > 1) { nb_back--; nb_forward++; - menu = menu_history[nb_back-1]; + menu = menu_history[nb_back - 1]; } - else return; + else + return; } - else if(flag == 1){ - if(nb_forward > 0){ + else if(flag == 1) { + if(nb_forward > 0) { nb_back++; nb_forward--; - menu = menu_history[nb_back-1]; + menu = menu_history[nb_back - 1]; } - else return; + else + return; } - else{ + else { menu = menu_asked; - if(!nb_back || menu_history[nb_back-1] != menu){ + if(!nb_back || menu_history[nb_back - 1] != menu) { menu_history[nb_back++] = menu; } nb_forward = 0; } - + int nb = 0; - - if(menu[0].label[0] == '0') m_module_butt->value(0); - else if(menu[0].label[0] == '1') m_module_butt->value(1); - else if(menu[0].label[0] == '2') m_module_butt->value(2); - else if(menu[0].label[0] == '3') m_module_butt->value(3); + + if(menu[0].label[0] == '0') + m_module_butt->value(0); + else if(menu[0].label[0] == '1') + m_module_butt->value(1); + else if(menu[0].label[0] == '2') + m_module_butt->value(2); + else if(menu[0].label[0] == '3') + m_module_butt->value(3); else { Msg(WARNING, "Something is wrong in your dynamic context definition"); return; } - - Msg(STATUS2, menu[0].label+1); - - switch(m_module_butt->value()){ - case 3 : // post-processing contexts - for(i = 0 ; i < List_Nbr(CTX.post.list) ; i++) { - if(i == NB_BUTT_MAX) break; - nb++ ; - v = (Post_View*)List_Pointer(CTX.post.list,i); + + Msg(STATUS2, menu[0].label + 1); + + switch (m_module_butt->value()) { + case 3: // post-processing contexts + for(i = 0; i < List_Nbr(CTX.post.list); i++) { + if(i == NB_BUTT_MAX) + break; + nb++; + v = (Post_View *) List_Pointer(CTX.post.list, i); m_push_butt[i]->hide(); m_toggle_butt[i]->show(); m_toggle_butt[i]->value(v->Visible); @@ -929,7 +981,7 @@ void GUI::set_context(Context_Item *menu_asked, int flag){ m_popup_butt[i]->show(); m_popup2_butt[i]->show(); } - for(i = List_Nbr(CTX.post.list) ; i < NB_BUTT_MAX ; i++) { + for(i = List_Nbr(CTX.post.list); i < NB_BUTT_MAX; i++) { m_push_butt[i]->hide(); m_toggle_butt[i]->hide(); m_toggle2_butt[i]->hide(); @@ -937,111 +989,126 @@ void GUI::set_context(Context_Item *menu_asked, int flag){ m_popup2_butt[i]->hide(); } break; - default : // geometry, mesh, solver contexts - if(m_module_butt->value() == 2){ //solver + default: // geometry, mesh, solver contexts + if(m_module_butt->value() == 2) { //solver // should handle MAXSOLVERS - menu[1].label = opt_solver_name0(0,GMSH_GET,0); - menu[2].label = opt_solver_name1(0,GMSH_GET,0); - menu[3].label = opt_solver_name2(0,GMSH_GET,0); - menu[4].label = opt_solver_name3(0,GMSH_GET,0); - menu[5].label = opt_solver_name4(0,GMSH_GET,0); - for(i=0 ; i<MAXSOLVERS ; i++){ - if(!strlen(menu[i+1].label)) menu[i+1].label = NULL; + menu[1].label = opt_solver_name0(0, GMSH_GET, 0); + menu[2].label = opt_solver_name1(0, GMSH_GET, 0); + menu[3].label = opt_solver_name2(0, GMSH_GET, 0); + menu[4].label = opt_solver_name3(0, GMSH_GET, 0); + menu[5].label = opt_solver_name4(0, GMSH_GET, 0); + for(i = 0; i < MAXSOLVERS; i++) { + if(!strlen(menu[i + 1].label)) + menu[i + 1].label = NULL; } } - for(i=0 ; i < NB_BUTT_MAX ; i++){ + for(i = 0; i < NB_BUTT_MAX; i++) { m_toggle_butt[i]->hide(); m_toggle2_butt[i]->hide(); m_popup_butt[i]->hide(); m_popup2_butt[i]->hide(); - if(menu[i+1].label){ - m_push_butt[i]->label(menu[i+1].label); - m_push_butt[i]->callback(menu[i+1].callback,menu[i+1].arg); - m_push_butt[i]->redraw(); - m_push_butt[i]->show(); - nb++; + if(menu[i + 1].label) { + m_push_butt[i]->label(menu[i + 1].label); + m_push_butt[i]->callback(menu[i + 1].callback, menu[i + 1].arg); + m_push_butt[i]->redraw(); + m_push_butt[i]->show(); + nb++; } else - break; + break; } - for(i=nb ; i<NB_BUTT_MAX ; i++){ + for(i = nb; i < NB_BUTT_MAX; i++) { m_toggle_butt[i]->hide(); m_toggle2_butt[i]->hide(); m_popup_butt[i]->hide(); m_popup2_butt[i]->hide(); m_push_butt[i]->hide(); } - break ; + break; } - + set_menu_size(nb); - + } -int GUI::get_context(){ +int GUI::get_context() +{ return m_module_butt->value(); } // Create the graphic window -void GUI::create_graphic_window(int argc, char **argv){ +void GUI::create_graphic_window(int argc, char **argv) +{ int i, x; - - if(g_window){ + + if(g_window) { g_window->show(1, argv); return; } - - int sh = 2*fontsize-4; // status bar height - int sw = fontsize+4; //status button width - int width = CTX.viewport[2]-CTX.viewport[0]; - int glheight = CTX.viewport[3]-CTX.viewport[1]; + + int sh = 2 * fontsize - 4; // status bar height + int sw = fontsize + 4; //status button width + int width = CTX.viewport[2] - CTX.viewport[0]; + int glheight = CTX.viewport[3] - CTX.viewport[1]; int height = glheight + sh; - + g_window = new Fl_Window(width, height); g_window->callback(file_quit_cb); // bottom button bar - Fl_Box *bottom = new Fl_Box(0,glheight,width,sh); + Fl_Box *bottom = new Fl_Box(0, glheight, width, sh); bottom->box(FL_THIN_UP_BOX); x = 2; - - g_status_butt[0] = new Fl_Button(x,glheight+2,sw,sh-4,"X"); x+=sw; - g_status_butt[0]->callback(status_xyz1p_cb, (void*)0); - g_status_butt[1] = new Fl_Button(x,glheight+2,sw,sh-4,"Y"); x+=sw; - g_status_butt[1]->callback(status_xyz1p_cb, (void*)1); - g_status_butt[2] = new Fl_Button(x,glheight+2,sw,sh-4,"Z"); x+=sw; - g_status_butt[2]->callback(status_xyz1p_cb, (void*)2); - g_status_butt[3] = new Fl_Button(x,glheight+2,2*fontsize,sh-4,"1:1"); x+=2*fontsize; - g_status_butt[3]->callback(status_xyz1p_cb, (void*)3); - g_status_butt[4] = new Fl_Button(x,glheight+2,sw,sh-4,"?"); x+=sw; - g_status_butt[4]->callback(status_xyz1p_cb, (void*)4); - g_status_butt[5] = new Fl_Button(x,glheight+2,sw,sh-4); x+=sw; + + g_status_butt[0] = new Fl_Button(x, glheight + 2, sw, sh - 4, "X"); + x += sw; + g_status_butt[0]->callback(status_xyz1p_cb, (void *)0); + g_status_butt[1] = new Fl_Button(x, glheight + 2, sw, sh - 4, "Y"); + x += sw; + g_status_butt[1]->callback(status_xyz1p_cb, (void *)1); + g_status_butt[2] = new Fl_Button(x, glheight + 2, sw, sh - 4, "Z"); + x += sw; + g_status_butt[2]->callback(status_xyz1p_cb, (void *)2); + g_status_butt[3] = + new Fl_Button(x, glheight + 2, 2 * fontsize, sh - 4, "1:1"); + x += 2 * fontsize; + g_status_butt[3]->callback(status_xyz1p_cb, (void *)3); + g_status_butt[4] = new Fl_Button(x, glheight + 2, sw, sh - 4, "?"); + x += sw; + g_status_butt[4]->callback(status_xyz1p_cb, (void *)4); + g_status_butt[5] = new Fl_Button(x, glheight + 2, sw, sh - 4); + x += sw; g_status_butt[5]->callback(status_rewind_cb); - rewind_bmp = new Fl_Bitmap(rewind_bits,rewind_width,rewind_height); + rewind_bmp = new Fl_Bitmap(rewind_bits, rewind_width, rewind_height); rewind_bmp->label(g_status_butt[5]); g_status_butt[5]->deactivate(); - g_status_butt[6] = new Fl_Button(x,glheight+2,sw,sh-4); x+=sw; + g_status_butt[6] = new Fl_Button(x, glheight + 2, sw, sh - 4); + x += sw; g_status_butt[6]->callback(status_play_cb); - start_bmp = new Fl_Bitmap(start_bits,start_width,start_height); + start_bmp = new Fl_Bitmap(start_bits, start_width, start_height); start_bmp->label(g_status_butt[6]); - stop_bmp = new Fl_Bitmap(stop_bits,stop_width,stop_height); + stop_bmp = new Fl_Bitmap(stop_bits, stop_width, stop_height); g_status_butt[6]->deactivate(); - for(i = 0 ; i<7 ; i++){ + for(i = 0; i < 7; i++) { g_status_butt[i]->box(FL_FLAT_BOX); g_status_butt[i]->selection_color(FL_WHITE); - g_status_butt[i]->align(FL_ALIGN_CENTER|FL_ALIGN_INSIDE|FL_ALIGN_CLIP); + g_status_butt[i]-> + align(FL_ALIGN_CENTER | FL_ALIGN_INSIDE | FL_ALIGN_CLIP); } - - g_status_label[0] = new Fl_Box(x,glheight+2,(width-x)/3,sh-4); - g_status_label[1] = new Fl_Box(x+(width-x)/3,glheight+2,(width-x)/3,sh-4); - g_status_label[2] = new Fl_Box(x+2*(width-x)/3,glheight+2,(width-x)/3-2,sh-4); - for(i = 0 ; i<3 ; i++){ + + g_status_label[0] = new Fl_Box(x, glheight + 2, (width - x) / 3, sh - 4); + g_status_label[1] = + new Fl_Box(x + (width - x) / 3, glheight + 2, (width - x) / 3, sh - 4); + g_status_label[2] = + new Fl_Box(x + 2 * (width - x) / 3, glheight + 2, (width - x) / 3 - 2, + sh - 4); + for(i = 0; i < 3; i++) { g_status_label[i]->box(FL_FLAT_BOX); - g_status_label[i]->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE|FL_ALIGN_CLIP); + g_status_label[i]->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE | FL_ALIGN_CLIP); } @@ -1057,65 +1124,69 @@ void GUI::create_graphic_window(int argc, char **argv){ // dummy resizable box - Dummy_Box *resize_box = new Dummy_Box(x,0,width-x,glheight); + Dummy_Box *resize_box = new Dummy_Box(x, 0, width - x, glheight); g_window->resizable(resize_box); // opengl window - g_opengl_window = new Opengl_Window(0,0,width,glheight); - if(!opt_general_double_buffer(0,GMSH_GET,0)){ + g_opengl_window = new Opengl_Window(0, 0, width, glheight); + if(!opt_general_double_buffer(0, GMSH_GET, 0)) { Msg(INFO, "Setting OpenGL visual to single buffered"); g_opengl_window->mode(FL_RGB | FL_DEPTH | FL_SINGLE); } g_opengl_window->end(); - g_window->position(CTX.gl_position[0],CTX.gl_position[1]); - g_window->end(); + g_window->position(CTX.gl_position[0], CTX.gl_position[1]); + g_window->end(); } // Set the size of the graphical window -void GUI::set_size(int new_w, int new_h){ - g_window->size(new_w,new_h+g_window->h()-g_opengl_window->h()); +void GUI::set_size(int new_w, int new_h) +{ + g_window->size(new_w, new_h + g_window->h() - g_opengl_window->h()); } // Set graphic window title -void GUI::set_title(char *str){ +void GUI::set_title(char *str) +{ g_window->label(str); } // Set animation button -void GUI::set_anim_buttons(int mode){ - if(mode){ +void GUI::set_anim_buttons(int mode) +{ + if(mode) { g_status_butt[6]->callback(status_play_cb); start_bmp->label(g_status_butt[6]); } - else{ + else { g_status_butt[6]->callback(status_pause_cb); stop_bmp->label(g_status_butt[6]); } } -void GUI::check_anim_buttons(){ - int i, play=0; - if(CTX.post.anim_cycle){ +void GUI::check_anim_buttons() +{ + int i, play = 0; + if(CTX.post.anim_cycle) { play = 1; } - else{ - for(i=0 ; i<List_Nbr(CTX.post.list) ; i++){ - if(((Post_View*)List_Pointer(CTX.post.list,i))->NbTimeStep > 1){ - play = 1 ; - break ; + else { + for(i = 0; i < List_Nbr(CTX.post.list); i++) { + if(((Post_View *) List_Pointer(CTX.post.list, i))->NbTimeStep > 1) { + play = 1; + break; } } } - if(!play){ + if(!play) { g_status_butt[5]->deactivate(); g_status_butt[6]->deactivate(); } - else{ + else { g_status_butt[5]->activate(); g_status_butt[6]->activate(); } @@ -1123,36 +1194,42 @@ void GUI::check_anim_buttons(){ // Set the status messages -void GUI::set_status(char *msg, int num){ +void GUI::set_status(char *msg, int num) +{ g_status_label[num]->label(msg); g_status_label[num]->redraw(); } // set the current drawing context -void GUI::make_opengl_current(){ +void GUI::make_opengl_current() +{ g_opengl_window->make_current(); } -void GUI::make_overlay_current(){ +void GUI::make_overlay_current() +{ g_opengl_window->make_overlay_current(); } // Draw the opengl window -void GUI::redraw_opengl(){ +void GUI::redraw_opengl() +{ g_opengl_window->redraw(); } // Draw the opengl overlay window -void GUI::redraw_overlay(){ +void GUI::redraw_overlay() +{ g_opengl_window->redraw_overlay(); } // Create the option window -void GUI::hide_option_subwindows(){ +void GUI::hide_option_subwindows() +{ gen_window->hide(); geo_window->hide(); mesh_window->hide(); @@ -1161,7 +1238,8 @@ void GUI::hide_option_subwindows(){ view_window->hide(); } -void GUI::create_general_options_window(){ +void GUI::create_general_options_window() +{ create_option_window(); hide_option_subwindows(); gen_window->show(); @@ -1169,15 +1247,17 @@ void GUI::create_general_options_window(){ opt_window->label("Options - General"); } -void GUI::create_geometry_options_window(){ +void GUI::create_geometry_options_window() +{ create_option_window(); hide_option_subwindows(); geo_window->show(); opt_browser->value(2); opt_window->label("Options - Geometry"); } - -void GUI::create_mesh_options_window(){ + +void GUI::create_mesh_options_window() +{ create_option_window(); hide_option_subwindows(); mesh_window->show(); @@ -1185,7 +1265,8 @@ void GUI::create_mesh_options_window(){ opt_window->label("Options - Mesh"); } -void GUI::create_solver_options_window(){ +void GUI::create_solver_options_window() +{ create_option_window(); hide_option_subwindows(); solver_window->show(); @@ -1193,7 +1274,8 @@ void GUI::create_solver_options_window(){ opt_window->label("Options - Solver"); } -void GUI::create_post_options_window(){ +void GUI::create_post_options_window() +{ create_option_window(); hide_option_subwindows(); post_window->show(); @@ -1201,18 +1283,20 @@ void GUI::create_post_options_window(){ opt_window->label("Options - Post-processing"); } -void GUI::create_view_options_window(int num){ +void GUI::create_view_options_window(int num) +{ create_option_window(); hide_option_subwindows(); update_view_window(num); view_window->show(); - opt_browser->value(6+num); + opt_browser->value(6 + num); static char str[128]; sprintf(str, "Options - View [%d]", num); opt_window->label(str); } -void GUI::reset_option_browser(){ +void GUI::reset_option_browser() +{ int i, select; char str[128]; select = opt_browser->value(); @@ -1222,186 +1306,258 @@ void GUI::reset_option_browser(){ opt_browser->add("Mesh"); opt_browser->add("Solver"); opt_browser->add("Post-processing"); - for(i = 0 ; i < List_Nbr(CTX.post.list) ; i++) { - if(i == NB_BUTT_MAX) break; + for(i = 0; i < List_Nbr(CTX.post.list); i++) { + if(i == NB_BUTT_MAX) + break; sprintf(str, "View [%d]", i); opt_browser->add(str); } - if(select<=opt_browser->size()) + if(select <= opt_browser->size()) opt_browser->value(select); } -void GUI::create_option_window(){ +void GUI::create_option_window() +{ int i; - int width = 40*fontsize; - int height = 13*BH ; + int width = 40 * fontsize; + int height = 13 * BH; int BROWSERW = 110; - if(opt_window){ + if(opt_window) { opt_window->show(); return; } - opt_window = new Fl_Window(width,height); + opt_window = new Fl_Window(width, height); opt_window->box(WINDOW_BOX); // Buttons - - { - Fl_Return_Button* o = new Fl_Return_Button(width-3*BB-3*WB, height-BH-WB, BB, BH, "Apply"); + + { + Fl_Return_Button *o = + new Fl_Return_Button(width - 3 * BB - 3 * WB, height - BH - WB, BB, BH, + "Apply"); o->callback(options_ok_cb); } - { - Fl_Button* o = new Fl_Button(width-2*BB-2*WB, height-BH-WB, BB, BH, "Save"); + { + Fl_Button *o = + new Fl_Button(width - 2 * BB - 2 * WB, height - BH - WB, BB, BH, + "Save"); o->callback(options_save_cb); } - { - Fl_Button* o = new Fl_Button(width-BB-WB, height-BH-WB, BB, BH, "Cancel"); - o->callback(cancel_cb, (void*)opt_window); + { + Fl_Button *o = + new Fl_Button(width - BB - WB, height - BH - WB, BB, BH, "Cancel"); + o->callback(cancel_cb, (void *)opt_window); } - + // Selection browser - opt_browser = new Fl_Hold_Browser(WB,WB,BROWSERW-WB,height-3*WB-BH); + opt_browser = + new Fl_Hold_Browser(WB, WB, BROWSERW - WB, height - 3 * WB - BH); reset_option_browser(); opt_browser->callback(options_browser_cb); opt_browser->value(1); opt_window->label("Options - General"); width -= BROWSERW; - int BW = width-4*WB; - height -= WB+BH; + int BW = width - 4 * WB; + height -= WB + BH; // General options - gen_window = new Fl_Window(BROWSERW,0,width,height,"General options"); - { - Fl_Tabs* o = new Fl_Tabs(WB, WB, width-2*WB, height-2*WB); - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Display"); - gen_butt[0] = new Fl_Check_Button(2*WB, 2*WB+1*BH, BW, BH, "Show moving axes"); - gen_butt[1] = new Fl_Check_Button(2*WB, 2*WB+2*BH, BW, BH, "Show small axes"); - gen_butt[2] = new Fl_Check_Button(2*WB, 2*WB+3*BH, BW, BH, "Enable fast redraw"); - gen_butt[3] = new Fl_Check_Button(2*WB, 2*WB+4*BH, BW, BH, "Enable double buffering"); - gen_butt[4] = new Fl_Check_Button(2*WB, 2*WB+5*BH, BW, BH, "Use display lists"); - gen_butt[5] = new Fl_Check_Button(2*WB, 2*WB+6*BH, BW, BH, "Enable alpha blending"); - gen_butt[6] = new Fl_Check_Button(2*WB, 2*WB+7*BH, BW, BH, "Use trackball rotation mode"); - for(i=0 ; i<7 ; i++){ - gen_butt[i]->type(FL_TOGGLE_BUTTON); - gen_butt[i]->down_box(TOGGLE_BOX); - gen_butt[i]->selection_color(TOGGLE_COLOR); + gen_window = new Fl_Window(BROWSERW, 0, width, height, "General options"); + { + Fl_Tabs *o = new Fl_Tabs(WB, WB, width - 2 * WB, height - 2 * WB); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Display"); + gen_butt[0] = + new Fl_Check_Button(2 * WB, 2 * WB + 1 * BH, BW, BH, + "Show moving axes"); + gen_butt[1] = + new Fl_Check_Button(2 * WB, 2 * WB + 2 * BH, BW, BH, + "Show small axes"); + gen_butt[2] = + new Fl_Check_Button(2 * WB, 2 * WB + 3 * BH, BW, BH, + "Enable fast redraw"); + gen_butt[3] = + new Fl_Check_Button(2 * WB, 2 * WB + 4 * BH, BW, BH, + "Enable double buffering"); + gen_butt[4] = + new Fl_Check_Button(2 * WB, 2 * WB + 5 * BH, BW, BH, + "Use display lists"); + gen_butt[5] = + new Fl_Check_Button(2 * WB, 2 * WB + 6 * BH, BW, BH, + "Enable alpha blending"); + gen_butt[6] = + new Fl_Check_Button(2 * WB, 2 * WB + 7 * BH, BW, BH, + "Use trackball rotation mode"); + for(i = 0; i < 7; i++) { + gen_butt[i]->type(FL_TOGGLE_BUTTON); + gen_butt[i]->down_box(TOGGLE_BOX); + gen_butt[i]->selection_color(TOGGLE_COLOR); } - gen_butt[13] = new Fl_Check_Button(2*WB, 2*WB+8*BH, BW, BH, "Show tooltips"); + gen_butt[13] = + new Fl_Check_Button(2 * WB, 2 * WB + 8 * BH, BW, BH, "Show tooltips"); gen_butt[13]->type(FL_TOGGLE_BUTTON); gen_butt[13]->down_box(TOGGLE_BOX); gen_butt[13]->selection_color(TOGGLE_COLOR); o->end(); } - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Output"); - gen_butt[7] = new Fl_Check_Button(2*WB, 2*WB+1*BH, BW, BH, "Print messages on terminal"); - gen_butt[8] = new Fl_Check_Button(2*WB, 2*WB+2*BH, BW, BH, "Save session information on exit"); - gen_butt[9] = new Fl_Check_Button(2*WB, 2*WB+3*BH, BW, BH, "Save options on exit"); - for(i=7 ; i<10 ; i++){ - gen_butt[i]->type(FL_TOGGLE_BUTTON); - gen_butt[i]->down_box(TOGGLE_BOX); - gen_butt[i]->selection_color(TOGGLE_COLOR); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Output"); + gen_butt[7] = + new Fl_Check_Button(2 * WB, 2 * WB + 1 * BH, BW, BH, + "Print messages on terminal"); + gen_butt[8] = + new Fl_Check_Button(2 * WB, 2 * WB + 2 * BH, BW, BH, + "Save session information on exit"); + gen_butt[9] = + new Fl_Check_Button(2 * WB, 2 * WB + 3 * BH, BW, BH, + "Save options on exit"); + for(i = 7; i < 10; i++) { + gen_butt[i]->type(FL_TOGGLE_BUTTON); + gen_butt[i]->down_box(TOGGLE_BOX); + gen_butt[i]->selection_color(TOGGLE_COLOR); } - gen_butt[14] = new Fl_Check_Button(2*WB, 2*WB+4*BH, BW, BH, "Ask confirmation before overwriting files"); + gen_butt[14] = + new Fl_Check_Button(2 * WB, 2 * WB + 4 * BH, BW, BH, + "Ask confirmation before overwriting files"); gen_butt[14]->type(FL_TOGGLE_BUTTON); gen_butt[14]->down_box(TOGGLE_BOX); gen_butt[14]->selection_color(TOGGLE_COLOR); - gen_value[5] = new Fl_Value_Input(2*WB, 2*WB+5*BH, IW, BH, "Message verbosity"); - gen_value[5]->minimum(0); - gen_value[5]->maximum(10); + gen_value[5] = + new Fl_Value_Input(2 * WB, 2 * WB + 5 * BH, IW, BH, + "Message verbosity"); + gen_value[5]->minimum(0); + gen_value[5]->maximum(10); gen_value[5]->step(1); gen_value[5]->align(FL_ALIGN_RIGHT); - gen_input[0] = new Fl_Input(2*WB, 2*WB+6*BH, IW, BH, "Default file name"); - gen_input[1] = new Fl_Input(2*WB, 2*WB+7*BH, IW, BH, "Temporary file"); - gen_input[2] = new Fl_Input(2*WB, 2*WB+8*BH, IW, BH, "Error file"); - gen_input[3] = new Fl_Input(2*WB, 2*WB+9*BH, IW, BH, "Option file"); - gen_input[4] = new Fl_Input(2*WB, 2*WB+10*BH, IW, BH, "Text editor command"); - for(i=0 ; i<5 ; i++){ - gen_input[i]->align(FL_ALIGN_RIGHT); + gen_input[0] = + new Fl_Input(2 * WB, 2 * WB + 6 * BH, IW, BH, "Default file name"); + gen_input[1] = + new Fl_Input(2 * WB, 2 * WB + 7 * BH, IW, BH, "Temporary file"); + gen_input[2] = + new Fl_Input(2 * WB, 2 * WB + 8 * BH, IW, BH, "Error file"); + gen_input[3] = + new Fl_Input(2 * WB, 2 * WB + 9 * BH, IW, BH, "Option file"); + gen_input[4] = + new Fl_Input(2 * WB, 2 * WB + 10 * BH, IW, BH, "Text editor command"); + for(i = 0; i < 5; i++) { + gen_input[i]->align(FL_ALIGN_RIGHT); } - Fl_Button* b0 = new Fl_Button(width-2*BB-2*WB, 2*WB+9*BH, 2*BB, BH, "Restore default options"); + Fl_Button *b0 = + new Fl_Button(width - 2 * BB - 2 * WB, 2 * WB + 9 * BH, 2 * BB, BH, + "Restore default options"); b0->callback(options_restore_defaults_cb); o->end(); } - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Aspect"); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Aspect"); o->hide(); - gen_butt[10] = new Fl_Check_Button(2*WB, 2*WB+1*BH, BW, BH, "Orthographic projection"); - gen_butt[11] = new Fl_Check_Button(2*WB, 2*WB+2*BH, BW, BH, "Perspective projection"); - for(i=10 ; i<12 ; i++){ - gen_butt[i]->type(FL_RADIO_BUTTON); - gen_butt[i]->down_box(RADIO_BOX); - gen_butt[i]->selection_color(RADIO_COLOR); + gen_butt[10] = + new Fl_Check_Button(2 * WB, 2 * WB + 1 * BH, BW, BH, + "Orthographic projection"); + gen_butt[11] = + new Fl_Check_Button(2 * WB, 2 * WB + 2 * BH, BW, BH, + "Perspective projection"); + for(i = 10; i < 12; i++) { + gen_butt[i]->type(FL_RADIO_BUTTON); + gen_butt[i]->down_box(RADIO_BOX); + gen_butt[i]->selection_color(RADIO_COLOR); } - gen_value[6] = new Fl_Value_Input(2*WB, 2*WB+3*BH, IW, BH, "Point size"); + gen_value[6] = + new Fl_Value_Input(2 * WB, 2 * WB + 3 * BH, IW, BH, "Point size"); gen_value[6]->minimum(0.1); gen_value[6]->maximum(50); gen_value[6]->step(0.1); - gen_value[7] = new Fl_Value_Input(2*WB, 2*WB+4*BH, IW, BH, "Line width"); + gen_value[7] = + new Fl_Value_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, "Line width"); gen_value[7]->minimum(0.1); gen_value[7]->maximum(50); gen_value[7]->step(0.1); - for(i=6 ; i<= 7 ; i++){ - gen_value[i]->align(FL_ALIGN_RIGHT); + for(i = 6; i <= 7; i++) { + gen_value[i]->align(FL_ALIGN_RIGHT); } o->end(); } - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Colors"); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Colors"); o->hide(); - gen_value[0] = new Fl_Value_Input(2*WB, 2*WB+1*BH, IW, BH, "Predefined color scheme"); - gen_value[0]->minimum(0); - gen_value[0]->maximum(2); + gen_value[0] = + new Fl_Value_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, + "Predefined color scheme"); + gen_value[0]->minimum(0); + gen_value[0]->maximum(2); gen_value[0]->step(1); gen_value[0]->align(FL_ALIGN_RIGHT); gen_value[0]->callback(general_options_color_scheme_cb); - - Fl_Scroll* s = new Fl_Scroll(2*WB, 3*WB+2*BH, IW+20, height-5*WB-2*BH); + + Fl_Scroll *s = + new Fl_Scroll(2 * WB, 3 * WB + 2 * BH, IW + 20, + height - 5 * WB - 2 * BH); i = 0; - while(GeneralOptions_Color[i].str){ - gen_col[i] = new Fl_Button(2*WB, 3*WB+(2+i)*BH, IW, BH, GeneralOptions_Color[i].str); - gen_col[i]->callback(color_cb, (void*)GeneralOptions_Color[i].function) ; - i++; + while(GeneralOptions_Color[i].str) { + gen_col[i] = + new Fl_Button(2 * WB, 3 * WB + (2 + i) * BH, IW, BH, + GeneralOptions_Color[i].str); + gen_col[i]->callback(color_cb, + (void *)GeneralOptions_Color[i].function); + i++; } s->end(); o->end(); } - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Light"); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Light"); o->hide(); - gen_value[1] = new Fl_Value_Input(2*WB, 2*WB+1*BH, IW, BH, "Material shininess"); - gen_value[1]->minimum(0); + gen_value[1] = + new Fl_Value_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, + "Material shininess"); + gen_value[1]->minimum(0); gen_value[1]->maximum(10); gen_value[1]->step(0.1); - gen_butt[12] = new Fl_Check_Button(2*WB, 2*WB+2*BH, BW, BH, "Moving light"); + gen_butt[12] = + new Fl_Check_Button(2 * WB, 2 * WB + 2 * BH, BW, BH, "Moving light"); gen_butt[12]->type(FL_TOGGLE_BUTTON); gen_butt[12]->down_box(TOGGLE_BOX); gen_butt[12]->selection_color(TOGGLE_COLOR); - gen_value[2] = new Fl_Value_Input(2*WB, 2*WB+3*BH, IW, BH, "Light position X"); - gen_value[2]->minimum(-1); + gen_value[2] = + new Fl_Value_Input(2 * WB, 2 * WB + 3 * BH, IW, BH, + "Light position X"); + gen_value[2]->minimum(-1); gen_value[2]->maximum(1); gen_value[2]->step(0.01); - gen_value[3] = new Fl_Value_Input(2*WB, 2*WB+4*BH, IW, BH, "Light position Y"); - gen_value[3]->minimum(-1); - gen_value[3]->maximum(1); + gen_value[3] = + new Fl_Value_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, + "Light position Y"); + gen_value[3]->minimum(-1); + gen_value[3]->maximum(1); gen_value[3]->step(0.01); - gen_value[4] = new Fl_Value_Input(2*WB, 2*WB+5*BH, IW, BH, "Light position Z"); - gen_value[4]->minimum(-1); - gen_value[4]->maximum(1); + gen_value[4] = + new Fl_Value_Input(2 * WB, 2 * WB + 5 * BH, IW, BH, + "Light position Z"); + gen_value[4]->minimum(-1); + gen_value[4]->maximum(1); gen_value[4]->step(0.01); - for(i=1 ; i<5 ; i++){ - gen_value[i]->align(FL_ALIGN_RIGHT); + for(i = 1; i < 5; i++) { + gen_value[i]->align(FL_ALIGN_RIGHT); } o->end(); } @@ -1410,96 +1566,136 @@ void GUI::create_option_window(){ gen_window->end(); // Geometry options - - geo_window = new Fl_Window(BROWSERW,0,width,height,"Geometry options"); + + geo_window = new Fl_Window(BROWSERW, 0, width, height, "Geometry options"); geo_window->hide(); - { - Fl_Tabs* o = new Fl_Tabs(WB, WB, width-2*WB, height-2*WB); - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "General"); + { + Fl_Tabs *o = new Fl_Tabs(WB, WB, width - 2 * WB, height - 2 * WB); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "General"); o->hide(); - geo_butt[8] = new Fl_Check_Button(2*WB, 2*WB+1*BH, BW, BH, "Auto coherence (suppress duplicates)"); + geo_butt[8] = + new Fl_Check_Button(2 * WB, 2 * WB + 1 * BH, BW, BH, + "Auto coherence (suppress duplicates)"); geo_butt[8]->type(FL_TOGGLE_BUTTON); geo_butt[8]->down_box(TOGGLE_BOX); geo_butt[8]->selection_color(TOGGLE_COLOR); o->end(); } - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Visibility"); - geo_butt[0] = new Fl_Check_Button(2*WB, 2*WB+1*BH, BW/2-WB, BH, "Points"); - geo_butt[1] = new Fl_Check_Button(2*WB, 2*WB+2*BH, BW/2-WB, BH, "Curves"); - geo_butt[2] = new Fl_Check_Button(2*WB, 2*WB+3*BH, BW/2-WB, BH, "Surfaces"); - geo_butt[3] = new Fl_Check_Button(2*WB, 2*WB+4*BH, BW/2-WB, BH, "Volumes"); - geo_butt[4] = new Fl_Check_Button(width/2, 2*WB+1*BH, BW/2-WB, BH, "Point numbers"); - geo_butt[5] = new Fl_Check_Button(width/2, 2*WB+2*BH, BW/2-WB, BH, "Curve numbers"); - geo_butt[6] = new Fl_Check_Button(width/2, 2*WB+3*BH, BW/2-WB, BH, "Surface numbers"); - geo_butt[7] = new Fl_Check_Button(width/2, 2*WB+4*BH, BW/2-WB, BH, "Volume numbers"); - for(i=0 ; i<8 ; i++){ - geo_butt[i]->type(FL_TOGGLE_BUTTON); - geo_butt[i]->down_box(TOGGLE_BOX); - geo_butt[i]->selection_color(TOGGLE_COLOR); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Visibility"); + geo_butt[0] = + new Fl_Check_Button(2 * WB, 2 * WB + 1 * BH, BW / 2 - WB, BH, + "Points"); + geo_butt[1] = + new Fl_Check_Button(2 * WB, 2 * WB + 2 * BH, BW / 2 - WB, BH, + "Curves"); + geo_butt[2] = + new Fl_Check_Button(2 * WB, 2 * WB + 3 * BH, BW / 2 - WB, BH, + "Surfaces"); + geo_butt[3] = + new Fl_Check_Button(2 * WB, 2 * WB + 4 * BH, BW / 2 - WB, BH, + "Volumes"); + geo_butt[4] = + new Fl_Check_Button(width / 2, 2 * WB + 1 * BH, BW / 2 - WB, BH, + "Point numbers"); + geo_butt[5] = + new Fl_Check_Button(width / 2, 2 * WB + 2 * BH, BW / 2 - WB, BH, + "Curve numbers"); + geo_butt[6] = + new Fl_Check_Button(width / 2, 2 * WB + 3 * BH, BW / 2 - WB, BH, + "Surface numbers"); + geo_butt[7] = + new Fl_Check_Button(width / 2, 2 * WB + 4 * BH, BW / 2 - WB, BH, + "Volume numbers"); + for(i = 0; i < 8; i++) { + geo_butt[i]->type(FL_TOGGLE_BUTTON); + geo_butt[i]->down_box(TOGGLE_BOX); + geo_butt[i]->selection_color(TOGGLE_COLOR); } - - geo_value[0] = new Fl_Value_Input(2*WB, 2*WB+5*BH, IW, BH, "Normals"); - geo_value[0]->minimum(0); + + geo_value[0] = + new Fl_Value_Input(2 * WB, 2 * WB + 5 * BH, IW, BH, "Normals"); + geo_value[0]->minimum(0); geo_value[0]->maximum(100); geo_value[0]->step(0.1); - geo_value[1] = new Fl_Value_Input(2*WB, 2*WB+6*BH, IW, BH, "Tangents"); + geo_value[1] = + new Fl_Value_Input(2 * WB, 2 * WB + 6 * BH, IW, BH, "Tangents"); geo_value[1]->minimum(0); geo_value[1]->maximum(100); geo_value[1]->step(0.1); - for(i=0 ; i<2 ; i++){ - geo_value[i]->align(FL_ALIGN_RIGHT); + for(i = 0; i < 2; i++) { + geo_value[i]->align(FL_ALIGN_RIGHT); } o->end(); } - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Aspect"); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Aspect"); o->hide(); - geo_value[3] = new Fl_Value_Input(2*WB, 2*WB+1*BH, IW, BH, "Point size"); + geo_value[3] = + new Fl_Value_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, "Point size"); geo_value[3]->minimum(0.1); geo_value[3]->maximum(50); geo_value[3]->step(0.1); - geo_value[5] = new Fl_Value_Input(2*WB, 2*WB+2*BH, IW, BH, "Highlighted point size"); + geo_value[5] = + new Fl_Value_Input(2 * WB, 2 * WB + 2 * BH, IW, BH, + "Highlighted point size"); geo_value[5]->minimum(0.1); geo_value[5]->maximum(50); geo_value[5]->step(0.1); - geo_choice[0] = new Fl_Choice(2*WB, 2*WB+3*BH, IW, BH, "Point display"); + geo_choice[0] = + new Fl_Choice(2 * WB, 2 * WB + 3 * BH, IW, BH, "Point display"); geo_choice[0]->menu(menu_point_display); geo_choice[0]->align(FL_ALIGN_RIGHT); - geo_value[4] = new Fl_Value_Input(2*WB, 2*WB+4*BH, IW, BH, "Line width"); + geo_value[4] = + new Fl_Value_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, "Line width"); geo_value[4]->minimum(0.1); geo_value[4]->maximum(50); geo_value[4]->step(0.1); - geo_choice[1] = new Fl_Choice(2*WB, 2*WB+5*BH, IW, BH, "Line display"); + geo_choice[1] = + new Fl_Choice(2 * WB, 2 * WB + 5 * BH, IW, BH, "Line display"); geo_choice[1]->menu(menu_line_display); geo_choice[1]->align(FL_ALIGN_RIGHT); - for(i=3 ; i<= 5 ; i++){ - geo_value[i]->align(FL_ALIGN_RIGHT); + for(i = 3; i <= 5; i++) { + geo_value[i]->align(FL_ALIGN_RIGHT); } o->end(); } - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Colors"); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Colors"); o->hide(); - geo_value[2] = new Fl_Value_Input(2*WB, 2*WB+1*BH, IW, BH, "Predefined color scheme"); - geo_value[2]->minimum(0); - geo_value[2]->maximum(2); + geo_value[2] = + new Fl_Value_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, + "Predefined color scheme"); + geo_value[2]->minimum(0); + geo_value[2]->maximum(2); geo_value[2]->step(1); geo_value[2]->align(FL_ALIGN_RIGHT); geo_value[2]->callback(geometry_options_color_scheme_cb); - - Fl_Scroll* s = new Fl_Scroll(2*WB, 3*WB+2*BH, IW+20, height-5*WB-2*BH); + + Fl_Scroll *s = new Fl_Scroll(2 * WB, 3 * WB + 2 * BH, IW + 20, + height - 5 * WB - 2 * BH); i = 0; - while(GeometryOptions_Color[i].str){ - geo_col[i] = new Fl_Button(2*WB, 3*WB+(2+i)*BH, IW, BH, GeometryOptions_Color[i].str); - geo_col[i]->callback(color_cb, (void*)GeometryOptions_Color[i].function) ; - i++; + while(GeometryOptions_Color[i].str) { + geo_col[i] = + new Fl_Button(2 * WB, 3 * WB + (2 + i) * BH, IW, BH, + GeometryOptions_Color[i].str); + geo_col[i]->callback(color_cb, + (void *)GeometryOptions_Color[i].function); + i++; } s->end(); o->end(); @@ -1509,171 +1705,238 @@ void GUI::create_option_window(){ geo_window->end(); // Mesh options - - mesh_window = new Fl_Window(BROWSERW,0,width,height,"Mesh options"); + + mesh_window = new Fl_Window(BROWSERW, 0, width, height, "Mesh options"); mesh_window->hide(); - { - Fl_Tabs* o = new Fl_Tabs(WB, WB, width-2*WB, height-2*WB); - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "General"); + { + Fl_Tabs *o = new Fl_Tabs(WB, WB, width - 2 * WB, height - 2 * WB); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "General"); o->hide(); - - mesh_value[0] = new Fl_Value_Input(2*WB, 2*WB+1*BH, IW, BH, "Number of smoothing steps"); + + mesh_value[0] = + new Fl_Value_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, + "Number of smoothing steps"); mesh_value[0]->minimum(0); - mesh_value[0]->maximum(100); + mesh_value[0]->maximum(100); mesh_value[0]->step(1); - mesh_value[1] = new Fl_Value_Input(2*WB, 2*WB+2*BH, IW, BH, "Mesh scaling factor"); + mesh_value[1] = + new Fl_Value_Input(2 * WB, 2 * WB + 2 * BH, IW, BH, + "Mesh scaling factor"); mesh_value[1]->minimum(0.001); - mesh_value[1]->maximum(1000); + mesh_value[1]->maximum(1000); mesh_value[1]->step(0.001); - mesh_value[2] = new Fl_Value_Input(2*WB, 2*WB+3*BH, IW, BH, "Characteristic length factor"); + mesh_value[2] = + new Fl_Value_Input(2 * WB, 2 * WB + 3 * BH, IW, BH, + "Characteristic length factor"); mesh_value[2]->minimum(0.001); - mesh_value[2]->maximum(1000); + mesh_value[2]->maximum(1000); mesh_value[2]->step(0.001); - mesh_value[3] = new Fl_Value_Input(2*WB, 2*WB+4*BH, IW, BH, "Random perturbation factor"); + mesh_value[3] = + new Fl_Value_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, + "Random perturbation factor"); mesh_value[3]->minimum(1.e-6); - mesh_value[3]->maximum(1.e-1); + mesh_value[3]->maximum(1.e-1); mesh_value[3]->step(1.e-6); - for(i = 0 ; i<4 ; i++){ - mesh_value[i]->align(FL_ALIGN_RIGHT); + for(i = 0; i < 4; i++) { + mesh_value[i]->align(FL_ALIGN_RIGHT); } - - mesh_butt[3] = new Fl_Check_Button(2*WB, 2*WB+5*BH, BW, BH, "Second order elements"); - mesh_butt[3]->deactivate();//2nd order elements do not work. Disable the graphical option. + + mesh_butt[3] = + new Fl_Check_Button(2 * WB, 2 * WB + 5 * BH, BW, BH, + "Second order elements"); + mesh_butt[3]->deactivate(); //2nd order elements do not work. Disable the graphical option. mesh_butt[3]->type(FL_TOGGLE_BUTTON); mesh_butt[3]->down_box(TOGGLE_BOX); mesh_butt[3]->selection_color(TOGGLE_COLOR); - mesh_butt[5] = new Fl_Check_Button(2*WB, 2*WB+6*BH, BW, BH, "Constrain background mesh"); + mesh_butt[5] = + new Fl_Check_Button(2 * WB, 2 * WB + 6 * BH, BW, BH, + "Constrain background mesh"); mesh_butt[5]->type(FL_TOGGLE_BUTTON); mesh_butt[5]->down_box(TOGGLE_BOX); mesh_butt[5]->selection_color(TOGGLE_COLOR); o->end(); } - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "2D"); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "2D"); o->hide(); - - mesh_butt[0] = new Fl_Check_Button(2*WB, 2*WB+1*BH, BW, BH, "Isotropic algorithm"); - mesh_butt[1] = new Fl_Check_Button(2*WB, 2*WB+2*BH, BW, BH, "Isotropic algorithm (Triangle)"); - mesh_butt[2] = new Fl_Check_Button(2*WB, 2*WB+3*BH, BW, BH, "Anisotropic algorithm"); - for(i=0 ; i<3 ; i++){ - mesh_butt[i]->type(FL_RADIO_BUTTON); - mesh_butt[i]->down_box(RADIO_BOX); - mesh_butt[i]->selection_color(RADIO_COLOR); + + mesh_butt[0] = + new Fl_Check_Button(2 * WB, 2 * WB + 1 * BH, BW, BH, + "Isotropic algorithm"); + mesh_butt[1] = + new Fl_Check_Button(2 * WB, 2 * WB + 2 * BH, BW, BH, + "Isotropic algorithm (Triangle)"); + mesh_butt[2] = + new Fl_Check_Button(2 * WB, 2 * WB + 3 * BH, BW, BH, + "Anisotropic algorithm"); + for(i = 0; i < 3; i++) { + mesh_butt[i]->type(FL_RADIO_BUTTON); + mesh_butt[i]->down_box(RADIO_BOX); + mesh_butt[i]->selection_color(RADIO_COLOR); } #if !defined(HAVE_TRIANGLE) mesh_butt[1]->deactivate(); #endif - mesh_butt[4] = new Fl_Check_Button(2*WB, 2*WB+4*BH, BW, BH, "Interactive"); + mesh_butt[4] = + new Fl_Check_Button(2 * WB, 2 * WB + 4 * BH, BW, BH, "Interactive"); mesh_butt[4]->type(FL_TOGGLE_BUTTON); mesh_butt[4]->down_box(TOGGLE_BOX); mesh_butt[4]->selection_color(TOGGLE_COLOR); o->end(); } - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Visibility"); - mesh_butt[6] = new Fl_Check_Button(2*WB, 2*WB+1*BH, BW/2-WB, BH, "Points"); - mesh_butt[7] = new Fl_Check_Button(2*WB, 2*WB+2*BH, BW/2-WB, BH, "Lines"); - mesh_butt[8] = new Fl_Check_Button(2*WB, 2*WB+3*BH, BW/2-WB, BH, "Surfaces"); - mesh_butt[9] = new Fl_Check_Button(2*WB, 2*WB+4*BH, BW/2-WB, BH, "Volumes"); - mesh_butt[10] = new Fl_Check_Button(width/2, 2*WB+1*BH, BW/2-WB, BH, "Point numbers"); - mesh_butt[11] = new Fl_Check_Button(width/2, 2*WB+2*BH, BW/2-WB, BH, "Line numbers"); - mesh_butt[12] = new Fl_Check_Button(width/2, 2*WB+3*BH, BW/2-WB, BH, "Surface numbers"); - mesh_butt[13] = new Fl_Check_Button(width/2, 2*WB+4*BH, BW/2-WB, BH, "Volume numbers"); - for(i=6 ; i<14 ; i++){ - mesh_butt[i]->type(FL_TOGGLE_BUTTON); - mesh_butt[i]->down_box(TOGGLE_BOX); - mesh_butt[i]->selection_color(TOGGLE_COLOR); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Visibility"); + mesh_butt[6] = + new Fl_Check_Button(2 * WB, 2 * WB + 1 * BH, BW / 2 - WB, BH, + "Points"); + mesh_butt[7] = + new Fl_Check_Button(2 * WB, 2 * WB + 2 * BH, BW / 2 - WB, BH, + "Lines"); + mesh_butt[8] = + new Fl_Check_Button(2 * WB, 2 * WB + 3 * BH, BW / 2 - WB, BH, + "Surfaces"); + mesh_butt[9] = + new Fl_Check_Button(2 * WB, 2 * WB + 4 * BH, BW / 2 - WB, BH, + "Volumes"); + mesh_butt[10] = + new Fl_Check_Button(width / 2, 2 * WB + 1 * BH, BW / 2 - WB, BH, + "Point numbers"); + mesh_butt[11] = + new Fl_Check_Button(width / 2, 2 * WB + 2 * BH, BW / 2 - WB, BH, + "Line numbers"); + mesh_butt[12] = + new Fl_Check_Button(width / 2, 2 * WB + 3 * BH, BW / 2 - WB, BH, + "Surface numbers"); + mesh_butt[13] = + new Fl_Check_Button(width / 2, 2 * WB + 4 * BH, BW / 2 - WB, BH, + "Volume numbers"); + for(i = 6; i < 14; i++) { + mesh_butt[i]->type(FL_TOGGLE_BUTTON); + mesh_butt[i]->down_box(TOGGLE_BOX); + mesh_butt[i]->selection_color(TOGGLE_COLOR); } - mesh_value[4] = new Fl_Value_Input(2*WB, 2*WB+5*BH, IW/2, BH); - mesh_value[4]->minimum(0); + mesh_value[4] = new Fl_Value_Input(2 * WB, 2 * WB + 5 * BH, IW / 2, BH); + mesh_value[4]->minimum(0); mesh_value[4]->maximum(1); mesh_value[4]->step(0.001); - mesh_value[5] = new Fl_Value_Input(2*WB+IW/2, 2*WB+5*BH, IW/2, BH, "Quality range"); - mesh_value[5]->minimum(0); + mesh_value[5] = + new Fl_Value_Input(2 * WB + IW / 2, 2 * WB + 5 * BH, IW / 2, BH, + "Quality range"); + mesh_value[5]->minimum(0); mesh_value[5]->maximum(1); mesh_value[5]->step(0.001); - - mesh_value[6] = new Fl_Value_Input(2*WB, 2*WB+6*BH, IW/2, BH); - mesh_value[7] = new Fl_Value_Input(2*WB+IW/2, 2*WB+6*BH, IW/2, BH, "Size range"); - - mesh_value[8] = new Fl_Value_Input(2*WB, 2*WB+7*BH, IW, BH, "Normals"); - mesh_value[8]->minimum(0); + + mesh_value[6] = new Fl_Value_Input(2 * WB, 2 * WB + 6 * BH, IW / 2, BH); + mesh_value[7] = + new Fl_Value_Input(2 * WB + IW / 2, 2 * WB + 6 * BH, IW / 2, BH, + "Size range"); + + mesh_value[8] = + new Fl_Value_Input(2 * WB, 2 * WB + 7 * BH, IW, BH, "Normals"); + mesh_value[8]->minimum(0); mesh_value[8]->maximum(100); mesh_value[8]->step(0.1); - for(i=4 ; i<9 ; i++){ - mesh_value[i]->align(FL_ALIGN_RIGHT); + for(i = 4; i < 9; i++) { + mesh_value[i]->align(FL_ALIGN_RIGHT); } - mesh_value[13] = new Fl_Value_Input(2*WB, 2*WB+8*BH, IW, BH, "Tangents"); - mesh_value[13]->minimum(0); + mesh_value[13] = + new Fl_Value_Input(2 * WB, 2 * WB + 8 * BH, IW, BH, "Tangents"); + mesh_value[13]->minimum(0); mesh_value[13]->maximum(100); mesh_value[13]->step(0.1); mesh_value[13]->align(FL_ALIGN_RIGHT); o->end(); } - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Aspect"); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Aspect"); o->hide(); - mesh_butt[14] = new Fl_Check_Button(2*WB, 2*WB+1*BH, BW, BH, "Wireframe"); - mesh_butt[15] = new Fl_Check_Button(2*WB, 2*WB+2*BH, BW, BH, "Hidden lines"); - mesh_butt[16] = new Fl_Check_Button(2*WB, 2*WB+3*BH, BW, BH, "Solid"); - for(i=14 ; i<17 ; i++){ - mesh_butt[i]->type(FL_RADIO_BUTTON); - mesh_butt[i]->down_box(RADIO_BOX); - mesh_butt[i]->selection_color(RADIO_COLOR); + mesh_butt[14] = + new Fl_Check_Button(2 * WB, 2 * WB + 1 * BH, BW, BH, "Wireframe"); + mesh_butt[15] = + new Fl_Check_Button(2 * WB, 2 * WB + 2 * BH, BW, BH, "Hidden lines"); + mesh_butt[16] = + new Fl_Check_Button(2 * WB, 2 * WB + 3 * BH, BW, BH, "Solid"); + for(i = 14; i < 17; i++) { + mesh_butt[i]->type(FL_RADIO_BUTTON); + mesh_butt[i]->down_box(RADIO_BOX); + mesh_butt[i]->selection_color(RADIO_COLOR); } - mesh_value[9] = new Fl_Value_Input(2*WB, 2*WB+4*BH, IW, BH, "Explode elements"); + mesh_value[9] = + new Fl_Value_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, + "Explode elements"); mesh_value[9]->minimum(0); mesh_value[9]->maximum(1); mesh_value[9]->step(0.01); - mesh_value[10] = new Fl_Value_Input(2*WB, 2*WB+5*BH, IW, BH, "Point size"); + mesh_value[10] = + new Fl_Value_Input(2 * WB, 2 * WB + 5 * BH, IW, BH, "Point size"); mesh_value[10]->minimum(0.1); mesh_value[10]->maximum(50); mesh_value[10]->step(0.1); - mesh_value[11] = new Fl_Value_Input(2*WB, 2*WB+7*BH, IW, BH, "Line width"); + mesh_value[11] = + new Fl_Value_Input(2 * WB, 2 * WB + 7 * BH, IW, BH, "Line width"); mesh_value[11]->minimum(0.1); mesh_value[11]->maximum(50); mesh_value[11]->step(0.1); - for(i=9 ; i<= 11 ; i++){ - mesh_value[i]->align(FL_ALIGN_RIGHT); + for(i = 9; i <= 11; i++) { + mesh_value[i]->align(FL_ALIGN_RIGHT); } - mesh_choice[0] = new Fl_Choice(2*WB, 2*WB+6*BH, IW, BH, "Point display"); + mesh_choice[0] = + new Fl_Choice(2 * WB, 2 * WB + 6 * BH, IW, BH, "Point display"); mesh_choice[0]->menu(menu_point_display); mesh_choice[0]->align(FL_ALIGN_RIGHT); - mesh_choice[1] = new Fl_Choice(2*WB, 2*WB+8*BH, IW, BH, "Line display"); + mesh_choice[1] = + new Fl_Choice(2 * WB, 2 * WB + 8 * BH, IW, BH, "Line display"); mesh_choice[1]->menu(menu_line_display); mesh_choice[1]->align(FL_ALIGN_RIGHT); o->end(); } - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Colors"); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Colors"); o->hide(); - mesh_butt[17] = new Fl_Check_Button(2*WB, 2*WB+1*BH, BW, BH, "Switch color by entity"); + mesh_butt[17] = + new Fl_Check_Button(2 * WB, 2 * WB + 1 * BH, BW, BH, + "Switch color by entity"); mesh_butt[17]->type(FL_TOGGLE_BUTTON); mesh_butt[17]->down_box(TOGGLE_BOX); mesh_butt[17]->selection_color(TOGGLE_COLOR); - - mesh_value[12] = new Fl_Value_Input(2*WB, 2*WB+2*BH, IW, BH, "Predefined color scheme"); - mesh_value[12]->minimum(0); - mesh_value[12]->maximum(2); + + mesh_value[12] = + new Fl_Value_Input(2 * WB, 2 * WB + 2 * BH, IW, BH, + "Predefined color scheme"); + mesh_value[12]->minimum(0); + mesh_value[12]->maximum(2); mesh_value[12]->step(1); mesh_value[12]->align(FL_ALIGN_RIGHT); mesh_value[12]->callback(mesh_options_color_scheme_cb); - - Fl_Scroll* s = new Fl_Scroll(2*WB, 3*WB+3*BH, IW+20, height-5*WB-3*BH); + + Fl_Scroll *s = new Fl_Scroll(2 * WB, 3 * WB + 3 * BH, IW + 20, + height - 5 * WB - 3 * BH); i = 0; - while(MeshOptions_Color[i].str){ - mesh_col[i] = new Fl_Button(2*WB, 3*WB+(3+i)*BH, IW, BH, MeshOptions_Color[i].str); - mesh_col[i]->callback(color_cb, (void*)MeshOptions_Color[i].function) ; - i++; + while(MeshOptions_Color[i].str) { + mesh_col[i] = + new Fl_Button(2 * WB, 3 * WB + (3 + i) * BH, IW, BH, + MeshOptions_Color[i].str); + mesh_col[i]->callback(color_cb, + (void *)MeshOptions_Color[i].function); + i++; } s->end(); o->end(); @@ -1684,69 +1947,95 @@ void GUI::create_option_window(){ // Solver options - solver_window = new Fl_Window(BROWSERW,0,width,height,"Solver options"); + solver_window = new Fl_Window(BROWSERW, 0, width, height, "Solver options"); solver_window->hide(); - { - Fl_Tabs* o = new Fl_Tabs(WB, WB, width-2*WB, height-2*WB); - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Solver"); - - Fl_Box *text = new Fl_Box(FL_NO_BOX, 2*WB, 3*WB+1*BH, width-4*WB, 2*BH, - "There are no global solver options available yet.\n\n" - "To define your own solver interface, edit the option file."); - text->align(FL_ALIGN_LEFT|FL_ALIGN_TOP|FL_ALIGN_INSIDE|FL_ALIGN_WRAP); + { + Fl_Tabs *o = new Fl_Tabs(WB, WB, width - 2 * WB, height - 2 * WB); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Solver"); + + Fl_Box *text = + new Fl_Box(FL_NO_BOX, 2 * WB, 3 * WB + 1 * BH, width - 4 * WB, 2 * BH, + "There are no global solver options available yet.\n\n" + "To define your own solver interface, edit the option file."); + text-> + align(FL_ALIGN_LEFT | FL_ALIGN_TOP | FL_ALIGN_INSIDE | FL_ALIGN_WRAP); o->end(); } o->end(); } - + solver_window->end(); - + // Post-processing options - post_window = new Fl_Window(BROWSERW,0,width,height,"Post-processing options"); + post_window = + new Fl_Window(BROWSERW, 0, width, height, "Post-processing options"); post_window->hide(); - { - Fl_Tabs* o = new Fl_Tabs(WB, WB, width-2*WB, height-2*WB); - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Views"); - post_butt[0] = new Fl_Check_Button(2*WB, 2*WB+1*BH, BW, BH, "Independent views"); - post_butt[1] = new Fl_Check_Button(2*WB, 2*WB+2*BH, BW, BH, "Apply next changes to all visible views"); - post_butt[2] = new Fl_Check_Button(2*WB, 2*WB+3*BH, BW, BH, "Apply next changes to all views"); - post_butt[3] = new Fl_Check_Button(2*WB, 2*WB+4*BH, BW, BH, "Force same options for all visible views"); - post_butt[4] = new Fl_Check_Button(2*WB, 2*WB+5*BH, BW, BH, "Force same options for all views"); - for(i=0 ; i<5 ; i++){ - post_butt[i]->type(FL_RADIO_BUTTON); - post_butt[i]->down_box(RADIO_BOX); - post_butt[i]->selection_color(RADIO_COLOR); + { + Fl_Tabs *o = new Fl_Tabs(WB, WB, width - 2 * WB, height - 2 * WB); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Views"); + post_butt[0] = + new Fl_Check_Button(2 * WB, 2 * WB + 1 * BH, BW, BH, + "Independent views"); + post_butt[1] = + new Fl_Check_Button(2 * WB, 2 * WB + 2 * BH, BW, BH, + "Apply next changes to all visible views"); + post_butt[2] = + new Fl_Check_Button(2 * WB, 2 * WB + 3 * BH, BW, BH, + "Apply next changes to all views"); + post_butt[3] = + new Fl_Check_Button(2 * WB, 2 * WB + 4 * BH, BW, BH, + "Force same options for all visible views"); + post_butt[4] = + new Fl_Check_Button(2 * WB, 2 * WB + 5 * BH, BW, BH, + "Force same options for all views"); + for(i = 0; i < 5; i++) { + post_butt[i]->type(FL_RADIO_BUTTON); + post_butt[i]->down_box(RADIO_BOX); + post_butt[i]->selection_color(RADIO_COLOR); } /* - Fl_Box *text = new Fl_Box(FL_NO_BOX, 2*WB, 3*WB+6*BH, width-4*WB, 2*BH, - "Individual view options are available " - "by clicking on the arrow next to each " - "view button in the post-processing menu"); - text->align(FL_ALIGN_LEFT|FL_ALIGN_TOP|FL_ALIGN_INSIDE|FL_ALIGN_WRAP); - */ + Fl_Box *text = new Fl_Box(FL_NO_BOX, 2*WB, 3*WB+6*BH, width-4*WB, 2*BH, + "Individual view options are available " + "by clicking on the arrow next to each " + "view button in the post-processing menu"); + text->align(FL_ALIGN_LEFT|FL_ALIGN_TOP|FL_ALIGN_INSIDE|FL_ALIGN_WRAP); + */ o->end(); } - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Smoothing"); - post_butt[5] = new Fl_Check_Button(2*WB, 2*WB+1*BH, BW, BH, "Smooth views during merge"); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Smoothing"); + post_butt[5] = + new Fl_Check_Button(2 * WB, 2 * WB + 1 * BH, BW, BH, + "Smooth views during merge"); post_butt[5]->type(FL_TOGGLE_BUTTON); post_butt[5]->down_box(TOGGLE_BOX); post_butt[5]->selection_color(TOGGLE_COLOR); o->end(); } - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Animation"); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Animation"); o->hide(); - post_value[0] = new Fl_Value_Input(2*WB, 2*WB+1*BH, IW, BH, "Delay"); + post_value[0] = + new Fl_Value_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, "Delay"); post_value[0]->minimum(0); - post_value[0]->maximum(10); + post_value[0]->maximum(10); post_value[0]->step(0.01); post_value[0]->align(FL_ALIGN_RIGHT); - post_butt[6] = new Fl_Check_Button(2*WB, 2*WB+2*BH, BW, BH, "Cycle through views instead of time steps"); + post_butt[6] = + new Fl_Check_Button(2 * WB, 2 * WB + 2 * BH, BW, BH, + "Cycle through views instead of time steps"); post_butt[6]->type(FL_TOGGLE_BUTTON); post_butt[6]->down_box(TOGGLE_BOX); post_butt[6]->selection_color(TOGGLE_COLOR); @@ -1754,334 +2043,433 @@ void GUI::create_option_window(){ } o->end(); } - + post_window->end(); // View options // WARNING! Don't forget to add the set_changed_cb() callback to any new widget! // initialise all buttons to NULL (see the clear_changed() in view_options_ok_cb) - for(i=0; i<VIEW_OPT_BUTT; i++){ + for(i = 0; i < VIEW_OPT_BUTT; i++) { view_butt[i] = NULL; view_value[i] = NULL; view_input[i] = NULL; view_choice[i] = NULL; } - view_number = -1 ; - - view_window = new Fl_Window(BROWSERW,0,width,height,"View options"); + view_number = -1; + + view_window = new Fl_Window(BROWSERW, 0, width, height, "View options"); view_window->hide(); - { - Fl_Tabs* o = new Fl_Tabs(WB, WB, width-2*WB, height-2*WB); + { + Fl_Tabs *o = new Fl_Tabs(WB, WB, width - 2 * WB, height - 2 * WB); // General - { - Fl_Group *o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "General"); - - view_butt[1] = new Fl_Check_Button(2*WB, 2*WB+1*BH, BW/2-WB, BH, "3D view"); - view_butt[2] = new Fl_Check_Button(2*WB, 2*WB+2*BH, BW/2-WB, BH, "2D space table"); - view_butt[3] = new Fl_Check_Button(2*WB, 2*WB+3*BH, BW/2-WB, BH, "2D time table"); - for(i=1 ; i<=3 ; i++){ - view_butt[i]->type(FL_RADIO_BUTTON); - view_butt[i]->down_box(RADIO_BOX); - view_butt[i]->selection_color(RADIO_COLOR); - view_butt[i]->callback(set_changed_cb, 0); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "General"); + + view_butt[1] = + new Fl_Check_Button(2 * WB, 2 * WB + 1 * BH, BW / 2 - WB, BH, + "3D view"); + view_butt[2] = + new Fl_Check_Button(2 * WB, 2 * WB + 2 * BH, BW / 2 - WB, BH, + "2D space table"); + view_butt[3] = + new Fl_Check_Button(2 * WB, 2 * WB + 3 * BH, BW / 2 - WB, BH, + "2D time table"); + for(i = 1; i <= 3; i++) { + view_butt[i]->type(FL_RADIO_BUTTON); + view_butt[i]->down_box(RADIO_BOX); + view_butt[i]->selection_color(RADIO_COLOR); + view_butt[i]->callback(set_changed_cb, 0); } - - view_input[0] = new Fl_Input(2*WB, 2*WB+4*BH, IW, BH, "Name"); - view_input[1] = new Fl_Input(2*WB, 2*WB+5*BH, IW, BH, "Format"); - for(i=0 ; i<=1 ; i++){ - view_input[i]->align(FL_ALIGN_RIGHT); - view_input[i]->callback(set_changed_cb, 0); + + view_input[0] = new Fl_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, "Name"); + view_input[1] = new Fl_Input(2 * WB, 2 * WB + 5 * BH, IW, BH, "Format"); + for(i = 0; i <= 1; i++) { + view_input[i]->align(FL_ALIGN_RIGHT); + view_input[i]->callback(set_changed_cb, 0); } - int sw=(int)(1.5*fontsize); - view_butt_rep[0] = new Fl_Repeat_Button(2*WB, 2*WB+6*BH, sw, BH, "-"); + int sw = (int)(1.5 * fontsize); + view_butt_rep[0] = + new Fl_Repeat_Button(2 * WB, 2 * WB + 6 * BH, sw, BH, "-"); //no set_changed since has its own callback - view_butt_rep[1] = new Fl_Repeat_Button(2*WB+IW-sw, 2*WB+6*BH, sw, BH, "+"); + view_butt_rep[1] = + new Fl_Repeat_Button(2 * WB + IW - sw, 2 * WB + 6 * BH, sw, BH, "+"); //no set_changed since has its own callback - view_value[50] = new Fl_Value_Input(2*WB+sw, 2*WB+6*BH, IW-2*sw, BH); + view_value[50] = + new Fl_Value_Input(2 * WB + sw, 2 * WB + 6 * BH, IW - 2 * sw, BH); view_value[50]->align(FL_ALIGN_RIGHT); - view_value[50]->minimum(0); - view_value[50]->maximum(0); + view_value[50]->minimum(0); + view_value[50]->maximum(0); view_value[50]->step(1); //no set_changed since has its own callback - Fl_Box *a = new Fl_Box(2*WB+IW, 2*WB+6*BH, IW/2, BH, "Step"); + Fl_Box *a = + new Fl_Box(2 * WB + IW, 2 * WB + 6 * BH, IW / 2, BH, "Step"); a->box(FL_NO_BOX); - a->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); - - view_value[20] = new Fl_Value_Input(2*WB, 2*WB+7*BH, IW/2, BH); - view_value[21] = new Fl_Value_Input(2*WB+IW/2, 2*WB+7*BH, IW/2, BH, "Position"); - view_value[22] = new Fl_Value_Input(2*WB, 2*WB+8*BH, IW/2, BH); - view_value[23] = new Fl_Value_Input(2*WB+IW/2, 2*WB+8*BH, IW/2, BH, "Size"); - for(i=20 ; i<=23 ; i++){ - view_value[i]->align(FL_ALIGN_RIGHT); - view_value[i]->callback(set_changed_cb, 0); + a->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); + + view_value[20] = + new Fl_Value_Input(2 * WB, 2 * WB + 7 * BH, IW / 2, BH); + view_value[21] = + new Fl_Value_Input(2 * WB + IW / 2, 2 * WB + 7 * BH, IW / 2, BH, + "Position"); + view_value[22] = + new Fl_Value_Input(2 * WB, 2 * WB + 8 * BH, IW / 2, BH); + view_value[23] = + new Fl_Value_Input(2 * WB + IW / 2, 2 * WB + 8 * BH, IW / 2, BH, + "Size"); + for(i = 20; i <= 23; i++) { + view_value[i]->align(FL_ALIGN_RIGHT); + view_value[i]->callback(set_changed_cb, 0); } - view_butt[8] = new Fl_Check_Button(width/2, 2*WB+1*BH, BW/2-WB, BH, "Show time"); - view_butt[5] = new Fl_Check_Button(width/2, 2*WB+2*BH, BW/2-WB, BH, "Show annotations"); - view_butt[4] = new Fl_Check_Button(width/2, 2*WB+3*BH, BW/2-WB, BH, "Show scale"); - view_butt[6] = new Fl_Check_Button(width/2, 2*WB+4*BH, BW/2-WB, BH, "Transparent scale"); - view_butt[7] = new Fl_Check_Button(width/2, 2*WB+5*BH, BW/2-WB, BH, "Auto position"); - for(i=4 ; i<=8 ; i++){ - view_butt[i]->type(FL_TOGGLE_BUTTON); - view_butt[i]->down_box(TOGGLE_BOX); - view_butt[i]->selection_color(TOGGLE_COLOR); - view_butt[i]->callback(set_changed_cb, 0); + view_butt[8] = + new Fl_Check_Button(width / 2, 2 * WB + 1 * BH, BW / 2 - WB, BH, + "Show time"); + view_butt[5] = + new Fl_Check_Button(width / 2, 2 * WB + 2 * BH, BW / 2 - WB, BH, + "Show annotations"); + view_butt[4] = + new Fl_Check_Button(width / 2, 2 * WB + 3 * BH, BW / 2 - WB, BH, + "Show scale"); + view_butt[6] = + new Fl_Check_Button(width / 2, 2 * WB + 4 * BH, BW / 2 - WB, BH, + "Transparent scale"); + view_butt[7] = + new Fl_Check_Button(width / 2, 2 * WB + 5 * BH, BW / 2 - WB, BH, + "Auto position"); + for(i = 4; i <= 8; i++) { + view_butt[i]->type(FL_TOGGLE_BUTTON); + view_butt[i]->down_box(TOGGLE_BOX); + view_butt[i]->selection_color(TOGGLE_COLOR); + view_butt[i]->callback(set_changed_cb, 0); } - + o->end(); } // 3D - { - view_3d = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "3D"); + { + view_3d = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "3D"); view_3d->hide(); - - view_butt[10] = new Fl_Check_Button(width/2, 2*WB+1*BH, BW/2-WB, BH, "Show elements"); - view_butt[11] = new Fl_Check_Button(width/2, 2*WB+2*BH, BW/2-WB, BH, "Enable lighting"); - view_butt[12] = new Fl_Check_Button(width/2, 2*WB+3*BH, BW/2-WB, BH, "Smooth normals"); - for(i=10 ; i<=12 ; i++){ - view_butt[i]->type(FL_TOGGLE_BUTTON); - view_butt[i]->down_box(TOGGLE_BOX); - view_butt[i]->selection_color(TOGGLE_COLOR); - view_butt[i]->callback(set_changed_cb, 0); + + view_butt[10] = + new Fl_Check_Button(width / 2, 2 * WB + 1 * BH, BW / 2 - WB, BH, + "Show elements"); + view_butt[11] = + new Fl_Check_Button(width / 2, 2 * WB + 2 * BH, BW / 2 - WB, BH, + "Enable lighting"); + view_butt[12] = + new Fl_Check_Button(width / 2, 2 * WB + 3 * BH, BW / 2 - WB, BH, + "Smooth normals"); + for(i = 10; i <= 12; i++) { + view_butt[i]->type(FL_TOGGLE_BUTTON); + view_butt[i]->down_box(TOGGLE_BOX); + view_butt[i]->selection_color(TOGGLE_COLOR); + view_butt[i]->callback(set_changed_cb, 0); } - view_value[10] = new Fl_Value_Input(width/2, 2*WB+4*BH, IW, BH, "Angle"); - view_value[10]->minimum(0.); - view_value[10]->step(1.); - view_value[10]->maximum(180.); - view_value[11] = new Fl_Value_Input(width/2, 2*WB+5*BH, IW, BH, "Boundary"); - view_value[11]->minimum(0); - view_value[11]->step(1); - view_value[11]->maximum(3); - view_value[12] = new Fl_Value_Input(width/2, 2*WB+6*BH, IW, BH, "Explode"); - view_value[12]->minimum(0.); - view_value[12]->step(0.01); - view_value[12]->maximum(1.); - for(i=10 ; i<=12 ; i++){ - view_value[i]->align(FL_ALIGN_RIGHT); - view_value[i]->callback(set_changed_cb, 0); + view_value[10] = + new Fl_Value_Input(width / 2, 2 * WB + 4 * BH, IW, BH, "Angle"); + view_value[10]->minimum(0.); + view_value[10]->step(1.); + view_value[10]->maximum(180.); + view_value[11] = + new Fl_Value_Input(width / 2, 2 * WB + 5 * BH, IW, BH, "Boundary"); + view_value[11]->minimum(0); + view_value[11]->step(1); + view_value[11]->maximum(3); + view_value[12] = + new Fl_Value_Input(width / 2, 2 * WB + 6 * BH, IW, BH, "Explode"); + view_value[12]->minimum(0.); + view_value[12]->step(0.01); + view_value[12]->maximum(1.); + for(i = 10; i <= 12; i++) { + view_value[i]->align(FL_ALIGN_RIGHT); + view_value[i]->callback(set_changed_cb, 0); } - - view_butt[13] = new Fl_Check_Button(2*WB, 2*WB+1*BH, BW/2-WB, BH, "Show points"); - view_butt[14] = new Fl_Check_Button(2*WB, 2*WB+2*BH, BW/2-WB, BH, "Show lines"); - view_butt[15] = new Fl_Check_Button(2*WB, 2*WB+3*BH, BW/2-WB, BH, "Show triangles"); - view_butt[16] = new Fl_Check_Button(2*WB, 2*WB+4*BH, BW/2-WB, BH, "Show quadrangles"); - view_butt[17] = new Fl_Check_Button(2*WB, 2*WB+5*BH, BW/2-WB, BH, "Show tetrahedra"); - view_butt[18] = new Fl_Check_Button(2*WB, 2*WB+6*BH, BW/2-WB, BH, "Show hexahedra"); - view_butt[19] = new Fl_Check_Button(2*WB, 2*WB+7*BH, BW/2-WB, BH, "Show prisms"); - view_butt[20] = new Fl_Check_Button(2*WB, 2*WB+8*BH, BW/2-WB, BH, "Show pyramids"); - view_butt[21] = new Fl_Check_Button(width/2, 2*WB+7*BH, BW/2-WB, BH, "Show scalar values"); - view_butt[22] = new Fl_Check_Button(width/2, 2*WB+8*BH, BW/2-WB, BH, "Show vector values"); - view_butt[23] = new Fl_Check_Button(width/2, 2*WB+9*BH, BW/2-WB, BH, "Show tensor values"); - for(i=13 ; i<=23 ; i++){ - view_butt[i]->type(FL_TOGGLE_BUTTON); - view_butt[i]->down_box(TOGGLE_BOX); - view_butt[i]->selection_color(TOGGLE_COLOR); - view_butt[i]->callback(set_changed_cb, 0); + + view_butt[13] = + new Fl_Check_Button(2 * WB, 2 * WB + 1 * BH, BW / 2 - WB, BH, + "Show points"); + view_butt[14] = + new Fl_Check_Button(2 * WB, 2 * WB + 2 * BH, BW / 2 - WB, BH, + "Show lines"); + view_butt[15] = + new Fl_Check_Button(2 * WB, 2 * WB + 3 * BH, BW / 2 - WB, BH, + "Show triangles"); + view_butt[16] = + new Fl_Check_Button(2 * WB, 2 * WB + 4 * BH, BW / 2 - WB, BH, + "Show quadrangles"); + view_butt[17] = + new Fl_Check_Button(2 * WB, 2 * WB + 5 * BH, BW / 2 - WB, BH, + "Show tetrahedra"); + view_butt[18] = + new Fl_Check_Button(2 * WB, 2 * WB + 6 * BH, BW / 2 - WB, BH, + "Show hexahedra"); + view_butt[19] = + new Fl_Check_Button(2 * WB, 2 * WB + 7 * BH, BW / 2 - WB, BH, + "Show prisms"); + view_butt[20] = + new Fl_Check_Button(2 * WB, 2 * WB + 8 * BH, BW / 2 - WB, BH, + "Show pyramids"); + view_butt[21] = + new Fl_Check_Button(width / 2, 2 * WB + 7 * BH, BW / 2 - WB, BH, + "Show scalar values"); + view_butt[22] = + new Fl_Check_Button(width / 2, 2 * WB + 8 * BH, BW / 2 - WB, BH, + "Show vector values"); + view_butt[23] = + new Fl_Check_Button(width / 2, 2 * WB + 9 * BH, BW / 2 - WB, BH, + "Show tensor values"); + for(i = 13; i <= 23; i++) { + view_butt[i]->type(FL_TOGGLE_BUTTON); + view_butt[i]->down_box(TOGGLE_BOX); + view_butt[i]->selection_color(TOGGLE_COLOR); + view_butt[i]->callback(set_changed_cb, 0); } - + view_3d->end(); } // 2D - { - view_2d = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "2D"); + { + view_2d = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, "2D"); view_2d->hide(); - - view_input[2] = new Fl_Input(2*WB, 2*WB+1*BH, IW, BH, "Abscissa name"); + + view_input[2] = + new Fl_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, "Abscissa name"); view_input[2]->align(FL_ALIGN_RIGHT); view_input[2]->callback(set_changed_cb, 0); - view_input[3] = new Fl_Input(2*WB, 2*WB+2*BH, IW, BH, "Abscissa format"); + view_input[3] = + new Fl_Input(2 * WB, 2 * WB + 2 * BH, IW, BH, "Abscissa format"); view_input[3]->align(FL_ALIGN_RIGHT); view_input[3]->callback(set_changed_cb, 0); - - view_value[25] = new Fl_Value_Input(2*WB, 2*WB+ 3*BH, IW, BH, "Abscissa points"); - view_value[25]->minimum(0.); - view_value[25]->step(1); - view_value[25]->maximum(256); - view_value[26] = new Fl_Value_Input(2*WB, 2*WB+ 4*BH, IW, BH, "Grid mode"); - view_value[26]->minimum(0.); - view_value[26]->step(1); - view_value[26]->maximum(3); - for(i=25 ; i<=26 ; i++){ - view_value[i]->align(FL_ALIGN_RIGHT); - view_value[i]->callback(set_changed_cb, 0); + + view_value[25] = + new Fl_Value_Input(2 * WB, 2 * WB + 3 * BH, IW, BH, + "Abscissa points"); + view_value[25]->minimum(0.); + view_value[25]->step(1); + view_value[25]->maximum(256); + view_value[26] = + new Fl_Value_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, "Grid mode"); + view_value[26]->minimum(0.); + view_value[26]->step(1); + view_value[26]->maximum(3); + for(i = 25; i <= 26; i++) { + view_value[i]->align(FL_ALIGN_RIGHT); + view_value[i]->callback(set_changed_cb, 0); } - + view_2d->end(); } // Range - { - view_range = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Range"); + { + view_range = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Range"); view_range->hide(); - - view_value[30] = new Fl_Value_Input(2*WB, 2*WB+1*BH, IW, BH, "Intervals"); + + view_value[30] = + new Fl_Value_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, "Intervals"); view_value[30]->align(FL_ALIGN_RIGHT); - view_value[30]->minimum(1); - view_value[30]->maximum(256); + view_value[30]->minimum(1); + view_value[30]->maximum(256); view_value[30]->step(1); view_value[30]->callback(set_changed_cb, 0); static Fl_Menu_Item menu_iso[] = { - {"Iso-values", 0, 0, 0}, - {"Filled iso-values", 0, 0, 0}, - {"Continuous map", 0, 0, 0}, - {"Numeric values", 0, 0, 0}, - {0} + {"Iso-values", 0, 0, 0}, + {"Filled iso-values", 0, 0, 0}, + {"Continuous map", 0, 0, 0}, + {"Numeric values", 0, 0, 0}, + {0} }; - view_choice[0] = new Fl_Choice(2*WB, 2*WB+2*BH, IW, BH, "Intervals type"); + view_choice[0] = + new Fl_Choice(2 * WB, 2 * WB + 2 * BH, IW, BH, "Intervals type"); view_choice[0]->menu(menu_iso); view_choice[0]->align(FL_ALIGN_RIGHT); view_choice[0]->callback(set_changed_cb, 0); - view_butt[34] = new Fl_Check_Button(2*WB, 2*WB+3*BH, IW, BH, "Custom range"); + view_butt[34] = + new Fl_Check_Button(2 * WB, 2 * WB + 3 * BH, IW, BH, "Custom range"); view_butt[34]->type(FL_TOGGLE_BUTTON); view_butt[34]->down_box(TOGGLE_BOX); view_butt[34]->selection_color(TOGGLE_COLOR); //no set_changed since customrange has its own callback - - view_value[31] = new Fl_Value_Input(2*WB, 2*WB+4*BH, IW, BH, "Minimum"); - view_value[32] = new Fl_Value_Input(2*WB, 2*WB+5*BH, IW, BH, "Maximum"); - for(i=31 ; i<=32 ; i++){ - view_value[i]->align(FL_ALIGN_RIGHT); - view_value[i]->callback(set_changed_cb, 0); + + view_value[31] = + new Fl_Value_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, "Minimum"); + view_value[32] = + new Fl_Value_Input(2 * WB, 2 * WB + 5 * BH, IW, BH, "Maximum"); + for(i = 31; i <= 32; i++) { + view_value[i]->align(FL_ALIGN_RIGHT); + view_value[i]->callback(set_changed_cb, 0); } static Fl_Menu_Item menu_scale[] = { - {"Linear", 0, 0, 0}, - {"Logarithmic", 0, 0, 0}, - {"Double logarithmic", 0, 0, 0}, - {0} + {"Linear", 0, 0, 0}, + {"Logarithmic", 0, 0, 0}, + {"Double logarithmic", 0, 0, 0}, + {0} }; - view_choice[1] = new Fl_Choice(2*WB, 2*WB+6*BH, IW, BH, "Scale"); + view_choice[1] = + new Fl_Choice(2 * WB, 2 * WB + 6 * BH, IW, BH, "Scale"); view_choice[1]->menu(menu_scale); view_choice[1]->align(FL_ALIGN_RIGHT); view_choice[1]->callback(set_changed_cb, 0); - - view_butt[38] = new Fl_Check_Button(2*WB, 2*WB+7*BH, IW, BH, "Saturate values"); + + view_butt[38] = + new Fl_Check_Button(2 * WB, 2 * WB + 7 * BH, IW, BH, + "Saturate values"); view_butt[38]->type(FL_TOGGLE_BUTTON); view_butt[38]->down_box(TOGGLE_BOX); view_butt[38]->selection_color(TOGGLE_COLOR); view_butt[38]->callback(set_changed_cb, 0); - + view_range->end(); } // Offset and Raise - { - Fl_Group *o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Offset"); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Offset"); o->hide(); - view_value[40] = new Fl_Value_Input(2*WB, 2*WB+1*BH, IW, BH, "X offset"); - view_value[41] = new Fl_Value_Input(2*WB, 2*WB+2*BH, IW, BH, "Y offset"); - view_value[42] = new Fl_Value_Input(2*WB, 2*WB+3*BH, IW, BH, "Z offset"); - view_value[43] = new Fl_Value_Input(width/2, 2*WB+1*BH, IW, BH, "X raise"); - view_value[44] = new Fl_Value_Input(width/2, 2*WB+2*BH, IW, BH, "Y raise"); - view_value[45] = new Fl_Value_Input(width/2, 2*WB+3*BH, IW, BH, "Z raise"); - for(i=40 ; i<=45 ; i++){ - view_value[i]->align(FL_ALIGN_RIGHT); - view_value[i]->callback(set_changed_cb, 0); - } + view_value[40] = + new Fl_Value_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, "X offset"); + view_value[41] = + new Fl_Value_Input(2 * WB, 2 * WB + 2 * BH, IW, BH, "Y offset"); + view_value[42] = + new Fl_Value_Input(2 * WB, 2 * WB + 3 * BH, IW, BH, "Z offset"); + view_value[43] = + new Fl_Value_Input(width / 2, 2 * WB + 1 * BH, IW, BH, "X raise"); + view_value[44] = + new Fl_Value_Input(width / 2, 2 * WB + 2 * BH, IW, BH, "Y raise"); + view_value[45] = + new Fl_Value_Input(width / 2, 2 * WB + 3 * BH, IW, BH, "Z raise"); + for(i = 40; i <= 45; i++) { + view_value[i]->align(FL_ALIGN_RIGHT); + view_value[i]->callback(set_changed_cb, 0); + } o->end(); } // Aspect - { - Fl_Group *o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB-BH, "Aspect"); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB - BH, + "Aspect"); o->hide(); - - view_value[61] = new Fl_Value_Input(2*WB, 2*WB+ 1*BH, IW, BH, "Point size"); - view_value[61]->minimum(0.1); + + view_value[61] = + new Fl_Value_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, "Point size"); + view_value[61]->minimum(0.1); view_value[61]->maximum(50); view_value[61]->step(0.1); view_value[61]->align(FL_ALIGN_RIGHT); view_value[61]->callback(set_changed_cb, 0); - view_choice[5] = new Fl_Choice(2*WB, 2*WB+ 2*BH, IW, BH, "Point display"); + view_choice[5] = + new Fl_Choice(2 * WB, 2 * WB + 2 * BH, IW, BH, "Point display"); view_choice[5]->menu(menu_point_display); view_choice[5]->align(FL_ALIGN_RIGHT); view_choice[5]->callback(set_changed_cb, 0); - - view_value[62] = new Fl_Value_Input(2*WB, 2*WB+ 3*BH, IW, BH, "Line width"); - view_value[62]->minimum(0.1); + + view_value[62] = + new Fl_Value_Input(2 * WB, 2 * WB + 3 * BH, IW, BH, "Line width"); + view_value[62]->minimum(0.1); view_value[62]->maximum(50); view_value[62]->step(0.1); view_value[62]->align(FL_ALIGN_RIGHT); view_value[62]->callback(set_changed_cb, 0); - view_choice[6] = new Fl_Choice(2*WB, 2*WB+ 4*BH, IW, BH, "Line display"); + view_choice[6] = + new Fl_Choice(2 * WB, 2 * WB + 4 * BH, IW, BH, "Line display"); view_choice[6]->menu(menu_line_display); view_choice[6]->align(FL_ALIGN_RIGHT); view_choice[6]->callback(set_changed_cb, 0); { - view_vector = new Fl_Group(2*WB, 2*WB+ 4*BH, width/2, 5*BH, 0); - - view_value[60] = new Fl_Value_Input(2*WB, 2*WB+5*BH, IW, BH, "Vector size"); - view_value[60]->minimum(0); - view_value[60]->align(FL_ALIGN_RIGHT); - view_value[60]->callback(set_changed_cb, 0); - - static Fl_Menu_Item menu_vectype[] = { - {"Line", 0, 0, 0}, - {"Arrow", 0, 0, 0}, - {"Pyramid", 0, 0, 0}, - {"Cone", 0, 0, 0}, - {"Displacement", 0, 0, 0}, - {0} - }; - view_choice[2] = new Fl_Choice(2*WB, 2*WB+6*BH, IW, BH, "Vector display"); - view_choice[2]->menu(menu_vectype); - view_choice[2]->align(FL_ALIGN_RIGHT); - view_choice[2]->callback(set_changed_cb, 0); - - static Fl_Menu_Item menu_vecloc[] = { - {"Cell centered", 0, 0, 0}, - {"Vertex centered", 0, 0, 0}, - {0} - }; - view_choice[3] = new Fl_Choice(2*WB, 2*WB+7*BH, IW, BH, "Vector location"); - view_choice[3]->menu(menu_vecloc); - view_choice[3]->align(FL_ALIGN_RIGHT); - view_choice[3]->callback(set_changed_cb, 0); - - static Fl_Menu_Item menu_tensor[] = { - {"Von-Mises", 0, 0, 0}, - //{"Eigenvectors", 0, 0, 0}, //not implemented yet - {0} - }; - view_choice[4] = new Fl_Choice(2*WB, 2*WB+8*BH, IW, BH, "Tensor display"); - view_choice[4]->menu(menu_tensor); - view_choice[4]->align(FL_ALIGN_RIGHT); - view_choice[4]->callback(set_changed_cb, 0); - - view_vector->end(); + view_vector = + new Fl_Group(2 * WB, 2 * WB + 4 * BH, width / 2, 5 * BH, 0); + + view_value[60] = + new Fl_Value_Input(2 * WB, 2 * WB + 5 * BH, IW, BH, "Vector size"); + view_value[60]->minimum(0); + view_value[60]->align(FL_ALIGN_RIGHT); + view_value[60]->callback(set_changed_cb, 0); + + static Fl_Menu_Item menu_vectype[] = { + {"Line", 0, 0, 0}, + {"Arrow", 0, 0, 0}, + {"Pyramid", 0, 0, 0}, + {"Cone", 0, 0, 0}, + {"Displacement", 0, 0, 0}, + {0} + }; + view_choice[2] = + new Fl_Choice(2 * WB, 2 * WB + 6 * BH, IW, BH, "Vector display"); + view_choice[2]->menu(menu_vectype); + view_choice[2]->align(FL_ALIGN_RIGHT); + view_choice[2]->callback(set_changed_cb, 0); + + static Fl_Menu_Item menu_vecloc[] = { + {"Cell centered", 0, 0, 0}, + {"Vertex centered", 0, 0, 0}, + {0} + }; + view_choice[3] = + new Fl_Choice(2 * WB, 2 * WB + 7 * BH, IW, BH, "Vector location"); + view_choice[3]->menu(menu_vecloc); + view_choice[3]->align(FL_ALIGN_RIGHT); + view_choice[3]->callback(set_changed_cb, 0); + + static Fl_Menu_Item menu_tensor[] = { + {"Von-Mises", 0, 0, 0}, + //{"Eigenvectors", 0, 0, 0}, //not implemented yet + {0} + }; + view_choice[4] = + new Fl_Choice(2 * WB, 2 * WB + 8 * BH, IW, BH, "Tensor display"); + view_choice[4]->menu(menu_tensor); + view_choice[4]->align(FL_ALIGN_RIGHT); + view_choice[4]->callback(set_changed_cb, 0); + + view_vector->end(); } - + o->end(); } // Colors - { - Fl_Group *o = new Fl_Group(WB, WB+BH, width-2*WB, height-2*WB, "Colors"); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 2 * WB, "Colors"); o->hide(); - view_colorbar_window = new Colorbar_Window(2*WB, 2*WB+BH, width-4*WB, height-4*WB-BH); + view_colorbar_window = + new Colorbar_Window(2 * WB, 2 * WB + BH, width - 4 * WB, + height - 4 * WB - BH); view_colorbar_window->end(); //no set_changed since colorbarwindow has its own callbacks o->end(); } o->end(); } - + view_window->end(); - + opt_window->position(CTX.opt_position[0], CTX.opt_position[1]); opt_window->end(); } -void GUI::update_view_window(int num){ +void GUI::update_view_window(int num) +{ int i; double val; - view_number = num ; - Post_View *v = (Post_View*)List_Pointer(CTX.post.list, num); + view_number = num; + Post_View *v = (Post_View *) List_Pointer(CTX.post.list, num); // general opt_view_name(num, GMSH_GUI, NULL); @@ -2091,11 +2479,11 @@ void GUI::update_view_window(int num){ opt_view_draw_strings(num, GMSH_GUI, 0); opt_view_transparent_scale(num, GMSH_GUI, 0); opt_view_auto_position(num, GMSH_GUI, 0); - if(v->NbSP){ + if(v->NbSP) { view_butt[2]->activate(); view_butt[3]->activate(); } - else{ + else { view_butt[2]->deactivate(); view_butt[3]->deactivate(); } @@ -2105,12 +2493,12 @@ void GUI::update_view_window(int num){ opt_view_size1(num, GMSH_GUI, 0); //3D - if(v->TextOnly){ + if(v->TextOnly) { view_3d->deactivate(); view_range->deactivate(); view_butt[1]->deactivate(); } - else{ + else { view_3d->activate(); view_range->activate(); view_butt[1]->activate(); @@ -2147,14 +2535,14 @@ void GUI::update_view_window(int num){ opt_view_nb_iso(num, GMSH_GUI, 0); opt_view_intervals_type(num, GMSH_GUI, 0); opt_view_range_type(num, GMSH_GUI, 0); - view_butt[34]->callback(view_options_custom_cb, (void*)num); - view_options_custom_cb(0,0); + view_butt[34]->callback(view_options_custom_cb, (void *)num); + view_options_custom_cb(0, 0); view_butt[34]->clear_changed(); opt_view_custom_min(num, GMSH_GUI, 0); opt_view_custom_max(num, GMSH_GUI, 0); - for(i=31 ; i<=32 ; i++){ - view_value[i]->minimum(v->CustomMin); - view_value[i]->maximum(v->CustomMax); + for(i = 31; i <= 32; i++) { + view_value[i]->minimum(v->CustomMin); + view_value[i]->maximum(v->CustomMax); } opt_view_scale_type(num, GMSH_GUI, 0); opt_view_saturate_values(num, GMSH_GUI, 0); @@ -2166,36 +2554,38 @@ void GUI::update_view_window(int num){ opt_view_raise0(num, GMSH_GUI, 0); opt_view_raise1(num, GMSH_GUI, 0); opt_view_raise2(num, GMSH_GUI, 0); - val = 10.*CTX.lc ; - for(i=40 ; i<=45 ; i++){ - view_value[i]->step(val,1000); - view_value[i]->minimum(-val); - view_value[i]->maximum(val); + val = 10. * CTX.lc; + for(i = 40; i <= 45; i++) { + view_value[i]->step(val, 1000); + view_value[i]->minimum(-val); + view_value[i]->maximum(val); } // timestep - if(v->NbTimeStep==1){ + if(v->NbTimeStep == 1) { view_value[50]->deactivate(); view_butt_rep[0]->deactivate(); view_butt_rep[1]->deactivate(); view_butt[8]->deactivate(); } - else{ + else { view_value[50]->activate(); view_butt_rep[0]->activate(); view_butt_rep[1]->activate(); view_butt[8]->activate(); } - view_value[50]->callback(view_options_timestep_cb, (void*)num); - view_value[50]->maximum(v->NbTimeStep-1); - view_butt_rep[0]->callback(view_options_timestep_decr_cb, (void*)num); - view_butt_rep[1]->callback(view_options_timestep_incr_cb, (void*)num); + view_value[50]->callback(view_options_timestep_cb, (void *)num); + view_value[50]->maximum(v->NbTimeStep - 1); + view_butt_rep[0]->callback(view_options_timestep_decr_cb, (void *)num); + view_butt_rep[1]->callback(view_options_timestep_incr_cb, (void *)num); opt_view_timestep(num, GMSH_GUI, 0); opt_view_show_time(num, GMSH_GUI, 0); // aspect - if(v->ScalarOnly) view_vector->deactivate(); - else view_vector->activate(); + if(v->ScalarOnly) + view_vector->deactivate(); + else + view_vector->activate(); opt_view_point_size(num, GMSH_GUI, 0); opt_view_point_type(num, GMSH_GUI, 0); opt_view_line_width(num, GMSH_GUI, 0); @@ -2212,141 +2602,221 @@ void GUI::update_view_window(int num){ // Create the window for the statistics -void GUI::create_statistics_window(){ - int i, num=0; +void GUI::create_statistics_window() +{ + int i, num = 0; - if(stat_window){ - if(!stat_window->shown()) set_statistics(); + if(stat_window) { + if(!stat_window->shown()) + set_statistics(); stat_window->show(); return; } - int width = 26*fontsize; - int height = 5*WB+17*BH ; - - stat_window = new Fl_Window(width,height,"Statistics"); + int width = 26 * fontsize; + int height = 5 * WB + 17 * BH; + + stat_window = new Fl_Window(width, height, "Statistics"); stat_window->box(WINDOW_BOX); { - Fl_Tabs* o = new Fl_Tabs(WB, WB, width-2*WB, height-3*WB-BH); - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-3*WB-2*BH, "Geometry"); + Fl_Tabs *o = new Fl_Tabs(WB, WB, width - 2 * WB, height - 3 * WB - BH); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, + "Geometry"); o->hide(); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+1*BH, IW, BH, "Points"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+2*BH, IW, BH, "Curves"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+3*BH, IW, BH, "Surfaces"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+4*BH, IW, BH, "Volumes"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 1 * BH, IW, BH, "Points"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 2 * BH, IW, BH, "Curves"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 3 * BH, IW, BH, "Surfaces"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 4 * BH, IW, BH, "Volumes"); o->end(); } - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-3*WB-2*BH, "Mesh"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+1*BH, IW, BH, "Nodes on curves"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+2*BH, IW, BH, "Nodes on surfaces"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+3*BH, IW, BH, "Nodes in volumes"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+4*BH, IW, BH, "Triangles"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+5*BH, IW, BH, "Quadrangles"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+6*BH, IW, BH, "Tetrahedra"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+7*BH, IW, BH, "Hexahedra"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+8*BH, IW, BH, "Prisms"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+9*BH, IW, BH, "Pyramids"); - - stat_value[num++] = new Fl_Output(2*WB, 2*WB+10*BH, IW, BH, "Time for 1D mesh"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+11*BH, IW, BH, "Time for 2D mesh"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+12*BH, IW, BH, "Time for 3D mesh"); - - stat_value[num++] = new Fl_Output(2*WB, 2*WB+13*BH, IW, BH, "Gamma factor"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+14*BH, IW, BH, "Eta factor"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+15*BH, IW, BH, "Rho factor"); - - Fl_Button* b0 = new Fl_Button(width-BB-2*WB, 2*WB+13*BH, BB, BH, "Graph"); - b0->callback(statistics_histogram_cb, (void*)0); - Fl_Button* b1 = new Fl_Button(width-BB-2*WB, 2*WB+14*BH, BB, BH, "Graph"); - b1->callback(statistics_histogram_cb, (void*)1); - Fl_Button* b2 = new Fl_Button(width-BB-2*WB, 2*WB+15*BH, BB, BH, "Graph"); - b2->callback(statistics_histogram_cb, (void*)2); - + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, + "Mesh"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 1 * BH, IW, BH, "Nodes on curves"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 2 * BH, IW, BH, "Nodes on surfaces"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 3 * BH, IW, BH, "Nodes in volumes"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 4 * BH, IW, BH, "Triangles"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 5 * BH, IW, BH, "Quadrangles"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 6 * BH, IW, BH, "Tetrahedra"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 7 * BH, IW, BH, "Hexahedra"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 8 * BH, IW, BH, "Prisms"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 9 * BH, IW, BH, "Pyramids"); + + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 10 * BH, IW, BH, "Time for 1D mesh"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 11 * BH, IW, BH, "Time for 2D mesh"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 12 * BH, IW, BH, "Time for 3D mesh"); + + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 13 * BH, IW, BH, "Gamma factor"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 14 * BH, IW, BH, "Eta factor"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 15 * BH, IW, BH, "Rho factor"); + + Fl_Button *b0 = + new Fl_Button(width - BB - 2 * WB, 2 * WB + 13 * BH, BB, BH, "Graph"); + b0->callback(statistics_histogram_cb, (void *)0); + Fl_Button *b1 = + new Fl_Button(width - BB - 2 * WB, 2 * WB + 14 * BH, BB, BH, "Graph"); + b1->callback(statistics_histogram_cb, (void *)1); + Fl_Button *b2 = + new Fl_Button(width - BB - 2 * WB, 2 * WB + 15 * BH, BB, BH, "Graph"); + b2->callback(statistics_histogram_cb, (void *)2); + o->end(); } - { - Fl_Group* o = new Fl_Group(WB, WB+BH, width-2*WB, height-3*WB-2*BH, "Post-processing"); + { + Fl_Group *o = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, + "Post-processing"); o->hide(); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+1*BH, IW, BH, "Views"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+2*BH, IW, BH, "Visible points"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+3*BH, IW, BH, "Visible lines"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+4*BH, IW, BH, "Visible triangles"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+5*BH, IW, BH, "Visible quadrangles"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+6*BH, IW, BH, "Visible tetrahedra"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+7*BH, IW, BH, "Visible hexahedra"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+8*BH, IW, BH, "Visible prisms"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+9*BH, IW, BH, "Visible pyramids"); - stat_value[num++] = new Fl_Output(2*WB, 2*WB+10*BH, IW, BH, "Visible strings"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 1 * BH, IW, BH, "Views"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 2 * BH, IW, BH, "Visible points"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 3 * BH, IW, BH, "Visible lines"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 4 * BH, IW, BH, "Visible triangles"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 5 * BH, IW, BH, "Visible quadrangles"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 6 * BH, IW, BH, "Visible tetrahedra"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 7 * BH, IW, BH, "Visible hexahedra"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 8 * BH, IW, BH, "Visible prisms"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 9 * BH, IW, BH, "Visible pyramids"); + stat_value[num++] = + new Fl_Output(2 * WB, 2 * WB + 10 * BH, IW, BH, "Visible strings"); o->end(); } o->end(); } - - for(i=0 ; i<num ; i++){ + + for(i = 0; i < num; i++) { stat_value[i]->align(FL_ALIGN_RIGHT); stat_value[i]->value(0); } - - { - Fl_Return_Button* o = new Fl_Return_Button(width-2*BB-2*WB, height-BH-WB, BB, BH, "Update"); + + { + Fl_Return_Button *o = + new Fl_Return_Button(width - 2 * BB - 2 * WB, height - BH - WB, BB, BH, + "Update"); o->callback(statistics_update_cb); } - { - Fl_Button* o = new Fl_Button(width-BB-WB, height-BH-WB, BB, BH, "Cancel"); - o->callback(cancel_cb, (void*)stat_window); + { + Fl_Button *o = + new Fl_Button(width - BB - WB, height - BH - WB, BB, BH, "Cancel"); + o->callback(cancel_cb, (void *)stat_window); } - + stat_window->position(CTX.stat_position[0], CTX.stat_position[1]); stat_window->end(); } -void GUI::set_statistics(){ +void GUI::set_statistics() +{ - int i,num=0; - static double s[50], p[20]; - static char label[50][256]; + int i, num = 0; + static double s[50], p[20]; + static char label[50][256]; GetStatistics(s); // geom - sprintf(label[num], "%g", s[0]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g", s[1]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g", s[2]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g", s[3]); stat_value[num]->value(label[num]); num++; + sprintf(label[num], "%g", s[0]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g", s[1]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g", s[2]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g", s[3]); + stat_value[num]->value(label[num]); + num++; // mesh - sprintf(label[num], "%g", s[4]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g", s[5]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g", s[6]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g", s[7]-s[8]); - stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g", s[8]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g", s[9]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g", s[10]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g", s[11]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g", s[12]); stat_value[num]->value(label[num]); num++; - - sprintf(label[num], "%g", s[13]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g", s[14]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g", s[15]); stat_value[num]->value(label[num]); num++; - - sprintf(label[num], "%.4g (%.4g->%.4g)", s[17], s[19], s[18]); - stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%.4g (%.4g->%.4g)", s[20], s[22], s[21]); - stat_value[num]->value(label[num]); num++; + sprintf(label[num], "%g", s[4]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g", s[5]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g", s[6]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g", s[7] - s[8]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g", s[8]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g", s[9]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g", s[10]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g", s[11]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g", s[12]); + stat_value[num]->value(label[num]); + num++; + + sprintf(label[num], "%g", s[13]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g", s[14]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g", s[15]); + stat_value[num]->value(label[num]); + num++; + + sprintf(label[num], "%.4g (%.4g->%.4g)", s[17], s[19], s[18]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%.4g (%.4g->%.4g)", s[20], s[22], s[21]); + stat_value[num]->value(label[num]); + num++; sprintf(label[num], "%.4g (%.4g->%.4g)", s[23], s[25], s[24]); - stat_value[num]->value(label[num]); num++; + stat_value[num]->value(label[num]); + num++; // post - p[0] = List_Nbr(CTX.post.list) ; - sprintf(label[num], "%g", p[0]); stat_value[num]->value(label[num]); num++; - p[1] = p[2] = p[3] = p[4] = p[5] = p[6] = p[7] = p[8] = p[9] = 0 ; - p[10] = p[11] = p[12] = p[13] = p[14] = p[15] = p[16] = p[17] = p[18] = 0 ; - for(i=0 ; i<List_Nbr(CTX.post.list) ; i++){ - Post_View *v = (Post_View*)List_Pointer(CTX.post.list, i); + p[0] = List_Nbr(CTX.post.list); + sprintf(label[num], "%g", p[0]); + stat_value[num]->value(label[num]); + num++; + p[1] = p[2] = p[3] = p[4] = p[5] = p[6] = p[7] = p[8] = p[9] = 0; + p[10] = p[11] = p[12] = p[13] = p[14] = p[15] = p[16] = p[17] = p[18] = 0; + for(i = 0; i < List_Nbr(CTX.post.list); i++) { + Post_View *v = (Post_View *) List_Pointer(CTX.post.list, i); p[1] += v->NbSP + v->NbVP + v->NbTP; p[2] += v->NbSL + v->NbVL + v->NbTL; p[3] += v->NbST + v->NbVT + v->NbTT; @@ -2356,111 +2826,140 @@ void GUI::set_statistics(){ p[7] += v->NbSI + v->NbVI + v->NbTI; p[8] += v->NbSY + v->NbVY + v->NbTY; p[9] += v->NbT2 + v->NbT3; - if(v->Visible){ - if(v->DrawPoints) p[10] += (v->DrawScalars ? v->NbSP : 0) + - (v->DrawVectors ? v->NbVP : 0) + - (v->DrawTensors ? v->NbTP : 0) ; - if(v->DrawLines) p[11] += (v->DrawScalars ? v->NbSL : 0) + - (v->DrawVectors ? v->NbVL : 0) + - (v->DrawTensors ? v->NbTL : 0) ; - if(v->DrawTriangles) p[12] += (v->DrawScalars ? v->NbST : 0) + - (v->DrawVectors ? v->NbVT : 0) + - (v->DrawTensors ? v->NbTT : 0) ; - if(v->DrawQuadrangles) p[13] += (v->DrawScalars ? v->NbSQ : 0) + - (v->DrawVectors ? v->NbVQ : 0) + - (v->DrawTensors ? v->NbTQ : 0) ; - if(v->DrawTetrahedra) p[14] += (v->DrawScalars ? v->NbSS : 0) + - (v->DrawVectors ? v->NbVS : 0) + - (v->DrawTensors ? v->NbTS : 0) ; - if(v->DrawHexahedra) p[15] += (v->DrawScalars ? v->NbSH : 0) + - (v->DrawVectors ? v->NbVH : 0) + - (v->DrawTensors ? v->NbTH : 0) ; - if(v->DrawPrisms) p[16] += (v->DrawScalars ? v->NbSI : 0) + - (v->DrawVectors ? v->NbVI : 0) + - (v->DrawTensors ? v->NbTI : 0) ; - if(v->DrawPyramids) p[17] += (v->DrawScalars ? v->NbSY : 0) + - (v->DrawVectors ? v->NbVY : 0) + - (v->DrawTensors ? v->NbTY : 0) ; - if(v->DrawStrings) p[18] += v->NbT2 + v->NbT3 ; + if(v->Visible) { + if(v->DrawPoints) + p[10] += (v->DrawScalars ? v->NbSP : 0) + + (v->DrawVectors ? v->NbVP : 0) + (v->DrawTensors ? v->NbTP : 0); + if(v->DrawLines) + p[11] += (v->DrawScalars ? v->NbSL : 0) + + (v->DrawVectors ? v->NbVL : 0) + (v->DrawTensors ? v->NbTL : 0); + if(v->DrawTriangles) + p[12] += (v->DrawScalars ? v->NbST : 0) + + (v->DrawVectors ? v->NbVT : 0) + (v->DrawTensors ? v->NbTT : 0); + if(v->DrawQuadrangles) + p[13] += (v->DrawScalars ? v->NbSQ : 0) + + (v->DrawVectors ? v->NbVQ : 0) + (v->DrawTensors ? v->NbTQ : 0); + if(v->DrawTetrahedra) + p[14] += (v->DrawScalars ? v->NbSS : 0) + + (v->DrawVectors ? v->NbVS : 0) + (v->DrawTensors ? v->NbTS : 0); + if(v->DrawHexahedra) + p[15] += (v->DrawScalars ? v->NbSH : 0) + + (v->DrawVectors ? v->NbVH : 0) + (v->DrawTensors ? v->NbTH : 0); + if(v->DrawPrisms) + p[16] += (v->DrawScalars ? v->NbSI : 0) + + (v->DrawVectors ? v->NbVI : 0) + (v->DrawTensors ? v->NbTI : 0); + if(v->DrawPyramids) + p[17] += (v->DrawScalars ? v->NbSY : 0) + + (v->DrawVectors ? v->NbVY : 0) + (v->DrawTensors ? v->NbTY : 0); + if(v->DrawStrings) + p[18] += v->NbT2 + v->NbT3; } } - sprintf(label[num], "%g/%g", p[10],p[1]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g/%g", p[11],p[2]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g/%g", p[12],p[3]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g/%g", p[13],p[4]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g/%g", p[14],p[5]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g/%g", p[15],p[6]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g/%g", p[16],p[7]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g/%g", p[17],p[8]); stat_value[num]->value(label[num]); num++; - sprintf(label[num], "%g/%g", p[18],p[9]); stat_value[num]->value(label[num]); num++; + sprintf(label[num], "%g/%g", p[10], p[1]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g/%g", p[11], p[2]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g/%g", p[12], p[3]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g/%g", p[13], p[4]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g/%g", p[14], p[5]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g/%g", p[15], p[6]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g/%g", p[16], p[7]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g/%g", p[17], p[8]); + stat_value[num]->value(label[num]); + num++; + sprintf(label[num], "%g/%g", p[18], p[9]); + stat_value[num]->value(label[num]); + num++; } // Create the window for the plugins -void GUI::add_multiline_in_browser(Fl_Browser *o, char* prefix, char *str){ +void GUI::add_multiline_in_browser(Fl_Browser * o, char *prefix, char *str) +{ int start = 0, len; char *buff; - if(!str || !strlen(str) || !strcmp(str, "\n")){ + if(!str || !strlen(str) || !strcmp(str, "\n")) { o->add(""); return; } - for(unsigned int i=0 ; i<strlen(str) ; i++){ - if(i==strlen(str)-1 || str[i]=='\n'){ - len = i-start+(str[i]=='\n'?0:1); - buff = new char[len+strlen(prefix)+2]; + for(unsigned int i = 0; i < strlen(str); i++) { + if(i == strlen(str) - 1 || str[i] == '\n') { + len = i - start + (str[i] == '\n' ? 0 : 1); + buff = new char[len + strlen(prefix) + 2]; strcpy(buff, prefix); strncat(buff, &str[start], len); - buff[len+strlen(prefix)]='\0'; + buff[len + strlen(prefix)] = '\0'; o->add(buff); - start = i+1; + start = i + 1; } } } -PluginDialogBox * GUI::create_plugin_window(GMSH_Plugin *p){ - char buffer[1024],namep[1024],copyright[256],author[256],help[1024]; +PluginDialogBox *GUI::create_plugin_window(GMSH_Plugin * p) +{ + char buffer[1024], namep[1024], copyright[256], author[256], help[1024]; // get plugin info int n = p->getNbOptions(); p->getName(namep); - p->getInfos(author,copyright,help); + p->getInfos(author, copyright, help); // create window - int width = 20*fontsize; - int height = ((n>5?n:5)+2)*BH + 5*WB; + int width = 20 * fontsize; + int height = ((n > 5 ? n : 5) + 2) * BH + 5 * WB; PluginDialogBox *pdb = new PluginDialogBox; - pdb->main_window = new Fl_Window(width,height); + pdb->main_window = new Fl_Window(width, height); pdb->main_window->box(WINDOW_BOX); - sprintf(buffer,"%s Plugin",namep); - char *nbuffer = new char[strlen(buffer)+1]; - strcpy(nbuffer,buffer); + sprintf(buffer, "%s Plugin", namep); + char *nbuffer = new char[strlen(buffer) + 1]; + strcpy(nbuffer, buffer); pdb->main_window->label(nbuffer); - { - Fl_Tabs *o = new Fl_Tabs(WB, WB, width-2*WB, height-3*WB-1*BH); - { - Fl_Group *g = new Fl_Group(WB, WB+BH, width-2*WB, height-3*WB-2*BH, "Options"); - - if(n > 20)Msg(GERROR, "Plugin has too many parameters"); - - for(int i=0;i<n;i++){ - StringXNumber *sxn; - sxn = p->GetOption(i); - pdb->view_value[i] = new Fl_Value_Input(2*WB, 2*WB+(i+1)*BH, IW, BH, sxn->str); - pdb->view_value[i]->align(FL_ALIGN_RIGHT); - pdb->view_value[i]->value(sxn->def); + { + Fl_Tabs *o = + new Fl_Tabs(WB, WB, width - 2 * WB, height - 3 * WB - 1 * BH); + { + Fl_Group *g = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, + "Options"); + + if(n > 20) + Msg(GERROR, "Plugin has too many parameters"); + + for(int i = 0; i < n; i++) { + StringXNumber *sxn; + sxn = p->GetOption(i); + pdb->view_value[i] = + new Fl_Value_Input(2 * WB, 2 * WB + (i + 1) * BH, IW, BH, sxn->str); + pdb->view_value[i]->align(FL_ALIGN_RIGHT); + pdb->view_value[i]->value(sxn->def); } g->end(); } - { - Fl_Group *g = new Fl_Group(WB, WB+BH, width-2*WB, height-3*WB-2*BH, "About"); + { + Fl_Group *g = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, + "About"); - Fl_Browser *o = new Fl_Browser(2*WB, 2*WB+1*BH, width-4*WB, height-5*WB-2*BH); + Fl_Browser *o = new Fl_Browser(2 * WB, 2 * WB + 1 * BH, width - 4 * WB, + height - 5 * WB - 2 * BH); o->add(""); add_multiline_in_browser(o, "@c@b@.", namep); @@ -2469,89 +2968,104 @@ PluginDialogBox * GUI::create_plugin_window(GMSH_Plugin *p){ o->add(""); add_multiline_in_browser(o, "Author(s): ", author); add_multiline_in_browser(o, "Copyright: ", copyright); - + g->end(); } o->end(); } - pdb->run_button = new Fl_Return_Button(width-2*BB-2*WB, height-BH-WB, BB, BH, "Run"); + pdb->run_button = + new Fl_Return_Button(width - 2 * BB - 2 * WB, height - BH - WB, BB, BH, + "Run"); - Fl_Button* cancel = new Fl_Button(width-BB-WB, height-BH-WB, BB, BH, "Cancel"); - cancel->callback(cancel_cb, (void*)pdb->main_window); + Fl_Button *cancel = + new Fl_Button(width - BB - WB, height - BH - WB, BB, BH, "Cancel"); + cancel->callback(cancel_cb, (void *)pdb->main_window); - pdb->main_window->resizable(new Fl_Box(2*WB,2*WB+BH,10,10)); + pdb->main_window->resizable(new Fl_Box(2 * WB, 2 * WB + BH, 10, 10)); if(CTX.center_windows) - pdb->main_window->position(m_window->x()+m_window->w()/2-width/2, - m_window->y()+9*BH-height/2); + pdb->main_window->position(m_window->x() + m_window->w() / 2 - width / 2, + m_window->y() + 9 * BH - height / 2); - pdb->main_window->end(); + pdb->main_window->end(); return pdb; } // Create the window for the messages -void GUI::create_message_window(){ +void GUI::create_message_window() +{ - if(msg_window){ + if(msg_window) { if(msg_window->shown()) msg_window->redraw(); else msg_window->show(); return; } - + int width = CTX.msg_size[0]; int height = CTX.msg_size[1]; - - msg_window = new Fl_Window(width,height,"Messages"); + + msg_window = new Fl_Window(width, height, "Messages"); msg_window->box(WINDOW_BOX); - - msg_browser = new Fl_Browser(WB, WB, width-2*WB, height-3*WB-BH); + + msg_browser = new Fl_Browser(WB, WB, width - 2 * WB, height - 3 * WB - BH); msg_browser->textfont(FL_COURIER); msg_browser->type(FL_MULTI_BROWSER); msg_browser->callback(message_copy_cb); - - { - Fl_Return_Button* o = new Fl_Return_Button(width-3*BB-3*WB, height-BH-WB, BB, BH, "Save"); + + { + Fl_Return_Button *o = + new Fl_Return_Button(width - 3 * BB - 3 * WB, height - BH - WB, BB, BH, + "Save"); o->callback(message_save_cb); } - { - Fl_Button* o = new Fl_Button(width-2*BB-2*WB, height-BH-WB, BB, BH, "Clear"); + { + Fl_Button *o = + new Fl_Button(width - 2 * BB - 2 * WB, height - BH - WB, BB, BH, + "Clear"); o->callback(message_clear_cb); } - { - Fl_Button* o = new Fl_Button(width-BB-WB, height-BH-WB, BB, BH, "Cancel"); - o->callback(cancel_cb, (void*)msg_window); + { + Fl_Button *o = + new Fl_Button(width - BB - WB, height - BH - WB, BB, BH, "Cancel"); + o->callback(cancel_cb, (void *)msg_window); } - - msg_window->resizable(new Fl_Box(WB,WB, 100,10)); - msg_window->size_range(WB+100 + 3*BB+4*WB,100); - + + msg_window->resizable(new Fl_Box(WB, WB, 100, 10)); + msg_window->size_range(WB + 100 + 3 * BB + 4 * WB, 100); + msg_window->position(CTX.msg_position[0], CTX.msg_position[1]); msg_window->end(); - + } -void GUI::add_message(char *msg){ - for(int i=0 ; i<(int)strlen(msg) ; i++) if(msg[i]=='\n') msg[i] = ' '; - msg_browser->add(msg,0); +void GUI::add_message(char *msg) +{ + for(int i = 0; i < (int)strlen(msg); i++) + if(msg[i] == '\n') + msg[i] = ' '; + msg_browser->add(msg, 0); msg_browser->bottomline(msg_browser->size()); } -void GUI::save_message(char *filename){ +void GUI::save_message(char *filename) +{ FILE *fp; - if(!(fp = fopen(filename,"w"))) { - Msg(GERROR, "Unable to open file '%s'", filename); + if(!(fp = fopen(filename, "w"))) { + Msg(GERROR, "Unable to open file '%s'", filename); return; } - for(int i = 1 ; i<=msg_browser->size() ; i++){ - const char *c=msg_browser->text(i); - if(c[0]=='@') fprintf(fp, "%s\n", &c[3]); - else fprintf(fp, "%s\n", c); + for(int i = 1; i <= msg_browser->size(); i++) { + const char *c = msg_browser->text(i); + if(c[0] == '@') + fprintf(fp, "%s\n", &c[3]); + else + fprintf(fp, "%s\n", c); } Msg(INFO, "Log creation complete '%s'", filename); @@ -2559,109 +3073,132 @@ void GUI::save_message(char *filename){ fclose(fp); } -void GUI::fatal_error(char *filename){ +void GUI::fatal_error(char *filename) +{ fl_alert("A fatal error has occurred, which will force Gmsh to exit " - "(all messages have been saved in the error log file '%s')", filename); + "(all messages have been saved in the error log file '%s')", + filename); } // Create the visibility window -void GUI::reset_visibility(){ - if(vis_window){ +void GUI::reset_visibility() +{ + if(vis_window) { vis_browser->clear(); - if(vis_window->shown()) - visibility_cb(NULL,NULL); + if(vis_window->shown()) + visibility_cb(NULL, NULL); } } -void GUI::create_visibility_window(){ +void GUI::create_visibility_window() +{ - if(vis_window){ + if(vis_window) { vis_window->show(); return; } - static int cols[5] = {15,95,95,180,0}; + static int cols[5] = { 15, 95, 95, 180, 0 }; static Fl_Menu_Item type_table[] = { - {"Elementary", 0, (Fl_Callback *)visibility_cb}, - {"Physical", 0, (Fl_Callback *)visibility_cb}, + {"Elementary", 0, (Fl_Callback *) visibility_cb}, + {"Physical", 0, (Fl_Callback *) visibility_cb}, {0} }; static Fl_Menu_Item browser_mode_table[] = { - {"Geometry+Mesh", 0, (Fl_Callback *)visibility_cb}, - {"Geometry", 0, (Fl_Callback *)visibility_cb}, - {"Mesh", 0, (Fl_Callback *)visibility_cb}, + {"Geometry+Mesh", 0, (Fl_Callback *) visibility_cb}, + {"Geometry", 0, (Fl_Callback *) visibility_cb}, + {"Mesh", 0, (Fl_Callback *) visibility_cb}, {0} }; static Fl_Menu_Item input_mode_table[] = { - {"Node", 0, 0}, - {"Element", 0, 0}, - {"Point", 0, 0}, - {"Curve", 0, 0}, - {"Surface", 0, 0}, - {"Volume", 0, 0}, + {"Node", 0, 0}, + {"Element", 0, 0}, + {"Point", 0, 0}, + {"Curve", 0, 0}, + {"Surface", 0, 0}, + {"Volume", 0, 0}, {0} }; - int width = cols[0]+cols[1]+cols[2]+cols[3]+2*WB; - int height = 15*BH ; - - vis_window = new Fl_Window(width,height,"Visibility"); + int width = cols[0] + cols[1] + cols[2] + cols[3] + 2 * WB; + int height = 15 * BH; + + vis_window = new Fl_Window(width, height, "Visibility"); vis_window->box(WINDOW_BOX); - - int brw = width-2*WB; - vis_type = new Fl_Choice(1*WB,1*WB+0*BH,brw/3,BH); + int brw = width - 2 * WB; + + vis_type = new Fl_Choice(1 * WB, 1 * WB + 0 * BH, brw / 3, BH); vis_type->menu(type_table); - - vis_browser_mode = new Fl_Choice(2*WB+(brw-2*WB)/3,1*WB+0*BH,(brw-2*WB)/3,BH); + + vis_browser_mode = + new Fl_Choice(2 * WB + (brw - 2 * WB) / 3, 1 * WB + 0 * BH, + (brw - 2 * WB) / 3, BH); vis_browser_mode->menu(browser_mode_table); - - vis_butt[0] = new Fl_Check_Button(3*WB+2*(brw-2*WB)/3, 1*WB+0*BH, (brw-2*WB)/3, BH, "Recursive"); + + vis_butt[0] = + new Fl_Check_Button(3 * WB + 2 * (brw - 2 * WB) / 3, 1 * WB + 0 * BH, + (brw - 2 * WB) / 3, BH, "Recursive"); vis_butt[0]->type(FL_TOGGLE_BUTTON); vis_butt[0]->down_box(TOGGLE_BOX); vis_butt[0]->selection_color(TOGGLE_COLOR); vis_butt[0]->value(1); - Fl_Button* o0 = new Fl_Button(1*WB, 2*WB+1*BH, cols[0], BH, "*"); - o0->callback(visibility_sort_cb, (void*)0); + Fl_Button *o0 = new Fl_Button(1 * WB, 2 * WB + 1 * BH, cols[0], BH, "*"); + o0->callback(visibility_sort_cb, (void *)0); - Fl_Button* o1 = new Fl_Button(1*WB+cols[0], 2*WB+1*BH, cols[1], BH, "Type"); + Fl_Button *o1 = + new Fl_Button(1 * WB + cols[0], 2 * WB + 1 * BH, cols[1], BH, "Type"); //Fl_Box *a = new Fl_Box(FL_NO_BOX, 1*WB+15+cols[0]-15-20, 2*WB+1*BH, 15, BH, "@#UpArrow"); //a->labeltype(FL_SYMBOL_LABEL); - o1->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); - o1->callback(visibility_sort_cb, (void*)1); - - Fl_Button* o2 = new Fl_Button(1*WB+cols[0]+cols[1], 2*WB+1*BH, cols[2], BH, "Number"); - o2->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); - o2->callback(visibility_sort_cb, (void*)2); - - Fl_Button* o3 = new Fl_Button(1*WB+cols[0]+cols[1]+cols[2], 2*WB+1*BH, cols[3], BH, "Name"); - o3->align(FL_ALIGN_LEFT|FL_ALIGN_INSIDE); - o3->callback(visibility_sort_cb, (void*)3); - - vis_browser = new Fl_Browser(1*WB, 2*WB+2*BH, brw, height-5*WB-4*BH); + o1->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); + o1->callback(visibility_sort_cb, (void *)1); + + Fl_Button *o2 = + new Fl_Button(1 * WB + cols[0] + cols[1], 2 * WB + 1 * BH, cols[2], BH, + "Number"); + o2->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); + o2->callback(visibility_sort_cb, (void *)2); + + Fl_Button *o3 = + new Fl_Button(1 * WB + cols[0] + cols[1] + cols[2], 2 * WB + 1 * BH, + cols[3], BH, "Name"); + o3->align(FL_ALIGN_LEFT | FL_ALIGN_INSIDE); + o3->callback(visibility_sort_cb, (void *)3); + + vis_browser = + new Fl_Browser(1 * WB, 2 * WB + 2 * BH, brw, height - 5 * WB - 4 * BH); vis_browser->textfont(FL_COURIER); vis_browser->type(FL_MULTI_BROWSER); vis_browser->column_widths(cols); - vis_window->resizable(new Fl_Box(width-3*WB-2*BB-10,3*WB+2*BH+10, 10,10)); - vis_window->size_range(width, 5*BH+5*WB); + vis_window-> + resizable(new + Fl_Box(width - 3 * WB - 2 * BB - 10, 3 * WB + 2 * BH + 10, 10, + 10)); + vis_window->size_range(width, 5 * BH + 5 * WB); - vis_input = new Fl_Input(1*WB, height-2*WB-2*BH, (brw-2*WB)/3, BH); + vis_input = + new Fl_Input(1 * WB, height - 2 * WB - 2 * BH, (brw - 2 * WB) / 3, BH); vis_input->callback(visibility_number_cb); - vis_input->when(FL_WHEN_ENTER_KEY|FL_WHEN_NOT_CHANGED); + vis_input->when(FL_WHEN_ENTER_KEY | FL_WHEN_NOT_CHANGED); - vis_input_mode = new Fl_Choice(2*WB+(brw-2*WB)/3, height-2*WB-2*BH, (brw-2*WB)/3, BH); + vis_input_mode = + new Fl_Choice(2 * WB + (brw - 2 * WB) / 3, height - 2 * WB - 2 * BH, + (brw - 2 * WB) / 3, BH); vis_input_mode->menu(input_mode_table); - - { - Fl_Return_Button* o = new Fl_Return_Button(width-2*BB-2*WB, height-BH-WB, BB, BH, "Apply"); + + { + Fl_Return_Button *o = + new Fl_Return_Button(width - 2 * BB - 2 * WB, height - BH - WB, BB, BH, + "Apply"); o->callback(visibility_ok_cb); } - { - Fl_Button* o = new Fl_Button(width-BB-WB, height-BH-WB, BB, BH, "Cancel"); - o->callback(cancel_cb, (void*)vis_window); + { + Fl_Button *o = + new Fl_Button(width - BB - WB, height - BH - WB, BB, BH, "Cancel"); + o->callback(cancel_cb, (void *)vis_window); } vis_window->position(CTX.vis_position[0], CTX.vis_position[1]); @@ -2670,28 +3207,30 @@ void GUI::create_visibility_window(){ // Create the about window -void GUI::create_about_window(){ +void GUI::create_about_window() +{ char buffer[1024]; - if(about_window){ + if(about_window) { about_window->show(); return; } - int width = 40*fontsize; - int height = 10*BH ; - - about_window = new Fl_Window(width,height,"About Gmsh"); + int width = 40 * fontsize; + int height = 10 * BH; + + about_window = new Fl_Window(width, height, "About Gmsh"); about_window->box(WINDOW_BOX); - + { - Fl_Box *o = new Fl_Box(2*WB, WB, about_width, height-3*WB-BH); - about_bmp = new Fl_Bitmap(about_bits,about_width,about_height); + Fl_Box *o = new Fl_Box(2 * WB, WB, about_width, height - 3 * WB - BH); + about_bmp = new Fl_Bitmap(about_bits, about_width, about_height); about_bmp->label(o); } - + { - Fl_Browser *o = new Fl_Browser(WB+80, WB, width-2*WB-80, height-3*WB-BH); + Fl_Browser *o = + new Fl_Browser(WB + 80, WB, width - 2 * WB - 80, height - 3 * WB - BH); o->add(""); o->add("@c@b@.Gmsh"); o->add("@c@.A three-dimensional finite element mesh generator"); @@ -2707,244 +3246,341 @@ void GUI::create_about_window(){ o->add("@c@.Please send all questions and bug reports to"); o->add("@c@b@.gmsh@geuz.org"); o->add(""); - sprintf(buffer, "@c@.Version: %d.%d.%d", GMSH_MAJOR_VERSION, - GMSH_MINOR_VERSION, GMSH_PATCH_VERSION); o->add(buffer); - sprintf(buffer, "@c@.Build date: %s", GMSH_DATE); o->add(buffer); - sprintf(buffer, "@c@.Build OS: %s", GMSH_OS); o->add(buffer); + sprintf(buffer, "@c@.Version: %d.%d.%d", GMSH_MAJOR_VERSION, + GMSH_MINOR_VERSION, GMSH_PATCH_VERSION); + o->add(buffer); + sprintf(buffer, "@c@.Build date: %s", GMSH_DATE); + o->add(buffer); + sprintf(buffer, "@c@.Build OS: %s", GMSH_OS); + o->add(buffer); sprintf(buffer, "@c@.Graphical user interface toolkit: FLTK %d.%d.%d", - FL_MAJOR_VERSION, FL_MINOR_VERSION, FL_PATCH_VERSION); o->add(buffer); - sprintf(buffer, "@c@.Build host: %s", GMSH_HOST); o->add(buffer); - sprintf(buffer, "@c@.Packaged by: %s", GMSH_PACKAGER); o->add(buffer); + FL_MAJOR_VERSION, FL_MINOR_VERSION, FL_PATCH_VERSION); + o->add(buffer); + sprintf(buffer, "@c@.Build host: %s", GMSH_HOST); + o->add(buffer); + sprintf(buffer, "@c@.Packaged by: %s", GMSH_PACKAGER); + o->add(buffer); o->add(""); o->add("@c@.Visit http://www.geuz.org/gmsh/ for more information"); o->add(""); } - - { - Fl_Return_Button* o = new Fl_Return_Button(width-BB-WB, height-BH-WB, BB, BH, "OK"); - o->callback(cancel_cb, (void*)about_window); + + { + Fl_Return_Button *o = + new Fl_Return_Button(width - BB - WB, height - BH - WB, BB, BH, "OK"); + o->callback(cancel_cb, (void *)about_window); } - + if(CTX.center_windows) - about_window->position(m_window->x()+m_window->w()/2-width/2, - m_window->y()+9*BH-height/2); + about_window->position(m_window->x() + m_window->w() / 2 - width / 2, + m_window->y() + 9 * BH - height / 2); about_window->end(); - + } // Create the window for geometry context dependant definitions -void GUI::create_geometry_context_window(int num){ +void GUI::create_geometry_context_window(int num) +{ static Fl_Group *g[10]; int i; - if(context_geometry_window){ - for(i=0 ; i<6 ; i++) g[i]->hide(); + if(context_geometry_window) { + for(i = 0; i < 6; i++) + g[i]->hide(); g[num]->show(); context_geometry_window->show(); return; } - int width = 31*fontsize; - int height = 5*WB+9*BH ; - - context_geometry_window = new Fl_Window(width,height,"Contextual geometry definitions"); + int width = 31 * fontsize; + int height = 5 * WB + 9 * BH; + + context_geometry_window = + new Fl_Window(width, height, "Contextual geometry definitions"); context_geometry_window->box(WINDOW_BOX); - { - Fl_Tabs* o = new Fl_Tabs(WB, WB, width-2*WB, height-3*WB-BH); + { + Fl_Tabs *o = new Fl_Tabs(WB, WB, width - 2 * WB, height - 3 * WB - BH); // 0: Parameter - { - g[0] = new Fl_Group(WB, WB+BH, width-2*WB, height-3*WB-2*BH, "Parameter"); - context_geometry_input[0] = new Fl_Input (2*WB, 2*WB+1*BH, IW, BH, "Name"); - context_geometry_input[1] = new Fl_Input (2*WB, 2*WB+2*BH, IW, BH, "Value"); - for(i=0 ; i<2 ; i++){ - context_geometry_input[i]->align(FL_ALIGN_RIGHT); + { + g[0] = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, + "Parameter"); + context_geometry_input[0] = + new Fl_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, "Name"); + context_geometry_input[1] = + new Fl_Input(2 * WB, 2 * WB + 2 * BH, IW, BH, "Value"); + for(i = 0; i < 2; i++) { + context_geometry_input[i]->align(FL_ALIGN_RIGHT); } - { - Fl_Return_Button* o = new Fl_Return_Button(width-BB-2*WB, 2*WB+7*BH, BB, BH, "Add"); - o->callback(con_geometry_define_parameter_cb); + { + Fl_Return_Button *o = + new Fl_Return_Button(width - BB - 2 * WB, 2 * WB + 7 * BH, BB, BH, + "Add"); + o->callback(con_geometry_define_parameter_cb); } g[0]->end(); } // 1: Point - { - g[1] = new Fl_Group(WB, WB+BH, width-2*WB, height-3*WB-2*BH, "Point"); - context_geometry_input[2] = new Fl_Input (2*WB, 2*WB+1*BH, IW, BH, "X coordinate"); - context_geometry_input[3] = new Fl_Input (2*WB, 2*WB+2*BH, IW, BH, "Y coordinate"); - context_geometry_input[4] = new Fl_Input (2*WB, 2*WB+3*BH, IW, BH, "Z coordinate"); - context_geometry_input[5] = new Fl_Input (2*WB, 2*WB+4*BH, IW, BH, "Characteristic length"); - for(i=2 ; i<6 ; i++){ - context_geometry_input[i]->align(FL_ALIGN_RIGHT); + { + g[1] = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, + "Point"); + context_geometry_input[2] = + new Fl_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, "X coordinate"); + context_geometry_input[3] = + new Fl_Input(2 * WB, 2 * WB + 2 * BH, IW, BH, "Y coordinate"); + context_geometry_input[4] = + new Fl_Input(2 * WB, 2 * WB + 3 * BH, IW, BH, "Z coordinate"); + context_geometry_input[5] = + new Fl_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, + "Characteristic length"); + for(i = 2; i < 6; i++) { + context_geometry_input[i]->align(FL_ALIGN_RIGHT); } - { - Fl_Return_Button* o = new Fl_Return_Button(width-BB-2*WB, 2*WB+7*BH, BB, BH, "Add"); - o->callback(con_geometry_define_point_cb); + { + Fl_Return_Button *o = + new Fl_Return_Button(width - BB - 2 * WB, 2 * WB + 7 * BH, BB, BH, + "Add"); + o->callback(con_geometry_define_point_cb); } g[1]->end(); } // 2: Translation - { - g[2] = new Fl_Group(WB, WB+BH, width-2*WB, height-3*WB-2*BH, "Translation"); - context_geometry_input[6] = new Fl_Input (2*WB, 2*WB+1*BH, IW, BH, "X component"); - context_geometry_input[7] = new Fl_Input (2*WB, 2*WB+2*BH, IW, BH, "Y component"); - context_geometry_input[8] = new Fl_Input (2*WB, 2*WB+3*BH, IW, BH, "Z component"); - for(i=6 ; i<9 ; i++){ - context_geometry_input[i]->align(FL_ALIGN_RIGHT); + { + g[2] = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, + "Translation"); + context_geometry_input[6] = + new Fl_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, "X component"); + context_geometry_input[7] = + new Fl_Input(2 * WB, 2 * WB + 2 * BH, IW, BH, "Y component"); + context_geometry_input[8] = + new Fl_Input(2 * WB, 2 * WB + 3 * BH, IW, BH, "Z component"); + for(i = 6; i < 9; i++) { + context_geometry_input[i]->align(FL_ALIGN_RIGHT); } - { - Fl_Return_Button* o = new Fl_Return_Button(width-BB-2*WB, 2*WB+7*BH, BB, BH, "Set"); - o->callback(con_geometry_define_translation_cb); + { + Fl_Return_Button *o = + new Fl_Return_Button(width - BB - 2 * WB, 2 * WB + 7 * BH, BB, BH, + "Set"); + o->callback(con_geometry_define_translation_cb); } g[2]->end(); } // 3: Rotation - { - g[3] = new Fl_Group(WB, WB+BH, width-2*WB, height-3*WB-2*BH, "Rotation"); - context_geometry_input[9] = new Fl_Input (2*WB, 2*WB+1*BH, IW, BH, "X coordinate of an axis point"); - context_geometry_input[10] = new Fl_Input (2*WB, 2*WB+2*BH, IW, BH, "Y coordinate of an axis point"); - context_geometry_input[11] = new Fl_Input (2*WB, 2*WB+3*BH, IW, BH, "Z coordinate of an axis point"); - context_geometry_input[12] = new Fl_Input (2*WB, 2*WB+4*BH, IW, BH, "X component of direction"); - context_geometry_input[13] = new Fl_Input (2*WB, 2*WB+5*BH, IW, BH, "Y component of direction"); - context_geometry_input[14] = new Fl_Input (2*WB, 2*WB+6*BH, IW, BH, "Z component of direction"); - context_geometry_input[15] = new Fl_Input (2*WB, 2*WB+7*BH, IW, BH, "Angle in radians"); - for(i=9 ; i<16 ; i++){ - context_geometry_input[i]->align(FL_ALIGN_RIGHT); + { + g[3] = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, + "Rotation"); + context_geometry_input[9] = + new Fl_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, + "X coordinate of an axis point"); + context_geometry_input[10] = + new Fl_Input(2 * WB, 2 * WB + 2 * BH, IW, BH, + "Y coordinate of an axis point"); + context_geometry_input[11] = + new Fl_Input(2 * WB, 2 * WB + 3 * BH, IW, BH, + "Z coordinate of an axis point"); + context_geometry_input[12] = + new Fl_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, + "X component of direction"); + context_geometry_input[13] = + new Fl_Input(2 * WB, 2 * WB + 5 * BH, IW, BH, + "Y component of direction"); + context_geometry_input[14] = + new Fl_Input(2 * WB, 2 * WB + 6 * BH, IW, BH, + "Z component of direction"); + context_geometry_input[15] = + new Fl_Input(2 * WB, 2 * WB + 7 * BH, IW, BH, "Angle in radians"); + for(i = 9; i < 16; i++) { + context_geometry_input[i]->align(FL_ALIGN_RIGHT); } - { - Fl_Return_Button* o = new Fl_Return_Button(width-BB-2*WB, 2*WB+7*BH, BB, BH, "Set"); - o->callback(con_geometry_define_rotation_cb); + { + Fl_Return_Button *o = + new Fl_Return_Button(width - BB - 2 * WB, 2 * WB + 7 * BH, BB, BH, + "Set"); + o->callback(con_geometry_define_rotation_cb); } g[3]->end(); } // 4: Scale - { - g[4] = new Fl_Group(WB, WB+BH, width-2*WB, height-3*WB-2*BH, "Scale"); - context_geometry_input[16] = new Fl_Input (2*WB, 2*WB+1*BH, IW, BH, "X component of direction"); - context_geometry_input[17] = new Fl_Input (2*WB, 2*WB+2*BH, IW, BH, "Y component of direction"); - context_geometry_input[18] = new Fl_Input (2*WB, 2*WB+3*BH, IW, BH, "Z component of direction"); - context_geometry_input[19] = new Fl_Input (2*WB, 2*WB+4*BH, IW, BH, "Factor"); - for(i=16 ; i<20 ; i++){ - context_geometry_input[i]->align(FL_ALIGN_RIGHT); + { + g[4] = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, + "Scale"); + context_geometry_input[16] = + new Fl_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, + "X component of direction"); + context_geometry_input[17] = + new Fl_Input(2 * WB, 2 * WB + 2 * BH, IW, BH, + "Y component of direction"); + context_geometry_input[18] = + new Fl_Input(2 * WB, 2 * WB + 3 * BH, IW, BH, + "Z component of direction"); + context_geometry_input[19] = + new Fl_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, "Factor"); + for(i = 16; i < 20; i++) { + context_geometry_input[i]->align(FL_ALIGN_RIGHT); } - { - Fl_Return_Button* o = new Fl_Return_Button(width-BB-2*WB, 2*WB+7*BH, BB, BH, "Set"); - o->callback(con_geometry_define_scale_cb); + { + Fl_Return_Button *o = + new Fl_Return_Button(width - BB - 2 * WB, 2 * WB + 7 * BH, BB, BH, + "Set"); + o->callback(con_geometry_define_scale_cb); } g[4]->end(); } // 5: Symmetry - { - g[5] = new Fl_Group(WB, WB+BH, width-2*WB, height-3*WB-2*BH, "Symmetry"); - context_geometry_input[20] = new Fl_Input (2*WB, 2*WB+1*BH, IW, BH, "1st plane equation coefficient"); - context_geometry_input[21] = new Fl_Input (2*WB, 2*WB+2*BH, IW, BH, "2nd plane equation coefficient"); - context_geometry_input[22] = new Fl_Input (2*WB, 2*WB+3*BH, IW, BH, "3rd plane equation coefficient"); - context_geometry_input[23] = new Fl_Input (2*WB, 2*WB+4*BH, IW, BH, "4th plane equation coefficient"); - for(i=20 ; i<24 ; i++){ - context_geometry_input[i]->align(FL_ALIGN_RIGHT); + { + g[5] = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, + "Symmetry"); + context_geometry_input[20] = + new Fl_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, + "1st plane equation coefficient"); + context_geometry_input[21] = + new Fl_Input(2 * WB, 2 * WB + 2 * BH, IW, BH, + "2nd plane equation coefficient"); + context_geometry_input[22] = + new Fl_Input(2 * WB, 2 * WB + 3 * BH, IW, BH, + "3rd plane equation coefficient"); + context_geometry_input[23] = + new Fl_Input(2 * WB, 2 * WB + 4 * BH, IW, BH, + "4th plane equation coefficient"); + for(i = 20; i < 24; i++) { + context_geometry_input[i]->align(FL_ALIGN_RIGHT); } - { - Fl_Return_Button* o = new Fl_Return_Button(width-BB-2*WB, 2*WB+7*BH, BB, BH, "Set"); - o->callback(con_geometry_define_symmetry_cb); + { + Fl_Return_Button *o = + new Fl_Return_Button(width - BB - 2 * WB, 2 * WB + 7 * BH, BB, BH, + "Set"); + o->callback(con_geometry_define_symmetry_cb); } g[5]->end(); } o->end(); } - - { - Fl_Button* o = new Fl_Button(width-BB-WB, height-BH-WB, BB, BH, "Cancel"); - o->callback(cancel_cb, (void*)context_geometry_window); + + { + Fl_Button *o = + new Fl_Button(width - BB - WB, height - BH - WB, BB, BH, "Cancel"); + o->callback(cancel_cb, (void *)context_geometry_window); } - - for(i=0 ; i<6 ; i++) g[i]->hide(); + + for(i = 0; i < 6; i++) + g[i]->hide(); g[num]->show(); - + if(CTX.center_windows) - context_geometry_window->position(m_window->x()+m_window->w()/2-width/2, - m_window->y()+9*BH-height/2); + context_geometry_window->position(m_window->x() + m_window->w() / 2 - + width / 2, + m_window->y() + 9 * BH - height / 2); context_geometry_window->end(); context_geometry_window->show(); - + } // Create the window for mesh context dependant definitions -void GUI::create_mesh_context_window(int num){ +void GUI::create_mesh_context_window(int num) +{ static Fl_Group *g[10]; int i; - if(context_mesh_window){ - for(i=0 ; i<3 ; i++) g[i]->hide(); + if(context_mesh_window) { + for(i = 0; i < 3; i++) + g[i]->hide(); g[num]->show(); context_mesh_window->show(); return; } - int width = 31*fontsize; - int height = 5*WB+5*BH ; - - context_mesh_window = new Fl_Window(width,height,"Contextual mesh definitions"); + int width = 31 * fontsize; + int height = 5 * WB + 5 * BH; + + context_mesh_window = + new Fl_Window(width, height, "Contextual mesh definitions"); context_mesh_window->box(WINDOW_BOX); - { - Fl_Tabs* o = new Fl_Tabs(WB, WB, width-2*WB, height-3*WB-BH); + { + Fl_Tabs *o = new Fl_Tabs(WB, WB, width - 2 * WB, height - 3 * WB - BH); // 0: Characteristic length - { - g[0] = new Fl_Group(WB, WB+BH, width-2*WB, height-3*WB-2*BH, "Characteristic length"); - context_mesh_input[0] = new Fl_Input (2*WB, 2*WB+1*BH, IW, BH, "Value"); + { + g[0] = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, + "Characteristic length"); + context_mesh_input[0] = + new Fl_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, "Value"); context_mesh_input[0]->align(FL_ALIGN_RIGHT); - { - Fl_Return_Button* o = new Fl_Return_Button(width-BB-2*WB, 2*WB+3*BH, BB, BH, "Set"); - o->callback(con_mesh_define_length_cb); + { + Fl_Return_Button *o = + new Fl_Return_Button(width - BB - 2 * WB, 2 * WB + 3 * BH, BB, BH, + "Set"); + o->callback(con_mesh_define_length_cb); } g[0]->end(); } // 1: Transfinite line - { - g[1] = new Fl_Group(WB, WB+BH, width-2*WB, height-3*WB-2*BH, "Transfinite line"); - context_mesh_input[1] = new Fl_Input (2*WB, 2*WB+1*BH, IW, BH, "Number of points"); - context_mesh_input[2] = new Fl_Input (2*WB, 2*WB+2*BH, IW, BH); - for(i=1 ; i<3 ; i++){ - context_mesh_input[i]->align(FL_ALIGN_RIGHT); + { + g[1] = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, + "Transfinite line"); + context_mesh_input[1] = + new Fl_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, "Number of points"); + context_mesh_input[2] = new Fl_Input(2 * WB, 2 * WB + 2 * BH, IW, BH); + for(i = 1; i < 3; i++) { + context_mesh_input[i]->align(FL_ALIGN_RIGHT); } static Fl_Menu_Item menu_trsf_mesh[] = { - {"Progression", 0, 0, 0}, - {"Bump", 0, 0, 0}, - {0} + {"Progression", 0, 0, 0}, + {"Bump", 0, 0, 0}, + {0} }; - context_mesh_choice[0] = new Fl_Choice (2*WB+IW, 2*WB+2*BH, IW, BH); + context_mesh_choice[0] = + new Fl_Choice(2 * WB + IW, 2 * WB + 2 * BH, IW, BH); context_mesh_choice[0]->menu(menu_trsf_mesh); - { - Fl_Return_Button* o = new Fl_Return_Button(width-BB-2*WB, 2*WB+3*BH, BB, BH, "Set"); - o->callback(con_mesh_define_transfinite_line_cb); + { + Fl_Return_Button *o = + new Fl_Return_Button(width - BB - 2 * WB, 2 * WB + 3 * BH, BB, BH, + "Set"); + o->callback(con_mesh_define_transfinite_line_cb); } g[1]->end(); } // 2: Transfinite volume - { - g[2] = new Fl_Group(WB, WB+BH, width-2*WB, height-3*WB-2*BH, "Transfinite volume"); - context_mesh_input[3] = new Fl_Input (2*WB, 2*WB+1*BH, IW, BH, "Volume number"); + { + g[2] = + new Fl_Group(WB, WB + BH, width - 2 * WB, height - 3 * WB - 2 * BH, + "Transfinite volume"); + context_mesh_input[3] = + new Fl_Input(2 * WB, 2 * WB + 1 * BH, IW, BH, "Volume number"); context_mesh_input[3]->align(FL_ALIGN_RIGHT); - { - Fl_Return_Button* o = new Fl_Return_Button(width-BB-2*WB, 2*WB+3*BH, BB, BH, "Set"); - o->callback(con_mesh_define_transfinite_volume_cb); + { + Fl_Return_Button *o = + new Fl_Return_Button(width - BB - 2 * WB, 2 * WB + 3 * BH, BB, BH, + "Set"); + o->callback(con_mesh_define_transfinite_volume_cb); } g[2]->end(); } o->end(); } - - { - Fl_Button* o = new Fl_Button(width-BB-WB, height-BH-WB, BB, BH, "Cancel"); - o->callback(cancel_cb, (void*)context_mesh_window); + + { + Fl_Button *o = + new Fl_Button(width - BB - WB, height - BH - WB, BB, BH, "Cancel"); + o->callback(cancel_cb, (void *)context_mesh_window); } - - for(i=0 ; i<3 ; i++) g[i]->hide(); + + for(i = 0; i < 3; i++) + g[i]->hide(); g[num]->show(); - + if(CTX.center_windows) - context_mesh_window->position(m_window->x()+m_window->w()/2-width/2, - m_window->y()+9*BH-height/2); + context_mesh_window->position(m_window->x() + m_window->w() / 2 - + width / 2, + m_window->y() + 9 * BH - height / 2); context_mesh_window->end(); context_mesh_window->show(); } @@ -2952,134 +3588,171 @@ void GUI::create_mesh_context_window(int num){ // Create the windows for the solvers -void GUI::create_solver_window(int num){ - int i, nbbutts=0, newrow=0; +void GUI::create_solver_window(int num) +{ + int i, nbbutts = 0, newrow = 0; static Fl_Group *g[10]; - int LL = (int)(1.75*IW); - int BBS = (5*fontsize+1); // smaller width of a button with internal label + int LL = (int)(1.75 * IW); + int BBS = (5 * fontsize + 1); // smaller width of a button with internal label - if(solver[num].window){ + if(solver[num].window) { solver[num].window->show(); return; } - for(i=0; i<MAXSOLVERS; i++) - if(strlen(SINFO[num].option_name[i])) SINFO[num].nboptions = i+1; + for(i = 0; i < MAXSOLVERS; i++) + if(strlen(SINFO[num].option_name[i])) + SINFO[num].nboptions = i + 1; + + for(i = 0; i < MAXSOLVERS; i++) + if(strlen(SINFO[num].button_name[i])) + nbbutts++; + if(nbbutts > 3) + newrow = 1; - for(i=0; i<MAXSOLVERS; i++) - if(strlen(SINFO[num].button_name[i])) nbbutts++ ; - if(nbbutts > 3) newrow = 1; + int width = 5 * BBS + 6 * WB; + int height = + (8 + SINFO[num].nboptions + newrow) * WB + (6 + SINFO[num].nboptions + + newrow) * BH; + if(height < 7 * WB + 7 * BH) + height = 7 * WB + 7 * BH; //minimum height required by Options tab - int width = 5*BBS+6*WB; - int height = (8+SINFO[num].nboptions+newrow)*WB+ (6+SINFO[num].nboptions+newrow)*BH ; - if(height < 7*WB+7*BH) height = 7*WB+7*BH; //minimum height required by Options tab - - solver[num].window = new Fl_Window(width,height); + solver[num].window = new Fl_Window(width, height); solver[num].window->box(WINDOW_BOX); - { - Fl_Tabs* o = new Fl_Tabs(WB, WB, width-2*WB, height-(3+newrow)*WB-(1+newrow)*BH); - { - g[0] = new Fl_Group(WB, WB+BH, width-2*WB, height-(3+newrow)*WB-(2+newrow)*BH, "General"); - - solver[num].input[0] = new Fl_Input(2*WB, 2*WB+1*BH, LL, BH, "Problem"); - Fl_Button *b1 = new Fl_Button(2*WB, 3*WB+2*BH, BB, BH, "Choose"); - b1->callback(solver_file_open_cb, (void*)num); - Fl_Button *b2 = new Fl_Button(3*WB+BB, 3*WB+2*BH, BB, BH, "Edit"); - b2->callback(solver_file_edit_cb, (void*)num); - - solver[num].input[1] = new Fl_Input(2*WB, 4*WB+3*BH, LL, BH, "Mesh"); - Fl_Button *b3 = new Fl_Button(2*WB, 5*WB+4*BH, BB, BH, "Choose"); - b3->callback(solver_choose_mesh_cb, (void*)num); - - for(i=0 ; i<2 ; i++){ - solver[num].input[i]->align(FL_ALIGN_RIGHT); + { + Fl_Tabs *o = new Fl_Tabs(WB, WB, width - 2 * WB, + height - (3 + newrow) * WB - (1 + newrow) * BH); + { + g[0] = + new Fl_Group(WB, WB + BH, width - 2 * WB, + height - (3 + newrow) * WB - (2 + newrow) * BH, + "General"); + + solver[num].input[0] = + new Fl_Input(2 * WB, 2 * WB + 1 * BH, LL, BH, "Problem"); + Fl_Button *b1 = + new Fl_Button(2 * WB, 3 * WB + 2 * BH, BB, BH, "Choose"); + b1->callback(solver_file_open_cb, (void *)num); + Fl_Button *b2 = + new Fl_Button(3 * WB + BB, 3 * WB + 2 * BH, BB, BH, "Edit"); + b2->callback(solver_file_edit_cb, (void *)num); + + solver[num].input[1] = + new Fl_Input(2 * WB, 4 * WB + 3 * BH, LL, BH, "Mesh"); + Fl_Button *b3 = + new Fl_Button(2 * WB, 5 * WB + 4 * BH, BB, BH, "Choose"); + b3->callback(solver_choose_mesh_cb, (void *)num); + + for(i = 0; i < 2; i++) { + solver[num].input[i]->align(FL_ALIGN_RIGHT); } - for(i=0; i<SINFO[num].nboptions; i++){ - solver[num].choice[i] = new Fl_Choice(2*WB, (6+i)*WB+(5+i)*BH, LL, BH, - SINFO[num].option_name[i]); - solver[num].choice[i]->align(FL_ALIGN_RIGHT); + for(i = 0; i < SINFO[num].nboptions; i++) { + solver[num].choice[i] = + new Fl_Choice(2 * WB, (6 + i) * WB + (5 + i) * BH, LL, BH, + SINFO[num].option_name[i]); + solver[num].choice[i]->align(FL_ALIGN_RIGHT); } g[0]->end(); } - { - g[1] = new Fl_Group(WB, WB+BH, width-2*WB, height-(3+newrow)*WB-(2+newrow)*BH, "Options"); - - solver[num].input[2] = new Fl_Input(2*WB, 2*WB+1*BH, LL, BH, "Executable"); + { + g[1] = + new Fl_Group(WB, WB + BH, width - 2 * WB, + height - (3 + newrow) * WB - (2 + newrow) * BH, + "Options"); + + solver[num].input[2] = + new Fl_Input(2 * WB, 2 * WB + 1 * BH, LL, BH, "Executable"); solver[num].input[2]->align(FL_ALIGN_RIGHT); - Fl_Button *b = new Fl_Button(2*WB, 3*WB+2*BH, BB, BH, "Choose"); - b->callback(solver_choose_executable_cb, (void*)num); - - solver[num].butt[2] = new Fl_Check_Button(2*WB, 4*WB+3*BH, LL, BH, - "Client/server connection"); - solver[num].butt[0] = new Fl_Check_Button(2*WB, 4*WB+4*BH, LL, BH, - "Automatic message display"); - solver[num].butt[1] = new Fl_Check_Button(2*WB, 4*WB+5*BH, LL, BH, - "Automatic view merge"); - for(i=0 ; i<3 ; i++){ - solver[num].butt[i]->type(FL_TOGGLE_BUTTON); - solver[num].butt[i]->down_box(TOGGLE_BOX); - solver[num].butt[i]->selection_color(TOGGLE_COLOR); + Fl_Button *b = new Fl_Button(2 * WB, 3 * WB + 2 * BH, BB, BH, "Choose"); + b->callback(solver_choose_executable_cb, (void *)num); + + solver[num].butt[2] = + new Fl_Check_Button(2 * WB, 4 * WB + 3 * BH, LL, BH, + "Client/server connection"); + solver[num].butt[0] = + new Fl_Check_Button(2 * WB, 4 * WB + 4 * BH, LL, BH, + "Automatic message display"); + solver[num].butt[1] = + new Fl_Check_Button(2 * WB, 4 * WB + 5 * BH, LL, BH, + "Automatic view merge"); + for(i = 0; i < 3; i++) { + solver[num].butt[i]->type(FL_TOGGLE_BUTTON); + solver[num].butt[i]->down_box(TOGGLE_BOX); + solver[num].butt[i]->selection_color(TOGGLE_COLOR); } - - { - Fl_Return_Button* o = new Fl_Return_Button(width-2*BB-3*WB, - height-(3+newrow)*WB-(2+newrow)*BH, BB, BH, "Apply"); - o->callback(solver_ok_cb, (void*)num); + + { + Fl_Return_Button *o = new Fl_Return_Button(width - 2 * BB - 3 * WB, + height - (3 + + newrow) * WB - + (2 + newrow) * BH, BB, BH, + "Apply"); + o->callback(solver_ok_cb, (void *)num); } { - Fl_Button* o = new Fl_Button(width-BB-2*WB, - height-(3+newrow)*WB-(2+newrow)*BH, BB, BH, "Save"); - o->callback(options_save_cb); + Fl_Button *o = new Fl_Button(width - BB - 2 * WB, + height - (3 + newrow) * WB - (2 + + newrow) * + BH, + BB, BH, "Save"); + o->callback(options_save_cb); } g[1]->end(); } - { - g[2] = new Fl_Group(WB, WB+BH, width-2*WB, height-(3+newrow)*WB-(2+newrow)*BH, "About"); - - Fl_Browser *o = new Fl_Browser(2*WB, 2*WB+1*BH, width-4*WB, - height-(5+newrow)*WB-(2+newrow)*BH); + { + g[2] = + new Fl_Group(WB, WB + BH, width - 2 * WB, + height - (3 + newrow) * WB - (2 + newrow) * BH, "About"); + + Fl_Browser *o = new Fl_Browser(2 * WB, 2 * WB + 1 * BH, width - 4 * WB, + height - (5 + newrow) * WB - (2 + + newrow) * + BH); o->add(""); add_multiline_in_browser(o, "@c@b@.", SINFO[num].name); o->add(""); add_multiline_in_browser(o, "@c@. ", SINFO[num].help); - + g[2]->end(); } o->end(); } static int arg[MAXSOLVERS][5][2]; - int nb=0; - for(i=4; i>=0; i--){ - if(strlen(SINFO[num].button_name[i])){ - arg[num][i][0]=num; - arg[num][i][1]=i; - solver[num].command[nb] = new Fl_Button(width-(1+nb+2*!newrow)*BBS-(1+nb+2*!newrow)*WB, - height-(1+newrow)*BH-(1+newrow)*WB, - BBS, BH, - SINFO[num].button_name[i]); - solver[num].command[nb]->callback(solver_command_cb,(void*)arg[num][i]); + int nb = 0; + for(i = 4; i >= 0; i--) { + if(strlen(SINFO[num].button_name[i])) { + arg[num][i][0] = num; + arg[num][i][1] = i; + solver[num].command[nb] = + new Fl_Button(width - (1 + nb + 2 * !newrow) * BBS - + (1 + nb + 2 * !newrow) * WB, + height - (1 + newrow) * BH - (1 + newrow) * WB, BBS, BH, + SINFO[num].button_name[i]); + solver[num].command[nb]->callback(solver_command_cb, + (void *)arg[num][i]); nb++; } } - - { - Fl_Button* o = new Fl_Button(width-2*BBS-2*WB, height-BH-WB, BBS, BH, "Kill"); - o->callback(solver_kill_cb, (void*)num); + + { + Fl_Button *o = + new Fl_Button(width - 2 * BBS - 2 * WB, height - BH - WB, BBS, BH, + "Kill"); + o->callback(solver_kill_cb, (void *)num); } - { - Fl_Button* o = new Fl_Button(width-BBS-WB, height-BH-WB, BBS, BH, "Cancel"); - o->callback(cancel_cb, (void*)solver[num].window); + { + Fl_Button *o = + new Fl_Button(width - BBS - WB, height - BH - WB, BBS, BH, "Cancel"); + o->callback(cancel_cb, (void *)solver[num].window); } - + if(CTX.center_windows) - solver[num].window->position(m_window->x()+m_window->w()/2-width/2, - m_window->y()+9*BH-height/2); + solver[num].window->position(m_window->x() + m_window->w() / 2 - + width / 2, + m_window->y() + 9 * BH - height / 2); solver[num].window->end(); } - - - diff --git a/Fltk/GmshServer.cpp b/Fltk/GmshServer.cpp index 86f1387f4ffcf48306b3647ce3cb58b4f132d6cf..76b890ec20c7ccb24bb77c1920814e65add75161 100644 --- a/Fltk/GmshServer.cpp +++ b/Fltk/GmshServer.cpp @@ -1,4 +1,4 @@ -/* $Id: GmshServer.cpp,v 1.9 2003-01-24 23:13:34 geuzaine Exp $ */ +/* $Id: GmshServer.cpp,v 1.10 2003-03-01 22:36:38 geuzaine Exp $ */ /* Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle @@ -39,40 +39,44 @@ void SystemCall(char *str); /* private functions */ -static int Socket_ReceiveData(int socket, void *buffer, int bytes){ +static int Socket_ReceiveData(int socket, void *buffer, int bytes) +{ int sofar, remaining, len; char *buf; - buf = (char*)buffer; + buf = (char *)buffer; sofar = 0; remaining = bytes; do { len = read(socket, buf + sofar, remaining); - if (len<=0) return 0; + if(len <= 0) + return 0; sofar += len; remaining -= len; - } while (remaining>0); + } while(remaining > 0); return bytes; } -static int Socket_UnlinkName(char *name){ +static int Socket_UnlinkName(char *name) +{ #ifdef _AIX - char name2[1000]; - strcpy(name2,name); - name2[strlen(name2)-1] = '\0'; - return unlink(name2); + char name2[1000]; + strcpy(name2, name); + name2[strlen(name2) - 1] = '\0'; + return unlink(name2); #else - return unlink(name); + return unlink(name); #endif } /* public interface */ -int Gmsh_StartClient(char *command, char *sockname){ +int Gmsh_StartClient(char *command, char *sockname) +{ int s, sock; #if defined(linux) || defined(_AIX) - socklen_t len ; + socklen_t len; #else int len; #endif @@ -82,7 +86,7 @@ int Gmsh_StartClient(char *command, char *sockname){ int retval; /* no socket? launch the command! */ - if(!sockname){ + if(!sockname) { //system(command); SystemCall(command); return 1; @@ -90,64 +94,68 @@ int Gmsh_StartClient(char *command, char *sockname){ /* first delete the socket's name if it exists */ Socket_UnlinkName(sockname); - + /* make the socket */ s = socket(PF_UNIX, SOCK_STREAM, 0); - if (s<0) return -1; /* Error: Couldn't create socket */ - + if(s < 0) + return -1; /* Error: Couldn't create socket */ + /* bind the socket to its name */ strcpy(addr.sun_path, sockname); addr.sun_family = AF_UNIX; - if(bind(s, (struct sockaddr *)&addr, - strlen(addr.sun_path)+sizeof(addr.sun_family)) < 0) - return -2; /* Error: Couldn't bind socket to name */ - + if(bind(s, (struct sockaddr *)&addr, + strlen(addr.sun_path) + sizeof(addr.sun_family)) < 0) + return -2; /* Error: Couldn't bind socket to name */ + /* change permissions on the socket name in case it has to be rm'd later */ chmod(sockname, 0666); - + /* Start the external function via system() call */ //system(command); SystemCall(command); /* wait for external function to connect */ - if(listen(s, 20)) return -3; /* Error: Socket listen failed */ - + if(listen(s, 20)) + return -3; /* Error: Socket listen failed */ + /* Watch s to see when it has input. */ /* Wait up to 2 seconds */ tv.tv_sec = 2; tv.tv_usec = 0; FD_ZERO(&rfds); FD_SET(s, &rfds); - retval = select(s+1, &rfds, NULL, NULL, &tv); - - if(!retval) return -4; /* Error: Socket listening timeout */ - + retval = select(s + 1, &rfds, NULL, NULL, &tv); + + if(!retval) + return -4; /* Error: Socket listening timeout */ + len = sizeof(from); - if ((sock = accept(s, (struct sockaddr *)&from, &len)) < 0) - return -5; /* Error: Socket accept failed */ - - close(s); /* don't need this socket anymore */ - + if((sock = accept(s, (struct sockaddr *)&from, &len)) < 0) + return -5; /* Error: Socket accept failed */ + + close(s); /* don't need this socket anymore */ + return sock; } -int Gmsh_ReceiveString(int socket, int *type, char str[]){ - int len; - - Socket_ReceiveData(socket, type, sizeof(int)); - if (Socket_ReceiveData(socket, &len, sizeof(int))) { - if (Socket_ReceiveData(socket, str, len)==len) { - str[len] = '\0'; - return 1; - } - } - return 0; +int Gmsh_ReceiveString(int socket, int *type, char str[]) +{ + int len; + + Socket_ReceiveData(socket, type, sizeof(int)); + if(Socket_ReceiveData(socket, &len, sizeof(int))) { + if(Socket_ReceiveData(socket, str, len) == len) { + str[len] = '\0'; + return 1; + } + } + return 0; } -int Gmsh_StopClient(char *sockname, int sock){ - if(Socket_UnlinkName(sockname)==-1) - return -1; /* Impossible to unlink the socket */ +int Gmsh_StopClient(char *sockname, int sock) +{ + if(Socket_UnlinkName(sockname) == -1) + return -1; /* Impossible to unlink the socket */ close(sock); return 0; } - diff --git a/Fltk/Main.cpp b/Fltk/Main.cpp index 4beb671ed6638a0b81e88b18999e93a985a60444..c10977cd34c5594dd2af3e26d7bf73e89f72a033 100644 --- a/Fltk/Main.cpp +++ b/Fltk/Main.cpp @@ -1,4 +1,4 @@ -// $Id: Main.cpp,v 1.43 2003-02-20 16:44:38 geuzaine Exp $ +// $Id: Main.cpp,v 1.44 2003-03-01 22:36:38 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -40,30 +40,32 @@ #include "CommandLine.h" #include "Numeric.h" -char yyname[256]; -int yyerrorstate; -Context_T CTX ; -Mesh M, *THEM=NULL, *LOCAL=NULL; -GUI *WID = NULL; - -int main(int argc, char *argv[]){ - int i, nbf; - char cmdline[1000]="", currtime[100]; - time_t now; - +char yyname[256]; +int yyerrorstate; +Context_T CTX; +Mesh M, *THEM = NULL, *LOCAL = NULL; +GUI *WID = NULL; + +int main(int argc, char *argv[]) +{ + int i, nbf; + char cmdline[1000] = "", currtime[100]; + time_t now; + // log some info - + time(&now); strcpy(currtime, ctime(&now)); - currtime[strlen(currtime)-1] = '\0'; + currtime[strlen(currtime) - 1] = '\0'; - for(i=0;i<argc;i++){ - if(i) strcat(cmdline, " "); + for(i = 0; i < argc; i++) { + if(i) + strcat(cmdline, " "); strcat(cmdline, argv[i]); } // Gmsh default options - + Init_Options(0); // Configuration files and command line options @@ -72,8 +74,8 @@ int main(int argc, char *argv[]){ // This does not work with FLTK right now... - CTX.overlay = 0 ; - CTX.geom.highlight = 0 ; + CTX.overlay = 0; + CTX.geom.highlight = 0; // Always print info on terminal for non-interactive execution @@ -81,9 +83,9 @@ int main(int argc, char *argv[]){ CTX.terminal = 1; if(CTX.verbosity && CTX.terminal) - fprintf(stderr, "%s, version %d.%d.%d, started %s\n", - gmsh_progname, GMSH_MAJOR_VERSION, GMSH_MINOR_VERSION, - GMSH_PATCH_VERSION, currtime); + fprintf(stderr, "%s, version %d.%d.%d, started %s\n", + gmsh_progname, GMSH_MAJOR_VERSION, GMSH_MINOR_VERSION, + GMSH_PATCH_VERSION, currtime); // Register Default Plugins (in test ...) if(CTX.default_plugins) @@ -91,62 +93,65 @@ int main(int argc, char *argv[]){ // Initialize the static Mesh - M.Vertices = NULL ; - M.VertexEdges = NULL ; - M.Simplexes = NULL ; - M.Points = NULL ; - M.Curves = NULL ; - M.SurfaceLoops = NULL ; - M.EdgeLoops = NULL ; - M.Surfaces = NULL ; - M.Volumes = NULL ; - M.PhysicalGroups = NULL ; - M.Metric = NULL ; + M.Vertices = NULL; + M.VertexEdges = NULL; + M.Simplexes = NULL; + M.Points = NULL; + M.Curves = NULL; + M.SurfaceLoops = NULL; + M.EdgeLoops = NULL; + M.Surfaces = NULL; + M.Volumes = NULL; + M.PhysicalGroups = NULL; + M.Metric = NULL; // Signal handling - signal(SIGINT, Signal); + signal(SIGINT, Signal); signal(SIGSEGV, Signal); - signal(SIGFPE, Signal); + signal(SIGFPE, Signal); // Non-interactive Gmsh - if(CTX.batch){ + if(CTX.batch) { check_gsl(); Msg(DIRECT, "Command line : %s", cmdline); OpenProblem(CTX.filename); if(yyerrorstate) exit(1); else { - for(i=1;i<nbf;i++) MergeProblem(TheFileNameTab[i]); - if(TheBgmFileName){ + for(i = 1; i < nbf; i++) + MergeProblem(TheFileNameTab[i]); + if(TheBgmFileName) { MergeProblem(TheBgmFileName); if(List_Nbr(CTX.post.list)) - BGMWithView((Post_View*)List_Pointer(CTX.post.list, List_Nbr(CTX.post.list)-1)); + BGMWithView((Post_View *) + List_Pointer(CTX.post.list, + List_Nbr(CTX.post.list) - 1)); else Msg(GERROR, "Invalid background mesh (no view)"); } - if(CTX.batch > 0){ + if(CTX.batch > 0) { mai3d(THEM, CTX.batch); Print_Mesh(THEM, CTX.output_filename, CTX.mesh.format); } else Print_Geo(THEM, CTX.output_filename); - if(CTX.mesh.histogram){ - Mesh_Quality(THEM); - Print_Histogram(THEM->Histogram[0]); + if(CTX.mesh.histogram) { + Mesh_Quality(THEM); + Print_Histogram(THEM->Histogram[0]); } exit(1); - } + } } - + // Interactive Gmsh - CTX.batch = -1 ; // The GUI is not ready yet for interactivity + CTX.batch = -1; // The GUI is not ready yet for interactivity // Create the GUI - + WID = new GUI(argc, argv); // Set all previously defined options in the GUI @@ -155,16 +160,16 @@ int main(int argc, char *argv[]){ // The GUI is ready - CTX.batch = 0 ; + CTX.batch = 0; // Say welcome! Msg(STATUS3N, "Ready"); - Msg(STATUS1, "Gmsh %d.%d.%d", GMSH_MAJOR_VERSION, GMSH_MINOR_VERSION, + Msg(STATUS1, "Gmsh %d.%d.%d", GMSH_MAJOR_VERSION, GMSH_MINOR_VERSION, GMSH_PATCH_VERSION); // Log the following for bug reports - + Msg(LOG_INFO, "-------------------------------------------------------"); Msg(LOG_INFO, gmsh_os); Msg(LOG_INFO, gmsh_date); @@ -176,7 +181,7 @@ int main(int argc, char *argv[]){ Msg(LOG_INFO, "-------------------------------------------------------"); // Check for buggy obsolete GSL versions - + check_gsl(); // Display the GUI immediately to have a quick "a la Windows" launch time @@ -189,47 +194,47 @@ int main(int argc, char *argv[]){ // Merge all other input files - for(i=1;i<nbf;i++) MergeProblem(TheFileNameTab[i]); - + for(i = 1; i < nbf; i++) + MergeProblem(TheFileNameTab[i]); + // Init first context - switch(CTX.initial_context){ - case 1 : - WID->set_context(menu_geometry, 0); + switch (CTX.initial_context) { + case 1: + WID->set_context(menu_geometry, 0); break; - case 2 : - WID->set_context(menu_mesh, 0); + case 2: + WID->set_context(menu_mesh, 0); break; - case 3 : - WID->set_context(menu_solver, 0); + case 3: + WID->set_context(menu_solver, 0); break; - case 4 : - WID->set_context(menu_post, 0); + case 4: + WID->set_context(menu_post, 0); break; - default : // automatic + default: // automatic if(List_Nbr(CTX.post.list)) WID->set_context(menu_post, 0); else - WID->set_context(menu_geometry, 0); + WID->set_context(menu_geometry, 0); break; - } + } // Read background mesh on disk - if(TheBgmFileName){ + if(TheBgmFileName) { MergeProblem(TheBgmFileName); if(List_Nbr(CTX.post.list)) - BGMWithView((Post_View*)List_Pointer(CTX.post.list, List_Nbr(CTX.post.list)-1)); + BGMWithView((Post_View *) + List_Pointer(CTX.post.list, List_Nbr(CTX.post.list) - 1)); else Msg(GERROR, "Invalid background mesh (no view)"); } // Draw the actual scene Draw(); - CTX.expose = 1 ; + CTX.expose = 1; // loop WID->run(); - } - diff --git a/Fltk/Message.cpp b/Fltk/Message.cpp index f20086eda3e19b8e8ce138a8f7eee5895b95faed..ab4bb1980e2e8ab6dc9eaade7904034bf68821f0 100644 --- a/Fltk/Message.cpp +++ b/Fltk/Message.cpp @@ -1,4 +1,4 @@ -// $Id: Message.cpp,v 1.36 2003-02-25 16:49:36 geuzaine Exp $ +// $Id: Message.cpp,v 1.37 2003-03-01 22:36:38 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -36,30 +36,30 @@ #include "Options.h" #include "GUI.h" -extern GUI *WID; -extern Context_T CTX; +extern GUI *WID; +extern Context_T CTX; // Handle signals. It is a crime to call stdio functions in a signal // handler. But who cares? ;-) -void Signal (int sig_num){ - - switch (sig_num){ - case SIGSEGV : +void Signal(int sig_num) +{ + switch (sig_num) { + case SIGSEGV: Msg(FATAL1, "Segmentation violation (invalid memory reference)"); Msg(FATAL2, "------------------------------------------------------"); Msg(FATAL2, "You have discovered a bug in Gmsh! You may report it"); Msg(FATAL2, "by e-mail (together with any helpful data permitting to"); - Msg(FATAL3, "reproduce it) to <gmsh@geuz.org>"); + Msg(FATAL3, "reproduce it) to <gmsh@geuz.org>"); break; - case SIGFPE : - Msg(FATAL, "Floating point exception (division by zero?)"); + case SIGFPE: + Msg(FATAL, "Floating point exception (division by zero?)"); break; - case SIGINT : - Msg(INFO, "Interrupt (generated from terminal special character)"); + case SIGINT: + Msg(INFO, "Interrupt (generated from terminal special character)"); Exit(1); break; - default : + default: Msg(FATAL, "Unknown signal"); break; } @@ -67,13 +67,16 @@ void Signal (int sig_num){ // General purpose message routine -void Debug(){ +void Debug() +{ + ; } -void Msg(int level, char *fmt, ...){ - va_list args; - int abort = 0, verb = 0, window = -1, log = 1; - char *str = NULL; +void Msg(int level, char *fmt, ...) +{ + va_list args; + int abort = 0, verb = 0, window = -1, log = 1; + char *str = NULL; // *INDENT-OFF* switch(level){ @@ -119,46 +122,52 @@ void Msg(int level, char *fmt, ...){ static char buff1[1024], buff2[1024], buff[4][1024]; - if(CTX.verbosity >= verb){ + if(CTX.verbosity >= verb) { if(!WID) window = -1; - else - WID->check(); + else + WID->check(); // this is pretty costly, but permits to keep the app // responsive... the downside is that it can cause race // conditions. Let's move it in here at least, so that we don;t // check() on DEBUG calls when not in debug mode. - va_start (args, fmt); + va_start(args, fmt); - if(window >= 0){ - vsprintf(buff[window], fmt, args); - if(window <= 2) WID->set_status(buff[window], window); - if(log && strlen(buff[window])) WID->add_message(buff[window]); + if(window >= 0) { + vsprintf(buff[window], fmt, args); + if(window <= 2) + WID->set_status(buff[window], window); + if(log && strlen(buff[window])) + WID->add_message(buff[window]); } - else{ + else { strcpy(buff1, "@C1"); - if(str) strcat(buff1, str); - vsprintf(buff2, fmt, args); - strcat(buff1,buff2); - if(CTX.terminal) fprintf(stderr, "%s\n", &buff1[3]); - if(WID){ - if(verb<2) - WID->add_message(buff1); - else - WID->add_message(&buff1[3]); - if(!verb) WID->create_message_window(); + if(str) + strcat(buff1, str); + vsprintf(buff2, fmt, args); + strcat(buff1, buff2); + if(CTX.terminal) + fprintf(stderr, "%s\n", &buff1[3]); + if(WID) { + if(verb < 2) + WID->add_message(buff1); + else + WID->add_message(&buff1[3]); + if(!verb) + WID->create_message_window(); } } - va_end (args); + va_end(args); - if(CTX.terminal) fflush(stderr); + if(CTX.terminal) + fflush(stderr); } - if(abort){ + if(abort) { Debug(); - if(WID){ + if(WID) { WID->save_message(CTX.error_filename); WID->fatal_error(CTX.error_filename); } @@ -169,9 +178,10 @@ void Msg(int level, char *fmt, ...){ // Clean exit -void Exit(int level){ - if(WID && !CTX.batch){ - if(CTX.session_save){ +void Exit(int level) +{ + if(WID && !CTX.batch) { + if(CTX.session_save) { CTX.position[0] = WID->m_window->x(); CTX.position[1] = WID->m_window->y(); CTX.gl_position[0] = WID->g_window->x(); @@ -191,28 +201,30 @@ void Exit(int level){ if(CTX.options_save) Print_Options(0, GMSH_OPTIONSRC, CTX.optionsrc_filename); } - unlink(CTX.tmp_filename);//delete temp file + unlink(CTX.tmp_filename); //delete temp file exit(level); } // CPU time computation, etc. -void GetResources(long *s, long *us, long *mem){ +void GetResources(long *s, long *us, long *mem) +{ static struct rusage r; - getrusage(RUSAGE_SELF,&r); - *s = (long)r.ru_utime.tv_sec ; - *us = (long)r.ru_utime.tv_usec ; - *mem = (long)r.ru_maxrss ; + getrusage(RUSAGE_SELF, &r); + *s = (long)r.ru_utime.tv_sec; + *us = (long)r.ru_utime.tv_usec; + *mem = (long)r.ru_maxrss; } -void PrintResources(char *fmt, long s, long us, long mem){ +void PrintResources(char *fmt, long s, long us, long mem) +{ Msg(DIRECT, "Resources = %scpu %ld.%ld s / mem %ld kb\n", fmt, s, us, mem); } -double Cpu(void){ +double Cpu(void) +{ long s, us, mem; GetResources(&s, &us, &mem); - return (double)s + (double)us/1.e6 ; + return (double)s + (double)us / 1.e6; } - diff --git a/Fltk/Opengl.cpp b/Fltk/Opengl.cpp index 2c1fbbece18669354e010f4b1772e711286930e7..dbdac6b33f3fd8c6a0b92a6212a74d4337173878 100644 --- a/Fltk/Opengl.cpp +++ b/Fltk/Opengl.cpp @@ -1,4 +1,4 @@ -// $Id: Opengl.cpp,v 1.30 2003-01-23 20:19:19 geuzaine Exp $ +// $Id: Opengl.cpp,v 1.31 2003-03-01 22:36:38 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -29,123 +29,134 @@ #include "GUI.h" #include "gl2ps.h" -extern GUI *WID; -extern Mesh M; -extern Context_T CTX; +extern GUI *WID; +extern Mesh M; +extern Context_T CTX; -void Process_SelectionBuffer(int x, int y, int *n, GLuint *ii, GLuint *jj); -void Filter_SelectionBuffer(int n, GLuint *typ, GLuint *ient, Vertex **thev, - Curve **thec, Surface **thes, Mesh *m); -void myZoom(GLdouble X1, GLdouble X2, GLdouble Y1, GLdouble Y2, - GLdouble Xc1, GLdouble Xc2, GLdouble Yc1, GLdouble Yc2); +void Process_SelectionBuffer(int x, int y, int *n, GLuint * ii, GLuint * jj); +void Filter_SelectionBuffer(int n, GLuint * typ, GLuint * ient, + Vertex ** thev, Curve ** thec, Surface ** thes, + Mesh * m); +void myZoom(GLdouble X1, GLdouble X2, GLdouble Y1, GLdouble Y2, GLdouble Xc1, + GLdouble Xc2, GLdouble Yc1, GLdouble Yc2); // Draw specialization -void InitOpengl(void){ +void InitOpengl(void) +{ WID->make_opengl_current(); - Orthogonalize(0,0); + Orthogonalize(0, 0); } -void InitOverlay(void){ +void InitOverlay(void) +{ WID->make_overlay_current(); - Orthogonalize(0,0); + Orthogonalize(0, 0); } -void ClearOpengl(void){ - glClearColor(UNPACK_RED(CTX.color.bg)/255., - UNPACK_GREEN(CTX.color.bg)/255., - UNPACK_BLUE(CTX.color.bg)/255., - 0.); - glClear(GL_DEPTH_BUFFER_BIT|GL_COLOR_BUFFER_BIT); +void ClearOpengl(void) +{ + glClearColor(UNPACK_RED(CTX.color.bg) / 255., + UNPACK_GREEN(CTX.color.bg) / 255., + UNPACK_BLUE(CTX.color.bg) / 255., 0.); + glClear(GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT); } -void Draw(void){ +void Draw(void) +{ WID->redraw_opengl(); } -void DrawUI(void){ +void DrawUI(void) +{ WID->check(); } -void Draw_String(char *s){ +void Draw_String(char *s) +{ - if(CTX.print.gl_fonts){ + if(CTX.print.gl_fonts) { gl_font(FL_HELVETICA, CTX.gl_fontsize); gl_draw(s); } - else{ // ps, pstex or jpegtex output - if(CTX.print.format == FORMAT_JPEGTEX) return; - gl2psText(s,CTX.print.eps_font,CTX.print.eps_font_size); + else { // ps, pstex or jpegtex output + if(CTX.print.format == FORMAT_JPEGTEX) + return; + gl2psText(s, CTX.print.eps_font, CTX.print.eps_font_size); } } // Euler angles set_XXX -void set_r(int i, double val){ - if(!CTX.useTrackball){ - if(!CTX.rlock[i]){ +void set_r(int i, double val) +{ + if(!CTX.useTrackball) { + if(!CTX.rlock[i]) { CTX.r[i] = val; } } } -void set_t(int i, double val){ - if(!CTX.tlock[i]){ +void set_t(int i, double val) +{ + if(!CTX.tlock[i]) { CTX.t[i] = val; } } -void set_s(int i, double val){ - if(!CTX.slock[i]){ +void set_s(int i, double val) +{ + if(!CTX.slock[i]) { CTX.s[i] = val; } } // Select entity routines -int check_type(int type, Vertex *v, Curve *c, Surface *s){ - return ( (type==ENT_POINT && v) || - (type==ENT_LINE && c) || - (type==ENT_SURFACE && s) ) ; +int check_type(int type, Vertex * v, Curve * c, Surface * s) +{ + return ((type == ENT_POINT && v) || + (type == ENT_LINE && c) || (type == ENT_SURFACE && s)); } -int SelectEntity(int type, Vertex **v, Curve **c, Surface **s){ - int hits; - GLuint ii[SELECTION_BUFFER_SIZE],jj[SELECTION_BUFFER_SIZE]; +int SelectEntity(int type, Vertex ** v, Curve ** c, Surface ** s) +{ + int hits; + GLuint ii[SELECTION_BUFFER_SIZE], jj[SELECTION_BUFFER_SIZE]; - *v = NULL; *c = NULL; *s = NULL; + *v = NULL; + *c = NULL; + *s = NULL; - WID->selection = type; + WID->selection = type; WID->try_selection = 0; WID->quit_selection = 0; WID->end_selection = 0; - while(1){ + while(1) { WID->wait(); - if(WID->quit_selection){ + if(WID->quit_selection) { WID->quit_selection = 0; WID->selection = 0; return 0; } - if(WID->end_selection){ + if(WID->end_selection) { WID->end_selection = 0; WID->selection = 0; return -1; } - if(WID->try_selection){ + if(WID->try_selection) { WID->try_selection = 0; Process_SelectionBuffer(Fl::event_x(), Fl::event_y(), &hits, ii, jj); - Filter_SelectionBuffer(hits,ii,jj,v,c,s,&M); - if(check_type(type,*v,*c,*s)){ + Filter_SelectionBuffer(hits, ii, jj, v, c, s, &M); + if(check_type(type, *v, *c, *s)) { BeginHighlight(); - HighlightEntity(*v,*c,*s,1); + HighlightEntity(*v, *c, *s, 1); EndHighlight(1); - WID->selection = 0; - return(1); + WID->selection = 0; + return (1); } } } } - - diff --git a/Fltk/Opengl_Window.cpp b/Fltk/Opengl_Window.cpp index f836285403b9c4c1007927bd00421541bff46678..2aca3c7138bcad409a321ff3d5771f6a1b16c5ea 100644 --- a/Fltk/Opengl_Window.cpp +++ b/Fltk/Opengl_Window.cpp @@ -1,4 +1,4 @@ -// $Id: Opengl_Window.cpp,v 1.29 2003-01-23 20:19:20 geuzaine Exp $ +// $Id: Opengl_Window.cpp,v 1.30 2003-03-01 22:36:38 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -35,47 +35,51 @@ extern GUI *WID; extern Mesh M; extern Context_T CTX; -void Process_SelectionBuffer(int x, int y, int *n, GLuint *ii, GLuint *jj); -void Filter_SelectionBuffer(int n, GLuint *typ, GLuint *ient, Vertex **thev, - Curve **thec, Surface **thes, Mesh *m); -void myZoom(GLdouble X1, GLdouble X2, GLdouble Y1, GLdouble Y2, - GLdouble Xc1, GLdouble Xc2, GLdouble Yc1, GLdouble Yc2); -int check_type(int type, Vertex *v, Curve *c, Surface *s); +void Process_SelectionBuffer(int x, int y, int *n, GLuint * ii, GLuint * jj); +void Filter_SelectionBuffer(int n, GLuint * typ, GLuint * ient, + Vertex ** thev, Curve ** thec, Surface ** thes, + Mesh * m); +void myZoom(GLdouble X1, GLdouble X2, GLdouble Y1, GLdouble Y2, GLdouble Xc1, + GLdouble Xc2, GLdouble Yc1, GLdouble Yc2); +int check_type(int type, Vertex * v, Curve * c, Surface * s); -static int ZOOM = 0 ; +static int ZOOM = 0; static double ZOOM_X0, ZOOM_Y0, ZOOM_X1, ZOOM_Y1; -void Opengl_Window::draw() { - static int locked=0; - if(locked) +void Opengl_Window::draw() +{ + static int locked = 0; + if(locked) return; else - locked=1; + locked = 1; Msg(DEBUG, "Opengl_Window->draw()"); - if(!valid()){ + if(!valid()) { valid(1); - CTX.viewport[0] = 0 ; CTX.viewport[1] = 0 ; - CTX.viewport[2] = w() ; CTX.viewport[3] = h() ; + CTX.viewport[0] = 0; + CTX.viewport[1] = 0; + CTX.viewport[2] = w(); + CTX.viewport[3] = h(); glViewport(CTX.viewport[0], CTX.viewport[1], - CTX.viewport[2], CTX.viewport[3]); + CTX.viewport[2], CTX.viewport[3]); } - else{ - if((w() != CTX.viewport[2]-CTX.viewport[0]) || - (h() != CTX.viewport[3]-CTX.viewport[1])){ - WID->set_size(CTX.viewport[2]-CTX.viewport[0], - CTX.viewport[3]-CTX.viewport[1]); + else { + if((w() != CTX.viewport[2] - CTX.viewport[0]) || + (h() != CTX.viewport[3] - CTX.viewport[1])) { + WID->set_size(CTX.viewport[2] - CTX.viewport[0], + CTX.viewport[3] - CTX.viewport[1]); glViewport(CTX.viewport[0], CTX.viewport[1], - CTX.viewport[2], CTX.viewport[3]); + CTX.viewport[2], CTX.viewport[3]); } } - if(!ZOOM){ - Orthogonalize(0,0); + if(!ZOOM) { + Orthogonalize(0, 0); ClearOpengl(); Draw3d(); Draw2d(); } - else{ + else { glPopMatrix(); glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); @@ -87,7 +91,7 @@ void Opengl_Window::draw() { glPushMatrix(); glLoadIdentity(); glDisable(GL_DEPTH_TEST); - glColor3f(1.,1.,1.); + glColor3f(1., 1., 1.); glBlendFunc(GL_ONE_MINUS_DST_COLOR, GL_ZERO); glEnable(GL_BLEND); glLineWidth(0.2); @@ -98,8 +102,12 @@ void Opengl_Window::draw() { glVertex2d(ZOOM_X0, ZOOM_Y1); glVertex2d(ZOOM_X0, ZOOM_Y0); glEnd(); - ZOOM_X1 = CTX.vxmin + ((double)Fl::event_x()/(double)w()) * (CTX.vxmax - CTX.vxmin); - ZOOM_Y1 = CTX.vymax - ((double)Fl::event_y()/(double)h()) * (CTX.vymax - CTX.vymin); + ZOOM_X1 = + CTX.vxmin + ((double)Fl::event_x() / (double)w()) * (CTX.vxmax - + CTX.vxmin); + ZOOM_Y1 = + CTX.vymax - ((double)Fl::event_y() / (double)h()) * (CTX.vymax - + CTX.vymin); glBegin(GL_LINE_STRIP); glVertex2d(ZOOM_X0, ZOOM_Y0); glVertex2d(ZOOM_X1, ZOOM_Y0); @@ -115,13 +123,15 @@ void Opengl_Window::draw() { glMatrixMode(GL_MODELVIEW); ZOOM = 0; } - locked=0; + locked = 0; } -void Opengl_Window::draw_overlay() { +void Opengl_Window::draw_overlay() +{ } -void Opengl_Window::clear_overlay() { +void Opengl_Window::clear_overlay() +{ } @@ -131,35 +141,36 @@ void Opengl_Window::clear_overlay() { // as treated, and is suppressed. If the handle returns 0, the event // is passed to the parent. -int Opengl_Window::handle(int event) { - static int xpos, ypos, xmov, ymov, ibut, hits; - static int ZoomClick=0, FirstClick=0; +int Opengl_Window::handle(int event) +{ + static int xpos, ypos, xmov, ymov, ibut, hits; + static int ZoomClick = 0, FirstClick = 0; static GLdouble xc, yc, xc1, yc1, xc2, yc2, xt1, yt1, xscale1, yscale1; - static Vertex *v=NULL, *ov; - static Curve *c=NULL, *oc; - static Surface *s=NULL, *os; + static Vertex *v = NULL, *ov; + static Curve *c = NULL, *oc; + static Surface *s = NULL, *os; - GLuint ii[SELECTION_BUFFER_SIZE], jj[SELECTION_BUFFER_SIZE]; + GLuint ii[SELECTION_BUFFER_SIZE], jj[SELECTION_BUFFER_SIZE]; switch (event) { - case FL_ENTER : - take_focus(); //force keyboard focus on the Opengl_Window + case FL_ENTER: + take_focus(); //force keyboard focus on the Opengl_Window return 1; - case FL_LEAVE : + case FL_LEAVE: return 1; - case FL_FOCUS : + case FL_FOCUS: return 1; - case FL_UNFOCUS : + case FL_UNFOCUS: return 1; - case FL_SHORTCUT : - case FL_KEYBOARD : + case FL_SHORTCUT: + case FL_KEYBOARD: // this overrides the default navigation - if(WID->arrow_shortcuts()){ + if(WID->arrow_shortcuts()) { return 1; } return Fl_Gl_Window::handle(event); @@ -170,49 +181,57 @@ int Opengl_Window::handle(int event) { xpos = Fl::event_x(); ypos = Fl::event_y(); - if(ibut == 1 && !Fl::event_state(FL_SHIFT) && !Fl::event_state(FL_ALT)){ - if(!ZoomClick && Fl::event_state(FL_CTRL)){ - ZOOM_X0 = ZOOM_X1 = CTX.vxmin + ((double)xpos/(double)w()) * (CTX.vxmax - CTX.vxmin); - ZOOM_Y0 = ZOOM_Y1 = CTX.vymax - ((double)ypos/(double)h()) * (CTX.vymax - CTX.vymin); - xc1 = ZOOM_X0/CTX.s[0] - CTX.t[0]; - yc1 = ZOOM_Y0/CTX.s[1] - CTX.t[1]; + if(ibut == 1 && !Fl::event_state(FL_SHIFT) && !Fl::event_state(FL_ALT)) { + if(!ZoomClick && Fl::event_state(FL_CTRL)) { + ZOOM_X0 = ZOOM_X1 = + CTX.vxmin + ((double)xpos / (double)w()) * (CTX.vxmax - CTX.vxmin); + ZOOM_Y0 = ZOOM_Y1 = + CTX.vymax - ((double)ypos / (double)h()) * (CTX.vymax - CTX.vymin); + xc1 = ZOOM_X0 / CTX.s[0] - CTX.t[0]; + yc1 = ZOOM_Y0 / CTX.s[1] - CTX.t[1]; ZoomClick = 1; } - else if(ZoomClick){ - xc2 = ZOOM_X1/CTX.s[0] - CTX.t[0]; - yc2 = ZOOM_Y1/CTX.s[1] - CTX.t[1]; + else if(ZoomClick) { + xc2 = ZOOM_X1 / CTX.s[0] - CTX.t[0]; + yc2 = ZOOM_Y1 / CTX.s[1] - CTX.t[1]; ZoomClick = 0; clear_overlay(); if(ZOOM_X0 != ZOOM_X1 && ZOOM_Y0 != ZOOM_Y1) - myZoom(ZOOM_X0,ZOOM_X1,ZOOM_Y0,ZOOM_Y1,xc1,xc2,yc1,yc2); + myZoom(ZOOM_X0, ZOOM_X1, ZOOM_Y0, ZOOM_Y1, xc1, xc2, yc1, yc2); } - else{ - WID->try_selection = 1 ; + else { + WID->try_selection = 1; } } - else if(ibut == 2 || (ibut == 1 && Fl::event_state(FL_SHIFT))){ - if(Fl::event_state(FL_CTRL) && !ZoomClick){ + else if(ibut == 2 || (ibut == 1 && Fl::event_state(FL_SHIFT))) { + if(Fl::event_state(FL_CTRL) && !ZoomClick) { set_s(1, CTX.s[0]); set_s(2, CTX.s[0]); redraw(); } - else{ + else { ZoomClick = 0; clear_overlay(); } } - else{ - if(Fl::event_state(FL_CTRL) && !ZoomClick){ - if(CTX.useTrackball) - CTX.setQuaternion(0.,0.,0.,1.); - else{ - set_r(0,0.); set_r(1,0.); set_r(2,0.); - } - set_t(0,0.); set_t(1,0.); set_t(2,0.); - set_s(0,1.); set_s(1,1.); set_s(2,1.); + else { + if(Fl::event_state(FL_CTRL) && !ZoomClick) { + if(CTX.useTrackball) + CTX.setQuaternion(0., 0., 0., 1.); + else { + set_r(0, 0.); + set_r(1, 0.); + set_r(2, 0.); + } + set_t(0, 0.); + set_t(1, 0.); + set_t(2, 0.); + set_s(0, 1.); + set_s(1, 1.); + set_s(2, 1.); redraw(); } - else{ + else { ZoomClick = 0; clear_overlay(); } @@ -223,9 +242,9 @@ int Opengl_Window::handle(int event) { ibut = Fl::event_button(); xpos = Fl::event_x(); ypos = Fl::event_y(); - if(!ZoomClick){ - CTX.mesh.draw = 1 ; - CTX.post.draw = 1 ; + if(!ZoomClick) { + CTX.mesh.draw = 1; + CTX.post.draw = 1; redraw(); } return 1; @@ -241,69 +260,92 @@ int Opengl_Window::handle(int event) { else { clear_overlay(); - if(FirstClick){ - xc1 = (((double)xpos/(double)w()) * (CTX.vxmax-CTX.vxmin) + CTX.vxmin) - / CTX.s[0] - CTX.t[0]; - yc1 = (CTX.vymax - ((double)ypos/(double)h()) * (CTX.vymax-CTX.vymin)) - / CTX.s[1] - CTX.t[1]; - xt1 = CTX.t[0]; - yt1 = CTX.t[1]; - xscale1 = CTX.s[0]; - yscale1 = CTX.s[1]; - FirstClick=0; + if(FirstClick) { + xc1 = + (((double)xpos / (double)w()) * (CTX.vxmax - CTX.vxmin) + CTX.vxmin) + / CTX.s[0] - CTX.t[0]; + yc1 = + (CTX.vymax - ((double)ypos / (double)h()) * (CTX.vymax - CTX.vymin)) + / CTX.s[1] - CTX.t[1]; + xt1 = CTX.t[0]; + yt1 = CTX.t[1]; + xscale1 = CTX.s[0]; + yscale1 = CTX.s[1]; + FirstClick = 0; } - if(ibut == 1 && !Fl::event_state(FL_SHIFT) && !Fl::event_state(FL_ALT)){ - if(CTX.useTrackball) - CTX.addQuaternion((2.0*xpos - w()) / w(), - (h() - 2.0*ypos) / h(), - (2.0*Fl::event_x() - w()) / w(), - (h() - 2.0*Fl::event_y()) / h()); - else{ - set_r(1, CTX.r[1] + ((abs(xmov) > abs(ymov))?180*(float)xmov/(float)w():0)); - set_r(0, CTX.r[0] + ((abs(xmov) > abs(ymov))?0:180*(float)ymov/(float)h())); - } + if(ibut == 1 && !Fl::event_state(FL_SHIFT) && !Fl::event_state(FL_ALT)) { + if(CTX.useTrackball) + CTX.addQuaternion((2.0 * xpos - w()) / w(), + (h() - 2.0 * ypos) / h(), + (2.0 * Fl::event_x() - w()) / w(), + (h() - 2.0 * Fl::event_y()) / h()); + else { + set_r(1, + CTX.r[1] + + ((abs(xmov) > + abs(ymov)) ? 180 * (float)xmov / (float)w() : 0)); + set_r(0, + CTX.r[0] + + ((abs(xmov) > + abs(ymov)) ? 0 : 180 * (float)ymov / (float)h())); + } } - else if(ibut == 2 || (ibut == 1 && Fl::event_state(FL_SHIFT))){ - if(!CTX.useTrackball) - set_r(2, CTX.r[2] + ((abs(ymov) > abs(xmov))?0:-180*(float)xmov/(float)w())); - set_s(0, CTX.s[0] * ( (abs(ymov) > abs(xmov)) ? - ( (ymov>0) ? (float)(CTX.zoom_factor*(abs(ymov)+h()))/(float)h() - : (float)(h())/(float)(CTX.zoom_factor*(abs(ymov)+h())) ) - : 1.) ); - set_s(1, CTX.s[0]); - set_s(2, CTX.s[0]); - if(abs(ymov) > abs(xmov)){ - set_t(0, xt1*(xscale1/CTX.s[0])-xc1*(1.-(xscale1/CTX.s[0]))); - set_t(1, yt1*(yscale1/CTX.s[1])-yc1*(1.-(yscale1/CTX.s[1]))); - } + else if(ibut == 2 || (ibut == 1 && Fl::event_state(FL_SHIFT))) { + if(!CTX.useTrackball) + set_r(2, + CTX.r[2] + + ((abs(ymov) > + abs(xmov)) ? 0 : -180 * (float)xmov / (float)w())); + set_s(0, + CTX.s[0] * + ((abs(ymov) > + abs(xmov)) ? ((ymov > + 0) ? (float)(CTX.zoom_factor * (abs(ymov) + + h())) / + (float)h() + : (float)(h()) / (float)(CTX.zoom_factor * + (abs(ymov) + h()))) + : 1.)); + set_s(1, CTX.s[0]); + set_s(2, CTX.s[0]); + if(abs(ymov) > abs(xmov)) { + set_t(0, + xt1 * (xscale1 / CTX.s[0]) - xc1 * (1. - + (xscale1 / CTX.s[0]))); + set_t(1, + yt1 * (yscale1 / CTX.s[1]) - yc1 * (1. - + (yscale1 / CTX.s[1]))); + } } - else{ - xc = ( ((double)xpos/(double)w()) * (CTX.vxmax - CTX.vxmin) + CTX.vxmin ) - / CTX.s[0]; - yc = ( CTX.vymax - ((double)ypos/(double)h()) * (CTX.vymax - CTX.vymin)) - / CTX.s[1]; - set_t(0, xc-xc1); - set_t(1, yc-yc1); - set_t(2, 0.); + else { + xc = + (((double)xpos / (double)w()) * (CTX.vxmax - CTX.vxmin) + CTX.vxmin) + / CTX.s[0]; + yc = + (CTX.vymax - ((double)ypos / (double)h()) * (CTX.vymax - CTX.vymin)) + / CTX.s[1]; + set_t(0, xc - xc1); + set_t(1, yc - yc1); + set_t(2, 0.); } - if(CTX.fast){ - CTX.mesh.draw = 0 ; - CTX.post.draw = 0; + if(CTX.fast) { + CTX.mesh.draw = 0; + CTX.post.draw = 0; } - + redraw(); } - xpos += xmov; - ypos += ymov; + xpos += xmov; + ypos += ymov; return 1; - + case FL_MOVE: - xmov = Fl::event_x()-xpos; - ymov = Fl::event_y()-ypos; + xmov = Fl::event_x() - xpos; + ymov = Fl::event_y() - ypos; if(ZoomClick) { ZOOM = 1; @@ -312,21 +354,26 @@ int Opengl_Window::handle(int event) { else { WID->make_opengl_current(); Process_SelectionBuffer(Fl::event_x(), Fl::event_y(), &hits, ii, jj); - ov = v; oc = c; os = s; v = NULL; c = NULL; s = NULL; - Filter_SelectionBuffer(hits,ii,jj,&v,&c,&s,&M); - if(ov != v || oc != c || os != s) { - if(check_type(WID->selection, v, c, s)) - WID->g_window->cursor(FL_CURSOR_CROSS,FL_BLACK,FL_WHITE); - else - WID->g_window->cursor(FL_CURSOR_DEFAULT,FL_BLACK,FL_WHITE); - BeginHighlight(); - HighlightEntity(v,c,s,0); - EndHighlight(0); + ov = v; + oc = c; + os = s; + v = NULL; + c = NULL; + s = NULL; + Filter_SelectionBuffer(hits, ii, jj, &v, &c, &s, &M); + if(ov != v || oc != c || os != s) { + if(check_type(WID->selection, v, c, s)) + WID->g_window->cursor(FL_CURSOR_CROSS, FL_BLACK, FL_WHITE); + else + WID->g_window->cursor(FL_CURSOR_DEFAULT, FL_BLACK, FL_WHITE); + BeginHighlight(); + HighlightEntity(v, c, s, 0); + EndHighlight(0); } } - xpos += xmov; - ypos += ymov; + xpos += xmov; + ypos += ymov; return 1; default: @@ -335,4 +382,3 @@ int Opengl_Window::handle(int event) { } } - diff --git a/Fltk/Solvers.cpp b/Fltk/Solvers.cpp index e88318919137cf3fa0e02df1b9fc4c53859d9cc7..91e1cc92d892d29049fce58999859acfd9d5d561 100644 --- a/Fltk/Solvers.cpp +++ b/Fltk/Solvers.cpp @@ -1,4 +1,4 @@ -// $Id: Solvers.cpp,v 1.18 2003-01-25 22:53:09 geuzaine Exp $ +// $Id: Solvers.cpp,v 1.19 2003-03-01 22:36:38 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -37,95 +37,111 @@ #include "Draw.h" #include "Context.h" -extern Context_T CTX; -extern GUI *WID; +extern Context_T CTX; +extern GUI *WID; -SolverInfo SINFO[MAXSOLVERS] ; +SolverInfo SINFO[MAXSOLVERS]; -int Solver(int num, char *args){ - int sock, type, stop=0, i, j, n; +int Solver(int num, char *args) +{ + int sock, type, stop = 0, i, j, n; char command[1000], socket_name[1000], str[1000]; - - if(!SINFO[num].client_server){ + + if(!SINFO[num].client_server) { sprintf(command, "%s %s &", SINFO[num].executable_name, args); Gmsh_StartClient(command, NULL); return 1; } sprintf(socket_name, "%s.gmshsock-%d", CTX.home_dir, num); - sprintf(command, "%s %s -socket \"%s\"", SINFO[num].executable_name, - args, socket_name); + sprintf(command, "%s %s -socket \"%s\"", SINFO[num].executable_name, + args, socket_name); #if !defined(WIN32) strcat(command, " &"); #endif sock = Gmsh_StartClient(command, socket_name); - if(sock<0){ - switch(sock){ - case -1 : Msg(GERROR, "Couldn't create socket '%s'", socket_name); break; - case -2 : Msg(GERROR, "Couldn't bin socket to name '%s'", socket_name); break; - case -3 : Msg(GERROR, "Socket listen failed on '%s'", socket_name); break; - case -4 : Msg(GERROR, "Solver not responding (is '%s' correctly installed/in your path?)", - SINFO[num].executable_name); break; - case -5 : Msg(GERROR, "Socket accept failed on '%s'", socket_name); break; + if(sock < 0) { + switch (sock) { + case -1: + Msg(GERROR, "Couldn't create socket '%s'", socket_name); + break; + case -2: + Msg(GERROR, "Couldn't bin socket to name '%s'", socket_name); + break; + case -3: + Msg(GERROR, "Socket listen failed on '%s'", socket_name); + break; + case -4: + Msg(GERROR, + "Solver not responding (is '%s' correctly installed/in your path?)", + SINFO[num].executable_name); + break; + case -5: + Msg(GERROR, "Socket accept failed on '%s'", socket_name); + break; } - for(i=0 ; i<SINFO[num].nboptions ; i++) + for(i = 0; i < SINFO[num].nboptions; i++) WID->solver[num].choice[i]->clear(); return 0; } - for(i=0 ; i<SINFO[num].nboptions ; i++) SINFO[num].nbval[i] = 0; + for(i = 0; i < SINFO[num].nboptions; i++) + SINFO[num].nbval[i] = 0; SINFO[num].pid = 0; - while(1){ - if(SINFO[num].pid < 0) break; + while(1) { + if(SINFO[num].pid < 0) + break; Gmsh_ReceiveString(sock, &type, str); - switch(type){ - case GMSH_CLIENT_START : + switch (type) { + case GMSH_CLIENT_START: SINFO[num].pid = atoi(str); break; - case GMSH_CLIENT_STOP : + case GMSH_CLIENT_STOP: SINFO[num].pid = -1; stop = 1; break; - case GMSH_CLIENT_PROGRESS : + case GMSH_CLIENT_PROGRESS: Msg(STATUS3N, "%s %s", SINFO[num].name, str); - break ; - case GMSH_CLIENT_OPTION_1 : - case GMSH_CLIENT_OPTION_2 : - case GMSH_CLIENT_OPTION_3 : - case GMSH_CLIENT_OPTION_4 : - case GMSH_CLIENT_OPTION_5 : - i = type-GMSH_CLIENT_OPTION; - strcpy(SINFO[num].option[i][SINFO[num].nbval[i]++],str); - break ; - case GMSH_CLIENT_VIEW : - if(SINFO[num].merge_views){ - n = List_Nbr(CTX.post.list); - MergeProblem(str); - Draw(); - if(n != List_Nbr(CTX.post.list)) - WID->set_context(menu_post, 0); + break; + case GMSH_CLIENT_OPTION_1: + case GMSH_CLIENT_OPTION_2: + case GMSH_CLIENT_OPTION_3: + case GMSH_CLIENT_OPTION_4: + case GMSH_CLIENT_OPTION_5: + i = type - GMSH_CLIENT_OPTION; + strcpy(SINFO[num].option[i][SINFO[num].nbval[i]++], str); + break; + case GMSH_CLIENT_VIEW: + if(SINFO[num].merge_views) { + n = List_Nbr(CTX.post.list); + MergeProblem(str); + Draw(); + if(n != List_Nbr(CTX.post.list)) + WID->set_context(menu_post, 0); } - break ; - case GMSH_CLIENT_INFO : - case GMSH_CLIENT_WARNING : - case GMSH_CLIENT_ERROR : + break; + case GMSH_CLIENT_INFO: + case GMSH_CLIENT_WARNING: + case GMSH_CLIENT_ERROR: Msg(DIRECT, "%s : %s", SINFO[num].name, str); break; - default : - Msg(WARNING, "Unknown type of message received from %s", SINFO[num].name); + default: + Msg(WARNING, "Unknown type of message received from %s", + SINFO[num].name); Msg(DIRECT, "%s : %s", SINFO[num].name, str); - break ; + break; } - if(stop) break; + if(stop) + break; } - for(i=0 ; i<SINFO[num].nboptions ; i++){ - if(SINFO[num].nbval[i]){ + for(i = 0; i < SINFO[num].nboptions; i++) { + if(SINFO[num].nbval[i]) { WID->solver[num].choice[i]->clear(); - for(j=0;j<SINFO[num].nbval[i];j++) - WID->solver[num].choice[i]->add(SINFO[num].option[i][j]); + for(j = 0; j < SINFO[num].nbval[i]; j++) + WID->solver[num].choice[i]->add(SINFO[num].option[i][j]); WID->solver[num].choice[i]->value(0); } } @@ -137,6 +153,3 @@ int Solver(int num, char *args){ return 1; } - - - diff --git a/Geo/CAD.cpp b/Geo/CAD.cpp index 3087e802ec49b25f31bd2dc37c1dfe638f2f968b..57963b60f613fa35f06de4a86421f422113965b2 100644 --- a/Geo/CAD.cpp +++ b/Geo/CAD.cpp @@ -1,4 +1,4 @@ -// $Id: CAD.cpp,v 1.58 2003-02-25 04:02:50 geuzaine Exp $ +// $Id: CAD.cpp,v 1.59 2003-03-01 22:36:38 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -36,89 +36,99 @@ #else #include "NR.h" #endif - -extern Mesh *THEM; -extern Context_T CTX; -static List_T *ListOfTransformedPoints=NULL; +extern Mesh *THEM; +extern Context_T CTX; + +static List_T *ListOfTransformedPoints = NULL; // Basic functions -int NEWPOINT(void){ +int NEWPOINT(void) +{ return (THEM->MaxPointNum + 1); } -int NEWLINE(void){ +int NEWLINE(void) +{ if(CTX.geom.old_newreg) return NEWREG(); else return (THEM->MaxLineNum + 1); } -int NEWLINELOOP(void){ +int NEWLINELOOP(void) +{ if(CTX.geom.old_newreg) return NEWREG(); else return (THEM->MaxLineLoopNum + 1); } -int NEWSURFACE(void){ +int NEWSURFACE(void) +{ if(CTX.geom.old_newreg) return NEWREG(); else return (THEM->MaxSurfaceNum + 1); } -int NEWSURFACELOOP(void){ +int NEWSURFACELOOP(void) +{ if(CTX.geom.old_newreg) return NEWREG(); else return (THEM->MaxSurfaceLoopNum + 1); } -int NEWVOLUME(void){ +int NEWVOLUME(void) +{ if(CTX.geom.old_newreg) return NEWREG(); else return (THEM->MaxVolumeNum + 1); } -int NEWPHYSICAL(void){ +int NEWPHYSICAL(void) +{ if(CTX.geom.old_newreg) return NEWREG(); else return (THEM->MaxPhysicalNum + 1); } -int NEWREG(void){ +int NEWREG(void) +{ return (IMAX(THEM->MaxLineNum, - IMAX(THEM->MaxLineLoopNum, - IMAX(THEM->MaxSurfaceNum, - IMAX(THEM->MaxSurfaceLoopNum, - IMAX(THEM->MaxVolumeNum, THEM->MaxPhysicalNum))))) - + 1); + IMAX(THEM->MaxLineLoopNum, + IMAX(THEM->MaxSurfaceNum, + IMAX(THEM->MaxSurfaceLoopNum, + IMAX(THEM->MaxVolumeNum, + THEM->MaxPhysicalNum))))) + + 1); } -int compare2Lists (List_T *List1, List_T *List2, - int (*fcmp)(const void *a, const void *b)){ - int i,found; +int compare2Lists(List_T * List1, List_T * List2, + int (*fcmp) (const void *a, const void *b)) +{ + int i, found; - if(List_Nbr(List1) != List_Nbr(List2))return List_Nbr(List1) - List_Nbr(List2); - - List_T *List1Prime = List_Create(List_Nbr(List1),1,List1->size); - List_T *List2Prime = List_Create(List_Nbr(List2),1,List2->size); - List_Copy(List1,List1Prime); - List_Copy(List2,List2Prime); - List_Sort(List1Prime,fcmp); - List_Sort(List2Prime,fcmp); - - for(i=0;i<List_Nbr(List1Prime);i++){ - found = fcmp(List_Pointer(List1Prime,i), - List_Pointer(List2Prime,i)); - if(found != 0){ + if(List_Nbr(List1) != List_Nbr(List2)) + return List_Nbr(List1) - List_Nbr(List2); + + List_T *List1Prime = List_Create(List_Nbr(List1), 1, List1->size); + List_T *List2Prime = List_Create(List_Nbr(List2), 1, List2->size); + List_Copy(List1, List1Prime); + List_Copy(List2, List2Prime); + List_Sort(List1Prime, fcmp); + List_Sort(List2Prime, fcmp); + + for(i = 0; i < List_Nbr(List1Prime); i++) { + found = fcmp(List_Pointer(List1Prime, i), List_Pointer(List2Prime, i)); + if(found != 0) { List_Delete(List1Prime); List_Delete(List2Prime); return found; @@ -129,102 +139,110 @@ int compare2Lists (List_T *List1, List_T *List2, return 0; } -void dist_ddg(double x1,double y1,double z1, - double x2,double y2,double z2, - double x3,double y3,double z3, - double x4,double y4,double z4, - double *x,double *y,double *z){ +void dist_ddg(double x1, double y1, double z1, + double x2, double y2, double z2, + double x3, double y3, double z3, + double x4, double y4, double z4, + double *x, double *y, double *z) +{ + double v[3], u[3], d; - double v[3],u[3],d; + u[0] = x1 - x3; + u[1] = y1 - y3; + u[2] = z1 - z3; - u[0] = x1-x3; - u[1] = y1-y3; - u[2] = z1-z3; - - v[0] = x4-x3; - v[1] = y4-y3; - v[2] = z4-z3; + v[0] = x4 - x3; + v[1] = y4 - y3; + v[2] = z4 - z3; norme(v); - prosca(u,v,&d); + prosca(u, v, &d); - *x = d* x4 + x3 * (1.-d); - *y = d* y4 + y3 * (1.-d); - *z = d* z4 + z3 * (1.-d); + *x = d * x4 + x3 * (1. - d); + *y = d * y4 + y3 * (1. - d); + *z = d * z4 + z3 * (1. - d); } -Vertex *FindPoint(int inum, Mesh *M){ - Vertex C,*pc; +Vertex *FindPoint(int inum, Mesh * M) +{ + Vertex C, *pc; pc = &C; pc->Num = inum; - if(Tree_Query(M->Points,&pc)){ + if(Tree_Query(M->Points, &pc)) { return pc; } return NULL; } -Vertex *FindVertex(int inum, Mesh *M){ - Vertex C,*pc; +Vertex *FindVertex(int inum, Mesh * M) +{ + Vertex C, *pc; pc = &C; pc->Num = inum; - if(Tree_Query(M->Vertices,&pc)){ + if(Tree_Query(M->Vertices, &pc)) { return pc; } return NULL; } -Curve *FindCurve(int inum, Mesh *M){ - Curve C,*pc; +Curve *FindCurve(int inum, Mesh * M) +{ + Curve C, *pc; pc = &C; pc->Num = inum; - if(Tree_Query(M->Curves,&pc)){ + if(Tree_Query(M->Curves, &pc)) { return pc; } return NULL; } -Surface *FindSurface(int inum, Mesh *M){ - Surface S,*ps; +Surface *FindSurface(int inum, Mesh * M) +{ + Surface S, *ps; ps = &S; ps->Num = inum; - if(Tree_Query(M->Surfaces,&ps)){ + if(Tree_Query(M->Surfaces, &ps)) { return ps; } return NULL; } -Volume *FindVolume(int inum, Mesh *M){ - Volume V,*pv; +Volume *FindVolume(int inum, Mesh * M) +{ + Volume V, *pv; pv = &V; pv->Num = inum; - if(Tree_Query(M->Volumes,&pv)){ + if(Tree_Query(M->Volumes, &pv)) { return pv; } return NULL; } -EdgeLoop *FindEdgeLoop(int inum, Mesh *M){ - EdgeLoop S,*ps; +EdgeLoop *FindEdgeLoop(int inum, Mesh * M) +{ + EdgeLoop S, *ps; ps = &S; ps->Num = inum; - if(Tree_Query(M->EdgeLoops,&ps)){ + if(Tree_Query(M->EdgeLoops, &ps)) { return ps; } return NULL; } -SurfaceLoop *FindSurfaceLoop(int inum, Mesh *M){ - SurfaceLoop S,*ps; +SurfaceLoop *FindSurfaceLoop(int inum, Mesh * M) +{ + SurfaceLoop S, *ps; ps = &S; ps->Num = inum; - if(Tree_Query(M->SurfaceLoops,&ps)){ + if(Tree_Query(M->SurfaceLoops, &ps)) { return ps; } return NULL; } -void CopyVertex (Vertex *v, Vertex *vv){ +void CopyVertex(Vertex * v, Vertex * vv) +{ vv->lc = v->lc; vv->u = v->u; vv->Pos.X = v->Pos.X; @@ -235,54 +253,63 @@ void CopyVertex (Vertex *v, Vertex *vv){ vv->Freeze.Z = v->Freeze.Z; } -Vertex *DuplicateVertex (Vertex *v){ +Vertex *DuplicateVertex(Vertex * v) +{ Vertex *pv; - pv = Create_Vertex(NEWPOINT(),0,0,0,0,0); - CopyVertex (v,pv); - Tree_Insert(THEM->Points,&pv); + pv = Create_Vertex(NEWPOINT(), 0, 0, 0, 0, 0); + CopyVertex(v, pv); + Tree_Insert(THEM->Points, &pv); return pv; } -void CopyCurve (Curve *c, Curve *cc){ - int i,j; +void CopyCurve(Curve * c, Curve * cc) +{ + int i, j; cc->Typ = c->Typ; //We should not copy the meshing method : if the meshes are to //be copied, the meshing algorithm will take care of it //(e.g. ExtrudeMesh()). //cc->Method = c->Method; - for(i=0;i<4;i++)cc->ipar[i] = c->ipar[i]; - for(i=0;i<4;i++)cc->dpar[i] = c->dpar[i]; + for(i = 0; i < 4; i++) + cc->ipar[i] = c->ipar[i]; + for(i = 0; i < 4; i++) + cc->dpar[i] = c->dpar[i]; cc->l = c->l; - for(i=0;i<4;i++)for(j=0;j<4;j++)cc->mat[i][j] = c->mat[i][j]; + for(i = 0; i < 4; i++) + for(j = 0; j < 4; j++) + cc->mat[i][j] = c->mat[i][j]; cc->beg = c->beg; cc->end = c->end; cc->ubeg = c->ubeg; cc->uend = c->uend; - cc->Control_Points = List_Create(List_Nbr(c->Control_Points),1,sizeof(Vertex*)); - List_Copy(c->Control_Points,cc->Control_Points); + cc->Control_Points = + List_Create(List_Nbr(c->Control_Points), 1, sizeof(Vertex *)); + List_Copy(c->Control_Points, cc->Control_Points); End_Curve(cc); - Tree_Insert(THEM->Curves,&cc); + Tree_Insert(THEM->Curves, &cc); } -Curve *DuplicateCurve (Curve *c){ +Curve *DuplicateCurve(Curve * c) +{ Curve *pc; - Vertex *v,*newv; - pc = Create_Curve(NEWLINE(),0,1,NULL,NULL,-1,-1,0.,1.); - CopyCurve(c,pc); - for(int i=0;i<List_Nbr(c->Control_Points);i++){ - List_Read(pc->Control_Points,i,&v); + Vertex *v, *newv; + pc = Create_Curve(NEWLINE(), 0, 1, NULL, NULL, -1, -1, 0., 1.); + CopyCurve(c, pc); + for(int i = 0; i < List_Nbr(c->Control_Points); i++) { + List_Read(pc->Control_Points, i, &v); newv = DuplicateVertex(v); - List_Write(pc->Control_Points,i,&newv); + List_Write(pc->Control_Points, i, &newv); } pc->beg = DuplicateVertex(c->beg); pc->end = DuplicateVertex(c->end); - CreateReversedCurve (THEM,pc); - + CreateReversedCurve(THEM, pc); + return pc; } -void CopySurface (Surface *s, Surface *ss){ - int i,j; +void CopySurface(Surface * s, Surface * ss) +{ + int i, j; ss->Typ = s->Typ; //We should not copy the meshing method: if the meshes are to //be copied, the meshing algorithm will take care of it @@ -290,53 +317,65 @@ void CopySurface (Surface *s, Surface *ss){ //ss->Method = s->Method; ss->Recombine = s->Recombine; ss->RecombineAngle = s->RecombineAngle; - for(i=0;i<4;i++)ss->ipar[i] = s->ipar[i]; + for(i = 0; i < 4; i++) + ss->ipar[i] = s->ipar[i]; ss->Nu = s->Nu; ss->Nv = s->Nv; - ss->a = s->a;ss->b = s->b;ss->c = s->c; ss->d = s->d; - for(i=0;i<3;i++)for(j=0;j<3;j++)ss->plan[i][j] = s->plan[i][j]; - for(i=0;i<3;i++)for(j=0;j<3;j++)ss->invplan[i][j] = s->invplan[i][j]; - ss->Generatrices = List_Create(List_Nbr(s->Generatrices),1,sizeof(Curve*)); - List_Copy(s->Generatrices,ss->Generatrices); - if(s->Control_Points){ - ss->Control_Points = List_Create(List_Nbr(s->Control_Points),1,sizeof(Vertex*)); - List_Copy(s->Control_Points,ss->Control_Points); + ss->a = s->a; + ss->b = s->b; + ss->c = s->c; + ss->d = s->d; + for(i = 0; i < 3; i++) + for(j = 0; j < 3; j++) + ss->plan[i][j] = s->plan[i][j]; + for(i = 0; i < 3; i++) + for(j = 0; j < 3; j++) + ss->invplan[i][j] = s->invplan[i][j]; + ss->Generatrices = + List_Create(List_Nbr(s->Generatrices), 1, sizeof(Curve *)); + List_Copy(s->Generatrices, ss->Generatrices); + if(s->Control_Points) { + ss->Control_Points = + List_Create(List_Nbr(s->Control_Points), 1, sizeof(Vertex *)); + List_Copy(s->Control_Points, ss->Control_Points); } End_Surface(ss); - Tree_Insert(THEM->Surfaces,&ss); + Tree_Insert(THEM->Surfaces, &ss); } -Surface *DuplicateSurface (Surface *s){ +Surface *DuplicateSurface(Surface * s) +{ Surface *ps; - Curve *c,*newc; - Vertex *v,*newv; + Curve *c, *newc; + Vertex *v, *newv; int i; - ps = Create_Surface(NEWSURFACE(),0); - CopySurface(s,ps); - for(i=0;i<List_Nbr(ps->Generatrices);i++){ - List_Read(ps->Generatrices,i,&c); + ps = Create_Surface(NEWSURFACE(), 0); + CopySurface(s, ps); + for(i = 0; i < List_Nbr(ps->Generatrices); i++) { + List_Read(ps->Generatrices, i, &c); newc = DuplicateCurve(c); - List_Write(ps->Generatrices,i,&newc); + List_Write(ps->Generatrices, i, &newc); } - - for(i=0;i<List_Nbr(ps->Control_Points);i++){ - List_Read(ps->Control_Points,i,&v); + + for(i = 0; i < List_Nbr(ps->Control_Points); i++) { + List_Read(ps->Control_Points, i, &v); newv = DuplicateVertex(v); - List_Write(ps->Control_Points,i,&newv); + List_Write(ps->Control_Points, i, &newv); } return ps; } -void CopyShape(int Type, int Num, int *New){ - Surface *s,*news; +void CopyShape(int Type, int Num, int *New) +{ + Surface *s, *news; Curve *c, *newc; - Vertex *v,*newv; - - switch(Type){ + Vertex *v, *newv; + + switch (Type) { case MSH_POINT: - if(!(v = FindPoint(Num,THEM))){ + if(!(v = FindPoint(Num, THEM))) { Msg(GERROR, "Unknown Vertex %d", Num); return; } @@ -350,7 +389,7 @@ void CopyShape(int Type, int Num, int *New){ case MSH_SEGM_CIRC: case MSH_SEGM_ELLI: case MSH_SEGM_NURBS: - if(!(c = FindCurve(Num,THEM))){ + if(!(c = FindCurve(Num, THEM))) { Msg(GERROR, "Unknown Curve %d", Num); return; } @@ -361,7 +400,7 @@ void CopyShape(int Type, int Num, int *New){ case MSH_SURF_TRIC: case MSH_SURF_REGL: case MSH_SURF_PLAN: - if(!(s = FindSurface(Num,THEM))){ + if(!(s = FindSurface(Num, THEM))) { Msg(GERROR, "Unknown Surface %d", Num); return; } @@ -374,59 +413,71 @@ void CopyShape(int Type, int Num, int *New){ } } -void DeletePoint(int ip){ - Vertex *v = FindPoint(ip,THEM); - if(!v) return; +void DeletePoint(int ip) +{ + Vertex *v = FindPoint(ip, THEM); + if(!v) + return; List_T *Curves = Tree2List(THEM->Curves); - for(int i=0;i<List_Nbr(Curves);i++){ + for(int i = 0; i < List_Nbr(Curves); i++) { Curve *c; - List_Read(Curves,i,&c); - for(int j=0;j<List_Nbr(c->Control_Points);j++){ - if(!compareVertex(List_Pointer(c->Control_Points,j),&v))return; + List_Read(Curves, i, &c); + for(int j = 0; j < List_Nbr(c->Control_Points); j++) { + if(!compareVertex(List_Pointer(c->Control_Points, j), &v)) + return; } } List_Delete(Curves); - if(v->Num == THEM->MaxPointNum) THEM->MaxPointNum--; - Tree_Suppress(THEM->Points,&v); + if(v->Num == THEM->MaxPointNum) + THEM->MaxPointNum--; + Tree_Suppress(THEM->Points, &v); } -void DeleteCurve(int ip){ - Curve *c = FindCurve(ip,THEM); - if(!c) return; +void DeleteCurve(int ip) +{ + Curve *c = FindCurve(ip, THEM); + if(!c) + return; List_T *Surfs = Tree2List(THEM->Surfaces); - for(int i=0;i<List_Nbr(Surfs);i++){ + for(int i = 0; i < List_Nbr(Surfs); i++) { Surface *s; - List_Read(Surfs,i,&s); - for(int j=0;j<List_Nbr(s->Generatrices);j++){ - if(!compareCurve(List_Pointer(s->Generatrices,j),&c))return; + List_Read(Surfs, i, &s); + for(int j = 0; j < List_Nbr(s->Generatrices); j++) { + if(!compareCurve(List_Pointer(s->Generatrices, j), &c)) + return; } } List_Delete(Surfs); - if(c->Num == THEM->MaxLineNum) THEM->MaxLineNum--; - Tree_Suppress(THEM->Curves,&c); + if(c->Num == THEM->MaxLineNum) + THEM->MaxLineNum--; + Tree_Suppress(THEM->Curves, &c); } -void DeleteSurface(int is){ +void DeleteSurface(int is) +{ // Il faut absolument coder une // structure coherente pour les volumes. - Surface *s = FindSurface(is,THEM); - if(!s) return; + Surface *s = FindSurface(is, THEM); + if(!s) + return; List_T *Vols = Tree2List(THEM->Volumes); - for(int i=0;i<List_Nbr(Vols);i++){ + for(int i = 0; i < List_Nbr(Vols); i++) { Volume *v; - List_Read(Vols,i,&v); - for(int j=0;j<List_Nbr(v->Surfaces);j++){ - if(!compareCurve(List_Pointer(v->Surfaces,j),&s))return; + List_Read(Vols, i, &v); + for(int j = 0; j < List_Nbr(v->Surfaces); j++) { + if(!compareCurve(List_Pointer(v->Surfaces, j), &s)) + return; } } List_Delete(Vols); - if(s->Num == THEM->MaxSurfaceNum) THEM->MaxSurfaceNum--; - Tree_Suppress(THEM->Surfaces,&s); + if(s->Num == THEM->MaxSurfaceNum) + THEM->MaxSurfaceNum--; + Tree_Suppress(THEM->Surfaces, &s); } -void DeleteShape(int Type, int Num){ - - switch(Type){ +void DeleteShape(int Type, int Num) +{ + switch (Type) { case MSH_POINT: DeletePoint(Num); break; @@ -451,23 +502,27 @@ void DeleteShape(int Type, int Num){ } } -void ColorCurve(int ip, unsigned int col){ - Curve *c = FindCurve(ip,THEM); - if(!c) return; +void ColorCurve(int ip, unsigned int col) +{ + Curve *c = FindCurve(ip, THEM); + if(!c) + return; c->Color.type = 1; c->Color.mesh = c->Color.geom = col; } -void ColorSurface(int is, unsigned int col){ - Surface *s = FindSurface(is,THEM); - if(!s) return; +void ColorSurface(int is, unsigned int col) +{ + Surface *s = FindSurface(is, THEM); + if(!s) + return; s->Color.type = 1; s->Color.mesh = s->Color.geom = col; } -void ColorShape(int Type, int Num, unsigned int Color){ - - switch(Type){ +void ColorShape(int Type, int Num, unsigned int Color) +{ + switch (Type) { case MSH_POINT: break; case MSH_SEGM_LINE: @@ -477,64 +532,72 @@ void ColorShape(int Type, int Num, unsigned int Color){ case MSH_SEGM_CIRC: case MSH_SEGM_ELLI: case MSH_SEGM_NURBS: - ColorCurve(Num,Color); + ColorCurve(Num, Color); break; case MSH_SURF_NURBS: case MSH_SURF_TRIC: case MSH_SURF_REGL: case MSH_SURF_PLAN: - ColorSurface(Num,Color); + ColorSurface(Num, Color); break; default: break; } } -Curve * CreateReversedCurve (Mesh *M,Curve *c){ +Curve *CreateReversedCurve(Mesh * M, Curve * c) +{ Curve *newc; - Vertex *e1,*e2,*e3,*e4; + Vertex *e1, *e2, *e3, *e4; int i; - newc = Create_Curve(-c->Num, c->Typ,1,NULL,NULL,-1,-1,0.,1.); - newc->Control_Points = List_Create(List_Nbr(c->Control_Points), 1, sizeof(Vertex*)); - if (c->Typ == MSH_SEGM_ELLI || c->Typ == MSH_SEGM_ELLI_INV){ - List_Read(c->Control_Points,0,&e1); - List_Read(c->Control_Points,1,&e2); - List_Read(c->Control_Points,2,&e3); - List_Read(c->Control_Points,3,&e4); - List_Add(newc->Control_Points,&e4); - List_Add(newc->Control_Points,&e2); - List_Add(newc->Control_Points,&e3); - List_Add(newc->Control_Points,&e1); + newc = Create_Curve(-c->Num, c->Typ, 1, NULL, NULL, -1, -1, 0., 1.); + newc->Control_Points = + List_Create(List_Nbr(c->Control_Points), 1, sizeof(Vertex *)); + if(c->Typ == MSH_SEGM_ELLI || c->Typ == MSH_SEGM_ELLI_INV) { + List_Read(c->Control_Points, 0, &e1); + List_Read(c->Control_Points, 1, &e2); + List_Read(c->Control_Points, 2, &e3); + List_Read(c->Control_Points, 3, &e4); + List_Add(newc->Control_Points, &e4); + List_Add(newc->Control_Points, &e2); + List_Add(newc->Control_Points, &e3); + List_Add(newc->Control_Points, &e1); } else List_Invert(c->Control_Points, newc->Control_Points); - - if (c->Typ == MSH_SEGM_NURBS && c->k){ - newc->k = (float*)malloc((c->degre + List_Nbr(c->Control_Points)+1)*sizeof(float)); - for(i=0;i<c->degre + List_Nbr(c->Control_Points)+1;i++) - newc->k[c->degre + List_Nbr(c->Control_Points)-i] = c->k[i]; - } - - if (c->Typ == MSH_SEGM_CIRC) newc->Typ = MSH_SEGM_CIRC_INV; - if (c->Typ == MSH_SEGM_CIRC_INV) newc->Typ = MSH_SEGM_CIRC; - if (c->Typ == MSH_SEGM_ELLI) newc->Typ = MSH_SEGM_ELLI_INV; - if (c->Typ == MSH_SEGM_ELLI_INV) newc->Typ = MSH_SEGM_ELLI; - newc->Vertices = List_Create(10 ,1 ,sizeof(Vertex*)); + + if(c->Typ == MSH_SEGM_NURBS && c->k) { + newc->k = + (float *)malloc((c->degre + List_Nbr(c->Control_Points) + 1) * + sizeof(float)); + for(i = 0; i < c->degre + List_Nbr(c->Control_Points) + 1; i++) + newc->k[c->degre + List_Nbr(c->Control_Points) - i] = c->k[i]; + } + + if(c->Typ == MSH_SEGM_CIRC) + newc->Typ = MSH_SEGM_CIRC_INV; + if(c->Typ == MSH_SEGM_CIRC_INV) + newc->Typ = MSH_SEGM_CIRC; + if(c->Typ == MSH_SEGM_ELLI) + newc->Typ = MSH_SEGM_ELLI_INV; + if(c->Typ == MSH_SEGM_ELLI_INV) + newc->Typ = MSH_SEGM_ELLI; + newc->Vertices = List_Create(10, 1, sizeof(Vertex *)); newc->Method = c->Method; - newc->degre = c->degre; + newc->degre = c->degre; newc->beg = c->end; newc->end = c->beg; newc->ubeg = 1. - c->uend; newc->uend = 1. - c->ubeg; End_Curve(newc); - + Curve **pc; - if((pc = (Curve**)Tree_PQuery(M->Curves,&newc))){ - Free_Curve(&newc,0); + if((pc = (Curve **) Tree_PQuery(M->Curves, &newc))) { + Free_Curve(&newc, 0); return *pc; } - else + else Tree_Insert(M->Curves, &newc); return newc; @@ -542,24 +605,25 @@ Curve * CreateReversedCurve (Mesh *M,Curve *c){ -void ModifyLcPoint(int ip, double lc){ - Vertex *v = FindPoint(ip,THEM); - if(v) v->lc = lc; +void ModifyLcPoint(int ip, double lc) +{ + Vertex *v = FindPoint(ip, THEM); + if(v) + v->lc = lc; } -int recognize_seg(int typ, List_T * liste, int *seg){ - int i,beg,end; +int recognize_seg(int typ, List_T * liste, int *seg) +{ + int i, beg, end; Curve *pc; List_T *temp = Tree2List(THEM->Curves); - List_Read(liste,0,&beg); - List_Read(liste,List_Nbr(liste)-1,&end); - for(i=0;i<List_Nbr(temp);i++){ - List_Read(temp,i,&pc); - if(pc->Typ == typ && - pc->beg->Num == beg && - pc->end->Num == end){ + List_Read(liste, 0, &beg); + List_Read(liste, List_Nbr(liste) - 1, &end); + for(i = 0; i < List_Nbr(temp); i++) { + List_Read(temp, i, &pc); + if(pc->Typ == typ && pc->beg->Num == beg && pc->end->Num == end) { List_Delete(temp); *seg = pc->Num; return 1; @@ -571,16 +635,17 @@ int recognize_seg(int typ, List_T * liste, int *seg){ -int recognize_loop(List_T * liste, int *loop){ - int i,res; +int recognize_loop(List_T * liste, int *loop) +{ + int i, res; EdgeLoop *pe; res = 0; *loop = 0; List_T *temp = Tree2List(THEM->EdgeLoops); - for(i=0;i<List_Nbr(temp);i++){ - List_Read(temp,i,&pe); - if(!compare2Lists(pe->Curves,liste,fcmp_absint)){ + for(i = 0; i < List_Nbr(temp); i++) { + List_Read(temp, i, &pe); + if(!compare2Lists(pe->Curves, liste, fcmp_absint)) { res = 1; *loop = pe->Num; break; @@ -590,16 +655,17 @@ int recognize_loop(List_T * liste, int *loop){ return res; } -int recognize_surfloop(List_T * liste, int *loop){ - int i,res; +int recognize_surfloop(List_T * liste, int *loop) +{ + int i, res; EdgeLoop *pe; res = 0; *loop = 0; List_T *temp = Tree2List(THEM->SurfaceLoops); - for(i=0;i<List_Nbr(temp);i++){ - List_Read(temp,i,&pe); - if(!compare2Lists(pe->Curves,liste,fcmp_absint)){ + for(i = 0; i < List_Nbr(temp); i++) { + List_Read(temp, i, &pe); + if(!compare2Lists(pe->Curves, liste, fcmp_absint)) { res = 1; *loop = pe->Num; break; @@ -611,69 +677,78 @@ int recognize_surfloop(List_T * liste, int *loop){ // Linear applications -void SetTranslationMatrix (double matrix[4][4],double T[3]){ +void SetTranslationMatrix(double matrix[4][4], double T[3]) +{ int i, j; - for(i=0;i<4;i++){ - for(j=0;j<4;j++){ - matrix[i][j] = (i==j)? 1.0:0.0; + for(i = 0; i < 4; i++) { + for(j = 0; j < 4; j++) { + matrix[i][j] = (i == j) ? 1.0 : 0.0; } } - for(i=0;i<3;i++)matrix[i][3] = T[i]; -} - -void SetSymmetryMatrix (double matrix[4][4],double A, double B, double C, double D){ - double F = -2.0 / (A*A+B*B+C*C); - matrix[0][0] = 1. + A*A*F; - matrix[0][1] = A*B*F; - matrix[0][2] = A*C*F; - matrix[0][3] = A*D*F; - matrix[1][0] = A*B*F; - matrix[1][1] = 1. + B*B*F; - matrix[1][2] = B*C*F; - matrix[1][3] = B*D*F; - matrix[2][0] = A*C*F; - matrix[2][1] = B*C*F; - matrix[2][2] = 1. + C*C*F; - matrix[2][3] = C*D*F; - matrix[3][0] = B*C*F; - matrix[3][1] = 0.0; - matrix[3][2] = 0.0; - matrix[3][3] = 1.0; -} - -void SetDilatationMatrix (double matrix[4][4],double T[3],double A){ + for(i = 0; i < 3; i++) + matrix[i][3] = T[i]; +} + +void SetSymmetryMatrix(double matrix[4][4], double A, double B, double C, + double D) +{ + double F = -2.0 / (A * A + B * B + C * C); + matrix[0][0] = 1. + A * A * F; + matrix[0][1] = A * B * F; + matrix[0][2] = A * C * F; + matrix[0][3] = A * D * F; + matrix[1][0] = A * B * F; + matrix[1][1] = 1. + B * B * F; + matrix[1][2] = B * C * F; + matrix[1][3] = B * D * F; + matrix[2][0] = A * C * F; + matrix[2][1] = B * C * F; + matrix[2][2] = 1. + C * C * F; + matrix[2][3] = C * D * F; + matrix[3][0] = B * C * F; + matrix[3][1] = 0.0; + matrix[3][2] = 0.0; + matrix[3][3] = 1.0; +} + +void SetDilatationMatrix(double matrix[4][4], double T[3], double A) +{ matrix[0][0] = A; matrix[0][1] = 0.0; matrix[0][2] = 0.0; - matrix[0][3] = T[0]*(1.0-A); + matrix[0][3] = T[0] * (1.0 - A); matrix[1][0] = 0.0; matrix[1][1] = A; matrix[1][2] = 0.0; - matrix[1][3] = T[1]*(1.0-A); + matrix[1][3] = T[1] * (1.0 - A); matrix[2][0] = 0.0; matrix[2][1] = 0.0; matrix[2][2] = A; - matrix[2][3] = T[2]*(1.0-A); + matrix[2][3] = T[2] * (1.0 - A); matrix[3][0] = 0.0; matrix[3][1] = 0.0; matrix[3][2] = 0.0; matrix[3][3] = 1.0; } -static void GramSchmidt (double v1[3], double v2[3], double v3[3]){ +static void GramSchmidt(double v1[3], double v2[3], double v3[3]) +{ double tmp[3]; norme(v1); - prodve(v3,v1,tmp); + prodve(v3, v1, tmp); norme(tmp); - v2[0] = tmp[0];v2[1] = tmp[1];v2[2] = tmp[2]; - prodve(v1,v2,v3); + v2[0] = tmp[0]; + v2[1] = tmp[1]; + v2[2] = tmp[2]; + prodve(v1, v2, v3); norme(v3); } -void SetRotationMatrix(double matrix[4][4],double Axe[3], double alpha){ - double t1[3],t2[3]; - if(Axe[0] != 0.0){ +void SetRotationMatrix(double matrix[4][4], double Axe[3], double alpha) +{ + double t1[3], t2[3]; + if(Axe[0] != 0.0) { t1[0] = 0.0; t1[1] = 1.0; t1[2] = 0.0; @@ -681,7 +756,7 @@ void SetRotationMatrix(double matrix[4][4],double Axe[3], double alpha){ t2[1] = 0.0; t2[2] = 1.0; } - else if(Axe[1] != 0.0){ + else if(Axe[1] != 0.0) { t1[0] = 1.0; t1[1] = 0.0; t1[2] = 0.0; @@ -697,127 +772,157 @@ void SetRotationMatrix(double matrix[4][4],double Axe[3], double alpha){ t2[1] = 1.0; t2[2] = 0.0; } - GramSchmidt(Axe,t1,t2); - double rot[3][3],plan[3][3],invplan[3][3]; - plan[0][0] = Axe[0]; plan[0][1] = Axe[1]; plan[0][2] = Axe[2]; - plan[1][0] = t1[0] ; plan[1][1] = t1[1]; plan[1][2] = t1[2]; - plan[2][0] = t2[0] ; plan[2][1] = t2[1]; plan[2][2] = t2[2]; - rot[2][2] = cos(alpha) ; rot[2][1] = sin(alpha) ; rot[2][0] = 0.; - rot[1][2] = -sin(alpha); rot[1][1] = cos(alpha) ; rot[1][0] = 0.; - rot[0][2] = 0. ; rot[0][1] = 0. ; rot[0][0] = 1.; - int i,j,k; - for(i=0;i<3;i++)for(j=0;j<3;j++)invplan[i][j] = plan[j][i]; + GramSchmidt(Axe, t1, t2); + double rot[3][3], plan[3][3], invplan[3][3]; + plan[0][0] = Axe[0]; + plan[0][1] = Axe[1]; + plan[0][2] = Axe[2]; + plan[1][0] = t1[0]; + plan[1][1] = t1[1]; + plan[1][2] = t1[2]; + plan[2][0] = t2[0]; + plan[2][1] = t2[1]; + plan[2][2] = t2[2]; + rot[2][2] = cos(alpha); + rot[2][1] = sin(alpha); + rot[2][0] = 0.; + rot[1][2] = -sin(alpha); + rot[1][1] = cos(alpha); + rot[1][0] = 0.; + rot[0][2] = 0.; + rot[0][1] = 0.; + rot[0][0] = 1.; + int i, j, k; + for(i = 0; i < 3; i++) + for(j = 0; j < 3; j++) + invplan[i][j] = plan[j][i]; double interm[3][3]; - for(i=0;i<3;i++)for(j=0;j<3;j++){ - interm[i][j] = 0.0; - for(k=0;k<3;k++)interm[i][j] += invplan[i][k] * rot[k][j]; - } - for(i=0;i<4;i++)for(j=0;j<4;j++)matrix[i][j] = 0.0; - for(i=0;i<3;i++)for(j=0;j<3;j++){ - for(k=0;k<3;k++)matrix[i][j] += interm[i][k] * plan[k][j]; - } + for(i = 0; i < 3; i++) + for(j = 0; j < 3; j++) { + interm[i][j] = 0.0; + for(k = 0; k < 3; k++) + interm[i][j] += invplan[i][k] * rot[k][j]; + } + for(i = 0; i < 4; i++) + for(j = 0; j < 4; j++) + matrix[i][j] = 0.0; + for(i = 0; i < 3; i++) + for(j = 0; j < 3; j++) { + for(k = 0; k < 3; k++) + matrix[i][j] += interm[i][k] * plan[k][j]; + } matrix[3][3] = 1.0; } -static void vecmat4x4(double mat[4][4],double vec[4], double res[4]){ - int i,j; - for(i=0;i<4;i++){ +static void vecmat4x4(double mat[4][4], double vec[4], double res[4]) +{ + int i, j; + for(i = 0; i < 4; i++) { res[i] = 0.0; - for(j=0;j<4;j++){ + for(j = 0; j < 4; j++) { res[i] += mat[i][j] * vec[j]; } } } -void ApplyTransformationToPoint(double matrix[4][4], Vertex *v){ - double pos[4],vec[4]; +void ApplyTransformationToPoint(double matrix[4][4], Vertex * v) +{ + double pos[4], vec[4]; if(!ListOfTransformedPoints) - ListOfTransformedPoints = List_Create(50,50,sizeof(int)); - - if(!List_Search(ListOfTransformedPoints,&v->Num,fcmp_absint)){ - List_Add(ListOfTransformedPoints,&v->Num); + ListOfTransformedPoints = List_Create(50, 50, sizeof(int)); + + if(!List_Search(ListOfTransformedPoints, &v->Num, fcmp_absint)) { + List_Add(ListOfTransformedPoints, &v->Num); } else return; - + vec[0] = v->Pos.X; vec[1] = v->Pos.Y; vec[2] = v->Pos.Z; vec[3] = v->w; - vecmat4x4(matrix,vec,pos); + vecmat4x4(matrix, vec, pos); v->Pos.X = pos[0]; v->Pos.Y = pos[1]; v->Pos.Z = pos[2]; v->w = pos[3]; } -void ApplyTransformationToCurve (double matrix[4][4],Curve *c){ +void ApplyTransformationToCurve(double matrix[4][4], Curve * c) +{ Vertex *v; - - ApplyTransformationToPoint (matrix,c->beg); - ApplyTransformationToPoint (matrix,c->end); - - for(int i=0;i<List_Nbr(c->Control_Points);i++){ - List_Read(c->Control_Points,i,&v); - ApplyTransformationToPoint (matrix,v); + + ApplyTransformationToPoint(matrix, c->beg); + ApplyTransformationToPoint(matrix, c->end); + + for(int i = 0; i < List_Nbr(c->Control_Points); i++) { + List_Read(c->Control_Points, i, &v); + ApplyTransformationToPoint(matrix, v); } End_Curve(c); } -void printCurve(Curve *c){ +void printCurve(Curve * c) +{ Vertex *v; int N = List_Nbr(c->Control_Points); - Msg(DEBUG,"Curve %d %d cp (%d->%d)",c->Num,N,c->beg->Num,c->end->Num); - for(int i=0;i<N;i++){ - List_Read(c->Control_Points,i,&v); - Msg(DEBUG,"Vertex %d (%g,%g,%g,%g)",v->Num,v->Pos.X,v->Pos.Y,v->Pos.Z,v->lc); + Msg(DEBUG, "Curve %d %d cp (%d->%d)", c->Num, N, c->beg->Num, c->end->Num); + for(int i = 0; i < N; i++) { + List_Read(c->Control_Points, i, &v); + Msg(DEBUG, "Vertex %d (%g,%g,%g,%g)", v->Num, v->Pos.X, v->Pos.Y, + v->Pos.Z, v->lc); } } -void ApplyTransformationToSurface (double matrix[4][4],Surface *s){ +void ApplyTransformationToSurface(double matrix[4][4], Surface * s) +{ Curve *c; Vertex *v; int i; - for(i=0;i<List_Nbr(s->Generatrices);i++){ - List_Read(s->Generatrices,i,&c); - ApplyTransformationToCurve (matrix,c); + for(i = 0; i < List_Nbr(s->Generatrices); i++) { + List_Read(s->Generatrices, i, &c); + ApplyTransformationToCurve(matrix, c); } - for(i=0;i<List_Nbr(s->Control_Points);i++){ - List_Read(s->Control_Points,i,&v); - ApplyTransformationToPoint (matrix,v); + for(i = 0; i < List_Nbr(s->Control_Points); i++) { + List_Read(s->Control_Points, i, &v); + ApplyTransformationToPoint(matrix, v); } End_Surface(s); } -void printSurface(Surface*s){ +void printSurface(Surface * s) +{ Curve *c; int N = List_Nbr(s->Generatrices); - Msg(DEBUG,"Surface %d, %d generatrices",s->Num,N); - for(int i=0;i<N;i++){ - List_Read(s->Generatrices,i,&c); + Msg(DEBUG, "Surface %d, %d generatrices", s->Num, N); + for(int i = 0; i < N; i++) { + List_Read(s->Generatrices, i, &c); printCurve(c); } } -void ApplicationOnShapes(double matrix[4][4], List_T *ListShapes){ +void ApplicationOnShapes(double matrix[4][4], List_T * ListShapes) +{ int i; Shape O; Vertex *v; Curve *c; Surface *s; - + List_Reset(ListOfTransformedPoints); - for(i=0;i<List_Nbr(ListShapes);i++){ - List_Read(ListShapes,i,&O); - switch(O.Type){ + for(i = 0; i < List_Nbr(ListShapes); i++) { + List_Read(ListShapes, i, &O); + switch (O.Type) { case MSH_POINT: - v = FindPoint(O.Num,THEM); - if(v) ApplyTransformationToPoint(matrix, v); - else Msg(GERROR, "Unknown Point %d", O.Num); + v = FindPoint(O.Num, THEM); + if(v) + ApplyTransformationToPoint(matrix, v); + else + Msg(GERROR, "Unknown Point %d", O.Num); break; case MSH_SEGM_LINE: case MSH_SEGM_SPLN: @@ -826,20 +931,25 @@ void ApplicationOnShapes(double matrix[4][4], List_T *ListShapes){ case MSH_SEGM_CIRC: case MSH_SEGM_ELLI: case MSH_SEGM_NURBS: - c = FindCurve(O.Num,THEM); - if(c) ApplyTransformationToCurve(matrix, c); - else Msg(GERROR, "Unknown Curve %d", O.Num); + c = FindCurve(O.Num, THEM); + if(c) + ApplyTransformationToCurve(matrix, c); + else + Msg(GERROR, "Unknown Curve %d", O.Num); break; - case MSH_SURF_NURBS : - case MSH_SURF_REGL : - case MSH_SURF_TRIC : - case MSH_SURF_PLAN : - s = FindSurface(O.Num,THEM); - if(s) ApplyTransformationToSurface(matrix, s); - else Msg(GERROR, "Unknown Surface %d", O.Num); + case MSH_SURF_NURBS: + case MSH_SURF_REGL: + case MSH_SURF_TRIC: + case MSH_SURF_PLAN: + s = FindSurface(O.Num, THEM); + if(s) + ApplyTransformationToSurface(matrix, s); + else + Msg(GERROR, "Unknown Surface %d", O.Num); break; default: - Msg(GERROR, "Impossible to transform entity %d (of type %d)", O.Num, O.Type); + Msg(GERROR, "Impossible to transform entity %d (of type %d)", O.Num, + O.Type); break; } } @@ -847,82 +957,103 @@ void ApplicationOnShapes(double matrix[4][4], List_T *ListShapes){ List_Reset(ListOfTransformedPoints); } -void TranslateShapes(double X,double Y,double Z, - List_T *ListShapes, int isFinal){ - double T[3],matrix[4][4]; +void TranslateShapes(double X, double Y, double Z, + List_T * ListShapes, int isFinal) +{ + double T[3], matrix[4][4]; - T[0] = X; T[1] = Y; T[2] = Z; - SetTranslationMatrix(matrix,T); - ApplicationOnShapes(matrix,ListShapes); + T[0] = X; + T[1] = Y; + T[2] = Z; + SetTranslationMatrix(matrix, T); + ApplicationOnShapes(matrix, ListShapes); - if(CTX.geom.auto_coherence && isFinal) ReplaceAllDuplicates(THEM); + if(CTX.geom.auto_coherence && isFinal) + ReplaceAllDuplicates(THEM); } -void DilatShapes(double X,double Y,double Z, double A, - List_T *ListShapes, int isFinal){ - double T[3],matrix[4][4]; +void DilatShapes(double X, double Y, double Z, double A, + List_T * ListShapes, int isFinal) +{ + double T[3], matrix[4][4]; - T[0] = X; T[1] = Y; T[2] = Z; - SetDilatationMatrix(matrix,T,A); - ApplicationOnShapes(matrix,ListShapes); + T[0] = X; + T[1] = Y; + T[2] = Z; + SetDilatationMatrix(matrix, T, A); + ApplicationOnShapes(matrix, ListShapes); - if(CTX.geom.auto_coherence) ReplaceAllDuplicates(THEM); + if(CTX.geom.auto_coherence) + ReplaceAllDuplicates(THEM); } -void RotateShapes (double Ax,double Ay,double Az, - double Px,double Py, double Pz, - double alpha, List_T *ListShapes){ +void RotateShapes(double Ax, double Ay, double Az, + double Px, double Py, double Pz, + double alpha, List_T * ListShapes) +{ double A[3], T[3], matrix[4][4]; - T[0] = -Px; T[1] = -Py; T[2] = -Pz; - SetTranslationMatrix(matrix,T); - ApplicationOnShapes(matrix,ListShapes); - - A[0] = Ax; A[1] = Ay; A[2] = Az; - SetRotationMatrix(matrix,A,alpha); - ApplicationOnShapes(matrix,ListShapes); - - T[0] = Px; T[1] = Py; T[2] = Pz; - SetTranslationMatrix(matrix,T); - ApplicationOnShapes(matrix,ListShapes); - - if(CTX.geom.auto_coherence) ReplaceAllDuplicates(THEM); + T[0] = -Px; + T[1] = -Py; + T[2] = -Pz; + SetTranslationMatrix(matrix, T); + ApplicationOnShapes(matrix, ListShapes); + + A[0] = Ax; + A[1] = Ay; + A[2] = Az; + SetRotationMatrix(matrix, A, alpha); + ApplicationOnShapes(matrix, ListShapes); + + T[0] = Px; + T[1] = Py; + T[2] = Pz; + SetTranslationMatrix(matrix, T); + ApplicationOnShapes(matrix, ListShapes); + + if(CTX.geom.auto_coherence) + ReplaceAllDuplicates(THEM); } -void SymmetryShapes (double A,double B,double C, - double D, List_T *ListShapes, int x){ +void SymmetryShapes(double A, double B, double C, + double D, List_T * ListShapes, int x) +{ double matrix[4][4]; - SetSymmetryMatrix(matrix,A,B,C,D); - ApplicationOnShapes(matrix,ListShapes); + SetSymmetryMatrix(matrix, A, B, C, D); + ApplicationOnShapes(matrix, ListShapes); - if(CTX.geom.auto_coherence) ReplaceAllDuplicates(THEM); + if(CTX.geom.auto_coherence) + ReplaceAllDuplicates(THEM); } // Extrusion routines -void ProtudeXYZ (double &x, double &y, double &z, ExtrudeParams *e){ +void ProtudeXYZ(double &x, double &y, double &z, ExtrudeParams * e) +{ double matrix[4][4]; double T[3]; - Vertex v(x,y,z); + Vertex v(x, y, z); T[0] = -e->geo.pt[0]; T[1] = -e->geo.pt[1]; T[2] = -e->geo.pt[2]; - SetTranslationMatrix(matrix,T); + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToPoint(matrix,&v); + ApplyTransformationToPoint(matrix, &v); - SetRotationMatrix(matrix,e->geo.axe,e->geo.angle); + SetRotationMatrix(matrix, e->geo.axe, e->geo.angle); List_Reset(ListOfTransformedPoints); - ApplyTransformationToPoint(matrix,&v); + ApplyTransformationToPoint(matrix, &v); - T[0] = -T[0]; T[1] = -T[1]; T[2] = -T[2]; - SetTranslationMatrix(matrix,T); + T[0] = -T[0]; + T[1] = -T[1]; + T[2] = -T[2]; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToPoint(matrix,&v); + ApplyTransformationToPoint(matrix, &v); x = v.Pos.X; y = v.Pos.Y; @@ -932,132 +1063,156 @@ void ProtudeXYZ (double &x, double &y, double &z, ExtrudeParams *e){ } -void Extrude_ProtudePoint(int type, int ip, - double T0, double T1, double T2, - double A0, double A1, double A2, +void Extrude_ProtudePoint(int type, int ip, + double T0, double T1, double T2, + double A0, double A1, double A2, double X0, double X1, double X2, double alpha, - Curve **pc, Curve **prc, - ExtrudeParams *e){ - double xnew,ynew,znew,matrix[4][4],T[3],Ax[3],d; - Vertex V,*pv,*newp,*chapeau; + Curve ** pc, Curve ** prc, ExtrudeParams * e) +{ + double xnew, ynew, znew, matrix[4][4], T[3], Ax[3], d; + Vertex V, *pv, *newp, *chapeau; Curve *c; int i; - - pv= &V; + + pv = &V; pv->Num = ip; *pc = *prc = NULL; - if(!Tree_Query(THEM->Points, &pv)) return; + if(!Tree_Query(THEM->Points, &pv)) + return; Msg(DEBUG, "Extrude Point %d", ip); chapeau = DuplicateVertex(pv); - switch(type){ + switch (type) { - case TRANSLATE : - T[0] = T0; T[1] = T1; T[2] = T2; - SetTranslationMatrix(matrix,T); + case TRANSLATE: + T[0] = T0; + T[1] = T1; + T[2] = T2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToPoint(matrix,chapeau); + ApplyTransformationToPoint(matrix, chapeau); - if(!comparePosition(&pv,&chapeau)) return ; - c = Create_Curve(NEWLINE(),MSH_SEGM_LINE,1,NULL,NULL,-1,-1,0.,1.); - c->Control_Points = List_Create(2,1,sizeof(Vertex*)); + if(!comparePosition(&pv, &chapeau)) + return; + c = Create_Curve(NEWLINE(), MSH_SEGM_LINE, 1, NULL, NULL, -1, -1, 0., 1.); + c->Control_Points = List_Create(2, 1, sizeof(Vertex *)); c->Extrude = new ExtrudeParams; - c->Extrude->fill(type,T0,T1,T2,A0,A1,A2,X0,X1,X2,alpha); - if(e) c->Extrude->mesh = e->mesh; + c->Extrude->fill(type, T0, T1, T2, A0, A1, A2, X0, X1, X2, alpha); + if(e) + c->Extrude->mesh = e->mesh; - List_Add(c->Control_Points,&pv); - List_Add(c->Control_Points,&chapeau); + List_Add(c->Control_Points, &pv); + List_Add(c->Control_Points, &chapeau); c->beg = pv; c->end = chapeau; break; - case ROTATE : - T[0] = -X0; T[1] = -X1; T[2] = -X2; - SetTranslationMatrix(matrix,T); + case ROTATE: + T[0] = -X0; + T[1] = -X1; + T[2] = -X2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToPoint(matrix,chapeau); + ApplyTransformationToPoint(matrix, chapeau); - Ax[0] = A0; Ax[1] = A1; Ax[2] = A2; - SetRotationMatrix(matrix,Ax,alpha); + Ax[0] = A0; + Ax[1] = A1; + Ax[2] = A2; + SetRotationMatrix(matrix, Ax, alpha); List_Reset(ListOfTransformedPoints); - ApplyTransformationToPoint(matrix,chapeau); + ApplyTransformationToPoint(matrix, chapeau); - T[0] = X0; T[1] = X1; T[2] = X2; - SetTranslationMatrix(matrix,T); + T[0] = X0; + T[1] = X1; + T[2] = X2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToPoint(matrix,chapeau); + ApplyTransformationToPoint(matrix, chapeau); - if(!comparePosition(&pv,&chapeau)) return ; - c = Create_Curve(NEWLINE(),MSH_SEGM_CIRC,1,NULL,NULL,-1,-1,0.,1.); - c->Control_Points = List_Create(3,1,sizeof(Vertex*)); + if(!comparePosition(&pv, &chapeau)) + return; + c = Create_Curve(NEWLINE(), MSH_SEGM_CIRC, 1, NULL, NULL, -1, -1, 0., 1.); + c->Control_Points = List_Create(3, 1, sizeof(Vertex *)); c->Extrude = new ExtrudeParams; - c->Extrude->fill(type,T0,T1,T2,A0,A1,A2,X0,X1,X2,alpha); - if(e) c->Extrude->mesh = e->mesh; - - List_Add(c->Control_Points,&pv); - dist_ddg(pv->Pos.X,pv->Pos.Y,pv->Pos.Z, - chapeau->Pos.X,chapeau->Pos.Y,chapeau->Pos.Z, - X0,X1,X2,X0+A0,X1+A1,X2+A2,&xnew,&ynew,&znew); + c->Extrude->fill(type, T0, T1, T2, A0, A1, A2, X0, X1, X2, alpha); + if(e) + c->Extrude->mesh = e->mesh; + + List_Add(c->Control_Points, &pv); + dist_ddg(pv->Pos.X, pv->Pos.Y, pv->Pos.Z, + chapeau->Pos.X, chapeau->Pos.Y, chapeau->Pos.Z, + X0, X1, X2, X0 + A0, X1 + A1, X2 + A2, &xnew, &ynew, &znew); newp = DuplicateVertex(pv); newp->Pos.X = xnew; newp->Pos.Y = ynew; newp->Pos.Z = znew; - List_Add(c->Control_Points,&newp); - List_Add(c->Control_Points,&chapeau); + List_Add(c->Control_Points, &newp); + List_Add(c->Control_Points, &chapeau); c->beg = pv; c->end = chapeau; break; - case TRANSLATE_ROTATE : + case TRANSLATE_ROTATE: d = CTX.geom.extrude_spline_points; - d = d?d:1; - c = Create_Curve(NEWLINE(),MSH_SEGM_SPLN,1,NULL,NULL,-1,-1,0.,1.); - c->Control_Points = List_Create(CTX.geom.extrude_spline_points+1,1,sizeof(Vertex*)); + d = d ? d : 1; + c = Create_Curve(NEWLINE(), MSH_SEGM_SPLN, 1, NULL, NULL, -1, -1, 0., 1.); + c->Control_Points = + List_Create(CTX.geom.extrude_spline_points + 1, 1, sizeof(Vertex *)); c->Extrude = new ExtrudeParams; - c->Extrude->fill(type,T0,T1,T2,A0,A1,A2,X0,X1,X2,alpha); - if(e) c->Extrude->mesh = e->mesh; - List_Add(c->Control_Points,&pv); + c->Extrude->fill(type, T0, T1, T2, A0, A1, A2, X0, X1, X2, alpha); + if(e) + c->Extrude->mesh = e->mesh; + List_Add(c->Control_Points, &pv); c->beg = pv; - for(i=0 ; i<CTX.geom.extrude_spline_points ; i++){ - if(i) chapeau = DuplicateVertex(chapeau); - - T[0] = -X0; T[1] = -X1; T[2] = -X2; - SetTranslationMatrix(matrix,T); + for(i = 0; i < CTX.geom.extrude_spline_points; i++) { + if(i) + chapeau = DuplicateVertex(chapeau); + + T[0] = -X0; + T[1] = -X1; + T[2] = -X2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToPoint(matrix,chapeau); + ApplyTransformationToPoint(matrix, chapeau); - Ax[0] = A0; Ax[1] = A1; Ax[2] = A2; - SetRotationMatrix(matrix,Ax,alpha/d); + Ax[0] = A0; + Ax[1] = A1; + Ax[2] = A2; + SetRotationMatrix(matrix, Ax, alpha / d); List_Reset(ListOfTransformedPoints); - ApplyTransformationToPoint(matrix,chapeau); + ApplyTransformationToPoint(matrix, chapeau); - T[0] = X0; T[1] = X1; T[2] = X2; - SetTranslationMatrix(matrix,T); + T[0] = X0; + T[1] = X1; + T[2] = X2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToPoint(matrix,chapeau); + ApplyTransformationToPoint(matrix, chapeau); - T[0] = T0/d; T[1] = T1/d; T[2] = T2/d; - SetTranslationMatrix(matrix,T); + T[0] = T0 / d; + T[1] = T1 / d; + T[2] = T2 / d; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToPoint(matrix,chapeau); + ApplyTransformationToPoint(matrix, chapeau); - List_Add(c->Control_Points,&chapeau); + List_Add(c->Control_Points, &chapeau); } c->end = chapeau; break; - default : + default: Msg(GERROR, "Unknown extrusion type"); return; } End_Curve(c); - Tree_Add(THEM->Curves,&c); - CreateReversedCurve (THEM,c); + Tree_Add(THEM->Curves, &c); + CreateReversedCurve(THEM, c); *pc = c; - *prc = FindCurve(-c->Num,THEM); + *prc = FindCurve(-c->Num, THEM); List_Reset(ListOfTransformedPoints); } @@ -1065,122 +1220,143 @@ void Extrude_ProtudePoint(int type, int ip, Surface *Extrude_ProtudeCurve(int type, int ic, double T0, double T1, double T2, double A0, double A1, double A2, - double X0, double X1, double X2, double alpha, - int final, ExtrudeParams *e){ - double matrix[4][4],T[3],Ax[3]; - Curve *CurveBeg,*CurveEnd; - Curve *ReverseChapeau,*ReverseBeg,*ReverseEnd; + double X0, double X1, double X2, double alpha, + int final, ExtrudeParams * e) +{ + double matrix[4][4], T[3], Ax[3]; + Curve *CurveBeg, *CurveEnd; + Curve *ReverseChapeau, *ReverseBeg, *ReverseEnd; Curve *pc, *revpc, *chapeau; Surface *s; - - pc = FindCurve(ic,THEM); - revpc = FindCurve(-ic,THEM); - - if(!pc || !revpc) return NULL; + + pc = FindCurve(ic, THEM); + revpc = FindCurve(-ic, THEM); + + if(!pc || !revpc) + return NULL; Msg(DEBUG, "Extrude Curve %d", ic); chapeau = DuplicateCurve(pc); - + chapeau->Extrude = new ExtrudeParams(COPIED_ENTITY); - chapeau->Extrude->fill(type,T0,T1,T2,A0,A1,A2,X0,X1,X2,alpha); + chapeau->Extrude->fill(type, T0, T1, T2, A0, A1, A2, X0, X1, X2, alpha); chapeau->Extrude->geo.Source = pc->Num; - if(e) chapeau->Extrude->mesh = e->mesh; - - switch(type){ - case TRANSLATE : - T[0] = T0; T[1] = T1; T[2] = T2; - SetTranslationMatrix(matrix,T); + if(e) + chapeau->Extrude->mesh = e->mesh; + + switch (type) { + case TRANSLATE: + T[0] = T0; + T[1] = T1; + T[2] = T2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToCurve(matrix,chapeau); + ApplyTransformationToCurve(matrix, chapeau); break; - case ROTATE : - T[0] = -X0; T[1] = -X1; T[2] = -X2; - SetTranslationMatrix(matrix,T); + case ROTATE: + T[0] = -X0; + T[1] = -X1; + T[2] = -X2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToCurve(matrix,chapeau); - - Ax[0] = A0; Ax[1] = A1; Ax[2] = A2; - SetRotationMatrix(matrix,Ax,alpha); + ApplyTransformationToCurve(matrix, chapeau); + + Ax[0] = A0; + Ax[1] = A1; + Ax[2] = A2; + SetRotationMatrix(matrix, Ax, alpha); List_Reset(ListOfTransformedPoints); - ApplyTransformationToCurve(matrix,chapeau); - - T[0] = X0; T[1] = X1; T[2] = X2; - SetTranslationMatrix(matrix,T); + ApplyTransformationToCurve(matrix, chapeau); + + T[0] = X0; + T[1] = X1; + T[2] = X2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToCurve(matrix,chapeau); + ApplyTransformationToCurve(matrix, chapeau); break; - case TRANSLATE_ROTATE : - T[0] = -X0; T[1] = -X1; T[2] = -X2; - SetTranslationMatrix(matrix,T); + case TRANSLATE_ROTATE: + T[0] = -X0; + T[1] = -X1; + T[2] = -X2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToCurve(matrix,chapeau); - - Ax[0] = A0; Ax[1] = A1; Ax[2] = A2; - SetRotationMatrix(matrix,Ax,alpha); + ApplyTransformationToCurve(matrix, chapeau); + + Ax[0] = A0; + Ax[1] = A1; + Ax[2] = A2; + SetRotationMatrix(matrix, Ax, alpha); List_Reset(ListOfTransformedPoints); - ApplyTransformationToCurve(matrix,chapeau); - - T[0] = X0; T[1] = X1; T[2] = X2; - SetTranslationMatrix(matrix,T); + ApplyTransformationToCurve(matrix, chapeau); + + T[0] = X0; + T[1] = X1; + T[2] = X2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToCurve(matrix,chapeau); + ApplyTransformationToCurve(matrix, chapeau); - T[0] = T0; T[1] = T1; T[2] = T2; - SetTranslationMatrix(matrix,T); + T[0] = T0; + T[1] = T1; + T[2] = T2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToCurve(matrix,chapeau); + ApplyTransformationToCurve(matrix, chapeau); break; - default : + default: Msg(GERROR, "Unknown extrusion type"); return NULL; } - Extrude_ProtudePoint(type,pc->beg->Num,T0,T1,T2, - A0,A1,A2,X0,X1,X2,alpha, - &CurveBeg,&ReverseBeg,e); - Extrude_ProtudePoint(type,pc->end->Num,T0,T1,T2, - A0,A1,A2,X0,X1,X2,alpha, - &CurveEnd,&ReverseEnd,e); - - if(!CurveBeg && !CurveEnd) return NULL; + Extrude_ProtudePoint(type, pc->beg->Num, T0, T1, T2, + A0, A1, A2, X0, X1, X2, alpha, + &CurveBeg, &ReverseBeg, e); + Extrude_ProtudePoint(type, pc->end->Num, T0, T1, T2, + A0, A1, A2, X0, X1, X2, alpha, + &CurveEnd, &ReverseEnd, e); + + if(!CurveBeg && !CurveEnd) + return NULL; if(!CurveBeg || !CurveEnd) - s = Create_Surface(NEWSURFACE(),MSH_SURF_TRIC); + s = Create_Surface(NEWSURFACE(), MSH_SURF_TRIC); else - s = Create_Surface(NEWSURFACE(),MSH_SURF_REGL); + s = Create_Surface(NEWSURFACE(), MSH_SURF_REGL); - s->Generatrices = List_Create(4,1,sizeof(Curve*)); + s->Generatrices = List_Create(4, 1, sizeof(Curve *)); s->Extrude = new ExtrudeParams; - s->Extrude->fill(type,T0,T1,T2,A0,A1,A2,X0,X1,X2,alpha); + s->Extrude->fill(type, T0, T1, T2, A0, A1, A2, X0, X1, X2, alpha); s->Extrude->geo.Source = pc->Num; - if(e) s->Extrude->mesh = e->mesh; - - ReverseChapeau = FindCurve(-chapeau->Num,THEM); + if(e) + s->Extrude->mesh = e->mesh; + + ReverseChapeau = FindCurve(-chapeau->Num, THEM); - if(!CurveBeg){ - List_Add(s->Generatrices,&pc); - List_Add(s->Generatrices,&CurveEnd); - List_Add(s->Generatrices,&ReverseChapeau); + if(!CurveBeg) { + List_Add(s->Generatrices, &pc); + List_Add(s->Generatrices, &CurveEnd); + List_Add(s->Generatrices, &ReverseChapeau); } - else if(!CurveEnd){ - List_Add(s->Generatrices,&ReverseChapeau); - List_Add(s->Generatrices,&ReverseBeg); - List_Add(s->Generatrices,&pc); + else if(!CurveEnd) { + List_Add(s->Generatrices, &ReverseChapeau); + List_Add(s->Generatrices, &ReverseBeg); + List_Add(s->Generatrices, &pc); } - else{ - List_Add(s->Generatrices,&pc); - List_Add(s->Generatrices,&CurveEnd); - List_Add(s->Generatrices,&ReverseChapeau); - List_Add(s->Generatrices,&ReverseBeg); + else { + List_Add(s->Generatrices, &pc); + List_Add(s->Generatrices, &CurveEnd); + List_Add(s->Generatrices, &ReverseChapeau); + List_Add(s->Generatrices, &ReverseBeg); } End_Surface(s); - Tree_Add(THEM->Surfaces,&s); + Tree_Add(THEM->Surfaces, &s); List_Reset(ListOfTransformedPoints); - if(final && CTX.geom.auto_coherence){ + if(final && CTX.geom.auto_coherence) { ReplaceAllDuplicates(THEM); return NULL; } @@ -1192,136 +1368,169 @@ void Extrude_ProtudeSurface(int type, int is, double T0, double T1, double T2, double A0, double A1, double A2, double X0, double X1, double X2, double alpha, - int NewVolume, ExtrudeParams *e){ - double matrix[4][4],T[3],Ax[3]; - Curve *c,*c2; + int NewVolume, ExtrudeParams * e) +{ + double matrix[4][4], T[3], Ax[3]; + Curve *c, *c2; int i; - Surface *s,*ps, *chapeau; + Surface *s, *ps, *chapeau; Volume *pv = NULL; - - if(!(ps = FindSurface(is,THEM))) return; + + if(!(ps = FindSurface(is, THEM))) + return; Msg(DEBUG, "Extrude Surface %d", is); chapeau = DuplicateSurface(ps); chapeau->Extrude = new ExtrudeParams(COPIED_ENTITY); - chapeau->Extrude->fill(type,T0,T1,T2,A0,A1,A2,X0,X1,X2,alpha); + chapeau->Extrude->fill(type, T0, T1, T2, A0, A1, A2, X0, X1, X2, alpha); chapeau->Extrude->geo.Source = ps->Num; - if(e) chapeau->Extrude->mesh = e->mesh; - - for(i=0;i<List_Nbr(chapeau->Generatrices);i++) { - List_Read(ps->Generatrices,i,&c2); - List_Read(chapeau->Generatrices,i,&c); - if(c->Num<0) - if(!(c = FindCurve(-c->Num,THEM))){ - Msg(GERROR, "Unknown Curve %d", -c->Num); - return; + if(e) + chapeau->Extrude->mesh = e->mesh; + + for(i = 0; i < List_Nbr(chapeau->Generatrices); i++) { + List_Read(ps->Generatrices, i, &c2); + List_Read(chapeau->Generatrices, i, &c); + if(c->Num < 0) + if(!(c = FindCurve(-c->Num, THEM))) { + Msg(GERROR, "Unknown Curve %d", -c->Num); + return; } c->Extrude = new ExtrudeParams(COPIED_ENTITY); - c->Extrude->fill(type,T0,T1,T2,A0,A1,A2,X0,X1,X2,alpha); + c->Extrude->fill(type, T0, T1, T2, A0, A1, A2, X0, X1, X2, alpha); //pas de abs()! il faut le signe pour copy_mesh dans ExtrudeMesh - c->Extrude->geo.Source = c2->Num; - if(e) c->Extrude->mesh = e->mesh; + c->Extrude->geo.Source = c2->Num; + if(e) + c->Extrude->mesh = e->mesh; } - - if(NewVolume){ - pv = Create_Volume(NewVolume,0); + + if(NewVolume) { + pv = Create_Volume(NewVolume, 0); pv->Extrude = new ExtrudeParams; - pv->Extrude->fill(type,T0,T1,T2,A0,A1,A2,X0,X1,X2,alpha); + pv->Extrude->fill(type, T0, T1, T2, A0, A1, A2, X0, X1, X2, alpha); pv->Extrude->geo.Source = is; - if(e) pv->Extrude->mesh = e->mesh; - if(pv) List_Add(pv->Surfaces,&ps); - } - if(pv) List_Add(pv->Surfaces,&chapeau); - - for(i=0;i<List_Nbr(ps->Generatrices);i++){ - List_Read(ps->Generatrices,i,&c); - s = Extrude_ProtudeCurve(type,c->Num,T0,T1,T2,A0,A1,A2,X0,X1,X2,alpha,0,e); - if(pv && s) List_Add(pv->Surfaces,&s); - } - - switch(type){ - case TRANSLATE : - T[0] = T0; T[1] = T1; T[2] = T2; - SetTranslationMatrix(matrix,T); + if(e) + pv->Extrude->mesh = e->mesh; + if(pv) + List_Add(pv->Surfaces, &ps); + } + if(pv) + List_Add(pv->Surfaces, &chapeau); + + for(i = 0; i < List_Nbr(ps->Generatrices); i++) { + List_Read(ps->Generatrices, i, &c); + s = + Extrude_ProtudeCurve(type, c->Num, T0, T1, T2, A0, A1, A2, X0, X1, X2, + alpha, 0, e); + if(pv && s) + List_Add(pv->Surfaces, &s); + } + + switch (type) { + case TRANSLATE: + T[0] = T0; + T[1] = T1; + T[2] = T2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToSurface(matrix,chapeau); + ApplyTransformationToSurface(matrix, chapeau); break; - case ROTATE : - T[0] = -X0; T[1] = -X1; T[2] = -X2; - SetTranslationMatrix(matrix,T); + case ROTATE: + T[0] = -X0; + T[1] = -X1; + T[2] = -X2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToSurface(matrix,chapeau); - - Ax[0] = A0; Ax[1] = A1; Ax[2] = A2; - SetRotationMatrix(matrix,Ax,alpha); + ApplyTransformationToSurface(matrix, chapeau); + + Ax[0] = A0; + Ax[1] = A1; + Ax[2] = A2; + SetRotationMatrix(matrix, Ax, alpha); List_Reset(ListOfTransformedPoints); - ApplyTransformationToSurface(matrix,chapeau); - - T[0] = X0; T[1] = X1; T[2] = X2; - SetTranslationMatrix(matrix,T); + ApplyTransformationToSurface(matrix, chapeau); + + T[0] = X0; + T[1] = X1; + T[2] = X2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToSurface(matrix,chapeau); + ApplyTransformationToSurface(matrix, chapeau); break; - case TRANSLATE_ROTATE : - T[0] = -X0; T[1] = -X1; T[2] = -X2; - SetTranslationMatrix(matrix,T); + case TRANSLATE_ROTATE: + T[0] = -X0; + T[1] = -X1; + T[2] = -X2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToSurface(matrix,chapeau); - - Ax[0] = A0; Ax[1] = A1; Ax[2] = A2; - SetRotationMatrix(matrix,Ax,alpha); + ApplyTransformationToSurface(matrix, chapeau); + + Ax[0] = A0; + Ax[1] = A1; + Ax[2] = A2; + SetRotationMatrix(matrix, Ax, alpha); List_Reset(ListOfTransformedPoints); - ApplyTransformationToSurface(matrix,chapeau); - - T[0] = X0; T[1] = X1; T[2] = X2; - SetTranslationMatrix(matrix,T); + ApplyTransformationToSurface(matrix, chapeau); + + T[0] = X0; + T[1] = X1; + T[2] = X2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToSurface(matrix,chapeau); + ApplyTransformationToSurface(matrix, chapeau); - T[0] = T0; T[1] = T1; T[2] = T2; - SetTranslationMatrix(matrix,T); + T[0] = T0; + T[1] = T1; + T[2] = T2; + SetTranslationMatrix(matrix, T); List_Reset(ListOfTransformedPoints); - ApplyTransformationToSurface(matrix,chapeau); + ApplyTransformationToSurface(matrix, chapeau); break; - default : + default: Msg(GERROR, "Unknown extrusion type"); return; } - Tree_Suppress(THEM->Surfaces,&chapeau); + Tree_Suppress(THEM->Surfaces, &chapeau); chapeau->Num = NEWSURFACE(); THEM->MaxSurfaceNum = chapeau->Num; - Tree_Add(THEM->Surfaces,&chapeau); - - if(pv) Tree_Add(THEM->Volumes,&pv); - - if(CTX.geom.auto_coherence) ReplaceAllDuplicates(THEM); + Tree_Add(THEM->Surfaces, &chapeau); + + if(pv) + Tree_Add(THEM->Volumes, &pv); + + if(CTX.geom.auto_coherence) + ReplaceAllDuplicates(THEM); List_Reset(ListOfTransformedPoints); } // Duplicate removal -int compareTwoCurves (const void *a, const void *b){ +int compareTwoCurves(const void *a, const void *b) +{ Curve *c1, *c2; - c1 = *(Curve**)a; - c2 = *(Curve**)b; + c1 = *(Curve **) a; + c2 = *(Curve **) b; int comp; - - if(c1->Typ != c2->Typ)return c1->Typ - c2->Typ; - comp = compareVertex(&c1->beg,&c2->beg); - if(comp)return comp; - comp = compareVertex(&c1->end,&c2->end); - if(comp)return comp; + + if(c1->Typ != c2->Typ) + return c1->Typ - c2->Typ; + comp = compareVertex(&c1->beg, &c2->beg); + if(comp) + return comp; + comp = compareVertex(&c1->end, &c2->end); + if(comp) + return comp; // a finir pour des splines !! return 0; //return c1->Num - c2->Num; } -int compareAbsCurve (const void *a, const void *b){ +int compareAbsCurve(const void *a, const void *b) +{ Curve **q, **w; q = (Curve **) a; @@ -1329,54 +1538,57 @@ int compareAbsCurve (const void *a, const void *b){ return (abs((*q)->Num) - abs((*w)->Num)); } -int compareTwoSurfaces (const void *a, const void *b){ +int compareTwoSurfaces(const void *a, const void *b) +{ Surface *s1, *s2; - s1 = *(Surface**)a; - s2 = *(Surface**)b; - return compare2Lists(s1->Generatrices, - s2->Generatrices, - compareAbsCurve); + s1 = *(Surface **) a; + s2 = *(Surface **) b; + return compare2Lists(s1->Generatrices, s2->Generatrices, compareAbsCurve); } -void MaxNumPoint(void *a, void *b){ - Vertex *v = *(Vertex**)a; - THEM->MaxPointNum = MAX(THEM->MaxPointNum,v->Num); +void MaxNumPoint(void *a, void *b) +{ + Vertex *v = *(Vertex **) a; + THEM->MaxPointNum = MAX(THEM->MaxPointNum, v->Num); } -void MaxNumCurve(void *a, void *b){ - Curve *c = *(Curve**)a; - THEM->MaxLineNum = MAX(THEM->MaxLineNum,c->Num); +void MaxNumCurve(void *a, void *b) +{ + Curve *c = *(Curve **) a; + THEM->MaxLineNum = MAX(THEM->MaxLineNum, c->Num); } -void MaxNumSurface(void *a, void *b){ - Surface *s = *(Surface**)a; - THEM->MaxSurfaceNum = MAX(THEM->MaxSurfaceNum,s->Num); +void MaxNumSurface(void *a, void *b) +{ + Surface *s = *(Surface **) a; + THEM->MaxSurfaceNum = MAX(THEM->MaxSurfaceNum, s->Num); } -void ReplaceDuplicatePoints(Mesh *m){ +void ReplaceDuplicatePoints(Mesh * m) +{ List_T *All; Tree_T *allNonDulpicatedPoints; Vertex *v, **pv, **pv2; Curve *c; Surface *s; - int i,j,start,end; + int i, j, start, end; - List_T *points2delete = List_Create(100,100,sizeof(Vertex*)); + List_T *points2delete = List_Create(100, 100, sizeof(Vertex *)); // Create unique points start = Tree_Nbr(m->Points); All = Tree2List(m->Points); - allNonDulpicatedPoints = Tree_Create(sizeof(Vertex*),comparePosition); - for(i=0;i<List_Nbr(All);i++){ - List_Read(All,i,&v); - if(!Tree_Search(allNonDulpicatedPoints,&v)){ - Tree_Insert(allNonDulpicatedPoints,&v); + allNonDulpicatedPoints = Tree_Create(sizeof(Vertex *), comparePosition); + for(i = 0; i < List_Nbr(All); i++) { + List_Read(All, i, &v); + if(!Tree_Search(allNonDulpicatedPoints, &v)) { + Tree_Insert(allNonDulpicatedPoints, &v); } - else{ - Tree_Suppress(m->Points,&v); - Tree_Suppress(m->Vertices,&v); + else { + Tree_Suppress(m->Points, &v); + Tree_Suppress(m->Vertices, &v); //List_Add(points2delete,&v); } } @@ -1384,35 +1596,35 @@ void ReplaceDuplicatePoints(Mesh *m){ end = Tree_Nbr(m->Points); - if(start == end){ + if(start == end) { Tree_Delete(allNonDulpicatedPoints); List_Delete(points2delete); return; } - Msg(DEBUG, "Removed %d duplicate points", start-end); + Msg(DEBUG, "Removed %d duplicate points", start - end); - if(CTX.geom.old_newreg){ - m->MaxPointNum=0; - Tree_Action(m->Points,MaxNumPoint); - Tree_Action(m->Vertices,MaxNumPoint); + if(CTX.geom.old_newreg) { + m->MaxPointNum = 0; + Tree_Action(m->Points, MaxNumPoint); + Tree_Action(m->Vertices, MaxNumPoint); } // Replace old points in curves All = Tree2List(m->Curves); - for(i=0;i<List_Nbr(All);i++){ - List_Read(All,i,&c); - if(!Tree_Query(allNonDulpicatedPoints,&c->beg)) + for(i = 0; i < List_Nbr(All); i++) { + List_Read(All, i, &c); + if(!Tree_Query(allNonDulpicatedPoints, &c->beg)) Msg(GERROR, "Weird point %d in Coherence", c->beg->Num); - if(!Tree_Query(allNonDulpicatedPoints,&c->end)) + if(!Tree_Query(allNonDulpicatedPoints, &c->end)) Msg(GERROR, "Weird point %d in Coherence", c->end->Num); - for(j=0;j<List_Nbr(c->Control_Points);j++){ - pv = (Vertex**)List_Pointer(c->Control_Points,j); - if(!(pv2 = (Vertex**)Tree_PQuery(allNonDulpicatedPoints, pv))) - Msg(GERROR, "Weird point %d in Coherence", (*pv)->Num); + for(j = 0; j < List_Nbr(c->Control_Points); j++) { + pv = (Vertex **) List_Pointer(c->Control_Points, j); + if(!(pv2 = (Vertex **) Tree_PQuery(allNonDulpicatedPoints, pv))) + Msg(GERROR, "Weird point %d in Coherence", (*pv)->Num); else - List_Write(c->Control_Points,j,pv2); + List_Write(c->Control_Points, j, pv2); } } List_Delete(All); @@ -1420,21 +1632,21 @@ void ReplaceDuplicatePoints(Mesh *m){ // Replace old points in surfaces All = Tree2List(m->Surfaces); - for(i=0;i<List_Nbr(All);i++){ - List_Read(All,i,&s); - for(j=0;j<List_Nbr(s->Control_Points);j++){ - pv = (Vertex**)List_Pointer(s->Control_Points,j); - if(!(pv2 = (Vertex**)Tree_PQuery(allNonDulpicatedPoints,pv))) - Msg(GERROR, "Weird point %d in Coherence", (*pv)->Num); + for(i = 0; i < List_Nbr(All); i++) { + List_Read(All, i, &s); + for(j = 0; j < List_Nbr(s->Control_Points); j++) { + pv = (Vertex **) List_Pointer(s->Control_Points, j); + if(!(pv2 = (Vertex **) Tree_PQuery(allNonDulpicatedPoints, pv))) + Msg(GERROR, "Weird point %d in Coherence", (*pv)->Num); else - List_Write(s->Control_Points,j,pv2); + List_Write(s->Control_Points, j, pv2); } } List_Delete(All); - for(int k = 0; k < List_Nbr(points2delete);k++){ - List_Read(points2delete,i,&v); - Free_Vertex(&v,0); + for(int k = 0; k < List_Nbr(points2delete); k++) { + List_Read(points2delete, i, &v); + Free_Vertex(&v, 0); } Tree_Delete(allNonDulpicatedPoints); @@ -1442,39 +1654,40 @@ void ReplaceDuplicatePoints(Mesh *m){ } -void ReplaceDuplicateCurves(Mesh *m){ +void ReplaceDuplicateCurves(Mesh * m) +{ List_T *All; Tree_T *allNonDulpicatedCurves; - Curve *c,*c2,**pc,**pc2; + Curve *c, *c2, **pc, **pc2; Surface *s; - int i,j,start,end; + int i, j, start, end; // Create unique curves start = Tree_Nbr(m->Curves); All = Tree2List(m->Curves); - allNonDulpicatedCurves = Tree_Create(sizeof(Curve*),compareTwoCurves); - for(i=0;i<List_Nbr(All);i++){ - List_Read(All,i,&c); - if(c->Num > 0){ - if(!Tree_Search(allNonDulpicatedCurves,&c)){ - Tree_Insert(allNonDulpicatedCurves,&c); - if(!(c2 = FindCurve(-c->Num,m))){ + allNonDulpicatedCurves = Tree_Create(sizeof(Curve *), compareTwoCurves); + for(i = 0; i < List_Nbr(All); i++) { + List_Read(All, i, &c); + if(c->Num > 0) { + if(!Tree_Search(allNonDulpicatedCurves, &c)) { + Tree_Insert(allNonDulpicatedCurves, &c); + if(!(c2 = FindCurve(-c->Num, m))) { Msg(GERROR, "Unknown Curve %d", -c->Num); - List_Delete(All); - return; - } - Tree_Insert(allNonDulpicatedCurves,&c2); + List_Delete(All); + return; + } + Tree_Insert(allNonDulpicatedCurves, &c2); } - else{ - Tree_Suppress(m->Curves,&c); - if(!(c2 = FindCurve(-c->Num,m))){ + else { + Tree_Suppress(m->Curves, &c); + if(!(c2 = FindCurve(-c->Num, m))) { Msg(GERROR, "Unknown Curve %d", -c->Num); - List_Delete(All); - return; - } - Tree_Suppress(m->Curves,&c2); + List_Delete(All); + return; + } + Tree_Suppress(m->Curves, &c2); } } } @@ -1482,60 +1695,61 @@ void ReplaceDuplicateCurves(Mesh *m){ end = Tree_Nbr(m->Curves); - if(start == end){ + if(start == end) { Tree_Delete(allNonDulpicatedCurves); return; - } + } - Msg(DEBUG, "Removed %d duplicate curves", start-end); + Msg(DEBUG, "Removed %d duplicate curves", start - end); - if(CTX.geom.old_newreg){ - m->MaxLineNum=0; - Tree_Action(m->Curves,MaxNumCurve); + if(CTX.geom.old_newreg) { + m->MaxLineNum = 0; + Tree_Action(m->Curves, MaxNumCurve); } // Replace old curves in surfaces All = Tree2List(m->Surfaces); - for(i=0;i<List_Nbr(All);i++){ - List_Read(All,i,&s); - for(j=0;j<List_Nbr(s->Generatrices);j++){ - pc = (Curve**)List_Pointer(s->Generatrices,j); - if(!(pc2 = (Curve**)Tree_PQuery(allNonDulpicatedCurves,pc))) - Msg(GERROR, "Weird curve %d in Coherence", (*pc)->Num); - else{ - List_Write(s->Generatrices,j,pc2); - // Arghhh. Revoir compareTwoCurves ! - End_Curve(*pc2); + for(i = 0; i < List_Nbr(All); i++) { + List_Read(All, i, &s); + for(j = 0; j < List_Nbr(s->Generatrices); j++) { + pc = (Curve **) List_Pointer(s->Generatrices, j); + if(!(pc2 = (Curve **) Tree_PQuery(allNonDulpicatedCurves, pc))) + Msg(GERROR, "Weird curve %d in Coherence", (*pc)->Num); + else { + List_Write(s->Generatrices, j, pc2); + // Arghhh. Revoir compareTwoCurves ! + End_Curve(*pc2); } } } List_Delete(All); - + Tree_Delete(allNonDulpicatedCurves); } -void ReplaceDuplicateSurfaces(Mesh *m){ +void ReplaceDuplicateSurfaces(Mesh * m) +{ List_T *All; Tree_T *allNonDulpicatedSurfaces; Surface *s, **ps, **ps2; Volume *vol; - int i,j,start,end; + int i, j, start, end; // Create unique surfaces start = Tree_Nbr(m->Surfaces); All = Tree2List(m->Surfaces); - allNonDulpicatedSurfaces = Tree_Create(sizeof(Curve*),compareTwoSurfaces); - for(i=0;i<List_Nbr(All);i++){ - List_Read(All,i,&s); - if(s->Num > 0){ - if(!Tree_Search(allNonDulpicatedSurfaces,&s)){ - Tree_Insert(allNonDulpicatedSurfaces,&s); + allNonDulpicatedSurfaces = Tree_Create(sizeof(Curve *), compareTwoSurfaces); + for(i = 0; i < List_Nbr(All); i++) { + List_Read(All, i, &s); + if(s->Num > 0) { + if(!Tree_Search(allNonDulpicatedSurfaces, &s)) { + Tree_Insert(allNonDulpicatedSurfaces, &s); } - else{ - Tree_Suppress(m->Surfaces,&s); + else { + Tree_Suppress(m->Surfaces, &s); } } } @@ -1543,29 +1757,29 @@ void ReplaceDuplicateSurfaces(Mesh *m){ end = Tree_Nbr(m->Surfaces); - if(start == end){ + if(start == end) { Tree_Delete(allNonDulpicatedSurfaces); return; } - Msg(DEBUG, "Removed %d duplicate surfaces", start-end); + Msg(DEBUG, "Removed %d duplicate surfaces", start - end); - if(CTX.geom.old_newreg){ - m->MaxSurfaceNum=0; - Tree_Action(m->Surfaces,MaxNumSurface); + if(CTX.geom.old_newreg) { + m->MaxSurfaceNum = 0; + Tree_Action(m->Surfaces, MaxNumSurface); } // Replace old surfaces in volumes All = Tree2List(m->Volumes); - for(i=0;i<List_Nbr(All);i++){ - List_Read(All,i,&vol); - for(j=0;j<List_Nbr(vol->Surfaces);j++){ - ps = (Surface**)List_Pointer(vol->Surfaces,j); - if(!(ps2 = (Surface**)Tree_PQuery(allNonDulpicatedSurfaces,ps))) - Msg(GERROR, "Weird surface %d in Coherence", (*ps)->Num); + for(i = 0; i < List_Nbr(All); i++) { + List_Read(All, i, &vol); + for(j = 0; j < List_Nbr(vol->Surfaces); j++) { + ps = (Surface **) List_Pointer(vol->Surfaces, j); + if(!(ps2 = (Surface **) Tree_PQuery(allNonDulpicatedSurfaces, ps))) + Msg(GERROR, "Weird surface %d in Coherence", (*ps)->Num); else - List_Write(vol->Surfaces,j,ps2); + List_Write(vol->Surfaces, j, ps2); } } List_Delete(All); @@ -1573,7 +1787,8 @@ void ReplaceDuplicateSurfaces(Mesh *m){ Tree_Delete(allNonDulpicatedSurfaces); } -void ReplaceAllDuplicates(Mesh *m){ +void ReplaceAllDuplicates(Mesh * m) +{ ReplaceDuplicatePoints(m); ReplaceDuplicateCurves(m); ReplaceDuplicateSurfaces(m); @@ -1598,134 +1813,143 @@ static Curve *CURVE, *CURVE_2; static Surface *SURFACE; static Vertex *VERTEX; -double min1d (double (*funct)(double), double *xmin){ - double ax=1.e-15, bx=1.e-12, cx= 1.E-11, fa, fb, fx, tol = 1.e-3; - mnbrak(&ax,&bx,&cx,&fa,&fx,&fb,funct); - // Msg(INFO, "--MIN1D : ax %12.5E bx %12.5E cx %12.5E \n",ax,bx,cx); - return(brent(ax,bx,cx,funct,tol,xmin)); +double min1d(double (*funct) (double), double *xmin) +{ + double ax = 1.e-15, bx = 1.e-12, cx = 1.e-11, fa, fb, fx, tol = 1.e-3; + mnbrak(&ax, &bx, &cx, &fa, &fx, &fb, funct); + //Msg(INFO, "--MIN1D : ax %12.5E bx %12.5E cx %12.5E",ax,bx,cx); + return (brent(ax, bx, cx, funct, tol, xmin)); } -static void intersectCS (int N, double x[], double res[]){ +static void intersectCS(int N, double x[], double res[]) +{ //x[1] = u x[2] = v x[3] = w - Vertex s,c; - s = InterpolateSurface(SURFACE,x[1],x[2],0,0); - c = InterpolateCurve (CURVE,x[3],0); + Vertex s, c; + s = InterpolateSurface(SURFACE, x[1], x[2], 0, 0); + c = InterpolateCurve(CURVE, x[3], 0); res[1] = s.Pos.X - c.Pos.X; res[2] = s.Pos.Y - c.Pos.Y; res[3] = s.Pos.Z - c.Pos.Z; } -static void intersectCC (int N, double x[], double res[]){ +static void intersectCC(int N, double x[], double res[]) +{ //x[1] = u x[2] = v - Vertex c2,c; - c2 = InterpolateCurve(CURVE_2,x[2],0); - c = InterpolateCurve (CURVE,x[1],0); + Vertex c2, c; + c2 = InterpolateCurve(CURVE_2, x[2], 0); + c = InterpolateCurve(CURVE, x[1], 0); res[1] = c2.Pos.X - c.Pos.X; res[2] = c2.Pos.Y - c.Pos.Y; } -static void projectPS (int N, double x[], double res[]){ +static void projectPS(int N, double x[], double res[]) +{ //x[1] = u x[2] = v - Vertex du,dv,c; - c = InterpolateSurface(SURFACE,x[1],x[2],0,0); - du = InterpolateSurface(SURFACE,x[1],x[2],1,1); - dv = InterpolateSurface(SURFACE,x[1],x[2],1,2); + Vertex du, dv, c; + c = InterpolateSurface(SURFACE, x[1], x[2], 0, 0); + du = InterpolateSurface(SURFACE, x[1], x[2], 1, 1); + dv = InterpolateSurface(SURFACE, x[1], x[2], 1, 2); res[1] = - (c.Pos.X - VERTEX->Pos.X)*du.Pos.X + - (c.Pos.Y - VERTEX->Pos.Y)*du.Pos.Y + - (c.Pos.Z - VERTEX->Pos.Z)*du.Pos.Z; - res[2] = - (c.Pos.X - VERTEX->Pos.X)*dv.Pos.X + - (c.Pos.Y - VERTEX->Pos.Y)*dv.Pos.Y + - (c.Pos.Z - VERTEX->Pos.Z)*dv.Pos.Z; + (c.Pos.X - VERTEX->Pos.X) * du.Pos.X + + (c.Pos.Y - VERTEX->Pos.Y) * du.Pos.Y + + (c.Pos.Z - VERTEX->Pos.Z) * du.Pos.Z; + res[2] = + (c.Pos.X - VERTEX->Pos.X) * dv.Pos.X + + (c.Pos.Y - VERTEX->Pos.Y) * dv.Pos.Y + + (c.Pos.Z - VERTEX->Pos.Z) * dv.Pos.Z; } -static double projectPC (double u){ +static double projectPC(double u) +{ //x[1] = u x[2] = v - if(u<CURVE->ubeg)u = CURVE->ubeg; - if(u<CURVE->ubeg)u = CURVE->ubeg; + if(u < CURVE->ubeg) + u = CURVE->ubeg; + if(u < CURVE->ubeg) + u = CURVE->ubeg; Vertex c; - c = InterpolateCurve(CURVE,u,0); - return sqrt(DSQR(c.Pos.X -VERTEX->Pos.X)+ - DSQR(c.Pos.Y -VERTEX->Pos.Y)+ - DSQR(c.Pos.Z -VERTEX->Pos.Z)); + c = InterpolateCurve(CURVE, u, 0); + return sqrt(DSQR(c.Pos.X - VERTEX->Pos.X) + + DSQR(c.Pos.Y - VERTEX->Pos.Y) + DSQR(c.Pos.Z - VERTEX->Pos.Z)); } -static int UFIXED=0; +static int UFIXED = 0; static double FIX; -static double projectPCS (double u){ +static double projectPCS(double u) +{ //x[1] = u x[2] = v - double tmin,tmax; - if(UFIXED){ + double tmin, tmax; + if(UFIXED) { tmin = SURFACE->kv[0]; - tmax = SURFACE->kv[SURFACE->Nv+SURFACE->OrderV]; + tmax = SURFACE->kv[SURFACE->Nv + SURFACE->OrderV]; } - else{ + else { tmin = SURFACE->ku[0]; - tmax = SURFACE->ku[SURFACE->Nu+SURFACE->OrderU]; + tmax = SURFACE->ku[SURFACE->Nu + SURFACE->OrderU]; } - - if(u<tmin)u = tmin; - if(u>tmax)u = tmax; + + if(u < tmin) + u = tmin; + if(u > tmax) + u = tmax; Vertex c; if(UFIXED) - c = InterpolateSurface(SURFACE,FIX,u,0,0); + c = InterpolateSurface(SURFACE, FIX, u, 0, 0); else - c = InterpolateSurface(SURFACE,u,FIX,0,0); - return sqrt(DSQR(c.Pos.X -VERTEX->Pos.X)+ - DSQR(c.Pos.Y -VERTEX->Pos.Y)+ - DSQR(c.Pos.Z -VERTEX->Pos.Z)); + c = InterpolateSurface(SURFACE, u, FIX, 0, 0); + return sqrt(DSQR(c.Pos.X - VERTEX->Pos.X) + + DSQR(c.Pos.Y - VERTEX->Pos.Y) + DSQR(c.Pos.Z - VERTEX->Pos.Z)); } -bool ProjectPointOnCurve (Curve *c, Vertex *v, Vertex *RES, Vertex *DER){ +bool ProjectPointOnCurve(Curve * c, Vertex * v, Vertex * RES, Vertex * DER) +{ double xmin; CURVE = c; VERTEX = v; - min1d (projectPC, &xmin); - *RES = InterpolateCurve(CURVE,xmin,0); - *DER = InterpolateCurve(CURVE,xmin,1); - if(xmin > c->uend){ - *RES = InterpolateCurve(CURVE,c->uend,0); - *DER = InterpolateCurve(CURVE,c->uend,1); + min1d(projectPC, &xmin); + *RES = InterpolateCurve(CURVE, xmin, 0); + *DER = InterpolateCurve(CURVE, xmin, 1); + if(xmin > c->uend) { + *RES = InterpolateCurve(CURVE, c->uend, 0); + *DER = InterpolateCurve(CURVE, c->uend, 1); } - else if(xmin < c->ubeg){ - *RES = InterpolateCurve(CURVE,c->ubeg,0); - *DER = InterpolateCurve(CURVE,c->ubeg,1); + else if(xmin < c->ubeg) { + *RES = InterpolateCurve(CURVE, c->ubeg, 0); + *DER = InterpolateCurve(CURVE, c->ubeg, 1); } return true; } -bool search_in_boundary (Surface *s, Vertex *p, double t, int Fixu, - double *uu, double *vv){ +bool search_in_boundary(Surface * s, Vertex * p, double t, int Fixu, + double *uu, double *vv) +{ double l, umin = 0., vmin = 0., lmin = 1.e200; int i, N; Vertex vr; double tmin, tmax, u, v; - - if(Fixu){ + + if(Fixu) { tmin = s->kv[0]; - tmax = s->kv[s->Nv+s->OrderV]; - N = 3*s->Nu; + tmax = s->kv[s->Nv + s->OrderV]; + N = 3 * s->Nu; } - else{ + else { tmin = s->ku[0]; - tmax = s->ku[s->Nu+s->OrderU]; - N = 3*s->Nv; + tmax = s->ku[s->Nu + s->OrderU]; + N = 3 * s->Nv; } - for(i=0;i<N;i++){ - if(Fixu){ + for(i = 0; i < N; i++) { + if(Fixu) { u = t; - v = tmin + (tmax-tmin)*(double)(i)/(double)(N-1); + v = tmin + (tmax - tmin) * (double)(i) / (double)(N - 1); } else { v = t; - u = tmin + (tmax-tmin)*(double)(i)/(double)(N-1); + u = tmin + (tmax - tmin) * (double)(i) / (double)(N - 1); } - vr = InterpolateSurface(SURFACE,u,v,0,0); - l = sqrt(DSQR(vr.Pos.X - p->Pos.X) + - DSQR(vr.Pos.Y - p->Pos.Y) + - DSQR(vr.Pos.Z - p->Pos.Z)); - if(l<lmin){ + vr = InterpolateSurface(SURFACE, u, v, 0, 0); + l = sqrt(DSQR(vr.Pos.X - p->Pos.X) + + DSQR(vr.Pos.Y - p->Pos.Y) + DSQR(vr.Pos.Z - p->Pos.Z)); + if(l < lmin) { lmin = l; umin = u; vmin = v; @@ -1735,37 +1959,44 @@ bool search_in_boundary (Surface *s, Vertex *p, double t, int Fixu, FIX = t; UFIXED = Fixu; double xm; - if(Fixu)xm = vmin; - else xm = umin; - if(lmin > 1.e-3) min1d (projectPCS, &xm); - if(Fixu){ + if(Fixu) + xm = vmin; + else + xm = umin; + if(lmin > 1.e-3) + min1d(projectPCS, &xm); + if(Fixu) { *uu = t; *vv = xm; } - else{ + else { *vv = t; *uu = xm; } - vr = InterpolateSurface(SURFACE,*uu,*vv,0,0); - l = sqrt(DSQR(vr.Pos.X - p->Pos.X) + - DSQR(vr.Pos.Y - p->Pos.Y) + - DSQR(vr.Pos.Z - p->Pos.Z)); - if(l<1.e-3)return true; + vr = InterpolateSurface(SURFACE, *uu, *vv, 0, 0); + l = sqrt(DSQR(vr.Pos.X - p->Pos.X) + + DSQR(vr.Pos.Y - p->Pos.Y) + DSQR(vr.Pos.Z - p->Pos.Z)); + if(l < 1.e-3) + return true; return false; } -bool try_a_value(Surface *s, Vertex *p, double u, double v,double *uu, double *vv){ - Vertex vr = InterpolateSurface(s,u,v,0,0); - double l = sqrt(DSQR(vr.Pos.X - p->Pos.X) + - DSQR(vr.Pos.Y - p->Pos.Y) + - DSQR(vr.Pos.Z - p->Pos.Z)); - *uu = u;*vv=v; - if(l<1.e-3)return true; +bool try_a_value(Surface * s, Vertex * p, double u, double v, double *uu, + double *vv) +{ + Vertex vr = InterpolateSurface(s, u, v, 0, 0); + double l = sqrt(DSQR(vr.Pos.X - p->Pos.X) + + DSQR(vr.Pos.Y - p->Pos.Y) + DSQR(vr.Pos.Z - p->Pos.Z)); + *uu = u; + *vv = v; + if(l < 1.e-3) + return true; return false; } -bool ProjectPointOnSurface (Surface *s, Vertex &p){ - double x[3] = {0.5,0.5,0.5}; +bool ProjectPointOnSurface(Surface * s, Vertex & p) +{ + double x[3] = { 0.5, 0.5, 0.5 }; Vertex vv; int check; SURFACE = s; @@ -1774,27 +2005,29 @@ bool ProjectPointOnSurface (Surface *s, Vertex &p){ double UMAX = 1.; double VMIN = 0.; double VMAX = 1.; - while(1){ - newt(x,2,&check,projectPS); - vv = InterpolateSurface(s,x[1],x[2],0,0); - if(x[1] >= UMIN && x[1] <= UMAX && x[2] >=VMIN && x[2] <= VMAX) break; - x[1] = UMIN + (UMAX-UMIN)*((rand() % 10000)/10000.); - x[2] = VMIN + (VMAX-VMIN)*((rand() % 10000)/10000.); + while(1) { + newt(x, 2, &check, projectPS); + vv = InterpolateSurface(s, x[1], x[2], 0, 0); + if(x[1] >= UMIN && x[1] <= UMAX && x[2] >= VMIN && x[2] <= VMAX) + break; + x[1] = UMIN + (UMAX - UMIN) * ((rand() % 10000) / 10000.); + x[2] = VMIN + (VMAX - VMIN) * ((rand() % 10000) / 10000.); } p.Pos.X = vv.Pos.X; p.Pos.Y = vv.Pos.Y; p.Pos.Z = vv.Pos.Z; - if(!check){ + if(!check) { return false; } return true; } -bool ProjectPointOnSurface (Surface *s, Vertex *p,double *u, double *v){ +bool ProjectPointOnSurface(Surface * s, Vertex * p, double *u, double *v) +{ static double x[3]; int check; static int deb = 1; - double VMIN,VMAX,UMIN,UMAX,l, lmin; + double VMIN, VMAX, UMIN, UMAX, l, lmin; Vertex vv; SURFACE = s; @@ -1804,161 +2037,186 @@ bool ProjectPointOnSurface (Surface *s, Vertex *p,double *u, double *v){ UMIN = s->ku[0]; VMAX = s->kv[s->Nv + s->OrderV]; VMIN = s->kv[0]; - if(deb){ - x[1] = UMIN + (UMAX-UMIN)*((rand() % 10000)/10000.); - x[2] = VMIN + (VMAX-VMIN)*((rand() % 10000)/10000.); + if(deb) { + x[1] = UMIN + (UMAX - UMIN) * ((rand() % 10000) / 10000.); + x[2] = VMIN + (VMAX - VMIN) * ((rand() % 10000) / 10000.); deb = 0; } - if(p->Num == 160){ + if(p->Num == 160) { lmin += 1.e90; - if(p->Num == 133)UMAX = s->ku[s->Nu + s->OrderU]; + if(p->Num == 133) + UMAX = s->ku[s->Nu + s->OrderU]; } - - if(try_a_value(SURFACE,VERTEX,SURFACE->ku[0]+VERTEX->u, - SURFACE->kv[0],u,v)) + + if(try_a_value(SURFACE, VERTEX, SURFACE->ku[0] + VERTEX->u, + SURFACE->kv[0], u, v)) return true; - if(try_a_value(SURFACE,VERTEX,SURFACE->ku[0]+VERTEX->u, - SURFACE->kv[SURFACE->Nv+SURFACE->OrderV],u,v)) + if(try_a_value(SURFACE, VERTEX, SURFACE->ku[0] + VERTEX->u, + SURFACE->kv[SURFACE->Nv + SURFACE->OrderV], u, v)) return true; - if(try_a_value(SURFACE,VERTEX,SURFACE->ku[SURFACE->Nu+SURFACE->OrderU]-VERTEX->u, - SURFACE->kv[0],u,v)) + if(try_a_value + (SURFACE, VERTEX, SURFACE->ku[SURFACE->Nu + SURFACE->OrderU] - VERTEX->u, + SURFACE->kv[0], u, v)) return true; - if(try_a_value(SURFACE,VERTEX,SURFACE->ku[SURFACE->Nu+SURFACE->OrderU]-VERTEX->u, - SURFACE->kv[SURFACE->Nv+SURFACE->OrderV],u,v)) + if(try_a_value + (SURFACE, VERTEX, SURFACE->ku[SURFACE->Nu + SURFACE->OrderU] - VERTEX->u, + SURFACE->kv[SURFACE->Nv + SURFACE->OrderV], u, v)) return true; - if(try_a_value(SURFACE,VERTEX,SURFACE->ku[0],SURFACE->kv[0]+VERTEX->u,u,v)) + if(try_a_value + (SURFACE, VERTEX, SURFACE->ku[0], SURFACE->kv[0] + VERTEX->u, u, v)) return true; - if(try_a_value(SURFACE,VERTEX,SURFACE->ku[0], - SURFACE->kv[SURFACE->Nv+SURFACE->OrderV]-VERTEX->u,u,v)) + if(try_a_value(SURFACE, VERTEX, SURFACE->ku[0], + SURFACE->kv[SURFACE->Nv + SURFACE->OrderV] - VERTEX->u, u, + v)) return true; - if(try_a_value(SURFACE,VERTEX,SURFACE->ku[SURFACE->Nu+SURFACE->OrderU], - SURFACE->kv[0]+VERTEX->u,u,v)) + if(try_a_value(SURFACE, VERTEX, SURFACE->ku[SURFACE->Nu + SURFACE->OrderU], + SURFACE->kv[0] + VERTEX->u, u, v)) return true; - if(try_a_value(SURFACE,VERTEX,SURFACE->ku[SURFACE->Nu+SURFACE->OrderU], - SURFACE->kv[SURFACE->Nv+SURFACE->OrderV]-VERTEX->u,u,v)) + if(try_a_value(SURFACE, VERTEX, SURFACE->ku[SURFACE->Nu + SURFACE->OrderU], + SURFACE->kv[SURFACE->Nv + SURFACE->OrderV] - VERTEX->u, u, + v)) return true; - - - if(search_in_boundary(SURFACE,VERTEX,SURFACE->kv[0],0,u,v)) + + + if(search_in_boundary(SURFACE, VERTEX, SURFACE->kv[0], 0, u, v)) return true; - if(search_in_boundary(SURFACE,VERTEX,SURFACE->kv[SURFACE->Nv+SURFACE->OrderV],0,u,v)) + if(search_in_boundary + (SURFACE, VERTEX, SURFACE->kv[SURFACE->Nv + SURFACE->OrderV], 0, u, v)) return true; - if(search_in_boundary(SURFACE,VERTEX,SURFACE->ku[0],1,u,v)) + if(search_in_boundary(SURFACE, VERTEX, SURFACE->ku[0], 1, u, v)) return true; - if(search_in_boundary(SURFACE,VERTEX,SURFACE->ku[SURFACE->Nu+SURFACE->OrderU],1,u,v)) + if(search_in_boundary + (SURFACE, VERTEX, SURFACE->ku[SURFACE->Nu + SURFACE->OrderU], 1, u, v)) return true; - - while(1){ - newt(x,2,&check,projectPS); - vv = InterpolateSurface(s,x[1],x[2],0,0); - l = sqrt(DSQR(vv.Pos.X - p->Pos.X) + - DSQR(vv.Pos.Y - p->Pos.Y) + - DSQR(vv.Pos.Z - p->Pos.Z)); - if(l < 1.e-1) break; + + while(1) { + newt(x, 2, &check, projectPS); + vv = InterpolateSurface(s, x[1], x[2], 0, 0); + l = sqrt(DSQR(vv.Pos.X - p->Pos.X) + + DSQR(vv.Pos.Y - p->Pos.Y) + DSQR(vv.Pos.Z - p->Pos.Z)); + if(l < 1.e-1) + break; else { - x[1] = UMIN + (UMAX-UMIN)*((rand() % 10000)/10000.); - x[2] = VMIN + (VMAX-VMIN)*((rand() % 10000)/10000.); + x[1] = UMIN + (UMAX - UMIN) * ((rand() % 10000) / 10000.); + x[2] = VMIN + (VMAX - VMIN) * ((rand() % 10000) / 10000.); } } *u = x[1]; *v = x[2]; - - if(!check){ + + if(!check) { return false; } return true; } -bool IntersectCurveSurface (Curve *c, Surface *s){ +bool IntersectCurveSurface(Curve * c, Surface * s) +{ double x[4]; int check; SURFACE = s; CURVE = c; - newt(x,3,&check,intersectCS); - if(!check)return false; + newt(x, 3, &check, intersectCS); + if(!check) + return false; return true; } -void DivideCurve (Curve *c , double u, Vertex *v, Curve **c1, Curve **c2){ - (*c1) = Create_Curve(NEWLINE(),c->Typ,1,NULL,NULL,-1,-1,0.,1.); - (*c2) = Create_Curve(NEWLINE(),c->Typ,1,NULL,NULL,-1,-1,0.,1.); - CopyCurve(c,*c1); - CopyCurve(c,*c2); +void DivideCurve(Curve * c, double u, Vertex * v, Curve ** c1, Curve ** c2) +{ + (*c1) = Create_Curve(NEWLINE(), c->Typ, 1, NULL, NULL, -1, -1, 0., 1.); + (*c2) = Create_Curve(NEWLINE(), c->Typ, 1, NULL, NULL, -1, -1, 0., 1.); + CopyCurve(c, *c1); + CopyCurve(c, *c2); (*c1)->uend = u; (*c2)->ubeg = u; (*c1)->end = v; (*c2)->beg = v; } -bool IntersectCurves (Curve *c1, Curve *c2, - Curve **c11, Curve **c12, - Curve **c21, Curve **c22, Vertex **v){ +bool IntersectCurves(Curve * c1, Curve * c2, + Curve ** c11, Curve ** c12, + Curve ** c21, Curve ** c22, Vertex ** v) +{ double x[3]; - Vertex v1,v2; + Vertex v1, v2; int check; - - if(!compareVertex(&c1->beg,&c2->beg))return false; - if(!compareVertex(&c1->end,&c2->end))return false; - if(!compareVertex(&c1->beg,&c2->end))return false; - if(!compareVertex(&c2->beg,&c1->end))return false; + + if(!compareVertex(&c1->beg, &c2->beg)) + return false; + if(!compareVertex(&c1->end, &c2->end)) + return false; + if(!compareVertex(&c1->beg, &c2->end)) + return false; + if(!compareVertex(&c2->beg, &c1->end)) + return false; CURVE_2 = c2; CURVE = c1; - x[1] = x[2] = 0.0; - newt(x,2,&check,intersectCC); - if(check) return false; - v1 = InterpolateCurve(c1,x[1],0); - v2 = InterpolateCurve(c2,x[2],0); + x[1] = x[2] = 0.0; + newt(x, 2, &check, intersectCC); + if(check) + return false; + v1 = InterpolateCurve(c1, x[1], 0); + v2 = InterpolateCurve(c2, x[2], 0); // Msg(INFO, "success : %lf %lf,%lf,%lf\n",v1.Pos.X,v1.Pos.Y,x[1],x[2]); - if(x[1] <= c1->ubeg) return false; - if(x[1] >= c1->uend) return false; - if(x[2] <= c2->ubeg) return false; - if(x[2] >= c2->uend) return false; - if(fabs(v1.Pos.Z - v2.Pos.Z) > 1.e-08 * CTX.lc) return false; - *v = Create_Vertex(NEWPOINT(), v1.Pos.X,v1.Pos.Y,v1.Pos.Z,v1.lc,x[1]); - Tree_Insert(THEM->Points,v); - DivideCurve(c1,x[1],*v,c11,c12); - DivideCurve(c2,x[2],*v,c21,c22); + if(x[1] <= c1->ubeg) + return false; + if(x[1] >= c1->uend) + return false; + if(x[2] <= c2->ubeg) + return false; + if(x[2] >= c2->uend) + return false; + if(fabs(v1.Pos.Z - v2.Pos.Z) > 1.e-08 * CTX.lc) + return false; + *v = Create_Vertex(NEWPOINT(), v1.Pos.X, v1.Pos.Y, v1.Pos.Z, v1.lc, x[1]); + Tree_Insert(THEM->Points, v); + DivideCurve(c1, x[1], *v, c11, c12); + DivideCurve(c2, x[2], *v, c21, c22); return true; } -bool IntersectAllSegmentsTogether (void) { +bool IntersectAllSegmentsTogether(void) +{ bool intersectionfound = true; List_T *TempList; - Curve *c1,*c2,*c11,*c12,*c21,*c22; + Curve *c1, *c2, *c11, *c12, *c21, *c22; Vertex *v; - int i,j; + int i, j; - while(intersectionfound){ + while(intersectionfound) { TempList = Tree2List(THEM->Curves); - if(!List_Nbr(TempList))return true; - for(i=0;i<List_Nbr(TempList);i++){ - List_Read(TempList,i,&c1); + if(!List_Nbr(TempList)) + return true; + for(i = 0; i < List_Nbr(TempList); i++) { + List_Read(TempList, i, &c1); intersectionfound = false; - for(j=0;j<List_Nbr(TempList);j++){ - List_Read(TempList,j,&c2); - if(c1->Num > 0 && c2->Num >0 && i!=j && intersectionfound == false){ - if(IntersectCurves(c1,c2,&c11,&c12,&c21,&c22,&v)){ - Msg(INFO, "Intersection Curve %d->%d",c1->Num,c2->Num); + for(j = 0; j < List_Nbr(TempList); j++) { + List_Read(TempList, j, &c2); + if(c1->Num > 0 && c2->Num > 0 && i != j && intersectionfound == false) { + if(IntersectCurves(c1, c2, &c11, &c12, &c21, &c22, &v)) { + Msg(INFO, "Intersection Curve %d->%d", c1->Num, c2->Num); intersectionfound = true; DeleteCurve(c1->Num); DeleteCurve(c2->Num); - Tree_Add(THEM->Curves,&c11); - Tree_Add(THEM->Curves,&c12); - Tree_Add(THEM->Curves,&c21); - Tree_Add(THEM->Curves,&c22); - - CreateReversedCurve(THEM,c11); - CreateReversedCurve(THEM,c12); - CreateReversedCurve(THEM,c21); - CreateReversedCurve(THEM,c22); + Tree_Add(THEM->Curves, &c11); + Tree_Add(THEM->Curves, &c12); + Tree_Add(THEM->Curves, &c21); + Tree_Add(THEM->Curves, &c22); + + CreateReversedCurve(THEM, c11); + CreateReversedCurve(THEM, c12); + CreateReversedCurve(THEM, c21); + CreateReversedCurve(THEM, c22); return true; } } } - if(intersectionfound) break; + if(intersectionfound) + break; } List_Delete(TempList); } @@ -1966,6 +2224,7 @@ bool IntersectAllSegmentsTogether (void) { } -void IntersectSurfaces (Surface *s1, Surface *s2){ - +void IntersectSurfaces(Surface * s1, Surface * s2) +{ + ; } diff --git a/Geo/DataBase.cpp b/Geo/DataBase.cpp index dd3a8ba2fd371fdd9b78ea9b81d1309c8bffffa2..3dfd9278451635189ba139ddf6f1400853dbe6bc 100644 --- a/Geo/DataBase.cpp +++ b/Geo/DataBase.cpp @@ -1,4 +1,4 @@ -// $Id: DataBase.cpp,v 1.23 2003-02-25 04:02:50 geuzaine Exp $ +// $Id: DataBase.cpp,v 1.24 2003-03-01 22:36:38 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -28,384 +28,401 @@ #include "Verif.h" #include "Context.h" -extern Context_T CTX ; -extern Mesh *THEM; +extern Context_T CTX; +extern Mesh *THEM; // Points -void Cdbpts101(int ip, double x, double y, double z, double l, double w){ +void Cdbpts101(int ip, double x, double y, double z, double l, double w) +{ Vertex *v; v = Create_Vertex(ip, - CTX.geom.scaling_factor*x, - CTX.geom.scaling_factor*y, - CTX.geom.scaling_factor*z, - CTX.geom.scaling_factor*l, - 0.0); + CTX.geom.scaling_factor * x, + CTX.geom.scaling_factor * y, + CTX.geom.scaling_factor * z, + CTX.geom.scaling_factor * l, 0.0); v->w = w; - Tree_Insert(THEM->Points,&v); + Tree_Insert(THEM->Points, &v); } // Curves -void AddCurveInDataBase (int NumCurve, int TypCurve, int Order, - List_T *ControlPoints, List_T *Knots, - int VertexBeg, int VertexEnd, - double uBeg, double uEnd){ +void AddCurveInDataBase(int NumCurve, int TypCurve, int Order, + List_T * ControlPoints, List_T * Knots, + int VertexBeg, int VertexEnd, + double uBeg, double uEnd) +{ Curve *c; - if(NumCurve<0) return; /* Negative Curves are reversed from positive ones*/ + if(NumCurve < 0) + return; /* Negative Curves are reversed from positive ones */ - c = Create_Curve(NumCurve,TypCurve,Order,ControlPoints,Knots, - VertexBeg,VertexEnd,uBeg,uEnd); + c = Create_Curve(NumCurve, TypCurve, Order, ControlPoints, Knots, + VertexBeg, VertexEnd, uBeg, uEnd); // curve in reverse direction - - Curve *rc = CreateReversedCurve(THEM,c); - Tree_Insert(THEM->Curves,&c); - Tree_Insert(THEM->Curves,&rc); + + Curve *rc = CreateReversedCurve(THEM, c); + Tree_Insert(THEM->Curves, &c); + Tree_Insert(THEM->Curves, &rc); } -void AddCircleInDataBase (int NumCurve, int TypCurve, List_T *ControlPoints, - double n[3]){ +void AddCircleInDataBase(int NumCurve, int TypCurve, List_T * ControlPoints, + double n[3]) +{ Curve *c; - - if(NumCurve<0) return; /* Negative Curves are reversed from positive ones*/ - c = Create_Curve(NumCurve,TypCurve,2,ControlPoints,NULL,-1,-1,0.,1.); + if(NumCurve < 0) + return; /* Negative Curves are reversed from positive ones */ + + c = + Create_Curve(NumCurve, TypCurve, 2, ControlPoints, NULL, -1, -1, 0., 1.); c->Circle.n[0] = n[0]; c->Circle.n[1] = n[1]; c->Circle.n[2] = n[2]; - + End_Curve(c); // curve in reverse direction - - Curve *rc = CreateReversedCurve(THEM,c); - + + Curve *rc = CreateReversedCurve(THEM, c); + rc->Circle.n[0] = n[0]; rc->Circle.n[1] = n[1]; rc->Circle.n[2] = n[2]; End_Curve(rc); - - Tree_Insert(THEM->Curves,&c); - Tree_Insert(THEM->Curves,&rc); + + Tree_Insert(THEM->Curves, &c); + Tree_Insert(THEM->Curves, &rc); } -void Cdbseg101(int iseg, int typseg, int degre, List_T *liste, List_T *listint, - int i1,int i2,double u1 ,double u2,char *c1, char *c2, char *c3){ - int i,j; +void Cdbseg101(int iseg, int typseg, int degre, List_T * liste, + List_T * listint, int i1, int i2, double u1, double u2, + char *c1, char *c2, char *c3) +{ + int i, j; double d; List_T *Temp; - if(listint){ - AddCurveInDataBase (iseg,typseg,degre,listint,NULL,i1,i2,u1,u2); + if(listint) { + AddCurveInDataBase(iseg, typseg, degre, listint, NULL, i1, i2, u1, u2); } - else{ - Temp = List_Create(List_Nbr(liste),1,sizeof(int)); - for(i=0;i<List_Nbr(liste);i++){ - List_Read(liste,i,&d); + else { + Temp = List_Create(List_Nbr(liste), 1, sizeof(int)); + for(i = 0; i < List_Nbr(liste); i++) { + List_Read(liste, i, &d); j = (int)d; - List_Add(Temp,&j); + List_Add(Temp, &j); } - AddCurveInDataBase (iseg,typseg,degre,Temp,NULL,i1,i2,u1,u2); + AddCurveInDataBase(iseg, typseg, degre, Temp, NULL, i1, i2, u1, u2); List_Delete(Temp); } - + } // Surfaces and volumes -void AddQuadricSurfaceInDataBase (int Typ, int NumQuadric, double zaxis[3], - double xaxis[3], double center[3], - double radius1, double radius2, List_T *loops){ - int ic,i,j,NbLoop,iLoop; +void AddQuadricSurfaceInDataBase(int Typ, int NumQuadric, double zaxis[3], + double xaxis[3], double center[3], + double radius1, double radius2, + List_T * loops) +{ + int ic, i, j, NbLoop, iLoop; Surface *s; Curve *c; EdgeLoop *el; - - s = Create_Surface(NumQuadric,Typ); + + s = Create_Surface(NumQuadric, Typ); s->Method = LIBRE; - for(i=0;i<3;i++)s->Cyl.xaxis[i] = xaxis[i]; - for(i=0;i<3;i++)s->Cyl.zaxis[i] = zaxis[i]; - for(i=0;i<3;i++)s->Cyl.center[i] = center[i]; + for(i = 0; i < 3; i++) + s->Cyl.xaxis[i] = xaxis[i]; + for(i = 0; i < 3; i++) + s->Cyl.zaxis[i] = zaxis[i]; + for(i = 0; i < 3; i++) + s->Cyl.center[i] = center[i]; s->Cyl.radius1 = radius1; s->Cyl.radius2 = radius2; - s->Generatrices = List_Create(4, 1, sizeof(Curve*)); + s->Generatrices = List_Create(4, 1, sizeof(Curve *)); NbLoop = List_Nbr(loops); - s->Generatrices = List_Create(4, 1, sizeof(Curve*)); - for(i=0;i<NbLoop;i++){ - List_Read(loops,i,&iLoop); - if(!(el = FindEdgeLoop(iLoop,THEM))){ + s->Generatrices = List_Create(4, 1, sizeof(Curve *)); + for(i = 0; i < NbLoop; i++) { + List_Read(loops, i, &iLoop); + if(!(el = FindEdgeLoop(iLoop, THEM))) { Msg(GERROR, "Unknown Line Loop %d", iLoop); List_Delete(s->Generatrices); Free(s); return; } - else{ - for(j=0;j<List_Nbr(el->Curves);j++){ - List_Read(el->Curves,j,&ic); - if(!(c = FindCurve(ic,THEM))){ + else { + for(j = 0; j < List_Nbr(el->Curves); j++) { + List_Read(el->Curves, j, &ic); + if(!(c = FindCurve(ic, THEM))) { Msg(GERROR, "Unknown Curve %d", ic); - List_Delete(s->Generatrices); - Free(s); - return; - } + List_Delete(s->Generatrices); + Free(s); + return; + } else - List_Add (s->Generatrices, &c); + List_Add(s->Generatrices, &c); } } } s->Support = s; End_Surface(s); - Tree_Insert (THEM->Surfaces , &s); + Tree_Insert(THEM->Surfaces, &s); } -void CreateSurfaceFromOldCrappyDatabase (int izon, int typzon, int o1, int o2, - int nbu, int nbv, int sup, - List_T *liste, List_T *loops, Mesh *M){ - int ic,i,j,l,NbLoop,iLoop; - Surface *s,*pS; - Curve *c; - Vertex V,*v; +void CreateSurfaceFromOldCrappyDatabase(int izon, int typzon, int o1, int o2, + int nbu, int nbv, int sup, + List_T * liste, List_T * loops, + Mesh * M) +{ + int ic, i, j, l, NbLoop, iLoop; + Surface *s, *pS; + Curve *c; + Vertex V, *v; EdgeLoop *el; - s = Create_Surface(izon,typzon); + s = Create_Surface(izon, typzon); s->Method = LIBRE; - + NbLoop = List_Nbr(loops); - s->Generatrices = List_Create(4, 1, sizeof(Curve*)); - for(i=0;i<NbLoop;i++){ - List_Read(loops,i,&iLoop); - if(!(el = FindEdgeLoop(iLoop,THEM))){ + s->Generatrices = List_Create(4, 1, sizeof(Curve *)); + for(i = 0; i < NbLoop; i++) { + List_Read(loops, i, &iLoop); + if(!(el = FindEdgeLoop(iLoop, THEM))) { Msg(GERROR, "Unknown Line Loop %d", iLoop); List_Delete(s->Generatrices); Free(s); return; - } - else{ - for(j=0;j<List_Nbr(el->Curves);j++){ - List_Read(el->Curves,j,&ic); - if(!(c = FindCurve(ic,THEM))){ + } + else { + for(j = 0; j < List_Nbr(el->Curves); j++) { + List_Read(el->Curves, j, &ic); + if(!(c = FindCurve(ic, THEM))) { Msg(GERROR, "Unknown Curve %d", ic); - List_Delete(s->Generatrices); - Free(s); - return; - } + List_Delete(s->Generatrices); + Free(s); + return; + } else - List_Add (s->Generatrices, &c); + List_Add(s->Generatrices, &c); } } } - - if((pS = FindSurface(sup,THEM))){ + + if((pS = FindSurface(sup, THEM))) { s->Support = pS; } - else{ + else { s->Support = s; } - if(typzon == MSH_SURF_NURBS && !pS){ - s->Control_Points = List_Create(4, 1, sizeof(Vertex*)); + if(typzon == MSH_SURF_NURBS && !pS) { + s->Control_Points = List_Create(4, 1, sizeof(Vertex *)); s->OrderU = o1; s->OrderV = o2; s->Nu = nbu; s->Nv = nbv; - for(l=0;l<List_Nbr(liste);l++){ - List_Read(liste,l,&iLoop); + for(l = 0; l < List_Nbr(liste); l++) { + List_Read(liste, l, &iLoop); v = &V; v->Num = iLoop; - List_Add (s->Control_Points, Tree_PQuery(M->Points, &v)); + List_Add(s->Control_Points, Tree_PQuery(M->Points, &v)); } } End_Surface(s); - Tree_Insert (M->Surfaces , &s); + Tree_Insert(M->Surfaces, &s); } -void CreateVolumeFromOldCrappyDatabase (int izon, List_T *loops, Mesh *M){ +void CreateVolumeFromOldCrappyDatabase(int izon, List_T * loops, Mesh * M) +{ SurfaceLoop *sl; - int i,j,iLoop,is; + int i, j, iLoop, is; Surface *s; Volume *v; - - v = Create_Volume(izon,MSH_VOLUME); - v->Surfaces = List_Create(4, 1, sizeof(Surface*)); - for(i=0;i<List_Nbr(loops);i++){ - List_Read(loops,i,&iLoop); - if(!(sl = FindSurfaceLoop(iLoop,THEM))){ + + v = Create_Volume(izon, MSH_VOLUME); + v->Surfaces = List_Create(4, 1, sizeof(Surface *)); + for(i = 0; i < List_Nbr(loops); i++) { + List_Read(loops, i, &iLoop); + if(!(sl = FindSurfaceLoop(iLoop, THEM))) { Msg(GERROR, "Unknown Surface Loop %d", iLoop); List_Delete(v->Surfaces); Free(v); return; } - else{ - for(j=0;j<List_Nbr(sl->Surfaces);j++){ - List_Read(sl->Surfaces,j,&is); - if(!(s = FindSurface(abs(is),THEM))){ + else { + for(j = 0; j < List_Nbr(sl->Surfaces); j++) { + List_Read(sl->Surfaces, j, &is); + if(!(s = FindSurface(abs(is), THEM))) { Msg(GERROR, "Unknown Surface %d", is); - List_Delete(v->Surfaces); - Free(v); - return; - } + List_Delete(v->Surfaces); + Free(v); + return; + } else - List_Add (v->Surfaces, &s); + List_Add(v->Surfaces, &s); } } } - Tree_Add(M->Volumes,&v); + Tree_Add(M->Volumes, &v); } -void Cdbz101(int izon, int typzon,int o1, int o2, int nbu, int nbv, - int support, List_T *ListCP, List_T *liste, - List_T *intlist){ +void Cdbz101(int izon, int typzon, int o1, int o2, int nbu, int nbv, + int support, List_T * ListCP, List_T * liste, List_T * intlist) +{ - int i,j; - double f; - List_T *templist = NULL; - Curve *c, *c0, *c1, *c2; + int i, j; + double f; + List_T *templist = NULL; + Curve *c, *c0, *c1, *c2; - if(liste){ - templist = List_Create(List_Nbr(liste),1,sizeof(int)); - for(i=0;i<List_Nbr(liste);i++){ - List_Read (liste, i, &f); + if(liste) { + templist = List_Create(List_Nbr(liste), 1, sizeof(int)); + for(i = 0; i < List_Nbr(liste); i++) { + List_Read(liste, i, &f); j = (int)f; - List_Add(templist,&j); + List_Add(templist, &j); } } - else if (intlist){ + else if(intlist) { templist = intlist; } if(typzon == MSH_SURF_REGL || typzon == MSH_SURF_TRIC || typzon == MSH_SURF_PLAN || typzon == MSH_SURF_TRIMMED || - typzon == MSH_SURF_NURBS ){ - CreateSurfaceFromOldCrappyDatabase (izon, typzon, o1,o2, nbu, nbv, - support, ListCP,templist,THEM); + typzon == MSH_SURF_NURBS) { + CreateSurfaceFromOldCrappyDatabase(izon, typzon, o1, o2, nbu, nbv, + support, ListCP, templist, THEM); } - else if(typzon == MSH_SURF_LOOP){ - Add_SurfaceLoop(izon,templist,THEM); + else if(typzon == MSH_SURF_LOOP) { + Add_SurfaceLoop(izon, templist, THEM); } - else if(typzon == MSH_SEGM_LOOP){ + else if(typzon == MSH_SEGM_LOOP) { // We sort the lines in the line loops. Without this sort, it very // difficult to write general scriptable surface generation in // complex cases. - int NbCurves = List_Nbr(templist) ; - List_T *curves = List_Create(NbCurves,1,sizeof(Curve*)); - for(i=0 ; i<NbCurves ; i++){ - if((c = FindCurve(*(int*)List_Pointer(templist,i), THEM))) - List_Add(curves, &c); + int NbCurves = List_Nbr(templist); + List_T *curves = List_Create(NbCurves, 1, sizeof(Curve *)); + for(i = 0; i < NbCurves; i++) { + if((c = FindCurve(*(int *)List_Pointer(templist, i), THEM))) + List_Add(curves, &c); else - Msg(GERROR, "Unknown Curve %d in Line Loop %d", - *(int*)List_Pointer(templist,i), izon); + Msg(GERROR, "Unknown Curve %d in Line Loop %d", + *(int *)List_Pointer(templist, i), izon); } List_Reset(templist); int j = 0, k = 0; - c0 = c1 = *(Curve**)List_Pointer(curves, 0); + c0 = c1 = *(Curve **) List_Pointer(curves, 0); List_Add(templist, &c1->Num); List_PSuppress(curves, 0); - while(List_Nbr(templist) < NbCurves){ - for(i=0 ; i<List_Nbr(curves); i++){ - c2 = *(Curve**)List_Pointer(curves, i); - if(c1->end == c2->beg){ - List_Add(templist, &c2->Num); - List_PSuppress(curves, i); - c1 = c2 ; - if(c2->end == c0->beg){ - if(List_Nbr(curves)){ - Msg(INFO, "Starting subloop %d in Line Loop %d (are you sure about this?)", - ++k, izon); - c0 = c1 = *(Curve**)List_Pointer(curves, 0); - List_Add(templist, &c1->Num); - List_PSuppress(curves, 0); - } - } - break; - } + while(List_Nbr(templist) < NbCurves) { + for(i = 0; i < List_Nbr(curves); i++) { + c2 = *(Curve **) List_Pointer(curves, i); + if(c1->end == c2->beg) { + List_Add(templist, &c2->Num); + List_PSuppress(curves, i); + c1 = c2; + if(c2->end == c0->beg) { + if(List_Nbr(curves)) { + Msg(INFO, + "Starting subloop %d in Line Loop %d (are you sure about this?)", + ++k, izon); + c0 = c1 = *(Curve **) List_Pointer(curves, 0); + List_Add(templist, &c1->Num); + List_PSuppress(curves, 0); + } + } + break; + } } - if(j++ > NbCurves){ - Msg(GERROR, "Line Loop %d is wrong", izon); - break; + if(j++ > NbCurves) { + Msg(GERROR, "Line Loop %d is wrong", izon); + break; } - } + } List_Delete(curves); /* - printf("Line Loop %d = {", izon); - for(i=0 ; i<List_Nbr(templist); i++){ - printf(" %d", *(int*)List_Pointer(templist, i)); - } - printf("}\n"); - */ - Add_EdgeLoop(izon,templist,THEM); + printf("Line Loop %d = {", izon); + for(i=0 ; i<List_Nbr(templist); i++){ + printf(" %d", *(int*)List_Pointer(templist, i)); + } + printf("}\n"); + */ + Add_EdgeLoop(izon, templist, THEM); } - else if(typzon == MSH_VOLUME){ - CreateVolumeFromOldCrappyDatabase (izon,templist,THEM); + else if(typzon == MSH_VOLUME) { + CreateVolumeFromOldCrappyDatabase(izon, templist, THEM); } - else{ - Add_PhysicalGroup(izon,typzon,templist,THEM); + else { + Add_PhysicalGroup(izon, typzon, templist, THEM); } - - if(liste)List_Delete (templist); - + + if(liste) + List_Delete(templist); + } -void CreateNurbsSurfaceSupport (int Num , int Order1, int Order2 , - List_T *List, List_T *ku, List_T *kv){ - +void CreateNurbsSurfaceSupport(int Num, int Order1, int Order2, + List_T * List, List_T * ku, List_T * kv) +{ List_T *ListOfDouble_L; List_T *ListCP; - int i,j,Nv,Nu,N; + int i, j, Nv, Nu, N; Surface *s; double d; float f; - ListCP = List_Create(2,2,sizeof(int)); - - for(j=0;j<List_Nbr(List);j++){ - List_Read(List,j,&ListOfDouble_L); - for(i=0;i<List_Nbr(ListOfDouble_L);i++){ - List_Read(ListOfDouble_L,i,&d); + ListCP = List_Create(2, 2, sizeof(int)); + + for(j = 0; j < List_Nbr(List); j++) { + List_Read(List, j, &ListOfDouble_L); + for(i = 0; i < List_Nbr(ListOfDouble_L); i++) { + List_Read(ListOfDouble_L, i, &d); N = (int)d; - List_Add(ListCP,&N); + List_Add(ListCP, &N); } } - List_Read(List,0,&ListOfDouble_L); + List_Read(List, 0, &ListOfDouble_L); Nu = List_Nbr(List); Nv = List_Nbr(ListOfDouble_L); - Cdbz101(Num,MSH_SURF_NURBS,Order1,Order2,Nv,Nu,0,ListCP,NULL,NULL); + Cdbz101(Num, MSH_SURF_NURBS, Order1, Order2, Nv, Nu, 0, ListCP, NULL, NULL); - if(!(s = FindSurface(Num,THEM))){ + if(!(s = FindSurface(Num, THEM))) { Msg(GERROR, "Unknown Surface Loop %d", Num); return; } - else{ - s->ku = (float*)malloc(List_Nbr(ku)*sizeof(float)); - s->kv = (float*)malloc(List_Nbr(kv)*sizeof(float)); + else { + s->ku = (float *)malloc(List_Nbr(ku) * sizeof(float)); + s->kv = (float *)malloc(List_Nbr(kv) * sizeof(float)); s->Support = NULL; - + double kumin = 0., kumax = 1.; double kvmin = 0., kvmax = 1.; /* - List_Read(ku,0,&kumin); - List_Read(ku,List_Nbr(ku)-1,&kumax); - List_Read(kv,0,&kvmin); - List_Read(kv,List_Nbr(kv)-1,&kvmax); - */ - - for(i=0;i<List_Nbr(ku);i++){ - List_Read(ku,i,&d); - f = (float) ((d-kumin)/(kumax-kumin)); + List_Read(ku,0,&kumin); + List_Read(ku,List_Nbr(ku)-1,&kumax); + List_Read(kv,0,&kvmin); + List_Read(kv,List_Nbr(kv)-1,&kvmax); + */ + + for(i = 0; i < List_Nbr(ku); i++) { + List_Read(ku, i, &d); + f = (float)((d - kumin) / (kumax - kumin)); s->ku[i] = f; } - for(i=0;i<List_Nbr(kv);i++) { - List_Read(kv,i,&d); - f = (float) ((d-kvmin)/(kvmax-kvmin)); + for(i = 0; i < List_Nbr(kv); i++) { + List_Read(kv, i, &d); + f = (float)((d - kvmin) / (kvmax - kvmin)); s->kv[i] = f; } } @@ -413,110 +430,115 @@ void CreateNurbsSurfaceSupport (int Num , int Order1, int Order2 , List_Delete(ListCP); } -void CreateNurbsSurface (int Num , int Order1 , int Order2 , List_T *List, - List_T *ku, List_T *kv ){ +void CreateNurbsSurface(int Num, int Order1, int Order2, List_T * List, + List_T * ku, List_T * kv) +{ List_T *ListOfDouble_L; - List_T *Listint,*ListCP; - int i,j,Loop[4],N,Nu,Nv; + List_T *Listint, *ListCP; + int i, j, Loop[4], N, Nu, Nv; double d; int TypLine = MSH_SEGM_NURBS; Curve *cc; - - Listint = List_Create(2,2,sizeof(int)); - ListCP = List_Create(2,2,sizeof(int)); + + Listint = List_Create(2, 2, sizeof(int)); + ListCP = List_Create(2, 2, sizeof(int)); double kumin, kumax; - List_Read(ku,0,&kumin); - List_Read(ku,List_Nbr(ku)-1,&kumax); + List_Read(ku, 0, &kumin); + List_Read(ku, List_Nbr(ku) - 1, &kumax); double kvmin, kvmax; - List_Read(kv,0,&kvmin); - List_Read(kv,List_Nbr(kv)-1,&kvmax); - for(j=0;j<List_Nbr(List);j++){ - List_Read(List,j,&ListOfDouble_L); - for(i=0;i<List_Nbr(ListOfDouble_L);i++){ - List_Read(ListOfDouble_L,i,&d); + List_Read(kv, 0, &kvmin); + List_Read(kv, List_Nbr(kv) - 1, &kvmax); + for(j = 0; j < List_Nbr(List); j++) { + List_Read(List, j, &ListOfDouble_L); + for(i = 0; i < List_Nbr(ListOfDouble_L); i++) { + List_Read(ListOfDouble_L, i, &d); N = (int)d; - List_Add(ListCP,&N); + List_Add(ListCP, &N); } } - - List_Read(List,0,&ListOfDouble_L); + + List_Read(List, 0, &ListOfDouble_L); Nu = List_Nbr(List); Nv = List_Nbr(ListOfDouble_L); - - for(i=0;i<List_Nbr(ListOfDouble_L);i++){ - List_Read(ListOfDouble_L,i,&d); + + for(i = 0; i < List_Nbr(ListOfDouble_L); i++) { + List_Read(ListOfDouble_L, i, &d); j = (int)d; - List_Add(Listint,&j); + List_Add(Listint, &j); } - if(recognize_seg(TypLine,Listint,&Loop[0])){ + if(recognize_seg(TypLine, Listint, &Loop[0])) { } - else{ + else { Loop[0] = NEWREG(); - Cdbseg101(Loop[0],TypLine,Order1,ListOfDouble_L,NULL,-1,-1,kumin,kumax,NULL,NULL,NULL); - if(!(cc = FindCurve(Loop[0],THEM))){ + Cdbseg101(Loop[0], TypLine, Order1, ListOfDouble_L, NULL, -1, -1, kumin, + kumax, NULL, NULL, NULL); + if(!(cc = FindCurve(Loop[0], THEM))) { Msg(GERROR, "Unknown Curve %d", Loop[0]); List_Delete(Listint); List_Delete(ListCP); return; } - else{ - cc->k = (float*)malloc(4*List_Nbr(ku)*sizeof(float)); - for(i=0;i<List_Nbr(ku);i++){ - List_Read(ku,i,&d); - cc->k[i] = (float)d/*((d-kumin)/(kumax-kumin))*/; + else { + cc->k = (float *)malloc(4 * List_Nbr(ku) * sizeof(float)); + for(i = 0; i < List_Nbr(ku); i++) { + List_Read(ku, i, &d); + cc->k[i] = (float)d /*((d-kumin)/(kumax-kumin)) */ ; } } } List_Reset(Listint); - - List_Read(List,List_Nbr(List)-1,&ListOfDouble_L); - for(i=0;i<List_Nbr(ListOfDouble_L);i++){ - List_Read(ListOfDouble_L,i,&d); + + List_Read(List, List_Nbr(List) - 1, &ListOfDouble_L); + for(i = 0; i < List_Nbr(ListOfDouble_L); i++) { + List_Read(ListOfDouble_L, i, &d); j = (int)d; - List_Add(Listint,&j); + List_Add(Listint, &j); } - if(recognize_seg(TypLine,Listint,&Loop[2])){ + if(recognize_seg(TypLine, Listint, &Loop[2])) { } - else{ + else { Loop[2] = NEWREG(); - Cdbseg101(Loop[2],TypLine,Order1,ListOfDouble_L,NULL,-1,-1,kumin,kumax,NULL,NULL,NULL); - if(!(cc = FindCurve(Loop[2],THEM))){ + Cdbseg101(Loop[2], TypLine, Order1, ListOfDouble_L, NULL, -1, -1, kumin, + kumax, NULL, NULL, NULL); + if(!(cc = FindCurve(Loop[2], THEM))) { Msg(GERROR, "Unknown Curve %d", Loop[2]); List_Delete(Listint); List_Delete(ListCP); return; } - else{ - cc->k = (float*)malloc(4*List_Nbr(ku)*sizeof(float)); - for(i=0;i<List_Nbr(ku);i++){ - List_Read(ku,i,&d); - cc->k[i] = (float)d/*((d-kumin)/(kumax-kumin))*/; + else { + cc->k = (float *)malloc(4 * List_Nbr(ku) * sizeof(float)); + for(i = 0; i < List_Nbr(ku); i++) { + List_Read(ku, i, &d); + cc->k[i] = (float)d /*((d-kumin)/(kumax-kumin)) */ ; } } } List_Reset(Listint); - - List_T *List1 = List_Create(List_Nbr(List),1,sizeof(double)); - List_T *List2 = List_Create(List_Nbr(List),1,sizeof(double)); - - for(i=0;i<List_Nbr(List);i++){ - List_Read(List,i,&ListOfDouble_L); - List_Add(List1,List_Pointer(ListOfDouble_L,0)); - List_Add(List2,List_Pointer(ListOfDouble_L,List_Nbr(ListOfDouble_L)-1)); - } - - for(i=0;i<List_Nbr(List1);i++){ - List_Read(List1,i,&d); + + List_T *List1 = List_Create(List_Nbr(List), 1, sizeof(double)); + List_T *List2 = List_Create(List_Nbr(List), 1, sizeof(double)); + + for(i = 0; i < List_Nbr(List); i++) { + List_Read(List, i, &ListOfDouble_L); + List_Add(List1, List_Pointer(ListOfDouble_L, 0)); + List_Add(List2, + List_Pointer(ListOfDouble_L, List_Nbr(ListOfDouble_L) - 1)); + } + + for(i = 0; i < List_Nbr(List1); i++) { + List_Read(List1, i, &d); j = (int)d; - List_Add(Listint,&j); + List_Add(Listint, &j); } - if(recognize_seg(TypLine,Listint,&Loop[1])){ + if(recognize_seg(TypLine, Listint, &Loop[1])) { } - else{ + else { Loop[1] = NEWREG(); - Cdbseg101(Loop[1],TypLine,Order2,List1,NULL,-1,-1,kvmin,kvmax,NULL,NULL,NULL); - if(!(cc = FindCurve(Loop[1],THEM))){ + Cdbseg101(Loop[1], TypLine, Order2, List1, NULL, -1, -1, kvmin, kvmax, + NULL, NULL, NULL); + if(!(cc = FindCurve(Loop[1], THEM))) { Msg(GERROR, "Unknown Curve %d", Loop[1]); List_Delete(List1); List_Delete(List2); @@ -524,58 +546,59 @@ void CreateNurbsSurface (int Num , int Order1 , int Order2 , List_T *List, List_Delete(ListCP); return; } - else{ - cc->k = (float*)malloc(4*List_Nbr(kv) * sizeof(float)); - for(i=0;i<List_Nbr(kv);i++){ - List_Read(kv,i,&d); - cc->k[i] = (float)d/*((d-kvmin)/(kvmax-kvmin))*/; + else { + cc->k = (float *)malloc(4 * List_Nbr(kv) * sizeof(float)); + for(i = 0; i < List_Nbr(kv); i++) { + List_Read(kv, i, &d); + cc->k[i] = (float)d /*((d-kvmin)/(kvmax-kvmin)) */ ; } } } List_Reset(Listint); - - for(i=0;i<List_Nbr(List2);i++){ - List_Read(List2,i,&d); + + for(i = 0; i < List_Nbr(List2); i++) { + List_Read(List2, i, &d); j = (int)d; - List_Add(Listint,&j); + List_Add(Listint, &j); } - if(recognize_seg(TypLine,Listint,&Loop[3])){ + if(recognize_seg(TypLine, Listint, &Loop[3])) { } - else{ + else { Loop[3] = NEWREG(); - Cdbseg101(Loop[3],TypLine,Order2,List2,NULL,-1,-1,kvmin,kvmax,NULL,NULL,NULL); - if(!(cc = FindCurve(Loop[3],THEM))) + Cdbseg101(Loop[3], TypLine, Order2, List2, NULL, -1, -1, kvmin, kvmax, + NULL, NULL, NULL); + if(!(cc = FindCurve(Loop[3], THEM))) Msg(GERROR, "Unknown Curve %d", Loop[3]); - else{ - cc->k = (float*)malloc(4*List_Nbr(kv)*sizeof(float)); - for(i=0;i<List_Nbr(kv);i++){ - List_Read(kv,i,&d); - cc->k[i] = (float)d/*((d-kvmin)/(kvmax-kvmin))*/; + else { + cc->k = (float *)malloc(4 * List_Nbr(kv) * sizeof(float)); + for(i = 0; i < List_Nbr(kv); i++) { + List_Read(kv, i, &d); + cc->k[i] = (float)d /*((d-kvmin)/(kvmax-kvmin)) */ ; } } } - + List_Reset(Listint); List_Delete(List1); List_Reset(List2); double f = (double)-Loop[0]; - List_Add(List2,&f); + List_Add(List2, &f); f = (double)Loop[1]; - List_Add(List2,&f); + List_Add(List2, &f); f = (double)Loop[2]; - List_Add(List2,&f); + List_Add(List2, &f); f = (double)-Loop[3]; - List_Add(List2,&f); - + List_Add(List2, &f); + int topnew = NEWREG(); - CreateNurbsSurfaceSupport (topnew,Order1 , Order2 ,List,ku,kv); + CreateNurbsSurfaceSupport(topnew, Order1, Order2, List, ku, kv); j = NEWREG(); - Cdbz101(j,MSH_SEGM_LOOP,0,0,0,0,0,NULL,List2,NULL); + Cdbz101(j, MSH_SEGM_LOOP, 0, 0, 0, 0, 0, NULL, List2, NULL); List_Delete(List2); - List_Add(Listint,&j); + List_Add(Listint, &j); j = NEWREG(); - Cdbz101(j,MSH_SURF_TRIMMED,Order1,Order2,Nv,Nu,topnew,ListCP,NULL,Listint); + Cdbz101(j, MSH_SURF_TRIMMED, Order1, Order2, Nv, Nu, topnew, ListCP, NULL, + Listint); List_Delete(Listint); List_Delete(ListCP); } - diff --git a/Geo/ExtrudeParams.cpp b/Geo/ExtrudeParams.cpp index e2709a6a71a55a0b7359d72dab6ec8ff51a841cf..3c3ac0af38f229f5d442492c8c40bafbe61336cf 100644 --- a/Geo/ExtrudeParams.cpp +++ b/Geo/ExtrudeParams.cpp @@ -1,4 +1,4 @@ -// $Id: ExtrudeParams.cpp,v 1.11 2003-01-23 20:19:20 geuzaine Exp $ +// $Id: ExtrudeParams.cpp,v 1.12 2003-03-01 22:36:38 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -24,8 +24,9 @@ #include "CAD.h" #include "ExtrudeParams.h" -void Projette (double p[3],double mat[3][3]) { - double X, Y, Z ; +void Projette(double p[3], double mat[3][3]) +{ + double X, Y, Z; X = p[0] * mat[0][0] + p[1] * mat[0][1] + p[2] * mat[0][2]; Y = p[0] * mat[1][0] + p[1] * mat[1][1] + p[2] * mat[1][2]; @@ -35,7 +36,8 @@ void Projette (double p[3],double mat[3][3]) { p[2] = Z; } -ExtrudeParams :: ExtrudeParams (int ModeEx){ +ExtrudeParams::ExtrudeParams(int ModeEx) +{ geo.Mode = ModeEx; geo.Source = -1; mesh.ExtrudeMesh = false; @@ -43,10 +45,11 @@ ExtrudeParams :: ExtrudeParams (int ModeEx){ } -void ExtrudeParams :: fill (int type , - double T0, double T1, double T2, - double A0, double A1, double A2, - double X0, double X1, double X2, double angle){ +void ExtrudeParams::fill(int type, + double T0, double T1, double T2, + double A0, double A1, double A2, + double X0, double X1, double X2, double angle) +{ geo.trans[0] = T0; geo.trans[1] = T1; geo.trans[2] = T2; @@ -60,91 +63,101 @@ void ExtrudeParams :: fill (int type , geo.Type = type; } -void ExtrudeParams :: Extrude ( int iLayer, int iElemLayer, - double &x, double &y, double &z){ +void ExtrudeParams::Extrude(int iLayer, int iElemLayer, + double &x, double &y, double &z) +{ + double dx0, dy0, dz0, dx1, dy1, dz1; + double dx, dy, dz, angle; - double dx0,dy0,dz0,dx1,dy1,dz1; - double dx,dy,dz,angle; - if(!iLayer){ - dx0=dy0=dz0=0.0; + if(!iLayer) { + dx0 = dy0 = dz0 = 0.0; dx1 = mesh.hLayer[0]; dy1 = mesh.hLayer[0]; dz1 = mesh.hLayer[0]; } - else{ - dx0 = mesh.hLayer[iLayer-1]; - dy0 = mesh.hLayer[iLayer-1]; - dz0 = mesh.hLayer[iLayer-1]; + else { + dx0 = mesh.hLayer[iLayer - 1]; + dy0 = mesh.hLayer[iLayer - 1]; + dz0 = mesh.hLayer[iLayer - 1]; dx1 = mesh.hLayer[iLayer]; dy1 = mesh.hLayer[iLayer]; dz1 = mesh.hLayer[iLayer]; } - double t = (double) iElemLayer /(double)mesh.NbElmLayer[iLayer]; - switch(geo.Type){ - case TRANSLATE : - dx = geo.trans[0]*(dx0 + t * (dx1-dx0)); - dy = geo.trans[1]*(dy0 + t * (dy1-dy0)); - dz = geo.trans[2]*(dz0 + t * (dz1-dz0)); - x+=dx;y+=dy;z+=dz; + double t = (double)iElemLayer / (double)mesh.NbElmLayer[iLayer]; + switch (geo.Type) { + case TRANSLATE: + dx = geo.trans[0] * (dx0 + t * (dx1 - dx0)); + dy = geo.trans[1] * (dy0 + t * (dy1 - dy0)); + dz = geo.trans[2] * (dz0 + t * (dz1 - dz0)); + x += dx; + y += dy; + z += dz; break; - case ROTATE : + case ROTATE: angle = geo.angle; - geo.angle = geo.angle*(dx0 + t * (dx1-dx0)); - ProtudeXYZ(x,y,z,this); + geo.angle = geo.angle * (dx0 + t * (dx1 - dx0)); + ProtudeXYZ(x, y, z, this); geo.angle = angle; break; - case TRANSLATE_ROTATE : + case TRANSLATE_ROTATE: angle = geo.angle; - geo.angle = geo.angle*(dx0 + t * (dx1-dx0)); - ProtudeXYZ(x,y,z,this); + geo.angle = geo.angle * (dx0 + t * (dx1 - dx0)); + ProtudeXYZ(x, y, z, this); geo.angle = angle; - dx = geo.trans[0]*(dx0 + t * (dx1-dx0)); - dy = geo.trans[1]*(dy0 + t * (dy1-dy0)); - dz = geo.trans[2]*(dz0 + t * (dz1-dz0)); - x+=dx;y+=dy;z+=dz; + dx = geo.trans[0] * (dx0 + t * (dx1 - dx0)); + dy = geo.trans[1] * (dy0 + t * (dy1 - dy0)); + dz = geo.trans[2] * (dz0 + t * (dz1 - dz0)); + x += dx; + y += dy; + z += dz; break; - default : + default: Msg(GERROR, "Unknown extrusion type"); break; } } -void ExtrudeParams :: Rotate(double matr[3][3]){ - Projette(geo.trans,matr); - Projette(geo.axe,matr); - Projette(geo.pt,matr); +void ExtrudeParams::Rotate(double matr[3][3]) +{ + Projette(geo.trans, matr); + Projette(geo.axe, matr); + Projette(geo.pt, matr); geo.angle = -geo.angle; } -void ExtrudeParams :: Extrude (double t, double &x, double &y, double &z){ - double dx,dy,dz,angle; +void ExtrudeParams::Extrude(double t, double &x, double &y, double &z) +{ + double dx, dy, dz, angle; - switch(geo.Type){ - case TRANSLATE : - dx = geo.trans[0]*t; - dy = geo.trans[1]*t; - dz = geo.trans[2]*t; - x+=dx;y+=dy;z+=dz; + switch (geo.Type) { + case TRANSLATE: + dx = geo.trans[0] * t; + dy = geo.trans[1] * t; + dz = geo.trans[2] * t; + x += dx; + y += dy; + z += dz; break; - case ROTATE : + case ROTATE: angle = geo.angle; - geo.angle = geo.angle*t; - ProtudeXYZ(x,y,z,this); + geo.angle = geo.angle * t; + ProtudeXYZ(x, y, z, this); geo.angle = angle; break; - case TRANSLATE_ROTATE : + case TRANSLATE_ROTATE: angle = geo.angle; - geo.angle = geo.angle*t; - ProtudeXYZ(x,y,z,this); + geo.angle = geo.angle * t; + ProtudeXYZ(x, y, z, this); geo.angle = angle; - dx = geo.trans[0]*t; - dy = geo.trans[1]*t; - dz = geo.trans[2]*t; - x+=dx;y+=dy;z+=dz; + dx = geo.trans[0] * t; + dy = geo.trans[1] * t; + dz = geo.trans[2] * t; + x += dx; + y += dy; + z += dz; break; - default : + default: Msg(GERROR, "Unknown extrusion type"); break; } } - diff --git a/Geo/Geo.cpp b/Geo/Geo.cpp index 5931da9af6770690e4134409f1602b70a8ad0f92..8ba163efbab1ec495ca7c1033b08880a4f59a609 100644 --- a/Geo/Geo.cpp +++ b/Geo/Geo.cpp @@ -1,4 +1,4 @@ -// $Id: Geo.cpp,v 1.30 2003-01-23 20:19:20 geuzaine Exp $ +// $Id: Geo.cpp,v 1.31 2003-03-01 22:36:38 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -27,19 +27,19 @@ #include "Parser.h" #include "Context.h" -extern Context_T CTX ; +extern Context_T CTX; #define BUFFSIZE 32000 // This is truly horrible :-) -char x_text[100] = "0.0", y_text[100] = "0.0", z_text[100] = "0.0"; -char l_text[100] = "1.0" ; +char x_text[100] = "0.0", y_text[100] = "0.0", z_text[100] = "0.0"; +char l_text[100] = "1.0"; char tx_text[100] = "0.0", ty_text[100] = "0.0", tz_text[100] = "0.0"; -char attrx_text[100] = "1.0", attry_text[100] = "1.0", attrz_text[100] = "1.0" ; +char attrx_text[100] = "1.0", attry_text[100] = "1.0", attrz_text[100] = "1.0"; char attrdec_text[100] = "2.0"; -char px_text[100] = "0.0", py_text[100] = "0.0", pz_text[100] = "0.0" ; -char angle_text[100] = "3.14159/2" ; +char px_text[100] = "0.0", py_text[100] = "0.0", pz_text[100] = "0.0"; +char angle_text[100] = "3.14159/2"; char ax_text[100] = "0.0", ay_text[100] = "0.0", az_text[100] = "1.0"; char dx_text[100] = "0.0", dy_text[100] = "0.0", dz_text[100] = "0.0", df_text[100] = "1.0"; char sa_text[100] = "0.0", sb_text[100] = "0.0", sc_text[100] = "0.0", sd_text[100] = "0.0"; @@ -47,400 +47,447 @@ char trsf_pts_text[100] = "2", trsf_type_text[100] = "Progression", trsf_typearg char trsf_vol_text[100] = "1"; char char_length_text[100] = "1."; -double evaluate_scalarfunction (char *var, double val, char *funct){ +double evaluate_scalarfunction(char *var, double val, char *funct) +{ FILE *tempf; tempf = yyin; - - if(!(yyin = fopen(CTX.tmp_filename,"w"))){ + + if(!(yyin = fopen(CTX.tmp_filename, "w"))) { Msg(GERROR, "Unable to open temporary file '%s'", CTX.tmp_filename); return 0.; } // pose "variable = function" and evaluate function - fprintf(yyin,"%s = %.16g ;\n",var,val); - fprintf(yyin,"ValeurTemporaire__ = %s ;\n",funct); + fprintf(yyin, "%s = %.16g ;\n", var, val); + fprintf(yyin, "ValeurTemporaire__ = %s ;\n", funct); fclose(yyin); - yyin = fopen(CTX.tmp_filename,"r"); - while(!feof(yyin)){ + yyin = fopen(CTX.tmp_filename, "r"); + while(!feof(yyin)) { yyparse(); } fclose(yyin); Symbol TheSymbol; - TheSymbol.Name = (char*)malloc(100); - strcpy(TheSymbol.Name,"ValeurTemporaire__"); + TheSymbol.Name = (char *)malloc(100); + strcpy(TheSymbol.Name, "ValeurTemporaire__"); yyin = tempf; - if (!List_Query(Symbol_L, &TheSymbol, CompareSymbols)) { + if(!List_Query(Symbol_L, &TheSymbol, CompareSymbols)) { free(TheSymbol.Name); return 0.0; } free(TheSymbol.Name); - return *(double*)List_Pointer_Fast(TheSymbol.val,0); + return *(double *)List_Pointer_Fast(TheSymbol.val, 0); } -void add_infile(char *text, char *fich){ +void add_infile(char *text, char *fich) +{ FILE *file; - if(!(yyin = fopen(CTX.tmp_filename,"w"))){ + if(!(yyin = fopen(CTX.tmp_filename, "w"))) { Msg(GERROR, "Unable to open temporary file '%s'", CTX.tmp_filename); return; } - if(!(file = fopen(fich,"a"))){ + if(!(file = fopen(fich, "a"))) { Msg(GERROR, "Unable to open file '%s'", fich); return; } - fprintf(yyin,"%s\n",text); - Msg(STATUS1,"%s",text); + fprintf(yyin, "%s\n", text); + Msg(STATUS1, "%s", text); fclose(yyin); - yyin = fopen(CTX.tmp_filename,"r"); - while(!feof(yyin)){ + yyin = fopen(CTX.tmp_filename, "r"); + while(!feof(yyin)) { yyparse(); } fclose(yyin); - fprintf(file,"%s\n",text); + fprintf(file, "%s\n", text); fclose(file); } -void delet(int p1, char *fich, char *what){ +void delet(int p1, char *fich, char *what) +{ char text[BUFFSIZE]; - sprintf(text,"Delete {\n %s{%d};\n}",what,p1); - add_infile(text,fich); + sprintf(text, "Delete {\n %s{%d};\n}", what, p1); + add_infile(text, fich); } -void add_trsfsurf (int N, int *l, char *fich){ +void add_trsfsurf(int N, int *l, char *fich) +{ char text[BUFFSIZE]; char text2[BUFFSIZE]; int i; - sprintf(text,"Transfinite Surface {%d} = {",l[0]); - for(i=1;i<N;i++){ - if(i==1)sprintf(text2,"%d",l[i]); - else sprintf(text2,",%d",l[i]); - strcat(text,text2); + sprintf(text, "Transfinite Surface {%d} = {", l[0]); + for(i = 1; i < N; i++) { + if(i == 1) + sprintf(text2, "%d", l[i]); + else + sprintf(text2, ",%d", l[i]); + strcat(text, text2); } - sprintf(text2,"};"); - strcat(text,text2); - add_infile(text,fich); + sprintf(text2, "};"); + strcat(text, text2); + add_infile(text, fich); } -void add_ellipticsurf (int N, int *l, char *fich){ +void add_ellipticsurf(int N, int *l, char *fich) +{ char text[BUFFSIZE]; char text2[BUFFSIZE]; int i; - sprintf(text,"Elliptic Surface {%d} = {",l[0]); - for(i=1;i<N;i++){ - if(i==1)sprintf(text2,"%d",l[i]); - else sprintf(text2,",%d",l[i]); - strcat(text,text2); + sprintf(text, "Elliptic Surface {%d} = {", l[0]); + for(i = 1; i < N; i++) { + if(i == 1) + sprintf(text2, "%d", l[i]); + else + sprintf(text2, ",%d", l[i]); + strcat(text, text2); } - sprintf(text2,"};"); - strcat(text,text2); - add_infile(text,fich); + sprintf(text2, "};"); + strcat(text, text2); + add_infile(text, fich); } -void add_charlength (int N, int *l, char *fich){ +void add_charlength(int N, int *l, char *fich) +{ char text[BUFFSIZE]; char text2[BUFFSIZE]; int i; - sprintf(text,"Characteristic Length {"); - for(i=0;i<N;i++){ - if(i==0)sprintf(text2,"%d",l[i]); - else sprintf(text2,",%d",l[i]); - strcat(text,text2); + sprintf(text, "Characteristic Length {"); + for(i = 0; i < N; i++) { + if(i == 0) + sprintf(text2, "%d", l[i]); + else + sprintf(text2, ",%d", l[i]); + strcat(text, text2); } - sprintf(text2,"} = %s;", char_length_text); - strcat(text,text2); - add_infile(text,fich); + sprintf(text2, "} = %s;", char_length_text); + strcat(text, text2); + add_infile(text, fich); } -void add_recosurf (int N, int *l, char *fich){ +void add_recosurf(int N, int *l, char *fich) +{ char text[BUFFSIZE]; char text2[BUFFSIZE]; int i; - sprintf(text,"Recombine Surface {"); - for(i=0;i<N;i++){ - if(i==0)sprintf(text2,"%d",l[i]); - else sprintf(text2,",%d",l[i]); - strcat(text,text2); + sprintf(text, "Recombine Surface {"); + for(i = 0; i < N; i++) { + if(i == 0) + sprintf(text2, "%d", l[i]); + else + sprintf(text2, ",%d", l[i]); + strcat(text, text2); } - sprintf(text2,"};"); - strcat(text,text2); - add_infile(text,fich); + sprintf(text2, "};"); + strcat(text, text2); + add_infile(text, fich); } -void add_trsfline (int N, int *l, char *fich){ +void add_trsfline(int N, int *l, char *fich) +{ char text[BUFFSIZE]; char text2[BUFFSIZE]; int i; - sprintf(text,"Transfinite Line {"); - for(i=0;i<N;i++){ - if(!i)sprintf(text2,"%d",l[i]); - else sprintf(text2,",%d",l[i]); - strcat(text,text2); + sprintf(text, "Transfinite Line {"); + for(i = 0; i < N; i++) { + if(!i) + sprintf(text2, "%d", l[i]); + else + sprintf(text2, ",%d", l[i]); + strcat(text, text2); } if(strlen(trsf_typearg_text)) - sprintf(text2,"} = %s Using %s %s;", trsf_pts_text, trsf_type_text, trsf_typearg_text); + sprintf(text2, "} = %s Using %s %s;", trsf_pts_text, trsf_type_text, + trsf_typearg_text); else - sprintf(text2,"} = %s;", trsf_pts_text); - strcat(text,text2); - add_infile(text,fich); + sprintf(text2, "} = %s;", trsf_pts_text); + strcat(text, text2); + add_infile(text, fich); } -void add_param (char *par, char *value, char *fich){ +void add_param(char *par, char *value, char *fich) +{ char text[BUFFSIZE]; - sprintf(text,"%s = %s;",par,value); - add_infile(text,fich); + sprintf(text, "%s = %s;", par, value); + add_infile(text, fich); } -void add_point(char *fich){ +void add_point(char *fich) +{ char text[BUFFSIZE]; int ip; ip = NEWPOINT(); - sprintf(text,"Point(%d) = {%s,%s,%s,%s};",ip,x_text,y_text,z_text,l_text); - add_infile(text,fich); + sprintf(text, "Point(%d) = {%s,%s,%s,%s};", ip, x_text, y_text, z_text, + l_text); + add_infile(text, fich); } -void add_attractor(char *fich, int ip, int typ){ +void add_attractor(char *fich, int ip, int typ) +{ char text[BUFFSIZE]; if(typ == 0) { - sprintf(text,"Attractor Point {%d} = {%s,%s,%s} = ;", - ip,attrx_text,attry_text,attrdec_text); + sprintf(text, "Attractor Point {%d} = {%s,%s,%s} = ;", + ip, attrx_text, attry_text, attrdec_text); } - else if(typ == 1){ - sprintf(text,"Attractor Line {%d} = {%s,%s,%s};", - ip, attrx_text,attry_text,attrdec_text); + else if(typ == 1) { + sprintf(text, "Attractor Line {%d} = {%s,%s,%s};", + ip, attrx_text, attry_text, attrdec_text); } else if(typ == 2) { - sprintf(text,"Attractor Surface {%d} = {%s,%s,%s};", - ip,attrx_text,attry_text,attrdec_text); + sprintf(text, "Attractor Surface {%d} = {%s,%s,%s};", + ip, attrx_text, attry_text, attrdec_text); } - add_infile(text,fich); + add_infile(text, fich); } -void add_line(int p1, int p2, char *fich){ +void add_line(int p1, int p2, char *fich) +{ char text[BUFFSIZE]; int iseg; - List_T *list = List_Create(2,2,sizeof(int)); - List_Add(list,&p1); - List_Add(list,&p2); - if((recognize_seg(MSH_SEGM_LINE,list,&iseg))){ + List_T *list = List_Create(2, 2, sizeof(int)); + List_Add(list, &p1); + List_Add(list, &p2); + if((recognize_seg(MSH_SEGM_LINE, list, &iseg))) { List_Delete(list); return; } List_Delete(list); - - sprintf(text,"Line(%d) = {%d,%d};",NEWLINE(),p1,p2); - add_infile(text,fich); + + sprintf(text, "Line(%d) = {%d,%d};", NEWLINE(), p1, p2); + add_infile(text, fich); } -void add_circ(int p1, int p2, int p3, char *fich){ +void add_circ(int p1, int p2, int p3, char *fich) +{ char text[BUFFSIZE]; - sprintf(text,"Circle(%d) = {%d,%d,%d};",NEWLINE(),p1,p2,p3); - add_infile(text,fich); + sprintf(text, "Circle(%d) = {%d,%d,%d};", NEWLINE(), p1, p2, p3); + add_infile(text, fich); } -void add_ell(int p1, int p2, int p3, int p4, char *fich){ +void add_ell(int p1, int p2, int p3, int p4, char *fich) +{ char text[BUFFSIZE]; - sprintf(text,"Ellipse(%d) = {%d,%d,%d,%d};",NEWLINE(),p1,p2,p3,p4); - add_infile(text,fich); + sprintf(text, "Ellipse(%d) = {%d,%d,%d,%d};", NEWLINE(), p1, p2, p3, p4); + add_infile(text, fich); } -void add_spline(int N, int *p, char *fich){ +void add_spline(int N, int *p, char *fich) +{ char text[BUFFSIZE]; char text2[BUFFSIZE]; int i; - sprintf(text,"CatmullRom(%d) = {",NEWLINE()); - for(i=0;i<N;i++){ - if(i != N-1) - sprintf(text2,"%d,",p[i]); + sprintf(text, "CatmullRom(%d) = {", NEWLINE()); + for(i = 0; i < N; i++) { + if(i != N - 1) + sprintf(text2, "%d,", p[i]); else - sprintf(text2,"%d};",p[i]); - strcat(text,text2); + sprintf(text2, "%d};", p[i]); + strcat(text, text2); } - add_infile(text,fich); + add_infile(text, fich); } -void add_bezier(int N, int *p, char *fich){ +void add_bezier(int N, int *p, char *fich) +{ char text[BUFFSIZE]; char text2[BUFFSIZE]; int i; - sprintf(text,"Bezier(%d) = {",NEWLINE()); - for(i=0;i<N;i++){ - if(i != N-1) - sprintf(text2,"%d,",p[i]); + sprintf(text, "Bezier(%d) = {", NEWLINE()); + for(i = 0; i < N; i++) { + if(i != N - 1) + sprintf(text2, "%d,", p[i]); else - sprintf(text2,"%d};",p[i]); - strcat(text,text2); + sprintf(text2, "%d};", p[i]); + strcat(text, text2); } - add_infile(text,fich); + add_infile(text, fich); } -void add_bspline(int N, int *p, char *fich){ +void add_bspline(int N, int *p, char *fich) +{ char text[BUFFSIZE]; char text2[BUFFSIZE]; int i; - sprintf(text,"BSpline(%d) = {",NEWLINE()); - for(i=0;i<N;i++){ - if(i != N-1) - sprintf(text2,"%d,",p[i]); + sprintf(text, "BSpline(%d) = {", NEWLINE()); + for(i = 0; i < N; i++) { + if(i != N - 1) + sprintf(text2, "%d,", p[i]); else - sprintf(text2,"%d};",p[i]); - strcat(text,text2); + sprintf(text2, "%d};", p[i]); + strcat(text, text2); } - add_infile(text,fich); + add_infile(text, fich); } -void add_multline(int N, int *p, char *fich){ +void add_multline(int N, int *p, char *fich) +{ char text[BUFFSIZE]; char text2[BUFFSIZE]; int i; int iseg; - List_T *list = List_Create(N,2,sizeof(int)); - for(i=0;i<N;i++) - List_Add(list,&p[i]); - if((recognize_seg(MSH_SEGM_LINE,list,&iseg))){ + List_T *list = List_Create(N, 2, sizeof(int)); + for(i = 0; i < N; i++) + List_Add(list, &p[i]); + if((recognize_seg(MSH_SEGM_LINE, list, &iseg))) { List_Delete(list); return; } List_Delete(list); - sprintf(text,"Line(%d) = {",NEWLINE()); - for(i=0;i<N;i++){ - if(i != N-1) - sprintf(text2,"%d,",p[i]); + sprintf(text, "Line(%d) = {", NEWLINE()); + for(i = 0; i < N; i++) { + if(i != N - 1) + sprintf(text2, "%d,", p[i]); else - sprintf(text2,"%d};",p[i]); - strcat(text,text2); + sprintf(text2, "%d};", p[i]); + strcat(text, text2); } - add_infile(text,fich); + add_infile(text, fich); } -void add_loop(List_T *list, char *fich, int *numloop){ +void add_loop(List_T * list, char *fich, int *numloop) +{ char text[BUFFSIZE]; char text2[BUFFSIZE]; - int i,seg; + int i, seg; - if((recognize_loop(list,numloop))) return; + if((recognize_loop(list, numloop))) + return; *numloop = NEWLINELOOP(); - sprintf(text,"Line Loop(%d) = {",*numloop); - for(i=0;i<List_Nbr(list);i++){ - List_Read(list,i,&seg); - if(i != List_Nbr(list)-1) - sprintf(text2,"%d,",seg); + sprintf(text, "Line Loop(%d) = {", *numloop); + for(i = 0; i < List_Nbr(list); i++) { + List_Read(list, i, &seg); + if(i != List_Nbr(list) - 1) + sprintf(text2, "%d,", seg); else - sprintf(text2,"%d};",seg); - strcat(text,text2); + sprintf(text2, "%d};", seg); + strcat(text, text2); } - add_infile(text,fich); + add_infile(text, fich); } -void add_surf(List_T *list, char *fich, int support, int typ){ +void add_surf(List_T * list, char *fich, int support, int typ) +{ char text[BUFFSIZE]; char text2[BUFFSIZE]; - int i,seg; + int i, seg; - if(typ ==1){ - sprintf(text,"Ruled Surface(%d) = {",NEWSURFACE()); + if(typ == 1) { + sprintf(text, "Ruled Surface(%d) = {", NEWSURFACE()); } - else if (typ == 2){ - sprintf(text,"Plane Surface(%d) = {",NEWSURFACE()); + else if(typ == 2) { + sprintf(text, "Plane Surface(%d) = {", NEWSURFACE()); } - else - { - sprintf(text,"Trimmed Surface(%d) = %d {",NEWSURFACE(),support); + else { + sprintf(text, "Trimmed Surface(%d) = %d {", NEWSURFACE(), support); } - for(i=0;i<List_Nbr(list);i++){ - List_Read(list,i,&seg); - if(i != List_Nbr(list)-1) - sprintf(text2,"%d,",seg); + for(i = 0; i < List_Nbr(list); i++) { + List_Read(list, i, &seg); + if(i != List_Nbr(list) - 1) + sprintf(text2, "%d,", seg); else - sprintf(text2,"%d};",seg); - strcat(text,text2); + sprintf(text2, "%d};", seg); + strcat(text, text2); } - add_infile(text,fich); + add_infile(text, fich); } -void add_vol(List_T *list, char *fich, int *numvol){ +void add_vol(List_T * list, char *fich, int *numvol) +{ char text[BUFFSIZE]; char text2[BUFFSIZE]; - int i,seg; + int i, seg; - if((recognize_surfloop(list,numvol))) return; + if((recognize_surfloop(list, numvol))) + return; *numvol = NEWSURFACELOOP(); - sprintf(text,"Surface Loop(%d) = {",*numvol); - for(i=0;i<List_Nbr(list);i++){ - List_Read(list,i,&seg); - if(i != List_Nbr(list)-1) - sprintf(text2,"%d,",seg); + sprintf(text, "Surface Loop(%d) = {", *numvol); + for(i = 0; i < List_Nbr(list); i++) { + List_Read(list, i, &seg); + if(i != List_Nbr(list) - 1) + sprintf(text2, "%d,", seg); else - sprintf(text2,"%d};",seg); - strcat(text,text2); + sprintf(text2, "%d};", seg); + strcat(text, text2); } - add_infile(text,fich); + add_infile(text, fich); } -void add_multvol(List_T *list, char *fich){ +void add_multvol(List_T * list, char *fich) +{ char text[BUFFSIZE]; char text2[BUFFSIZE]; - int i,seg; + int i, seg; - sprintf(text,"Volume(%d) = {",NEWVOLUME()); - for(i=0;i<List_Nbr(list);i++){ - List_Read(list,i,&seg); - if(i != List_Nbr(list)-1) - sprintf(text2,"%d,",seg); + sprintf(text, "Volume(%d) = {", NEWVOLUME()); + for(i = 0; i < List_Nbr(list); i++) { + List_Read(list, i, &seg); + if(i != List_Nbr(list) - 1) + sprintf(text2, "%d,", seg); else - sprintf(text2,"%d};",seg); - strcat(text,text2); + sprintf(text2, "%d};", seg); + strcat(text, text2); } - add_infile(text,fich); + add_infile(text, fich); } -void add_trsfvol(int N, int *l, char *fich){ +void add_trsfvol(int N, int *l, char *fich) +{ char text[BUFFSIZE], text2[BUFFSIZE]; int i; - sprintf(text,"Transfinite Volume{%s} = {", trsf_vol_text); - for(i=0;i<N;i++){ - if(i==0)sprintf(text2,"%d",l[i]); - else sprintf(text2,",%d",l[i]); - strcat(text,text2); + sprintf(text, "Transfinite Volume{%s} = {", trsf_vol_text); + for(i = 0; i < N; i++) { + if(i == 0) + sprintf(text2, "%d", l[i]); + else + sprintf(text2, ",%d", l[i]); + strcat(text, text2); } - sprintf(text2,"};"); - strcat(text,text2); - add_infile(text,fich); + sprintf(text2, "};"); + strcat(text, text2); + add_infile(text, fich); } -void add_physical(List_T *list, char *fich, int type, int *num){ +void add_physical(List_T * list, char *fich, int type, int *num) +{ char text[BUFFSIZE], text2[BUFFSIZE]; - int i, elementary_entity; + int i, elementary_entity; *num = NEWPHYSICAL(); - switch(type){ - case ENT_POINT : sprintf(text, "Physical Point(%d) = {", *num); break; - case ENT_LINE : sprintf(text, "Physical Line(%d) = {", *num); break; - case ENT_SURFACE : sprintf(text, "Physical Surface(%d) = {", *num); break; - case ENT_VOLUME : sprintf(text, "Physical Volume(%d) = {", *num); break; + switch (type) { + case ENT_POINT: + sprintf(text, "Physical Point(%d) = {", *num); + break; + case ENT_LINE: + sprintf(text, "Physical Line(%d) = {", *num); + break; + case ENT_SURFACE: + sprintf(text, "Physical Surface(%d) = {", *num); + break; + case ENT_VOLUME: + sprintf(text, "Physical Volume(%d) = {", *num); + break; } - for(i=0; i<List_Nbr(list); i++){ + for(i = 0; i < List_Nbr(list); i++) { List_Read(list, i, &elementary_entity); - if(i != List_Nbr(list)-1) + if(i != List_Nbr(list) - 1) sprintf(text2, "%d,", elementary_entity); else sprintf(text2, "%d};", elementary_entity); @@ -449,61 +496,76 @@ void add_physical(List_T *list, char *fich, int type, int *num){ add_infile(text, fich); } -void translate(int add, int s, char *fich, char *what){ +void translate(int add, int s, char *fich, char *what) +{ char text[BUFFSIZE]; if(add) - sprintf(text,"Translate {%s,%s,%s} {\n Duplicata { %s{%d}; }\n}", - tx_text,ty_text,tz_text,what,s); + sprintf(text, "Translate {%s,%s,%s} {\n Duplicata { %s{%d}; }\n}", + tx_text, ty_text, tz_text, what, s); else - sprintf(text,"Translate {%s,%s,%s} {\n %s{%d};\n}", - tx_text,ty_text,tz_text,what,s); - add_infile(text,fich); + sprintf(text, "Translate {%s,%s,%s} {\n %s{%d};\n}", + tx_text, ty_text, tz_text, what, s); + add_infile(text, fich); } -void rotate(int add, int s, char *fich, char *quoi){ + +void rotate(int add, int s, char *fich, char *quoi) +{ char text[BUFFSIZE]; if(add) - sprintf(text,"Rotate { {%s,%s,%s},{%s,%s,%s},%s } {\n Duplicata { %s{%d}; }\n}", - ax_text,ay_text,az_text,px_text,py_text,pz_text,angle_text, quoi,s); + sprintf(text, + "Rotate { {%s,%s,%s},{%s,%s,%s},%s } {\n Duplicata { %s{%d}; }\n}", + ax_text, ay_text, az_text, px_text, py_text, pz_text, angle_text, + quoi, s); else - sprintf(text,"Rotate { {%s,%s,%s},{%s,%s,%s},%s } {\n %s{%d};\n }", - ax_text,ay_text,az_text,px_text,py_text,pz_text,angle_text, quoi,s); - add_infile(text,fich); + sprintf(text, "Rotate { {%s,%s,%s},{%s,%s,%s},%s } {\n %s{%d};\n }", + ax_text, ay_text, az_text, px_text, py_text, pz_text, angle_text, + quoi, s); + add_infile(text, fich); } -void dilate(int add, int s, char *fich, char *quoi){ + +void dilate(int add, int s, char *fich, char *quoi) +{ char text[BUFFSIZE]; if(add) - sprintf(text,"Dilate { {%s,%s,%s},%s } {\n Duplicata { %s{%d}; }\n}", - dx_text,dy_text,dz_text,df_text, quoi,s); + sprintf(text, "Dilate { {%s,%s,%s},%s } {\n Duplicata { %s{%d}; }\n}", + dx_text, dy_text, dz_text, df_text, quoi, s); else - sprintf(text,"Dilate { {%s,%s,%s},%s } {\n %s{%d};\n }", - dx_text,dy_text,dz_text,df_text, quoi,s); - add_infile(text,fich); + sprintf(text, "Dilate { {%s,%s,%s},%s } {\n %s{%d};\n }", + dx_text, dy_text, dz_text, df_text, quoi, s); + add_infile(text, fich); } -void symmetry(int add, int s, char *fich, char *quoi){ + +void symmetry(int add, int s, char *fich, char *quoi) +{ char text[BUFFSIZE]; if(add) - sprintf(text,"Symmetry { %s,%s,%s,%s } {\n Duplicata { %s{%d}; }\n}", - sa_text,sb_text,sc_text,sd_text, quoi,s); + sprintf(text, "Symmetry { %s,%s,%s,%s } {\n Duplicata { %s{%d}; }\n}", + sa_text, sb_text, sc_text, sd_text, quoi, s); else - sprintf(text,"Symmetry { %s,%s,%s,%s } {\n %s{%d};\n }", - sa_text,sb_text,sc_text,sd_text, quoi,s); - add_infile(text,fich); + sprintf(text, "Symmetry { %s,%s,%s,%s } {\n %s{%d};\n }", + sa_text, sb_text, sc_text, sd_text, quoi, s); + add_infile(text, fich); } -void extrude(int s, char *fich, char *what){ + +void extrude(int s, char *fich, char *what) +{ char text[BUFFSIZE]; - sprintf(text,"Extrude %s {%d, {%s,%s,%s}};",what,s,tx_text,ty_text,tz_text); - add_infile(text,fich); + sprintf(text, "Extrude %s {%d, {%s,%s,%s}};", what, s, tx_text, ty_text, + tz_text); + add_infile(text, fich); } -void protude(int s, char *fich, char *what){ + +void protude(int s, char *fich, char *what) +{ char text[BUFFSIZE]; - sprintf(text,"Extrude %s {%d, {%s,%s,%s}, {%s,%s,%s}, %s};",what,s,ax_text,ay_text, - az_text,px_text,py_text,pz_text,angle_text); - add_infile(text,fich); + sprintf(text, "Extrude %s {%d, {%s,%s,%s}, {%s,%s,%s}, %s};", what, s, + ax_text, ay_text, az_text, px_text, py_text, pz_text, angle_text); + add_infile(text, fich); } diff --git a/Geo/MinMax.cpp b/Geo/MinMax.cpp index 692e35c11701bd1f7f5bcb646f2ce3fb278542cb..c73ef6fe40f589fa71b4121fe34b143f05b87090 100644 --- a/Geo/MinMax.cpp +++ b/Geo/MinMax.cpp @@ -1,4 +1,4 @@ -// $Id: MinMax.cpp,v 1.10 2003-01-23 20:19:20 geuzaine Exp $ +// $Id: MinMax.cpp,v 1.11 2003-03-01 22:36:38 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -24,11 +24,12 @@ #include "Vertex.h" #include "Context.h" -extern Context_T CTX ; +extern Context_T CTX; -void minmax(void *a , void*b){ +void minmax(void *a, void *b) +{ Vertex *v; - v = *(Vertex**)a; + v = *(Vertex **) a; CTX.min[0] = (CTX.min[0] < v->Pos.X) ? CTX.min[0] : v->Pos.X; CTX.max[0] = (CTX.max[0] > v->Pos.X) ? CTX.max[0] : v->Pos.X; CTX.min[1] = (CTX.min[1] < v->Pos.Y) ? CTX.min[1] : v->Pos.Y; @@ -37,85 +38,90 @@ void minmax(void *a , void*b){ CTX.max[2] = (CTX.max[2] > v->Pos.Z) ? CTX.max[2] : v->Pos.Z; } -void CalculateMinMax (Tree_T *t, double *bbox){ - Vertex *v; - double frac; - int exp; +void CalculateMinMax(Tree_T * t, double *bbox) +{ + Vertex *v; + double frac; + int exp; - if(!Tree_Nbr(t)){ - if(!bbox || (bbox[0] > bbox[1])){ //the bbox is wrong + if(!Tree_Nbr(t)) { + if(!bbox || (bbox[0] > bbox[1])) { //the bbox is wrong CTX.min[0] = CTX.min[1] = CTX.min[2] = -1.; - CTX.max[0] = CTX.max[1] = CTX.max[2] = 1.; + CTX.max[0] = CTX.max[1] = CTX.max[2] = 1.; CTX.range[0] = CTX.range[1] = CTX.range[2] = 0.; CTX.lc = CTX.lc_middle = 1.; return; } - else{ - CTX.min[0] = bbox[0] ; CTX.max[0] = bbox[1] ; - CTX.min[1] = bbox[2] ; CTX.max[1] = bbox[3] ; - CTX.min[2] = bbox[4] ; CTX.max[2] = bbox[5] ; + else { + CTX.min[0] = bbox[0]; + CTX.max[0] = bbox[1]; + CTX.min[1] = bbox[2]; + CTX.max[1] = bbox[3]; + CTX.min[2] = bbox[4]; + CTX.max[2] = bbox[5]; } } - else{ - Tree_Right(t,&v); + else { + Tree_Right(t, &v); CTX.min[0] = CTX.max[0] = v->Pos.X; CTX.min[1] = CTX.max[1] = v->Pos.Y; CTX.min[2] = CTX.max[2] = v->Pos.Z; - Tree_Action(t,minmax); + Tree_Action(t, minmax); } - CTX.range[0] = CTX.max[0]-CTX.min[0]; - CTX.range[1] = CTX.max[1]-CTX.min[1]; - CTX.range[2] = CTX.max[2]-CTX.min[2]; + CTX.range[0] = CTX.max[0] - CTX.min[0]; + CTX.range[1] = CTX.max[1] - CTX.min[1]; + CTX.range[2] = CTX.max[2] - CTX.min[2]; - if(CTX.range[0] == 0. && CTX.range[1] == 0. && CTX.range[2] == 0.){ - CTX.min[0] -= 1. ; - CTX.min[1] -= 1. ; - CTX.max[0] += 1. ; - CTX.max[1] += 1. ; + if(CTX.range[0] == 0. && CTX.range[1] == 0. && CTX.range[2] == 0.) { + CTX.min[0] -= 1.; + CTX.min[1] -= 1.; + CTX.max[0] += 1.; + CTX.max[1] += 1.; CTX.lc = 1.; CTX.lc_middle = 0.; } - else if(CTX.range[0] == 0. && CTX.range[1] == 0.){ + else if(CTX.range[0] == 0. && CTX.range[1] == 0.) { CTX.lc = CTX.lc_middle = CTX.range[2]; - CTX.min[0] -= CTX.lc; - CTX.min[1] -= CTX.lc; - CTX.max[0] += CTX.lc; + CTX.min[0] -= CTX.lc; + CTX.min[1] -= CTX.lc; + CTX.max[0] += CTX.lc; CTX.max[1] += CTX.lc; } - else if(CTX.range[0] == 0. && CTX.range[2] == 0.){ + else if(CTX.range[0] == 0. && CTX.range[2] == 0.) { CTX.lc = CTX.lc_middle = CTX.range[1]; - CTX.min[0] -= CTX.lc; - CTX.max[0] += CTX.lc; + CTX.min[0] -= CTX.lc; + CTX.max[0] += CTX.lc; } - else if(CTX.range[1] == 0. && CTX.range[2] == 0.){ + else if(CTX.range[1] == 0. && CTX.range[2] == 0.) { CTX.lc = CTX.lc_middle = CTX.range[0]; - CTX.min[1] -= CTX.lc; - CTX.max[1] += CTX.lc; + CTX.min[1] -= CTX.lc; + CTX.max[1] += CTX.lc; } - else if(CTX.range[0] == 0.){ - CTX.lc = sqrt(DSQR(CTX.range[1])+DSQR(CTX.range[2])); + else if(CTX.range[0] == 0.) { + CTX.lc = sqrt(DSQR(CTX.range[1]) + DSQR(CTX.range[2])); CTX.lc_middle = DMIN(CTX.range[1], CTX.range[2]); - CTX.min[0] -= CTX.lc; + CTX.min[0] -= CTX.lc; CTX.max[0] += CTX.lc; } - else if(CTX.range[1] == 0.){ - CTX.lc = sqrt(DSQR(CTX.range[0])+DSQR(CTX.range[2])); + else if(CTX.range[1] == 0.) { + CTX.lc = sqrt(DSQR(CTX.range[0]) + DSQR(CTX.range[2])); CTX.lc_middle = DMIN(CTX.range[0], CTX.range[2]); - CTX.min[1] -= CTX.lc; + CTX.min[1] -= CTX.lc; CTX.max[1] += CTX.lc; } - else if(CTX.range[2] == 0.){ - CTX.lc = sqrt(DSQR(CTX.range[0])+DSQR(CTX.range[1])); + else if(CTX.range[2] == 0.) { + CTX.lc = sqrt(DSQR(CTX.range[0]) + DSQR(CTX.range[1])); CTX.lc_middle = DMIN(CTX.range[0], CTX.range[1]); } - else{ - CTX.lc = sqrt(DSQR(CTX.range[0])+DSQR(CTX.range[1])+DSQR(CTX.range[2])); - if((CTX.range[1] <= CTX.range[0] && CTX.range[0] <= CTX.range[2]) || - (CTX.range[2] <= CTX.range[0] && CTX.range[0] <= CTX.range[1])) + else { + CTX.lc = + sqrt(DSQR(CTX.range[0]) + DSQR(CTX.range[1]) + DSQR(CTX.range[2])); + if((CTX.range[1] <= CTX.range[0] && CTX.range[0] <= CTX.range[2]) + || (CTX.range[2] <= CTX.range[0] && CTX.range[0] <= CTX.range[1])) CTX.lc_middle = CTX.range[0]; - else if((CTX.range[0] <= CTX.range[1] && CTX.range[1] <= CTX.range[2]) || - (CTX.range[2] <= CTX.range[1] && CTX.range[1] <= CTX.range[0])) + else if((CTX.range[0] <= CTX.range[1] && CTX.range[1] <= CTX.range[2]) || + (CTX.range[2] <= CTX.range[1] && CTX.range[1] <= CTX.range[0])) CTX.lc_middle = CTX.range[1]; else CTX.lc_middle = CTX.range[2]; @@ -123,7 +129,6 @@ void CalculateMinMax (Tree_T *t, double *bbox){ // CTX.lc_order : CTX.lc == f * 10^CTX.lc_order with -1<f<1 - frac = frexp(CTX.lc, &exp); - CTX.lc_order = (int)floor(log10(ldexp(frac,exp))); + frac = frexp(CTX.lc, &exp); + CTX.lc_order = (int)floor(log10(ldexp(frac, exp))); } - diff --git a/Geo/Print_Geo.cpp b/Geo/Print_Geo.cpp index 68b0078f74535b1369534699f8306449d4a6837e..8acf042fe62573cfac661e6ab65df5b32923a260 100644 --- a/Geo/Print_Geo.cpp +++ b/Geo/Print_Geo.cpp @@ -1,4 +1,4 @@ -// $Id: Print_Geo.cpp,v 1.28 2003-01-23 20:19:20 geuzaine Exp $ +// $Id: Print_Geo.cpp,v 1.29 2003-03-01 22:36:38 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -28,231 +28,252 @@ FILE *FOUT; -void Print_Point(void *a, void *b){ +void Print_Point(void *a, void *b) +{ Vertex *v; - v = *(Vertex**)a; + v = *(Vertex **) a; fprintf(FOUT, "Point(%d) = {%.16g, %.16g, %.16g, %.16g};\n", - v->Num,v->Pos.X,v->Pos.Y,v->Pos.Z,v->lc); + v->Num, v->Pos.X, v->Pos.Y, v->Pos.Z, v->lc); } -void Print_Nurbs (Curve *c, FILE *f){ - int i,j; +void Print_Nurbs(Curve * c, FILE * f) +{ + int i, j; Vertex *v; - fprintf(f,"Nurbs (%d) = {",c->Num); - for(i=0;i<List_Nbr(c->Control_Points);i++){ - List_Read(c->Control_Points,i,&v); + fprintf(f, "Nurbs (%d) = {", c->Num); + for(i = 0; i < List_Nbr(c->Control_Points); i++) { + List_Read(c->Control_Points, i, &v); if(!i) - fprintf(FOUT,"%d",v->Num); + fprintf(FOUT, "%d", v->Num); else - fprintf(FOUT,", %d",v->Num); - if(i%8 == 7 && i!=List_Nbr(c->Control_Points)-1)fprintf(FOUT,"\n"); + fprintf(FOUT, ", %d", v->Num); + if(i % 8 == 7 && i != List_Nbr(c->Control_Points) - 1) + fprintf(FOUT, "\n"); } - fprintf(f,"}\n"); - fprintf(f," Knots {"); - for(j=0;j<List_Nbr(c->Control_Points)+c->degre+1;j++){ - if(!j)fprintf(f,"%.16g",c->k[j]); - else fprintf(f,", %.16g",c->k[j]); - if(j%5 == 4 && j!=List_Nbr(c->Control_Points)+c->degre)fprintf(FOUT,"\n "); + fprintf(f, "}\n"); + fprintf(f, " Knots {"); + for(j = 0; j < List_Nbr(c->Control_Points) + c->degre + 1; j++) { + if(!j) + fprintf(f, "%.16g", c->k[j]); + else + fprintf(f, ", %.16g", c->k[j]); + if(j % 5 == 4 && j != List_Nbr(c->Control_Points) + c->degre) + fprintf(FOUT, "\n "); } - fprintf(f,"}\n"); - fprintf(f," Order %d;\n",c->degre); + fprintf(f, "}\n"); + fprintf(f, " Order %d;\n", c->degre); } -void Print_Curve(void *a, void *b){ +void Print_Curve(void *a, void *b) +{ Curve *c; Vertex *v; int i; - c = *(Curve**)a; + c = *(Curve **) a; - if(c->Num < 0 || c->Dirty)return; + if(c->Num < 0 || c->Dirty) + return; - switch(c->Typ){ + switch (c->Typ) { case MSH_SEGM_LINE: - fprintf(FOUT,"Line (%d) = ",c->Num); + fprintf(FOUT, "Line (%d) = ", c->Num); break; case MSH_SEGM_CIRC: case MSH_SEGM_CIRC_INV: - fprintf(FOUT,"Circle (%d) = ",c->Num); + fprintf(FOUT, "Circle (%d) = ", c->Num); break; case MSH_SEGM_ELLI: case MSH_SEGM_ELLI_INV: - fprintf(FOUT,"Ellipse (%d) = ",c->Num); + fprintf(FOUT, "Ellipse (%d) = ", c->Num); break; case MSH_SEGM_NURBS: - Print_Nurbs(c,FOUT); + Print_Nurbs(c, FOUT); return; case MSH_SEGM_SPLN: - fprintf(FOUT,"CatmullRom (%d) = ",c->Num); + fprintf(FOUT, "CatmullRom (%d) = ", c->Num); break; case MSH_SEGM_BSPLN: - fprintf(FOUT,"BSpline (%d) = ",c->Num); + fprintf(FOUT, "BSpline (%d) = ", c->Num); break; case MSH_SEGM_BEZIER: - fprintf(FOUT,"Bezier (%d) = ",c->Num); + fprintf(FOUT, "Bezier (%d) = ", c->Num); break; default: Msg(GERROR, "Unknown Curve type %d", c->Typ); return; } - - for(i=0;i<List_Nbr(c->Control_Points);i++){ - List_Read(c->Control_Points,i,&v); + + for(i = 0; i < List_Nbr(c->Control_Points); i++) { + List_Read(c->Control_Points, i, &v); if(i) - fprintf(FOUT,", %d",v->Num); + fprintf(FOUT, ", %d", v->Num); else - fprintf(FOUT,"{%d",v->Num); - if(i%6 == 7)fprintf(FOUT,"\n"); + fprintf(FOUT, "{%d", v->Num); + if(i % 6 == 7) + fprintf(FOUT, "\n"); } - switch(c->Typ){ + switch (c->Typ) { case MSH_SEGM_CIRC: case MSH_SEGM_CIRC_INV: case MSH_SEGM_ELLI: case MSH_SEGM_ELLI_INV: - fprintf(FOUT,"} Plane{%.16g, %.16g, %.16g};\n", - c->Circle.n[0],c->Circle.n[1],c->Circle.n[2]); + fprintf(FOUT, "} Plane{%.16g, %.16g, %.16g};\n", + c->Circle.n[0], c->Circle.n[1], c->Circle.n[2]); break; - default : - fprintf(FOUT,"};\n"); + default: + fprintf(FOUT, "};\n"); break; } - + } -void Print_Surface(void *a, void *b){ +void Print_Surface(void *a, void *b) +{ Curve *c; Surface *s; Vertex *v; - int i,j; - s = *(Surface**)a; + int i, j; + s = *(Surface **) a; - if(s->Dirty) return; + if(s->Dirty) + return; int NUMLOOP = s->Num + 1000000; - if(s->Typ != MSH_SURF_NURBS){ - fprintf(FOUT,"Line Loop (%d) = ",NUMLOOP); - - for(i=0;i<List_Nbr(s->Generatrices);i++){ - List_Read(s->Generatrices,i,&c); + if(s->Typ != MSH_SURF_NURBS) { + fprintf(FOUT, "Line Loop (%d) = ", NUMLOOP); + + for(i = 0; i < List_Nbr(s->Generatrices); i++) { + List_Read(s->Generatrices, i, &c); if(i) - fprintf(FOUT,", %d",c->Num); + fprintf(FOUT, ", %d", c->Num); else - fprintf(FOUT,"{%d",c->Num); + fprintf(FOUT, "{%d", c->Num); } - fprintf(FOUT,"};\n"); + fprintf(FOUT, "};\n"); } - switch(s->Typ){ + switch (s->Typ) { case MSH_SURF_REGL: case MSH_SURF_TRIC: - fprintf(FOUT,"Ruled Surface (%d) = {%d};\n",s->Num,NUMLOOP); + fprintf(FOUT, "Ruled Surface (%d) = {%d};\n", s->Num, NUMLOOP); break; case MSH_SURF_PLAN: - fprintf(FOUT,"Plane Surface (%d) = {%d};\n",s->Num,NUMLOOP); + fprintf(FOUT, "Plane Surface (%d) = {%d};\n", s->Num, NUMLOOP); break; case MSH_SURF_TRIMMED: - fprintf(FOUT,"Trimmed Surface (%d) = %d {%d};\n",s->Num,s->Support->Num,NUMLOOP); + fprintf(FOUT, "Trimmed Surface (%d) = %d {%d};\n", s->Num, + s->Support->Num, NUMLOOP); break; case MSH_SURF_NURBS: - fprintf(FOUT,"Nurbs Surface (%d) = {\n",s->Num); - for(i=0;i<s->Nv;i++){ - fprintf(FOUT," {"); - for(j=0;j<s->Nu;j++){ - List_Read(s->Control_Points,j+s->Nu *i,&v); + fprintf(FOUT, "Nurbs Surface (%d) = {\n", s->Num); + for(i = 0; i < s->Nv; i++) { + fprintf(FOUT, " {"); + for(j = 0; j < s->Nu; j++) { + List_Read(s->Control_Points, j + s->Nu * i, &v); if(!j) - fprintf(FOUT,"%d",v->Num); + fprintf(FOUT, "%d", v->Num); else - fprintf(FOUT,", %d",v->Num); + fprintf(FOUT, ", %d", v->Num); } - if(i!=s->Nv-1) - fprintf(FOUT,"},\n"); + if(i != s->Nv - 1) + fprintf(FOUT, "},\n"); else - fprintf(FOUT,"}}\n"); + fprintf(FOUT, "}}\n"); } - fprintf(FOUT," Knots\n {"); - for(j=0;j<s->Nu+s->OrderU+1;j++){ - if(!j)fprintf(FOUT,"%.16g",s->ku[j]); - else fprintf(FOUT,", %.16g",s->ku[j]); - if(j%5 == 4 && j!=s->Nu + s->OrderU)fprintf(FOUT,"\n "); + fprintf(FOUT, " Knots\n {"); + for(j = 0; j < s->Nu + s->OrderU + 1; j++) { + if(!j) + fprintf(FOUT, "%.16g", s->ku[j]); + else + fprintf(FOUT, ", %.16g", s->ku[j]); + if(j % 5 == 4 && j != s->Nu + s->OrderU) + fprintf(FOUT, "\n "); } - fprintf(FOUT,"}\n {"); - for(j=0;j<s->Nv+s->OrderV+1;j++){ - if(!j)fprintf(FOUT,"%.16g",s->kv[j]); - else fprintf(FOUT,", %.16g",s->kv[j]); - if(j%5 == 4 && j!=s->Nv + s->OrderV)fprintf(FOUT,"\n "); + fprintf(FOUT, "}\n {"); + for(j = 0; j < s->Nv + s->OrderV + 1; j++) { + if(!j) + fprintf(FOUT, "%.16g", s->kv[j]); + else + fprintf(FOUT, ", %.16g", s->kv[j]); + if(j % 5 == 4 && j != s->Nv + s->OrderV) + fprintf(FOUT, "\n "); } - fprintf(FOUT,"}\n Order %d %d;\n",s->OrderU,s->OrderV); + fprintf(FOUT, "}\n Order %d %d;\n", s->OrderU, s->OrderV); break; } } -void Print_Volume(void *a, void *b){ +void Print_Volume(void *a, void *b) +{ Surface *s; Volume *vol; int i; - vol = *(Volume**)a; + vol = *(Volume **) a; - if(vol->Dirty) return; + if(vol->Dirty) + return; int NUMLOOP = vol->Num + 1000000; - fprintf(FOUT,"Surface Loop (%d) = ",NUMLOOP); - - for(i=0;i<List_Nbr(vol->Surfaces);i++){ - List_Read(vol->Surfaces,i,&s); + fprintf(FOUT, "Surface Loop (%d) = ", NUMLOOP); + + for(i = 0; i < List_Nbr(vol->Surfaces); i++) { + List_Read(vol->Surfaces, i, &s); if(i) - fprintf(FOUT,", %d",s->Num); + fprintf(FOUT, ", %d", s->Num); else - fprintf(FOUT,"{%d",s->Num); + fprintf(FOUT, "{%d", s->Num); } - fprintf(FOUT,"};\n"); + fprintf(FOUT, "};\n"); - switch(vol->Typ){ + switch (vol->Typ) { case MSH_VOLUME: - fprintf(FOUT,"Volume (%d) = {%d};\n",vol->Num,NUMLOOP); + fprintf(FOUT, "Volume (%d) = {%d};\n", vol->Num, NUMLOOP); break; } } -void Print_PhysicalGroups(void *a, void *b){ - PhysicalGroup *pg ; +void Print_PhysicalGroups(void *a, void *b) +{ + PhysicalGroup *pg; int i, j; - pg = *(PhysicalGroup**)a; - - switch(pg->Typ){ - case MSH_PHYSICAL_POINT : - fprintf(FOUT,"Physical Point (%d) = ",pg->Num); + pg = *(PhysicalGroup **) a; + + switch (pg->Typ) { + case MSH_PHYSICAL_POINT: + fprintf(FOUT, "Physical Point (%d) = ", pg->Num); break; - case MSH_PHYSICAL_LINE : - fprintf(FOUT,"Physical Line (%d) = ",pg->Num); + case MSH_PHYSICAL_LINE: + fprintf(FOUT, "Physical Line (%d) = ", pg->Num); break; - case MSH_PHYSICAL_SURFACE : - fprintf(FOUT,"Physical Surface (%d) = ",pg->Num); + case MSH_PHYSICAL_SURFACE: + fprintf(FOUT, "Physical Surface (%d) = ", pg->Num); break; - case MSH_PHYSICAL_VOLUME : - fprintf(FOUT,"Physical Volume (%d) = ",pg->Num); + case MSH_PHYSICAL_VOLUME: + fprintf(FOUT, "Physical Volume (%d) = ", pg->Num); break; } - for(i=0;i<List_Nbr(pg->Entities);i++){ - List_Read(pg->Entities,i,&j); + for(i = 0; i < List_Nbr(pg->Entities); i++) { + List_Read(pg->Entities, i, &j); if(i) - fprintf(FOUT,", %d",j); + fprintf(FOUT, ", %d", j); else - fprintf(FOUT,"{%d",j); + fprintf(FOUT, "{%d", j); } - fprintf(FOUT,"};\n"); + fprintf(FOUT, "};\n"); } -void Print_Geo(Mesh *M, char *filename){ - - if(filename){ - FOUT = fopen(filename,"w"); - if(!FOUT){ +void Print_Geo(Mesh * M, char *filename) +{ + if(filename) { + FOUT = fopen(filename, "w"); + if(!FOUT) { Msg(GERROR, "Unable to open file '%s'", filename); return; } @@ -260,17 +281,16 @@ void Print_Geo(Mesh *M, char *filename){ else FOUT = stdout; - Tree_Action(M->Points,Print_Point); - Tree_Action(M->Curves,Print_Curve); - Tree_Action(M->Surfaces,Print_Surface); - Tree_Action(M->Volumes,Print_Volume); - List_Action(M->PhysicalGroups,Print_PhysicalGroups); + Tree_Action(M->Points, Print_Point); + Tree_Action(M->Curves, Print_Curve); + Tree_Action(M->Surfaces, Print_Surface); + Tree_Action(M->Volumes, Print_Volume); + List_Action(M->PhysicalGroups, Print_PhysicalGroups); - if(filename){ + if(filename) { Msg(INFO, "Geo output complete '%s'", filename); Msg(STATUS2, "Wrote '%s'", filename); fclose(FOUT); } } - diff --git a/Geo/StepGeomDatabase.cpp b/Geo/StepGeomDatabase.cpp index b8bb964209aa115fa1a2c053f6642c6677432d39..06941bae04d5ddb149f6ba0513f2c56cd96edf40 100644 --- a/Geo/StepGeomDatabase.cpp +++ b/Geo/StepGeomDatabase.cpp @@ -1,4 +1,4 @@ -// $Id: StepGeomDatabase.cpp,v 1.12 2003-02-25 04:02:50 geuzaine Exp $ +// $Id: StepGeomDatabase.cpp,v 1.13 2003-03-01 22:36:38 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -28,419 +28,505 @@ extern Context_T CTX; -static Step_Solid_BRep_t *BREP=NULL; +static Step_Solid_BRep_t *BREP = NULL; -Step_Solid_BRep_t *Create_Step_Solid_BRep(void){ +Step_Solid_BRep_t *Create_Step_Solid_BRep(void) +{ Step_Solid_BRep_t *NEWBREP; - NEWBREP = (Step_Solid_BRep_t *)Malloc(sizeof(Step_Solid_BRep_t)); - NEWBREP->AllDirections = List_Create(10,10,sizeof(Step_Direction_t)); - NEWBREP->AllVectors = List_Create(10,10,sizeof(Step_Vector_t)); - NEWBREP->AllCartesian_Points = List_Create(10,10,sizeof(Step_Cartesian_Point_t)); - NEWBREP->AllVertex_Points = List_Create(10,10,sizeof(Step_Vertex_Point_t)); - NEWBREP->AllCurves = List_Create(10,10,sizeof(Step_Curve_t)); - NEWBREP->AllSurfaces = List_Create(10,10,sizeof(Step_Surface_t)); - NEWBREP->AllClosed_Shells = List_Create(10,10,sizeof(Step_Closed_Shell_t)); - NEWBREP->AllFaces_Outer_Bound = List_Create(10,10,sizeof(Step_Face_Outer_Bound_t)); - NEWBREP->AllOriented_Edges = List_Create(10,10,sizeof(Step_Oriented_Edge_t)); - NEWBREP->AllEdge_Loops = List_Create(10,10,sizeof(Step_Edge_Loop_t)); - NEWBREP->AllEdge_Curves = List_Create(10,10,sizeof(Step_Edge_Curve_t)); - NEWBREP->AllAdvanced_Faces = List_Create(10,10,sizeof(Step_Advanced_Face_t)); - NEWBREP->AllAxis2_Placement3D = List_Create(10,10,sizeof(Step_Axis2_Placement3D_t)); - NEWBREP->AllClosed_Shells = List_Create(10,10,sizeof(Step_Closed_Shell_t)); + NEWBREP = (Step_Solid_BRep_t *) Malloc(sizeof(Step_Solid_BRep_t)); + NEWBREP->AllDirections = List_Create(10, 10, sizeof(Step_Direction_t)); + NEWBREP->AllVectors = List_Create(10, 10, sizeof(Step_Vector_t)); + NEWBREP->AllCartesian_Points = List_Create(10, 10, sizeof(Step_Cartesian_Point_t)); + NEWBREP->AllVertex_Points = List_Create(10, 10, sizeof(Step_Vertex_Point_t)); + NEWBREP->AllCurves = List_Create(10, 10, sizeof(Step_Curve_t)); + NEWBREP->AllSurfaces = List_Create(10, 10, sizeof(Step_Surface_t)); + NEWBREP->AllClosed_Shells = List_Create(10, 10, sizeof(Step_Closed_Shell_t)); + NEWBREP->AllFaces_Outer_Bound = List_Create(10, 10, sizeof(Step_Face_Outer_Bound_t)); + NEWBREP->AllOriented_Edges = List_Create(10, 10, sizeof(Step_Oriented_Edge_t)); + NEWBREP->AllEdge_Loops = List_Create(10, 10, sizeof(Step_Edge_Loop_t)); + NEWBREP->AllEdge_Curves = List_Create(10, 10, sizeof(Step_Edge_Curve_t)); + NEWBREP->AllAdvanced_Faces = List_Create(10, 10, sizeof(Step_Advanced_Face_t)); + NEWBREP->AllAxis2_Placement3D = List_Create(10, 10, sizeof(Step_Axis2_Placement3D_t)); + NEWBREP->AllClosed_Shells = List_Create(10, 10, sizeof(Step_Closed_Shell_t)); BREP = NEWBREP; return NEWBREP; } // Directions -void Add_Direction (int Num , char *name , double x, double y, double z ){ +void Add_Direction(int Num, char *name, double x, double y, double z) +{ Step_Direction_t Dir; - if(!BREP)return; + if(!BREP) + return; Dir.Pos.X = x; Dir.Pos.Y = y; Dir.Pos.Z = z; Dir.Num = Num; - List_Add(BREP->AllDirections,&Dir); + List_Add(BREP->AllDirections, &Dir); } -static int comparedir (const void *a, const void *b){ - return (((Step_Direction_t *)a)->Num - - ((Step_Direction_t *)b)->Num); +static int comparedir(const void *a, const void *b) +{ + return (((Step_Direction_t *) a)->Num - ((Step_Direction_t *) b)->Num); } -Step_Direction_t *Get_Direction (int Num){ +Step_Direction_t *Get_Direction(int Num) +{ Step_Direction_t Dir; - if(!BREP)return NULL; + if(!BREP) + return NULL; Dir.Num = Num; - return (Step_Direction_t*)List_PQuery ( BREP->AllDirections,&Dir, comparedir ); + return (Step_Direction_t *) List_PQuery(BREP->AllDirections, &Dir, + comparedir); } // Axis2_Placement3D -void Add_Axis2_Placement3D (int Num, int dir1, int dir2, int ver){ +void Add_Axis2_Placement3D(int Num, int dir1, int dir2, int ver) +{ Step_Axis2_Placement3D_t Axe; - if(!BREP)return; + if(!BREP) + return; Axe.Num = Num; Axe.Step_Cartesian_Point = ver; Axe.Step_Direction1 = dir1; Axe.Step_Direction2 = dir2; - List_Add(BREP->AllAxis2_Placement3D,&Axe); + List_Add(BREP->AllAxis2_Placement3D, &Axe); } -static int compareax (const void *a, const void *b){ - return (((Step_Axis2_Placement3D_t *)a)->Num - - ((Step_Axis2_Placement3D_t *)b)->Num); +static int compareax(const void *a, const void *b) +{ + return (((Step_Axis2_Placement3D_t *) a)->Num - + ((Step_Axis2_Placement3D_t *) b)->Num); } -Step_Axis2_Placement3D_t *Get_Axis2_Placement3D (int Num){ +Step_Axis2_Placement3D_t *Get_Axis2_Placement3D(int Num) +{ Step_Axis2_Placement3D_t Axe; - if(!BREP)return NULL; + if(!BREP) + return NULL; Axe.Num = Num; - return (Step_Axis2_Placement3D_t*)List_PQuery ( BREP->AllAxis2_Placement3D, - &Axe, compareax ); + return (Step_Axis2_Placement3D_t *) List_PQuery(BREP->AllAxis2_Placement3D, + &Axe, compareax); } // Vectors -void Add_Vector (int Num , char *name , int Dir, double l ){ +void Add_Vector(int Num, char *name, int Dir, double l) +{ Step_Vector_t Vec; - if(!BREP)return; + if(!BREP) + return; Vec.Lenght = l; Vec.Step_Direction = Dir; Vec.Num = Num; - List_Add(BREP->AllVectors,&Vec); + List_Add(BREP->AllVectors, &Vec); } -static int comparevec (const void *a, const void *b){ - return (((Step_Vector_t *)a)->Num - - ((Step_Vector_t *)b)->Num); +static int comparevec(const void *a, const void *b) +{ + return (((Step_Vector_t *) a)->Num - ((Step_Vector_t *) b)->Num); } -Step_Vector_t *Get_Vector (int Num){ +Step_Vector_t *Get_Vector(int Num) +{ Step_Vector_t Vec; - if(!BREP)return NULL; + if(!BREP) + return NULL; Vec.Num = Num; - return (Step_Vector_t*)List_PQuery ( BREP->AllVectors,&Vec, comparevec ); + return (Step_Vector_t *) List_PQuery(BREP->AllVectors, &Vec, comparevec); } // Cartesian_Points -void Add_Cartesian_Point (int Num , char *name , double x, double y, double z){ +void Add_Cartesian_Point(int Num, char *name, double x, double y, double z) +{ Step_Cartesian_Point_t CP; - if(!BREP){ + if(!BREP) { return; } CP.Pos.X = x; CP.Pos.Y = y; CP.Pos.Z = z; CP.Num = Num; - - List_Add(BREP->AllCartesian_Points,&CP); + + List_Add(BREP->AllCartesian_Points, &CP); } -static int comparecp (const void *a, const void *b){ - return (((Step_Cartesian_Point_t *)a)->Num - - ((Step_Cartesian_Point_t *)b)->Num); +static int comparecp(const void *a, const void *b) +{ + return (((Step_Cartesian_Point_t *) a)->Num - + ((Step_Cartesian_Point_t *) b)->Num); } -Step_Cartesian_Point_t *Get_Cartesian_Point (int Num){ + +Step_Cartesian_Point_t *Get_Cartesian_Point(int Num) +{ Step_Cartesian_Point_t CP; - if(!BREP)return NULL; + if(!BREP) + return NULL; CP.Num = Num; - return (Step_Cartesian_Point_t*)List_PQuery ( BREP->AllCartesian_Points,&CP, comparecp ); + return (Step_Cartesian_Point_t *) List_PQuery(BREP->AllCartesian_Points, + &CP, comparecp); } // Vertex_Points -void Add_Vertex_Point (int Num , char *name, int cp){ +void Add_Vertex_Point(int Num, char *name, int cp) +{ Step_Vertex_Point_t VP; - if(!BREP)return; + if(!BREP) + return; VP.Cartesian_Point = cp; VP.Num = Num; - List_Add(BREP->AllVertex_Points,&VP); + List_Add(BREP->AllVertex_Points, &VP); } -static int comparevp (const void *a, const void *b){ - return (((Step_Vertex_Point_t *)a)->Num - - ((Step_Vertex_Point_t *)b)->Num); +static int comparevp(const void *a, const void *b) +{ + return (((Step_Vertex_Point_t *) a)->Num - + ((Step_Vertex_Point_t *) b)->Num); } -Step_Vertex_Point_t *Get_Vertex_Point (int Num){ + +Step_Vertex_Point_t *Get_Vertex_Point(int Num) +{ Step_Vertex_Point_t VP; - if(!BREP)return NULL; + if(!BREP) + return NULL; VP.Num = Num; - return (Step_Vertex_Point_t*)List_PQuery ( BREP->AllVertex_Points,&VP, comparevp ); + return (Step_Vertex_Point_t *) List_PQuery(BREP->AllVertex_Points, &VP, + comparevp); } // Curves -void Add_Line (int Num, char *name , int begin, int dir){ +void Add_Line(int Num, char *name, int begin, int dir) +{ Step_Curve_t Curve; - if(!BREP)return; + if(!BREP) + return; Curve.Num = Num; Curve.Typ = STEP_LINE; Curve.Curve.Line.Step_Cartesian_Point = begin; Curve.Curve.Line.Step_Vector = dir; - List_Add(BREP->AllCurves,&Curve); + List_Add(BREP->AllCurves, &Curve); } -void Add_Circle (int Num, char *name , int axis, double radius){ +void Add_Circle(int Num, char *name, int axis, double radius) +{ Step_Curve_t Curve; - if(!BREP)return; + if(!BREP) + return; Curve.Num = Num; Curve.Typ = STEP_CIRC; Curve.Curve.Circle.Radius1 = radius; Curve.Curve.Circle.Radius2 = radius; Curve.Curve.Circle.Step_Axis2_Placement3D = axis; - List_Add(BREP->AllCurves,&Curve); + List_Add(BREP->AllCurves, &Curve); } -void Add_Ellipse (int Num, char *name , int axis, double radius1, double radius2){ +void Add_Ellipse(int Num, char *name, int axis, double radius1, + double radius2) +{ Step_Curve_t Curve; - if(!BREP)return; + if(!BREP) + return; Curve.Num = Num; Curve.Typ = STEP_ELLP; Curve.Curve.Circle.Radius1 = radius1; Curve.Curve.Circle.Radius2 = radius2; Curve.Curve.Circle.Step_Axis2_Placement3D = axis; - List_Add(BREP->AllCurves,&Curve); + List_Add(BREP->AllCurves, &Curve); } -void Add_BSpline_Curve_With_Knots (int Num, char *name, int Order, List_T *lcp, - List_T *multk, List_T *knots, double udeb, double uend){ +void Add_BSpline_Curve_With_Knots(int Num, char *name, int Order, + List_T * lcp, List_T * multk, + List_T * knots, double udeb, double uend) +{ Step_Curve_t Curve; - int i,j,mult; + int i, j, mult; double d; - if(!BREP)return; + if(!BREP) + return; Curve.Num = Num; Curve.Typ = STEP_BSPL; - Curve.Curve.BSpline.ListOf_Knots = List_Create (List_Nbr(lcp) + Order + 1 - ,1,sizeof(double)); + Curve.Curve.BSpline.ListOf_Knots = + List_Create(List_Nbr(lcp) + Order + 1, 1, sizeof(double)); // Adding knots with their multiplicity - for(i=0;i<List_Nbr(multk);i++){ - List_Read(multk,i,&d); + for(i = 0; i < List_Nbr(multk); i++) { + List_Read(multk, i, &d); mult = (int)d; - List_Read(knots,i,&d); - for(j=0;j<mult;j++){ - List_Add(Curve.Curve.BSpline.ListOf_Knots,&d); + List_Read(knots, i, &d); + for(j = 0; j < mult; j++) { + List_Add(Curve.Curve.BSpline.ListOf_Knots, &d); } } - Curve.Curve.BSpline.ListOf_Cartesian_Points = List_Create(List_Nbr(lcp),1,sizeof(int)); - for(i=0;i<List_Nbr(lcp);i++){ - List_Read(lcp,i,&d); + Curve.Curve.BSpline.ListOf_Cartesian_Points = + List_Create(List_Nbr(lcp), 1, sizeof(int)); + for(i = 0; i < List_Nbr(lcp); i++) { + List_Read(lcp, i, &d); j = (int)d; - List_Add(Curve.Curve.BSpline.ListOf_Cartesian_Points,&j); + List_Add(Curve.Curve.BSpline.ListOf_Cartesian_Points, &j); } Curve.Curve.BSpline.Order = Order; Curve.Curve.BSpline.Ubeg = udeb; Curve.Curve.BSpline.Uend = uend; - List_Add(BREP->AllCurves,&Curve); + List_Add(BREP->AllCurves, &Curve); } -static int comparecur (const void *a, const void *b){ - return (((Step_Curve_t *)a)->Num - - ((Step_Curve_t *)b)->Num); +static int comparecur(const void *a, const void *b) +{ + return (((Step_Curve_t *) a)->Num - ((Step_Curve_t *) b)->Num); } -Step_Curve_t *Get_Curve (int Num){ + +Step_Curve_t *Get_Curve(int Num) +{ Step_Curve_t C; - if(!BREP)return NULL; + if(!BREP) + return NULL; C.Num = Num; - return (Step_Curve_t*)List_PQuery ( BREP->AllCurves,&C, comparecur ); + return (Step_Curve_t *) List_PQuery(BREP->AllCurves, &C, comparecur); } // Edge_Curves -void Add_Edge_Curve (int Num, char *name , int beg, int end, int curve ){ +void Add_Edge_Curve(int Num, char *name, int beg, int end, int curve) +{ Step_Edge_Curve_t EC; - if(!BREP)return; + if(!BREP) + return; EC.Num = Num; EC.Step_Vertex_Point_Begin = beg; - EC.Step_Vertex_Point_End = end; + EC.Step_Vertex_Point_End = end; EC.Step_Curve = curve; - List_Add(BREP->AllEdge_Curves,&EC); + List_Add(BREP->AllEdge_Curves, &EC); } -static int compareec (const void *a, const void *b){ - return (((Step_Edge_Curve_t *)a)->Num - - ((Step_Edge_Curve_t *)b)->Num); +static int compareec(const void *a, const void *b) +{ + return (((Step_Edge_Curve_t *) a)->Num - ((Step_Edge_Curve_t *) b)->Num); } -Step_Edge_Curve_t *Get_Edge_Curve (int Num){ + +Step_Edge_Curve_t *Get_Edge_Curve(int Num) +{ Step_Edge_Curve_t EC; - if(!BREP)return NULL; + if(!BREP) + return NULL; EC.Num = Num; - return (Step_Edge_Curve_t*)List_PQuery ( BREP->AllEdge_Curves,&EC, compareec ); + return (Step_Edge_Curve_t *) List_PQuery(BREP->AllEdge_Curves, &EC, + compareec); } // Oriented_Edges -void Add_Oriented_Edge (int Num, char *name , int ec, bool dir ){ +void Add_Oriented_Edge(int Num, char *name, int ec, bool dir) +{ Step_Oriented_Edge_t OE; - if(!BREP)return; + if(!BREP) + return; OE.Num = Num; OE.Step_Edge_Curve = ec; OE.dir = dir; - List_Add(BREP->AllOriented_Edges,&OE); + List_Add(BREP->AllOriented_Edges, &OE); } -static int compareoe (const void *a, const void *b){ - return (((Step_Oriented_Edge_t *)a)->Num - - ((Step_Oriented_Edge_t *)b)->Num); +static int compareoe(const void *a, const void *b) +{ + return (((Step_Oriented_Edge_t *) a)->Num - + ((Step_Oriented_Edge_t *) b)->Num); } -Step_Oriented_Edge_t *Get_Oriented_Edge (int Num){ + +Step_Oriented_Edge_t *Get_Oriented_Edge(int Num) +{ Step_Oriented_Edge_t OE; - if(!BREP)return NULL; + if(!BREP) + return NULL; OE.Num = Num; - return (Step_Oriented_Edge_t*)List_PQuery ( BREP->AllOriented_Edges,&OE, compareoe ); + return (Step_Oriented_Edge_t *) List_PQuery(BREP->AllOriented_Edges, &OE, + compareoe); } // Edge_Loops -void Add_Edge_Loop (int Num, char *name , List_T *list ){ +void Add_Edge_Loop(int Num, char *name, List_T * list) +{ Step_Edge_Loop_t EL; - if(!BREP)return; + if(!BREP) + return; EL.Num = Num; EL.ListOf_Step_Oriented_Edge = list; - List_Add(BREP->AllEdge_Loops,&EL); + List_Add(BREP->AllEdge_Loops, &EL); } -static int compareel (const void *a, const void *b){ - return (((Step_Edge_Loop_t *)a)->Num - - ((Step_Edge_Loop_t *)b)->Num); +static int compareel(const void *a, const void *b) +{ + return (((Step_Edge_Loop_t *) a)->Num - ((Step_Edge_Loop_t *) b)->Num); } -Step_Edge_Loop_t *Get_Edge_Loop (int Num){ + +Step_Edge_Loop_t *Get_Edge_Loop(int Num) +{ Step_Edge_Loop_t EL; - if(!BREP)return NULL; + if(!BREP) + return NULL; EL.Num = Num; - return (Step_Edge_Loop_t*)List_PQuery ( BREP->AllEdge_Loops,&EL, compareel ); + return (Step_Edge_Loop_t *) List_PQuery(BREP->AllEdge_Loops, &EL, + compareel); } // Faces_Outer_Bounds -void Add_Face_Outer_Bound (int Num, char *name , int el, bool dir, bool outer ){ +void Add_Face_Outer_Bound(int Num, char *name, int el, bool dir, bool outer) +{ Step_Face_Outer_Bound_t F; - if(!BREP)return; + if(!BREP) + return; F.Num = Num; F.Step_Edge_Loop = el; F.dir = dir; F.outer = outer; - List_Add(BREP->AllFaces_Outer_Bound,&F); + List_Add(BREP->AllFaces_Outer_Bound, &F); } -static int comparefab (const void *a, const void *b){ - return (((Step_Face_Outer_Bound_t *)a)->Num - - ((Step_Face_Outer_Bound_t *)b)->Num); +static int comparefab(const void *a, const void *b) +{ + return (((Step_Face_Outer_Bound_t *) a)->Num - + ((Step_Face_Outer_Bound_t *) b)->Num); } -Step_Face_Outer_Bound_t *Get_Face_Outer_Bound (int Num){ + +Step_Face_Outer_Bound_t *Get_Face_Outer_Bound(int Num) +{ Step_Face_Outer_Bound_t F; - if(!BREP)return NULL; + if(!BREP) + return NULL; F.Num = Num; - return (Step_Face_Outer_Bound_t*)List_PQuery ( BREP->AllFaces_Outer_Bound,&F, comparefab ); + return (Step_Face_Outer_Bound_t *) List_PQuery(BREP->AllFaces_Outer_Bound, + &F, comparefab); } // Advanced_Faces -void Add_Advanced_Face (int Num, char *name , List_T *el, int surf, bool dir ){ +void Add_Advanced_Face(int Num, char *name, List_T * el, int surf, bool dir) +{ Step_Advanced_Face_t F; - if(!BREP)return; + if(!BREP) + return; F.Num = Num; F.ListOf_Step_Face_Outer_Bound = el; F.Step_Surface = surf; F.dir = dir; - List_Add(BREP->AllAdvanced_Faces,&F); + List_Add(BREP->AllAdvanced_Faces, &F); } -static int compareaf (const void *a, const void *b){ - return (((Step_Advanced_Face_t *)a)->Num - - ((Step_Advanced_Face_t *)b)->Num); +static int compareaf(const void *a, const void *b) +{ + return (((Step_Advanced_Face_t *) a)->Num - + ((Step_Advanced_Face_t *) b)->Num); } -Step_Advanced_Face_t *Get_Advanced_Face (int Num){ + +Step_Advanced_Face_t *Get_Advanced_Face(int Num) +{ Step_Advanced_Face_t F; - if(!BREP)return NULL; + if(!BREP) + return NULL; F.Num = Num; - return (Step_Advanced_Face_t*)List_PQuery ( BREP->AllAdvanced_Faces,&F, compareaf ); + return (Step_Advanced_Face_t *) List_PQuery(BREP->AllAdvanced_Faces, &F, + compareaf); } // Surfaces -void Add_Plane (int Num, char *name , int axis){ +void Add_Plane(int Num, char *name, int axis) +{ Step_Surface_t Surface; - if(!BREP)return; + if(!BREP) + return; Surface.Num = Num; Surface.Typ = STEP_PLAN; Surface.Surface.Plane.Step_Axis2_Placement3D = axis; - List_Add(BREP->AllSurfaces,&Surface); + List_Add(BREP->AllSurfaces, &Surface); } -void Add_Cylinder (int Num, char *name , int axis, double radius){ +void Add_Cylinder(int Num, char *name, int axis, double radius) +{ Step_Surface_t S; - if(!BREP)return; + if(!BREP) + return; S.Num = Num; S.Typ = STEP_CYLD; S.Surface.Quadric.Radius1 = radius; S.Surface.Quadric.Radius2 = 0.0; S.Surface.Quadric.Step_Axis2_Placement3D = axis; - List_Add(BREP->AllSurfaces,&S); + List_Add(BREP->AllSurfaces, &S); } -void Add_Torus (int Num, char *name , int axis, double radius1, double radius2){ +void Add_Torus(int Num, char *name, int axis, double radius1, double radius2) +{ Step_Surface_t S; - if(!BREP)return; + if(!BREP) + return; S.Num = Num; S.Typ = STEP_TORD; S.Surface.Quadric.Radius1 = radius1; S.Surface.Quadric.Radius2 = radius2; S.Surface.Quadric.Step_Axis2_Placement3D = axis; - List_Add(BREP->AllSurfaces,&S); + List_Add(BREP->AllSurfaces, &S); } -void Add_Cone (int Num, char *name , int axis, double radius1, double radius2){ +void Add_Cone(int Num, char *name, int axis, double radius1, double radius2) +{ Step_Surface_t S; - if(!BREP)return; + if(!BREP) + return; S.Num = Num; S.Typ = STEP_CONE; S.Surface.Quadric.Radius1 = radius1; S.Surface.Quadric.Radius2 = radius2; S.Surface.Quadric.Step_Axis2_Placement3D = axis; - List_Add(BREP->AllSurfaces,&S); + List_Add(BREP->AllSurfaces, &S); } -void Add_BSpline_Surface_With_Knots (int Num,char *name, int OrderU,int OrderV, - List_T *lcp,List_T *lmu, List_T *lmv, List_T *lku, - List_T *lkv, double udeb, double uend, double vdeb, - double vend){ +void Add_BSpline_Surface_With_Knots(int Num, char *name, int OrderU, + int OrderV, List_T * lcp, List_T * lmu, + List_T * lmv, List_T * lku, List_T * lkv, + double udeb, double uend, double vdeb, + double vend) +{ Step_Surface_t Surface; - int i,j,mult; + int i, j, mult; double d; - if(!BREP)return; + if(!BREP) + return; - Surface.Surface.BSpline.ListOf_KnotsU = - List_Create (List_Nbr(lku) + OrderU + 1,1,sizeof(double)); + Surface.Surface.BSpline.ListOf_KnotsU = + List_Create(List_Nbr(lku) + OrderU + 1, 1, sizeof(double)); Surface.Surface.BSpline.ListOf_KnotsV = - List_Create (List_Nbr(lkv) + OrderV + 1,1,sizeof(double)); + List_Create(List_Nbr(lkv) + OrderV + 1, 1, sizeof(double)); // Adding knots with their multiplicity - for(i=0;i<List_Nbr(lmu);i++){ - List_Read(lmu,i,&d); + for(i = 0; i < List_Nbr(lmu); i++) { + List_Read(lmu, i, &d); mult = (int)d; - List_Read(lku,i,&d); - for(j=0;j<mult;j++){ - List_Add(Surface.Surface.BSpline.ListOf_KnotsU,&d); + List_Read(lku, i, &d); + for(j = 0; j < mult; j++) { + List_Add(Surface.Surface.BSpline.ListOf_KnotsU, &d); } } - for(i=0;i<List_Nbr(lmv);i++){ - List_Read(lmv,i,&d); + for(i = 0; i < List_Nbr(lmv); i++) { + List_Read(lmv, i, &d); mult = (int)d; - List_Read(lkv,i,&d); - for(j=0;j<mult;j++){ - List_Add(Surface.Surface.BSpline.ListOf_KnotsV,&d); + List_Read(lkv, i, &d); + for(j = 0; j < mult; j++) { + List_Add(Surface.Surface.BSpline.ListOf_KnotsV, &d); } } // Adding the points ! Surface.Surface.BSpline.ListOf_Cartesian_Points = lcp; - + Surface.Num = Num; Surface.Typ = STEP_BSPL; Surface.Surface.BSpline.OrderU = OrderU; @@ -449,70 +535,82 @@ void Add_BSpline_Surface_With_Knots (int Num,char *name, int OrderU,int OrderV, Surface.Surface.BSpline.Uend = uend; Surface.Surface.BSpline.Vbeg = vdeb; Surface.Surface.BSpline.Vend = vend; - List_Add(BREP->AllSurfaces,&Surface); + List_Add(BREP->AllSurfaces, &Surface); } -static int comparesur (const void *a, const void *b){ - return (((Step_Surface_t *)a)->Num - - ((Step_Surface_t *)b)->Num); +static int comparesur(const void *a, const void *b) +{ + return (((Step_Surface_t *) a)->Num - ((Step_Surface_t *) b)->Num); } -Step_Surface_t *Get_Surface (int Num){ + +Step_Surface_t *Get_Surface(int Num) +{ Step_Surface_t S; - if(!BREP)return NULL; + if(!BREP) + return NULL; S.Num = Num; - return (Step_Surface_t*)List_PQuery ( BREP->AllSurfaces,&S, comparesur ); + return (Step_Surface_t *) List_PQuery(BREP->AllSurfaces, &S, comparesur); } // Closed_Shells -void Add_Closed_Shell (int Num, char *name , List_T *list ){ +void Add_Closed_Shell(int Num, char *name, List_T * list) +{ Step_Closed_Shell_t S; - if(!BREP)return; + if(!BREP) + return; S.Num = Num; S.ListOf_Step_Advanced_Face = list; - List_Add(BREP->AllClosed_Shells,&S); + List_Add(BREP->AllClosed_Shells, &S); } -static int comparecs (const void *a, const void *b){ - return (((Step_Closed_Shell_t *)a)->Num - - ((Step_Closed_Shell_t *)b)->Num); +static int comparecs(const void *a, const void *b) +{ + return (((Step_Closed_Shell_t *) a)->Num - + ((Step_Closed_Shell_t *) b)->Num); } -Step_Closed_Shell_t *Get_Closed_Shell (int Num){ + +Step_Closed_Shell_t *Get_Closed_Shell(int Num) +{ Step_Closed_Shell_t F; - if(!BREP)return NULL; + if(!BREP) + return NULL; F.Num = Num; - return (Step_Closed_Shell_t*)List_PQuery ( BREP->AllClosed_Shells,&F, comparecs ); + return (Step_Closed_Shell_t *) List_PQuery(BREP->AllClosed_Shells, &F, + comparecs); } // Closed_Shells -void Resolve_BREP (void){ - int i,j,k,l; +void Resolve_BREP(void) +{ + int i, j, k, l; double d; - int obj,err; - Step_Vertex_Point_t vp; - Step_Direction_t *d1,*d2; - Step_Cartesian_Point_t *pcp,cp; - Step_Edge_Curve_t ec; - Step_Curve_t *pc; - Step_Advanced_Face_t af, *paf; - Step_Surface_t s; - Step_Surface_t *ps; - Step_Face_Outer_Bound_t *pfab; - Step_Edge_Loop_t *pel; - Step_Oriented_Edge_t *poe; + int obj, err; + Step_Vertex_Point_t vp; + Step_Direction_t *d1, *d2; + Step_Cartesian_Point_t *pcp, cp; + Step_Edge_Curve_t ec; + Step_Curve_t *pc; + Step_Advanced_Face_t af, *paf; + Step_Surface_t s; + Step_Surface_t *ps; + Step_Face_Outer_Bound_t *pfab; + Step_Edge_Loop_t *pel; + Step_Oriented_Edge_t *poe; Step_Axis2_Placement3D_t *axs; - Step_Closed_Shell_t cs; - List_T *ListInt,*ListIntBis; - double ubeg,uend,n[3],t[3],p[3],XMIN=0.,XMAX=0.,YMIN=0.,YMAX=0.,ZMIN=0.,ZMAX=0.,L; + Step_Closed_Shell_t cs; + List_T *ListInt, *ListIntBis; + double ubeg, uend, n[3], t[3], p[3], XMIN = 0., XMAX = 0., YMIN = 0., YMAX = + 0., ZMIN = 0., ZMAX = 0., L; int fob; - ListInt = List_Create(2,2,sizeof(int)); - ListIntBis = List_Create(2,2,sizeof(int)); + ListInt = List_Create(2, 2, sizeof(int)); + ListIntBis = List_Create(2, 2, sizeof(int)); - for(i=0;i<List_Nbr(BREP->AllCartesian_Points);i++){ - List_Read(BREP->AllCartesian_Points,i,&cp); - if(!i){ + for(i = 0; i < List_Nbr(BREP->AllCartesian_Points); i++) { + List_Read(BREP->AllCartesian_Points, i, &cp); + if(!i) { XMAX = cp.Pos.X; YMAX = cp.Pos.Y; ZMAX = cp.Pos.Z; @@ -520,138 +618,146 @@ void Resolve_BREP (void){ YMIN = cp.Pos.Y; ZMIN = cp.Pos.Z; } - else{ - XMAX = MAX(cp.Pos.X,XMAX); - YMAX = MAX(cp.Pos.Y,YMAX); - ZMAX = MAX(cp.Pos.Z,ZMAX); - XMIN = MIN(cp.Pos.X,XMIN); - YMIN = MIN(cp.Pos.Y,YMIN); - ZMIN = MIN(cp.Pos.Z,ZMIN); + else { + XMAX = MAX(cp.Pos.X, XMAX); + YMAX = MAX(cp.Pos.Y, YMAX); + ZMAX = MAX(cp.Pos.Z, ZMAX); + XMIN = MIN(cp.Pos.X, XMIN); + YMIN = MIN(cp.Pos.Y, YMIN); + ZMIN = MIN(cp.Pos.Z, ZMIN); } } - CTX.lc = L = sqrt(SQR(XMIN-XMAX) + SQR(YMIN-YMAX) + SQR(ZMIN-ZMAX)); + CTX.lc = L = sqrt(SQR(XMIN - XMAX) + SQR(YMIN - YMAX) + SQR(ZMIN - ZMAX)); // resolving cartesian_points - for(i=0;i<List_Nbr(BREP->AllCartesian_Points);i++){ - List_Read(BREP->AllCartesian_Points,i,&cp); - Cdbpts101(cp.Num,cp.Pos.X,cp.Pos.Y,cp.Pos.Z,L*.01,1); + for(i = 0; i < List_Nbr(BREP->AllCartesian_Points); i++) { + List_Read(BREP->AllCartesian_Points, i, &cp); + Cdbpts101(cp.Num, cp.Pos.X, cp.Pos.Y, cp.Pos.Z, L * .01, 1); } // resolving vertex_points - for(i=0;i<List_Nbr(BREP->AllVertex_Points);i++){ - List_Read(BREP->AllVertex_Points,i,&vp); - if((pcp = Get_Cartesian_Point(vp.Cartesian_Point))){ - Cdbpts101(vp.Num,pcp->Pos.X,pcp->Pos.Y,pcp->Pos.Z,L*.01,1); + for(i = 0; i < List_Nbr(BREP->AllVertex_Points); i++) { + List_Read(BREP->AllVertex_Points, i, &vp); + if((pcp = Get_Cartesian_Point(vp.Cartesian_Point))) { + Cdbpts101(vp.Num, pcp->Pos.X, pcp->Pos.Y, pcp->Pos.Z, L * .01, 1); } } // resolving Edge_Curves - for(i=0;i<List_Nbr(BREP->AllEdge_Curves);i++){ - List_Read(BREP->AllEdge_Curves,i,&ec); - if((pc = Get_Curve(ec.Step_Curve))){ - if(pc->Typ == STEP_LINE){ - List_Add(ListInt,&ec.Step_Vertex_Point_Begin); - List_Add(ListInt,&ec.Step_Vertex_Point_End); - Cdbseg101(ec.Num,MSH_SEGM_LINE,1,NULL,ListInt,-1,-1,0.,1.,NULL,NULL,NULL); + for(i = 0; i < List_Nbr(BREP->AllEdge_Curves); i++) { + List_Read(BREP->AllEdge_Curves, i, &ec); + if((pc = Get_Curve(ec.Step_Curve))) { + if(pc->Typ == STEP_LINE) { + List_Add(ListInt, &ec.Step_Vertex_Point_Begin); + List_Add(ListInt, &ec.Step_Vertex_Point_End); + Cdbseg101(ec.Num, MSH_SEGM_LINE, 1, NULL, ListInt, -1, -1, 0., 1., + NULL, NULL, NULL); List_Reset(ListInt); } - else if(pc->Typ == STEP_BSPL){ - List_Read( pc->Curve.BSpline.ListOf_Knots , 0, &ubeg); - List_Read( pc->Curve.BSpline.ListOf_Knots , - List_Nbr(pc->Curve.BSpline.ListOf_Knots)-1, &uend); - AddCurveInDataBase (ec.Num, - MSH_SEGM_NURBS, - pc->Curve.BSpline.Order, - pc->Curve.BSpline.ListOf_Cartesian_Points, - pc->Curve.BSpline.ListOf_Knots, - ec.Step_Vertex_Point_Begin, - ec.Step_Vertex_Point_End, - ubeg, - uend); + else if(pc->Typ == STEP_BSPL) { + List_Read(pc->Curve.BSpline.ListOf_Knots, 0, &ubeg); + List_Read(pc->Curve.BSpline.ListOf_Knots, + List_Nbr(pc->Curve.BSpline.ListOf_Knots) - 1, &uend); + AddCurveInDataBase(ec.Num, + MSH_SEGM_NURBS, + pc->Curve.BSpline.Order, + pc->Curve.BSpline.ListOf_Cartesian_Points, + pc->Curve.BSpline.ListOf_Knots, + ec.Step_Vertex_Point_Begin, + ec.Step_Vertex_Point_End, ubeg, uend); } - else if(pc->Typ == STEP_CIRC || pc->Typ == STEP_ELLP){ - axs = Get_Axis2_Placement3D(pc->Curve.Circle.Step_Axis2_Placement3D); - pcp = Get_Cartesian_Point(axs->Step_Cartesian_Point); - d1 = Get_Direction(axs->Step_Direction1); - d2 = Get_Direction(axs->Step_Direction2); + else if(pc->Typ == STEP_CIRC || pc->Typ == STEP_ELLP) { + axs = Get_Axis2_Placement3D(pc->Curve.Circle.Step_Axis2_Placement3D); + pcp = Get_Cartesian_Point(axs->Step_Cartesian_Point); + d1 = Get_Direction(axs->Step_Direction1); + d2 = Get_Direction(axs->Step_Direction2); n[0] = d1->Pos.X; n[1] = d1->Pos.Y; n[2] = d1->Pos.Z; - List_Add(ListInt,&ec.Step_Vertex_Point_Begin); - List_Add(ListInt,&pcp->Num); - List_Add(ListInt,&ec.Step_Vertex_Point_End); - AddCircleInDataBase ( ec.Num,MSH_SEGM_CIRC , - ListInt,n); + List_Add(ListInt, &ec.Step_Vertex_Point_Begin); + List_Add(ListInt, &pcp->Num); + List_Add(ListInt, &ec.Step_Vertex_Point_End); + AddCircleInDataBase(ec.Num, MSH_SEGM_CIRC, ListInt, n); // Cdbseg101(ec.Num,MSH_SEGM_CIRC,1,NULL, - // ListInt,-1,-1,0.,1.,NULL,NULL,NULL); + // ListInt,-1,-1,0.,1.,NULL,NULL,NULL); List_Reset(ListInt); } } } // resolving Surfaces - for(i=0;i<List_Nbr(BREP->AllSurfaces);i++){ - List_Read(BREP->AllSurfaces,i,&s); - if(s.Typ == STEP_BSPL){ - CreateNurbsSurfaceSupport ( - s.Num , - s.Surface.BSpline.OrderV , - s.Surface.BSpline.OrderU , - s.Surface.BSpline.ListOf_Cartesian_Points , - s.Surface.BSpline.ListOf_KnotsV , - s.Surface.BSpline.ListOf_KnotsU ); + for(i = 0; i < List_Nbr(BREP->AllSurfaces); i++) { + List_Read(BREP->AllSurfaces, i, &s); + if(s.Typ == STEP_BSPL) { + CreateNurbsSurfaceSupport(s.Num, + s.Surface.BSpline.OrderV, + s.Surface.BSpline.OrderU, + s.Surface.BSpline.ListOf_Cartesian_Points, + s.Surface.BSpline.ListOf_KnotsV, + s.Surface.BSpline.ListOf_KnotsU); } } // resolving Advanced_Faces - for(i=0;i<List_Nbr(BREP->AllAdvanced_Faces);i++){ + for(i = 0; i < List_Nbr(BREP->AllAdvanced_Faces); i++) { err = 0; - List_Read(BREP->AllAdvanced_Faces,i,&af); + List_Read(BREP->AllAdvanced_Faces, i, &af); fob = 0; - for(j=0;j<List_Nbr(af.ListOf_Step_Face_Outer_Bound);j++){ - List_Read(af.ListOf_Step_Face_Outer_Bound,j,&d); + for(j = 0; j < List_Nbr(af.ListOf_Step_Face_Outer_Bound); j++) { + List_Read(af.ListOf_Step_Face_Outer_Bound, j, &d); obj = (int)d; - if((pfab = Get_Face_Outer_Bound(obj)) && - (!j || fob)){ - if(pfab->outer)fob = 1; - if((pel = Get_Edge_Loop(pfab->Step_Edge_Loop))){ - for(k=0;k<List_Nbr(pel->ListOf_Step_Oriented_Edge);k++){ - List_Read(pel->ListOf_Step_Oriented_Edge,k,&d); + if((pfab = Get_Face_Outer_Bound(obj)) && (!j || fob)) { + if(pfab->outer) + fob = 1; + if((pel = Get_Edge_Loop(pfab->Step_Edge_Loop))) { + for(k = 0; k < List_Nbr(pel->ListOf_Step_Oriented_Edge); k++) { + List_Read(pel->ListOf_Step_Oriented_Edge, k, &d); obj = (int)d; - if((poe = Get_Oriented_Edge(obj))){ - l = (poe->dir)?poe->Step_Edge_Curve:-poe->Step_Edge_Curve; - List_Add(ListInt,&l); + if((poe = Get_Oriented_Edge(obj))) { + l = (poe->dir) ? poe->Step_Edge_Curve : -poe->Step_Edge_Curve; + List_Add(ListInt, &l); } - else err = 1; + else + err = 1; } } - else err = 1; - if(!err){ - Cdbz101(pfab->Num,MSH_SEGM_LOOP,0,0,0,0,0,NULL,NULL,ListInt); - List_Add(ListIntBis,& pfab->Num); + else + err = 1; + if(!err) { + Cdbz101(pfab->Num, MSH_SEGM_LOOP, 0, 0, 0, 0, 0, NULL, NULL, + ListInt); + List_Add(ListIntBis, &pfab->Num); } List_Reset(ListInt); } - else err = 0; + else + err = 0; } - if(!err && (ps = Get_Surface(af.Step_Surface))){ - if(ps->Typ == STEP_PLAN){ - Cdbz101(af.Num,MSH_SURF_PLAN,0,0,0,0,0,NULL,NULL,ListIntBis); + if(!err && (ps = Get_Surface(af.Step_Surface))) { + if(ps->Typ == STEP_PLAN) { + Cdbz101(af.Num, MSH_SURF_PLAN, 0, 0, 0, 0, 0, NULL, NULL, ListIntBis); } else if(ps->Typ == STEP_CYLD || ps->Typ == STEP_CONE - /*|| ps->Typ == STEP_TORD || ps->Typ == STEP_CONE*/){ - axs = Get_Axis2_Placement3D(ps->Surface.Quadric.Step_Axis2_Placement3D); - pcp = Get_Cartesian_Point(axs->Step_Cartesian_Point); - d1 = Get_Direction(axs->Step_Direction1); - d2 = Get_Direction(axs->Step_Direction2); - n[0] = d1->Pos.X;n[1] = d1->Pos.Y;n[2] = d1->Pos.Z; - t[0] = d2->Pos.X;t[1] = d2->Pos.Y;t[2] = d2->Pos.Z; - p[0] = pcp->Pos.X;p[1] = pcp->Pos.Y;p[2] = pcp->Pos.Z; - int typ = 0; - switch(ps->Typ){ + /*|| ps->Typ == STEP_TORD || ps->Typ == STEP_CONE */ ) { + axs = + Get_Axis2_Placement3D(ps->Surface.Quadric.Step_Axis2_Placement3D); + pcp = Get_Cartesian_Point(axs->Step_Cartesian_Point); + d1 = Get_Direction(axs->Step_Direction1); + d2 = Get_Direction(axs->Step_Direction2); + n[0] = d1->Pos.X; + n[1] = d1->Pos.Y; + n[2] = d1->Pos.Z; + t[0] = d2->Pos.X; + t[1] = d2->Pos.Y; + t[2] = d2->Pos.Z; + p[0] = pcp->Pos.X; + p[1] = pcp->Pos.Y; + p[2] = pcp->Pos.Z; + int typ = 0; + switch (ps->Typ) { case STEP_CYLD: typ = MSH_SURF_CYLNDR; break; @@ -662,40 +768,39 @@ void Resolve_BREP (void){ typ = MSH_SURF_CONE; break; } - AddQuadricSurfaceInDataBase (typ, - af.Num, - n,t,p, - ps->Surface.Quadric.Radius1, - ps->Surface.Quadric.Radius2, - ListIntBis); + AddQuadricSurfaceInDataBase(typ, + af.Num, + n, t, p, + ps->Surface.Quadric.Radius1, + ps->Surface.Quadric.Radius2, ListIntBis); //Cdbz101(af.Num,MSH_SURF_REGL,0,0,0,0,0,NULL,NULL,ListIntBis); } - else if(ps->Typ == STEP_BSPL){ - Cdbz101(af.Num,MSH_SURF_TRIMMED,0,0,0,0,af.Step_Surface,NULL,NULL,ListIntBis); + else if(ps->Typ == STEP_BSPL) { + Cdbz101(af.Num, MSH_SURF_TRIMMED, 0, 0, 0, 0, af.Step_Surface, NULL, + NULL, ListIntBis); } } List_Reset(ListIntBis); } - + // resolving closed shells (sheila) - for(i=0;i<List_Nbr(BREP->AllClosed_Shells);i++){ + for(i = 0; i < List_Nbr(BREP->AllClosed_Shells); i++) { List_Reset(ListInt); - List_Read(BREP->AllClosed_Shells,i,&cs); - for(j=0;j<List_Nbr(cs.ListOf_Step_Advanced_Face);j++){ - List_Read(cs.ListOf_Step_Advanced_Face,j,&d); + List_Read(BREP->AllClosed_Shells, i, &cs); + for(j = 0; j < List_Nbr(cs.ListOf_Step_Advanced_Face); j++) { + List_Read(cs.ListOf_Step_Advanced_Face, j, &d); obj = (int)d; - if((paf = Get_Advanced_Face(obj))){ - List_Add(ListInt,&paf->Num); + if((paf = Get_Advanced_Face(obj))) { + List_Add(ListInt, &paf->Num); } } - Cdbz101(cs.Num+1000000,MSH_SURF_LOOP,0,0,0,0,0,NULL,NULL,ListInt); + Cdbz101(cs.Num + 1000000, MSH_SURF_LOOP, 0, 0, 0, 0, 0, NULL, NULL, + ListInt); List_Reset(ListInt); - j = cs.Num+1000000; - List_Add(ListInt,&j); - Cdbz101(cs.Num,MSH_VOLUME,0,0,0,0,0,NULL,NULL,ListInt); + j = cs.Num + 1000000; + List_Add(ListInt, &j); + Cdbz101(cs.Num, MSH_VOLUME, 0, 0, 0, 0, 0, NULL, NULL, ListInt); } } - - diff --git a/Geo/Verif.cpp b/Geo/Verif.cpp index 4c152623495a5177df31c7dbc40ae3410c48e93b..84dc2b59b7d59588bc555cea49accfce5194a554 100644 --- a/Geo/Verif.cpp +++ b/Geo/Verif.cpp @@ -1,4 +1,4 @@ -// $Id: Verif.cpp,v 1.13 2003-01-23 20:19:20 geuzaine Exp $ +// $Id: Verif.cpp,v 1.14 2003-03-01 22:36:38 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -33,54 +33,58 @@ static Tree_T *treelink; static Tree_T *treeedges; static Tree_T *treefaces; -typedef struct { - int n,a,arbre; +typedef struct{ + int n, a, arbre; }nxa; -typedef struct { - int n,visited; +typedef struct{ + int n, visited; List_T *l; }lnk; -int complink(const void*a, const void*b){ - lnk *q,*w; - q = (lnk*)a; - w = (lnk*)b; - return q->n-w->n; +int complink(const void *a, const void *b) +{ + lnk *q, *w; + q = (lnk *) a; + w = (lnk *) b; + return (q->n - w->n); } static int POINT_FINAL; static int CONTOUR_TROUVE; static List_T *VisitedNodes; -void recur_trouvecont(int ip , int ed , List_T *Liste, int gauche , List_T *old ){ +void recur_trouvecont(int ip, int ed, List_T * Liste, int gauche, + List_T * old) +{ lnk lk; nxa a; - int i,rev; + int i, rev; lk.n = ip; - Tree_Query(treelink,&lk); - if(List_Nbr(lk.l) != 2 && !old)return; - for(i=0;i<List_Nbr(lk.l);i++){ - List_Read(lk.l,i,&a); - if(abs(a.a) != abs(ed)){ - if(!old || List_Search(old,&a.a,fcmp_absint) || List_Nbr(lk.l) == 2){ - if(!gauche){ - List_Add(Liste,&a.a); - if(List_Search(VisitedNodes, &a.n, fcmp_absint)){ - CONTOUR_TROUVE =1; + Tree_Query(treelink, &lk); + if(List_Nbr(lk.l) != 2 && !old) + return; + for(i = 0; i < List_Nbr(lk.l); i++) { + List_Read(lk.l, i, &a); + if(abs(a.a) != abs(ed)) { + if(!old || List_Search(old, &a.a, fcmp_absint) || List_Nbr(lk.l) == 2) { + if(!gauche) { + List_Add(Liste, &a.a); + if(List_Search(VisitedNodes, &a.n, fcmp_absint)) { + CONTOUR_TROUVE = 1; return; } } - if(a.n == POINT_FINAL){ + if(a.n == POINT_FINAL) { CONTOUR_TROUVE = 1; } - else{ - recur_trouvecont(a.n,abs(a.a),Liste,gauche,old); + else { + recur_trouvecont(a.n, abs(a.a), Liste, gauche, old); } - if(gauche){ + if(gauche) { rev = -a.a; - List_Add(Liste,&rev); + List_Add(Liste, &rev); List_Add(VisitedNodes, &a.n); } } @@ -89,36 +93,37 @@ void recur_trouvecont(int ip , int ed , List_T *Liste, int gauche , List_T *old } -void recur_trouvevol(int ifac , int iedge, List_T *Liste, List_T *old , - Tree_T *treeedges, Tree_T *treefaces){ - +void recur_trouvevol(int ifac, int iedge, List_T * Liste, List_T * old, + Tree_T * treeedges, Tree_T * treefaces) +{ lnk lk; nxa a; - int i,is,rev,l; + int i, is, rev, l; Curve *c; - Surface *s = FindSurface(abs(ifac),THEM); + Surface *s = FindSurface(abs(ifac), THEM); - for(l=0;l<List_Nbr(s->Generatrices);l++){ - List_Read(s->Generatrices,l,&c); + for(l = 0; l < List_Nbr(s->Generatrices); l++) { + List_Read(s->Generatrices, l, &c); lk.n = abs(c->Num); is = lk.n; - if(!Tree_Search(treeedges,&is)){ - Tree_Add(treeedges,&is); + if(!Tree_Search(treeedges, &is)) { + Tree_Add(treeedges, &is); } - else{ - Tree_Suppress(treeedges,&is); + else { + Tree_Suppress(treeedges, &is); } - Tree_Query(treelink,&lk); - if(List_Nbr(lk.l) == 2 || old){ - for(i=0;i<List_Nbr(lk.l);i++){ - List_Read(lk.l,i,&a); - if(abs(a.a) != abs(ifac)){ - if(!Tree_Search(treefaces,&a.a)){ - Tree_Add(treefaces,&a.a); - if(!old || List_Search(old,&a.a,fcmp_absint) || List_Nbr(lk.l) == 2){ + Tree_Query(treelink, &lk); + if(List_Nbr(lk.l) == 2 || old) { + for(i = 0; i < List_Nbr(lk.l); i++) { + List_Read(lk.l, i, &a); + if(abs(a.a) != abs(ifac)) { + if(!Tree_Search(treefaces, &a.a)) { + Tree_Add(treefaces, &a.a); + if(!old || List_Search(old, &a.a, fcmp_absint) + || List_Nbr(lk.l) == 2) { rev = abs(a.a); - List_Add(Liste,&rev); - recur_trouvevol(rev,is,Liste,old,treeedges,treefaces); + List_Add(Liste, &rev); + recur_trouvevol(rev, is, Liste, old, treeedges, treefaces); } } } @@ -128,77 +133,80 @@ void recur_trouvevol(int ifac , int iedge, List_T *Liste, List_T *old , } -void BegEndCurve (Curve *c, int *ip1, int *ip2){ - *ip1 = c->beg->Num; - *ip2 = c->end->Num; +void BegEndCurve(Curve * c, int *ip1, int *ip2) +{ + *ip1 = c->beg->Num; + *ip2 = c->end->Num; } -void CreeLiens ( void ) { - int i,is,ip1,ip2; - lnk li,*pli; - nxa na1,na2; +void CreeLiens(void) +{ + int i, is, ip1, ip2; + lnk li, *pli; + nxa na1, na2; Curve *ic; - treelink = Tree_Create(sizeof(lnk),complink); + treelink = Tree_Create(sizeof(lnk), complink); List_T *temp = Tree2List(THEM->Curves); - for(i=0;i<List_Nbr(temp);i++){ - List_Read(temp,i,&ic); - if(ic->Num > 0){ - is = ic->Num; - BegEndCurve(ic,&ip1,&ip2); - - na1.a = -is; - na2.a = is; - na2.arbre = na1.arbre = li.visited = 0; - na1.n = li.n = ip1; - na2.n = ip2; - if((pli = (lnk*)Tree_PQuery(treelink,&li))){ - List_Add(pli->l,&na2); - } - else{ - li.l = List_Create(20,1,sizeof(nxa)); - List_Add(li.l,&na2); - Tree_Add(treelink,&li); - } - li.n = ip2; - if((pli = (lnk*)Tree_PQuery(treelink,&li))){ - List_Add(pli->l,&na1); - } - else{ - li.l = List_Create(20,1,sizeof(nxa)); - List_Add(li.l,&na1); - Tree_Add(treelink,&li); - } - } + for(i = 0; i < List_Nbr(temp); i++) { + List_Read(temp, i, &ic); + if(ic->Num > 0) { + is = ic->Num; + BegEndCurve(ic, &ip1, &ip2); + + na1.a = -is; + na2.a = is; + na2.arbre = na1.arbre = li.visited = 0; + na1.n = li.n = ip1; + na2.n = ip2; + if((pli = (lnk *) Tree_PQuery(treelink, &li))) { + List_Add(pli->l, &na2); + } + else { + li.l = List_Create(20, 1, sizeof(nxa)); + List_Add(li.l, &na2); + Tree_Add(treelink, &li); + } + li.n = ip2; + if((pli = (lnk *) Tree_PQuery(treelink, &li))) { + List_Add(pli->l, &na1); + } + else { + li.l = List_Create(20, 1, sizeof(nxa)); + List_Add(li.l, &na1); + Tree_Add(treelink, &li); + } + } } } -void CreeLiens2 ( void ) { - int i,k; - lnk li,*pli; - nxa na; +void CreeLiens2(void) +{ + int i, k; + lnk li, *pli; + nxa na; Surface *s; Curve *c; - treelink = Tree_Create(sizeof(lnk),complink); + treelink = Tree_Create(sizeof(lnk), complink); List_T *temp = Tree2List(THEM->Surfaces); - for(i=0;i<List_Nbr(temp);i++){ - List_Read(temp,i,&s); + for(i = 0; i < List_Nbr(temp); i++) { + List_Read(temp, i, &s); if(s->Num > 0) na.a = s->Num; - for(k=0;k<List_Nbr(s->Generatrices);k++){ - List_Read(s->Generatrices,k,&c); + for(k = 0; k < List_Nbr(s->Generatrices); k++) { + List_Read(s->Generatrices, k, &c); li.n = abs(c->Num); - if((pli = (lnk*)Tree_PQuery(treelink,&li))){ - List_Add(pli->l,&na); + if((pli = (lnk *) Tree_PQuery(treelink, &li))) { + List_Add(pli->l, &na); } - else{ - li.l = List_Create(20,1,sizeof(nxa)); - List_Add(li.l,&na); - Tree_Add(treelink,&li); + else { + li.l = List_Create(20, 1, sizeof(nxa)); + List_Add(li.l, &na); + Tree_Add(treelink, &li); } } } @@ -206,73 +214,73 @@ void CreeLiens2 ( void ) { } -int alledgeslinked ( int ed , List_T *Liste , List_T *old){ - int ip1,ip2,i,rev; +int alledgeslinked(int ed, List_T * Liste, List_T * old) +{ + int ip1, ip2, i, rev; lnk lk; nxa a; - VisitedNodes = List_Create(20,20,sizeof(int)); + VisitedNodes = List_Create(20, 20, sizeof(int)); CreeLiens(); - Curve *c,C; + Curve *c, C; c = &C; c->Num = ed; - Tree_Query(THEM->Curves,&c); + Tree_Query(THEM->Curves, &c); - BegEndCurve(c,&ip1,&ip2); + BegEndCurve(c, &ip1, &ip2); CONTOUR_TROUVE = 0; POINT_FINAL = ip2; - recur_trouvecont(ip1,ed,Liste,1,old); + recur_trouvecont(ip1, ed, Liste, 1, old); - if(old){ - List_Sort(old,fcmp_absint); + if(old) { + List_Sort(old, fcmp_absint); } lk.n = ip2; - Tree_Query(treelink,&lk); - for(i=0;i<List_Nbr(lk.l);i++){ - List_Read(lk.l,i,&a); - if(abs(a.a) == abs(ed)){ + Tree_Query(treelink, &lk); + for(i = 0; i < List_Nbr(lk.l); i++) { + List_Read(lk.l, i, &a); + if(abs(a.a) == abs(ed)) { rev = -a.a; - List_Add(Liste,&rev); + List_Add(Liste, &rev); } } - if(!CONTOUR_TROUVE){ + if(!CONTOUR_TROUVE) { POINT_FINAL = ip1; - recur_trouvecont(ip2,ed,Liste,0,old); + recur_trouvecont(ip2, ed, Liste, 0, old); } List_Delete(VisitedNodes); - return(CONTOUR_TROUVE); + return (CONTOUR_TROUVE); } -int allfaceslinked (int iz , List_T *Liste , List_T *old){ - +int allfaceslinked(int iz, List_T * Liste, List_T * old) +{ CreeLiens2(); - treeedges = Tree_Create(sizeof(int),fcmp_absint); - treefaces = Tree_Create(sizeof(int),fcmp_absint); + treeedges = Tree_Create(sizeof(int), fcmp_absint); + treefaces = Tree_Create(sizeof(int), fcmp_absint); - Tree_Add(treefaces,&iz); - List_Add(Liste,&iz); - recur_trouvevol(iz,0,Liste,old,treeedges,treefaces); + Tree_Add(treefaces, &iz); + List_Add(Liste, &iz); + recur_trouvevol(iz, 0, Liste, old, treeedges, treefaces); - if(!Tree_Nbr(treeedges)){ + if(!Tree_Nbr(treeedges)) { CONTOUR_TROUVE = 1; } - else{ + else { CONTOUR_TROUVE = 0; } Tree_Delete(treeedges); Tree_Delete(treefaces); - return(CONTOUR_TROUVE); + return (CONTOUR_TROUVE); } - diff --git a/Graphics/Axes.cpp b/Graphics/Axes.cpp index 86f4d4762184958f61a24c3ed1d0b613b7b4ef18..6ade7feb23d224d68716c27aa35ecaa75c0b7bc7 100644 --- a/Graphics/Axes.cpp +++ b/Graphics/Axes.cpp @@ -1,4 +1,4 @@ -// $Id: Axes.cpp,v 1.17 2003-01-23 20:19:20 geuzaine Exp $ +// $Id: Axes.cpp,v 1.18 2003-03-01 22:36:39 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -27,126 +27,138 @@ #include "Context.h" #include "gl2ps.h" -extern Context_T CTX; +extern Context_T CTX; -void Draw_Axes (double s) { - double f, g, b, c; - - if(s == 0.) return; +void Draw_Axes(double s) +{ + double f, g, b, c; - if(!CTX.range[0] && !CTX.range[1] && !CTX.range[2]) return ; + if(s == 0.) + return; + + if(!CTX.range[0] && !CTX.range[1] && !CTX.range[2]) + return; f = 0.666 * s; g = 1.233 * s; b = .1 * s; c = 0.666 * b; - glLineWidth(1.); - gl2psLineWidth(1.*CTX.print.eps_line_width_factor); - glColor4ubv((GLubyte*)&CTX.color.axes); + glLineWidth(1.); + gl2psLineWidth(1. * CTX.print.eps_line_width_factor); + glColor4ubv((GLubyte *) & CTX.color.axes); glBegin(GL_LINES); - if(CTX.range[2] != 0.){ + if(CTX.range[2] != 0.) { // X - glVertex3d(0., 0., 0.); - glVertex3d(s, 0., 0.); - glVertex3d(g-b, b, 0.); - glVertex3d(g+b, -b, 0.); - glVertex3d(g, -b, b); - glVertex3d(g, b, -b); + glVertex3d(0., 0., 0.); + glVertex3d(s, 0., 0.); + glVertex3d(g - b, b, 0.); + glVertex3d(g + b, -b, 0.); + glVertex3d(g, -b, b); + glVertex3d(g, b, -b); // Y - glVertex3d(0., 0., 0.); - glVertex3d(0., s, 0.); - glVertex3d(-b, g+b, 0.); - glVertex3d(0., g, 0.); - glVertex3d(0., g, 0.); - glVertex3d(0., g+b, -b); - glVertex3d(0., g, 0.); - glVertex3d(.5*b, g-b, .5*b); + glVertex3d(0., 0., 0.); + glVertex3d(0., s, 0.); + glVertex3d(-b, g + b, 0.); + glVertex3d(0., g, 0.); + glVertex3d(0., g, 0.); + glVertex3d(0., g + b, -b); + glVertex3d(0., g, 0.); + glVertex3d(.5 * b, g - b, .5 * b); // Z - glVertex3d(0., 0., 0.); - glVertex3d(0., 0., s); - glVertex3d(-b, b, g); - glVertex3d(0., b, g-b); - glVertex3d(0., b, g-b); - glVertex3d(0., -b, g+b); - glVertex3d(0., -b, g+b); - glVertex3d(b, -b, g); + glVertex3d(0., 0., 0.); + glVertex3d(0., 0., s); + glVertex3d(-b, b, g); + glVertex3d(0., b, g - b); + glVertex3d(0., b, g - b); + glVertex3d(0., -b, g + b); + glVertex3d(0., -b, g + b); + glVertex3d(b, -b, g); } - else{ + else { // X - glVertex3d(0., 0., 0.); - glVertex3d(s, 0., 0.); - glVertex3d(g-c, b, 0.); - glVertex3d(g+c, -b, 0.); - glVertex3d(g-c, -b, 0.); - glVertex3d(g+c, b, 0.); + glVertex3d(0., 0., 0.); + glVertex3d(s, 0., 0.); + glVertex3d(g - c, b, 0.); + glVertex3d(g + c, -b, 0.); + glVertex3d(g - c, -b, 0.); + glVertex3d(g + c, b, 0.); // Y - glVertex3d(0., 0., 0.); - glVertex3d(0., s, 0.); - glVertex3d(-c, g+b, 0.); - glVertex3d(0., g, 0.); - glVertex3d(0., g, 0.); - glVertex3d(c, g+b, 0.); - glVertex3d(0., g, 0.); - glVertex3d(0., g-b, 0.); + glVertex3d(0., 0., 0.); + glVertex3d(0., s, 0.); + glVertex3d(-c, g + b, 0.); + glVertex3d(0., g, 0.); + glVertex3d(0., g, 0.); + glVertex3d(c, g + b, 0.); + glVertex3d(0., g, 0.); + glVertex3d(0., g - b, 0.); } glEnd(); - + glEnable(GL_LINE_STIPPLE); - glLineStipple(2,0x0F0F); + glLineStipple(2, 0x0F0F); glBegin(GL_LINES); - if(CTX.range[2] != 0.){ - glVertex3d(f, 0., 0.); - glVertex3d(f, 0., f ); - glVertex3d(f, 0., f ); - glVertex3d(0., 0., f ); - glVertex3d(0., 0., f ); - glVertex3d(0., f, f ); - glVertex3d(0., f, f ); - glVertex3d(0., f, 0.); + if(CTX.range[2] != 0.) { + glVertex3d(f, 0., 0.); + glVertex3d(f, 0., f); + glVertex3d(f, 0., f); + glVertex3d(0., 0., f); + glVertex3d(0., 0., f); + glVertex3d(0., f, f); + glVertex3d(0., f, f); + glVertex3d(0., f, 0.); } - glVertex3d(0., f, 0.); - glVertex3d(f, f, 0.); - glVertex3d(f, f, 0.); - glVertex3d(f, 0., 0.); + glVertex3d(0., f, 0.); + glVertex3d(f, f, 0.); + glVertex3d(f, f, 0.); + glVertex3d(f, 0., 0.); glEnd(); glDisable(GL_LINE_STIPPLE); } -void Draw_SmallAxes(void){ - double l,o,xx,xy,yx,yy,zx,zy,cx,cy; +void Draw_SmallAxes(void) +{ + double l, o, xx, xy, yx, yy, zx, zy, cx, cy; - l = 30 ; - o = 2 ; + l = 30; + o = 2; - if(CTX.small_axes_pos[0]>0) + if(CTX.small_axes_pos[0] > 0) cx = CTX.viewport[0] + CTX.small_axes_pos[0]; else cx = CTX.viewport[2] + CTX.small_axes_pos[0]; - if(CTX.small_axes_pos[1]>0) - cy = CTX.viewport[3] - CTX.small_axes_pos[1]; + if(CTX.small_axes_pos[1] > 0) + cy = CTX.viewport[3] - CTX.small_axes_pos[1]; else - cy = CTX.viewport[1] - CTX.small_axes_pos[1]; + cy = CTX.viewport[1] - CTX.small_axes_pos[1]; - xx = l*CTX.rot[0][0] ; xy = l*CTX.rot[0][1] ; - yx = l*CTX.rot[1][0] ; yy = l*CTX.rot[1][1] ; - zx = l*CTX.rot[2][0] ; zy = l*CTX.rot[2][1] ; + xx = l * CTX.rot[0][0]; + xy = l * CTX.rot[0][1]; + yx = l * CTX.rot[1][0]; + yy = l * CTX.rot[1][1]; + zx = l * CTX.rot[2][0]; + zy = l * CTX.rot[2][1]; - glLineWidth(1.); - gl2psLineWidth(1.*CTX.print.eps_line_width_factor); - glColor4ubv((GLubyte*)&CTX.color.small_axes); + glLineWidth(1.); + gl2psLineWidth(1. * CTX.print.eps_line_width_factor); + glColor4ubv((GLubyte *) & CTX.color.small_axes); glBegin(GL_LINES); - glVertex2d(cx,cy); glVertex2d(cx+xx,cy+xy); - glVertex2d(cx,cy); glVertex2d(cx+yx,cy+yy); - glVertex2d(cx,cy); glVertex2d(cx+zx,cy+zy); + glVertex2d(cx, cy); + glVertex2d(cx + xx, cy + xy); + glVertex2d(cx, cy); + glVertex2d(cx + yx, cy + yy); + glVertex2d(cx, cy); + glVertex2d(cx + zx, cy + zy); glEnd(); - glRasterPos2d(cx+xx+o,cy+xy+o); Draw_String("X"); - glRasterPos2d(cx+yx+o,cy+yy+o); Draw_String("Y"); - glRasterPos2d(cx+zx+o,cy+zy+o); Draw_String("Z"); + glRasterPos2d(cx + xx + o, cy + xy + o); + Draw_String("X"); + glRasterPos2d(cx + yx + o, cy + yy + o); + Draw_String("Y"); + glRasterPos2d(cx + zx + o, cy + zy + o); + Draw_String("Z"); } - diff --git a/Graphics/CreateFile.cpp b/Graphics/CreateFile.cpp index 2f44f4d5032562948aaed4b2609d117736bd18b2..d5aef962a8d17ea79197f39f44a86159bf283e44 100644 --- a/Graphics/CreateFile.cpp +++ b/Graphics/CreateFile.cpp @@ -1,4 +1,4 @@ -// $Id: CreateFile.cpp,v 1.37 2003-01-23 20:19:20 geuzaine Exp $ +// $Id: CreateFile.cpp,v 1.38 2003-03-01 22:36:39 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -27,8 +27,8 @@ #include "Context.h" #include "Options.h" -extern Context_T CTX; -extern Mesh M; +extern Context_T CTX; +extern Mesh M; #include "gl2ps.h" #include "gl2gif.h" @@ -36,167 +36,199 @@ extern Mesh M; #include "gl2ppm.h" #include "gl2yuv.h" -void FillBuffer(void){ +void FillBuffer(void) +{ InitOpengl(); ClearOpengl(); Draw3d(); Draw2d(); } -void CreateOutputFile (char *name, int format) { - FILE *fp; - GLint size3d; - char ext[256]; - int res, i, oldformat, psformat, pssort, psoptions; +void CreateOutputFile(char *name, int format) +{ + FILE *fp; + GLint size3d; + char ext[256]; + int res, i, oldformat, psformat, pssort, psoptions; - if(!name || !strlen(name)) return; + if(!name || !strlen(name)) + return; oldformat = CTX.print.format; CTX.print.format = format; - switch(format){ + switch (format) { - case FORMAT_AUTO : - for(i=strlen(name)-1; i>=0; i--){ - if(name[i] == '.'){ - strcpy(ext,&name[i]); - break; + case FORMAT_AUTO: + for(i = strlen(name) - 1; i >= 0; i--) { + if(name[i] == '.') { + strcpy(ext, &name[i]); + break; } } - if(i<=0) strcpy(ext,""); - - if (!strcmp(ext,".geo")) CreateOutputFile(name, FORMAT_GEO); - else if(!strcmp(ext,".opt")) CreateOutputFile(name, FORMAT_OPT); - else if(!strcmp(ext,".msh")) CreateOutputFile(name, FORMAT_MSH); - else if(!strcmp(ext,".unv")) CreateOutputFile(name, FORMAT_UNV); - else if(!strcmp(ext,".gif")) CreateOutputFile(name, FORMAT_GIF); - else if(!strcmp(ext,".jpg")) CreateOutputFile(name, FORMAT_JPEG); - else if(!strcmp(ext,".jpeg")) CreateOutputFile(name, FORMAT_JPEG); - else if(!strcmp(ext,".ps")) CreateOutputFile(name, FORMAT_PS); - else if(!strcmp(ext,".eps")) CreateOutputFile(name, FORMAT_EPS); - else if(!strcmp(ext,".tex")) CreateOutputFile(name, FORMAT_TEX); - else if(!strcmp(ext,".pstex")) CreateOutputFile(name, FORMAT_PSTEX); - else if(!strcmp(ext,".epstex")) CreateOutputFile(name, FORMAT_EPSTEX); - else if(!strcmp(ext,".jpegtex")) CreateOutputFile(name, FORMAT_JPEGTEX); - else if(!strcmp(ext,".ppm")) CreateOutputFile(name, FORMAT_PPM); - else if(!strcmp(ext,".yuv")) CreateOutputFile(name, FORMAT_YUV); - else if(!strcmp(ext,".gref")) CreateOutputFile(name, FORMAT_GREF); - else if(!strcmp(ext,".Gref")) CreateOutputFile(name, FORMAT_GREF); - else if(!strcmp(ext,".wrl")) CreateOutputFile(name, FORMAT_VRML); - else Msg(GERROR, "Unknown extension '%s' for automatic format detection", ext); + if(i <= 0) + strcpy(ext, ""); + + if(!strcmp(ext, ".geo")) + CreateOutputFile(name, FORMAT_GEO); + else if(!strcmp(ext, ".opt")) + CreateOutputFile(name, FORMAT_OPT); + else if(!strcmp(ext, ".msh")) + CreateOutputFile(name, FORMAT_MSH); + else if(!strcmp(ext, ".unv")) + CreateOutputFile(name, FORMAT_UNV); + else if(!strcmp(ext, ".gif")) + CreateOutputFile(name, FORMAT_GIF); + else if(!strcmp(ext, ".jpg")) + CreateOutputFile(name, FORMAT_JPEG); + else if(!strcmp(ext, ".jpeg")) + CreateOutputFile(name, FORMAT_JPEG); + else if(!strcmp(ext, ".ps")) + CreateOutputFile(name, FORMAT_PS); + else if(!strcmp(ext, ".eps")) + CreateOutputFile(name, FORMAT_EPS); + else if(!strcmp(ext, ".tex")) + CreateOutputFile(name, FORMAT_TEX); + else if(!strcmp(ext, ".pstex")) + CreateOutputFile(name, FORMAT_PSTEX); + else if(!strcmp(ext, ".epstex")) + CreateOutputFile(name, FORMAT_EPSTEX); + else if(!strcmp(ext, ".jpegtex")) + CreateOutputFile(name, FORMAT_JPEGTEX); + else if(!strcmp(ext, ".ppm")) + CreateOutputFile(name, FORMAT_PPM); + else if(!strcmp(ext, ".yuv")) + CreateOutputFile(name, FORMAT_YUV); + else if(!strcmp(ext, ".gref")) + CreateOutputFile(name, FORMAT_GREF); + else if(!strcmp(ext, ".Gref")) + CreateOutputFile(name, FORMAT_GREF); + else if(!strcmp(ext, ".wrl")) + CreateOutputFile(name, FORMAT_VRML); + else + Msg(GERROR, "Unknown extension '%s' for automatic format detection", + ext); break; - case FORMAT_GEO : + case FORMAT_GEO: Print_Geo(&M, name); break; - case FORMAT_OPT : - Print_Options(0,GMSH_FULLRC, name); + case FORMAT_OPT: + Print_Options(0, GMSH_FULLRC, name); break; - case FORMAT_MSH : - Print_Mesh(&M, name, FORMAT_MSH); + case FORMAT_MSH: + Print_Mesh(&M, name, FORMAT_MSH); break; - case FORMAT_UNV : - Print_Mesh(&M, name, FORMAT_UNV); + case FORMAT_UNV: + Print_Mesh(&M, name, FORMAT_UNV); break; - - case FORMAT_GREF : - Print_Mesh(&M, name, FORMAT_GREF); + + case FORMAT_GREF: + Print_Mesh(&M, name, FORMAT_GREF); break; - case FORMAT_VRML : - Print_Mesh(&M, name, FORMAT_VRML); + case FORMAT_VRML: + Print_Mesh(&M, name, FORMAT_VRML); break; - case FORMAT_JPEG : - case FORMAT_JPEGTEX : - if(!(fp = fopen(name,"wb"))) { - Msg(GERROR, "Unable to open file '%s'", name); + case FORMAT_JPEG: + case FORMAT_JPEGTEX: + if(!(fp = fopen(name, "wb"))) { + Msg(GERROR, "Unable to open file '%s'", name); return; } - if(format == FORMAT_JPEGTEX) CTX.print.gl_fonts = 0; + if(format == FORMAT_JPEGTEX) + CTX.print.gl_fonts = 0; FillBuffer(); CTX.print.gl_fonts = 1; - create_jpeg(fp, CTX.viewport[2]-CTX.viewport[0], - CTX.viewport[3]-CTX.viewport[1], - CTX.print.jpeg_quality); + create_jpeg(fp, CTX.viewport[2] - CTX.viewport[0], + CTX.viewport[3] - CTX.viewport[1], CTX.print.jpeg_quality); Msg(INFO, "JPEG creation complete '%s'", name); Msg(STATUS2, "Wrote '%s'", name); fclose(fp); break; - case FORMAT_GIF : - if(!(fp = fopen(name,"wb"))) { - Msg(GERROR, "Unable to open file '%s'", name); + case FORMAT_GIF: + if(!(fp = fopen(name, "wb"))) { + Msg(GERROR, "Unable to open file '%s'", name); return; } FillBuffer(); - create_gif(fp, CTX.viewport[2]-CTX.viewport[0], - CTX.viewport[3]-CTX.viewport[1], - CTX.print.gif_dither, - CTX.print.gif_sort, - CTX.print.gif_interlace, - CTX.print.gif_transparent, - UNPACK_RED(CTX.color.bg), - UNPACK_GREEN(CTX.color.bg), - UNPACK_BLUE(CTX.color.bg)); + create_gif(fp, CTX.viewport[2] - CTX.viewport[0], + CTX.viewport[3] - CTX.viewport[1], + CTX.print.gif_dither, + CTX.print.gif_sort, + CTX.print.gif_interlace, + CTX.print.gif_transparent, + UNPACK_RED(CTX.color.bg), + UNPACK_GREEN(CTX.color.bg), UNPACK_BLUE(CTX.color.bg)); Msg(INFO, "GIF creation complete '%s'", name); Msg(STATUS2, "Wrote '%s'", name); fclose(fp); break; - case FORMAT_PPM : - if(!(fp = fopen(name,"wb"))) { - Msg(GERROR, "Unable to open file '%s'", name); + case FORMAT_PPM: + if(!(fp = fopen(name, "wb"))) { + Msg(GERROR, "Unable to open file '%s'", name); return; } FillBuffer(); - create_ppm(fp, CTX.viewport[2]-CTX.viewport[0], - CTX.viewport[3]-CTX.viewport[1]); + create_ppm(fp, CTX.viewport[2] - CTX.viewport[0], + CTX.viewport[3] - CTX.viewport[1]); Msg(INFO, "PPM creation complete '%s'", name); Msg(STATUS2, "Wrote '%s'", name); fclose(fp); break; - case FORMAT_YUV : - if(!(fp = fopen(name,"wb"))) { - Msg(GERROR, "Unable to open file '%s'", name); + case FORMAT_YUV: + if(!(fp = fopen(name, "wb"))) { + Msg(GERROR, "Unable to open file '%s'", name); return; } FillBuffer(); - create_yuv(fp, CTX.viewport[2]-CTX.viewport[0], - CTX.viewport[3]-CTX.viewport[1]); + create_yuv(fp, CTX.viewport[2] - CTX.viewport[0], + CTX.viewport[3] - CTX.viewport[1]); Msg(INFO, "YUV creation complete '%s'", name); Msg(STATUS2, "Wrote '%s'", name); fclose(fp); break; - case FORMAT_PS : - case FORMAT_PSTEX : - case FORMAT_EPS : - case FORMAT_EPSTEX : - if(!(fp = fopen(name,"w"))) { - Msg(GERROR, "Unable to open file '%s'", name); + case FORMAT_PS: + case FORMAT_PSTEX: + case FORMAT_EPS: + case FORMAT_EPSTEX: + if(!(fp = fopen(name, "w"))) { + Msg(GERROR, "Unable to open file '%s'", name); return; } - psformat = (format==FORMAT_PS || format==FORMAT_PSTEX) ? GL2PS_PS : GL2PS_EPS; - pssort = (CTX.print.eps_quality==1) ? GL2PS_SIMPLE_SORT : GL2PS_BSP_SORT; - psoptions = GL2PS_SIMPLE_LINE_OFFSET | GL2PS_SILENT | - (CTX.print.eps_occlusion_culling ? GL2PS_OCCLUSION_CULL : 0) | - (CTX.print.eps_best_root ? GL2PS_BEST_ROOT : 0) | - (CTX.print.eps_background ? GL2PS_DRAW_BACKGROUND : 0) | - (format==FORMAT_PSTEX ? GL2PS_NO_TEXT : 0) | - (format==FORMAT_EPSTEX ? GL2PS_NO_TEXT : 0); - - size3d = 0 ; - res = GL2PS_OVERFLOW ; - - while(res == GL2PS_OVERFLOW){ - size3d += 2048*2048 ; + psformat = (format == FORMAT_PS + || format == FORMAT_PSTEX) ? GL2PS_PS : GL2PS_EPS; + pssort = + (CTX.print.eps_quality == 1) ? GL2PS_SIMPLE_SORT : GL2PS_BSP_SORT; + psoptions = + GL2PS_SIMPLE_LINE_OFFSET | GL2PS_SILENT | (CTX.print. + eps_occlusion_culling ? + GL2PS_OCCLUSION_CULL : 0) | + (CTX.print.eps_best_root ? GL2PS_BEST_ROOT : 0) | (CTX.print. + eps_background ? + GL2PS_DRAW_BACKGROUND + : 0) | (format == + FORMAT_PSTEX + ? + GL2PS_NO_TEXT + : 0) | + (format == FORMAT_EPSTEX ? GL2PS_NO_TEXT : 0); + + size3d = 0; + res = GL2PS_OVERFLOW; + + while(res == GL2PS_OVERFLOW) { + size3d += 2048 * 2048; gl2psBeginPage(CTX.base_filename, "Gmsh", psformat, pssort, psoptions, - GL_RGBA, 0, NULL, size3d, fp, name); + GL_RGBA, 0, NULL, size3d, fp, name); CTX.print.gl_fonts = 0; FillBuffer(); CTX.print.gl_fonts = 1; @@ -205,16 +237,16 @@ void CreateOutputFile (char *name, int format) { Msg(INFO, "PS/EPS creation complete '%s'", name); Msg(STATUS2, "Wrote '%s'", name); fclose(fp); - break ; + break; - case FORMAT_TEX : - if(!(fp = fopen(name,"w"))) { - Msg(GERROR, "Unable to open file '%s'", name); + case FORMAT_TEX: + if(!(fp = fopen(name, "w"))) { + Msg(GERROR, "Unable to open file '%s'", name); return; } - gl2psBeginPage(CTX.base_filename, "Gmsh", - GL2PS_TEX, GL2PS_NO_SORT, 0, - GL_RGBA, 0, NULL, 1, fp, name); + gl2psBeginPage(CTX.base_filename, "Gmsh", + GL2PS_TEX, GL2PS_NO_SORT, 0, + GL_RGBA, 0, NULL, 1, fp, name); CTX.print.gl_fonts = 0; FillBuffer(); CTX.print.gl_fonts = 1; @@ -224,7 +256,7 @@ void CreateOutputFile (char *name, int format) { fclose(fp); break; - default : + default: Msg(WARNING, "Unknown print format"); break; } @@ -232,4 +264,3 @@ void CreateOutputFile (char *name, int format) { CTX.print.format = oldformat; } - diff --git a/Graphics/Draw.cpp b/Graphics/Draw.cpp index 51dc5e8daa97a95397e503de3de58eecd1b7926e..6e2bb6d4e1dd1fb3b02c49bf6f2275bf1454d757 100644 --- a/Graphics/Draw.cpp +++ b/Graphics/Draw.cpp @@ -1,4 +1,4 @@ -// $Id: Draw.cpp,v 1.35 2003-02-12 20:27:12 geuzaine Exp $ +// $Id: Draw.cpp,v 1.36 2003-03-01 22:36:39 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -27,15 +27,16 @@ #include "Context.h" #include "MinMax.h" -extern Context_T CTX ; -extern Mesh M; +extern Context_T CTX; +extern Mesh M; // Global Draw functions -void Draw3d(void){ +void Draw3d(void) +{ int i; - if(CTX.alpha){ + if(CTX.alpha) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); #if !defined(WIN32) @@ -46,97 +47,108 @@ void Draw3d(void){ } glPolygonOffset(1.0, 1); - for(i = 0 ; i < 6 ; i++) - if(CTX.clip[i]) glEnable((GLenum)(GL_CLIP_PLANE0 + i)); + for(i = 0; i < 6; i++) + if(CTX.clip[i]) + glEnable((GLenum) (GL_CLIP_PLANE0 + i)); glShadeModel(GL_SMOOTH); glDepthFunc(GL_LESS); glEnable(GL_DEPTH_TEST); - glDisable(GL_CULL_FACE); + glDisable(GL_CULL_FACE); glPushMatrix(); Draw_Mesh(&M); - glPopMatrix(); + glPopMatrix(); } -void Draw2d(void){ +void Draw2d(void) +{ int i; glDisable(GL_DEPTH_TEST); glDisable(GL_LIGHTING); glShadeModel(GL_FLAT); - for(i = 0 ; i < 6 ; i++) - glDisable((GLenum)(GL_CLIP_PLANE0 + i)); + for(i = 0; i < 6; i++) + glDisable((GLenum) (GL_CLIP_PLANE0 + i)); glMatrixMode(GL_PROJECTION); glLoadIdentity(); /* to draw directly in screen coords */ glOrtho((double)CTX.viewport[0], (double)CTX.viewport[2], - (double)CTX.viewport[1], - (double)CTX.viewport[3],-1.,1.); + (double)CTX.viewport[1], (double)CTX.viewport[3], -1., 1.); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glPushMatrix(); Draw_Graph2D(); Draw_Text2D(); - if(CTX.post.draw && CTX.post.scales) Draw_Scales(); - if(CTX.small_axes) Draw_SmallAxes(); + if(CTX.post.draw && CTX.post.scales) + Draw_Scales(); + if(CTX.small_axes) + Draw_SmallAxes(); glPopMatrix(); } // Ortho -void Orthogonalize(int x, int y){ - double Va,Wa; - +void Orthogonalize(int x, int y) +{ + double Va, Wa; + glMatrixMode(GL_PROJECTION); glLoadIdentity(); if(CTX.render_mode == GMSH_SELECT) - gluPickMatrix ((GLdouble)x, - (GLdouble)(CTX.viewport[3]-y), - 5.0, - 5.0, - (GLint*)CTX.viewport); - - Va = (GLdouble)(CTX.viewport[3]-CTX.viewport[1]) / - (GLdouble)(CTX.viewport[2]-CTX.viewport[0]) ; - - Wa = (CTX.max[1]-CTX.min[1]) / (CTX.max[0]-CTX.min[0]); - - if(Va>Wa){ + gluPickMatrix((GLdouble) x, + (GLdouble) (CTX.viewport[3] - y), + 5.0, 5.0, (GLint *) CTX.viewport); + + Va = (GLdouble) (CTX.viewport[3] - CTX.viewport[1]) / + (GLdouble) (CTX.viewport[2] - CTX.viewport[0]); + + Wa = (CTX.max[1] - CTX.min[1]) / (CTX.max[0] - CTX.min[0]); + + if(Va > Wa) { CTX.vxmin = CTX.min[0]; CTX.vxmax = CTX.max[0]; - CTX.vymin = 0.5*(CTX.min[1]+CTX.max[1]-Va*(CTX.max[0]-CTX.min[0])); - CTX.vymax = 0.5*(CTX.min[1]+CTX.max[1]+Va*(CTX.max[0]-CTX.min[0])); + CTX.vymin = + 0.5 * (CTX.min[1] + CTX.max[1] - Va * (CTX.max[0] - CTX.min[0])); + CTX.vymax = + 0.5 * (CTX.min[1] + CTX.max[1] + Va * (CTX.max[0] - CTX.min[0])); } - else{ - CTX.vxmin = 0.5*(CTX.min[0]+CTX.max[0]-(CTX.max[1]-CTX.min[1])/Va); - CTX.vxmax = 0.5*(CTX.min[0]+CTX.max[0]+(CTX.max[1]-CTX.min[1])/Va); + else { + CTX.vxmin = + 0.5 * (CTX.min[0] + CTX.max[0] - (CTX.max[1] - CTX.min[1]) / Va); + CTX.vxmax = + 0.5 * (CTX.min[0] + CTX.max[0] + (CTX.max[1] - CTX.min[1]) / Va); CTX.vymin = CTX.min[1]; CTX.vymax = CTX.max[1]; } - CTX.vxmin -= (CTX.vxmax-CTX.vxmin)/3.; CTX.vxmax += 0.25*(CTX.vxmax-CTX.vxmin); - CTX.vymin -= (CTX.vymax-CTX.vymin)/3.; CTX.vymax += 0.25*(CTX.vymax-CTX.vymin); + CTX.vxmin -= (CTX.vxmax - CTX.vxmin) / 3.; + CTX.vxmax += 0.25 * (CTX.vxmax - CTX.vxmin); + CTX.vymin -= (CTX.vymax - CTX.vymin) / 3.; + CTX.vymax += 0.25 * (CTX.vymax - CTX.vymin); + + CTX.pixel_equiv_x = + (CTX.vxmax - CTX.vxmin) / (CTX.viewport[2] - CTX.viewport[0]); + CTX.pixel_equiv_y = + (CTX.vymax - CTX.vymin) / (CTX.viewport[3] - CTX.viewport[1]); - CTX.pixel_equiv_x = (CTX.vxmax-CTX.vxmin)/(CTX.viewport[2]-CTX.viewport[0]); - CTX.pixel_equiv_y = (CTX.vymax-CTX.vymin)/(CTX.viewport[3]-CTX.viewport[1]); - if(CTX.ortho) { - glOrtho(CTX.vxmin,CTX.vxmax,CTX.vymin,CTX.vymax,0,100*CTX.lc); + glOrtho(CTX.vxmin, CTX.vxmax, CTX.vymin, CTX.vymax, 0, 100 * CTX.lc); glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslated(0.0, 0.0, -50*CTX.lc); + glLoadIdentity(); + glTranslated(0.0, 0.0, -50 * CTX.lc); } - else{ - glFrustum(CTX.vxmin,CTX.vxmax,CTX.vymin,CTX.vymax,CTX.lc,100*CTX.lc); + else { + glFrustum(CTX.vxmin, CTX.vxmax, CTX.vymin, CTX.vymax, CTX.lc, + 100 * CTX.lc); glMatrixMode(GL_MODELVIEW); - glLoadIdentity(); - glTranslated(0.0, 0.0, -10*CTX.lc); - glScaled(10.,10.,10.); + glLoadIdentity(); + glTranslated(0.0, 0.0, -10 * CTX.lc); + glScaled(10., 10., 10.); } @@ -144,14 +156,15 @@ void Orthogonalize(int x, int y){ // Init -void InitRenderModel(void){ +void InitRenderModel(void) +{ int i; float specular[4]; - for(i = 0 ; i < 6 ; i++){ - if(CTX.light[i]){ - glLightfv((GLenum)(GL_LIGHT0 + i), GL_POSITION, CTX.light_position[i]); - glEnable((GLenum)(GL_LIGHT0 + i)); + for(i = 0; i < 6; i++) { + if(CTX.light[i]) { + glLightfv((GLenum) (GL_LIGHT0 + i), GL_POSITION, CTX.light_position[i]); + glEnable((GLenum) (GL_LIGHT0 + i)); } } glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); @@ -165,19 +178,22 @@ void InitRenderModel(void){ glMaterialfv(GL_FRONT_AND_BACK, GL_SPECULAR, specular); } -void InitShading(){ +void InitShading() +{ glEnable(GL_LIGHTING); glEnable(GL_NORMALIZE); glEnable(GL_COLOR_MATERIAL); } -void InitNoShading(void){ +void InitNoShading(void) +{ glDisable(GL_LIGHTING); } -void InitPosition(void){ - glScaled (CTX.s[0], CTX.s[1], CTX.s[2]); +void InitPosition(void) +{ + glScaled(CTX.s[0], CTX.s[1], CTX.s[2]); glTranslated(CTX.t[0], CTX.t[1], CTX.t[2]); CTX.buildRotmatrix(); @@ -186,81 +202,94 @@ void InitPosition(void){ // Replot // this should only be used when some new points get added in the db -void Replot(void){ - CalculateMinMax(M.Points,NULL); +void Replot(void) +{ + CalculateMinMax(M.Points, NULL); Draw(); } // Entity selection -void Process_SelectionBuffer(int x, int y, int *n, GLuint *ii, GLuint *jj){ +void Process_SelectionBuffer(int x, int y, int *n, GLuint * ii, GLuint * jj) +{ GLuint selectBuf[SELECTION_BUFFER_SIZE]; - GLint i,j,hits,names,*ptr; + GLint i, j, hits, names, *ptr; glSelectBuffer(SELECTION_BUFFER_SIZE, selectBuf); - glRenderMode(GL_SELECT); + glRenderMode(GL_SELECT); CTX.render_mode = GMSH_SELECT; glInitNames(); glPushName(0); glPushMatrix(); - Orthogonalize(x,y); + Orthogonalize(x, y); Draw_Mesh(&M); - glPopMatrix (); + glPopMatrix(); hits = glRenderMode(GL_RENDER); - CTX.render_mode = GMSH_RENDER ; - - if(hits<0) return; // Selection Buffer Overflow + CTX.render_mode = GMSH_RENDER; + + if(hits < 0) + return; // Selection Buffer Overflow + + ptr = (GLint *) selectBuf; - ptr = (GLint*)selectBuf; - - for(i=0; i<hits; i++){ + for(i = 0; i < hits; i++) { names = *ptr; - ptr++; ptr++; ptr++; - for(j=0; j<names; j++){ - if (j==0) ii[i] = *ptr; - else if (j==1) jj[i] = *ptr; + ptr++; + ptr++; + ptr++; + for(j = 0; j < names; j++) { + if(j == 0) + ii[i] = *ptr; + else if(j == 1) + jj[i] = *ptr; ptr++; } } *n = hits; } -void Filter_SelectionBuffer(int n, GLuint *typ, GLuint *ient, Vertex **thev, - Curve **thec, Surface **thes, Mesh *m){ +void Filter_SelectionBuffer(int n, GLuint * typ, GLuint * ient, + Vertex ** thev, Curve ** thec, Surface ** thes, + Mesh * m) +{ - Vertex *v=NULL, V; - Curve *c=NULL, C; - Surface *s=NULL, S; + Vertex *v = NULL, V; + Curve *c = NULL, C; + Surface *s = NULL, S; - int i; - GLuint typmin; + int i; + GLuint typmin; typmin = 4; - for(i=0;i<n;i++){ - if(typ[i]<typmin) typmin = typ[i]; + for(i = 0; i < n; i++) { + if(typ[i] < typmin) + typmin = typ[i]; } - - for(i=0;i<n;i++){ - if(typ[i] == typmin){ - switch(typ[i]){ - case 0: - v = &V; + + for(i = 0; i < n; i++) { + if(typ[i] == typmin) { + switch (typ[i]) { + case 0: + v = &V; v->Num = ient[i]; - if(Tree_Query(m->Points,&v)) *thev = v; + if(Tree_Query(m->Points, &v)) + *thev = v; break; case 1: c = &C; c->Num = ient[i]; - if(Tree_Query(m->Curves,&c)) *thec = c; + if(Tree_Query(m->Curves, &c)) + *thec = c; break; case 2: s = &S; s->Num = ient[i]; - if(Tree_Query(m->Surfaces,&s)) *thes = s; + if(Tree_Query(m->Surfaces, &s)) + *thes = s; break; } } @@ -271,17 +300,23 @@ void Filter_SelectionBuffer(int n, GLuint *typ, GLuint *ient, Vertex **thev, // FIXME: this is notoriously wrong :-) void myZoom(GLdouble X1, GLdouble X2, GLdouble Y1, GLdouble Y2, - GLdouble Xc1, GLdouble Xc2, GLdouble Yc1, GLdouble Yc2){ - GLdouble xscale1, yscale1; + GLdouble Xc1, GLdouble Xc2, GLdouble Yc1, GLdouble Yc2) +{ + GLdouble xscale1, yscale1; xscale1 = CTX.s[0]; yscale1 = CTX.s[1]; - set_s(0, CTX.s[0] * (CTX.vxmax-CTX.vxmin)/(X2-X1)); - set_s(1, CTX.s[1] * (CTX.vymax-CTX.vymin)/(Y1-Y2)); + set_s(0, CTX.s[0] * (CTX.vxmax - CTX.vxmin) / (X2 - X1)); + set_s(1, CTX.s[1] * (CTX.vymax - CTX.vymin) / (Y1 - Y2)); /* bif bif bif */ - set_s(2, 0.5*(CTX.s[0]+CTX.s[1])); - set_t(0, CTX.t[0] * (xscale1/CTX.s[0]) - ((Xc1+Xc2)/2.)*(1.-(xscale1/CTX.s[0]))); - set_t(1, CTX.t[1] * (yscale1/CTX.s[1]) - ((Yc1+Yc2)/2.)*(1.-(yscale1/CTX.s[1]))); + set_s(2, 0.5 * (CTX.s[0] + CTX.s[1])); + set_t(0, + CTX.t[0] * (xscale1 / CTX.s[0]) - ((Xc1 + Xc2) / 2.) * (1. - + (xscale1 / + CTX.s[0]))); + set_t(1, + CTX.t[1] * (yscale1 / CTX.s[1]) - ((Yc1 + Yc2) / 2.) * (1. - + (yscale1 / + CTX.s[1]))); Draw(); } - diff --git a/Graphics/Entity.cpp b/Graphics/Entity.cpp index d3f17c62d704e0eeee8a71445c97515b709ef2a7..1900707d022b51cf61e010d46c25175e5a3dff34 100644 --- a/Graphics/Entity.cpp +++ b/Graphics/Entity.cpp @@ -1,4 +1,4 @@ -// $Id: Entity.cpp,v 1.25 2003-01-23 20:19:20 geuzaine Exp $ +// $Id: Entity.cpp,v 1.26 2003-03-01 22:36:39 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -26,24 +26,28 @@ #include "Draw.h" #include "Context.h" -extern Context_T CTX; +extern Context_T CTX; -void Draw_Point (int type, double size, double *x, double *y, double *z, double Raise[3][8]){ - if(type){ - Draw_Sphere(size, x[0]+Raise[0][0], y[0]+Raise[1][0], z[0]+Raise[2][0]); +void Draw_Point(int type, double size, double *x, double *y, double *z, + double Raise[3][8]) +{ + if(type) { + Draw_Sphere(size, x[0] + Raise[0][0], y[0] + Raise[1][0], + z[0] + Raise[2][0]); } - else{ + else { glBegin(GL_POINTS); - glVertex3d(x[0]+Raise[0][0], y[0]+Raise[1][0], z[0]+Raise[2][0]); + glVertex3d(x[0] + Raise[0][0], y[0] + Raise[1][0], z[0] + Raise[2][0]); glEnd(); } } -void Draw_Sphere (double size, double x, double y, double z){ +void Draw_Sphere(double size, double x, double y, double z) +{ static GLUquadricObj *qua; static int first = 1, listnum; - float s = size*CTX.pixel_equiv_x/CTX.s[0]; // size is in pixels - if(first){ + float s = size * CTX.pixel_equiv_x / CTX.s[0]; // size is in pixels + if(first) { first = 0; qua = gluNewQuadric(); listnum = glGenLists(1); @@ -51,21 +55,22 @@ void Draw_Sphere (double size, double x, double y, double z){ gluSphere(qua, 1, CTX.quadric_subdivisions, CTX.quadric_subdivisions); glEndList(); } - glPushMatrix(); - glTranslatef(x,y,z); - glScalef(s,s,s); + glPushMatrix(); + glTranslatef(x, y, z); + glScalef(s, s, s); glCallList(listnum); glPopMatrix(); } -void Draw_Cylinder (double width, double *x, double *y, double *z){ +void Draw_Cylinder(double width, double *x, double *y, double *z) +{ double mat[4][4], r[3]; static GLUquadricObj *qua; static int first = 1; //static listnum; - float s = width*CTX.pixel_equiv_x/CTX.s[0]; // width is in pixels - if(first){ + float s = width * CTX.pixel_equiv_x / CTX.s[0]; // width is in pixels + if(first) { first = 0; qua = gluNewQuadric(); //listnum = glGenLists(1); @@ -74,53 +79,56 @@ void Draw_Cylinder (double width, double *x, double *y, double *z){ //glEndList(); } - r[0] = x[1]-x[0]; r[1] = y[1]-y[0]; r[2] = z[1]-z[0]; - double rn = sqrt(SQR(r[0])+SQR(r[1])+SQR(r[2])); - double theta = atan2( sqrt(SQR(r[0])+SQR(r[1])) , r[2] ) ; - double phi = atan2( r[1] , r[0] ) ; - - mat[0][0] = sin(theta) * cos(phi) ; - mat[0][1] = sin(theta) * sin(phi) ; - mat[0][2] = cos(theta) ; - mat[0][3] = 0. ; - mat[1][0] = cos(theta) * cos(phi) ; - mat[1][1] = cos(theta) * sin(phi) ; - mat[1][2] = - sin(theta) ; - mat[1][3] = 0. ; - mat[2][0] = - sin(phi) ; - mat[2][1] = cos(phi) ; - mat[2][2] = 0. ; - mat[2][3] = 0. ; - mat[3][0] = 0. ; - mat[3][1] = 0. ; - mat[3][2] = 0. ; - mat[3][3] = 1.0 ; - - glPushMatrix(); - glTranslated(x[0],y[0],z[0]); + r[0] = x[1] - x[0]; + r[1] = y[1] - y[0]; + r[2] = z[1] - z[0]; + double rn = sqrt(SQR(r[0]) + SQR(r[1]) + SQR(r[2])); + double theta = atan2(sqrt(SQR(r[0]) + SQR(r[1])), r[2]); + double phi = atan2(r[1], r[0]); + + mat[0][0] = sin(theta) * cos(phi); + mat[0][1] = sin(theta) * sin(phi); + mat[0][2] = cos(theta); + mat[0][3] = 0.; + mat[1][0] = cos(theta) * cos(phi); + mat[1][1] = cos(theta) * sin(phi); + mat[1][2] = -sin(theta); + mat[1][3] = 0.; + mat[2][0] = -sin(phi); + mat[2][1] = cos(phi); + mat[2][2] = 0.; + mat[2][3] = 0.; + mat[3][0] = 0.; + mat[3][1] = 0.; + mat[3][2] = 0.; + mat[3][3] = 1.0; + + glPushMatrix(); + glTranslated(x[0], y[0], z[0]); glMultMatrixd(&(mat[0][0])); glRotated(90., 0, 1, 0); - glScaled(s,s,rn); + glScaled(s, s, rn); //glCallList(listnum); gluCylinder(qua, 1, 1, 1, CTX.quadric_subdivisions, 1); glPopMatrix(); } -void Draw_Line (int type, double width, double *x, double *y, double *z, - double Raise[3][8]){ +void Draw_Line(int type, double width, double *x, double *y, double *z, + double Raise[3][8]) +{ double X[2], Y[2], Z[2]; - - X[0] = x[0]+Raise[0][0]; - Y[0] = y[0]+Raise[1][0]; - Z[0] = z[0]+Raise[2][0]; - X[1] = x[1]+Raise[0][1]; - Y[1] = y[1]+Raise[1][1]; - Z[1] = z[1]+Raise[2][1]; + X[0] = x[0] + Raise[0][0]; + Y[0] = y[0] + Raise[1][0]; + Z[0] = z[0] + Raise[2][0]; + + X[1] = x[1] + Raise[0][1]; + Y[1] = y[1] + Raise[1][1]; + Z[1] = z[1] + Raise[2][1]; if(type) Draw_Cylinder(width, X, Y, Z); - else{ + else { glBegin(GL_LINES); glVertex3d(X[0], Y[0], Z[0]); glVertex3d(X[1], Y[1], Z[1]); @@ -128,54 +136,55 @@ void Draw_Line (int type, double width, double *x, double *y, double *z, } } -void Draw_Triangle (double *x, double *y, double *z, double *n, - double Raise[3][8], int shade){ - +void Draw_Triangle(double *x, double *y, double *z, double *n, + double Raise[3][8], int shade) +{ double x1x0, y1y0, z1z0, x2x0, y2y0, z2z0, nn[3]; glBegin(GL_TRIANGLES); - if (shade){ - if(!n){ - x1x0 = (x[1]+Raise[0][1]) - (x[0]+Raise[0][0]); - y1y0 = (y[1]+Raise[1][1]) - (y[0]+Raise[1][0]); - z1z0 = (z[1]+Raise[2][1]) - (z[0]+Raise[2][0]); - x2x0 = (x[2]+Raise[0][2]) - (x[0]+Raise[0][0]); - y2y0 = (y[2]+Raise[1][2]) - (y[0]+Raise[1][0]); - z2z0 = (z[2]+Raise[2][2]) - (z[0]+Raise[2][0]); - nn[0] = y1y0 * z2z0 - z1z0 * y2y0 ; - nn[1] = z1z0 * x2x0 - x1x0 * z2z0 ; - nn[2] = x1x0 * y2y0 - y1y0 * x2x0 ; + if(shade) { + if(!n) { + x1x0 = (x[1] + Raise[0][1]) - (x[0] + Raise[0][0]); + y1y0 = (y[1] + Raise[1][1]) - (y[0] + Raise[1][0]); + z1z0 = (z[1] + Raise[2][1]) - (z[0] + Raise[2][0]); + x2x0 = (x[2] + Raise[0][2]) - (x[0] + Raise[0][0]); + y2y0 = (y[2] + Raise[1][2]) - (y[0] + Raise[1][0]); + z2z0 = (z[2] + Raise[2][2]) - (z[0] + Raise[2][0]); + nn[0] = y1y0 * z2z0 - z1z0 * y2y0; + nn[1] = z1z0 * x2x0 - x1x0 * z2z0; + nn[2] = x1x0 * y2y0 - y1y0 * x2x0; //norme(nn); not necessary if GL_NORMALIZE is enabled glNormal3dv(nn); } else glNormal3dv(&n[0]); } - - glVertex3d(x[0]+Raise[0][0], y[0]+Raise[1][0], z[0]+Raise[2][0]); - if (shade && n) + glVertex3d(x[0] + Raise[0][0], y[0] + Raise[1][0], z[0] + Raise[2][0]); + + if(shade && n) glNormal3dv(&n[3]); - glVertex3d(x[1]+Raise[0][1], y[1]+Raise[1][1], z[1]+Raise[2][1]); + glVertex3d(x[1] + Raise[0][1], y[1] + Raise[1][1], z[1] + Raise[2][1]); - if (shade && n) + if(shade && n) glNormal3dv(&n[6]); - glVertex3d(x[2]+Raise[0][2], y[2]+Raise[1][2], z[2]+Raise[2][2]); + glVertex3d(x[2] + Raise[0][2], y[2] + Raise[1][2], z[2] + Raise[2][2]); glEnd(); } -void Draw_Quadrangle (double *x, double *y, double *z, double *n, - double Raise[3][8], int shade){ - double x2[3]={x[2],x[3],x[0]}; - double y2[3]={y[2],y[3],y[0]}; - double z2[3]={z[2],z[3],z[0]}; +void Draw_Quadrangle(double *x, double *y, double *z, double *n, + double Raise[3][8], int shade) +{ + double x2[3] = { x[2], x[3], x[0] }; + double y2[3] = { y[2], y[3], y[0] }; + double z2[3] = { z[2], z[3], z[0] }; - Draw_Triangle(x,y,z,n,Raise,shade); - if (n){ - double n2[9]; + Draw_Triangle(x, y, z, n, Raise, shade); + if(n) { + double n2[9]; n2[0] = n[6]; n2[1] = n[7]; n2[2] = n[8]; @@ -185,242 +194,276 @@ void Draw_Quadrangle (double *x, double *y, double *z, double *n, n2[6] = n[0]; n2[7] = n[1]; n2[8] = n[2]; - Draw_Triangle(x2,y2,z2,n2,Raise,shade); + Draw_Triangle(x2, y2, z2, n2, Raise, shade); } else - Draw_Triangle(x2,y2,z2,n,Raise,shade); + Draw_Triangle(x2, y2, z2, n, Raise, shade); } -void Draw_Vector (int Type, int Fill, - double x, double y, double z, - double d, double dx, double dy, double dz, - double Raise[3][8]){ +void Draw_Vector(int Type, int Fill, + double x, double y, double z, + double d, double dx, double dy, double dz, + double Raise[3][8]) +{ + double n[3], t[3], u[3]; + double l, b, c, f1, f2; - double n[3],t[3],u[3]; - double l,b,c, f1, f2; + if(d == 0.0) + return; - if(d == 0.0) return; - - if(Raise != NULL){ - x += Raise[0][0] ; - y += Raise[1][0] ; - z += Raise[2][0] ; + if(Raise != NULL) { + x += Raise[0][0]; + y += Raise[1][0]; + z += Raise[2][0]; } - if(Type == DRAW_POST_SEGMENT){ + if(Type == DRAW_POST_SEGMENT) { glBegin(GL_LINES); - glVertex3d(x, y, z); - glVertex3d(x+dx, y+dy, z+dz); + glVertex3d(x, y, z); + glVertex3d(x + dx, y + dy, z + dz); glEnd(); return; } - n[0] = dx/d ; n[1] = dy/d ; n[2] = dz/d ; - - if( (fabs(n[0]) >= fabs(n[1]) && fabs(n[0]) >= fabs(n[2])) || - (fabs(n[1]) >= fabs(n[0]) && fabs(n[1]) >= fabs(n[2])) ){ - t[0] = n[1] ; t[1] = -n[0] ; t[2] = 0. ; + n[0] = dx / d; + n[1] = dy / d; + n[2] = dz / d; + + if((fabs(n[0]) >= fabs(n[1]) && fabs(n[0]) >= fabs(n[2])) || + (fabs(n[1]) >= fabs(n[0]) && fabs(n[1]) >= fabs(n[2]))) { + t[0] = n[1]; + t[1] = -n[0]; + t[2] = 0.; } - else{ - t[0] = 0. ; t[1] = n[2] ; t[2] = -n[1] ; + else { + t[0] = 0.; + t[1] = n[2]; + t[2] = -n[1]; } - l = sqrt(t[0]*t[0]+t[1]*t[1]+t[2]*t[2]); - t[0] /= l ; t[1] /= l ; t[2] /= l ; + l = sqrt(t[0] * t[0] + t[1] * t[1] + t[2] * t[2]); + t[0] /= l; + t[1] /= l; + t[2] /= l; - u[0] = n[1]*t[2]-n[2]*t[1]; - u[1] = n[2]*t[0]-n[0]*t[2]; - u[2] = n[0]*t[1]-n[1]*t[0]; + u[0] = n[1] * t[2] - n[2] * t[1]; + u[1] = n[2] * t[0] - n[0] * t[2]; + u[2] = n[0] * t[1] - n[1] * t[0]; - l = sqrt(u[0]*u[0]+u[1]*u[1]+u[2]*u[2]); - u[0] /= l ; u[1] /= l ; u[2] /= l ; + l = sqrt(u[0] * u[0] + u[1] * u[1] + u[2] * u[2]); + u[0] /= l; + u[1] /= l; + u[2] /= l; - switch(Type){ + switch (Type) { - case DRAW_POST_ARROW : + case DRAW_POST_ARROW: b = 0.0666 * d; - f1 = 0.85 ; - f2 = 0.8 ; + f1 = 0.85; + f2 = 0.8; + + b *= 2; + f1 /= 1.5; + f2 /= 1.5; - b *= 2 ; - f1 /= 1.5 ; - f2 /= 1.5 ; - - if(Fill){ + if(Fill) { glBegin(GL_LINES); - glVertex3d(x, y, z); - glVertex3d(x+dx, y+dy, z+dz); + glVertex3d(x, y, z); + glVertex3d(x + dx, y + dy, z + dz); glEnd(); - + glBegin(GL_TRIANGLES); - glVertex3d(x+dx, y+dy, z+dz); - glVertex3d(x+f2*dx+b*(t[0]), y+f2*dy+b*(t[1]), z+f2*dz+b*(t[2])); - glVertex3d(x+f1*dx, y+f1*dy, z+f1*dz); - - glVertex3d(x+dx, y+dy, z+dz); - glVertex3d(x+f2*dx+b*(-t[0]), y+f2*dy+b*(-t[1]), z+f2*dz+b*(-t[2])); - glVertex3d(x+f1*dx, y+f1*dy, z+f1*dz); - - glVertex3d(x+dx, y+dy, z+dz); - glVertex3d(x+f2*dx+b*(-u[0]), y+f2*dy+b*(-u[1]), z+f2*dz+b*(-u[2])); - glVertex3d(x+f1*dx, y+f1*dy, z+f1*dz); - - glVertex3d(x+dx, y+dy, z+dz); - glVertex3d(x+f2*dx+b*(u[0]), y+f2*dy+b*(u[1]), z+f2*dz+b*(u[2])); - glVertex3d(x+f1*dx, y+f1*dy, z+f1*dz); + glVertex3d(x + dx, y + dy, z + dz); + glVertex3d(x + f2 * dx + b * (t[0]), y + f2 * dy + b * (t[1]), + z + f2 * dz + b * (t[2])); + glVertex3d(x + f1 * dx, y + f1 * dy, z + f1 * dz); + + glVertex3d(x + dx, y + dy, z + dz); + glVertex3d(x + f2 * dx + b * (-t[0]), y + f2 * dy + b * (-t[1]), + z + f2 * dz + b * (-t[2])); + glVertex3d(x + f1 * dx, y + f1 * dy, z + f1 * dz); + + glVertex3d(x + dx, y + dy, z + dz); + glVertex3d(x + f2 * dx + b * (-u[0]), y + f2 * dy + b * (-u[1]), + z + f2 * dz + b * (-u[2])); + glVertex3d(x + f1 * dx, y + f1 * dy, z + f1 * dz); + + glVertex3d(x + dx, y + dy, z + dz); + glVertex3d(x + f2 * dx + b * (u[0]), y + f2 * dy + b * (u[1]), + z + f2 * dz + b * (u[2])); + glVertex3d(x + f1 * dx, y + f1 * dy, z + f1 * dz); glEnd(); } - else{ + else { glBegin(GL_LINE_STRIP); - glVertex3d(x, y, z); - glVertex3d(x+dx, y+dy, z+dz); - glVertex3d(x+f2*dx+b*(t[0]), y+f2*dy+b*(t[1]), z+f2*dz+b*(t[2])); - glVertex3d(x+f1*dx, y+f1*dy, z+f1*dz); - glVertex3d(x+f2*dx+b*(-t[0]), y+f2*dy+b*(-t[1]), z+f2*dz+b*(-t[2])); - glVertex3d(x+dx, y+dy, z+dz); - glVertex3d(x+f2*dx+b*(-u[0]), y+f2*dy+b*(-u[1]), z+f2*dz+b*(-u[2])); - glVertex3d(x+f1*dx, y+f1*dy, z+f1*dz); - glVertex3d(x+f2*dx+b*(u[0]), y+f2*dy+b*(u[1]), z+f2*dz+b*(u[2])); - glVertex3d(x+dx, y+dy, z+dz); + glVertex3d(x, y, z); + glVertex3d(x + dx, y + dy, z + dz); + glVertex3d(x + f2 * dx + b * (t[0]), y + f2 * dy + b * (t[1]), + z + f2 * dz + b * (t[2])); + glVertex3d(x + f1 * dx, y + f1 * dy, z + f1 * dz); + glVertex3d(x + f2 * dx + b * (-t[0]), y + f2 * dy + b * (-t[1]), + z + f2 * dz + b * (-t[2])); + glVertex3d(x + dx, y + dy, z + dz); + glVertex3d(x + f2 * dx + b * (-u[0]), y + f2 * dy + b * (-u[1]), + z + f2 * dz + b * (-u[2])); + glVertex3d(x + f1 * dx, y + f1 * dy, z + f1 * dz); + glVertex3d(x + f2 * dx + b * (u[0]), y + f2 * dy + b * (u[1]), + z + f2 * dz + b * (u[2])); + glVertex3d(x + dx, y + dy, z + dz); glEnd(); } - break ; - - case DRAW_POST_PYRAMID : + break; + + case DRAW_POST_PYRAMID: b = .1333 * d; - - if(Fill){ + + if(Fill) { glBegin(GL_TRIANGLES); - glVertex3d(x+dx, y+dy, z+dz); - glVertex3d(x+b*(t[0]), y+b*(t[1]), z+b*(t[2])); - glVertex3d(x+b*(-u[0]), y+b*(-u[1]), z+b*(-u[2])); - - glVertex3d(x+dx, y+dy, z+dz); - glVertex3d(x+b*(-u[0]), y+b*(-u[1]), z+b*(-u[2])); - glVertex3d(x+b*(-t[0]), y+b*(-t[1]), z+b*(-t[2])); - - glVertex3d(x+dx, y+dy, z+dz); - glVertex3d(x+b*(-t[0]), y+b*(-t[1]), z+b*(-t[2])); - glVertex3d(x+b*(u[0]), y+b*(u[1]), z+b*(u[2])); - - glVertex3d(x+dx, y+dy, z+dz); - glVertex3d(x+b*(u[0]), y+b*(u[1]), z+b*(u[2])); - glVertex3d(x+b*(t[0]), y+b*(t[1]), z+b*(t[2])); + glVertex3d(x + dx, y + dy, z + dz); + glVertex3d(x + b * (t[0]), y + b * (t[1]), z + b * (t[2])); + glVertex3d(x + b * (-u[0]), y + b * (-u[1]), z + b * (-u[2])); + + glVertex3d(x + dx, y + dy, z + dz); + glVertex3d(x + b * (-u[0]), y + b * (-u[1]), z + b * (-u[2])); + glVertex3d(x + b * (-t[0]), y + b * (-t[1]), z + b * (-t[2])); + + glVertex3d(x + dx, y + dy, z + dz); + glVertex3d(x + b * (-t[0]), y + b * (-t[1]), z + b * (-t[2])); + glVertex3d(x + b * (u[0]), y + b * (u[1]), z + b * (u[2])); + + glVertex3d(x + dx, y + dy, z + dz); + glVertex3d(x + b * (u[0]), y + b * (u[1]), z + b * (u[2])); + glVertex3d(x + b * (t[0]), y + b * (t[1]), z + b * (t[2])); glEnd(); } - else{ + else { glBegin(GL_LINE_LOOP); - glVertex3d(x+b*(t[0]), y+b*(t[1]), z+b*(t[2])); - glVertex3d(x+b*(-u[0]), y+b*(-u[1]), z+b*(-u[2])); - glVertex3d(x+b*(-t[0]), y+b*(-t[1]), z+b*(-t[2])); - glVertex3d(x+b*(u[0]), y+b*(u[1]), z+b*(u[2])); + glVertex3d(x + b * (t[0]), y + b * (t[1]), z + b * (t[2])); + glVertex3d(x + b * (-u[0]), y + b * (-u[1]), z + b * (-u[2])); + glVertex3d(x + b * (-t[0]), y + b * (-t[1]), z + b * (-t[2])); + glVertex3d(x + b * (u[0]), y + b * (u[1]), z + b * (u[2])); glEnd(); - + glBegin(GL_LINES); - glVertex3d(x+b*(t[0]), y+b*(t[1]), z+b*(t[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+b*(-u[0]), y+b*(-u[1]), z+b*(-u[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+b*(-t[0]), y+b*(-t[1]), z+b*(-t[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d (x+b*(u[0]), y+b*(u[1]), z+b*(u[2])); - glVertex3d(x+dx, y+dy, z+dz); + glVertex3d(x + b * (t[0]), y + b * (t[1]), z + b * (t[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + b * (-u[0]), y + b * (-u[1]), z + b * (-u[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + b * (-t[0]), y + b * (-t[1]), z + b * (-t[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + b * (u[0]), y + b * (u[1]), z + b * (u[2])); + glVertex3d(x + dx, y + dy, z + dz); glEnd(); } - break ; + break; - case DRAW_POST_CONE : + case DRAW_POST_CONE: b = .1333 * d; - c = .7071 * b; + c = .7071 * b; - if(Fill){ + if(Fill) { glBegin(GL_TRIANGLES); - glVertex3d(x+b*(t[0]), y+b*(t[1]), z+b*(t[2])); - glVertex3d(x+c*(t[0]-u[0]), y+c*(t[1]-u[1]), z+c*(t[2]-u[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+c*(t[0]-u[0]), y+c*(t[1]-u[1]), z+c*(t[2]-u[2])); - glVertex3d(x+b*(-u[0]), y+b*(-u[1]), z+b*(-u[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+b*(-u[0]), y+b*(-u[1]), z+b*(-u[2])); - glVertex3d(x+c*(-t[0]-u[0]), y+c*(-t[1]-u[1]), z+c*(-t[2]-u[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+c*(-t[0]-u[0]), y+c*(-t[1]-u[1]), z+c*(-t[2]-u[2])); - glVertex3d(x+b*(-t[0]), y+b*(-t[1]), z+b*(-t[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+b*(-t[0]), y+b*(-t[1]), z+b*(-t[2])); - glVertex3d(x+c*(u[0]-t[0]), y+c*(u[1]-t[1]), z+c*(u[2]-t[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+c*(u[0]-t[0]), y+c*(u[1]-t[1]), z+c*(u[2]-t[2])); - glVertex3d(x+b*(u[0]), y+b*(u[1]), z+b*(u[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+b*(u[0]), y+b*(u[1]), z+b*(u[2])); - glVertex3d(x+c*(t[0]+u[0]), y+c*(t[1]+u[1]), z+c*(t[2]+u[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+c*(t[0]+u[0]), y+c*(t[1]+u[1]), z+c*(t[2]+u[2])); - glVertex3d(x+b*(t[0]), y+b*(t[1]), z+b*(t[2])); - glVertex3d(x+dx, y+dy, z+dz); + glVertex3d(x + b * (t[0]), y + b * (t[1]), z + b * (t[2])); + glVertex3d(x + c * (t[0] - u[0]), y + c * (t[1] - u[1]), + z + c * (t[2] - u[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + c * (t[0] - u[0]), y + c * (t[1] - u[1]), + z + c * (t[2] - u[2])); + glVertex3d(x + b * (-u[0]), y + b * (-u[1]), z + b * (-u[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + b * (-u[0]), y + b * (-u[1]), z + b * (-u[2])); + glVertex3d(x + c * (-t[0] - u[0]), y + c * (-t[1] - u[1]), + z + c * (-t[2] - u[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + c * (-t[0] - u[0]), y + c * (-t[1] - u[1]), + z + c * (-t[2] - u[2])); + glVertex3d(x + b * (-t[0]), y + b * (-t[1]), z + b * (-t[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + b * (-t[0]), y + b * (-t[1]), z + b * (-t[2])); + glVertex3d(x + c * (u[0] - t[0]), y + c * (u[1] - t[1]), + z + c * (u[2] - t[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + c * (u[0] - t[0]), y + c * (u[1] - t[1]), + z + c * (u[2] - t[2])); + glVertex3d(x + b * (u[0]), y + b * (u[1]), z + b * (u[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + b * (u[0]), y + b * (u[1]), z + b * (u[2])); + glVertex3d(x + c * (t[0] + u[0]), y + c * (t[1] + u[1]), + z + c * (t[2] + u[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + c * (t[0] + u[0]), y + c * (t[1] + u[1]), + z + c * (t[2] + u[2])); + glVertex3d(x + b * (t[0]), y + b * (t[1]), z + b * (t[2])); + glVertex3d(x + dx, y + dy, z + dz); glEnd(); } - else{ + else { glBegin(GL_LINE_LOOP); - glVertex3d(x+b*(t[0]), y+b*(t[1]), z+b*(t[2])); - glVertex3d(x+c*(t[0]-u[0]), y+c*(t[1]-u[1]), z+c*(t[2]-u[2])); - glVertex3d(x+b*(-u[0]), y+b*(-u[1]), z+b*(-u[2])); - glVertex3d(x+c*(-t[0]-u[0]), y+c*(-t[1]-u[1]), z+c*(-t[2]-u[2])); - glVertex3d(x+b*(-t[0]), y+b*(-t[1]), z+b*(-t[2])); - glVertex3d(x+c*(u[0]-t[0]), y+c*(u[1]-t[1]), z+c*(u[2]-t[2])); - glVertex3d(x+b*(u[0]), y+b*(u[1]), z+b*(u[2])); - glVertex3d(x+c*(t[0]+u[0]), y+c*(t[1]+u[1]), z+c*(t[2]+u[2])); + glVertex3d(x + b * (t[0]), y + b * (t[1]), z + b * (t[2])); + glVertex3d(x + c * (t[0] - u[0]), y + c * (t[1] - u[1]), + z + c * (t[2] - u[2])); + glVertex3d(x + b * (-u[0]), y + b * (-u[1]), z + b * (-u[2])); + glVertex3d(x + c * (-t[0] - u[0]), y + c * (-t[1] - u[1]), + z + c * (-t[2] - u[2])); + glVertex3d(x + b * (-t[0]), y + b * (-t[1]), z + b * (-t[2])); + glVertex3d(x + c * (u[0] - t[0]), y + c * (u[1] - t[1]), + z + c * (u[2] - t[2])); + glVertex3d(x + b * (u[0]), y + b * (u[1]), z + b * (u[2])); + glVertex3d(x + c * (t[0] + u[0]), y + c * (t[1] + u[1]), + z + c * (t[2] + u[2])); glEnd(); - + glBegin(GL_LINES); - glVertex3d(x+b*(t[0]), y+b*(t[1]), z+b*(t[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+c*(t[0]-u[0]), y+c*(t[1]-u[1]), z+c*(t[2]-u[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+b*(-u[0]), y+b*(-u[1]), z+b*(-u[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+c*(-t[0]-u[0]), y+c*(-t[1]-u[1]), z+c*(-t[2]-u[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+b*(-t[0]), y+b*(-t[1]), z+b*(-t[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+c*(u[0]-t[0]), y+c*(u[1]-t[1]), z+c*(u[2]-t[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+b*(u[0]), y+b*(u[1]), z+b*(u[2])); - glVertex3d(x+dx, y+dy, z+dz); - - glVertex3d(x+c*(t[0]+u[0]), y+c*(t[1]+u[1]), z+c*(t[2]+u[2])); - glVertex3d(x+dx, y+dy, z+dz); + glVertex3d(x + b * (t[0]), y + b * (t[1]), z + b * (t[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + c * (t[0] - u[0]), y + c * (t[1] - u[1]), + z + c * (t[2] - u[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + b * (-u[0]), y + b * (-u[1]), z + b * (-u[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + c * (-t[0] - u[0]), y + c * (-t[1] - u[1]), + z + c * (-t[2] - u[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + b * (-t[0]), y + b * (-t[1]), z + b * (-t[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + c * (u[0] - t[0]), y + c * (u[1] - t[1]), + z + c * (u[2] - t[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + b * (u[0]), y + b * (u[1]), z + b * (u[2])); + glVertex3d(x + dx, y + dy, z + dz); + + glVertex3d(x + c * (t[0] + u[0]), y + c * (t[1] + u[1]), + z + c * (t[2] + u[2])); + glVertex3d(x + dx, y + dy, z + dz); glEnd(); } - break ; + break; - default : + default: //Msg(GERROR, "Unknown type of vector to draw"); break; } - -} +} diff --git a/Graphics/Geom.cpp b/Graphics/Geom.cpp index 5c88d41099e721273e62c2acf4d9c9c7a7aa069e..4b8610f84b67967dafaeb126a63fa542049ab57a 100644 --- a/Graphics/Geom.cpp +++ b/Graphics/Geom.cpp @@ -1,4 +1,4 @@ -// $Id: Geom.cpp,v 1.43 2003-02-25 04:02:50 geuzaine Exp $ +// $Id: Geom.cpp,v 1.44 2003-03-01 22:36:39 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -32,66 +32,68 @@ #include "STL.h" #include "gl2ps.h" -extern Context_T CTX; -extern Mesh *THEM; +extern Context_T CTX; +extern Mesh *THEM; // Points -static int Highlighted = 0; +static int Highlighted = 0; -void Draw_GeoPoint (void *a, void *b){ +void Draw_GeoPoint(void *a, void *b) +{ Vertex *v; char Num[100]; - v = *(Vertex**)a; + v = *(Vertex **) a; - if(!(v->Visible & VIS_GEOM)) return; + if(!(v->Visible & VIS_GEOM)) + return; - if(CTX.render_mode == GMSH_SELECT){ + if(CTX.render_mode == GMSH_SELECT) { glLoadName(0); glPushName(v->Num); } - if(v->Frozen){ - glPointSize(CTX.geom.point_sel_size); + if(v->Frozen) { + glPointSize(CTX.geom.point_sel_size); gl2psPointSize(CTX.geom.point_sel_size * CTX.print.eps_point_size_factor); - glColor4ubv((GLubyte*)&CTX.color.geom.point_sel); + glColor4ubv((GLubyte *) & CTX.color.geom.point_sel); } - else if(Highlighted){ + else if(Highlighted) { glPointSize(CTX.geom.point_sel_size); gl2psPointSize(CTX.geom.point_sel_size * CTX.print.eps_point_size_factor); - glColor4ubv((GLubyte*)&CTX.color.geom.point_hlt); + glColor4ubv((GLubyte *) & CTX.color.geom.point_hlt); } - else{ + else { glPointSize(CTX.geom.point_size); gl2psPointSize(CTX.geom.point_size * CTX.print.eps_point_size_factor); - glColor4ubv((GLubyte*)&CTX.color.geom.point); + glColor4ubv((GLubyte *) & CTX.color.geom.point); } - if(CTX.geom.points){ + if(CTX.geom.points) { - if(CTX.geom.point_type){ + if(CTX.geom.point_type) { if(v->Frozen || Highlighted) - Draw_Sphere(CTX.geom.point_sel_size, v->Pos.X, v->Pos.Y, v->Pos.Z); + Draw_Sphere(CTX.geom.point_sel_size, v->Pos.X, v->Pos.Y, v->Pos.Z); else - Draw_Sphere(CTX.geom.point_size, v->Pos.X, v->Pos.Y, v->Pos.Z); + Draw_Sphere(CTX.geom.point_size, v->Pos.X, v->Pos.Y, v->Pos.Z); } - else{ + else { glBegin(GL_POINTS); glVertex3d(v->Pos.X, v->Pos.Y, v->Pos.Z); glEnd(); } } - if(CTX.geom.points_num){ - sprintf(Num,"%d",v->Num); - glRasterPos3d(v->Pos.X+3*CTX.pixel_equiv_x/CTX.s[0], - v->Pos.Y+3*CTX.pixel_equiv_x/CTX.s[1], - v->Pos.Z+3*CTX.pixel_equiv_x/CTX.s[2]); + if(CTX.geom.points_num) { + sprintf(Num, "%d", v->Num); + glRasterPos3d(v->Pos.X + 3 * CTX.pixel_equiv_x / CTX.s[0], + v->Pos.Y + 3 * CTX.pixel_equiv_x / CTX.s[1], + v->Pos.Z + 3 * CTX.pixel_equiv_x / CTX.s[2]); Draw_String(Num); } - if(CTX.render_mode == GMSH_SELECT){ + if(CTX.render_mode == GMSH_SELECT) { glPopName(); } @@ -99,228 +101,248 @@ void Draw_GeoPoint (void *a, void *b){ // Curves -void Draw_Curve (void *a, void *b){ - int i,N; - double mod,dd,x[2],y[2],z[2]; - char Num[100]; - Curve *c; - Vertex v,dv; +void Draw_Curve(void *a, void *b) +{ + int i, N; + double mod, dd, x[2], y[2], z[2]; + char Num[100]; + Curve *c; + Vertex v, dv; - c = *(Curve**)a; + c = *(Curve **) a; - if(c->Num<0 || !(c->Visible & VIS_GEOM) || c->Dirty) return; + if(c->Num < 0 || !(c->Visible & VIS_GEOM) || c->Dirty) + return; - if(CTX.render_mode == GMSH_SELECT){ + if(CTX.render_mode == GMSH_SELECT) { glLoadName(1); glPushName(c->Num); } - if((c)->ipar[3]){ + if((c)->ipar[3]) { glLineWidth(CTX.geom.line_sel_width); gl2psLineWidth(CTX.geom.line_sel_width * CTX.print.eps_line_width_factor); - glColor4ubv((GLubyte*)&CTX.color.geom.line_sel); + glColor4ubv((GLubyte *) & CTX.color.geom.line_sel); } - else if(Highlighted){ - glLineWidth(CTX.geom.line_sel_width); + else if(Highlighted) { + glLineWidth(CTX.geom.line_sel_width); gl2psLineWidth(CTX.geom.line_sel_width * CTX.print.eps_line_width_factor); - glColor4ubv((GLubyte*)&CTX.color.geom.line_hlt); + glColor4ubv((GLubyte *) & CTX.color.geom.line_hlt); } - else{ + else { glLineWidth(CTX.geom.line_width); gl2psLineWidth(CTX.geom.line_width * CTX.print.eps_line_width_factor); - glColor4ubv((GLubyte*)&CTX.color.geom.line); + glColor4ubv((GLubyte *) & CTX.color.geom.line); } - if(CTX.geom.lines){ - + if(CTX.geom.lines) { + int n = List_Nbr(c->Control_Points); - switch(c->Typ){ - case MSH_SEGM_LINE : - N = n; + switch (c->Typ) { + case MSH_SEGM_LINE: + N = n; break; - case MSH_SEGM_CIRC : - case MSH_SEGM_CIRC_INV : - case MSH_SEGM_ELLI : - case MSH_SEGM_ELLI_INV : + case MSH_SEGM_CIRC: + case MSH_SEGM_CIRC_INV: + case MSH_SEGM_ELLI: + case MSH_SEGM_ELLI_INV: N = CTX.geom.circle_points; break; - default : + default: N = 10 * n; break; } - if(c->Typ == MSH_SEGM_DISCRETE){ + if(c->Typ == MSH_SEGM_DISCRETE) { Simplex *s; List_T *temp = Tree2List(c->Simplexes); - for(i=0;i<List_Nbr(temp);i++){ - List_Read(temp,i,&s); - glBegin(GL_LINE_STRIP); - glVertex3d(s->V[0]->Pos.X,s->V[0]->Pos.Y,s->V[0]->Pos.Z); - glVertex3d(s->V[1]->Pos.X,s->V[1]->Pos.Y,s->V[1]->Pos.Z); - glEnd(); + for(i = 0; i < List_Nbr(temp); i++) { + List_Read(temp, i, &s); + glBegin(GL_LINE_STRIP); + glVertex3d(s->V[0]->Pos.X, s->V[0]->Pos.Y, s->V[0]->Pos.Z); + glVertex3d(s->V[1]->Pos.X, s->V[1]->Pos.Y, s->V[1]->Pos.Z); + glEnd(); } List_Delete(temp); } - else{ - if(CTX.geom.line_type){ - for(i=0;i<N-1;i++){ - v = InterpolateCurve(c,(double)i/(double)(N-1),0); - dv = InterpolateCurve(c,(double)(i+1)/(double)(N-1),0); - x[0] = v.Pos.X; y[0] = v.Pos.Y; z[0] = v.Pos.Z; - x[1] = dv.Pos.X; y[1] = dv.Pos.Y; z[1] = dv.Pos.Z; - Draw_Cylinder(CTX.geom.line_width,x,y,z); - } + else { + if(CTX.geom.line_type) { + for(i = 0; i < N - 1; i++) { + v = InterpolateCurve(c, (double)i / (double)(N - 1), 0); + dv = InterpolateCurve(c, (double)(i + 1) / (double)(N - 1), 0); + x[0] = v.Pos.X; + y[0] = v.Pos.Y; + z[0] = v.Pos.Z; + x[1] = dv.Pos.X; + y[1] = dv.Pos.Y; + z[1] = dv.Pos.Z; + Draw_Cylinder(CTX.geom.line_width, x, y, z); + } } - else{ - glBegin(GL_LINE_STRIP); - for(i=0;i<N;i++){ - v = InterpolateCurve(c,(double)i/(double)(N-1),0); - glVertex3d(v.Pos.X,v.Pos.Y,v.Pos.Z); - } - glEnd(); + else { + glBegin(GL_LINE_STRIP); + for(i = 0; i < N; i++) { + v = InterpolateCurve(c, (double)i / (double)(N - 1), 0); + glVertex3d(v.Pos.X, v.Pos.Y, v.Pos.Z); + } + glEnd(); } } } - if(CTX.geom.lines_num){ - v = InterpolateCurve(c,0.5,0); - sprintf(Num,"%d",c->Num); - glRasterPos3d(v.Pos.X+3*CTX.pixel_equiv_x/CTX.s[0], - v.Pos.Y+3*CTX.pixel_equiv_x/CTX.s[1], - v.Pos.Z+3*CTX.pixel_equiv_x/CTX.s[2]); + if(CTX.geom.lines_num) { + v = InterpolateCurve(c, 0.5, 0); + sprintf(Num, "%d", c->Num); + glRasterPos3d(v.Pos.X + 3 * CTX.pixel_equiv_x / CTX.s[0], + v.Pos.Y + 3 * CTX.pixel_equiv_x / CTX.s[1], + v.Pos.Z + 3 * CTX.pixel_equiv_x / CTX.s[2]); Draw_String(Num); } - - if(CTX.geom.tangents){ - v = InterpolateCurve(c,0.5,0); - dv = InterpolateCurve(c,0.5,1); - mod = sqrt(dv.Pos.X*dv.Pos.X+dv.Pos.Y*dv.Pos.Y+dv.Pos.Z*dv.Pos.Z); - dv.Pos.X = dv.Pos.X / mod * CTX.geom.tangents * CTX.pixel_equiv_x/CTX.s[0] ; - dv.Pos.Y = dv.Pos.Y / mod * CTX.geom.tangents * CTX.pixel_equiv_x/CTX.s[1] ; - dv.Pos.Z = dv.Pos.Z / mod * CTX.geom.tangents * CTX.pixel_equiv_x/CTX.s[2] ; - dd = sqrt(dv.Pos.X*dv.Pos.X+dv.Pos.Y*dv.Pos.Y+dv.Pos.Z*dv.Pos.Z); - glColor4ubv((GLubyte*)&CTX.color.geom.tangents); - Draw_Vector(DRAW_POST_ARROW, 0, v.Pos.X,v.Pos.Y,v.Pos.Z, - dd, dv.Pos.X,dv.Pos.Y,dv.Pos.Z, NULL); - } - if(CTX.render_mode == GMSH_SELECT){ - glPopName (); + if(CTX.geom.tangents) { + v = InterpolateCurve(c, 0.5, 0); + dv = InterpolateCurve(c, 0.5, 1); + mod = + sqrt(dv.Pos.X * dv.Pos.X + dv.Pos.Y * dv.Pos.Y + dv.Pos.Z * dv.Pos.Z); + dv.Pos.X = + dv.Pos.X / mod * CTX.geom.tangents * CTX.pixel_equiv_x / CTX.s[0]; + dv.Pos.Y = + dv.Pos.Y / mod * CTX.geom.tangents * CTX.pixel_equiv_x / CTX.s[1]; + dv.Pos.Z = + dv.Pos.Z / mod * CTX.geom.tangents * CTX.pixel_equiv_x / CTX.s[2]; + dd = + sqrt(dv.Pos.X * dv.Pos.X + dv.Pos.Y * dv.Pos.Y + dv.Pos.Z * dv.Pos.Z); + glColor4ubv((GLubyte *) & CTX.color.geom.tangents); + Draw_Vector(DRAW_POST_ARROW, 0, v.Pos.X, v.Pos.Y, v.Pos.Z, + dd, dv.Pos.X, dv.Pos.Y, dv.Pos.Z, NULL); + } + + if(CTX.render_mode == GMSH_SELECT) { + glPopName(); } } // Surfaces -void put_Z (Vertex *v, Surface *s){ +void put_Z(Vertex * v, Surface * s) +{ Vertex V; V.Pos.X = s->a; V.Pos.Y = s->b; - V.Pos.Z = s->c; - Projette(&V,s->plan); + V.Pos.Z = s->c; + Projette(&V, s->plan); if(V.Pos.Z != 0.0) - v->Pos.Z = (s->d - V.Pos.X * v->Pos.X - V.Pos.Y * v->Pos.Y)/V.Pos.Z; - else v->Pos.Z = 0.0; + v->Pos.Z = (s->d - V.Pos.X * v->Pos.X - V.Pos.Y * v->Pos.Y) / V.Pos.Z; + else + v->Pos.Z = 0.0; - Projette(v,s->invplan); + Projette(v, s->invplan); } -int isPointOnPlanarSurface (Surface *S, double X, double Y, double Z, double n[3]){ +int isPointOnPlanarSurface(Surface * S, double X, double Y, double Z, + double n[3]) +{ Curve *C; - Vertex V,P1,P2; - int i,j,N; - double Angle,u1,u2; + Vertex V, P1, P2; + int i, j, N; + double Angle, u1, u2; Angle = 0.0; V.Pos.X = X; V.Pos.Y = Y; V.Pos.Z = Z; - for(i=0;i<List_Nbr(S->Generatrices);i++){ + for(i = 0; i < List_Nbr(S->Generatrices); i++) { - List_Read(S->Generatrices,i,&C); + List_Read(S->Generatrices, i, &C); if(C->Typ == MSH_SEGM_LINE) N = 1; else N = 10; - for(j=0;j<N;j++){ - u1 = (double)j/(double)(N); - u2 = (double)(j+1)/(double)(N); - P1 = InterpolateCurve(C,u1,0); - P2 = InterpolateCurve(C,u2,0); - Angle += angle_plan(&V,&P1,&P2,n); + for(j = 0; j < N; j++) { + u1 = (double)j / (double)(N); + u2 = (double)(j + 1) / (double)(N); + P1 = InterpolateCurve(C, u1, 0); + P2 = InterpolateCurve(C, u2, 0); + Angle += angle_plan(&V, &P1, &P2, n); } } //printf(" %d -> angle %g\n", S->Num, fabs(Angle)); - if(fabs(Angle) > 6.0 && fabs(Angle) < 7.0) // Should be 2 * Pi or 0 + if(fabs(Angle) > 6.0 && fabs(Angle) < 7.0) // Should be 2 * Pi or 0 return 1; return 0; } -void Draw_Plane_Surface (Surface *s){ - int i, j, k; - Curve *c; - double minx=0., miny=0., maxx=0., maxy=0., t, n[3], nn; - Vertex P1, P2, P3, V[4], vv, vv1, vv2; - char Num[100]; +void Draw_Plane_Surface(Surface * s) +{ + int i, j, k; + Curve *c; + double minx = 0., miny = 0., maxx = 0., maxy = 0., t, n[3], nn; + Vertex P1, P2, P3, V[4], vv, vv1, vv2; + char Num[100]; - static List_T *points; - static int deb=1; + static List_T *points; + static int deb = 1; - if(!s->Orientations){ + if(!s->Orientations) { - s->Orientations = List_Create(20,2,sizeof(Vertex)); + s->Orientations = List_Create(20, 2, sizeof(Vertex)); - if(deb){ - points = List_Create(10,10,sizeof(Vertex*)); + if(deb) { + points = List_Create(10, 10, sizeof(Vertex *)); deb = 0; } else List_Reset(points); - for(i=0;i<List_Nbr(s->Generatrices);i++){ - List_Read(s->Generatrices,i,&c); - for(j=0;j<List_Nbr(c->Control_Points);j++){ - List_Add(points,List_Pointer(c->Control_Points,j)); + for(i = 0; i < List_Nbr(s->Generatrices); i++) { + List_Read(s->Generatrices, i, &c); + for(j = 0; j < List_Nbr(c->Control_Points); j++) { + List_Add(points, List_Pointer(c->Control_Points, j)); } } MeanPlane(points, s); k = 0; - - for(i=0;i<List_Nbr(s->Generatrices);i++){ - List_Read (s->Generatrices,i,&c); - P1 = InterpolateCurve(c,0.0,0); - P2 = InterpolateCurve(c,0.5,0); - P3 = InterpolateCurve(c,1.0,0); - Projette(&P1,s->plan); - Projette(&P2,s->plan); - Projette(&P3,s->plan); - if(!k){ + + for(i = 0; i < List_Nbr(s->Generatrices); i++) { + List_Read(s->Generatrices, i, &c); + P1 = InterpolateCurve(c, 0.0, 0); + P2 = InterpolateCurve(c, 0.5, 0); + P3 = InterpolateCurve(c, 1.0, 0); + Projette(&P1, s->plan); + Projette(&P2, s->plan); + Projette(&P3, s->plan); + if(!k) { k = 1; minx = maxx = P1.Pos.X; miny = maxy = P1.Pos.Y; } - minx = DMIN(DMIN(DMIN(minx,P1.Pos.X),P2.Pos.X),P3.Pos.X); - miny = DMIN(DMIN(DMIN(miny,P1.Pos.Y),P2.Pos.Y),P3.Pos.Y); - maxx = DMAX(DMAX(DMAX(maxx,P1.Pos.X),P2.Pos.X),P3.Pos.X); - maxy = DMAX(DMAX(DMAX(maxy,P1.Pos.Y),P2.Pos.Y),P3.Pos.Y); + minx = DMIN(DMIN(DMIN(minx, P1.Pos.X), P2.Pos.X), P3.Pos.X); + miny = DMIN(DMIN(DMIN(miny, P1.Pos.Y), P2.Pos.Y), P3.Pos.Y); + maxx = DMAX(DMAX(DMAX(maxx, P1.Pos.X), P2.Pos.X), P3.Pos.X); + maxy = DMAX(DMAX(DMAX(maxy, P1.Pos.Y), P2.Pos.Y), P3.Pos.Y); } - V[0].Pos.X = minx; V[0].Pos.Y = miny; - V[1].Pos.X = maxx; V[1].Pos.Y = miny; - V[2].Pos.X = maxx; V[2].Pos.Y = maxy; - V[3].Pos.X = minx; V[3].Pos.Y = maxy; + V[0].Pos.X = minx; + V[0].Pos.Y = miny; + V[1].Pos.X = maxx; + V[1].Pos.Y = miny; + V[2].Pos.X = maxx; + V[2].Pos.Y = maxy; + V[3].Pos.X = minx; + V[3].Pos.Y = maxy; - for(i=0;i<4;i++){ + for(i = 0; i < 4; i++) { V[i].Pos.Z = 0.0; - put_Z(&V[i],s); + put_Z(&V[i], s); } n[0] = s->plan[2][0]; @@ -329,127 +351,141 @@ void Draw_Plane_Surface (Surface *s){ norme(n); k = 0; - for(i=0;i<100;i++){ - t = (double)i/(double)(100); - vv.Pos.X = t * 0.5 * (V[0].Pos.X + V[1].Pos.X) + (1.-t) * - 0.5 * (V[2].Pos.X + V[3].Pos.X); - vv.Pos.Y = t * 0.5 * (V[0].Pos.Y + V[1].Pos.Y) + (1.-t) * - 0.5 * (V[2].Pos.Y + V[3].Pos.Y); - vv.Pos.Z = t * 0.5 * (V[0].Pos.Z + V[1].Pos.Z) + (1.-t) * - 0.5 * (V[2].Pos.Z + V[3].Pos.Z); - - if(isPointOnPlanarSurface(s,vv.Pos.X,vv.Pos.Y,vv.Pos.Z,n)){ - if(!k){ - List_Add(s->Orientations,&vv); + for(i = 0; i < 100; i++) { + t = (double)i / (double)(100); + vv.Pos.X = t * 0.5 * (V[0].Pos.X + V[1].Pos.X) + (1. - t) * + 0.5 * (V[2].Pos.X + V[3].Pos.X); + vv.Pos.Y = t * 0.5 * (V[0].Pos.Y + V[1].Pos.Y) + (1. - t) * + 0.5 * (V[2].Pos.Y + V[3].Pos.Y); + vv.Pos.Z = t * 0.5 * (V[0].Pos.Z + V[1].Pos.Z) + (1. - t) * + 0.5 * (V[2].Pos.Z + V[3].Pos.Z); + + if(isPointOnPlanarSurface(s, vv.Pos.X, vv.Pos.Y, vv.Pos.Z, n)) { + if(!k) { + List_Add(s->Orientations, &vv); k = 1; } } - else{ - if(k){ - List_Add(s->Orientations,&vv); + else { + if(k) { + List_Add(s->Orientations, &vv); k = 0; - } + } } } - if(k) List_Add(s->Orientations,&vv); - + if(k) + List_Add(s->Orientations, &vv); + k = 0; - for(i=0;i<100;i++){ - t = (double)i/(double)(100); - vv.Pos.X = t*.5*(V[0].Pos.X+V[3].Pos.X)+(1.-t)*.5*(V[2].Pos.X+V[1].Pos.X); - vv.Pos.Y = t*.5*(V[0].Pos.Y+V[3].Pos.Y)+(1.-t)*.5*(V[2].Pos.Y+V[1].Pos.Y); - vv.Pos.Z = t*.5*(V[0].Pos.Z+V[3].Pos.Z)+(1.-t)*.5*(V[2].Pos.Z+V[1].Pos.Z); - if(isPointOnPlanarSurface(s,vv.Pos.X,vv.Pos.Y,vv.Pos.Z,n)){ - if(!k){ - List_Add(s->Orientations,&vv); + for(i = 0; i < 100; i++) { + t = (double)i / (double)(100); + vv.Pos.X = + t * .5 * (V[0].Pos.X + V[3].Pos.X) + (1. - t) * .5 * (V[2].Pos.X + + V[1].Pos.X); + vv.Pos.Y = + t * .5 * (V[0].Pos.Y + V[3].Pos.Y) + (1. - t) * .5 * (V[2].Pos.Y + + V[1].Pos.Y); + vv.Pos.Z = + t * .5 * (V[0].Pos.Z + V[3].Pos.Z) + (1. - t) * .5 * (V[2].Pos.Z + + V[1].Pos.Z); + if(isPointOnPlanarSurface(s, vv.Pos.X, vv.Pos.Y, vv.Pos.Z, n)) { + if(!k) { + List_Add(s->Orientations, &vv); k = 1; } } - else{ - if(k){ - List_Add(s->Orientations,&vv); + else { + if(k) { + List_Add(s->Orientations, &vv); k = 0; - } + } } } - if(k)List_Add(s->Orientations,&vv); + if(k) + List_Add(s->Orientations, &vv); - Msg(STATUS2, "Plane Surface %d (%d points)",s->Num,List_Nbr(s->Orientations)); + Msg(STATUS2, "Plane Surface %d (%d points)", s->Num, + List_Nbr(s->Orientations)); } - if(CTX.geom.surfaces){ + if(CTX.geom.surfaces) { glBegin(GL_LINES); - for(i=0;i<List_Nbr(s->Orientations);i++){ - List_Read(s->Orientations,i,&vv); - glVertex3d(vv.Pos.X,vv.Pos.Y,vv.Pos.Z); + for(i = 0; i < List_Nbr(s->Orientations); i++) { + List_Read(s->Orientations, i, &vv); + glVertex3d(vv.Pos.X, vv.Pos.Y, vv.Pos.Z); } glEnd(); } - if(List_Nbr(s->Orientations)>1){//draw_surface can get called during the computation... - - if(CTX.geom.surfaces_num){ - List_Read(s->Orientations,0,&vv1); - List_Read(s->Orientations,1,&vv2); - sprintf(Num,"%d",s->Num); - glRasterPos3d((vv2.Pos.X+vv1.Pos.X)/2. + 3*CTX.pixel_equiv_x/CTX.s[0], - (vv2.Pos.Y+vv1.Pos.Y)/2. + 3*CTX.pixel_equiv_x/CTX.s[1], - (vv2.Pos.Z+vv1.Pos.Z)/2. + 3*CTX.pixel_equiv_x/CTX.s[2]); + if(List_Nbr(s->Orientations) > 1) { //draw_surface can get called during the computation... + + if(CTX.geom.surfaces_num) { + List_Read(s->Orientations, 0, &vv1); + List_Read(s->Orientations, 1, &vv2); + sprintf(Num, "%d", s->Num); + glRasterPos3d((vv2.Pos.X + vv1.Pos.X) / 2. + + 3 * CTX.pixel_equiv_x / CTX.s[0], + (vv2.Pos.Y + vv1.Pos.Y) / 2. + + 3 * CTX.pixel_equiv_x / CTX.s[1], + (vv2.Pos.Z + vv1.Pos.Z) / 2. + + 3 * CTX.pixel_equiv_x / CTX.s[2]); Draw_String(Num); } - + if(CTX.geom.normals) { - glDisable(GL_LINE_STIPPLE) ; - List_Read(s->Orientations,0,&vv1); - List_Read(s->Orientations,1,&vv2); + glDisable(GL_LINE_STIPPLE); + List_Read(s->Orientations, 0, &vv1); + List_Read(s->Orientations, 1, &vv2); n[0] = s->plan[2][0]; n[1] = s->plan[2][1]; n[2] = s->plan[2][2]; norme(n); - n[0] *= CTX.geom.normals * CTX.pixel_equiv_x/CTX.s[0] ; - n[1] *= CTX.geom.normals * CTX.pixel_equiv_x/CTX.s[1] ; - n[2] *= CTX.geom.normals * CTX.pixel_equiv_x/CTX.s[2] ; - nn = sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]); - glColor4ubv((GLubyte*)&CTX.color.geom.normals); - Draw_Vector(DRAW_POST_ARROW, 0, (vv2.Pos.X+vv1.Pos.X)/2., (vv2.Pos.Y+vv1.Pos.Y)/2., - (vv2.Pos.Z+vv1.Pos.Z)/2., nn, n[0],n[1],n[2],NULL); + n[0] *= CTX.geom.normals * CTX.pixel_equiv_x / CTX.s[0]; + n[1] *= CTX.geom.normals * CTX.pixel_equiv_x / CTX.s[1]; + n[2] *= CTX.geom.normals * CTX.pixel_equiv_x / CTX.s[2]; + nn = sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]); + glColor4ubv((GLubyte *) & CTX.color.geom.normals); + Draw_Vector(DRAW_POST_ARROW, 0, (vv2.Pos.X + vv1.Pos.X) / 2., + (vv2.Pos.Y + vv1.Pos.Y) / 2., (vv2.Pos.Z + vv1.Pos.Z) / 2., + nn, n[0], n[1], n[2], NULL); } - + } } -void Draw_NonPlane_Surface (Surface *s){ - Vertex v,n1,n2,n3; - int i,NbTics,N=0; - double u,n[3],nn,nx[3],ny[3]; - double tics[20]; - double u0, un,v0,vn; +void Draw_NonPlane_Surface(Surface * s) +{ + Vertex v, n1, n2, n3; + int i, NbTics, N = 0; + double u, n[3], nn, nx[3], ny[3]; + double tics[20]; + double u0, un, v0, vn; int kk; char Num[100]; u0 = v0 = 0; un = vn = 1; - if(s->Typ == MSH_SURF_NURBS){ + if(s->Typ == MSH_SURF_NURBS) { NbTics = 5; u0 = s->ku[0]; un = s->ku[s->OrderU + s->Nu]; v0 = s->kv[0]; vn = s->kv[s->OrderV + s->Nv]; - for(i=0;i<NbTics;i++) - tics[i] = v0 + ((double)(i+1)/(double)NbTics) * (vn - v0); - if(CTX.geom.shade){ + for(i = 0; i < NbTics; i++) + tics[i] = v0 + ((double)(i + 1) / (double)NbTics) * (vn - v0); + if(CTX.geom.shade) { GLUnurbsObj *nurb; - nurb=gluNewNurbsRenderer(); - gluNurbsProperty(nurb,(GLenum)GLU_SAMPLING_TOLERANCE,50.0); - gluNurbsProperty(nurb,(GLenum)GLU_DISPLAY_MODE,GLU_FILL ); + nurb = gluNewNurbsRenderer(); + gluNurbsProperty(nurb, (GLenum) GLU_SAMPLING_TOLERANCE, 50.0); + gluNurbsProperty(nurb, (GLenum) GLU_DISPLAY_MODE, GLU_FILL); gluBeginSurface(nurb); - gluNurbsSurface(nurb, s->Nu+s->OrderU+1,s->ku, s->Nv+s->OrderV+1,s->kv, - 4, 4*s->Nu, s->cp, s->OrderU+1,s->OrderV+1, - GL_MAP2_VERTEX_4); + gluNurbsSurface(nurb, s->Nu + s->OrderU + 1, s->ku, + s->Nv + s->OrderV + 1, s->kv, 4, 4 * s->Nu, s->cp, + s->OrderU + 1, s->OrderV + 1, GL_MAP2_VERTEX_4); gluEndSurface(nurb); gluDeleteNurbsRenderer(nurb); return; @@ -460,120 +496,124 @@ void Draw_NonPlane_Surface (Surface *s){ tics[0] = 0.5; } - if(CTX.geom.surfaces){ - for(kk = 0;kk<NbTics;kk++){ + if(CTX.geom.surfaces) { + for(kk = 0; kk < NbTics; kk++) { N = 50; glBegin(GL_LINE_STRIP); - for(i=0;i<N+1;i++){ - u = u0 + (un-u0)*(double)i/(double)N; - v = InterpolateSurface(s,u,tics[kk],0,0); - glVertex3d(v.Pos.X,v.Pos.Y,v.Pos.Z); + for(i = 0; i < N + 1; i++) { + u = u0 + (un - u0) * (double)i / (double)N; + v = InterpolateSurface(s, u, tics[kk], 0, 0); + glVertex3d(v.Pos.X, v.Pos.Y, v.Pos.Z); } glEnd(); } } - if(s->Typ == MSH_SURF_NURBS){ - for(i=0;i<NbTics;i++){ - tics[i] = u0+((double)(i+1)/(double)NbTics) * (un - u0); + if(s->Typ == MSH_SURF_NURBS) { + for(i = 0; i < NbTics; i++) { + tics[i] = u0 + ((double)(i + 1) / (double)NbTics) * (un - u0); } } - if(CTX.geom.surfaces){ - for( kk = 0;kk<NbTics;kk++){ + if(CTX.geom.surfaces) { + for(kk = 0; kk < NbTics; kk++) { glBegin(GL_LINE_STRIP); - for(i=0;i<N+1;i++){ - u = v0 + (vn-v0)*(double)i/(double)N; - v = InterpolateSurface(s,tics[kk],u,0,0); - glVertex3d(v.Pos.X,v.Pos.Y,v.Pos.Z); + for(i = 0; i < N + 1; i++) { + u = v0 + (vn - v0) * (double)i / (double)N; + v = InterpolateSurface(s, tics[kk], u, 0, 0); + glVertex3d(v.Pos.X, v.Pos.Y, v.Pos.Z); } glEnd(); } } - if(CTX.geom.surfaces_num){ - v = InterpolateSurface(s,0.5,0.5,0,0); - sprintf(Num,"%d",s->Num); - glRasterPos3d(v.Pos.X+3*CTX.pixel_equiv_x/CTX.s[0], - v.Pos.Y+3*CTX.pixel_equiv_x/CTX.s[1], - v.Pos.Z+3*CTX.pixel_equiv_x/CTX.s[2]); + if(CTX.geom.surfaces_num) { + v = InterpolateSurface(s, 0.5, 0.5, 0, 0); + sprintf(Num, "%d", s->Num); + glRasterPos3d(v.Pos.X + 3 * CTX.pixel_equiv_x / CTX.s[0], + v.Pos.Y + 3 * CTX.pixel_equiv_x / CTX.s[1], + v.Pos.Z + 3 * CTX.pixel_equiv_x / CTX.s[2]); Draw_String(Num); } - if(CTX.geom.normals){ + if(CTX.geom.normals) { glDisable(GL_LINE_STIPPLE); - n1 = InterpolateSurface(s,0.5,0.5,0,0); - n2 = InterpolateSurface(s,0.6,0.5,0,0); - n3 = InterpolateSurface(s,0.5,0.6,0,0); + n1 = InterpolateSurface(s, 0.5, 0.5, 0, 0); + n2 = InterpolateSurface(s, 0.6, 0.5, 0, 0); + n3 = InterpolateSurface(s, 0.5, 0.6, 0, 0); nx[0] = n2.Pos.X - n1.Pos.X; nx[1] = n2.Pos.Y - n1.Pos.Y; nx[2] = n2.Pos.Z - n1.Pos.Z; ny[0] = n3.Pos.X - n1.Pos.X; ny[1] = n3.Pos.Y - n1.Pos.Y; ny[2] = n3.Pos.Z - n1.Pos.Z; - prodve(nx,ny,n); + prodve(nx, ny, n); norme(n); - n[0] *= CTX.geom.normals * CTX.pixel_equiv_x/CTX.s[0] ; - n[1] *= CTX.geom.normals * CTX.pixel_equiv_x/CTX.s[1] ; - n[2] *= CTX.geom.normals * CTX.pixel_equiv_x/CTX.s[2] ; - nn = sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]); - glColor4ubv((GLubyte*)&CTX.color.geom.normals); + n[0] *= CTX.geom.normals * CTX.pixel_equiv_x / CTX.s[0]; + n[1] *= CTX.geom.normals * CTX.pixel_equiv_x / CTX.s[1]; + n[2] *= CTX.geom.normals * CTX.pixel_equiv_x / CTX.s[2]; + nn = sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]); + glColor4ubv((GLubyte *) & CTX.color.geom.normals); Draw_Vector(DRAW_POST_ARROW, 0, n1.Pos.X, n1.Pos.Y, n1.Pos.Z, - nn, n[0],n[1],n[2],NULL); + nn, n[0], n[1], n[2], NULL); } } -void Draw_Surface (void *a, void *b){ +void Draw_Surface(void *a, void *b) +{ Surface *s; - s = *(Surface**)a; + s = *(Surface **) a; - if(!s || !s->Support || !(s->Visible & VIS_GEOM) || s->Dirty) return; + if(!s || !s->Support || !(s->Visible & VIS_GEOM) || s->Dirty) + return; - if(CTX.render_mode == GMSH_SELECT){ + if(CTX.render_mode == GMSH_SELECT) { glLoadName(2); glPushName(s->Num); } - if(!CTX.geom.shade){ - if(s->ipar[4]){ - glLineWidth(CTX.geom.line_sel_width); - gl2psLineWidth(CTX.geom.line_sel_width * CTX.print.eps_line_width_factor); - glColor4ubv((GLubyte*)&CTX.color.geom.surface_sel); + if(!CTX.geom.shade) { + if(s->ipar[4]) { + glLineWidth(CTX.geom.line_sel_width); + gl2psLineWidth(CTX.geom.line_sel_width * + CTX.print.eps_line_width_factor); + glColor4ubv((GLubyte *) & CTX.color.geom.surface_sel); } - else if (Highlighted){ - glLineWidth(CTX.geom.line_sel_width); - gl2psLineWidth(CTX.geom.line_sel_width * CTX.print.eps_line_width_factor); - glColor4ubv((GLubyte*)&CTX.color.geom.surface_hlt); + else if(Highlighted) { + glLineWidth(CTX.geom.line_sel_width); + gl2psLineWidth(CTX.geom.line_sel_width * + CTX.print.eps_line_width_factor); + glColor4ubv((GLubyte *) & CTX.color.geom.surface_hlt); } - else{ - glLineWidth(CTX.geom.line_width); + else { + glLineWidth(CTX.geom.line_width); gl2psLineWidth(CTX.geom.line_width * CTX.print.eps_line_width_factor); - glColor4ubv((GLubyte*)&CTX.color.geom.surface); + glColor4ubv((GLubyte *) & CTX.color.geom.surface); } glEnable(GL_LINE_STIPPLE); - glLineStipple(1,0x0F0F); + glLineStipple(1, 0x0F0F); } - else{ + else { ColorSwitch(abs(s->Num)); } - if(s->Typ == MSH_SURF_STL){ + if(s->Typ == MSH_SURF_STL) { glDisable(GL_LINE_STIPPLE); - Tree_Action(s->STL->Simplexes,Draw_Simplex_Surface); + Tree_Action(s->STL->Simplexes, Draw_Simplex_Surface); } - else if(s->Typ == MSH_SURF_DISCRETE){ + else if(s->Typ == MSH_SURF_DISCRETE) { glDisable(GL_LINE_STIPPLE); - Tree_Action(s->Simplexes,Draw_Simplex_Surface); + Tree_Action(s->Simplexes, Draw_Simplex_Surface); } else if(s->Typ == MSH_SURF_PLAN) Draw_Plane_Surface(s); else Draw_NonPlane_Surface(s); - if(CTX.render_mode == GMSH_SELECT){ - glPopName (); + if(CTX.render_mode == GMSH_SELECT) { + glPopName(); } glDisable(GL_LINE_STIPPLE); @@ -584,17 +624,18 @@ void Draw_Surface (void *a, void *b){ int TheVolume; -void Draw_Curve_For_Volume (void *a, void *b){ - int i,N; - Curve *c; - Vertex v; +void Draw_Curve_For_Volume(void *a, void *b) +{ + int i, N; + Curve *c; + Vertex v; glLineWidth(CTX.geom.line_width); gl2psLineWidth(CTX.geom.line_width * CTX.print.eps_line_width_factor); - c = *(Curve**)a; + c = *(Curve **) a; - if(CTX.render_mode == GMSH_SELECT){ + if(CTX.render_mode == GMSH_SELECT) { glLoadName(3); glPushName(TheVolume); } @@ -605,172 +646,195 @@ void Draw_Curve_For_Volume (void *a, void *b){ N = 10; glBegin(GL_LINE_STRIP); - for(i=0;i<N;i++){ - v = InterpolateCurve(c,0.2*(double)i/(double)(N-1),0); - glVertex3d(v.Pos.X,v.Pos.Y,v.Pos.Z); + for(i = 0; i < N; i++) { + v = InterpolateCurve(c, 0.2 * (double)i / (double)(N - 1), 0); + glVertex3d(v.Pos.X, v.Pos.Y, v.Pos.Z); } glEnd(); glBegin(GL_LINE_STRIP); - for(i=N-1;i>=0;i--){ - v = InterpolateCurve(c,1.-0.2*(double)i/(double)(N-1),0); - glVertex3d(v.Pos.X,v.Pos.Y,v.Pos.Z); + for(i = N - 1; i >= 0; i--) { + v = InterpolateCurve(c, 1. - 0.2 * (double)i / (double)(N - 1), 0); + glVertex3d(v.Pos.X, v.Pos.Y, v.Pos.Z); } glEnd(); - if(CTX.render_mode == GMSH_SELECT){ - glPopName (); + if(CTX.render_mode == GMSH_SELECT) { + glPopName(); } } -void DrawVolumes (Mesh *m){ +void DrawVolumes(Mesh * m) +{ } // Draw geometry -void Draw_Geom (Mesh *m) { +void Draw_Geom(Mesh * m) +{ + if(m->status == -1) + return; - if(m->status == -1) return; - - if(CTX.geom.points || CTX.geom.points_num){ - if(CTX.geom.point_type) InitShading(); + if(CTX.geom.points || CTX.geom.points_num) { + if(CTX.geom.point_type) + InitShading(); Tree_Action(m->Points, Draw_GeoPoint); - if(CTX.geom.point_type && !CTX.geom.shade) InitNoShading(); + if(CTX.geom.point_type && !CTX.geom.shade) + InitNoShading(); } - if(CTX.geom.lines || CTX.geom.lines_num){ - if(CTX.geom.line_type) InitShading(); - Tree_Action(m->Curves, Draw_Curve ); - if(CTX.geom.line_type && !CTX.geom.shade) InitNoShading(); + if(CTX.geom.lines || CTX.geom.lines_num) { + if(CTX.geom.line_type) + InitShading(); + Tree_Action(m->Curves, Draw_Curve); + if(CTX.geom.line_type && !CTX.geom.shade) + InitNoShading(); } if(CTX.geom.surfaces || CTX.geom.surfaces_num) - Tree_Action(m->Surfaces,Draw_Surface); + Tree_Action(m->Surfaces, Draw_Surface); if(CTX.geom.volumes || CTX.geom.volumes_num) DrawVolumes(m); } -void ZeroCurve(void *a,void *b){ +void ZeroCurve(void *a, void *b) +{ Curve *c; - c = *(Curve**)a; + c = *(Curve **) a; c->ipar[3] = 0; } -void ZeroPoint(void *a,void *b){ +void ZeroPoint(void *a, void *b) +{ Vertex *v; - v = *(Vertex**)a; + v = *(Vertex **) a; v->Frozen = 0; } -void ZeroSurface(void *a,void *b){ +void ZeroSurface(void *a, void *b) +{ Surface *s; - s = *(Surface**)a; + s = *(Surface **) a; s->ipar[4] = 0; } -void ZeroHighlight(Mesh *m){ - Tree_Action(m->Points,ZeroPoint); - Tree_Action(m->Curves,ZeroCurve); - Tree_Action(m->Surfaces,ZeroSurface); +void ZeroHighlight(Mesh * m) +{ + Tree_Action(m->Points, ZeroPoint); + Tree_Action(m->Curves, ZeroCurve); + Tree_Action(m->Surfaces, ZeroSurface); } // Highlight routines -void BeginHighlight(void){ - if(CTX.geom.highlight){ +void BeginHighlight(void) +{ + if(CTX.geom.highlight) { if(CTX.overlay) InitOverlay(); else InitOpengl(); Highlighted = 1; glPushMatrix(); - InitPosition(); + InitPosition(); } } -void EndHighlight(int permanent){ +void EndHighlight(int permanent) +{ Highlighted = 0; - if(permanent) + if(permanent) Draw(); - else{ + else { if(CTX.geom.highlight) { glPopMatrix(); } } } -void HighlightEntity(Vertex *v,Curve *c, Surface *s, int permanent){ +void HighlightEntity(Vertex * v, Curve * c, Surface * s, int permanent) +{ Curve *cc; - char Message[256],temp[256]; - int i,nbg; - - if(v){ - if(permanent) v->Frozen = 1; - if(CTX.geom.highlight) Draw_GeoPoint(&v,NULL); - Msg(STATUS1N,"Point %d {%.5g,%.5g,%.5g} (%.5g)", v->Num,v->Pos.X,v->Pos.Y,v->Pos.Z,v->lc); - } - else if(c){ - if(permanent) c->ipar[3] = 1; - if(CTX.geom.highlight) Draw_Curve(&c,NULL); - Msg(STATUS1N,"Curve %d {%d->%d}",c->Num,c->beg->Num,c->end->Num); - } - else if(s){ - if(permanent && s->ipar[4] == 1) return; - if(permanent) s->ipar[4] = 1; - if(CTX.geom.highlight) Draw_Surface(&s,NULL); - sprintf(Message,"Surface %d {",s->Num); - - nbg = List_Nbr(s->Generatrices) ; - - if(nbg < 10){ - for(i=0;i<nbg;i++){ - List_Read(s->Generatrices,i,&cc); - if(!i)sprintf(temp,"%d",cc->Num); - else sprintf(temp,",%d",cc->Num); - strcat(Message,temp); + char Message[256], temp[256]; + int i, nbg; + + if(v) { + if(permanent) + v->Frozen = 1; + if(CTX.geom.highlight) + Draw_GeoPoint(&v, NULL); + Msg(STATUS1N, "Point %d {%.5g,%.5g,%.5g} (%.5g)", v->Num, v->Pos.X, + v->Pos.Y, v->Pos.Z, v->lc); + } + else if(c) { + if(permanent) + c->ipar[3] = 1; + if(CTX.geom.highlight) + Draw_Curve(&c, NULL); + Msg(STATUS1N, "Curve %d {%d->%d}", c->Num, c->beg->Num, c->end->Num); + } + else if(s) { + if(permanent && s->ipar[4] == 1) + return; + if(permanent) + s->ipar[4] = 1; + if(CTX.geom.highlight) + Draw_Surface(&s, NULL); + sprintf(Message, "Surface %d {", s->Num); + + nbg = List_Nbr(s->Generatrices); + + if(nbg < 10) { + for(i = 0; i < nbg; i++) { + List_Read(s->Generatrices, i, &cc); + if(!i) + sprintf(temp, "%d", cc->Num); + else + sprintf(temp, ",%d", cc->Num); + strcat(Message, temp); } } - else{ - strcat(Message,"..."); + else { + strcat(Message, "..."); } - strcat(Message,"}"); - Msg(STATUS1N,Message); + strcat(Message, "}"); + Msg(STATUS1N, Message); } - else{ - Msg(STATUS1N," "); + else { + Msg(STATUS1N, " "); } glFlush(); } -void HighlightEntityNum(int v, int c, int s, int permanant){ - Vertex *pv,V; - Curve *pc,C; - Surface *ps,S; - if(v){ +void HighlightEntityNum(int v, int c, int s, int permanant) +{ + Vertex *pv, V; + Curve *pc, C; + Surface *ps, S; + if(v) { pv = &V; pv->Num = v; - if(Tree_Query(THEM->Vertices,&pv)){ - HighlightEntity(pv,NULL,NULL,permanant); + if(Tree_Query(THEM->Vertices, &pv)) { + HighlightEntity(pv, NULL, NULL, permanant); } } - if(c){ + if(c) { pc = &C; pc->Num = c; - if(Tree_Query(THEM->Curves,&pc)){ - HighlightEntity(NULL,pc,NULL,permanant); + if(Tree_Query(THEM->Curves, &pc)) { + HighlightEntity(NULL, pc, NULL, permanant); } } - if(s){ + if(s) { ps = &S; ps->Num = s; - if(Tree_Query(THEM->Surfaces,&ps)){ - HighlightEntity(NULL,NULL,ps,permanant); + if(Tree_Query(THEM->Surfaces, &ps)) { + HighlightEntity(NULL, NULL, ps, permanant); } } } - diff --git a/Graphics/Graph2D.cpp b/Graphics/Graph2D.cpp index 1980625614328e0e0c6f1c67fe2e148b70e1f367..f9378756bfca680c5b42e262b20514d599d904a3 100644 --- a/Graphics/Graph2D.cpp +++ b/Graphics/Graph2D.cpp @@ -1,4 +1,4 @@ -// $Id: Graph2D.cpp,v 1.26 2003-02-25 04:02:50 geuzaine Exp $ +// $Id: Graph2D.cpp,v 1.27 2003-03-01 22:36:39 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -28,362 +28,392 @@ #include "Views.h" #include "gl2ps.h" -extern Context_T CTX; +extern Context_T CTX; // 2D graphics (gnuplot style) -static void getval(Post_View *v, int i, int j, double *p1, double *p2, - double *Abs, double *Val){ +static void getval(Post_View * v, int i, int j, double *p1, double *p2, + double *Abs, double *Val) +{ int k; - if(v->Type==DRAW_POST_2D_SPACE){ - for(k=0;k<3;k++){ - List_Read(v->SP,j+k,&p2[k]); - if(j) p1[k] = p2[k]-p1[k]; + if(v->Type == DRAW_POST_2D_SPACE) { + for(k = 0; k < 3; k++) { + List_Read(v->SP, j + k, &p2[k]); + if(j) + p1[k] = p2[k] - p1[k]; } - *Abs += sqrt (p1[0] * p1[0] + p1[1] * p1[1] + p1[2] * p1[2]); - for(k=0;k<3;k++){ + *Abs += sqrt(p1[0] * p1[0] + p1[1] * p1[1] + p1[2] * p1[2]); + for(k = 0; k < 3; k++) { p1[k] = p2[k]; } - *Val = ((double*)List_Pointer_Fast(v->SP,j+3))[v->TimeStep]; + *Val = ((double *)List_Pointer_Fast(v->SP, j + 3))[v->TimeStep]; } - else{ - *Abs = *(double*)List_Pointer_Fast(v->Time,j); - *Val = ((double*)List_Pointer_Fast(v->SP,i+3))[j]; + else { + *Abs = *(double *)List_Pointer_Fast(v->Time, j); + *Val = ((double *)List_Pointer_Fast(v->SP, i + 3))[j]; } } -static void addval(Post_View *v, double Abs, double Val, - double AbsMin, double AbsMax, double ValMin, double ValMax, - double xtop, double width, double ybot, double height, - int numeric){ +static void addval(Post_View * v, double Abs, double Val, + double AbsMin, double AbsMax, double ValMin, double ValMax, + double xtop, double width, double ybot, double height, + int numeric) +{ char label[256]; double x, y; - if(AbsMax==AbsMin) + if(AbsMax == AbsMin) x = xtop; else - x = xtop+(Abs-AbsMin)/(AbsMax-AbsMin)*width; + x = xtop + (Abs - AbsMin) / (AbsMax - AbsMin) * width; - if(v->SaturateValues){ - if(Val > ValMax) Val = ValMax; - else if(Val < ValMin) Val = ValMin; + if(v->SaturateValues) { + if(Val > ValMax) + Val = ValMax; + else if(Val < ValMin) + Val = ValMin; } - - if(ValMax==ValMin) + + if(ValMax == ValMin) y = ybot; else - y = ybot+(Val-ValMin)/(ValMax-ValMin)*height; + y = ybot + (Val - ValMin) / (ValMax - ValMin) * height; - if(Val>=ValMin && Val<=ValMax){ - Palette2(v,ValMin,ValMax,Val); - if(numeric){ - glRasterPos2d(x+3,y+3); + if(Val >= ValMin && Val <= ValMax) { + Palette2(v, ValMin, ValMax, Val); + if(numeric) { + glRasterPos2d(x + 3, y + 3); sprintf(label, v->Format, Val); Draw_String(label); } else - glVertex2d(x,y); + glVertex2d(x, y); } } -static void Draw_Graph2D(Post_View *v, - double xx, double yy, double width, double height, - double tic, double bb[4]){ - char label[1024] ; - float font_h, font_a ; +static void Draw_Graph2D(Post_View * v, + double xx, double yy, double width, double height, + double tic, double bb[4]) +{ + char label[1024]; + float font_h, font_a; int i, i_inc, i_max, j, j_inc, j_max, k, nb; double dx, dy, dv; double xtop = xx; - double ytop = CTX.viewport[3]-yy; - double ybot = ytop-height; - double Abs, Val, ValMin=0., ValMax=0., AbsMin, AbsMax; + double ytop = CTX.viewport[3] - yy; + double ybot = ytop - height; + double Abs, Val, ValMin = 0., ValMax = 0., AbsMin, AbsMax; double p1[3], p2[3]; - if(!v->TransparentScale){ - glColor4ubv((GLubyte*)&CTX.color.bg); + if(!v->TransparentScale) { + glColor4ubv((GLubyte *) & CTX.color.bg); glBegin(GL_QUADS); - glVertex2d(bb[0],CTX.viewport[3]-bb[1]); - glVertex2d(bb[2],CTX.viewport[3]-bb[1]); - glVertex2d(bb[2],CTX.viewport[3]-bb[3]); - glVertex2d(bb[0],CTX.viewport[3]-bb[3]); - glEnd(); + glVertex2d(bb[0], CTX.viewport[3] - bb[1]); + glVertex2d(bb[2], CTX.viewport[3] - bb[1]); + glVertex2d(bb[2], CTX.viewport[3] - bb[3]); + glVertex2d(bb[0], CTX.viewport[3] - bb[3]); + glEnd(); } - - gl_font(FL_HELVETICA,CTX.gl_fontsize); - font_h = gl_height() ; // total font height - font_a = gl_height()-gl_descent() ; // height above ref pt - - switch(v->RangeType){ - case DRAW_POST_DEFAULT : ValMin = v->Min ; ValMax = v->Max ; break; - case DRAW_POST_CUSTOM : ValMin = v->CustomMin ; ValMax = v->CustomMax ; break; + + gl_font(FL_HELVETICA, CTX.gl_fontsize); + font_h = gl_height(); // total font height + font_a = gl_height() - gl_descent(); // height above ref pt + + switch (v->RangeType) { + case DRAW_POST_DEFAULT: + ValMin = v->Min; + ValMax = v->Max; + break; + case DRAW_POST_CUSTOM: + ValMin = v->CustomMin; + ValMax = v->CustomMax; + break; } - glPointSize(CTX.point_size); + glPointSize(CTX.point_size); gl2psPointSize(CTX.point_size * CTX.print.eps_point_size_factor); - glLineWidth(CTX.line_width); + glLineWidth(CTX.line_width); gl2psLineWidth(CTX.line_width * CTX.print.eps_line_width_factor); - + // axes - if(v->Grid){ - glColor4ubv((GLubyte*)&CTX.color.fg); + if(v->Grid) { + glColor4ubv((GLubyte *) & CTX.color.fg); glBegin(GL_LINE_STRIP); - glVertex2d(xtop,ytop); - glVertex2d(xtop,ytop-height); - glVertex2d(xtop+width,ybot); - if(v->Grid>1){ - glVertex2d(xtop+width,ytop); - glVertex2d(xtop,ytop); + glVertex2d(xtop, ytop); + glVertex2d(xtop, ytop - height); + glVertex2d(xtop + width, ybot); + if(v->Grid > 1) { + glVertex2d(xtop + width, ytop); + glVertex2d(xtop, ytop); } glEnd(); } - + // y tics + labels - nb = v->NbIso?v->NbIso:1; - if(v->ShowScale && (v->NbIso * font_h > height)) nb = (int)floor(height/font_h); + nb = v->NbIso ? v->NbIso : 1; + if(v->ShowScale && (v->NbIso * font_h > height)) + nb = (int)floor(height / font_h); - dy = height/(double)nb; - dv = (ValMax-ValMin)/(double)nb; - for(i=0; i<nb+1; i++){ - if(v->Grid>0){ - glColor4ubv((GLubyte*)&CTX.color.fg); + dy = height / (double)nb; + dv = (ValMax - ValMin) / (double)nb; + for(i = 0; i < nb + 1; i++) { + if(v->Grid > 0) { + glColor4ubv((GLubyte *) & CTX.color.fg); glBegin(GL_LINES); - glVertex2d(xtop,ytop-i*dy); - glVertex2d(xtop+tic,ytop-i*dy); - if(v->Grid>1){ - glVertex2d(xtop+width-tic,ytop-i*dy); - glVertex2d(xtop+width,ytop-i*dy); + glVertex2d(xtop, ytop - i * dy); + glVertex2d(xtop + tic, ytop - i * dy); + if(v->Grid > 1) { + glVertex2d(xtop + width - tic, ytop - i * dy); + glVertex2d(xtop + width, ytop - i * dy); } glEnd(); - if(v->Grid>2 && i!=0 && i!=nb){ - glEnable(GL_LINE_STIPPLE); - glLineStipple(1,0x1111); - gl2psEnable(GL2PS_LINE_STIPPLE); - glLineWidth(1.); - gl2psLineWidth(1. * CTX.print.eps_line_width_factor); - glBegin(GL_LINES); - glVertex2d(xtop,ytop-i*dy); - glVertex2d(xtop+width,ytop-i*dy); - glEnd(); - glDisable(GL_LINE_STIPPLE); - gl2psDisable(GL2PS_LINE_STIPPLE); - glLineWidth(CTX.line_width); - gl2psLineWidth(CTX.line_width * CTX.print.eps_line_width_factor); + if(v->Grid > 2 && i != 0 && i != nb) { + glEnable(GL_LINE_STIPPLE); + glLineStipple(1, 0x1111); + gl2psEnable(GL2PS_LINE_STIPPLE); + glLineWidth(1.); + gl2psLineWidth(1. * CTX.print.eps_line_width_factor); + glBegin(GL_LINES); + glVertex2d(xtop, ytop - i * dy); + glVertex2d(xtop + width, ytop - i * dy); + glEnd(); + glDisable(GL_LINE_STIPPLE); + gl2psDisable(GL2PS_LINE_STIPPLE); + glLineWidth(CTX.line_width); + gl2psLineWidth(CTX.line_width * CTX.print.eps_line_width_factor); } } - if(v->ShowScale){ - glColor4ubv((GLubyte*)&CTX.color.text); - sprintf(label, v->Format, (i==nb)?ValMin:(ValMax-i*dv)); + if(v->ShowScale) { + glColor4ubv((GLubyte *) & CTX.color.text); + sprintf(label, v->Format, (i == nb) ? ValMin : (ValMax - i * dv)); if(!CTX.print.gl_fonts) - glRasterPos2d(xtop-gl_width(label)-3*tic,ytop-i*dy-font_a/3.); + glRasterPos2d(xtop - gl_width(label) - 3 * tic, + ytop - i * dy - font_a / 3.); else - glRasterPos2d(xtop-gl_width(label)-tic,ytop-i*dy-font_a/3.); + glRasterPos2d(xtop - gl_width(label) - tic, + ytop - i * dy - font_a / 3.); Draw_String(label); } } - - if(v->ShowScale){ - glColor4ubv((GLubyte*)&CTX.color.text); - if(v->Type==DRAW_POST_2D_SPACE && List_Nbr(v->Time)>1 && v->ShowTime) - sprintf(label, "%s (%g)", v->Name, *(double*)List_Pointer(v->Time,v->TimeStep)); + + if(v->ShowScale) { + glColor4ubv((GLubyte *) & CTX.color.text); + if(v->Type == DRAW_POST_2D_SPACE && List_Nbr(v->Time) > 1 && v->ShowTime) + sprintf(label, "%s (%g)", v->Name, + *(double *)List_Pointer(v->Time, v->TimeStep)); else sprintf(label, "%s", v->Name); - glRasterPos2d(xtop-gl_width(label)/2.,ytop+1.5*font_h); + glRasterPos2d(xtop - gl_width(label) / 2., ytop + 1.5 * font_h); Draw_String(label); } // x tics + labels - if(v->Type==DRAW_POST_2D_SPACE){ + if(v->Type == DRAW_POST_2D_SPACE) { AbsMin = AbsMax = 0.; - double p1[3]={0.,0.,0.}, p2[3]; - for(i=0; i<List_Nbr(v->SP); i+=List_Nbr(v->SP)/v->NbSP){ - for(k=0;k<3;k++){ - List_Read(v->SP,i+k,&p2[k]); - if(i) p1[k] = p2[k]-p1[k]; + double p1[3] = { 0., 0., 0. }, p2[3]; + for(i = 0; i < List_Nbr(v->SP); i += List_Nbr(v->SP) / v->NbSP) { + for(k = 0; k < 3; k++) { + List_Read(v->SP, i + k, &p2[k]); + if(i) + p1[k] = p2[k] - p1[k]; + } + AbsMax += sqrt(p1[0] * p1[0] + p1[1] * p1[1] + p1[2] * p1[2]); + for(k = 0; k < 3; k++) { + p1[k] = p2[k]; } - AbsMax += sqrt (p1[0] * p1[0] + p1[1] * p1[1] + p1[2] * p1[2]); - for(k=0;k<3;k++){ - p1[k] = p2[k]; - } } } - else{ - AbsMin = *(double*)List_Pointer(v->Time,0); - AbsMax = *(double*)List_Pointer(v->Time,List_Nbr(v->Time)-1); + else { + AbsMin = *(double *)List_Pointer(v->Time, 0); + AbsMax = *(double *)List_Pointer(v->Time, List_Nbr(v->Time) - 1); } nb = v->NbAbscissa; - if(v->ShowScale){ + if(v->ShowScale) { sprintf(label, v->AbscissaFormat, AbsMin); double ww = gl_width(label); sprintf(label, v->AbscissaFormat, AbsMax); - if(gl_width(label) > ww) ww = gl_width(label); - if((nb-1)*(ww+2) > width) nb = (int)floor(width/(ww+2))+1; + if(gl_width(label) > ww) + ww = gl_width(label); + if((nb - 1) * (ww + 2) > width) + nb = (int)floor(width / (ww + 2)) + 1; } - if(nb==1) + if(nb == 1) dx = width; else - dx = width/(double)(nb-1); + dx = width / (double)(nb - 1); - for(i=0; i<nb; i++){ - if(v->Grid>0){ - glColor4ubv((GLubyte*)&CTX.color.fg); + for(i = 0; i < nb; i++) { + if(v->Grid > 0) { + glColor4ubv((GLubyte *) & CTX.color.fg); glBegin(GL_LINES); - glVertex2d(xtop+i*dx,ybot); - glVertex2d(xtop+i*dx,ybot+tic); - if(v->Grid>1){ - glVertex2d(xtop+i*dx,ytop); - glVertex2d(xtop+i*dx,ytop-tic); + glVertex2d(xtop + i * dx, ybot); + glVertex2d(xtop + i * dx, ybot + tic); + if(v->Grid > 1) { + glVertex2d(xtop + i * dx, ytop); + glVertex2d(xtop + i * dx, ytop - tic); } glEnd(); - if(v->Grid>2 && i!=0 && i!=nb-1){ - glEnable(GL_LINE_STIPPLE); - glLineStipple(1,0x1111); - gl2psEnable(GL2PS_LINE_STIPPLE); - glLineWidth(1.); - gl2psLineWidth(1. * CTX.print.eps_line_width_factor); - glBegin(GL_LINES); - glVertex2d(xtop+i*dx,ytop); - glVertex2d(xtop+i*dx,ybot); - glEnd(); - glDisable(GL_LINE_STIPPLE); - gl2psDisable(GL2PS_LINE_STIPPLE); - glLineWidth(CTX.line_width); - gl2psLineWidth(CTX.line_width * CTX.print.eps_line_width_factor); + if(v->Grid > 2 && i != 0 && i != nb - 1) { + glEnable(GL_LINE_STIPPLE); + glLineStipple(1, 0x1111); + gl2psEnable(GL2PS_LINE_STIPPLE); + glLineWidth(1.); + gl2psLineWidth(1. * CTX.print.eps_line_width_factor); + glBegin(GL_LINES); + glVertex2d(xtop + i * dx, ytop); + glVertex2d(xtop + i * dx, ybot); + glEnd(); + glDisable(GL_LINE_STIPPLE); + gl2psDisable(GL2PS_LINE_STIPPLE); + glLineWidth(CTX.line_width); + gl2psLineWidth(CTX.line_width * CTX.print.eps_line_width_factor); } } - if(v->ShowScale){ - glColor4ubv((GLubyte*)&CTX.color.text); - if(nb==1) - sprintf(label, v->AbscissaFormat, AbsMin); + if(v->ShowScale) { + glColor4ubv((GLubyte *) & CTX.color.text); + if(nb == 1) + sprintf(label, v->AbscissaFormat, AbsMin); else - sprintf(label, v->AbscissaFormat, AbsMin+i*(AbsMax-AbsMin)/(double)(nb-1)); - glRasterPos2d(xtop+i*dx-gl_width(label)/2.,ybot-1.5*font_h); + sprintf(label, v->AbscissaFormat, + AbsMin + i * (AbsMax - AbsMin) / (double)(nb - 1)); + glRasterPos2d(xtop + i * dx - gl_width(label) / 2., + ybot - 1.5 * font_h); Draw_String(label); } } - if(v->ShowScale){ - glColor4ubv((GLubyte*)&CTX.color.text); + if(v->ShowScale) { + glColor4ubv((GLubyte *) & CTX.color.text); sprintf(label, "%s", v->AbscissaName); - glRasterPos2d(xtop+width/2-gl_width(label)/2.,ybot-3*font_h); + glRasterPos2d(xtop + width / 2 - gl_width(label) / 2., ybot - 3 * font_h); Draw_String(label); } // the curve(s) - glPointSize(v->PointSize); + glPointSize(v->PointSize); gl2psPointSize(v->PointSize * CTX.print.eps_point_size_factor); - glLineWidth(v->LineWidth); + glLineWidth(v->LineWidth); gl2psLineWidth(v->LineWidth * CTX.print.eps_line_width_factor); - if(v->Type==DRAW_POST_2D_SPACE){ + if(v->Type == DRAW_POST_2D_SPACE) { i_inc = 1; i_max = 1; - j_inc = List_Nbr(v->SP)/v->NbSP ; + j_inc = List_Nbr(v->SP) / v->NbSP; j_max = List_Nbr(v->SP); } - else{ - i_inc = List_Nbr(v->SP)/v->NbSP ; - i_max = List_Nbr(v->SP) ; + else { + i_inc = List_Nbr(v->SP) / v->NbSP; + i_max = List_Nbr(v->SP); j_inc = 1; - j_max = v->TimeStep+1; + j_max = v->TimeStep + 1; } - for(i=0; i<i_max; i+=i_inc){ - if(v->IntervalsType == DRAW_POST_ISO || + for(i = 0; i < i_max; i += i_inc) { + if(v->IntervalsType == DRAW_POST_ISO || v->IntervalsType == DRAW_POST_DISCRETE || - v->IntervalsType == DRAW_POST_NUMERIC){ - glBegin(GL_POINTS); + v->IntervalsType == DRAW_POST_NUMERIC) { + glBegin(GL_POINTS); Abs = Val = p1[0] = p1[1] = p1[2] = 0.; - for(j=0; j<j_max; j+=j_inc){ - getval(v,i,j,p1,p2,&Abs,&Val); - addval(v,Abs,Val,AbsMin,AbsMax,ValMin,ValMax,xtop,width,ybot,height,0); + for(j = 0; j < j_max; j += j_inc) { + getval(v, i, j, p1, p2, &Abs, &Val); + addval(v, Abs, Val, AbsMin, AbsMax, ValMin, ValMax, xtop, width, ybot, + height, 0); } glEnd(); } - if(v->IntervalsType == DRAW_POST_NUMERIC){ + if(v->IntervalsType == DRAW_POST_NUMERIC) { Abs = Val = p1[0] = p1[1] = p1[2] = 0.; - for(j=0; j<j_max; j+=j_inc){ - getval(v,i,j,p1,p2,&Abs,&Val); - addval(v,Abs,Val,AbsMin,AbsMax,ValMin,ValMax,xtop,width,ybot,height,1); + for(j = 0; j < j_max; j += j_inc) { + getval(v, i, j, p1, p2, &Abs, &Val); + addval(v, Abs, Val, AbsMin, AbsMax, ValMin, ValMax, xtop, width, ybot, + height, 1); } } - if(v->IntervalsType == DRAW_POST_DISCRETE || - v->IntervalsType == DRAW_POST_CONTINUOUS){ - glBegin(GL_LINE_STRIP); + if(v->IntervalsType == DRAW_POST_DISCRETE || + v->IntervalsType == DRAW_POST_CONTINUOUS) { + glBegin(GL_LINE_STRIP); Abs = Val = p1[0] = p1[1] = p1[2] = 0.; - for(j=0; j<j_max; j+=j_inc){ - getval(v,i,j,p1,p2,&Abs,&Val); - addval(v,Abs,Val,AbsMin,AbsMax,ValMin,ValMax,xtop,width,ybot,height,0); + for(j = 0; j < j_max; j += j_inc) { + getval(v, i, j, p1, p2, &Abs, &Val); + addval(v, Abs, Val, AbsMin, AbsMax, ValMin, ValMax, xtop, width, ybot, + height, 0); } glEnd(); } - + } - + } -void getbb(double pos[2], double width, double height, - double dx, double dy, double tic, double space, - double bbtot[4], double bb[4]){ - bbtot[0] = pos[0]-dx-space;//topleft x +void getbb(double pos[2], double width, double height, + double dx, double dy, double tic, double space, + double bbtot[4], double bb[4]) +{ + bbtot[0] = pos[0] - dx - space; //topleft x bb[0] = bbtot[0]; //don't recompute bbtot[1]. - bb[1] = pos[1]-1.5*dy-space;//topleft y - - bbtot[2] = MAX(bbtot[2],pos[0]+width+(dx-tic)/2+space);//bottomright x - bb[2] = pos[0]+width+(dx-tic)/2+space; + bb[1] = pos[1] - 1.5 * dy - space; //topleft y - bbtot[3] = pos[1]+height+2*dy+space;//bottomright y + bbtot[2] = MAX(bbtot[2], pos[0] + width + (dx - tic) / 2 + space); //bottomright x + bb[2] = pos[0] + width + (dx - tic) / 2 + space; + + bbtot[3] = pos[1] + height + 2 * dy + space; //bottomright y bb[3] = bbtot[3]; } -void Draw_Graph2D(void){ - int i,nbauto=0; +void Draw_Graph2D(void) +{ + int i, nbauto = 0; Post_View *v; - double dx,dy,bb[4],bbtot[4]={0.,0.,0.,0.},pos[2],tic,space=10.; + double dx, dy, bb[4], bbtot[4] = { 0., 0., 0., 0. }, pos[2], tic, space = + 10.; char label[1024]; - if(!CTX.post.list) return; + if(!CTX.post.list) + return; - for(i=0;i<List_Nbr(CTX.post.list);i++){ - v = (Post_View*)List_Pointer(CTX.post.list,i); - if(v->Visible && !v->Dirty && v->NbSP && v->Type!=DRAW_POST_3D){ + for(i = 0; i < List_Nbr(CTX.post.list); i++) { + v = (Post_View *) List_Pointer(CTX.post.list, i); + if(v->Visible && !v->Dirty && v->NbSP && v->Type != DRAW_POST_3D) { tic = 5; dx = dy = 0.; - if(v->ShowScale){ - gl_font(FL_HELVETICA,CTX.gl_fontsize); - sprintf(label,v->AbscissaFormat,v->CustomMin); - if(gl_width(label)+tic > dx) dx = gl_width(label)+tic; - sprintf(label,v->AbscissaFormat,v->CustomMax); - if(gl_width(label)+tic > dx) dx = gl_width(label)+tic; - dy = 1.5*gl_height(); //2 below and & above! + if(v->ShowScale) { + gl_font(FL_HELVETICA, CTX.gl_fontsize); + sprintf(label, v->AbscissaFormat, v->CustomMin); + if(gl_width(label) + tic > dx) + dx = gl_width(label) + tic; + sprintf(label, v->AbscissaFormat, v->CustomMax); + if(gl_width(label) + tic > dx) + dx = gl_width(label) + tic; + dy = 1.5 * gl_height(); //2 below and & above! } - if(!v->AutoPosition || !nbauto){ - pos[0] = v->Position[0]; - pos[1] = v->Position[1]; - bbtot[1] = pos[1]-1.5*dy-space;//top y - getbb(pos,v->Size[0],v->Size[1],dx,dy,tic,space,bbtot,bb); - Draw_Graph2D(v,pos[0],pos[1],v->Size[0],v->Size[1],tic,bb); + if(!v->AutoPosition || !nbauto) { + pos[0] = v->Position[0]; + pos[1] = v->Position[1]; + bbtot[1] = pos[1] - 1.5 * dy - space; //top y + getbb(pos, v->Size[0], v->Size[1], dx, dy, tic, space, bbtot, bb); + Draw_Graph2D(v, pos[0], pos[1], v->Size[0], v->Size[1], tic, bb); } - else{ - if(bbtot[3]+v->Size[1]+3*dy+2*space < CTX.viewport[3]){//try to put below - pos[1] = bbtot[3]+1.5*dy+space; - getbb(pos,v->Size[0],v->Size[1],dx,dy,tic,space,bbtot,bb); - Draw_Graph2D(v,pos[0],pos[1],v->Size[0],v->Size[1],tic,bb); - } - else{ //start a new column - pos[0]=bbtot[2]+dx+space; - pos[1]=bbtot[1]+1.5*dy+space; - getbb(pos,v->Size[0],v->Size[1],dx,dy,tic,space,bbtot,bb); - Draw_Graph2D(v,pos[0],pos[1],v->Size[0],v->Size[1],tic,bb); - } + else { + if(bbtot[3] + v->Size[1] + 3 * dy + 2 * space < CTX.viewport[3]) { //try to put below + pos[1] = bbtot[3] + 1.5 * dy + space; + getbb(pos, v->Size[0], v->Size[1], dx, dy, tic, space, bbtot, bb); + Draw_Graph2D(v, pos[0], pos[1], v->Size[0], v->Size[1], tic, bb); + } + else { //start a new column + pos[0] = bbtot[2] + dx + space; + pos[1] = bbtot[1] + 1.5 * dy + space; + getbb(pos, v->Size[0], v->Size[1], dx, dy, tic, space, bbtot, bb); + Draw_Graph2D(v, pos[0], pos[1], v->Size[0], v->Size[1], tic, bb); + } } nbauto++; } @@ -400,58 +430,69 @@ void Draw_Graph2D(void){ // T3D list of double: x,y,z,style,index,x,y,z,style,index,... // T3C list of chars: string\0,string\0,string\0,string\0,... -void Draw_Text2D3D(int dim, int timestep, int nb, List_T *td, List_T *tc){ - int j,k,l,nbd,index,nbchar; +void Draw_Text2D3D(int dim, int timestep, int nb, List_T * td, List_T * tc) +{ + int j, k, l, nbd, index, nbchar; char *c; double *d1, *d2, style, x, y, z; - if(dim==2) nbd=4; - else if(dim==3) nbd=5; - else return; + if(dim == 2) + nbd = 4; + else if(dim == 3) + nbd = 5; + else + return; -#if 0 //debug - if(nb){ - for(j=0; j<List_Nbr(tc); j++){ - c = (char*)List_Pointer(tc, j); +#if 0 //debug + if(nb) { + for(j = 0; j < List_Nbr(tc); j++) { + c = (char *)List_Pointer(tc, j); if(*c == '\0') - printf("|"); + printf("|"); else - printf("%c", *c); + printf("%c", *c); } printf("\n"); } #endif - for(j=0; j<nb; j++){ - d1 = (double*)List_Pointer(td, j*nbd); - d2 = (double*)List_Pointer_Test(td, (j+1)*nbd); - if(dim==2){ + for(j = 0; j < nb; j++) { + d1 = (double *)List_Pointer(td, j * nbd); + d2 = (double *)List_Pointer_Test(td, (j + 1) * nbd); + if(dim == 2) { x = d1[0]; - if(x<0) x = CTX.viewport[2] + x; - y = CTX.viewport[3]-d1[1]; - if(d1[1]<0) y = -d1[1]; + if(x < 0) + x = CTX.viewport[2] + x; + y = CTX.viewport[3] - d1[1]; + if(d1[1] < 0) + y = -d1[1]; z = 0.; style = d1[2]; index = (int)d1[3]; - if(d2) nbchar=(int)d2[3]-index; - else nbchar=List_Nbr(tc)-index; + if(d2) + nbchar = (int)d2[3] - index; + else + nbchar = List_Nbr(tc) - index; } - else{ + else { x = d1[0]; y = d1[1]; z = d1[2]; style = d1[3]; index = (int)d1[4]; - if(d2) nbchar=(int)d2[4]-index; - else nbchar=List_Nbr(tc)-index; + if(d2) + nbchar = (int)d2[4] - index; + else + nbchar = List_Nbr(tc) - index; } - glRasterPos3d(x,y,z); - c = (char*)List_Pointer(tc, index); - k=l=0; - while(k<nbchar && l!=timestep){ - if(c[k++]=='\0') l++; + glRasterPos3d(x, y, z); + c = (char *)List_Pointer(tc, index); + k = l = 0; + while(k < nbchar && l != timestep) { + if(c[k++] == '\0') + l++; } - if(k<nbchar && l==timestep) + if(k < nbchar && l == timestep) Draw_String(&c[k]); else Draw_String(c); @@ -459,19 +500,20 @@ void Draw_Text2D3D(int dim, int timestep, int nb, List_T *td, List_T *tc){ } -void Draw_Text2D(void){ +void Draw_Text2D(void) +{ int i; Post_View *v; - if(!CTX.post.list) return; + if(!CTX.post.list) + return; - glColor4ubv((GLubyte*)&CTX.color.text); + glColor4ubv((GLubyte *) & CTX.color.text); - for(i=0;i<List_Nbr(CTX.post.list);i++){ - v = (Post_View*)List_Pointer(CTX.post.list,i); - if(v->Visible && !v->Dirty && v->DrawStrings) + for(i = 0; i < List_Nbr(CTX.post.list); i++) { + v = (Post_View *) List_Pointer(CTX.post.list, i); + if(v->Visible && !v->Dirty && v->DrawStrings) Draw_Text2D3D(2, v->TimeStep, v->NbT2, v->T2D, v->T2C); } } - diff --git a/Graphics/Iso.cpp b/Graphics/Iso.cpp index 80ddeacc7c0190feaf51f34d249ff6474b3ccaac..5287a6fc7bf9eeb2c12761eca9796e36a5aed9e8 100644 --- a/Graphics/Iso.cpp +++ b/Graphics/Iso.cpp @@ -1,4 +1,4 @@ -// $Id: Iso.cpp,v 1.17 2003-02-05 01:35:08 geuzaine Exp $ +// $Id: Iso.cpp,v 1.18 2003-03-01 22:36:39 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -28,24 +28,27 @@ #include "Views.h" #include "Numeric.h" -extern Context_T CTX; +extern Context_T CTX; void RaiseFill(int i, double Val, double ValMin, double Raise[3][8]); // Iso line computation for triangles. -void CutTriangle1D(double *X, double *Y, double *Z, double *Val, - double V, double *Xp, double *Yp, double *Zp, int *nb){ - +void CutTriangle1D(double *X, double *Y, double *Z, double *Val, + double V, double *Xp, double *Yp, double *Zp, int *nb) +{ *nb = 0; - if((Val[0] >= V && Val[1] <= V) || (Val[1] >= V && Val[0] <= V)){ - InterpolateIso(X,Y,Z,Val,V,0,1,&Xp[*nb],&Yp[*nb],&Zp[*nb]); (*nb)++; + if((Val[0] >= V && Val[1] <= V) || (Val[1] >= V && Val[0] <= V)) { + InterpolateIso(X, Y, Z, Val, V, 0, 1, &Xp[*nb], &Yp[*nb], &Zp[*nb]); + (*nb)++; } - if((Val[0] >= V && Val[2] <= V) || (Val[2] >= V && Val[0] <= V)){ - InterpolateIso(X,Y,Z,Val,V,0,2,&Xp[*nb],&Yp[*nb],&Zp[*nb]); (*nb)++; + if((Val[0] >= V && Val[2] <= V) || (Val[2] >= V && Val[0] <= V)) { + InterpolateIso(X, Y, Z, Val, V, 0, 2, &Xp[*nb], &Yp[*nb], &Zp[*nb]); + (*nb)++; } - if((Val[1] >= V && Val[2] <= V) || (Val[2] >= V && Val[1] <= V)){ - InterpolateIso(X,Y,Z,Val,V,1,2,&Xp[*nb],&Yp[*nb],&Zp[*nb]); (*nb)++; + if((Val[1] >= V && Val[2] <= V) || (Val[2] >= V && Val[1] <= V)) { + InterpolateIso(X, Y, Z, Val, V, 1, 2, &Xp[*nb], &Yp[*nb], &Zp[*nb]); + (*nb)++; } } @@ -53,20 +56,21 @@ void CutTriangle1D(double *X, double *Y, double *Z, double *Val, // Contour computation for triangles. FIXME: the orientation of the // newly created polygons is wrong. -void CutTriangle2D(double *X, double *Y, double *Z, double *Val, - double V1, double V2, double *Xp2, double *Yp2, double *Zp2, - int *Np2, double *Vp2){ - - int i, io[3],j,iot,Np,Fl; - double Xp[5],Yp[5],Zp[5],Vp[5]; +void CutTriangle2D(double *X, double *Y, double *Z, double *Val, + double V1, double V2, double *Xp2, double *Yp2, + double *Zp2, int *Np2, double *Vp2) +{ + int i, io[3], j, iot, Np, Fl; + double Xp[5], Yp[5], Zp[5], Vp[5]; *Np2 = 0; - for(i=0;i<3;i++) io[i] = i; + for(i = 0; i < 3; i++) + io[i] = i; - for(i=0;i<2;i++){ - for(j=i+1;j<3;j++){ - if(Val[io[i]]>Val[io[j]]){ + for(i = 0; i < 2; i++) { + for(j = i + 1; j < 3; j++) { + if(Val[io[i]] > Val[io[j]]) { iot = io[i]; io[i] = io[j]; io[j] = iot; @@ -76,123 +80,139 @@ void CutTriangle2D(double *X, double *Y, double *Z, double *Val, // io[] contains an indexing of nodes such that Val[io[i]] > Val[io[j]] if i > j - if(Val[io[0]] > V2) return; - if(Val[io[2]] < V1) return; + if(Val[io[0]] > V2) + return; + if(Val[io[2]] < V1) + return; - if(V1 <= Val[io[0]] && Val[io[2]] <= V2){ - for(i=0;i<3;i++){ - Vp2[i]=Val[i]; - Xp2[i]=X[i]; - Yp2[i]=Y[i]; - Zp2[i]=Z[i]; + if(V1 <= Val[io[0]] && Val[io[2]] <= V2) { + for(i = 0; i < 3; i++) { + Vp2[i] = Val[i]; + Xp2[i] = X[i]; + Yp2[i] = Y[i]; + Zp2[i] = Z[i]; } *Np2 = 3; return; } Np = 0; - if(V1<=Val[io[0]]){ + if(V1 <= Val[io[0]]) { Vp[Np] = Val[io[0]]; - Xp[Np] = X[io[0]]; - Yp[Np] = Y[io[0]]; - Zp[Np] = Z[io[0]]; - Np++; Fl = 1; + Xp[Np] = X[io[0]]; + Yp[Np] = Y[io[0]]; + Zp[Np] = Z[io[0]]; + Np++; + Fl = 1; } - else if(Val[io[0]] < V1 && V1 <= Val[io[1]]){ + else if(Val[io[0]] < V1 && V1 <= Val[io[1]]) { Vp[Np] = V1; - InterpolateIso(X,Y,Z,Val,V1,io[0],io[2],&Xp[Np],&Yp[Np],&Zp[Np]); Np++; + InterpolateIso(X, Y, Z, Val, V1, io[0], io[2], &Xp[Np], &Yp[Np], &Zp[Np]); + Np++; Vp[Np] = V1; - InterpolateIso(X,Y,Z,Val,V1,io[0],io[1],&Xp[Np],&Yp[Np],&Zp[Np]); Np++; Fl = 1; + InterpolateIso(X, Y, Z, Val, V1, io[0], io[1], &Xp[Np], &Yp[Np], &Zp[Np]); + Np++; + Fl = 1; } else { Vp[Np] = V1; - InterpolateIso(X,Y,Z,Val,V1,io[0],io[2],&Xp[Np],&Yp[Np],&Zp[Np]); Np++; + InterpolateIso(X, Y, Z, Val, V1, io[0], io[2], &Xp[Np], &Yp[Np], &Zp[Np]); + Np++; Vp[Np] = V1; - InterpolateIso(X,Y,Z,Val,V1,io[1],io[2],&Xp[Np],&Yp[Np],&Zp[Np]); Np++; Fl = 0; - } + InterpolateIso(X, Y, Z, Val, V1, io[1], io[2], &Xp[Np], &Yp[Np], &Zp[Np]); + Np++; + Fl = 0; + } - if(V2 == Val[io[0]]){ + if(V2 == Val[io[0]]) { return; } - else if((Val[io[0]]<V2) && ( V2 < Val[io[1]])){ + else if((Val[io[0]] < V2) && (V2 < Val[io[1]])) { Vp[Np] = V2; - InterpolateIso(X,Y,Z,Val,V2,io[0],io[1],&Xp[Np],&Yp[Np],&Zp[Np]); Np++; + InterpolateIso(X, Y, Z, Val, V2, io[0], io[1], &Xp[Np], &Yp[Np], &Zp[Np]); + Np++; Vp[Np] = V2; - InterpolateIso(X,Y,Z,Val,V2,io[0],io[2],&Xp[Np],&Yp[Np],&Zp[Np]); Np++; + InterpolateIso(X, Y, Z, Val, V2, io[0], io[2], &Xp[Np], &Yp[Np], &Zp[Np]); + Np++; } - else if(V2 < Val[io[2]]){ - if(Fl){ + else if(V2 < Val[io[2]]) { + if(Fl) { Vp[Np] = Val[io[1]]; - Xp[Np] = X[io[1]]; - Yp[Np] = Y[io[1]]; + Xp[Np] = X[io[1]]; + Yp[Np] = Y[io[1]]; Zp[Np] = Z[io[1]]; Np++; } Vp[Np] = V2; - InterpolateIso(X,Y,Z,Val,V2,io[1],io[2],&Xp[Np],&Yp[Np],&Zp[Np]); Np++; + InterpolateIso(X, Y, Z, Val, V2, io[1], io[2], &Xp[Np], &Yp[Np], &Zp[Np]); + Np++; Vp[Np] = V2; - InterpolateIso(X,Y,Z,Val,V2,io[0],io[2],&Xp[Np],&Yp[Np],&Zp[Np]); Np++; + InterpolateIso(X, Y, Z, Val, V2, io[0], io[2], &Xp[Np], &Yp[Np], &Zp[Np]); + Np++; } - else{ - if(Fl){ + else { + if(Fl) { Vp[Np] = Val[io[1]]; Xp[Np] = X[io[1]]; - Yp[Np] = Y[io[1]]; + Yp[Np] = Y[io[1]]; Zp[Np] = Z[io[1]]; Np++; } Vp[Np] = Val[io[2]]; - Xp[Np] = X[io[2]]; - Yp[Np] = Y[io[2]]; + Xp[Np] = X[io[2]]; + Yp[Np] = Y[io[2]]; Zp[Np] = Z[io[2]]; Np++; } Vp2[0] = Vp[0]; - Xp2[0] = Xp[0]; - Yp2[0] = Yp[0]; - Zp2[0] = Zp[0]; + Xp2[0] = Xp[0]; + Yp2[0] = Yp[0]; + Zp2[0] = Zp[0]; *Np2 = 1; - for(i=1;i<Np;i++){ - if((Xp[i] != Xp2[(*Np2)-1]) ||(Yp[i] != Yp2[(*Np2)-1]) ||(Zp[i] != Zp2[(*Np2)-1])){ + for(i = 1; i < Np; i++) { + if((Xp[i] != Xp2[(*Np2) - 1]) || (Yp[i] != Yp2[(*Np2) - 1]) + || (Zp[i] != Zp2[(*Np2) - 1])) { Vp2[*Np2] = Vp[i]; - Xp2[*Np2] = Xp[i]; - Yp2[*Np2] = Yp[i]; + Xp2[*Np2] = Xp[i]; + Yp2[*Np2] = Yp[i]; Zp2[*Np2] = Zp[i]; (*Np2)++; } } - if(Xp2[0] == Xp2[(*Np2)-1] && Yp2[0] == Yp2[(*Np2)-1] && Zp2[0] == Zp2[(*Np2)-1]){ - (*Np2)-- ; + if(Xp2[0] == Xp2[(*Np2) - 1] && Yp2[0] == Yp2[(*Np2) - 1] + && Zp2[0] == Zp2[(*Np2) - 1]) { + (*Np2)--; } } // Iso for lines -void CutLine0D(double *X, double *Y, double *Z, double *Val, - double V, double *Xp, double *Yp, double *Zp, int *nb){ - +void CutLine0D(double *X, double *Y, double *Z, double *Val, + double V, double *Xp, double *Yp, double *Zp, int *nb) +{ *nb = 0; - if((Val[0] >= V && Val[1] <= V) || (Val[1] >= V && Val[0] <= V)){ - InterpolateIso(X,Y,Z,Val,V,0,1,Xp,Yp,Zp); *nb = 1; + if((Val[0] >= V && Val[1] <= V) || (Val[1] >= V && Val[0] <= V)) { + InterpolateIso(X, Y, Z, Val, V, 0, 1, Xp, Yp, Zp); + *nb = 1; } } -void CutLine1D(double *X, double *Y, double *Z, double *Val, +void CutLine1D(double *X, double *Y, double *Z, double *Val, double V1, double V2, double *Xp2, double *Yp2, double *Zp2, - int *Np2, double *Vp2){ - + int *Np2, double *Vp2) +{ int i, io[2]; - if(Val[0]<Val[1]){ + if(Val[0] < Val[1]) { io[0] = 0; io[1] = 1; } - else{ + else { io[0] = 1; io[1] = 0; } @@ -201,77 +221,79 @@ void CutLine1D(double *X, double *Y, double *Z, double *Val, *Np2 = 0; - if(Val[io[0]] > V2) return; - if(Val[io[1]] < V1) return; + if(Val[io[0]] > V2) + return; + if(Val[io[1]] < V1) + return; *Np2 = 2; - if(V1 <= Val[io[0]] && Val[io[1]] <= V2){ - for(i=0;i<2;i++){ - Vp2[i]=Val[i]; - Xp2[i]=X[i]; - Yp2[i]=Y[i]; - Zp2[i]=Z[i]; + if(V1 <= Val[io[0]] && Val[io[1]] <= V2) { + for(i = 0; i < 2; i++) { + Vp2[i] = Val[i]; + Xp2[i] = X[i]; + Yp2[i] = Y[i]; + Zp2[i] = Z[i]; } return; } - if(V1<=Val[io[0]]){ + if(V1 <= Val[io[0]]) { Vp2[0] = Val[io[0]]; - Xp2[0] = X[io[0]]; - Yp2[0] = Y[io[0]]; - Zp2[0] = Z[io[0]]; + Xp2[0] = X[io[0]]; + Yp2[0] = Y[io[0]]; + Zp2[0] = Z[io[0]]; } - else{ + else { Vp2[0] = V1; - InterpolateIso(X,Y,Z,Val,V1,io[0],io[1],&Xp2[0],&Yp2[0],&Zp2[0]); + InterpolateIso(X, Y, Z, Val, V1, io[0], io[1], &Xp2[0], &Yp2[0], &Zp2[0]); } - if(V2>=Val[io[1]]){ + if(V2 >= Val[io[1]]) { Vp2[1] = Val[io[1]]; - Xp2[1] = X[io[1]]; - Yp2[1] = Y[io[1]]; - Zp2[1] = Z[io[1]]; + Xp2[1] = X[io[1]]; + Yp2[1] = Y[io[1]]; + Zp2[1] = Z[io[1]]; } - else{ + else { Vp2[1] = V2; - InterpolateIso(X,Y,Z,Val,V2,io[0],io[1],&Xp2[1],&Yp2[1],&Zp2[1]); + InterpolateIso(X, Y, Z, Val, V2, io[0], io[1], &Xp2[1], &Yp2[1], &Zp2[1]); } } // compute the gradient of a linear interpolation in a tetrahedron -void EnhanceSimplexPolygon (Post_View *View, - int nb, // nb of points in polygon - double *Xp, // x positions - double *Yp, // y positions - double *Zp, // z positions - double *Valp, // values at points - double *X, // x positions of the simplex - double *Y, // y positions of the simplex - double *Z, // z posistions of the simplex - double *Val, // values at simplex points - double *norms, // output : normals at points - int preproNormals // do we compute normals or do we get them - ){ +void EnhanceSimplexPolygon(Post_View * View, int nb, // nb of points in polygon + double *Xp, // x positions + double *Yp, // y positions + double *Zp, // z positions + double *Valp, // values at points + double *X, // x positions of the simplex + double *Y, // y positions of the simplex + double *Z, // z posistions of the simplex + double *Val, // values at simplex points + double *norms, // output : normals at points + int preproNormals // do we compute normals or do we get them + ) +{ /* - 3 possibilities for quads - -) 0,2,5,3 - -) 0,1,5,4 - -) 1,2,4,3 - in all cases, simply invert the 2 last ones - for having the quads ordered + 3 possibilities for quads + -) 0,2,5,3 + -) 0,1,5,4 + -) 1,2,4,3 + in all cases, simply invert the 2 last ones + for having the quads ordered */ int i; - double Xpi[6],Ypi[6],Zpi[6]; - - if(nb == 4){ - double xx = Xp[3]; - double yy = Yp[3]; - double zz = Zp[3]; - Xp[3] = Xp[2]; - Yp[3] = Yp[2]; + double Xpi[6], Ypi[6], Zpi[6]; + + if(nb == 4) { + double xx = Xp[3]; + double yy = Yp[3]; + double zz = Zp[3]; + Xp[3] = Xp[2]; + Yp[3] = Yp[2]; Zp[3] = Zp[2]; Xp[2] = xx; Yp[2] = yy; @@ -279,107 +301,119 @@ void EnhanceSimplexPolygon (Post_View *View, } /* - for having a nice isosurface, we should have n . grad v > 0 - n = normal to the polygon - v = unknown field we wanna draw + for having a nice isosurface, we should have n . grad v > 0 + n = normal to the polygon + v = unknown field we wanna draw */ - if(!View->Light){ - norms = NULL; // we don't need to compute these + if(!View->Light) { + norms = NULL; // we don't need to compute these return; } - double v1[3] = {Xp[2]-Xp[0],Yp[2]-Yp[0],Zp[2]-Zp[0]}; - double v2[3] = {Xp[1]-Xp[0],Yp[1]-Yp[0],Zp[1]-Zp[0]}; + double v1[3] = { Xp[2] - Xp[0], Yp[2] - Yp[0], Zp[2] - Zp[0] }; + double v2[3] = { Xp[1] - Xp[0], Yp[1] - Yp[0], Zp[1] - Zp[0] }; double gr[3]; - double n[3],xx; - prodve(v1,v2,n); + double n[3], xx; + prodve(v1, v2, n); //norme(n); not necessary since GL_NORMALIZE is enabled - gradSimplex(X,Y,Z,Val,gr); - prosca(gr,n,&xx); - - if(xx > 0){ - for(i=0;i<nb;i++){ + gradSimplex(X, Y, Z, Val, gr); + prosca(gr, n, &xx); + + if(xx > 0) { + for(i = 0; i < nb; i++) { Xpi[i] = Xp[i]; Ypi[i] = Yp[i]; Zpi[i] = Zp[i]; } - for(i=0;i<nb;i++){ - Xp[i] = Xpi[nb-i-1]; - Yp[i] = Ypi[nb-i-1]; - Zp[i] = Zpi[nb-i-1]; + for(i = 0; i < nb; i++) { + Xp[i] = Xpi[nb - i - 1]; + Yp[i] = Ypi[nb - i - 1]; + Zp[i] = Zpi[nb - i - 1]; } } - else{ + else { n[0] = -n[0]; n[1] = -n[1]; n[2] = -n[2]; } - - if(View->SmoothNormals){ - if(preproNormals){ - for(i=0;i<nb;i++){ - View->add_normal(Xp[i],Yp[i],Zp[i],n[0],n[1],n[2]); + + if(View->SmoothNormals) { + if(preproNormals) { + for(i = 0; i < nb; i++) { + View->add_normal(Xp[i], Yp[i], Zp[i], n[0], n[1], n[2]); } return; } - else{ - for(i=0;i<nb;i++){ - norms[3*i] = n[0]; - norms[3*i+1] = n[1]; - norms[3*i+2] = n[2]; - if(!View->get_normal(Xp[i],Yp[i],Zp[i],norms[3*i],norms[3*i+1],norms[3*i+2])){ - //Msg(WARNING, "Oups, did not find smoothed normal"); - } - } + else { + for(i = 0; i < nb; i++) { + norms[3 * i] = n[0]; + norms[3 * i + 1] = n[1]; + norms[3 * i + 2] = n[2]; + if(!View-> + get_normal(Xp[i], Yp[i], Zp[i], norms[3 * i], norms[3 * i + 1], + norms[3 * i + 2])) { + //Msg(WARNING, "Oups, did not find smoothed normal"); + } + } } } - else{ - for(i=0;i<nb;i++){ - norms[3*i] = n[0]; - norms[3*i+1] = n[1]; - norms[3*i+2] = n[2]; + else { + for(i = 0; i < nb; i++) { + norms[3 * i] = n[0]; + norms[3 * i + 1] = n[1]; + norms[3 * i + 2] = n[2]; } } } -void IsoSimplex( Post_View *View, - int preproNormals, - double *X, double *Y, double *Z, double *Val, - double V, double Raise[3][8]){ - int nb; - double Xp[6],Yp[6],Zp[6],PVals[6]; +void IsoSimplex(Post_View * View, + int preproNormals, + double *X, double *Y, double *Z, double *Val, + double V, double Raise[3][8]) +{ + int nb; + double Xp[6], Yp[6], Zp[6], PVals[6]; double norms[12]; nb = 0; - if((Val[0] >= V && Val[1] <= V) || (Val[1] >= V && Val[0] <= V)){ - InterpolateIso(X,Y,Z,Val,V,0,1,&Xp[nb],&Yp[nb],&Zp[nb]); nb++; + if((Val[0] >= V && Val[1] <= V) || (Val[1] >= V && Val[0] <= V)) { + InterpolateIso(X, Y, Z, Val, V, 0, 1, &Xp[nb], &Yp[nb], &Zp[nb]); + nb++; } - if((Val[0] >= V && Val[2] <= V) || (Val[2] >= V && Val[0] <= V)){ - InterpolateIso(X,Y,Z,Val,V,0,2,&Xp[nb],&Yp[nb],&Zp[nb]); nb++; + if((Val[0] >= V && Val[2] <= V) || (Val[2] >= V && Val[0] <= V)) { + InterpolateIso(X, Y, Z, Val, V, 0, 2, &Xp[nb], &Yp[nb], &Zp[nb]); + nb++; } - if((Val[0] >= V && Val[3] <= V) || (Val[3] >= V && Val[0] <= V)){ - InterpolateIso(X,Y,Z,Val,V,0,3,&Xp[nb],&Yp[nb],&Zp[nb]); nb++; + if((Val[0] >= V && Val[3] <= V) || (Val[3] >= V && Val[0] <= V)) { + InterpolateIso(X, Y, Z, Val, V, 0, 3, &Xp[nb], &Yp[nb], &Zp[nb]); + nb++; } - if((Val[1] >= V && Val[2] <= V) || (Val[2] >= V && Val[1] <= V)){ - InterpolateIso(X,Y,Z,Val,V,1,2,&Xp[nb],&Yp[nb],&Zp[nb]); nb++; + if((Val[1] >= V && Val[2] <= V) || (Val[2] >= V && Val[1] <= V)) { + InterpolateIso(X, Y, Z, Val, V, 1, 2, &Xp[nb], &Yp[nb], &Zp[nb]); + nb++; } - if((Val[1] >= V && Val[3] <= V) || (Val[3] >= V && Val[1] <= V)){ - InterpolateIso(X,Y,Z,Val,V,1,3,&Xp[nb],&Yp[nb],&Zp[nb]); nb++; + if((Val[1] >= V && Val[3] <= V) || (Val[3] >= V && Val[1] <= V)) { + InterpolateIso(X, Y, Z, Val, V, 1, 3, &Xp[nb], &Yp[nb], &Zp[nb]); + nb++; } - if((Val[2] >= V && Val[3] <= V) || (Val[3] >= V && Val[2] <= V)){ - InterpolateIso(X,Y,Z,Val,V,2,3,&Xp[nb],&Yp[nb],&Zp[nb]); nb++; + if((Val[2] >= V && Val[3] <= V) || (Val[3] >= V && Val[2] <= V)) { + InterpolateIso(X, Y, Z, Val, V, 2, 3, &Xp[nb], &Yp[nb], &Zp[nb]); + nb++; } - if(nb < 3 || nb > 4) return; + if(nb < 3 || nb > 4) + return; - EnhanceSimplexPolygon (View, nb, Xp, Yp, Zp, PVals, X, Y, Z, Val, norms, preproNormals); + EnhanceSimplexPolygon(View, nb, Xp, Yp, Zp, PVals, X, Y, Z, Val, norms, + preproNormals); - if(preproNormals) return; + if(preproNormals) + return; - if(nb == 3) - Draw_Triangle(Xp,Yp,Zp,norms,Raise,View->Light); + if(nb == 3) + Draw_Triangle(Xp, Yp, Zp, norms, Raise, View->Light); else if(nb == 4) - Draw_Quadrangle(Xp,Yp,Zp,norms,Raise,View->Light); + Draw_Quadrangle(Xp, Yp, Zp, norms, Raise, View->Light); } diff --git a/Graphics/Mesh.cpp b/Graphics/Mesh.cpp index 975926910b4670b39fa5af845f6778aa35be8c75..479b66994cb0e18180eaf5e31fce5243a579dec1 100644 --- a/Graphics/Mesh.cpp +++ b/Graphics/Mesh.cpp @@ -1,4 +1,4 @@ -// $Id: Mesh.cpp,v 1.57 2003-02-14 04:02:30 geuzaine Exp $ +// $Id: Mesh.cpp,v 1.58 2003-03-01 22:36:39 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -31,24 +31,27 @@ #include "Verif.h" #include "Numeric.h" -extern Mesh *THEM; -extern Context_T CTX; +extern Mesh *THEM; +extern Context_T CTX; -void draw_polygon_2d (double r, double g, double b, int n, - double *x, double *y, double *z){ - int i ; +void draw_polygon_2d(double r, double g, double b, int n, + double *x, double *y, double *z) +{ + int i; - CalculateMinMax(THEM->Points,NULL); + CalculateMinMax(THEM->Points, NULL); InitOpengl(); InitPosition(); glDisable(GL_DEPTH_TEST); glDrawBuffer(GL_FRONT); - glColor3f(r,g,b); + glColor3f(r, g, b); glBegin(GL_LINE_STRIP); - for(i=0 ; i<n ; i++) - if(z)glVertex3d(x[i], y[i],z[i]); - else glVertex2d(x[i], y[i]); + for(i = 0; i < n; i++) + if(z) + glVertex3d(x[i], y[i], z[i]); + else + glVertex2d(x[i], y[i]); glEnd(); glFlush(); glDrawBuffer(GL_BACK); @@ -59,16 +62,19 @@ void draw_polygon_2d (double r, double g, double b, int n, static int iColor; static DrawingColor theColor; -void ColorSwitch(int i){ - glColor4ubv((GLubyte*)&CTX.color.mesh.carousel[i%10]); +void ColorSwitch(int i) +{ + glColor4ubv((GLubyte *) & CTX.color.mesh.carousel[i % 10]); } -static int DrawVertexSupp ; +static int DrawVertexSupp; -void Draw_Mesh (Mesh *M) { +void Draw_Mesh(Mesh * M) +{ int i; - if(!CTX.moving_light) InitRenderModel(); + if(!CTX.moving_light) + InitRenderModel(); if(CTX.mesh.shade) InitShading(); @@ -76,35 +82,37 @@ void Draw_Mesh (Mesh *M) { InitNoShading(); InitPosition(); - if(CTX.moving_light) InitRenderModel(); + if(CTX.moving_light) + InitRenderModel(); - for(i = 0 ; i < 6 ; i++) + for(i = 0; i < 6; i++) if(CTX.clip[i]) - glClipPlane((GLenum)(GL_CLIP_PLANE0 + i), CTX.clip_plane[i]); + glClipPlane((GLenum) (GL_CLIP_PLANE0 + i), CTX.clip_plane[i]); - glPointSize(CTX.mesh.point_size); + glPointSize(CTX.mesh.point_size); gl2psPointSize(CTX.mesh.point_size * CTX.print.eps_point_size_factor); - glLineWidth(CTX.mesh.line_width); + glLineWidth(CTX.mesh.line_width); gl2psLineWidth(CTX.mesh.line_width * CTX.print.eps_line_width_factor); - if(CTX.mesh.hidden) glEnable(GL_POLYGON_OFFSET_FILL); + if(CTX.mesh.hidden) + glEnable(GL_POLYGON_OFFSET_FILL); // draw the bbox of the mesh in fast redraw mode if there is no geometry - if(!CTX.mesh.draw && Tree_Nbr(M->Vertices) && !Tree_Nbr(M->Points)){ - glColor4ubv((GLubyte*)&CTX.color.fg); + if(!CTX.mesh.draw && Tree_Nbr(M->Vertices) && !Tree_Nbr(M->Points)) { + glColor4ubv((GLubyte *) & CTX.color.fg); glBegin(GL_LINE_LOOP); glVertex3d(CTX.min[0], CTX.min[1], CTX.min[2]); glVertex3d(CTX.max[0], CTX.min[1], CTX.min[2]); glVertex3d(CTX.max[0], CTX.max[1], CTX.min[2]); glVertex3d(CTX.min[0], CTX.max[1], CTX.min[2]); - glEnd(); + glEnd(); glBegin(GL_LINE_LOOP); glVertex3d(CTX.min[0], CTX.min[1], CTX.max[2]); glVertex3d(CTX.max[0], CTX.min[1], CTX.max[2]); glVertex3d(CTX.max[0], CTX.max[1], CTX.max[2]); glVertex3d(CTX.min[0], CTX.max[1], CTX.max[2]); - glEnd(); + glEnd(); glBegin(GL_LINES); glVertex3d(CTX.min[0], CTX.min[1], CTX.min[2]); glVertex3d(CTX.min[0], CTX.min[1], CTX.max[2]); @@ -114,80 +122,86 @@ void Draw_Mesh (Mesh *M) { glVertex3d(CTX.max[0], CTX.max[1], CTX.max[2]); glVertex3d(CTX.min[0], CTX.max[1], CTX.min[2]); glVertex3d(CTX.min[0], CTX.max[1], CTX.max[2]); - glEnd(); + glEnd(); } iColor = 0; - if(CTX.mesh.draw && CTX.render_mode != GMSH_SELECT){ + if(CTX.mesh.draw && CTX.render_mode != GMSH_SELECT) { static int first = 1, listnum; - if(CTX.mesh.display_lists && CTX.mesh.changed){ - if(first) listnum = glGenLists(1); + if(CTX.mesh.display_lists && CTX.mesh.changed) { + if(first) + listnum = glGenLists(1); first = 0; //printf("new mesh display list\n"); glNewList(listnum, GL_COMPILE_AND_EXECUTE); } - - if(!CTX.mesh.display_lists || (CTX.mesh.display_lists && CTX.mesh.changed)){ + + if(!CTX.mesh.display_lists + || (CTX.mesh.display_lists && CTX.mesh.changed)) { //printf("normal mesh drawing\n"); - if(M->status >= 3 && (CTX.mesh.volumes || CTX.mesh.volumes_num)){ - Tree_Action(M->Volumes, Draw_Mesh_Volumes); + if(M->status >= 3 && (CTX.mesh.volumes || CTX.mesh.volumes_num)) { + Tree_Action(M->Volumes, Draw_Mesh_Volumes); } - - if(M->status >= 2 && (CTX.mesh.surfaces || CTX.mesh.surfaces_num)){ - Tree_Action(M->Surfaces, Draw_Mesh_Surfaces); - if(CTX.mesh.oldxtrude)//old extrusion algo - Tree_Action(M->Volumes, Draw_Mesh_Extruded_Surfaces); + + if(M->status >= 2 && (CTX.mesh.surfaces || CTX.mesh.surfaces_num)) { + Tree_Action(M->Surfaces, Draw_Mesh_Surfaces); + if(CTX.mesh.oldxtrude) //old extrusion algo + Tree_Action(M->Volumes, Draw_Mesh_Extruded_Surfaces); } - - if(M->status >= 1 && (CTX.mesh.lines || CTX.mesh.lines_num)){ - Tree_Action(M->Curves, Draw_Mesh_Curves); - DrawVertexSupp = 1 ; - Tree_Action(M->VertexEdges, Draw_Mesh_Points); + + if(M->status >= 1 && (CTX.mesh.lines || CTX.mesh.lines_num)) { + Tree_Action(M->Curves, Draw_Mesh_Curves); + DrawVertexSupp = 1; + Tree_Action(M->VertexEdges, Draw_Mesh_Points); } - - if(M->status >= 0 && (CTX.mesh.points || CTX.mesh.points_num)){ - DrawVertexSupp = 0 ; - Tree_Action(M->Vertices, Draw_Mesh_Points); + + if(M->status >= 0 && (CTX.mesh.points || CTX.mesh.points_num)) { + DrawVertexSupp = 0; + Tree_Action(M->Vertices, Draw_Mesh_Points); } - + } - else{ + else { //printf("calling mesh display list\n"); glCallList(listnum); } - if(CTX.mesh.display_lists){ - if(CTX.mesh.changed){ - glEndList(); - CTX.mesh.changed=0; + if(CTX.mesh.display_lists) { + if(CTX.mesh.changed) { + glEndList(); + CTX.mesh.changed = 0; } } - + } - if(M->status >= 0){ - if(!CTX.geom.shade) InitNoShading(); + if(M->status >= 0) { + if(!CTX.geom.shade) + InitNoShading(); Draw_Geom(M); } - if(CTX.mesh.hidden) glDisable(GL_POLYGON_OFFSET_FILL); + if(CTX.mesh.hidden) + glDisable(GL_POLYGON_OFFSET_FILL); - if(CTX.render_mode != GMSH_SELECT){ - if(CTX.axes) Draw_Axes(CTX.lc_middle/4.); - Draw_Post(); // les init de shading se font par view + if(CTX.render_mode != GMSH_SELECT) { + if(CTX.axes) + Draw_Axes(CTX.lc_middle / 4.); + Draw_Post(); // les init de shading se font par view } } -void Draw_Mesh_Volumes(void *a, void *b){ +void Draw_Mesh_Volumes(void *a, void *b) +{ Volume *v; - v = *(Volume**)a; + v = *(Volume **) a; iColor++; theColor = v->Color; // FIXME: this is the correct method, but will only work when a @@ -199,221 +213,247 @@ void Draw_Mesh_Volumes(void *a, void *b){ Tree_Action(v->Pyramids, Draw_Pyramid_Volume); } -int Test_Simple_Surface_Draw(){ +int Test_Simple_Surface_Draw() +{ if(CTX.mesh.use_cut_plane || CTX.mesh.explode != 1.0 || - CTX.mesh.dual || - CTX.mesh.surfaces_num || - CTX.mesh.normals) + CTX.mesh.dual || CTX.mesh.surfaces_num || CTX.mesh.normals) return 0; //printf("simple simplex surface drawing\n"); return 1; } -void Draw_Mesh_Surfaces (void *a,void *b){ +void Draw_Mesh_Surfaces(void *a, void *b) +{ Surface *s; - s = *(Surface**)a; + s = *(Surface **) a; iColor++; theColor = s->Color; - if(!(s->Visible & VIS_MESH)) return; + if(!(s->Visible & VIS_MESH)) + return; if(!Test_Simple_Surface_Draw()) Tree_Action(s->Simplexes, Draw_Simplex_Surface); else Tree_Action(s->Simplexes, Draw_Simplex_Surface_Simple); } -void Draw_Mesh_Extruded_Surfaces(void *a, void *b){ +void Draw_Mesh_Extruded_Surfaces(void *a, void *b) +{ Volume *v; - v = *(Volume**)a; - if(!(v->Visible & VIS_MESH)) return; + v = *(Volume **) a; + if(!(v->Visible & VIS_MESH)) + return; if(!Test_Simple_Surface_Draw()) Tree_Action(v->Simp_Surf, Draw_Simplex_Surface); else Tree_Action(v->Simp_Surf, Draw_Simplex_Surface_Simple); } -void Draw_Mesh_Curves (void *a, void *b){ +void Draw_Mesh_Curves(void *a, void *b) +{ Curve *c; - c = *(Curve**)a; - if(c->Num < 0) return; + c = *(Curve **) a; + if(c->Num < 0) + return; iColor++; theColor = c->Color; - if(!(c->Visible & VIS_MESH)) return; - Tree_Action(c->Simplexes,Draw_Simplex_Curves); + if(!(c->Visible & VIS_MESH)) + return; + Tree_Action(c->Simplexes, Draw_Simplex_Curves); } -void Draw_Mesh_Points (void *a, void *b){ +void Draw_Mesh_Points(void *a, void *b) +{ Vertex *v; char Num[100]; - v = *(Vertex**)a; + v = *(Vertex **) a; - if(!(v->Visible & VIS_MESH)) return; + if(!(v->Visible & VIS_MESH)) + return; - if(CTX.mesh.use_cut_plane){ - if(CTX.mesh.evalCutPlane(v->Pos.X, v->Pos.Y, v->Pos.Z) < 0) return; + if(CTX.mesh.use_cut_plane) { + if(CTX.mesh.evalCutPlane(v->Pos.X, v->Pos.Y, v->Pos.Z) < 0) + return; } - - if(CTX.render_mode == GMSH_SELECT){ + + if(CTX.render_mode == GMSH_SELECT) { glLoadName(0); glPushName(v->Num); } - if(DrawVertexSupp) - glColor4ubv((GLubyte*)&CTX.color.mesh.vertex_supp); + if(DrawVertexSupp) + glColor4ubv((GLubyte *) & CTX.color.mesh.vertex_supp); else - glColor4ubv((GLubyte*)&CTX.color.mesh.vertex); + glColor4ubv((GLubyte *) & CTX.color.mesh.vertex); - if(CTX.mesh.points){ - if(CTX.mesh.point_type){ + if(CTX.mesh.points) { + if(CTX.mesh.point_type) { Draw_Sphere(CTX.mesh.point_size, v->Pos.X, v->Pos.Y, v->Pos.Z); } - else{ + else { glBegin(GL_POINTS); glVertex3d(v->Pos.X, v->Pos.Y, v->Pos.Z); glEnd(); } } - - if(CTX.mesh.points_num){ - sprintf(Num,"%d",v->Num); - glRasterPos3d(v->Pos.X+3*CTX.pixel_equiv_x/CTX.s[0], - v->Pos.Y+3*CTX.pixel_equiv_x/CTX.s[1], - v->Pos.Z+3*CTX.pixel_equiv_x/CTX.s[2]); + + if(CTX.mesh.points_num) { + sprintf(Num, "%d", v->Num); + glRasterPos3d(v->Pos.X + 3 * CTX.pixel_equiv_x / CTX.s[0], + v->Pos.Y + 3 * CTX.pixel_equiv_x / CTX.s[1], + v->Pos.Z + 3 * CTX.pixel_equiv_x / CTX.s[2]); Draw_String(Num); } - - if(CTX.render_mode == GMSH_SELECT){ + + if(CTX.render_mode == GMSH_SELECT) { glPopName(); } } // Draw simplex -void Draw_Simplex_Volume (void *a, void *b){ +void Draw_Simplex_Volume(void *a, void *b) +{ Simplex *s; char Num[100]; int fulldraw = 0; - double tmp, X[4],Y[4],Z[4]; + double tmp, X[4], Y[4], Z[4]; - s = *(Simplex**)a; + s = *(Simplex **) a; - if(!s->V[3] || !(s->Visible & VIS_MESH)) return; + if(!s->V[3] || !(s->Visible & VIS_MESH)) + return; // FIXME: remove as soon as a coherent structure exists for volumes - Volume *V; if((V = FindVolume(s->iEnt,THEM)) && !(V->Visible & VIS_MESH)) return; + Volume *V; + if((V = FindVolume(s->iEnt, THEM)) && !(V->Visible & VIS_MESH)) + return; - if(CTX.mesh.gamma_sup){ + if(CTX.mesh.gamma_sup) { tmp = s->GammaShapeMeasure(); - if(tmp < CTX.mesh.gamma_inf || tmp > CTX.mesh.gamma_sup) return; + if(tmp < CTX.mesh.gamma_inf || tmp > CTX.mesh.gamma_sup) + return; fulldraw = 1; } - if(CTX.mesh.radius_sup){ - if(s->Radius < CTX.mesh.radius_inf || s->Radius > CTX.mesh.radius_sup) return; + if(CTX.mesh.radius_sup) { + if(s->Radius < CTX.mesh.radius_inf || s->Radius > CTX.mesh.radius_sup) + return; fulldraw = 1; } - double Xc = .25 * (s->V[0]->Pos.X + s->V[1]->Pos.X + + double Xc = .25 * (s->V[0]->Pos.X + s->V[1]->Pos.X + s->V[2]->Pos.X + s->V[3]->Pos.X); - double Yc = .25 * (s->V[0]->Pos.Y + s->V[1]->Pos.Y + + double Yc = .25 * (s->V[0]->Pos.Y + s->V[1]->Pos.Y + s->V[2]->Pos.Y + s->V[3]->Pos.Y); - double Zc = .25 * (s->V[0]->Pos.Z + s->V[1]->Pos.Z + + double Zc = .25 * (s->V[0]->Pos.Z + s->V[1]->Pos.Z + s->V[2]->Pos.Z + s->V[3]->Pos.Z); - if(CTX.mesh.use_cut_plane){ - if(CTX.mesh.evalCutPlane(Xc,Yc,Zc) < 0) return; + if(CTX.mesh.use_cut_plane) { + if(CTX.mesh.evalCutPlane(Xc, Yc, Zc) < 0) + return; fulldraw = 1; } if(CTX.mesh.color_carousel && !fulldraw) ColorSwitch(s->iEnt); else if(fulldraw) - glColor4ubv((GLubyte*)&CTX.color.mesh.line); + glColor4ubv((GLubyte *) & CTX.color.mesh.line); else - glColor4ubv((GLubyte*)&CTX.color.mesh.tetrahedron); + glColor4ubv((GLubyte *) & CTX.color.mesh.tetrahedron); // this is killing us!!! - for (int i=0 ; i<4 ; i++) { + for(int i = 0; i < 4; i++) { X[i] = Xc + CTX.mesh.explode * (s->V[i]->Pos.X - Xc); Y[i] = Yc + CTX.mesh.explode * (s->V[i]->Pos.Y - Yc); Z[i] = Zc + CTX.mesh.explode * (s->V[i]->Pos.Z - Zc); } - if(CTX.mesh.shade) glDisable(GL_LIGHTING); + if(CTX.mesh.shade) + glDisable(GL_LIGHTING); - if(CTX.mesh.volumes && !(fulldraw && CTX.mesh.shade)){ + if(CTX.mesh.volumes && !(fulldraw && CTX.mesh.shade)) { glBegin(GL_LINES); glVertex3d(X[1], Y[1], Z[1]); glVertex3d(X[0], Y[0], Z[0]); - + glVertex3d(X[2], Y[2], Z[2]); glVertex3d(X[0], Y[0], Z[0]); - + glVertex3d(X[3], Y[3], Z[3]); glVertex3d(X[0], Y[0], Z[0]); - + glVertex3d(X[3], Y[3], Z[3]); glVertex3d(X[1], Y[1], Z[1]); - + glVertex3d(X[3], Y[3], Z[3]); glVertex3d(X[2], Y[2], Z[2]); - + glVertex3d(X[1], Y[1], Z[1]); glVertex3d(X[2], Y[2], Z[2]); - + glVertex3d(X[2], Y[2], Z[2]); glVertex3d(X[3], Y[3], Z[3]); glEnd(); } - if(CTX.mesh.volumes_num){ - sprintf(Num,"%d",s->Num); - glRasterPos3d(Xc,Yc,Zc); + if(CTX.mesh.volumes_num) { + sprintf(Num, "%d", s->Num); + glRasterPos3d(Xc, Yc, Zc); Draw_String(Num); } - if (CTX.mesh.dual){ - glColor4ubv((GLubyte*)&CTX.color.fg); + if(CTX.mesh.dual) { + glColor4ubv((GLubyte *) & CTX.color.fg); glEnable(GL_LINE_STIPPLE); - glLineStipple(1,0x0F0F); + glLineStipple(1, 0x0F0F); gl2psEnable(GL2PS_LINE_STIPPLE); glBegin(GL_LINES); - glVertex3d(Xc, Yc, Zc); - glVertex3d((X[0]+X[1]+X[2])/3., (Y[0]+Y[1]+Y[2])/3., (Z[0]+Z[1]+Z[2])/3.); - glVertex3d(Xc, Yc, Zc); - glVertex3d((X[0]+X[1]+X[3])/3., (Y[0]+Y[1]+Y[3])/3., (Z[0]+Z[1]+Z[3])/3.); - glVertex3d(Xc, Yc, Zc); - glVertex3d((X[0]+X[2]+X[3])/3., (Y[0]+Y[2]+Y[3])/3., (Z[0]+Z[2]+Z[3])/3.); - glVertex3d(Xc, Yc, Zc); - glVertex3d((X[1]+X[2]+X[3])/3., (Y[1]+Y[2]+Y[3])/3., (Z[1]+Z[2]+Z[3])/3.); + glVertex3d(Xc, Yc, Zc); + glVertex3d((X[0] + X[1] + X[2]) / 3., (Y[0] + Y[1] + Y[2]) / 3., + (Z[0] + Z[1] + Z[2]) / 3.); + glVertex3d(Xc, Yc, Zc); + glVertex3d((X[0] + X[1] + X[3]) / 3., (Y[0] + Y[1] + Y[3]) / 3., + (Z[0] + Z[1] + Z[3]) / 3.); + glVertex3d(Xc, Yc, Zc); + glVertex3d((X[0] + X[2] + X[3]) / 3., (Y[0] + Y[2] + Y[3]) / 3., + (Z[0] + Z[2] + Z[3]) / 3.); + glVertex3d(Xc, Yc, Zc); + glVertex3d((X[1] + X[2] + X[3]) / 3., (Y[1] + Y[2] + Y[3]) / 3., + (Z[1] + Z[2] + Z[3]) / 3.); glEnd(); glDisable(GL_LINE_STIPPLE); gl2psDisable(GL2PS_LINE_STIPPLE); } - if(CTX.mesh.shade) glEnable(GL_LIGHTING); + if(CTX.mesh.shade) + glEnable(GL_LIGHTING); - if(!fulldraw) return ; + if(!fulldraw) + return; double n[4], x1x0, y1y0, z1z0, x2x0, y2y0, z2z0; if(CTX.mesh.color_carousel) ColorSwitch(s->iEnt); else - glColor4ubv((GLubyte*)&CTX.color.mesh.tetrahedron); - - if (CTX.mesh.hidden) { - - if(CTX.mesh.shade){ - x1x0 = X[2]-X[0]; y1y0 = Y[2]-Y[0]; - z1z0 = Z[2]-Z[0]; x2x0 = X[1]-X[0]; - y2y0 = Y[1]-Y[0]; z2z0 = Z[1]-Z[0]; - n[0] = y1y0 * z2z0 - z1z0 * y2y0 ; - n[1] = z1z0 * x2x0 - x1x0 * z2z0 ; - n[2] = x1x0 * y2y0 - y1y0 * x2x0; + glColor4ubv((GLubyte *) & CTX.color.mesh.tetrahedron); + + if(CTX.mesh.hidden) { + + if(CTX.mesh.shade) { + x1x0 = X[2] - X[0]; + y1y0 = Y[2] - Y[0]; + z1z0 = Z[2] - Z[0]; + x2x0 = X[1] - X[0]; + y2y0 = Y[1] - Y[0]; + z2z0 = Z[1] - Z[0]; + n[0] = y1y0 * z2z0 - z1z0 * y2y0; + n[1] = z1z0 * x2x0 - x1x0 * z2z0; + n[2] = x1x0 * y2y0 - y1y0 * x2x0; glNormal3dv(n); } @@ -423,13 +463,16 @@ void Draw_Simplex_Volume (void *a, void *b){ glVertex3d(X[1], Y[1], Z[1]); glEnd(); - if(CTX.mesh.shade){ - x1x0 = X[1]-X[0]; y1y0 = Y[1]-Y[0]; - z1z0 = Z[1]-Z[0]; x2x0 = X[3]-X[0]; - y2y0 = Y[3]-Y[0]; z2z0 = Z[3]-Z[0]; - n[0] = y1y0 * z2z0 - z1z0 * y2y0 ; - n[1] = z1z0 * x2x0 - x1x0 * z2z0 ; - n[2] = x1x0 * y2y0 - y1y0 * x2x0; + if(CTX.mesh.shade) { + x1x0 = X[1] - X[0]; + y1y0 = Y[1] - Y[0]; + z1z0 = Z[1] - Z[0]; + x2x0 = X[3] - X[0]; + y2y0 = Y[3] - Y[0]; + z2z0 = Z[3] - Z[0]; + n[0] = y1y0 * z2z0 - z1z0 * y2y0; + n[1] = z1z0 * x2x0 - x1x0 * z2z0; + n[2] = x1x0 * y2y0 - y1y0 * x2x0; glNormal3dv(n); } @@ -439,13 +482,16 @@ void Draw_Simplex_Volume (void *a, void *b){ glVertex3d(X[3], Y[3], Z[3]); glEnd(); - if(CTX.mesh.shade){ - x1x0 = X[3]-X[0]; y1y0 = Y[3]-Y[0]; - z1z0 = Z[3]-Z[0]; x2x0 = X[2]-X[0]; - y2y0 = Y[2]-Y[0]; z2z0 = Z[2]-Z[0]; - n[0] = y1y0 * z2z0 - z1z0 * y2y0 ; - n[1] = z1z0 * x2x0 - x1x0 * z2z0 ; - n[2] = x1x0 * y2y0 - y1y0 * x2x0; + if(CTX.mesh.shade) { + x1x0 = X[3] - X[0]; + y1y0 = Y[3] - Y[0]; + z1z0 = Z[3] - Z[0]; + x2x0 = X[2] - X[0]; + y2y0 = Y[2] - Y[0]; + z2z0 = Z[2] - Z[0]; + n[0] = y1y0 * z2z0 - z1z0 * y2y0; + n[1] = z1z0 * x2x0 - x1x0 * z2z0; + n[2] = x1x0 * y2y0 - y1y0 * x2x0; glNormal3dv(n); } @@ -455,13 +501,16 @@ void Draw_Simplex_Volume (void *a, void *b){ glVertex3d(X[2], Y[2], Z[2]); glEnd(); - if(CTX.mesh.shade){ - x1x0 = X[3]-X[1]; y1y0 = Y[3]-Y[1]; - z1z0 = Z[3]-Z[1]; x2x0 = X[2]-X[1]; - y2y0 = Y[2]-Y[1]; z2z0 = Z[2]-Z[1]; - n[0] = y1y0 * z2z0 - z1z0 * y2y0 ; - n[1] = z1z0 * x2x0 - x1x0 * z2z0 ; - n[2] = x1x0 * y2y0 - y1y0 * x2x0; + if(CTX.mesh.shade) { + x1x0 = X[3] - X[1]; + y1y0 = Y[3] - Y[1]; + z1z0 = Z[3] - Z[1]; + x2x0 = X[2] - X[1]; + y2y0 = Y[2] - Y[1]; + z2z0 = Z[2] - Z[1]; + n[0] = y1y0 * z2z0 - z1z0 * y2y0; + n[1] = z1z0 * x2x0 - x1x0 * z2z0; + n[2] = x1x0 * y2y0 - y1y0 * x2x0; glNormal3dv(n); } @@ -475,130 +524,136 @@ void Draw_Simplex_Volume (void *a, void *b){ } -void Draw_Simplex_Surface_Common(Simplex *s, double *pX, double *pY, double *pZ, double n[3]){ +void Draw_Simplex_Surface_Common(Simplex * s, double *pX, double *pY, + double *pZ, double n[3]) +{ double x1x0, y1y0, z1z0, x2x0, y2y0, z2z0; int i, K, L; L = (s->VSUP) ? 1 : 0; K = (s->V[3]) ? 4 : 3; - if(CTX.mesh.normals || CTX.mesh.shade){ - x1x0 = s->V[1]->Pos.X - s->V[0]->Pos.X; + if(CTX.mesh.normals || CTX.mesh.shade) { + x1x0 = s->V[1]->Pos.X - s->V[0]->Pos.X; y1y0 = s->V[1]->Pos.Y - s->V[0]->Pos.Y; - z1z0 = s->V[1]->Pos.Z - s->V[0]->Pos.Z; + z1z0 = s->V[1]->Pos.Z - s->V[0]->Pos.Z; x2x0 = s->V[2]->Pos.X - s->V[0]->Pos.X; - y2y0 = s->V[2]->Pos.Y - s->V[0]->Pos.Y; + y2y0 = s->V[2]->Pos.Y - s->V[0]->Pos.Y; z2z0 = s->V[2]->Pos.Z - s->V[0]->Pos.Z; - n[0] = y1y0 * z2z0 - z1z0 * y2y0 ; - n[1] = z1z0 * x2x0 - x1x0 * z2z0 ; + n[0] = y1y0 * z2z0 - z1z0 * y2y0; + n[1] = z1z0 * x2x0 - x1x0 * z2z0; n[2] = x1x0 * y2y0 - y1y0 * x2x0; } - if(CTX.mesh.hidden && CTX.mesh.shade) glNormal3dv(n); - - if(CTX.mesh.surfaces && CTX.mesh.lines){ + if(CTX.mesh.hidden && CTX.mesh.shade) + glNormal3dv(n); - if(CTX.mesh.color_carousel && ! (CTX.mesh.hidden || CTX.mesh.shade)){ + if(CTX.mesh.surfaces && CTX.mesh.lines) { + + if(CTX.mesh.color_carousel && !(CTX.mesh.hidden || CTX.mesh.shade)) { if(theColor.type) - glColor4ubv((GLubyte*)&theColor.mesh); + glColor4ubv((GLubyte *) & theColor.mesh); else - ColorSwitch(iColor); + ColorSwitch(iColor); } - else{ - glColor4ubv((GLubyte*)&CTX.color.mesh.line); + else { + glColor4ubv((GLubyte *) & CTX.color.mesh.line); } - if(CTX.mesh.shade) glDisable(GL_LIGHTING); + if(CTX.mesh.shade) + glDisable(GL_LIGHTING); - if(pX && pY && pZ){ // using precomputed vertices + if(pX && pY && pZ) { // using precomputed vertices glBegin(GL_LINE_LOOP); - for(i=0 ; i<K*(1+L) ; i++){ - glVertex3d(pX[i],pY[i],pZ[i]); + for(i = 0; i < K * (1 + L); i++) { + glVertex3d(pX[i], pY[i], pZ[i]); } - glEnd(); + glEnd(); } - else{ // using the element's unmodified coordinates - if(!L){ - glBegin(GL_LINE_LOOP); - for(i=0 ; i<K ; i++){ - glVertex3d(s->V[i]->Pos.X,s->V[i]->Pos.Y,s->V[i]->Pos.Z); - } - glEnd(); + else { // using the element's unmodified coordinates + if(!L) { + glBegin(GL_LINE_LOOP); + for(i = 0; i < K; i++) { + glVertex3d(s->V[i]->Pos.X, s->V[i]->Pos.Y, s->V[i]->Pos.Z); + } + glEnd(); } - else{ - glBegin(GL_LINE_LOOP); - for(i=0 ; i<K ; i++){ - glVertex3d(s->V[i]->Pos.X,s->V[i]->Pos.Y,s->V[i]->Pos.Z); - glVertex3d(s->VSUP[i]->Pos.X,s->VSUP[i]->Pos.Y,s->VSUP[i]->Pos.Z); - } - glEnd(); + else { + glBegin(GL_LINE_LOOP); + for(i = 0; i < K; i++) { + glVertex3d(s->V[i]->Pos.X, s->V[i]->Pos.Y, s->V[i]->Pos.Z); + glVertex3d(s->VSUP[i]->Pos.X, s->VSUP[i]->Pos.Y, s->VSUP[i]->Pos.Z); + } + glEnd(); } } - if(CTX.mesh.shade) glEnable(GL_LIGHTING); + if(CTX.mesh.shade) + glEnable(GL_LIGHTING); } - if(CTX.mesh.color_carousel){ + if(CTX.mesh.color_carousel) { if(theColor.type) - glColor4ubv((GLubyte*)&theColor.mesh); + glColor4ubv((GLubyte *) & theColor.mesh); else ColorSwitch(iColor); } - else{ - if(K==3) - glColor4ubv((GLubyte*)&CTX.color.mesh.triangle); + else { + if(K == 3) + glColor4ubv((GLubyte *) & CTX.color.mesh.triangle); else - glColor4ubv((GLubyte*)&CTX.color.mesh.quadrangle); + glColor4ubv((GLubyte *) & CTX.color.mesh.quadrangle); } - if(CTX.mesh.surfaces && CTX.mesh.hidden){ + if(CTX.mesh.surfaces && CTX.mesh.hidden) { - if(pX && pY && pZ){ // using precomputed vertices - if(L){ - glBegin(GL_POLYGON); - for(i=0 ; i<K*(1+L) ; i++) glVertex3d(pX[i], pY[i], pZ[i]); - glEnd(); + if(pX && pY && pZ) { // using precomputed vertices + if(L) { + glBegin(GL_POLYGON); + for(i = 0; i < K * (1 + L); i++) + glVertex3d(pX[i], pY[i], pZ[i]); + glEnd(); } - else if(K==4){ - glBegin(GL_QUADS); - glVertex3d(pX[0], pY[0], pZ[0]); - glVertex3d(pX[1], pY[1], pZ[1]); - glVertex3d(pX[2], pY[2], pZ[2]); - glVertex3d(pX[3], pY[3], pZ[3]); - glEnd(); + else if(K == 4) { + glBegin(GL_QUADS); + glVertex3d(pX[0], pY[0], pZ[0]); + glVertex3d(pX[1], pY[1], pZ[1]); + glVertex3d(pX[2], pY[2], pZ[2]); + glVertex3d(pX[3], pY[3], pZ[3]); + glEnd(); } - else{ - glBegin(GL_TRIANGLES); - glVertex3d(pX[0], pY[0], pZ[0]); - glVertex3d(pX[1], pY[1], pZ[1]); - glVertex3d(pX[2], pY[2], pZ[2]); - glEnd(); + else { + glBegin(GL_TRIANGLES); + glVertex3d(pX[0], pY[0], pZ[0]); + glVertex3d(pX[1], pY[1], pZ[1]); + glVertex3d(pX[2], pY[2], pZ[2]); + glEnd(); } } - else{ // using the element's unmodified coordinates - if(L){ - glBegin(GL_POLYGON); - for(i=0 ; i<K ; i++){ - glVertex3d(s->V[i]->Pos.X,s->V[i]->Pos.Y,s->V[i]->Pos.Z); - glVertex3d(s->VSUP[i]->Pos.X,s->VSUP[i]->Pos.Y,s->VSUP[i]->Pos.Z); - } - glEnd(); + else { // using the element's unmodified coordinates + if(L) { + glBegin(GL_POLYGON); + for(i = 0; i < K; i++) { + glVertex3d(s->V[i]->Pos.X, s->V[i]->Pos.Y, s->V[i]->Pos.Z); + glVertex3d(s->VSUP[i]->Pos.X, s->VSUP[i]->Pos.Y, s->VSUP[i]->Pos.Z); + } + glEnd(); } - else if(K==4){ - glBegin(GL_QUADS); - glVertex3d(s->V[0]->Pos.X,s->V[0]->Pos.Y,s->V[0]->Pos.Z); - glVertex3d(s->V[1]->Pos.X,s->V[1]->Pos.Y,s->V[1]->Pos.Z); - glVertex3d(s->V[2]->Pos.X,s->V[2]->Pos.Y,s->V[2]->Pos.Z); - glVertex3d(s->V[3]->Pos.X,s->V[3]->Pos.Y,s->V[3]->Pos.Z); - glEnd(); + else if(K == 4) { + glBegin(GL_QUADS); + glVertex3d(s->V[0]->Pos.X, s->V[0]->Pos.Y, s->V[0]->Pos.Z); + glVertex3d(s->V[1]->Pos.X, s->V[1]->Pos.Y, s->V[1]->Pos.Z); + glVertex3d(s->V[2]->Pos.X, s->V[2]->Pos.Y, s->V[2]->Pos.Z); + glVertex3d(s->V[3]->Pos.X, s->V[3]->Pos.Y, s->V[3]->Pos.Z); + glEnd(); } - else{ - glBegin(GL_TRIANGLES); - glVertex3d(s->V[0]->Pos.X,s->V[0]->Pos.Y,s->V[0]->Pos.Z); - glVertex3d(s->V[1]->Pos.X,s->V[1]->Pos.Y,s->V[1]->Pos.Z); - glVertex3d(s->V[2]->Pos.X,s->V[2]->Pos.Y,s->V[2]->Pos.Z); - glEnd(); + else { + glBegin(GL_TRIANGLES); + glVertex3d(s->V[0]->Pos.X, s->V[0]->Pos.Y, s->V[0]->Pos.Z); + glVertex3d(s->V[1]->Pos.X, s->V[1]->Pos.Y, s->V[1]->Pos.Z); + glVertex3d(s->V[2]->Pos.X, s->V[2]->Pos.Y, s->V[2]->Pos.Z); + glEnd(); } } @@ -606,77 +661,83 @@ void Draw_Simplex_Surface_Common(Simplex *s, double *pX, double *pY, double *pZ, } -void Draw_Simplex_Surface_Simple (void *a, void *b){ +void Draw_Simplex_Surface_Simple(void *a, void *b) +{ Simplex *s; double n[3]; - s = *(Simplex**)a; + s = *(Simplex **) a; - if(!s->V[2] || !(s->Visible & VIS_MESH)) return ; + if(!s->V[2] || !(s->Visible & VIS_MESH)) + return; Draw_Simplex_Surface_Common(s, NULL, NULL, NULL, n); } -void Draw_Simplex_Surface (void *a, void *b){ +void Draw_Simplex_Surface(void *a, void *b) +{ Simplex *s; - double Xc,Yc,Zc,pX[8],pY[8],pZ[8]; + double Xc, Yc, Zc, pX[8], pY[8], pZ[8]; double n[3], nn; - int i,j,K,L,k; + int i, j, K, L, k; char Num[256]; - - s = *(Simplex**)a; - if(!s->V[2] || !(s->Visible & VIS_MESH)) return ; + s = *(Simplex **) a; + + if(!s->V[2] || !(s->Visible & VIS_MESH)) + return; L = (s->VSUP) ? 1 : 0; K = (s->V[3]) ? 4 : 3; - + if(K == 4) { - Xc = .25 * (s->V[0]->Pos.X + s->V[1]->Pos.X + + Xc = .25 * (s->V[0]->Pos.X + s->V[1]->Pos.X + s->V[2]->Pos.X + s->V[3]->Pos.X); - Yc = .25 * (s->V[0]->Pos.Y + s->V[1]->Pos.Y + + Yc = .25 * (s->V[0]->Pos.Y + s->V[1]->Pos.Y + s->V[2]->Pos.Y + s->V[3]->Pos.Y); - Zc = .25 * (s->V[0]->Pos.Z + s->V[1]->Pos.Z + + Zc = .25 * (s->V[0]->Pos.Z + s->V[1]->Pos.Z + s->V[2]->Pos.Z + s->V[3]->Pos.Z); } else { - Xc = (s->V[0]->Pos.X + s->V[1]->Pos.X + s->V[2]->Pos.X) / 3. ; - Yc = (s->V[0]->Pos.Y + s->V[1]->Pos.Y + s->V[2]->Pos.Y) / 3. ; - Zc = (s->V[0]->Pos.Z + s->V[1]->Pos.Z + s->V[2]->Pos.Z) / 3. ; + Xc = (s->V[0]->Pos.X + s->V[1]->Pos.X + s->V[2]->Pos.X) / 3.; + Yc = (s->V[0]->Pos.Y + s->V[1]->Pos.Y + s->V[2]->Pos.Y) / 3.; + Zc = (s->V[0]->Pos.Z + s->V[1]->Pos.Z + s->V[2]->Pos.Z) / 3.; } - if(CTX.mesh.use_cut_plane){ - if(CTX.mesh.evalCutPlane(Xc,Yc,Zc) < 0) return; + if(CTX.mesh.use_cut_plane) { + if(CTX.mesh.evalCutPlane(Xc, Yc, Zc) < 0) + return; } - k=0; - for (i=0 ; i<K ; i++) { + k = 0; + for(i = 0; i < K; i++) { pX[k] = Xc + CTX.mesh.explode * (s->V[i]->Pos.X - Xc); pY[k] = Yc + CTX.mesh.explode * (s->V[i]->Pos.Y - Yc); pZ[k] = Zc + CTX.mesh.explode * (s->V[i]->Pos.Z - Zc); - k+=(L+1); + k += (L + 1); } - - if(L){ - k=1; - for (i=0 ; i<K ; i++) { + + if(L) { + k = 1; + for(i = 0; i < K; i++) { pX[k] = Xc + CTX.mesh.explode * (s->VSUP[i]->Pos.X - Xc); pY[k] = Yc + CTX.mesh.explode * (s->VSUP[i]->Pos.Y - Yc); - pZ[k] = Zc + CTX.mesh.explode * (s->VSUP[i]->Pos.Z - Zc); - k+=(L+1); + pZ[k] = Zc + CTX.mesh.explode * (s->VSUP[i]->Pos.Z - Zc); + k += (L + 1); } } - if(CTX.mesh.dual){ - glColor4ubv((GLubyte*)&CTX.color.fg); + if(CTX.mesh.dual) { + glColor4ubv((GLubyte *) & CTX.color.fg); glEnable(GL_LINE_STIPPLE); - glLineStipple(1,0x0F0F); + glLineStipple(1, 0x0F0F); gl2psEnable(GL2PS_LINE_STIPPLE); glBegin(GL_LINES); - for (i=0 ; i<K ; i++) { - (!i) ? j = K-1 : j = i-1 ; - glVertex3d(Xc, Yc, Zc); - glVertex3d((pX[i]+pX[j])/2., (pY[i]+pY[j])/2., (pZ[i]+pZ[j])/2.); + for(i = 0; i < K; i++) { + (!i) ? j = K - 1 : j = i - 1; + glVertex3d(Xc, Yc, Zc); + glVertex3d((pX[i] + pX[j]) / 2., (pY[i] + pY[j]) / 2., + (pZ[i] + pZ[j]) / 2.); } glEnd(); glDisable(GL_LINE_STIPPLE); @@ -685,157 +746,167 @@ void Draw_Simplex_Surface (void *a, void *b){ Draw_Simplex_Surface_Common(s, pX, pY, pZ, n); - if(CTX.mesh.surfaces_num){ - sprintf(Num,"%d",s->Num); - glRasterPos3d(Xc,Yc,Zc); + if(CTX.mesh.surfaces_num) { + sprintf(Num, "%d", s->Num); + glRasterPos3d(Xc, Yc, Zc); Draw_String(Num); } - + if(CTX.mesh.normals) { norme(n); - glColor4ubv((GLubyte*)&CTX.color.mesh.normals); - n[0] *= CTX.mesh.normals * CTX.pixel_equiv_x/CTX.s[0] ; - n[1] *= CTX.mesh.normals * CTX.pixel_equiv_x/CTX.s[1] ; - n[2] *= CTX.mesh.normals * CTX.pixel_equiv_x/CTX.s[2] ; - nn = sqrt(n[0]*n[0]+n[1]*n[1]+n[2]*n[2]); - Draw_Vector(DRAW_POST_ARROW, 0, Xc,Yc,Zc, nn, n[0],n[1],n[2],NULL); + glColor4ubv((GLubyte *) & CTX.color.mesh.normals); + n[0] *= CTX.mesh.normals * CTX.pixel_equiv_x / CTX.s[0]; + n[1] *= CTX.mesh.normals * CTX.pixel_equiv_x / CTX.s[1]; + n[2] *= CTX.mesh.normals * CTX.pixel_equiv_x / CTX.s[2]; + nn = sqrt(n[0] * n[0] + n[1] * n[1] + n[2] * n[2]); + Draw_Vector(DRAW_POST_ARROW, 0, Xc, Yc, Zc, nn, n[0], n[1], n[2], NULL); } - + } -void Draw_Simplex_Curves(void *a,void *b){ +void Draw_Simplex_Curves(void *a, void *b) +{ Simplex *s; - double Xc = 0.0 , Yc = 0.0, Zc = 0.0, m[3], mm ; + double Xc = 0.0, Yc = 0.0, Zc = 0.0, m[3], mm; char Num[100]; - s = *(Simplex**)a; + s = *(Simplex **) a; - if(!(s->Visible & VIS_MESH)) return ; + if(!(s->Visible & VIS_MESH)) + return; Xc = 0.5 * (s->V[0]->Pos.X + s->V[1]->Pos.X); Yc = 0.5 * (s->V[0]->Pos.Y + s->V[1]->Pos.Y); Zc = 0.5 * (s->V[0]->Pos.Z + s->V[1]->Pos.Z); - double X[2],Y[2],Z[2]; - for (int i=0 ; i<2 ; i++) { + double X[2], Y[2], Z[2]; + for(int i = 0; i < 2; i++) { X[i] = Xc + CTX.mesh.explode * (s->V[i]->Pos.X - Xc); Y[i] = Yc + CTX.mesh.explode * (s->V[i]->Pos.Y - Yc); Z[i] = Zc + CTX.mesh.explode * (s->V[i]->Pos.Z - Zc); } /* - if(CTX.mesh.points){ - glColor4ubv((GLubyte*)&CTX.color.mesh.vertex); - glBegin(GL_POINTS); - glVertex3d(s->V[1]->Pos.X, s->V[1]->Pos.Y, s->V[1]->Pos.Z); - glEnd(); - - if(s->VSUP){ - glColor4ubv((GLubyte*)&CTX.color.mesh.vertex_supp); - glBegin(GL_POINTS); - glVertex3d(s->VSUP[0]->Pos.X, s->VSUP[0]->Pos.Y, s->VSUP[0]->Pos.Z); - glEnd(); - } - } - */ - - if(CTX.mesh.color_carousel){ + if(CTX.mesh.points){ + glColor4ubv((GLubyte*)&CTX.color.mesh.vertex); + glBegin(GL_POINTS); + glVertex3d(s->V[1]->Pos.X, s->V[1]->Pos.Y, s->V[1]->Pos.Z); + glEnd(); + + if(s->VSUP){ + glColor4ubv((GLubyte*)&CTX.color.mesh.vertex_supp); + glBegin(GL_POINTS); + glVertex3d(s->VSUP[0]->Pos.X, s->VSUP[0]->Pos.Y, s->VSUP[0]->Pos.Z); + glEnd(); + } + } + */ + + if(CTX.mesh.color_carousel) { if(theColor.type) - glColor4ubv((GLubyte*)&theColor.mesh); - else + glColor4ubv((GLubyte *) & theColor.mesh); + else ColorSwitch(iColor); } else - glColor4ubv((GLubyte*)&CTX.color.mesh.line); + glColor4ubv((GLubyte *) & CTX.color.mesh.line); - if(CTX.mesh.shade) glDisable(GL_LIGHTING); + if(CTX.mesh.shade) + glDisable(GL_LIGHTING); - if(CTX.mesh.lines){ + if(CTX.mesh.lines) { glBegin(GL_LINES); glVertex3d(X[0], Y[0], Z[0]); glVertex3d(X[1], Y[1], Z[1]); - glEnd(); + glEnd(); } - if(CTX.mesh.lines_num){ - sprintf(Num,"%d",s->Num); - glRasterPos3d(Xc + 3*CTX.pixel_equiv_x/CTX.s[0], - Yc + 3*CTX.pixel_equiv_x/CTX.s[1], - Zc + 3*CTX.pixel_equiv_x/CTX.s[2]); + if(CTX.mesh.lines_num) { + sprintf(Num, "%d", s->Num); + glRasterPos3d(Xc + 3 * CTX.pixel_equiv_x / CTX.s[0], + Yc + 3 * CTX.pixel_equiv_x / CTX.s[1], + Zc + 3 * CTX.pixel_equiv_x / CTX.s[2]); Draw_String(Num); } if(CTX.mesh.tangents) { - glColor4ubv((GLubyte*)&CTX.color.mesh.tangents); - m[0] = X[1]-X[0]; - m[1] = Y[1]-Y[0]; - m[2] = Z[1]-Z[0]; + glColor4ubv((GLubyte *) & CTX.color.mesh.tangents); + m[0] = X[1] - X[0]; + m[1] = Y[1] - Y[0]; + m[2] = Z[1] - Z[0]; norme(m); - m[0] *= CTX.mesh.tangents * CTX.pixel_equiv_x/CTX.s[0]; - m[1] *= CTX.mesh.tangents * CTX.pixel_equiv_x/CTX.s[1]; - m[2] *= CTX.mesh.tangents * CTX.pixel_equiv_x/CTX.s[2]; - mm = sqrt(m[0]*m[0]+m[1]*m[1]+m[2]*m[2]); - Draw_Vector(DRAW_POST_ARROW, 0, Xc,Yc,Zc,mm,m[0],m[1],m[2],NULL); + m[0] *= CTX.mesh.tangents * CTX.pixel_equiv_x / CTX.s[0]; + m[1] *= CTX.mesh.tangents * CTX.pixel_equiv_x / CTX.s[1]; + m[2] *= CTX.mesh.tangents * CTX.pixel_equiv_x / CTX.s[2]; + mm = sqrt(m[0] * m[0] + m[1] * m[1] + m[2] * m[2]); + Draw_Vector(DRAW_POST_ARROW, 0, Xc, Yc, Zc, mm, m[0], m[1], m[2], NULL); } - - if(CTX.mesh.shade) glEnable(GL_LIGHTING); + + if(CTX.mesh.shade) + glEnable(GL_LIGHTING); } -void Draw_Hexahedron_Volume (void *a, void *b){ +void Draw_Hexahedron_Volume(void *a, void *b) +{ Hexahedron *h; - int i ; - double Xc = 0.0 , Yc = 0.0, Zc = 0.0 , X[8],Y[8],Z[8]; + int i; + double Xc = 0.0, Yc = 0.0, Zc = 0.0, X[8], Y[8], Z[8]; char Num[100]; - h = *(Hexahedron**)a; + h = *(Hexahedron **) a; - if(!(h->Visible & VIS_MESH)) return ; + if(!(h->Visible & VIS_MESH)) + return; // FIXME: remove as soon as a coherent structure exists for volumes - Volume *V; if((V = FindVolume(h->iEnt,THEM)) && !(V->Visible & VIS_MESH)) return; + Volume *V; + if((V = FindVolume(h->iEnt, THEM)) && !(V->Visible & VIS_MESH)) + return; - for(i=0 ; i<8 ; i++){ + for(i = 0; i < 8; i++) { Xc += h->V[i]->Pos.X; Yc += h->V[i]->Pos.Y; Zc += h->V[i]->Pos.Z; } - Xc *= .125 ; - Zc *= .125 ; - Yc *= .125 ; + Xc *= .125; + Zc *= .125; + Yc *= .125; - if(CTX.mesh.use_cut_plane){ - if(CTX.mesh.evalCutPlane(Xc,Yc,Zc) < 0)return; + if(CTX.mesh.use_cut_plane) { + if(CTX.mesh.evalCutPlane(Xc, Yc, Zc) < 0) + return; } if(CTX.mesh.color_carousel) - ColorSwitch(h->iEnt); + ColorSwitch(h->iEnt); else - glColor4ubv((GLubyte*)&CTX.color.mesh.hexahedron); + glColor4ubv((GLubyte *) & CTX.color.mesh.hexahedron); - for (i=0 ; i<8 ; i++) { + for(i = 0; i < 8; i++) { X[i] = Xc + CTX.mesh.explode * (h->V[i]->Pos.X - Xc); Y[i] = Yc + CTX.mesh.explode * (h->V[i]->Pos.Y - Yc); Z[i] = Zc + CTX.mesh.explode * (h->V[i]->Pos.Z - Zc); } - if(CTX.mesh.shade) glDisable(GL_LIGHTING); + if(CTX.mesh.shade) + glDisable(GL_LIGHTING); glBegin(GL_LINE_LOOP); glVertex3d(X[0], Y[0], Z[0]); glVertex3d(X[1], Y[1], Z[1]); glVertex3d(X[2], Y[2], Z[2]); glVertex3d(X[3], Y[3], Z[3]); - glEnd(); + glEnd(); glBegin(GL_LINE_LOOP); glVertex3d(X[4], Y[4], Z[4]); glVertex3d(X[5], Y[5], Z[5]); glVertex3d(X[6], Y[6], Z[6]); glVertex3d(X[7], Y[7], Z[7]); - glEnd(); + glEnd(); glBegin(GL_LINES); glVertex3d(X[0], Y[0], Z[0]); @@ -846,110 +917,135 @@ void Draw_Hexahedron_Volume (void *a, void *b){ glVertex3d(X[6], Y[6], Z[6]); glVertex3d(X[3], Y[3], Z[3]); glVertex3d(X[7], Y[7], Z[7]); - glEnd(); + glEnd(); - if(CTX.mesh.volumes_num){ - sprintf(Num,"%d",h->Num); - glRasterPos3d(Xc,Yc,Zc); + if(CTX.mesh.volumes_num) { + sprintf(Num, "%d", h->Num); + glRasterPos3d(Xc, Yc, Zc); Draw_String(Num); } - if(CTX.mesh.dual){ + if(CTX.mesh.dual) { - glColor4ubv((GLubyte*)&CTX.color.fg); + glColor4ubv((GLubyte *) & CTX.color.fg); glEnable(GL_LINE_STIPPLE); - glLineStipple(1,0x0F0F); + glLineStipple(1, 0x0F0F); gl2psEnable(GL2PS_LINE_STIPPLE); glBegin(GL_LINES); - glVertex3d(Xc, Yc, Zc); + glVertex3d(Xc, Yc, Zc); glVertex3d - ( (h->V[0]->Pos.X+h->V[1]->Pos.X+h->V[5]->Pos.X+h->V[4]->Pos.X)/4., - (h->V[0]->Pos.Y+h->V[1]->Pos.Y+h->V[5]->Pos.Y+h->V[4]->Pos.Y)/4., - (h->V[0]->Pos.Z+h->V[1]->Pos.Z+h->V[5]->Pos.Z+h->V[4]->Pos.Z)/4. ); - glVertex3d(Xc, Yc, Zc); + ((h->V[0]->Pos.X + h->V[1]->Pos.X + h->V[5]->Pos.X + + h->V[4]->Pos.X) / 4., + (h->V[0]->Pos.Y + h->V[1]->Pos.Y + h->V[5]->Pos.Y + + h->V[4]->Pos.Y) / 4., + (h->V[0]->Pos.Z + h->V[1]->Pos.Z + h->V[5]->Pos.Z + + h->V[4]->Pos.Z) / 4.); + glVertex3d(Xc, Yc, Zc); glVertex3d - ( (h->V[0]->Pos.X+h->V[3]->Pos.X+h->V[2]->Pos.X+h->V[1]->Pos.X)/4., - (h->V[0]->Pos.Y+h->V[3]->Pos.Y+h->V[2]->Pos.Y+h->V[1]->Pos.Y)/4., - (h->V[0]->Pos.Z+h->V[3]->Pos.Z+h->V[2]->Pos.Z+h->V[1]->Pos.Z)/4. ); - glVertex3d(Xc, Yc, Zc); + ((h->V[0]->Pos.X + h->V[3]->Pos.X + h->V[2]->Pos.X + + h->V[1]->Pos.X) / 4., + (h->V[0]->Pos.Y + h->V[3]->Pos.Y + h->V[2]->Pos.Y + + h->V[1]->Pos.Y) / 4., + (h->V[0]->Pos.Z + h->V[3]->Pos.Z + h->V[2]->Pos.Z + + h->V[1]->Pos.Z) / 4.); + glVertex3d(Xc, Yc, Zc); glVertex3d - ( (h->V[0]->Pos.X+h->V[4]->Pos.X+h->V[7]->Pos.X+h->V[3]->Pos.X)/4., - (h->V[0]->Pos.Y+h->V[4]->Pos.Y+h->V[7]->Pos.Y+h->V[3]->Pos.Y)/4., - (h->V[0]->Pos.Z+h->V[4]->Pos.Z+h->V[7]->Pos.Z+h->V[3]->Pos.Z)/4. ); - glVertex3d(Xc, Yc, Zc); + ((h->V[0]->Pos.X + h->V[4]->Pos.X + h->V[7]->Pos.X + + h->V[3]->Pos.X) / 4., + (h->V[0]->Pos.Y + h->V[4]->Pos.Y + h->V[7]->Pos.Y + + h->V[3]->Pos.Y) / 4., + (h->V[0]->Pos.Z + h->V[4]->Pos.Z + h->V[7]->Pos.Z + + h->V[3]->Pos.Z) / 4.); + glVertex3d(Xc, Yc, Zc); glVertex3d - ( (h->V[1]->Pos.X+h->V[2]->Pos.X+h->V[6]->Pos.X+h->V[5]->Pos.X)/4., - (h->V[1]->Pos.Y+h->V[2]->Pos.Y+h->V[6]->Pos.Y+h->V[5]->Pos.Y)/4., - (h->V[1]->Pos.Z+h->V[2]->Pos.Z+h->V[6]->Pos.Z+h->V[5]->Pos.Z)/4. ); - glVertex3d(Xc, Yc, Zc); + ((h->V[1]->Pos.X + h->V[2]->Pos.X + h->V[6]->Pos.X + + h->V[5]->Pos.X) / 4., + (h->V[1]->Pos.Y + h->V[2]->Pos.Y + h->V[6]->Pos.Y + + h->V[5]->Pos.Y) / 4., + (h->V[1]->Pos.Z + h->V[2]->Pos.Z + h->V[6]->Pos.Z + + h->V[5]->Pos.Z) / 4.); + glVertex3d(Xc, Yc, Zc); glVertex3d - ( (h->V[2]->Pos.X+h->V[3]->Pos.X+h->V[7]->Pos.X+h->V[6]->Pos.X)/4., - (h->V[2]->Pos.Y+h->V[3]->Pos.Y+h->V[7]->Pos.Y+h->V[6]->Pos.Y)/4., - (h->V[2]->Pos.Z+h->V[3]->Pos.Z+h->V[7]->Pos.Z+h->V[6]->Pos.Z)/4. ); - glVertex3d(Xc, Yc, Zc); + ((h->V[2]->Pos.X + h->V[3]->Pos.X + h->V[7]->Pos.X + + h->V[6]->Pos.X) / 4., + (h->V[2]->Pos.Y + h->V[3]->Pos.Y + h->V[7]->Pos.Y + + h->V[6]->Pos.Y) / 4., + (h->V[2]->Pos.Z + h->V[3]->Pos.Z + h->V[7]->Pos.Z + + h->V[6]->Pos.Z) / 4.); + glVertex3d(Xc, Yc, Zc); glVertex3d - ( (h->V[4]->Pos.X+h->V[5]->Pos.X+h->V[6]->Pos.X+h->V[7]->Pos.X)/4., - (h->V[4]->Pos.Y+h->V[5]->Pos.Y+h->V[6]->Pos.Y+h->V[7]->Pos.Y)/4., - (h->V[4]->Pos.Z+h->V[5]->Pos.Z+h->V[6]->Pos.Z+h->V[7]->Pos.Z)/4. ); + ((h->V[4]->Pos.X + h->V[5]->Pos.X + h->V[6]->Pos.X + + h->V[7]->Pos.X) / 4., + (h->V[4]->Pos.Y + h->V[5]->Pos.Y + h->V[6]->Pos.Y + + h->V[7]->Pos.Y) / 4., + (h->V[4]->Pos.Z + h->V[5]->Pos.Z + h->V[6]->Pos.Z + + h->V[7]->Pos.Z) / 4.); glEnd(); glDisable(GL_LINE_STIPPLE); gl2psDisable(GL2PS_LINE_STIPPLE); } - if(CTX.mesh.shade) glEnable(GL_LIGHTING); + if(CTX.mesh.shade) + glEnable(GL_LIGHTING); } -void Draw_Prism_Volume (void *a, void *b){ +void Draw_Prism_Volume(void *a, void *b) +{ Prism *p; - int i ; - double Xc = 0.0 , Yc = 0.0, Zc = 0.0, X[6],Y[6],Z[6] ; + int i; + double Xc = 0.0, Yc = 0.0, Zc = 0.0, X[6], Y[6], Z[6]; char Num[100]; - p = *(Prism**)a; + p = *(Prism **) a; - if(!(p->Visible & VIS_MESH)) return ; + if(!(p->Visible & VIS_MESH)) + return; // FIXME: remove as soon as a coherent structure exists for volumes - Volume *V; if((V = FindVolume(p->iEnt,THEM)) && !(V->Visible & VIS_MESH)) return; + Volume *V; + if((V = FindVolume(p->iEnt, THEM)) && !(V->Visible & VIS_MESH)) + return; - for(i=0 ; i<6 ; i++){ + for(i = 0; i < 6; i++) { Xc += p->V[i]->Pos.X; Yc += p->V[i]->Pos.Y; Zc += p->V[i]->Pos.Z; } - Xc /= 6. ; - Zc /= 6. ; - Yc /= 6. ; + Xc /= 6.; + Zc /= 6.; + Yc /= 6.; - if(CTX.mesh.use_cut_plane){ - if(CTX.mesh.evalCutPlane(Xc,Yc,Zc) < 0)return; + if(CTX.mesh.use_cut_plane) { + if(CTX.mesh.evalCutPlane(Xc, Yc, Zc) < 0) + return; } if(CTX.mesh.color_carousel) ColorSwitch(p->iEnt); else - glColor4ubv((GLubyte*)&CTX.color.mesh.prism); + glColor4ubv((GLubyte *) & CTX.color.mesh.prism); - for (i=0 ; i<6 ; i++) { + for(i = 0; i < 6; i++) { X[i] = Xc + CTX.mesh.explode * (p->V[i]->Pos.X - Xc); Y[i] = Yc + CTX.mesh.explode * (p->V[i]->Pos.Y - Yc); Z[i] = Zc + CTX.mesh.explode * (p->V[i]->Pos.Z - Zc); } - if(CTX.mesh.shade) glDisable(GL_LIGHTING); - + if(CTX.mesh.shade) + glDisable(GL_LIGHTING); + glBegin(GL_LINE_LOOP); glVertex3d(X[0], Y[0], Z[0]); glVertex3d(X[1], Y[1], Z[1]); glVertex3d(X[2], Y[2], Z[2]); - glEnd(); + glEnd(); glBegin(GL_LINE_LOOP); glVertex3d(X[3], Y[3], Z[3]); glVertex3d(X[4], Y[4], Z[4]); glVertex3d(X[5], Y[5], Z[5]); - glEnd(); + glEnd(); glBegin(GL_LINES); glVertex3d(X[0], Y[0], Z[0]); @@ -958,99 +1054,115 @@ void Draw_Prism_Volume (void *a, void *b){ glVertex3d(X[4], Y[4], Z[4]); glVertex3d(X[2], Y[2], Z[2]); glVertex3d(X[5], Y[5], Z[5]); - glEnd(); + glEnd(); - if(CTX.mesh.volumes_num){ - sprintf(Num,"%d",p->Num); - glRasterPos3d(Xc,Yc,Zc); + if(CTX.mesh.volumes_num) { + sprintf(Num, "%d", p->Num); + glRasterPos3d(Xc, Yc, Zc); Draw_String(Num); } - if(CTX.mesh.dual){ - glColor4ubv((GLubyte*)&CTX.color.fg); + if(CTX.mesh.dual) { + glColor4ubv((GLubyte *) & CTX.color.fg); glEnable(GL_LINE_STIPPLE); - glLineStipple(1,0x0F0F); + glLineStipple(1, 0x0F0F); gl2psEnable(GL2PS_LINE_STIPPLE); glBegin(GL_LINES); - glVertex3d(Xc, Yc, Zc); + glVertex3d(Xc, Yc, Zc); glVertex3d - ( (p->V[0]->Pos.X+p->V[2]->Pos.X+p->V[1]->Pos.X)/3., - (p->V[0]->Pos.Y+p->V[2]->Pos.Y+p->V[1]->Pos.Y)/3., - (p->V[0]->Pos.Z+p->V[2]->Pos.Z+p->V[1]->Pos.Z)/3. ); - glVertex3d(Xc, Yc, Zc); + ((p->V[0]->Pos.X + p->V[2]->Pos.X + p->V[1]->Pos.X) / 3., + (p->V[0]->Pos.Y + p->V[2]->Pos.Y + p->V[1]->Pos.Y) / 3., + (p->V[0]->Pos.Z + p->V[2]->Pos.Z + p->V[1]->Pos.Z) / 3.); + glVertex3d(Xc, Yc, Zc); glVertex3d - ( (p->V[3]->Pos.X+p->V[4]->Pos.X+p->V[5]->Pos.X)/3., - (p->V[3]->Pos.Y+p->V[4]->Pos.Y+p->V[5]->Pos.Y)/3., - (p->V[3]->Pos.Z+p->V[4]->Pos.Z+p->V[5]->Pos.Z)/3. ); - glVertex3d(Xc, Yc, Zc); + ((p->V[3]->Pos.X + p->V[4]->Pos.X + p->V[5]->Pos.X) / 3., + (p->V[3]->Pos.Y + p->V[4]->Pos.Y + p->V[5]->Pos.Y) / 3., + (p->V[3]->Pos.Z + p->V[4]->Pos.Z + p->V[5]->Pos.Z) / 3.); + glVertex3d(Xc, Yc, Zc); glVertex3d - ( (p->V[0]->Pos.X+p->V[1]->Pos.X+p->V[4]->Pos.X+p->V[3]->Pos.X)/4., - (p->V[0]->Pos.Y+p->V[1]->Pos.Y+p->V[4]->Pos.Y+p->V[3]->Pos.Y)/4., - (p->V[0]->Pos.Z+p->V[1]->Pos.Z+p->V[4]->Pos.Z+p->V[3]->Pos.Z)/4. ); - glVertex3d(Xc, Yc, Zc); + ((p->V[0]->Pos.X + p->V[1]->Pos.X + p->V[4]->Pos.X + + p->V[3]->Pos.X) / 4., + (p->V[0]->Pos.Y + p->V[1]->Pos.Y + p->V[4]->Pos.Y + + p->V[3]->Pos.Y) / 4., + (p->V[0]->Pos.Z + p->V[1]->Pos.Z + p->V[4]->Pos.Z + + p->V[3]->Pos.Z) / 4.); + glVertex3d(Xc, Yc, Zc); glVertex3d - ( (p->V[0]->Pos.X+p->V[3]->Pos.X+p->V[5]->Pos.X+p->V[2]->Pos.X)/4., - (p->V[0]->Pos.Y+p->V[3]->Pos.Y+p->V[5]->Pos.Y+p->V[2]->Pos.Y)/4., - (p->V[0]->Pos.Z+p->V[3]->Pos.Z+p->V[5]->Pos.Z+p->V[2]->Pos.Z)/4. ); - glVertex3d(Xc, Yc, Zc); + ((p->V[0]->Pos.X + p->V[3]->Pos.X + p->V[5]->Pos.X + + p->V[2]->Pos.X) / 4., + (p->V[0]->Pos.Y + p->V[3]->Pos.Y + p->V[5]->Pos.Y + + p->V[2]->Pos.Y) / 4., + (p->V[0]->Pos.Z + p->V[3]->Pos.Z + p->V[5]->Pos.Z + + p->V[2]->Pos.Z) / 4.); + glVertex3d(Xc, Yc, Zc); glVertex3d - ( (p->V[1]->Pos.X+p->V[2]->Pos.X+p->V[5]->Pos.X+p->V[4]->Pos.X)/4., - (p->V[1]->Pos.Y+p->V[2]->Pos.Y+p->V[5]->Pos.Y+p->V[4]->Pos.Y)/4., - (p->V[1]->Pos.Z+p->V[2]->Pos.Z+p->V[5]->Pos.Z+p->V[4]->Pos.Z)/4. ); + ((p->V[1]->Pos.X + p->V[2]->Pos.X + p->V[5]->Pos.X + + p->V[4]->Pos.X) / 4., + (p->V[1]->Pos.Y + p->V[2]->Pos.Y + p->V[5]->Pos.Y + + p->V[4]->Pos.Y) / 4., + (p->V[1]->Pos.Z + p->V[2]->Pos.Z + p->V[5]->Pos.Z + + p->V[4]->Pos.Z) / 4.); glEnd(); glDisable(GL_LINE_STIPPLE); gl2psDisable(GL2PS_LINE_STIPPLE); } - if(CTX.mesh.shade) glEnable(GL_LIGHTING); + if(CTX.mesh.shade) + glEnable(GL_LIGHTING); } -void Draw_Pyramid_Volume (void *a, void *b){ +void Draw_Pyramid_Volume(void *a, void *b) +{ Pyramid *p; - int i ; - double Xc = 0.0 , Yc = 0.0, Zc = 0.0, X[5],Y[5],Z[5] ; + int i; + double Xc = 0.0, Yc = 0.0, Zc = 0.0, X[5], Y[5], Z[5]; char Num[100]; - p = *(Pyramid**)a; + p = *(Pyramid **) a; - if(!(p->Visible & VIS_MESH)) return ; + if(!(p->Visible & VIS_MESH)) + return; // FIXME: remove as soon as a coherent structure exists for volumes - Volume *V; if((V = FindVolume(p->iEnt,THEM)) && !(V->Visible & VIS_MESH)) return; + Volume *V; + if((V = FindVolume(p->iEnt, THEM)) && !(V->Visible & VIS_MESH)) + return; - for(i=0 ; i<5 ; i++){ + for(i = 0; i < 5; i++) { Xc += p->V[i]->Pos.X; Yc += p->V[i]->Pos.Y; Zc += p->V[i]->Pos.Z; } - Xc /= 5. ; - Zc /= 5. ; - Yc /= 5. ; + Xc /= 5.; + Zc /= 5.; + Yc /= 5.; - if(CTX.mesh.use_cut_plane){ - if(CTX.mesh.evalCutPlane(Xc,Yc,Zc) < 0)return; + if(CTX.mesh.use_cut_plane) { + if(CTX.mesh.evalCutPlane(Xc, Yc, Zc) < 0) + return; } if(CTX.mesh.color_carousel) ColorSwitch(p->iEnt); else - glColor4ubv((GLubyte*)&CTX.color.mesh.pyramid); + glColor4ubv((GLubyte *) & CTX.color.mesh.pyramid); - for (i=0 ; i<5 ; i++) { + for(i = 0; i < 5; i++) { X[i] = Xc + CTX.mesh.explode * (p->V[i]->Pos.X - Xc); Y[i] = Yc + CTX.mesh.explode * (p->V[i]->Pos.Y - Yc); Z[i] = Zc + CTX.mesh.explode * (p->V[i]->Pos.Z - Zc); } - - if(CTX.mesh.shade) glDisable(GL_LIGHTING); + + if(CTX.mesh.shade) + glDisable(GL_LIGHTING); glBegin(GL_LINE_LOOP); glVertex3d(X[0], Y[0], Z[0]); glVertex3d(X[1], Y[1], Z[1]); glVertex3d(X[2], Y[2], Z[2]); glVertex3d(X[3], Y[3], Z[3]); - glEnd(); + glEnd(); glBegin(GL_LINES); glVertex3d(X[0], Y[0], Z[0]); @@ -1061,16 +1173,15 @@ void Draw_Pyramid_Volume (void *a, void *b){ glVertex3d(X[4], Y[4], Z[4]); glVertex3d(X[3], Y[3], Z[3]); glVertex3d(X[4], Y[4], Z[4]); - glEnd(); + glEnd(); - if(CTX.mesh.volumes_num){ - sprintf(Num,"%d",p->Num); - glRasterPos3d(Xc,Yc,Zc); + if(CTX.mesh.volumes_num) { + sprintf(Num, "%d", p->Num); + glRasterPos3d(Xc, Yc, Zc); Draw_String(Num); } - if(CTX.mesh.shade) glEnable(GL_LIGHTING); + if(CTX.mesh.shade) + glEnable(GL_LIGHTING); } - - diff --git a/Graphics/Post.cpp b/Graphics/Post.cpp index 447ee399798e7d73e946da728463f96cff1eaa38..37315f18bc5f3a89682f9b46c57578d00f12d5a0 100644 --- a/Graphics/Post.cpp +++ b/Graphics/Post.cpp @@ -1,4 +1,4 @@ -// $Id: Post.cpp,v 1.45 2003-02-25 04:02:50 geuzaine Exp $ +// $Id: Post.cpp,v 1.46 2003-03-01 22:36:40 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -29,100 +29,132 @@ #include "Context.h" #include "gl2ps.h" -extern Context_T CTX; +extern Context_T CTX; -static double Raise[3][8]; -static double RaiseFactor[3]; +static double Raise[3][8]; +static double RaiseFactor[3]; // Give Value from Index -double GiveValueFromIndex_Lin(double ValMin, double ValMax, int NbIso, int Iso){ - if(NbIso==1) return (ValMax+ValMin)/2.; - return ValMin + Iso*(ValMax-ValMin)/(NbIso-1.) ; +double GiveValueFromIndex_Lin(double ValMin, double ValMax, int NbIso, + int Iso) +{ + if(NbIso == 1) + return (ValMax + ValMin) / 2.; + return ValMin + Iso * (ValMax - ValMin) / (NbIso - 1.); } -double GiveValueFromIndex_Log(double ValMin, double ValMax, int NbIso, int Iso){ - if(NbIso==1) return (ValMax+ValMin)/2.; - if(ValMin <= 0.) return 0. ; - return pow(10.,log10(ValMin)+Iso*(log10(ValMax)-log10(ValMin))/(NbIso-1.)) ; +double GiveValueFromIndex_Log(double ValMin, double ValMax, int NbIso, + int Iso) +{ + if(NbIso == 1) + return (ValMax + ValMin) / 2.; + if(ValMin <= 0.) + return 0.; + return pow(10., + log10(ValMin) + Iso * (log10(ValMax) - log10(ValMin)) / (NbIso - + 1.)); } -double GiveValueFromIndex_DoubleLog(double ValMin, double ValMax, int NbIso, int Iso){ - if(NbIso==1) return (ValMax+ValMin)/2.; - if(ValMin <= 0.) return 0. ; +double GiveValueFromIndex_DoubleLog(double ValMin, double ValMax, int NbIso, + int Iso) +{ + if(NbIso == 1) + return (ValMax + ValMin) / 2.; + if(ValMin <= 0.) + return 0.; - double Iso2 = Iso/2.; - double NbIso2 = NbIso/2.; + double Iso2 = Iso / 2.; + double NbIso2 = NbIso / 2.; - return pow(10.,log10(ValMin)+Iso2*(log10(ValMax)-log10(ValMin))/(NbIso2-1.)) ; + return pow(10., + log10(ValMin) + Iso2 * (log10(ValMax) - + log10(ValMin)) / (NbIso2 - 1.)); } // Give Index From Value -int GiveIndexFromValue_Lin(double ValMin, double ValMax, int NbIso, double Val){ - if(ValMin==ValMax) return NbIso/2 ; - return (int)((Val-ValMin)*(NbIso-1)/(ValMax-ValMin)) ; +int GiveIndexFromValue_Lin(double ValMin, double ValMax, int NbIso, + double Val) +{ + if(ValMin == ValMax) + return NbIso / 2; + return (int)((Val - ValMin) * (NbIso - 1) / (ValMax - ValMin)); } -int GiveIndexFromValue_Log(double ValMin, double ValMax, int NbIso, double Val){ - if(ValMin==ValMax) return NbIso/2 ; - if(ValMin <= 0.) return 0 ; - return (int)((log10(Val)-log10(ValMin))*(NbIso-1)/(log10(ValMax)-log10(ValMin))) ; +int GiveIndexFromValue_Log(double ValMin, double ValMax, int NbIso, + double Val) +{ + if(ValMin == ValMax) + return NbIso / 2; + if(ValMin <= 0.) + return 0; + return (int)((log10(Val) - log10(ValMin)) * (NbIso - 1) / (log10(ValMax) - + log10(ValMin))); } -int GiveIndexFromValue_DoubleLog(double ValMin, double ValMax, int NbIso, double Val){ - if(ValMin==ValMax) return NbIso/2 ; - if(ValMin <= 0.) return 0 ; - return (int)((log10(Val)-log10(ValMin))*(NbIso-1)/(log10(ValMax)-log10(ValMin))) ; +int GiveIndexFromValue_DoubleLog(double ValMin, double ValMax, int NbIso, + double Val) +{ + if(ValMin == ValMax) + return NbIso / 2; + if(ValMin <= 0.) + return 0; + return (int)((log10(Val) - log10(ValMin)) * (NbIso - 1) / (log10(ValMax) - + log10(ValMin))); } // Color Palette -void Palette1(Post_View *v, int nbi, int i){ /* i in [0,nbi-1] */ - int index ; +void Palette1(Post_View * v, int nbi, int i) +{ /* i in [0,nbi-1] */ + int index; - index = (nbi==1) ? - v->CT.size/2 : - (int) (i/(double)(nbi-1)*(v->CT.size-1) + 0.5) ; + index = (nbi == 1) ? + v->CT.size / 2 : (int)(i / (double)(nbi - 1) * (v->CT.size - 1) + 0.5); - glColor4ubv( (GLubyte *) &v->CT.table[index] ); + glColor4ubv((GLubyte *) & v->CT.table[index]); } -void Palette2(Post_View *v,double min, double max, double val){ /* val in [min,max] */ - int index; +void Palette2(Post_View * v, double min, double max, double val) +{ /* val in [min,max] */ + int index; - index = (min==max) ? - v->CT.size/2 : - (int)( (val-min)/(max-min)*(v->CT.size-1) + 0.5); + index = (min == max) ? + v->CT.size / 2 : + (int)((val - min) / (max - min) * (v->CT.size - 1) + 0.5); - glColor4ubv((GLubyte *) &v->CT.table[index]); + glColor4ubv((GLubyte *) & v->CT.table[index]); } -void RaiseFill(int i, double Val, double ValMin, double Raise[3][8]){ - int j ; - for(j=0 ; j<3 ; j++) Raise[j][i] = (Val-ValMin) * RaiseFactor[j] ; +void RaiseFill(int i, double Val, double ValMin, double Raise[3][8]) +{ + int j; + for(j = 0; j < 3; j++) + Raise[j][i] = (Val - ValMin) * RaiseFactor[j]; } // Compute node coordinates taking Offset and Explode into account -void Get_Coords(double Explode, double *Offset, int nbnod, - double *x1, double *y1, double *z1, - double *x2, double *y2, double *z2){ +void Get_Coords(double Explode, double *Offset, int nbnod, + double *x1, double *y1, double *z1, + double *x2, double *y2, double *z2) +{ int i; - double xc=0., yc=0., zc=0.; + double xc = 0., yc = 0., zc = 0.; - if(Explode==1){ - for(i=0; i<nbnod; i++){ - x2[i] = x1[i]+Offset[0]; - y2[i] = y1[i]+Offset[1]; - z2[i] = z1[i]+Offset[2]; + if(Explode == 1) { + for(i = 0; i < nbnod; i++) { + x2[i] = x1[i] + Offset[0]; + y2[i] = y1[i] + Offset[1]; + z2[i] = z1[i] + Offset[2]; } } - else{ - for(i=0; i<nbnod; i++){ + else { + for(i = 0; i < nbnod; i++) { xc += x1[i]; yc += y1[i]; zc += z1[i]; @@ -130,26 +162,27 @@ void Get_Coords(double Explode, double *Offset, int nbnod, xc /= (double)nbnod; yc /= (double)nbnod; zc /= (double)nbnod; - for(i=0; i<nbnod; i++){ - x2[i] = xc + Explode * (x1[i]-xc) + Offset[0]; - y2[i] = yc + Explode * (y1[i]-yc) + Offset[1]; - z2[i] = zc + Explode * (z1[i]-zc) + Offset[2]; + for(i = 0; i < nbnod; i++) { + x2[i] = xc + Explode * (x1[i] - xc) + Offset[0]; + y2[i] = yc + Explode * (y1[i] - yc) + Offset[1]; + z2[i] = zc + Explode * (z1[i] - zc) + Offset[2]; } } } // Compare barycenters with viewpoint (eye) -static double storedEye[3]={0.,0.,0.}; +static double storedEye[3] = { 0., 0., 0. }; -int changedEye(){ - double zeye=100*CTX.lc, tmp[3]; +int changedEye() +{ + double zeye = 100 * CTX.lc, tmp[3]; tmp[0] = CTX.rot[0][2] * zeye; tmp[1] = CTX.rot[1][2] * zeye; tmp[2] = CTX.rot[2][2] * zeye; - if(fabs(tmp[0]-storedEye[0])>1.e-3 || - fabs(tmp[1]-storedEye[1])>1.e-3 || - fabs(tmp[2]-storedEye[2])>1.e-3){ + if(fabs(tmp[0] - storedEye[0]) > 1.e-3 || + fabs(tmp[1] - storedEye[1]) > 1.e-3 || + fabs(tmp[2] - storedEye[2]) > 1.e-3) { storedEye[0] = tmp[0]; storedEye[1] = tmp[1]; storedEye[2] = tmp[2]; @@ -161,19 +194,22 @@ int changedEye(){ // to be rigorous, we should take Raise into account -int compareEye(double *q, double *w, int nbnodes){ - double d, dq, dw, cgq[3]={0.,0.,0.}, cgw[3]={0.,0.,0.}; - for(int i=0; i<nbnodes; i++){ +int compareEye(double *q, double *w, int nbnodes) +{ + double d, dq, dw, cgq[3] = { 0., 0., 0. }, cgw[3] = + { + 0., 0., 0.}; + for(int i = 0; i < nbnodes; i++) { cgq[0] += q[i]; - cgq[1] += q[i+nbnodes]; - cgq[2] += q[i+2*nbnodes]; + cgq[1] += q[i + nbnodes]; + cgq[2] += q[i + 2 * nbnodes]; cgw[0] += w[i]; - cgw[1] += w[i+nbnodes]; - cgw[2] += w[i+2*nbnodes]; + cgw[1] += w[i + nbnodes]; + cgw[2] += w[i + 2 * nbnodes]; } - prosca(storedEye,cgq,&dq); - prosca(storedEye,cgw,&dw); - d = dq-dw; + prosca(storedEye, cgq, &dq); + prosca(storedEye, cgw, &dw); + d = dq - dw; if(d > 0) return 1; if(d < 0) @@ -181,351 +217,402 @@ int compareEye(double *q, double *w, int nbnodes){ return 0; } -int compareEye3Nodes(const void *a, const void *b){ - return compareEye((double*)a,(double*)b,3); +int compareEye3Nodes(const void *a, const void *b) +{ + return compareEye((double *)a, (double *)b, 3); } -int compareEye4Nodes(const void *a, const void *b){ - return compareEye((double*)a,(double*)b,4); +int compareEye4Nodes(const void *a, const void *b) +{ + return compareEye((double *)a, (double *)b, 4); } -int compareEye5Nodes(const void *a, const void *b){ - return compareEye((double*)a,(double*)b,5); +int compareEye5Nodes(const void *a, const void *b) +{ + return compareEye((double *)a, (double *)b, 5); } -int compareEye6Nodes(const void *a, const void *b){ - return compareEye((double*)a,(double*)b,6); +int compareEye6Nodes(const void *a, const void *b) +{ + return compareEye((double *)a, (double *)b, 6); } -int compareEye8Nodes(const void *a, const void *b){ - return compareEye((double*)a,(double*)b,8); +int compareEye8Nodes(const void *a, const void *b) +{ + return compareEye((double *)a, (double *)b, 8); } // Draw_Post -void Draw_ScalarList(Post_View *v, double ValMin, double ValMax, double Raise[3][8], - List_T *list, int nbelm, int nbnod, int smoothnormals, - void (*draw)(Post_View *, int, double, double, double [3][8], - double *, double *, double *, double *)){ +void Draw_ScalarList(Post_View * v, double ValMin, double ValMax, + double Raise[3][8], List_T * list, int nbelm, int nbnod, + int smoothnormals, void (*draw) (Post_View *, int, + double, double, + double[3][8], double *, + double *, double *, + double *)) +{ int i, nb; - double X[8],Y[8],Z[8]; - - if(nbelm && v->DrawScalars){ - nb = List_Nbr(list) / nbelm ; - if(smoothnormals && v->Light && v->SmoothNormals && v->Changed && - v->IntervalsType != DRAW_POST_ISO){ - v->reset_normals(); // we might save some normal stuff by - // checking if the change actually changed - // the "geometry"... Should put - // e.g. Change=2 if timestep chnaged, etc. + double X[8], Y[8], Z[8]; + + if(nbelm && v->DrawScalars) { + nb = List_Nbr(list) / nbelm; + if(smoothnormals && v->Light && v->SmoothNormals && v->Changed && + v->IntervalsType != DRAW_POST_ISO) { + v->reset_normals(); // we might save some normal stuff by + // checking if the change actually changed + // the "geometry"... Should put + // e.g. Change=2 if timestep chnaged, etc. Msg(DEBUG, "Preprocessing of normals in view %d", v->Num); - for(i = 0 ; i < List_Nbr(list) ; i+=nb){ - Get_Coords(v->Explode, v->Offset, nbnod, - (double*)List_Pointer_Fast(list,i), - (double*)List_Pointer_Fast(list,i+nbnod), - (double*)List_Pointer_Fast(list,i+2*nbnod), X, Y, Z); - draw(v, 1, ValMin, ValMax, Raise, X, Y, Z, - (double*)List_Pointer_Fast(list,i+3*nbnod)); + for(i = 0; i < List_Nbr(list); i += nb) { + Get_Coords(v->Explode, v->Offset, nbnod, + (double *)List_Pointer_Fast(list, i), + (double *)List_Pointer_Fast(list, i + nbnod), + (double *)List_Pointer_Fast(list, i + 2 * nbnod), X, Y, Z); + draw(v, 1, ValMin, ValMax, Raise, X, Y, Z, + (double *)List_Pointer_Fast(list, i + 3 * nbnod)); } } - for(i = 0 ; i < List_Nbr(list) ; i+=nb){ - Get_Coords(v->Explode, v->Offset, nbnod, - (double*)List_Pointer_Fast(list,i), - (double*)List_Pointer_Fast(list,i+nbnod), - (double*)List_Pointer_Fast(list,i+2*nbnod), X, Y, Z); - draw(v, 0, ValMin, ValMax, Raise, X, Y, Z, - (double*)List_Pointer_Fast(list,i+3*nbnod)); + for(i = 0; i < List_Nbr(list); i += nb) { + Get_Coords(v->Explode, v->Offset, nbnod, + (double *)List_Pointer_Fast(list, i), + (double *)List_Pointer_Fast(list, i + nbnod), + (double *)List_Pointer_Fast(list, i + 2 * nbnod), X, Y, Z); + draw(v, 0, ValMin, ValMax, Raise, X, Y, Z, + (double *)List_Pointer_Fast(list, i + 3 * nbnod)); } } } -void Draw_VectorList(Post_View *v, double ValMin, double ValMax, double Raise[3][8], - List_T *list, int nbelm, int nbnod, - void (*draw)(Post_View *, double, double, double [3][8], - double *, double *, double *, double *)){ +void Draw_VectorList(Post_View * v, double ValMin, double ValMax, + double Raise[3][8], List_T * list, int nbelm, int nbnod, + void (*draw) (Post_View *, double, double, double[3][8], + double *, double *, double *, double *)) +{ int i, nb; - double X[8],Y[8],Z[8]; + double X[8], Y[8], Z[8]; - if(nbelm && v->DrawVectors){ - nb = List_Nbr(list) / nbelm ; - for(i = 0 ; i < List_Nbr(list) ; i+=nb){ + if(nbelm && v->DrawVectors) { + nb = List_Nbr(list) / nbelm; + for(i = 0; i < List_Nbr(list); i += nb) { Get_Coords(v->Explode, v->Offset, nbnod, - (double*)List_Pointer_Fast(list,i), - (double*)List_Pointer_Fast(list,i+nbnod), - (double*)List_Pointer_Fast(list,i+2*nbnod), X, Y, Z); - draw(v, ValMin, ValMax, Raise, X, Y, Z, - (double*)List_Pointer_Fast(list,i+3*nbnod)); + (double *)List_Pointer_Fast(list, i), + (double *)List_Pointer_Fast(list, i + nbnod), + (double *)List_Pointer_Fast(list, i + 2 * nbnod), X, Y, Z); + draw(v, ValMin, ValMax, Raise, X, Y, Z, + (double *)List_Pointer_Fast(list, i + 3 * nbnod)); } } } -void Draw_TensorList(Post_View *v, double ValMin, double ValMax, double Raise[3][8], - List_T *list, int nbelm, int nbnod, - void (*draw)(Post_View *, double, double, double [3][8], - double *, double *, double *, double *)){ +void Draw_TensorList(Post_View * v, double ValMin, double ValMax, + double Raise[3][8], List_T * list, int nbelm, int nbnod, + void (*draw) (Post_View *, double, double, double[3][8], + double *, double *, double *, double *)) +{ int i, nb; - double X[8],Y[8],Z[8]; + double X[8], Y[8], Z[8]; - if(nbelm && v->DrawTensors){ - nb = List_Nbr(list) / nbelm ; - for(i = 0 ; i < List_Nbr(list) ; i+=nb){ + if(nbelm && v->DrawTensors) { + nb = List_Nbr(list) / nbelm; + for(i = 0; i < List_Nbr(list); i += nb) { Get_Coords(v->Explode, v->Offset, nbnod, - (double*)List_Pointer_Fast(list,i), - (double*)List_Pointer_Fast(list,i+nbnod), - (double*)List_Pointer_Fast(list,i+2*nbnod), X, Y, Z); - draw(v, ValMin, ValMax, Raise, X, Y, Z, - (double*)List_Pointer_Fast(list,i+3*nbnod)); + (double *)List_Pointer_Fast(list, i), + (double *)List_Pointer_Fast(list, i + nbnod), + (double *)List_Pointer_Fast(list, i + 2 * nbnod), X, Y, Z); + draw(v, ValMin, ValMax, Raise, X, Y, Z, + (double *)List_Pointer_Fast(list, i + 3 * nbnod)); } } } -void Draw_Post(void){ - int iView,j,k,nb; - double ValMin=0.,ValMax=0.,AbsMax; - Post_View *v; - - if(!CTX.post.list) return; - - if(!CTX.post.draw){ // draw only the bbox of the visible views - for(iView=0 ; iView<List_Nbr(CTX.post.list) ; iView++){ - v = (Post_View*)List_Pointer(CTX.post.list,iView); - if(v->Visible && v->Type==DRAW_POST_3D){ - glColor4ubv((GLubyte*)&CTX.color.fg); - glBegin(GL_LINE_LOOP); - glVertex3d(v->BBox[0], v->BBox[2], v->BBox[4]); - glVertex3d(v->BBox[1], v->BBox[2], v->BBox[4]); - glVertex3d(v->BBox[1], v->BBox[3], v->BBox[4]); - glVertex3d(v->BBox[0], v->BBox[3], v->BBox[4]); - glEnd(); - glBegin(GL_LINE_LOOP); - glVertex3d(v->BBox[0], v->BBox[2], v->BBox[5]); - glVertex3d(v->BBox[1], v->BBox[2], v->BBox[5]); - glVertex3d(v->BBox[1], v->BBox[3], v->BBox[5]); - glVertex3d(v->BBox[0], v->BBox[3], v->BBox[5]); - glEnd(); - glBegin(GL_LINES); - glVertex3d(v->BBox[0], v->BBox[2], v->BBox[4]); - glVertex3d(v->BBox[0], v->BBox[2], v->BBox[5]); - glVertex3d(v->BBox[1], v->BBox[2], v->BBox[4]); - glVertex3d(v->BBox[1], v->BBox[2], v->BBox[5]); - glVertex3d(v->BBox[1], v->BBox[3], v->BBox[4]); - glVertex3d(v->BBox[1], v->BBox[3], v->BBox[5]); - glVertex3d(v->BBox[0], v->BBox[3], v->BBox[4]); - glVertex3d(v->BBox[0], v->BBox[3], v->BBox[5]); - glEnd(); +void Draw_Post(void) +{ + int iView, j, k, nb; + double ValMin = 0., ValMax = 0., AbsMax; + Post_View *v; + + if(!CTX.post.list) + return; + + if(!CTX.post.draw) { // draw only the bbox of the visible views + for(iView = 0; iView < List_Nbr(CTX.post.list); iView++) { + v = (Post_View *) List_Pointer(CTX.post.list, iView); + if(v->Visible && v->Type == DRAW_POST_3D) { + glColor4ubv((GLubyte *) & CTX.color.fg); + glBegin(GL_LINE_LOOP); + glVertex3d(v->BBox[0], v->BBox[2], v->BBox[4]); + glVertex3d(v->BBox[1], v->BBox[2], v->BBox[4]); + glVertex3d(v->BBox[1], v->BBox[3], v->BBox[4]); + glVertex3d(v->BBox[0], v->BBox[3], v->BBox[4]); + glEnd(); + glBegin(GL_LINE_LOOP); + glVertex3d(v->BBox[0], v->BBox[2], v->BBox[5]); + glVertex3d(v->BBox[1], v->BBox[2], v->BBox[5]); + glVertex3d(v->BBox[1], v->BBox[3], v->BBox[5]); + glVertex3d(v->BBox[0], v->BBox[3], v->BBox[5]); + glEnd(); + glBegin(GL_LINES); + glVertex3d(v->BBox[0], v->BBox[2], v->BBox[4]); + glVertex3d(v->BBox[0], v->BBox[2], v->BBox[5]); + glVertex3d(v->BBox[1], v->BBox[2], v->BBox[4]); + glVertex3d(v->BBox[1], v->BBox[2], v->BBox[5]); + glVertex3d(v->BBox[1], v->BBox[3], v->BBox[4]); + glVertex3d(v->BBox[1], v->BBox[3], v->BBox[5]); + glVertex3d(v->BBox[0], v->BBox[3], v->BBox[4]); + glVertex3d(v->BBox[0], v->BBox[3], v->BBox[5]); + glEnd(); } - } + } return; } - - for(iView=0 ; iView<List_Nbr(CTX.post.list) ; iView++){ - v = (Post_View*)List_Pointer(CTX.post.list,iView); + for(iView = 0; iView < List_Nbr(CTX.post.list); iView++) { - if(v->Visible && !v->Dirty){ + v = (Post_View *) List_Pointer(CTX.post.list, iView); + + if(v->Visible && !v->Dirty) { // sort the data % eye for transparency. Hybrid views // (e.g. tri+qua) or multiple views will be sorted // incorrectly... One should have a function (plugin?) to // merge+decompose in simplices a group of views. - if(CTX.alpha && ColorTable_IsAlpha(&v->CT) && changedEye()){ - Msg(DEBUG, "Sorting view %d", v->Num); - - if(v->DrawScalars){ - - if(v->IntervalsType != DRAW_POST_ISO){ - - if(v->NbST && v->DrawTriangles){ - nb = List_Nbr(v->ST) / v->NbST ; - qsort(v->ST->array,v->NbST,nb*sizeof(double),compareEye3Nodes); - v->Changed = 1; - } - if(v->NbSQ && v->DrawQuadrangles){ - nb = List_Nbr(v->SQ) / v->NbSQ ; - qsort(v->SQ->array,v->NbSQ,nb*sizeof(double),compareEye4Nodes); - v->Changed = 1; - } - - } - - // the following is of course not rigorous (we should store - // the triangles generated during the iso computation, and - // sort these... But this is better than doing nothing :-) - if(v->NbSS && v->DrawTetrahedra){ - nb = List_Nbr(v->SS) / v->NbSS ; - qsort(v->SS->array,v->NbSS,nb*sizeof(double),compareEye4Nodes); - v->Changed = 1; - } - if(v->NbSH && v->DrawHexahedra){ - nb = List_Nbr(v->SH) / v->NbSH ; - qsort(v->SH->array,v->NbSH,nb*sizeof(double),compareEye8Nodes); - v->Changed = 1; - } - if(v->NbSI && v->DrawPrisms){ - nb = List_Nbr(v->SI) / v->NbSI ; - qsort(v->SI->array,v->NbSI,nb*sizeof(double),compareEye6Nodes); - v->Changed = 1; - } - if(v->NbSY && v->DrawPyramids){ - nb = List_Nbr(v->SY) / v->NbSY ; - qsort(v->SY->array,v->NbSY,nb*sizeof(double),compareEye5Nodes); - v->Changed = 1; - } - - } + if(CTX.alpha && ColorTable_IsAlpha(&v->CT) && changedEye()) { + Msg(DEBUG, "Sorting view %d", v->Num); + + if(v->DrawScalars) { + + if(v->IntervalsType != DRAW_POST_ISO) { + + if(v->NbST && v->DrawTriangles) { + nb = List_Nbr(v->ST) / v->NbST; + qsort(v->ST->array, v->NbST, nb * sizeof(double), + compareEye3Nodes); + v->Changed = 1; + } + if(v->NbSQ && v->DrawQuadrangles) { + nb = List_Nbr(v->SQ) / v->NbSQ; + qsort(v->SQ->array, v->NbSQ, nb * sizeof(double), + compareEye4Nodes); + v->Changed = 1; + } + + } + + // the following is of course not rigorous (we should store + // the triangles generated during the iso computation, and + // sort these... But this is better than doing nothing :-) + if(v->NbSS && v->DrawTetrahedra) { + nb = List_Nbr(v->SS) / v->NbSS; + qsort(v->SS->array, v->NbSS, nb * sizeof(double), + compareEye4Nodes); + v->Changed = 1; + } + if(v->NbSH && v->DrawHexahedra) { + nb = List_Nbr(v->SH) / v->NbSH; + qsort(v->SH->array, v->NbSH, nb * sizeof(double), + compareEye8Nodes); + v->Changed = 1; + } + if(v->NbSI && v->DrawPrisms) { + nb = List_Nbr(v->SI) / v->NbSI; + qsort(v->SI->array, v->NbSI, nb * sizeof(double), + compareEye6Nodes); + v->Changed = 1; + } + if(v->NbSY && v->DrawPyramids) { + nb = List_Nbr(v->SY) / v->NbSY; + qsort(v->SY->array, v->NbSY, nb * sizeof(double), + compareEye5Nodes); + v->Changed = 1; + } + + } } - if(CTX.post.display_lists && !v->Changed && v->DisplayListNum>0){ + if(CTX.post.display_lists && !v->Changed && v->DisplayListNum > 0) { - Msg(DEBUG, "Call display List %d", v->DisplayListNum); + Msg(DEBUG, "Call display List %d", v->DisplayListNum); glCallList(v->DisplayListNum); } - else{ - - if(CTX.post.display_lists){ - if(v->DisplayListNum>0){ - Msg(DEBUG, "Delete display List %d", v->DisplayListNum); - glDeleteLists(v->DisplayListNum,1); - } - else{ - v->DisplayListNum = glGenLists(1); - Msg(DEBUG, "Gen display list -> %d", v->DisplayListNum); - } - - if(v->DisplayListNum>0){ - Msg(DEBUG, "New display List %d", v->DisplayListNum); - glNewList(v->DisplayListNum, GL_COMPILE_AND_EXECUTE); - } - else - Msg(GERROR, "Unable to create display list"); + else { + + if(CTX.post.display_lists) { + if(v->DisplayListNum > 0) { + Msg(DEBUG, "Delete display List %d", v->DisplayListNum); + glDeleteLists(v->DisplayListNum, 1); + } + else { + v->DisplayListNum = glGenLists(1); + Msg(DEBUG, "Gen display list -> %d", v->DisplayListNum); + } + + if(v->DisplayListNum > 0) { + Msg(DEBUG, "New display List %d", v->DisplayListNum); + glNewList(v->DisplayListNum, GL_COMPILE_AND_EXECUTE); + } + else + Msg(GERROR, "Unable to create display list"); } - glPointSize(v->PointSize); - gl2psPointSize(v->PointSize * CTX.print.eps_point_size_factor); + glPointSize(v->PointSize); + gl2psPointSize(v->PointSize * CTX.print.eps_point_size_factor); - glLineWidth(v->LineWidth); - gl2psLineWidth(v->LineWidth * CTX.print.eps_line_width_factor); + glLineWidth(v->LineWidth); + gl2psLineWidth(v->LineWidth * CTX.print.eps_line_width_factor); if(v->Light) InitShading(); else InitNoShading(); - if(v->ShowElement) - glEnable(GL_POLYGON_OFFSET_FILL) ; + if(v->ShowElement) + glEnable(GL_POLYGON_OFFSET_FILL); // force this - if(v->IntervalsType == DRAW_POST_CONTINUOUS){ - glShadeModel(GL_SMOOTH); - glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); + if(v->IntervalsType == DRAW_POST_CONTINUOUS) { + glShadeModel(GL_SMOOTH); + glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE); + } + else { // there is a bug in CutTriangle2D!! See Iso.cpp + glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); } - else{// there is a bug in CutTriangle2D!! See Iso.cpp - glLightModelf(GL_LIGHT_MODEL_TWO_SIDE, GL_FALSE); - } - switch(v->RangeType){ - case DRAW_POST_DEFAULT : ValMin = v->Min ; ValMax = v->Max ; break; - case DRAW_POST_CUSTOM : ValMin = v->CustomMin ; ValMax = v->CustomMax ; break; + switch (v->RangeType) { + case DRAW_POST_DEFAULT: + ValMin = v->Min; + ValMax = v->Max; + break; + case DRAW_POST_CUSTOM: + ValMin = v->CustomMin; + ValMax = v->CustomMax; + break; } - - switch(v->ScaleType){ - case DRAW_POST_LINEAR : - v->GIFV = GiveIndexFromValue_Lin ; - v->GVFI = GiveValueFromIndex_Lin ; + + switch (v->ScaleType) { + case DRAW_POST_LINEAR: + v->GIFV = GiveIndexFromValue_Lin; + v->GVFI = GiveValueFromIndex_Lin; + break; + case DRAW_POST_LOGARITHMIC: + v->GIFV = GiveIndexFromValue_Log; + v->GVFI = GiveValueFromIndex_Log; break; - case DRAW_POST_LOGARITHMIC : - v->GIFV = GiveIndexFromValue_Log ; - v->GVFI = GiveValueFromIndex_Log ; - break; - case DRAW_POST_DOUBLELOGARITHMIC : - v->GIFV = GiveIndexFromValue_DoubleLog ; - v->GVFI = GiveValueFromIndex_DoubleLog ; + case DRAW_POST_DOUBLELOGARITHMIC: + v->GIFV = GiveIndexFromValue_DoubleLog; + v->GVFI = GiveValueFromIndex_DoubleLog; break; } - - AbsMax = DMAX(fabs(ValMin),fabs(ValMax)); - AbsMax = (AbsMax==0.) ? 1. : AbsMax; - - for(j=0;j<3;j++){ - RaiseFactor[j] = v->Raise[j] / AbsMax ; - for(k=0;k<5;k++) Raise[j][k] = 0. ; + + AbsMax = DMAX(fabs(ValMin), fabs(ValMax)); + AbsMax = (AbsMax == 0.) ? 1. : AbsMax; + + for(j = 0; j < 3; j++) { + RaiseFactor[j] = v->Raise[j] / AbsMax; + for(k = 0; k < 5; k++) + Raise[j][k] = 0.; + } + + // Points + if(v->DrawPoints) { + if(v->Type == DRAW_POST_3D) + Draw_ScalarList(v, ValMin, ValMax, Raise, v->SP, v->NbSP, 1, 0, + Draw_ScalarPoint); + Draw_VectorList(v, ValMin, ValMax, Raise, v->VP, v->NbVP, 1, + Draw_VectorPoint); + Draw_TensorList(v, ValMin, ValMax, Raise, v->TP, v->NbTP, 1, + Draw_TensorPoint); + } + + // Lines + if(v->DrawLines) { + Draw_ScalarList(v, ValMin, ValMax, Raise, v->SL, v->NbSL, 2, 0, + Draw_ScalarLine); + Draw_VectorList(v, ValMin, ValMax, Raise, v->VL, v->NbVL, 2, + Draw_VectorLine); + Draw_TensorList(v, ValMin, ValMax, Raise, v->TL, v->NbTL, 2, + Draw_TensorLine); + } + + // Triangles + if(v->DrawTriangles) { + Draw_ScalarList(v, ValMin, ValMax, Raise, v->ST, v->NbST, 3, 1, + Draw_ScalarTriangle); + Draw_VectorList(v, ValMin, ValMax, Raise, v->VT, v->NbVT, 3, + Draw_VectorTriangle); + Draw_TensorList(v, ValMin, ValMax, Raise, v->TT, v->NbTT, 3, + Draw_TensorTriangle); + } + + // Quadrangles + if(v->DrawQuadrangles) { + Draw_ScalarList(v, ValMin, ValMax, Raise, v->SQ, v->NbSQ, 4, 1, + Draw_ScalarQuadrangle); + Draw_VectorList(v, ValMin, ValMax, Raise, v->VQ, v->NbVQ, 4, + Draw_VectorQuadrangle); + Draw_TensorList(v, ValMin, ValMax, Raise, v->TQ, v->NbTQ, 4, + Draw_TensorQuadrangle); + } + + // Tetrahedra + if(v->DrawTetrahedra) { + Draw_ScalarList(v, ValMin, ValMax, Raise, v->SS, v->NbSS, 4, 1, + Draw_ScalarTetrahedron); + Draw_VectorList(v, ValMin, ValMax, Raise, v->VS, v->NbVS, 4, + Draw_VectorTetrahedron); + Draw_TensorList(v, ValMin, ValMax, Raise, v->TS, v->NbTS, 4, + Draw_TensorTetrahedron); + } + + // Hexahedra + if(v->DrawHexahedra) { + Draw_ScalarList(v, ValMin, ValMax, Raise, v->SH, v->NbSH, 8, 1, + Draw_ScalarHexahedron); + Draw_VectorList(v, ValMin, ValMax, Raise, v->VH, v->NbVH, 8, + Draw_VectorHexahedron); + Draw_TensorList(v, ValMin, ValMax, Raise, v->TH, v->NbTH, 8, + Draw_TensorHexahedron); + } + + // Prisms + if(v->DrawPrisms) { + Draw_ScalarList(v, ValMin, ValMax, Raise, v->SI, v->NbSI, 6, 1, + Draw_ScalarPrism); + Draw_VectorList(v, ValMin, ValMax, Raise, v->VI, v->NbVI, 6, + Draw_VectorPrism); + Draw_TensorList(v, ValMin, ValMax, Raise, v->TI, v->NbTI, 6, + Draw_TensorPrism); } - // Points - if(v->DrawPoints){ - if(v->Type==DRAW_POST_3D) - Draw_ScalarList(v, ValMin, ValMax, Raise, v->SP, v->NbSP, 1, 0, Draw_ScalarPoint); - Draw_VectorList(v, ValMin, ValMax, Raise, v->VP, v->NbVP, 1, Draw_VectorPoint); - Draw_TensorList(v, ValMin, ValMax, Raise, v->TP, v->NbTP, 1, Draw_TensorPoint); - } - - // Lines - if(v->DrawLines){ - Draw_ScalarList(v, ValMin, ValMax, Raise, v->SL, v->NbSL, 2, 0, Draw_ScalarLine); - Draw_VectorList(v, ValMin, ValMax, Raise, v->VL, v->NbVL, 2, Draw_VectorLine); - Draw_TensorList(v, ValMin, ValMax, Raise, v->TL, v->NbTL, 2, Draw_TensorLine); - } - - // Triangles - if(v->DrawTriangles){ - Draw_ScalarList(v, ValMin, ValMax, Raise, v->ST, v->NbST, 3, 1, Draw_ScalarTriangle); - Draw_VectorList(v, ValMin, ValMax, Raise, v->VT, v->NbVT, 3, Draw_VectorTriangle); - Draw_TensorList(v, ValMin, ValMax, Raise, v->TT, v->NbTT, 3, Draw_TensorTriangle); - } - - // Quadrangles - if(v->DrawQuadrangles){ - Draw_ScalarList(v, ValMin, ValMax, Raise, v->SQ, v->NbSQ, 4, 1, Draw_ScalarQuadrangle); - Draw_VectorList(v, ValMin, ValMax, Raise, v->VQ, v->NbVQ, 4, Draw_VectorQuadrangle); - Draw_TensorList(v, ValMin, ValMax, Raise, v->TQ, v->NbTQ, 4, Draw_TensorQuadrangle); - } - - // Tetrahedra - if(v->DrawTetrahedra){ - Draw_ScalarList(v, ValMin, ValMax, Raise, v->SS, v->NbSS, 4, 1, Draw_ScalarTetrahedron); - Draw_VectorList(v, ValMin, ValMax, Raise, v->VS, v->NbVS, 4, Draw_VectorTetrahedron); - Draw_TensorList(v, ValMin, ValMax, Raise, v->TS, v->NbTS, 4, Draw_TensorTetrahedron); - } - - // Hexahedra - if(v->DrawHexahedra){ - Draw_ScalarList(v, ValMin, ValMax, Raise, v->SH, v->NbSH, 8, 1, Draw_ScalarHexahedron); - Draw_VectorList(v, ValMin, ValMax, Raise, v->VH, v->NbVH, 8, Draw_VectorHexahedron); - Draw_TensorList(v, ValMin, ValMax, Raise, v->TH, v->NbTH, 8, Draw_TensorHexahedron); - } - - // Prisms - if(v->DrawPrisms){ - Draw_ScalarList(v, ValMin, ValMax, Raise, v->SI, v->NbSI, 6, 1, Draw_ScalarPrism); - Draw_VectorList(v, ValMin, ValMax, Raise, v->VI, v->NbVI, 6, Draw_VectorPrism); - Draw_TensorList(v, ValMin, ValMax, Raise, v->TI, v->NbTI, 6, Draw_TensorPrism); - } - - // Pyramids - if(v->DrawPyramids){ - Draw_ScalarList(v, ValMin, ValMax, Raise, v->SY, v->NbSY, 5, 1, Draw_ScalarPyramid); - Draw_VectorList(v, ValMin, ValMax, Raise, v->VY, v->NbVY, 5, Draw_VectorPyramid); - Draw_TensorList(v, ValMin, ValMax, Raise, v->TY, v->NbTY, 5, Draw_TensorPyramid); - } - - // Strings - if(v->DrawStrings){ - glColor4ubv((GLubyte*)&CTX.color.text); - Draw_Text2D3D(3, v->TimeStep, v->NbT3, v->T3D, v->T3C); - } - - if(CTX.post.display_lists) glEndList(); - - v->Changed=0; - - if(v->ShowElement || v->ArrowType == DRAW_POST_DISPLACEMENT) - glDisable(GL_POLYGON_OFFSET_FILL) ; - + // Pyramids + if(v->DrawPyramids) { + Draw_ScalarList(v, ValMin, ValMax, Raise, v->SY, v->NbSY, 5, 1, + Draw_ScalarPyramid); + Draw_VectorList(v, ValMin, ValMax, Raise, v->VY, v->NbVY, 5, + Draw_VectorPyramid); + Draw_TensorList(v, ValMin, ValMax, Raise, v->TY, v->NbTY, 5, + Draw_TensorPyramid); + } + + // Strings + if(v->DrawStrings) { + glColor4ubv((GLubyte *) & CTX.color.text); + Draw_Text2D3D(3, v->TimeStep, v->NbT3, v->T3D, v->T3C); + } + + if(CTX.post.display_lists) + glEndList(); + + v->Changed = 0; + + if(v->ShowElement || v->ArrowType == DRAW_POST_DISPLACEMENT) + glDisable(GL_POLYGON_OFFSET_FILL); + } - + } } @@ -534,4 +621,3 @@ void Draw_Post(void){ InitNoShading(); } - diff --git a/Graphics/PostElement.cpp b/Graphics/PostElement.cpp index ab7130ae7d685e7ee07afbfb6d6f2d012ef5905c..7428e206f34a53ee5c1f0df8882041af5246a14a 100644 --- a/Graphics/PostElement.cpp +++ b/Graphics/PostElement.cpp @@ -1,4 +1,4 @@ -// $Id: PostElement.cpp,v 1.10 2003-02-25 04:02:50 geuzaine Exp $ +// $Id: PostElement.cpp,v 1.11 2003-03-01 22:36:40 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -44,123 +44,165 @@ #define PRISM 6 #define PYRAMID 7 -extern Context_T CTX; +extern Context_T CTX; -void Draw_ElementBoundary(int type, Post_View *View, double *X, double *Y, double *Z, - double Raise[3][8]){ +void Draw_ElementBoundary(int type, Post_View * View, double *X, double *Y, + double *Z, double Raise[3][8]) +{ int k; double xx[8], yy[8], zz[8]; - if(View->Light) glDisable(GL_LIGHTING); + if(View->Light) + glDisable(GL_LIGHTING); - glColor4ubv((GLubyte*)&CTX.color.fg); - switch(type){ - case POINT : - Draw_Point(View->PointType,View->PointSize,X,Y,Z,Raise); + glColor4ubv((GLubyte *) & CTX.color.fg); + switch (type) { + case POINT: + Draw_Point(View->PointType, View->PointSize, X, Y, Z, Raise); break; - case LINE : - Draw_Line(0,View->LineWidth,X,Y,Z,Raise); + case LINE: + Draw_Line(0, View->LineWidth, X, Y, Z, Raise); break; - case TRIANGLE : + case TRIANGLE: glBegin(GL_LINE_LOOP); - for(k=0 ; k<3 ; k++) - glVertex3d(X[k]+Raise[0][k], Y[k]+Raise[1][k], Z[k]+Raise[2][k]); + for(k = 0; k < 3; k++) + glVertex3d(X[k] + Raise[0][k], Y[k] + Raise[1][k], Z[k] + Raise[2][k]); glEnd(); break; - case TETRAHEDRON : - for(k=0 ; k<4 ; k++){ - xx[k] = X[k]+Raise[0][k] ; - yy[k] = Y[k]+Raise[1][k] ; - zz[k] = Z[k]+Raise[2][k] ; + case TETRAHEDRON: + for(k = 0; k < 4; k++) { + xx[k] = X[k] + Raise[0][k]; + yy[k] = Y[k] + Raise[1][k]; + zz[k] = Z[k] + Raise[2][k]; } glBegin(GL_LINES); - glVertex3d(xx[0], yy[0], zz[0]); glVertex3d(xx[1], yy[1], zz[1]); - glVertex3d(xx[0], yy[0], zz[0]); glVertex3d(xx[2], yy[2], zz[2]); - glVertex3d(xx[0], yy[0], zz[0]); glVertex3d(xx[3], yy[3], zz[3]); - glVertex3d(xx[1], yy[1], zz[1]); glVertex3d(xx[2], yy[2], zz[2]); - glVertex3d(xx[1], yy[1], zz[1]); glVertex3d(xx[3], yy[3], zz[3]); - glVertex3d(xx[2], yy[2], zz[2]); glVertex3d(xx[3], yy[3], zz[3]); + glVertex3d(xx[0], yy[0], zz[0]); + glVertex3d(xx[1], yy[1], zz[1]); + glVertex3d(xx[0], yy[0], zz[0]); + glVertex3d(xx[2], yy[2], zz[2]); + glVertex3d(xx[0], yy[0], zz[0]); + glVertex3d(xx[3], yy[3], zz[3]); + glVertex3d(xx[1], yy[1], zz[1]); + glVertex3d(xx[2], yy[2], zz[2]); + glVertex3d(xx[1], yy[1], zz[1]); + glVertex3d(xx[3], yy[3], zz[3]); + glVertex3d(xx[2], yy[2], zz[2]); + glVertex3d(xx[3], yy[3], zz[3]); glEnd(); break; - case QUADRANGLE : + case QUADRANGLE: glBegin(GL_LINE_LOOP); - for(k=0 ; k<4 ; k++) - glVertex3d(X[k]+Raise[0][k], Y[k]+Raise[1][k], Z[k]+Raise[2][k]); + for(k = 0; k < 4; k++) + glVertex3d(X[k] + Raise[0][k], Y[k] + Raise[1][k], Z[k] + Raise[2][k]); glEnd(); break; - case HEXAHEDRON : - for(k=0 ; k<8 ; k++){ - xx[k] = X[k]+Raise[0][k] ; - yy[k] = Y[k]+Raise[1][k] ; - zz[k] = Z[k]+Raise[2][k] ; + case HEXAHEDRON: + for(k = 0; k < 8; k++) { + xx[k] = X[k] + Raise[0][k]; + yy[k] = Y[k] + Raise[1][k]; + zz[k] = Z[k] + Raise[2][k]; } glBegin(GL_LINES); - glVertex3d(xx[0], yy[0], zz[0]); glVertex3d(xx[1], yy[1], zz[1]); - glVertex3d(xx[0], yy[0], zz[0]); glVertex3d(xx[3], yy[3], zz[3]); - glVertex3d(xx[0], yy[0], zz[0]); glVertex3d(xx[4], yy[4], zz[4]); - glVertex3d(xx[1], yy[1], zz[1]); glVertex3d(xx[2], yy[2], zz[2]); - glVertex3d(xx[1], yy[1], zz[1]); glVertex3d(xx[5], yy[5], zz[5]); - glVertex3d(xx[2], yy[2], zz[2]); glVertex3d(xx[3], yy[3], zz[3]); - glVertex3d(xx[2], yy[2], zz[2]); glVertex3d(xx[6], yy[6], zz[6]); - glVertex3d(xx[3], yy[3], zz[3]); glVertex3d(xx[7], yy[7], zz[7]); - glVertex3d(xx[4], yy[4], zz[4]); glVertex3d(xx[5], yy[5], zz[5]); - glVertex3d(xx[4], yy[4], zz[4]); glVertex3d(xx[7], yy[7], zz[7]); - glVertex3d(xx[5], yy[5], zz[5]); glVertex3d(xx[6], yy[6], zz[6]); - glVertex3d(xx[6], yy[6], zz[6]); glVertex3d(xx[7], yy[7], zz[7]); + glVertex3d(xx[0], yy[0], zz[0]); + glVertex3d(xx[1], yy[1], zz[1]); + glVertex3d(xx[0], yy[0], zz[0]); + glVertex3d(xx[3], yy[3], zz[3]); + glVertex3d(xx[0], yy[0], zz[0]); + glVertex3d(xx[4], yy[4], zz[4]); + glVertex3d(xx[1], yy[1], zz[1]); + glVertex3d(xx[2], yy[2], zz[2]); + glVertex3d(xx[1], yy[1], zz[1]); + glVertex3d(xx[5], yy[5], zz[5]); + glVertex3d(xx[2], yy[2], zz[2]); + glVertex3d(xx[3], yy[3], zz[3]); + glVertex3d(xx[2], yy[2], zz[2]); + glVertex3d(xx[6], yy[6], zz[6]); + glVertex3d(xx[3], yy[3], zz[3]); + glVertex3d(xx[7], yy[7], zz[7]); + glVertex3d(xx[4], yy[4], zz[4]); + glVertex3d(xx[5], yy[5], zz[5]); + glVertex3d(xx[4], yy[4], zz[4]); + glVertex3d(xx[7], yy[7], zz[7]); + glVertex3d(xx[5], yy[5], zz[5]); + glVertex3d(xx[6], yy[6], zz[6]); + glVertex3d(xx[6], yy[6], zz[6]); + glVertex3d(xx[7], yy[7], zz[7]); glEnd(); break; - case PRISM : - for(k=0 ; k<6 ; k++){ - xx[k] = X[k]+Raise[0][k] ; - yy[k] = Y[k]+Raise[1][k] ; - zz[k] = Z[k]+Raise[2][k] ; + case PRISM: + for(k = 0; k < 6; k++) { + xx[k] = X[k] + Raise[0][k]; + yy[k] = Y[k] + Raise[1][k]; + zz[k] = Z[k] + Raise[2][k]; } glBegin(GL_LINES); - glVertex3d(xx[0], yy[0], zz[0]); glVertex3d(xx[1], yy[1], zz[1]); - glVertex3d(xx[0], yy[0], zz[0]); glVertex3d(xx[2], yy[2], zz[2]); - glVertex3d(xx[0], yy[0], zz[0]); glVertex3d(xx[3], yy[3], zz[3]); - glVertex3d(xx[1], yy[1], zz[1]); glVertex3d(xx[2], yy[2], zz[2]); - glVertex3d(xx[1], yy[1], zz[1]); glVertex3d(xx[4], yy[4], zz[4]); - glVertex3d(xx[2], yy[2], zz[2]); glVertex3d(xx[5], yy[5], zz[5]); - glVertex3d(xx[3], yy[3], zz[3]); glVertex3d(xx[4], yy[4], zz[4]); - glVertex3d(xx[3], yy[3], zz[3]); glVertex3d(xx[5], yy[5], zz[5]); - glVertex3d(xx[4], yy[4], zz[4]); glVertex3d(xx[5], yy[5], zz[5]); + glVertex3d(xx[0], yy[0], zz[0]); + glVertex3d(xx[1], yy[1], zz[1]); + glVertex3d(xx[0], yy[0], zz[0]); + glVertex3d(xx[2], yy[2], zz[2]); + glVertex3d(xx[0], yy[0], zz[0]); + glVertex3d(xx[3], yy[3], zz[3]); + glVertex3d(xx[1], yy[1], zz[1]); + glVertex3d(xx[2], yy[2], zz[2]); + glVertex3d(xx[1], yy[1], zz[1]); + glVertex3d(xx[4], yy[4], zz[4]); + glVertex3d(xx[2], yy[2], zz[2]); + glVertex3d(xx[5], yy[5], zz[5]); + glVertex3d(xx[3], yy[3], zz[3]); + glVertex3d(xx[4], yy[4], zz[4]); + glVertex3d(xx[3], yy[3], zz[3]); + glVertex3d(xx[5], yy[5], zz[5]); + glVertex3d(xx[4], yy[4], zz[4]); + glVertex3d(xx[5], yy[5], zz[5]); glEnd(); break; - case PYRAMID : - for(k=0 ; k<5 ; k++){ - xx[k] = X[k]+Raise[0][k] ; - yy[k] = Y[k]+Raise[1][k] ; - zz[k] = Z[k]+Raise[2][k] ; + case PYRAMID: + for(k = 0; k < 5; k++) { + xx[k] = X[k] + Raise[0][k]; + yy[k] = Y[k] + Raise[1][k]; + zz[k] = Z[k] + Raise[2][k]; } glBegin(GL_LINES); - glVertex3d(xx[0], yy[0], zz[0]); glVertex3d(xx[1], yy[1], zz[1]); - glVertex3d(xx[1], yy[1], zz[1]); glVertex3d(xx[2], yy[2], zz[2]); - glVertex3d(xx[3], yy[3], zz[3]); glVertex3d(xx[2], yy[2], zz[2]); - glVertex3d(xx[0], yy[0], zz[0]); glVertex3d(xx[3], yy[3], zz[3]); - glVertex3d(xx[0], yy[0], zz[0]); glVertex3d(xx[4], yy[4], zz[4]); - glVertex3d(xx[1], yy[1], zz[1]); glVertex3d(xx[4], yy[4], zz[4]); - glVertex3d(xx[3], yy[3], zz[3]); glVertex3d(xx[4], yy[4], zz[4]); - glVertex3d(xx[2], yy[2], zz[2]); glVertex3d(xx[4], yy[4], zz[4]); + glVertex3d(xx[0], yy[0], zz[0]); + glVertex3d(xx[1], yy[1], zz[1]); + glVertex3d(xx[1], yy[1], zz[1]); + glVertex3d(xx[2], yy[2], zz[2]); + glVertex3d(xx[3], yy[3], zz[3]); + glVertex3d(xx[2], yy[2], zz[2]); + glVertex3d(xx[0], yy[0], zz[0]); + glVertex3d(xx[3], yy[3], zz[3]); + glVertex3d(xx[0], yy[0], zz[0]); + glVertex3d(xx[4], yy[4], zz[4]); + glVertex3d(xx[1], yy[1], zz[1]); + glVertex3d(xx[4], yy[4], zz[4]); + glVertex3d(xx[3], yy[3], zz[3]); + glVertex3d(xx[4], yy[4], zz[4]); + glVertex3d(xx[2], yy[2], zz[2]); + glVertex3d(xx[4], yy[4], zz[4]); glEnd(); break; } - if(View->Light) glEnable(GL_LIGHTING); + if(View->Light) + glEnable(GL_LIGHTING); } void SaturateValues(int saturate, double min, double max, - double *v1, double *v2, int nbnod){ + double *v1, double *v2, int nbnod) +{ int i; - if(saturate){ - for(i=0;i<nbnod;i++){ - if(v1[i] > max) v2[i] = max; - else if(v1[i] < min) v2[i] = min; - else v2[i] = v1[i]; + if(saturate) { + for(i = 0; i < nbnod; i++) { + if(v1[i] > max) + v2[i] = max; + else if(v1[i] < min) + v2[i] = min; + else + v2[i] = v1[i]; } } - else{ - for(i=0;i<nbnod;i++){ + else { + for(i = 0; i < nbnod; i++) { v2[i] = v1[i]; } } @@ -191,54 +233,60 @@ void SaturateValues(int saturate, double min, double max, // Scalar Elements -void Draw_ScalarPoint(Post_View *View, int preproNormals, - double ValMin, double ValMax, double Raise[3][8], - double *X, double *Y, double *Z, double *V){ - double d; +void Draw_ScalarPoint(Post_View * View, int preproNormals, + double ValMin, double ValMax, double Raise[3][8], + double *X, double *Y, double *Z, double *V) +{ + double d; char Num[100]; - if(View->Boundary > 0) return; + if(View->Boundary > 0) + return; d = V[View->TimeStep]; - if(View->SaturateValues){ - if(d > ValMax) d = ValMax; - else if(d < ValMin) d = ValMin; + if(View->SaturateValues) { + if(d > ValMax) + d = ValMax; + else if(d < ValMin) + d = ValMin; } RaiseFill(0, d, ValMin, Raise); - if(View->ShowElement) Draw_ElementBoundary(POINT,View,X,Y,Z,Raise); + if(View->ShowElement) + Draw_ElementBoundary(POINT, View, X, Y, Z, Raise); - if(d>=ValMin && d<=ValMax){ - Palette2(View,ValMin,ValMax,d); - if(View->IntervalsType == DRAW_POST_NUMERIC){ - glRasterPos3d(X[0]+Raise[0][0], Y[0]+Raise[1][0], Z[0]+Raise[2][0]); + if(d >= ValMin && d <= ValMax) { + Palette2(View, ValMin, ValMax, d); + if(View->IntervalsType == DRAW_POST_NUMERIC) { + glRasterPos3d(X[0] + Raise[0][0], Y[0] + Raise[1][0], + Z[0] + Raise[2][0]); sprintf(Num, View->Format, d); Draw_String(Num); } else - Draw_Point(View->PointType,View->PointSize,X,Y,Z,Raise); + Draw_Point(View->PointType, View->PointSize, X, Y, Z, Raise); } } -void Draw_ScalarLine(Post_View *View, int preproNormals, - double ValMin, double ValMax, double Raise[3][8], - double *X, double *Y, double *Z, double *V){ - - int i,k,nb=0; - double d; - double Xp[5],Yp[5],Zp[5],Val[5],value[5],thev; - char Num[100] ; +void Draw_ScalarLine(Post_View * View, int preproNormals, + double ValMin, double ValMax, double Raise[3][8], + double *X, double *Y, double *Z, double *V) +{ + int i, k, nb = 0; + double d; + double Xp[5], Yp[5], Zp[5], Val[5], value[5], thev; + char Num[100]; - double *vv = &V[2*View->TimeStep]; + double *vv = &V[2 * View->TimeStep]; - if(View->Boundary > 0){ + if(View->Boundary > 0) { View->Boundary--; int ts = View->TimeStep; View->TimeStep = 0; - Draw_ScalarPoint(View, 0, ValMin, ValMax, Raise, &X[0], &Y[0], &Z[0], &vv[0]);//0 - Draw_ScalarPoint(View, 0, ValMin, ValMax, Raise, &X[1], &Y[1], &Z[1], &vv[1]);//1 + Draw_ScalarPoint(View, 0, ValMin, ValMax, Raise, &X[0], &Y[0], &Z[0], &vv[0]); //0 + Draw_ScalarPoint(View, 0, ValMin, ValMax, Raise, &X[1], &Y[1], &Z[1], &vv[1]); //1 View->TimeStep = ts; View->Boundary++; return; @@ -246,70 +294,75 @@ void Draw_ScalarLine(Post_View *View, int preproNormals, SaturateValues(View->SaturateValues, ValMin, ValMax, vv, Val, 2); - for(k=0 ; k<2 ; k++) RaiseFill(k, Val[k], ValMin, Raise); + for(k = 0; k < 2; k++) + RaiseFill(k, Val[k], ValMin, Raise); - if(View->ShowElement) Draw_ElementBoundary(LINE,View,X,Y,Z,Raise); + if(View->ShowElement) + Draw_ElementBoundary(LINE, View, X, Y, Z, Raise); - if(View->IntervalsType == DRAW_POST_NUMERIC){ + if(View->IntervalsType == DRAW_POST_NUMERIC) { - d = (Val[0]+Val[1]) / 2.; + d = (Val[0] + Val[1]) / 2.; - if(d >= ValMin && d <= ValMax){ - Palette2(View,ValMin,ValMax,d); + if(d >= ValMin && d <= ValMax) { + Palette2(View, ValMin, ValMax, d); sprintf(Num, View->Format, d); - glRasterPos3d((X[0]+Raise[0][0] + X[1]+Raise[0][1])/2., - (Y[0]+Raise[1][0] + Y[1]+Raise[1][1])/2., - (Z[0]+Raise[2][0] + Z[1]+Raise[2][1])/2.); + glRasterPos3d((X[0] + Raise[0][0] + X[1] + Raise[0][1]) / 2., + (Y[0] + Raise[1][0] + Y[1] + Raise[1][1]) / 2., + (Z[0] + Raise[2][0] + Z[1] + Raise[2][1]) / 2.); Draw_String(Num); } } - else{ + else { - if(View->IntervalsType==DRAW_POST_CONTINUOUS){ + if(View->IntervalsType == DRAW_POST_CONTINUOUS) { if(Val[0] >= ValMin && Val[0] <= ValMax && - Val[1] >= ValMin && Val[1] <= ValMax){ - if(View->LineType){ - // not perfect... - Palette2(View,ValMin,ValMax,Val[0]); - Draw_Line(View->LineType,View->LineWidth,X,Y,Z,Raise); - } - else{ - glBegin(GL_LINES); - Palette2(View,ValMin,ValMax,Val[0]); - glVertex3d(X[0]+Raise[0][0], Y[0]+Raise[1][0], Z[0]+Raise[2][0]); - Palette2(View,ValMin,ValMax,Val[1]); - glVertex3d(X[1]+Raise[0][1], Y[1]+Raise[1][1], Z[1]+Raise[2][1]); - glEnd(); - } + Val[1] >= ValMin && Val[1] <= ValMax) { + if(View->LineType) { + // not perfect... + Palette2(View, ValMin, ValMax, Val[0]); + Draw_Line(View->LineType, View->LineWidth, X, Y, Z, Raise); + } + else { + glBegin(GL_LINES); + Palette2(View, ValMin, ValMax, Val[0]); + glVertex3d(X[0] + Raise[0][0], Y[0] + Raise[1][0], + Z[0] + Raise[2][0]); + Palette2(View, ValMin, ValMax, Val[1]); + glVertex3d(X[1] + Raise[0][1], Y[1] + Raise[1][1], + Z[1] + Raise[2][1]); + glEnd(); + } } - else{ - //todo + else { + //todo } } - else{ - for(k=0 ; k<View->NbIso ; k++){ - Palette1(View,View->NbIso,k); - if(View->IntervalsType==DRAW_POST_DISCRETE){ - CutLine1D(X,Y,Z,&Val[0], - View->GVFI(ValMin,ValMax,View->NbIso+1,k), - View->GVFI(ValMin,ValMax,View->NbIso+1,k+1), - Xp,Yp,Zp,&nb,value); - if(nb == 2){ - for(i=0;i<2;i++) RaiseFill(i,value[i],ValMin,Raise); - Draw_Line(View->LineType,View->LineWidth,Xp,Yp,Zp,Raise); - } - } - else{ - thev = View->GVFI(ValMin,ValMax,View->NbIso,k); - CutLine0D(X,Y,Z,&Val[0],thev,Xp,Yp,Zp,&nb); - if(nb){ - RaiseFill(0,thev,ValMin,Raise); - Draw_Point(View->PointType,View->PointSize,Xp,Yp,Zp,Raise); - } - } + else { + for(k = 0; k < View->NbIso; k++) { + Palette1(View, View->NbIso, k); + if(View->IntervalsType == DRAW_POST_DISCRETE) { + CutLine1D(X, Y, Z, &Val[0], + View->GVFI(ValMin, ValMax, View->NbIso + 1, k), + View->GVFI(ValMin, ValMax, View->NbIso + 1, k + 1), + Xp, Yp, Zp, &nb, value); + if(nb == 2) { + for(i = 0; i < 2; i++) + RaiseFill(i, value[i], ValMin, Raise); + Draw_Line(View->LineType, View->LineWidth, Xp, Yp, Zp, Raise); + } + } + else { + thev = View->GVFI(ValMin, ValMax, View->NbIso, k); + CutLine0D(X, Y, Z, &Val[0], thev, Xp, Yp, Zp, &nb); + if(nb) { + RaiseFill(0, thev, ValMin, Raise); + Draw_Point(View->PointType, View->PointSize, Xp, Yp, Zp, Raise); + } + } } } @@ -317,26 +370,26 @@ void Draw_ScalarLine(Post_View *View, int preproNormals, } -void Draw_ScalarTriangle(Post_View *View, int preproNormals, - double ValMin, double ValMax, double Raise[3][8], - double *X, double *Y, double *Z, double *V){ - - int i, k, nb=0; - double d; - double x1x0, y1y0, z1z0, x2x0, y2y0, z2z0, nn[3], norms[9]; - double Xp[5],Yp[5],Zp[5],Val[3],value[5],thev; - char Num[100] ; +void Draw_ScalarTriangle(Post_View * View, int preproNormals, + double ValMin, double ValMax, double Raise[3][8], + double *X, double *Y, double *Z, double *V) +{ + int i, k, nb = 0; + double d; + double x1x0, y1y0, z1z0, x2x0, y2y0, z2z0, nn[3], norms[9]; + double Xp[5], Yp[5], Zp[5], Val[3], value[5], thev; + char Num[100]; - double *vv = &V[3*View->TimeStep]; + double *vv = &V[3 * View->TimeStep]; - if(!preproNormals && View->Boundary > 0){ + if(!preproNormals && View->Boundary > 0) { View->Boundary--; int ts = View->TimeStep; View->TimeStep = 0; - Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, &X[0], &Y[0], &Z[0], &vv[0]);//01 - Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, &X[1], &Y[1], &Z[1], &vv[1]);//12 - REORDER2(0,2); - Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val);//02 + Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, &X[0], &Y[0], &Z[0], &vv[0]); //01 + Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, &X[1], &Y[1], &Z[1], &vv[1]); //12 + REORDER2(0, 2); + Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); //02 View->TimeStep = ts; View->Boundary++; return; @@ -344,46 +397,49 @@ void Draw_ScalarTriangle(Post_View *View, int preproNormals, SaturateValues(View->SaturateValues, ValMin, ValMax, vv, Val, 3); - for(k=0 ; k<3 ; k++) RaiseFill(k, Val[k], ValMin, Raise); - - if(View->Light){ - - x1x0 = (X[1]+Raise[0][1]) - (X[0]+Raise[0][0]); - y1y0 = (Y[1]+Raise[1][1]) - (Y[0]+Raise[1][0]); - z1z0 = (Z[1]+Raise[2][1]) - (Z[0]+Raise[2][0]); - x2x0 = (X[2]+Raise[0][2]) - (X[0]+Raise[0][0]); - y2y0 = (Y[2]+Raise[1][2]) - (Y[0]+Raise[1][0]); - z2z0 = (Z[2]+Raise[2][2]) - (Z[0]+Raise[2][0]); - nn[0] = y1y0 * z2z0 - z1z0 * y2y0 ; - nn[1] = z1z0 * x2x0 - x1x0 * z2z0 ; - nn[2] = x1x0 * y2y0 - y1y0 * x2x0 ; - - if(View->SmoothNormals){ - if(preproNormals){ - for(i=0;i<3;i++){ - View->add_normal(X[i]+Raise[0][i],Y[i]+Raise[1][i],Z[i]+Raise[2][i], - nn[0],nn[1],nn[2]); - } - return; + for(k = 0; k < 3; k++) + RaiseFill(k, Val[k], ValMin, Raise); + + if(View->Light) { + + x1x0 = (X[1] + Raise[0][1]) - (X[0] + Raise[0][0]); + y1y0 = (Y[1] + Raise[1][1]) - (Y[0] + Raise[1][0]); + z1z0 = (Z[1] + Raise[2][1]) - (Z[0] + Raise[2][0]); + x2x0 = (X[2] + Raise[0][2]) - (X[0] + Raise[0][0]); + y2y0 = (Y[2] + Raise[1][2]) - (Y[0] + Raise[1][0]); + z2z0 = (Z[2] + Raise[2][2]) - (Z[0] + Raise[2][0]); + nn[0] = y1y0 * z2z0 - z1z0 * y2y0; + nn[1] = z1z0 * x2x0 - x1x0 * z2z0; + nn[2] = x1x0 * y2y0 - y1y0 * x2x0; + + if(View->SmoothNormals) { + if(preproNormals) { + for(i = 0; i < 3; i++) { + View->add_normal(X[i] + Raise[0][i], Y[i] + Raise[1][i], + Z[i] + Raise[2][i], nn[0], nn[1], nn[2]); + } + return; } - else{ - for(i=0;i<3;i++){ - norms[3*i] = nn[0]; - norms[3*i+1] = nn[1]; - norms[3*i+2] = nn[2]; - if(!View->get_normal(X[i]+Raise[0][i],Y[i]+Raise[1][i],Z[i]+Raise[2][i], - norms[3*i],norms[3*i+1],norms[3*i+2])){ - //don't print this (unless we fix draw_vector_triangle with displacement) - //Msg(WARNING, "Oups, did not find smoothed normal"); - } - } + else { + for(i = 0; i < 3; i++) { + norms[3 * i] = nn[0]; + norms[3 * i + 1] = nn[1]; + norms[3 * i + 2] = nn[2]; + if(!View-> + get_normal(X[i] + Raise[0][i], Y[i] + Raise[1][i], + Z[i] + Raise[2][i], norms[3 * i], norms[3 * i + 1], + norms[3 * i + 2])) { + //don't print this (unless we fix draw_vector_triangle with displacement) + //Msg(WARNING, "Oups, did not find smoothed normal"); + } + } } } - else{ - for(i=0;i<3;i++){ - norms[3*i] = nn[0]; - norms[3*i+1] = nn[1]; - norms[3*i+2] = nn[2]; + else { + for(i = 0; i < 3; i++) { + norms[3 * i] = nn[0]; + norms[3 * i + 1] = nn[1]; + norms[3 * i + 2] = nn[2]; } } //norme(norms); not necessary since GL_NORMALIZE is enabled @@ -392,109 +448,122 @@ void Draw_ScalarTriangle(Post_View *View, int preproNormals, glNormal3dv(norms); } - if(preproNormals) return; + if(preproNormals) + return; - if(View->ShowElement) Draw_ElementBoundary(TRIANGLE,View,X,Y,Z,Raise); + if(View->ShowElement) + Draw_ElementBoundary(TRIANGLE, View, X, Y, Z, Raise); - if(View->IntervalsType == DRAW_POST_NUMERIC){ + if(View->IntervalsType == DRAW_POST_NUMERIC) { - d = (Val[0]+Val[1]+Val[2]) / 3.; - if(d >= ValMin && d <= ValMax){ - Palette2(View,ValMin,ValMax,d); + d = (Val[0] + Val[1] + Val[2]) / 3.; + if(d >= ValMin && d <= ValMax) { + Palette2(View, ValMin, ValMax, d); sprintf(Num, View->Format, d); - glRasterPos3d( (X[0]+Raise[0][0] + X[1]+Raise[0][1] + X[2]+Raise[0][2])/3., - (Y[0]+Raise[1][0] + Y[1]+Raise[1][1] + Y[2]+Raise[1][2])/3., - (Z[0]+Raise[2][0] + Z[1]+Raise[2][1] + Z[2]+Raise[2][2])/3.); + glRasterPos3d((X[0] + Raise[0][0] + X[1] + Raise[0][1] + X[2] + + Raise[0][2]) / 3., + (Y[0] + Raise[1][0] + Y[1] + Raise[1][1] + Y[2] + + Raise[1][2]) / 3., + (Z[0] + Raise[2][0] + Z[1] + Raise[2][1] + Z[2] + + Raise[2][2]) / 3.); Draw_String(Num); } } - else{ - - if(View->IntervalsType == DRAW_POST_CONTINUOUS){ + else { + + if(View->IntervalsType == DRAW_POST_CONTINUOUS) { if(Val[0] >= ValMin && Val[0] <= ValMax && Val[1] >= ValMin && Val[1] <= ValMax && - Val[2] >= ValMin && Val[2] <= ValMax){ + Val[2] >= ValMin && Val[2] <= ValMax) { glBegin(GL_TRIANGLES); - Palette2(View,ValMin,ValMax,Val[0]); - glNormal3dv(&norms[0]); - glVertex3d(X[0]+Raise[0][0], Y[0]+Raise[1][0], Z[0]+Raise[2][0]); - Palette2(View,ValMin,ValMax,Val[1]); - glNormal3dv(&norms[3]); - glVertex3d(X[1]+Raise[0][1], Y[1]+Raise[1][1], Z[1]+Raise[2][1]); - Palette2(View,ValMin,ValMax,Val[2]); - glNormal3dv(&norms[6]); - glVertex3d(X[2]+Raise[0][2], Y[2]+Raise[1][2], Z[2]+Raise[2][2]); + Palette2(View, ValMin, ValMax, Val[0]); + glNormal3dv(&norms[0]); + glVertex3d(X[0] + Raise[0][0], Y[0] + Raise[1][0], + Z[0] + Raise[2][0]); + Palette2(View, ValMin, ValMax, Val[1]); + glNormal3dv(&norms[3]); + glVertex3d(X[1] + Raise[0][1], Y[1] + Raise[1][1], + Z[1] + Raise[2][1]); + Palette2(View, ValMin, ValMax, Val[2]); + glNormal3dv(&norms[6]); + glVertex3d(X[2] + Raise[0][2], Y[2] + Raise[1][2], + Z[2] + Raise[2][2]); glEnd(); } - else{ - CutTriangle2D(X,Y,Z,Val,ValMin,ValMax, - Xp,Yp,Zp,&nb,value); - if(nb >= 3){ + else { + CutTriangle2D(X, Y, Z, Val, ValMin, ValMax, Xp, Yp, Zp, &nb, value); + if(nb >= 3) { glBegin(GL_POLYGON); - for(i=0 ; i<nb ; i++){ - Palette2(View,ValMin,ValMax,value[i]); - RaiseFill(i,value[i],ValMin,Raise); - glVertex3d(Xp[i]+Raise[0][i], Yp[i]+Raise[1][i], Zp[i]+Raise[2][i]); + for(i = 0; i < nb; i++) { + Palette2(View, ValMin, ValMax, value[i]); + RaiseFill(i, value[i], ValMin, Raise); + glVertex3d(Xp[i] + Raise[0][i], Yp[i] + Raise[1][i], + Zp[i] + Raise[2][i]); } glEnd(); } } } - else{ - for(k=0 ; k<View->NbIso ; k++){ - if(View->IntervalsType == DRAW_POST_DISCRETE){ - Palette1(View,View->NbIso,k); - CutTriangle2D(X,Y,Z,Val, - View->GVFI(ValMin,ValMax,View->NbIso+1,k), - View->GVFI(ValMin,ValMax,View->NbIso+1,k+1), - Xp,Yp,Zp,&nb,value); - if(nb >= 3){ - for(i=0 ; i<nb ; i++) RaiseFill(i,value[i],ValMin,Raise); - glBegin(GL_POLYGON); - for(i=0;i<nb;i++) glVertex3d(Xp[i]+Raise[0][i], - Yp[i]+Raise[1][i], - Zp[i]+Raise[2][i]); - glEnd(); + else { + for(k = 0; k < View->NbIso; k++) { + if(View->IntervalsType == DRAW_POST_DISCRETE) { + Palette1(View, View->NbIso, k); + CutTriangle2D(X, Y, Z, Val, + View->GVFI(ValMin, ValMax, View->NbIso + 1, k), + View->GVFI(ValMin, ValMax, View->NbIso + 1, k + 1), + Xp, Yp, Zp, &nb, value); + if(nb >= 3) { + for(i = 0; i < nb; i++) + RaiseFill(i, value[i], ValMin, Raise); + glBegin(GL_POLYGON); + for(i = 0; i < nb; i++) + glVertex3d(Xp[i] + Raise[0][i], + Yp[i] + Raise[1][i], Zp[i] + Raise[2][i]); + glEnd(); } } - else{ - Palette1(View,View->NbIso,k); - thev = View->GVFI(ValMin,ValMax,View->NbIso,k); - CutTriangle1D(X,Y,Z,Val,thev,Xp,Yp,Zp,&nb); - if(nb == 2){ - for(i=0 ; i<2 ; i++) RaiseFill(i,thev,ValMin,Raise); - Draw_Line(View->LineType,View->LineWidth,Xp,Yp,Zp,Raise); + else { + Palette1(View, View->NbIso, k); + thev = View->GVFI(ValMin, ValMax, View->NbIso, k); + CutTriangle1D(X, Y, Z, Val, thev, Xp, Yp, Zp, &nb); + if(nb == 2) { + for(i = 0; i < 2; i++) + RaiseFill(i, thev, ValMin, Raise); + Draw_Line(View->LineType, View->LineWidth, Xp, Yp, Zp, Raise); } } } } } - -} -void Draw_ScalarTetrahedron(Post_View *View, int preproNormals, - double ValMin, double ValMax, double Raise[3][8], - double *X, double *Y, double *Z, double *V){ +} - int k; - double d, Xp[4], Yp[4], Zp[4]; +void Draw_ScalarTetrahedron(Post_View * View, int preproNormals, + double ValMin, double ValMax, double Raise[3][8], + double *X, double *Y, double *Z, double *V) +{ + int k; + double d, Xp[4], Yp[4], Zp[4]; char Num[100]; double Val[4]; - double *vv = &V[4*View->TimeStep]; + double *vv = &V[4 * View->TimeStep]; - if(!preproNormals && View->Boundary > 0){ + if(!preproNormals && View->Boundary > 0) { View->Boundary--; int ts = View->TimeStep; View->TimeStep = 0; - Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, &X[0], &Y[0], &Z[0], &vv[0]);//012 - Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, &X[1], &Y[1], &Z[1], &vv[1]);//123 - REORDER3(0,1,3); - Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val);//013 - Xp[1] = X[2]; Yp[1] = Y[2]; Zp[1] = Z[2]; Val[1] = vv[2]; - Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val);//023 + Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, &X[0], &Y[0], &Z[0], &vv[0]); //012 + Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, &X[1], &Y[1], &Z[1], &vv[1]); //123 + REORDER3(0, 1, 3); + Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); //013 + Xp[1] = X[2]; + Yp[1] = Y[2]; + Zp[1] = Z[2]; + Val[1] = vv[2]; + Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); //023 View->TimeStep = ts; View->Boundary++; return; @@ -502,166 +571,185 @@ void Draw_ScalarTetrahedron(Post_View *View, int preproNormals, SaturateValues(View->SaturateValues, ValMin, ValMax, vv, Val, 4); - for(k=0 ; k<4 ; k++) RaiseFill(k, Val[k], ValMin, Raise); + for(k = 0; k < 4; k++) + RaiseFill(k, Val[k], ValMin, Raise); - if(!preproNormals && View->ShowElement) Draw_ElementBoundary(TETRAHEDRON,View,X,Y,Z,Raise); + if(!preproNormals && View->ShowElement) + Draw_ElementBoundary(TETRAHEDRON, View, X, Y, Z, Raise); - if(!preproNormals && View->IntervalsType == DRAW_POST_NUMERIC){ + if(!preproNormals && View->IntervalsType == DRAW_POST_NUMERIC) { - d = 0.25 * (Val[0] +Val[1]+Val[2] + Val[3]); - if(d >= ValMin && d <= ValMax){ - Palette2(View,ValMin,ValMax,d); + d = 0.25 * (Val[0] + Val[1] + Val[2] + Val[3]); + if(d >= ValMin && d <= ValMax) { + Palette2(View, ValMin, ValMax, d); sprintf(Num, View->Format, d); - glRasterPos3d(0.25 * (X[0]+Raise[0][0] + X[1]+Raise[0][1] + - X[2]+Raise[0][2] + X[3]+Raise[0][3]), - 0.25 * (Y[0]+Raise[1][0] + Y[1]+Raise[1][1] + - Y[2]+Raise[1][2] + Y[3]+Raise[1][3]), - 0.25 * (Z[0]+Raise[2][0] + Z[1]+Raise[2][1] + - Z[2]+Raise[2][2] + Z[3]+Raise[2][3])); + glRasterPos3d(0.25 * (X[0] + Raise[0][0] + X[1] + Raise[0][1] + + X[2] + Raise[0][2] + X[3] + Raise[0][3]), + 0.25 * (Y[0] + Raise[1][0] + Y[1] + Raise[1][1] + + Y[2] + Raise[1][2] + Y[3] + Raise[1][3]), + 0.25 * (Z[0] + Raise[2][0] + Z[1] + Raise[2][1] + + Z[2] + Raise[2][2] + Z[3] + Raise[2][3])); Draw_String(Num); } } - else{ - for(k=0 ; k<View->NbIso ; k++){ - if(!preproNormals) Palette1(View,View->NbIso,k); + else { + for(k = 0; k < View->NbIso; k++) { + if(!preproNormals) + Palette1(View, View->NbIso, k); IsoSimplex(View, preproNormals, X, Y, Z, Val, - View->GVFI(ValMin,ValMax,View->NbIso,k), Raise); + View->GVFI(ValMin, ValMax, View->NbIso, k), Raise); } } } -void Draw_ScalarQuadrangle(Post_View *View, int preproNormals, - double ValMin, double ValMax, double Raise[3][8], - double *X, double *Y, double *Z, double *V){ - int k, ts, show=0; - double Val[4],Xp[4],Yp[4],Zp[4]; - double *vv = &V[4*View->TimeStep]; +void Draw_ScalarQuadrangle(Post_View * View, int preproNormals, + double ValMin, double ValMax, double Raise[3][8], + double *X, double *Y, double *Z, double *V) +{ + int k, ts, show = 0; + double Val[4], Xp[4], Yp[4], Zp[4]; + double *vv = &V[4 * View->TimeStep]; - ts = View->TimeStep; View->TimeStep = 0; + ts = View->TimeStep; + View->TimeStep = 0; - if(!preproNormals && View->Boundary > 0){ + if(!preproNormals && View->Boundary > 0) { View->Boundary--; - Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, &X[0], &Y[0], &Z[0], &vv[0]);//01 - Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, &X[1], &Y[1], &Z[1], &vv[1]);//12 - Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, &X[2], &Y[2], &Z[2], &vv[2]);//23 - REORDER2(0,3); - Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val);//03 + Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, &X[0], &Y[0], &Z[0], &vv[0]); //01 + Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, &X[1], &Y[1], &Z[1], &vv[1]); //12 + Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, &X[2], &Y[2], &Z[2], &vv[2]); //23 + REORDER2(0, 3); + Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); //03 View->TimeStep = ts; View->Boundary++; return; } - show = View->ShowElement; View->ShowElement = 0; + show = View->ShowElement; + View->ShowElement = 0; - if(!preproNormals && show){ + if(!preproNormals && show) { SaturateValues(View->SaturateValues, ValMin, ValMax, vv, Val, 4); - for(k=0 ; k<4 ; k++) RaiseFill(k, Val[k], ValMin, Raise); - Draw_ElementBoundary(QUADRANGLE,View,X,Y,Z,Raise); + for(k = 0; k < 4; k++) + RaiseFill(k, Val[k], ValMin, Raise); + Draw_ElementBoundary(QUADRANGLE, View, X, Y, Z, Raise); } Draw_ScalarTriangle(View, preproNormals, ValMin, ValMax, Raise, X, Y, Z, vv); //012 - REORDER3(0,2,3); - Draw_ScalarTriangle(View, preproNormals, ValMin, ValMax, Raise, Xp,Yp,Zp,Val); //023 + REORDER3(0, 2, 3); + Draw_ScalarTriangle(View, preproNormals, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); //023 View->TimeStep = ts; View->ShowElement = show; } -void Draw_ScalarHexahedron(Post_View *View, int preproNormals, - double ValMin, double ValMax, double Raise[3][8], - double *X, double *Y, double *Z, double *V){ - int k, ts, show=0; - double Val[8],Xp[8],Yp[8],Zp[8]; - double *vv = &V[8*View->TimeStep]; +void Draw_ScalarHexahedron(Post_View * View, int preproNormals, + double ValMin, double ValMax, double Raise[3][8], + double *X, double *Y, double *Z, double *V) +{ + int k, ts, show = 0; + double Val[8], Xp[8], Yp[8], Zp[8]; + double *vv = &V[8 * View->TimeStep]; - ts = View->TimeStep; View->TimeStep = 0; + ts = View->TimeStep; + View->TimeStep = 0; - if(!preproNormals && View->Boundary > 0){ + if(!preproNormals && View->Boundary > 0) { View->Boundary--; - REORDER4(0,1,5,4); - Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val);//0154 - REORDER4(0,3,2,1); - Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val);//0321 - REORDER4(0,4,7,3); - Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val);//0473 - REORDER4(1,2,6,5); - Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val);//1265 - REORDER4(2,3,7,6); - Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val);//2376 - Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, &X[4], &Y[4], &Z[4], &vv[4]);//4567 + REORDER4(0, 1, 5, 4); + Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); //0154 + REORDER4(0, 3, 2, 1); + Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); //0321 + REORDER4(0, 4, 7, 3); + Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); //0473 + REORDER4(1, 2, 6, 5); + Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); //1265 + REORDER4(2, 3, 7, 6); + Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); //2376 + Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, &X[4], &Y[4], &Z[4], &vv[4]); //4567 View->TimeStep = ts; View->Boundary++; return; } - show = View->ShowElement; View->ShowElement = 0; + show = View->ShowElement; + View->ShowElement = 0; - if(!preproNormals && show){ + if(!preproNormals && show) { SaturateValues(View->SaturateValues, ValMin, ValMax, vv, Val, 8); - for(k=0 ; k<8 ; k++) RaiseFill(k, Val[k], ValMin, Raise); - Draw_ElementBoundary(HEXAHEDRON,View,X,Y,Z,Raise); + for(k = 0; k < 8; k++) + RaiseFill(k, Val[k], ValMin, Raise); + Draw_ElementBoundary(HEXAHEDRON, View, X, Y, Z, Raise); } - REORDER6(0,1,3, 4,5,7); - Draw_ScalarPrism(View, preproNormals, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); - REORDER6(1,2,3, 5,6,7); - Draw_ScalarPrism(View, preproNormals, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); + REORDER6(0, 1, 3, 4, 5, 7); + Draw_ScalarPrism(View, preproNormals, ValMin, ValMax, Raise, Xp, Yp, Zp, + Val); + REORDER6(1, 2, 3, 5, 6, 7); + Draw_ScalarPrism(View, preproNormals, ValMin, ValMax, Raise, Xp, Yp, Zp, + Val); View->TimeStep = ts; View->ShowElement = show; } -void Draw_ScalarPrism(Post_View *View, int preproNormals, - double ValMin, double ValMax, double Raise[3][8], - double *X, double *Y, double *Z, double *V){ - int k, ts, show=0; - double Val[6],Xp[6],Yp[6],Zp[6]; - double *vv = &V[6*View->TimeStep]; +void Draw_ScalarPrism(Post_View * View, int preproNormals, + double ValMin, double ValMax, double Raise[3][8], + double *X, double *Y, double *Z, double *V) +{ + int k, ts, show = 0; + double Val[6], Xp[6], Yp[6], Zp[6]; + double *vv = &V[6 * View->TimeStep]; - ts = View->TimeStep; View->TimeStep = 0; + ts = View->TimeStep; + View->TimeStep = 0; - if(!preproNormals && View->Boundary > 0){ + if(!preproNormals && View->Boundary > 0) { View->Boundary--; - REORDER4(0,1,4,3); + REORDER4(0, 1, 4, 3); Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); - REORDER3(0,2,1); + REORDER3(0, 2, 1); Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); - REORDER4(0,3,5,2); + REORDER4(0, 3, 5, 2); Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); - REORDER4(1,2,5,4); + REORDER4(1, 2, 5, 4); Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); - Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, &X[3], &Y[3], &Z[3], &V[3]); + Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, &X[3], &Y[3], &Z[3], + &V[3]); View->TimeStep = ts; View->Boundary++; return; } - show = View->ShowElement; View->ShowElement = 0; + show = View->ShowElement; + View->ShowElement = 0; - if(!preproNormals && show){ + if(!preproNormals && show) { SaturateValues(View->SaturateValues, ValMin, ValMax, vv, Val, 6); - for(k=0 ; k<6 ; k++) RaiseFill(k, Val[k], ValMin, Raise); - Draw_ElementBoundary(PRISM,View,X,Y,Z,Raise); + for(k = 0; k < 6; k++) + RaiseFill(k, Val[k], ValMin, Raise); + Draw_ElementBoundary(PRISM, View, X, Y, Z, Raise); } - Draw_ScalarTetrahedron(View, 0, ValMin, ValMax, Raise, &X[0], &Y[0], &Z[0], &V[0]);//0123 - REORDER4(3,4,5,2); - Draw_ScalarTetrahedron(View, preproNormals, ValMin, ValMax, Raise, Xp, Yp, Zp, Val);//3452 - REORDER4(1,2,4,3); - Draw_ScalarTetrahedron(View, preproNormals, ValMin, ValMax, Raise, Xp, Yp, Zp, Val);//1243 + Draw_ScalarTetrahedron(View, 0, ValMin, ValMax, Raise, &X[0], &Y[0], &Z[0], &V[0]); //0123 + REORDER4(3, 4, 5, 2); + Draw_ScalarTetrahedron(View, preproNormals, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); //3452 + REORDER4(1, 2, 4, 3); + Draw_ScalarTetrahedron(View, preproNormals, ValMin, ValMax, Raise, Xp, Yp, Zp, Val); //1243 View->TimeStep = ts; View->ShowElement = show; } -void Draw_ScalarPyramid(Post_View *View, int preproNormals, - double ValMin, double ValMax, double Raise[3][8], - double *X, double *Y, double *Z, double *V){ - static int error=0 ; - if(!error){ +void Draw_ScalarPyramid(Post_View * View, int preproNormals, + double ValMin, double ValMax, double Raise[3][8], + double *X, double *Y, double *Z, double *V) +{ + static int error = 0; + if(!error) { error = 1; Msg(WARNING, "Pyramid drawing not implemented yet..."); } @@ -669,37 +757,57 @@ void Draw_ScalarPyramid(Post_View *View, int preproNormals, // Vector Elements -void Draw_VectorElement(int type, Post_View *View, - double ValMin, double ValMax, double Raise[3][8], - double *X, double *Y, double *Z, double *V){ - int j, k, nbnod=0 ; - double fact, xx[8], yy[8], zz[8], xc=0., yc=0., zc=0., Val[8][3], d[8]; - double dx=0., dy=0., dz=0., dd; - char Num[100]; - - switch(type){ - case POINT : nbnod = 1; break; - case LINE : nbnod = 2; break; - case TRIANGLE : nbnod = 3; break; - case QUADRANGLE : nbnod = 4; break; - case TETRAHEDRON : nbnod = 4; break; - case HEXAHEDRON : nbnod = 8; break; - case PRISM : nbnod = 6; break; - case PYRAMID : nbnod = 5; break; +void Draw_VectorElement(int type, Post_View * View, + double ValMin, double ValMax, double Raise[3][8], + double *X, double *Y, double *Z, double *V) +{ + int j, k, nbnod = 0; + double fact, xx[8], yy[8], zz[8], xc = 0., yc = 0., zc = + 0., Val[8][3], d[8]; + double dx = 0., dy = 0., dz = 0., dd; + char Num[100]; + + switch (type) { + case POINT: + nbnod = 1; + break; + case LINE: + nbnod = 2; + break; + case TRIANGLE: + nbnod = 3; + break; + case QUADRANGLE: + nbnod = 4; + break; + case TETRAHEDRON: + nbnod = 4; + break; + case HEXAHEDRON: + nbnod = 8; + break; + case PRISM: + nbnod = 6; + break; + case PYRAMID: + nbnod = 5; + break; } - for(k=0 ; k<nbnod ; k++){ - Val[k][0] = V[3*nbnod*View->TimeStep+3*k] ; - Val[k][1] = V[3*nbnod*View->TimeStep+3*k+1] ; - Val[k][2] = V[3*nbnod*View->TimeStep+3*k+2] ; - d[k] = sqrt(Val[k][0]*Val[k][0]+Val[k][1]*Val[k][1]+Val[k][2]*Val[k][2]); + for(k = 0; k < nbnod; k++) { + Val[k][0] = V[3 * nbnod * View->TimeStep + 3 * k]; + Val[k][1] = V[3 * nbnod * View->TimeStep + 3 * k + 1]; + Val[k][2] = V[3 * nbnod * View->TimeStep + 3 * k + 2]; + d[k] = + sqrt(Val[k][0] * Val[k][0] + Val[k][1] * Val[k][1] + + Val[k][2] * Val[k][2]); RaiseFill(k, d[k], ValMin, Raise); } - if(View->ArrowType == DRAW_POST_DISPLACEMENT){ + if(View->ArrowType == DRAW_POST_DISPLACEMENT) { - fact = View->ArrowScale/50. ; - for(k=0 ; k<nbnod ; k++){ + fact = View->ArrowScale / 50.; + for(k = 0; k < nbnod; k++) { xx[k] = X[k] + fact * Val[k][0] + Raise[0][k]; yy[k] = Y[k] + fact * Val[k][1] + Raise[1][k]; zz[k] = Z[k] + fact * Val[k][2] + Raise[2][k]; @@ -707,101 +815,144 @@ void Draw_VectorElement(int type, Post_View *View, int ts = View->TimeStep; View->TimeStep = 0; - switch(type){ + switch (type) { case POINT: Draw_ScalarPoint(View, 0, ValMin, ValMax, Raise, xx, yy, zz, d); - if(ts){//draw trajectory - if(View->LineType){ - double dx2, dy2, dz2, XX[2], YY[2], ZZ[2]; - for(j=0 ; j<ts ; j++){ - dx = V[3*(ts-j)]; dy = V[3*(ts-j)+1]; dz = V[3*(ts-j)+2]; - dx2 = V[3*(ts-j-1)]; dy2 = V[3*(ts-j-1)+1]; dz2 = V[3*(ts-j-1)+2]; - dd = sqrt(dx*dx+dy*dy+dz*dz); - // not perfect... - Palette2(View,ValMin,ValMax,dd); - XX[0] = X[0] + fact*dx; XX[1] = X[1] + fact*dx2; - YY[0] = Y[0] + fact*dy; YY[1] = Y[1] + fact*dy2; - ZZ[0] = Z[0] + fact*dz; ZZ[1] = Z[1] + fact*dz2; - Draw_Line(View->LineType,View->LineWidth,XX,YY,ZZ,Raise); - } - } - else{ - glBegin(GL_LINE_STRIP); - for(j=0 ; j<ts+1 ; j++){ - dx = V[3*(ts-j)]; dy = V[3*(ts-j)+1]; dz = V[3*(ts-j)+2]; - dd = sqrt(dx*dx+dy*dy+dz*dz); - Palette2(View,ValMin,ValMax,dd); - glVertex3d(X[0] + fact*dx + Raise[0][0], - Y[0] + fact*dy + Raise[1][0], - Z[0] + fact*dz + Raise[2][0]); - } - glEnd(); - } + if(ts) { //draw trajectory + if(View->LineType) { + double dx2, dy2, dz2, XX[2], YY[2], ZZ[2]; + for(j = 0; j < ts; j++) { + dx = V[3 * (ts - j)]; + dy = V[3 * (ts - j) + 1]; + dz = V[3 * (ts - j) + 2]; + dx2 = V[3 * (ts - j - 1)]; + dy2 = V[3 * (ts - j - 1) + 1]; + dz2 = V[3 * (ts - j - 1) + 2]; + dd = sqrt(dx * dx + dy * dy + dz * dz); + // not perfect... + Palette2(View, ValMin, ValMax, dd); + XX[0] = X[0] + fact * dx; + XX[1] = X[1] + fact * dx2; + YY[0] = Y[0] + fact * dy; + YY[1] = Y[1] + fact * dy2; + ZZ[0] = Z[0] + fact * dz; + ZZ[1] = Z[1] + fact * dz2; + Draw_Line(View->LineType, View->LineWidth, XX, YY, ZZ, Raise); + } + } + else { + glBegin(GL_LINE_STRIP); + for(j = 0; j < ts + 1; j++) { + dx = V[3 * (ts - j)]; + dy = V[3 * (ts - j) + 1]; + dz = V[3 * (ts - j) + 2]; + dd = sqrt(dx * dx + dy * dy + dz * dz); + Palette2(View, ValMin, ValMax, dd); + glVertex3d(X[0] + fact * dx + Raise[0][0], + Y[0] + fact * dy + Raise[1][0], + Z[0] + fact * dz + Raise[2][0]); + } + glEnd(); + } } break; - case LINE: Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, xx, yy, zz, d); break; - case TRIANGLE: Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, xx, yy, zz, d); break; - case TETRAHEDRON: Draw_ScalarTetrahedron(View, 0, ValMin, ValMax, Raise, xx, yy, zz, d); break; - case QUADRANGLE: Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, xx, yy, zz, d); break; - case HEXAHEDRON: Draw_ScalarHexahedron(View, 0, ValMin, ValMax, Raise, xx, yy, zz, d); break; - case PRISM: Draw_ScalarPrism(View, 0, ValMin, ValMax, Raise, xx, yy, zz, d); break; - case PYRAMID: Draw_ScalarPyramid(View, 0, ValMin, ValMax, Raise, xx, yy, zz, d); break; + case LINE: + Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, xx, yy, zz, d); + break; + case TRIANGLE: + Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, xx, yy, zz, d); + break; + case TETRAHEDRON: + Draw_ScalarTetrahedron(View, 0, ValMin, ValMax, Raise, xx, yy, zz, d); + break; + case QUADRANGLE: + Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, xx, yy, zz, d); + break; + case HEXAHEDRON: + Draw_ScalarHexahedron(View, 0, ValMin, ValMax, Raise, xx, yy, zz, d); + break; + case PRISM: + Draw_ScalarPrism(View, 0, ValMin, ValMax, Raise, xx, yy, zz, d); + break; + case PYRAMID: + Draw_ScalarPyramid(View, 0, ValMin, ValMax, Raise, xx, yy, zz, d); + break; } View->TimeStep = ts; return; } - if(View->ShowElement) Draw_ElementBoundary(type,View,X,Y,Z,Raise); + if(View->ShowElement) + Draw_ElementBoundary(type, View, X, Y, Z, Raise); if(View->ArrowLocation == DRAW_POST_LOCATE_COG || - View->IntervalsType == DRAW_POST_NUMERIC){ - for(k = 0 ; k<nbnod ; k++){ - dx += Val[k][0]; xc += X[k] + Raise[0][k]; - dy += Val[k][1]; yc += Y[k] + Raise[1][k]; - dz += Val[k][2]; zc += Z[k] + Raise[2][k]; + View->IntervalsType == DRAW_POST_NUMERIC) { + for(k = 0; k < nbnod; k++) { + dx += Val[k][0]; + xc += X[k] + Raise[0][k]; + dy += Val[k][1]; + yc += Y[k] + Raise[1][k]; + dz += Val[k][2]; + zc += Z[k] + Raise[2][k]; } - dx /= (double)nbnod; xc /= (double)nbnod; - dy /= (double)nbnod; yc /= (double)nbnod; - dz /= (double)nbnod; zc /= (double)nbnod; - dd = sqrt(dx*dx+dy*dy+dz*dz); + dx /= (double)nbnod; + xc /= (double)nbnod; + dy /= (double)nbnod; + yc /= (double)nbnod; + dz /= (double)nbnod; + zc /= (double)nbnod; + dd = sqrt(dx * dx + dy * dy + dz * dz); // allow for some roundoff error due to the computation at the barycenter - if(dd!=0.0 && dd>=ValMin*(1.-1.e-15) && dd<=ValMax*(1.+1.e-15)){ - Palette1(View,View->NbIso,View->GIFV(ValMin,ValMax,View->NbIso,dd)); - if(View->IntervalsType == DRAW_POST_NUMERIC){ - glRasterPos3d(xc, yc, zc); - sprintf(Num, View->Format, dd); - Draw_String(Num); + if(dd != 0.0 && dd >= ValMin * (1. - 1.e-15) + && dd <= ValMax * (1. + 1.e-15)) { + Palette1(View, View->NbIso, + View->GIFV(ValMin, ValMax, View->NbIso, dd)); + if(View->IntervalsType == DRAW_POST_NUMERIC) { + glRasterPos3d(xc, yc, zc); + sprintf(Num, View->Format, dd); + Draw_String(Num); } - else{ - fact = CTX.pixel_equiv_x/CTX.s[0] * View->ArrowScale/ValMax ; - if(View->ScaleType == DRAW_POST_LOGARITHMIC && ValMin>0){ - dx /= dd ; dy /= dd ; dz /= dd ; - dd = log10(dd/ValMin) ; - dx *= dd ; dy *= dd ; dz *= dd ; - } - RaiseFill(0, dd, ValMin, Raise); - Draw_Vector(View->ArrowType, View->IntervalsType!=DRAW_POST_ISO, - xc, yc, zc, fact*dd, fact*dx, fact*dy, fact*dz, Raise); + else { + fact = CTX.pixel_equiv_x / CTX.s[0] * View->ArrowScale / ValMax; + if(View->ScaleType == DRAW_POST_LOGARITHMIC && ValMin > 0) { + dx /= dd; + dy /= dd; + dz /= dd; + dd = log10(dd / ValMin); + dx *= dd; + dy *= dd; + dz *= dd; + } + RaiseFill(0, dd, ValMin, Raise); + Draw_Vector(View->ArrowType, View->IntervalsType != DRAW_POST_ISO, + xc, yc, zc, fact * dd, fact * dx, fact * dy, fact * dz, + Raise); } } } - else{ - for(k=0 ; k<nbnod ; k++){ - if(d[k]!=0.0 && d[k]>=ValMin && d[k]<=ValMax){ - Palette1(View,View->NbIso,View->GIFV(ValMin,ValMax,View->NbIso,d[k])); - fact = CTX.pixel_equiv_x/CTX.s[0] * View->ArrowScale/ValMax ; - if(View->ScaleType == DRAW_POST_LOGARITHMIC && ValMin>0){ - Val[k][0] /= d[k] ; Val[k][1] /= d[k] ; Val[k][2] /= d[k] ; - d[k] = log10(d[k]/ValMin) ; - Val[k][0] *= d[k] ; Val[k][1] *= d[k] ; Val[k][2] *= d[k] ; - } - RaiseFill(0, d[k], ValMin, Raise); - Draw_Vector(View->ArrowType, View->IntervalsType!=DRAW_POST_ISO, - X[k], Y[k], Z[k], - fact*d[k], fact*Val[k][0], fact*Val[k][1], fact*Val[k][2], Raise); - } - } + else { + for(k = 0; k < nbnod; k++) { + if(d[k] != 0.0 && d[k] >= ValMin && d[k] <= ValMax) { + Palette1(View, View->NbIso, + View->GIFV(ValMin, ValMax, View->NbIso, d[k])); + fact = CTX.pixel_equiv_x / CTX.s[0] * View->ArrowScale / ValMax; + if(View->ScaleType == DRAW_POST_LOGARITHMIC && ValMin > 0) { + Val[k][0] /= d[k]; + Val[k][1] /= d[k]; + Val[k][2] /= d[k]; + d[k] = log10(d[k] / ValMin); + Val[k][0] *= d[k]; + Val[k][1] *= d[k]; + Val[k][2] *= d[k]; + } + RaiseFill(0, d[k], ValMin, Raise); + Draw_Vector(View->ArrowType, View->IntervalsType != DRAW_POST_ISO, + X[k], Y[k], Z[k], + fact * d[k], fact * Val[k][0], fact * Val[k][1], + fact * Val[k][2], Raise); + } + } } } @@ -810,77 +961,137 @@ void Draw_VectorElement(int type, Post_View *View, double ValMin, double ValMax, double Raise[3][8], \ double *X, double *Y, double *Z, double *V -void Draw_VectorPoint(ARGS){ - Draw_VectorElement(POINT, View, ValMin, ValMax, Raise, X, Y, Z, V); } -void Draw_VectorLine(ARGS){ - Draw_VectorElement(LINE, View, ValMin, ValMax, Raise, X, Y, Z, V); } -void Draw_VectorTriangle(ARGS){ - Draw_VectorElement(TRIANGLE, View, ValMin, ValMax, Raise, X, Y, Z, V); } -void Draw_VectorTetrahedron(ARGS){ - Draw_VectorElement(TETRAHEDRON, View, ValMin, ValMax, Raise, X, Y, Z, V); } -void Draw_VectorQuadrangle(ARGS){ - Draw_VectorElement(QUADRANGLE, View, ValMin, ValMax, Raise, X, Y, Z, V); } -void Draw_VectorHexahedron(ARGS){ - Draw_VectorElement(HEXAHEDRON, View, ValMin, ValMax, Raise, X, Y, Z, V); } -void Draw_VectorPrism(ARGS){ - Draw_VectorElement(PRISM, View, ValMin, ValMax, Raise, X, Y, Z, V); } -void Draw_VectorPyramid(ARGS){ - Draw_VectorElement(PYRAMID, View, ValMin, ValMax, Raise, X, Y, Z, V); } +void Draw_VectorPoint(ARGS) +{ + Draw_VectorElement(POINT, View, ValMin, ValMax, Raise, X, Y, Z, V); +} + +void Draw_VectorLine(ARGS) +{ + Draw_VectorElement(LINE, View, ValMin, ValMax, Raise, X, Y, Z, V); +} + +void Draw_VectorTriangle(ARGS) +{ + Draw_VectorElement(TRIANGLE, View, ValMin, ValMax, Raise, X, Y, Z, V); +} + +void Draw_VectorTetrahedron(ARGS) +{ + Draw_VectorElement(TETRAHEDRON, View, ValMin, ValMax, Raise, X, Y, Z, V); +} + +void Draw_VectorQuadrangle(ARGS) +{ + Draw_VectorElement(QUADRANGLE, View, ValMin, ValMax, Raise, X, Y, Z, V); +} + +void Draw_VectorHexahedron(ARGS) +{ + Draw_VectorElement(HEXAHEDRON, View, ValMin, ValMax, Raise, X, Y, Z, V); +} + +void Draw_VectorPrism(ARGS) +{ + Draw_VectorElement(PRISM, View, ValMin, ValMax, Raise, X, Y, Z, V); +} + +void Draw_VectorPyramid(ARGS) +{ + Draw_VectorElement(PYRAMID, View, ValMin, ValMax, Raise, X, Y, Z, V); +} #undef ARGS // Tensor Elements -void Draw_TensorElement(int type, Post_View *View, - double ValMin, double ValMax, double Raise[3][8], - double *X, double *Y, double *Z, double *V){ - int nbnod=0 ; - - switch(type){ - case POINT : nbnod = 1; break; - case LINE : nbnod = 2; break; - case TRIANGLE : nbnod = 3; break; - case QUADRANGLE : nbnod = 4; break; - case TETRAHEDRON : nbnod = 4; break; - case HEXAHEDRON : nbnod = 8; break; - case PRISM : nbnod = 6; break; - case PYRAMID : nbnod = 5; break; +void Draw_TensorElement(int type, Post_View * View, + double ValMin, double ValMax, double Raise[3][8], + double *X, double *Y, double *Z, double *V) +{ + int nbnod = 0; + + switch (type) { + case POINT: + nbnod = 1; + break; + case LINE: + nbnod = 2; + break; + case TRIANGLE: + nbnod = 3; + break; + case QUADRANGLE: + nbnod = 4; + break; + case TETRAHEDRON: + nbnod = 4; + break; + case HEXAHEDRON: + nbnod = 8; + break; + case PRISM: + nbnod = 6; + break; + case PYRAMID: + nbnod = 5; + break; } /// we want to compute "von mises" value i.e. max eigenvalue /// this will simply call the scalar function - if(View->TensorType == DRAW_POST_VONMISES){ - static const double THIRD = 1.e0/3.e0; - double V_VonMises [8]; - for(int i=0;i<nbnod;i++){ - double tr = (V[0+9*i]+V[4+9*i]+V[8+9*i])*THIRD; - double v11 = V[0+9*i]-tr; - double v12 = V[1+9*i]; - double v13 = V[2+9*i]; - double v21 = V[3+9*i]; - double v22 = V[4+9*i]-tr; - double v23 = V[5+9*i]; - double v31 = V[6+9*i]; - double v32 = V[7+9*i]; - double v33 = V[8+9*i]-tr; - V_VonMises[i] = sqrt (1.5 * ( v11*v11 + v12*v12 + v13*v13 + - v21*v21 + v22*v22 + v23*v23 + - v31*v31 + v32*v32 + v33*v33 ) ); + if(View->TensorType == DRAW_POST_VONMISES) { + static const double THIRD = 1.e0 / 3.e0; + double V_VonMises[8]; + for(int i = 0; i < nbnod; i++) { + double tr = (V[0 + 9 * i] + V[4 + 9 * i] + V[8 + 9 * i]) * THIRD; + double v11 = V[0 + 9 * i] - tr; + double v12 = V[1 + 9 * i]; + double v13 = V[2 + 9 * i]; + double v21 = V[3 + 9 * i]; + double v22 = V[4 + 9 * i] - tr; + double v23 = V[5 + 9 * i]; + double v31 = V[6 + 9 * i]; + double v32 = V[7 + 9 * i]; + double v33 = V[8 + 9 * i] - tr; + V_VonMises[i] = sqrt(1.5 * (v11 * v11 + v12 * v12 + v13 * v13 + + v21 * v21 + v22 * v22 + v23 * v23 + + v31 * v31 + v32 * v32 + v33 * v33)); } - switch(type){ - case POINT : Draw_ScalarPoint(View, 0, ValMin, ValMax, Raise, X,Y,Z,V_VonMises); break; - case LINE : Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, X,Y,Z,V_VonMises); break; - case TRIANGLE : Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, X,Y,Z,V_VonMises); break; - case QUADRANGLE : Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, X,Y,Z,V_VonMises); break; - case TETRAHEDRON : Draw_ScalarTetrahedron(View, 0, ValMin, ValMax, Raise, X,Y,Z,V_VonMises); break; - case HEXAHEDRON : Draw_ScalarHexahedron(View, 0, ValMin, ValMax, Raise, X,Y,Z,V_VonMises); break; - case PRISM : Draw_ScalarPrism(View, 0, ValMin, ValMax, Raise, X,Y,Z,V_VonMises); break; - case PYRAMID : Draw_ScalarPyramid(View, 0, ValMin, ValMax, Raise, X,Y,Z,V_VonMises); break; + switch (type) { + case POINT: + Draw_ScalarPoint(View, 0, ValMin, ValMax, Raise, X, Y, Z, V_VonMises); + break; + case LINE: + Draw_ScalarLine(View, 0, ValMin, ValMax, Raise, X, Y, Z, V_VonMises); + break; + case TRIANGLE: + Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, X, Y, Z, + V_VonMises); + break; + case QUADRANGLE: + Draw_ScalarQuadrangle(View, 0, ValMin, ValMax, Raise, X, Y, Z, + V_VonMises); + break; + case TETRAHEDRON: + Draw_ScalarTetrahedron(View, 0, ValMin, ValMax, Raise, X, Y, Z, + V_VonMises); + break; + case HEXAHEDRON: + Draw_ScalarHexahedron(View, 0, ValMin, ValMax, Raise, X, Y, Z, + V_VonMises); + break; + case PRISM: + Draw_ScalarPrism(View, 0, ValMin, ValMax, Raise, X, Y, Z, V_VonMises); + break; + case PYRAMID: + Draw_ScalarPyramid(View, 0, ValMin, ValMax, Raise, X, Y, Z, V_VonMises); + break; } } else { - static int error=0 ; - if(!error){ + static int error = 0; + if(!error) { error = 1; Msg(GERROR, "Tensor field visualization is not implemented"); Msg(GERROR, "We *need* some ideas on how to implement this!"); @@ -893,36 +1104,58 @@ void Draw_TensorElement(int type, Post_View *View, double ValMin, double ValMax, double Raise[3][8], \ double *X, double *Y, double *Z, double *V -void Draw_TensorPoint(ARGS){ - Draw_TensorElement(POINT, View, ValMin, ValMax, Raise, X, Y, Z, V); } -void Draw_TensorLine(ARGS){ - Draw_TensorElement(LINE, View, ValMin, ValMax, Raise, X, Y, Z, V); } -void Draw_TensorTriangle(ARGS){ +void Draw_TensorPoint(ARGS) +{ + Draw_TensorElement(POINT, View, ValMin, ValMax, Raise, X, Y, Z, V); +} + +void Draw_TensorLine(ARGS) +{ + Draw_TensorElement(LINE, View, ValMin, ValMax, Raise, X, Y, Z, V); +} + +void Draw_TensorTriangle(ARGS) +{ /* - /// we want to compute "von mises" value i.e. max eigenvalue - /// this will simply call the scalar function - if(View->TensorType == DRAW_POST_VONMISES){ - double V_VonMises [3]; - for(int i=0;i<3;i++){ - double xx = V[0+9*i]; - double yy = V[4+9*i]; - double xy = V[1+9*i]; - V_VonMises[i] = sqrt (0.5 * ( (xx-yy) * (xx-yy) + - (xx-xy) * (xx-xy) + - (xy-yy) * (xy-yy) ) ); - } - Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, X,Y,Z,V_VonMises); - } - */ - Draw_TensorElement(TRIANGLE, View, ValMin, ValMax, Raise, X, Y, Z, V); } -void Draw_TensorTetrahedron(ARGS){ - Draw_TensorElement(TETRAHEDRON, View, ValMin, ValMax, Raise, X, Y, Z, V); } -void Draw_TensorQuadrangle(ARGS){ - Draw_TensorElement(QUADRANGLE, View, ValMin, ValMax, Raise, X, Y, Z, V); } -void Draw_TensorHexahedron(ARGS){ - Draw_TensorElement(HEXAHEDRON, View, ValMin, ValMax, Raise, X, Y, Z, V); } -void Draw_TensorPrism(ARGS){ - Draw_TensorElement(PRISM, View, ValMin, ValMax, Raise, X, Y, Z, V); } -void Draw_TensorPyramid(ARGS){ - Draw_TensorElement(PYRAMID, View, ValMin, ValMax, Raise, X, Y, Z, V); } + /// we want to compute "von mises" value i.e. max eigenvalue + /// this will simply call the scalar function + if(View->TensorType == DRAW_POST_VONMISES){ + double V_VonMises [3]; + for(int i=0;i<3;i++){ + double xx = V[0+9*i]; + double yy = V[4+9*i]; + double xy = V[1+9*i]; + V_VonMises[i] = sqrt (0.5 * ( (xx-yy) * (xx-yy) + + (xx-xy) * (xx-xy) + + (xy-yy) * (xy-yy) ) ); + } + Draw_ScalarTriangle(View, 0, ValMin, ValMax, Raise, X,Y,Z,V_VonMises); + } + */ + Draw_TensorElement(TRIANGLE, View, ValMin, ValMax, Raise, X, Y, Z, V); +} + +void Draw_TensorTetrahedron(ARGS) +{ + Draw_TensorElement(TETRAHEDRON, View, ValMin, ValMax, Raise, X, Y, Z, V); +} + +void Draw_TensorQuadrangle(ARGS) +{ + Draw_TensorElement(QUADRANGLE, View, ValMin, ValMax, Raise, X, Y, Z, V); +} + +void Draw_TensorHexahedron(ARGS) +{ + Draw_TensorElement(HEXAHEDRON, View, ValMin, ValMax, Raise, X, Y, Z, V); +} +void Draw_TensorPrism(ARGS) +{ + Draw_TensorElement(PRISM, View, ValMin, ValMax, Raise, X, Y, Z, V); +} + +void Draw_TensorPyramid(ARGS) +{ + Draw_TensorElement(PYRAMID, View, ValMin, ValMax, Raise, X, Y, Z, V); +} diff --git a/Graphics/ReadImg.cpp b/Graphics/ReadImg.cpp index 11d6f4443191c4faca52d000d44f028256e5c61f..92da97e277b23a20c2980739b58a51062a9783ee 100644 --- a/Graphics/ReadImg.cpp +++ b/Graphics/ReadImg.cpp @@ -1,126 +1,111 @@ -// $Id: ReadImg.cpp,v 1.2 2003-02-12 20:27:12 geuzaine Exp $ -// -// Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle -// -// This program is free software; you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation; either version 2 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 -// USA. -// -// Please report all bugs and problems to "gmsh@geuz.org". - -#include "ReadImg.h" -#include "Gmsh.h" -#include "GmshUI.h" -#include "Views.h" - -#include <FL/Fl_PNM_Image.H> - -// from an image, we create a post pro object -Post_View * Img2Pos ( Fl_RGB_Image & img_init) -{ - - img_init.desaturate(); - Fl_RGB_Image *img = ( Fl_RGB_Image * ) img_init.copy(128,128); - - const uchar * data = img->array; - int height = img->h(); - int width = img->w(); - int dim = img->d(); - - Post_View *v = BeginView (1); - - for (int i=0;i<width-1;i++) - { - const uchar *a = data + i*width*dim; - const uchar *a1 = data + (i+1)*width*dim; - double y = 1.-(double) i/((double) width - 1.); - double y1 = 1.-(double) (i+1)/((double) width - 1.); - for (int j=0;j<height-1;j++) - { - double x = (double) j/((double) height - 1.); - double x1 = (double) (j+1)/((double) height - 1.); - double z = 0.0; - if (dim == 1) // grayscale - { - uchar G1 = a[j]; - uchar G2 = a1[j]; - uchar G3 = a1[j+1]; - uchar G4 = a[j+1]; - const double eps = 0.005; - const double Eps = .25; - - double val1 = Eps * (G1) / 255. + eps; - double val2 = Eps * (G2) / 255. + eps; - double val3 = Eps * (G3) / 255. + eps; - double val4 = Eps * (G4) / 255. + eps; - - /* - val1*=val1; - val2*=val2; - val3*=val3; - val4*=val4; - */ - List_Add (v->ST,&x); - List_Add (v->ST,&x); - List_Add (v->ST,&x1); - - List_Add (v->ST,&y); - List_Add (v->ST,&y1); - List_Add (v->ST,&y1); - - List_Add (v->ST,&z); - List_Add (v->ST,&z); - List_Add (v->ST,&z); - - List_Add (v->ST,&val1); - List_Add (v->ST,&val2); - List_Add (v->ST,&val3); - v->NbST++; - - - List_Add (v->ST,&x); - List_Add (v->ST,&x1); - List_Add (v->ST,&x1); - - List_Add (v->ST,&y); - List_Add (v->ST,&y1); - List_Add (v->ST,&y); - - List_Add (v->ST,&z); - List_Add (v->ST,&z); - List_Add (v->ST,&z); - - List_Add (v->ST,&val1); - List_Add (v->ST,&val3); - List_Add (v->ST,&val4); - v->NbST++; - } - } - } - delete img; - return v; -} - - -void read_pnm (char *name) -{ - Fl_PNM_Image theVeryNicePicture ( name ); - Post_View * v = Img2Pos (theVeryNicePicture); - char name2[256]; - strcpy(name2,name); - strcat(name2,".pos"); - EndView (v,1,name2,name); -} - - +// $Id: ReadImg.cpp,v 1.3 2003-03-01 22:36:40 geuzaine Exp $ +// +// Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle +// +// This program is free software; you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation; either version 2 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 +// USA. +// +// Please report all bugs and problems to "gmsh@geuz.org". + +#include "ReadImg.h" +#include "Gmsh.h" +#include "GmshUI.h" +#include "Views.h" + +#include <FL/Fl_PNM_Image.H> + +// from an image, we create a post pro object +Post_View * Img2Pos(Fl_RGB_Image & img_init) +{ + img_init.desaturate(); + + Fl_RGB_Image * img = (Fl_RGB_Image *) img_init.copy(128, 128); + + const uchar *data = img->array; + int height = img->h(); + int width = img->w(); + int dim = img->d(); + + Post_View * v = BeginView(1); + + for(int i = 0; i < width - 1; i++) { + const uchar *a = data + i * width * dim; + const uchar *a1 = data + (i + 1) * width * dim; + double y = 1. - (double)i / ((double)width - 1.); + double y1 = 1. - (double)(i + 1) / ((double)width - 1.); + for(int j = 0; j < height - 1; j++) { + double x = (double)j / ((double)height - 1.); + double x1 = (double)(j + 1) / ((double)height - 1.); + double z = 0.0; + if(dim == 1) { // grayscale + uchar G1 = a[j]; + uchar G2 = a1[j]; + uchar G3 = a1[j + 1]; + uchar G4 = a[j + 1]; + const double eps = 0.005; + const double Eps = .25; + double val1 = Eps * (G1) / 255. + eps; + double val2 = Eps * (G2) / 255. + eps; + double val3 = Eps * (G3) / 255. + eps; + double val4 = Eps * (G4) / 255. + eps; + /* + val1*=val1; + val2*=val2; + val3*=val3; + val4*=val4; + */ + List_Add(v->ST, &x); + List_Add(v->ST, &x); + List_Add(v->ST, &x1); + List_Add(v->ST, &y); + List_Add(v->ST, &y1); + List_Add(v->ST, &y1); + List_Add(v->ST, &z); + List_Add(v->ST, &z); + List_Add(v->ST, &z); + List_Add(v->ST, &val1); + List_Add(v->ST, &val2); + List_Add(v->ST, &val3); + v->NbST++; + List_Add(v->ST, &x); + List_Add(v->ST, &x1); + List_Add(v->ST, &x1); + List_Add(v->ST, &y); + List_Add(v->ST, &y1); + List_Add(v->ST, &y); + List_Add(v->ST, &z); + List_Add(v->ST, &z); + List_Add(v->ST, &z); + List_Add(v->ST, &val1); + List_Add(v->ST, &val3); + List_Add(v->ST, &val4); + v->NbST++; + } + } + } + delete img; + return v; +} + +void read_pnm(char *name) +{ + Fl_PNM_Image theVeryNicePicture(name); + Post_View * v = Img2Pos(theVeryNicePicture); + char name2[256]; + strcpy(name2, name); + strcat(name2, ".pos"); + EndView(v, 1, name2, name); +} + diff --git a/Graphics/Scale.cpp b/Graphics/Scale.cpp index ddbd7704791f59f582ffff1ccfe734918265c9f4..fb9a37025b1597fb1a2c1546c0be55e37fd2d83c 100644 --- a/Graphics/Scale.cpp +++ b/Graphics/Scale.cpp @@ -1,4 +1,4 @@ -// $Id: Scale.cpp,v 1.33 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: Scale.cpp,v 1.34 2003-03-01 22:36:40 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -28,239 +28,257 @@ #include "Views.h" #include "gl2ps.h" -extern Context_T CTX; +extern Context_T CTX; // Even if all computations in these routines are made in window // coordinates, double precision is used to work at subpixel accuracy -extern double GiveValueFromIndex_Lin(double ValMin, double ValMax, int NbIso, int Iso); -extern double GiveValueFromIndex_Log(double ValMin, double ValMax, int NbIso, int Iso); -extern int GiveIndexFromValue_Lin(double ValMin, double ValMax, int NbIso, double Val); -extern int GiveIndexFromValue_Log(double ValMin, double ValMax, int NbIso, double Val); +extern double GiveValueFromIndex_Lin(double ValMin, double ValMax, int NbIso, + int Iso); +extern double GiveValueFromIndex_Log(double ValMin, double ValMax, int NbIso, + int Iso); +extern int GiveIndexFromValue_Lin(double ValMin, double ValMax, int NbIso, + double Val); +extern int GiveIndexFromValue_Log(double ValMin, double ValMax, int NbIso, + double Val); -void draw_scale(Post_View *v, - double xmin, double ymin, double width, double height, - double tic, double space, double dx, double dy){ - - int i, nbv; - double font_h, font_a; - double cs_bh, cv_xmin, cv_bh; - char label[1024] ; - double Val, ValMin, ValMax; +void draw_scale(Post_View * v, + double xmin, double ymin, double width, double height, + double tic, double space, double dx, double dy) +{ + int i, nbv; + double font_h, font_a; + double cs_bh, cv_xmin, cv_bh; + char label[1024]; + double Val, ValMin, ValMax; - gl_font(FL_HELVETICA,CTX.gl_fontsize); - font_h = gl_height() ; // total font height - font_a = gl_height()-gl_descent() ; // height above ref pt - cs_bh = height/(v->NbIso?v->NbIso:1) ; // colorscale box height - cv_xmin = xmin+width+tic ; // valuescale xmin + gl_font(FL_HELVETICA, CTX.gl_fontsize); + font_h = gl_height(); // total font height + font_a = gl_height() - gl_descent(); // height above ref pt + cs_bh = height / (v->NbIso ? v->NbIso : 1); // colorscale box height + cv_xmin = xmin + width + tic; // valuescale xmin - glPointSize(v->PointSize); + glPointSize(v->PointSize); gl2psPointSize(v->PointSize * CTX.print.eps_point_size_factor); - glLineWidth(v->LineWidth); + glLineWidth(v->LineWidth); gl2psLineWidth(v->LineWidth * CTX.print.eps_line_width_factor); - if(!v->TransparentScale){ - double dytop=0.; + if(!v->TransparentScale) { + double dytop = 0.; if(v->IntervalsType != DRAW_POST_ISO) - dytop = font_h/2.; - glColor4ubv((GLubyte*)&CTX.color.bg); + dytop = font_h / 2.; + glColor4ubv((GLubyte *) & CTX.color.bg); glBegin(GL_QUADS); - glVertex2d(xmin-space,ymin-dy-space); - glVertex2d(xmin+width+dx+space,ymin-dy-space); - glVertex2d(xmin+width+dx+space,ymin+height+dytop+space); - glVertex2d(xmin-space,ymin+height+dytop+space); - glEnd(); + glVertex2d(xmin - space, ymin - dy - space); + glVertex2d(xmin + width + dx + space, ymin - dy - space); + glVertex2d(xmin + width + dx + space, ymin + height + dytop + space); + glVertex2d(xmin - space, ymin + height + dytop + space); + glEnd(); } - + if(v->IntervalsType == DRAW_POST_CONTINUOUS) glShadeModel(GL_SMOOTH); else glShadeModel(GL_FLAT); - - if(v->RangeType == DRAW_POST_CUSTOM){ - ValMin = v->CustomMin ; ValMax = v->CustomMax ; + + if(v->RangeType == DRAW_POST_CUSTOM) { + ValMin = v->CustomMin; + ValMax = v->CustomMax; } - else{ - ValMin = v->Min ; ValMax = v->Max ; + else { + ValMin = v->Min; + ValMax = v->Max; } - - switch(v->ScaleType){ - case DRAW_POST_LINEAR : - v->GIFV = GiveIndexFromValue_Lin ; - v->GVFI = GiveValueFromIndex_Lin ; + + switch (v->ScaleType) { + case DRAW_POST_LINEAR: + v->GIFV = GiveIndexFromValue_Lin; + v->GVFI = GiveValueFromIndex_Lin; break; - case DRAW_POST_LOGARITHMIC : - v->GIFV = GiveIndexFromValue_Log ; - v->GVFI = GiveValueFromIndex_Log ; + case DRAW_POST_LOGARITHMIC: + v->GIFV = GiveIndexFromValue_Log; + v->GVFI = GiveValueFromIndex_Log; break; } // colorscale - for(i=0;i<v->NbIso;i++){ - if(v->IntervalsType==DRAW_POST_DISCRETE){ - Palette1(v,v->NbIso,i); + for(i = 0; i < v->NbIso; i++) { + if(v->IntervalsType == DRAW_POST_DISCRETE) { + Palette1(v, v->NbIso, i); glBegin(GL_QUADS); - glVertex2d(xmin, ymin+i*cs_bh); - glVertex2d(xmin+width, ymin+i*cs_bh); - glVertex2d(xmin+width, ymin+(i+1)*cs_bh); - glVertex2d(xmin, ymin+(i+1)*cs_bh); + glVertex2d(xmin, ymin + i * cs_bh); + glVertex2d(xmin + width, ymin + i * cs_bh); + glVertex2d(xmin + width, ymin + (i + 1) * cs_bh); + glVertex2d(xmin, ymin + (i + 1) * cs_bh); glEnd(); } - else if (v->IntervalsType==DRAW_POST_CONTINUOUS){ + else if(v->IntervalsType == DRAW_POST_CONTINUOUS) { glBegin(GL_QUADS); - Palette2(v,ValMin,ValMax,ValMin+i*(ValMax-ValMin)/(v->NbIso?v->NbIso:1)); - glVertex2d(xmin, ymin+i*cs_bh); - glVertex2d(xmin+width, ymin+i*cs_bh); - Palette2(v,ValMin,ValMax,ValMin+(i+1)*(ValMax-ValMin)/(v->NbIso?v->NbIso:1)); - glVertex2d(xmin+width, ymin+(i+1)*cs_bh); - glVertex2d(xmin, ymin+(i+1)*cs_bh); - glEnd(); + Palette2(v, ValMin, ValMax, + ValMin + i * (ValMax - ValMin) / (v->NbIso ? v->NbIso : 1)); + glVertex2d(xmin, ymin + i * cs_bh); + glVertex2d(xmin + width, ymin + i * cs_bh); + Palette2(v, ValMin, ValMax, + ValMin + (i + 1) * (ValMax - + ValMin) / (v->NbIso ? v->NbIso : 1)); + glVertex2d(xmin + width, ymin + (i + 1) * cs_bh); + glVertex2d(xmin, ymin + (i + 1) * cs_bh); + glEnd(); } - else{ - Palette1(v,v->NbIso,i); + else { + Palette1(v, v->NbIso, i); glBegin(GL_LINES); - glVertex2d(xmin, ymin+i*cs_bh+0.5*cs_bh); - glVertex2d(xmin+width, ymin+i*cs_bh+0.5*cs_bh); + glVertex2d(xmin, ymin + i * cs_bh + 0.5 * cs_bh); + glVertex2d(xmin + width, ymin + i * cs_bh + 0.5 * cs_bh); glEnd(); } - } - + } + // valuescale - - nbv = (v->NbIso<floor(height/font_h))?v->NbIso:-1; - cv_bh = height/nbv; - glColor4ubv((GLubyte*)&CTX.color.text); + nbv = (v->NbIso < floor(height / font_h)) ? v->NbIso : -1; + cv_bh = height / nbv; + + glColor4ubv((GLubyte *) & CTX.color.text); - - if(nbv<0){ // only min and max if not enough room + + if(nbv < 0) { // only min and max if not enough room if(v->IntervalsType == DRAW_POST_DISCRETE || - v->IntervalsType == DRAW_POST_CONTINUOUS){ + v->IntervalsType == DRAW_POST_CONTINUOUS) { sprintf(label, v->Format, ValMin); - glRasterPos2d(cv_xmin,ymin-font_a/3.); + glRasterPos2d(cv_xmin, ymin - font_a / 3.); Draw_String(label); sprintf(label, v->Format, ValMax); - glRasterPos2d(cv_xmin,ymin+height-font_a/3.); + glRasterPos2d(cv_xmin, ymin + height - font_a / 3.); Draw_String(label); } else { sprintf(label, v->Format, ValMin); - glRasterPos2d(cv_xmin,ymin+(cs_bh/2)-font_a/3.); + glRasterPos2d(cv_xmin, ymin + (cs_bh / 2) - font_a / 3.); Draw_String(label); sprintf(label, v->Format, ValMax); - glRasterPos2d(cv_xmin,ymin+height-(cs_bh/2)-font_a/3.); + glRasterPos2d(cv_xmin, ymin + height - (cs_bh / 2) - font_a / 3.); Draw_String(label); } } else { if(v->IntervalsType == DRAW_POST_DISCRETE || - v->IntervalsType == DRAW_POST_CONTINUOUS){ - for(i=0 ; i<nbv+1 ; i++){ - Val = v->GVFI(ValMin,ValMax,nbv+1,i); + v->IntervalsType == DRAW_POST_CONTINUOUS) { + for(i = 0; i < nbv + 1; i++) { + Val = v->GVFI(ValMin, ValMax, nbv + 1, i); sprintf(label, v->Format, Val); - glRasterPos2d(cv_xmin,ymin+i*cv_bh-font_a/3.); + glRasterPos2d(cv_xmin, ymin + i * cv_bh - font_a / 3.); Draw_String(label); } } else { - for(i=0 ; i<nbv ; i++){ - Val = v->GVFI(ValMin,ValMax,nbv,i); + for(i = 0; i < nbv; i++) { + Val = v->GVFI(ValMin, ValMax, nbv, i); sprintf(label, v->Format, Val); - glRasterPos2d(cv_xmin,ymin+(2*i+1)*(cv_bh/2)-font_a/3.); + glRasterPos2d(cv_xmin, + ymin + (2 * i + 1) * (cv_bh / 2) - font_a / 3.); Draw_String(label); } } } // the label - - glRasterPos2d(cv_xmin,ymin-2*font_h); - if(List_Nbr(v->Time)>1 && v->ShowTime) - sprintf(label, "%s (%g)", v->Name, *(double*)List_Pointer(v->Time,v->TimeStep)); + + glRasterPos2d(cv_xmin, ymin - 2 * font_h); + if(List_Nbr(v->Time) > 1 && v->ShowTime) + sprintf(label, "%s (%g)", v->Name, + *(double *)List_Pointer(v->Time, v->TimeStep)); else sprintf(label, "%s", v->Name); Draw_String(label); } -static List_T *todraw=NULL; +static List_T *todraw = NULL; -void Draw_Scales(void){ +void Draw_Scales(void) +{ int i; double xmin, ymin, width, height, xsep, ysep; double oldwidth, totalwidth; - double dx=0., dy=0., tic=5., space=10.; + double dx = 0., dy = 0., tic = 5., space = 10.; char label[1024]; - Post_View *v; + Post_View *v; - if(!CTX.post.list) return; + if(!CTX.post.list) + return; // scales to draw? - + if(!todraw) - todraw = List_Create(5,5,sizeof(Post_View*)); + todraw = List_Create(5, 5, sizeof(Post_View *)); else List_Reset(todraw); - for(i=0;i<List_Nbr(CTX.post.list);i++){ - v = (Post_View*)List_Pointer(CTX.post.list,i); + for(i = 0; i < List_Nbr(CTX.post.list); i++) { + v = (Post_View *) List_Pointer(CTX.post.list, i); if(v->Visible && !v->Dirty && v->ShowScale && - v->Type==DRAW_POST_3D && !v->TextOnly) - List_Add(todraw,&v); + v->Type == DRAW_POST_3D && !v->TextOnly) + List_Add(todraw, &v); } - - if(!List_Nbr(todraw)){ + + if(!List_Nbr(todraw)) { return; } - xsep = 20. ; + xsep = 20.; width = 16.0; totalwidth = 0.0; - if(List_Nbr(todraw)==1) - ysep = (CTX.viewport[3]-CTX.viewport[1])/6. ; + if(List_Nbr(todraw) == 1) + ysep = (CTX.viewport[3] - CTX.viewport[1]) / 6.; else - ysep = (CTX.viewport[3]-CTX.viewport[1])/15. ; - xmin = CTX.viewport[0] + xsep ; - ymin = CTX.viewport[1] + ysep ; + ysep = (CTX.viewport[3] - CTX.viewport[1]) / 15.; + xmin = CTX.viewport[0] + xsep; + ymin = CTX.viewport[1] + ysep; - for(i=0;i<List_Nbr(todraw);i++){ - v = *(Post_View**)List_Pointer(todraw,i); - oldwidth = width+dx+space; + for(i = 0; i < List_Nbr(todraw); i++) { + v = *(Post_View **) List_Pointer(todraw, i); + oldwidth = width + dx + space; dx = dy = 0.; - gl_font(FL_HELVETICA,CTX.gl_fontsize); - sprintf(label,v->Format,v->CustomMin); - if(gl_width(label)+tic > dx) dx = gl_width(label)+tic; - sprintf(label,v->Format,v->CustomMax); - if(gl_width(label)+tic > dx) dx = gl_width(label)+tic; - if(List_Nbr(v->Time)>1 && v->ShowTime) - sprintf(label, "%s (%g)", v->Name, *(double*)List_Pointer(v->Time,v->TimeStep)); + gl_font(FL_HELVETICA, CTX.gl_fontsize); + sprintf(label, v->Format, v->CustomMin); + if(gl_width(label) + tic > dx) + dx = gl_width(label) + tic; + sprintf(label, v->Format, v->CustomMax); + if(gl_width(label) + tic > dx) + dx = gl_width(label) + tic; + if(List_Nbr(v->Time) > 1 && v->ShowTime) + sprintf(label, "%s (%g)", v->Name, + *(double *)List_Pointer(v->Time, v->TimeStep)); else sprintf(label, "%s", v->Name); - if(gl_width(label)+tic > dx) dx = gl_width(label)+tic; - dy = 2.*gl_height(); - if(v->AutoPosition){ - if(List_Nbr(todraw)==1){ - height = CTX.viewport[3]-CTX.viewport[1]-2*ysep-dy ; - draw_scale(v,xmin,ymin+dy,width,height,tic,space,dx,dy); + if(gl_width(label) + tic > dx) + dx = gl_width(label) + tic; + dy = 2. * gl_height(); + if(v->AutoPosition) { + if(List_Nbr(todraw) == 1) { + height = CTX.viewport[3] - CTX.viewport[1] - 2 * ysep - dy; + draw_scale(v, xmin, ymin + dy, width, height, tic, space, dx, dy); } - else{ - height = (CTX.viewport[3]-CTX.viewport[1]-3*ysep-2.5*dy)/2. ; - draw_scale(v, - xmin+totalwidth+(i/2)*xsep, - ymin+dy+(1-i%2)*(height+1.5*dy+ysep), - width, height, tic, space,dx, dy); + else { + height = + (CTX.viewport[3] - CTX.viewport[1] - 3 * ysep - 2.5 * dy) / 2.; + draw_scale(v, xmin + totalwidth + (i / 2) * xsep, + ymin + dy + (1 - i % 2) * (height + 1.5 * dy + ysep), + width, height, tic, space, dx, dy); } - if(i%2) totalwidth += DMAX(width+dx+space,oldwidth); + if(i % 2) + totalwidth += DMAX(width + dx + space, oldwidth); } else - draw_scale(v,v->Position[0],CTX.viewport[3]-v->Size[1]-v->Position[1], - v->Size[0],v->Size[1],tic,space,dx,dy); + draw_scale(v, v->Position[0], + CTX.viewport[3] - v->Size[1] - v->Position[1], v->Size[0], + v->Size[1], tic, space, dx, dy); } } - diff --git a/Graphics/Visibility.cpp b/Graphics/Visibility.cpp index 60b4b1fcb67f01fd55045df23fb550b61acf416d..3cd932288af17e679fa37d0b8ce44b1ed88476c2 100644 --- a/Graphics/Visibility.cpp +++ b/Graphics/Visibility.cpp @@ -1,4 +1,4 @@ -// $Id: Visibility.cpp,v 1.6 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: Visibility.cpp,v 1.7 2003-03-01 22:36:40 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -30,46 +30,61 @@ extern Mesh *THEM; static List_T *ElementaryEntities = NULL, *PhysicalEntities = NULL; -static Tree_T *VisibleThroughPhysical[4] = {NULL,NULL,NULL,NULL}; +static Tree_T *VisibleThroughPhysical[4] = { NULL, NULL, NULL, NULL }; static List_T *NumxSymb = NULL; static int Sort = 1; -int Entity::Num(){ - switch(type){ - case 1 : - case 2 : - case 3 : - case 4 : return data.physical ? data.physical->Num : 0; - case 5 : return data.vertex ? data.vertex->Num : 0; - case 6 : return data.curve ? data.curve->Num : 0; - case 7 : return data.surface ? data.surface->Num : 0; - case 8 : return data.volume ? data.volume->Num : 0; - default : return 0; +int Entity::Num() +{ + switch (type) { + case 1: + case 2: + case 3: + case 4: + return data.physical ? data.physical->Num : 0; + case 5: + return data.vertex ? data.vertex->Num : 0; + case 6: + return data.curve ? data.curve->Num : 0; + case 7: + return data.surface ? data.surface->Num : 0; + case 8: + return data.volume ? data.volume->Num : 0; + default: + return 0; } } -char * Entity::Type(){ - switch(type){ - case 1 : - case 5 : return "Point"; - case 2 : - case 6 : return "Curve"; - case 3 : - case 7 : return "Surface"; - case 4 : - case 8 : return "Volume"; - default : return "Unknown"; +char *Entity::Type() +{ + switch (type) { + case 1: + case 5: + return "Point"; + case 2: + case 6: + return "Curve"; + case 3: + case 7: + return "Surface"; + case 4: + case 8: + return "Volume"; + default: + return "Unknown"; } } -char * Entity::Name(){ - char *tmp=""; - return str?str:tmp; +char *Entity::Name() +{ + char *tmp = ""; + return str ? str : tmp; } static char browserline[512]; -char * Entity::BrowserLine(){ - if(type){ +char *Entity::BrowserLine() +{ + if(type) { sprintf(browserline, "\t%s\t%d\t%s", Type(), Num(), Name()); return browserline; } @@ -77,182 +92,240 @@ char * Entity::BrowserLine(){ return Name(); } -int Entity::Visible(){ - switch(type){ - case 1 : - case 2 : - case 3 : - case 4 : return data.physical ? data.physical->Visible : 0; - case 5 : return data.vertex ? data.vertex->Visible : 0; - case 6 : return data.curve ? data.curve->Visible : 0; - case 7 : return data.surface ? data.surface->Visible : 0; - case 8 : return data.volume ? data.volume->Visible : 0; - default : return 0; +int Entity::Visible() +{ + switch (type) { + case 1: + case 2: + case 3: + case 4: + return data.physical ? data.physical->Visible : 0; + case 5: + return data.vertex ? data.vertex->Visible : 0; + case 6: + return data.curve ? data.curve->Visible : 0; + case 7: + return data.surface ? data.surface->Visible : 0; + case 8: + return data.volume ? data.volume->Visible : 0; + default: + return 0; } } -void Entity::Visible(int mode){ +void Entity::Visible(int mode) +{ Vertex *v; Curve *c; Surface *s; Volume *V; - int i,j; + int i, j; - switch(type){ - case 1 : - if(!data.physical) break; + switch (type) { + case 1: + if(!data.physical) + break; data.physical->Visible = mode; - for(i=0;i<List_Nbr(data.physical->Entities);i++){ - List_Read(data.physical->Entities,i,&j); - if((v=FindPoint(j,THEM))){ - if(Tree_Search(VisibleThroughPhysical[0],&j)){ - v->Visible = v->Visible|mode; - } - else{ - v->Visible = mode; - if(mode) Tree_Add(VisibleThroughPhysical[0],&j); - } + for(i = 0; i < List_Nbr(data.physical->Entities); i++) { + List_Read(data.physical->Entities, i, &j); + if((v = FindPoint(j, THEM))) { + if(Tree_Search(VisibleThroughPhysical[0], &j)) { + v->Visible = v->Visible | mode; + } + else { + v->Visible = mode; + if(mode) + Tree_Add(VisibleThroughPhysical[0], &j); + } } } break; - case 2 : - if(!data.physical) break; + case 2: + if(!data.physical) + break; data.physical->Visible = mode; - for(i=0;i<List_Nbr(data.physical->Entities);i++){ - List_Read(data.physical->Entities,i,&j); - if((c=FindCurve(abs(j),THEM))){ - if(Tree_Search(VisibleThroughPhysical[1],&j)){ - c->Visible = c->Visible|mode; - } - else{ - c->Visible = mode; - if(mode) Tree_Add(VisibleThroughPhysical[1],&j); - } + for(i = 0; i < List_Nbr(data.physical->Entities); i++) { + List_Read(data.physical->Entities, i, &j); + if((c = FindCurve(abs(j), THEM))) { + if(Tree_Search(VisibleThroughPhysical[1], &j)) { + c->Visible = c->Visible | mode; + } + else { + c->Visible = mode; + if(mode) + Tree_Add(VisibleThroughPhysical[1], &j); + } } } break; - case 3 : - if(!data.physical) break; + case 3: + if(!data.physical) + break; data.physical->Visible = mode; - for(i=0;i<List_Nbr(data.physical->Entities);i++){ - List_Read(data.physical->Entities,i,&j); - if((s=FindSurface(abs(j),THEM))){ - if(Tree_Search(VisibleThroughPhysical[2],&j)){ - s->Visible = s->Visible|mode; - } - else{ - s->Visible = mode; - if(mode) Tree_Add(VisibleThroughPhysical[2],&j); - } + for(i = 0; i < List_Nbr(data.physical->Entities); i++) { + List_Read(data.physical->Entities, i, &j); + if((s = FindSurface(abs(j), THEM))) { + if(Tree_Search(VisibleThroughPhysical[2], &j)) { + s->Visible = s->Visible | mode; + } + else { + s->Visible = mode; + if(mode) + Tree_Add(VisibleThroughPhysical[2], &j); + } }; } break; - case 4 : - if(!data.physical) break; + case 4: + if(!data.physical) + break; data.physical->Visible = mode; - for(i=0;i<List_Nbr(data.physical->Entities);i++){ - List_Read(data.physical->Entities,i,&j); - if((V=FindVolume(abs(j),THEM))){ - if(Tree_Search(VisibleThroughPhysical[3],&j)){ - V->Visible = V->Visible|mode; - } - else{ - V->Visible = mode; - if(mode) Tree_Add(VisibleThroughPhysical[3],&j); - } + for(i = 0; i < List_Nbr(data.physical->Entities); i++) { + List_Read(data.physical->Entities, i, &j); + if((V = FindVolume(abs(j), THEM))) { + if(Tree_Search(VisibleThroughPhysical[3], &j)) { + V->Visible = V->Visible | mode; + } + else { + V->Visible = mode; + if(mode) + Tree_Add(VisibleThroughPhysical[3], &j); + } } } break; - case 5 : if(!data.vertex) break; data.vertex->Visible = mode; break; - case 6 : if(!data.curve) break; data.curve->Visible = mode; break; - case 7 : if(!data.surface) break; data.surface->Visible = mode; break; - case 8 : if(!data.volume) break; data.volume->Visible = mode; break; + case 5: + if(!data.vertex) + break; + data.vertex->Visible = mode; + break; + case 6: + if(!data.curve) + break; + data.curve->Visible = mode; + break; + case 7: + if(!data.surface) + break; + data.surface->Visible = mode; + break; + case 8: + if(!data.volume) + break; + data.volume->Visible = mode; + break; } } -static void Recur(Curve *c, int mode){ +static void Recur(Curve * c, int mode) +{ int k; Vertex *v; - for(k=0;k<List_Nbr(c->Control_Points);k++){ - List_Read(c->Control_Points,k,&v); - v->Visible = v->Visible|mode; + for(k = 0; k < List_Nbr(c->Control_Points); k++) { + List_Read(c->Control_Points, k, &v); + v->Visible = v->Visible | mode; } } -static void Recur(Surface *s, int mode){ - int k,l; +static void Recur(Surface * s, int mode) +{ + int k, l; Vertex *v; Curve *c; - for(k=0;k<List_Nbr(s->Generatrices);k++){ - List_Read(s->Generatrices,k,&c); - if(c->Num<0) c = FindCurve(-c->Num,THEM); - if(c){ - c->Visible = c->Visible|mode; - for(l=0;l<List_Nbr(c->Control_Points);l++){ - List_Read(c->Control_Points,l,&v); - v->Visible = v->Visible|mode; + for(k = 0; k < List_Nbr(s->Generatrices); k++) { + List_Read(s->Generatrices, k, &c); + if(c->Num < 0) + c = FindCurve(-c->Num, THEM); + if(c) { + c->Visible = c->Visible | mode; + for(l = 0; l < List_Nbr(c->Control_Points); l++) { + List_Read(c->Control_Points, l, &v); + v->Visible = v->Visible | mode; } } } } -static void Recur(Volume *V, int mode){ - int k,l,m; +static void Recur(Volume * V, int mode) +{ + int k, l, m; Vertex *v; Curve *c; Surface *s; - for(k=0;k<List_Nbr(V->Surfaces);k++){ - List_Read(V->Surfaces,k,&s); - s->Visible = s->Visible|mode; - for(l=0;l<List_Nbr(s->Generatrices);l++){ - List_Read(s->Generatrices,l,&c); - if(c->Num<0) c = FindCurve(-c->Num,THEM); - if(c){ - c->Visible = c->Visible|mode; - for(m=0;m<List_Nbr(c->Control_Points);m++){ - List_Read(c->Control_Points,m,&v); - v->Visible = v->Visible|mode; - } + for(k = 0; k < List_Nbr(V->Surfaces); k++) { + List_Read(V->Surfaces, k, &s); + s->Visible = s->Visible | mode; + for(l = 0; l < List_Nbr(s->Generatrices); l++) { + List_Read(s->Generatrices, l, &c); + if(c->Num < 0) + c = FindCurve(-c->Num, THEM); + if(c) { + c->Visible = c->Visible | mode; + for(m = 0; m < List_Nbr(c->Control_Points); m++) { + List_Read(c->Control_Points, m, &v); + v->Visible = v->Visible | mode; + } } } } } -void Entity::RecurVisible(){ - int j,k,mode; +void Entity::RecurVisible() +{ + int j, k, mode; Curve *c; Surface *s; Volume *V; mode = Visible(); - if(mode){ - switch(type){ - case 1 : break; - case 2 : - if(!data.physical) break; - for(j=0;j<List_Nbr(data.physical->Entities);j++){ - List_Read(data.physical->Entities,j,&k); - if((c=FindCurve(abs(k),THEM))) Recur(c,mode); + if(mode) { + switch (type) { + case 1: + break; + case 2: + if(!data.physical) + break; + for(j = 0; j < List_Nbr(data.physical->Entities); j++) { + List_Read(data.physical->Entities, j, &k); + if((c = FindCurve(abs(k), THEM))) + Recur(c, mode); } break; - case 3 : - if(!data.physical) break; - for(j=0;j<List_Nbr(data.physical->Entities);j++){ - List_Read(data.physical->Entities,j,&k); - if((s=FindSurface(abs(k),THEM))) Recur(s,mode); + case 3: + if(!data.physical) + break; + for(j = 0; j < List_Nbr(data.physical->Entities); j++) { + List_Read(data.physical->Entities, j, &k); + if((s = FindSurface(abs(k), THEM))) + Recur(s, mode); } break; - case 4 : - if(!data.physical) break; - for(j=0;j<List_Nbr(data.physical->Entities);j++){ - List_Read(data.physical->Entities,j,&k); - if((V=FindVolume(abs(k),THEM))) Recur(V,mode); + case 4: + if(!data.physical) + break; + for(j = 0; j < List_Nbr(data.physical->Entities); j++) { + List_Read(data.physical->Entities, j, &k); + if((V = FindVolume(abs(k), THEM))) + Recur(V, mode); } break; - case 5 : break; - case 6 : if(!data.curve) break; Recur(data.curve,mode); break; - case 7 : if(!data.surface) break; Recur(data.surface,mode); break; - case 8 : if(!data.volume) break; Recur(data.volume,mode); break; + case 5: + break; + case 6: + if(!data.curve) + break; + Recur(data.curve, mode); + break; + case 7: + if(!data.surface) + break; + Recur(data.surface, mode); + break; + case 8: + if(!data.volume) + break; + Recur(data.volume, mode); + break; } } } @@ -260,56 +333,77 @@ void Entity::RecurVisible(){ -void SetVisibilitySort(int sort){ +void SetVisibilitySort(int sort) +{ if(Sort == sort) Sort = -sort; else Sort = sort; } -static int CompareEntity(const void *a, const void *b){ - Entity *p=(Entity*)a, *q=(Entity*)b; - switch(Sort){ - case 1 : return p->type - q->type; - case -1 : return q->type - p->type; - case 2 : return p->Num() - q->Num(); - case -2 : return q->Num() - p->Num(); - case 3 : return strcmp(p->Name(), q->Name()); - case -3 : return strcmp(q->Name(), p->Name()); - default : return 0; +static int CompareEntity(const void *a, const void *b) +{ + Entity *p = (Entity *) a, *q = (Entity *) b; + switch (Sort) { + case 1: + return p->type - q->type; + case -1: + return q->type - p->type; + case 2: + return p->Num() - q->Num(); + case -2: + return q->Num() - p->Num(); + case 3: + return strcmp(p->Name(), q->Name()); + case -3: + return strcmp(q->Name(), p->Name()); + default: + return 0; } } -static int CompareNxS(const void *a, const void *b){ - NxS *p=(NxS*)a, *q=(NxS*)b; +static int CompareNxS(const void *a, const void *b) +{ + NxS *p = (NxS *) a, *q = (NxS *) b; return p->n - q->n; } -static char * GetString(int num){ +static char *GetString(int num) +{ NxS nxs, *pnxs; nxs.n = num; - if((pnxs = (NxS*)List_PQuery(NumxSymb,&nxs,CompareNxS))) + if((pnxs = (NxS *) List_PQuery(NumxSymb, &nxs, CompareNxS))) return pnxs->s; else return NULL; } -static void AddPhysical(void *a, void *b){ - PhysicalGroup *p=*(PhysicalGroup**)a; +static void AddPhysical(void *a, void *b) +{ + PhysicalGroup *p = *(PhysicalGroup **) a; Entity e; - switch(p->Typ){ - case MSH_PHYSICAL_POINT : e.type = 1; break; - case MSH_PHYSICAL_LINE : e.type = 2; break; - case MSH_PHYSICAL_SURFACE: e.type = 3; break; - case MSH_PHYSICAL_VOLUME : e.type = 4; break; + switch (p->Typ) { + case MSH_PHYSICAL_POINT: + e.type = 1; + break; + case MSH_PHYSICAL_LINE: + e.type = 2; + break; + case MSH_PHYSICAL_SURFACE: + e.type = 3; + break; + case MSH_PHYSICAL_VOLUME: + e.type = 4; + break; } e.data.physical = p; e.str = GetString(p->Num); List_Add(PhysicalEntities, &e); } -static void AddVertex(void *a, void *b){ - Vertex *v=*(Vertex**)a; +static void AddVertex(void *a, void *b) +{ + Vertex *v = *(Vertex **) a; Entity e; e.type = 5; e.data.vertex = v; @@ -317,9 +411,11 @@ static void AddVertex(void *a, void *b){ List_Add(ElementaryEntities, &e); } -static void AddCurve(void *a, void *b){ - Curve *c=*(Curve**)a; - if(c->Num < 0) return; +static void AddCurve(void *a, void *b) +{ + Curve *c = *(Curve **) a; + if(c->Num < 0) + return; Entity e; e.type = 6; e.data.curve = c; @@ -327,8 +423,9 @@ static void AddCurve(void *a, void *b){ List_Add(ElementaryEntities, &e); } -static void AddSurface(void *a, void *b){ - Surface *s=*(Surface**)a; +static void AddSurface(void *a, void *b) +{ + Surface *s = *(Surface **) a; Entity e; e.type = 7; e.data.surface = s; @@ -336,8 +433,9 @@ static void AddSurface(void *a, void *b){ List_Add(ElementaryEntities, &e); } -static void AddVolume(void *a, void *b){ - Volume *v=*(Volume**)a; +static void AddVolume(void *a, void *b) +{ + Volume *v = *(Volume **) a; Entity e; e.type = 8; e.data.volume = v; @@ -345,30 +443,31 @@ static void AddVolume(void *a, void *b){ List_Add(ElementaryEntities, &e); } -List_T* GetVisibilityList(int type){ +List_T *GetVisibilityList(int type) +{ int i, j; Symbol *s; NxS nxs; - if(!ElementaryEntities) - ElementaryEntities = List_Create(100,100,sizeof(Entity)); + if(!ElementaryEntities) + ElementaryEntities = List_Create(100, 100, sizeof(Entity)); else List_Reset(ElementaryEntities); if(!PhysicalEntities) - PhysicalEntities = List_Create(100,100,sizeof(Entity)); + PhysicalEntities = List_Create(100, 100, sizeof(Entity)); else List_Reset(PhysicalEntities); - if(!NumxSymb) - NumxSymb = List_Create(100,100,sizeof(NxS)); + if(!NumxSymb) + NumxSymb = List_Create(100, 100, sizeof(NxS)); else List_Reset(NumxSymb); - for(i=0; i<List_Nbr(Symbol_L); i++){ - s=(Symbol*)List_Pointer(Symbol_L,i); - for(j=0; j<List_Nbr(s->val); j++){ - nxs.n = (int)(*(double*)List_Pointer(s->val, j)); + for(i = 0; i < List_Nbr(Symbol_L); i++) { + s = (Symbol *) List_Pointer(Symbol_L, i); + for(j = 0; j < List_Nbr(s->val); j++) { + nxs.n = (int)(*(double *)List_Pointer(s->val, j)); nxs.s = s->Name; List_Add(NumxSymb, &nxs); } @@ -380,50 +479,82 @@ List_T* GetVisibilityList(int type){ Tree_Action(THEM->Curves, AddCurve); Tree_Action(THEM->Surfaces, AddSurface); Tree_Action(THEM->Volumes, AddVolume); - + List_Sort(ElementaryEntities, CompareEntity); List_Sort(PhysicalEntities, CompareEntity); - switch(type){ - case ELEMENTARY : return ElementaryEntities; - case PHYSICAL : return PhysicalEntities; - default : return NULL; + switch (type) { + case ELEMENTARY: + return ElementaryEntities; + case PHYSICAL: + return PhysicalEntities; + default: + return NULL; } } -void ClearVisibilityList(int type){ +void ClearVisibilityList(int type) +{ int i; Entity *e; - List_T *list = (type==ELEMENTARY) ? ElementaryEntities : PhysicalEntities; - for(i=0;i<List_Nbr(list);i++){ - e = (Entity*)List_Pointer(list, i); + List_T *list = (type == ELEMENTARY) ? ElementaryEntities : PhysicalEntities; + for(i = 0; i < List_Nbr(list); i++) { + e = (Entity *) List_Pointer(list, i); e->Visible(0); } } -void InitVisibilityThroughPhysical(){ +void InitVisibilityThroughPhysical() +{ int i; - for(i=0;i<4;i++){ - if(VisibleThroughPhysical[i]) Tree_Delete(VisibleThroughPhysical[i]); - VisibleThroughPhysical[i] = Tree_Create(sizeof(int),fcmp_absint); + for(i = 0; i < 4; i++) { + if(VisibleThroughPhysical[i]) + Tree_Delete(VisibleThroughPhysical[i]); + VisibleThroughPhysical[i] = Tree_Create(sizeof(int), fcmp_absint); } } static int vnod, velm, vcur, vsur, vvol; -static void vis_nod(void *a, void *b){ (*(Vertex**)a)->Visible = vnod; } -static void vis_sim(void *a, void *b){ (*(Simplex**)a)->Visible = velm; } -static void vis_hex(void *a, void *b){ (*(Hexahedron**)a)->Visible = velm; } -static void vis_pri(void *a, void *b){ (*(Prism**)a)->Visible = velm; } -static void vis_pyr(void *a, void *b){ (*(Pyramid**)a)->Visible = velm; } -static void vis_cur(void *a, void *b){ (*(Curve**)a)->Visible = vcur; } -static void vis_sur(void *a, void *b){ (*(Surface**)a)->Visible = vsur; } -static void vis_vol(void *a, void *b){ (*(Volume**)a)->Visible = vvol; } - -void SetVisibilityByNumber(char *str, int type, int mode){ - static int allnod=1, allelm=1, allpnt=1, allcur=1, allsur=1, allvol=1; +static void vis_nod(void *a, void *b) +{ + (*(Vertex **) a)->Visible = vnod; +} +static void vis_sim(void *a, void *b) +{ + (*(Simplex **) a)->Visible = velm; +} +static void vis_hex(void *a, void *b) +{ + (*(Hexahedron **) a)->Visible = velm; +} +static void vis_pri(void *a, void *b) +{ + (*(Prism **) a)->Visible = velm; +} +static void vis_pyr(void *a, void *b) +{ + (*(Pyramid **) a)->Visible = velm; +} +static void vis_cur(void *a, void *b) +{ + (*(Curve **) a)->Visible = vcur; +} +static void vis_sur(void *a, void *b) +{ + (*(Surface **) a)->Visible = vsur; +} +static void vis_vol(void *a, void *b) +{ + (*(Volume **) a)->Visible = vvol; +} + +void SetVisibilityByNumber(char *str, int type, int mode) +{ + static int allnod = 1, allelm = 1, allpnt = 1, allcur = 1, allsur = + 1, allvol = 1; int i, found, num; List_T *tmp; - Vertex vv,*v,**pv; + Vertex vv, *v, **pv; Curve *c; Surface *s; Volume *V; @@ -432,134 +563,163 @@ void SetVisibilityByNumber(char *str, int type, int mode){ Prism PP, *P, **pP; Pyramid QQ, *Q, **pQ; - if (!strcmp(str,"all") || !strcmp(str,"*")){ - switch(type){ - case 0: //node + if(!strcmp(str, "all") || !strcmp(str, "*")) { + switch (type) { + case 0: //node allnod = !allnod; vnod = allnod ? VIS_MESH : 0; Tree_Action(THEM->Vertices, vis_nod); break; - case 1: //element + case 1: //element allelm = !allelm; velm = allelm ? VIS_MESH : 0; tmp = Tree2List(THEM->Curves); - for(i=0; i<List_Nbr(tmp); i++){ - List_Read(tmp, i, &c); - Tree_Action(c->Simplexes, vis_sim); + for(i = 0; i < List_Nbr(tmp); i++) { + List_Read(tmp, i, &c); + Tree_Action(c->Simplexes, vis_sim); } List_Delete(tmp); tmp = Tree2List(THEM->Surfaces); - for(i=0; i<List_Nbr(tmp); i++){ - List_Read(tmp, i, &s); - Tree_Action(s->Simplexes, vis_sim); + for(i = 0; i < List_Nbr(tmp); i++) { + List_Read(tmp, i, &s); + Tree_Action(s->Simplexes, vis_sim); } List_Delete(tmp); Tree_Action(THEM->Simplexes, vis_sim); tmp = Tree2List(THEM->Volumes); - for(i=0; i<List_Nbr(tmp); i++){ - List_Read(tmp, i, &V); - Tree_Action(V->Hexahedra, vis_hex); - Tree_Action(V->Prisms, vis_pri); - Tree_Action(V->Pyramids, vis_pyr); + for(i = 0; i < List_Nbr(tmp); i++) { + List_Read(tmp, i, &V); + Tree_Action(V->Hexahedra, vis_hex); + Tree_Action(V->Prisms, vis_pri); + Tree_Action(V->Pyramids, vis_pyr); } List_Delete(tmp); break; - case 2: //point + case 2: //point allpnt = !allpnt; - vnod = allpnt ? VIS_MESH|VIS_GEOM : 0; + vnod = allpnt ? VIS_MESH | VIS_GEOM : 0; Tree_Action(THEM->Points, vis_nod); break; - case 3: //curve + case 3: //curve allcur = !allcur; - vcur = allcur ? VIS_MESH|VIS_GEOM : 0; + vcur = allcur ? VIS_MESH | VIS_GEOM : 0; Tree_Action(THEM->Curves, vis_cur); break; - case 4: //surface + case 4: //surface allsur = !allsur; - vsur = allsur ? VIS_MESH|VIS_GEOM : 0; + vsur = allsur ? VIS_MESH | VIS_GEOM : 0; Tree_Action(THEM->Surfaces, vis_sur); break; - case 5: //volume - allvol= !allvol; - vvol = allvol ? VIS_MESH|VIS_GEOM : 0; + case 5: //volume + allvol = !allvol; + vvol = allvol ? VIS_MESH | VIS_GEOM : 0; Tree_Action(THEM->Volumes, vis_vol); break; } } - else{ + else { num = atoi(str); - switch(type){ - case 0: //node - vv.Num = num; v = &vv; - if((pv = (Vertex**)Tree_PQuery(THEM->Vertices, &v))) - (*pv)->Visible = (*pv)->Visible ? 0 : VIS_MESH; + switch (type) { + case 0: //node + vv.Num = num; + v = &vv; + if((pv = (Vertex **) Tree_PQuery(THEM->Vertices, &v))) + (*pv)->Visible = (*pv)->Visible ? 0 : VIS_MESH; else - Msg(WARNING, "Unknown node %d (use '*' to hide/show all nodes)", num); + Msg(WARNING, "Unknown node %d (use '*' to hide/show all nodes)", num); break; - case 1: //element - SS.Num = num; S = &SS; - HH.Num = num; H = &HH; - PP.Num = num; P = &PP; - QQ.Num = num; Q = &QQ; + case 1: //element + SS.Num = num; + S = &SS; + HH.Num = num; + H = &HH; + PP.Num = num; + P = &PP; + QQ.Num = num; + Q = &QQ; found = 0; tmp = Tree2List(THEM->Curves); - for(i=0; i<List_Nbr(tmp); i++){ - List_Read(tmp, i, &c); - if((pS = (Simplex**)Tree_PQuery(c->Simplexes, &S))){ - (*pS)->Visible = (*pS)->Visible ? 0 : VIS_MESH; found = 1; break; - } + for(i = 0; i < List_Nbr(tmp); i++) { + List_Read(tmp, i, &c); + if((pS = (Simplex **) Tree_PQuery(c->Simplexes, &S))) { + (*pS)->Visible = (*pS)->Visible ? 0 : VIS_MESH; + found = 1; + break; + } } List_Delete(tmp); - if(!found){ - tmp = Tree2List(THEM->Surfaces); - for(i=0; i<List_Nbr(tmp); i++){ - List_Read(tmp, i, &s); - if((pS = (Simplex**)Tree_PQuery(s->Simplexes, &S))){ - (*pS)->Visible = (*pS)->Visible ? 0 : VIS_MESH; found = 1; break; - } - } - List_Delete(tmp); - if(!found){ - if((pS = (Simplex**)Tree_PQuery(THEM->Simplexes, &S))){ - (*pS)->Visible = (*pS)->Visible ? 0 : VIS_MESH; - } - else{ - tmp = Tree2List(THEM->Volumes); - for(i=0; i<List_Nbr(tmp); i++){ - List_Read(tmp, i, &V); - if((pH = (Hexahedron**)Tree_PQuery(V->Hexahedra, &H))){ - (*pH)->Visible = (*pH)->Visible ? 0 : VIS_MESH; found = 1; break; - } - if((pP = (Prism**)Tree_PQuery(V->Prisms, &P))){ - (*pP)->Visible = (*pP)->Visible ? 0 : VIS_MESH; found = 1; break; - } - if((pQ = (Pyramid**)Tree_PQuery(V->Pyramids, &Q))){ - (*pQ)->Visible = (*pQ)->Visible ? 0 : VIS_MESH; found = 1; break; - } - } - List_Delete(tmp); - if(!found) - Msg(WARNING, "Unknown element %d (use '*' to hide/show all elements)", num); - } - } + if(!found) { + tmp = Tree2List(THEM->Surfaces); + for(i = 0; i < List_Nbr(tmp); i++) { + List_Read(tmp, i, &s); + if((pS = (Simplex **) Tree_PQuery(s->Simplexes, &S))) { + (*pS)->Visible = (*pS)->Visible ? 0 : VIS_MESH; + found = 1; + break; + } + } + List_Delete(tmp); + if(!found) { + if((pS = (Simplex **) Tree_PQuery(THEM->Simplexes, &S))) { + (*pS)->Visible = (*pS)->Visible ? 0 : VIS_MESH; + } + else { + tmp = Tree2List(THEM->Volumes); + for(i = 0; i < List_Nbr(tmp); i++) { + List_Read(tmp, i, &V); + if((pH = (Hexahedron **) Tree_PQuery(V->Hexahedra, &H))) { + (*pH)->Visible = (*pH)->Visible ? 0 : VIS_MESH; + found = 1; + break; + } + if((pP = (Prism **) Tree_PQuery(V->Prisms, &P))) { + (*pP)->Visible = (*pP)->Visible ? 0 : VIS_MESH; + found = 1; + break; + } + if((pQ = (Pyramid **) Tree_PQuery(V->Pyramids, &Q))) { + (*pQ)->Visible = (*pQ)->Visible ? 0 : VIS_MESH; + found = 1; + break; + } + } + List_Delete(tmp); + if(!found) + Msg(WARNING, + "Unknown element %d (use '*' to hide/show all elements)", + num); + } + } } break; - case 2: //point - if((v=FindPoint(num,THEM))) v->Visible = v->Visible ? 0 : VIS_GEOM|VIS_MESH ; - else Msg(WARNING, "Unknown point %d (use '*' to hide/show all points)", num); + case 2: //point + if((v = FindPoint(num, THEM))) + v->Visible = v->Visible ? 0 : VIS_GEOM | VIS_MESH; + else + Msg(WARNING, "Unknown point %d (use '*' to hide/show all points)", + num); break; - case 3: //curve - if((c=FindCurve(num,THEM))) c->Visible = c->Visible ? 0 : VIS_GEOM|VIS_MESH ; - else Msg(WARNING, "Unknown curve %d (use '*' to hide/show all curves)", num); + case 3: //curve + if((c = FindCurve(num, THEM))) + c->Visible = c->Visible ? 0 : VIS_GEOM | VIS_MESH; + else + Msg(WARNING, "Unknown curve %d (use '*' to hide/show all curves)", + num); break; - case 4: //surface - if((s=FindSurface(num,THEM))) s->Visible = s->Visible ? 0 : VIS_GEOM|VIS_MESH ; - else Msg(WARNING, "Unknown surface %d (use '*' to hide/show all surfaces)", num); + case 4: //surface + if((s = FindSurface(num, THEM))) + s->Visible = s->Visible ? 0 : VIS_GEOM | VIS_MESH; + else + Msg(WARNING, "Unknown surface %d (use '*' to hide/show all surfaces)", + num); break; - case 5: //volume - if((V=FindVolume(num,THEM))) V->Visible = V->Visible ? 0 : VIS_GEOM|VIS_MESH ; - else Msg(WARNING, "Unknown volume %d (use '*' to hide/show all volumes)", num); + case 5: //volume + if((V = FindVolume(num, THEM))) + V->Visible = V->Visible ? 0 : VIS_GEOM | VIS_MESH; + else + Msg(WARNING, "Unknown volume %d (use '*' to hide/show all volumes)", + num); break; } } diff --git a/Graphics/gl2gif.cpp b/Graphics/gl2gif.cpp index 84d21a60a83d558fdeb807fae4e79fe6442f884b..bdf4f6c7f85c07d19b1b5ab768c12a3b37a94caa 100644 --- a/Graphics/gl2gif.cpp +++ b/Graphics/gl2gif.cpp @@ -2,7 +2,7 @@ * GL2GIF, an OpenGL to GIF Printing Library * Copyright (C) 1999-2002 Christophe Geuzaine * - * $Id: gl2gif.cpp,v 1.16 2003-02-25 04:02:50 geuzaine Exp $ + * $Id: gl2gif.cpp,v 1.17 2003-03-01 22:36:40 geuzaine Exp $ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -60,81 +60,85 @@ #define HASH_SIZE 20023 #define ppm_hashpixel(p) ( ( (int) (p) & 0x7fffffff ) % HASH_SIZE ) -static int static_red[MAX_GIFCOLORS]; -static int static_green[MAX_GIFCOLORS]; -static int static_blue[MAX_GIFCOLORS]; -static int static_perm[MAX_GIFCOLORS], static_permi[MAX_GIFCOLORS]; -static int static_nbcolors; -static pixel** static_pixels; +static int static_red[MAX_GIFCOLORS]; +static int static_green[MAX_GIFCOLORS]; +static int static_blue[MAX_GIFCOLORS]; +static int static_perm[MAX_GIFCOLORS], static_permi[MAX_GIFCOLORS]; +static int static_nbcolors; +static pixel **static_pixels; static colorhash_table static_cht; -colorhash_table ppm_alloccolorhash( ){ +colorhash_table ppm_alloccolorhash() +{ colorhash_table cht; int i; - - cht = (colorhash_table) Malloc( HASH_SIZE * sizeof(colorhist_list) ); - for ( i = 0; i < HASH_SIZE; ++i ) + cht = (colorhash_table) Malloc(HASH_SIZE * sizeof(colorhist_list)); + + for(i = 0; i < HASH_SIZE; ++i) cht[i] = (colorhist_list) 0; - + return cht; } -void ppm_freecolorhash( colorhash_table cht ){ +void ppm_freecolorhash(colorhash_table cht) +{ int i; colorhist_list chl, chlnext; - - for ( i = 0; i < HASH_SIZE; ++i ) - for ( chl = cht[i]; chl != (colorhist_list) 0; chl = chlnext ){ + + for(i = 0; i < HASH_SIZE; ++i) + for(chl = cht[i]; chl != (colorhist_list) 0; chl = chlnext) { chlnext = chl->next; - Free( (char*) chl ); + Free((char *)chl); } - Free( (char*) cht ); + Free((char *)cht); } -colorhash_table ppm_computecolorhash( pixel ** const pixels, - const int cols, const int rows, - const int maxcolors, int * const colorsP ){ +colorhash_table ppm_computecolorhash(pixel ** const pixels, + const int cols, const int rows, + const int maxcolors, int *const colorsP) +{ colorhash_table cht; - const pixel* pP; + const pixel *pP; colorhist_list chl; int col, row, hash; - - cht = ppm_alloccolorhash( ); + + cht = ppm_alloccolorhash(); *colorsP = 0; - + /* Go through the entire image, building a hash table of colors. */ - for ( row = 0; row < rows; ++row ) - for ( col = 0, pP = pixels[row]; col < cols; ++col, ++pP ){ - hash = ppm_hashpixel( *pP ); - for ( chl = cht[hash]; chl != (colorhist_list) 0; chl = chl->next ) - if ( PPM_EQUAL( chl->ch.color, *pP ) ) - break; - if ( chl != (colorhist_list) 0 ) - ++(chl->ch.value); - else{ - if ( ++(*colorsP) > maxcolors ){ - ppm_freecolorhash( cht ); - return (colorhash_table) 0; - } - chl = (colorhist_list) Malloc( sizeof(struct colorhist_list_item) ); - chl->ch.color = *pP; - chl->ch.value = 1; - chl->next = cht[hash]; - cht[hash] = chl; + for(row = 0; row < rows; ++row) + for(col = 0, pP = pixels[row]; col < cols; ++col, ++pP) { + hash = ppm_hashpixel(*pP); + for(chl = cht[hash]; chl != (colorhist_list) 0; chl = chl->next) + if(PPM_EQUAL(chl->ch.color, *pP)) + break; + if(chl != (colorhist_list) 0) + ++(chl->ch.value); + else { + if(++(*colorsP) > maxcolors) { + ppm_freecolorhash(cht); + return (colorhash_table) 0; + } + chl = (colorhist_list) Malloc(sizeof(struct colorhist_list_item)); + chl->ch.color = *pP; + chl->ch.value = 1; + chl->next = cht[hash]; + cht[hash] = chl; } } - + return cht; } -int ppm_addtocolorhash( colorhash_table cht, const pixel * const colorP, - const int value ){ +int ppm_addtocolorhash(colorhash_table cht, const pixel * const colorP, + const int value) +{ register int hash; register colorhist_list chl; - - chl = (colorhist_list) Malloc( sizeof(struct colorhist_list_item) ); - hash = ppm_hashpixel( *colorP ); + + chl = (colorhist_list) Malloc(sizeof(struct colorhist_list_item)); + hash = ppm_hashpixel(*colorP); chl->ch.color = *colorP; chl->ch.value = value; chl->next = cht[hash]; @@ -142,142 +146,152 @@ int ppm_addtocolorhash( colorhash_table cht, const pixel * const colorP, return 0; } -colorhist_vector ppm_colorhashtocolorhist( const colorhash_table cht, - const int maxcolors ){ +colorhist_vector ppm_colorhashtocolorhist(const colorhash_table cht, + const int maxcolors) +{ colorhist_vector chv; colorhist_list chl; int i, j; - + /* Now collate the hash table into a simple colorhist array. */ - chv = (colorhist_vector) Malloc( maxcolors * sizeof(struct colorhist_item) ); + chv = (colorhist_vector) Malloc(maxcolors * sizeof(struct colorhist_item)); /* Loop through the hash table. */ j = 0; - for ( i = 0; i < HASH_SIZE; ++i ) - for ( chl = cht[i]; chl != (colorhist_list) 0; chl = chl->next ){ + for(i = 0; i < HASH_SIZE; ++i) + for(chl = cht[i]; chl != (colorhist_list) 0; chl = chl->next) { /* Add the new entry. */ chv[j] = chl->ch; ++j; } - + /* All done. */ return chv; } -colorhash_table ppm_colorhisttocolorhash( const colorhist_vector chv, - const int colors ){ +colorhash_table ppm_colorhisttocolorhash(const colorhist_vector chv, + const int colors) +{ colorhash_table cht; int i, hash; pixel color; colorhist_list chl; - - cht = ppm_alloccolorhash( ); /* Initializes to NULLs */ - - for ( i = 0; i < colors; ++i ){ + + cht = ppm_alloccolorhash(); /* Initializes to NULLs */ + + for(i = 0; i < colors; ++i) { color = chv[i].color; - hash = ppm_hashpixel( color ); - for ( chl = cht[hash]; chl != (colorhist_list) 0; chl = chl->next ) - if ( PPM_EQUAL( chl->ch.color, color ) ) - Msg(GERROR, "GIF: same color found twice - %d %d %d", PPM_GETR(color), - PPM_GETG(color), PPM_GETB(color) ); - chl = (colorhist_list) Malloc( sizeof(struct colorhist_list_item) ); + hash = ppm_hashpixel(color); + for(chl = cht[hash]; chl != (colorhist_list) 0; chl = chl->next) + if(PPM_EQUAL(chl->ch.color, color)) + Msg(GERROR, "GIF: same color found twice - %d %d %d", PPM_GETR(color), + PPM_GETG(color), PPM_GETB(color)); + chl = (colorhist_list) Malloc(sizeof(struct colorhist_list_item)); chl->ch.color = color; chl->ch.value = i; chl->next = cht[hash]; cht[hash] = chl; } - + return cht; } -colorhist_vector ppm_computecolorhist( pixel ** const pixels, - const int cols, const int rows, - const int maxcolors, - int * const colorsP ){ +colorhist_vector ppm_computecolorhist(pixel ** const pixels, + const int cols, const int rows, + const int maxcolors, int *const colorsP) +{ colorhash_table cht; colorhist_vector chv; - - cht = ppm_computecolorhash( pixels, cols, rows, maxcolors, colorsP ); - if ( cht == (colorhash_table) 0 ) + + cht = ppm_computecolorhash(pixels, cols, rows, maxcolors, colorsP); + if(cht == (colorhash_table) 0) return (colorhist_vector) 0; - chv = ppm_colorhashtocolorhist( cht, maxcolors ); - ppm_freecolorhash( cht ); + chv = ppm_colorhashtocolorhist(cht, maxcolors); + ppm_freecolorhash(cht); return chv; } -int ppm_lookupcolor( const colorhash_table cht, const pixel * const colorP ){ +int ppm_lookupcolor(const colorhash_table cht, const pixel * const colorP) +{ int hash; colorhist_list chl; - - hash = ppm_hashpixel( *colorP ); - for ( chl = cht[hash]; chl != (colorhist_list) 0; chl = chl->next ) - if ( PPM_EQUAL( chl->ch.color, *colorP ) ) + + hash = ppm_hashpixel(*colorP); + for(chl = cht[hash]; chl != (colorhist_list) 0; chl = chl->next) + if(PPM_EQUAL(chl->ch.color, *colorP)) return chl->ch.value; - + return -1; } -void ppm_freecolorhist( colorhist_vector chv ){ - Free( (char*) chv ); +void ppm_freecolorhist(colorhist_vector chv) +{ + Free((char *)chv); } -static int colorstobpp( int colors ){ +static int colorstobpp(int colors) +{ int bpp; - if ( colors <= 2 ) + if(colors <= 2) bpp = 1; - else if ( colors <= 4 ) + else if(colors <= 4) bpp = 2; - else if ( colors <= 8 ) + else if(colors <= 8) bpp = 3; - else if ( colors <= 16 ) + else if(colors <= 16) bpp = 4; - else if ( colors <= 32 ) + else if(colors <= 32) bpp = 5; - else if ( colors <= 64 ) + else if(colors <= 64) bpp = 6; - else if ( colors <= 128 ) + else if(colors <= 128) bpp = 7; - else if ( colors <= 256 ) + else if(colors <= 256) + bpp = 8; + else { + Msg(GERROR, "GIF: can't happen: too many colors"); bpp = 8; - else{ - Msg(GERROR, "GIF: can't happen: too many colors" ); - bpp = 8 ; } return bpp; } -static int sqr(int x){ - return x*x; +static int sqr(int x) +{ + return x * x; } -static int closestcolor(pixel color){ - int i,r,g,b,d,imin=0,dmin; - - r=(int)PPM_GETR(color); - g=(int)PPM_GETG(color); - b=(int)PPM_GETB(color); - - dmin=1000000; - for (i=0 ; i<static_nbcolors ; i++) { - d = sqr(r-static_red[i]) + sqr(g-static_green[i]) + sqr(b-static_blue[i]); - if (d<dmin) { - dmin=d; - imin=i; - } +static int closestcolor(pixel color) +{ + int i, r, g, b, d, imin = 0, dmin; + + r = (int)PPM_GETR(color); + g = (int)PPM_GETG(color); + b = (int)PPM_GETB(color); + + dmin = 1000000; + for(i = 0; i < static_nbcolors; i++) { + d = + sqr(r - static_red[i]) + sqr(g - static_green[i]) + sqr(b - + static_blue[i]); + if(d < dmin) { + dmin = d; + imin = i; + } } - ppm_addtocolorhash(static_cht,&color,static_permi[imin]); + ppm_addtocolorhash(static_cht, &color, static_permi[imin]); return imin; } -static int GetPixel( int x, int y ){ +static int GetPixel(int x, int y) +{ int color; - - color = ppm_lookupcolor( static_cht, &static_pixels[y][x] ); - if (color == -1) + + color = ppm_lookupcolor(static_cht, &static_pixels[y][x]); + if(color == -1) color = closestcolor(static_pixels[y][x]); else color = static_perm[color]; @@ -294,30 +308,35 @@ static int GetPixel( int x, int y ){ /* #define REP_AVERAGE_COLORS */ #define REP_AVERAGE_PIXELS -typedef struct box* box_vector; -struct box{ +typedef struct box *box_vector; +struct box +{ int ind; int colors; int sum; }; -static int redcompare( const void *ch1, const void *ch2 ){ - return (int) PPM_GETR( ((colorhist_vector)ch1)->color ) - - (int) PPM_GETR( ((colorhist_vector)ch2)->color ); +static int redcompare(const void *ch1, const void *ch2) +{ + return (int)PPM_GETR(((colorhist_vector) ch1)->color) - + (int)PPM_GETR(((colorhist_vector) ch2)->color); } -static int greencompare( const void *ch1, const void *ch2 ) { - return (int) PPM_GETG(((colorhist_vector) ch1)->color ) - - (int) PPM_GETG( ((colorhist_vector)ch2)->color ); +static int greencompare(const void *ch1, const void *ch2) +{ + return (int)PPM_GETG(((colorhist_vector) ch1)->color) - + (int)PPM_GETG(((colorhist_vector) ch2)->color); } -static int bluecompare(const void *ch1, const void *ch2 ) { - return (int) PPM_GETB(((colorhist_vector)ch1)->color ) - - (int) PPM_GETB(((colorhist_vector)ch2)->color ); +static int bluecompare(const void *ch1, const void *ch2) +{ + return (int)PPM_GETB(((colorhist_vector) ch1)->color) - + (int)PPM_GETB(((colorhist_vector) ch2)->color); } -static int sumcompare(const void *b1, const void *b2 ) { - return(((box_vector)b2)->sum - ((box_vector)b1)->sum); +static int sumcompare(const void *b1, const void *b2) +{ + return (((box_vector) b2)->sum - ((box_vector) b1)->sum); } /* @@ -326,21 +345,22 @@ static int sumcompare(const void *b1, const void *b2 ) { * Display", SIGGRAPH '82 Proceedings, page 297. */ -static colorhist_vector mediancut( colorhist_vector chv, int colors, - int sum, pixval maxval, int newcolors ){ +static colorhist_vector mediancut(colorhist_vector chv, int colors, + int sum, pixval maxval, int newcolors) +{ colorhist_vector colormap; box_vector bv; register int bi, i; int boxes; - - bv = (box_vector) malloc( sizeof(struct box) * newcolors ); + + bv = (box_vector) malloc(sizeof(struct box) * newcolors); colormap = - (colorhist_vector) malloc( sizeof(struct colorhist_item) * newcolors ); - if ( bv == (box_vector) 0 || colormap == (colorhist_vector) 0 ) - Msg(GERROR, "GIF: out of memory" ); - for ( i = 0; i < newcolors; ++i ) - PPM_ASSIGN( colormap[i].color, 0, 0, 0 ); - + (colorhist_vector) malloc(sizeof(struct colorhist_item) * newcolors); + if(bv == (box_vector) 0 || colormap == (colorhist_vector) 0) + Msg(GERROR, "GIF: out of memory"); + for(i = 0; i < newcolors; ++i) + PPM_ASSIGN(colormap[i].color, 0, 0, 0); + /* * Set up the initial box. */ @@ -348,47 +368,53 @@ static colorhist_vector mediancut( colorhist_vector chv, int colors, bv[0].colors = colors; bv[0].sum = sum; boxes = 1; - + /* * Main loop: split boxes until we have enough. */ - while ( boxes < newcolors ){ + while(boxes < newcolors) { register int indx, clrs; int sm; register int minr, maxr, ming, maxg, minb, maxb, v; int halfsum, lowersum; - + /* - * Find the first splittable box. - */ - for ( bi = 0; bi < boxes; ++bi ) - if ( bv[bi].colors >= 2 ) - break; - if ( bi == boxes ) - break; /* ran out of colors! */ + * Find the first splittable box. + */ + for(bi = 0; bi < boxes; ++bi) + if(bv[bi].colors >= 2) + break; + if(bi == boxes) + break; /* ran out of colors! */ indx = bv[bi].ind; clrs = bv[bi].colors; sm = bv[bi].sum; - + /* * Go through the box finding the minimum and maximum of each * component - the boundaries of the box. */ - minr = maxr = PPM_GETR( chv[indx].color ); - ming = maxg = PPM_GETG( chv[indx].color ); - minb = maxb = PPM_GETB( chv[indx].color ); - for ( i = 1; i < clrs; ++i ){ - v = PPM_GETR( chv[indx + i].color ); - if ( v < minr ) minr = v; - if ( v > maxr ) maxr = v; - v = PPM_GETG( chv[indx + i].color ); - if ( v < ming ) ming = v; - if ( v > maxg ) maxg = v; - v = PPM_GETB( chv[indx + i].color ); - if ( v < minb ) minb = v; - if ( v > maxb ) maxb = v; + minr = maxr = PPM_GETR(chv[indx].color); + ming = maxg = PPM_GETG(chv[indx].color); + minb = maxb = PPM_GETB(chv[indx].color); + for(i = 1; i < clrs; ++i) { + v = PPM_GETR(chv[indx + i].color); + if(v < minr) + minr = v; + if(v > maxr) + maxr = v; + v = PPM_GETG(chv[indx + i].color); + if(v < ming) + ming = v; + if(v > maxg) + maxg = v; + v = PPM_GETB(chv[indx + i].color); + if(v < minb) + minb = v; + if(v > maxb) + maxb = v; } - + /* * Find the largest dimension, and sort by that component. I have * included two methods for determining the "largest" dimension; @@ -398,16 +424,16 @@ static colorhist_vector mediancut( colorhist_vector chv, int colors, * the LARGE_ defines at the beginning of this source file. */ #ifdef LARGE_NORM - if ( maxr - minr >= maxg - ming && maxr - minr >= maxb - minb ) - qsort( (char*) &(chv[indx]), clrs, sizeof(struct colorhist_item), - redcompare ); - else if ( maxg - ming >= maxb - minb ) - qsort( (char*) &(chv[indx]), clrs, sizeof(struct colorhist_item), - greencompare ); + if(maxr - minr >= maxg - ming && maxr - minr >= maxb - minb) + qsort((char *)&(chv[indx]), clrs, sizeof(struct colorhist_item), + redcompare); + else if(maxg - ming >= maxb - minb) + qsort((char *)&(chv[indx]), clrs, sizeof(struct colorhist_item), + greencompare); else - qsort( (char*) &(chv[indx]), clrs, sizeof(struct colorhist_item), - bluecompare ); -#endif + qsort((char *)&(chv[indx]), clrs, sizeof(struct colorhist_item), + bluecompare); +#endif #ifdef LARGE_LUM pixel p; @@ -419,40 +445,40 @@ static colorhist_vector mediancut( colorhist_vector chv, int colors, gl = PPM_LUMIN(p); PPM_ASSIGN(p, 0, 0, maxb - minb); bl = PPM_LUMIN(p); - - if ( rl >= gl && rl >= bl ) - qsort( (char*) &(chv[indx]), clrs, sizeof(struct colorhist_item), - &redcompare ); - else if ( gl >= bl ) - qsort( (char*) &(chv[indx]), clrs, sizeof(struct colorhist_item), - &greencompare ); + + if(rl >= gl && rl >= bl) + qsort((char *)&(chv[indx]), clrs, sizeof(struct colorhist_item), + &redcompare); + else if(gl >= bl) + qsort((char *)&(chv[indx]), clrs, sizeof(struct colorhist_item), + &greencompare); else - qsort( (char*) &(chv[indx]), clrs, sizeof(struct colorhist_item), - &bluecompare ); + qsort((char *)&(chv[indx]), clrs, sizeof(struct colorhist_item), + &bluecompare); #endif - + /* * Now find the median based on the counts, so that about half the * pixels (not colors, pixels) are in each subdivision. */ lowersum = chv[indx].value; halfsum = sm / 2; - for ( i = 1; i < clrs - 1; ++i ){ - if ( lowersum >= halfsum ) - break; + for(i = 1; i < clrs - 1; ++i) { + if(lowersum >= halfsum) + break; lowersum += chv[indx + i].value; } - + /* - * Split the box, and sort to bring the biggest boxes to the top. - */ + * Split the box, and sort to bring the biggest boxes to the top. + */ bv[bi].colors = i; bv[bi].sum = lowersum; bv[boxes].ind = indx + i; bv[boxes].colors = clrs - i; bv[boxes].sum = sm - lowersum; ++boxes; - qsort( (char*) bv, boxes, sizeof(struct box), sumcompare ); + qsort((char *)bv, boxes, sizeof(struct box), sumcompare); } /* @@ -465,68 +491,71 @@ static colorhist_vector mediancut( colorhist_vector chv, int colors, * method is used by switching the commenting on the REP_ defines at * the beginning of this source file. */ - for ( bi = 0; bi < boxes; ++bi ){ + for(bi = 0; bi < boxes; ++bi) { #ifdef REP_CENTER_BOX register int indx = bv[bi].ind; register int clrs = bv[bi].colors; register int minr, maxr, ming, maxg, minb, maxb, v; - - minr = maxr = PPM_GETR( chv[indx].color ); - ming = maxg = PPM_GETG( chv[indx].color ); - minb = maxb = PPM_GETB( chv[indx].color ); - for ( i = 1; i < clrs; ++i ){ - v = PPM_GETR( chv[indx + i].color ); - minr = min( minr, v ); - maxr = max( maxr, v ); - v = PPM_GETG( chv[indx + i].color ); - ming = min( ming, v ); - maxg = max( maxg, v ); - v = PPM_GETB( chv[indx + i].color ); - minb = min( minb, v ); - maxb = max( maxb, v ); + + minr = maxr = PPM_GETR(chv[indx].color); + ming = maxg = PPM_GETG(chv[indx].color); + minb = maxb = PPM_GETB(chv[indx].color); + for(i = 1; i < clrs; ++i) { + v = PPM_GETR(chv[indx + i].color); + minr = min(minr, v); + maxr = max(maxr, v); + v = PPM_GETG(chv[indx + i].color); + ming = min(ming, v); + maxg = max(maxg, v); + v = PPM_GETB(chv[indx + i].color); + minb = min(minb, v); + maxb = max(maxb, v); } - PPM_ASSIGN( colormap[bi].color, ( minr + maxr ) / 2, ( ming + maxg ) / 2, - ( minb + maxb ) / 2 ); + PPM_ASSIGN(colormap[bi].color, (minr + maxr) / 2, (ming + maxg) / 2, + (minb + maxb) / 2); #endif #ifdef REP_AVERAGE_COLORS register int indx = bv[bi].ind; register int clrs = bv[bi].colors; register long r = 0, g = 0, b = 0; - - for ( i = 0; i < clrs; ++i ){ - r += PPM_GETR( chv[indx + i].color ); - g += PPM_GETG( chv[indx + i].color ); - b += PPM_GETB( chv[indx + i].color ); + + for(i = 0; i < clrs; ++i) { + r += PPM_GETR(chv[indx + i].color); + g += PPM_GETG(chv[indx + i].color); + b += PPM_GETB(chv[indx + i].color); } r = r / clrs; g = g / clrs; b = b / clrs; - PPM_ASSIGN( colormap[bi].color, r, g, b ); + PPM_ASSIGN(colormap[bi].color, r, g, b); #endif #ifdef REP_AVERAGE_PIXELS register int indx = bv[bi].ind; register int clrs = bv[bi].colors; register long r = 0, g = 0, b = 0, sum = 0; - - for ( i = 0; i < clrs; ++i ){ - r += PPM_GETR( chv[indx + i].color ) * chv[indx + i].value; - g += PPM_GETG( chv[indx + i].color ) * chv[indx + i].value; - b += PPM_GETB( chv[indx + i].color ) * chv[indx + i].value; + + for(i = 0; i < clrs; ++i) { + r += PPM_GETR(chv[indx + i].color) * chv[indx + i].value; + g += PPM_GETG(chv[indx + i].color) * chv[indx + i].value; + b += PPM_GETB(chv[indx + i].color) * chv[indx + i].value; sum += chv[indx + i].value; } r = r / sum; - if ( r > (long)maxval ) r = maxval; /* avoid math errors */ + if(r > (long)maxval) + r = maxval; /* avoid math errors */ g = g / sum; - if ( g > (long)maxval ) g = maxval; + if(g > (long)maxval) + g = maxval; b = b / sum; - if ( b > (long)maxval ) b = maxval; - PPM_ASSIGN( colormap[bi].color, r, g, b ); + if(b > (long)maxval) + b = maxval; + PPM_ASSIGN(colormap[bi].color, r, g, b); #endif } - + /* * All done. */ @@ -537,39 +566,39 @@ static colorhist_vector mediancut( colorhist_vector chv, int colors, /* GIF compression routines */ #define BITS 12 -#define HSIZE 5003 /* 80% occupancy */ +#define HSIZE 5003 /* 80% occupancy */ #define TRUE 1 #define FALSE 0 -typedef unsigned char char_type; -typedef int (* ifunptr)(int, int); +typedef unsigned char char_type; +typedef int (*ifunptr) (int, int); -static int g_init_bits; -static FILE* g_outfile; -static int Width, Height; -static int curx, cury; -static long CountDown; -static int Pass = 0; -static int Interlace; +static int g_init_bits; +static FILE *g_outfile; +static int Width, Height; +static int curx, cury; +static long CountDown; +static int Pass = 0; +static int Interlace; #include <ctype.h> #define ARGVAL() (*++(*argv) || (--argc && *++argv)) -static int n_bits; /* number of bits/code */ -static int maxbits = BITS; /* user settable max # bits/code */ -static code_int maxcode; /* maximum code, given n_bits */ -static code_int maxmaxcode = (code_int)1 << BITS; +static int n_bits; /* number of bits/code */ +static int maxbits = BITS; /* user settable max # bits/code */ +static code_int maxcode; /* maximum code, given n_bits */ +static code_int maxmaxcode = (code_int) 1 << BITS; /* should NEVER generate this code */ #define MAXCODE(n_bits) (((code_int) 1 << (n_bits)) - 1) -static count_int htab [HSIZE]; -static unsigned short codetab [HSIZE]; +static count_int htab[HSIZE]; +static unsigned short codetab[HSIZE]; #define HashTabOf(i) htab[i] #define CodeTabOf(i) codetab[i] -static code_int hsize = HSIZE; /* for dynamic table sizing */ +static code_int hsize = HSIZE; /* for dynamic table sizing */ /* * To save much memory, we overlay the table used by compress() with those @@ -584,7 +613,7 @@ static code_int hsize = HSIZE; /* for dynamic table sizing */ #define tab_suffixof(i) ((char_type*)(htab))[i] #define de_stack ((char_type*)&tab_suffixof((code_int)1<<BITS)) -static code_int free_ent = 0; /* first unused entry */ +static code_int free_ent = 0; /* first unused entry */ /* * block compression parameters -- after all codes are used up, @@ -592,8 +621,8 @@ static code_int free_ent = 0; /* first unused entry */ */ static int clear_flg = 0; -static long int in_count = 1; /* length of input */ -static long int out_count = 0; /* # of codes output (for debugging) */ +static long int in_count = 1; /* length of input */ +static long int out_count = 0; /* # of codes output (for debugging) */ static int ClearCode; static int EOFCode; @@ -605,23 +634,25 @@ static int a_count; /* * Set up the 'byte output' routine */ -static void char_init(){ +static void char_init() +{ a_count = 0; } /* * Define the storage for the packet accumulator */ -static char accum[ 256 ]; +static char accum[256]; /* * Flush the packet to disk, and reset the accumulator */ -static void flush_char(){ - if( a_count > 0 ) { - fputc( a_count, g_outfile ); - fwrite( accum, 1, a_count, g_outfile ); +static void flush_char() +{ + if(a_count > 0) { + fputc(a_count, g_outfile); + fwrite(accum, 1, a_count, g_outfile); a_count = 0; } } @@ -630,9 +661,10 @@ static void flush_char(){ * Add a character to the end of the current packet, and if it is 254 * characters, flush the packet to disk. */ -static void char_out( int c){ - accum[ a_count++ ] = c; - if( a_count >= 254 ) +static void char_out(int c) +{ + accum[a_count++] = c; + if(a_count >= 254) flush_char(); } @@ -640,52 +672,53 @@ static void char_out( int c){ * Bump the 'curx' and 'cury' to point to the next pixel */ -static void BumpPixel(){ +static void BumpPixel() +{ /* * Bump the current X position */ ++curx; - + /* * If we are at the end of a scan line, set curx back to the beginning * If we are interlaced, bump the cury to the appropriate spot, * otherwise, just increment it. */ - if( curx == Width ) { + if(curx == Width) { curx = 0; - - if( !Interlace ) + + if(!Interlace) ++cury; else { - switch( Pass ) { - + switch (Pass) { + case 0: - cury += 8; - if( cury >= Height ) { - ++Pass; - cury = 4; - } - break; - + cury += 8; + if(cury >= Height) { + ++Pass; + cury = 4; + } + break; + case 1: - cury += 8; - if( cury >= Height ) { - ++Pass; - cury = 2; - } - break; - + cury += 8; + if(cury >= Height) { + ++Pass; + cury = 2; + } + break; + case 2: - cury += 4; - if( cury >= Height ) { - ++Pass; - cury = 1; - } - break; - + cury += 4; + if(cury >= Height) { + ++Pass; + cury = 1; + } + break; + case 3: - cury += 2; - break; + cury += 2; + break; } } } @@ -695,18 +728,19 @@ static void BumpPixel(){ /* * Return the next pixel from the image */ -static int GIFNextPixel( ifunptr getpixel){ +static int GIFNextPixel(ifunptr getpixel) +{ int r; - if( CountDown == 0 ) + if(CountDown == 0) return EOF; - + --CountDown; - - r = ( * getpixel )( curx, cury ); - + + r = (*getpixel) (curx, cury); + BumpPixel(); - + return r; } @@ -730,60 +764,62 @@ static unsigned long cur_accum = 0; static int cur_bits = 0; static unsigned long masks[] = { 0x0000, 0x0001, 0x0003, 0x0007, 0x000F, - 0x001F, 0x003F, 0x007F, 0x00FF, - 0x01FF, 0x03FF, 0x07FF, 0x0FFF, - 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF }; - -static void output( code_int code){ - cur_accum &= masks[ cur_bits ]; - - if( cur_bits > 0 ) + 0x001F, 0x003F, 0x007F, 0x00FF, + 0x01FF, 0x03FF, 0x07FF, 0x0FFF, + 0x1FFF, 0x3FFF, 0x7FFF, 0xFFFF +}; + +static void output(code_int code) +{ + cur_accum &= masks[cur_bits]; + + if(cur_bits > 0) cur_accum |= ((long)code << cur_bits); else cur_accum = code; - + cur_bits += n_bits; - - while( cur_bits >= 8 ) { - char_out( (unsigned int)(cur_accum & 0xff) ); + + while(cur_bits >= 8) { + char_out((unsigned int)(cur_accum & 0xff)); cur_accum >>= 8; cur_bits -= 8; } - + /* * If the next entry is going to be too big for the code size, * then increase it, if possible. */ - if ( free_ent > maxcode || clear_flg ) { - - if( clear_flg ) { - maxcode = MAXCODE (n_bits = g_init_bits); + if(free_ent > maxcode || clear_flg) { + + if(clear_flg) { + maxcode = MAXCODE(n_bits = g_init_bits); clear_flg = 0; - } + } else { ++n_bits; - if ( n_bits == maxbits ) - maxcode = maxmaxcode; + if(n_bits == maxbits) + maxcode = maxmaxcode; else - maxcode = MAXCODE(n_bits); + maxcode = MAXCODE(n_bits); } } - - if( code == EOFCode ) { + + if(code == EOFCode) { /* * At EOF, write the rest of the buffer. */ - while( cur_bits > 0 ) { - char_out( (unsigned int)(cur_accum & 0xff) ); + while(cur_bits > 0) { + char_out((unsigned int)(cur_accum & 0xff)); cur_accum >>= 8; cur_bits -= 8; } - + flush_char(); - - fflush( g_outfile ); - - if( ferror( g_outfile ) ) + + fflush(g_outfile); + + if(ferror(g_outfile)) Msg(GERROR, "GIF: Error writing output file"); } } @@ -805,34 +841,35 @@ static void output( code_int code){ * questions about this implementation to ames!jaw. */ -static void cl_hash(register count_int hsize){ /* reset code table */ - register count_int *htab_p = htab+hsize; - +static void cl_hash(register count_int hsize) +{ /* reset code table */ + register count_int *htab_p = htab + hsize; + register long i; register long m1 = -1; - + i = hsize - 16; - do { /* might use Sys V memset(3) here */ - *(htab_p-16) = m1; - *(htab_p-15) = m1; - *(htab_p-14) = m1; - *(htab_p-13) = m1; - *(htab_p-12) = m1; - *(htab_p-11) = m1; - *(htab_p-10) = m1; - *(htab_p-9) = m1; - *(htab_p-8) = m1; - *(htab_p-7) = m1; - *(htab_p-6) = m1; - *(htab_p-5) = m1; - *(htab_p-4) = m1; - *(htab_p-3) = m1; - *(htab_p-2) = m1; - *(htab_p-1) = m1; + do { /* might use Sys V memset(3) here */ + *(htab_p - 16) = m1; + *(htab_p - 15) = m1; + *(htab_p - 14) = m1; + *(htab_p - 13) = m1; + *(htab_p - 12) = m1; + *(htab_p - 11) = m1; + *(htab_p - 10) = m1; + *(htab_p - 9) = m1; + *(htab_p - 8) = m1; + *(htab_p - 7) = m1; + *(htab_p - 6) = m1; + *(htab_p - 5) = m1; + *(htab_p - 4) = m1; + *(htab_p - 3) = m1; + *(htab_p - 2) = m1; + *(htab_p - 1) = m1; htab_p -= 16; - } while ((i -= 16) >= 0); - - for ( i += 16; i > 0; --i ) + } while((i -= 16) >= 0); + + for(i += 16; i > 0; --i) *--htab_p = m1; } @@ -840,18 +877,20 @@ static void cl_hash(register count_int hsize){ /* reset code table */ /* * Clear out the hash table */ -static void cl_block (){ /* table clear for block compress */ - - cl_hash ( (count_int) hsize ); +static void cl_block() +{ /* table clear for block compress */ + + cl_hash((count_int) hsize); free_ent = ClearCode + 2; clear_flg = 1; - - output( (code_int)ClearCode ); + + output((code_int) ClearCode); } -static void compress( int init_bits, FILE* outfile, ifunptr ReadValue){ +static void compress(int init_bits, FILE * outfile, ifunptr ReadValue) +{ register long fcode; - register code_int i /* = 0 */; + register code_int i /* = 0 */ ; register int c; register code_int ent; register code_int disp; @@ -864,7 +903,7 @@ static void compress( int init_bits, FILE* outfile, ifunptr ReadValue){ */ g_init_bits = init_bits; g_outfile = outfile; - + /* * Set up the necessary values */ @@ -872,83 +911,87 @@ static void compress( int init_bits, FILE* outfile, ifunptr ReadValue){ clear_flg = 0; in_count = 1; maxcode = MAXCODE(n_bits = g_init_bits); - + ClearCode = (1 << (init_bits - 1)); EOFCode = ClearCode + 1; free_ent = ClearCode + 2; - + char_init(); - - ent = GIFNextPixel( ReadValue ); - + + ent = GIFNextPixel(ReadValue); + hshift = 0; - for ( fcode = (long) hsize; fcode < 65536L; fcode *= 2L ) + for(fcode = (long)hsize; fcode < 65536L; fcode *= 2L) ++hshift; - hshift = 8 - hshift; /* set hash code range bound */ - + hshift = 8 - hshift; /* set hash code range bound */ + hsize_reg = hsize; - cl_hash( (count_int) hsize_reg); /* clear hash table */ - - output( (code_int)ClearCode ); - - while ( (c = GIFNextPixel( ReadValue )) != EOF ) { - + cl_hash((count_int) hsize_reg); /* clear hash table */ + + output((code_int) ClearCode); + + while((c = GIFNextPixel(ReadValue)) != EOF) { + ++in_count; - - fcode = (long) (((long) c << maxbits) + ent); - i = (((code_int)c << hshift) ^ ent); /* xor hashing */ - - if ( HashTabOf (i) == fcode ) { - ent = CodeTabOf (i); + + fcode = (long)(((long)c << maxbits) + ent); + i = (((code_int) c << hshift) ^ ent); /* xor hashing */ + + if(HashTabOf(i) == fcode) { + ent = CodeTabOf(i); continue; - } else if ( (long)HashTabOf (i) < 0 ) /* empty slot */ + } + else if((long)HashTabOf(i) < 0) /* empty slot */ goto nomatch; - disp = hsize_reg - i; /* secondary hash (after G. Knott) */ - if ( i == 0 ) + disp = hsize_reg - i; /* secondary hash (after G. Knott) */ + if(i == 0) disp = 1; -probe: - if ( (i -= disp) < 0 ) + probe: + if((i -= disp) < 0) i += hsize_reg; - - if ( HashTabOf (i) == fcode ) { - ent = CodeTabOf (i); + + if(HashTabOf(i) == fcode) { + ent = CodeTabOf(i); continue; } - if ( (long)HashTabOf (i) > 0 ) + if((long)HashTabOf(i) > 0) goto probe; -nomatch: - output ( (code_int) ent ); + nomatch: + output((code_int) ent); ++out_count; ent = c; - if ( free_ent < maxmaxcode ) { - CodeTabOf (i) = free_ent++; /* code -> hashtable */ - HashTabOf (i) = fcode; - } else + if(free_ent < maxmaxcode) { + CodeTabOf(i) = free_ent++; /* code -> hashtable */ + HashTabOf(i) = fcode; + } + else cl_block(); } /* * Put out the final code. */ - output( (code_int)ent ); + output((code_int) ent); ++out_count; - output( (code_int) EOFCode ); + output((code_int) EOFCode); } /* * Write out a word to the GIF file */ -static void Putword( int w, FILE* fp){ - fputc( w & 0xff, fp ); - fputc( (w / 256) & 0xff, fp ); +static void Putword(int w, FILE * fp) +{ + fputc(w & 0xff, fp); + fputc((w / 256) & 0xff, fp); } -static void GIFEncode( FILE* fp, - int GWidth, int GHeight, - int GInterlace, int Background, int Transparent, - int BitsPerPixel, int Red[], int Green[], int Blue[], - ifunptr GetPixel){ +static void GIFEncode(FILE * fp, + int GWidth, int GHeight, + int GInterlace, int Background, int Transparent, + int BitsPerPixel, int Red[], int Green[], int Blue[], + ifunptr GetPixel) +{ int B; int RWidth, RHeight; int LeftOfs, TopOfs; @@ -963,144 +1006,144 @@ static void GIFEncode( FILE* fp, free_ent = 0; Interlace = GInterlace; - + ColorMapSize = 1 << BitsPerPixel; - + RWidth = Width = GWidth; RHeight = Height = GHeight; LeftOfs = TopOfs = 0; - + Resolution = BitsPerPixel; - + /* * Calculate number of bits we are expecting */ - CountDown = (long)Width * (long)Height; - + CountDown = (long)Width *(long)Height; + /* * Indicate which pass we are on (if interlace) */ Pass = 0; - + /* * The initial code size */ - if( BitsPerPixel <= 1 ) + if(BitsPerPixel <= 1) InitCodeSize = 2; else InitCodeSize = BitsPerPixel; - + /* * Set up the current x and y position */ curx = cury = 0; - + /* * Write the Magic header */ - fwrite( Transparent < 0 ? "GIF87a" : "GIF89a", 1, 6, fp ); - + fwrite(Transparent < 0 ? "GIF87a" : "GIF89a", 1, 6, fp); + /* * Write out the screen width and height */ - Putword( RWidth, fp ); - Putword( RHeight, fp ); - + Putword(RWidth, fp); + Putword(RHeight, fp); + /* * Indicate that there is a global colour map */ - B = 0x80; /* Yes, there is a color map */ - + B = 0x80; /* Yes, there is a color map */ + /* * OR in the resolution */ B |= (Resolution - 1) << 5; - + /* * OR in the Bits per Pixel */ B |= (BitsPerPixel - 1); - + /* * Write it out */ - fputc( B, fp ); - + fputc(B, fp); + /* * Write out the Background colour */ - fputc( Background, fp ); - + fputc(Background, fp); + /* * Byte of 0's (future expansion) */ - fputc( 0, fp ); - + fputc(0, fp); + /* * Write out the Global Colour Map */ - for( i=0; i<ColorMapSize; ++i ) { - fputc( Red[i], fp ); - fputc( Green[i], fp ); - fputc( Blue[i], fp ); + for(i = 0; i < ColorMapSize; ++i) { + fputc(Red[i], fp); + fputc(Green[i], fp); + fputc(Blue[i], fp); } - + /* * Write out extension for transparent colour index, if necessary. */ - if ( Transparent >= 0 ) { - fputc( '!', fp ); - fputc( 0xf9, fp ); - fputc( 4, fp ); - fputc( 1, fp ); - fputc( 0, fp ); - fputc( 0, fp ); - fputc( Transparent, fp ); - fputc( 0, fp ); + if(Transparent >= 0) { + fputc('!', fp); + fputc(0xf9, fp); + fputc(4, fp); + fputc(1, fp); + fputc(0, fp); + fputc(0, fp); + fputc(Transparent, fp); + fputc(0, fp); } - + /* * Write an Image separator */ - fputc( ',', fp ); - + fputc(',', fp); + /* * Write the Image header */ - - Putword( LeftOfs, fp ); - Putword( TopOfs, fp ); - Putword( Width, fp ); - Putword( Height, fp ); - + + Putword(LeftOfs, fp); + Putword(TopOfs, fp); + Putword(Width, fp); + Putword(Height, fp); + /* * Write out whether or not the image is interlaced */ - if( Interlace ) - fputc( 0x40, fp ); + if(Interlace) + fputc(0x40, fp); else - fputc( 0x00, fp ); - + fputc(0x00, fp); + /* * Write out the initial code size */ - fputc( InitCodeSize, fp ); - + fputc(InitCodeSize, fp); + /* * Go and actually compress the data */ - compress( InitCodeSize+1, fp, GetPixel ); - + compress(InitCodeSize + 1, fp, GetPixel); + /* * Write out a Zero-length packet (to end the series) */ - fputc( 0, fp ); - + fputc(0, fp); + /* * Write the GIF file terminator */ - fputc( ';', fp ); - + fputc(';', fp); + } @@ -1109,48 +1152,50 @@ static void GIFEncode( FILE* fp, #define FS_SCALE 1024 #define MAXCOL2 32767 -void create_gif(FILE *outfile, int width, int height, - int dither, int sort, int interlace, - int transparency, int bg_r, int bg_g, int bg_b){ +void create_gif(FILE * outfile, int width, int height, + int dither, int sort, int interlace, + int transparency, int bg_r, int bg_g, int bg_b) +{ - int i,j,k,transparent,rows,cols; + int i, j, k, transparent, rows, cols; pixel transcolor; colorhist_vector chv, colormap; int BitsPerPixel, usehash; unsigned char *RedBuffer, *GreenBuffer, *BlueBuffer; - pixval maxval=MAXCOL2, newmaxval; + pixval maxval = MAXCOL2, newmaxval; colorhash_table cht; - register pixel* pP; + register pixel *pP; register int col, row, limitcol, ind; - int newcolors=256; - long *thisrerr=NULL, *nextrerr=NULL, *thisgerr=NULL, *nextgerr=NULL; - long *thisberr=NULL, *nextberr=NULL, *temperr=NULL; - register long sr=0, sg=0, sb=0, err=0; - int fs_direction=0; + int newcolors = 256; + long *thisrerr = NULL, *nextrerr = NULL, *thisgerr = NULL, *nextgerr = NULL; + long *thisberr = NULL, *nextberr = NULL, *temperr = NULL; + register long sr = 0, sg = 0, sb = 0, err = 0; + int fs_direction = 0; /* This is stupid, but I couldn't figure out how to pack the data directly from the OpenGL frame buffer into unsigned long pixel[][] */ - glPixelStorei(GL_PACK_ALIGNMENT,1); - glPixelStorei(GL_UNPACK_ALIGNMENT,1); - RedBuffer = (unsigned char *)Malloc(height*width*sizeof(unsigned char)); - GreenBuffer = (unsigned char *)Malloc(height*width*sizeof(unsigned char)); - BlueBuffer = (unsigned char *)Malloc(height*width*sizeof(unsigned char)); - glReadPixels(0,0,width,height,GL_RED,GL_UNSIGNED_BYTE,RedBuffer); - glReadPixels(0,0,width,height,GL_GREEN,GL_UNSIGNED_BYTE,GreenBuffer); - glReadPixels(0,0,width,height,GL_BLUE,GL_UNSIGNED_BYTE,BlueBuffer); - - static_pixels = (pixel**)Malloc(height*sizeof(pixel*)); - for(i = 0 ; i<height ; i++) - static_pixels[i] = (pixel*)Malloc(3*width*sizeof(pixel)); - - for(i = 0 ; i<height ; i++) - for(j = 0 ; j<width ; j++) - PPM_ASSIGN(static_pixels[height-1-i][j], - RedBuffer[i*width+j], - GreenBuffer[i*width+j], - BlueBuffer[i*width+j]); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + RedBuffer = (unsigned char *)Malloc(height * width * sizeof(unsigned char)); + GreenBuffer = + (unsigned char *)Malloc(height * width * sizeof(unsigned char)); + BlueBuffer = + (unsigned char *)Malloc(height * width * sizeof(unsigned char)); + glReadPixels(0, 0, width, height, GL_RED, GL_UNSIGNED_BYTE, RedBuffer); + glReadPixels(0, 0, width, height, GL_GREEN, GL_UNSIGNED_BYTE, GreenBuffer); + glReadPixels(0, 0, width, height, GL_BLUE, GL_UNSIGNED_BYTE, BlueBuffer); + + static_pixels = (pixel **) Malloc(height * sizeof(pixel *)); + for(i = 0; i < height; i++) + static_pixels[i] = (pixel *) Malloc(3 * width * sizeof(pixel)); + + for(i = 0; i < height; i++) + for(j = 0; j < width; j++) + PPM_ASSIGN(static_pixels[height - 1 - i][j], + RedBuffer[i * width + j], + GreenBuffer[i * width + j], BlueBuffer[i * width + j]); Free(RedBuffer); Free(GreenBuffer); @@ -1158,195 +1203,204 @@ void create_gif(FILE *outfile, int width, int height, /* Try to compute color histogram */ - chv = ppm_computecolorhist( static_pixels, width, height, MAX_GIFCOLORS, - &static_nbcolors ); + chv = ppm_computecolorhist(static_pixels, width, height, MAX_GIFCOLORS, + &static_nbcolors); /* Fuck, there are more than 256 colors in the picture: we need to quantize */ - if ( chv == (colorhist_vector) 0 ){ + if(chv == (colorhist_vector) 0) { Msg(DEBUG, "GIF: too many colors in image"); - - rows = height ; - cols = width ; - - while(1){ - Msg(DEBUG, "GIF: making histogram..." ); - chv = ppm_computecolorhist(static_pixels, width, height, MAXCOL2, - &static_nbcolors ); - if ( chv != (colorhist_vector) 0 ) - break; - Msg(DEBUG, "GIF: still too many colors!" ); + + rows = height; + cols = width; + + while(1) { + Msg(DEBUG, "GIF: making histogram..."); + chv = ppm_computecolorhist(static_pixels, width, height, MAXCOL2, + &static_nbcolors); + if(chv != (colorhist_vector) 0) + break; + Msg(DEBUG, "GIF: still too many colors!"); newmaxval = maxval / 2; - Msg(DEBUG, "GIF: scaling colors from maxval=%d to maxval=%d to improve clustering...", - maxval, newmaxval ); - for ( row = 0; row < rows; ++row ) - for ( col = 0, pP = static_pixels[row]; col < cols; ++col, ++pP ) - PPM_DEPTH( *pP, *pP, maxval, newmaxval ); + Msg(DEBUG, + "GIF: scaling colors from maxval=%d to maxval=%d to improve clustering...", + maxval, newmaxval); + for(row = 0; row < rows; ++row) + for(col = 0, pP = static_pixels[row]; col < cols; ++col, ++pP) + PPM_DEPTH(*pP, *pP, maxval, newmaxval); maxval = newmaxval; } - Msg(DEBUG, "GIF: %d colors found", static_nbcolors ); - Msg(DEBUG, "GIF: choosing %d colors...", newcolors ); - colormap = mediancut( chv, static_nbcolors, rows * cols, maxval, newcolors ); + Msg(DEBUG, "GIF: %d colors found", static_nbcolors); + Msg(DEBUG, "GIF: choosing %d colors...", newcolors); + colormap = + mediancut(chv, static_nbcolors, rows * cols, maxval, newcolors); - cht = ppm_alloccolorhash( ); + cht = ppm_alloccolorhash(); - ppm_freecolorhist( chv ); + ppm_freecolorhist(chv); /* map the colors in the image to their closest match in the new colormap */ - Msg(DEBUG, "GIF: mapping image to new colors..." ); + Msg(DEBUG, "GIF: mapping image to new colors..."); usehash = 1; - if ( dither ){ - Msg(DEBUG, "GIF: Floyd-Steinberg dithering is selected..." ); + if(dither) { + Msg(DEBUG, "GIF: Floyd-Steinberg dithering is selected..."); /* Initialize Floyd-Steinberg error vectors. */ - thisrerr = (long*) Malloc( (cols + 2)* sizeof(long) ); - nextrerr = (long*) Malloc( (cols + 2)* sizeof(long) ); - thisgerr = (long*) Malloc( (cols + 2)* sizeof(long) ); - nextgerr = (long*) Malloc( (cols + 2)* sizeof(long) ); - thisberr = (long*) Malloc( (cols + 2)* sizeof(long) ); - nextberr = (long*) Malloc( (cols + 2)* sizeof(long) ); + thisrerr = (long *)Malloc((cols + 2) * sizeof(long)); + nextrerr = (long *)Malloc((cols + 2) * sizeof(long)); + thisgerr = (long *)Malloc((cols + 2) * sizeof(long)); + nextgerr = (long *)Malloc((cols + 2) * sizeof(long)); + thisberr = (long *)Malloc((cols + 2) * sizeof(long)); + nextberr = (long *)Malloc((cols + 2) * sizeof(long)); /* srand( (int) ( time( 0 ) ^ getpid( ) ) ); */ - for ( col = 0; col < cols + 2; ++col ){ - thisrerr[col] = rand( ) % ( FS_SCALE * 2 ) - FS_SCALE; - thisgerr[col] = rand( ) % ( FS_SCALE * 2 ) - FS_SCALE; - thisberr[col] = rand( ) % ( FS_SCALE * 2 ) - FS_SCALE; - /* (random errors in [-1 .. 1]) */ + for(col = 0; col < cols + 2; ++col) { + thisrerr[col] = rand() % (FS_SCALE * 2) - FS_SCALE; + thisgerr[col] = rand() % (FS_SCALE * 2) - FS_SCALE; + thisberr[col] = rand() % (FS_SCALE * 2) - FS_SCALE; + /* (random errors in [-1 .. 1]) */ } fs_direction = 1; } - for ( row = 0; row < rows; ++row ){ + for(row = 0; row < rows; ++row) { - if ( dither ) - for ( col = 0; col < cols + 2; ++col ) - nextrerr[col] = nextgerr[col] = nextberr[col] = 0; + if(dither) + for(col = 0; col < cols + 2; ++col) + nextrerr[col] = nextgerr[col] = nextberr[col] = 0; - if ( ( ! dither ) || fs_direction ){ - col = 0; - limitcol = cols; - pP = static_pixels[row]; + if((!dither) || fs_direction) { + col = 0; + limitcol = cols; + pP = static_pixels[row]; } - else{ - col = cols - 1; - limitcol = -1; - pP = &(static_pixels[row][col]); + else { + col = cols - 1; + limitcol = -1; + pP = &(static_pixels[row][col]); } - do{ - - if ( dither ){ - /* Use Floyd-Steinberg errors to adjust actual color. */ - sr = PPM_GETR(*pP) + thisrerr[col + 1] / FS_SCALE; - sg = PPM_GETG(*pP) + thisgerr[col + 1] / FS_SCALE; - sb = PPM_GETB(*pP) + thisberr[col + 1] / FS_SCALE; - if ( sr < 0 ) sr = 0; - else if ( sr > (long)maxval ) sr = maxval; - if ( sg < 0 ) sg = 0; - else if ( sg > (long)maxval ) sg = maxval; - if ( sb < 0 ) sb = 0; - else if ( sb > (long)maxval ) sb = maxval; - PPM_ASSIGN( *pP, sr, sg, sb ); - } - - /* Check hash table to see if we have already matched this color. */ - ind = ppm_lookupcolor( cht, pP ); - if ( ind == -1 ){ /* No; search colormap for closest match. */ - register int i, r1, g1, b1, r2, g2, b2; - register long dist, newdist; - r1 = PPM_GETR( *pP ); - g1 = PPM_GETG( *pP ); - b1 = PPM_GETB( *pP ); - dist = 2000000000; - for ( i = 0; i < newcolors; ++i ){ - r2 = PPM_GETR( colormap[i].color ); - g2 = PPM_GETG( colormap[i].color ); - b2 = PPM_GETB( colormap[i].color ); - newdist = - ( r1 - r2 ) * ( r1 - r2 ) + - ( g1 - g2 ) * ( g1 - g2 ) + - ( b1 - b2 ) * ( b1 - b2 ); - if ( newdist < dist ){ - ind = i; - dist = newdist; - } - } - if ( usehash ){ - if ( ppm_addtocolorhash( cht, pP, ind ) < 0 ){ - Msg(WARNING, "GIF: Out of memory adding to hash table, proceeding without it"); - usehash = 0; - } - } - } - - if ( dither ){ - /* Propagate Floyd-Steinberg error terms. */ - if ( fs_direction ){ - err = ( sr - (long) PPM_GETR( colormap[ind].color ) ) * FS_SCALE; - thisrerr[col + 2] += ( err * 7 ) / 16; - nextrerr[col ] += ( err * 3 ) / 16; - nextrerr[col + 1] += ( err * 5 ) / 16; - nextrerr[col + 2] += ( err ) / 16; - err = ( sg - (long) PPM_GETG( colormap[ind].color ) ) * FS_SCALE; - thisgerr[col + 2] += ( err * 7 ) / 16; - nextgerr[col ] += ( err * 3 ) / 16; - nextgerr[col + 1] += ( err * 5 ) / 16; - nextgerr[col + 2] += ( err ) / 16; - err = ( sb - (long) PPM_GETB( colormap[ind].color ) ) * FS_SCALE; - thisberr[col + 2] += ( err * 7 ) / 16; - nextberr[col ] += ( err * 3 ) / 16; - nextberr[col + 1] += ( err * 5 ) / 16; - nextberr[col + 2] += ( err ) / 16; - } - else{ - err = ( sr - (long) PPM_GETR( colormap[ind].color ) ) * FS_SCALE; - thisrerr[col ] += ( err * 7 ) / 16; - nextrerr[col + 2] += ( err * 3 ) / 16; - nextrerr[col + 1] += ( err * 5 ) / 16; - nextrerr[col ] += ( err ) / 16; - err = ( sg - (long) PPM_GETG( colormap[ind].color ) ) * FS_SCALE; - thisgerr[col ] += ( err * 7 ) / 16; - nextgerr[col + 2] += ( err * 3 ) / 16; - nextgerr[col + 1] += ( err * 5 ) / 16; - nextgerr[col ] += ( err ) / 16; - err = ( sb - (long) PPM_GETB( colormap[ind].color ) ) * FS_SCALE; - thisberr[col ] += ( err * 7 ) / 16; - nextberr[col + 2] += ( err * 3 ) / 16; - nextberr[col + 1] += ( err * 5 ) / 16; - nextberr[col ] += ( err ) / 16; - } - } - - *pP = colormap[ind].color; - - if ( ( ! dither ) || fs_direction ){ - ++col; - ++pP; - } - else{ - --col; - --pP; - } + do { + + if(dither) { + /* Use Floyd-Steinberg errors to adjust actual color. */ + sr = PPM_GETR(*pP) + thisrerr[col + 1] / FS_SCALE; + sg = PPM_GETG(*pP) + thisgerr[col + 1] / FS_SCALE; + sb = PPM_GETB(*pP) + thisberr[col + 1] / FS_SCALE; + if(sr < 0) + sr = 0; + else if(sr > (long)maxval) + sr = maxval; + if(sg < 0) + sg = 0; + else if(sg > (long)maxval) + sg = maxval; + if(sb < 0) + sb = 0; + else if(sb > (long)maxval) + sb = maxval; + PPM_ASSIGN(*pP, sr, sg, sb); + } + + /* Check hash table to see if we have already matched this color. */ + ind = ppm_lookupcolor(cht, pP); + if(ind == -1) { /* No; search colormap for closest match. */ + register int i, r1, g1, b1, r2, g2, b2; + register long dist, newdist; + r1 = PPM_GETR(*pP); + g1 = PPM_GETG(*pP); + b1 = PPM_GETB(*pP); + dist = 2000000000; + for(i = 0; i < newcolors; ++i) { + r2 = PPM_GETR(colormap[i].color); + g2 = PPM_GETG(colormap[i].color); + b2 = PPM_GETB(colormap[i].color); + newdist = + (r1 - r2) * (r1 - r2) + + (g1 - g2) * (g1 - g2) + (b1 - b2) * (b1 - b2); + if(newdist < dist) { + ind = i; + dist = newdist; + } + } + if(usehash) { + if(ppm_addtocolorhash(cht, pP, ind) < 0) { + Msg(WARNING, + "GIF: Out of memory adding to hash table, proceeding without it"); + usehash = 0; + } + } + } + + if(dither) { + /* Propagate Floyd-Steinberg error terms. */ + if(fs_direction) { + err = (sr - (long)PPM_GETR(colormap[ind].color)) * FS_SCALE; + thisrerr[col + 2] += (err * 7) / 16; + nextrerr[col] += (err * 3) / 16; + nextrerr[col + 1] += (err * 5) / 16; + nextrerr[col + 2] += (err) / 16; + err = (sg - (long)PPM_GETG(colormap[ind].color)) * FS_SCALE; + thisgerr[col + 2] += (err * 7) / 16; + nextgerr[col] += (err * 3) / 16; + nextgerr[col + 1] += (err * 5) / 16; + nextgerr[col + 2] += (err) / 16; + err = (sb - (long)PPM_GETB(colormap[ind].color)) * FS_SCALE; + thisberr[col + 2] += (err * 7) / 16; + nextberr[col] += (err * 3) / 16; + nextberr[col + 1] += (err * 5) / 16; + nextberr[col + 2] += (err) / 16; + } + else { + err = (sr - (long)PPM_GETR(colormap[ind].color)) * FS_SCALE; + thisrerr[col] += (err * 7) / 16; + nextrerr[col + 2] += (err * 3) / 16; + nextrerr[col + 1] += (err * 5) / 16; + nextrerr[col] += (err) / 16; + err = (sg - (long)PPM_GETG(colormap[ind].color)) * FS_SCALE; + thisgerr[col] += (err * 7) / 16; + nextgerr[col + 2] += (err * 3) / 16; + nextgerr[col + 1] += (err * 5) / 16; + nextgerr[col] += (err) / 16; + err = (sb - (long)PPM_GETB(colormap[ind].color)) * FS_SCALE; + thisberr[col] += (err * 7) / 16; + nextberr[col + 2] += (err * 3) / 16; + nextberr[col + 1] += (err * 5) / 16; + nextberr[col] += (err) / 16; + } + } + + *pP = colormap[ind].color; + + if((!dither) || fs_direction) { + ++col; + ++pP; + } + else { + --col; + --pP; + } } - while ( col != limitcol ); - - if ( dither ){ - temperr = thisrerr; - thisrerr = nextrerr; - nextrerr = temperr; - temperr = thisgerr; - thisgerr = nextgerr; - nextgerr = temperr; - temperr = thisberr; - thisberr = nextberr; - nextberr = temperr; - fs_direction = ! fs_direction; + while(col != limitcol); + + if(dither) { + temperr = thisrerr; + thisrerr = nextrerr; + nextrerr = temperr; + temperr = thisgerr; + thisgerr = nextgerr; + nextgerr = temperr; + temperr = thisberr; + thisberr = nextberr; + nextberr = temperr; + fs_direction = !fs_direction; } } - if(cht) ppm_freecolorhash(cht); - if(dither){ + if(cht) + ppm_freecolorhash(cht); + if(dither) { Free(thisrerr); Free(nextrerr); Free(thisgerr); @@ -1354,62 +1408,71 @@ void create_gif(FILE *outfile, int width, int height, Free(thisberr); Free(nextberr); } - chv = ppm_computecolorhist( static_pixels, width, height, MAX_GIFCOLORS, - &static_nbcolors ); + chv = ppm_computecolorhist(static_pixels, width, height, MAX_GIFCOLORS, + &static_nbcolors); } /* We now have a colormap of maximum 256 colors */ - for ( i = 0; i < static_nbcolors; ++i ){ - static_red[i] = PPM_GETR( chv[i].color ); - static_green[i] = PPM_GETG( chv[i].color ); - static_blue[i] = PPM_GETB( chv[i].color ); + for(i = 0; i < static_nbcolors; ++i) { + static_red[i] = PPM_GETR(chv[i].color); + static_green[i] = PPM_GETG(chv[i].color); + static_blue[i] = PPM_GETB(chv[i].color); } /* Sort the colormap */ - for (i=0 ; i<static_nbcolors ; i++) + for(i = 0; i < static_nbcolors; i++) static_permi[i] = i; - if (sort) { + if(sort) { Msg(DEBUG, "GIF: sorting colormap"); - for (i=0 ; i<static_nbcolors ; i++) - for (j=i+1 ; j<static_nbcolors ; j++) - if (((static_red[i]*MAX_GIFCOLORS)+static_green[i])*MAX_GIFCOLORS+static_blue[i] > - ((static_red[j]*MAX_GIFCOLORS)+static_green[j])*MAX_GIFCOLORS+static_blue[j]) { - k = static_permi[i]; static_permi[i] = static_permi[j]; static_permi[j] = k; - k = static_red[i]; static_red[i] = static_red[j]; static_red[j] = k; - k = static_green[i]; static_green[i] = static_green[j]; static_green[j] = k; - k = static_blue[i]; static_blue[i] = static_blue[j]; static_blue[j] = k; - } + for(i = 0; i < static_nbcolors; i++) + for(j = i + 1; j < static_nbcolors; j++) + if(((static_red[i] * MAX_GIFCOLORS) + + static_green[i]) * MAX_GIFCOLORS + static_blue[i] > + ((static_red[j] * MAX_GIFCOLORS) + + static_green[j]) * MAX_GIFCOLORS + static_blue[j]) { + k = static_permi[i]; + static_permi[i] = static_permi[j]; + static_permi[j] = k; + k = static_red[i]; + static_red[i] = static_red[j]; + static_red[j] = k; + k = static_green[i]; + static_green[i] = static_green[j]; + static_green[j] = k; + k = static_blue[i]; + static_blue[i] = static_blue[j]; + static_blue[j] = k; + } } - for (i=0 ; i<static_nbcolors ; i++) - static_perm[static_permi[i]]=i; - - BitsPerPixel = colorstobpp( static_nbcolors ); + for(i = 0; i < static_nbcolors; i++) + static_perm[static_permi[i]] = i; + + BitsPerPixel = colorstobpp(static_nbcolors); /* And make a hash table for fast lookup. */ - static_cht = ppm_colorhisttocolorhash( chv, static_nbcolors ); - ppm_freecolorhist( chv ); - + static_cht = ppm_colorhisttocolorhash(chv, static_nbcolors); + ppm_freecolorhist(chv); + /* figure out the transparent colour index */ - if (transparency) { + if(transparency) { PPM_ASSIGN(transcolor, bg_r, bg_g, bg_b); - transparent = ppm_lookupcolor( static_cht, &transcolor ); - if (transparent == -1) - transparent = closestcolor( transcolor ); + transparent = ppm_lookupcolor(static_cht, &transcolor); + if(transparent == -1) + transparent = closestcolor(transcolor); else transparent = static_perm[transparent]; } else - transparent = -1 ; + transparent = -1; /* All set, let's do it. */ GIFEncode(outfile, width, height, interlace, 0, transparent, BitsPerPixel, - static_red, static_green, static_blue, GetPixel ); + static_red, static_green, static_blue, GetPixel); - for(i = 0 ; i<height ; i++) + for(i = 0; i < height; i++) Free(static_pixels[i]); Free(static_pixels); } - diff --git a/Graphics/gl2jpeg.cpp b/Graphics/gl2jpeg.cpp index 0058c40fb05cda4194717da23407a41d5694b85f..b12fd634bc8eec9014f28d544e07104cc83101c0 100644 --- a/Graphics/gl2jpeg.cpp +++ b/Graphics/gl2jpeg.cpp @@ -2,7 +2,7 @@ * GL2JPEG, an OpenGL to JPEG Printing Library * Copyright (C) 1999-2002 Christophe Geuzaine * - * $Id: gl2jpeg.cpp,v 1.15 2003-02-17 02:08:46 geuzaine Exp $ + * $Id: gl2jpeg.cpp,v 1.16 2003-03-01 22:36:40 geuzaine Exp $ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -25,7 +25,8 @@ #if !defined(HAVE_LIBJPEG) -void create_jpeg(FILE *outfile, int width, int height, int quality){ +void create_jpeg(FILE * outfile, int width, int height, int quality) +{ Msg(GERROR, "This version of Gmsh was compiled without jpeg support"); } @@ -39,12 +40,14 @@ void create_jpeg(FILE *outfile, int width, int height, int quality){ #define XMD_H #endif -extern "C" { +extern "C" +{ #include <jpeglib.h> #include <jerror.h> } -void my_output_message (j_common_ptr cinfo){ +void my_output_message(j_common_ptr cinfo) +{ char buffer[JMSG_LENGTH_MAX]; (*cinfo->err->format_message) (cinfo, buffer); @@ -52,41 +55,42 @@ void my_output_message (j_common_ptr cinfo){ Msg(DEBUG, "%s", buffer); } -void create_jpeg(FILE *outfile, int width, int height, int quality){ +void create_jpeg(FILE * outfile, int width, int height, int quality) +{ int i; unsigned char *pixels; struct jpeg_compress_struct cinfo; struct jpeg_error_mgr jerr; JSAMPROW row_pointer[1]; int row_stride; - + cinfo.err = jpeg_std_error(&jerr); cinfo.err->output_message = my_output_message; jpeg_create_compress(&cinfo); jpeg_stdio_dest(&cinfo, outfile); - cinfo.image_width = width; // in pixels + cinfo.image_width = width; // in pixels cinfo.image_height = height; - cinfo.input_components = 3; // 3 color components per pixel + cinfo.input_components = 3; // 3 color components per pixel cinfo.in_color_space = JCS_RGB; - jpeg_set_defaults(&cinfo); + jpeg_set_defaults(&cinfo); jpeg_set_quality(&cinfo, quality, TRUE); jpeg_start_compress(&cinfo, TRUE); - glPixelStorei(GL_PACK_ALIGNMENT,1); - glPixelStorei(GL_UNPACK_ALIGNMENT,1); - pixels=(unsigned char *)Malloc(height*width*3); - glReadPixels(0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,pixels); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + pixels = (unsigned char *)Malloc(height * width * 3); + glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); row_stride = width * 3; - i=cinfo.image_height-1; - while (i >= 0) { + i = cinfo.image_height - 1; + while(i >= 0) { row_pointer[0] = &pixels[i * row_stride]; - (void) jpeg_write_scanlines(&cinfo, row_pointer, 1); + (void)jpeg_write_scanlines(&cinfo, row_pointer, 1); i--; } jpeg_finish_compress(&cinfo); - jpeg_destroy_compress(&cinfo); + jpeg_destroy_compress(&cinfo); Free(pixels); } diff --git a/Graphics/gl2ppm.cpp b/Graphics/gl2ppm.cpp index cfe506686d5b63426774b4ad022f20702a0e0eed..0e98f6357e701a29093feb8a5168d421e2fb08e7 100644 --- a/Graphics/gl2ppm.cpp +++ b/Graphics/gl2ppm.cpp @@ -2,7 +2,7 @@ * GL2PPM, an OpenGL to PPM Printing Library * Copyright (C) 1999-2002 Christophe Geuzaine * - * $Id: gl2ppm.cpp,v 1.9 2002-05-25 19:17:45 geuzaine Exp $ + * $Id: gl2ppm.cpp,v 1.10 2003-03-01 22:36:40 geuzaine Exp $ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -23,26 +23,26 @@ #include "Gmsh.h" #include "GmshUI.h" -void create_ppm(FILE *outfile, int width, int height){ +void create_ppm(FILE * outfile, int width, int height) +{ unsigned char *pixels; int i, row_stride; - glPixelStorei(GL_PACK_ALIGNMENT,1); - glPixelStorei(GL_UNPACK_ALIGNMENT,1); - pixels=(unsigned char *)Malloc(height*width*3); - glReadPixels(0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,pixels); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + pixels = (unsigned char *)Malloc(height * width * 3); + glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); fprintf(outfile, "P6\n"); fprintf(outfile, "%d %d\n", width, height); fprintf(outfile, "%d\n", 255); row_stride = width * 3; - i = height-1; - while (i >= 0) { + i = height - 1; + while(i >= 0) { fwrite(&pixels[i * row_stride], 1, row_stride, outfile); i--; } Free(pixels); } - diff --git a/Graphics/gl2yuv.cpp b/Graphics/gl2yuv.cpp index 29935b1be7388abd750cf6219ff0d80ede90ab33..d880e8621f3261832b952f8a364b59ab4055631e 100644 --- a/Graphics/gl2yuv.cpp +++ b/Graphics/gl2yuv.cpp @@ -2,7 +2,7 @@ * GL2YUV, an OpenGL to YUV Printing Library * Copyright (C) 1999-2002 Christophe Geuzaine * - * $Id: gl2yuv.cpp,v 1.7 2002-05-25 19:17:45 geuzaine Exp $ + * $Id: gl2yuv.cpp,v 1.8 2003-03-01 22:36:40 geuzaine Exp $ * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -50,8 +50,8 @@ #include "Gmsh.h" #include "GmshUI.h" -void create_yuv(FILE *outfile, int width, int height){ - +void create_yuv(FILE * outfile, int width, int height) +{ register int x, y; register unsigned char *dy0, *dy1; register unsigned char *dcr, *dcb; @@ -63,131 +63,132 @@ void create_yuv(FILE *outfile, int width, int height){ static float mult16874[1024], mult33126[1024], mult5[1024]; static float mult41869[1024], mult08131[1024]; - unsigned char *pixels; - unsigned char **orig_y, **orig_cr, **orig_cb; + unsigned char *pixels; + unsigned char **orig_y, **orig_cr, **orig_cb; int row_stride; - - if (first){ + + if(first) { register int index; register int maxValue; - + maxValue = 255; - for (index = 0; index <= maxValue; index++){ - mult299[index] = index*0.29900; - mult587[index] = index*0.58700; - mult114[index] = index*0.11400; - mult16874[index] = -0.16874*index; - mult33126[index] = -0.33126*index; - mult5[index] = index*0.50000; - mult41869[index] = -0.41869*index; - mult08131[index] = -0.08131*index; + for(index = 0; index <= maxValue; index++) { + mult299[index] = index * 0.29900; + mult587[index] = index * 0.58700; + mult114[index] = index * 0.11400; + mult16874[index] = -0.16874 * index; + mult33126[index] = -0.33126 * index; + mult5[index] = index * 0.50000; + mult41869[index] = -0.41869 * index; + mult08131[index] = -0.08131 * index; } - + first = 0; } // yuv format assumes even number of rows and columns - height -= height%2; - width -= width%2; + height -= height % 2; + width -= width % 2; - glPixelStorei(GL_PACK_ALIGNMENT,1); - glPixelStorei(GL_UNPACK_ALIGNMENT,1); - pixels=(unsigned char *)Malloc(height*width*3); - glReadPixels(0,0,width,height,GL_RGB,GL_UNSIGNED_BYTE,pixels); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + glPixelStorei(GL_UNPACK_ALIGNMENT, 1); + pixels = (unsigned char *)Malloc(height * width * 3); + glReadPixels(0, 0, width, height, GL_RGB, GL_UNSIGNED_BYTE, pixels); row_stride = width * 3; - orig_y = (unsigned char **) Malloc(sizeof(unsigned char *) * height); - for (y = 0; y < height; y++) { - orig_y[y] = (unsigned char *) Malloc(sizeof(unsigned char) * width); + orig_y = (unsigned char **)Malloc(sizeof(unsigned char *) * height); + for(y = 0; y < height; y++) { + orig_y[y] = (unsigned char *)Malloc(sizeof(unsigned char) * width); } - orig_cr = (unsigned char **) Malloc(sizeof(char *) * height / 2); - for (y = 0; y < height / 2; y++) { - orig_cr[y] = (unsigned char *) Malloc(sizeof(char) * width / 2); + orig_cr = (unsigned char **)Malloc(sizeof(char *) * height / 2); + for(y = 0; y < height / 2; y++) { + orig_cr[y] = (unsigned char *)Malloc(sizeof(char) * width / 2); } - - orig_cb = (unsigned char **) Malloc(sizeof(char *) * height / 2); - for (y = 0; y < height / 2; y++) { - orig_cb[y] = (unsigned char *) Malloc(sizeof(char) * width / 2); + + orig_cb = (unsigned char **)Malloc(sizeof(char *) * height / 2); + for(y = 0; y < height / 2; y++) { + orig_cb[y] = (unsigned char *)Malloc(sizeof(char) * width / 2); } - + // assume ydivisor = 1, so cdivisor = 4 cdivisor = 4; - - for (y = 0; y < height; y += 2){ + + for(y = 0; y < height; y += 2) { src0 = &(pixels[y * row_stride]); - src1 = &(pixels[(y+1) * row_stride]); + src1 = &(pixels[(y + 1) * row_stride]); dy0 = orig_y[y]; dy1 = orig_y[y + 1]; dcr = orig_cr[y / 2]; dcb = orig_cb[y / 2]; - - for (x = 0; x < width; x += 2, dy0 += 2, dy1 += 2, dcr++, - dcb++, src0 += 6, src1 += 6){ + + for(x = 0; x < width; x += 2, dy0 += 2, dy1 += 2, dcr++, + dcb++, src0 += 6, src1 += 6) { *dy0 = (unsigned char)(mult299[*src0] + - mult587[src0[1]] + - mult114[src0[2]]); - + mult587[src0[1]] + mult114[src0[2]]); + *dy1 = (unsigned char)(mult299[*src1] + - mult587[src1[1]] + - mult114[src1[2]]); - + mult587[src1[1]] + mult114[src1[2]]); + dy0[1] = (unsigned char)(mult299[src0[3]] + - mult587[src0[4]] + - mult114[src0[5]]); - + mult587[src0[4]] + mult114[src0[5]]); + dy1[1] = (unsigned char)(mult299[src1[3]] + - mult587[src1[4]] + - mult114[src1[5]]); - + mult587[src1[4]] + mult114[src1[5]]); + *dcb = (unsigned char)((mult16874[*src0] + - mult33126[src0[1]] + - mult5[src0[2]] + - mult16874[*src1] + - mult33126[src1[1]] + - mult5[src1[2]] + - mult16874[src0[3]] + - mult33126[src0[4]] + - mult5[src0[5]] + - mult16874[src1[3]] + - mult33126[src1[4]] + - mult5[src1[5]]) / cdivisor) + 128; - + mult33126[src0[1]] + + mult5[src0[2]] + + mult16874[*src1] + + mult33126[src1[1]] + + mult5[src1[2]] + + mult16874[src0[3]] + + mult33126[src0[4]] + + mult5[src0[5]] + + mult16874[src1[3]] + + mult33126[src1[4]] + + mult5[src1[5]]) / cdivisor) + 128; + *dcr = (unsigned char)((mult5[*src0] + - mult41869[src0[1]] + - mult08131[src0[2]] + - mult5[*src1] + - mult41869[src1[1]] + - mult08131[src1[2]] + - mult5[src0[3]] + - mult41869[src0[4]] + - mult08131[src0[5]] + - mult5[src1[3]] + - mult41869[src1[4]] + - mult08131[src1[5]]) / cdivisor) + 128; + mult41869[src0[1]] + + mult08131[src0[2]] + + mult5[*src1] + + mult41869[src1[1]] + + mult08131[src1[2]] + + mult5[src0[3]] + + mult41869[src0[4]] + + mult08131[src0[5]] + + mult5[src1[3]] + + mult41869[src1[4]] + + mult08131[src1[5]]) / cdivisor) + 128; } } // Y - for (y = height-1; y >=0; y--) fwrite(orig_y[y], 1, width, outfile); - + for(y = height - 1; y >= 0; y--) + fwrite(orig_y[y], 1, width, outfile); + // U - for (y = height/2-1; y >=0; y--) fwrite(orig_cb[y], 1, width / 2, outfile); - + for(y = height / 2 - 1; y >= 0; y--) + fwrite(orig_cb[y], 1, width / 2, outfile); + // V - for (y = height/2-1; y >=0; y--) fwrite(orig_cr[y], 1, width / 2, outfile); + for(y = height / 2 - 1; y >= 0; y--) + fwrite(orig_cr[y], 1, width / 2, outfile); Free(pixels); - for (y = 0; y < height; y++) Free(orig_y[y]); + for(y = 0; y < height; y++) + Free(orig_y[y]); Free(orig_y); - for (y = 0; y < height / 2; y++) Free(orig_cr[y]); + for(y = 0; y < height / 2; y++) + Free(orig_cr[y]); Free(orig_cr); - - for (y = 0; y < height / 2; y++) Free(orig_cb[y]); + + for(y = 0; y < height / 2; y++) + Free(orig_cb[y]); Free(orig_cb); } - diff --git a/Makefile b/Makefile index 638a9ea2cf6b6d8c35475fecc17bebd64c539e95..30bee9396e2b419689058f9a2572fe4cd9e30baa 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,9 @@ -# $Id: Makefile,v 1.267 2003-02-26 03:25:30 geuzaine Exp $ +# $Id: Makefile,v 1.268 2003-03-01 22:36:36 geuzaine Exp $ include variables GMSH_MAJOR_VERSION = 1 -GMSH_MINOR_VERSION = 40 +GMSH_MINOR_VERSION = 41 GMSH_PATCH_VERSION = 0 GMSH_VERSION_FILE = Common/GmshVersion.h diff --git a/Mesh/1D_Mesh.cpp b/Mesh/1D_Mesh.cpp index 10d32445b0225f3cfe5660f6a0a849b507fff356..2b0e4015a2d08830660f0cf414e392ffcf13fc82 100644 --- a/Mesh/1D_Mesh.cpp +++ b/Mesh/1D_Mesh.cpp @@ -1,4 +1,4 @@ -// $Id: 1D_Mesh.cpp,v 1.29 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: 1D_Mesh.cpp,v 1.30 2003-03-01 22:36:40 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -27,97 +27,107 @@ #include "Context.h" #include "Interpolation.h" -extern Mesh *THEM; -extern Context_T CTX; +extern Mesh *THEM; +extern Context_T CTX; -static Curve *THEC=NULL; +static Curve *THEC = NULL; // ipar[0] = nbpoints // abs(ipar[1]) = method // sign(ipar[1]) = orientation // dpar[0] = parameter -double F_One (double t){ +double F_One(double t) +{ Vertex der; double d; - der = InterpolateCurve (THEC, t, 1); - d = sqrt (der.Pos.X * der.Pos.X + der.Pos.Y * der.Pos.Y + der.Pos.Z * der.Pos.Z); + der = InterpolateCurve(THEC, t, 1); + d = + sqrt(der.Pos.X * der.Pos.X + der.Pos.Y * der.Pos.Y + + der.Pos.Z * der.Pos.Z); return (d); } -double F_Transfini (double t){ +double F_Transfini(double t) +{ Vertex der; double d, a, b, val; int i; - der = InterpolateCurve (THEC, t, 1); - d = sqrt (der.Pos.X * der.Pos.X + der.Pos.Y * der.Pos.Y + - der.Pos.Z * der.Pos.Z); + der = InterpolateCurve(THEC, t, 1); + d = sqrt(der.Pos.X * der.Pos.X + der.Pos.Y * der.Pos.Y + + der.Pos.Z * der.Pos.Z); - if (THEC->dpar[0] == 0.0 || THEC->dpar[0] == 1.0){ - val = d * (double) THEC->ipar[0] / THEC->l ; + if(THEC->dpar[0] == 0.0 || THEC->dpar[0] == 1.0) { + val = d * (double)THEC->ipar[0] / THEC->l; } - else{ - switch (abs (THEC->ipar[1])){ + else { + switch (abs(THEC->ipar[1])) { - case 1: // Geometric progression ar^i; Sum of n terms = THEC->l = a (r^n-1)/(r-1) + case 1: // Geometric progression ar^i; Sum of n terms = THEC->l = a (r^n-1)/(r-1) if(THEC->dpar[0] == 1.) - a = THEC->l/(double)THEC->ipar[0]; + a = THEC->l / (double)THEC->ipar[0]; else - a = THEC->l * (THEC->dpar[0]-1.)/(pow(THEC->dpar[0],THEC->ipar[0])-1.) ; - i = (int)( log(t*THEC->l/a*(THEC->dpar[0]-1.)+1.) / log(THEC->dpar[0]) ); - val = d/(a*pow(THEC->dpar[0],(double)i)); + a = + THEC->l * (THEC->dpar[0] - + 1.) / (pow(THEC->dpar[0], THEC->ipar[0]) - 1.); + i = + (int)(log(t * THEC->l / a * (THEC->dpar[0] - 1.) + 1.) / + log(THEC->dpar[0])); + val = d / (a * pow(THEC->dpar[0], (double)i)); break; - case 2: // Bump - if (THEC->dpar[0] > 1.0){ - a = -4. * sqrt (THEC->dpar[0] - 1.) * - atan2 (1., sqrt (THEC->dpar[0] - 1.)) / - ((double) THEC->ipar[0] * THEC->l); + case 2: // Bump + if(THEC->dpar[0] > 1.0) { + a = -4. * sqrt(THEC->dpar[0] - 1.) * + atan2(1., sqrt(THEC->dpar[0] - 1.)) / + ((double)THEC->ipar[0] * THEC->l); } - else{ - a = 2. * sqrt (1. - THEC->dpar[0]) * - log (fabs ((1. + 1. / sqrt (1. - THEC->dpar[0])) - / (1. - 1. / sqrt (1. - THEC->dpar[0])))) - / ((double) THEC->ipar[0] * THEC->l); + else { + a = 2. * sqrt(1. - THEC->dpar[0]) * + log(fabs((1. + 1. / sqrt(1. - THEC->dpar[0])) + / (1. - 1. / sqrt(1. - THEC->dpar[0])))) + / ((double)THEC->ipar[0] * THEC->l); } - b = -a * THEC->l * THEC->l / (4. * (THEC->dpar[0] - 1.)) ; - val = d / (-a * DSQR (t * THEC->l - (THEC->l) * 0.5) + b) ; - break ; + b = -a * THEC->l * THEC->l / (4. * (THEC->dpar[0] - 1.)); + val = d / (-a * DSQR(t * THEC->l - (THEC->l) * 0.5) + b); + break; default: Msg(WARNING, "Unknown case in Transfinite Line mesh"); - val = 1. ; + val = 1.; } } - return val ; + return val; } -double F_Lc (double t){ - Vertex der, point; - double Lc, d; +double F_Lc(double t) +{ + Vertex der, point; + double Lc, d; - if (CTX.mesh.algo == DELAUNAY_ISO && THEM->BGM.Typ == ONFILE){ + if(CTX.mesh.algo == DELAUNAY_ISO && THEM->BGM.Typ == ONFILE) { der = InterpolateCurve(THEC, t, 1); - point = InterpolateCurve(THEC, t, 0); + point = InterpolateCurve(THEC, t, 0); Lc = Lc_XYZ(point.Pos.X, point.Pos.Y, point.Pos.Z, THEM); - d = sqrt(DSQR(der.Pos.X)+DSQR(der.Pos.Y)+DSQR(der.Pos.Z)); - if(!Lc){ + d = sqrt(DSQR(der.Pos.X) + DSQR(der.Pos.Y) + DSQR(der.Pos.Z)); + if(!Lc) { Msg(GERROR, "Null characteristic length in background mesh"); return d; } if(CTX.mesh.constrained_bgmesh) - return MAX(d/Lc,THEM->Metric->getLc(t, THEC)); + return MAX(d / Lc, THEM->Metric->getLc(t, THEC)); else - return d/Lc; + return d / Lc; } else return THEM->Metric->getLc(t, THEC); } -void Maillage_Curve (void *data, void *dummy){ +void Maillage_Curve(void *data, void *dummy) +{ Curve *c; Simplex *s; double b, a, d, dt, dp, t; @@ -128,87 +138,88 @@ void Maillage_Curve (void *data, void *dummy){ THEC = c = *(Curve **) data; - if (c->Num < 0) + if(c->Num < 0) return; - if(c->Dirty){ + if(c->Dirty) { Msg(INFO, "Not meshing dirty Curve %d", c->Num); return; } Msg(STATUS3, "Meshing Curve %d", c->Num); - Points = List_Create (10, 10, sizeof (IntPoint)); - c->l = Integration (c->ubeg, c->uend, F_One, Points, 1.e-4); - List_Delete (Points); + Points = List_Create(10, 10, sizeof(IntPoint)); + c->l = Integration(c->ubeg, c->uend, F_One, Points, 1.e-4); + List_Delete(Points); - if(!c->l){ + if(!c->l) { Msg(GERROR, "Zero length Curve %d", c->Num); return; } - if (c->Method == TRANSFINI || !Extrude_Mesh (c)){ - if (c->Method == TRANSFINI){ - Points = List_Create (10, 10, sizeof (IntPoint)); - a = Integration (c->ubeg, c->uend, F_Transfini, Points, 1.e-7); + if(c->Method == TRANSFINI || !Extrude_Mesh(c)) { + if(c->Method == TRANSFINI) { + Points = List_Create(10, 10, sizeof(IntPoint)); + a = Integration(c->ubeg, c->uend, F_Transfini, Points, 1.e-7); N = c->ipar[0]; } - else{ - Points = List_Create (10, 10, sizeof (IntPoint)); - a = Integration (c->ubeg, c->uend, F_Lc, Points, 1.e-4); - N = IMAX (2, (int) (a + 1.)); - - if (c->Typ == MSH_SEGM_CIRC || - c->Typ == MSH_SEGM_CIRC_INV || - c->Typ == MSH_SEGM_ELLI || - c->Typ == MSH_SEGM_ELLI_INV){ - N = IMAX (N, (int) (fabs (c->Circle.t1 - c->Circle.t2) * - (double)CTX.mesh.min_circ_points / Pi)); + else { + Points = List_Create(10, 10, sizeof(IntPoint)); + a = Integration(c->ubeg, c->uend, F_Lc, Points, 1.e-4); + N = IMAX(2, (int)(a + 1.)); + + if(c->Typ == MSH_SEGM_CIRC || + c->Typ == MSH_SEGM_CIRC_INV || + c->Typ == MSH_SEGM_ELLI || c->Typ == MSH_SEGM_ELLI_INV) { + N = IMAX(N, (int)(fabs(c->Circle.t1 - c->Circle.t2) * + (double)CTX.mesh.min_circ_points / Pi)); } - else if (c->Typ == MSH_SEGM_NURBS){ - N = IMAX (N, 2); + else if(c->Typ == MSH_SEGM_NURBS) { + N = IMAX(N, 2); } } - b = a / (double) (N - 1); - c->Vertices = List_Create (N, 2, sizeof (Vertex *)); - + b = a / (double)(N - 1); + c->Vertices = List_Create(N, 2, sizeof(Vertex *)); + v = &c->beg; - if ((vexist = (Vertex **) Tree_PQuery (THEM->Vertices, v))){ + if((vexist = (Vertex **) Tree_PQuery(THEM->Vertices, v))) { (*vexist)->u = c->ubeg; - Tree_Insert (THEM->Vertices, vexist); - if ((*vexist)->ListCurves) - List_Add ((*vexist)->ListCurves, &c); - List_Add (c->Vertices, vexist); + Tree_Insert(THEM->Vertices, vexist); + if((*vexist)->ListCurves) + List_Add((*vexist)->ListCurves, &c); + List_Add(c->Vertices, vexist); } - else{ - pV = Create_Vertex ((*v)->Num, (*v)->Pos.X, (*v)->Pos.Y, - (*v)->Pos.Z, (*v)->lc, c->ubeg); - pV->ListCurves = List_Create (1, 1, sizeof (Curve *)); - List_Add (pV->ListCurves, &c); - Tree_Insert (THEM->Vertices, &pV); - List_Add (c->Vertices, &pV); + else { + pV = Create_Vertex((*v)->Num, (*v)->Pos.X, (*v)->Pos.Y, + (*v)->Pos.Z, (*v)->lc, c->ubeg); + pV->ListCurves = List_Create(1, 1, sizeof(Curve *)); + List_Add(pV->ListCurves, &c); + Tree_Insert(THEM->Vertices, &pV); + List_Add(c->Vertices, &pV); } count = NUMP = 1; - while (NUMP < N - 1){ - List_Read (Points, count - 1, &P1); - List_Read (Points, count, &P2); - d = (double) NUMP *b; + while(NUMP < N - 1) { + List_Read(Points, count - 1, &P1); + List_Read(Points, count, &P2); + d = (double)NUMP *b; - if ((fabs (P2.p) >= fabs (d)) && (fabs (P1.p) < fabs (d))){ + if((fabs(P2.p) >= fabs(d)) && (fabs(P1.p) < fabs(d))) { dt = P2.t - P1.t; dp = P2.p - P1.p; t = P1.t + dt / dp * (d - P1.p); - V = InterpolateCurve (c, t, 0); - pV = Create_Vertex (++THEM->MaxPointNum, V.Pos.X, V.Pos.Y, V.Pos.Z, V.lc, t); + V = InterpolateCurve(c, t, 0); + pV = + Create_Vertex(++THEM->MaxPointNum, V.Pos.X, V.Pos.Y, V.Pos.Z, V.lc, + t); pV->w = V.w; - pV->ListCurves = List_Create (1, 1, sizeof (Curve *)); - List_Add (pV->ListCurves, &c); - Tree_Insert (THEM->Vertices, &pV); - List_Add (c->Vertices, &pV); + pV->ListCurves = List_Create(1, 1, sizeof(Curve *)); + List_Add(pV->ListCurves, &c); + Tree_Insert(THEM->Vertices, &pV); + List_Add(c->Vertices, &pV); NUMP++; } - else{ + else { count++; } } @@ -216,42 +227,43 @@ void Maillage_Curve (void *data, void *dummy){ List_Delete(Points); v = &c->end; - if ((vexist = (Vertex **) Tree_PQuery (THEM->Vertices, v))){ + if((vexist = (Vertex **) Tree_PQuery(THEM->Vertices, v))) { (*vexist)->u = c->uend; - Tree_Insert (THEM->Vertices, vexist); - if ((*vexist)->ListCurves) - List_Add ((*vexist)->ListCurves, &c); - List_Add (c->Vertices, vexist); + Tree_Insert(THEM->Vertices, vexist); + if((*vexist)->ListCurves) + List_Add((*vexist)->ListCurves, &c); + List_Add(c->Vertices, vexist); } - else{ - pV = Create_Vertex ((*v)->Num, (*v)->Pos.X, (*v)->Pos.Y, - (*v)->Pos.Z, (*v)->lc, c->uend); - pV->ListCurves = List_Create (1, 1, sizeof (Curve *)); - List_Add (pV->ListCurves, &c); - Tree_Insert (THEM->Vertices, &pV); - List_Add (c->Vertices, &pV); + else { + pV = Create_Vertex((*v)->Num, (*v)->Pos.X, (*v)->Pos.Y, + (*v)->Pos.Z, (*v)->lc, c->uend); + pV->ListCurves = List_Create(1, 1, sizeof(Curve *)); + List_Add(pV->ListCurves, &c); + Tree_Insert(THEM->Vertices, &pV); + List_Add(c->Vertices, &pV); } } - for (i = 0; i < List_Nbr (c->Vertices) - 1; i++){ - List_Read (c->Vertices, i, &v1); - List_Read (c->Vertices, i + 1, &v2); - s = Create_Simplex (v1, v2, NULL, NULL); + for(i = 0; i < List_Nbr(c->Vertices) - 1; i++) { + List_Read(c->Vertices, i, &v1); + List_Read(c->Vertices, i + 1, &v2); + s = Create_Simplex(v1, v2, NULL, NULL); s->iEnt = c->Num; - Tree_Add (c->Simplexes, &s); - List_Add (c->TrsfSimplexes, &s); + Tree_Add(c->Simplexes, &s); + List_Add(c->TrsfSimplexes, &s); } - if (CTX.mesh.degree == 2) - Degre2 (THEM->Vertices, THEM->VertexEdges, c->Simplexes, c, NULL); + if(CTX.mesh.degree == 2) + Degre2(THEM->Vertices, THEM->VertexEdges, c->Simplexes, c, NULL); - THEM->Statistics[4] += List_Nbr (c->Vertices); + THEM->Statistics[4] += List_Nbr(c->Vertices); #if 0 - if(fabs(c->Num) != 41) return; + if(fabs(c->Num) != 41) + return; printf("curve %d : ", c->Num); - for (i = 0; i < List_Nbr (c->Vertices); i++){ - List_Read (c->Vertices, i, &v1); + for(i = 0; i < List_Nbr(c->Vertices); i++) { + List_Read(c->Vertices, i, &v1); printf(" %d (%g %g %g)", v1->Num, v1->Pos.X, v1->Pos.Y, v1->Pos.Z); } printf("\n"); diff --git a/Mesh/2D_BGMesh.cpp b/Mesh/2D_BGMesh.cpp index 519b7e9716c7339b1766fc3ee5573752e3585d8a..01842c41194705a42a65d124be338b48bf6b75c2 100644 --- a/Mesh/2D_BGMesh.cpp +++ b/Mesh/2D_BGMesh.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_BGMesh.cpp,v 1.12 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: 2D_BGMesh.cpp,v 1.13 2003-03-01 22:36:40 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -29,8 +29,8 @@ extern Mesh *THEM; // Compute Calcul the charact. length on 1 pt by interpolating in the // background mesh -double find_quality (MPoint center, DocRecord * BGMESH){ - +double find_quality(MPoint center, DocRecord * BGMESH) +{ int i; Delaunay *del; PointRecord *pPointArray; @@ -38,7 +38,7 @@ double find_quality (MPoint center, DocRecord * BGMESH){ double qual, q1, q2, q3, X[3], Y[3], u, v, det, Xp, Yp; double Exp = 2., r, deno, nume; - if ((del = Find_Triangle (center, BGMESH, BOF)) == NULL){ + if((del = Find_Triangle(center, BGMESH, BOF)) == NULL) { Msg(GERROR, "Exterior point (%g,%g)", center.v, center.h); return 1.e-15; } @@ -66,27 +66,27 @@ double find_quality (MPoint center, DocRecord * BGMESH){ det = (X[2] - X[0]) * (Y[1] - Y[0]) - (Y[2] - Y[0]) * (X[1] - X[0]); - if (det != 0.0){ + if(det != 0.0) { u = ((Xp - X[0]) * (Y[1] - Y[0]) - (Yp - Y[0]) * (X[1] - X[0])) / det; v = ((X[2] - X[0]) * (Yp - Y[0]) - (Y[2] - Y[0]) * (Xp - X[0])) / det; } - else{ + else { Msg(WARNING, "Degenerated triangle (det=%g)", det); u = v = 0.0; } - - if (u >= -1.e-8 && v >= -1.e-8 && 1. - u - v >= -1.e-8){ + + if(u >= -1.e-8 && v >= -1.e-8 && 1. - u - v >= -1.e-8) { qual = q1 * (1. - u - v) + q2 * v + q3 * u; return (qual); } - else{ + else { pPointArray = BGMESH->points; deno = nume = 0.0; - for (i = 0; i < BGMESH->numPoints; i++){ - r = sqrt (DSQR (center.h - pPointArray[i].where.h) + - DSQR (center.v - pPointArray[i].where.v)); - r = pow (r, Exp); - if (r < 1.e-10) + for(i = 0; i < BGMESH->numPoints; i++) { + r = sqrt(DSQR(center.h - pPointArray[i].where.h) + + DSQR(center.v - pPointArray[i].where.v)); + r = pow(r, Exp); + if(r < 1.e-10) return (pPointArray[i].quality); nume += pPointArray[i].quality / r; deno += 1. / r; diff --git a/Mesh/2D_Bowyer.cpp b/Mesh/2D_Bowyer.cpp index c127538cc1655db2cb29d085b44c37e5296a81e8..e331e79afdaa35e1bda20d05a2a8bd22af5042ee 100644 --- a/Mesh/2D_Bowyer.cpp +++ b/Mesh/2D_Bowyer.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_Bowyer.cpp,v 1.12 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: 2D_Bowyer.cpp,v 1.13 2003-03-01 22:36:40 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -45,53 +45,54 @@ extern PointRecord *gPointArray; -int Is_pt_in_CircCircle (Delaunay * del, MPoint pt){ - +int Is_pt_in_CircCircle(Delaunay * del, MPoint pt) +{ double rc, dc, Xa, Ya; PointNumero a; - dc = DSQR (del->t.xc - pt.h) + DSQR (del->t.yc - pt.v); + dc = DSQR(del->t.xc - pt.h) + DSQR(del->t.yc - pt.v); a = del->t.a; Xa = gPointArray[a].where.h; Ya = gPointArray[a].where.v; - rc = DSQR (del->t.xc - Xa) + DSQR (del->t.yc - Ya); + rc = DSQR(del->t.xc - Xa) + DSQR(del->t.yc - Ya); - if (rc >= dc) + if(rc >= dc) return 1; return 0; } -int PE_Del_Triangle (Delaunay *del , MPoint pt, DListPeek *ListEdges , - List_T *listkill, List_T *listDelforlink, - int *numlink, int *numdel){ +int PE_Del_Triangle(Delaunay * del, MPoint pt, DListPeek * ListEdges, + List_T * listkill, List_T * listDelforlink, + int *numlink, int *numdel) +{ int rslt; - PointNumero a,b,c; - int count,order[3],same; + PointNumero a, b, c; + int count, order[3], same; DListPeek p; - Delaunay *de1,*de2,*de3; - - rslt = Is_pt_in_CircCircle ( del , pt ); + Delaunay *de1, *de2, *de3; + + rslt = Is_pt_in_CircCircle(del, pt); - if ( (!rslt) && (*numdel == 0)) { - return(0); + if((!rslt) && (*numdel == 0)) { + return (0); } - if (!rslt) { + if(!rslt) { + + /* On retient les triangles du pourtour */ - /* On retient les triangles du pourtour */ - del->t.info = NOTTOLINK; List_Put(listDelforlink, *numlink, &del); (*numlink)++; - return(1); - + return (1); + } - else { - + else { + List_Put(listkill, *numdel, &del); (*numdel)++; @@ -99,103 +100,118 @@ int PE_Del_Triangle (Delaunay *del , MPoint pt, DListPeek *ListEdges , b = del->t.b; c = del->t.c; - if ( *ListEdges == NULL ) { - - rslt = DListInsert(ListEdges,pt,a); - rslt &= DListInsert(ListEdges,pt,b); - rslt &= DListInsert(ListEdges,pt,c); + if(*ListEdges == NULL) { + + rslt = DListInsert(ListEdges, pt, a); + rslt &= DListInsert(ListEdges, pt, b); + rslt &= DListInsert(ListEdges, pt, c); if(!rslt) - Msg(GERROR, "List insert failed in Boyer Watson"); - + Msg(GERROR, "List insert failed in Boyer Watson"); + } - else { - + else { + count = 0; p = *ListEdges; order[0] = order[1] = order[2] = 0; same = 0; - - do { - if (p->point_num == a ) { + + do { + if(p->point_num == a) { same = same + 1; - order[count]=a; - count++ ; + order[count] = a; + count++; } - if (p->point_num == b ) { + if(p->point_num == b) { same = same + 10; - order[count]=b; - count++ ; + order[count] = b; + count++; } - if (p->point_num == c ) { + if(p->point_num == c) { same = same + 100; - order[count]=c; - count++ ; + order[count] = c; + count++; } p = Pred(p); - }while ( p != *ListEdges ); - if (count == 1) { - return(0); + } while(p != *ListEdges); + if(count == 1) { + return (0); } - else if (count == 2) { - if (same == 11 ) { - rslt = DListInsert(ListEdges,pt,c); + else if(count == 2) { + if(same == 11) { + rslt = DListInsert(ListEdges, pt, c); } - if (same == 101 ) { - rslt = DListInsert(ListEdges,pt,b); + if(same == 101) { + rslt = DListInsert(ListEdges, pt, b); } - if (same == 110 ) { - rslt = DListInsert(ListEdges,pt,a); + if(same == 110) { + rslt = DListInsert(ListEdges, pt, a); } } - else if (count == 3) { - rslt = DListDelete(ListEdges,order[1]); + else if(count == 3) { + rslt = DListDelete(ListEdges, order[1]); } else { - return(0); + return (0); } } - - de1 = del->v.voisin1; + + de1 = del->v.voisin1; de2 = del->v.voisin2; de3 = del->v.voisin3; - - - if(de1 != NULL){ - if (de1->v.voisin1 == del )de1->v.voisin1 = NULL; - else if (de1->v.voisin2 == del )de1->v.voisin2 = NULL; - else if (de1->v.voisin3 == del )de1->v.voisin3 = NULL; + + + if(de1 != NULL) { + if(de1->v.voisin1 == del) + de1->v.voisin1 = NULL; + else if(de1->v.voisin2 == del) + de1->v.voisin2 = NULL; + else if(de1->v.voisin3 == del) + de1->v.voisin3 = NULL; else - Msg(GERROR, "Bad link in Boyer Watson"); + Msg(GERROR, "Bad link in Boyer Watson"); } - if(de2 != NULL){ - if (de2->v.voisin1 == del )de2->v.voisin1 = NULL; - else if (de2->v.voisin2 == del )de2->v.voisin2 = NULL; - else if (de2->v.voisin3 == del )de2->v.voisin3 = NULL; + if(de2 != NULL) { + if(de2->v.voisin1 == del) + de2->v.voisin1 = NULL; + else if(de2->v.voisin2 == del) + de2->v.voisin2 = NULL; + else if(de2->v.voisin3 == del) + de2->v.voisin3 = NULL; else - Msg(GERROR, "Bad link in Boyer Watson"); - } - if(de3 != NULL){ - if (de3->v.voisin1 == del )de3->v.voisin1 = NULL; - else if (de3->v.voisin2 == del )de3->v.voisin2 = NULL; - else if (de3->v.voisin3 == del )de3->v.voisin3 = NULL; + Msg(GERROR, "Bad link in Boyer Watson"); + } + if(de3 != NULL) { + if(de3->v.voisin1 == del) + de3->v.voisin1 = NULL; + else if(de3->v.voisin2 == del) + de3->v.voisin2 = NULL; + else if(de3->v.voisin3 == del) + de3->v.voisin3 = NULL; else Msg(GERROR, "Bad link in Boyer Watson"); - } - - del->v.voisin1 = NULL ; - del->v.voisin2 = NULL ; - del->v.voisin3 = NULL ; - - - if ( de1 != NULL ){ - if(!PE_Del_Triangle ( de1,pt,ListEdges,listkill,listDelforlink, numlink, numdel))return(0); } - if ( de2 != NULL ){ - if(!PE_Del_Triangle ( de2,pt,ListEdges,listkill,listDelforlink, numlink, numdel))return(0); + + del->v.voisin1 = NULL; + del->v.voisin2 = NULL; + del->v.voisin3 = NULL; + + + if(de1 != NULL) { + if(!PE_Del_Triangle + (de1, pt, ListEdges, listkill, listDelforlink, numlink, numdel)) + return (0); + } + if(de2 != NULL) { + if(!PE_Del_Triangle + (de2, pt, ListEdges, listkill, listDelforlink, numlink, numdel)) + return (0); } - if ( de3 != NULL ){ - if(!PE_Del_Triangle ( de3,pt,ListEdges,listkill,listDelforlink, numlink, numdel))return(0); + if(de3 != NULL) { + if(!PE_Del_Triangle + (de3, pt, ListEdges, listkill, listDelforlink, numlink, numdel)) + return (0); } - return(1); + return (1); } } diff --git a/Mesh/2D_Bricks.cpp b/Mesh/2D_Bricks.cpp index 314e68f9337d9e1df6fb87374590bd84b90a37a3..4a1a9dbab6966c5a3be1176eeb19e24522663ba3 100644 --- a/Mesh/2D_Bricks.cpp +++ b/Mesh/2D_Bricks.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_Bricks.cpp,v 1.9 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: 2D_Bricks.cpp,v 1.10 2003-03-01 22:36:40 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -24,58 +24,60 @@ #include "Mesh.h" #include "2D_Mesh.h" -static double XmaxGrid,YmaxGrid,XminGrid,YminGrid,ZmaxGrid,ZminGrid; -static double XminBox,XmaxBox,YminBox,YmaxBox,ZminBox,ZmaxBox; -static int Nx=0,Ny=0,Nz=0; -static List_T *GridList; -static DocRecord *MyMesh; +static double XmaxGrid, YmaxGrid, XminGrid, YminGrid, ZmaxGrid, ZminGrid; +static double XminBox, XmaxBox, YminBox, YmaxBox, ZminBox, ZmaxBox; +static int Nx = 0, Ny = 0, Nz = 0; +static List_T *GridList; +static DocRecord *MyMesh; extern PointRecord *gPointArray; -int fcmp_Map(const void * a, const void * b) { - return ((struct Map *)a)->Num - ((struct Map *)b)->Num ; +int fcmp_Map(const void *a, const void *b) +{ + return ((struct Map *)a)->Num - ((struct Map *)b)->Num; } -void Invert_MappingLists (List_T * List1, List_T * List2) { - - struct Map TmpMap1, TmpMap2 ; - struct Map * TmpMap; - List_T * TmpList; +void Invert_MappingLists(List_T * List1, List_T * List2) +{ + struct Map TmpMap1, TmpMap2; + struct Map *TmpMap; + List_T *TmpList; int i, j, Entity, CurrentEntity; - TmpList = List_Create(10*List_Nbr(List1), 100, sizeof(int)); + TmpList = List_Create(10 * List_Nbr(List1), 100, sizeof(int)); - for(i=0 ; i<List_Nbr(List1) ; i++){ + for(i = 0; i < List_Nbr(List1); i++) { List_Read(List1, i, &TmpMap1); - for(j=0 ; j<List_Nbr(TmpMap1.List) ; j++){ + for(j = 0; j < List_Nbr(TmpMap1.List); j++) { List_Read(TmpMap1.List, j, &Entity); List_Add(TmpList, &Entity); } } - + List_Sort(TmpList, fcmp_int); List_Read(TmpList, 0, &CurrentEntity); TmpMap1.Num = CurrentEntity; TmpMap1.List = List_Create(10, 10, sizeof(int)); List_Add(List2, &TmpMap1); - for(i=1 ; i<List_Nbr(TmpList) ; i++){ + for(i = 1; i < List_Nbr(TmpList); i++) { List_Read(TmpList, i, &Entity); - if (Entity != CurrentEntity) { + if(Entity != CurrentEntity) { CurrentEntity = Entity; TmpMap1.Num = CurrentEntity; TmpMap1.List = List_Create(10, 10, sizeof(int)); List_Add(List2, &TmpMap1); } } - - for(i=0 ; i<List_Nbr(List1) ; i++){ + + for(i = 0; i < List_Nbr(List1); i++) { List_Read(List1, i, &TmpMap1); - for(j=0 ; j<List_Nbr(TmpMap1.List) ; j++){ + for(j = 0; j < List_Nbr(TmpMap1.List); j++) { List_Read(TmpMap1.List, j, &Entity); TmpMap2.Num = Entity; - if ((TmpMap = (struct Map*)List_PQuery(List2, &TmpMap2, fcmp_Map)) != NULL) { + if((TmpMap = + (struct Map *)List_PQuery(List2, &TmpMap2, fcmp_Map)) != NULL) { List_Add(TmpMap->List, &TmpMap1.Num); } } @@ -85,78 +87,80 @@ void Invert_MappingLists (List_T * List1, List_T * List2) { } -int InWhichBrick (double X, double Y, double Z) { - - int Ix,Iy,Iz; +int InWhichBrick(double X, double Y, double Z) +{ + int Ix, Iy, Iz; - if(X > XmaxGrid || X < XminGrid || Y > YmaxGrid || + if(X > XmaxGrid || X < XminGrid || Y > YmaxGrid || Y < YminGrid || Z > ZmaxGrid || Z < ZminGrid) - return(-1); - - Ix = (int) ((double)Nx * (X-XminGrid) / (XmaxGrid-XminGrid)); - Iy = (int) ((double)Ny * (Y-YminGrid) / (YmaxGrid-YminGrid)); - Iz = (int) ((double)Nz * (Z-ZminGrid) / (ZmaxGrid-ZminGrid)); - Ix = (Ix< Nx)? Ix : Nx-1; - Iy = (Iy< Ny)? Iy : Ny-1; - Iz = (Iz< Nz)? Iz : Nz-1; - return(1 + Ix + Iy*Nx + Iz*Nx*Ny); + return (-1); + + Ix = (int)((double)Nx * (X - XminGrid) / (XmaxGrid - XminGrid)); + Iy = (int)((double)Ny * (Y - YminGrid) / (YmaxGrid - YminGrid)); + Iz = (int)((double)Nz * (Z - ZminGrid) / (ZmaxGrid - ZminGrid)); + Ix = (Ix < Nx) ? Ix : Nx - 1; + Iy = (Iy < Ny) ? Iy : Ny - 1; + Iz = (Iz < Nz) ? Iz : Nz - 1; + return (1 + Ix + Iy * Nx + Iz * Nx * Ny); } - -List_T *AllBricksForABox (void){ +List_T *AllBricksForABox(void) +{ List_T *List; - int Ix1,Ix2,Iy1,Iy2,Iz1,Iz2; - int i,j,k,Num; - - Ix1 = (int) ( (double)Nx * (XminBox-XminGrid) / (XmaxGrid-XminGrid)); - Ix2 = (int) ( (double)Nx * (XmaxBox-XminGrid) / (XmaxGrid-XminGrid)); - Iy1 = (int) ( (double)Ny * (YminBox-YminGrid) / (YmaxGrid-YminGrid)); - Iy2 = (int) ( (double)Ny * (YmaxBox-YminGrid) / (YmaxGrid-YminGrid)); - Iz1 = (int) ( (double)Nz * (ZminBox-ZminGrid) / (ZmaxGrid-ZminGrid)); - Iz2 = (int) ( (double)Nz * (ZmaxBox-ZminGrid) / (ZmaxGrid-ZminGrid)); - Ix1 = (Ix1<Nx)? Ix1 : Nx-1; - Ix2 = (Ix2<Nx)? Ix2 : Nx-1; - Iy1 = (Iy1<Ny)? Iy1 : Ny-1; - Iy2 = (Iy2<Ny)? Iy2 : Ny-1; - Iz1 = (Iz1<Nz)? Iz1 : Nz-1; - Iz2 = (Iz2<Nz)? Iz2 : Nz-1; - - List = List_Create((Ix2-Ix1+1)*(Iy2-Iy1+1)*(Iz2-Iz1+1), 1, sizeof(int)); - - for(i=Ix1;i<=Ix2;i++){ - for(j=Iy1;j<=Iy2;j++){ - for(k=Iz1;k<=Iz2;k++){ - Num = 1 + i + j*Nx + k*Nx*Ny ; + int Ix1, Ix2, Iy1, Iy2, Iz1, Iz2; + int i, j, k, Num; + + Ix1 = (int)((double)Nx * (XminBox - XminGrid) / (XmaxGrid - XminGrid)); + Ix2 = (int)((double)Nx * (XmaxBox - XminGrid) / (XmaxGrid - XminGrid)); + Iy1 = (int)((double)Ny * (YminBox - YminGrid) / (YmaxGrid - YminGrid)); + Iy2 = (int)((double)Ny * (YmaxBox - YminGrid) / (YmaxGrid - YminGrid)); + Iz1 = (int)((double)Nz * (ZminBox - ZminGrid) / (ZmaxGrid - ZminGrid)); + Iz2 = (int)((double)Nz * (ZmaxBox - ZminGrid) / (ZmaxGrid - ZminGrid)); + Ix1 = (Ix1 < Nx) ? Ix1 : Nx - 1; + Ix2 = (Ix2 < Nx) ? Ix2 : Nx - 1; + Iy1 = (Iy1 < Ny) ? Iy1 : Ny - 1; + Iy2 = (Iy2 < Ny) ? Iy2 : Ny - 1; + Iz1 = (Iz1 < Nz) ? Iz1 : Nz - 1; + Iz2 = (Iz2 < Nz) ? Iz2 : Nz - 1; + + List = + List_Create((Ix2 - Ix1 + 1) * (Iy2 - Iy1 + 1) * (Iz2 - Iz1 + 1), 1, + sizeof(int)); + + for(i = Ix1; i <= Ix2; i++) { + for(j = Iy1; j <= Iy2; j++) { + for(k = Iz1; k <= Iz2; k++) { + Num = 1 + i + j * Nx + k * Nx * Ny; List_Add(List, &Num); } } } - return(List); + return (List); } -void InitBricks (DocRecord *MESH) { - - int i,j,a,b,c; - List_T *InvList; - struct Map InvMap; - double X[3],Y[3],dx,dy; +void InitBricks(DocRecord * MESH) +{ + int i, j, a, b, c; + List_T *InvList; + struct Map InvMap; + double X[3], Y[3], dx, dy; MyMesh = MESH; Nx = (int)sqrt((double)MESH->numTriangles) + 1; Ny = Nx; - Nz=1; - ZminGrid=0.; - ZmaxGrid=1.; + Nz = 1; + ZminGrid = 0.; + ZmaxGrid = 1.; - GridList = List_Create(Nx*Ny*Nz, 1, sizeof(struct Map)); - InvList = List_Create(MESH->numTriangles, 1, sizeof(struct Map)); + GridList = List_Create(Nx * Ny * Nz, 1, sizeof(struct Map)); + InvList = List_Create(MESH->numTriangles, 1, sizeof(struct Map)); - for(i=0;i<MESH->numTriangles;i++){ + for(i = 0; i < MESH->numTriangles; i++) { a = MESH->delaunay[i].t.a; b = MESH->delaunay[i].t.b; c = MESH->delaunay[i].t.c; - + X[0] = MESH->points[a].where.h; X[1] = MESH->points[b].where.h; X[2] = MESH->points[c].where.h; @@ -164,16 +168,16 @@ void InitBricks (DocRecord *MESH) { Y[1] = MESH->points[b].where.v; Y[2] = MESH->points[c].where.v; - if(!i){ + if(!i) { XminGrid = XmaxGrid = X[0]; YminGrid = YmaxGrid = Y[0]; } - for(j=0;j<3;j++){ - XmaxGrid = DMAX (XmaxGrid,X[j]); - XminGrid = DMIN (XminGrid,X[j]); - YmaxGrid = DMAX (YmaxGrid,Y[j]); - YminGrid = DMIN (YminGrid,Y[j]); + for(j = 0; j < 3; j++) { + XmaxGrid = DMAX(XmaxGrid, X[j]); + XminGrid = DMIN(XminGrid, X[j]); + YmaxGrid = DMAX(YmaxGrid, Y[j]); + YminGrid = DMIN(YminGrid, Y[j]); } } dx = XmaxGrid - XminGrid; @@ -183,11 +187,11 @@ void InitBricks (DocRecord *MESH) { XminGrid -= 0.01 * dx; YminGrid -= 0.01 * dy; - for(i=0;i<MESH->numTriangles;i++){ + for(i = 0; i < MESH->numTriangles; i++) { a = MESH->delaunay[i].t.a; b = MESH->delaunay[i].t.b; c = MESH->delaunay[i].t.c; - + X[0] = XminBox = XmaxBox = MESH->points[a].where.h; X[1] = MESH->points[b].where.h; X[2] = MESH->points[c].where.h; @@ -195,17 +199,17 @@ void InitBricks (DocRecord *MESH) { Y[1] = MESH->points[b].where.v; Y[2] = MESH->points[c].where.v; - for(j=1;j<3;j++){ - XmaxBox = DMAX ( XmaxBox ,X[j] ); - XminBox = DMIN ( XminBox ,X[j] ); - YmaxBox = DMAX ( YmaxBox ,Y[j] ); - YminBox = DMIN ( YminBox ,Y[j] ); + for(j = 1; j < 3; j++) { + XmaxBox = DMAX(XmaxBox, X[j]); + XminBox = DMIN(XminBox, X[j]); + YmaxBox = DMAX(YmaxBox, Y[j]); + YminBox = DMIN(YminBox, Y[j]); } ZmaxBox = 1.0; ZminBox = 0.0; InvMap.Num = i; - InvMap.List = AllBricksForABox(); + InvMap.List = AllBricksForABox(); List_Add(InvList, &InvMap); } @@ -214,36 +218,37 @@ void InitBricks (DocRecord *MESH) { } -Delaunay * Find_Triangle (MPoint pt, DocRecord *MESH, int typ) { - - int a,b,c,i,found,KeyBrick,j; - Delaunay *del,*del2; - double Z,Znew; +Delaunay *Find_Triangle(MPoint pt, DocRecord * MESH, int typ) +{ + int a, b, c, i, found, KeyBrick, j; + Delaunay *del, *del2; + double Z, Znew; PointRecord *ptr; - double Xcg,Ycg; - struct Map *pBrick; + double Xcg, Ycg; + struct Map *pBrick; ptr = gPointArray; gPointArray = MESH->points; - if(MyMesh == MESH){ - KeyBrick = InWhichBrick(pt.h,pt.v,0.0); - if((pBrick = (struct Map *)List_PQuery(GridList, &KeyBrick, fcmp_Map)) == NULL){ - if(typ == A_TOUT_PRIX){ + if(MyMesh == MESH) { + KeyBrick = InWhichBrick(pt.h, pt.v, 0.0); + if((pBrick = + (struct Map *)List_PQuery(GridList, &KeyBrick, fcmp_Map)) == NULL) { + if(typ == A_TOUT_PRIX) { gPointArray = ptr; - return(NULL); + return (NULL); } } - else{ - for(i=0;i<List_Nbr(pBrick->List);i++){ - j = *(int *)List_Pointer(pBrick->List,i); + else { + for(i = 0; i < List_Nbr(pBrick->List); i++) { + j = *(int *)List_Pointer(pBrick->List, i); a = MESH->delaunay[j].t.a; b = MESH->delaunay[j].t.b; c = MESH->delaunay[j].t.c; - if(MESH->delaunay[j].t.position != EXTERN || typ == BOF){ - if(PtInTriangle(pt,a,b,c)){ + if(MESH->delaunay[j].t.position != EXTERN || typ == BOF) { + if(PtInTriangle(pt, a, b, c)) { gPointArray = ptr; - return(&MESH->delaunay[j]); + return (&MESH->delaunay[j]); } } } @@ -254,53 +259,50 @@ Delaunay * Find_Triangle (MPoint pt, DocRecord *MESH, int typ) { } } else { - i=0; + i = 0; found = 0; - while (!found && i<MESH->numTriangles) { - if( (!PtInTriangle(pt,MESH->delaunay[i].t.a,MESH->delaunay[i].t.b, - MESH->delaunay[i].t.c)) || - (MESH->delaunay[i].t.position == EXTERN && typ != BOF ))i++; + while(!found && i < MESH->numTriangles) { + if((!PtInTriangle(pt, MESH->delaunay[i].t.a, MESH->delaunay[i].t.b, + MESH->delaunay[i].t.c)) || + (MESH->delaunay[i].t.position == EXTERN && typ != BOF)) + i++; else found = 1; }; - - if(found == 1){ + + if(found == 1) { gPointArray = ptr; - return(&(MESH->delaunay[i])); + return (&(MESH->delaunay[i])); } - if(typ == A_TOUT_PRIX){ + if(typ == A_TOUT_PRIX) { gPointArray = ptr; return NULL; } } - + del = &(MESH->delaunay[0]); - Xcg = gPointArray[del->t.a].where.h + - gPointArray[del->t.b].where.h + - gPointArray[del->t.c].where.h; - - Ycg = gPointArray[del->t.a].where.v + - gPointArray[del->t.b].where.v + - gPointArray[del->t.c].where.v; - - Xcg/=3.; - Ycg/=3.; - - Z = DSQR(Xcg-pt.h) + DSQR(Ycg-pt.v); - - for (i=1;i<MESH->numTriangles;i++){ - del2 = &(MESH->delaunay[i]); - Xcg = gPointArray[del2->t.a].where.h + - gPointArray[del2->t.b].where.h + - gPointArray[del2->t.c].where.h; - Ycg = gPointArray[del2->t.a].where.v + - gPointArray[del2->t.b].where.v + - gPointArray[del2->t.c].where.v; - Xcg /= 3. ; + Xcg = gPointArray[del->t.a].where.h + + gPointArray[del->t.b].where.h + gPointArray[del->t.c].where.h; + + Ycg = gPointArray[del->t.a].where.v + + gPointArray[del->t.b].where.v + gPointArray[del->t.c].where.v; + + Xcg /= 3.; + Ycg /= 3.; + + Z = DSQR(Xcg - pt.h) + DSQR(Ycg - pt.v); + + for(i = 1; i < MESH->numTriangles; i++) { + del2 = &(MESH->delaunay[i]); + Xcg = gPointArray[del2->t.a].where.h + + gPointArray[del2->t.b].where.h + gPointArray[del2->t.c].where.h; + Ycg = gPointArray[del2->t.a].where.v + + gPointArray[del2->t.b].where.v + gPointArray[del2->t.c].where.v; + Xcg /= 3.; Ycg /= 3.; - Znew = DSQR(Xcg-pt.h) + DSQR(Ycg-pt.v); - if (Znew<Z){ + Znew = DSQR(Xcg - pt.h) + DSQR(Ycg - pt.v); + if(Znew < Z) { del = del2; Z = Znew; } @@ -310,10 +312,11 @@ Delaunay * Find_Triangle (MPoint pt, DocRecord *MESH, int typ) { return del; } -int PtInTriangle(MPoint p , PointNumero a , PointNumero b , PointNumero c){ - double Xmin , Xmax , Ymin, Ymax , Xtr[4],Ytr[4],A[2],B[2],X,Y,Signus[3]; +int PtInTriangle(MPoint p, PointNumero a, PointNumero b, PointNumero c) +{ + double Xmin, Xmax, Ymin, Ymax, Xtr[4], Ytr[4], A[2], B[2], X, Y, Signus[3]; int i; - + X = p.h; Y = p.v; Xtr[0] = Xmax = Xmin = gPointArray[a].where.h; @@ -324,26 +327,27 @@ int PtInTriangle(MPoint p , PointNumero a , PointNumero b , PointNumero c){ Ytr[3] = gPointArray[a].where.v; Ytr[1] = gPointArray[b].where.v; Ytr[2] = gPointArray[c].where.v; - - for(i=1;i<3;i++){ - Xmin = (Xtr[i]<Xmin)?Xtr[i]:Xmin; - Xmax = (Xtr[i]>Xmax)?Xtr[i]:Xmax; - Ymin = (Ytr[i]<Ymin)?Ytr[i]:Ymin; - Ymax = (Ytr[i]>Ymax)?Ytr[i]:Ymax; + + for(i = 1; i < 3; i++) { + Xmin = (Xtr[i] < Xmin) ? Xtr[i] : Xmin; + Xmax = (Xtr[i] > Xmax) ? Xtr[i] : Xmax; + Ymin = (Ytr[i] < Ymin) ? Ytr[i] : Ymin; + Ymax = (Ytr[i] > Ymax) ? Ytr[i] : Ymax; } - - if(X>Xmax || X<Xmin || Y>Ymax || Y<Ymin) return(0); - - for (i=0;i<3;i++){ - A[0] = Xtr[i+1] - Xtr[i]; - A[1] = Ytr[i+1] - Ytr[i]; + + if(X > Xmax || X < Xmin || Y > Ymax || Y < Ymin) + return (0); + + for(i = 0; i < 3; i++) { + A[0] = Xtr[i + 1] - Xtr[i]; + A[1] = Ytr[i + 1] - Ytr[i]; B[0] = X - Xtr[i]; B[1] = Y - Ytr[i]; Signus[i] = A[0] * B[1] - A[1] * B[0]; } - for (i=0;i<2;i++){ - if(( Signus[i] * Signus[i+1] ) <= 0 ) return(0); + for(i = 0; i < 2; i++) { + if((Signus[i] * Signus[i + 1]) <= 0) + return (0); } - return(1); + return (1); } - diff --git a/Mesh/2D_Cylindrical.cpp b/Mesh/2D_Cylindrical.cpp index 823bd93770619e8feae5c00f85b5b32e2fdf7ccc..ca66bd705b95330dff583e40a4ddf1017139fa6e 100644 --- a/Mesh/2D_Cylindrical.cpp +++ b/Mesh/2D_Cylindrical.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_Cylindrical.cpp,v 1.13 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: 2D_Cylindrical.cpp,v 1.14 2003-03-01 22:36:40 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -24,24 +24,26 @@ #include "Mesh.h" #include "Context.h" -extern Mesh *THEM; -extern Context_T CTX; +extern Mesh *THEM; +extern Context_T CTX; static Surface *SURF; static double THETAMIN, THETAMAX; -void ChangePi (void *a, void *dum){ +void ChangePi(void *a, void *dum) +{ Vertex *v; v = *(Vertex **) a; - if ((v->Pos.X / SURF->Cyl.radius1) >= THETAMIN + .99999 * Pi){ + if((v->Pos.X / SURF->Cyl.radius1) >= THETAMIN + .99999 * Pi) { Msg(INFO, "%g -> ", v->Pos.X / SURF->Cyl.radius1); v->Pos.X -= (2. * Pi) * SURF->Cyl.radius1; Msg(INFO, "%g -> ", v->Pos.X / SURF->Cyl.radius1); } } -void THETAMINMAX (void *a, void *dum){ +void THETAMINMAX(void *a, void *dum) +{ Vertex *v; double ZRepere, S, C, y[3], teta; double p[3], z[3], x[3], o[3]; @@ -54,8 +56,8 @@ void THETAMINMAX (void *a, void *dum){ z[0] = SURF->Cyl.zaxis[0]; z[1] = SURF->Cyl.zaxis[1]; z[2] = SURF->Cyl.zaxis[2]; - norme (z); - prosca (p, z, &ZRepere); + norme(z); + prosca(p, z, &ZRepere); //ZRepere = fabs(ZRepere); @@ -66,20 +68,21 @@ void THETAMINMAX (void *a, void *dum){ x[1] = SURF->Cyl.xaxis[1]; x[2] = SURF->Cyl.xaxis[2]; - norme (o); - norme (x); - prodve (z, x, y); - norme (y); - prosca (o, x, &C); - prosca (o, y, &S); - teta = atan2 (S, C); - THETAMIN = DMIN (teta, THETAMIN); - THETAMAX = DMAX (teta, THETAMAX); + norme(o); + norme(x); + prodve(z, x, y); + norme(y); + prosca(o, x, &C); + prosca(o, y, &S); + teta = atan2(S, C); + THETAMIN = DMIN(teta, THETAMIN); + THETAMAX = DMAX(teta, THETAMAX); } // Cylindrical surfaces -void XYZtoTZ (void *a, void *dum){ +void XYZtoTZ(void *a, void *dum) +{ Vertex *v; double ZRepere, S, C, y[3], teta; double p[3], z[3], x[3], o[3]; @@ -92,8 +95,8 @@ void XYZtoTZ (void *a, void *dum){ z[0] = SURF->Cyl.zaxis[0]; z[1] = SURF->Cyl.zaxis[1]; z[2] = SURF->Cyl.zaxis[2]; - norme (z); - prosca (p, z, &ZRepere); + norme(z); + prosca(p, z, &ZRepere); //ZRepere = fabs(ZRepere); @@ -104,13 +107,13 @@ void XYZtoTZ (void *a, void *dum){ x[1] = SURF->Cyl.xaxis[1]; x[2] = SURF->Cyl.xaxis[2]; - norme (o); - norme (x); - prodve (z, x, y); - norme (y); - prosca (o, x, &C); - prosca (o, y, &S); - teta = atan2 (S, C); + norme(o); + norme(x); + prodve(z, x, y); + norme(y); + prosca(o, x, &C); + prosca(o, y, &S); + teta = atan2(S, C); Msg(DEBUG, "pt %d %g %g", v->Num, ZRepere, teta); v->Pos.X = teta * SURF->Cyl.radius1; @@ -118,7 +121,8 @@ void XYZtoTZ (void *a, void *dum){ v->Pos.Z = 0.0; } -void TZtoXYZ (void *a, void *dum){ +void TZtoXYZ(void *a, void *dum) +{ Vertex *v; double d[3], x[3], prv[3]; double XX, YY, ZZ; @@ -127,23 +131,23 @@ void TZtoXYZ (void *a, void *dum){ d[0] = SURF->Cyl.zaxis[0]; d[1] = SURF->Cyl.zaxis[1]; d[2] = SURF->Cyl.zaxis[2]; - norme (d); + norme(d); x[0] = SURF->Cyl.xaxis[0]; x[1] = SURF->Cyl.xaxis[1]; x[2] = SURF->Cyl.xaxis[2]; - norme (x); - prodve (d, x, prv); - norme (prv); + norme(x); + prodve(d, x, prv); + norme(prv); XX = SURF->Cyl.center[0] + v->Pos.Y * d[0] + - SURF->Cyl.radius1 * cos (v->Pos.X / SURF->Cyl.radius1) * x[0] + - SURF->Cyl.radius1 * (sin (v->Pos.X / SURF->Cyl.radius1)) * prv[0]; + SURF->Cyl.radius1 * cos(v->Pos.X / SURF->Cyl.radius1) * x[0] + + SURF->Cyl.radius1 * (sin(v->Pos.X / SURF->Cyl.radius1)) * prv[0]; YY = SURF->Cyl.center[1] + v->Pos.Y * d[1] + - SURF->Cyl.radius1 * cos (v->Pos.X / SURF->Cyl.radius1) * x[1] + - SURF->Cyl.radius1 * (sin (v->Pos.X / SURF->Cyl.radius1)) * prv[1]; + SURF->Cyl.radius1 * cos(v->Pos.X / SURF->Cyl.radius1) * x[1] + + SURF->Cyl.radius1 * (sin(v->Pos.X / SURF->Cyl.radius1)) * prv[1]; ZZ = SURF->Cyl.center[2] + v->Pos.Y * d[2] + - SURF->Cyl.radius1 * cos (v->Pos.X / SURF->Cyl.radius1) * x[2] + - SURF->Cyl.radius1 * (sin (v->Pos.X / SURF->Cyl.radius1)) * prv[2]; + SURF->Cyl.radius1 * cos(v->Pos.X / SURF->Cyl.radius1) * x[2] + + SURF->Cyl.radius1 * (sin(v->Pos.X / SURF->Cyl.radius1)) * prv[2]; v->Pos.X = XX; v->Pos.Y = YY; @@ -152,7 +156,8 @@ void TZtoXYZ (void *a, void *dum){ // Conical surfaces -void XYZtoCone (void *a, void *dum){ +void XYZtoCone(void *a, void *dum) +{ Vertex *v; double ZRepere, S, C, y[3], teta; double p[3], z[3], x[3], o[3]; @@ -166,8 +171,8 @@ void XYZtoCone (void *a, void *dum){ z[0] = SURF->Cyl.zaxis[0]; z[1] = SURF->Cyl.zaxis[1]; z[2] = SURF->Cyl.zaxis[2]; - norme (z); - prosca (p, z, &ZRepere); + norme(z); + prosca(p, z, &ZRepere); //ZRepere = fabs(ZRepere); @@ -178,27 +183,28 @@ void XYZtoCone (void *a, void *dum){ x[1] = SURF->Cyl.xaxis[1]; x[2] = SURF->Cyl.xaxis[2]; - norme (o); - norme (x); - prodve (z, x, y); - norme (y); - prosca (o, x, &C); - prosca (o, y, &S); - teta = atan2 (S, C); - if (teta >= THETAMIN + .99999 * Pi) + norme(o); + norme(x); + prodve(z, x, y); + norme(y); + prosca(o, x, &C); + prosca(o, y, &S); + teta = atan2(S, C); + if(teta >= THETAMIN + .99999 * Pi) teta -= (2. * Pi); inclinaison = Pi * SURF->Cyl.radius2 / 180.; - ract = SURF->Cyl.radius1 - ZRepere * tan (inclinaison); + ract = SURF->Cyl.radius1 - ZRepere * tan(inclinaison); - v->Pos.X = ract * cos (teta); - v->Pos.Y = ract * sin (teta); + v->Pos.X = ract * cos(teta); + v->Pos.Y = ract * sin(teta); v->Pos.Z = 0.0; - Msg (DEBUG, "%g %g", ZRepere, v->Pos.X); + Msg(DEBUG, "%g %g", ZRepere, v->Pos.X); } -void ConetoXYZ (void *a, void *dum){ +void ConetoXYZ(void *a, void *dum) +{ Vertex *v; double d[3], z, x[3], prv[3]; double XX, YY, ZZ; @@ -208,27 +214,24 @@ void ConetoXYZ (void *a, void *dum){ d[0] = SURF->Cyl.zaxis[0]; d[1] = SURF->Cyl.zaxis[1]; d[2] = SURF->Cyl.zaxis[2]; - norme (d); + norme(d); x[0] = SURF->Cyl.xaxis[0]; x[1] = SURF->Cyl.xaxis[1]; x[2] = SURF->Cyl.xaxis[2]; - norme (x); - prodve (d, x, prv); - norme (prv); + norme(x); + prodve(d, x, prv); + norme(prv); inclinaison = Pi * SURF->Cyl.radius2 / 180.; - z = (SURF->Cyl.radius1 - myhypot (v->Pos.X, v->Pos.Y)) / tan (inclinaison); - radiusact = (SURF->Cyl.radius1 + z * tan (inclinaison)); - teta = atan2 (v->Pos.Y, v->Pos.X); + z = (SURF->Cyl.radius1 - myhypot(v->Pos.X, v->Pos.Y)) / tan(inclinaison); + radiusact = (SURF->Cyl.radius1 + z * tan(inclinaison)); + teta = atan2(v->Pos.Y, v->Pos.X); XX = SURF->Cyl.center[0] + z * d[0] + - radiusact * cos (teta) * x[0] + - radiusact * (sin (teta)) * prv[0]; + radiusact * cos(teta) * x[0] + radiusact * (sin(teta)) * prv[0]; YY = SURF->Cyl.center[1] + z * d[1] + - radiusact * cos (teta) * x[1] + - radiusact * (sin (teta)) * prv[1]; + radiusact * cos(teta) * x[1] + radiusact * (sin(teta)) * prv[1]; ZZ = SURF->Cyl.center[2] + z * d[2] + - radiusact * cos (teta) * x[2] + - radiusact * (sin (teta)) * prv[2]; + radiusact * cos(teta) * x[2] + radiusact * (sin(teta)) * prv[2]; v->Pos.X = XX; v->Pos.Y = YY; @@ -236,11 +239,11 @@ void ConetoXYZ (void *a, void *dum){ } -int MeshCylindricalSurface (Surface * s){ - +int MeshCylindricalSurface(Surface * s) +{ return 0; -#if 0 +#if 0 int i, j, ori; Curve *pC; @@ -249,63 +252,63 @@ int MeshCylindricalSurface (Surface * s){ char text[256]; extern double MAXIMUM_LC_FOR_SURFACE; - if (s->Typ != MSH_SURF_CYLNDR && s->Typ != MSH_SURF_CONE - && s->Typ != MSH_SURF_TORUS) + if(s->Typ != MSH_SURF_CYLNDR && s->Typ != MSH_SURF_CONE + && s->Typ != MSH_SURF_TORUS) return 0; - if (s->Typ == MSH_SURF_TORUS) + if(s->Typ == MSH_SURF_TORUS) return 1; - Msg (DEBUG, "z %d : %12.5E %12.5E %12.5E", s->Num, s->Cyl.zaxis[0], - s->Cyl.zaxis[1], s->Cyl.zaxis[2]); + Msg(DEBUG, "z %d : %12.5E %12.5E %12.5E", s->Num, s->Cyl.zaxis[0], + s->Cyl.zaxis[1], s->Cyl.zaxis[2]); Msg(DEBUG, "x %d : %12.5E %12.5E %12.5E", s->Num, s->Cyl.xaxis[0], s->Cyl.xaxis[1], s->Cyl.xaxis[2]); SURF = s; - for (i = 0; i < List_Nbr (s->Generatrices); i++){ - List_Read (s->Generatrices, i, &pC); - for (j = 0; j < List_Nbr (pC->Vertices); j++){ - List_Read (pC->Vertices, j, &v); - Tree_Insert (s->Vertices, List_Pointer (pC->Vertices, j)); + for(i = 0; i < List_Nbr(s->Generatrices); i++) { + List_Read(s->Generatrices, i, &pC); + for(j = 0; j < List_Nbr(pC->Vertices); j++) { + List_Read(pC->Vertices, j, &v); + Tree_Insert(s->Vertices, List_Pointer(pC->Vertices, j)); } } THETAMIN = 2. * Pi; THETAMAX = -2. * Pi; - Tree_Action (s->Vertices, THETAMINMAX); - Tree_Action (s->Vertices, Freeze_Vertex); + Tree_Action(s->Vertices, THETAMINMAX); + Tree_Action(s->Vertices, Freeze_Vertex); - if (s->Typ == MSH_SURF_CYLNDR) - Tree_Action (s->Vertices, XYZtoTZ); - else if (s->Typ == MSH_SURF_CONE) - Tree_Action (s->Vertices, XYZtoCone); + if(s->Typ == MSH_SURF_CYLNDR) + Tree_Action(s->Vertices, XYZtoTZ); + else if(s->Typ == MSH_SURF_CONE) + Tree_Action(s->Vertices, XYZtoCone); Msg(DEBUG, "%12.5E %12.5E", THETAMAX, THETAMIN); - if ((s->Typ == MSH_SURF_CYLNDR) && (THETAMAX - THETAMIN > Pi * 1.01)) - Tree_Action (s->Vertices, ChangePi); + if((s->Typ == MSH_SURF_CYLNDR) && (THETAMAX - THETAMIN > Pi * 1.01)) + Tree_Action(s->Vertices, ChangePi); - ori = Calcule_Contours (s); + ori = Calcule_Contours(s); MAXIMUM_LC_FOR_SURFACE = SURF->Cyl.radius1 / 3.; - if (CTX.mesh.algo == DELAUNAY_ISO) - Maillage_Automatique_VieuxCode (s, THEM, ori); - else if (CTX.mesh.algo == DELAUNAY_ANISO) - AlgorithmeMaillage2DAnisotropeModeJF (s); + if(CTX.mesh.algo == DELAUNAY_ISO) + Maillage_Automatique_VieuxCode(s, THEM, ori); + else if(CTX.mesh.algo == DELAUNAY_ANISO) + AlgorithmeMaillage2DAnisotropeModeJF(s); else Mesh_Shewchuk(s); - for(i = 0 ; i < CTX.mesh.nb_smoothing ; i++){ - tnxe = Tree_Create (sizeof (NXE), compareNXE); - create_NXE (s->Vertices, s->Simplexes, tnxe); - Tree_Action (tnxe, ActionLiss); - Tree_Delete (tnxe); + for(i = 0; i < CTX.mesh.nb_smoothing; i++) { + tnxe = Tree_Create(sizeof(NXE), compareNXE); + create_NXE(s->Vertices, s->Simplexes, tnxe); + Tree_Action(tnxe, ActionLiss); + Tree_Delete(tnxe); } - if (s->Typ == MSH_SURF_CYLNDR) - Tree_Action (s->Vertices, TZtoXYZ); - else if (s->Typ == MSH_SURF_CONE) - Tree_Action (s->Vertices, ConetoXYZ); - Tree_Action (s->Vertices, deFreeze_Vertex); + if(s->Typ == MSH_SURF_CYLNDR) + Tree_Action(s->Vertices, TZtoXYZ); + else if(s->Typ == MSH_SURF_CONE) + Tree_Action(s->Vertices, ConetoXYZ); + Tree_Action(s->Vertices, deFreeze_Vertex); return 1; diff --git a/Mesh/2D_DivAndConq.cpp b/Mesh/2D_DivAndConq.cpp index 67008c43bf504f47f107c9b492d6a47d06044b9e..88c7d5e258ed8aac3dbf11a8c007ce846aa76500 100644 --- a/Mesh/2D_DivAndConq.cpp +++ b/Mesh/2D_DivAndConq.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_DivAndConq.cpp,v 1.16 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: 2D_DivAndConq.cpp,v 1.17 2003-03-01 22:36:40 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -46,91 +46,100 @@ extern double LC2D; static PointRecord *pPointArray; -int Insert(PointNumero a,PointNumero b); -int Delete(PointNumero a,PointNumero b); +int Insert(PointNumero a, PointNumero b); +int Delete(PointNumero a, PointNumero b); -void PushgPointArray(PointRecord *ptr){ +void PushgPointArray(PointRecord * ptr) +{ pPointArray = ptr; } -PointRecord *PopgPointArray(void){ - return(pPointArray) ; +PointRecord *PopgPointArray(void) +{ + return (pPointArray); } -PointNumero Predecessor(PointNumero a, PointNumero b){ - DListPeek p; - +PointNumero Predecessor(PointNumero a, PointNumero b) +{ + DListPeek p; + p = pPointArray[a].adjacent; - if (p == NULL) - return -1; + if(p == NULL) + return -1; do { - if (p->point_num == b) return (Pred(p)->point_num); + if(p->point_num == b) + return (Pred(p)->point_num); p = Pred(p); - } while (p != pPointArray[a].adjacent); + } while(p != pPointArray[a].adjacent); + + return -1; - return -1; - } -PointNumero Successor(PointNumero a,PointNumero b){ - DListPeek p; - +PointNumero Successor(PointNumero a, PointNumero b) +{ + DListPeek p; + p = pPointArray[a].adjacent; - if (p == NULL) + if(p == NULL) return -1; do { - if (p->point_num == b) return (Succ(p)->point_num); + if(p->point_num == b) + return (Succ(p)->point_num); p = Succ(p); - } while (p != pPointArray[a].adjacent); + } while(p != pPointArray[a].adjacent); + + return -1; - return -1; - } -int FixFirst(PointNumero x,PointNumero f){ - DListPeek p,copy; - int out = 0; - +int FixFirst(PointNumero x, PointNumero f) +{ + DListPeek p, copy; + int out = 0; + p = pPointArray[x].adjacent; - if (p == NULL) - return(0); + if(p == NULL) + return (0); copy = p; do { - if (p->point_num == f){ + if(p->point_num == f) { pPointArray[x].adjacent = p; out = 1; } else p = p->next; - } while ((p != copy) && !out); + } while((p != copy) && !out); return out; } -PointNumero First(PointNumero x){ +PointNumero First(PointNumero x) +{ return (pPointArray[x].adjacent)->point_num; } -Segment LowerCommonTangent(DT vl,DT vr){ - PointNumero x,y,z,z1,z2,temp; - Segment s; - - x = vl.end; /* vu le tri, c'est le point le + a droite */ - y = vr.begin; /* idem, le + a gauche */ +Segment LowerCommonTangent(DT vl, DT vr) +{ + PointNumero x, y, z, z1, z2, temp; + Segment s; + + x = vl.end; /* vu le tri, c'est le point le + a droite */ + y = vr.begin; /* idem, le + a gauche */ z = First(y); z1 = First(x); - z2 = Predecessor(x,z1); - for (;;) { - if (Is_right_of(x,y,z)){ + z2 = Predecessor(x, z1); + for(;;) { + if(Is_right_of(x, y, z)) { temp = z; - z = Successor(z,y); + z = Successor(z, y); y = temp; } - else if (Is_right_of(x,y,z2)){ + else if(Is_right_of(x, y, z2)) { temp = z2; - z2 = Predecessor(z2,x); + z2 = Predecessor(z2, x); x = temp; } else { @@ -142,27 +151,28 @@ Segment LowerCommonTangent(DT vl,DT vr){ } -Segment UpperCommonTangent(DT vl,DT vr){ - PointNumero x,y,z,z1,z2,temp; - Segment s; - - x = vl.end; /* vu le tri, c'est le point le + a droite */ - y = vr.begin; /* idem, le + a gauche */ +Segment UpperCommonTangent(DT vl, DT vr) +{ + PointNumero x, y, z, z1, z2, temp; + Segment s; + + x = vl.end; /* vu le tri, c'est le point le + a droite */ + y = vr.begin; /* idem, le + a gauche */ z = First(y); z1 = First(x); - z2 = Predecessor(y,z); - for (;;){ - if (Is_left_of(x,y,z2)){ + z2 = Predecessor(y, z); + for(;;) { + if(Is_left_of(x, y, z2)) { temp = z2; - z2 = Predecessor(z2,y); - y = temp; + z2 = Predecessor(z2, y); + y = temp; } - else if (Is_left_of(x,y,z1)){ + else if(Is_left_of(x, y, z1)) { temp = z1; - z1 = Successor(z1,x); + z1 = Successor(z1, x); x = temp; } - else{ + else { s.from = x; s.to = y; return s; @@ -174,157 +184,172 @@ Segment UpperCommonTangent(DT vl,DT vr){ /* return 1 if the point k is NOT in the circumcircle of triangle hij */ -int Qtest(PointNumero h,PointNumero i,PointNumero j,PointNumero k){ - double xc,yc,rcarre,distca; - - if ((h == i) && (h == j) && (h == k)){ - Msg(GERROR, "3 identical points in Qtest"); - return(0); /* returning 1 will cause looping for ever */ +int Qtest(PointNumero h, PointNumero i, PointNumero j, PointNumero k) +{ + double xc, yc, rcarre, distca; + + if((h == i) && (h == j) && (h == k)) { + Msg(GERROR, "3 identical points in Qtest"); + return (0); /* returning 1 will cause looping for ever */ } - if (CircumCircle( (double) pPointArray[h].where.h, - (double) pPointArray[h].where.v, - (double) pPointArray[i].where.h, - (double) pPointArray[i].where.v, - (double) pPointArray[j].where.h, - (double) pPointArray[j].where.v, - &xc, &yc )){ - rcarre = square(xc - (double) pPointArray[i].where.h) + - square(yc - (double) pPointArray[i].where.v); - - distca = square(xc - (double) pPointArray[k].where.h) + - square(yc - (double) pPointArray[k].where.v); - + if(CircumCircle((double)pPointArray[h].where.h, + (double)pPointArray[h].where.v, + (double)pPointArray[i].where.h, + (double)pPointArray[i].where.v, + (double)pPointArray[j].where.h, + (double)pPointArray[j].where.v, &xc, &yc)) { + rcarre = square(xc - (double)pPointArray[i].where.h) + + square(yc - (double)pPointArray[i].where.v); + + distca = square(xc - (double)pPointArray[k].where.h) + + square(yc - (double)pPointArray[k].where.v); + return (distca > rcarre); } else - return(0); /* point not in circle, because no circle ! */ + return (0); /* point not in circle, because no circle ! */ } -int merge(DT vl,DT vr){ - Segment bt,ut; - int a,b,out; - PointNumero r,r1,r2,l,l1,l2; - - bt = LowerCommonTangent(vl,vr); - ut = UpperCommonTangent(vl,vr); - l = bt.from; /* left endpoint of BT */ - r = bt.to; /* right endpoint of BT */ - - while ((l != ut.from) || (r != ut.to)) { +int merge(DT vl, DT vr) +{ + Segment bt, ut; + int a, b, out; + PointNumero r, r1, r2, l, l1, l2; + + bt = LowerCommonTangent(vl, vr); + ut = UpperCommonTangent(vl, vr); + l = bt.from; /* left endpoint of BT */ + r = bt.to; /* right endpoint of BT */ + + while((l != ut.from) || (r != ut.to)) { a = b = 0; - if (!Insert(l,r)) return(0); - - r1 = Predecessor(r,l); - if (r1 == -1) return(0); - if (Is_right_of(l,r,r1)) + if(!Insert(l, r)) + return (0); + + r1 = Predecessor(r, l); + if(r1 == -1) + return (0); + if(Is_right_of(l, r, r1)) a = 1; - else{ + else { out = 0; - while (!out){ - r2 = Predecessor(r,r1); - if (r2 == -1) return(0); - if (r2 < vr.begin) + while(!out) { + r2 = Predecessor(r, r1); + if(r2 == -1) + return (0); + if(r2 < vr.begin) out = 1; - else if (Qtest(l,r,r1,r2)) + else if(Qtest(l, r, r1, r2)) out = 1; - else{ - if (!Delete(r,r1)) return(0); + else { + if(!Delete(r, r1)) + return (0); r1 = r2; - if (Is_right_of(l,r,r1)) out = a = 1; + if(Is_right_of(l, r, r1)) + out = a = 1; } } } - - l1 = Successor(l,r); - if (l1 == -1) return(0); - if (Is_left_of(r,l,l1)) + + l1 = Successor(l, r); + if(l1 == -1) + return (0); + if(Is_left_of(r, l, l1)) b = 1; - else{ + else { out = 0; - while (!out){ - l2 = Successor(l,l1); - if (l2 == -1) return(0); - if (l2 > vl.end) + while(!out) { + l2 = Successor(l, l1); + if(l2 == -1) + return (0); + if(l2 > vl.end) out = 1; - else if (Qtest(r,l,l1,l2)) + else if(Qtest(r, l, l1, l2)) out = 1; - else{ - if (!Delete(l,l1)) return(0); + else { + if(!Delete(l, l1)) + return (0); l1 = l2; - if (Is_left_of(r,l,l1)) out = b = 1; - } + if(Is_left_of(r, l, l1)) + out = b = 1; + } } } - - if (a) + + if(a) l = l1; - else if (b) + else if(b) r = r1; - else{ - if (Qtest(l,r,r1,l1)) + else { + if(Qtest(l, r, r1, l1)) r = r1; else l = l1; } } - if (!Insert(l,r)) return(0); - - if (!FixFirst(ut.to,ut.from)) return(0); - if (!FixFirst(bt.from,bt.to)) return(0); - return(1); + if(!Insert(l, r)) + return (0); + + if(!FixFirst(ut.to, ut.from)) + return (0); + if(!FixFirst(bt.from, bt.to)) + return (0); + return (1); } -DT recur_trig(PointNumero left,PointNumero right){ - int n,m; - DT dt; - +DT recur_trig(PointNumero left, PointNumero right) +{ + int n, m; + DT dt; + dt.begin = left; dt.end = right; - n = right - left + 1; /* nombre de points a triangulariser */ - switch (n){ + n = right - left + 1; /* nombre de points a triangulariser */ + switch (n) { case 0: case 1: /* 0 ou 1 points -> rien a faire */ break; - - case 2: /* deux points : cas trivial */ - Insert(left,right); - FixFirst(left,right); - FixFirst(right,left); + + case 2: /* deux points : cas trivial */ + Insert(left, right); + FixFirst(left, right); + FixFirst(right, left); break; - - case 3: /* trois points : cas trivial */ - Insert(left,right); - Insert(left,left + 1); - Insert(left + 1,right); - if (Is_right_of(left,right,left + 1)){ - FixFirst(left,left + 1); - FixFirst(left + 1,right); - FixFirst(right,left); + + case 3: /* trois points : cas trivial */ + Insert(left, right); + Insert(left, left + 1); + Insert(left + 1, right); + if(Is_right_of(left, right, left + 1)) { + FixFirst(left, left + 1); + FixFirst(left + 1, right); + FixFirst(right, left); } - else{ - FixFirst(left,right); - FixFirst(left + 1,left); - FixFirst(right,left + 1); + else { + FixFirst(left, right); + FixFirst(left + 1, left); + FixFirst(right, left + 1); } break; - + default: /* plus de trois points : cas recursif */ m = (left + right) >> 1; - if (!merge(recur_trig(left,m),recur_trig(m + 1,right))) - + if(!merge(recur_trig(left, m), recur_trig(m + 1, right))) + break; } return dt; } -int comparePoints(const void *i, const void *j){ - double x,y; - - x = ((PointRecord *)i)->where.h - ((PointRecord *)j)->where.h; - if (x == 0.) { - y = ((PointRecord *)i)->where.v - ((PointRecord *)j)->where.v; +int comparePoints(const void *i, const void *j) +{ + double x, y; + + x = ((PointRecord *) i)->where.h - ((PointRecord *) j)->where.h; + if(x == 0.) { + y = ((PointRecord *) i)->where.v - ((PointRecord *) j)->where.v; return ((y < 0.) ? -1 : 1); } else @@ -334,199 +359,212 @@ int comparePoints(const void *i, const void *j){ /* this fonction builds the delaunay triangulation and the voronoi for a window. All error handling is done here. */ - -int DelaunayAndVoronoi(DocPeek doc){ - PushgPointArray(doc->points); - if (doc->numPoints < 2) return(1); +int DelaunayAndVoronoi(DocPeek doc) +{ + PushgPointArray(doc->points); - qsort(doc->points,doc->numPoints,sizeof(PointRecord),comparePoints); - recur_trig(0,doc->numPoints - 1); + if(doc->numPoints < 2) + return (1); - return 1; + qsort(doc->points, doc->numPoints, sizeof(PointRecord), comparePoints); + recur_trig(0, doc->numPoints - 1); + + return 1; } /* this routine puts in xc and yc the coord of the center of the circumcircle of triangle (x1,y1),(x2,y2),(x3,y3) */ - -int CircumCircle(double x1,double y1,double x2,double y2,double x3,double y3, - double *xc,double *yc){ - double d,a1,a2,a3; - - - d = 2. * (double)(y1*(x2-x3)+y2*(x3-x1)+y3*(x1-x2)); - if (d == 0.0){ - Msg(WARNING, "Colinear points in circum circle computation"); - *xc = *yc = -99999.; - return(0); + +int CircumCircle(double x1, double y1, double x2, double y2, double x3, + double y3, double *xc, double *yc) +{ + double d, a1, a2, a3; + + + d = 2. * (double)(y1 * (x2 - x3) + y2 * (x3 - x1) + y3 * (x1 - x2)); + if(d == 0.0) { + Msg(WARNING, "Colinear points in circum circle computation"); + *xc = *yc = -99999.; + return (0); } - - a1 = x1*x1 + y1*y1; - a2 = x2*x2 + y2*y2; - a3 = x3*x3 + y3*y3; - *xc = (double) ((a1*(y3-y2) + a2*(y1-y3) + a3*(y2-y1)) / d); - *yc = (double) ((a1*(x2-x3) + a2*(x3-x1) + a3*(x1-x2)) / d); - + + a1 = x1 * x1 + y1 * y1; + a2 = x2 * x2 + y2 * y2; + a3 = x3 * x3 + y3 * y3; + *xc = (double)((a1 * (y3 - y2) + a2 * (y1 - y3) + a3 * (y2 - y1)) / d); + *yc = (double)((a1 * (x2 - x3) + a2 * (x3 - x1) + a3 * (x1 - x2)) / d); + if(fabs(d) < 1.e-12 * DSQR(LC2D)) - Msg(WARNING, "Almost colinear points in circum circle computation (d = %g)", d); + Msg(WARNING, + "Almost colinear points in circum circle computation (d = %g)", d); - return(1); + return (1); } -int Is_right_of(PointNumero x,PointNumero y,PointNumero check){ - return Is_left_of(y,x,check); +int Is_right_of(PointNumero x, PointNumero y, PointNumero check) +{ + return Is_left_of(y, x, check); } -int Is_left_of(PointNumero x,PointNumero y,PointNumero check){ - static double xx,yy,alpha,beta; - - yy = (double) (pPointArray[y].where.v - pPointArray[x].where.v); - xx = (double) (pPointArray[y].where.h - pPointArray[x].where.h); - alpha = atan2(yy,xx); - - yy = (double) (pPointArray[check].where.v - pPointArray[x].where.v); - xx = (double) (pPointArray[check].where.h - pPointArray[x].where.h); - beta = atan2(yy,xx) - alpha; - if (beta <= 0) beta += Deux_Pi; - +int Is_left_of(PointNumero x, PointNumero y, PointNumero check) +{ + static double xx, yy, alpha, beta; + + yy = (double)(pPointArray[y].where.v - pPointArray[x].where.v); + xx = (double)(pPointArray[y].where.h - pPointArray[x].where.h); + alpha = atan2(yy, xx); + + yy = (double)(pPointArray[check].where.v - pPointArray[x].where.v); + xx = (double)(pPointArray[check].where.h - pPointArray[x].where.h); + beta = atan2(yy, xx) - alpha; + if(beta <= 0) + beta += Deux_Pi; + return ((beta >= 0) && (beta <= Pi)); } /* This routine insert the point 'newPoint' in the list dlist, respecting the clock-wise orientation. */ - -int DListInsert(DListRecord **dlist, MPoint center, PointNumero newPoint){ - DListRecord *p, *newp; - double alpha1,alpha,beta,xx,yy; - int first; - newp = (DListRecord*) Malloc(sizeof(DListRecord)); +int DListInsert(DListRecord ** dlist, MPoint center, PointNumero newPoint) +{ + DListRecord *p, *newp; + double alpha1, alpha, beta, xx, yy; + int first; + + newp = (DListRecord *) Malloc(sizeof(DListRecord)); newp->point_num = newPoint; - if (*dlist == NULL){ + if(*dlist == NULL) { *dlist = newp; Pred(*dlist) = newp; Succ(*dlist) = newp; - return(1); + return (1); } - if (Succ(*dlist) == *dlist){ + if(Succ(*dlist) == *dlist) { Pred(*dlist) = newp; Succ(*dlist) = newp; Pred(newp) = *dlist; Succ(newp) = *dlist; - return(1); + return (1); } /* If we are here, the double-linked circular list has 2 or more - elements, so we have to calculate where to put the new one. */ - + elements, so we have to calculate where to put the new one. */ + p = *dlist; first = p->point_num; - + /* first, compute polar coord. of the first point. */ - yy = (double) (pPointArray[first].where.v - center.v); - xx = (double) (pPointArray[first].where.h - center.h); - alpha1 = atan2(yy,xx); - + yy = (double)(pPointArray[first].where.v - center.v); + xx = (double)(pPointArray[first].where.h - center.h); + alpha1 = atan2(yy, xx); + /* compute polar coord of the point to insert. */ - yy = (double) (pPointArray[newPoint].where.v - center.v); - xx = (double) (pPointArray[newPoint].where.h - center.h); - beta = atan2(yy,xx) - alpha1; - if (beta <= 0) beta += Deux_Pi; - - do{ - yy = (double) (pPointArray[Succ(p)->point_num].where.v - center.v); - xx = (double) (pPointArray[Succ(p)->point_num].where.h - center.h); - alpha = atan2(yy,xx) - alpha1; - if (alpha <= 1.e-15) alpha += Deux_Pi; - if (alpha >= beta){ + yy = (double)(pPointArray[newPoint].where.v - center.v); + xx = (double)(pPointArray[newPoint].where.h - center.h); + beta = atan2(yy, xx) - alpha1; + if(beta <= 0) + beta += Deux_Pi; + + do { + yy = (double)(pPointArray[Succ(p)->point_num].where.v - center.v); + xx = (double)(pPointArray[Succ(p)->point_num].where.h - center.h); + alpha = atan2(yy, xx) - alpha1; + if(alpha <= 1.e-15) + alpha += Deux_Pi; + if(alpha >= beta) { Succ(newp) = Succ(p); Succ(p) = newp; Pred(newp) = p; Pred(Succ(newp)) = newp; - return(1); + return (1); } p = Succ(p); - } while (p != *dlist); - + } while(p != *dlist); + /*** ON NE DOIT JAMAIS ARRIVER ICI ***/ - return(0); -} + return (0); +} -int Insert(PointNumero a,PointNumero b){ +int Insert(PointNumero a, PointNumero b) +{ int rslt; - + /* This routine inserts the point 'a' in the adjency list of 'b' and the point 'b' in the adjency list of 'a'. */ - - rslt = DListInsert(&pPointArray[a].adjacent,pPointArray[a].where,b); - rslt &= DListInsert(&pPointArray[b].adjacent,pPointArray[b].where,a); + + rslt = DListInsert(&pPointArray[a].adjacent, pPointArray[a].where, b); + rslt &= DListInsert(&pPointArray[b].adjacent, pPointArray[b].where, a); return rslt; } -int DListDelete(DListPeek *dlist,PointNumero oldPoint){ - DListPeek p; - - if (*dlist == NULL) - return(0); - if (Succ(*dlist) == *dlist){ - if ((*dlist)->point_num == oldPoint){ +int DListDelete(DListPeek * dlist, PointNumero oldPoint) +{ + DListPeek p; + + if(*dlist == NULL) + return (0); + if(Succ(*dlist) == *dlist) { + if((*dlist)->point_num == oldPoint) { Free(*dlist); *dlist = NULL; - return(1); + return (1); } else - return(0); + return (0); } p = *dlist; - do{ - if (p->point_num == oldPoint){ + do { + if(p->point_num == oldPoint) { Succ(Pred(p)) = Succ(p); Pred(Succ(p)) = Pred(p); - if (p == *dlist){ + if(p == *dlist) { *dlist = Succ(p); } Free(p); - return(1); + return (1); } p = Succ(p); - } while (p != *dlist); - - return(0); + } while(p != *dlist); + + return (0); } /* This routine removes the point 'a' in the adjency list of 'b' and the point 'b' in the adjency list of 'a'. */ - -int Delete(PointNumero a,PointNumero b){ - int rslt; - - rslt = DListDelete(&pPointArray[a].adjacent,b); - rslt &= DListDelete(&pPointArray[b].adjacent,a); + +int Delete(PointNumero a, PointNumero b) +{ + int rslt; + + rslt = DListDelete(&pPointArray[a].adjacent, b); + rslt &= DListDelete(&pPointArray[b].adjacent, a); return rslt; } /* Cette routine efface toutes les listes d'adjacence du pPointArray. */ -void remove_all_dlist(int n, PointRecord *pPointArray){ - int i; - DListPeek p,temp; - - for (i=0;i<n;i++) - if (pPointArray[i].adjacent != NULL){ +void remove_all_dlist(int n, PointRecord * pPointArray) +{ + int i; + DListPeek p, temp; + + for(i = 0; i < n; i++) + if(pPointArray[i].adjacent != NULL) { p = pPointArray[i].adjacent; - do{ + do { temp = p; p = Pred(p); - Free(temp); - } while (p != pPointArray[i].adjacent); - pPointArray[i].adjacent = NULL; + Free(temp); + } while(p != pPointArray[i].adjacent); + pPointArray[i].adjacent = NULL; } } - diff --git a/Mesh/2D_Elliptic.cpp b/Mesh/2D_Elliptic.cpp index f43d53970025266134daa6c55d2f87a8c257ee1e..7c4519edd8dc2f6eda46dc80fc52d8a3addb9a93 100644 --- a/Mesh/2D_Elliptic.cpp +++ b/Mesh/2D_Elliptic.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_Elliptic.cpp,v 1.13 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: 2D_Elliptic.cpp,v 1.14 2003-03-01 22:36:40 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -27,142 +27,142 @@ extern Mesh *THEM; -int MeshEllipticSurface (Surface * sur){ - +int MeshEllipticSurface(Surface * sur) +{ int i, j, k, nb, N1, N2, N3, N4; Curve *GG[444]; - Vertex **list; + Vertex **list; Simplex *simp; double alpha, beta, gamma, u, v, lc, x, y, z; Vertex *S[4], *v11, *v12, *v13, *v21, *v22, *v23, *v31, *v32, *v33; List_T *l1, *l2, *l3, *l4; - if (sur->Method != ELLIPTIC) + if(sur->Method != ELLIPTIC) return (0); - nb = List_Nbr (sur->Generatrices); - if (nb < 4) + nb = List_Nbr(sur->Generatrices); + if(nb < 4) return (0); - for (i = 0; i < nb; i++){ - List_Read (sur->Generatrices, i, &GG[i]); + for(i = 0; i < nb; i++) { + List_Read(sur->Generatrices, i, &GG[i]); } - if (!(S[0] = FindPoint (sur->ipar[0], THEM))) + if(!(S[0] = FindPoint(sur->ipar[0], THEM))) return 0; - if (!(S[1] = FindPoint (sur->ipar[1], THEM))) + if(!(S[1] = FindPoint(sur->ipar[1], THEM))) return 0; - if (!(S[2] = FindPoint (sur->ipar[2], THEM))) + if(!(S[2] = FindPoint(sur->ipar[2], THEM))) return 0; - if (!(S[3] = FindPoint (sur->ipar[3], THEM))) + if(!(S[3] = FindPoint(sur->ipar[3], THEM))) return 0; N1 = N2 = N3 = N4 = 0; // step 1 - l1 = List_Create (20, 10, sizeof (Vertex *)); - for (i = 0; i < nb; i++){ - if (!compareVertex (&GG[i]->beg, &S[0])){ + l1 = List_Create(20, 10, sizeof(Vertex *)); + for(i = 0; i < nb; i++) { + if(!compareVertex(&GG[i]->beg, &S[0])) { j = i; - do{ - if (!List_Nbr (l1)) - List_Add (l1, List_Pointer (GG[j]->Vertices, 0)); - for (k = 1; k < List_Nbr (GG[j]->Vertices); k++) - List_Add (l1, List_Pointer (GG[j]->Vertices, k)); + do { + if(!List_Nbr(l1)) + List_Add(l1, List_Pointer(GG[j]->Vertices, 0)); + for(k = 1; k < List_Nbr(GG[j]->Vertices); k++) + List_Add(l1, List_Pointer(GG[j]->Vertices, k)); j = (j + 1 < nb) ? j + 1 : 0; - if (j == i) + if(j == i) return 0; } - while (compareVertex (&GG[j]->beg, &S[1])); + while(compareVertex(&GG[j]->beg, &S[1])); } } - + // step 2 - l2 = List_Create (20, 10, sizeof (Vertex *)); - for (i = 0; i < nb; i++){ - if (!compareVertex (&GG[i]->beg, &S[1])){ + l2 = List_Create(20, 10, sizeof(Vertex *)); + for(i = 0; i < nb; i++) { + if(!compareVertex(&GG[i]->beg, &S[1])) { j = i; - do{ - if (!List_Nbr (l2)) - List_Add (l2, List_Pointer (GG[j]->Vertices, 0)); - for (k = 1; k < List_Nbr (GG[j]->Vertices); k++) - List_Add (l2, List_Pointer (GG[j]->Vertices, k)); + do { + if(!List_Nbr(l2)) + List_Add(l2, List_Pointer(GG[j]->Vertices, 0)); + for(k = 1; k < List_Nbr(GG[j]->Vertices); k++) + List_Add(l2, List_Pointer(GG[j]->Vertices, k)); j = (j + 1 < nb) ? j + 1 : 0; - if (j == i) + if(j == i) return 0; } - while (compareVertex (&GG[j]->beg, &S[2])); + while(compareVertex(&GG[j]->beg, &S[2])); } } // step 3 - l3 = List_Create (20, 10, sizeof (Vertex *)); - for (i = 0; i < nb; i++){ - if (!compareVertex (&GG[i]->beg, &S[2])){ + l3 = List_Create(20, 10, sizeof(Vertex *)); + for(i = 0; i < nb; i++) { + if(!compareVertex(&GG[i]->beg, &S[2])) { j = i; - do{ - if (!List_Nbr (l3)) - List_Add (l3, List_Pointer (GG[j]->Vertices, 0)); - for (k = 1; k < List_Nbr (GG[j]->Vertices); k++) - List_Add (l3, List_Pointer (GG[j]->Vertices, k)); + do { + if(!List_Nbr(l3)) + List_Add(l3, List_Pointer(GG[j]->Vertices, 0)); + for(k = 1; k < List_Nbr(GG[j]->Vertices); k++) + List_Add(l3, List_Pointer(GG[j]->Vertices, k)); j = (j + 1 < nb) ? j + 1 : 0; - if (j == i) + if(j == i) return 0; } - while (compareVertex (&GG[j]->beg, &S[3])); + while(compareVertex(&GG[j]->beg, &S[3])); } } // step 4 - l4 = List_Create (20, 10, sizeof (Vertex *)); - for (i = 0; i < nb; i++){ - if (!compareVertex (&GG[i]->beg, &S[3])){ + l4 = List_Create(20, 10, sizeof(Vertex *)); + for(i = 0; i < nb; i++) { + if(!compareVertex(&GG[i]->beg, &S[3])) { j = i; - do{ - if (!List_Nbr (l4)) - List_Add (l4, List_Pointer (GG[j]->Vertices, 0)); - for (k = 1; k < List_Nbr (GG[j]->Vertices); k++) - List_Add (l4, List_Pointer (GG[j]->Vertices, k)); + do { + if(!List_Nbr(l4)) + List_Add(l4, List_Pointer(GG[j]->Vertices, 0)); + for(k = 1; k < List_Nbr(GG[j]->Vertices); k++) + List_Add(l4, List_Pointer(GG[j]->Vertices, k)); j = (j + 1 < nb) ? j + 1 : 0; - if (j == i) + if(j == i) return 0; } - while (compareVertex (&GG[j]->beg, &S[0])); + while(compareVertex(&GG[j]->beg, &S[0])); } } - N1 = List_Nbr (l1); - N2 = List_Nbr (l2); - N3 = List_Nbr (l3); - N4 = List_Nbr (l4); - if (N1 != N3 || N2 != N4){ - List_Delete (l1); - List_Delete (l2); - List_Delete (l3); - List_Delete (l4); + N1 = List_Nbr(l1); + N2 = List_Nbr(l2); + N3 = List_Nbr(l3); + N4 = List_Nbr(l4); + if(N1 != N3 || N2 != N4) { + List_Delete(l1); + List_Delete(l2); + List_Delete(l3); + List_Delete(l4); return 0; } sur->Nu = N1; sur->Nv = N2; - list = (Vertex **) Malloc (N1 * N2 * sizeof (Vertex *)); + list = (Vertex **) Malloc(N1 * N2 * sizeof(Vertex *)); - for (i = 0; i < N1; i++){ - for (j = 0; j < N2; j++){ - if (i == 0){ - List_Read (l4, N2 - j - 1, &list[i + N1 * j]); + for(i = 0; i < N1; i++) { + for(j = 0; j < N2; j++) { + if(i == 0) { + List_Read(l4, N2 - j - 1, &list[i + N1 * j]); } - else if (i == N1 - 1){ - List_Read (l2, j, &list[i + N1 * j]); + else if(i == N1 - 1) { + List_Read(l2, j, &list[i + N1 * j]); } - else if (j == 0){ - List_Read (l1, i, &list[i + N1 * j]); + else if(j == 0) { + List_Read(l1, i, &list[i + N1 * j]); } - else if (j == N2 - 1){ - List_Read (l3, N1 - i - 1, &list[i + N1 * j]); + else if(j == N2 - 1) { + List_Read(l3, N1 - i - 1, &list[i + N1 * j]); } - else{ - u = 1. - 2. * (double) i / double (N1 - 1); - v = 1. - 2. * (double) j / double (N2 - 1); + else { + u = 1. - 2. * (double)i / double (N1 - 1); + v = 1. - 2. * (double)j / double (N2 - 1); x = 0.25 * ((S[0]->Pos.X * (1 + u) * (1. + v)) + (S[1]->Pos.X * (1 - u) * (1. + v)) + (S[2]->Pos.X * (1 - u) * (1. - v)) + @@ -179,20 +179,21 @@ int MeshEllipticSurface (Surface * sur){ (S[1]->lc * (1 - u) * (1. + v)) + (S[2]->lc * (1 - u) * (1. - v)) + (S[3]->lc * (1 + u) * (1. - v))); - - list[i + N1 * j] = Create_Vertex (++THEM->MaxPointNum, x, y, z, lc, 0.0); + + list[i + N1 * j] = + Create_Vertex(++THEM->MaxPointNum, x, y, z, lc, 0.0); } } } - + k = 0; - - while (1){ + + while(1) { k++; - if (k > 1000) + if(k > 1000) break; - for (i = 1; i < N1 - 1; i++){ - for (j = 1; j < N2 - 1; j++){ + for(i = 1; i < N1 - 1; i++) { + for(j = 1; j < N2 - 1; j++) { v11 = list[i - 1 + N1 * (j - 1)]; v12 = list[i + N1 * (j - 1)]; v13 = list[i + 1 + N1 * (j - 1)]; @@ -202,62 +203,67 @@ int MeshEllipticSurface (Surface * sur){ v31 = list[i - 1 + N1 * (j + 1)]; v32 = list[i + N1 * (j + 1)]; v33 = list[i + 1 + N1 * (j + 1)]; - - alpha = 0.25 * (DSQR (v23->Pos.X - v21->Pos.X) + - DSQR (v23->Pos.Y - v21->Pos.Y)); - gamma = 0.25 * (DSQR (v32->Pos.X - v12->Pos.X) + - DSQR (v32->Pos.Y - v12->Pos.Y)); + + alpha = 0.25 * (DSQR(v23->Pos.X - v21->Pos.X) + + DSQR(v23->Pos.Y - v21->Pos.Y)); + gamma = 0.25 * (DSQR(v32->Pos.X - v12->Pos.X) + + DSQR(v32->Pos.Y - v12->Pos.Y)); beta = 0.0625 * ((v32->Pos.X - v12->Pos.X) * (v23->Pos.X - v21->Pos.X) + (v32->Pos.Y - v12->Pos.Y) * (v23->Pos.Y - v21->Pos.Y)); - + v22->Pos.X = 0.5 * (alpha * (v32->Pos.X + v12->Pos.X) + gamma * (v23->Pos.X + v21->Pos.X) - - 2. * beta * (v33->Pos.X - v13->Pos.X - v31->Pos.X + v11->Pos.X)) + 2. * beta * (v33->Pos.X - v13->Pos.X - + v31->Pos.X + v11->Pos.X)) / (alpha + gamma); v22->Pos.Y = 0.5 * (alpha * (v32->Pos.Y + v12->Pos.Y) + gamma * (v23->Pos.Y + v21->Pos.Y) - - 2. * beta * (v33->Pos.Y - v13->Pos.Y - v31->Pos.Y + v11->Pos.Y)) + 2. * beta * (v33->Pos.Y - v13->Pos.Y - + v31->Pos.Y + v11->Pos.Y)) / (alpha + gamma); v22->Pos.Z = 0.5 * (alpha * (v32->Pos.Z + v12->Pos.Z) + gamma * (v23->Pos.Z + v21->Pos.Z) - - 2. * beta * (v33->Pos.Z - v13->Pos.Z - v31->Pos.Z + v11->Pos.Z)) + 2. * beta * (v33->Pos.Z - v13->Pos.Z - + v31->Pos.Z + v11->Pos.Z)) / (alpha + gamma); - + } } - + } - for (i = 0; i < N1 - 1; i++){ - for (j = 0; j < N2 - 1; j++){ - if (sur->Recombine){ + for(i = 0; i < N1 - 1; i++) { + for(j = 0; j < N2 - 1; j++) { + if(sur->Recombine) { simp = Create_Quadrangle - (list[(i) + N1 * (j)], list[(i + 1) + N1 * (j)], - list[(i + 1) + N1 * (j + 1)], list[i + N1 * (j + 1)]); + (list[(i) + N1 * (j)], list[(i + 1) + N1 * (j)], + list[(i + 1) + N1 * (j + 1)], list[i + N1 * (j + 1)]); simp->iEnt = sur->Num; - Tree_Add (sur->Simplexes, &simp); - List_Add (sur->TrsfSimplexes, &simp); + Tree_Add(sur->Simplexes, &simp); + List_Add(sur->TrsfSimplexes, &simp); } - else{ - simp = Create_Simplex (list[(i) + N1 * (j)], list[(i + 1) + N1 * (j)], - list[(i) + N1 * (j + 1)], NULL); + else { + simp = Create_Simplex(list[(i) + N1 * (j)], list[(i + 1) + N1 * (j)], + list[(i) + N1 * (j + 1)], NULL); simp->iEnt = sur->Num; - Tree_Add (sur->Simplexes, &simp); - List_Add (sur->TrsfSimplexes, &simp); - - simp = Create_Simplex (list[(i + 1) + N1 * (j + 1)], list[(i) + N1 * (j + 1)], - list[(i + 1) + N1 * (j)], NULL); + Tree_Add(sur->Simplexes, &simp); + List_Add(sur->TrsfSimplexes, &simp); + + simp = + Create_Simplex(list[(i + 1) + N1 * (j + 1)], + list[(i) + N1 * (j + 1)], list[(i + 1) + N1 * (j)], + NULL); simp->iEnt = sur->Num; - Tree_Add (sur->Simplexes, &simp); - List_Add (sur->TrsfSimplexes, &simp); + Tree_Add(sur->Simplexes, &simp); + List_Add(sur->TrsfSimplexes, &simp); } } } // We count this here, to be able to distinguish very quickly // between triangles and quadrangles later - if (sur->Recombine) + if(sur->Recombine) THEM->Statistics[8] += List_Nbr(sur->TrsfSimplexes); return 1; diff --git a/Mesh/2D_InitMesh.cpp b/Mesh/2D_InitMesh.cpp index d3e86ac49a9d5f37e507c9c7eee56b8d127c78ef..34812a5573b568167013614e120865ff7f6c1e8e 100644 --- a/Mesh/2D_InitMesh.cpp +++ b/Mesh/2D_InitMesh.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_InitMesh.cpp,v 1.17 2003-02-25 04:02:50 geuzaine Exp $ +// $Id: 2D_InitMesh.cpp,v 1.18 2003-03-01 22:36:40 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -78,229 +78,261 @@ #include "Mesh.h" #include "2D_Mesh.h" -extern PointRecord *gPointArray; +extern PointRecord *gPointArray; -static Tree_T *ETree=NULL,*EDToSwap=NULL; -static int pointA,pointB,Counter,Stagnant,StopNow; -static int *permut; +static Tree_T *ETree = NULL, *EDToSwap = NULL; +static int pointA, pointB, Counter, Stagnant, StopNow; +static int *permut; -typedef struct { +typedef struct +{ int from; int to; int NbOccur; Delaunay *Liste[2]; -}ED; +} +ED; -void makepermut (int numpoints){ - int i, ip ; - permut = (int *) Malloc (numpoints * sizeof (int)); //Memory leak! this is never freed... - for ( i=0 ; i<numpoints ; i++ ){ +void makepermut(int numpoints) +{ + int i, ip; + permut = (int *)Malloc(numpoints * sizeof(int)); //Memory leak! this is never freed... + for(i = 0; i < numpoints; i++) { ip = gPointArray[i].permu; - permut[ip] = i; + permut[ip] = i; } -} - -int crossED ( ED * e ){ - double Xma,Xmb,Yma,Ymb,det,t,q; - double XMa,XMb,YMa,YMb; - double xa1,xa2,ya1,ya2; - double xb1,xb2,yb1,yb2; - +} + +int crossED(ED * e) +{ + double Xma, Xmb, Yma, Ymb, det, t, q; + double XMa, XMb, YMa, YMb; + double xa1, xa2, ya1, ya2; + double xb1, xb2, yb1, yb2; + xa1 = gPointArray[pointA].where.h; xa2 = gPointArray[pointB].where.h; ya1 = gPointArray[pointA].where.v; ya2 = gPointArray[pointB].where.v; - + xb1 = gPointArray[e->from].where.h; xb2 = gPointArray[e->to].where.h; yb1 = gPointArray[e->from].where.v; yb2 = gPointArray[e->to].where.v; - Xma = DMIN(xa1,xa2); - Xmb = DMIN(xb1,xb2); + Xma = DMIN(xa1, xa2); + Xmb = DMIN(xb1, xb2); - XMa = DMAX(xa1,xa2); - XMb = DMAX(xb1,xb2); + XMa = DMAX(xa1, xa2); + XMb = DMAX(xb1, xb2); - if(XMa < Xmb || XMb < Xma)return(0); + if(XMa < Xmb || XMb < Xma) + return (0); - Yma = DMIN(ya1,ya2); - Ymb = DMIN(yb1,yb2); + Yma = DMIN(ya1, ya2); + Ymb = DMIN(yb1, yb2); - YMa = DMAX(ya1,ya2); - YMb = DMAX(yb1,yb2); + YMa = DMAX(ya1, ya2); + YMb = DMAX(yb1, yb2); - if(YMa < Ymb || YMb < Yma)return(0); + if(YMa < Ymb || YMb < Yma) + return (0); - det = (xa2 - xa1)*(yb1-yb2) - (xb1 - xb2)*(ya2-ya1); + det = (xa2 - xa1) * (yb1 - yb2) - (xb1 - xb2) * (ya2 - ya1); - if(det == 0.0){ - return(0); + if(det == 0.0) { + return (0); } - t = ((xb1 - xa1)*(yb1-yb2) - (xb1 - xb2)*(yb1-ya1))/det; - q = ((xa2 - xa1)*(yb1-ya1) - (ya2 - ya1)*(xb1-xa1))/det; + t = ((xb1 - xa1) * (yb1 - yb2) - (xb1 - xb2) * (yb1 - ya1)) / det; + q = ((xa2 - xa1) * (yb1 - ya1) - (ya2 - ya1) * (xb1 - xa1)) / det; - if(t>1. || t<0.)return(0); - if(q>1. || q<0.)return(0); + if(t > 1. || t < 0.) + return (0); + if(q > 1. || q < 0.) + return (0); //printf("t=%g q=%g det=%g\n", t, q, det); - return(1); + return (1); } - -int compareED2 (const void *a, const void *b){ - ED *q,*w; - q=(ED*)a; - w=(ED*)b; - if(q->NbOccur > w->NbOccur)return(-1); - if(q->NbOccur < w->NbOccur)return(1); - if(q->from > w->from)return(1); - if(q->from < w->from)return(-1); - if(q->to > w->to)return(1); - if(q->to < w->to)return(-1); - return(0); + +int compareED2(const void *a, const void *b) +{ + ED *q, *w; + q = (ED *) a; + w = (ED *) b; + if(q->NbOccur > w->NbOccur) + return (-1); + if(q->NbOccur < w->NbOccur) + return (1); + if(q->from > w->from) + return (1); + if(q->from < w->from) + return (-1); + if(q->to > w->to) + return (1); + if(q->to < w->to) + return (-1); + return (0); } -int compareED (const void *a, const void *b){ - ED *q,*w; - q=(ED*)a; - w=(ED*)b; - if(q->from > w->from)return(1); - if(q->from < w->from)return(-1); - if(q->to > w->to)return(1); - if(q->to < w->to)return(-1); - return(0); +int compareED(const void *a, const void *b) +{ + ED *q, *w; + q = (ED *) a; + w = (ED *) b; + if(q->from > w->from) + return (1); + if(q->from < w->from) + return (-1); + if(q->to > w->to) + return (1); + if(q->to < w->to) + return (-1); + return (0); } -void DoWeSwapED ( void *data , void *dummy){ +void DoWeSwapED(void *data, void *dummy) +{ ED *e; - e = (ED*)data; - - if(e->from == pointA || e->from == pointB || - e->to == pointA || e->to == pointB){ + e = (ED *) data; + + if(e->from == pointA || e->from == pointB || + e->to == pointA || e->to == pointB) { return; } - else if ( Tree_PQuery ( EDToSwap,e) ){ - } - else if ( crossED ( e ) ) { - Tree_Add ( EDToSwap ,e); + else if(Tree_PQuery(EDToSwap, e)) { + } + else if(crossED(e)) { + Tree_Add(EDToSwap, e); } } -void Print ( void *data , void *dummy){ +void Print(void *data, void *dummy) +{ ED *e; - e = (ED*)data; - Msg(INFO,"%d %d",e->from,e->to); + e = (ED *) data; + Msg(INFO, "%d %d", e->from, e->to); } -void SwapED ( void *data , void *dummy){ - ED *e,E; - int from=0,to=0; +void SwapED(void *data, void *dummy) +{ + ED *e, E; + int from = 0, to = 0; - e = (ED*)data; + e = (ED *) data; - if(Stagnant && Counter <= StopNow)return; - else if(Stagnant)Counter++; + if(Stagnant && Counter <= StopNow) + return; + else if(Stagnant) + Counter++; - if(!e->Liste[0] || !e->Liste[1]){ + if(!e->Liste[0] || !e->Liste[1]) { Msg(GERROR, "Initial mesh is wrong. Try the new isotropic algorithm."); return; } if(e->from != e->Liste[0]->t.a && e->from != e->Liste[0]->t.b && - e->from != e->Liste[0]->t.c ) + e->from != e->Liste[0]->t.c) return; if(e->from != e->Liste[1]->t.a && e->from != e->Liste[1]->t.b && - e->from != e->Liste[1]->t.c ) + e->from != e->Liste[1]->t.c) return; if(e->to != e->Liste[0]->t.a && e->to != e->Liste[0]->t.b && - e->to != e->Liste[0]->t.c ) + e->to != e->Liste[0]->t.c) return; if(e->to != e->Liste[1]->t.a && e->to != e->Liste[1]->t.b && - e->to != e->Liste[1]->t.c ) + e->to != e->Liste[1]->t.c) return; - - if(e->from != e->Liste[0]->t.a && e->to != e->Liste[0]->t.a) + + if(e->from != e->Liste[0]->t.a && e->to != e->Liste[0]->t.a) from = e->Liste[0]->t.a; - else if(e->from != e->Liste[0]->t.b && e->to != e->Liste[0]->t.b) + else if(e->from != e->Liste[0]->t.b && e->to != e->Liste[0]->t.b) from = e->Liste[0]->t.b; - else if(e->from != e->Liste[0]->t.c && e->to != e->Liste[0]->t.c) + else if(e->from != e->Liste[0]->t.c && e->to != e->Liste[0]->t.c) from = e->Liste[0]->t.c; - if(e->from != e->Liste[1]->t.a && e->to != e->Liste[1]->t.a) + if(e->from != e->Liste[1]->t.a && e->to != e->Liste[1]->t.a) to = e->Liste[1]->t.a; - else if(e->from != e->Liste[1]->t.b && e->to != e->Liste[1]->t.b) + else if(e->from != e->Liste[1]->t.b && e->to != e->Liste[1]->t.b) to = e->Liste[1]->t.b; - else if(e->from != e->Liste[1]->t.c && e->to != e->Liste[1]->t.c) + else if(e->from != e->Liste[1]->t.c && e->to != e->Liste[1]->t.c) to = e->Liste[1]->t.c; pointA = e->from; pointB = e->to; E.from = from; - E.to = to; - if(!crossED(&E))return; + E.to = to; + if(!crossED(&E)) + return; e->Liste[0]->t.a = from; e->Liste[0]->t.b = to; e->Liste[0]->t.c = e->from; - + e->Liste[1]->t.a = from; e->Liste[1]->t.b = to; e->Liste[1]->t.c = e->to; - e->from = IMAX(from,to); - e->to = IMIN(from,to); + e->from = IMAX(from, to); + e->to = IMIN(from, to); } - -void SuppressInETree( void *data , void *dummy){ - if(!Tree_Suppress(ETree,data)) - Msg(WARNING, "Cannot suppress in ETree"); + +void SuppressInETree(void *data, void *dummy) +{ + if(!Tree_Suppress(ETree, data)) + Msg(WARNING, "Cannot suppress in ETree"); } -void AddInETree( void *data , void *dummy){ - Tree_Add(ETree,data); +void AddInETree(void *data, void *dummy) +{ + Tree_Add(ETree, data); } -int verifie_cas_scabreux (int pa, int pb, ContourRecord **ListContours, int Nc){ +int verifie_cas_scabreux(int pa, int pb, ContourRecord ** ListContours, + int Nc) +{ ED Edge; - int i,k,a,b; + int i, k, a, b; ContourRecord *contour; - - Edge.from = IMAX(pa,pb); - Edge.to = IMIN(pa,pb); - for(k=0;k<Nc;k++){ + + Edge.from = IMAX(pa, pb); + Edge.to = IMIN(pa, pb); + for(k = 0; k < Nc; k++) { contour = ListContours[k]; - for ( i = -1 ; i < (contour->numpoints - 1) ; i++) { - if(i == -1){ - a = permut [ contour->oriented_points[0].permu ]; - b = permut [ contour->oriented_points[contour->numpoints - 1].permu ]; + for(i = -1; i < (contour->numpoints - 1); i++) { + if(i == -1) { + a = permut[contour->oriented_points[0].permu]; + b = permut[contour->oriented_points[contour->numpoints - 1].permu]; } - else{ - a = permut [ contour->oriented_points[i].permu ]; - b = permut [ contour->oriented_points[i+1].permu ]; + else { + a = permut[contour->oriented_points[i].permu]; + b = permut[contour->oriented_points[i + 1].permu]; } - - pointA = IMAX(a,b); - pointB = IMIN(a,b); + + pointA = IMAX(a, b); + pointB = IMIN(a, b); if(a != pa && b != pa && a != pb && b != pb) - if(crossED(&Edge)) return (1); + if(crossED(&Edge)) + return (1); } - } + } return (0); } -void verify_edges (List_T *ListDelaunay, ContourRecord **ListContour, - int NumContours){ +void verify_edges(List_T * ListDelaunay, ContourRecord ** ListContour, + int NumContours) +{ - ED *pEdge; - ED Edge; - int ok,max,i,k,c,a,b; + ED *pEdge; + ED Edge; + int ok, max, i, k, c, a, b; ContourRecord *contour; Delaunay *del_P; @@ -309,106 +341,109 @@ void verify_edges (List_T *ListDelaunay, ContourRecord **ListContour, c = 0; do { c++; - if(c>max)break; - ETree = Tree_Create ( sizeof (Edge) , compareED ); - for (i=0;i< List_Nbr(ListDelaunay);i++) { + if(c > max) + break; + ETree = Tree_Create(sizeof(Edge), compareED); + for(i = 0; i < List_Nbr(ListDelaunay); i++) { - del_P = *(Delaunay**)List_Pointer(ListDelaunay, i); + del_P = *(Delaunay **) List_Pointer(ListDelaunay, i); - Edge.from = IMAX ( del_P->t.a, del_P->t.b ); - Edge.to = IMIN ( del_P->t.a, del_P->t.b ); + Edge.from = IMAX(del_P->t.a, del_P->t.b); + Edge.to = IMIN(del_P->t.a, del_P->t.b); Edge.NbOccur = 1; - if((pEdge = (ED*)Tree_PQuery(ETree,&Edge))){ + if((pEdge = (ED *) Tree_PQuery(ETree, &Edge))) { pEdge->Liste[1] = del_P; } else { Edge.Liste[0] = del_P; Edge.Liste[1] = NULL; - Tree_Add (ETree,&Edge); + Tree_Add(ETree, &Edge); } - - Edge.from = IMAX ( del_P->t.a, del_P->t.c ); - Edge.to = IMIN ( del_P->t.a, del_P->t.c ); - - if((pEdge = (ED*)Tree_PQuery(ETree,&Edge))){ + + Edge.from = IMAX(del_P->t.a, del_P->t.c); + Edge.to = IMIN(del_P->t.a, del_P->t.c); + + if((pEdge = (ED *) Tree_PQuery(ETree, &Edge))) { pEdge->Liste[1] = del_P; } else { Edge.Liste[0] = del_P; Edge.Liste[1] = NULL; - Tree_Add (ETree,&Edge); + Tree_Add(ETree, &Edge); } - - Edge.from = IMAX ( del_P->t.c, del_P->t.b ); - Edge.to = IMIN ( del_P->t.c, del_P->t.b ); - - if((pEdge = (ED*)Tree_PQuery(ETree,&Edge))){ + + Edge.from = IMAX(del_P->t.c, del_P->t.b); + Edge.to = IMIN(del_P->t.c, del_P->t.b); + + if((pEdge = (ED *) Tree_PQuery(ETree, &Edge))) { pEdge->Liste[1] = del_P; } else { Edge.Liste[0] = del_P; Edge.Liste[1] = NULL; - Tree_Add (ETree,&Edge); + Tree_Add(ETree, &Edge); } } - + ok = 0; - for(k=0;k<NumContours;k++){ + for(k = 0; k < NumContours; k++) { contour = ListContour[k]; - for ( i = -1 ; i < contour->numpoints - 1 ; i++){ - - if(i == -1){ - a = permut [ contour->oriented_points[0].permu ]; - b = permut [ contour->oriented_points[contour->numpoints - 1].permu ]; + for(i = -1; i < contour->numpoints - 1; i++) { + + if(i == -1) { + a = permut[contour->oriented_points[0].permu]; + b = permut[contour->oriented_points[contour->numpoints - 1].permu]; } - else{ - a = permut [ contour->oriented_points[i].permu ]; - b = permut [ contour->oriented_points[i+1].permu ]; + else { + a = permut[contour->oriented_points[i].permu]; + b = permut[contour->oriented_points[i + 1].permu]; } - - Edge.from = IMAX(a,b); - Edge.to = IMIN(a,b); - - if(!Tree_Search( ETree , &Edge ))ok++;; + + Edge.from = IMAX(a, b); + Edge.to = IMIN(a, b); + + if(!Tree_Search(ETree, &Edge)) + ok++;; } } - if(!ok){ + if(!ok) { return; } - - Msg(INFO, "Swapping (%d missing edges)", ok); - + + Msg(INFO, "Swapping (%d missing edges)", ok); + //EDToSwap = NULL; - if(EDToSwap)Tree_Delete(EDToSwap); - EDToSwap = Tree_Create (sizeof(ED),compareED2); - for(k=0;k<NumContours;k++){ + if(EDToSwap) + Tree_Delete(EDToSwap); + EDToSwap = Tree_Create(sizeof(ED), compareED2); + for(k = 0; k < NumContours; k++) { contour = ListContour[k]; - for ( i = -1 ; i < contour->numpoints - 1 ; i++){ - - if(i == -1){ - a = permut [ contour->oriented_points[0].permu ]; - b = permut [ contour->oriented_points[contour->numpoints - 1].permu ]; + for(i = -1; i < contour->numpoints - 1; i++) { + + if(i == -1) { + a = permut[contour->oriented_points[0].permu]; + b = permut[contour->oriented_points[contour->numpoints - 1].permu]; } - else{ - a = permut [ contour->oriented_points[i].permu ]; - b = permut [ contour->oriented_points[i+1].permu ]; + else { + a = permut[contour->oriented_points[i].permu]; + b = permut[contour->oriented_points[i + 1].permu]; } - - pointA = IMAX(a,b); - pointB = IMIN(a,b); - - Tree_Action ( ETree , DoWeSwapED ); - + + pointA = IMAX(a, b); + pointB = IMIN(a, b); + + Tree_Action(ETree, DoWeSwapED); + } } - Msg(INFO, "Elimination (%d swaps)", Tree_Nbr(EDToSwap)); + Msg(INFO, "Elimination (%d swaps)", Tree_Nbr(EDToSwap)); - Tree_Action (EDToSwap , SuppressInETree); - Tree_Action (EDToSwap , SwapED); - Tree_Action (EDToSwap , AddInETree); - }while(Tree_Nbr(EDToSwap)); + Tree_Action(EDToSwap, SuppressInETree); + Tree_Action(EDToSwap, SwapED); + Tree_Action(EDToSwap, AddInETree); + } while(Tree_Nbr(EDToSwap)); Tree_Delete(EDToSwap); Tree_Delete(ETree); @@ -417,28 +452,31 @@ void verify_edges (List_T *ListDelaunay, ContourRecord **ListContour, -int comparepermu(const void *i, const void *j){ - return ( gPointArray[*(PointNumero *)i].permu - gPointArray[*(PointNumero *)j].permu); +int comparepermu(const void *i, const void *j) +{ + return (gPointArray[*(PointNumero *) i].permu - + gPointArray[*(PointNumero *) j].permu); } -void verify_inside (Delaunay * ListDelaunay , int NumDelaunay ){ +void verify_inside(Delaunay * ListDelaunay, int NumDelaunay) +{ PointNumero pt[3], compare, a, b; - int i, inside, cont[3]; + int i, inside, cont[3]; + + for(i = 0; i < NumDelaunay; i++) { - for ( i=0 ; i < NumDelaunay ; i++){ - pt[0] = ListDelaunay[i].t.a; pt[1] = ListDelaunay[i].t.b; pt[2] = ListDelaunay[i].t.c; - qsort(pt,3,sizeof(PointNumero),comparepermu); + qsort(pt, 3, sizeof(PointNumero), comparepermu); cont[0] = gPointArray[pt[0]].numcontour; cont[1] = gPointArray[pt[1]].numcontour; cont[2] = gPointArray[pt[2]].numcontour; - if((cont[1] != cont[2])||(cont[0]!=cont[1])||(cont[0]!=cont[2])) + if((cont[1] != cont[2]) || (cont[0] != cont[1]) || (cont[0] != cont[2])) inside = 1; else inside = 0; @@ -447,13 +485,12 @@ void verify_inside (Delaunay * ListDelaunay , int NumDelaunay ){ a = pt[0]; b = pt[1]; compare = pt[2]; - - if ((Is_left_of ( a,b,compare ) && (inside == 0))){ - ListDelaunay[i].t.position = EXTERN ; + + if((Is_left_of(a, b, compare) && (inside == 0))) { + ListDelaunay[i].t.position = EXTERN; } } return; - -} +} diff --git a/Mesh/2D_Links.cpp b/Mesh/2D_Links.cpp index f049b885f9c1526bf79e10b4f966bf530e287e86..2c6b9dd829668c7604533c7eabd08932347fd259 100644 --- a/Mesh/2D_Links.cpp +++ b/Mesh/2D_Links.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_Links.cpp,v 1.13 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: 2D_Links.cpp,v 1.14 2003-03-01 22:36:40 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -24,52 +24,56 @@ #include "Mesh.h" #include "2D_Mesh.h" -extern PointRecord *gPointArray; -extern int LocalNewPoint; -extern DocRecord *FGMESH; +extern PointRecord *gPointArray; +extern int LocalNewPoint; +extern DocRecord *FGMESH; extern PointNumero First(PointNumero x); /* compte les points sur le polygone convexe */ -int CountPointsOnHull(int n, PointRecord *pPointArray){ - PointNumero p,p2,temp; +int CountPointsOnHull(int n, PointRecord * pPointArray) +{ + PointNumero p, p2, temp; int i; - - if (pPointArray[0].adjacent == NULL) return 0; + + if(pPointArray[0].adjacent == NULL) + return 0; i = 1; p = 0; p2 = First(0); - while ((p2 != 0) && (i < n)) { + while((p2 != 0) && (i < n)) { i++; temp = p2; - p2 = Successor(p2,p); + p2 = Successor(p2, p); p = temp; } return ((i <= n) ? i : -1); } -PointNumero *ConvertDlistToArray(DListPeek *dlist,int *n){ - DListPeek p,temp; - int i,max = 0; - PointNumero *ptr; - +PointNumero *ConvertDlistToArray(DListPeek * dlist, int *n) +{ + DListPeek p, temp; + int i, max = 0; + PointNumero *ptr; + p = *dlist; - do{ + do { max++; - p = Pred(p); - } while (p != *dlist); - ptr = (PointNumero *) Malloc((int) ((max+1) * sizeof(PointNumero))); - if (ptr == NULL) return NULL; + p = Pred(p); + } while(p != *dlist); + ptr = (PointNumero *) Malloc((int)((max + 1) * sizeof(PointNumero))); + if(ptr == NULL) + return NULL; p = *dlist; - for (i=0;i<max;i++){ + for(i = 0; i < max; i++) { ptr[i] = p->point_num; temp = p; p = Pred(p); Free(temp); } - ptr[max]=ptr[0]; + ptr[max] = ptr[0]; *dlist = NULL; *n = max; return ptr; @@ -78,175 +82,179 @@ PointNumero *ConvertDlistToArray(DListPeek *dlist,int *n){ /* Convertir les listes d'adjacence en triangles */ -int Conversion(DocPeek doc ){ - +int Conversion(DocPeek doc) +{ /* on suppose que n >= 3 gPointArray est suppose OK. */ Striangle *striangle; - int n,i,j; - int count = 0,count2 = 0; - PointNumero aa,bb,cc; + int n, i, j; + int count = 0, count2 = 0; + PointNumero aa, bb, cc; PointRecord *ptemp; ptemp = gPointArray; - gPointArray = doc->points; - + gPointArray = doc->points; + n = doc->numPoints; - striangle = (Striangle *) Malloc((int) (n * sizeof(Striangle))); - count2 = (int) CountPointsOnHull(n,doc->points); + striangle = (Striangle *) Malloc((int)(n * sizeof(Striangle))); + count2 = (int)CountPointsOnHull(n, doc->points); /* nombre de triangles que l'on doit obtenir */ - count2 = 2 * (n - 1) - count2; - - if(doc->delaunay)Free (doc->delaunay); + count2 = 2 * (n - 1) - count2; + + if(doc->delaunay) + Free(doc->delaunay); - doc->delaunay = (Delaunay *) Malloc(2*count2 * sizeof(Delaunay)); + doc->delaunay = (Delaunay *) Malloc(2 * count2 * sizeof(Delaunay)); - for (i=0;i<n;i++){ - /* on cree une liste de points connectes au point i (t) + nombre de points (t_length) */ - striangle[i].t = ConvertDlistToArray(&gPointArray[i].adjacent,&striangle[i].t_length); + for(i = 0; i < n; i++) { + /* on cree une liste de points connectes au point i (t) + nombre de points (t_length) */ + striangle[i].t = + ConvertDlistToArray(&gPointArray[i].adjacent, &striangle[i].t_length); striangle[i].info = NULL; striangle[i].info_length = 0; } /* on balaye les noeuds de gauche a droite -> on cree les triangles */ count = 0; - for (i=0;i<n;i++){ - for (j=0;j<striangle[i].t_length;j++){ - if ( ( striangle[i].t[j] > i) && ( striangle[i].t[j+1] > i) && - (Is_right_of(i,striangle[i].t[j],striangle[i].t[j+1])) ) { + for(i = 0; i < n; i++) { + for(j = 0; j < striangle[i].t_length; j++) { + if((striangle[i].t[j] > i) && (striangle[i].t[j + 1] > i) && + (Is_right_of(i, striangle[i].t[j], striangle[i].t[j + 1]))) { aa = i; bb = striangle[i].t[j]; - cc = striangle[i].t[j+1]; - filldel(&doc->delaunay[count],aa,bb,cc,gPointArray,NULL); - count++; - } + cc = striangle[i].t[j + 1]; + filldel(&doc->delaunay[count], aa, bb, cc, gPointArray, NULL); + count++; + } } } - for (i=0;i<n;i++) Free(striangle[i].t); - Free(striangle); + for(i = 0; i < n; i++) + Free(striangle[i].t); + Free(striangle); doc->numTriangles = count2; gPointArray = ptemp; - return(1); + return (1); } -int compareEdge(const void *e1, const void *e2){ +int compareEdge(const void *e1, const void *e2) +{ PointNumero tmp; - if ((tmp = ((edge *)e1)->from - ((edge *)e2)->from) != 0) return(tmp); - return(((edge *)e1)->to - ((edge *)e2)->to); + if((tmp = ((edge *) e1)->from - ((edge *) e2)->from) != 0) + return (tmp); + return (((edge *) e1)->to - ((edge *) e2)->to); } /* pour la liste de delaunays ListDelaunay, CreateLinks cree les liens entre triangles c.a.d determine les voisins de chaque triangle */ -int CreateLinks(List_T * ListDelaunay , int NumDelaunay, - ContourRecord **ListContours , int Nc){ +int CreateLinks(List_T * ListDelaunay, int NumDelaunay, + ContourRecord ** ListContours, int Nc) +{ int i; edge *ListEdges; MPoint pt; Delaunay *del_Pi, *del_Pj; - - ListEdges = (edge *) Malloc((3* NumDelaunay + 2)* sizeof(edge)); - ListEdges[3* NumDelaunay + 1].num=0; - - for (i=0;i< NumDelaunay;i++){ + ListEdges = (edge *) Malloc((3 * NumDelaunay + 2) * sizeof(edge)); + + ListEdges[3 * NumDelaunay + 1].num = 0; - del_Pi = *(Delaunay**)List_Pointer(ListDelaunay, i); + for(i = 0; i < NumDelaunay; i++) { + + del_Pi = *(Delaunay **) List_Pointer(ListDelaunay, i); /* arete a b */ - if (del_Pi->t.a > del_Pi->t.b ){ - ListEdges[3*i].from = del_Pi->t.a; - ListEdges[3*i].to = del_Pi->t.b; - ListEdges[3*i].num = i; + if(del_Pi->t.a > del_Pi->t.b) { + ListEdges[3 * i].from = del_Pi->t.a; + ListEdges[3 * i].to = del_Pi->t.b; + ListEdges[3 * i].num = i; } - else { - ListEdges[3*i].from = del_Pi->t.b; - ListEdges[3*i].to = del_Pi->t.a; - ListEdges[3*i].num = i; + else { + ListEdges[3 * i].from = del_Pi->t.b; + ListEdges[3 * i].to = del_Pi->t.a; + ListEdges[3 * i].num = i; } - - /* arete b c */ - if (del_Pi->t.b > del_Pi->t.c ){ - ListEdges[3*i+1].from = del_Pi->t.b; - ListEdges[3*i+1].to = del_Pi->t.c; - ListEdges[3*i+1].num = i; + + /* arete b c */ + if(del_Pi->t.b > del_Pi->t.c) { + ListEdges[3 * i + 1].from = del_Pi->t.b; + ListEdges[3 * i + 1].to = del_Pi->t.c; + ListEdges[3 * i + 1].num = i; } - else { - ListEdges[3*i+1].from = del_Pi->t.c; - ListEdges[3*i+1].to = del_Pi->t.b; - ListEdges[3*i+1].num = i; + else { + ListEdges[3 * i + 1].from = del_Pi->t.c; + ListEdges[3 * i + 1].to = del_Pi->t.b; + ListEdges[3 * i + 1].num = i; } - + /* arete c a */ - if (del_Pi->t.c > del_Pi->t.a ){ - ListEdges[3*i+2].from = del_Pi->t.c; - ListEdges[3*i+2].to = del_Pi->t.a; - ListEdges[3*i+2].num = i; + if(del_Pi->t.c > del_Pi->t.a) { + ListEdges[3 * i + 2].from = del_Pi->t.c; + ListEdges[3 * i + 2].to = del_Pi->t.a; + ListEdges[3 * i + 2].num = i; } - else { - ListEdges[3*i+2].from = del_Pi->t.a; - ListEdges[3*i+2].to = del_Pi->t.c; - ListEdges[3*i+2].num = i; + else { + ListEdges[3 * i + 2].from = del_Pi->t.a; + ListEdges[3 * i + 2].to = del_Pi->t.c; + ListEdges[3 * i + 2].num = i; } - + } - - qsort(ListEdges,3*NumDelaunay,sizeof(edge),compareEdge); - i=0; + qsort(ListEdges, 3 * NumDelaunay, sizeof(edge), compareEdge); + + i = 0; do { - if ( (ListEdges[i].from == ListEdges[i+1].from) && - (ListEdges[i].to == ListEdges[i+1].to)){ /* create link */ + if((ListEdges[i].from == ListEdges[i + 1].from) && (ListEdges[i].to == ListEdges[i + 1].to)) { /* create link */ - del_Pi = *(Delaunay**)List_Pointer(ListDelaunay, ListEdges[i].num); - del_Pj = *(Delaunay**)List_Pointer(ListDelaunay, ListEdges[i+1].num); + del_Pi = *(Delaunay **) List_Pointer(ListDelaunay, ListEdges[i].num); + del_Pj = + *(Delaunay **) List_Pointer(ListDelaunay, ListEdges[i + 1].num); - if ( ( del_Pi->t.position != EXTERN ) && - ( del_Pj->t.position != EXTERN ) && - ( (del_Pj->t.info == TOLINK ) || - (del_Pi->t.info == TOLINK ) ) ) { + if((del_Pi->t.position != EXTERN) && + (del_Pj->t.position != EXTERN) && + ((del_Pj->t.info == TOLINK) || (del_Pi->t.info == TOLINK))) { - if (del_Pi->v.voisin1 == NULL) + if(del_Pi->v.voisin1 == NULL) del_Pi->v.voisin1 = del_Pj; - else if (del_Pi->v.voisin2 == NULL) + else if(del_Pi->v.voisin2 == NULL) del_Pi->v.voisin2 = del_Pj; - else if (del_Pi->v.voisin3 == NULL) + else if(del_Pi->v.voisin3 == NULL) del_Pi->v.voisin3 = del_Pj; else - Msg(GERROR, "Bad link for triangle"); + Msg(GERROR, "Bad link for triangle"); - if (del_Pj->v.voisin1 == NULL) + if(del_Pj->v.voisin1 == NULL) del_Pj->v.voisin1 = del_Pi; - else if (del_Pj->v.voisin2 == NULL) + else if(del_Pj->v.voisin2 == NULL) del_Pj->v.voisin2 = del_Pi; - else if (del_Pj->v.voisin3 == NULL) + else if(del_Pj->v.voisin3 == NULL) del_Pj->v.voisin3 = del_Pi; else - Msg(GERROR, "Bad link for triangle"); + Msg(GERROR, "Bad link for triangle"); } - i+=2; + i += 2; } else i++; - } while ( i < 3*NumDelaunay ); - + } while(i < 3 * NumDelaunay); + Free(ListEdges); - - for(i=0 ; i<NumDelaunay ;i++){ - del_Pi = *(Delaunay**)List_Pointer(ListDelaunay, i); - - if(del_Pi->t.position != EXTERN){ + + for(i = 0; i < NumDelaunay; i++) { + del_Pi = *(Delaunay **) List_Pointer(ListDelaunay, i); + + if(del_Pi->t.position != EXTERN) { pt.h = del_Pi->t.xc; pt.v = del_Pi->t.yc; - if(!PtInTriangle(pt, del_Pi->t.a, del_Pi->t.b, - del_Pi->t.c)){ - if(!Find_Triangle(pt,FGMESH,A_TOUT_PRIX)){ + if(!PtInTriangle(pt, del_Pi->t.a, del_Pi->t.b, del_Pi->t.c)) { + if(!Find_Triangle(pt, FGMESH, A_TOUT_PRIX)) { if(LocalNewPoint == VORONOI_INSERT) { del_Pi->t.position = ACCEPTED; } @@ -256,24 +264,23 @@ int CreateLinks(List_T * ListDelaunay , int NumDelaunay, } } - if((LocalNewPoint == VORONOI_INSERT)){ - for(i=0 ; i<NumDelaunay ;i++){ - del_Pi = *(Delaunay**)List_Pointer(ListDelaunay, i); - if( ((del_Pi->t.position == NONACCEPTED ) || (del_Pi->t.position == INTERN )) && - (del_Pi->t.info == TOLINK )){ - if ((del_Pi->v.voisin1 == NULL) || - (del_Pi->v.voisin2 == NULL) || - (del_Pi->v.voisin3 == NULL)){ + if((LocalNewPoint == VORONOI_INSERT)) { + for(i = 0; i < NumDelaunay; i++) { + del_Pi = *(Delaunay **) List_Pointer(ListDelaunay, i); + if(((del_Pi->t.position == NONACCEPTED) + || (del_Pi->t.position == INTERN)) && (del_Pi->t.info == TOLINK)) { + if((del_Pi->v.voisin1 == NULL) || (del_Pi->v.voisin2 == NULL) + || (del_Pi->v.voisin3 == NULL)) { del_Pi->t.position = ACTIF; } - else if ((del_Pi->v.voisin1->t.position == ACCEPTED) && - (del_Pi->v.voisin2->t.position == ACCEPTED) && - (del_Pi->v.voisin3->t.position == ACCEPTED)){ + else if((del_Pi->v.voisin1->t.position == ACCEPTED) && + (del_Pi->v.voisin2->t.position == ACCEPTED) && + (del_Pi->v.voisin3->t.position == ACCEPTED)) { del_Pi->t.position = ACCEPTED; } - else if ((del_Pi->v.voisin1->t.position == ACCEPTED) || - (del_Pi->v.voisin2->t.position == ACCEPTED) || - (del_Pi->v.voisin3->t.position == ACCEPTED)){ + else if((del_Pi->v.voisin1->t.position == ACCEPTED) || + (del_Pi->v.voisin2->t.position == ACCEPTED) || + (del_Pi->v.voisin3->t.position == ACCEPTED)) { del_Pi->t.position = ACTIF; } else { @@ -283,6 +290,5 @@ int CreateLinks(List_T * ListDelaunay , int NumDelaunay, } } - return(1); + return (1); } - diff --git a/Mesh/2D_Mesh.cpp b/Mesh/2D_Mesh.cpp index 534ce5c1450b02d148d184f7426707cba0af4f4b..db82c9c757bd9a51ed9319b51f837da7d6d45e36 100644 --- a/Mesh/2D_Mesh.cpp +++ b/Mesh/2D_Mesh.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_Mesh.cpp,v 1.45 2003-02-25 04:02:51 geuzaine Exp $ +// $Id: 2D_Mesh.cpp,v 1.46 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -44,64 +44,68 @@ #include "2D_Mesh.h" #include "Context.h" -extern Mesh *THEM; -extern Context_T CTX; +extern Mesh *THEM; +extern Context_T CTX; -PointRecord *gPointArray; -DocRecord *BGMESH, *FGMESH; -int LocalNewPoint, is_3D = 0; -double LC2D ; +PointRecord *gPointArray; +DocRecord *BGMESH, *FGMESH; +int LocalNewPoint, is_3D = 0; +double LC2D; -static Surface *THESURFACE, *THESUPPORT; +static Surface *THESURFACE, *THESUPPORT; -void ProjetteSurface (void *a, void *b){ +void ProjetteSurface(void *a, void *b) +{ Vertex *v; v = *(Vertex **) a; - if (!v->ListCurves) - ProjectPointOnSurface (THESUPPORT, *v); + if(!v->ListCurves) + ProjectPointOnSurface(THESUPPORT, *v); } -void Projette_Plan_Moyen (void *a, void *b){ +void Projette_Plan_Moyen(void *a, void *b) +{ Vertex *v = *(Vertex **) a; - Projette (v, THESURFACE->plan); + Projette(v, THESURFACE->plan); } -void Projette_Inverse (void *a, void *b){ +void Projette_Inverse(void *a, void *b) +{ Vertex *v = *(Vertex **) a; - Projette (v, THESURFACE->invplan); + Projette(v, THESURFACE->invplan); } -void Plan_Moyen (void *data, void *dum){ - int i, j; - Vertex *v; - Curve *pC; - Surface **pS, *s; - static List_T *points; - static int deb = 1; +void Plan_Moyen(void *data, void *dum) +{ + int i, j; + Vertex *v; + Curve *pC; + Surface **pS, *s; + static List_T *points; + static int deb = 1; pS = (Surface **) data; s = *pS; - if (deb){ - points = List_Create (10, 10, sizeof (Vertex *)); + if(deb) { + points = List_Create(10, 10, sizeof(Vertex *)); deb = 0; } else - List_Reset (points); + List_Reset(points); - switch (s->Typ){ + switch (s->Typ) { case MSH_SURF_PLAN: case MSH_SURF_TRIC: case MSH_SURF_REGL: case MSH_SURF_NURBS: case MSH_SURF_TRIMMED: - for (i = 0; i < List_Nbr (s->Generatrices); i++){ - List_Read (s->Generatrices, i, &pC); - for (j = 0; j < List_Nbr (pC->Vertices); j++){ - List_Read (pC->Vertices, j, &v); - List_Add (points, &v); - Tree_Insert (s->Vertices, List_Pointer (pC->Vertices, j)); + for(i = 0; i < List_Nbr(s->Generatrices); i++) { + List_Read(s->Generatrices, i, &pC); + for(j = 0; j < List_Nbr(pC->Vertices); j++) { + List_Read(pC->Vertices, j, &v); + List_Add(points, &v); + Tree_Insert(s->Vertices, List_Pointer(pC->Vertices, j)); } } break; @@ -111,64 +115,66 @@ void Plan_Moyen (void *data, void *dum){ } -int Calcule_Contours (Surface * s){ +int Calcule_Contours(Surface * s) +{ int i, j, ori, ORI = 0; Vertex *v, *first, *last; List_T *l, *linv; Curve *c; - double n[] = {0., 0., 1.}; + double n[] = { 0., 0., 1. }; - l = List_Create (10, 10, sizeof (Vertex *)); - for (i = 0; i < List_Nbr (s->Generatrices); i++){ - List_Read (s->Generatrices, i, &c); - if (!List_Nbr (l)){ - List_Read (c->Vertices, 0, &first); + l = List_Create(10, 10, sizeof(Vertex *)); + for(i = 0; i < List_Nbr(s->Generatrices); i++) { + List_Read(s->Generatrices, i, &c); + if(!List_Nbr(l)) { + List_Read(c->Vertices, 0, &first); } - for (j = 1; j < List_Nbr (c->Vertices); j++){ - List_Read (c->Vertices, j, &v); - List_Add (l, &v); - if (j == List_Nbr (c->Vertices) - 1){ + for(j = 1; j < List_Nbr(c->Vertices); j++) { + List_Read(c->Vertices, j, &v); + List_Add(l, &v); + if(j == List_Nbr(c->Vertices) - 1) { last = v; } } - if (!compareVertex (&last, &first)){ - ori = Oriente (l, n); + if(!compareVertex(&last, &first)) { + ori = Oriente(l, n); /* Le premier contour est oriente aire a droite Les autes sont des trous orientes aire a gauche */ - - if (!List_Nbr (s->Contours)) + + if(!List_Nbr(s->Contours)) ORI = ori; - if ((!List_Nbr (s->Contours) && !ori) || - (List_Nbr (s->Contours) && ori)){ - linv = List_Create (10, 10, sizeof (Vertex *)); - List_Invert (l, linv); - List_Delete (l); + if((!List_Nbr(s->Contours) && !ori) || (List_Nbr(s->Contours) && ori)) { + linv = List_Create(10, 10, sizeof(Vertex *)); + List_Invert(l, linv); + List_Delete(l); l = linv; } - List_Add (s->Contours, &l); - l = List_Create (10, 10, sizeof (Vertex *)); + List_Add(s->Contours, &l); + l = List_Create(10, 10, sizeof(Vertex *)); } } return ORI; } -void Calcule_Z (void *data, void *dum){ +void Calcule_Z(void *data, void *dum) +{ Vertex **pv, *v; double Z, U, V; pv = (Vertex **) data; v = *pv; - if (v->Frozen || v->Num < 0) + if(v->Frozen || v->Num < 0) return; - XYtoUV (THESUPPORT, &v->Pos.X, &v->Pos.Y, &U, &V, &Z, 1.0); + XYtoUV(THESUPPORT, &v->Pos.X, &v->Pos.Y, &U, &V, &Z, 1.0); v->Pos.Z = Z; } -void Calcule_Z_Plan (void *data, void *dum){ +void Calcule_Z_Plan(void *data, void *dum) +{ Vertex **pv, *v; Vertex V; @@ -176,11 +182,11 @@ void Calcule_Z_Plan (void *data, void *dum){ V.Pos.Y = THESURFACE->b; V.Pos.Z = THESURFACE->c; - Projette (&V, THESURFACE->plan); + Projette(&V, THESURFACE->plan); pv = (Vertex **) data; v = *pv; - if (V.Pos.Z != 0.0) + if(V.Pos.Z != 0.0) v->Pos.Z = (THESURFACE->d - V.Pos.X * v->Pos.X - V.Pos.Y * v->Pos.Y) / V.Pos.Z; else @@ -188,12 +194,14 @@ void Calcule_Z_Plan (void *data, void *dum){ } -void Add_In_Mesh (void *a, void *b){ - if (!Tree_Search (THEM->Vertices, a)) - Tree_Add (THEM->Vertices, a); +void Add_In_Mesh(void *a, void *b) +{ + if(!Tree_Search(THEM->Vertices, a)) + Tree_Add(THEM->Vertices, a); } -void Freeze_Vertex (void *a, void *b){ +void Freeze_Vertex(void *a, void *b) +{ Vertex *pv; pv = *(Vertex **) a; pv->Freeze.X = pv->Pos.X; @@ -202,10 +210,11 @@ void Freeze_Vertex (void *a, void *b){ pv->Frozen = 1; } -void deFreeze_Vertex (void *a, void *b){ +void deFreeze_Vertex(void *a, void *b) +{ Vertex *pv; pv = *(Vertex **) a; - if (!pv->Frozen) + if(!pv->Frozen) return; pv->Pos.X = pv->Freeze.X; pv->Pos.Y = pv->Freeze.Y; @@ -213,19 +222,20 @@ void deFreeze_Vertex (void *a, void *b){ pv->Frozen = 0; } -void PutVertex_OnSurf (void *a, void *b){ +void PutVertex_OnSurf(void *a, void *b) +{ Vertex *pv; pv = *(Vertex **) a; - if (!pv->ListSurf) - pv->ListSurf = List_Create (1, 1, sizeof (Surface *)); - List_Add (pv->ListSurf, &THESURFACE); + if(!pv->ListSurf) + pv->ListSurf = List_Create(1, 1, sizeof(Surface *)); + List_Add(pv->ListSurf, &THESURFACE); } /* remplis la structure Delaunay d'un triangle cree */ -Delaunay * testconv (avlptr * root, int *conv, DocRecord * ptr){ - +Delaunay *testconv(avlptr * root, int *conv, DocRecord * ptr) +{ avlptr *proot; double qual; Delaunay *pdel; @@ -235,19 +245,19 @@ Delaunay * testconv (avlptr * root, int *conv, DocRecord * ptr){ pdel = NULL; *conv = 0; - if (*root == NULL) + if(*root == NULL) *conv = 1; - else{ - pdel = findrightest (*proot, ptr); + else { + pdel = findrightest(*proot, ptr); qual = pdel->t.quality_value; - switch (LocalNewPoint){ + switch (LocalNewPoint) { case CENTER_CIRCCIRC: case BARYCENTER: - if (qual < CONV_VALUE) + if(qual < CONV_VALUE) *conv = 1; break; case VORONOI_INSERT: - if ((*root) == NULL) + if((*root) == NULL) *conv = 1; break; } @@ -256,31 +266,33 @@ Delaunay * testconv (avlptr * root, int *conv, DocRecord * ptr){ } -int mesh_domain (ContourPeek * ListContours, int numcontours, - maillage * mai, int *numpoints, int OnlyTheInitialMesh){ - List_T *kill_L, *del_L ; +int mesh_domain(ContourPeek * ListContours, int numcontours, + maillage * mai, int *numpoints, int OnlyTheInitialMesh) +{ + List_T *kill_L, *del_L; MPoint pt; DocRecord docm, *doc; - int conv,i,j,nump,numact,numlink,numkil,numaloc,numtri,numtrr,numtrwait; + int conv, i, j, nump, numact, numlink, numkil, numaloc, numtri, numtrr, + numtrwait; Delaunay *del, *del_P, *deladd, **listdel; PointNumero aa, bb, cc, a, b, c; DListPeek list, p, q; avlptr *root, *proot, *root_w, *root_acc; double volume_old, volume_new; - root = (avlptr *) Malloc (sizeof (avlptr)); - root_w = (avlptr *) Malloc (sizeof (avlptr)); - root_acc = (avlptr *) Malloc (sizeof (avlptr)); + root = (avlptr *) Malloc(sizeof(avlptr)); + root_w = (avlptr *) Malloc(sizeof(avlptr)); + root_acc = (avlptr *) Malloc(sizeof(avlptr)); nump = 0; - for (i = 0; i < numcontours; i++) + for(i = 0; i < numcontours; i++) nump += ListContours[i]->numpoints; /* creation du maillage initial grace au puissant algorithme "divide and conquer" */ doc = &docm; FGMESH = &docm; - doc->points = (PointRecord *) Malloc ((nump + 100) * sizeof(PointRecord)); + doc->points = (PointRecord *) Malloc((nump + 100) * sizeof(PointRecord)); gPointArray = doc->points; numaloc = nump; @@ -290,14 +302,14 @@ int mesh_domain (ContourPeek * ListContours, int numcontours, mai->numtriangles = 0; mai->numpoints = 0; - if (!numcontours){ + if(!numcontours) { Msg(GERROR, "No contour"); return 0; } numact = 0; - for (i = 0; i < numcontours; i++){ - for (j = 0; j < ListContours[i]->numpoints; j++){ + for(i = 0; i < numcontours; i++) { + for(j = 0; j < ListContours[i]->numpoints; j++) { doc->points[numact + j].where.h = ListContours[i]->oriented_points[j].where.h + ListContours[i]->perturbations[j].h; @@ -316,13 +328,13 @@ int mesh_domain (ContourPeek * ListContours, int numcontours, numact += ListContours[i]->numpoints; } - DelaunayAndVoronoi (doc); - Conversion (doc); - remove_all_dlist (doc->numPoints, doc->points); + DelaunayAndVoronoi(doc); + Conversion(doc); + remove_all_dlist(doc->numPoints, doc->points); - if (!is_3D || CTX.mesh.constrained_bgmesh){ + if(!is_3D || CTX.mesh.constrained_bgmesh) { BGMESH = doc; - InitBricks (BGMESH); + InitBricks(BGMESH); } else BGMESH = NULL; @@ -330,26 +342,25 @@ int mesh_domain (ContourPeek * ListContours, int numcontours, /* elimination des triangles exterieurs + verification de l'existence des edges (coherence) */ - makepermut (nump); - del_L = List_Create(doc->numTriangles, 1000, sizeof(Delaunay*)); + makepermut(nump); + del_L = List_Create(doc->numTriangles, 1000, sizeof(Delaunay *)); - for(i= 0;i<doc->numTriangles;i++){ - del_P = &doc->delaunay[i] ; - if((del_P->t.a == del_P->t.b) && - (del_P->t.a == del_P->t.c)){ + for(i = 0; i < doc->numTriangles; i++) { + del_P = &doc->delaunay[i]; + if((del_P->t.a == del_P->t.b) && (del_P->t.a == del_P->t.c)) { Msg(GERROR, "Initial mesh is wrong. Try the new isotropic algorithm."); } else List_Add(del_L, &del_P); } doc->numTriangles = List_Nbr(del_L); - - verify_edges (del_L, ListContours, numcontours); - verify_inside (doc->delaunay, doc->numTriangles); + + verify_edges(del_L, ListContours, numcontours); + verify_inside(doc->delaunay, doc->numTriangles); /* creation des liens ( triangles voisins ) */ - CreateLinks (del_L, doc->numTriangles, ListContours, numcontours); + CreateLinks(del_L, doc->numTriangles, ListContours, numcontours); /* initialisation de l'arbre */ @@ -357,31 +368,31 @@ int mesh_domain (ContourPeek * ListContours, int numcontours, int onlyinit = OnlyTheInitialMesh; - if (doc->numTriangles == 1){ + if(doc->numTriangles == 1) { doc->delaunay[0].t.position = INTERN; Msg(INFO, "Only one triangle in initial mesh (skipping refinement)"); onlyinit = 1; } - for (i = 0; i < doc->numTriangles; i++){ - if (doc->delaunay[i].t.position != EXTERN){ + for(i = 0; i < doc->numTriangles; i++) { + if(doc->delaunay[i].t.position != EXTERN) { del = &doc->delaunay[i]; - switch (LocalNewPoint){ + switch (LocalNewPoint) { case CENTER_CIRCCIRC: case BARYCENTER: - Insert_Triangle (root, del); + Insert_Triangle(root, del); break; case VORONOI_INSERT: - switch (del->t.position){ + switch (del->t.position) { case ACTIF: case INTERN: - Insert_Triangle (root, del); + Insert_Triangle(root, del); break; case WAITING: - Insert_Triangle (root_w, del); + Insert_Triangle(root_w, del); break; case ACCEPTED: - Insert_Triangle (root_acc, del); + Insert_Triangle(root_acc, del); break; } } @@ -396,134 +407,134 @@ int mesh_domain (ContourPeek * ListContours, int numcontours, 4) on ajoute les triangles dans l'arbre et on recommence jusque quand tous les triangles sont OK */ - del = testconv (root, &conv, doc); + del = testconv(root, &conv, doc); - PushgPointArray (doc->points); + PushgPointArray(doc->points); List_Reset(del_L); - kill_L = List_Create(1000, 1000, sizeof(Delaunay*)); + kill_L = List_Create(1000, 1000, sizeof(Delaunay *)); - if (onlyinit) + if(onlyinit) conv = 1; - while (conv != 1){ + while(conv != 1) { - pt = Localize (del, doc); + pt = Localize(del, doc); numlink = 0; numkil = 0; list = NULL; - if (!PE_Del_Triangle (del, pt, &list, kill_L, del_L, &numlink, &numkil)){ + if(!PE_Del_Triangle(del, pt, &list, kill_L, del_L, &numlink, &numkil)) { Msg(WARNING, "Triangle non deleted"); - Delete_Triangle (root, del); - Delete_Triangle (root_w, del); + Delete_Triangle(root, del); + Delete_Triangle(root_w, del); del->t.quality_value /= 10.; - switch (LocalNewPoint){ + switch (LocalNewPoint) { case CENTER_CIRCCIRC: case BARYCENTER: - Insert_Triangle (root, del); + Insert_Triangle(root, del); break; case VORONOI_INSERT: del->t.position = ACCEPTED; - Insert_Triangle (root_acc, del); + Insert_Triangle(root_acc, del); break; } - + numlink = numkil = 0; - if (list != NULL){ + if(list != NULL) { p = list; - do{ + do { q = p; - p = Pred (p); - Free (q); + p = Pred(p); + Free(q); } - while (p != list); + while(p != list); } list = NULL; - del = testconv (root, &conv, doc); + del = testconv(root, &conv, doc); continue; } /* Test du Volume */ - + i = 0; p = list; volume_new = 0.0; - do{ + do { q = p->next; bb = p->point_num; cc = q->point_num; - volume_new += fabs ((doc->points[bb].where.h - pt.h) * - (doc->points[cc].where.v - doc->points[bb].where.v) - - (doc->points[cc].where.h - doc->points[bb].where.h) * - (doc->points[bb].where.v - pt.v)); + volume_new += fabs((doc->points[bb].where.h - pt.h) * + (doc->points[cc].where.v - doc->points[bb].where.v) - + (doc->points[cc].where.h - doc->points[bb].where.h) * + (doc->points[bb].where.v - pt.v)); p = q; - } while (p != list); + } while(p != list); volume_old = 0.0; - for (i = 0; i < numkil; i++){ - del_P = *(Delaunay**)List_Pointer(kill_L, i); + for(i = 0; i < numkil; i++) { + del_P = *(Delaunay **) List_Pointer(kill_L, i); aa = del_P->t.a; bb = del_P->t.b; cc = del_P->t.c; - volume_old += fabs ((doc->points[bb].where.h - doc->points[aa].where.h) * - (doc->points[cc].where.v - doc->points[bb].where.v) - - (doc->points[cc].where.h - doc->points[bb].where.h) * - (doc->points[bb].where.v - doc->points[aa].where.v)); + volume_old += fabs((doc->points[bb].where.h - doc->points[aa].where.h) * + (doc->points[cc].where.v - doc->points[bb].where.v) - + (doc->points[cc].where.h - doc->points[bb].where.h) * + (doc->points[bb].where.v - doc->points[aa].where.v)); } - - if ((volume_old - volume_new) / (volume_old + volume_new) > 1.e-6){ + + if((volume_old - volume_new) / (volume_old + volume_new) > 1.e-6) { Msg(WARNING, "Volume has changed (%g->%g)", volume_old, volume_new); - Delete_Triangle (root, del); - Delete_Triangle (root_w, del); + Delete_Triangle(root, del); + Delete_Triangle(root_w, del); del->t.quality_value /= 10.; - switch (LocalNewPoint){ + switch (LocalNewPoint) { case CENTER_CIRCCIRC: case BARYCENTER: - Insert_Triangle (root, del); + Insert_Triangle(root, del); break; case VORONOI_INSERT: del->t.position = ACCEPTED; - Insert_Triangle (root_acc, del); + Insert_Triangle(root_acc, del); break; } numlink = numkil = 0; - if (list != NULL){ + if(list != NULL) { p = list; - do{ + do { q = p; - p = Pred (p); - Free (q); - } while (p != list); + p = Pred(p); + Free(q); + } while(p != list); } list = NULL; - del = testconv (root, &conv, doc); + del = testconv(root, &conv, doc); continue; } /* Fin test du volume */ - for (i = 0; i < numkil; i++){ - del_P = *(Delaunay**)List_Pointer(kill_L, i); + for(i = 0; i < numkil; i++) { + del_P = *(Delaunay **) List_Pointer(kill_L, i); - switch (LocalNewPoint){ + switch (LocalNewPoint) { case CENTER_CIRCCIRC: case BARYCENTER: - Delete_Triangle (root, del_P); + Delete_Triangle(root, del_P); break; case VORONOI_INSERT: - switch (del_P->t.position){ + switch (del_P->t.position) { case WAITING: - Delete_Triangle (root_w, del_P); + Delete_Triangle(root_w, del_P); break; case ACTIF: case INTERN: - Delete_Triangle (root, del_P); + Delete_Triangle(root, del_P); break; case ACCEPTED: - Delete_Triangle (root_acc, del_P); + Delete_Triangle(root_acc, del_P); break; } } @@ -532,65 +543,65 @@ int mesh_domain (ContourPeek * ListContours, int numcontours, } *numpoints = doc->numPoints; - Insert_Point (pt, numpoints, &numaloc, doc, BGMESH, is_3D); + Insert_Point(pt, numpoints, &numaloc, doc, BGMESH, is_3D); doc->points = gPointArray; doc->numPoints = *numpoints; i = 0; p = list; - do{ + do { q = p->next; - + aa = doc->numPoints - 1; bb = p->point_num; cc = q->point_num; - - deladd = (Delaunay *) Malloc (sizeof (Delaunay)); - - filldel (deladd, aa, bb, cc, doc->points, BGMESH); - - List_Put(del_L, numlink+i, &deladd); + + deladd = (Delaunay *) Malloc(sizeof(Delaunay)); + + filldel(deladd, aa, bb, cc, doc->points, BGMESH); + + List_Put(del_L, numlink + i, &deladd); i++; p = q; - - } while (p != list); + + } while(p != list); p = list; - - do{ + + do { q = p; - p = Pred (p); - Free (q); - } while (p != list); + p = Pred(p); + Free(q); + } while(p != list); - CreateLinks (del_L, i + numlink, ListContours, numcontours); + CreateLinks(del_L, i + numlink, ListContours, numcontours); - for (j = 0; j < i; j++){ - del_P = *(Delaunay**)List_Pointer(del_L, j+numlink) ; + for(j = 0; j < i; j++) { + del_P = *(Delaunay **) List_Pointer(del_L, j + numlink); switch (LocalNewPoint) { case CENTER_CIRCCIRC: case BARYCENTER: - Insert_Triangle (root, del_P); + Insert_Triangle(root, del_P); break; case VORONOI_INSERT: - switch (del_P->t.position){ + switch (del_P->t.position) { case ACTIF: case INTERN: - Insert_Triangle (root, del_P); + Insert_Triangle(root, del_P); break; case WAITING: - Insert_Triangle (root_w, del_P); + Insert_Triangle(root_w, del_P); break; case ACCEPTED: - Insert_Triangle (root_acc, del_P); + Insert_Triangle(root_acc, del_P); break; } } } - - del = testconv (root, &conv, doc); - + + del = testconv(root, &conv, doc); + } List_Delete(kill_L); @@ -598,36 +609,36 @@ int mesh_domain (ContourPeek * ListContours, int numcontours, numtri = 0; numtrwait = 0; - if (*root_w != NULL){ + if(*root_w != NULL) { proot = root_w; - avltree_count (*proot, &numtrwait); + avltree_count(*proot, &numtrwait); } numtrr = 0; proot = root; - switch (LocalNewPoint){ + switch (LocalNewPoint) { case VORONOI_INSERT: proot = root_acc; break; } - avltree_count (*proot, &numtrr); + avltree_count(*proot, &numtrr); - alloue_Mai_Del (mai, numtrr + numtrwait + 1, 100); + alloue_Mai_Del(mai, numtrr + numtrwait + 1, 100); listdel = mai->listdel; numtri = 0; - avltree_print(*proot,listdel,&numtri); - if(numtrwait != 0){ + avltree_print(*proot, listdel, &numtri); + if(numtrwait != 0) { numtri = 0; - avltree_print(*root_w,(Delaunay**)del_L->array,&numtri); - for(i=0;i<numtrwait;i++){ - mai->listdel[i+numtrr] = *(Delaunay**)List_Pointer(del_L, i); + avltree_print(*root_w, (Delaunay **) del_L->array, &numtri); + for(i = 0; i < numtrwait; i++) { + mai->listdel[i + numtrr] = *(Delaunay **) List_Pointer(del_L, i); } avltree_remove(root_w); } avltree_remove(root); - + List_Delete(del_L); mai->numtriangles = numtrr + numtrwait; @@ -636,22 +647,22 @@ int mesh_domain (ContourPeek * ListContours, int numcontours, /* Tous Les Triangles doivent etre orientes */ - if (!mai->numtriangles){ + if(!mai->numtriangles) { Msg(GERROR, "No triangles in surface mesh"); return 0; //mai->numtriangles = 1; } - for (i = 0; i < mai->numtriangles; i++){ + for(i = 0; i < mai->numtriangles; i++) { a = mai->listdel[i]->t.a; b = mai->listdel[i]->t.b; c = mai->listdel[i]->t.c; mai->listdel[i]->v.voisin1 = NULL; - if (((doc->points[b].where.h - doc->points[a].where.h) * - (doc->points[c].where.v - doc->points[b].where.v) - - (doc->points[c].where.h - doc->points[b].where.h) * - (doc->points[b].where.v - doc->points[a].where.v)) > 0.0){ + if(((doc->points[b].where.h - doc->points[a].where.h) * + (doc->points[c].where.v - doc->points[b].where.v) - + (doc->points[c].where.h - doc->points[b].where.h) * + (doc->points[b].where.v - doc->points[a].where.v)) > 0.0) { mai->listdel[i]->t.a = b; mai->listdel[i]->t.b = a; } @@ -662,146 +673,153 @@ int mesh_domain (ContourPeek * ListContours, int numcontours, return 1; } -void Maillage_Automatique_VieuxCode (Surface * pS, Mesh * m, int ori){ +void Maillage_Automatique_VieuxCode(Surface * pS, Mesh * m, int ori) +{ ContourRecord *cp, **liste; List_T *c; Vertex *v, V[3], *ver[3], **pp[3]; maillage M; int err, i, j, k, N, a, b, d; Simplex *s; - double Xmin=0., Xmax=0., Ymin=0., Ymax=0.; + double Xmin = 0., Xmax = 0., Ymin = 0., Ymax = 0.; - if (m->BGM.Typ == WITHPOINTS){ + if(m->BGM.Typ == WITHPOINTS) { is_3D = 0; } - else{ + else { is_3D = 1; } - liste = (ContourPeek *) Malloc (List_Nbr (pS->Contours) * sizeof (ContourPeek)); + liste = + (ContourPeek *) Malloc(List_Nbr(pS->Contours) * sizeof(ContourPeek)); k = 0; - for (i = 0; i < List_Nbr (pS->Contours); i++){ - cp = (ContourRecord *) Malloc (sizeof (ContourRecord)); - List_Read (pS->Contours, i, &c); - cp->oriented_points = (PointRecord *) Malloc (List_Nbr (c) * sizeof (PointRecord)); - cp->perturbations = (MPoint *) Malloc (List_Nbr (c) * sizeof (MPoint)); + for(i = 0; i < List_Nbr(pS->Contours); i++) { + cp = (ContourRecord *) Malloc(sizeof(ContourRecord)); + List_Read(pS->Contours, i, &c); + cp->oriented_points = + (PointRecord *) Malloc(List_Nbr(c) * sizeof(PointRecord)); + cp->perturbations = (MPoint *) Malloc(List_Nbr(c) * sizeof(MPoint)); cp->numerocontour = i; - for (j = 0; j < List_Nbr (c); j++){ - List_Read (c, j, &v); - if(!j){ - Xmin = Xmax = v->Pos.X ; - Ymin = Ymax = v->Pos.Y ; + for(j = 0; j < List_Nbr(c); j++) { + List_Read(c, j, &v); + if(!j) { + Xmin = Xmax = v->Pos.X; + Ymin = Ymax = v->Pos.Y; } - else{ - Xmin = DMIN(Xmin, v->Pos.X) ; - Xmax = DMAX(Xmax, v->Pos.X) ; - Ymin = DMIN(Ymin, v->Pos.Y) ; - Ymax = DMAX(Ymax, v->Pos.Y) ; + else { + Xmin = DMIN(Xmin, v->Pos.X); + Xmax = DMAX(Xmax, v->Pos.X); + Ymin = DMIN(Ymin, v->Pos.Y); + Ymax = DMAX(Ymax, v->Pos.Y); } } - LC2D = sqrt(DSQR(Xmax-Xmin)+DSQR(Ymax-Ymin)); + LC2D = sqrt(DSQR(Xmax - Xmin) + DSQR(Ymax - Ymin)); - for (j = 0; j < List_Nbr (c); j++){ - List_Read (c, j, &v); + for(j = 0; j < List_Nbr(c); j++) { + List_Read(c, j, &v); cp->oriented_points[j].where.h = v->Pos.X; cp->oriented_points[j].where.v = v->Pos.Y; // On pourrait imaginer diviser les perturbations par un facteur // dependant de v->lc, mais ca n'a pas l'air d'ameliorer le bignou - cp->perturbations[j].h = CTX.mesh.rand_factor * LC2D * - (double)rand()/(double)RAND_MAX; + cp->perturbations[j].h = CTX.mesh.rand_factor * LC2D * + (double)rand() / (double)RAND_MAX; cp->perturbations[j].v = CTX.mesh.rand_factor * LC2D * - (double)rand()/(double)RAND_MAX; + (double)rand() / (double)RAND_MAX; cp->oriented_points[j].numcontour = i; cp->oriented_points[j].quality = v->lc; cp->oriented_points[j].permu = k++; cp->oriented_points[j].initial = v->Num; } - cp->numpoints = List_Nbr (c); + cp->numpoints = List_Nbr(c); liste[i] = cp; } - if (pS->Method) - mesh_domain (liste, List_Nbr (pS->Contours), &M, &N, (CTX.mesh.initial_only==2)); + if(pS->Method) + mesh_domain(liste, List_Nbr(pS->Contours), &M, &N, + (CTX.mesh.initial_only == 2)); - for (i = 0; i < M.numpoints; i++){ - if (gPointArray[i].initial < 0){ + for(i = 0; i < M.numpoints; i++) { + if(gPointArray[i].initial < 0) { gPointArray[i].initial = ++THEM->MaxPointNum; - v = Create_Vertex (gPointArray[i].initial, gPointArray[i].where.h, - gPointArray[i].where.v, 0.0, gPointArray[i].quality, 0.0); - if (!Tree_Search (pS->Vertices, &v)) - Tree_Add (pS->Vertices, &v); + v = Create_Vertex(gPointArray[i].initial, gPointArray[i].where.h, + gPointArray[i].where.v, 0.0, gPointArray[i].quality, + 0.0); + if(!Tree_Search(pS->Vertices, &v)) + Tree_Add(pS->Vertices, &v); } } - for (i = 0; i < 3; i++) + for(i = 0; i < 3; i++) ver[i] = &V[i]; - for (i = 0; i < M.numtriangles; i++){ + for(i = 0; i < M.numtriangles; i++) { a = M.listdel[i]->t.a; b = M.listdel[i]->t.b; d = M.listdel[i]->t.c; - + ver[0]->Num = gPointArray[a].initial; ver[1]->Num = gPointArray[b].initial; ver[2]->Num = gPointArray[d].initial; err = 0; - for (j = 0; j < 3; j++){ - if ((pp[j] = (Vertex **) Tree_PQuery (pS->Vertices, &ver[j]))){ + for(j = 0; j < 3; j++) { + if((pp[j] = (Vertex **) Tree_PQuery(pS->Vertices, &ver[j]))) { } - else{ + else { err = 1; Msg(GERROR, "Unknown vertex %d", ver[j]->Num); } } /* - Je n'ai pas l'impression que ceci fonctionne comme voulu (essaie - e.g. avec demos/machine.geo)... - if (ori && !err) - s = Create_Simplex (*pp[0], *pp[1], *pp[2], NULL); - else if (!err) - s = Create_Simplex (*pp[0], *pp[2], *pp[1], NULL); - if (!err){ + Je n'ai pas l'impression que ceci fonctionne comme voulu (essaie + e.g. avec demos/machine.geo)... + if (ori && !err) + s = Create_Simplex (*pp[0], *pp[1], *pp[2], NULL); + else if (!err) + s = Create_Simplex (*pp[0], *pp[2], *pp[1], NULL); + if (!err){ + s->iEnt = pS->Num; + Tree_Insert (pS->Simplexes, &s); + } + */ + if(!err) { + s = Create_Simplex(*pp[0], *pp[2], *pp[1], NULL); s->iEnt = pS->Num; - Tree_Insert (pS->Simplexes, &s); - } - */ - if (!err){ - s = Create_Simplex (*pp[0], *pp[2], *pp[1], NULL); - s->iEnt = pS->Num; - Tree_Insert (pS->Simplexes, &s); + Tree_Insert(pS->Simplexes, &s); } // MEMORY LEAK (JF) // Free(M.listdel[i]); } // ANOTHER ONE (JF) - Free (M.listdel); - Free (gPointArray); + Free(M.listdel); + Free(gPointArray); } -void Make_Mesh_With_Points (DocRecord * ptr, PointRecord * Liste, int Numpoints){ +void Make_Mesh_With_Points(DocRecord * ptr, PointRecord * Liste, + int Numpoints) +{ ptr->numTriangles = 0; ptr->points = Liste; ptr->numPoints = Numpoints; ptr->delaunay = 0; - DelaunayAndVoronoi (ptr); - Conversion (ptr); - remove_all_dlist (ptr->numPoints, ptr->points); + DelaunayAndVoronoi(ptr); + Conversion(ptr); + remove_all_dlist(ptr->numPoints, ptr->points); } -void filldel (Delaunay * deladd, int aa, int bb, int cc, - PointRecord * points, DocRecord * mesh){ - +void filldel(Delaunay * deladd, int aa, int bb, int cc, + PointRecord * points, DocRecord * mesh) +{ double qual, newqual, L; MPoint pt2, pt4; Vertex *v, *dum; @@ -815,65 +833,69 @@ void filldel (Delaunay * deladd, int aa, int bb, int cc, deladd->v.voisin2 = NULL; deladd->v.voisin3 = NULL; - CircumCircle (points[aa].where.h, - points[aa].where.v, - points[bb].where.h, - points[bb].where.v, - points[cc].where.h, - points[cc].where.v, - &deladd->t.xc, - &deladd->t.yc); + CircumCircle(points[aa].where.h, + points[aa].where.v, + points[bb].where.h, + points[bb].where.v, + points[cc].where.h, + points[cc].where.v, &deladd->t.xc, &deladd->t.yc); pt2.h = deladd->t.xc; pt2.v = deladd->t.yc; - if (!is_3D){ - if (mesh){ - newqual = find_quality (pt2, mesh); + if(!is_3D) { + if(mesh) { + newqual = find_quality(pt2, mesh); } - else{ - newqual = (points[aa].quality + points[bb].quality + points[cc].quality) / 3.; + else { + newqual = + (points[aa].quality + points[bb].quality + points[cc].quality) / 3.; } - v = Create_Vertex (-1, pt2.h, pt2.v, 0.0, 0.0, 0.0); - Calcule_Z_Plan (&v, &dum); - Projette_Inverse (&v, &dum); - Free_Vertex (&v,0); + v = Create_Vertex(-1, pt2.h, pt2.v, 0.0, 0.0, 0.0); + Calcule_Z_Plan(&v, &dum); + Projette_Inverse(&v, &dum); + Free_Vertex(&v, 0); } - else{ - v = Create_Vertex (-1, pt2.h, pt2.v, 0.0, 0.0, 0.0); - Calcule_Z_Plan (&v, &dum); - Projette_Inverse (&v, &dum); - qual = Lc_XYZ (v->Pos.X, v->Pos.Y, v->Pos.Z, THEM); - if(CTX.mesh.constrained_bgmesh){ - if (mesh){ - newqual = MIN(qual,find_quality (pt2, mesh)); + else { + v = Create_Vertex(-1, pt2.h, pt2.v, 0.0, 0.0, 0.0); + Calcule_Z_Plan(&v, &dum); + Projette_Inverse(&v, &dum); + qual = Lc_XYZ(v->Pos.X, v->Pos.Y, v->Pos.Z, THEM); + if(CTX.mesh.constrained_bgmesh) { + if(mesh) { + newqual = MIN(qual, find_quality(pt2, mesh)); } - else{ - newqual = MIN(qual, (points[aa].quality + points[bb].quality + points[cc].quality) / 3.); + else { + newqual = + MIN(qual, + (points[aa].quality + points[bb].quality + + points[cc].quality) / 3.); } } else newqual = qual; - Free_Vertex (&v,0); + Free_Vertex(&v, 0); } - switch (LocalNewPoint){ + switch (LocalNewPoint) { case CENTER_CIRCCIRC: case BARYCENTER: deladd->t.quality_value = - sqrt ((deladd->t.xc - points[cc].where.h) * (deladd->t.xc - points[cc].where.h) + - (deladd->t.yc - points[cc].where.v) * (deladd->t.yc - points[cc].where.v) - ) / newqual; + sqrt((deladd->t.xc - points[cc].where.h) * (deladd->t.xc - + points[cc].where.h) + + (deladd->t.yc - points[cc].where.v) * (deladd->t.yc - + points[cc].where.v) + ) / newqual; deladd->t.position = INTERN; break; - + case VORONOI_INSERT: pt4.h = points[bb].where.h; pt4.v = points[bb].where.v; //pt3.h = .5 * (points[bb].where.h + points[cc].where.h); //pt3.v = .5 * (points[bb].where.v + points[cc].where.v); - deladd->t.quality_value = myhypot (pt2.h - pt4.h, pt2.v - pt4.v); + deladd->t.quality_value = myhypot(pt2.h - pt4.h, pt2.v - pt4.v); L = newqual / deladd->t.quality_value; - if (L > 1.5) + if(L > 1.5) deladd->t.position = ACCEPTED; else deladd->t.position = NONACCEPTED; @@ -881,23 +903,25 @@ void filldel (Delaunay * deladd, int aa, int bb, int cc, } } -void ActionEndTheCurve (void *a, void *b){ +void ActionEndTheCurve(void *a, void *b) +{ Curve *c = *(Curve **) a; - End_Curve (c); + End_Curve(c); } -void Maillage_Surface (void *data, void *dum){ - Surface **pS, *s; - Tree_T *tnxe; - int ori, nbqua = 0; +void Maillage_Surface(void *data, void *dum) +{ + Surface **pS, *s; + Tree_T *tnxe; + int ori, nbqua = 0; pS = (Surface **) data; s = *pS; - if (!s->Support) + if(!s->Support) return; - if(s->Dirty){ + if(s->Dirty) { Msg(INFO, "Not meshing dirty Surface %d", s->Num); return; } @@ -907,25 +931,24 @@ void Maillage_Surface (void *data, void *dum){ LocalNewPoint = CTX.mesh.point_insertion; - if (Tree_Nbr (s->Simplexes)) - Tree_Delete (s->Simplexes); - s->Simplexes = Tree_Create (sizeof (Simplex *), compareQuality); - if (Tree_Nbr (s->Vertices)) - Tree_Delete (s->Vertices); - s->Vertices = Tree_Create (sizeof (Vertex *), compareVertex); + if(Tree_Nbr(s->Simplexes)) + Tree_Delete(s->Simplexes); + s->Simplexes = Tree_Create(sizeof(Simplex *), compareQuality); + if(Tree_Nbr(s->Vertices)) + Tree_Delete(s->Vertices); + s->Vertices = Tree_Create(sizeof(Vertex *), compareVertex); Msg(STATUS3, "Meshing Surface %d", s->Num); - if (MeshTransfiniteSurface (s) || - MeshEllipticSurface (s) || - MeshCylindricalSurface (s) || - MeshParametricSurface (s) || - Extrude_Mesh (s)){ - Tree_Action (THEM->Points, PutVertex_OnSurf); - Tree_Action (s->Vertices, PutVertex_OnSurf); - Tree_Action (s->Vertices, Add_In_Mesh); - if (CTX.mesh.degree == 2) - Degre2 (THEM->Vertices, s->Vertices, s->Simplexes, NULL, s); + if(MeshTransfiniteSurface(s) || + MeshEllipticSurface(s) || + MeshCylindricalSurface(s) || + MeshParametricSurface(s) || Extrude_Mesh(s)) { + Tree_Action(THEM->Points, PutVertex_OnSurf); + Tree_Action(s->Vertices, PutVertex_OnSurf); + Tree_Action(s->Vertices, Add_In_Mesh); + if(CTX.mesh.degree == 2) + Degre2(THEM->Vertices, s->Vertices, s->Simplexes, NULL, s); THEM->Statistics[5] += Tree_Nbr(THESURFACE->Vertices); THEM->Statistics[7] += Tree_Nbr(THESURFACE->Simplexes); @@ -934,74 +957,74 @@ void Maillage_Surface (void *data, void *dum){ Link_Simplexes(NULL, THES->Simplexes); void constraint_the_edge (int ,int ,int); constraint_the_edge (6, 45, 85); - */ + */ return; } int TypSurface = s->Typ; - Plan_Moyen (pS, dum); - Tree_Action (THEM->Points, Freeze_Vertex); - Tree_Action (s->Vertices, Freeze_Vertex); - Tree_Action (THEM->Points, Projette_Plan_Moyen); - Tree_Action (s->Vertices , Projette_Plan_Moyen); - Tree_Action (THEM->Curves, ActionEndTheCurve); + Plan_Moyen(pS, dum); + Tree_Action(THEM->Points, Freeze_Vertex); + Tree_Action(s->Vertices, Freeze_Vertex); + Tree_Action(THEM->Points, Projette_Plan_Moyen); + Tree_Action(s->Vertices, Projette_Plan_Moyen); + Tree_Action(THEM->Curves, ActionEndTheCurve); s->Typ = MSH_SURF_PLAN; - End_Surface (s); + End_Surface(s); - ori = Calcule_Contours (s); + ori = Calcule_Contours(s); - if (CTX.mesh.algo == DELAUNAY_ISO) - Maillage_Automatique_VieuxCode (s, THEM, ori); + if(CTX.mesh.algo == DELAUNAY_ISO) + Maillage_Automatique_VieuxCode(s, THEM, ori); else if(CTX.mesh.algo == DELAUNAY_ANISO) - AlgorithmeMaillage2DAnisotropeModeJF (s); + AlgorithmeMaillage2DAnisotropeModeJF(s); else Mesh_Shewchuk(s); - if(CTX.mesh.nb_smoothing){ + if(CTX.mesh.nb_smoothing) { Msg(STATUS3, "Mesh smoothing"); - tnxe = Tree_Create (sizeof (NXE), compareNXE); - create_NXE (s->Vertices, s->Simplexes, tnxe); - for (int i = 0; i < CTX.mesh.nb_smoothing; i++) - Tree_Action (tnxe, ActionLiss); + tnxe = Tree_Create(sizeof(NXE), compareNXE); + create_NXE(s->Vertices, s->Simplexes, tnxe); + for(int i = 0; i < CTX.mesh.nb_smoothing; i++) + Tree_Action(tnxe, ActionLiss); // MEMORY LEAK (JF) - delete_NXE (tnxe); + delete_NXE(tnxe); } - if (s->Recombine) - nbqua = Recombine (s->Vertices, s->Simplexes, s->RecombineAngle); + if(s->Recombine) + nbqua = Recombine(s->Vertices, s->Simplexes, s->RecombineAngle); s->Typ = TypSurface; - if (s->Typ != MSH_SURF_PLAN){ - if (s->Extrude) - s->Extrude->Rotate (s->plan); - Tree_Action (s->Vertices, Calcule_Z); - if (s->Extrude) - s->Extrude->Rotate (s->invplan); + if(s->Typ != MSH_SURF_PLAN) { + if(s->Extrude) + s->Extrude->Rotate(s->plan); + Tree_Action(s->Vertices, Calcule_Z); + if(s->Extrude) + s->Extrude->Rotate(s->invplan); } else - Tree_Action (s->Vertices, Calcule_Z_Plan); + Tree_Action(s->Vertices, Calcule_Z_Plan); - Tree_Action (s->Vertices, Projette_Inverse); - Tree_Action (THEM->Points, Projette_Inverse); + Tree_Action(s->Vertices, Projette_Inverse); + Tree_Action(THEM->Points, Projette_Inverse); - Tree_Action (THEM->Points, deFreeze_Vertex); - Tree_Action (s->Vertices, deFreeze_Vertex); + Tree_Action(THEM->Points, deFreeze_Vertex); + Tree_Action(s->Vertices, deFreeze_Vertex); - Tree_Action (THEM->Points, PutVertex_OnSurf); - Tree_Action (s->Vertices, PutVertex_OnSurf); - Tree_Action (s->Vertices, Add_In_Mesh); + Tree_Action(THEM->Points, PutVertex_OnSurf); + Tree_Action(s->Vertices, PutVertex_OnSurf); + Tree_Action(s->Vertices, Add_In_Mesh); - Tree_Action (THEM->Curves, ActionEndTheCurve); - End_Surface (s->Support); - End_Surface (s); + Tree_Action(THEM->Curves, ActionEndTheCurve); + End_Surface(s->Support); + End_Surface(s); - if (CTX.mesh.degree == 2) - Degre2 (THEM->Vertices, THEM->VertexEdges, s->Simplexes, NULL, THESUPPORT); + if(CTX.mesh.degree == 2) + Degre2(THEM->Vertices, THEM->VertexEdges, s->Simplexes, NULL, THESUPPORT); THEM->Statistics[5] += Tree_Nbr(THESURFACE->Vertices); - THEM->Statistics[7] += Tree_Nbr(THESURFACE->Simplexes); // tri+qua + THEM->Statistics[7] += Tree_Nbr(THESURFACE->Simplexes); // tri+qua THEM->Statistics[8] += nbqua; } diff --git a/Mesh/2D_Mesh_Aniso.cpp b/Mesh/2D_Mesh_Aniso.cpp index 6a67cfd4da5209c0913a53ace5ea1de91ed551e3..da2b38940342145521e351ffd491294cfda9780d 100644 --- a/Mesh/2D_Mesh_Aniso.cpp +++ b/Mesh/2D_Mesh_Aniso.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_Mesh_Aniso.cpp,v 1.33 2003-02-25 04:02:51 geuzaine Exp $ +// $Id: 2D_Mesh_Aniso.cpp,v 1.34 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -30,26 +30,22 @@ #include "Create.h" #include "Context.h" -extern Context_T CTX ; -extern double LC2D ; +extern Context_T CTX; +extern double LC2D; -inline void cgsmpl (Simplex *s, double &x, double &y) +inline void cgsmpl(Simplex * s, double &x, double &y) { - x = (1./3.) * ( s->V[0]->Pos.X + - s->V[1]->Pos.X + - s->V[2]->Pos.X); - y = (1./3.) * ( s->V[0]->Pos.Y + - s->V[1]->Pos.Y + - s->V[2]->Pos.Y); + x = (1. / 3.) * (s->V[0]->Pos.X + s->V[1]->Pos.X + s->V[2]->Pos.X); + y = (1. / 3.) * (s->V[0]->Pos.Y + s->V[1]->Pos.Y + s->V[2]->Pos.Y); } -MeshParameters:: MeshParameters (): - NbSmoothing (3), - DelaunayAlgorithm (DELAUNAY_ANISO), - DelaunayInsertionMethod (INSERTION_CENTROID), - DelaunayQuality (QUALITY_EDGES_BASED), - InteractiveDelaunay (false) +MeshParameters::MeshParameters() + : NbSmoothing(3), + DelaunayAlgorithm(DELAUNAY_ANISO), + DelaunayInsertionMethod(INSERTION_CENTROID), + DelaunayQuality(QUALITY_EDGES_BASED), InteractiveDelaunay(false) { + ; } extern Simplex MyNewBoundary; @@ -59,7 +55,7 @@ extern int Alerte_Point_Scabreux; extern PointRecord *gPointArray; extern Surface *PARAMETRIC; -static Tree_T *Tsd, *Sim_Sur_Le_Bord ; +static Tree_T *Tsd, *Sim_Sur_Le_Bord; static List_T *Simplexes_Destroyed, *Simplexes_New, *Suppress; static Simplex *THES; static Vertex *THEV; @@ -69,16 +65,18 @@ static int ZONEELIMINEE, Methode = 0; static double volume; static List_T *coquille; static Edge *THEEDGE; -extern void LCBGM (double X, double Y, double Z, double *l); -double Interpole_lcTriangle (Simplex * s, Vertex * vv){ + +extern void LCBGM(double X, double Y, double Z, double *l); + +double Interpole_lcTriangle(Simplex * s, Vertex * vv) +{ double Xp, Yp, X[3], Y[3], det, u, v, q1, q2, q3; - if (THEM->BGM.Typ == ONFILE) - { - double LL; - LCBGM (vv->Pos.X,vv->Pos.Y,0.0,&LL); - return LL * CTX.mesh.lc_factor; - } + if(THEM->BGM.Typ == ONFILE) { + double LL; + LCBGM(vv->Pos.X, vv->Pos.Y, 0.0, &LL); + return LL * CTX.mesh.lc_factor; + } Xp = vv->Pos.X; Yp = vv->Pos.Y; @@ -97,11 +95,11 @@ double Interpole_lcTriangle (Simplex * s, Vertex * vv){ det = (X[2] - X[0]) * (Y[1] - Y[0]) - (Y[2] - Y[0]) * (X[1] - X[0]); - if (det != 0.0){ + if(det != 0.0) { u = ((Xp - X[0]) * (Y[1] - Y[0]) - (Yp - Y[0]) * (X[1] - X[0])) / det; v = ((X[2] - X[0]) * (Yp - Y[0]) - (Y[2] - Y[0]) * (Xp - X[0])) / det; } - else{ + else { u = v = 0.0; } return (q1 * (1. - u - v) + q2 * v + q3 * u); @@ -117,51 +115,54 @@ double Interpole_lcTriangle (Simplex * s, Vertex * vv){ (x-x1) M (x-x1) = (x-x3) M (x-x3) */ -void matXmat (int n, double mat1[3][3], double mat2[3][3], double Res[3][3]){ - for (int i = 0; i < n; i++){ - for (int j = 0; j < n; j++){ +void matXmat(int n, double mat1[3][3], double mat2[3][3], double Res[3][3]) +{ + for(int i = 0; i < n; i++) { + for(int j = 0; j < n; j++) { Res[i][j] = 0.0; - for (int k = 0; k < n; k++) + for(int k = 0; k < n; k++) Res[i][j] += mat1[i][k] * mat2[k][j]; } } } -void TmatXmat (int n, double mat1[3][3], double mat2[3][3], double Res[3][3]){ - for (int i = 0; i < n; i++){ - for (int j = 0; j < n; j++){ +void TmatXmat(int n, double mat1[3][3], double mat2[3][3], double Res[3][3]) +{ + for(int i = 0; i < n; i++) { + for(int j = 0; j < n; j++) { Res[i][j] = 0.0; - for (int k = 0; k < n; k++) + for(int k = 0; k < n; k++) Res[i][j] += mat1[k][i] * mat2[k][j]; } } } -Simplex * Create_Simplex_For2dmesh (Vertex * v1, Vertex * v2, Vertex * v3, Vertex * v4){ +Simplex *Create_Simplex_For2dmesh(Vertex * v1, Vertex * v2, Vertex * v3, + Vertex * v4) +{ Simplex *s; double p12, p23, p13; double srf = ((v2->Pos.X - v1->Pos.X) * - (v3->Pos.Y - v2->Pos.Y) - - (v3->Pos.X - v2->Pos.X) * - (v2->Pos.Y - v1->Pos.Y)); + (v3->Pos.Y - v2->Pos.Y) - + (v3->Pos.X - v2->Pos.X) * (v2->Pos.Y - v1->Pos.Y)); if(srf > 0) - s = Create_Simplex (v3, v2, v1, v4); + s = Create_Simplex(v3, v2, v1, v4); else - s = Create_Simplex (v1, v2, v3, v4); - - THEM->Metric->setSimplexQuality (s, PARAMETRIC); - - if (PARAMETRIC){ - if ((!v2->ListCurves && !v3->ListCurves && !v3->ListCurves)){ - prosca (v1->us, v2->us, &p12); - p12 = fabs (p12); - prosca (v1->us, v3->us, &p13); - p13 = fabs (p13); - prosca (v2->us, v3->us, &p23); - p23 = fabs (p23); - if (s->Quality < CONV_VALUE && - (p12 < THEM->Metric->min_cos || p13 < THEM->Metric->min_cos || - p23 < THEM->Metric->min_cos)) + s = Create_Simplex(v1, v2, v3, v4); + + THEM->Metric->setSimplexQuality(s, PARAMETRIC); + + if(PARAMETRIC) { + if((!v2->ListCurves && !v3->ListCurves && !v3->ListCurves)) { + prosca(v1->us, v2->us, &p12); + p12 = fabs(p12); + prosca(v1->us, v3->us, &p13); + p13 = fabs(p13); + prosca(v2->us, v3->us, &p23); + p23 = fabs(p23); + if(s->Quality < CONV_VALUE && + (p12 < THEM->Metric->min_cos || p13 < THEM->Metric->min_cos || + p23 < THEM->Metric->min_cos)) s->Quality = 1.0; } } @@ -170,50 +171,54 @@ Simplex * Create_Simplex_For2dmesh (Vertex * v1, Vertex * v2, Vertex * v3, Verte /*En l'honneur de ma femme Stephanie... */ -void VSIM_2D (void *a, void *b){ +void VSIM_2D(void *a, void *b) +{ Simplex *S; S = *(Simplex **) a; - if (S->V[2]) - volume += fabs (S->Volume_Simplexe2D ()); + if(S->V[2]) + volume += fabs(S->Volume_Simplexe2D()); } -void Box_2_Triangles (List_T * P, Surface * s){ +void Box_2_Triangles(List_T * P, Surface * s) +{ #define FACT 1.1 #define LOIN 0.2 int i, j; static int pts[4][2] = { {0, 0}, - {1, 0}, - {1, 1}, - {0, 1} }; - static int tri[2][3] = { {1, 4, 2}, - {2, 4, 3} }; - double Xm=0., Ym=0., XM=0., YM=0., Xc=0., Yc=0.; + {1, 0}, + {1, 1}, + {0, 1} + }; + static int tri[2][3] = { {1, 4, 2}, + {2, 4, 3} + }; + double Xm = 0., Ym = 0., XM = 0., YM = 0., Xc = 0., Yc = 0.; Simplex *S, *ps; Vertex *V, *v, *pv; List_T *smp; - smp = List_Create (2, 1, sizeof (Simplex *)); + smp = List_Create(2, 1, sizeof(Simplex *)); - V = (Vertex *) Malloc (4 * sizeof (Vertex)); + V = (Vertex *) Malloc(4 * sizeof(Vertex)); - for (i = 0; i < List_Nbr (P); i++){ - List_Read (P, i, &v); - if (!i){ + for(i = 0; i < List_Nbr(P); i++) { + List_Read(P, i, &v); + if(!i) { Xm = XM = v->Pos.X; Ym = YM = v->Pos.Y; } - else{ - Xm = DMIN (Xm, v->Pos.X); - XM = DMAX (XM, v->Pos.X); - Ym = DMIN (Ym, v->Pos.Y); - YM = DMAX (YM, v->Pos.Y); + else { + Xm = DMIN(Xm, v->Pos.X); + XM = DMAX(XM, v->Pos.X); + Ym = DMIN(Ym, v->Pos.Y); + YM = DMAX(YM, v->Pos.Y); } } - if (Xm == XM) + if(Xm == XM) XM = Xm + 1.; - if (Ym == YM) + if(Ym == YM) YM = Ym + 1.; Xc = XM - Xm; @@ -231,44 +236,44 @@ void Box_2_Triangles (List_T * P, Surface * s){ /* Longueur Caracteristique */ - LC2D = sqrt (Xc * Xc + Yc * Yc); + LC2D = sqrt(Xc * Xc + Yc * Yc); - for (i = 0; i < 4; i++){ - if (pts[i][0]) + for(i = 0; i < 4; i++) { + if(pts[i][0]) V[i].Freeze.X = V[i].Pos.X = Xm - LOIN * Xc; else V[i].Freeze.X = V[i].Pos.X = XM + LOIN * Xc; - if (pts[i][1]) + if(pts[i][1]) V[i].Freeze.Y = V[i].Pos.Y = Ym - LOIN * Yc; else V[i].Freeze.Y = V[i].Pos.Y = YM + LOIN * Yc; - + V[i].Freeze.Z = V[i].Pos.Z = 0.0; - + V[i].Num = -(++THEM->MaxPointNum); V[i].ListSurf = NULL; pv = &V[i]; pv->lc = 1.0; pv->Mov = NULL; - Tree_Replace (s->Vertices, &pv); + Tree_Replace(s->Vertices, &pv); } - + /* 2 Triangles forment le maillage de la boite */ - for (i = 0; i < 2; i++){ - S = Create_Simplex_For2dmesh (&V[tri[i][0] - 1], &V[tri[i][1] - 1], - &V[tri[i][2] - 1], NULL); - List_Add (smp, &S); + for(i = 0; i < 2; i++) { + S = Create_Simplex_For2dmesh(&V[tri[i][0] - 1], &V[tri[i][1] - 1], + &V[tri[i][2] - 1], NULL); + List_Add(smp, &S); S->iEnt = s->Num; } - - Link_Simplexes (smp, NULL); - for (i = 0; i < List_Nbr (smp); i++){ - List_Read (smp, i, &ps); - for (j = 0; j < 3; j++) - if (ps->S[j] == NULL) + + Link_Simplexes(smp, NULL); + for(i = 0; i < List_Nbr(smp); i++) { + List_Read(smp, i, &ps); + for(j = 0; j < 3; j++) + if(ps->S[j] == NULL) ps->S[j] = &MyNewBoundary; - Tree_Replace (s->Simplexes, &ps); + Tree_Replace(s->Simplexes, &ps); } List_Delete(smp); @@ -276,7 +281,8 @@ void Box_2_Triangles (List_T * P, Surface * s){ } -int Intersect_Edges_2d (Edge * a, Edge * b){ +int Intersect_Edges_2d(Edge * a, Edge * b) +{ double mat[2][2]; double rhs[2], x[2]; mat[0][0] = (a->V[1]->Pos.X - a->V[0]->Pos.X); @@ -285,134 +291,141 @@ int Intersect_Edges_2d (Edge * a, Edge * b){ mat[1][1] = -(b->V[1]->Pos.Y - b->V[0]->Pos.Y); rhs[0] = b->V[0]->Pos.X - a->V[0]->Pos.X; rhs[1] = b->V[0]->Pos.Y - a->V[0]->Pos.Y; - if (!sys2x2 (mat, rhs, x)) + if(!sys2x2(mat, rhs, x)) return 0; - if (x[0] > 0.0 && x[0] < 1.0 && x[1] > 0.0 && x[1] < 1.0) + if(x[0] > 0.0 && x[0] < 1.0 && x[1] > 0.0 && x[1] < 1.0) return 1; return 0; } -int compareedgeptr (const void *a, const void *b){ +int compareedgeptr(const void *a, const void *b) +{ int i1, i2, j1, j2; Edge *q, *w; q = *(Edge **) a; w = *(Edge **) b; - i1 = IMAX (q->V[0]->Num, q->V[1]->Num); - i2 = IMAX (w->V[0]->Num, w->V[1]->Num); - j1 = IMIN (q->V[0]->Num, q->V[1]->Num); - j2 = IMIN (w->V[0]->Num, w->V[1]->Num); + i1 = IMAX(q->V[0]->Num, q->V[1]->Num); + i2 = IMAX(w->V[0]->Num, w->V[1]->Num); + j1 = IMIN(q->V[0]->Num, q->V[1]->Num); + j2 = IMIN(w->V[0]->Num, w->V[1]->Num); - if (i1 < i2) + if(i1 < i2) return (1); - if (i1 > i2) + if(i1 > i2) return (-1); - if (j1 < j2) + if(j1 < j2) return (1); - if (j1 > j2) + if(j1 > j2) return (-1); return 0; } -void putaindecoquille_2D (void *a, void *b){ +void putaindecoquille_2D(void *a, void *b) +{ Edge *e = (Edge *) a; - if (!compareVertex (&e->V[0], &THEEDGE->V[0]) || - !compareVertex (&e->V[0], &THEEDGE->V[1]) || - !compareVertex (&e->V[1], &THEEDGE->V[0]) || - !compareVertex (&e->V[1], &THEEDGE->V[1])){ + if(!compareVertex(&e->V[0], &THEEDGE->V[0]) || + !compareVertex(&e->V[0], &THEEDGE->V[1]) || + !compareVertex(&e->V[1], &THEEDGE->V[0]) || + !compareVertex(&e->V[1], &THEEDGE->V[1])) { return; } - if (Intersect_Edges_2d (e, THEEDGE)) - List_Add (coquille, &e); + if(Intersect_Edges_2d(e, THEEDGE)) + List_Add(coquille, &e); } -void Recover_Edge (Surface * s, Edge * e, EdgesContainer & Edges){ +void Recover_Edge(Surface * s, Edge * e, EdgesContainer & Edges) +{ THEEDGE = e; int i; Edge *me, E; Vertex *v[2]; - coquille = List_Create (3, 3, sizeof (Edge *)); + coquille = List_Create(3, 3, sizeof(Edge *)); /*On cherche la coquille */ - Tree_Action (Edges.AllEdges, putaindecoquille_2D); - Msg(INFO, "Edge %d->%d, %d intersections", - e->V[0]->Num, e->V[1]->Num, List_Nbr (coquille)); + Tree_Action(Edges.AllEdges, putaindecoquille_2D); + Msg(INFO, "Edge %d->%d, %d intersections", + e->V[0]->Num, e->V[1]->Num, List_Nbr(coquille)); - if(List_Nbr(coquille)==1){ + if(List_Nbr(coquille) == 1) { Msg(WARNING, "Unable to swap edge"); - List_Delete (coquille); + List_Delete(coquille); return; } - + /*on swappe au hasard jusqu'a ce qu l'arete soit recuperee */ - while (List_Nbr(coquille)){ + while(List_Nbr(coquille)) { - i = (int) (List_Nbr(coquille)*rand()/(RAND_MAX+1.0)); + i = (int)(List_Nbr(coquille) * rand() / (RAND_MAX + 1.0)); //i = rand () % List_Nbr (coquille); - List_Read (coquille, i, &me); + List_Read(coquille, i, &me); v[0] = me->V[0]; v[1] = me->V[1]; - List_Suppress (coquille, &me, compareedgeptr); - Edges.SwapEdge (v); - if (Edges.Search (e->V[0], e->V[1])) + List_Suppress(coquille, &me, compareedgeptr); + Edges.SwapEdge(v); + if(Edges.Search(e->V[0], e->V[1])) break; E.V[0] = v[0]; E.V[1] = v[1]; - me = (Edge *) Tree_PQuery (Edges.AllEdges, &E); - putaindecoquille_2D (me, NULL); + me = (Edge *) Tree_PQuery(Edges.AllEdges, &E); + putaindecoquille_2D(me, NULL); } - List_Delete (coquille); + List_Delete(coquille); Msg(INFO, "Edge recovered"); /*On swappe */ } -void constraint_the_edge (int isurf, int iv1, int iv2){ - Vertex *v1 = FindVertex (iv1, THEM); - Vertex *v2 = FindVertex (iv2, THEM); - Surface *s = FindSurface (isurf, THEM); +void constraint_the_edge(int isurf, int iv1, int iv2) +{ + Vertex *v1 = FindVertex(iv1, THEM); + Vertex *v2 = FindVertex(iv2, THEM); + Surface *s = FindSurface(isurf, THEM); Edge e; - if (!v1 || !v2) + if(!v1 || !v2) return; - EdgesContainer EdgesOnSurface (s->Simplexes, false); + EdgesContainer EdgesOnSurface(s->Simplexes, false); e.V[0] = v1; e.V[1] = v2; - if (!EdgesOnSurface.Search (v1, v2)){ - Recover_Edge (s, &e, EdgesOnSurface); + if(!EdgesOnSurface.Search(v1, v2)) { + Recover_Edge(s, &e, EdgesOnSurface); } } -void missing_edges_2d (Surface * s){ +void missing_edges_2d(Surface * s) +{ int i, j; Curve *c; Vertex *v1, *v2; Edge e; - EdgesContainer EdgesOnSurface (s->Simplexes, false); + EdgesContainer EdgesOnSurface(s->Simplexes, false); - for (i = 0; i < List_Nbr (s->Generatrices); i++){ - List_Read (s->Generatrices, i, &c); - for (j = 1; j < List_Nbr (c->Vertices); j++){ - List_Read (c->Vertices, j - 1, &v1); - List_Read (c->Vertices, j, &v2); + for(i = 0; i < List_Nbr(s->Generatrices); i++) { + List_Read(s->Generatrices, i, &c); + for(j = 1; j < List_Nbr(c->Vertices); j++) { + List_Read(c->Vertices, j - 1, &v1); + List_Read(c->Vertices, j, &v2); e.V[0] = v1; e.V[1] = v2; - if (!EdgesOnSurface.Search (v1, v2)) { + if(!EdgesOnSurface.Search(v1, v2)) { Msg(INFO, "Missing edge %d->%d", v1->Num, v2->Num); - Recover_Edge (s, &e, EdgesOnSurface); + Recover_Edge(s, &e, EdgesOnSurface); } } } } -int Restore_Boundary (Surface * s){ - missing_edges_2d (s); +int Restore_Boundary(Surface * s) +{ + missing_edges_2d(s); return 1; } -int Maillage_Edge (Vertex * v1, Vertex * v2, List_T * Points){ +int Maillage_Edge(Vertex * v1, Vertex * v2, List_T * Points) +{ int i; static int qq = 1; Simplex S, *s; @@ -421,124 +434,132 @@ int Maillage_Edge (Vertex * v1, Vertex * v2, List_T * Points){ s->F[0].V[0] = v1; s->F[0].V[1] = v2; - if (Tree_Search (FacesTree, &s)) + if(Tree_Search(FacesTree, &s)) return 0; - s = Create_Simplex_For2dmesh (v1, v2, NULL, NULL); - Tree_Add (FacesTree, &s); + s = Create_Simplex_For2dmesh(v1, v2, NULL, NULL); + Tree_Add(FacesTree, &s); - Curve *c = Create_Curve (qq++, MSH_SEGM_LINE, 1, NULL, NULL, -1, -1, 0, 1); + Curve *c = Create_Curve(qq++, MSH_SEGM_LINE, 1, NULL, NULL, -1, -1, 0, 1); Vertex *v; - c->Control_Points = List_Create (2, 1, sizeof (Vertex *)); - List_Add (c->Control_Points, &v1); - List_Add (c->Control_Points, &v2); + c->Control_Points = List_Create(2, 1, sizeof(Vertex *)); + List_Add(c->Control_Points, &v1); + List_Add(c->Control_Points, &v2); c->beg = v1; c->end = v2; - Maillage_Curve (&c, NULL); - for (i = 1; i < List_Nbr (c->Vertices) - 1; i++){ - List_Read (c->Vertices, i, &v); - List_Delete (v->ListCurves); + Maillage_Curve(&c, NULL); + for(i = 1; i < List_Nbr(c->Vertices) - 1; i++) { + List_Read(c->Vertices, i, &v); + List_Delete(v->ListCurves); v->ListCurves = NULL; - List_Add (Points, &v); + List_Add(Points, &v); } - List_Delete (c->Vertices); - List_Delete (c->Control_Points); - Free_Curve (&c,0); + List_Delete(c->Vertices); + List_Delete(c->Control_Points); + Free_Curve(&c, 0); return 1; } -void Action_First_Simplexes_2D (void *a, void *b){ +void Action_First_Simplexes_2D(void *a, void *b) +{ Simplex *q; - if (!THES){ + if(!THES) { q = *(Simplex **) a; - if (q->Pt_In_Ellipse (THEV, THEM->Metric->m)){ + if(q->Pt_In_Ellipse(THEV, THEM->Metric->m)) { THES = q; } } } -void Fill_Sim_Des_2D (void *a, void *b){ +void Fill_Sim_Des_2D(void *a, void *b) +{ Simplex *S; S = *(Simplex **) a; - if (S->Pt_In_Ellipse (THEV, THEM->Metric->m)) - List_Add (Simplexes_Destroyed, a); + if(S->Pt_In_Ellipse(THEV, THEM->Metric->m)) + List_Add(Simplexes_Destroyed, a); } -void TStoLS_2D (void *a, void *b){ - List_Add (Simplexes_Destroyed, a); +void TStoLS_2D(void *a, void *b) +{ + List_Add(Simplexes_Destroyed, a); } -void TAtoLA_2D (void *a, void *b){ - List_Add (Simplexes_New, a); +void TAtoLA_2D(void *a, void *b) +{ + List_Add(Simplexes_New, a); } -void CrSi_2D (void *a, void *b){ +void CrSi_2D(void *a, void *b) +{ SxF *S; Simplex *s; S = (SxF *) a; - if (S->NumFaceSimpl == 1){ - s = Create_Simplex_For2dmesh (THEV, S->F.V[0], S->F.V[1], NULL); + if(S->NumFaceSimpl == 1) { + s = Create_Simplex_For2dmesh(THEV, S->F.V[0], S->F.V[1], NULL); s->iEnt = ZONEELIMINEE; - List_Add (Simplexes_New, &s); + List_Add(Simplexes_New, &s); } - else if (S->NumFaceSimpl != 2){ + else if(S->NumFaceSimpl != 2) { Msg(GERROR, "Panic in CrSi_2D..."); } } -void NewSimplexes_2D (Surface * s, List_T * Sim, List_T * news){ +void NewSimplexes_2D(Surface * s, List_T * Sim, List_T * news) +{ int i, j; Tree_T *SimXFac; Simplex *S; SxF SXF, *pSXF; - SimXFac = Tree_Create (sizeof (SxF), compareSxF); + SimXFac = Tree_Create(sizeof(SxF), compareSxF); - for (i = 0; i < List_Nbr (Sim); i++){ - List_Read (Sim, i, &S); - if (!i) + for(i = 0; i < List_Nbr(Sim); i++) { + List_Read(Sim, i, &S); + if(!i) ZONEELIMINEE = S->iEnt; - else{ - if (S->iEnt != ZONEELIMINEE){ + else { + if(S->iEnt != ZONEELIMINEE) { Msg(WARNING, "Huh! The elimination failed %d %d", S->iEnt, ZONEELIMINEE); } } - for (j = 0; j < 3; j++){ + for(j = 0; j < 3; j++) { SXF.F = S->F[j]; - - if ((pSXF = (SxF *) Tree_PQuery (SimXFac, &SXF))) { + + if((pSXF = (SxF *) Tree_PQuery(SimXFac, &SXF))) { (pSXF->NumFaceSimpl)++; } else { SXF.NumFaceSimpl = 1; - Tree_Add (SimXFac, &SXF); + Tree_Add(SimXFac, &SXF); } } } - + /* Les faces non communes sont obligatoirement a la frontiere ... -> Nouveaux simplexes */ - Tree_Action (SimXFac, CrSi_2D); - Tree_Delete (SimXFac); + Tree_Action(SimXFac, CrSi_2D); + Tree_Delete(SimXFac); } -int recur_bowyer_2D (Simplex * s){ +int recur_bowyer_2D(Simplex * s) +{ int i; - Tree_Insert (Tsd, &s); - for (i = 0; i < 3; i++){ - if (s->S[i] && s->S[i] != &MyNewBoundary && !Tree_Query (Tsd, &s->S[i])){ - if (s->S[i]->Pt_In_Ellipse (THEV, THEM->Metric->m) && (s->iEnt == s->S[i]->iEnt)){ - recur_bowyer_2D (s->S[i]); + Tree_Insert(Tsd, &s); + for(i = 0; i < 3; i++) { + if(s->S[i] && s->S[i] != &MyNewBoundary && !Tree_Query(Tsd, &s->S[i])) { + if(s->S[i]->Pt_In_Ellipse(THEV, THEM->Metric->m) + && (s->iEnt == s->S[i]->iEnt)) { + recur_bowyer_2D(s->S[i]); } - else{ - if (s->iEnt != s->S[i]->iEnt){ + else { + if(s->iEnt != s->S[i]->iEnt) { Alerte_Point_Scabreux = 1; } - Tree_Insert (Sim_Sur_Le_Bord, &s->S[i]); + Tree_Insert(Sim_Sur_Le_Bord, &s->S[i]); } } } @@ -546,19 +567,20 @@ int recur_bowyer_2D (Simplex * s){ } -bool draw_simplex2d (Surface * sur, Simplex * s, bool nouv){ +bool draw_simplex2d(Surface * sur, Simplex * s, bool nouv) +{ double x[3], y[3], z[3]; Vertex v1, v2, v3; - if (!THEM->MeshParams.InteractiveDelaunay) + if(!THEM->MeshParams.InteractiveDelaunay) return false; - if (s == &MyNewBoundary || !s || !s->iEnt) + if(s == &MyNewBoundary || !s || !s->iEnt) return false; - v1 = InterpolateSurface (sur->Support, s->V[0]->Pos.X, s->V[0]->Pos.Y, 0, 0); - v2 = InterpolateSurface (sur->Support, s->V[1]->Pos.X, s->V[1]->Pos.Y, 0, 0); - v3 = InterpolateSurface (sur->Support, s->V[2]->Pos.X, s->V[2]->Pos.Y, 0, 0); + v1 = InterpolateSurface(sur->Support, s->V[0]->Pos.X, s->V[0]->Pos.Y, 0, 0); + v2 = InterpolateSurface(sur->Support, s->V[1]->Pos.X, s->V[1]->Pos.Y, 0, 0); + v3 = InterpolateSurface(sur->Support, s->V[2]->Pos.X, s->V[2]->Pos.Y, 0, 0); x[0] = v1.Pos.X; x[1] = v2.Pos.X; @@ -571,18 +593,19 @@ bool draw_simplex2d (Surface * sur, Simplex * s, bool nouv){ z[2] = v3.Pos.Z; #if defined(HAVE_FLTK) - void draw_polygon_2d (double r, double g, double b, int n, - double *x, double *y, double *z); - if (nouv) - draw_polygon_2d (1., 0., 0., 3, x, y, z); + void draw_polygon_2d(double r, double g, double b, int n, + double *x, double *y, double *z); + if(nouv) + draw_polygon_2d(1., 0., 0., 3, x, y, z); else - draw_polygon_2d (0., 0., 0., 3, x, y, z); + draw_polygon_2d(0., 0., 0., 3, x, y, z); #endif return true; } -bool Bowyer_Watson_2D (Surface * sur, Vertex * v, Simplex * S, int force){ +bool Bowyer_Watson_2D(Surface * sur, Vertex * v, Simplex * S, int force) +{ int i; Simplex *s; static int init = 1; @@ -593,142 +616,154 @@ bool Bowyer_Watson_2D (Surface * sur, Vertex * v, Simplex * S, int force){ double x = (S->V[0]->Pos.X + S->V[1]->Pos.X + S->V[2]->Pos.X) / 3.; double y = (S->V[0]->Pos.Y + S->V[1]->Pos.Y + S->V[2]->Pos.Y) / 3.; - if (force) - THEM->Metric->setMetricMin (x, y, sur->Support); + if(force) + THEM->Metric->setMetricMin(x, y, sur->Support); else - THEM->Metric->setMetric (x, y, sur->Support); + THEM->Metric->setMetric(x, y, sur->Support); - Tsd = Tree_Create (sizeof (Simplex *), compareSimplex); - Sim_Sur_Le_Bord = Tree_Create (sizeof (Simplex *), compareSimplex); - if (init){ - Simplexes_New = List_Create (10, 10, sizeof (Simplex *)); - Simplexes_Destroyed = List_Create (10, 10, sizeof (Simplex *)); + Tsd = Tree_Create(sizeof(Simplex *), compareSimplex); + Sim_Sur_Le_Bord = Tree_Create(sizeof(Simplex *), compareSimplex); + if(init) { + Simplexes_New = List_Create(10, 10, sizeof(Simplex *)); + Simplexes_Destroyed = List_Create(10, 10, sizeof(Simplex *)); init = 0; } - if (Methode){ - Tree_Action (sur->Simplexes, Fill_Sim_Des_2D); + if(Methode) { + Tree_Action(sur->Simplexes, Fill_Sim_Des_2D); S = NULL; } - else{ - recur_bowyer_2D (S); + else { + recur_bowyer_2D(S); } - - Tree_Action (Tsd, TStoLS_2D); - NewSimplexes_2D (sur, Simplexes_Destroyed, Simplexes_New); + + Tree_Action(Tsd, TStoLS_2D); + NewSimplexes_2D(sur, Simplexes_Destroyed, Simplexes_New); /* calcul des volumes des simplexes crees */ - if (Alerte_Point_Scabreux || !CTX.mesh.speed_max){ + if(Alerte_Point_Scabreux || !CTX.mesh.speed_max) { volume = 0.0; - for (i = 0; i < List_Nbr (Simplexes_Destroyed); i++){ - VSIM_2D (List_Pointer (Simplexes_Destroyed, i), NULL); + for(i = 0; i < List_Nbr(Simplexes_Destroyed); i++) { + VSIM_2D(List_Pointer(Simplexes_Destroyed, i), NULL); } volumeold = volume; volume = 0.0; - for (i = 0; i < List_Nbr (Simplexes_New); i++){ - VSIM_2D (List_Pointer (Simplexes_New, i), NULL); + for(i = 0; i < List_Nbr(Simplexes_New); i++) { + VSIM_2D(List_Pointer(Simplexes_New, i), NULL); } volumenew = volume; - if (volumeold + volumenew == 0.0) + if(volumeold + volumenew == 0.0) volumenew = 1.0; } - else{ + else { volumeold = 1.0; volumenew = 1.0; } /* critere du volume */ - if ((fabs (volumeold - volumenew) / (volumeold + volumenew)) > 1.e-8){ - if (S){ - Tree_Suppress (sur->Simplexes, &S); + if((fabs(volumeold - volumenew) / (volumeold + volumenew)) > 1.e-8) { + if(S) { + Tree_Suppress(sur->Simplexes, &S); S->Quality /= 2.; - Tree_Add (sur->Simplexes, &S); + Tree_Add(sur->Simplexes, &S); } - if(force){ - List_Reset (Simplexes_New); - List_Reset (Simplexes_Destroyed); - Tree_Delete (Sim_Sur_Le_Bord); - Tree_Delete (Tsd); + if(force) { + List_Reset(Simplexes_New); + List_Reset(Simplexes_Destroyed); + Tree_Delete(Sim_Sur_Le_Bord); + Tree_Delete(Tsd); return false; } } - else{ - Tree_Add (sur->Vertices, &THEV); + else { + Tree_Add(sur->Vertices, &THEV); /* Suppression des simplexes elimines */ - for (i = 0; i < List_Nbr (Simplexes_Destroyed); i++){ - List_Read (Simplexes_Destroyed, i, &s); - draw_simplex2d (sur, s, 0); - if (!Tree_Suppress (sur->Simplexes, &s)){ + for(i = 0; i < List_Nbr(Simplexes_Destroyed); i++) { + List_Read(Simplexes_Destroyed, i, &s); + draw_simplex2d(sur, s, 0); + if(!Tree_Suppress(sur->Simplexes, &s)) { Msg(WARNING, "Failed to suppress simplex %d", s->Num); } - Free_Simplex (&s,0); + Free_Simplex(&s, 0); } - for (i = 0; i < List_Nbr (Simplexes_New); i++){ - List_Read (Simplexes_New, i, &s); - if(0 || !force) - { - double xc = s->Center.X; - double yc = s->Center.Y; - double rd = s->Radius; - cgsmpl (s,x,y); - THEM->Metric->setMetric (x, y, sur->Support); - THEM->Metric->setSimplexQuality (s, sur->Support); - s->Center.X = xc; - s->Center.Y = yc; - s->Radius = rd; - if(force)THEM->Metric->Identity(); - } - draw_simplex2d (sur, s, 1); - Tree_Add (sur->Simplexes, &s); + for(i = 0; i < List_Nbr(Simplexes_New); i++) { + List_Read(Simplexes_New, i, &s); + if(0 || !force) { + double xc = s->Center.X; + double yc = s->Center.Y; + double rd = s->Radius; + cgsmpl(s, x, y); + THEM->Metric->setMetric(x, y, sur->Support); + THEM->Metric->setSimplexQuality(s, sur->Support); + s->Center.X = xc; + s->Center.Y = yc; + s->Radius = rd; + if(force) + THEM->Metric->Identity(); + } + draw_simplex2d(sur, s, 1); + Tree_Add(sur->Simplexes, &s); } - + /* Creation des liens entre nouveaux simplexes */ - - Tree_Action (Sim_Sur_Le_Bord, TAtoLA_2D); - Link_Simplexes (Simplexes_New, sur->Simplexes); + + Tree_Action(Sim_Sur_Le_Bord, TAtoLA_2D); + Link_Simplexes(Simplexes_New, sur->Simplexes); } - - List_Reset (Simplexes_New); - List_Reset (Simplexes_Destroyed); - Tree_Delete (Sim_Sur_Le_Bord); - Tree_Delete (Tsd); + + List_Reset(Simplexes_New); + List_Reset(Simplexes_Destroyed); + Tree_Delete(Sim_Sur_Le_Bord); + Tree_Delete(Tsd); return true; } -void Convex_Hull_Mesh_2D (List_T * Points, Surface * s){ +void Convex_Hull_Mesh_2D(List_T * Points, Surface * s) +{ int i, N; - N = List_Nbr (Points); + N = List_Nbr(Points); - Box_2_Triangles (Points, s); - for (i = 0; i < N; i++){ + Box_2_Triangles(Points, s); + for(i = 0; i < N; i++) { THES = NULL; - List_Read (Points, i, &THEV); - Tree_Action (s->Simplexes, Action_First_Simplexes_2D); + List_Read(Points, i, &THEV); + Tree_Action(s->Simplexes, Action_First_Simplexes_2D); /* - if(i%n == n-1){ - volume = 0.0; - Tree_Action(s->Simplexes,VSIM_2D); - Msg(STATUS3, %d->%d Nodes, %d Elements",i+1,N,Tree_Nbr(s->Simplexes)); - } - */ - if (!THES){ - Msg(GERROR, "Vertex (%g,%g,%g) in no simplex", THEV->Pos.X, THEV->Pos.Y, THEV->Pos.Z); - THEV->Pos.X += CTX.mesh.rand_factor * LC2D * (1.-(double)rand()/(double)RAND_MAX); - THEV->Pos.Y += CTX.mesh.rand_factor * LC2D * (1.-(double)rand()/(double)RAND_MAX); - THEV->Pos.Z += CTX.mesh.rand_factor * LC2D * (1.-(double)rand()/(double)RAND_MAX); - Tree_Action (s->Simplexes, Action_First_Simplexes_2D); + if(i%n == n-1){ + volume = 0.0; + Tree_Action(s->Simplexes,VSIM_2D); + Msg(STATUS3, %d->%d Nodes, %d Elements",i+1,N,Tree_Nbr(s->Simplexes)); + } + */ + if(!THES) { + Msg(GERROR, "Vertex (%g,%g,%g) in no simplex", THEV->Pos.X, THEV->Pos.Y, + THEV->Pos.Z); + THEV->Pos.X += + CTX.mesh.rand_factor * LC2D * (1. - + (double)rand() / (double)RAND_MAX); + THEV->Pos.Y += + CTX.mesh.rand_factor * LC2D * (1. - + (double)rand() / (double)RAND_MAX); + THEV->Pos.Z += + CTX.mesh.rand_factor * LC2D * (1. - + (double)rand() / (double)RAND_MAX); + Tree_Action(s->Simplexes, Action_First_Simplexes_2D); } - bool ca_marche = Bowyer_Watson_2D (s, THEV, THES, 1); - while(!ca_marche){ - double dx = CTX.mesh.rand_factor * LC2D * (1.-(double)rand()/(double)RAND_MAX); - double dy = CTX.mesh.rand_factor * LC2D * (1.-(double)rand()/(double)RAND_MAX); + bool ca_marche = Bowyer_Watson_2D(s, THEV, THES, 1); + while(!ca_marche) { + double dx = + CTX.mesh.rand_factor * LC2D * (1. - + (double)rand() / (double)RAND_MAX); + double dy = + CTX.mesh.rand_factor * LC2D * (1. - + (double)rand() / (double)RAND_MAX); THEV->Pos.X += dx; THEV->Pos.Y += dy; - ca_marche = Bowyer_Watson_2D (s, THEV, THES, 1); + ca_marche = Bowyer_Watson_2D(s, THEV, THES, 1); THEV->Pos.X -= dx; THEV->Pos.Y -= dy; } @@ -743,57 +778,62 @@ static Tree_T *keep; static Simplex *SIMP; static int iSurface; -void attribueSurface (void *a, void *b){ +void attribueSurface(void *a, void *b) +{ Simplex *s; s = *(Simplex **) a; s->iEnt = iSurface; } -void Trouve_Simplex_2D (void *a, void *b){ +void Trouve_Simplex_2D(void *a, void *b) +{ Simplex *s; - if (SIMP != NULL) + if(SIMP != NULL) return; s = *(Simplex **) a; - if (s->iEnt < 0) + if(s->iEnt < 0) SIMP = s; } -void Trouve_Simplex_Bord_2D (void *a, void *b){ +void Trouve_Simplex_Bord_2D(void *a, void *b) +{ Simplex *s; - if (SIMP != NULL) + if(SIMP != NULL) return; s = *(Simplex **) a; - if (s->V[0]->Num < 0 || s->V[1]->Num < 0 || s->V[2]->Num < 0) + if(s->V[0]->Num < 0 || s->V[1]->Num < 0 || s->V[2]->Num < 0) SIMP = s; } -void CourbesDansSurface (Surface * s, List_T * ListAllCurves){ +void CourbesDansSurface(Surface * s, List_T * ListAllCurves) +{ int i, iseg; Curve *c; - for (i = 0; i < List_Nbr (s->Generatrices); i++){ - List_Read (s->Generatrices, i, &c); - iseg = abs (c->Num); - List_Replace (ListAllCurves, &iseg, fcmp_int); + for(i = 0; i < List_Nbr(s->Generatrices); i++) { + List_Read(s->Generatrices, i, &c); + iseg = abs(c->Num); + List_Replace(ListAllCurves, &iseg, fcmp_int); } } -int isListaSurface (List_T * ListSurf, Surface * s){ +int isListaSurface(List_T * ListSurf, Surface * s) +{ int NN, j, srf; bool found; Curve *c; NN = 0; found = true; - for (j = 0; j < List_Nbr (s->Generatrices); j++){ - List_Read (s->Generatrices, j, &c); - srf = abs (c->Num); - if (!List_Search (ListSurf, &srf, fcmp_int)){ + for(j = 0; j < List_Nbr(s->Generatrices); j++) { + List_Read(s->Generatrices, j, &c); + srf = abs(c->Num); + if(!List_Search(ListSurf, &srf, fcmp_int)) { found = false; } else NN++; } - if (found && NN == List_Nbr (ListSurf)) + if(found && NN == List_Nbr(ListSurf)) return s->Num; return 0; } @@ -801,119 +841,125 @@ int isListaSurface (List_T * ListSurf, Surface * s){ static List_T *StackSimp; #define MAX_DEPTH 500 -void recur_trouve_surface (Simplex * s, int *Depth){ +void recur_trouve_surface(Simplex * s, int *Depth) +{ int i, j; Simplex *pS, S; - if (s->iEnt != -1) + if(s->iEnt != -1) return; - if ((*Depth) > MAX_DEPTH){ - List_Add (StackSimp, &s); + if((*Depth) > MAX_DEPTH) { + List_Add(StackSimp, &s); return; } - + (*Depth)++; s->iEnt = -2; - Tree_Add (keep, &s); - for (i = 0; i < 3; i++){ + Tree_Add(keep, &s); + for(i = 0; i < 3; i++) { pS = &S; pS->F[0] = s->F[i]; - if (Tree_Query (FacesTree, &pS) && List_Search (ListAllCurves, &pS->iEnt, fcmp_int)){ - j = abs (pS->iEnt); - List_Replace (ListCurves, &j, fcmp_int); + if(Tree_Query(FacesTree, &pS) + && List_Search(ListAllCurves, &pS->iEnt, fcmp_int)) { + j = abs(pS->iEnt); + List_Replace(ListCurves, &j, fcmp_int); } - else if (s->S[i] && s->S[i] != &MyNewBoundary){ - recur_trouve_surface (s->S[i], Depth); + else if(s->S[i] && s->S[i] != &MyNewBoundary) { + recur_trouve_surface(s->S[i], Depth); } } (*Depth)--; } -extern int compareSimpSurf (const void *a, const void *b); +extern int compareSimpSurf(const void *a, const void *b); -void Restore_Surface (Surface * s){ +void Restore_Surface(Surface * s) +{ int N; int i, depth; - StackSimp = List_Create (100, 100, sizeof (Simplex *)); - ListCurves = List_Create (2, 2, sizeof (int)); + StackSimp = List_Create(100, 100, sizeof(Simplex *)); + ListCurves = List_Create(2, 2, sizeof(int)); iSurface = -1; - Tree_Action (s->Simplexes, attribueSurface); + Tree_Action(s->Simplexes, attribueSurface); /* Les simplexes sur le bord exterieur sont elimines */ - ListAllCurves = List_Create (10, 3, sizeof (int)); - CourbesDansSurface (s, ListAllCurves); + ListAllCurves = List_Create(10, 3, sizeof(int)); + CourbesDansSurface(s, ListAllCurves); SIMP = NULL; - Tree_Action (s->Simplexes, Trouve_Simplex_Bord_2D); + Tree_Action(s->Simplexes, Trouve_Simplex_Bord_2D); - if (SIMP){ - List_Add (StackSimp, &SIMP); - keep = Tree_Create (sizeof (Simplex *), compareQuality); + if(SIMP) { + List_Add(StackSimp, &SIMP); + keep = Tree_Create(sizeof(Simplex *), compareQuality); depth = 0; i = 0; - do{ - List_Read (StackSimp, i, &SIMP); - recur_trouve_surface (SIMP, &depth); + do { + List_Read(StackSimp, i, &SIMP); + recur_trouve_surface(SIMP, &depth); } - while (++i < List_Nbr (StackSimp)); - List_Reset (StackSimp); - - N = Tree_Nbr (keep); + while(++i < List_Nbr(StackSimp)); + List_Reset(StackSimp); + + N = Tree_Nbr(keep); iSurface = 0; - Tree_Action (keep, attribueSurface); - Tree_Delete (keep); - List_Reset (ListCurves); + Tree_Action(keep, attribueSurface); + Tree_Delete(keep); + List_Reset(ListCurves); } - while (1){ + while(1) { SIMP = NULL; - keep = Tree_Create (sizeof (Simplex *), compareQuality); - Tree_Action (s->Simplexes, Trouve_Simplex_2D); - if (!SIMP) + keep = Tree_Create(sizeof(Simplex *), compareQuality); + Tree_Action(s->Simplexes, Trouve_Simplex_2D); + if(!SIMP) break; - List_Add (StackSimp, &SIMP); + List_Add(StackSimp, &SIMP); depth = 0; i = 0; - do{ - List_Read (StackSimp, i, &SIMP); - recur_trouve_surface (SIMP, &depth); - }while (++i < List_Nbr (StackSimp)); - - iSurface = isListaSurface (ListCurves, s); - - N = Tree_Nbr (keep); - Msg(INFO, "Initial mesh of Surface %d: %d simplices, %d/%d curves, %d faces", - iSurface, N, List_Nbr (ListCurves), List_Nbr (ListAllCurves), - Tree_Nbr (FacesTree)); - - Tree_Action (keep, attribueSurface); - Tree_Delete (keep); - List_Reset (ListCurves); - List_Reset (StackSimp); + do { + List_Read(StackSimp, i, &SIMP); + recur_trouve_surface(SIMP, &depth); + } while(++i < List_Nbr(StackSimp)); + + iSurface = isListaSurface(ListCurves, s); + + N = Tree_Nbr(keep); + Msg(INFO, + "Initial mesh of Surface %d: %d simplices, %d/%d curves, %d faces", + iSurface, N, List_Nbr(ListCurves), List_Nbr(ListAllCurves), + Tree_Nbr(FacesTree)); + + Tree_Action(keep, attribueSurface); + Tree_Delete(keep); + List_Reset(ListCurves); + List_Reset(StackSimp); } // MEMORY LEAK (JF) - List_Delete (StackSimp); - List_Delete (ListCurves); - List_Delete (ListAllCurves); + List_Delete(StackSimp); + List_Delete(ListCurves); + List_Delete(ListAllCurves); } -void suppress_simplex_2D (void *data, void *dum){ +void suppress_simplex_2D(void *data, void *dum) +{ Simplex **pv; pv = (Simplex **) data; - if ((*pv)->iEnt == 0) - List_Add (Suppress, pv); + if((*pv)->iEnt == 0) + List_Add(Suppress, pv); } -Vertex * NewVertex_2D (Simplex * s){ - Vertex *v=NULL; +Vertex *NewVertex_2D(Simplex * s) +{ + Vertex *v = NULL; double lc; - lc = (s->V[0]->lc + s->V[1]->lc + s->V[2]->lc) / 3. ; + lc = (s->V[0]->lc + s->V[1]->lc + s->V[2]->lc) / 3.; //lc = DMIN(MAXIMUM_LC_FOR_SURFACE,lc); @@ -923,31 +969,36 @@ Vertex * NewVertex_2D (Simplex * s){ 0.0, lc, 0.0); */ - if (THEM->MeshParams.DelaunayInsertionMethod == INSERTION_CENTROID) - v = Create_Vertex (++THEM->MaxPointNum, s->Center.X, s->Center.Y, 0.0, lc, 0.0); - else if (THEM->MeshParams.DelaunayInsertionMethod == INSERTION_EDGE) { + if(THEM->MeshParams.DelaunayInsertionMethod == INSERTION_CENTROID) + v = + Create_Vertex(++THEM->MaxPointNum, s->Center.X, s->Center.Y, 0.0, lc, + 0.0); + else if(THEM->MeshParams.DelaunayInsertionMethod == INSERTION_EDGE) { Vertex *vv[2]; - double l = THEM->Metric->getWorstEdge (s, PARAMETRIC, vv); + double l = THEM->Metric->getWorstEdge(s, PARAMETRIC, vv); double f = 0.5; - - if (vv[0]->lc <= vv[1]->lc) + + if(vv[0]->lc <= vv[1]->lc) f = vv[0]->lc / l; else f = 1. - (vv[1]->lc / l); - - if (f >= 1) - v = Create_Vertex (++THEM->MaxPointNum, s->Center.X, s->Center.Y, 0.0, lc, 0.0); + + if(f >= 1) + v = + Create_Vertex(++THEM->MaxPointNum, s->Center.X, s->Center.Y, 0.0, lc, + 0.0); else - v = Create_Vertex (++THEM->MaxPointNum, - f * vv[0]->Pos.X + (1. - f) * vv[1]->Pos.X, - f * vv[0]->Pos.Y + (1. - f) * vv[1]->Pos.Y, 0.0, lc, 0.0); + v = Create_Vertex(++THEM->MaxPointNum, + f * vv[0]->Pos.X + (1. - f) * vv[1]->Pos.X, + f * vv[0]->Pos.Y + (1. - f) * vv[1]->Pos.Y, 0.0, lc, + 0.0); } - v->lc = Interpole_lcTriangle (s, v); + v->lc = Interpole_lcTriangle(s, v); - if (PARAMETRIC){ - if (!v->ListCurves) - Normal2Surface (PARAMETRIC->Support, v->Pos.X, v->Pos.Y, v->us); + if(PARAMETRIC) { + if(!v->ListCurves) + Normal2Surface(PARAMETRIC->Support, v->Pos.X, v->Pos.Y, v->us); else { v->us[0] = v->us[1] = v->us[2] = 0.0; } @@ -957,60 +1008,64 @@ Vertex * NewVertex_2D (Simplex * s){ extern Mesh *LOCAL; -void TRIE_MON_GARS (void *a, void *b){ +void TRIE_MON_GARS(void *a, void *b) +{ Simplex *s = *(Simplex **) a; - s->Fourre_Simplexe (s->V[0], s->V[1], s->V[2], s->V[3]); + s->Fourre_Simplexe(s->V[0], s->V[1], s->V[2], s->V[3]); s->iEnt = SURF->Num; s->S[0] = s->S[1] = s->S[2] = NULL; - THEM->Metric->setSimplexQuality (s, PARAMETRIC); + THEM->Metric->setSimplexQuality(s, PARAMETRIC); //SURF->Num; //qsort(s->F[0].V,3,sizeof(Vertex*),compareVertex); } -void RandomSwapEdges2d (Surface * s){ +void RandomSwapEdges2d(Surface * s) +{ int i, j = 1, k; - List_T *AllTrg = Tree2List (s->Simplexes); + List_T *AllTrg = Tree2List(s->Simplexes); Simplex *t; - for (i = 0; i < List_Nbr (AllTrg); i++){ - k = rand () % List_Nbr (AllTrg); - List_Read (AllTrg, k, &t); - j = rand () % 3; - if (draw_simplex2d (s, t, false)) - draw_simplex2d (s, t->S[j], false); - t->SwapEdge (j); - if (draw_simplex2d (s, t, true)) - draw_simplex2d (s, t->S[j], true); + for(i = 0; i < List_Nbr(AllTrg); i++) { + k = rand() % List_Nbr(AllTrg); + List_Read(AllTrg, k, &t); + j = rand() % 3; + if(draw_simplex2d(s, t, false)) + draw_simplex2d(s, t->S[j], false); + t->SwapEdge(j); + if(draw_simplex2d(s, t, true)) + draw_simplex2d(s, t->S[j], true); } } -void IntelligentSwapEdges (Surface * s, GMSHMetric * m){ +void IntelligentSwapEdges(Surface * s, GMSHMetric * m) +{ int i, j, k; - List_T *AllTrg = Tree2List (s->Simplexes); + List_T *AllTrg = Tree2List(s->Simplexes); Vertex *p[4], *q[4]; Simplex *t; - for (i = 0; i < List_Nbr (AllTrg); i++) { - k = rand () % List_Nbr (AllTrg); - List_Read (AllTrg, k, &t); - j = rand () % 3; - if (t->ExtractOppositeEdges (j, p, q)){ - double qp = 2. * m->EdgeLengthOnSurface (s, p, 1) + for(i = 0; i < List_Nbr(AllTrg); i++) { + k = rand() % List_Nbr(AllTrg); + List_Read(AllTrg, k, &t); + j = rand() % 3; + if(t->ExtractOppositeEdges(j, p, q)) { + double qp = 2. * m->EdgeLengthOnSurface(s, p, 1) / (RacineDeTrois * (p[0]->lc + p[1]->lc)); - double qq = 2. * m->EdgeLengthOnSurface (s, q, 1) + double qq = 2. * m->EdgeLengthOnSurface(s, q, 1) / (RacineDeTrois * (q[0]->lc + q[1]->lc)); - if (fabs (qp) > fabs (qq)){ - if (draw_simplex2d (s, t, false)) - draw_simplex2d (s, t->S[j], false); - t->SwapEdge (j); - if (draw_simplex2d (s, t, true)) - draw_simplex2d (s, t->S[j], true); + if(fabs(qp) > fabs(qq)) { + if(draw_simplex2d(s, t, false)) + draw_simplex2d(s, t->S[j], false); + t->SwapEdge(j); + if(draw_simplex2d(s, t, true)) + draw_simplex2d(s, t->S[j], true); } } } - List_Delete (AllTrg); + List_Delete(AllTrg); } -int AlgorithmeMaillage2DAnisotropeModeJF (Surface * s){ - List_T *Points = List_Create (100, 100, sizeof (Vertex *)); +int AlgorithmeMaillage2DAnisotropeModeJF(Surface * s) +{ + List_T *Points = List_Create(100, 100, sizeof(Vertex *)); int j, i, N, n; List_T *c; Curve *cur, *curinv; @@ -1024,109 +1079,114 @@ int AlgorithmeMaillage2DAnisotropeModeJF (Surface * s){ SURF = s; LOCAL = NULL; - if (s->Typ == MSH_SURF_PLAN || s->Typ == MSH_SURF_REGL || s->Typ == MSH_SURF_TRIC) + if(s->Typ == MSH_SURF_PLAN || s->Typ == MSH_SURF_REGL + || s->Typ == MSH_SURF_TRIC) PARAMETRIC = NULL; ZONEELIMINEE = s->Num; - for (i = 0; i < List_Nbr (s->Contours); i++){ - List_Read (s->Contours, i, &c); - for (j = 0; j < List_Nbr (c); j++){ + for(i = 0; i < List_Nbr(s->Contours); i++) { + List_Read(s->Contours, i, &c); + for(j = 0; j < List_Nbr(c); j++) { Vertex *pv; - List_Read (c, j, &pv); - List_Add (Points, &pv); + List_Read(c, j, &pv); + List_Add(Points, &pv); } } - - N = List_Nbr (Points); + + N = List_Nbr(Points); n = N + 100; Msg(STATUS2, "Mesh 2D... (initial)"); - Convex_Hull_Mesh_2D (Points, s); - List_Reset (Points); - Link_Simplexes (NULL, s->Simplexes); + Convex_Hull_Mesh_2D(Points, s); + List_Reset(Points); + Link_Simplexes(NULL, s->Simplexes); //return 1; - if (!Restore_Boundary (s)){ + if(!Restore_Boundary(s)) { //s->Simplexes = Tree_Create(sizeof(Simplex*),compareSimplex); FACE_DIMENSION = 2; - Tree_Action (s->Simplexes, TRIE_MON_GARS); + Tree_Action(s->Simplexes, TRIE_MON_GARS); return 1; } - Tree_Action (s->Simplexes, TRIE_MON_GARS); - Link_Simplexes (NULL, s->Simplexes); - List_T *List = Tree2List (s->Simplexes); - Tree_Delete (s->Simplexes); - s->Simplexes = Tree_Create (sizeof (Simplex *), compareQuality); - for (i = 0; i < List_Nbr (List); i++) - Tree_Add (s->Simplexes, List_Pointer (List, i)); - List_Delete (List); + Tree_Action(s->Simplexes, TRIE_MON_GARS); + Link_Simplexes(NULL, s->Simplexes); + List_T *List = Tree2List(s->Simplexes); + Tree_Delete(s->Simplexes); + s->Simplexes = Tree_Create(sizeof(Simplex *), compareQuality); + for(i = 0; i < List_Nbr(List); i++) + Tree_Add(s->Simplexes, List_Pointer(List, i)); + List_Delete(List); // return 1; - FacesTree = Tree_Create (sizeof (Simplex *), compareSimpSurf); - for (i = 0; i < List_Nbr (s->Generatrices); i++){ - List_Read (s->Generatrices, i, &cur); - curinv = FindCurve (abs (cur->Num), THEM); - List_T *temp = Tree2List (curinv->Simplexes); - for (j = 0; j < List_Nbr (temp); j++){ - Tree_Add (FacesTree, List_Pointer (temp, j)); + FacesTree = Tree_Create(sizeof(Simplex *), compareSimpSurf); + for(i = 0; i < List_Nbr(s->Generatrices); i++) { + List_Read(s->Generatrices, i, &cur); + curinv = FindCurve(abs(cur->Num), THEM); + List_T *temp = Tree2List(curinv->Simplexes); + for(j = 0; j < List_Nbr(temp); j++) { + Tree_Add(FacesTree, List_Pointer(temp, j)); } - List_Delete (temp); + List_Delete(temp); } - Restore_Surface (s); + Restore_Surface(s); // MEMORY LEAK (JF) Tree_Delete(FacesTree); - Suppress = List_Create (10, 10, sizeof (Simplex *)); - Tree_Action (s->Simplexes, suppress_simplex_2D); - for (i = 0; i < List_Nbr (Suppress); i++){ - Tree_Suppress (s->Simplexes, List_Pointer (Suppress, i)); + Suppress = List_Create(10, 10, sizeof(Simplex *)); + Tree_Action(s->Simplexes, suppress_simplex_2D); + for(i = 0; i < List_Nbr(Suppress); i++) { + Tree_Suppress(s->Simplexes, List_Pointer(Suppress, i)); } Msg(STATUS2, "Mesh 2D... (final)"); - if(!Tree_Right (s->Simplexes, &simp)) + if(!Tree_Right(s->Simplexes, &simp)) Msg(WARNING, "No simplex left"); - else{ + else { i = 0; - while ( simp->Quality > CONV_VALUE){ - newv = NewVertex_2D (simp); - while (!simp->Pt_In_Simplex_2D (newv) && - (simp->S[0] == &MyNewBoundary || !simp->S[0]->Pt_In_Simplex_2D (newv)) && - (simp->S[1] == &MyNewBoundary || !simp->S[1]->Pt_In_Simplex_2D (newv)) && - (simp->S[2] == &MyNewBoundary || !simp->S[2]->Pt_In_Simplex_2D (newv))){ + while(simp->Quality > CONV_VALUE) { + newv = NewVertex_2D(simp); + while(!simp->Pt_In_Simplex_2D(newv) && + (simp->S[0] == &MyNewBoundary + || !simp->S[0]->Pt_In_Simplex_2D(newv)) + && (simp->S[1] == &MyNewBoundary + || !simp->S[1]->Pt_In_Simplex_2D(newv)) + && (simp->S[2] == &MyNewBoundary + || !simp->S[2]->Pt_In_Simplex_2D(newv))) { /* - Msg(INFO,"pt : %12.5E %12.5E",newv->Pos.X,newv->Pos.Y); - Msg(INFO,"not in : (%12.5E %12.5E) (%12.5E %12.5E) (%12.5E %12.5E)", - simp->V[0]->Pos.X,simp->V[0]->Pos.Y,simp->V[1]->Pos.X, - simp->V[1]->Pos.Y,simp->V[2]->Pos.X,simp->V[2]->Pos.Y); - */ - Tree_Suppress (s->Simplexes, &simp); + Msg(INFO,"pt : %12.5E %12.5E",newv->Pos.X,newv->Pos.Y); + Msg(INFO,"not in : (%12.5E %12.5E) (%12.5E %12.5E) (%12.5E %12.5E)", + simp->V[0]->Pos.X,simp->V[0]->Pos.Y,simp->V[1]->Pos.X, + simp->V[1]->Pos.Y,simp->V[2]->Pos.X,simp->V[2]->Pos.Y); + */ + Tree_Suppress(s->Simplexes, &simp); simp->Quality /= 2.; - Tree_Insert (s->Simplexes, &simp); - Tree_Right (s->Simplexes, &simp); - if (simp->Quality < CONV_VALUE) + Tree_Insert(s->Simplexes, &simp); + Tree_Right(s->Simplexes, &simp); + if(simp->Quality < CONV_VALUE) break; - newv = NewVertex_2D (simp); + newv = NewVertex_2D(simp); } - if (simp->Quality < CONV_VALUE) + if(simp->Quality < CONV_VALUE) break; i++; - if (i % n == n - 1){ + if(i % n == n - 1) { volume = 0.0; - Tree_Action (s->Simplexes, VSIM_2D); + Tree_Action(s->Simplexes, VSIM_2D); Msg(STATUS3, "Nod=%d Elm=%d", - Tree_Nbr (s->Vertices), Tree_Nbr (s->Simplexes)); - Msg(STATUS1, "Vol(%g) Conv(%g->%g)", volume, simp->Quality, CONV_VALUE); + Tree_Nbr(s->Vertices), Tree_Nbr(s->Simplexes)); + Msg(STATUS1, "Vol(%g) Conv(%g->%g)", volume, simp->Quality, + CONV_VALUE); } - Bowyer_Watson_2D (s, newv, simp, 0); - Tree_Right (s->Simplexes, &simp); + Bowyer_Watson_2D(s, newv, simp, 0); + Tree_Right(s->Simplexes, &simp); //if(i>COUNT)break; } } @@ -1134,32 +1194,32 @@ int AlgorithmeMaillage2DAnisotropeModeJF (Surface * s){ //for(i=0;i<3;i++)RandomSwapEdges2d(s); //for(i=0;i<2;i++)IntelligentSwapEdges(s,THEM->Metric); - List_Reset (Points); + List_Reset(Points); FACE_DIMENSION = 2; COUNT++; - Tree_Action (s->Simplexes, TRIE_MON_GARS); - Link_Simplexes (NULL, s->Simplexes); - List = Tree2List (s->Simplexes); - Tree_Delete (s->Simplexes); - s->Simplexes = Tree_Create (sizeof (Simplex *), compareSimplex); - for (i = 0; i < List_Nbr (List); i++) - Tree_Add (s->Simplexes, List_Pointer (List, i)); - List_Delete (List); + Tree_Action(s->Simplexes, TRIE_MON_GARS); + Link_Simplexes(NULL, s->Simplexes); + List = Tree2List(s->Simplexes); + Tree_Delete(s->Simplexes); + s->Simplexes = Tree_Create(sizeof(Simplex *), compareSimplex); + for(i = 0; i < List_Nbr(List); i++) + Tree_Add(s->Simplexes, List_Pointer(List, i)); + List_Delete(List); /*suppression des points de la boite */ - List = Tree2List (s->Vertices); - for (i = 0; i < List_Nbr (List); i++){ - List_Read (List, i, &THEV); - if (THEV->Num < 0){ - Tree_Suppress (s->Vertices, &THEV); + List = Tree2List(s->Vertices); + for(i = 0; i < List_Nbr(List); i++) { + List_Read(List, i, &THEV); + if(THEV->Num < 0) { + Tree_Suppress(s->Vertices, &THEV); // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG // MEMORY LEAK (JF) BUT THIS CAUSES PROBLEMS AFTER !! // Free(THEV); // BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG BUG } } - List_Delete (List); + List_Delete(List); if(!Tree_Nbr(s->Simplexes)) Msg(GERROR, "No triangles in surface %d", s->Num); @@ -1170,16 +1230,15 @@ int AlgorithmeMaillage2DAnisotropeModeJF (Surface * s){ */ //IntelligentSwapEdges(s,THEM->Metric); - List_Delete (Points); + List_Delete(Points); // WAS A MEMORY LEAK - for (i = 0; i < List_Nbr (Suppress); i++){ - Free_Simplex(List_Pointer (Suppress, i),0); + for(i = 0; i < List_Nbr(Suppress); i++) { + Free_Simplex(List_Pointer(Suppress, i), 0); } - List_Delete (Suppress); - + List_Delete(Suppress); + return 1; } - diff --git a/Mesh/2D_Mesh_Triangle.cpp b/Mesh/2D_Mesh_Triangle.cpp index f57205731692f2b544ef62ffac87bc6614d2a542..fc87260d09b688252e3a70f4a7389732ee82c4f7 100644 --- a/Mesh/2D_Mesh_Triangle.cpp +++ b/Mesh/2D_Mesh_Triangle.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_Mesh_Triangle.cpp,v 1.1 2003-02-11 03:14:51 geuzaine Exp $ +// $Id: 2D_Mesh_Triangle.cpp,v 1.2 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -26,7 +26,8 @@ #if !defined(HAVE_TRIANGLE) -int Mesh_Shewchuk(Surface *s){ +int Mesh_Shewchuk(Surface * s) +{ Msg(GERROR, "Triangle is not compiled in this version of Gmsh"); return 1; } @@ -36,45 +37,50 @@ int Mesh_Shewchuk(Surface *s){ #define ANSI_DECLARATORS #define REAL double -extern "C" { +extern "C" +{ #include "triangle.h" } -extern Context_T CTX; -extern Mesh * THEM; +extern Context_T CTX; +extern Mesh *THEM; -void AddInMesh(Surface *sur, int nbbound, Vertex **vertexbound, - struct triangulateio *out){ +void AddInMesh(Surface * sur, int nbbound, Vertex ** vertexbound, + struct triangulateio *out) +{ int i; Vertex **vtable; Simplex *s; //Msg(INFO, "Add in database..."); - vtable = (Vertex**) Malloc(out->numberofpoints*sizeof(Vertex*)); + vtable = (Vertex **) Malloc(out->numberofpoints * sizeof(Vertex *)); - for (i = 0; i < nbbound; i++) vtable[i] = vertexbound[i]; + for(i = 0; i < nbbound; i++) + vtable[i] = vertexbound[i]; Free(vertexbound); - - for (i = nbbound; i < out->numberofpoints; i++) { - vtable[i] = Create_Vertex (++(THEM->MaxPointNum), - out->pointlist[i * 2], out->pointlist[i * 2 + 1], 0.0, - out->pointattributelist[i], 0.0); - Tree_Add (sur->Vertices, &vtable[i]); + + for(i = nbbound; i < out->numberofpoints; i++) { + vtable[i] = Create_Vertex(++(THEM->MaxPointNum), + out->pointlist[i * 2], + out->pointlist[i * 2 + 1], 0.0, + out->pointattributelist[i], 0.0); + Tree_Add(sur->Vertices, &vtable[i]); } Free(out->pointlist); Free(out->pointattributelist); - for (i = 0; i < out->numberoftriangles; i++) { - s = Create_Simplex(vtable[out->trianglelist[i * out->numberofcorners + 0]], - vtable[out->trianglelist[i * out->numberofcorners + 1]], - vtable[out->trianglelist[i * out->numberofcorners + 2]], - NULL); + for(i = 0; i < out->numberoftriangles; i++) { + s = + Create_Simplex(vtable[out->trianglelist[i * out->numberofcorners + 0]], + vtable[out->trianglelist[i * out->numberofcorners + 1]], + vtable[out->trianglelist[i * out->numberofcorners + 2]], + NULL); s->iEnt = sur->Num; - Tree_Add (sur->Simplexes, &s); + Tree_Add(sur->Simplexes, &s); } - + Free(vtable); Free(out->trianglelist); Free(out->triangleattributelist); @@ -84,82 +90,86 @@ void AddInMesh(Surface *sur, int nbbound, Vertex **vertexbound, // This is horrible... -void FindPointInHole(List_T* verts, REAL *x, REAL *y){ +void FindPointInHole(List_T * verts, REAL * x, REAL * y) +{ Vertex *v1, *v2; double a[3], b[3], c[3]; - List_Read (verts, 0, &v1); - List_Read (verts, 1, &v2); + List_Read(verts, 0, &v1); + List_Read(verts, 1, &v2); a[0] = v2->Pos.X - v1->Pos.X; a[1] = v2->Pos.Y - v1->Pos.Y; a[2] = 0.; b[0] = 0.; b[1] = 0.; b[2] = 1.; - prodve(b,a,c); + prodve(b, a, c); norme(c); - *x = 0.5*(v1->Pos.X + v2->Pos.X) + 1.e-12*CTX.lc * c[0]; - *y = 0.5*(v1->Pos.Y + v2->Pos.Y) + 1.e-12*CTX.lc * c[1]; + *x = 0.5 * (v1->Pos.X + v2->Pos.X) + 1.e-12 * CTX.lc * c[0]; + *y = 0.5 * (v1->Pos.Y + v2->Pos.Y) + 1.e-12 * CTX.lc * c[1]; } -int Mesh_Shewchuk(Surface *s){ +int Mesh_Shewchuk(Surface * s) +{ char opts[128]; - int i, j, k, l, NbPts=0, first; + int i, j, k, l, NbPts = 0, first; double val; List_T *list; Vertex *v, **vtable; struct triangulateio in, mid, out; - for (i = 0; i < List_Nbr (s->Contours); i++){ - List_Read (s->Contours, i, &list); + for(i = 0; i < List_Nbr(s->Contours); i++) { + List_Read(s->Contours, i, &list); NbPts += List_Nbr(list); } in.numberofpoints = NbPts; in.pointlist = (REAL *) Malloc(in.numberofpoints * 2 * sizeof(REAL)); - vtable = (Vertex**) Malloc(in.numberofpoints*sizeof(Vertex*)); + vtable = (Vertex **) Malloc(in.numberofpoints * sizeof(Vertex *)); in.numberofpointattributes = 1; in.pointattributelist = (REAL *) Malloc(in.numberofpoints * in.numberofpointattributes * sizeof(REAL)); - in.pointmarkerlist = NULL; + in.pointmarkerlist = NULL; in.numberofsegments = NbPts; - in.segmentlist = (int*)Malloc(in.numberofsegments * 2 * sizeof(int)); - in.segmentmarkerlist = (int *) Malloc(in.numberofsegments * sizeof(int)); + in.segmentlist = (int *)Malloc(in.numberofsegments * 2 * sizeof(int)); + in.segmentmarkerlist = (int *)Malloc(in.numberofsegments * sizeof(int)); in.numberofregions = 0; - in.regionlist = NULL; + in.regionlist = NULL; - k=0; l=0; - for (i = 0; i < List_Nbr(s->Contours); i++){ - List_Read (s->Contours, i, &list); + k = 0; + l = 0; + for(i = 0; i < List_Nbr(s->Contours); i++) { + List_Read(s->Contours, i, &list); first = l; - for (j = 0; j < List_Nbr(list); j++){ - List_Read (list, j, &v); + for(j = 0; j < List_Nbr(list); j++) { + List_Read(list, j, &v); in.pointlist[k] = v->Pos.X; - in.pointlist[k+1] = v->Pos.Y; + in.pointlist[k + 1] = v->Pos.Y; in.pointattributelist[l] = v->lc; vtable[l] = v; in.segmentlist[k] = l; - in.segmentlist[k+1] = (j==List_Nbr(list)-1)? (first) : (l+1); + in.segmentlist[k + 1] = (j == List_Nbr(list) - 1) ? (first) : (l + 1); in.segmentmarkerlist[l] = i; - k+=2; + k += 2; l++; } } - if(List_Nbr(s->Contours) > 1){ - in.numberofholes = List_Nbr(s->Contours)-1; + if(List_Nbr(s->Contours) > 1) { + in.numberofholes = List_Nbr(s->Contours) - 1; in.holelist = (REAL *) Malloc(in.numberofholes * 2 * sizeof(REAL)); - for(i = 1; i < List_Nbr(s->Contours); i++){ - List_Read (s->Contours, i, &list); - FindPointInHole(list, &in.holelist[(i-1)*2], &in.holelist[(i-1)*2+1]); + for(i = 1; i < List_Nbr(s->Contours); i++) { + List_Read(s->Contours, i, &list); + FindPointInHole(list, &in.holelist[(i - 1) * 2], + &in.holelist[(i - 1) * 2 + 1]); } } - else{ + else { in.numberofholes = 0; in.holelist = NULL; } - - mid.pointlist = NULL; + + mid.pointlist = NULL; mid.pointattributelist = NULL; mid.pointmarkerlist = NULL; mid.trianglelist = NULL; @@ -173,7 +183,8 @@ int Mesh_Shewchuk(Surface *s){ // triangulate the points with minimum angle > 20 deg, with no boundary breaking strcpy(opts, "pqzY"); - if(CTX.verbosity < 3) strcat(opts, "Q"); + if(CTX.verbosity < 3) + strcat(opts, "Q"); triangulate(opts, &in, &mid, NULL); Free(in.pointlist); @@ -184,29 +195,30 @@ int Mesh_Shewchuk(Surface *s){ Free(in.segmentmarkerlist); Free(in.holelist); - if(CTX.mesh.initial_only==2){ + if(CTX.mesh.initial_only == 2) { AddInMesh(s, NbPts, vtable, &mid); return 0; } #ifndef BGMESH - mid.trianglearealist = (REAL *) Malloc(mid.numberoftriangles * sizeof(REAL)); - for (i = 0; i < mid.numberoftriangles; i++) { + mid.trianglearealist = + (REAL *) Malloc(mid.numberoftriangles * sizeof(REAL)); + for(i = 0; i < mid.numberoftriangles; i++) { val = 0; - for (j = 0; j < mid.numberofcorners; j++) { + for(j = 0; j < mid.numberofcorners; j++) { k = mid.trianglelist[i * mid.numberofcorners + j]; val += mid.pointattributelist[k]; } val /= mid.numberofcorners; - val = val*val / 2. ; // we generate isotropic meshes + val = val * val / 2.; // we generate isotropic meshes mid.trianglearealist[i] = val; } #else - + Msg(FATAL, "Triangle is not ready to be used with a background mesh"); - + #endif out.pointlist = NULL; @@ -217,7 +229,8 @@ int Mesh_Shewchuk(Surface *s){ // refine the triangulation according to the triangle area constraints strcpy(opts, "praqzBPY"); - if(CTX.verbosity < 3) strcat(opts, "Q"); + if(CTX.verbosity < 3) + strcat(opts, "Q"); triangulate(opts, &mid, &out, NULL); // free all allocated arrays + those allocated by Triangle diff --git a/Mesh/2D_Parametric.cpp b/Mesh/2D_Parametric.cpp index 0cd7aa9a485d55144889c95cba3a9992ac3d8461..93f989590df8bd132bfc37b38053b386a5e813e4 100644 --- a/Mesh/2D_Parametric.cpp +++ b/Mesh/2D_Parametric.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_Parametric.cpp,v 1.11 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: 2D_Parametric.cpp,v 1.12 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -29,8 +29,8 @@ #include "Create.h" #include "Context.h" -extern Mesh *THEM; -extern Context_T CTX; +extern Mesh *THEM; +extern Context_T CTX; static Surface *SURF; @@ -38,62 +38,64 @@ Surface *PARAMETRIC; /* SURFACES CYLINDRIQUES */ -void XYZtoUV (void *a, void *dum){ +void XYZtoUV(void *a, void *dum) +{ Vertex *v; double uu, vv; v = *(Vertex **) a; - ProjectPointOnSurface (SURF->Support, v, &uu, &vv); + ProjectPointOnSurface(SURF->Support, v, &uu, &vv); v->Pos.X = uu; v->Pos.Y = vv; v->Pos.Z = 0.0; } -void UVtoXYZ (void *a, void *dum){ +void UVtoXYZ(void *a, void *dum) +{ Vertex *v, n; v = *(Vertex **) a; - n = InterpolateSurface (SURF->Support, v->Pos.X, v->Pos.Y, 0, 0); + n = InterpolateSurface(SURF->Support, v->Pos.X, v->Pos.Y, 0, 0); v->Pos.X = n.Pos.X; v->Pos.Y = n.Pos.Y; v->Pos.Z = n.Pos.Z; } -void printMetric (Mesh * m, Surface * s, char *name){ - +void printMetric(Mesh * m, Surface * s, char *name) +{ int N = 10, M = 10, i, j; double u, v; - FILE *f = fopen (name, "w"); - if (!f) + FILE *f = fopen(name, "w"); + if(!f) return; - fprintf (f, "View \"metric\" Offset{0,0,0} {\n"); - for (i = 0; i < N; i++){ - u = (s->ku[0]) + (s->ku[s->Nu + s->OrderU] - s->ku[0]) - * (double) i / (double) (N - 1); - for (j = 0; j < M; j++){ - v = (s->kv[0]) + (s->kv[s->Nv + s->OrderV] - s->kv[0]) - * (double) j / (double) (M - 1); - m->Metric->setMetric (u, v, s); - fprintf (f, "VT (%f,%f,0,%f,%f,0,%f,%f,0)" - "{%g,%g,%g,%g,%g,%g,%g,%g,%g};\n", - u, v, u, v, u, v, - m->Metric->m[0][0], m->Metric->m[0][1], 0.0, - m->Metric->m[0][0], m->Metric->m[0][1], 0.0, - m->Metric->m[0][0], m->Metric->m[0][1], 0.0); - fprintf (f, "VT (%f,%f,0,%f,%f,0,%f,%f,0)" - "{%g,%g,%g,%g,%g,%g,%g,%g,%g};\n", - u, v, u, v, u, v, - m->Metric->m[1][0], m->Metric->m[1][1], 0.0, - m->Metric->m[1][0], m->Metric->m[1][1], 0.0, - m->Metric->m[1][0], m->Metric->m[1][1], 0.0); + fprintf(f, "View \"metric\" Offset{0,0,0} {\n"); + for(i = 0; i < N; i++) { + u = (s->ku[0]) + (s->ku[s->Nu + s->OrderU] - s->ku[0]) + * (double)i / (double)(N - 1); + for(j = 0; j < M; j++) { + v = (s->kv[0]) + (s->kv[s->Nv + s->OrderV] - s->kv[0]) + * (double)j / (double)(M - 1); + m->Metric->setMetric(u, v, s); + fprintf(f, "VT (%f,%f,0,%f,%f,0,%f,%f,0)" + "{%g,%g,%g,%g,%g,%g,%g,%g,%g};\n", + u, v, u, v, u, v, + m->Metric->m[0][0], m->Metric->m[0][1], 0.0, + m->Metric->m[0][0], m->Metric->m[0][1], 0.0, + m->Metric->m[0][0], m->Metric->m[0][1], 0.0); + fprintf(f, "VT (%f,%f,0,%f,%f,0,%f,%f,0)" + "{%g,%g,%g,%g,%g,%g,%g,%g,%g};\n", + u, v, u, v, u, v, + m->Metric->m[1][0], m->Metric->m[1][1], 0.0, + m->Metric->m[1][0], m->Metric->m[1][1], 0.0, + m->Metric->m[1][0], m->Metric->m[1][1], 0.0); } } - fprintf (f, "};\n"); - fclose (f); + fprintf(f, "};\n"); + fclose(f); } -int MeshParametricSurface (Surface * s){ - +int MeshParametricSurface(Surface * s) +{ int i, j, ori; Curve *pC; Vertex *v; @@ -101,46 +103,46 @@ int MeshParametricSurface (Surface * s){ PARAMETRIC = s; - if (s->Typ == MSH_SURF_NURBS) + if(s->Typ == MSH_SURF_NURBS) return 1; - if (s->Typ != MSH_SURF_TRIMMED || s->Support->Typ != MSH_SURF_NURBS) + if(s->Typ != MSH_SURF_TRIMMED || s->Support->Typ != MSH_SURF_NURBS) return 0; SURF = s; - if (!List_Nbr (s->Generatrices)) + if(!List_Nbr(s->Generatrices)) return 1; - for (i = 0; i < List_Nbr (s->Generatrices); i++){ - List_Read (s->Generatrices, i, &pC); - for (j = 0; j < List_Nbr (pC->Vertices); j++){ - List_Read (pC->Vertices, j, &v); - Tree_Insert (s->Vertices, List_Pointer (pC->Vertices, j)); + for(i = 0; i < List_Nbr(s->Generatrices); i++) { + List_Read(s->Generatrices, i, &pC); + for(j = 0; j < List_Nbr(pC->Vertices); j++) { + List_Read(pC->Vertices, j, &v); + Tree_Insert(s->Vertices, List_Pointer(pC->Vertices, j)); } } //printMetric(THEM,s,"metric.pos"); - Tree_Action (s->Vertices, Freeze_Vertex); + Tree_Action(s->Vertices, Freeze_Vertex); + + Tree_Action(s->Vertices, XYZtoUV); + ori = Calcule_Contours(s); - Tree_Action (s->Vertices, XYZtoUV); - ori = Calcule_Contours (s); + if(!AlgorithmeMaillage2DAnisotropeModeJF(s)) + Maillage_Automatique_VieuxCode(s, THEM, ori); - if (!AlgorithmeMaillage2DAnisotropeModeJF (s)) - Maillage_Automatique_VieuxCode (s, THEM, ori); + if(CTX.mesh.nb_smoothing) { + tnxe = Tree_Create(sizeof(NXE), compareNXE); + create_NXE(s->Vertices, s->Simplexes, tnxe); + + for(i = 0; i < CTX.mesh.nb_smoothing; i++) + Tree_Action(tnxe, ActionLiss); - if (CTX.mesh.nb_smoothing){ - tnxe = Tree_Create (sizeof (NXE), compareNXE); - create_NXE (s->Vertices, s->Simplexes, tnxe); - - for(i = 0 ; i < CTX.mesh.nb_smoothing ; i++) - Tree_Action (tnxe, ActionLiss); - //AmelioreSurface_EliminationTripet (s, THEM, tnxe); - - Tree_Delete (tnxe); + + Tree_Delete(tnxe); } - Tree_Action (s->Vertices, UVtoXYZ); - Tree_Action (s->Vertices, deFreeze_Vertex); + Tree_Action(s->Vertices, UVtoXYZ); + Tree_Action(s->Vertices, deFreeze_Vertex); PARAMETRIC = NULL; diff --git a/Mesh/2D_Recombine.cpp b/Mesh/2D_Recombine.cpp index 5269f62bf769b172baff4c5b842ec8aeb3a4996f..a7ab0635e0da5354086f0cf8263eb23be6a7a492 100644 --- a/Mesh/2D_Recombine.cpp +++ b/Mesh/2D_Recombine.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_Recombine.cpp,v 1.14 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: 2D_Recombine.cpp,v 1.15 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -29,55 +29,65 @@ extern Context_T CTX; -static Tree_T *RecEdges,*Triangles; -static Tree_T *RecSimplex,*TREEELM; -static double ALPHA; -static int RECNUM; +static Tree_T *RecEdges, *Triangles; +static Tree_T *RecSimplex, *TREEELM; +static double ALPHA; +static int RECNUM; -void addTriangles(void *data, void *dum){ +void addTriangles(void *data, void *dum) +{ Simplex *S; - S = *(Simplex**)data; - if(S->V[2] && !S->V[3])Tree_Add(Triangles,&S); + S = *(Simplex **) data; + if(S->V[2] && !S->V[3]) + Tree_Add(Triangles, &S); } -void addrecedges (void *a, void *b){ +void addrecedges(void *a, void *b) +{ Edge *ed; - ed = (Edge*)a; - if(ed->a < ALPHA)Tree_Add(RecEdges,ed); + ed = (Edge *) a; + if(ed->a < ALPHA) + Tree_Add(RecEdges, ed); } -void CalculeAngles (void *a, void *b){ +void CalculeAngles(void *a, void *b) +{ Edge *ed; double Angle; - ed = (Edge*)a; - if(List_Nbr(ed->Simplexes) != 2){ + ed = (Edge *) a; + if(List_Nbr(ed->Simplexes) != 2) { ed->a = 90.; return; } - - Angle = fabs(90. - angle_3pts(ed->O[0],ed->V[0],ed->O[1])); - Angle = DMAX(fabs(90. - angle_3pts(ed->V[0],ed->O[1],ed->V[1])),Angle); - Angle = DMAX(fabs(90. - angle_3pts(ed->O[1],ed->V[1],ed->O[0])),Angle); - Angle = DMAX(fabs(90. - angle_3pts(ed->V[0],ed->O[0],ed->V[1])),Angle); + + Angle = fabs(90. - angle_3pts(ed->O[0], ed->V[0], ed->O[1])); + Angle = DMAX(fabs(90. - angle_3pts(ed->V[0], ed->O[1], ed->V[1])), Angle); + Angle = DMAX(fabs(90. - angle_3pts(ed->O[1], ed->V[1], ed->O[0])), Angle); + Angle = DMAX(fabs(90. - angle_3pts(ed->V[0], ed->O[0], ed->V[1])), Angle); ed->a = Angle; } -void Recombine_Farce (void *a, void *b){ +void Recombine_Farce(void *a, void *b) +{ Edge *ed; - Simplex *s1,*s2; - ed = (Edge*)a; - - if (ed->a < ALPHA){ - List_Read(ed->Simplexes,0,&s1); - List_Read(ed->Simplexes,1,&s2); - if(Tree_Search(RecSimplex,&s1)) return; - if(s1->V[3]) return; - if(Tree_Search(RecSimplex,&s2)) return; - if(s2->V[3]) return; - Tree_Add(RecSimplex,&s1); - Tree_Suppress(TREEELM,&s1); + Simplex *s1, *s2; + ed = (Edge *) a; + + if(ed->a < ALPHA) { + List_Read(ed->Simplexes, 0, &s1); + List_Read(ed->Simplexes, 1, &s2); + if(Tree_Search(RecSimplex, &s1)) + return; + if(s1->V[3]) + return; + if(Tree_Search(RecSimplex, &s2)) + return; + if(s2->V[3]) + return; + Tree_Add(RecSimplex, &s1); + Tree_Suppress(TREEELM, &s1); s2->V[3] = ed->V[0]; s2->V[2] = ed->O[0]; s2->V[1] = ed->V[1]; @@ -86,37 +96,38 @@ void Recombine_Farce (void *a, void *b){ } } -int Recombine (Tree_T *TreeAllVert, Tree_T *TreeAllElg, double a){ - Tree_T *TreeEdges,*tnxe; +int Recombine(Tree_T * TreeAllVert, Tree_T * TreeAllElg, double a) +{ + Tree_T *TreeEdges, *tnxe; int ntot; ALPHA = a; TREEELM = TreeAllElg; ntot = 0; - while(1){ + while(1) { /* Initialisation */ RECNUM = 0; - TreeEdges = Tree_Create(sizeof(Edge),compareedge); - RecEdges = Tree_Create(sizeof(Edge),compareedge_angle); - RecSimplex = Tree_Create(sizeof(Simplex*),compareSimplex); - Triangles = Tree_Create(sizeof(Simplex*),compareSimplex); + TreeEdges = Tree_Create(sizeof(Edge), compareedge); + RecEdges = Tree_Create(sizeof(Edge), compareedge_angle); + RecSimplex = Tree_Create(sizeof(Simplex *), compareSimplex); + Triangles = Tree_Create(sizeof(Simplex *), compareSimplex); /* Recombinaison */ - Tree_Action(TreeAllElg,addTriangles); - crEdges(Triangles,TreeEdges); - Tree_Action(TreeEdges,CalculeAngles); - Tree_Action(TreeEdges,addrecedges); - Tree_Action(RecEdges,Recombine_Farce); + Tree_Action(TreeAllElg, addTriangles); + crEdges(Triangles, TreeEdges); + Tree_Action(TreeEdges, CalculeAngles); + Tree_Action(TreeEdges, addrecedges); + Tree_Action(RecEdges, Recombine_Farce); /* Lissage */ - if(CTX.mesh.nb_smoothing){ + if(CTX.mesh.nb_smoothing) { Msg(STATUS3, "Mesh smoothing"); - tnxe = Tree_Create(sizeof(NXE),compareNXE); - create_NXE(TreeAllVert,TreeAllElg,tnxe); - for (int i = 0; i < CTX.mesh.nb_smoothing; i++) - Tree_Action(tnxe,ActionLissSurf); + tnxe = Tree_Create(sizeof(NXE), compareNXE); + create_NXE(TreeAllVert, TreeAllElg, tnxe); + for(int i = 0; i < CTX.mesh.nb_smoothing; i++) + Tree_Action(tnxe, ActionLissSurf); // MEMORY LEAK (JF) delete_NXE(tnxe); } @@ -129,14 +140,12 @@ int Recombine (Tree_T *TreeAllVert, Tree_T *TreeAllElg, double a){ /* Si aucune recombinaison -> fin */ ntot += RECNUM; - if(!RECNUM)break; + if(!RECNUM) + break; } - Msg(STATUS2, "Recombined %d Quadrangles",ntot); - - return ntot ; - -} - + Msg(STATUS2, "Recombined %d Quadrangles", ntot); + return ntot; +} diff --git a/Mesh/2D_SMesh.cpp b/Mesh/2D_SMesh.cpp index 4fcdf0eb00bc916ddb431833f5b4d7de103c7680..f480f1258b07efa14068ff96330d85f9ca86c16c 100644 --- a/Mesh/2D_SMesh.cpp +++ b/Mesh/2D_SMesh.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_SMesh.cpp,v 1.12 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: 2D_SMesh.cpp,v 1.13 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -45,33 +45,39 @@ #include "Numeric.h" #include "Interpolation.h" -extern Mesh *THEM; +extern Mesh *THEM; -int index1d (int flag, int N, int n){ - switch(flag){ - case 0 : return(n); - case 1 : return(N-n-1); - default : return -1; +int index1d(int flag, int N, int n) +{ + switch (flag) { + case 0: + return (n); + case 1: + return (N - n - 1); + default: + return -1; } } -int MeshTransfiniteSurface (Surface *sur) { - int i,j,k,flag,nb,N1,N2,issphere; - int nbquad=0,nbtri=0; - Curve *G[4],*GG[4]; - Vertex V,**vexist,*pV,*c1,*c2,**list,*CP[2]; - Simplex *simp; - double u,v; - int C_flag[4]; - Vertex *C[4],*S[4]; +int MeshTransfiniteSurface(Surface * sur) +{ + int i, j, k, flag, nb, N1, N2, issphere; + int nbquad = 0, nbtri = 0; + Curve *G[4], *GG[4]; + Vertex V, **vexist, *pV, *c1, *c2, **list, *CP[2]; + Simplex *simp; + double u, v; + int C_flag[4]; + Vertex *C[4], *S[4]; - static int tab1qua[] = {0,1, 1,2, 3,2, 0,3}; - static int tab1tri[] = {0,1, 1,2, 0,2}; - static int tab2[] = {0,1, 1,0}; + static int tab1qua[] = { 0, 1, 1, 2, 3, 2, 0, 3 }; + static int tab1tri[] = { 0, 1, 1, 2, 0, 2 }; + static int tab2[] = { 0, 1, 1, 0 }; - if (sur->Method != TRANSFINI) return(0); + if(sur->Method != TRANSFINI) + return (0); - switch(sur->Typ){ + switch (sur->Typ) { case MSH_SURF_REGL: case MSH_SURF_PLAN: @@ -79,221 +85,247 @@ int MeshTransfiniteSurface (Surface *sur) { case MSH_SURF_NURBS: nb = List_Nbr(sur->Generatrices); - if(nb != 3 && nb != 4) return(0); + if(nb != 3 && nb != 4) + return (0); - for(i=0;i<4;i++) G[i] = NULL ; + for(i = 0; i < 4; i++) + G[i] = NULL; - for(i=0;i<nb;i++){ + for(i = 0; i < nb; i++) { V.Num = sur->ipar[i]; pV = &V; - if((vexist = (Vertex**)Tree_PQuery(THEM->Vertices,&pV)) == NULL) { + if((vexist = (Vertex **) Tree_PQuery(THEM->Vertices, &pV)) == NULL) { Msg(WARNING, "Unknown Control Point %d in Transfinite Surface %d", - V.Num,sur->Num); - return(0); + V.Num, sur->Num); + return (0); } - else{ - S[i]=*vexist; + else { + S[i] = *vexist; } - } - - for(i=0;i<nb;i++) List_Read(sur->Generatrices,i,&GG[i]); - - for(i=0;i<nb;i++){ - List_Read(GG[i]->Control_Points,0,&CP[0]); - List_Read(GG[i]->Control_Points,List_Nbr(GG[i]->Control_Points)-1,&CP[1]); + } - for(flag=0;flag<2;flag++){ - for(k=0;k<nb;k++){ - if(nb == 4){ - if(S[tab1qua[2*k ]]->Num == CP[tab2[2*flag ]]->Num && - S[tab1qua[2*k+1]]->Num == CP[tab2[2*flag+1]]->Num){ - G[k]=GG[i]; - C_flag[k]=flag; + for(i = 0; i < nb; i++) + List_Read(sur->Generatrices, i, &GG[i]); + + for(i = 0; i < nb; i++) { + List_Read(GG[i]->Control_Points, 0, &CP[0]); + List_Read(GG[i]->Control_Points, List_Nbr(GG[i]->Control_Points) - 1, + &CP[1]); + + for(flag = 0; flag < 2; flag++) { + for(k = 0; k < nb; k++) { + if(nb == 4) { + if(S[tab1qua[2 * k]]->Num == CP[tab2[2 * flag]]->Num && + S[tab1qua[2 * k + 1]]->Num == CP[tab2[2 * flag + 1]]->Num) { + G[k] = GG[i]; + C_flag[k] = flag; } } - else{ - if(S[tab1tri[2*k ]]->Num == CP[tab2[2*flag ]]->Num && - S[tab1tri[2*k+1]]->Num == CP[tab2[2*flag+1]]->Num){ - G[k]=GG[i]; - C_flag[k]=flag; + else { + if(S[tab1tri[2 * k]]->Num == CP[tab2[2 * flag]]->Num && + S[tab1tri[2 * k + 1]]->Num == CP[tab2[2 * flag + 1]]->Num) { + G[k] = GG[i]; + C_flag[k] = flag; } } - } + } } } - for(i=0;i<nb;i++) + for(i = 0; i < nb; i++) if(G[i] == NULL) { - Msg(WARNING, "Wrong definition of Transfinite Surface %d", - sur->Num); - return(0); + Msg(WARNING, "Wrong definition of Transfinite Surface %d", sur->Num); + return (0); } if(nb == 4) { - if((N1 = List_Nbr(G[0]->Vertices)) != List_Nbr(G[2]->Vertices)) return(0); - if((N2 = List_Nbr(G[1]->Vertices)) != List_Nbr(G[3]->Vertices)) return(0); + if((N1 = List_Nbr(G[0]->Vertices)) != List_Nbr(G[2]->Vertices)) + return (0); + if((N2 = List_Nbr(G[1]->Vertices)) != List_Nbr(G[3]->Vertices)) + return (0); } else { - if((N1 = List_Nbr(G[0]->Vertices)) != List_Nbr(G[2]->Vertices)) return(0); - N2 = List_Nbr(G[1]->Vertices); + if((N1 = List_Nbr(G[0]->Vertices)) != List_Nbr(G[2]->Vertices)) + return (0); + N2 = List_Nbr(G[1]->Vertices); } sur->Nu = N1; sur->Nv = N2; - list = (Vertex**)Malloc(N1*N2*sizeof(Vertex*)); + list = (Vertex **) Malloc(N1 * N2 * sizeof(Vertex *)); issphere = 1; - for(i=0;i<nb;i++){ - if(G[i]->Typ != MSH_SEGM_CIRC && G[i]->Typ != MSH_SEGM_CIRC_INV){ + for(i = 0; i < nb; i++) { + if(G[i]->Typ != MSH_SEGM_CIRC && G[i]->Typ != MSH_SEGM_CIRC_INV) { issphere = 0; } - else if (issphere){ - if(!i){ + else if(issphere) { + if(!i) { List_Read(G[i]->Control_Points, 1, &c1); } - else{ + else { List_Read(G[i]->Control_Points, 1, &c2); - if(compareVertex(&c1,&c2))issphere = 0; + if(compareVertex(&c1, &c2)) + issphere = 0; } } } - - for(i=0;i<N1;i++){ - List_Read(G[0]->Vertices, index1d(C_flag[0],N1,i), &C[0]); - List_Read(G[2]->Vertices, index1d(C_flag[2],N1,i), &C[2]); - if( (G[0]->Num>0 && C_flag[0]) || (G[0]->Num<0 && !C_flag[0]) ) - u = 1.-C[0]->u; + for(i = 0; i < N1; i++) { + List_Read(G[0]->Vertices, index1d(C_flag[0], N1, i), &C[0]); + List_Read(G[2]->Vertices, index1d(C_flag[2], N1, i), &C[2]); + + if((G[0]->Num > 0 && C_flag[0]) || (G[0]->Num < 0 && !C_flag[0])) + u = 1. - C[0]->u; else u = C[0]->u; - for(j=0;j<N2;j++){ - List_Read(G[1]->Vertices, index1d(C_flag[1],N2,j), &C[1]); - if(nb == 4) - List_Read(G[3]->Vertices, index1d(C_flag[3],N2,j), &C[3]); + for(j = 0; j < N2; j++) { + List_Read(G[1]->Vertices, index1d(C_flag[1], N2, j), &C[1]); + if(nb == 4) + List_Read(G[3]->Vertices, index1d(C_flag[3], N2, j), &C[3]); - if( (G[1]->Num>0 && C_flag[1]) || (G[1]->Num<0 && !C_flag[1]) ) - v = 1.-C[1]->u; + if((G[1]->Num > 0 && C_flag[1]) || (G[1]->Num < 0 && !C_flag[1])) + v = 1. - C[1]->u; else v = C[1]->u; - if(i && j && i != N1-1 && j != N2-1){ - if (sur->Typ == MSH_SURF_NURBS) - V = InterpolateSurface (sur, u, v, 0, 0); - else if(nb == 4) - V = TransfiniteQua(*C[0],*C[1],*C[2],*C[3],*S[0],*S[1],*S[2],*S[3],u,v); + if(i && j && i != N1 - 1 && j != N2 - 1) { + if(sur->Typ == MSH_SURF_NURBS) + V = InterpolateSurface(sur, u, v, 0, 0); + else if(nb == 4) + V = + TransfiniteQua(*C[0], *C[1], *C[2], *C[3], *S[0], *S[1], *S[2], + *S[3], u, v); else - V = TransfiniteTri(*C[0],*C[1],*C[2],*S[0],*S[1],*S[2],u,v); - if(issphere) - TransfiniteSph(*C[0],*c1,&V); - list[i+N1*j] = Create_Vertex(++THEM->MaxPointNum,V.Pos.X,V.Pos.Y,V.Pos.Z,V.lc,0.0); + V = + TransfiniteTri(*C[0], *C[1], *C[2], *S[0], *S[1], *S[2], u, v); + if(issphere) + TransfiniteSph(*C[0], *c1, &V); + list[i + N1 * j] = + Create_Vertex(++THEM->MaxPointNum, V.Pos.X, V.Pos.Y, V.Pos.Z, + V.lc, 0.0); } - else if(!i) - list[i+N1*j] = (nb == 4)?C[3]:C[2]; - else if(!j) - list[i+N1*j] = C[0]; - else if(i == N1-1) - list[i+N1*j] = C[1]; - else if(j == N2-1) - list[i+N1*j] = C[2]; - + else if(!i) + list[i + N1 * j] = (nb == 4) ? C[3] : C[2]; + else if(!j) + list[i + N1 * j] = C[0]; + else if(i == N1 - 1) + list[i + N1 * j] = C[1]; + else if(j == N2 - 1) + list[i + N1 * j] = C[2]; + list[i + N1 * j]->us[0] = u; list[i + N1 * j]->us[1] = v; } } - for(i=0;i<N1;i++){ - for(j=0;j<N2;j++){ - List_Add(sur->TrsfVertices,&list[i+N1*j]); + for(i = 0; i < N1; i++) { + for(j = 0; j < N2; j++) { + List_Add(sur->TrsfVertices, &list[i + N1 * j]); } } - if(nb == 4){ - for(i=0;i<N1;i++){ - for(j=0;j<N2;j++){ - Tree_Replace(sur->Vertices,&list[i+N1*j]); + if(nb == 4) { + for(i = 0; i < N1; i++) { + for(j = 0; j < N2; j++) { + Tree_Replace(sur->Vertices, &list[i + N1 * j]); } - } - for(i=0;i<N1-1;i++){ - for(j=0;j<N2-1;j++){ - if(sur->Recombine){ - simp = Create_Quadrangle(list[(i) + N1*(j)], list[(i+1)+ N1*(j)], - list[(i+1)+ N1*(j+1)], list[(i)+ N1*(j+1)]); + } + for(i = 0; i < N1 - 1; i++) { + for(j = 0; j < N2 - 1; j++) { + if(sur->Recombine) { + simp = + Create_Quadrangle(list[(i) + N1 * (j)], + list[(i + 1) + N1 * (j)], + list[(i + 1) + N1 * (j + 1)], + list[(i) + N1 * (j + 1)]); simp->iEnt = sur->Num; - Tree_Add(sur->Simplexes,&simp); - List_Add(sur->TrsfSimplexes,&simp); + Tree_Add(sur->Simplexes, &simp); + List_Add(sur->TrsfSimplexes, &simp); nbquad++; } - else{ - simp = Create_Simplex(list[(i) + N1*(j)], list[(i+1) + N1*(j)], - list[(i) + N1*(j+1)], NULL); + else { + simp = + Create_Simplex(list[(i) + N1 * (j)], list[(i + 1) + N1 * (j)], + list[(i) + N1 * (j + 1)], NULL); simp->iEnt = sur->Num; - Tree_Add(sur->Simplexes,&simp); - List_Add(sur->TrsfSimplexes,&simp); + Tree_Add(sur->Simplexes, &simp); + List_Add(sur->TrsfSimplexes, &simp); - simp = Create_Simplex(list[(i+1) + N1*(j+1)], list[(i) + N1*(j+1)], - list[(i+1) + N1*(j)], NULL); + simp = + Create_Simplex(list[(i + 1) + N1 * (j + 1)], + list[(i) + N1 * (j + 1)], + list[(i + 1) + N1 * (j)], NULL); simp->iEnt = sur->Num; - Tree_Add(sur->Simplexes,&simp); - List_Add(sur->TrsfSimplexes,&simp); + Tree_Add(sur->Simplexes, &simp); + List_Add(sur->TrsfSimplexes, &simp); nbtri += 2; } } - } + } } else if(nb == 3) { - Tree_Replace(sur->Vertices,&list[0]); - for(i=1;i<N1;i++){ - for(j=0;j<N2;j++){ - Tree_Replace(sur->Vertices,&list[i+N1*j]); + Tree_Replace(sur->Vertices, &list[0]); + for(i = 1; i < N1; i++) { + for(j = 0; j < N2; j++) { + Tree_Replace(sur->Vertices, &list[i + N1 * j]); } - } - for(j=0;j<N2-1;j++){ - simp = Create_Simplex(list[1 + N1*(j+1)], list[N1*(j+1)],list[1 + N1*(j)],NULL); + } + for(j = 0; j < N2 - 1; j++) { + simp = + Create_Simplex(list[1 + N1 * (j + 1)], list[N1 * (j + 1)], + list[1 + N1 * (j)], NULL); simp->iEnt = sur->Num; - Tree_Add(sur->Simplexes,&simp); - List_Add(sur->TrsfSimplexes,&simp); + Tree_Add(sur->Simplexes, &simp); + List_Add(sur->TrsfSimplexes, &simp); nbtri++; - } - for(i=1;i<N1-1;i++){ - for(j=0;j<N2-1;j++){ - if(sur->Recombine){ - simp = Create_Quadrangle(list[(i) + N1*(j)],list[(i+1) + N1*(j)], - list[(i+1) + N1*(j+1)],list[i+N1*(j+1)]); + } + for(i = 1; i < N1 - 1; i++) { + for(j = 0; j < N2 - 1; j++) { + if(sur->Recombine) { + simp = + Create_Quadrangle(list[(i) + N1 * (j)], + list[(i + 1) + N1 * (j)], + list[(i + 1) + N1 * (j + 1)], + list[i + N1 * (j + 1)]); simp->iEnt = sur->Num; - Tree_Add(sur->Simplexes,&simp); - List_Add(sur->TrsfSimplexes,&simp); + Tree_Add(sur->Simplexes, &simp); + List_Add(sur->TrsfSimplexes, &simp); nbquad++; } - else{ - simp = Create_Simplex(list[(i) + N1*(j)], list[(i+1) + N1*(j)], - list[(i) + N1*(j+1)],NULL); + else { + simp = + Create_Simplex(list[(i) + N1 * (j)], list[(i + 1) + N1 * (j)], + list[(i) + N1 * (j + 1)], NULL); simp->iEnt = sur->Num; - Tree_Add(sur->Simplexes,&simp); - List_Add(sur->TrsfSimplexes,&simp); + Tree_Add(sur->Simplexes, &simp); + List_Add(sur->TrsfSimplexes, &simp); - simp = Create_Simplex(list[(i+1) + N1*(j+1)], list[(i) + N1*(j+1)], - list[(i+1) + N1*(j)], NULL); + simp = + Create_Simplex(list[(i + 1) + N1 * (j + 1)], + list[(i) + N1 * (j + 1)], + list[(i + 1) + N1 * (j)], NULL); simp->iEnt = sur->Num; - Tree_Add(sur->Simplexes,&simp); - List_Add(sur->TrsfSimplexes,&simp); + Tree_Add(sur->Simplexes, &simp); + List_Add(sur->TrsfSimplexes, &simp); nbtri += 2; } } - } - + } + } break; - + default: - return(0); - } + return (0); + } Free(list); @@ -301,6 +333,5 @@ int MeshTransfiniteSurface (Surface *sur) { // between triangles and quadrangles later THEM->Statistics[8] += nbquad; - return(1); + return (1); } - diff --git a/Mesh/2D_Tree.cpp b/Mesh/2D_Tree.cpp index af28eb9e1a7ac9f8f3e4fa4025a520e9fecd84be..10bdcbd55fd460fdfacba263de9f07a788b3604b 100644 --- a/Mesh/2D_Tree.cpp +++ b/Mesh/2D_Tree.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_Tree.cpp,v 1.8 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: 2D_Tree.cpp,v 1.9 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -25,132 +25,132 @@ /* BOUSILLE L'ARBRE TOTALEMENT (pas les donnees mais les liens) */ -int avltree_remove (avlstruct **root){ - int delete_this_node = 0; +int avltree_remove(avlstruct ** root) +{ + int delete_this_node = 0; - if(*root == NULL) return(1); - - if (((*root)->left == NULL) && ((*root)->right == NULL)) + if(*root == NULL) + return (1); + + if(((*root)->left == NULL) && ((*root)->right == NULL)) delete_this_node = 1; - else - { - if ((*root)->left == NULL) - if (avltree_remove(&(*root)->left)) - { - Free((*root)->left); - (*root)->left = NULL; - } - if ((*root)->right == NULL) - if (avltree_remove(&(*root)->right)) - { - Free((*root)->right); - (*root)->right = NULL; - } - if (((*root)->left == NULL) && ((*root)->right == NULL)) - delete_this_node = 1; - } + else { + if((*root)->left == NULL) + if(avltree_remove(&(*root)->left)) { + Free((*root)->left); + (*root)->left = NULL; + } + if((*root)->right == NULL) + if(avltree_remove(&(*root)->right)) { + Free((*root)->right); + (*root)->right = NULL; + } + if(((*root)->left == NULL) && ((*root)->right == NULL)) + delete_this_node = 1; + } return delete_this_node; } /* INSERE UN NOEUD */ -int avltree_insert (avlstruct **root, void *item, - int (*fcmp)(void *a, void *b)){ +int avltree_insert(avlstruct ** root, void *item, + int (*fcmp) (void *a, void *b)) +{ int cmpresult; if(*root != NULL) - cmpresult = fcmp(item,(*root)->treedata); + cmpresult = fcmp(item, (*root)->treedata); - if (*root == NULL){ - *root = (avlstruct *) Malloc (sizeof(avlstruct)); + if(*root == NULL) { + *root = (avlstruct *) Malloc(sizeof(avlstruct)); (*root)->treedata = item; (*root)->left = NULL; (*root)->right = NULL; } - else if (cmpresult < 0) - avltree_insert(&(*root)->left,item,fcmp); + else if(cmpresult < 0) + avltree_insert(&(*root)->left, item, fcmp); else - avltree_insert(&(*root)->right,item,fcmp); - return(1); + avltree_insert(&(*root)->right, item, fcmp); + return (1); } /* EFFACE UN NOEUD */ -int avltree_delete (avlstruct **root, void *item, - int (*fcmp)(void *a, void *b)){ +int avltree_delete(avlstruct ** root, void *item, + int (*fcmp) (void *a, void *b)) +{ + avlstruct *t1, *t12; + int cmpresult; - avlstruct *t1,*t12; - int cmpresult; + if(*root != NULL) + cmpresult = fcmp(item, (*root)->treedata); - if(*root != NULL) - cmpresult = fcmp(item , (*root)->treedata); - - if (*root == NULL) { - return(1); + if(*root == NULL) { + return (1); + } + if(cmpresult < 0) { + return (avltree_delete(&(*root)->left, item, fcmp)); } - if (cmpresult < 0){ - return(avltree_delete(&(*root)->left,item,fcmp)); - } - else if (cmpresult > 0){ - return(avltree_delete(&(*root)->right,item,fcmp)); + else if(cmpresult > 0) { + return (avltree_delete(&(*root)->right, item, fcmp)); } - else if ((cmpresult == 0)) { - if (((*root)->right == NULL) && (&(*root)->left == NULL)){ + else if((cmpresult == 0)) { + if(((*root)->right == NULL) && (&(*root)->left == NULL)) { Free(*root); - return(1); + return (1); } - else if((*root)->right == NULL){ + else if((*root)->right == NULL) { t1 = (*root)->left; Free(*root); *root = t1; - return(1); + return (1); } - else if ((*root)->left == NULL){ + else if((*root)->left == NULL) { t1 = (*root)->right; Free(*root); *root = t1; - return(1); + return (1); } - else{ + else { t1 = t12 = (*root)->right; while(t12->left != NULL) t12 = t12->left; t12->left = (*root)->left; Free(*root); *root = t1; - return(1); + return (1); } } - else{ - return(avltree_delete(&(*root)->left,item,fcmp)); + else { + return (avltree_delete(&(*root)->left, item, fcmp)); } } /* compte le nombre d'elements d'un arbre */ -void avltree_count (avlptr root, int *numtri){ +void avltree_count(avlptr root, int *numtri) +{ + if(root != NULL) { + avltree_count(root->left, numtri); - if(root != NULL){ - avltree_count(root->left,numtri); - - (*numtri)++; - - avltree_count(root->right,numtri); + (*numtri)++; + + avltree_count(root->right, numtri); } } /* deroule l'arbre dans un vecteur */ -void avltree_print (avlptr root, Delaunay **listdel, int *numtri){ - if(root != NULL){ - avltree_print(root->left,listdel,numtri); - listdel[(*numtri)++] = (Delaunay*)(root)->treedata; - avltree_print(root->right,listdel,numtri); +void avltree_print(avlptr root, Delaunay ** listdel, int *numtri) +{ + if(root != NULL) { + avltree_print(root->left, listdel, numtri); + listdel[(*numtri)++] = (Delaunay *) (root)->treedata; + avltree_print(root->right, listdel, numtri); } } - diff --git a/Mesh/2D_Util.cpp b/Mesh/2D_Util.cpp index 8ec709834d143dd7abd7f90c0b7157374e4e462e..98f6cbe08d3d7108397e10a48be862b0bbfa1780 100644 --- a/Mesh/2D_Util.cpp +++ b/Mesh/2D_Util.cpp @@ -1,4 +1,4 @@ -// $Id: 2D_Util.cpp,v 1.18 2003-02-25 04:02:51 geuzaine Exp $ +// $Id: 2D_Util.cpp,v 1.19 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -25,63 +25,69 @@ #include "2D_Mesh.h" #include "Context.h" -extern Context_T CTX; -extern int LocalNewPoint; -extern PointRecord *gPointArray; -extern Mesh *THEM; +extern Context_T CTX; +extern int LocalNewPoint; +extern PointRecord *gPointArray; +extern Mesh *THEM; -int Comparekey(void * d1,void * d2){ +int Comparekey(void *d1, void *d2) +{ + double val; + PointNumero a, b, c, aa, bb, cc; - double val ; - PointNumero a,b,c,aa,bb,cc; + a = ((Delaunay *) d1)->t.a; + b = ((Delaunay *) d1)->t.b; + c = ((Delaunay *) d1)->t.c; + aa = ((Delaunay *) d2)->t.a; + bb = ((Delaunay *) d2)->t.b; + cc = ((Delaunay *) d2)->t.c; - a = ((Delaunay*)d1)->t.a; - b = ((Delaunay*)d1)->t.b; - c = ((Delaunay*)d1)->t.c; - aa = ((Delaunay*)d2)->t.a; - bb = ((Delaunay*)d2)->t.b; - cc = ((Delaunay*)d2)->t.c; + val = + ((Delaunay *) d2)->t.quality_value - ((Delaunay *) d1)->t.quality_value; - val = ((Delaunay*)d2)->t.quality_value - ((Delaunay*)d1)->t.quality_value; - - if ((aa==a)&&(bb==b)&&(cc==c)){ + if((aa == a) && (bb == b) && (cc == c)) { return 0; } - else if (val > 1.e-21 ) + else if(val > 1.e-21) return 1; - else if (val < -1.e-21 ) + else if(val < -1.e-21) return -1; - else{ - if (((Delaunay*)d1)->t.xc > ((Delaunay*)d2)->t.xc) + else { + if(((Delaunay *) d1)->t.xc > ((Delaunay *) d2)->t.xc) return -1; - else - return 1; + else + return 1; } } -int Insert_Triangle (avlstruct **root, Delaunay * del){ - - if ( !avltree_insert(root,del,Comparekey) ) return(0); +int Insert_Triangle(avlstruct ** root, Delaunay * del) +{ + if(!avltree_insert(root, del, Comparekey)) + return (0); - return(1); + return (1); } -int Delete_Triangle ( avlstruct **root, Delaunay * del ){ +int Delete_Triangle(avlstruct ** root, Delaunay * del) +{ + if(!avltree_delete(root, del, Comparekey)) + return (0); - if (!avltree_delete(root,del,Comparekey)) return(0); - - if (*root == NULL) return(0); - return(1); + if(*root == NULL) + return (0); + return (1); } -int Insert_Point (MPoint pt, int *numpoints, int *numalloc, - DocRecord *doc, DocRecord *BGM, int is3d){ - Vertex *v,*dum; +int Insert_Point(MPoint pt, int *numpoints, int *numalloc, + DocRecord * doc, DocRecord * BGM, int is3d) +{ + Vertex *v, *dum; double qual; - if ( *numpoints >= *numalloc ) { - gPointArray = (PointRecord *) Realloc(gPointArray, - (*numalloc + 1000) * sizeof(PointRecord)); + if(*numpoints >= *numalloc) { + gPointArray = (PointRecord *) Realloc(gPointArray, + (*numalloc + + 1000) * sizeof(PointRecord)); *numalloc += 1000; doc->points = gPointArray; } @@ -91,139 +97,141 @@ int Insert_Point (MPoint pt, int *numpoints, int *numalloc, gPointArray[*numpoints].numcontour = -1; gPointArray[*numpoints].initial = -1; if(!is3d) - gPointArray[*numpoints].quality = find_quality(pt,BGM); - else{ - v = Create_Vertex (-1,pt.h,pt.v,0.0,0.0,0.0); + gPointArray[*numpoints].quality = find_quality(pt, BGM); + else { + v = Create_Vertex(-1, pt.h, pt.v, 0.0, 0.0, 0.0); Calcule_Z_Plan(&v, &dum); Projette_Inverse(&v, &dum); - qual = Lc_XYZ ( v->Pos.X,v->Pos.Y,v->Pos.Z,THEM) ; + qual = Lc_XYZ(v->Pos.X, v->Pos.Y, v->Pos.Z, THEM); if(CTX.mesh.constrained_bgmesh) - gPointArray[*numpoints].quality = MIN(find_quality(pt,BGM),qual); - else + gPointArray[*numpoints].quality = MIN(find_quality(pt, BGM), qual); + else gPointArray[*numpoints].quality = qual; - Free_Vertex(&v,0); + Free_Vertex(&v, 0); } - + (*numpoints)++; return 1; } -void findtree(avlptr root, double *qualm, Delaunay **delf, DocRecord *MESH){ - +void findtree(avlptr root, double *qualm, Delaunay ** delf, DocRecord * MESH) +{ /* trouve le triangle possedant le facteur de qualite max modif : le centre du cercle circonscrit de ce triangle doit etre dans le domaine - */ + */ MPoint pt; double q; Delaunay *del; - if(root != NULL){ - findtree((root)->left,qualm,delf,MESH); - del = (Delaunay*)root->treedata; + if(root != NULL) { + findtree((root)->left, qualm, delf, MESH); + del = (Delaunay *) root->treedata; q = del->t.quality_value; pt.h = del->t.xc; pt.v = del->t.yc; - if ((q>*qualm) && (Find_Triangle (pt ,MESH,A_TOUT_PRIX) != NULL) ){ + if((q > *qualm) && (Find_Triangle(pt, MESH, A_TOUT_PRIX) != NULL)) { *qualm = q; *delf = del; } - findtree((root)->right,qualm,delf,MESH); + findtree((root)->right, qualm, delf, MESH); } } -Delaunay *findrightest(avlptr root, DocRecord *MESH){ - - Delaunay *del,**dee; +Delaunay *findrightest(avlptr root, DocRecord * MESH) +{ + Delaunay *del, **dee; MPoint pt; avlptr exroot; double qualm; exroot = root; - while((exroot)->left != NULL){ + while((exroot)->left != NULL) { exroot = (exroot)->left; } - del = (Delaunay*)(exroot)->treedata; + del = (Delaunay *) (exroot)->treedata; pt.h = del->t.xc; pt.v = del->t.yc; - if( (LocalNewPoint == VORONOI_INSERT) ||(LocalNewPoint == SQUARE_TRI) ) + if((LocalNewPoint == VORONOI_INSERT) || (LocalNewPoint == SQUARE_TRI)) + return del; + + if(Find_Triangle(pt, MESH, A_TOUT_PRIX) != NULL) return del; - if(Find_Triangle(pt,MESH,A_TOUT_PRIX) != NULL )return del; - exroot = root; - del = (Delaunay*)(root)->treedata; + del = (Delaunay *) (root)->treedata; qualm = del->t.quality_value; dee = &del; findtree(exroot, &qualm, dee, MESH); del = *dee; - - return (del); -} -double lengthseg (MPoint a, MPoint b){ - return (pow(DSQR(a.h-b.h)+DSQR(a.v-b.v),0.5)); + return (del); } +double lengthseg(MPoint a, MPoint b) +{ + return (pow(DSQR(a.h - b.h) + DSQR(a.v - b.v), 0.5)); +} -MPoint Localize (Delaunay * del , DocRecord *MESH) { +MPoint Localize(Delaunay * del, DocRecord * MESH) +{ /* - Routine de localisation du point a inserer. - Variable globale LocalNewPoint : - - CENTER_CIRCCIRC : au centre du cercle circonscrit - - VORONOI_INSERT : sur une branche de voronoi - - BARYCENTER : au centre de gravite - - SQUARE_TRI : essaie de creer des triangles rectangles isoceles - dans le but de mailler avec des quadrangles - */ - - MPoint pt,pta,ptb,ptc,ptm; - PointNumero a=0,b=0; - double p,q,val,vec[2],ro,rm; - Delaunay *v1,*v2,*v3,*del2=NULL; + Routine de localisation du point a inserer. + Variable globale LocalNewPoint : + - CENTER_CIRCCIRC : au centre du cercle circonscrit + - VORONOI_INSERT : sur une branche de voronoi + - BARYCENTER : au centre de gravite + - SQUARE_TRI : essaie de creer des triangles rectangles isoceles + dans le but de mailler avec des quadrangles + */ + + MPoint pt, pta, ptb, ptc, ptm; + PointNumero a = 0, b = 0; + double p, q, val, vec[2], ro, rm; + Delaunay *v1, *v2, *v3, *del2 = NULL; switch (LocalNewPoint) { - case (CENTER_CIRCCIRC) : + case (CENTER_CIRCCIRC): pt.h = del->t.xc; pt.v = del->t.yc; - return(pt); + return (pt); - case (BARYCENTER) : + case (BARYCENTER): - pt.h = ( gPointArray[del->t.a].where.h + gPointArray[del->t.b].where.h - + gPointArray[del->t.c].where.h ) /3.; - pt.v = ( gPointArray[del->t.a].where.v + gPointArray[del->t.b].where.v - + gPointArray[del->t.c].where.v ) /3.; + pt.h = (gPointArray[del->t.a].where.h + gPointArray[del->t.b].where.h + + gPointArray[del->t.c].where.h) / 3.; + pt.v = (gPointArray[del->t.a].where.v + gPointArray[del->t.b].where.v + + gPointArray[del->t.c].where.v) / 3.; - return(pt); + return (pt); - case (VORONOI_INSERT) : - case (SQUARE_TRI) : + case (VORONOI_INSERT): + case (SQUARE_TRI): /* si le triangle est pres d'un bord -> ce bord est l'arete choisie - */ - if ((v1 = del->v.voisin1) == NULL) { + */ + if((v1 = del->v.voisin1) == NULL) { /* v1 == NULL; */ v2 = del->v.voisin2; v3 = del->v.voisin3; } - else if ((v2 = del->v.voisin2) == NULL) { + else if((v2 = del->v.voisin2) == NULL) { v1 = NULL; v2 = del->v.voisin1; v3 = del->v.voisin3; } - else if ((v3 = del->v.voisin3) == NULL) { + else if((v3 = del->v.voisin3) == NULL) { v1 = NULL; v2 = del->v.voisin1; v3 = del->v.voisin2; @@ -236,93 +244,113 @@ MPoint Localize (Delaunay * del , DocRecord *MESH) { /* Si l'arete est un bord -> - */ - if (v1 == NULL){ - - if((v2 != NULL) && (v3 != NULL) ) { - - if ( ((del->t.a == v2->t.a) || (del->t.a == v2->t.b) || (del->t.a == v2->t.c)) && - ((del->t.a == v3->t.a) || (del->t.a == v3->t.b) || (del->t.a == v3->t.c))){ + */ + if(v1 == NULL) { + + if((v2 != NULL) && (v3 != NULL)) { + + if(((del->t.a == v2->t.a) || (del->t.a == v2->t.b) + || (del->t.a == v2->t.c)) && ((del->t.a == v3->t.a) + || (del->t.a == v3->t.b) + || (del->t.a == v3->t.c))) { a = del->t.b; b = del->t.c; } - else if ( ((del->t.b == v2->t.a) || (del->t.b == v2->t.b) || (del->t.b == v2->t.c)) && - ((del->t.b == v3->t.a) || (del->t.b == v3->t.b) || (del->t.b == v3->t.c))){ + else + if(((del->t.b == v2->t.a) || (del->t.b == v2->t.b) + || (del->t.b == v2->t.c)) && ((del->t.b == v3->t.a) + || (del->t.b == v3->t.b) + || (del->t.b == v3->t.c))) { a = del->t.a; b = del->t.c; } - else if ( ((del->t.c == v2->t.a) || (del->t.c == v2->t.b) || (del->t.c == v2->t.c)) && - ((del->t.c == v3->t.a) || (del->t.c == v3->t.b) || (del->t.c == v3->t.c))){ + else + if(((del->t.c == v2->t.a) || (del->t.c == v2->t.b) + || (del->t.c == v2->t.c)) && ((del->t.c == v3->t.a) + || (del->t.c == v3->t.b) + || (del->t.c == v3->t.c))) { a = del->t.a; b = del->t.b; } - else{ - Msg(GERROR, "Voronoi insert 1"); + else { + Msg(GERROR, "Voronoi insert 1"); } - } - else if(v2 != NULL) { - if((del->t.a != v2->t.c) && (del->t.a != v2->t.c) && (del->t.a != v2->t.c)){ + } + else if(v2 != NULL) { + if((del->t.a != v2->t.c) && (del->t.a != v2->t.c) + && (del->t.a != v2->t.c)) { a = del->t.a; b = del->t.b; } - else if((del->t.b != v2->t.c) && (del->t.b != v2->t.c) && (del->t.b != v2->t.c)){ + else if((del->t.b != v2->t.c) && (del->t.b != v2->t.c) + && (del->t.b != v2->t.c)) { a = del->t.b; b = del->t.c; } - else if((del->t.c != v2->t.c) && (del->t.c != v2->t.c) && (del->t.c != v2->t.c)){ + else if((del->t.c != v2->t.c) && (del->t.c != v2->t.c) + && (del->t.c != v2->t.c)) { a = del->t.a; b = del->t.c; } else { - Msg(GERROR,"Voronoi insert 2"); + Msg(GERROR, "Voronoi insert 2"); } - } - else if(v3 != NULL) { - if((del->t.a != v3->t.c) && (del->t.a != v3->t.c) && (del->t.a != v3->t.c)){ + } + else if(v3 != NULL) { + if((del->t.a != v3->t.c) && (del->t.a != v3->t.c) + && (del->t.a != v3->t.c)) { a = del->t.a; b = del->t.b; } - else if((del->t.b != v3->t.c) && (del->t.b != v3->t.c) && (del->t.b != v3->t.c)){ + else if((del->t.b != v3->t.c) && (del->t.b != v3->t.c) + && (del->t.b != v3->t.c)) { a = del->t.b; b = del->t.c; } - else if((del->t.c != v3->t.c) && (del->t.c != v3->t.c) && (del->t.c != v3->t.c)){ + else if((del->t.c != v3->t.c) && (del->t.c != v3->t.c) + && (del->t.c != v3->t.c)) { a = del->t.a; b = del->t.c; } else { - Msg(GERROR, "Voronoi insert 3"); + Msg(GERROR, "Voronoi insert 3"); } } - } + } else { - if( v1->t.position == ACCEPTED )del2 = v1; - else if( v2->t.position == ACCEPTED )del2 = v2; - else if( v3->t.position == ACCEPTED )del2 = v3; + if(v1->t.position == ACCEPTED) + del2 = v1; + else if(v2->t.position == ACCEPTED) + del2 = v2; + else if(v3->t.position == ACCEPTED) + del2 = v3; else { - Msg(GERROR,"Coherence in Localize"); + Msg(GERROR, "Coherence in Localize"); } - - if((del->t.a != del2->t.a) && (del->t.a != del2->t.b) && (del->t.a != del2->t.c)){ + + if((del->t.a != del2->t.a) && (del->t.a != del2->t.b) + && (del->t.a != del2->t.c)) { a = del->t.b; b = del->t.c; } - else if((del->t.b != del2->t.a) && (del->t.b != del2->t.b) && (del->t.b != del2->t.c)){ + else if((del->t.b != del2->t.a) && (del->t.b != del2->t.b) + && (del->t.b != del2->t.c)) { a = del->t.a; b = del->t.c; } - else if((del->t.c != del2->t.a) && (del->t.c != del2->t.b) && (del->t.c != del2->t.c)){ + else if((del->t.c != del2->t.a) && (del->t.c != del2->t.b) + && (del->t.c != del2->t.c)) { a = del->t.a; b = del->t.b; } - else{ - Msg(GERROR,"Voronoi insert"); + else { + Msg(GERROR, "Voronoi insert"); } } /* On sait que l'arete du nouveau triangle est a b - */ + */ pta.h = gPointArray[a].where.h; ptb.h = gPointArray[b].where.h; @@ -330,38 +358,38 @@ MPoint Localize (Delaunay * del , DocRecord *MESH) { ptb.v = gPointArray[b].where.v; /* - pte.h = gPointArray[c].where.h; - pte.v = gPointArray[c].where.v; - */ + pte.h = gPointArray[c].where.h; + pte.v = gPointArray[c].where.v; + */ - p = 0.5 * lengthseg(pta,ptb); + p = 0.5 * lengthseg(pta, ptb); ptc.h = del->t.xc; ptc.v = del->t.yc; - - ptm.h = 0.5*( pta.h + ptb.h ); - ptm.v = 0.5*( pta.v + ptb.v ); - - q = lengthseg(ptm,ptc); - - vec[0] = (ptc.h - ptm.h)/q; - vec[1] = (ptc.v - ptm.v)/q; - - val = (p*p + q*q) / (2.*q); - - ro = find_quality(ptm,MESH)/RacineDeTrois; - - rm = ((ro > q )? ro : ro ); - rm = ((rm < val)? rm : val); + + ptm.h = 0.5 * (pta.h + ptb.h); + ptm.v = 0.5 * (pta.v + ptb.v); + + q = lengthseg(ptm, ptc); + + vec[0] = (ptc.h - ptm.h) / q; + vec[1] = (ptc.v - ptm.v) / q; + + val = (p * p + q * q) / (2. * q); + + ro = find_quality(ptm, MESH) / RacineDeTrois; + + rm = ((ro > q) ? ro : ro); + rm = ((rm < val) ? rm : val); // WARNING RANDOM - - pt.h = ptm.h + vec[0] * (rm + pow( rm*rm - p * p,0.5 )) ; + + pt.h = ptm.h + vec[0] * (rm + pow(rm * rm - p * p, 0.5)); //+ (double) (rand() % 1000) / 1.e8; - pt.v = ptm.v + vec[1] * (rm + pow( rm*rm - p * p,0.5 )) ; + pt.v = ptm.v + vec[1] * (rm + pow(rm * rm - p * p, 0.5)); //+ (double) (rand() % 1000) / 1.e8; - return(pt); + return (pt); } pt.h = 0.0; @@ -369,23 +397,24 @@ MPoint Localize (Delaunay * del , DocRecord *MESH) { return pt; } - -void alloue_Mai_Pts(maillage *mai , int Nballoc , int incrAlloc){ + +void alloue_Mai_Pts(maillage * mai, int Nballoc, int incrAlloc) +{ int i; - mai->points = (PointRecord *)Malloc(Nballoc*sizeof(PointRecord)); - for(i=0;i<Nballoc;i++){ - mai->points[i].where.h=0.0; - mai->points[i].where.v=0.0; + mai->points = (PointRecord *) Malloc(Nballoc * sizeof(PointRecord)); + for(i = 0; i < Nballoc; i++) { + mai->points[i].where.h = 0.0; + mai->points[i].where.v = 0.0; } mai->IncrAllocPoints = incrAlloc; mai->NumAllocPoints = Nballoc; } -void alloue_Mai_Del(maillage *mai , int Nballoc , int incrAlloc){ - mai->listdel = (delpeek *)Malloc(Nballoc * sizeof(delpeek)); +void alloue_Mai_Del(maillage * mai, int Nballoc, int incrAlloc) +{ + mai->listdel = (delpeek *) Malloc(Nballoc * sizeof(delpeek)); mai->IncrAllocTri = incrAlloc; mai->NumAllocTri = Nballoc; } - diff --git a/Mesh/3D_BGMesh.cpp b/Mesh/3D_BGMesh.cpp index 7797c95522b68a73b302f6c32466002abc462181..3591c4a5ca5fecb54e35a195918fe510e98cd9fa 100644 --- a/Mesh/3D_BGMesh.cpp +++ b/Mesh/3D_BGMesh.cpp @@ -1,4 +1,4 @@ -// $Id: 3D_BGMesh.cpp,v 1.22 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: 3D_BGMesh.cpp,v 1.23 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -28,199 +28,206 @@ #include "Context.h" extern Mesh *THEM; -extern Context_T CTX; +extern Context_T CTX; static Mesh m; static double XX, YY, ZZ, D, LL; -void ExportLcFieldOnVolume (Mesh * M){ - List_T *l = Tree2List (M->Volumes); +void ExportLcFieldOnVolume(Mesh * M) +{ + List_T *l = Tree2List(M->Volumes); Volume *vol; Simplex *simp; - FILE *f = fopen ("OutFile.pos", "w"); + FILE *f = fopen("OutFile.pos", "w"); - if(!f){ + if(!f) { Msg(GERROR, "Unable to open file"); return; } - fprintf (f, "View \"LC_FIELD\" Offset{0,0,0} {\n"); - for (int i = 0; i < List_Nbr (l); i++){ - List_Read (l, i, &vol); - List_T *ll = Tree2List (vol->Simplexes); - for (int j = 0; j < List_Nbr (ll); j++){ - List_Read (ll, j, &simp); - simp->ExportLcField (f); + fprintf(f, "View \"LC_FIELD\" Offset{0,0,0} {\n"); + for(int i = 0; i < List_Nbr(l); i++) { + List_Read(l, i, &vol); + List_T *ll = Tree2List(vol->Simplexes); + for(int j = 0; j < List_Nbr(ll); j++) { + List_Read(ll, j, &simp); + simp->ExportLcField(f); } - List_Delete (ll); + List_Delete(ll); } - List_Delete (l); - fprintf (f, "};\n"); - fclose (f); + List_Delete(l); + fprintf(f, "};\n"); + fclose(f); } -void ExportLcFieldOnSurfaces (Mesh * M){ - List_T *l = Tree2List (M->Surfaces); +void ExportLcFieldOnSurfaces(Mesh * M) +{ + List_T *l = Tree2List(M->Surfaces); Surface *surf; Simplex *simp; - FILE *f = fopen ("OutFileS.pos", "w"); + FILE *f = fopen("OutFileS.pos", "w"); - if(!f){ + if(!f) { Msg(GERROR, "Unable to open file"); return; } - fprintf (f, "View \"LC_FIELD\" Offset{0,0,0} {\n"); - for (int i = 0; i < List_Nbr (l); i++){ - List_Read (l, i, &surf); - List_T *ll = Tree2List (surf->Simplexes); - for (int j = 0; j < List_Nbr (ll); j++){ - List_Read (ll, j, &simp); - simp->ExportLcField (f); + fprintf(f, "View \"LC_FIELD\" Offset{0,0,0} {\n"); + for(int i = 0; i < List_Nbr(l); i++) { + List_Read(l, i, &surf); + List_T *ll = Tree2List(surf->Simplexes); + for(int j = 0; j < List_Nbr(ll); j++) { + List_Read(ll, j, &simp); + simp->ExportLcField(f); } - List_Delete (ll); + List_Delete(ll); } - List_Delete (l); - fprintf (f, "};\n"); - fclose (f); + List_Delete(l); + fprintf(f, "};\n"); + fclose(f); } -void findcloser (void *a, void *b){ +void findcloser(void *a, void *b) +{ Vertex *v; double dd; v = *(Vertex **) a; - dd = DSQR (v->Pos.X - XX) + DSQR (v->Pos.Y - YY) + DSQR (v->Pos.Z - ZZ); - if (dd < D){ + dd = DSQR(v->Pos.X - XX) + DSQR(v->Pos.Y - YY) + DSQR(v->Pos.Z - ZZ); + if(dd < D) { D = dd; LL = v->lc; } } -void LCBGM (double X, double Y, double Z, double *l){ - if (Pt_In_Volume (X, Y, Z, &m, l, .01)); - else if (Pt_In_Volume (X, Y, Z, &m, l, .02)); - else if (Pt_In_Volume (X, Y, Z, &m, l, .07)); - else if (Pt_In_Volume (X, Y, Z, &m, l, .1)); - else if (Pt_In_Volume (X, Y, Z, &m, l, .2)); - else if (Pt_In_Volume (X, Y, Z, &m, l, .8)); - else if (Pt_In_Volume (X, Y, Z, &m, l, 20.)); +void LCBGM(double X, double Y, double Z, double *l) +{ + if(Pt_In_Volume(X, Y, Z, &m, l, .01)); + else if(Pt_In_Volume(X, Y, Z, &m, l, .02)); + else if(Pt_In_Volume(X, Y, Z, &m, l, .07)); + else if(Pt_In_Volume(X, Y, Z, &m, l, .1)); + else if(Pt_In_Volume(X, Y, Z, &m, l, .2)); + else if(Pt_In_Volume(X, Y, Z, &m, l, .8)); + else if(Pt_In_Volume(X, Y, Z, &m, l, 20.)); else { XX = X; YY = Y; ZZ = Z; D = 1.e24; LL = 1; - Tree_Action (m.Vertices, findcloser); + Tree_Action(m.Vertices, findcloser); *l = LL; } } -double Lc_XYZ (double X, double Y, double Z, Mesh * m){ +double Lc_XYZ(double X, double Y, double Z, Mesh * m) +{ double l; //l = 0.1 * fabs(cos(2 * 3.14159 * X) * cos( 2 * 3.14159 * Y)) + 0.01; //return l; - switch (m->BGM.Typ){ + switch (m->BGM.Typ) { case FUNCTION: break; case CONSTANT: l = m->BGM.lc; break; case ONFILE: - LCBGM (X, Y, Z, &l); + LCBGM(X, Y, Z, &l); break; case WITHPOINTS: Msg(WARNING, "Send a mail to <gmsh@geuz.org> if you see this (Lc_XYZ)"); - if (Pt_In_Volume (X, Y, Z, m, &l, 0.0)); - else if (Pt_In_Volume (X, Y, Z, m, &l, 0.2)); - else if (Pt_In_Volume (X, Y, Z, m, &l, 0.5)); - else{ + if(Pt_In_Volume(X, Y, Z, m, &l, 0.0)); + else if(Pt_In_Volume(X, Y, Z, m, &l, 0.2)); + else if(Pt_In_Volume(X, Y, Z, m, &l, 0.5)); + else { Msg(GERROR, "Exterior Point (%g,%g,%g)", X, Y, Z); l = 1.e-25; } break; } - return CTX.mesh.lc_factor*l; + return CTX.mesh.lc_factor * l; } static Tree_T *Pts; -static void AIG (void *a, void *b){ +static void AIG(void *a, void *b) +{ Simplex *s = *(Simplex **) a; - AddSimplexInGrid (&m, s, BOITE); + AddSimplexInGrid(&m, s, BOITE); } -int BGMWithView (Post_View * ErrView){ +int BGMWithView(Post_View * ErrView) +{ static Vertex *VertexUp, *v, V, *ver[4]; int i, j, k, nb; double *X, *Y, *Z, *Val; Simplex *si; - VertexUp = Create_Vertex (-1, 0., 0., 1., 1., -1.0); - Pts = Tree_Create (sizeof (Vertex *), comparePosition); + VertexUp = Create_Vertex(-1, 0., 0., 1., 1., -1.0); + Pts = Tree_Create(sizeof(Vertex *), comparePosition); m.BGM.Typ = ONFILE; - m.Vertices = Tree_Create (sizeof (Vertex *), compareVertex); - m.Simplexes = Tree_Create (sizeof (Simplex *), compareSimplex); - Create_BgMesh (ONFILE, .2, THEM); + m.Vertices = Tree_Create(sizeof(Vertex *), compareVertex); + m.Simplexes = Tree_Create(sizeof(Simplex *), compareSimplex); + Create_BgMesh(ONFILE, .2, THEM); k = 1; - if(ErrView->NbST){ - nb = List_Nbr(ErrView->ST) / ErrView->NbST ; - for(i = 0 ; i < List_Nbr(ErrView->ST) ; i+=nb){ - X = (double*)List_Pointer_Fast(ErrView->ST,i); - Y = (double*)List_Pointer_Fast(ErrView->ST,i+3); - Z = (double*)List_Pointer_Fast(ErrView->ST,i+6); - Val = (double*)List_Pointer_Fast(ErrView->ST,i+9); - - for (j = 0; j < 3; j++){ - v = &V; - v->Pos.X = X[j]; - v->Pos.Y = Y[j]; - v->Pos.Z = Z[j]; - if (Tree_Query (Pts, &v)){ - ver[j] = v; - } - else{ - v = Create_Vertex (k++, X[j], Y[j], Z[j], Val[j], -1.0); - ver[j] = v; - Tree_Add (m.Vertices, &v); - Tree_Add (Pts, &v); - } + if(ErrView->NbST) { + nb = List_Nbr(ErrView->ST) / ErrView->NbST; + for(i = 0; i < List_Nbr(ErrView->ST); i += nb) { + X = (double *)List_Pointer_Fast(ErrView->ST, i); + Y = (double *)List_Pointer_Fast(ErrView->ST, i + 3); + Z = (double *)List_Pointer_Fast(ErrView->ST, i + 6); + Val = (double *)List_Pointer_Fast(ErrView->ST, i + 9); + + for(j = 0; j < 3; j++) { + v = &V; + v->Pos.X = X[j]; + v->Pos.Y = Y[j]; + v->Pos.Z = Z[j]; + if(Tree_Query(Pts, &v)) { + ver[j] = v; + } + else { + v = Create_Vertex(k++, X[j], Y[j], Z[j], Val[j], -1.0); + ver[j] = v; + Tree_Add(m.Vertices, &v); + Tree_Add(Pts, &v); + } } - si = Create_Simplex (ver[0], ver[1], ver[2], VertexUp); - Tree_Add (m.Simplexes, &si); + si = Create_Simplex(ver[0], ver[1], ver[2], VertexUp); + Tree_Add(m.Simplexes, &si); } } - if(ErrView->NbSS){ - nb = List_Nbr(ErrView->SS) / ErrView->NbSS ; - for(i = 0 ; i < List_Nbr(ErrView->SS) ; i+=nb){ - X = (double*)List_Pointer_Fast(ErrView->SS,i); - Y = (double*)List_Pointer_Fast(ErrView->SS,i+4); - Z = (double*)List_Pointer_Fast(ErrView->SS,i+8); - Val = (double*)List_Pointer_Fast(ErrView->SS,i+12); - - for (j = 0; j < 4; j++){ - v = &V; - v->Pos.X = X[j]; - v->Pos.Y = Y[j]; - v->Pos.Z = Z[j]; - if (Tree_Query (Pts, &v)){ - ver[j] = v; - } - else{ - v = Create_Vertex (k++, X[j], Y[j], Z[j], Val[j], -1.0); - ver[j] = v; - Tree_Add (m.Vertices, &v); - Tree_Add (Pts, &v); - } + if(ErrView->NbSS) { + nb = List_Nbr(ErrView->SS) / ErrView->NbSS; + for(i = 0; i < List_Nbr(ErrView->SS); i += nb) { + X = (double *)List_Pointer_Fast(ErrView->SS, i); + Y = (double *)List_Pointer_Fast(ErrView->SS, i + 4); + Z = (double *)List_Pointer_Fast(ErrView->SS, i + 8); + Val = (double *)List_Pointer_Fast(ErrView->SS, i + 12); + + for(j = 0; j < 4; j++) { + v = &V; + v->Pos.X = X[j]; + v->Pos.Y = Y[j]; + v->Pos.Z = Z[j]; + if(Tree_Query(Pts, &v)) { + ver[j] = v; + } + else { + v = Create_Vertex(k++, X[j], Y[j], Z[j], Val[j], -1.0); + ver[j] = v; + Tree_Add(m.Vertices, &v); + Tree_Add(Pts, &v); + } } - si = Create_Simplex (ver[0], ver[1], ver[2], ver[3]); - Tree_Add (m.Simplexes, &si); + si = Create_Simplex(ver[0], ver[1], ver[2], ver[3]); + Tree_Add(m.Simplexes, &si); } } @@ -228,51 +235,52 @@ int BGMWithView (Post_View * ErrView){ m.Grid.Nx = 10; m.Grid.Ny = 10; m.Grid.Nz = 10; - Tree_Action (m.Vertices, findminmax); - getminmax (&m.Grid.min.X, &m.Grid.min.Y, &m.Grid.min.Z, - &m.Grid.max.X, &m.Grid.max.Y, &m.Grid.max.Z); + Tree_Action(m.Vertices, findminmax); + getminmax(&m.Grid.min.X, &m.Grid.min.Y, &m.Grid.min.Z, + &m.Grid.max.X, &m.Grid.max.Y, &m.Grid.max.Z); - if (m.Grid.max.Z == m.Grid.min.Z){ + if(m.Grid.max.Z == m.Grid.min.Z) { m.Grid.Nz = 1; - Tree_Add (m.Vertices, &VertexUp); - Tree_Action (m.Vertices, findminmax); - getminmax (&m.Grid.min.X, &m.Grid.min.Y, &m.Grid.min.Z, - &m.Grid.max.X, &m.Grid.max.Y, &m.Grid.max.Z); + Tree_Add(m.Vertices, &VertexUp); + Tree_Action(m.Vertices, findminmax); + getminmax(&m.Grid.min.X, &m.Grid.min.Y, &m.Grid.min.Z, + &m.Grid.max.X, &m.Grid.max.Y, &m.Grid.max.Z); } - Tree_Action (m.Simplexes, AIG); + Tree_Action(m.Simplexes, AIG); Msg(INFO, "Background mesh loaded (%d nodes, %d elements)", - Tree_Nbr(m.Vertices), Tree_Nbr(m.Simplexes)); + Tree_Nbr(m.Vertices), Tree_Nbr(m.Simplexes)); return (1); } -double ErrorInView (Post_View * ErrView, int *n){ - double e, tot=0.0, *Val; - int i, j=0, nb; +double ErrorInView(Post_View * ErrView, int *n) +{ + double e, tot = 0.0, *Val; + int i, j = 0, nb; - if(ErrView == NULL){ + if(ErrView == NULL) { Msg(WARNING, "Empty error view"); return 0.; } - if(ErrView->NbST){ - nb = List_Nbr(ErrView->ST) / ErrView->NbST ; - for(i = 0 ; i < List_Nbr(ErrView->ST) ; i+=nb){ - Val = (double*)List_Pointer_Fast(ErrView->ST,i+9); - e = (Val[0] + Val[1] + Val[2]) / 3. ; + if(ErrView->NbST) { + nb = List_Nbr(ErrView->ST) / ErrView->NbST; + for(i = 0; i < List_Nbr(ErrView->ST); i += nb) { + Val = (double *)List_Pointer_Fast(ErrView->ST, i + 9); + e = (Val[0] + Val[1] + Val[2]) / 3.; tot += e * e; j++; } } - if(ErrView->NbSS){ - nb = List_Nbr(ErrView->SS) / ErrView->NbSS ; - for(i = 0 ; i < List_Nbr(ErrView->SS) ; i+=nb){ - Val = (double*)List_Pointer_Fast(ErrView->SS,i+12); - e = (Val[0] + Val[1] + Val[2] + Val[3]) * 0.25 ; + if(ErrView->NbSS) { + nb = List_Nbr(ErrView->SS) / ErrView->NbSS; + for(i = 0; i < List_Nbr(ErrView->SS); i += nb) { + Val = (double *)List_Pointer_Fast(ErrView->SS, i + 12); + e = (Val[0] + Val[1] + Val[2] + Val[3]) * 0.25; tot += e * e; j++; } @@ -280,6 +288,5 @@ double ErrorInView (Post_View * ErrView, int *n){ *n = j; - return 100 * sqrt (tot); + return 100 * sqrt(tot); } - diff --git a/Mesh/3D_Bricks.cpp b/Mesh/3D_Bricks.cpp index 5343061490b3ae4c7113583eb3d05744ffb884b2..9b2eff87437cbde76f55ad8a883890e9f8c3e949 100644 --- a/Mesh/3D_Bricks.cpp +++ b/Mesh/3D_Bricks.cpp @@ -1,4 +1,4 @@ -// $Id: 3D_Bricks.cpp,v 1.12 2003-02-25 04:02:51 geuzaine Exp $ +// $Id: 3D_Bricks.cpp,v 1.13 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -23,33 +23,40 @@ #include "Numeric.h" #include "Mesh.h" -Brick LaBrique (Grid_T * pGrid, double X, double Y, double Z){ +Brick LaBrique(Grid_T * pGrid, double X, double Y, double Z) +{ int Ix, Iy, Iz, index; Brick B; B.N = -1; B.pT = NULL; - if (X > pGrid->max.X || X < pGrid->min.X || Y > pGrid->max.Y || - Y < pGrid->min.Y || Z > pGrid->max.Z || Z < pGrid->min.Z){ + if(X > pGrid->max.X || X < pGrid->min.X || Y > pGrid->max.Y || + Y < pGrid->min.Y || Z > pGrid->max.Z || Z < pGrid->min.Z) { return (B); } - Ix = (int) ((double) pGrid->Nx * (X - pGrid->min.X) / (pGrid->max.X - pGrid->min.X)); - Iy = (int) ((double) pGrid->Ny * (Y - pGrid->min.Y) / (pGrid->max.Y - pGrid->min.Y)); - Iz = (int) ((double) pGrid->Nz * (Z - pGrid->min.Z) / (pGrid->max.Z - pGrid->min.Z)); - Ix = IMIN (Ix, pGrid->Nx - 1); - Iy = IMIN (Iy, pGrid->Ny - 1); - Iz = IMIN (Iz, pGrid->Nz - 1); - - if (Ix < 0) + Ix = + (int)((double)pGrid->Nx * (X - pGrid->min.X) / + (pGrid->max.X - pGrid->min.X)); + Iy = + (int)((double)pGrid->Ny * (Y - pGrid->min.Y) / + (pGrid->max.Y - pGrid->min.Y)); + Iz = + (int)((double)pGrid->Nz * (Z - pGrid->min.Z) / + (pGrid->max.Z - pGrid->min.Z)); + Ix = IMIN(Ix, pGrid->Nx - 1); + Iy = IMIN(Iy, pGrid->Ny - 1); + Iz = IMIN(Iz, pGrid->Nz - 1); + + if(Ix < 0) Ix = 0; - if (Iy < 0) + if(Iy < 0) Iy = 0; - if (Iz < 0) + if(Iz < 0) Iz = 0; index = Ix + Iy * pGrid->Nx + Iz * pGrid->Nx * pGrid->Ny; - List_Read (pGrid->Bricks, index, &B); + List_Read(pGrid->Bricks, index, &B); return (B); } @@ -57,9 +64,9 @@ Brick LaBrique (Grid_T * pGrid, double X, double Y, double Z){ int DEBUT = 0; Coord MINIM, MAXIM; -void getminmax (double *xmin, double *ymin, double *zmin, - double *xmax, double *ymax, double *zmax){ - +void getminmax(double *xmin, double *ymin, double *zmin, + double *xmax, double *ymax, double *zmax) +{ double dx, dy, dz, f; dx = MAXIM.X - MINIM.X; @@ -75,20 +82,20 @@ void getminmax (double *xmin, double *ymin, double *zmin, *zmax = MAXIM.Z + f * dz; } -void findminmax (void *a, void *b){ - +void findminmax(void *a, void *b) +{ Vertex *v; v = *(Vertex **) a; - if (!DEBUT){ - MINIM.X = DMIN (MINIM.X, v->Pos.X); - MAXIM.X = DMAX (MAXIM.X, v->Pos.X); - MINIM.Y = DMIN (MINIM.Y, v->Pos.Y); - MAXIM.Y = DMAX (MAXIM.Y, v->Pos.Y); - MINIM.Z = DMIN (MINIM.Z, v->Pos.Z); - MAXIM.Z = DMAX (MAXIM.Z, v->Pos.Z); + if(!DEBUT) { + MINIM.X = DMIN(MINIM.X, v->Pos.X); + MAXIM.X = DMAX(MAXIM.X, v->Pos.X); + MINIM.Y = DMIN(MINIM.Y, v->Pos.Y); + MAXIM.Y = DMAX(MAXIM.Y, v->Pos.Y); + MINIM.Z = DMIN(MINIM.Z, v->Pos.Z); + MAXIM.Z = DMAX(MAXIM.Z, v->Pos.Z); } - else{ + else { DEBUT = 0; MINIM.X = v->Pos.X; MAXIM.X = v->Pos.X; @@ -100,37 +107,38 @@ void findminmax (void *a, void *b){ } -void AddSimplexInGrid (Mesh * m, Simplex * s, int boule_boite){ - - double XminBox=0., XmaxBox=0., YminBox=0., YmaxBox=0., ZmaxBox=0., ZminBox=0.; +void AddSimplexInGrid(Mesh * m, Simplex * s, int boule_boite) +{ + double XminBox = 0., XmaxBox = 0., YminBox = 0., YmaxBox = 0., ZmaxBox = 0., ZminBox = 0.; int Ix1, Ix2, Iy1, Iy2, Iz1, Iz2; int i, j, k, index; Brick Br, *pBrick; - if (!m->Grid.init){ - m->Grid.Bricks = List_Create (m->Grid.Nx * m->Grid.Ny * m->Grid.Nz, 10, sizeof (Brick)); - for (i = 0; i < m->Grid.Nx * m->Grid.Ny * m->Grid.Nz; i++){ - Br.pT = List_Create (2, 2, sizeof (Simplex *)); + if(!m->Grid.init) { + m->Grid.Bricks = + List_Create(m->Grid.Nx * m->Grid.Ny * m->Grid.Nz, 10, sizeof(Brick)); + for(i = 0; i < m->Grid.Nx * m->Grid.Ny * m->Grid.Nz; i++) { + Br.pT = List_Create(2, 2, sizeof(Simplex *)); Br.N = i + 1; - List_Add (m->Grid.Bricks, &Br); + List_Add(m->Grid.Bricks, &Br); } m->Grid.init = 1; } - - if (boule_boite == BOITE){ + + if(boule_boite == BOITE) { XminBox = XmaxBox = s->V[0]->Pos.X; YminBox = YmaxBox = s->V[0]->Pos.Y; ZminBox = ZmaxBox = s->V[0]->Pos.Z; - for (i = 1; i < 4; i++){ - XminBox = DMIN (XminBox, s->V[i]->Pos.X); - XmaxBox = DMAX (XmaxBox, s->V[i]->Pos.X); - YminBox = DMIN (YminBox, s->V[i]->Pos.Y); - YmaxBox = DMAX (YmaxBox, s->V[i]->Pos.Y); - ZminBox = DMIN (ZminBox, s->V[i]->Pos.Z); - ZmaxBox = DMAX (ZmaxBox, s->V[i]->Pos.Z); + for(i = 1; i < 4; i++) { + XminBox = DMIN(XminBox, s->V[i]->Pos.X); + XmaxBox = DMAX(XmaxBox, s->V[i]->Pos.X); + YminBox = DMIN(YminBox, s->V[i]->Pos.Y); + YmaxBox = DMAX(YmaxBox, s->V[i]->Pos.Y); + ZminBox = DMIN(ZminBox, s->V[i]->Pos.Z); + ZmaxBox = DMAX(ZmaxBox, s->V[i]->Pos.Z); } } - else if (boule_boite == BOULE){ + else if(boule_boite == BOULE) { XminBox = s->Center.X - s->Radius; XmaxBox = s->Center.X + s->Radius; YminBox = s->Center.Y - s->Radius; @@ -138,34 +146,34 @@ void AddSimplexInGrid (Mesh * m, Simplex * s, int boule_boite){ ZminBox = s->Center.Z - s->Radius; ZmaxBox = s->Center.Z + s->Radius; } - - - Ix1 = (int) ((double) m->Grid.Nx * (XminBox - m->Grid.min.X) / - (m->Grid.max.X - m->Grid.min.X)); - Ix2 = (int) ((double) m->Grid.Nx * (XmaxBox - m->Grid.min.X) / - (m->Grid.max.X - m->Grid.min.X)); - Iy1 = (int) ((double) m->Grid.Ny * (YminBox - m->Grid.min.Y) / - (m->Grid.max.Y - m->Grid.min.Y)); - Iy2 = (int) ((double) m->Grid.Ny * (YmaxBox - m->Grid.min.Y) / - (m->Grid.max.Y - m->Grid.min.Y)); - Iz1 = (int) ((double) m->Grid.Nz * (ZminBox - m->Grid.min.Z) / - (m->Grid.max.Z - m->Grid.min.Z)); - Iz2 = (int) ((double) m->Grid.Nz * (ZmaxBox - m->Grid.min.Z) / - (m->Grid.max.Z - m->Grid.min.Z)); - - Ix1 = IMAX (Ix1, 0); - Ix2 = IMIN (Ix2, m->Grid.Nx - 1); - Iy1 = IMAX (Iy1, 0); - Iy2 = IMIN (Iy2, m->Grid.Ny - 1); - Iz1 = IMAX (Iz1, 0); - Iz2 = IMIN (Iz2, m->Grid.Nz - 1); - - for (i = Ix1; i <= Ix2; i++){ - for (j = Iy1; j <= Iy2; j++){ - for (k = Iz1; k <= Iz2; k++){ + + + Ix1 = (int)((double)m->Grid.Nx * (XminBox - m->Grid.min.X) / + (m->Grid.max.X - m->Grid.min.X)); + Ix2 = (int)((double)m->Grid.Nx * (XmaxBox - m->Grid.min.X) / + (m->Grid.max.X - m->Grid.min.X)); + Iy1 = (int)((double)m->Grid.Ny * (YminBox - m->Grid.min.Y) / + (m->Grid.max.Y - m->Grid.min.Y)); + Iy2 = (int)((double)m->Grid.Ny * (YmaxBox - m->Grid.min.Y) / + (m->Grid.max.Y - m->Grid.min.Y)); + Iz1 = (int)((double)m->Grid.Nz * (ZminBox - m->Grid.min.Z) / + (m->Grid.max.Z - m->Grid.min.Z)); + Iz2 = (int)((double)m->Grid.Nz * (ZmaxBox - m->Grid.min.Z) / + (m->Grid.max.Z - m->Grid.min.Z)); + + Ix1 = IMAX(Ix1, 0); + Ix2 = IMIN(Ix2, m->Grid.Nx - 1); + Iy1 = IMAX(Iy1, 0); + Iy2 = IMIN(Iy2, m->Grid.Ny - 1); + Iz1 = IMAX(Iz1, 0); + Iz2 = IMIN(Iz2, m->Grid.Nz - 1); + + for(i = Ix1; i <= Ix2; i++) { + for(j = Iy1; j <= Iy2; j++) { + for(k = Iz1; k <= Iz2; k++) { index = i + j * m->Grid.Nx + k * m->Grid.Nx * m->Grid.Ny; - pBrick = (Brick *) List_Pointer (m->Grid.Bricks, index); - List_Add (pBrick->pT, &s); + pBrick = (Brick *) List_Pointer(m->Grid.Bricks, index); + List_Add(pBrick->pT, &s); } } } diff --git a/Mesh/3D_Coherence.cpp b/Mesh/3D_Coherence.cpp index ec23e1061bc724c5cd9ccf9aa0fafd595cf609bc..e661d01fb90549bf9474649d039204f583cc2eb5 100644 --- a/Mesh/3D_Coherence.cpp +++ b/Mesh/3D_Coherence.cpp @@ -1,4 +1,4 @@ -// $Id: 3D_Coherence.cpp,v 1.28 2003-02-25 04:02:51 geuzaine Exp $ +// $Id: 3D_Coherence.cpp,v 1.29 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -33,26 +33,31 @@ extern Simplex MyNewBoundary; static Volume *THEVOL; static Edge *TheEdge; static Face *TheFace; -static List_T *Teti; +static List_T *Teti; List_T *Missing, *MissingF, *MissingS; Tree_T *EdgesTree, *FacesTree, *swaps, *touchedvertex; -int edges_quad[4][2] = { {0, 1}, - {1, 2}, - {2, 3}, - {3, 0} }; -int edges_tetra[6][2] = { {0, 1}, - {1, 2}, - {2, 0}, - {3, 0}, - {3, 2}, - {3, 1} }; -int edges_non[3] = {2, 0, 1}; +int edges_quad[4][2] = { + {0, 1}, + {1, 2}, + {2, 3}, + {3, 0} +}; +int edges_tetra[6][2] = { + {0, 1}, + {1, 2}, + {2, 0}, + {3, 0}, + {3, 2}, + {3, 1} +}; +int edges_non[3] = { 2, 0, 1 }; int EdgesInVolume = 1; -int memesens (Vertex * v1, Vertex * v2, Vertex * v3, - Vertex * c1, Vertex * c2, Vertex * c3){ +int memesens(Vertex * v1, Vertex * v2, Vertex * v3, + Vertex * c1, Vertex * c2, Vertex * c3) +{ double v12[3], v13[3], n1[3], n2[3], p; v12[0] = c1->Pos.X - c2->Pos.X; @@ -63,7 +68,7 @@ int memesens (Vertex * v1, Vertex * v2, Vertex * v3, v13[1] = c1->Pos.Y - c3->Pos.Y; v13[2] = c1->Pos.Z - c3->Pos.Z; - prodve (v12, v13, n1); + prodve(v12, v13, n1); v12[0] = v1->Pos.X - v2->Pos.X; v12[1] = v1->Pos.Y - v2->Pos.Y; @@ -73,93 +78,101 @@ int memesens (Vertex * v1, Vertex * v2, Vertex * v3, v13[1] = v1->Pos.Y - v3->Pos.Y; v13[2] = v1->Pos.Z - v3->Pos.Z; - prodve (v12, v13, n2); + prodve(v12, v13, n2); - prosca (n1, n2, &p); + prosca(n1, n2, &p); return ((p > 0) ? 1 : 0); } -static void pvertex (void *a, void *b){ +static void pvertex(void *a, void *b) +{ /* - Vertex *v; - v = (Vertex *) a; - printf ("noeud %d = (%12.5E,%12.5E,%12.5E)\n", v->Num, v->Pos.X, v->Pos.Y, v->Pos.Z); - */ + Vertex *v; + v = (Vertex *) a; + printf ("noeud %d = (%12.5E,%12.5E,%12.5E)\n", v->Num, v->Pos.X, v->Pos.Y, v->Pos.Z); + */ } -static void pedge (void *a, void *b){ +static void pedge(void *a, void *b) +{ /* - Edge *e; - e = (Edge *) a; - printf ("arete %d (%12.5E,%12.5E,%12.5E) -> %d (%12.5E,%12.5E,%12.5E)\n", - e->V[0]->Num, e->V[0]->Pos.X, e->V[0]->Pos.Y, e->V[0]->Pos.Z, - e->V[1]->Num, e->V[1]->Pos.X, e->V[1]->Pos.Y, e->V[1]->Pos.Z); - */ + Edge *e; + e = (Edge *) a; + printf ("arete %d (%12.5E,%12.5E,%12.5E) -> %d (%12.5E,%12.5E,%12.5E)\n", + e->V[0]->Num, e->V[0]->Pos.X, e->V[0]->Pos.Y, e->V[0]->Pos.Z, + e->V[1]->Num, e->V[1]->Pos.X, e->V[1]->Pos.Y, e->V[1]->Pos.Z); + */ } -void find_quads (void *a, void *b){ +void find_quads(void *a, void *b) +{ Edge *q; Edge diag; Simplex *s1, *s2; q = (Edge *) a; - if (!List_Search (Missing, q, compareedge)) + if(!List_Search(Missing, q, compareedge)) return; - if (List_Nbr (q->Simplexes) != 2) + if(List_Nbr(q->Simplexes) != 2) return; - List_Read (q->Simplexes, 0, &s1); - List_Read (q->Simplexes, 1, &s2); - if (s1->iEnt != s2->iEnt) + List_Read(q->Simplexes, 0, &s1); + List_Read(q->Simplexes, 1, &s2); + if(s1->iEnt != s2->iEnt) return; - if (!q->O[1]) + if(!q->O[1]) return; diag.V[0] = q->O[0]; diag.V[1] = q->O[1]; - if (Tree_Search (EdgesTree, &diag)){ - Tree_Add (swaps, q); + if(Tree_Search(EdgesTree, &diag)) { + Tree_Add(swaps, q); } } -void swap_quads (void *a, void *b){ +void swap_quads(void *a, void *b) +{ Edge *q; Simplex *s1, *s2; q = (Edge *) a; - List_Read (q->Simplexes, 0, &s1); - List_Read (q->Simplexes, 1, &s2); + List_Read(q->Simplexes, 0, &s1); + List_Read(q->Simplexes, 1, &s2); - if(Tree_Query(touchedvertex, &q->V[0])) return; - if(Tree_Query(touchedvertex, &q->V[1])) return; - if(Tree_Query(touchedvertex, &q->O[0])) return; - if(Tree_Query(touchedvertex, &q->O[1])) return; + if(Tree_Query(touchedvertex, &q->V[0])) + return; + if(Tree_Query(touchedvertex, &q->V[1])) + return; + if(Tree_Query(touchedvertex, &q->O[0])) + return; + if(Tree_Query(touchedvertex, &q->O[1])) + return; Tree_Add(touchedvertex, &q->V[0]); Tree_Add(touchedvertex, &q->V[1]); Tree_Add(touchedvertex, &q->O[0]); Tree_Add(touchedvertex, &q->O[1]); - if (memesens (s1->V[0], s1->V[1], s1->V[2], q->O[0], q->O[1], q->V[0])){ + if(memesens(s1->V[0], s1->V[1], s1->V[2], q->O[0], q->O[1], q->V[0])) { s1->V[0] = q->O[0]; s1->V[1] = q->O[1]; s1->V[2] = q->V[0]; } - else{ + else { s1->V[0] = q->O[1]; s1->V[1] = q->O[0]; s1->V[2] = q->V[0]; } - if (memesens (s2->V[0], s2->V[1], s2->V[2], q->O[0], q->O[1], q->V[1])){ + if(memesens(s2->V[0], s2->V[1], s2->V[2], q->O[0], q->O[1], q->V[1])) { s2->V[0] = q->O[0]; s2->V[1] = q->O[1]; s2->V[2] = q->V[1]; } - else{ + else { s2->V[0] = q->O[1]; s2->V[1] = q->O[0]; s2->V[2] = q->V[1]; @@ -173,53 +186,56 @@ void swap_quads (void *a, void *b){ s2->F[0].V[1] = s2->V[1]; s2->F[0].V[2] = s2->V[2]; - qsort (s1->F[0].V, 3, sizeof (Vertex *), compareVertex); - qsort (s2->F[0].V, 3, sizeof (Vertex *), compareVertex); + qsort(s1->F[0].V, 3, sizeof(Vertex *), compareVertex); + qsort(s2->F[0].V, 3, sizeof(Vertex *), compareVertex); - List_Suppress (Missing, q, compareedge); + List_Suppress(Missing, q, compareedge); q->V[0] = q->O[0]; q->V[1] = q->O[1]; } -int create_Quads (Volume * V){ +int create_Quads(Volume * V) +{ int i, n; Surface *S; - swaps = Tree_Create (sizeof (Edge), compareedge); - touchedvertex = Tree_Create (sizeof (Vertex*), compareVertex); - for (i = 0; i < List_Nbr (V->Surfaces); i++){ - List_Read (V->Surfaces, i, &S); - Tree_Action (S->Edges, find_quads); + swaps = Tree_Create(sizeof(Edge), compareedge); + touchedvertex = Tree_Create(sizeof(Vertex *), compareVertex); + for(i = 0; i < List_Nbr(V->Surfaces); i++) { + List_Read(V->Surfaces, i, &S); + Tree_Action(S->Edges, find_quads); } - Tree_Action (swaps, swap_quads); + Tree_Action(swaps, swap_quads); n = Tree_Nbr(swaps); Tree_Delete(swaps); Tree_Delete(touchedvertex); return n; } -void create_Fac (void *a, void *b){ +void create_Fac(void *a, void *b) +{ Simplex **ps, *s; int i; ps = (Simplex **) a; s = *ps; - for (i = 0; i < 4; i++){ - Tree_Insert (FacesTree, &s->F[i]); + for(i = 0; i < 4; i++) { + Tree_Insert(FacesTree, &s->F[i]); } } -void create_Faces (Volume * V){ - if(V->Faces) - { - Tree_Delete (V->Faces); - } - V->Faces = Tree_Create (sizeof (Face), compareFace); +void create_Faces(Volume * V) +{ + if(V->Faces) { + Tree_Delete(V->Faces); + } + V->Faces = Tree_Create(sizeof(Face), compareFace); FacesTree = V->Faces; - Tree_Action (V->Simplexes, create_Fac); + Tree_Action(V->Simplexes, create_Fac); } -void create_Edge (void *a, void *b){ +void create_Edge(void *a, void *b) +{ Simplex **ps, *s; int N, i, j; Edge E, *pE; @@ -227,133 +243,137 @@ void create_Edge (void *a, void *b){ s = *ps; int edges[6][2]; - if (s->V[3] && EdgesInVolume){ + if(s->V[3] && EdgesInVolume) { N = 6; - for (i = 0; i < N; i++) - for (j = 0; j < 2; j++) - edges[i][j] = edges_tetra[i][j]; + for(i = 0; i < N; i++) + for(j = 0; j < 2; j++) + edges[i][j] = edges_tetra[i][j]; } - else if (s->V[3]){ + else if(s->V[3]) { N = 4; - for (i = 0; i < N; i++) - for (j = 0; j < 2; j++) + for(i = 0; i < N; i++) + for(j = 0; j < 2; j++) edges[i][j] = edges_quad[i][j]; } - else if (s->V[2]){ + else if(s->V[2]) { N = 3; - for (i = 0; i < N; i++) - for (j = 0; j < 2; j++) + for(i = 0; i < N; i++) + for(j = 0; j < 2; j++) edges[i][j] = edges_tetra[i][j]; } - else{ + else { N = 1; - for (i = 0; i < N; i++) - for (j = 0; j < 2; j++) + for(i = 0; i < N; i++) + for(j = 0; j < 2; j++) edges[i][j] = edges_tetra[i][j]; } - for (i = 0; i < N; i++){ + for(i = 0; i < N; i++) { E.V[0] = s->V[edges[i][0]]; E.V[1] = s->V[edges[i][1]]; - if ((pE = (Edge *) Tree_PQuery (EdgesTree, &E))){ - List_Add (pE->Simplexes, ps); - if (N == 3) + if((pE = (Edge *) Tree_PQuery(EdgesTree, &E))) { + List_Add(pE->Simplexes, ps); + if(N == 3) pE->O[1] = s->V[edges_non[i]]; } - else{ - E.Simplexes = List_Create (2, 1, sizeof (Simplex *)); - if (N == 3) + else { + E.Simplexes = List_Create(2, 1, sizeof(Simplex *)); + if(N == 3) E.O[0] = s->V[edges_non[i]]; - if (N == 3) + if(N == 3) E.O[1] = NULL; - List_Add (E.Simplexes, &s); + List_Add(E.Simplexes, &s); E.newv = NULL; - Tree_Replace (EdgesTree, &E); + Tree_Replace(EdgesTree, &E); } } } -void create_Edges (Volume * V){ +void create_Edges(Volume * V) +{ int i; Surface *S; // MEMORY LEAK (JF) - if(V->Edges) - { - Tree_Action(V->Edges,Free_Edge); - Tree_Delete(V->Edges); - } + if(V->Edges) { + Tree_Action(V->Edges, Free_Edge); + Tree_Delete(V->Edges); + } - V->Edges = Tree_Create (sizeof (Edge), compareedge); + V->Edges = Tree_Create(sizeof(Edge), compareedge); EdgesTree = V->Edges; - Tree_Action (V->Simplexes, create_Edge); - for (i = 0; i < List_Nbr (V->Surfaces); i++){ - List_Read (V->Surfaces, i, &S); + Tree_Action(V->Simplexes, create_Edge); + for(i = 0; i < List_Nbr(V->Surfaces); i++) { + List_Read(V->Surfaces, i, &S); // MEMORY LEAK (JF) - if(S->Edges) - { - // BUG BUG BUG (This causes crash) - //Tree_Action(S->Edges,Free_Edge); - Tree_Delete(S->Edges); - } - S->Edges = Tree_Create (sizeof (Edge), compareedge); + if(S->Edges) { + // BUG BUG BUG (This causes crash) + //Tree_Action(S->Edges,Free_Edge); + Tree_Delete(S->Edges); + } + S->Edges = Tree_Create(sizeof(Edge), compareedge); EdgesTree = S->Edges; - Tree_Action (S->Simplexes, create_Edge); + Tree_Action(S->Simplexes, create_Edge); } } -void crEdges (Tree_T * TreeElem, Tree_T * treeedges){ +void crEdges(Tree_T * TreeElem, Tree_T * treeedges) +{ EdgesTree = treeedges; - Tree_Action (TreeElem, create_Edge); + Tree_Action(TreeElem, create_Edge); } -void find_missing (void *a, void *b){ +void find_missing(void *a, void *b) +{ Edge *e; e = (Edge *) a; - if (!Tree_Search (EdgesTree, e)){ - List_Add (Missing, e); - Tree_Add (EdgesTree, e); + if(!Tree_Search(EdgesTree, e)) { + List_Add(Missing, e); + Tree_Add(EdgesTree, e); } } -void find_missingf (void *a, void *b){ +void find_missingf(void *a, void *b) +{ Simplex *s; s = *(Simplex **) a; - if (!FacesTree || !Tree_Search (FacesTree, &s->F[0])){ - List_Add (MissingF, &s->F[0]); - List_Add (MissingS, &s); + if(!FacesTree || !Tree_Search(FacesTree, &s->F[0])) { + List_Add(MissingF, &s->F[0]); + List_Add(MissingS, &s); } } -List_T *Missing_Edges (Volume * V){ +List_T *Missing_Edges(Volume * V) +{ int i; Surface *S; - Missing = List_Create (10, 10, sizeof (Edge)); + Missing = List_Create(10, 10, sizeof(Edge)); EdgesTree = V->Edges; - for (i = 0; i < List_Nbr (V->Surfaces); i++){ - List_Read (V->Surfaces, i, &S); - Tree_Action (S->Edges, find_missing); + for(i = 0; i < List_Nbr(V->Surfaces); i++) { + List_Read(V->Surfaces, i, &S); + Tree_Action(S->Edges, find_missing); } return Missing; } -List_T *Missing_Faces (Volume * V){ +List_T *Missing_Faces(Volume * V) +{ int i; Surface *S; - MissingF = List_Create (10, 10, sizeof (Face)); - MissingS = List_Create (10, 10, sizeof (Simplex *)); + MissingF = List_Create(10, 10, sizeof(Face)); + MissingS = List_Create(10, 10, sizeof(Simplex *)); - for (i = 0; i < List_Nbr (V->Surfaces); i++){ - List_Read (V->Surfaces, i, &S); - Tree_Action (S->Simplexes, find_missingf); + for(i = 0; i < List_Nbr(V->Surfaces); i++) { + List_Read(V->Surfaces, i, &S); + Tree_Action(S->Simplexes, find_missingf); } return MissingF; } @@ -364,10 +384,11 @@ List_T *Missing_Faces (Volume * V){ List_T *traite; Tree_T *traited; -void Ajoute_traite (Simplex ** s){ - if (!Tree_Search (traited, s)){ - List_Add (traite, s); - Tree_Add (traited, s); +void Ajoute_traite(Simplex ** s) +{ + if(!Tree_Search(traited, s)) { + List_Add(traite, s); + Tree_Add(traited, s); } } @@ -376,31 +397,33 @@ Vertex *m1, *m2, *e1, *e2; Face *f1; int Cloture; -void fillRi (void *a, void *b){ +void fillRi(void *a, void *b) +{ int i, c; Simplex *s; s = *(Simplex **) a; c = 0; - for (i = 0; i < 4; i++){ - if (!compareVertex (&e1, &s->V[i])) + for(i = 0; i < 4; i++) { + if(!compareVertex(&e1, &s->V[i])) c++; - if (!compareVertex (&e2, &s->V[i])) + if(!compareVertex(&e2, &s->V[i])) c++; } - if (c == 2){ - Ajoute_traite (&s); + if(c == 2) { + Ajoute_traite(&s); } } -void fillTeti (void *a, void *b){ +void fillTeti(void *a, void *b) +{ int i; Simplex *s; s = *(Simplex **) a; - for (i = 0; i < 4; i++){ - if (!compareVertex (&m1, &s->V[i])){ - List_Add (Teti, &s); + for(i = 0; i < 4; i++) { + if(!compareVertex(&m1, &s->V[i])) { + List_Add(Teti, &s); return; } } @@ -413,19 +436,20 @@ typedef struct{ Edge e; Face *f; Vertex *newv; -} xNewv; +}xNewv; -int compxNewv (const void *a, const void *b){ +int compxNewv(const void *a, const void *b) +{ xNewv *q, *w; q = (xNewv *) a; w = (xNewv *) b; - if (q->ef != w->ef) + if(q->ef != w->ef) return (q->ef - w->ef); - if (q->ef == 1) - return compareedge (&q->e, &w->e); - if (q->ef == 2) - return compareFace (q->f, w->f); + if(q->ef == 1) + return compareedge(&q->e, &w->e); + if(q->ef == 2) + return compareFace(q->f, w->f); return 1; } @@ -459,75 +483,84 @@ int compxNewv (const void *a, const void *b){ #define eps_prec (-1.e-10) -int Edge_Node (Edge * e, Vertex * v){ - double u=0.0, lc; +int Edge_Node(Edge * e, Vertex * v) +{ + double u = 0.0, lc; - if (!compareVertex (&e->V[0], &v)) + if(!compareVertex(&e->V[0], &v)) return 1; - if (!compareVertex (&e->V[1], &v)) + if(!compareVertex(&e->V[1], &v)) return 1; - lc = myhypot (myhypot (e->V[0]->Pos.X - e->V[1]->Pos.X, e->V[0]->Pos.Y - e->V[1]->Pos.Y), - e->V[0]->Pos.Z - e->V[1]->Pos.Z); - - if (e->V[0]->Pos.X != e->V[1]->Pos.X){ + lc = + myhypot(myhypot + (e->V[0]->Pos.X - e->V[1]->Pos.X, + e->V[0]->Pos.Y - e->V[1]->Pos.Y), + e->V[0]->Pos.Z - e->V[1]->Pos.Z); + + if(e->V[0]->Pos.X != e->V[1]->Pos.X) { u = (v->Pos.X - e->V[0]->Pos.X) / (e->V[1]->Pos.X - e->V[0]->Pos.X); } - else if (e->V[0]->Pos.Y != e->V[1]->Pos.Y){ + else if(e->V[0]->Pos.Y != e->V[1]->Pos.Y) { u = (v->Pos.Y - e->V[0]->Pos.Y) / (e->V[1]->Pos.Y - e->V[0]->Pos.Y); } - else if (e->V[0]->Pos.Z != e->V[1]->Pos.Z){ + else if(e->V[0]->Pos.Z != e->V[1]->Pos.Z) { u = (v->Pos.Z - e->V[0]->Pos.Z) / (e->V[1]->Pos.Z - e->V[0]->Pos.Z); } - - if (u < -eps_prec || u > 1. + eps_prec) + + if(u < -eps_prec || u > 1. + eps_prec) return 0; - if (fabs ((1. - u) * e->V[0]->Pos.X + u * e->V[1]->Pos.X - v->Pos.X) > 1.e-7 * lc){ + if(fabs((1. - u) * e->V[0]->Pos.X + u * e->V[1]->Pos.X - v->Pos.X) > + 1.e-7 * lc) { return 0; } - if (fabs ((1. - u) * e->V[0]->Pos.Y + u * e->V[1]->Pos.Y - v->Pos.Y) > 1.e-7 * lc){ + if(fabs((1. - u) * e->V[0]->Pos.Y + u * e->V[1]->Pos.Y - v->Pos.Y) > + 1.e-7 * lc) { return 0; } - if (fabs ((1. - u) * e->V[0]->Pos.Z + u * e->V[1]->Pos.Z - v->Pos.Z) > 1.e-7 * lc){ + if(fabs((1. - u) * e->V[0]->Pos.Z + u * e->V[1]->Pos.Z - v->Pos.Z) > + 1.e-7 * lc) { return 0; } return 2; } -List_T *SurfComm (List_T * S1, List_T * S2){ +List_T *SurfComm(List_T * S1, List_T * S2) +{ int i; List_T *List; Surface *s; - List = List_Create (2, 2, sizeof (Surface *)); + List = List_Create(2, 2, sizeof(Surface *)); - if (!S1 || !S2) + if(!S1 || !S2) return List; - for (i = 0; i < List_Nbr (S1); i++){ - List_Read (S1, i, &s); - if (List_Search (S2, &s, compareSurface)) - List_Add (List, &s); + for(i = 0; i < List_Nbr(S1); i++) { + List_Read(S1, i, &s); + if(List_Search(S2, &s, compareSurface)) + List_Add(List, &s); } return List; } -Vertex *Edge_Face (Edge * e, Face * f){ +Vertex *Edge_Face(Edge * e, Face * f) +{ Vertex *v; double mat[3][3], det; double b[3], res[3]; - if (!compareVertex (&e->V[0], &f->V[0])) + if(!compareVertex(&e->V[0], &f->V[0])) return NULL; - if (!compareVertex (&e->V[0], &f->V[1])) + if(!compareVertex(&e->V[0], &f->V[1])) return NULL; - if (!compareVertex (&e->V[0], &f->V[2])) + if(!compareVertex(&e->V[0], &f->V[2])) return NULL; - if (!compareVertex (&e->V[1], &f->V[0])) + if(!compareVertex(&e->V[1], &f->V[0])) return NULL; - if (!compareVertex (&e->V[1], &f->V[1])) + if(!compareVertex(&e->V[1], &f->V[1])) return NULL; - if (!compareVertex (&e->V[1], &f->V[2])) + if(!compareVertex(&e->V[1], &f->V[2])) return NULL; mat[0][0] = f->V[1]->Pos.X - f->V[0]->Pos.X; @@ -546,154 +579,160 @@ Vertex *Edge_Face (Edge * e, Face * f){ b[1] = e->V[0]->Pos.Y - f->V[0]->Pos.Y; b[2] = e->V[0]->Pos.Z - f->V[0]->Pos.Z; - if (!sys3x3_with_tol (mat, b, res, &det))//???TOLERANCE????????????? + if(!sys3x3_with_tol(mat, b, res, &det)) //???TOLERANCE????????????? return NULL; /* res donne les coordonnees u,v de l'intersection dans la face et donne w la coordonnee de l'intersection dans l'arete - */ + */ /* coordonnees dans l'arete */ - if (res[2] >= 1.0 - eps_prec || res[2] <= eps_prec) + if(res[2] >= 1.0 - eps_prec || res[2] <= eps_prec) return NULL; /* coordonnees dans la face */ - if (res[0] >= 1.0 + eps_prec || res[0] <= -eps_prec) + if(res[0] >= 1.0 + eps_prec || res[0] <= -eps_prec) return NULL; - if (res[1] <= -eps_prec || res[1] >= 1. + eps_prec - res[0]) + if(res[1] <= -eps_prec || res[1] >= 1. + eps_prec - res[0]) return NULL; - if (res[0] == 1.0 || res[2] == 0.0 || res[0] == 0.0 || - res[1] == 1. - res[0] || res[1] == 0.0 || res[0] == 1.0){ - Msg(DEBUG1, "Face p1 %g %g %g", f->V[0]->Pos.X, f->V[0]->Pos.Y, f->V[0]->Pos.Z); - Msg(DEBUG2, "facette p2 %g %g %g", f->V[1]->Pos.X, f->V[1]->Pos.Y, f->V[1]->Pos.Z); - Msg(DEBUG2, "facette p3 %g %g %g", f->V[2]->Pos.X, f->V[2]->Pos.Y, f->V[2]->Pos.Z); - Msg(DEBUG2, "edge e2 %g %g %g", e->V[0]->Pos.X, e->V[0]->Pos.Y, e->V[0]->Pos.Z); - Msg(DEBUG2, "edge e3 %g %g %g", e->V[1]->Pos.X, e->V[1]->Pos.Y, e->V[1]->Pos.Z); + if(res[0] == 1.0 || res[2] == 0.0 || res[0] == 0.0 || + res[1] == 1. - res[0] || res[1] == 0.0 || res[0] == 1.0) { + Msg(DEBUG1, "Face p1 %g %g %g", f->V[0]->Pos.X, f->V[0]->Pos.Y, + f->V[0]->Pos.Z); + Msg(DEBUG2, "facette p2 %g %g %g", f->V[1]->Pos.X, f->V[1]->Pos.Y, + f->V[1]->Pos.Z); + Msg(DEBUG2, "facette p3 %g %g %g", f->V[2]->Pos.X, f->V[2]->Pos.Y, + f->V[2]->Pos.Z); + Msg(DEBUG2, "edge e2 %g %g %g", e->V[0]->Pos.X, e->V[0]->Pos.Y, + e->V[0]->Pos.Z); + Msg(DEBUG2, "edge e3 %g %g %g", e->V[1]->Pos.X, e->V[1]->Pos.Y, + e->V[1]->Pos.Z); Msg(DEBUG3, "%g %g %g", res[0], res[1], res[2]); } - v = Create_Vertex (++THEM->MaxPointNum, - (1. - res[2]) * e->V[0]->Pos.X + res[2] * e->V[1]->Pos.X, - (1. - res[2]) * e->V[0]->Pos.Y + res[2] * e->V[1]->Pos.Y, - (1. - res[2]) * e->V[0]->Pos.Z + res[2] * e->V[1]->Pos.Z, - (1. - res[2]) * e->V[0]->lc + res[2] * e->V[1]->lc, 0.0); - v->ListSurf = List_Create (1, 1, sizeof (Surface *)); + v = Create_Vertex(++THEM->MaxPointNum, + (1. - res[2]) * e->V[0]->Pos.X + res[2] * e->V[1]->Pos.X, + (1. - res[2]) * e->V[0]->Pos.Y + res[2] * e->V[1]->Pos.Y, + (1. - res[2]) * e->V[0]->Pos.Z + res[2] * e->V[1]->Pos.Z, + (1. - res[2]) * e->V[0]->lc + res[2] * e->V[1]->lc, 0.0); + v->ListSurf = List_Create(1, 1, sizeof(Surface *)); return v; } -Vertex *Edge_Edge (Edge * e, Vertex * v1, Vertex * v2){ +Vertex *Edge_Edge(Edge * e, Vertex * v1, Vertex * v2) +{ Vertex *v; int dir; //int dx1, dx2, dy1, dy2, dz1, dz2; double mat[2][2]; double b[3], res[3]; double XmaxS, XminS, YmaxS, YminS, ZmaxS, ZminS, lc; - double XmaxV, XminV, YmaxV, YminV, ZmaxV, ZminV, val=0.; + double XmaxV, XminV, YmaxV, YminV, ZmaxV, ZminV, val = 0.; - if (!compareVertex (&e->V[0], &v1)) + if(!compareVertex(&e->V[0], &v1)) return NULL; - if (!compareVertex (&e->V[1], &v1)) + if(!compareVertex(&e->V[1], &v1)) return NULL; - if (!compareVertex (&e->V[0], &v2)) + if(!compareVertex(&e->V[0], &v2)) return NULL; - if (!compareVertex (&e->V[1], &v2)) + if(!compareVertex(&e->V[1], &v2)) return NULL; - XminS = DMIN (e->V[0]->Pos.X, e->V[1]->Pos.X); - XmaxS = DMAX (e->V[0]->Pos.X, e->V[1]->Pos.X); - YminS = DMIN (e->V[0]->Pos.Y, e->V[1]->Pos.Y); - YmaxS = DMAX (e->V[0]->Pos.Y, e->V[1]->Pos.Y); - ZminS = DMIN (e->V[0]->Pos.Z, e->V[1]->Pos.Z); - ZmaxS = DMAX (e->V[0]->Pos.Z, e->V[1]->Pos.Z); - - XminV = DMIN (v1->Pos.X, v2->Pos.X); - XmaxV = DMAX (v1->Pos.X, v2->Pos.X); - YminV = DMIN (v1->Pos.Y, v2->Pos.Y); - YmaxV = DMAX (v1->Pos.Y, v2->Pos.Y); - ZminV = DMIN (v1->Pos.Z, v2->Pos.Z); - ZmaxV = DMAX (v1->Pos.Z, v2->Pos.Z); - - if (XmaxS < XminV || XmaxV < XminS) + XminS = DMIN(e->V[0]->Pos.X, e->V[1]->Pos.X); + XmaxS = DMAX(e->V[0]->Pos.X, e->V[1]->Pos.X); + YminS = DMIN(e->V[0]->Pos.Y, e->V[1]->Pos.Y); + YmaxS = DMAX(e->V[0]->Pos.Y, e->V[1]->Pos.Y); + ZminS = DMIN(e->V[0]->Pos.Z, e->V[1]->Pos.Z); + ZmaxS = DMAX(e->V[0]->Pos.Z, e->V[1]->Pos.Z); + + XminV = DMIN(v1->Pos.X, v2->Pos.X); + XmaxV = DMAX(v1->Pos.X, v2->Pos.X); + YminV = DMIN(v1->Pos.Y, v2->Pos.Y); + YmaxV = DMAX(v1->Pos.Y, v2->Pos.Y); + ZminV = DMIN(v1->Pos.Z, v2->Pos.Z); + ZmaxV = DMAX(v1->Pos.Z, v2->Pos.Z); + + if(XmaxS < XminV || XmaxV < XminS) return NULL; - if (YmaxS < YminV || YmaxV < YminS) + if(YmaxS < YminV || YmaxV < YminS) return NULL; - if (ZmaxS < ZminV || ZmaxV < ZminS) + if(ZmaxS < ZminV || ZmaxV < ZminS) return NULL; - lc = myhypot (myhypot (XminV - XmaxV, YminV - YmaxV), ZminV - ZmaxV); + lc = myhypot(myhypot(XminV - XmaxV, YminV - YmaxV), ZminV - ZmaxV); /* - if (e->V[1]->Pos.X != e->V[0]->Pos.X && - fabs (e->V[1]->Pos.X - e->V[0]->Pos.X) / lc > 1.e-2) - dx1 = 1; - else - dx1 = 0; - if (e->V[1]->Pos.Y != e->V[0]->Pos.Y && - fabs (e->V[1]->Pos.Y - e->V[0]->Pos.Y) / lc > 1.e-2) - dy1 = 1; - else - dy1 = 0; - if (e->V[1]->Pos.Z != e->V[0]->Pos.Z && - fabs (e->V[1]->Pos.Z - e->V[0]->Pos.Z) / lc > 1.e-2) - dz1 = 1; - else - dz1 = 0; - - if (v1->Pos.X != v2->Pos.X && - fabs (v1->Pos.X - v2->Pos.X) / lc > 1.e-2) - dx2 = 1; - else - dx2 = 0; - if (v1->Pos.Y != v2->Pos.Y && - fabs (v1->Pos.Y - v2->Pos.Y) / lc > 1.e-2) - dy2 = 1; - else - dy2 = 0; - if (v1->Pos.Z != v2->Pos.Z && - fabs (v1->Pos.Z - v2->Pos.Z) / lc > 1.e-2) - dz2 = 1; - else - dz2 = 0; - - if(dx1 && dx2){ - mat[0][0] = e->V[1]->Pos.X - e->V[0]->Pos.X; - mat[0][1] = v1->Pos.X - v2->Pos.X; - b[0] = - e->V[0]->Pos.X + v1->Pos.X; - if(dy1 || dy2){ - mat[1][0] = e->V[1]->Pos.Y - e->V[0]->Pos.Y; - mat[1][1] = v1->Pos.Y - v2->Pos.Y; - b[1] = - e->V[0]->Pos.Y + v1->Pos.Y; - dir = 2; - } - else if(dz1 || dz2){ - mat[1][0] = e->V[1]->Pos.Z - e->V[0]->Pos.Z; - mat[1][1] = v1->Pos.Z - v2->Pos.Z; - b[1] = - e->V[0]->Pos.Z + v1->Pos.Z; - dir = 3; - } - } - else if (dy1 && dy2){ - mat[0][0] = e->V[1]->Pos.Y - e->V[0]->Pos.Y; - mat[0][1] = v1->Pos.Y - v2->Pos.Y; - b[0] = - e->V[0]->Pos.Y + v1->Pos.Y; - if(dy1 || dy2){ - mat[1][0] = e->V[1]->Pos.Y - e->V[0]->Pos.Y; - mat[1][1] = v1->Pos.Y - v2->Pos.Y; - b[1] = - e->V[0]->Pos.Y + v1->Pos.Y; - dir = 2; - } - else if(dz1 || dz2){ - mat[1][0] = e->V[1]->Pos.Z - e->V[0]->Pos.Z; - mat[1][1] = v1->Pos.Z - v2->Pos.Z; - b[1] = - e->V[0]->Pos.Z + v1->Pos.Z; - dir = 3; - } - } - */ + if (e->V[1]->Pos.X != e->V[0]->Pos.X && + fabs (e->V[1]->Pos.X - e->V[0]->Pos.X) / lc > 1.e-2) + dx1 = 1; + else + dx1 = 0; + if (e->V[1]->Pos.Y != e->V[0]->Pos.Y && + fabs (e->V[1]->Pos.Y - e->V[0]->Pos.Y) / lc > 1.e-2) + dy1 = 1; + else + dy1 = 0; + if (e->V[1]->Pos.Z != e->V[0]->Pos.Z && + fabs (e->V[1]->Pos.Z - e->V[0]->Pos.Z) / lc > 1.e-2) + dz1 = 1; + else + dz1 = 0; + + if (v1->Pos.X != v2->Pos.X && + fabs (v1->Pos.X - v2->Pos.X) / lc > 1.e-2) + dx2 = 1; + else + dx2 = 0; + if (v1->Pos.Y != v2->Pos.Y && + fabs (v1->Pos.Y - v2->Pos.Y) / lc > 1.e-2) + dy2 = 1; + else + dy2 = 0; + if (v1->Pos.Z != v2->Pos.Z && + fabs (v1->Pos.Z - v2->Pos.Z) / lc > 1.e-2) + dz2 = 1; + else + dz2 = 0; + + if(dx1 && dx2){ + mat[0][0] = e->V[1]->Pos.X - e->V[0]->Pos.X; + mat[0][1] = v1->Pos.X - v2->Pos.X; + b[0] = - e->V[0]->Pos.X + v1->Pos.X; + if(dy1 || dy2){ + mat[1][0] = e->V[1]->Pos.Y - e->V[0]->Pos.Y; + mat[1][1] = v1->Pos.Y - v2->Pos.Y; + b[1] = - e->V[0]->Pos.Y + v1->Pos.Y; + dir = 2; + } + else if(dz1 || dz2){ + mat[1][0] = e->V[1]->Pos.Z - e->V[0]->Pos.Z; + mat[1][1] = v1->Pos.Z - v2->Pos.Z; + b[1] = - e->V[0]->Pos.Z + v1->Pos.Z; + dir = 3; + } + } + else if (dy1 && dy2){ + mat[0][0] = e->V[1]->Pos.Y - e->V[0]->Pos.Y; + mat[0][1] = v1->Pos.Y - v2->Pos.Y; + b[0] = - e->V[0]->Pos.Y + v1->Pos.Y; + if(dy1 || dy2){ + mat[1][0] = e->V[1]->Pos.Y - e->V[0]->Pos.Y; + mat[1][1] = v1->Pos.Y - v2->Pos.Y; + b[1] = - e->V[0]->Pos.Y + v1->Pos.Y; + dir = 2; + } + else if(dz1 || dz2){ + mat[1][0] = e->V[1]->Pos.Z - e->V[0]->Pos.Z; + mat[1][1] = v1->Pos.Z - v2->Pos.Z; + b[1] = - e->V[0]->Pos.Z + v1->Pos.Z; + dir = 3; + } + } + */ mat[0][0] = e->V[1]->Pos.X - e->V[0]->Pos.X; @@ -703,47 +742,47 @@ Vertex *Edge_Edge (Edge * e, Vertex * v1, Vertex * v2){ mat[1][1] = v1->Pos.Y - v2->Pos.Y; b[1] = -e->V[0]->Pos.Y + v1->Pos.Y; - if (!sys2x2 (mat, b, res)){ + if(!sys2x2(mat, b, res)) { mat[1][0] = e->V[1]->Pos.Z - e->V[0]->Pos.Z; mat[1][1] = v1->Pos.Z - v2->Pos.Z; b[1] = -e->V[0]->Pos.Z + v1->Pos.Z; - if (!sys2x2 (mat, b, res)){ + if(!sys2x2(mat, b, res)) { mat[0][0] = e->V[1]->Pos.Y - e->V[0]->Pos.Y; mat[0][1] = v1->Pos.Y - v2->Pos.Y; b[0] = -e->V[0]->Pos.Y + v1->Pos.Y; - if (!sys2x2 (mat, b, res)){ + if(!sys2x2(mat, b, res)) { /* SEGMENTS PARALLELES */ /* printf("systeme singulier\n"); printf("arete %d -> %d\n",v1->Num,v2->Num); printf("arete %g %g %g --> %g %g %g\n", - v1->Pos.X,v1->Pos.Y,v1->Pos.Z,v2->Pos.X,v2->Pos.Y,v2->Pos.Z); + v1->Pos.X,v1->Pos.Y,v1->Pos.Z,v2->Pos.X,v2->Pos.Y,v2->Pos.Z); printf("arete %g %g %g --> %g %g %g\n", - e->V[0]->Pos.X,e->V[0]->Pos.Y,e->V[0]->Pos.Z, - e->V[1]->Pos.X,e->V[1]->Pos.Y,e->V[1]->Pos.Z); + e->V[0]->Pos.X,e->V[0]->Pos.Y,e->V[0]->Pos.Z, + e->V[1]->Pos.X,e->V[1]->Pos.Y,e->V[1]->Pos.Z); printf("%g %g\n",mat[0][0],mat[0][1]); printf("%g %g\n",mat[1][0],mat[1][1]); getchar(); - */ + */ return NULL; } - else{ + else { dir = 1; } } - else{ + else { dir = 2; } } - else{ + else { dir = 3; } - - if (res[0] <= eps_prec || res[0] >= 1.0 - eps_prec) + + if(res[0] <= eps_prec || res[0] >= 1.0 - eps_prec) return NULL; - if (res[1] <= eps_prec || res[1] >= 1.0 - eps_prec) + if(res[1] <= eps_prec || res[1] >= 1.0 - eps_prec) return NULL; - switch (dir){ + switch (dir) { case 1: val = e->V[0]->Pos.X * (1. - res[0]) + e->V[1]->Pos.X * res[0] - v1->Pos.X * (1. - res[1]) - v2->Pos.X * res[1]; @@ -757,54 +796,55 @@ Vertex *Edge_Edge (Edge * e, Vertex * v1, Vertex * v2){ v1->Pos.Z * (1. - res[1]) - v2->Pos.Z * res[1]; break; } - if (fabs (val / lc) > 1.e-08 /*08 */ ) + if(fabs(val / lc) > 1.e-08 /*08 */ ) return NULL; - v = Create_Vertex (++THEM->MaxPointNum, - (1. - res[0]) * e->V[0]->Pos.X + res[0] * e->V[1]->Pos.X, - (1. - res[0]) * e->V[0]->Pos.Y + res[0] * e->V[1]->Pos.Y, - (1. - res[0]) * e->V[0]->Pos.Z + res[0] * e->V[1]->Pos.Z, - (1. - res[0]) * e->V[0]->lc + res[0] * e->V[1]->lc, 0.0); - - v->ListSurf = List_Create (1, 1, sizeof (Surface *)); + v = Create_Vertex(++THEM->MaxPointNum, + (1. - res[0]) * e->V[0]->Pos.X + res[0] * e->V[1]->Pos.X, + (1. - res[0]) * e->V[0]->Pos.Y + res[0] * e->V[1]->Pos.Y, + (1. - res[0]) * e->V[0]->Pos.Z + res[0] * e->V[1]->Pos.Z, + (1. - res[0]) * e->V[0]->lc + res[0] * e->V[1]->lc, 0.0); + + v->ListSurf = List_Create(1, 1, sizeof(Surface *)); return v; } -int intersection_2_aretes (double Xa, double Ya, double Za, - double Xb, double Yb, double Zb, - double Xc, double Yc, double Zc, - double Xd, double Yd, double Zd, - int p1, int p2, int p3, int p4, - double *X, double *Y, double *Z){ +int intersection_2_aretes(double Xa, double Ya, double Za, + double Xb, double Yb, double Zb, + double Xc, double Yc, double Zc, + double Xd, double Yd, double Zd, + int p1, int p2, int p3, int p4, + double *X, double *Y, double *Z) +{ Vertex *v1, *v2, *v3, *v4, *v; Edge e; - v1 = Create_Vertex (p1, Xa, Ya, Za, 0.0, 0.0); - v2 = Create_Vertex (p2, Xb, Yb, Zb, 0.0, 0.0); - v3 = Create_Vertex (p3, Xc, Yc, Zc, 0.0, 0.0); - v4 = Create_Vertex (p4, Xd, Yd, Zd, 0.0, 0.0); + v1 = Create_Vertex(p1, Xa, Ya, Za, 0.0, 0.0); + v2 = Create_Vertex(p2, Xb, Yb, Zb, 0.0, 0.0); + v3 = Create_Vertex(p3, Xc, Yc, Zc, 0.0, 0.0); + v4 = Create_Vertex(p4, Xd, Yd, Zd, 0.0, 0.0); e.V[0] = v3; e.V[1] = v4; - if ((v = Edge_Edge (&e, v1, v2))){ - + if((v = Edge_Edge(&e, v1, v2))) { + *X = v->Pos.X; *Y = v->Pos.Y; *Z = v->Pos.Z; - Free (v1); - Free (v2); - Free (v3); - Free (v4); - Free (v); + Free(v1); + Free(v2); + Free(v3); + Free(v4); + Free(v); return 1; } - else{ - Free (v1); - Free (v2); - Free (v3); - Free (v4); - Free (v); + else { + Free(v1); + Free(v2); + Free(v3); + Free(v4); + Free(v); return 0; } @@ -812,9 +852,9 @@ int intersection_2_aretes (double Xa, double Ya, double Za, List_T *NewPoints; -void Intersect_Edge_Simplexe (Edge * e, Simplex * s, Intersection * I){ - - int i, NbInt=0, NbVer=0, NbEdg=0, NbFac=0, j; +void Intersect_Edge_Simplexe(Edge * e, Simplex * s, Intersection * I) +{ + int i, NbInt = 0, NbVer = 0, NbEdg = 0, NbFac = 0, j; Vertex *v; double XminS, YminS, ZminS, XmaxS, YmaxS, ZmaxS; double XminE, YminE, ZminE, XmaxE, YmaxE, ZmaxE; @@ -828,29 +868,29 @@ void Intersect_Edge_Simplexe (Edge * e, Simplex * s, Intersection * I){ I->NbIntersect = 0; /* - On regarde d'abord si une intersection est possible en - calculant les boites de l'arete et du simplexe - */ + On regarde d'abord si une intersection est possible en + calculant les boites de l'arete et du simplexe + */ - if (s->V[3]){ + if(s->V[3]) { NbVer = 4; NbEdg = 6; NbFac = 4; NbInt = 2; } - else if (s->V[2]){ + else if(s->V[2]) { NbVer = 3; NbEdg = 3; NbFac = 1; NbInt = 2; } - - XminE = DMIN (e->V[0]->Pos.X, e->V[1]->Pos.X); - XmaxE = DMAX (e->V[0]->Pos.X, e->V[1]->Pos.X); - YminE = DMIN (e->V[0]->Pos.Y, e->V[1]->Pos.Y); - YmaxE = DMAX (e->V[0]->Pos.Y, e->V[1]->Pos.Y); - ZminE = DMIN (e->V[0]->Pos.Z, e->V[1]->Pos.Z); - ZmaxE = DMAX (e->V[0]->Pos.Z, e->V[1]->Pos.Z); + + XminE = DMIN(e->V[0]->Pos.X, e->V[1]->Pos.X); + XmaxE = DMAX(e->V[0]->Pos.X, e->V[1]->Pos.X); + YminE = DMIN(e->V[0]->Pos.Y, e->V[1]->Pos.Y); + YmaxE = DMAX(e->V[0]->Pos.Y, e->V[1]->Pos.Y); + ZminE = DMIN(e->V[0]->Pos.Z, e->V[1]->Pos.Z); + ZmaxE = DMAX(e->V[0]->Pos.Z, e->V[1]->Pos.Z); XminS = s->V[0]->Pos.X; XmaxS = s->V[0]->Pos.X; @@ -859,99 +899,99 @@ void Intersect_Edge_Simplexe (Edge * e, Simplex * s, Intersection * I){ ZminS = s->V[0]->Pos.Z; ZmaxS = s->V[0]->Pos.Z; - for (i = 1; i < NbVer; i++){ - XminS = DMIN (XminS, s->V[i]->Pos.X); - XmaxS = DMAX (XmaxS, s->V[i]->Pos.X); - YminS = DMIN (YminS, s->V[i]->Pos.Y); - YmaxS = DMAX (YmaxS, s->V[i]->Pos.Y); - ZminS = DMIN (ZminS, s->V[i]->Pos.Z); - ZmaxS = DMAX (ZmaxS, s->V[i]->Pos.Z); + for(i = 1; i < NbVer; i++) { + XminS = DMIN(XminS, s->V[i]->Pos.X); + XmaxS = DMAX(XmaxS, s->V[i]->Pos.X); + YminS = DMIN(YminS, s->V[i]->Pos.Y); + YmaxS = DMAX(YmaxS, s->V[i]->Pos.Y); + ZminS = DMIN(ZminS, s->V[i]->Pos.Z); + ZmaxS = DMAX(ZmaxS, s->V[i]->Pos.Z); } - if (XmaxS < XminE || XmaxE < XminS) + if(XmaxS < XminE || XmaxE < XminS) return; - if (YmaxS < YminE || YmaxE < YminS) + if(YmaxS < YminE || YmaxE < YminS) return; - if (ZmaxS < ZminE || ZmaxE < ZminS) + if(ZmaxS < ZminE || ZmaxE < ZminS) return; /* - On regarde si l'arete coupe un des 4 noeuds du - simplexe - */ + On regarde si l'arete coupe un des 4 noeuds du + simplexe + */ - for (i = 0; i < NbVer; i++){ - if ((j = Edge_Node (e, s->V[i]))){ + for(i = 0; i < NbVer; i++) { + if((j = Edge_Node(e, s->V[i]))) { I->V[I->NbVertex] = s->V[i]; I->iV[I->NbVertex++] = i; (I->NbIntersect)++; - if (j == 2){ - List_Replace (NewPoints, &s->V[i], compareVertex); - //printf("l'arete intersecte un noeud\n"); - pvertex (s->V[i], s->V[i]); - pedge (e, e); + if(j == 2) { + List_Replace(NewPoints, &s->V[i], compareVertex); + //printf("l'arete intersecte un noeud\n"); + pvertex(s->V[i], s->V[i]); + pedge(e, e); } } } - if (I->NbIntersect == NbInt){ + if(I->NbIntersect == NbInt) { Msg(WARNING, "If the mesh is still correct after this, contact us :-)"); return; } /* On regarde si l'arete coupe une autre arete */ - for (i = 0; i < NbEdg; i++){ + for(i = 0; i < NbEdg; i++) { x.ef = 1; x.e.V[0] = s->V[edges_tetra[i][0]]; x.e.V[1] = s->V[edges_tetra[i][1]]; - if (Tree_Query (TreexNewv, &x)){ + if(Tree_Query(TreexNewv, &x)) { v = x.newv; I->E[I->NbEdge] = i; I->VE[(I->NbEdge)++] = v; (I->NbIntersect)++; } - else if ((v = Edge_Edge (e, s->V[edges_tetra[i][0]], - s->V[edges_tetra[i][1]]))) { - List_Add (NewPoints, &v); + else if((v = Edge_Edge(e, s->V[edges_tetra[i][0]], + s->V[edges_tetra[i][1]]))) { + List_Add(NewPoints, &v); I->E[I->NbEdge] = i; I->VE[(I->NbEdge)++] = v; (I->NbIntersect)++; x.newv = v; - Tree_Add (TreexNewv, &x); + Tree_Add(TreexNewv, &x); } } - - if (I->NbIntersect == NbInt) + + if(I->NbIntersect == NbInt) return; /* - On regarde si l'arete coupe une face - */ + On regarde si l'arete coupe une face + */ - for (i = 0; i < NbFac; i++){ + for(i = 0; i < NbFac; i++) { x.ef = 2; x.f = &s->F[i]; - if (Tree_Query (TreexNewv, &x)){ + if(Tree_Query(TreexNewv, &x)) { v = x.newv; I->VF[I->NbFace] = v; I->F[I->NbFace] = &s->F[i]; I->iF[(I->NbFace)++] = i; (I->NbIntersect)++; } - else if ((v = Edge_Face (e, &s->F[i]))){ + else if((v = Edge_Face(e, &s->F[i]))) { I->VF[I->NbFace] = v; - List_Add (NewPoints, &v); + List_Add(NewPoints, &v); I->F[I->NbFace] = &s->F[i]; I->iF[I->NbFace++] = i; (I->NbIntersect)++; x.newv = v; - Tree_Add (TreexNewv, &x); + Tree_Add(TreexNewv, &x); } } } -void Intersect_Face_Simplexe (Face * f, Simplex * s, Intersection * I){ - - int i ; +void Intersect_Face_Simplexe(Face * f, Simplex * s, Intersection * I) +{ + int i; Vertex *v; double XminS, YminS, ZminS, XmaxS, YmaxS, ZmaxS; double XminE, YminE, ZminE, XmaxE, YmaxE, ZmaxE; @@ -965,16 +1005,16 @@ void Intersect_Face_Simplexe (Face * f, Simplex * s, Intersection * I){ I->NbIntersect = 0; /* - On regarde d'abord si une intersection est possible en - calculant les boites de l'arete et du simplexe - */ + On regarde d'abord si une intersection est possible en + calculant les boites de l'arete et du simplexe + */ - XminE = DMIN (DMIN (f->V[0]->Pos.X, f->V[1]->Pos.X), f->V[2]->Pos.X); - XmaxE = DMAX (DMAX (f->V[0]->Pos.X, f->V[1]->Pos.X), f->V[2]->Pos.X); - YminE = DMIN (DMIN (f->V[0]->Pos.Y, f->V[1]->Pos.Y), f->V[2]->Pos.Y); - YmaxE = DMAX (DMAX (f->V[0]->Pos.Y, f->V[1]->Pos.Y), f->V[2]->Pos.Y); - ZminE = DMIN (DMIN (f->V[0]->Pos.Z, f->V[1]->Pos.Z), f->V[2]->Pos.Z); - ZmaxE = DMAX (DMAX (f->V[0]->Pos.Z, f->V[1]->Pos.Z), f->V[2]->Pos.Z); + XminE = DMIN(DMIN(f->V[0]->Pos.X, f->V[1]->Pos.X), f->V[2]->Pos.X); + XmaxE = DMAX(DMAX(f->V[0]->Pos.X, f->V[1]->Pos.X), f->V[2]->Pos.X); + YminE = DMIN(DMIN(f->V[0]->Pos.Y, f->V[1]->Pos.Y), f->V[2]->Pos.Y); + YmaxE = DMAX(DMAX(f->V[0]->Pos.Y, f->V[1]->Pos.Y), f->V[2]->Pos.Y); + ZminE = DMIN(DMIN(f->V[0]->Pos.Z, f->V[1]->Pos.Z), f->V[2]->Pos.Z); + ZmaxE = DMAX(DMAX(f->V[0]->Pos.Z, f->V[1]->Pos.Z), f->V[2]->Pos.Z); XminS = s->V[0]->Pos.X; XmaxS = s->V[0]->Pos.X; @@ -983,148 +1023,156 @@ void Intersect_Face_Simplexe (Face * f, Simplex * s, Intersection * I){ ZminS = s->V[0]->Pos.Z; ZmaxS = s->V[0]->Pos.Z; - for (i = 1; i < 4; i++){ - XminS = DMIN (XminS, s->V[i]->Pos.X); - XmaxS = DMAX (XmaxS, s->V[i]->Pos.X); - YminS = DMIN (YminS, s->V[i]->Pos.Y); - YmaxS = DMAX (YmaxS, s->V[i]->Pos.Y); - ZminS = DMIN (ZminS, s->V[i]->Pos.Z); - ZmaxS = DMAX (ZmaxS, s->V[i]->Pos.Z); + for(i = 1; i < 4; i++) { + XminS = DMIN(XminS, s->V[i]->Pos.X); + XmaxS = DMAX(XmaxS, s->V[i]->Pos.X); + YminS = DMIN(YminS, s->V[i]->Pos.Y); + YmaxS = DMAX(YmaxS, s->V[i]->Pos.Y); + ZminS = DMIN(ZminS, s->V[i]->Pos.Z); + ZmaxS = DMAX(ZmaxS, s->V[i]->Pos.Z); } - if (XmaxS < XminE || XmaxE < XminS) + if(XmaxS < XminE || XmaxE < XminS) return; - if (YmaxS < YminE || YmaxE < YminS) + if(YmaxS < YminE || YmaxE < YminS) return; - if (ZmaxS < ZminE || ZmaxE < ZminS) + if(ZmaxS < ZminE || ZmaxE < ZminS) return; /* On regarde si l'arete coupe la facette */ - for (i = 0; i < 6; i++){ + for(i = 0; i < 6; i++) { x.ef = 1; x.e.V[0] = s->V[edges_tetra[i][0]]; x.e.V[1] = s->V[edges_tetra[i][1]]; - if (Tree_Query (TreexNewv, &x)){ + if(Tree_Query(TreexNewv, &x)) { v = x.newv; I->E[I->NbEdge] = i; I->VE[(I->NbEdge)++] = v; (I->NbIntersect)++; } - else if ((v = Edge_Face (&x.e, f))){ + else if((v = Edge_Face(&x.e, f))) { /* printf("%d %d %d %d\n",s->V[0]->Num,s->V[1]->Num,s->V[2]->Num,s->V[3]->Num); */ - List_Add (NewPoints, &v); + List_Add(NewPoints, &v); I->E[I->NbEdge] = i; I->VE[I->NbEdge] = v; (I->NbEdge)++; (I->NbIntersect)++; x.newv = v; - Tree_Add (TreexNewv, &x); + Tree_Add(TreexNewv, &x); } } } Tree_T *Actual_Tree, *TetAdd, *TetDel; -static void _Add (void *data, void *dum){ - Tree_Add (Actual_Tree, data); +static void _Add(void *data, void *dum) +{ + Tree_Add(Actual_Tree, data); } -static void _Del (void *data, void *dum){ - Tree_Suppress (Actual_Tree, data); +static void _Del(void *data, void *dum) +{ + Tree_Suppress(Actual_Tree, data); } -void Recover_Edge (void *a, void *b){ +void Recover_Edge(void *a, void *b) +{ Simplex *s; Intersection I; s = *(Simplex **) a; - Intersect_Edge_Simplexe (TheEdge, s, &I); - if (I.NbIntersect){ - cut_tetraedre (&I, TetAdd, TetDel, THEVOL->Vertices); + Intersect_Edge_Simplexe(TheEdge, s, &I); + if(I.NbIntersect) { + cut_tetraedre(&I, TetAdd, TetDel, THEVOL->Vertices); } } -void Recover_Face (void *a, void *b){ +void Recover_Face(void *a, void *b) +{ Simplex *s; Intersection I; s = *(Simplex **) a; - Intersect_Face_Simplexe (TheFace, s, &I); - if (I.NbEdge){ - cut_tetraedre (&I, TetAdd, TetDel, THEVOL->Vertices); + Intersect_Face_Simplexe(TheFace, s, &I); + if(I.NbEdge) { + cut_tetraedre(&I, TetAdd, TetDel, THEVOL->Vertices); } } static double volume; -static void VSIM (void *a, void *b){ +static void VSIM(void *a, void *b) +{ Simplex *S; S = *(Simplex **) a; - if (S->V[3]) - volume += fabs (S->Volume_Simplexe ()); + if(S->V[3]) + volume += fabs(S->Volume_Simplexe()); } Vertex *DEPART; -int comparePos (const void *a, const void *b){ +int comparePos(const void *a, const void *b) +{ Vertex *q, *w; double d1, d2; q = *(Vertex **) a; w = *(Vertex **) b; - d1 = DSQR (q->Pos.X - DEPART->Pos.X) + - DSQR (q->Pos.Y - DEPART->Pos.Y) + - DSQR (q->Pos.Z - DEPART->Pos.Z); - d2 = DSQR (w->Pos.X - DEPART->Pos.X) + - DSQR (w->Pos.Y - DEPART->Pos.Y) + - DSQR (w->Pos.Z - DEPART->Pos.Z); - if (d1 < d2) + d1 = DSQR(q->Pos.X - DEPART->Pos.X) + + DSQR(q->Pos.Y - DEPART->Pos.Y) + DSQR(q->Pos.Z - DEPART->Pos.Z); + d2 = DSQR(w->Pos.X - DEPART->Pos.X) + + DSQR(w->Pos.Y - DEPART->Pos.Y) + DSQR(w->Pos.Z - DEPART->Pos.Z); + if(d1 < d2) return 1; - if (d1 > d2) + if(d1 > d2) return -1; - exit (1); + exit(1); return 1; } List_T *ListFaces; -void findFaces (void *a, void *b){ +void findFaces(void *a, void *b) +{ Simplex *s; int i; s = *(Simplex **) a; - if (List_Search (NewPoints, &s->V[0], compareVertex) || - List_Search (NewPoints, &s->V[1], compareVertex) || - List_Search (NewPoints, &s->V[2], compareVertex) || - List_Search (NewPoints, &s->V[3], compareVertex)) + if(List_Search(NewPoints, &s->V[0], compareVertex) || + List_Search(NewPoints, &s->V[1], compareVertex) || + List_Search(NewPoints, &s->V[2], compareVertex) || + List_Search(NewPoints, &s->V[3], compareVertex)) /* - printf("%d %d %d %d\n",s->V[0]->Num,s->V[1]->Num,s->V[2]->Num,s->V[3]->Num); - */ - for (i = 0; i < 4; i++){ - if (List_Search (NewPoints, &s->F[i].V[0], compareVertex) && - List_Search (NewPoints, &s->F[i].V[1], compareVertex) && - List_Search (NewPoints, &s->F[i].V[2], compareVertex)) - List_Replace (ListFaces, &s->F[i], compareFace); + printf("%d %d %d %d\n",s->V[0]->Num,s->V[1]->Num,s->V[2]->Num,s->V[3]->Num); + */ + for(i = 0; i < 4; i++) { + if(List_Search(NewPoints, &s->F[i].V[0], compareVertex) && + List_Search(NewPoints, &s->F[i].V[1], compareVertex) && + List_Search(NewPoints, &s->F[i].V[2], compareVertex)) + List_Replace(ListFaces, &s->F[i], compareFace); } } -void findEdges (void *a, void *b){ +void findEdges(void *a, void *b) +{ } -Simplex * Create_Simplex_MemeSens (Simplex * sold, Vertex * v1, Vertex * v2, Vertex * v3){ - +Simplex *Create_Simplex_MemeSens(Simplex * sold, Vertex * v1, Vertex * v2, + Vertex * v3) +{ Simplex *s; - if (memesens (sold->V[0], sold->V[1], sold->V[2], v1, v2, v3) > 0.0){ - s = Create_Simplex (v1, v2, v3, NULL); + if(memesens(sold->V[0], sold->V[1], sold->V[2], v1, v2, v3) > 0.0) { + s = Create_Simplex(v1, v2, v3, NULL); } - else{ - s = Create_Simplex (v2, v1, v3, NULL); + else { + s = Create_Simplex(v2, v1, v3, NULL); } s->iEnt = sold->iEnt; return s; } -int Coherence (Volume * v, Mesh * m){ - int i, j, k, Np, Nh, nb_swaps=0; +int Coherence(Volume * v, Mesh * m) +{ + int i, j, k, Np, Nh, nb_swaps = 0; Surface *s; //Vertex V1, V2, *ver1, *ver2 ; Face Face; @@ -1139,210 +1187,215 @@ int Coherence (Volume * v, Mesh * m){ THEVOL = v; - Remise_A_Zero (); + Remise_A_Zero(); /* Edge Swapping */ - do{ - create_Edges (v); - MissingEdges = Missing_Edges (v); - nb_swaps = create_Quads (v); + do { + create_Edges(v); + MissingEdges = Missing_Edges(v); + nb_swaps = create_Quads(v); Msg(INFO, "Swapped %d edges", nb_swaps); } while(nb_swaps); /* Missing Edges */ - create_Edges (v); - MissingEdges = Missing_Edges (v); + create_Edges(v); + MissingEdges = Missing_Edges(v); /* Missing Faces */ - create_Faces (v); - MissingFaces = Missing_Faces (v); + create_Faces(v); + MissingFaces = Missing_Faces(v); /* Edges Recovery */ Msg(STATUS3, "Boundary edges recovery"); volume = 0; - Tree_Action (v->Simplexes, VSIM); + Tree_Action(v->Simplexes, VSIM); Msg(INFO, "Volume = %g", volume); Msg(INFO1, "==================================================="); - Msg(INFO2, "Number of missing edges = %d", List_Nbr (Missing)); + Msg(INFO2, "Number of missing edges = %d", List_Nbr(Missing)); Msg(INFO3, "==================================================="); - for (i = 0; i < List_Nbr (Missing); i++){ - - pE1 = (Edge *) List_Pointer (Missing, i); + for(i = 0; i < List_Nbr(Missing); i++) { + + pE1 = (Edge *) List_Pointer(Missing, i); TheEdge = pE1; - - TreexNewv = Tree_Create (sizeof (xNewv), compxNewv); - NewPoints = List_Create (1, 1, sizeof (Vertex *)); - TetAdd = Tree_Create (sizeof (Simplex *), compareSimplex); - TetDel = Tree_Create (sizeof (Simplex *), compareSimplex); - - Tree_Action (v->Simplexes, Recover_Edge); + + TreexNewv = Tree_Create(sizeof(xNewv), compxNewv); + NewPoints = List_Create(1, 1, sizeof(Vertex *)); + TetAdd = Tree_Create(sizeof(Simplex *), compareSimplex); + TetDel = Tree_Create(sizeof(Simplex *), compareSimplex); + + Tree_Action(v->Simplexes, Recover_Edge); Actual_Tree = v->Simplexes; - Tree_Action (TetAdd, _Add); - Tree_Action (TetDel, _Del); + Tree_Action(TetAdd, _Add); + Tree_Action(TetDel, _Del); pE1->Liste = NewPoints; /* - if(CTX.mesh.nb_smoothing){ - DEPART = pE1->V[0]; - List_Tri(NewPoints,comparePos); - for(j=0;j<List_Nbr(NewPoints);j++){ - List_Read(NewPoints,j,&ver1); - u = (double)(j+1) / (double)(List_Nbr(NewPoints)+1); - ver1->Pos.X = u * pE1->V[1]->Pos.X + (1.-u) * pE1->V[0]->Pos.X; - ver1->Pos.Y = u * pE1->V[1]->Pos.Y + (1.-u) * pE1->V[0]->Pos.Y; - ver1->Pos.Z = u * pE1->V[1]->Pos.Z + (1.-u) * pE1->V[0]->Pos.Z; - } - } - */ - Msg(INFO, "%d/%d: Edge %d->%d => %d division(s)", - i+1, List_Nbr(Missing), pE1->V[0]->Num, pE1->V[1]->Num, - List_Nbr(NewPoints)); - - if (!List_Nbr (NewPoints)) - Msg(GERROR, "Missing edge without any intersection (%g,%g,%g) (%g,%g,%g)", + if(CTX.mesh.nb_smoothing){ + DEPART = pE1->V[0]; + List_Tri(NewPoints,comparePos); + for(j=0;j<List_Nbr(NewPoints);j++){ + List_Read(NewPoints,j,&ver1); + u = (double)(j+1) / (double)(List_Nbr(NewPoints)+1); + ver1->Pos.X = u * pE1->V[1]->Pos.X + (1.-u) * pE1->V[0]->Pos.X; + ver1->Pos.Y = u * pE1->V[1]->Pos.Y + (1.-u) * pE1->V[0]->Pos.Y; + ver1->Pos.Z = u * pE1->V[1]->Pos.Z + (1.-u) * pE1->V[0]->Pos.Z; + } + } + */ + Msg(INFO, "%d/%d: Edge %d->%d => %d division(s)", + i + 1, List_Nbr(Missing), pE1->V[0]->Num, pE1->V[1]->Num, + List_Nbr(NewPoints)); + + if(!List_Nbr(NewPoints)) + Msg(GERROR, + "Missing edge without any intersection (%g,%g,%g) (%g,%g,%g)", pE1->V[0]->Pos.X, pE1->V[0]->Pos.Y, pE1->V[0]->Pos.Z, pE1->V[1]->Pos.X, pE1->V[1]->Pos.Y, pE1->V[1]->Pos.Z); - + } Msg(STATUS3, "Boundary faces recovery"); volume = 0; - Tree_Action (v->Simplexes, VSIM); + Tree_Action(v->Simplexes, VSIM); Msg(INFO, "Volume = %g", volume); /* Missing Faces */ Msg(INFO1, "==================================================="); - Msg(INFO2, "Number of missing faces = %d", List_Nbr (MissingFaces)); + Msg(INFO2, "Number of missing faces = %d", List_Nbr(MissingFaces)); Msg(INFO3, "==================================================="); - for (i = 0; i < List_Nbr (MissingS); i++){ - List_Read (MissingS, i, &simp); + for(i = 0; i < List_Nbr(MissingS); i++) { + List_Read(MissingS, i, &simp); TheFace = &simp->F[0]; - Msg(INFO, "%d/%d: Face %d %d %d", - i+1, List_Nbr (MissingS), simp->F[0].V[0]->Num, + Msg(INFO, "%d/%d: Face %d %d %d", + i + 1, List_Nbr(MissingS), simp->F[0].V[0]->Num, simp->F[0].V[1]->Num, simp->F[0].V[2]->Num); E.V[0] = simp->F[0].V[0]; E.V[1] = simp->F[0].V[1]; - pE1 = (Edge *) List_PQuery (Missing, &E, compareedge); + pE1 = (Edge *) List_PQuery(Missing, &E, compareedge); E.V[0] = simp->F[0].V[1]; E.V[1] = simp->F[0].V[2]; - pE2 = (Edge *) List_PQuery (Missing, &E, compareedge); + pE2 = (Edge *) List_PQuery(Missing, &E, compareedge); E.V[0] = simp->F[0].V[2]; E.V[1] = simp->F[0].V[0]; - pE3 = (Edge *) List_PQuery (Missing, &E, compareedge); + pE3 = (Edge *) List_PQuery(Missing, &E, compareedge); /* On verifie si c'est simple c a d si les tetraedres couvrent entierement la face */ - NewPoints = List_Create (3, 1, sizeof (Vertex *)); - List_Add (NewPoints, &simp->F[0].V[0]); - if (pE1) - for (j = 0; j < List_Nbr (pE1->Liste); j++) - List_Add (NewPoints, List_Pointer (pE1->Liste, j)); - List_Add (NewPoints, &simp->F[0].V[1]); - if (pE2) - for (j = 0; j < List_Nbr (pE2->Liste); j++) - List_Add (NewPoints, List_Pointer (pE2->Liste, j)); - List_Add (NewPoints, &simp->F[0].V[2]); - if (pE3) - for (j = 0; j < List_Nbr (pE3->Liste); j++) - List_Add (NewPoints, List_Pointer (pE3->Liste, j)); - ListFaces = List_Create (2, 2, sizeof (Face)); - Tree_Action (v->Simplexes, findFaces); - - Nh = List_Nbr (NewPoints); - + NewPoints = List_Create(3, 1, sizeof(Vertex *)); + List_Add(NewPoints, &simp->F[0].V[0]); + if(pE1) + for(j = 0; j < List_Nbr(pE1->Liste); j++) + List_Add(NewPoints, List_Pointer(pE1->Liste, j)); + List_Add(NewPoints, &simp->F[0].V[1]); + if(pE2) + for(j = 0; j < List_Nbr(pE2->Liste); j++) + List_Add(NewPoints, List_Pointer(pE2->Liste, j)); + List_Add(NewPoints, &simp->F[0].V[2]); + if(pE3) + for(j = 0; j < List_Nbr(pE3->Liste); j++) + List_Add(NewPoints, List_Pointer(pE3->Liste, j)); + ListFaces = List_Create(2, 2, sizeof(Face)); + Tree_Action(v->Simplexes, findFaces); + + Nh = List_Nbr(NewPoints); + /* il reste des intersections */ - if (List_Nbr (ListFaces) != Nh - 2){ - - Msg(INFO, "Intersections left (the face contains %d initial faces, divided in %d points)", - List_Nbr(ListFaces), List_Nbr(NewPoints)); - - TreexNewv = Tree_Create (sizeof (xNewv), compxNewv); - TetAdd = Tree_Create (sizeof (Simplex *), compareSimplex); - TetDel = Tree_Create (sizeof (Simplex *), compareSimplex); - Tree_Action (v->Simplexes, Recover_Face); + if(List_Nbr(ListFaces) != Nh - 2) { + + Msg(INFO, + "Intersections left (the face contains %d initial faces, divided in %d points)", + List_Nbr(ListFaces), List_Nbr(NewPoints)); - Msg(INFO, "The face is divided in %d points (simplexes added=%d, deleted=%d)", - List_Nbr(NewPoints),Tree_Nbr(TetAdd),Tree_Nbr(TetDel)); + TreexNewv = Tree_Create(sizeof(xNewv), compxNewv); + TetAdd = Tree_Create(sizeof(Simplex *), compareSimplex); + TetDel = Tree_Create(sizeof(Simplex *), compareSimplex); + Tree_Action(v->Simplexes, Recover_Face); + + Msg(INFO, + "The face is divided in %d points (simplexes added=%d, deleted=%d)", + List_Nbr(NewPoints), Tree_Nbr(TetAdd), Tree_Nbr(TetDel)); Actual_Tree = v->Simplexes; - Tree_Action (TetAdd, _Add); - Tree_Action (TetDel, _Del); - ListFaces = List_Create (2, 2, sizeof (Face)); - Tree_Action (v->Simplexes, findFaces); + Tree_Action(TetAdd, _Add); + Tree_Action(TetDel, _Del); + ListFaces = List_Create(2, 2, sizeof(Face)); + Tree_Action(v->Simplexes, findFaces); } - Np = List_Nbr (NewPoints); + Np = List_Nbr(NewPoints); - if (1 || List_Nbr (ListFaces) == 2 * (Np - 1) - Nh){ + if(1 || List_Nbr(ListFaces) == 2 * (Np - 1) - Nh) { // provisoire!!! - if (List_Nbr (ListFaces) != 2 * (Np - 1) - Nh){ - Msg(WARNING, "*Unrecoverable* face (%d <--> %d=2*(%d-1)-%d)", - List_Nbr(ListFaces), 2 * (Np - 1) - Nh, Np, Nh); + if(List_Nbr(ListFaces) != 2 * (Np - 1) - Nh) { + Msg(WARNING, "*Unrecoverable* face (%d <--> %d=2*(%d-1)-%d)", + List_Nbr(ListFaces), 2 * (Np - 1) - Nh, Np, Nh); } else - Msg(INFO, "Recoverable face (%d <--> %d=2*(%d-1)-%d)", - List_Nbr(ListFaces), 2 * (Np - 1) - Nh, Np, Nh); - - for (j = 0; j < List_Nbr (v->Surfaces); j++){ - List_Read (v->Surfaces, j, &s); - if (Tree_Search (s->Simplexes, &simp)){ - for (k = 0; k < List_Nbr (ListFaces); k++){ - List_Read (ListFaces, k, &Face); - simp1 = Create_Simplex_MemeSens (simp, Face.V[0], Face.V[1], Face.V[2]); - Tree_Add (s->Simplexes, &simp1); - Tree_Replace (s->Vertices, &Face.V[0]); - Tree_Replace (s->Vertices, &Face.V[1]); - Tree_Replace (s->Vertices, &Face.V[2]); - Tree_Replace (v->Vertices, &Face.V[0]); - Tree_Replace (v->Vertices, &Face.V[1]); - Tree_Replace (v->Vertices, &Face.V[2]); + Msg(INFO, "Recoverable face (%d <--> %d=2*(%d-1)-%d)", + List_Nbr(ListFaces), 2 * (Np - 1) - Nh, Np, Nh); + + for(j = 0; j < List_Nbr(v->Surfaces); j++) { + List_Read(v->Surfaces, j, &s); + if(Tree_Search(s->Simplexes, &simp)) { + for(k = 0; k < List_Nbr(ListFaces); k++) { + List_Read(ListFaces, k, &Face); + simp1 = + Create_Simplex_MemeSens(simp, Face.V[0], Face.V[1], Face.V[2]); + Tree_Add(s->Simplexes, &simp1); + Tree_Replace(s->Vertices, &Face.V[0]); + Tree_Replace(s->Vertices, &Face.V[1]); + Tree_Replace(s->Vertices, &Face.V[2]); + Tree_Replace(v->Vertices, &Face.V[0]); + Tree_Replace(v->Vertices, &Face.V[1]); + Tree_Replace(v->Vertices, &Face.V[2]); } - Tree_Suppress (s->Simplexes, &simp); + Tree_Suppress(s->Simplexes, &simp); } } } - else{ + else { Msg(GERROR, "*Unrecoverable* face (%d <--> %d=2*(%d-1)-%d)", - List_Nbr (ListFaces), 2 * (Np - 1) - Nh, Np, Nh); - for (k = 0; k < List_Nbr (ListFaces); k++){ - List_Read (ListFaces, k, &Face); - Msg(STATUS2, "Face %d %d %d", Face.V[0]->Num, Face.V[1]->Num, Face.V[2]->Num); + List_Nbr(ListFaces), 2 * (Np - 1) - Nh, Np, Nh); + for(k = 0; k < List_Nbr(ListFaces); k++) { + List_Read(ListFaces, k, &Face); + Msg(STATUS2, "Face %d %d %d", Face.V[0]->Num, Face.V[1]->Num, + Face.V[2]->Num); } - Tree_Action (v->Simplexes, findEdges); + Tree_Action(v->Simplexes, findEdges); } } volume = 0; - Tree_Action (v->Simplexes, VSIM); + Tree_Action(v->Simplexes, VSIM); Msg(INFO, "Volume after edge/face recovery = %g", volume); /* Missing Edges */ - create_Edges (v); - MissingEdges = Missing_Edges (v); + create_Edges(v); + MissingEdges = Missing_Edges(v); /* Missing Faces */ - create_Faces (v); - MissingFaces = Missing_Faces (v); + create_Faces(v); + MissingFaces = Missing_Faces(v); - Msg(INFO, "Final check: %d missing edges, %d missing faces", + Msg(INFO, "Final check: %d missing edges, %d missing faces", List_Nbr(MissingEdges), List_Nbr(MissingFaces)); - Impression_Resultats (); + Impression_Resultats(); - if (List_Nbr (MissingFaces) || List_Nbr (MissingEdges)){ + if(List_Nbr(MissingFaces) || List_Nbr(MissingEdges)) { Msg(GERROR, "Could not restore all edges/faces"); return 0; } - Link_Simplexes (NULL, v->Simplexes); + Link_Simplexes(NULL, v->Simplexes); Msg(STATUS3, "Volume recovery"); - Restore_Volume (v); + Restore_Volume(v); return 1; } @@ -1356,183 +1409,192 @@ Tree_T *keep; Simplex *SIMP; int iVolume; -void attribueVolume (void *a, void *b){ +void attribueVolume(void *a, void *b) +{ Simplex *s; s = *(Simplex **) a; s->iEnt = iVolume; } -void Trouve_Simplex (void *a, void *b){ +void Trouve_Simplex(void *a, void *b) +{ Simplex *s; - if (SIMP != NULL) + if(SIMP != NULL) return; s = *(Simplex **) a; - if (s->iEnt < 0) + if(s->iEnt < 0) SIMP = s; } -void Trouve_Simplex_Bord (void *a, void *b){ +void Trouve_Simplex_Bord(void *a, void *b) +{ Simplex *s; - if (SIMP != NULL) + if(SIMP != NULL) return; s = *(Simplex **) a; - if (s->V[0]->Num < 0 || s->V[1]->Num < 0 || s->V[2]->Num < 0 || s->V[3]->Num < 0) + if(s->V[0]->Num < 0 || s->V[1]->Num < 0 || s->V[2]->Num < 0 + || s->V[3]->Num < 0) SIMP = s; } -void SurfacesDansVolume (Volume * v, List_T * ListAllSurf){ +void SurfacesDansVolume(Volume * v, List_T * ListAllSurf) +{ int i, iseg; Surface *s; - for (i = 0; i < List_Nbr (v->Surfaces); i++) - { - List_Read (v->Surfaces, i, &s); - iseg = abs (s->Num); - List_Replace (ListAllSurf, &iseg, fcmp_int); - } + for(i = 0; i < List_Nbr(v->Surfaces); i++) { + List_Read(v->Surfaces, i, &s); + iseg = abs(s->Num); + List_Replace(ListAllSurf, &iseg, fcmp_int); + } } -int isListaVolume (List_T * ListSurf, Mesh * M){ +int isListaVolume(List_T * ListSurf, Mesh * M) +{ int NN, i, j, srf; bool found; Surface *Surf; Volume *v; - List_T *AllVolumes = Tree2List (M->Volumes); + List_T *AllVolumes = Tree2List(M->Volumes); - for (i = 0; i < List_Nbr (AllVolumes); i++){ - List_Read (AllVolumes, i, &v); + for(i = 0; i < List_Nbr(AllVolumes); i++) { + List_Read(AllVolumes, i, &v); found = true; NN = 0; - if (v->Typ == MSH_VOLUME){ - for (j = 0; j < List_Nbr (v->Surfaces); j++){ - List_Read (v->Surfaces, j, &Surf); - srf = abs (Surf->Num); - if (!List_Search (ListSurf, &srf, fcmp_int)){ + if(v->Typ == MSH_VOLUME) { + for(j = 0; j < List_Nbr(v->Surfaces); j++) { + List_Read(v->Surfaces, j, &Surf); + srf = abs(Surf->Num); + if(!List_Search(ListSurf, &srf, fcmp_int)) { found = false; } else NN++; } - if (found && NN == List_Nbr (ListSurf)) + if(found && NN == List_Nbr(ListSurf)) return v->Num; } } return 0; } -int compareSimpSurf (const void *a, const void *b){ +int compareSimpSurf(const void *a, const void *b) +{ Simplex *q, *w; q = *(Simplex **) a; w = *(Simplex **) b; - return compareFace (&q->F[0], &w->F[0]); + return compareFace(&q->F[0], &w->F[0]); } List_T *StackSimp; #define MAX_DEPTH 500 -void recur_trouve_volume (Simplex * s, int *Depth){ +void recur_trouve_volume(Simplex * s, int *Depth) +{ int i, j; Simplex *pS, S; - if (s->iEnt != -1) + if(s->iEnt != -1) return; - if ((*Depth) > MAX_DEPTH) { - List_Add (StackSimp, &s); + if((*Depth) > MAX_DEPTH) { + List_Add(StackSimp, &s); return; } - + (*Depth)++; s->iEnt = -2; - Tree_Add (keep, &s); - for (i = 0; i < 4; i++){ + Tree_Add(keep, &s); + for(i = 0; i < 4; i++) { pS = &S; pS->F[0] = s->F[i]; - if (Tree_Query (FacesTree, &pS) && List_Search (ListAllSurf, &pS->iEnt, fcmp_int)){ - j = abs (pS->iEnt); - List_Replace (ListSurfaces, &j, fcmp_int); + if(Tree_Query(FacesTree, &pS) + && List_Search(ListAllSurf, &pS->iEnt, fcmp_int)) { + j = abs(pS->iEnt); + List_Replace(ListSurfaces, &j, fcmp_int); } - else if (s->S[i] && s->S[i] != &MyNewBoundary){ - recur_trouve_volume (s->S[i], Depth); + else if(s->S[i] && s->S[i] != &MyNewBoundary) { + recur_trouve_volume(s->S[i], Depth); } } (*Depth)--; } -void Restore_Volume (Volume * v){ +void Restore_Volume(Volume * v) +{ int N; int j, i, depth; Surface *s; - StackSimp = List_Create (100, 100, sizeof (Simplex *)); + StackSimp = List_Create(100, 100, sizeof(Simplex *)); - FacesTree = Tree_Create (sizeof (Simplex *), compareSimpSurf); + FacesTree = Tree_Create(sizeof(Simplex *), compareSimpSurf); Actual_Tree = FacesTree; - for (j = 0; j < List_Nbr (v->Surfaces); j++){ - List_Read (v->Surfaces, j, &s); - Tree_Action (s->Simplexes, _Add); + for(j = 0; j < List_Nbr(v->Surfaces); j++) { + List_Read(v->Surfaces, j, &s); + Tree_Action(s->Simplexes, _Add); } - ListSurfaces = List_Create (2, 2, sizeof (int)); + ListSurfaces = List_Create(2, 2, sizeof(int)); iVolume = -1; - Tree_Action (v->Simplexes, attribueVolume); + Tree_Action(v->Simplexes, attribueVolume); /* Les simplexes sur le bord exterieur sont elimines */ - ListAllSurf = List_Create (10, 3, sizeof (int)); - SurfacesDansVolume (v, ListAllSurf); + ListAllSurf = List_Create(10, 3, sizeof(int)); + SurfacesDansVolume(v, ListAllSurf); SIMP = NULL; - Tree_Action (v->Simplexes, Trouve_Simplex_Bord); + Tree_Action(v->Simplexes, Trouve_Simplex_Bord); - if (SIMP){ - List_Add (StackSimp, &SIMP); - keep = Tree_Create (sizeof (Simplex *), compareQuality); + if(SIMP) { + List_Add(StackSimp, &SIMP); + keep = Tree_Create(sizeof(Simplex *), compareQuality); depth = 0; i = 0; - do{ - List_Read (StackSimp, i, &SIMP); - recur_trouve_volume (SIMP, &depth); - } while (++i < List_Nbr (StackSimp)); - List_Reset (StackSimp); - - for (i = 0; i < List_Nbr (ListSurfaces); i++){ - List_Read (ListSurfaces, i, &j); + do { + List_Read(StackSimp, i, &SIMP); + recur_trouve_volume(SIMP, &depth); + } while(++i < List_Nbr(StackSimp)); + List_Reset(StackSimp); + + for(i = 0; i < List_Nbr(ListSurfaces); i++) { + List_Read(ListSurfaces, i, &j); Msg(STATUS2, "Surface %d", j); } - + iVolume = 0; - Tree_Action (keep, attribueVolume); - Tree_Delete (keep); - List_Reset (ListSurfaces); + Tree_Action(keep, attribueVolume); + Tree_Delete(keep); + List_Reset(ListSurfaces); } - - while (1){ + + while(1) { SIMP = NULL; - keep = Tree_Create (sizeof (Simplex *), compareQuality); - Tree_Action (v->Simplexes, Trouve_Simplex); - if (!SIMP) + keep = Tree_Create(sizeof(Simplex *), compareQuality); + Tree_Action(v->Simplexes, Trouve_Simplex); + if(!SIMP) break; - List_Add (StackSimp, &SIMP); + List_Add(StackSimp, &SIMP); depth = 0; i = 0; - do{ - List_Read (StackSimp, i, &SIMP); - recur_trouve_volume (SIMP, &depth); - }while (++i < List_Nbr (StackSimp)); - - iVolume = isListaVolume (ListSurfaces, THEM); - - for (i = 0; i < List_Nbr (ListSurfaces); i++){ - List_Read (ListSurfaces, i, &j); + do { + List_Read(StackSimp, i, &SIMP); + recur_trouve_volume(SIMP, &depth); + } while(++i < List_Nbr(StackSimp)); + + iVolume = isListaVolume(ListSurfaces, THEM); + + for(i = 0; i < List_Nbr(ListSurfaces); i++) { + List_Read(ListSurfaces, i, &j); Msg(STATUS2, "Surface %d", j); } - - N = Tree_Nbr (keep); + + N = Tree_Nbr(keep); Msg(INFO, "Initial mesh of volume %d: %d simplices", iVolume, N); - Tree_Action (keep, attribueVolume); - Tree_Delete (keep); - List_Reset (ListSurfaces); - List_Reset (StackSimp); + Tree_Action(keep, attribueVolume); + Tree_Delete(keep); + List_Reset(ListSurfaces); + List_Reset(StackSimp); } } diff --git a/Mesh/3D_Divide.cpp b/Mesh/3D_Divide.cpp index 81633e42186c59b905821c319520ea8e16ee0e61..ee1090bb3d56462428a9dbd0672f9ccc9c7e6b0e 100644 --- a/Mesh/3D_Divide.cpp +++ b/Mesh/3D_Divide.cpp @@ -1,4 +1,4 @@ -// $Id: 3D_Divide.cpp,v 1.19 2003-02-25 04:02:51 geuzaine Exp $ +// $Id: 3D_Divide.cpp,v 1.20 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -32,684 +32,689 @@ #include "Numeric.h" #include "Mesh.h" -extern Mesh * THEM; -extern int edges_tetra[6][2]; +extern Mesh *THEM; +extern int edges_tetra[6][2]; static Tree_T *New_Edges = NULL; -static int IENT; +static int IENT; -typedef struct { +typedef struct{ int i; int j; }nxn; -static int are_exists (Vertex *v1, Vertex *v2){ +static int are_exists(Vertex * v1, Vertex * v2) +{ nxn nx; - nx.i = IMAX(v1->Num,v2->Num); - nx.j = IMIN(v1->Num,v2->Num); - return Tree_Search(New_Edges,&nx); + nx.i = IMAX(v1->Num, v2->Num); + nx.j = IMIN(v1->Num, v2->Num); + return Tree_Search(New_Edges, &nx); } -static void are_add (Vertex *v1, Vertex *v2){ +static void are_add(Vertex * v1, Vertex * v2) +{ nxn nx; - nx.i = IMAX(v1->Num,v2->Num); - nx.j = IMIN(v1->Num,v2->Num); - Tree_Add(New_Edges,&nx); + nx.i = IMAX(v1->Num, v2->Num); + nx.j = IMIN(v1->Num, v2->Num); + Tree_Add(New_Edges, &nx); } -static int compnxn (const void *a, const void *b){ - nxn *q,*w; - q = (nxn*)a; - w = (nxn*)b; - if(q->i>w->i)return 1; - if(q->i<w->i)return -1; - if(q->j>w->j)return 1; - if(q->j<w->j)return -1; +static int compnxn(const void *a, const void *b) +{ + nxn *q, *w; + q = (nxn *) a; + w = (nxn *) b; + if(q->i > w->i) + return 1; + if(q->i < w->i) + return -1; + if(q->j > w->j) + return 1; + if(q->j < w->j) + return -1; return 0; } -static int FF,FV,EV,EE,FE,EEE,EEEE; -void Remise_A_Zero (void){ - FF=EE=FV=EV=FE=EEE=EEEE=0; +static int FF, FV, EV, EE, FE, EEE, EEEE; +void Remise_A_Zero(void) +{ + FF = EE = FV = EV = FE = EEE = EEEE = 0; } -void Impression_Resultats (void){ - +void Impression_Resultats(void) +{ Msg(INFO1, "==================================================="); Msg(INFO2, "Surface coherence results (number of intersections)"); Msg(INFO2, "%d EV, %d EE, %d FV, %d FF, %d FE, %d EEE, %d EEEE", EV, EE, FV, FF, FE, EEE, EEEE); Msg(INFO3, "==================================================="); - + } int PARLE = 0; -void cut_prism (Vertex * v1, Vertex * v2, Vertex * v3, - Vertex * v4, Vertex * v5, Vertex * v6, - Tree_T * newpoints, Tree_T * AddedTet){ - +void cut_prism(Vertex * v1, Vertex * v2, Vertex * v3, + Vertex * v4, Vertex * v5, Vertex * v6, + Tree_T * newpoints, Tree_T * AddedTet) +{ Simplex *news; Vertex *e1; //Msg(INFO, "Prism cut"); +#if 0 /* test des meilleures aretes a creer */ - /* - if(!are_exists(v1,v6) && + if(!are_exists(v1,v6) && !are_exists(v4,v3)){ - - if(fabs(angle_3p(v1,v4,v6)) > - fabs(angle_3p(v4,v6,v3))){ - are_add(v4,v3); - } - else{ - are_add(v1,v6); - } - } - - if(!are_exists(v3,v5) && + + if(fabs(angle_3p(v1,v4,v6)) > + fabs(angle_3p(v4,v6,v3))){ + are_add(v4,v3); + } + else{ + are_add(v1,v6); + } + } + + if(!are_exists(v3,v5) && !are_exists(v6,v2)){ - - if(fabs(angle_3p(v6,v5,v2)) > - fabs(angle_3p(v5,v2,v3))){ - are_add(v5,v3); - } - else{ - are_add(v2,v6); - } - } - - if(!are_exists(v1,v5) && + + if(fabs(angle_3p(v6,v5,v2)) > + fabs(angle_3p(v5,v2,v3))){ + are_add(v5,v3); + } + else{ + are_add(v2,v6); + } + } + + if(!are_exists(v1,v5) && !are_exists(v4,v2)){ + + if(fabs(angle_3p(v1,v4,v5)) > + fabs(angle_3p(v4,v5,v2))){ + are_add(v4,v2); + } + else{ + are_add(v1,v5); + } + } +#endif - if(fabs(angle_3p(v1,v4,v5)) > - fabs(angle_3p(v4,v5,v2))){ - are_add(v4,v2); - } - else{ - are_add(v1,v5); - } - } - */ - if (!are_exists (v1, v5) && //OK - !are_exists (v6, v2) && - !are_exists (v6, v1)){ - news = Create_Simplex (v1, v2, v3, v4); + if(!are_exists(v1, v5) && //OK + !are_exists(v6, v2) && !are_exists(v6, v1)) { + news = Create_Simplex(v1, v2, v3, v4); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (v4, v5, v6, v3); + Tree_Add(AddedTet, &news); + news = Create_Simplex(v4, v5, v6, v3); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (v2, v4, v5, v3); + Tree_Add(AddedTet, &news); + news = Create_Simplex(v2, v4, v5, v3); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - are_add (v4, v2); - are_add (v5, v3); - are_add (v4, v3); + Tree_Add(AddedTet, &news); + are_add(v4, v2); + are_add(v5, v3); + are_add(v4, v3); } - else if (!are_exists (v1, v5) && //OK - !are_exists (v3, v5) && - !are_exists (v1, v6)){ - news = Create_Simplex (v1, v2, v3, v4); + else if(!are_exists(v1, v5) && //OK + !are_exists(v3, v5) && !are_exists(v1, v6)) { + news = Create_Simplex(v1, v2, v3, v4); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (v4, v5, v6, v2); + Tree_Add(AddedTet, &news); + news = Create_Simplex(v4, v5, v6, v2); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (v4, v2, v6, v3); + Tree_Add(AddedTet, &news); + news = Create_Simplex(v4, v2, v6, v3); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - are_add (v4, v2); - are_add (v2, v6); - are_add (v4, v3); + Tree_Add(AddedTet, &news); + are_add(v4, v2); + are_add(v2, v6); + are_add(v4, v3); } - else if (!are_exists (v1, v5) && //OK - !are_exists (v3, v5) && - !are_exists (v4, v3)){ - news = Create_Simplex (v1, v2, v3, v6); + else if(!are_exists(v1, v5) && //OK + !are_exists(v3, v5) && !are_exists(v4, v3)) { + news = Create_Simplex(v1, v2, v3, v6); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (v4, v5, v6, v2); + Tree_Add(AddedTet, &news); + news = Create_Simplex(v4, v5, v6, v2); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (v2, v4, v6, v1); + Tree_Add(AddedTet, &news); + news = Create_Simplex(v2, v4, v6, v1); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - are_add (v4, v2); - are_add (v2, v6); - are_add (v6, v1); + Tree_Add(AddedTet, &news); + are_add(v4, v2); + are_add(v2, v6); + are_add(v6, v1); } - else if (!are_exists (v4, v2) && //OK - !are_exists (v6, v2) && - !are_exists (v6, v1)){ - news = Create_Simplex (v1, v2, v3, v5); + else if(!are_exists(v4, v2) && //OK + !are_exists(v6, v2) && !are_exists(v6, v1)) { + news = Create_Simplex(v1, v2, v3, v5); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (v4, v5, v6, v3); + Tree_Add(AddedTet, &news); + news = Create_Simplex(v4, v5, v6, v3); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (v1, v4, v5, v3); + Tree_Add(AddedTet, &news); + news = Create_Simplex(v1, v4, v5, v3); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - are_add (v5, v1); - are_add (v5, v3); - are_add (v4, v3); + Tree_Add(AddedTet, &news); + are_add(v5, v1); + are_add(v5, v3); + are_add(v4, v3); } - else if (!are_exists (v4, v2) && //OK - !are_exists (v6, v2) && - !are_exists (v4, v3)){ - news = Create_Simplex (v1, v2, v3, v5); + else if(!are_exists(v4, v2) && //OK + !are_exists(v6, v2) && !are_exists(v4, v3)) { + news = Create_Simplex(v1, v2, v3, v5); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (v4, v5, v6, v1); + Tree_Add(AddedTet, &news); + news = Create_Simplex(v4, v5, v6, v1); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (v1, v3, v5, v6); + Tree_Add(AddedTet, &news); + news = Create_Simplex(v1, v3, v5, v6); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - are_add (v5, v1); - are_add (v5, v3); - are_add (v6, v1); + Tree_Add(AddedTet, &news); + are_add(v5, v1); + are_add(v5, v3); + are_add(v6, v1); } - else if (!are_exists (v4, v2) && //OK - !are_exists (v3, v5) && - !are_exists (v4, v3)){ - news = Create_Simplex (v1, v2, v3, v6); + else if(!are_exists(v4, v2) && //OK + !are_exists(v3, v5) && !are_exists(v4, v3)) { + news = Create_Simplex(v1, v2, v3, v6); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (v4, v5, v6, v1); + Tree_Add(AddedTet, &news); + news = Create_Simplex(v4, v5, v6, v1); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (v1, v2, v5, v6); + Tree_Add(AddedTet, &news); + news = Create_Simplex(v1, v2, v5, v6); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - are_add (v5, v1); - are_add (v2, v6); - are_add (v6, v1); + Tree_Add(AddedTet, &news); + are_add(v5, v1); + are_add(v2, v6); + are_add(v6, v1); } - else if (are_exists (v6, v1) && - are_exists (v5, v3) && - are_exists (v4, v2)) { + else if(are_exists(v6, v1) && are_exists(v5, v3) && are_exists(v4, v2)) { Msg(INFO, "Found steiner prism 1!"); - - e1 = Create_Vertex + + e1 = Create_Vertex (++THEM->MaxPointNum, - (v1->Pos.X + v2->Pos.X + v3->Pos.X + v4->Pos.X + v5->Pos.X + v6->Pos.X) / 6., - (v1->Pos.Y + v2->Pos.Y + v3->Pos.Y + v4->Pos.Y + v5->Pos.Y + v6->Pos.Y) / 6., - (v1->Pos.Z + v2->Pos.Z + v3->Pos.Z + v4->Pos.Z + v5->Pos.Z + v6->Pos.Z) / 6., - (v1->lc + v2->lc + v3->lc + v4->lc + v5->lc + v6->lc) / 6., - 0.0); - Tree_Add (newpoints, &e1); - news = Create_Simplex (e1, v6, v1, v4); + (v1->Pos.X + v2->Pos.X + v3->Pos.X + v4->Pos.X + v5->Pos.X + + v6->Pos.X) / 6., + (v1->Pos.Y + v2->Pos.Y + v3->Pos.Y + v4->Pos.Y + v5->Pos.Y + + v6->Pos.Y) / 6., + (v1->Pos.Z + v2->Pos.Z + v3->Pos.Z + v4->Pos.Z + v5->Pos.Z + + v6->Pos.Z) / 6., + (v1->lc + v2->lc + v3->lc + v4->lc + v5->lc + v6->lc) / 6., 0.0); + Tree_Add(newpoints, &e1); + news = Create_Simplex(e1, v6, v1, v4); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (e1, v6, v1, v3); + Tree_Add(AddedTet, &news); + news = Create_Simplex(e1, v6, v1, v3); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (e1, v5, v3, v6); + Tree_Add(AddedTet, &news); + news = Create_Simplex(e1, v5, v3, v6); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (e1, v5, v3, v2); + Tree_Add(AddedTet, &news); + news = Create_Simplex(e1, v5, v3, v2); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (e1, v4, v2, v1); + Tree_Add(AddedTet, &news); + news = Create_Simplex(e1, v4, v2, v1); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (e1, v4, v2, v5); + Tree_Add(AddedTet, &news); + news = Create_Simplex(e1, v4, v2, v5); news->iEnt = IENT; - Tree_Add (AddedTet, &news); + Tree_Add(AddedTet, &news); } - else if (are_exists (v4, v3) && - are_exists (v6, v2) && - are_exists (v5, v1)){ + else if(are_exists(v4, v3) && are_exists(v6, v2) && are_exists(v5, v1)) { Msg(INFO, "Found steiner prism 2!"); - e1 = Create_Vertex + e1 = Create_Vertex (++THEM->MaxPointNum, - (v1->Pos.X + v2->Pos.X + v3->Pos.X + v4->Pos.X + v5->Pos.X + v6->Pos.X) / 6., - (v1->Pos.Y + v2->Pos.Y + v3->Pos.Y + v4->Pos.Y + v5->Pos.Y + v6->Pos.Y) / 6., - (v1->Pos.Z + v2->Pos.Z + v3->Pos.Z + v4->Pos.Z + v5->Pos.Z + v6->Pos.Z) / 6., - (v1->lc + v2->lc + v3->lc + v4->lc + v5->lc + v6->lc) / 6., - 0.0); - Tree_Add (newpoints, &e1); - news = Create_Simplex (e1, v4, v3, v6); + (v1->Pos.X + v2->Pos.X + v3->Pos.X + v4->Pos.X + v5->Pos.X + + v6->Pos.X) / 6., + (v1->Pos.Y + v2->Pos.Y + v3->Pos.Y + v4->Pos.Y + v5->Pos.Y + + v6->Pos.Y) / 6., + (v1->Pos.Z + v2->Pos.Z + v3->Pos.Z + v4->Pos.Z + v5->Pos.Z + + v6->Pos.Z) / 6., + (v1->lc + v2->lc + v3->lc + v4->lc + v5->lc + v6->lc) / 6., 0.0); + Tree_Add(newpoints, &e1); + news = Create_Simplex(e1, v4, v3, v6); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (e1, v4, v3, v1); + Tree_Add(AddedTet, &news); + news = Create_Simplex(e1, v4, v3, v1); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (e1, v6, v2, v5); + Tree_Add(AddedTet, &news); + news = Create_Simplex(e1, v6, v2, v5); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (e1, v6, v2, v3); + Tree_Add(AddedTet, &news); + news = Create_Simplex(e1, v6, v2, v3); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (e1, v5, v1, v4); + Tree_Add(AddedTet, &news); + news = Create_Simplex(e1, v5, v1, v4); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - news = Create_Simplex (e1, v5, v1, v2); + Tree_Add(AddedTet, &news); + news = Create_Simplex(e1, v5, v1, v2); news->iEnt = IENT; - Tree_Add (AddedTet, &news); - + Tree_Add(AddedTet, &news); + } - else{ + else { Msg(GERROR, "Uncoherent prism"); } } -void cut_tetraedre (Intersection * pI, Tree_T * AddedTet, Tree_T * TetDel, - Tree_T * newpoints){ +void cut_tetraedre(Intersection * pI, Tree_T * AddedTet, Tree_T * TetDel, + Tree_T * newpoints) +{ int i; nxn nx; Simplex *s; - Vertex *common, *other1, *other2, *lonely=NULL, *e1, *e2; - Vertex *point1=NULL, *point2=NULL, *point3=NULL, *point4=NULL; - Vertex *v1=NULL, *v2=NULL, *v3=NULL, *v4=NULL, *v5=NULL, *v6=NULL, *v7=NULL, *v8=NULL; + Vertex *common, *other1, *other2, *lonely = NULL, *e1, *e2; + Vertex *point1 = NULL, *point2 = NULL, *point3 = NULL, *point4 = NULL; + Vertex *v1 = NULL, *v2 = NULL, *v3 = NULL, *v4 = NULL, *v5 = NULL, *v6 = + NULL, *v7 = NULL, *v8 = NULL; - if (!New_Edges) - New_Edges = Tree_Create (sizeof (nxn), compnxn); + if(!New_Edges) + New_Edges = Tree_Create(sizeof(nxn), compnxn); IENT = pI->s->iEnt; /* 1 tetraedre -> 2 tetraedres */ - if ((pI->NbEdge == 0) && (pI->NbFace == 0)){ + if((pI->NbEdge == 0) && (pI->NbFace == 0)) { } - else if (pI->NbEdge == 1 && pI->NbFace == 0){ + else if(pI->NbEdge == 1 && pI->NbFace == 0) { + + Tree_Add(TetDel, &pI->s); + - Tree_Add (TetDel, &pI->s); - - EV++; - if (pI->E[0] == 0){ + if(pI->E[0] == 0) { /* Verifie */ - s = Create_Simplex (pI->s->V[2], pI->s->V[3], pI->s->V[0], pI->VE[0]); + s = Create_Simplex(pI->s->V[2], pI->s->V[3], pI->s->V[0], pI->VE[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - if (PARLE) - printf ("ajout %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); - s = Create_Simplex (pI->s->V[1], pI->s->V[3], pI->s->V[2], pI->VE[0]); - if (PARLE) - printf ("ajout %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + Tree_Add(AddedTet, &s); + if(PARLE) + printf("ajout %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + s = Create_Simplex(pI->s->V[1], pI->s->V[3], pI->s->V[2], pI->VE[0]); + if(PARLE) + printf("ajout %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); s->iEnt = IENT; - Tree_Add (AddedTet, &s); + Tree_Add(AddedTet, &s); } - if (pI->E[0] == 1){ + if(pI->E[0] == 1) { /* Verifie */ - s = Create_Simplex (pI->s->V[0], pI->s->V[3], pI->s->V[2], pI->VE[0]); - if (PARLE) - printf ("ajout %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + s = Create_Simplex(pI->s->V[0], pI->s->V[3], pI->s->V[2], pI->VE[0]); + if(PARLE) + printf("ajout %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->s->V[3], pI->s->V[1], pI->s->V[0], pI->VE[0]); - if (PARLE) - printf ("ajout %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->s->V[3], pI->s->V[1], pI->s->V[0], pI->VE[0]); + if(PARLE) + printf("ajout %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); s->iEnt = IENT; - Tree_Add (AddedTet, &s); + Tree_Add(AddedTet, &s); } - if (pI->E[0] == 2){ + if(pI->E[0] == 2) { /* Verifie */ - s = Create_Simplex (pI->s->V[0], pI->s->V[1], pI->s->V[3], pI->VE[0]); - if (PARLE) - printf ("ajout %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + s = Create_Simplex(pI->s->V[0], pI->s->V[1], pI->s->V[3], pI->VE[0]); + if(PARLE) + printf("ajout %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->s->V[1], pI->s->V[3], pI->s->V[2], pI->VE[0]); - if (PARLE) - printf ("ajout %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->s->V[1], pI->s->V[3], pI->s->V[2], pI->VE[0]); + if(PARLE) + printf("ajout %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); s->iEnt = IENT; - Tree_Add (AddedTet, &s); + Tree_Add(AddedTet, &s); } - if (pI->E[0] == 3){ + if(pI->E[0] == 3) { /* Verifie */ - s = Create_Simplex (pI->s->V[0], pI->s->V[1], pI->s->V[2], pI->VE[0]); - if (PARLE) - printf ("ajout %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + s = Create_Simplex(pI->s->V[0], pI->s->V[1], pI->s->V[2], pI->VE[0]); + if(PARLE) + printf("ajout %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->s->V[1], pI->s->V[2], pI->s->V[3], pI->VE[0]); - if (PARLE) - printf ("ajout %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->s->V[1], pI->s->V[2], pI->s->V[3], pI->VE[0]); + if(PARLE) + printf("ajout %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); s->iEnt = IENT; - Tree_Add (AddedTet, &s); + Tree_Add(AddedTet, &s); } - if (pI->E[0] == 4){ + if(pI->E[0] == 4) { /* Verifie */ - s = Create_Simplex (pI->s->V[2], pI->s->V[0], pI->s->V[1], pI->VE[0]); - if (PARLE) - printf ("ajout %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + s = Create_Simplex(pI->s->V[2], pI->s->V[0], pI->s->V[1], pI->VE[0]); + if(PARLE) + printf("ajout %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->s->V[1], pI->s->V[3], pI->s->V[0], pI->VE[0]); - if (PARLE) - printf ("ajout %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->s->V[1], pI->s->V[3], pI->s->V[0], pI->VE[0]); + if(PARLE) + printf("ajout %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); s->iEnt = IENT; - Tree_Add (AddedTet, &s); + Tree_Add(AddedTet, &s); } - if (pI->E[0] == 5){ + if(pI->E[0] == 5) { /* Verifie */ - s = Create_Simplex (pI->s->V[0], pI->s->V[3], pI->s->V[2], pI->VE[0]); - if (PARLE) - printf ("ajout %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + s = Create_Simplex(pI->s->V[0], pI->s->V[3], pI->s->V[2], pI->VE[0]); + if(PARLE) + printf("ajout %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->s->V[0], pI->s->V[1], pI->s->V[2], pI->VE[0]); - if (PARLE) - printf ("ajout %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->s->V[0], pI->s->V[1], pI->s->V[2], pI->VE[0]); + if(PARLE) + printf("ajout %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); s->iEnt = IENT; - Tree_Add (AddedTet, &s); + Tree_Add(AddedTet, &s); } } - else if (pI->NbVertex == 1 && pI->NbFace == 1){ + else if(pI->NbVertex == 1 && pI->NbFace == 1) { FV++; - Tree_Add (TetDel, &pI->s); - s = Create_Simplex (pI->V[0], pI->VF[0], pI->F[0]->V[0], pI->F[0]->V[1]); + Tree_Add(TetDel, &pI->s); + s = Create_Simplex(pI->V[0], pI->VF[0], pI->F[0]->V[0], pI->F[0]->V[1]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->V[0], pI->VF[0], pI->F[0]->V[1], pI->F[0]->V[2]); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->V[0], pI->VF[0], pI->F[0]->V[1], pI->F[0]->V[2]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->V[0], pI->VF[0], pI->F[0]->V[2], pI->F[0]->V[0]); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->V[0], pI->VF[0], pI->F[0]->V[2], pI->F[0]->V[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); + Tree_Add(AddedTet, &s); } /* DU CUL LES COPINES TROIS ARETES QUI PENETRENT LA MEME FACE TRIPLETTE, TRIPLE PENETRATION */ - - else if (pI->NbEdge == 3){ + + else if(pI->NbEdge == 3) { EEE++; /* - printf("tet %d %d %d %d\n", - pI->s->V[0]->Num,pI->s->V[1]->Num,pI->s->V[2]->Num,pI->s->V[3]->Num); - printf("ed %d %d\n",pI->s->V[edges_tetra[pI->E[0]][0]]->Num, - pI->s->V[edges_tetra[pI->E[0]][1]]->Num); - printf("ed %d %d\n",pI->s->V[edges_tetra[pI->E[1]][0]]->Num, - pI->s->V[edges_tetra[pI->E[1]][1]]->Num); - printf("ed %d %d\n",pI->s->V[edges_tetra[pI->E[2]][0]]->Num, - pI->s->V[edges_tetra[pI->E[2]][1]]->Num); - */ - Tree_Add (TetDel, &pI->s); + printf("tet %d %d %d %d\n", + pI->s->V[0]->Num,pI->s->V[1]->Num,pI->s->V[2]->Num,pI->s->V[3]->Num); + printf("ed %d %d\n",pI->s->V[edges_tetra[pI->E[0]][0]]->Num, + pI->s->V[edges_tetra[pI->E[0]][1]]->Num); + printf("ed %d %d\n",pI->s->V[edges_tetra[pI->E[1]][0]]->Num, + pI->s->V[edges_tetra[pI->E[1]][1]]->Num); + printf("ed %d %d\n",pI->s->V[edges_tetra[pI->E[2]][0]]->Num, + pI->s->V[edges_tetra[pI->E[2]][1]]->Num); + */ + Tree_Add(TetDel, &pI->s); v4 = pI->VE[0]; v5 = pI->VE[1]; v6 = pI->VE[2]; - if (pI->E[0] == 0 && pI->E[1] == 1 && pI->E[2] == 5){ + if(pI->E[0] == 0 && pI->E[1] == 1 && pI->E[2] == 5) { v1 = pI->s->V[0]; v2 = pI->s->V[2]; v3 = pI->s->V[3]; v7 = pI->s->V[1]; } - else if (pI->E[0] == 0 && pI->E[1] == 2 && pI->E[2] == 3){ + else if(pI->E[0] == 0 && pI->E[1] == 2 && pI->E[2] == 3) { v1 = pI->s->V[1]; v2 = pI->s->V[2]; v3 = pI->s->V[3]; v7 = pI->s->V[0]; } - else if (pI->E[0] == 1 && pI->E[1] == 2 && pI->E[2] == 4){ + else if(pI->E[0] == 1 && pI->E[1] == 2 && pI->E[2] == 4) { v1 = pI->s->V[1]; v2 = pI->s->V[0]; v3 = pI->s->V[3]; v7 = pI->s->V[2]; } - else if (pI->E[0] == 3 && pI->E[1] == 4 && pI->E[2] == 5){ + else if(pI->E[0] == 3 && pI->E[1] == 4 && pI->E[2] == 5) { v1 = pI->s->V[0]; v2 = pI->s->V[2]; v3 = pI->s->V[1]; v7 = pI->s->V[3]; } - else{ + else { Msg(GERROR, "Three edges cut without common point!"); return; } - - s = Create_Simplex (v4, v5, v6, v7); - Tree_Add (AddedTet, &s); - cut_prism (v1, v2, v3, v4, v5, v6, newpoints, AddedTet); - + + s = Create_Simplex(v4, v5, v6, v7); + Tree_Add(AddedTet, &s); + cut_prism(v1, v2, v3, v4, v5, v6, newpoints, AddedTet); + } - else if (pI->NbFace == 2){ + else if(pI->NbFace == 2) { FF++; point3 = NULL; - Tree_Add (TetDel, &pI->s); - if (PARLE){ - printf ("simp = %d %d %d %d\n", - pI->s->V[0]->Num, pI->s->V[1]->Num, pI->s->V[2]->Num, pI->s->V[3]->Num); - printf ("are = %d %d\n", - pI->VF[0]->Num, pI->VF[1]->Num); - printf ("face1 = %d %d %d\n", - pI->F[0]->V[0]->Num, pI->F[0]->V[1]->Num, pI->F[0]->V[2]->Num); - printf ("face2 = %d %d %d\n", - pI->F[1]->V[0]->Num, pI->F[1]->V[1]->Num, pI->F[1]->V[2]->Num); - } - for (i = 0; i < 4; i++){ - if (compareVertex (&pI->F[0]->V[0], &pI->s->V[i]) && - compareVertex (&pI->F[0]->V[1], &pI->s->V[i]) && - compareVertex (&pI->F[0]->V[2], &pI->s->V[i])) + Tree_Add(TetDel, &pI->s); + if(PARLE) { + printf("simp = %d %d %d %d\n", + pI->s->V[0]->Num, pI->s->V[1]->Num, pI->s->V[2]->Num, + pI->s->V[3]->Num); + printf("are = %d %d\n", pI->VF[0]->Num, pI->VF[1]->Num); + printf("face1 = %d %d %d\n", + pI->F[0]->V[0]->Num, pI->F[0]->V[1]->Num, pI->F[0]->V[2]->Num); + printf("face2 = %d %d %d\n", + pI->F[1]->V[0]->Num, pI->F[1]->V[1]->Num, pI->F[1]->V[2]->Num); + } + for(i = 0; i < 4; i++) { + if(compareVertex(&pI->F[0]->V[0], &pI->s->V[i]) && + compareVertex(&pI->F[0]->V[1], &pI->s->V[i]) && + compareVertex(&pI->F[0]->V[2], &pI->s->V[i])) point1 = pI->s->V[i]; - else if (compareVertex (&pI->F[1]->V[0], &pI->s->V[i]) && - compareVertex (&pI->F[1]->V[1], &pI->s->V[i]) && - compareVertex (&pI->F[1]->V[2], &pI->s->V[i])) + else if(compareVertex(&pI->F[1]->V[0], &pI->s->V[i]) && + compareVertex(&pI->F[1]->V[1], &pI->s->V[i]) && + compareVertex(&pI->F[1]->V[2], &pI->s->V[i])) point2 = pI->s->V[i]; - else if (point3) + else if(point3) point4 = pI->s->V[i]; else point3 = pI->s->V[i]; } - s = Create_Simplex (point3, point4, pI->VF[0], pI->VF[1]); + s = Create_Simplex(point3, point4, pI->VF[0], pI->VF[1]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - if (PARLE) - printf ("simp = %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); - s = Create_Simplex (point1, point4, pI->VF[0], pI->VF[1]); + Tree_Add(AddedTet, &s); + if(PARLE) + printf("simp = %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + s = Create_Simplex(point1, point4, pI->VF[0], pI->VF[1]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - if (PARLE) - printf ("simp = %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); - s = Create_Simplex (point1, point3, pI->VF[0], pI->VF[1]); + Tree_Add(AddedTet, &s); + if(PARLE) + printf("simp = %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + s = Create_Simplex(point1, point3, pI->VF[0], pI->VF[1]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - if (PARLE) - printf ("simp = %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); - s = Create_Simplex (point2, point4, point1, pI->VF[0]); + Tree_Add(AddedTet, &s); + if(PARLE) + printf("simp = %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + s = Create_Simplex(point2, point4, point1, pI->VF[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - if (PARLE) - printf ("simp = %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); - s = Create_Simplex (point2, point3, point1, pI->VF[0]); + Tree_Add(AddedTet, &s); + if(PARLE) + printf("simp = %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + s = Create_Simplex(point2, point3, point1, pI->VF[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - if (PARLE) - printf ("simp = %d %d %d %d\n", - s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + Tree_Add(AddedTet, &s); + if(PARLE) + printf("simp = %d %d %d %d\n", + s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); } - else if (pI->NbEdge == 2){ + else if(pI->NbEdge == 2) { EE++; - Tree_Add (TetDel, &pI->s); - if (pI->E[0] == 1 && pI->E[1] == 3){ - s = Create_Simplex (pI->s->V[0], pI->VE[1], pI->s->V[1], pI->VE[0]); + Tree_Add(TetDel, &pI->s); + if(pI->E[0] == 1 && pI->E[1] == 3) { + s = Create_Simplex(pI->s->V[0], pI->VE[1], pI->s->V[1], pI->VE[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->s->V[0], pI->VE[1], pI->s->V[2], pI->VE[0]); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->s->V[0], pI->VE[1], pI->s->V[2], pI->VE[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->s->V[1], pI->VE[1], pI->s->V[3], pI->VE[0]); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->s->V[1], pI->VE[1], pI->s->V[3], pI->VE[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->s->V[2], pI->VE[1], pI->s->V[3], pI->VE[0]); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->s->V[2], pI->VE[1], pI->s->V[3], pI->VE[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); + Tree_Add(AddedTet, &s); return; } - else if (pI->E[0] == 2 && pI->E[1] == 5){ - s = Create_Simplex (pI->s->V[0], pI->VE[1], pI->s->V[1], pI->VE[0]); + else if(pI->E[0] == 2 && pI->E[1] == 5) { + s = Create_Simplex(pI->s->V[0], pI->VE[1], pI->s->V[1], pI->VE[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->s->V[1], pI->VE[1], pI->s->V[2], pI->VE[0]); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->s->V[1], pI->VE[1], pI->s->V[2], pI->VE[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->s->V[0], pI->VE[1], pI->s->V[3], pI->VE[0]); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->s->V[0], pI->VE[1], pI->s->V[3], pI->VE[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->s->V[2], pI->VE[1], pI->s->V[3], pI->VE[0]); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->s->V[2], pI->VE[1], pI->s->V[3], pI->VE[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); + Tree_Add(AddedTet, &s); return; } - - else if (pI->E[0] == 0 && pI->E[1] == 4){ - s = Create_Simplex (pI->s->V[0], pI->VE[1], pI->s->V[2], pI->VE[0]); + + else if(pI->E[0] == 0 && pI->E[1] == 4) { + s = Create_Simplex(pI->s->V[0], pI->VE[1], pI->s->V[2], pI->VE[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->s->V[1], pI->VE[1], pI->s->V[2], pI->VE[0]); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->s->V[1], pI->VE[1], pI->s->V[2], pI->VE[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->s->V[0], pI->VE[1], pI->s->V[3], pI->VE[0]); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->s->V[0], pI->VE[1], pI->s->V[3], pI->VE[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (pI->s->V[1], pI->VE[1], pI->s->V[3], pI->VE[0]); + Tree_Add(AddedTet, &s); + s = Create_Simplex(pI->s->V[1], pI->VE[1], pI->s->V[3], pI->VE[0]); s->iEnt = IENT; - Tree_Add (AddedTet, &s); + Tree_Add(AddedTet, &s); return; } - + e1 = pI->VE[0]; e2 = pI->VE[1]; - - if (!compareVertex (&pI->s->V[edges_tetra[pI->E[0]][0]], - &pI->s->V[edges_tetra[pI->E[1]][0]])){ + + if(!compareVertex(&pI->s->V[edges_tetra[pI->E[0]][0]], + &pI->s->V[edges_tetra[pI->E[1]][0]])) { common = pI->s->V[edges_tetra[pI->E[0]][0]]; other1 = pI->s->V[edges_tetra[pI->E[0]][1]]; other2 = pI->s->V[edges_tetra[pI->E[1]][1]]; } - else if (!compareVertex (&pI->s->V[edges_tetra[pI->E[0]][0]], - &pI->s->V[edges_tetra[pI->E[1]][1]])){ + else if(!compareVertex(&pI->s->V[edges_tetra[pI->E[0]][0]], + &pI->s->V[edges_tetra[pI->E[1]][1]])) { common = pI->s->V[edges_tetra[pI->E[0]][0]]; other1 = pI->s->V[edges_tetra[pI->E[0]][1]]; other2 = pI->s->V[edges_tetra[pI->E[1]][0]]; } - else if (!compareVertex (&pI->s->V[edges_tetra[pI->E[0]][1]], - &pI->s->V[edges_tetra[pI->E[1]][0]])){ + else if(!compareVertex(&pI->s->V[edges_tetra[pI->E[0]][1]], + &pI->s->V[edges_tetra[pI->E[1]][0]])) { common = pI->s->V[edges_tetra[pI->E[0]][1]]; other1 = pI->s->V[edges_tetra[pI->E[0]][0]]; other2 = pI->s->V[edges_tetra[pI->E[1]][1]]; } - else if (!compareVertex (&pI->s->V[edges_tetra[pI->E[0]][1]], - &pI->s->V[edges_tetra[pI->E[1]][1]])){ + else if(!compareVertex(&pI->s->V[edges_tetra[pI->E[0]][1]], + &pI->s->V[edges_tetra[pI->E[1]][1]])) { common = pI->s->V[edges_tetra[pI->E[0]][1]]; other1 = pI->s->V[edges_tetra[pI->E[0]][0]]; other2 = pI->s->V[edges_tetra[pI->E[1]][0]]; } - - for (i = 0; i < 4; i++){ - if (compareVertex (&pI->s->V[i], &common) && - compareVertex (&pI->s->V[i], &other1) && - compareVertex (&pI->s->V[i], &other2)) + + for(i = 0; i < 4; i++) { + if(compareVertex(&pI->s->V[i], &common) && + compareVertex(&pI->s->V[i], &other1) && + compareVertex(&pI->s->V[i], &other2)) lonely = pI->s->V[i]; } - - nx.i = IMAX (e1->Num, other2->Num); - nx.j = IMIN (e1->Num, other2->Num); - - if (Tree_Search (New_Edges, &nx)){ - s = Create_Simplex (e1, other1, other2, lonely); + + nx.i = IMAX(e1->Num, other2->Num); + nx.j = IMIN(e1->Num, other2->Num); + + if(Tree_Search(New_Edges, &nx)) { + s = Create_Simplex(e1, other1, other2, lonely); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (e2, e1, common, lonely); + Tree_Add(AddedTet, &s); + s = Create_Simplex(e2, e1, common, lonely); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (e2, other2, e1, lonely); + Tree_Add(AddedTet, &s); + s = Create_Simplex(e2, other2, e1, lonely); s->iEnt = IENT; - Tree_Add (AddedTet, &s); + Tree_Add(AddedTet, &s); } - else{ - nx.i = IMAX (e2->Num, other1->Num); - nx.j = IMIN (e2->Num, other1->Num); - Tree_Add (New_Edges, &nx); - s = Create_Simplex (e1, other1, e2, lonely); + else { + nx.i = IMAX(e2->Num, other1->Num); + nx.j = IMIN(e2->Num, other1->Num); + Tree_Add(New_Edges, &nx); + s = Create_Simplex(e1, other1, e2, lonely); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (e2, e1, common, lonely); + Tree_Add(AddedTet, &s); + s = Create_Simplex(e2, e1, common, lonely); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (e2, other1, other2, lonely); + Tree_Add(AddedTet, &s); + s = Create_Simplex(e2, other1, other2, lonely); s->iEnt = IENT; - Tree_Add (AddedTet, &s); + Tree_Add(AddedTet, &s); } } - else if (pI->NbFace == 1 && pI->NbEdge == 1){ + else if(pI->NbFace == 1 && pI->NbEdge == 1) { FE++; - - Tree_Add (TetDel, &pI->s); - for (i = 0; i < 4; i++) - if (compareVertex (&pI->s->V[i], &pI->F[0]->V[0]) && - compareVertex (&pI->s->V[i], &pI->F[0]->V[1]) && - compareVertex (&pI->s->V[i], &pI->F[0]->V[2])) + + Tree_Add(TetDel, &pI->s); + for(i = 0; i < 4; i++) + if(compareVertex(&pI->s->V[i], &pI->F[0]->V[0]) && + compareVertex(&pI->s->V[i], &pI->F[0]->V[1]) && + compareVertex(&pI->s->V[i], &pI->F[0]->V[2])) v1 = pI->s->V[i]; v2 = NULL; v3 = NULL; - - for (i = 0; i < 4; i++){ - if (compareVertex (&pI->s->V[i], &v1)){ - if (compareVertex (&pI->s->V[i], &pI->s->V[edges_tetra[pI->E[0]][0]]) && - compareVertex (&pI->s->V[i], &pI->s->V[edges_tetra[pI->E[0]][1]])){ - if (v2) + + for(i = 0; i < 4; i++) { + if(compareVertex(&pI->s->V[i], &v1)) { + if(compareVertex(&pI->s->V[i], &pI->s->V[edges_tetra[pI->E[0]][0]]) && + compareVertex(&pI->s->V[i], &pI->s->V[edges_tetra[pI->E[0]][1]])) { + if(v2) v3 = pI->s->V[i]; else v2 = pI->s->V[i]; } - else{ + else { v4 = pI->s->V[i]; } } } - + e1 = pI->VE[0]; e2 = pI->VF[0]; - - s = Create_Simplex (e1, e2, v3, v4); + + s = Create_Simplex(e1, e2, v3, v4); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (e1, e2, v2, v4); + Tree_Add(AddedTet, &s); + s = Create_Simplex(e1, e2, v2, v4); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (e1, e2, v2, v3); + Tree_Add(AddedTet, &s); + s = Create_Simplex(e1, e2, v2, v3); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - s = Create_Simplex (e1, v1, v2, v3); + Tree_Add(AddedTet, &s); + s = Create_Simplex(e1, v1, v2, v3); s->iEnt = IENT; - Tree_Add (AddedTet, &s); - + Tree_Add(AddedTet, &s); + } - else if (pI->NbEdge == 4){ + else if(pI->NbEdge == 4) { EEEE++; - + // Allez j-f il faut le faire ! - - Tree_Add (TetDel, &pI->s); - if (pI->E[0] == 1 && pI->E[1] == 2 && pI->E[2] == 3 && pI->E[3] == 5){ + + Tree_Add(TetDel, &pI->s); + if(pI->E[0] == 1 && pI->E[1] == 2 && pI->E[2] == 3 && pI->E[3] == 5) { v1 = pI->s->V[0]; v2 = pI->s->V[1]; v3 = pI->s->V[2]; @@ -719,7 +724,7 @@ void cut_tetraedre (Intersection * pI, Tree_T * AddedTet, Tree_T * TetDel, v7 = pI->VE[0]; v8 = pI->VE[3]; } - else if (pI->E[0] == 0 && pI->E[1] == 2 && pI->E[2] == 4 && pI->E[3] == 5){ + else if(pI->E[0] == 0 && pI->E[1] == 2 && pI->E[2] == 4 && pI->E[3] == 5) { v1 = pI->s->V[1]; v2 = pI->s->V[2]; v3 = pI->s->V[0]; @@ -729,7 +734,7 @@ void cut_tetraedre (Intersection * pI, Tree_T * AddedTet, Tree_T * TetDel, v7 = pI->VE[1]; v8 = pI->VE[2]; } - else if (pI->E[0] == 0 && pI->E[1] == 1 && pI->E[2] == 3 && pI->E[3] == 4){ + else if(pI->E[0] == 0 && pI->E[1] == 1 && pI->E[2] == 3 && pI->E[3] == 4) { v1 = pI->s->V[0]; v2 = pI->s->V[2]; v3 = pI->s->V[1]; @@ -739,19 +744,15 @@ void cut_tetraedre (Intersection * pI, Tree_T * AddedTet, Tree_T * TetDel, v7 = pI->VE[1]; v8 = pI->VE[3]; } - else{ + else { Msg(GERROR, "Incoherent 4 edges intersection"); return; } - cut_prism (v8, v4, v6, v7, v3, v5, newpoints, AddedTet); - cut_prism (v2, v8, v7, v1, v6, v5, newpoints, AddedTet); + cut_prism(v8, v4, v6, v7, v3, v5, newpoints, AddedTet); + cut_prism(v2, v8, v7, v1, v6, v5, newpoints, AddedTet); } - else{ - Msg(GERROR, "Error on cut %d %d %d", pI->NbVertex, pI->NbEdge, pI->NbFace); + else { + Msg(GERROR, "Error on cut %d %d %d", pI->NbVertex, pI->NbEdge, + pI->NbFace); } } - - - - - diff --git a/Mesh/3D_Extrude.cpp b/Mesh/3D_Extrude.cpp index dec3ae3e48ba67e706c34cd9230cbbc4d4b6051b..25f4c738d41e978bf6a8137a03e38428f8d03df7 100644 --- a/Mesh/3D_Extrude.cpp +++ b/Mesh/3D_Extrude.cpp @@ -1,4 +1,4 @@ -// $Id: 3D_Extrude.cpp,v 1.59 2003-02-25 04:02:51 geuzaine Exp $ +// $Id: 3D_Extrude.cpp,v 1.60 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -27,62 +27,73 @@ #include "Context.h" #include "Create.h" -extern Context_T CTX ; -extern Mesh *THEM; +extern Context_T CTX; +extern Mesh *THEM; -static int DIM, NUM; // current dimension of parent entity +static int DIM, NUM; // current dimension of parent entity static int TEST_IS_ALL_OK; static Tree_T *Tree_Ares = NULL, *Tree_Swaps = NULL, *Vertex_Bound = NULL; -static Curve *THEC=NULL; -static Surface *THES=NULL; -static Volume *THEV=NULL; +static Curve *THEC = NULL; +static Surface *THES = NULL; +static Volume *THEV = NULL; static ExtrudeParams *ep; // Vertex_Bound contains the vertices on the boundary (on the curves // for extrude_mesh(surface) and on the surfaces for // extrude_mesh(volume)) -typedef struct{ +typedef struct +{ int Dim, Num; - List_T * List; -}nxl; + List_T *List; +} +nxl; -static int compnxl (const void *a, const void *b){ - int val ; - nxl *q = (nxl *)a, *w = (nxl *)b; +static int compnxl(const void *a, const void *b) +{ + int val; + nxl *q = (nxl *) a, *w = (nxl *) b; - if ((val = q->Dim - w->Dim) != 0) return val; + if((val = q->Dim - w->Dim) != 0) + return val; return q->Num - w->Num; } -List_T* getnxl(Vertex *v, Curve *c){ +List_T *getnxl(Vertex * v, Curve * c) +{ nxl NXL; NXL.Dim = 1; NXL.Num = abs(c->Num); - nxl *NXLP = (nxl*)List_PQuery(v->Extruded_Points, &NXL, compnxl); - if(NXLP) return NXLP->List; + nxl *NXLP = (nxl *) List_PQuery(v->Extruded_Points, &NXL, compnxl); + if(NXLP) + return NXLP->List; return NULL; } -List_T* getnxl(Vertex *v, Surface *s){ +List_T *getnxl(Vertex * v, Surface * s) +{ nxl NXL; NXL.Dim = 2; NXL.Num = s->Num; - nxl *NXLP = (nxl*)List_PQuery(v->Extruded_Points, &NXL, compnxl); - if(NXLP) return NXLP->List; + nxl *NXLP = (nxl *) List_PQuery(v->Extruded_Points, &NXL, compnxl); + if(NXLP) + return NXLP->List; return NULL; } -List_T* getnxl(Vertex *v, Volume *vol){ +List_T *getnxl(Vertex * v, Volume * vol) +{ nxl NXL; NXL.Dim = 3; NXL.Num = vol->Num; - nxl *NXLP = (nxl*)List_PQuery(v->Extruded_Points, &NXL, compnxl); - if(NXLP) return NXLP->List; + nxl *NXLP = (nxl *) List_PQuery(v->Extruded_Points, &NXL, compnxl); + if(NXLP) + return NXLP->List; return NULL; } -List_T* getnxl(Vertex *v, int dim){ +List_T *getnxl(Vertex * v, int dim) +{ int i, j; Curve *c; Surface *s; @@ -91,38 +102,38 @@ List_T* getnxl(Vertex *v, int dim){ // the test on the source entity is in case we extrude a // curve/surface resulting from the extrusion of a point/curve... - if(dim==1){ + if(dim == 1) { if((list = getnxl(v, THEC))) return list; } - else if(dim==2){ + else if(dim == 2) { if((list = getnxl(v, THES))) return list; - else{ - for(i=0; i<List_Nbr(THES->Generatrices); i++){ - if((abs(ep->geo.Source)!=c->Num) && (list = getnxl(v, c))) - return list; + else { + for(i = 0; i < List_Nbr(THES->Generatrices); i++) { + if((abs(ep->geo.Source) != c->Num) && (list = getnxl(v, c))) + return list; } } } - else if(dim==3){ - if((list = getnxl(v, THEV))) + else if(dim == 3) { + if((list = getnxl(v, THEV))) return list; - else{ - for(i=0; i<List_Nbr(THEV->Surfaces); i++){ - List_Read(THEV->Surfaces, i, &s); - if((ep->geo.Source!=s->Num) && (list = getnxl(v, s))) - return list; + else { + for(i = 0; i < List_Nbr(THEV->Surfaces); i++) { + List_Read(THEV->Surfaces, i, &s); + if((ep->geo.Source != s->Num) && (list = getnxl(v, s))) + return list; } - for(i=0; i<List_Nbr(THEV->Surfaces); i++){ - List_Read(THEV->Surfaces, i, &s); - if(ep->geo.Source!=s->Num){ - for(j=0; j<List_Nbr(s->Generatrices); j++){ - List_Read(s->Generatrices, j, &c); - if((list = getnxl(v, c))) - return list; - } - } + for(i = 0; i < List_Nbr(THEV->Surfaces); i++) { + List_Read(THEV->Surfaces, i, &s); + if(ep->geo.Source != s->Num) { + for(j = 0; j < List_Nbr(s->Generatrices); j++) { + List_Read(s->Generatrices, j, &c); + if((list = getnxl(v, c))) + return list; + } + } } } } @@ -131,35 +142,40 @@ List_T* getnxl(Vertex *v, int dim){ return NULL; } -void Free_ExtrudedPoints(List_T* Extruded_Points){ +void Free_ExtrudedPoints(List_T * Extruded_Points) +{ nxl *NXL; - for(int i=0; i<List_Nbr(Extruded_Points); i++){ - NXL = (nxl*)List_Pointer(Extruded_Points, i); + for(int i = 0; i < List_Nbr(Extruded_Points); i++) { + NXL = (nxl *) List_Pointer(Extruded_Points, i); List_Delete(NXL->List); } List_Delete(Extruded_Points); } -typedef struct{ +typedef struct +{ int a, b; -}nxn; +} +nxn; -static int compnxn (const void *a, const void *b){ +static int compnxn(const void *a, const void *b) +{ nxn *q, *w; q = (nxn *) a; w = (nxn *) b; - if (q->a > w->a) + if(q->a > w->a) return 1; - if (q->a < w->a) + if(q->a < w->a) return -1; - if (q->b > w->b) + if(q->b > w->b) return 1; - if (q->b < w->b) + if(q->b < w->b) return -1; return 0; } -void ReplaceInVertexBound(void *a, void *b){ +void ReplaceInVertexBound(void *a, void *b) +{ //Warning! We must do a 'replace', and not an 'add'/'insert'! //Otherwise, we get 'Points' mixed up with 'Vertices'. The old //extrusion (applied to a 2D extruded mesh) would then crash since @@ -168,12 +184,16 @@ void ReplaceInVertexBound(void *a, void *b){ Tree_Replace(Vertex_Bound, a); } -void InitExtrude (){ - if(!Tree_Ares) Tree_Ares = Tree_Create (sizeof (nxn), compnxn); - if(!Tree_Swaps) Tree_Swaps = Tree_Create (sizeof (nxn), compnxn); +void InitExtrude() +{ + if(!Tree_Ares) + Tree_Ares = Tree_Create(sizeof(nxn), compnxn); + if(!Tree_Swaps) + Tree_Swaps = Tree_Create(sizeof(nxn), compnxn); - if(Vertex_Bound) Tree_Delete(Vertex_Bound); - Vertex_Bound = Tree_Create (sizeof (Vertex *), comparePosition); + if(Vertex_Bound) + Tree_Delete(Vertex_Bound); + Vertex_Bound = Tree_Create(sizeof(Vertex *), comparePosition); //ceci doit etre enleve: ca fout le boxon si des points du maillage //correspondent a des points de controle de la geometrie, lors du Free. @@ -182,36 +202,44 @@ void InitExtrude (){ Tree_Action(THEM->Vertices, ReplaceInVertexBound); } -void ExitExtrude (){ - if(Tree_Ares) Tree_Delete(Tree_Ares); - if(Tree_Swaps) Tree_Delete(Tree_Swaps); - if(Vertex_Bound) Tree_Delete (Vertex_Bound); +void ExitExtrude() +{ + if(Tree_Ares) + Tree_Delete(Tree_Ares); + if(Tree_Swaps) + Tree_Delete(Tree_Swaps); + if(Vertex_Bound) + Tree_Delete(Vertex_Bound); Tree_Ares = Tree_Swaps = Vertex_Bound = NULL; } -int are_exist (Vertex * v1, Vertex * v2, Tree_T * t){ +int are_exist(Vertex * v1, Vertex * v2, Tree_T * t) +{ nxn n; - n.a = IMAX (v1->Num, v2->Num); - n.b = IMIN (v1->Num, v2->Num); - return Tree_Search (t, &n); + n.a = IMAX(v1->Num, v2->Num); + n.b = IMIN(v1->Num, v2->Num); + return Tree_Search(t, &n); } -void are_cree (Vertex * v1, Vertex * v2, Tree_T * t){ +void are_cree(Vertex * v1, Vertex * v2, Tree_T * t) +{ nxn n; - n.a = IMAX (v1->Num, v2->Num); - n.b = IMIN (v1->Num, v2->Num); - Tree_Replace (t, &n); + n.a = IMAX(v1->Num, v2->Num); + n.b = IMIN(v1->Num, v2->Num); + Tree_Replace(t, &n); } -void are_del (Vertex * v1, Vertex * v2, Tree_T * t){ +void are_del(Vertex * v1, Vertex * v2, Tree_T * t) +{ nxn n; - n.a = IMAX (v1->Num, v2->Num); - n.b = IMIN (v1->Num, v2->Num); - Tree_Suppress (t, &n); + n.a = IMAX(v1->Num, v2->Num); + n.b = IMIN(v1->Num, v2->Num); + Tree_Suppress(t, &n); } -void Extrude_Simplex_Phase1 (void *data, void *dum){ +void Extrude_Simplex_Phase1(void *data, void *dum) +{ Simplex **pS, *s; int i, j, k; Vertex *v1, *v2, *v3, *v4, *v5, *v6; @@ -220,163 +248,168 @@ void Extrude_Simplex_Phase1 (void *data, void *dum){ pS = (Simplex **) data; s = *pS; - L0 = getnxl(s->V[0],DIM); - L1 = getnxl(s->V[1],DIM); - L2 = getnxl(s->V[2],DIM); + L0 = getnxl(s->V[0], DIM); + L1 = getnxl(s->V[1], DIM); + L2 = getnxl(s->V[2], DIM); k = 0; - for (i = 0; i < ep->mesh.NbLayer; i++){ - for (j = 0; j < ep->mesh.NbElmLayer[i]; j++){ - List_Read (L0, k, &v1); - List_Read (L1, k, &v2); - List_Read (L2, k, &v3); - List_Read (L0, k + 1, &v4); - List_Read (L1, k + 1, &v5); - List_Read (L2, k + 1, &v6); + for(i = 0; i < ep->mesh.NbLayer; i++) { + for(j = 0; j < ep->mesh.NbElmLayer[i]; j++) { + List_Read(L0, k, &v1); + List_Read(L1, k, &v2); + List_Read(L2, k, &v3); + List_Read(L0, k + 1, &v4); + List_Read(L1, k + 1, &v5); + List_Read(L2, k + 1, &v6); k++; - if (!are_exist (v1, v5, Tree_Ares)) - are_cree (v2, v4, Tree_Ares); - if (!are_exist (v5, v3, Tree_Ares)) - are_cree (v2, v6, Tree_Ares); - if (!are_exist (v4, v3, Tree_Ares)) - are_cree (v1, v6, Tree_Ares); + if(!are_exist(v1, v5, Tree_Ares)) + are_cree(v2, v4, Tree_Ares); + if(!are_exist(v5, v3, Tree_Ares)) + are_cree(v2, v6, Tree_Ares); + if(!are_exist(v4, v3, Tree_Ares)) + are_cree(v1, v6, Tree_Ares); } } } -void Create_HexPri(int iEnt, Vertex *v[8]){ - int i, j=0, dup[4]; +void Create_HexPri(int iEnt, Vertex * v[8]) +{ + int i, j = 0, dup[4]; Hexahedron *newh; Prism *newp; - if(CTX.mesh.allow_degenerated_extrude){ - newh = Create_Hexahedron(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7]); + if(CTX.mesh.allow_degenerated_extrude) { + newh = Create_Hexahedron(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); newh->iEnt = iEnt; - Tree_Add(THEV->Hexahedra,&newh); + Tree_Add(THEV->Hexahedra, &newh); return; } - for(i=0; i<4; i++) - if(v[i]->Num == v[i+4]->Num) dup[j++] = i; - - if(j==2){ - if(dup[0]==0 && dup[1]==1) - newp = Create_Prism(v[0],v[3],v[7],v[1],v[6],v[2]); - else if(dup[0]==1 && dup[1]==2) - newp = Create_Prism(v[0],v[1],v[4],v[3],v[2],v[7]); - else if(dup[0]==2 && dup[1]==3) - newp = Create_Prism(v[0],v[3],v[4],v[1],v[5],v[7]); - else if(dup[0]==0 && dup[1]==3) - newp = Create_Prism(v[0],v[1],v[5],v[3],v[2],v[6]); - else{ + for(i = 0; i < 4; i++) + if(v[i]->Num == v[i + 4]->Num) + dup[j++] = i; + + if(j == 2) { + if(dup[0] == 0 && dup[1] == 1) + newp = Create_Prism(v[0], v[3], v[7], v[1], v[6], v[2]); + else if(dup[0] == 1 && dup[1] == 2) + newp = Create_Prism(v[0], v[1], v[4], v[3], v[2], v[7]); + else if(dup[0] == 2 && dup[1] == 3) + newp = Create_Prism(v[0], v[3], v[4], v[1], v[5], v[7]); + else if(dup[0] == 0 && dup[1] == 3) + newp = Create_Prism(v[0], v[1], v[5], v[3], v[2], v[6]); + else { Msg(GERROR, "Uncoherent hexahedron (nodes %d %d %d %d %d %d %d %d)", - v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7]); + v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); return; } newp->iEnt = iEnt; - Tree_Add(THEV->Prisms,&newp); + Tree_Add(THEV->Prisms, &newp); } - else{ - newh = Create_Hexahedron(v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7]); + else { + newh = Create_Hexahedron(v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); newh->iEnt = iEnt; - Tree_Add(THEV->Hexahedra,&newh); + Tree_Add(THEV->Hexahedra, &newh); if(j) - Msg(GERROR, "Degenerated hexahedron %d (nodes %d %d %d %d %d %d %d %d)", - newh->Num,v[0],v[1],v[2],v[3],v[4],v[5],v[6],v[7]); + Msg(GERROR, "Degenerated hexahedron %d (nodes %d %d %d %d %d %d %d %d)", + newh->Num, v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); } } -void Create_PriPyrTet(int iEnt, Vertex *v[6]){ - int i, j=0, dup[3]; +void Create_PriPyrTet(int iEnt, Vertex * v[6]) +{ + int i, j = 0, dup[3]; Prism *newp; Pyramid *newpyr; Simplex *news; - if(CTX.mesh.allow_degenerated_extrude){ - newp = Create_Prism(v[0],v[1],v[2],v[3],v[4],v[5]); + if(CTX.mesh.allow_degenerated_extrude) { + newp = Create_Prism(v[0], v[1], v[2], v[3], v[4], v[5]); newp->iEnt = iEnt; - Tree_Add(THEV->Prisms,&newp); + Tree_Add(THEV->Prisms, &newp); return; } - for(i=0; i<3; i++) - if(v[i]->Num == v[i+3]->Num) dup[j++] = i; + for(i = 0; i < 3; i++) + if(v[i]->Num == v[i + 3]->Num) + dup[j++] = i; - if(j==2){ - if(dup[0]==0 && dup[1]==1) - news = Create_Simplex(v[0],v[1],v[2],v[5]); - else if(dup[0]==1 && dup[1]==2) - news = Create_Simplex(v[0],v[1],v[2],v[3]); + if(j == 2) { + if(dup[0] == 0 && dup[1] == 1) + news = Create_Simplex(v[0], v[1], v[2], v[5]); + else if(dup[0] == 1 && dup[1] == 2) + news = Create_Simplex(v[0], v[1], v[2], v[3]); else - news = Create_Simplex(v[0],v[1],v[2],v[4]); + news = Create_Simplex(v[0], v[1], v[2], v[4]); news->iEnt = iEnt; - Tree_Add(THEV->Simplexes,&news); + Tree_Add(THEV->Simplexes, &news); } - else if(j==1){ - if(dup[0]==0) - newpyr = Create_Pyramid(v[1],v[4],v[5],v[2],v[0]); - else if(dup[0]==1) - newpyr = Create_Pyramid(v[0],v[2],v[5],v[3],v[1]); + else if(j == 1) { + if(dup[0] == 0) + newpyr = Create_Pyramid(v[1], v[4], v[5], v[2], v[0]); + else if(dup[0] == 1) + newpyr = Create_Pyramid(v[0], v[2], v[5], v[3], v[1]); else - newpyr = Create_Pyramid(v[0],v[1],v[4],v[3],v[2]); + newpyr = Create_Pyramid(v[0], v[1], v[4], v[3], v[2]); newpyr->iEnt = iEnt; - Tree_Add(THEV->Pyramids,&newpyr); + Tree_Add(THEV->Pyramids, &newpyr); } - else{ - newp = Create_Prism(v[0],v[1],v[2],v[3],v[4],v[5]); + else { + newp = Create_Prism(v[0], v[1], v[2], v[3], v[4], v[5]); newp->iEnt = iEnt; - Tree_Add(THEV->Prisms,&newp); + Tree_Add(THEV->Prisms, &newp); if(j) - Msg(GERROR, "Degenerated prism %d (nodes %d %d %d %d %d %d)", - newp->Num,v[0],v[1],v[2],v[3],v[4],v[5]); + Msg(GERROR, "Degenerated prism %d (nodes %d %d %d %d %d %d)", + newp->Num, v[0], v[1], v[2], v[3], v[4], v[5]); } } -void Extrude_Simplex_Phase3 (void *data, void *dum){ - +void Extrude_Simplex_Phase3(void *data, void *dum) +{ Simplex **pS, *s, *news; int i, j, k; Vertex *v[8]; - List_T *L0, *L1, *L2, *L3=NULL; + List_T *L0, *L1, *L2, *L3 = NULL; pS = (Simplex **) data; s = *pS; - if(s->V[3] && !ep->mesh.Recombine){ + if(s->V[3] && !ep->mesh.Recombine) { Msg(GERROR, "You have to use 'Recombine' to extrude quadrangular meshes"); return; } - L0 = getnxl(s->V[0],DIM); - L1 = getnxl(s->V[1],DIM); - L2 = getnxl(s->V[2],DIM); - if(s->V[3]) L3 = getnxl(s->V[3],DIM); + L0 = getnxl(s->V[0], DIM); + L1 = getnxl(s->V[1], DIM); + L2 = getnxl(s->V[2], DIM); + if(s->V[3]) + L3 = getnxl(s->V[3], DIM); //printf("orig: %d %d %d %d\n",s->V[0]->Num,s->V[1]->Num,s->V[2]->Num,s->V[3]->Num); k = 0; - for (i = 0; i < ep->mesh.NbLayer; i++){ - for (j = 0; j < ep->mesh.NbElmLayer[i]; j++){ + for(i = 0; i < ep->mesh.NbLayer; i++) { + for(j = 0; j < ep->mesh.NbElmLayer[i]; j++) { - if(s->V[3]){ - List_Read(L0,k,&v[0]); - List_Read(L1,k,&v[1]); - List_Read(L2,k,&v[2]); - List_Read(L3,k,&v[3]); + if(s->V[3]) { + List_Read(L0, k, &v[0]); + List_Read(L1, k, &v[1]); + List_Read(L2, k, &v[2]); + List_Read(L3, k, &v[3]); - //printf(" 1: %d %d %d %d\n",v[0]->Num,v[1]->Num,v[2]->Num,v[3]->Num); + //printf(" 1: %d %d %d %d\n",v[0]->Num,v[1]->Num,v[2]->Num,v[3]->Num); - List_Read(L0,k+1,&v[4]); - List_Read(L1,k+1,&v[5]); - List_Read(L2,k+1,&v[6]); - List_Read(L3,k+1,&v[7]); + List_Read(L0, k + 1, &v[4]); + List_Read(L1, k + 1, &v[5]); + List_Read(L2, k + 1, &v[6]); + List_Read(L3, k + 1, &v[7]); - //printf(" 2: %d %d %d %d\n",v[4]->Num,v[5]->Num,v[6]->Num,v[7]->Num); + //printf(" 2: %d %d %d %d\n",v[4]->Num,v[5]->Num,v[6]->Num,v[7]->Num); - } - else{ + } + else { List_Read(L0, k, &v[0]); List_Read(L1, k, &v[1]); List_Read(L2, k, &v[2]); @@ -386,93 +419,93 @@ void Extrude_Simplex_Phase3 (void *data, void *dum){ } k++; - if (ep->mesh.ZonLayer[i]){ + if(ep->mesh.ZonLayer[i]) { - if(ep->mesh.Recombine){ + if(ep->mesh.Recombine) { if(s->V[3]) - Create_HexPri(ep->mesh.ZonLayer[i],v); + Create_HexPri(ep->mesh.ZonLayer[i], v); else - Create_PriPyrTet(ep->mesh.ZonLayer[i],v); + Create_PriPyrTet(ep->mesh.ZonLayer[i], v); } - else{ - - if (are_exist (v[3], v[1], Tree_Ares) && - are_exist (v[4], v[2], Tree_Ares) && - are_exist (v[3], v[2], Tree_Ares)){ - news = Create_Simplex (v[0], v[1], v[2], v[3]); + else { + + if(are_exist(v[3], v[1], Tree_Ares) && + are_exist(v[4], v[2], Tree_Ares) && + are_exist(v[3], v[2], Tree_Ares)) { + news = Create_Simplex(v[0], v[1], v[2], v[3]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); - news = Create_Simplex (v[3], v[4], v[5], v[2]); + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v[3], v[4], v[5], v[2]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); - news = Create_Simplex (v[1], v[3], v[4], v[2]); + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v[1], v[3], v[4], v[2]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); + Tree_Add(THEV->Simplexes, &news); } - if (are_exist (v[3], v[1], Tree_Ares) && - are_exist (v[1], v[5], Tree_Ares) && - are_exist (v[3], v[2], Tree_Ares)){ - news = Create_Simplex (v[0], v[1], v[2], v[3]); + if(are_exist(v[3], v[1], Tree_Ares) && + are_exist(v[1], v[5], Tree_Ares) && + are_exist(v[3], v[2], Tree_Ares)) { + news = Create_Simplex(v[0], v[1], v[2], v[3]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); - news = Create_Simplex (v[3], v[4], v[5], v[1]); + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v[3], v[4], v[5], v[1]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); - news = Create_Simplex (v[3], v[1], v[5], v[2]); + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v[3], v[1], v[5], v[2]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); + Tree_Add(THEV->Simplexes, &news); } - if (are_exist (v[3], v[1], Tree_Ares) && - are_exist (v[1], v[5], Tree_Ares) && - are_exist (v[5], v[0], Tree_Ares)){ - news = Create_Simplex (v[0], v[1], v[2], v[5]); + if(are_exist(v[3], v[1], Tree_Ares) && + are_exist(v[1], v[5], Tree_Ares) && + are_exist(v[5], v[0], Tree_Ares)) { + news = Create_Simplex(v[0], v[1], v[2], v[5]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); - news = Create_Simplex (v[3], v[4], v[5], v[1]); + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v[3], v[4], v[5], v[1]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); - news = Create_Simplex (v[1], v[3], v[5], v[0]); + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v[1], v[3], v[5], v[0]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); + Tree_Add(THEV->Simplexes, &news); } - if (are_exist (v[4], v[0], Tree_Ares) && - are_exist (v[4], v[2], Tree_Ares) && - are_exist (v[3], v[2], Tree_Ares)){ - news = Create_Simplex (v[0], v[1], v[2], v[4]); + if(are_exist(v[4], v[0], Tree_Ares) && + are_exist(v[4], v[2], Tree_Ares) && + are_exist(v[3], v[2], Tree_Ares)) { + news = Create_Simplex(v[0], v[1], v[2], v[4]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); - news = Create_Simplex (v[3], v[4], v[5], v[2]); + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v[3], v[4], v[5], v[2]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); - news = Create_Simplex (v[0], v[3], v[4], v[2]); + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v[0], v[3], v[4], v[2]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); + Tree_Add(THEV->Simplexes, &news); } - if (are_exist (v[4], v[0], Tree_Ares) && - are_exist (v[4], v[2], Tree_Ares) && - are_exist (v[5], v[0], Tree_Ares)){ - news = Create_Simplex (v[0], v[1], v[2], v[4]); + if(are_exist(v[4], v[0], Tree_Ares) && + are_exist(v[4], v[2], Tree_Ares) && + are_exist(v[5], v[0], Tree_Ares)) { + news = Create_Simplex(v[0], v[1], v[2], v[4]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); - news = Create_Simplex (v[3], v[4], v[5], v[0]); + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v[3], v[4], v[5], v[0]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); - news = Create_Simplex (v[0], v[2], v[4], v[5]); + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v[0], v[2], v[4], v[5]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); + Tree_Add(THEV->Simplexes, &news); } - if (are_exist (v[4], v[0], Tree_Ares) && - are_exist (v[1], v[5], Tree_Ares) && - are_exist (v[5], v[0], Tree_Ares)){ - news = Create_Simplex (v[0], v[1], v[2], v[5]); + if(are_exist(v[4], v[0], Tree_Ares) && + are_exist(v[1], v[5], Tree_Ares) && + are_exist(v[5], v[0], Tree_Ares)) { + news = Create_Simplex(v[0], v[1], v[2], v[5]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); - news = Create_Simplex (v[3], v[4], v[5], v[0]); + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v[3], v[4], v[5], v[0]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); - news = Create_Simplex (v[0], v[1], v[4], v[5]); + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v[0], v[1], v[4], v[5]); news->iEnt = ep->mesh.ZonLayer[i]; - Tree_Add (THEV->Simplexes, &news); + Tree_Add(THEV->Simplexes, &news); } } } @@ -480,8 +513,8 @@ void Extrude_Simplex_Phase3 (void *data, void *dum){ } } -void Extrude_Simplex_Phase2 (void *data, void *dum){ - +void Extrude_Simplex_Phase2(void *data, void *dum) +{ Simplex **pS, *s; int i, j, k; Vertex *v1, *v2, *v3, *v4, *v5, *v6; @@ -490,65 +523,63 @@ void Extrude_Simplex_Phase2 (void *data, void *dum){ pS = (Simplex **) data; s = *pS; - L0 = getnxl(s->V[0],DIM); - L1 = getnxl(s->V[1],DIM); - L2 = getnxl(s->V[2],DIM); + L0 = getnxl(s->V[0], DIM); + L1 = getnxl(s->V[1], DIM); + L2 = getnxl(s->V[2], DIM); k = 0; - for (i = 0; i < ep->mesh.NbLayer; i++){ - for (j = 0; j < ep->mesh.NbElmLayer[i]; j++){ - List_Read (L0, k, &v1); - List_Read (L1, k, &v2); - List_Read (L2, k, &v3); - List_Read (L0, k + 1, &v4); - List_Read (L1, k + 1, &v5); - List_Read (L2, k + 1, &v6); + for(i = 0; i < ep->mesh.NbLayer; i++) { + for(j = 0; j < ep->mesh.NbElmLayer[i]; j++) { + List_Read(L0, k, &v1); + List_Read(L1, k, &v2); + List_Read(L2, k, &v3); + List_Read(L0, k + 1, &v4); + List_Read(L1, k + 1, &v5); + List_Read(L2, k + 1, &v6); k++; //if((double)rand()/(double)RAND_MAX < 0.1) break; - if (are_exist (v4, v2, Tree_Ares) && - are_exist (v5, v3, Tree_Ares) && - are_exist (v1, v6, Tree_Ares)){ + if(are_exist(v4, v2, Tree_Ares) && + are_exist(v5, v3, Tree_Ares) && are_exist(v1, v6, Tree_Ares)) { TEST_IS_ALL_OK++; - if (!are_exist (v4, v2, Tree_Swaps)){ - are_del (v4, v2, Tree_Ares); - are_cree (v1, v5, Tree_Ares); - are_cree (v1, v5, Tree_Swaps); - are_cree (v4, v2, Tree_Swaps); + if(!are_exist(v4, v2, Tree_Swaps)) { + are_del(v4, v2, Tree_Ares); + are_cree(v1, v5, Tree_Ares); + are_cree(v1, v5, Tree_Swaps); + are_cree(v4, v2, Tree_Swaps); } - else if (!are_exist (v5, v3, Tree_Swaps)){ - are_del (v5, v3, Tree_Ares); - are_cree (v2, v6, Tree_Ares); - are_cree (v5, v3, Tree_Swaps); - are_cree (v2, v6, Tree_Swaps); + else if(!are_exist(v5, v3, Tree_Swaps)) { + are_del(v5, v3, Tree_Ares); + are_cree(v2, v6, Tree_Ares); + are_cree(v5, v3, Tree_Swaps); + are_cree(v2, v6, Tree_Swaps); } - else if (!are_exist (v1, v6, Tree_Swaps)){ - are_del (v1, v6, Tree_Ares); - are_cree (v4, v3, Tree_Ares); - are_cree (v1, v6, Tree_Swaps); - are_cree (v4, v3, Tree_Swaps); + else if(!are_exist(v1, v6, Tree_Swaps)) { + are_del(v1, v6, Tree_Ares); + are_cree(v4, v3, Tree_Ares); + are_cree(v1, v6, Tree_Swaps); + are_cree(v4, v3, Tree_Swaps); } } - else if (are_exist (v1, v5, Tree_Ares) && - are_exist (v2, v6, Tree_Ares) && - are_exist (v4, v3, Tree_Ares)){ + else if(are_exist(v1, v5, Tree_Ares) && + are_exist(v2, v6, Tree_Ares) && are_exist(v4, v3, Tree_Ares)) { TEST_IS_ALL_OK++; - if (!are_exist (v1, v5, Tree_Swaps)){ - are_del (v1, v5, Tree_Ares); - are_cree (v4, v2, Tree_Ares); - are_cree (v1, v5, Tree_Swaps); - are_cree (v4, v2, Tree_Swaps); + if(!are_exist(v1, v5, Tree_Swaps)) { + are_del(v1, v5, Tree_Ares); + are_cree(v4, v2, Tree_Ares); + are_cree(v1, v5, Tree_Swaps); + are_cree(v4, v2, Tree_Swaps); } - else if (!are_exist (v2, v6, Tree_Swaps)){ - are_del (v2, v6, Tree_Ares); - are_cree (v5, v3, Tree_Ares); - are_cree (v5, v3, Tree_Swaps); - are_cree (v2, v6, Tree_Swaps); + else if(!are_exist(v2, v6, Tree_Swaps)) { + are_del(v2, v6, Tree_Ares); + are_cree(v5, v3, Tree_Ares); + are_cree(v5, v3, Tree_Swaps); + are_cree(v2, v6, Tree_Swaps); } - else if (!are_exist (v4, v3, Tree_Swaps)){ - are_del (v4, v3, Tree_Ares); - are_cree (v1, v6, Tree_Ares); - are_cree (v1, v6, Tree_Swaps); - are_cree (v4, v3, Tree_Swaps); + else if(!are_exist(v4, v3, Tree_Swaps)) { + are_del(v4, v3, Tree_Ares); + are_cree(v1, v6, Tree_Ares); + are_cree(v1, v6, Tree_Swaps); + are_cree(v4, v3, Tree_Swaps); } } } @@ -556,117 +587,124 @@ void Extrude_Simplex_Phase2 (void *data, void *dum){ } -void Extrude_Vertex (void *data, void *dum){ +void Extrude_Vertex(void *data, void *dum) +{ Vertex **pV, *v, *newv; int i, j; nxl NXL; - v = *((Vertex**)data); + v = *((Vertex **) data); if(!v->Extruded_Points) - v->Extruded_Points = List_Create (1, 1, sizeof (nxl)); + v->Extruded_Points = List_Create(1, 1, sizeof(nxl)); NXL.Num = NUM; NXL.Dim = DIM; if(List_Search(v->Extruded_Points, &NXL, compnxl)) return; else - NXL.List = List_Create(ep->mesh.NbLayer, 1, sizeof (Vertex *)); + NXL.List = List_Create(ep->mesh.NbLayer, 1, sizeof(Vertex *)); - List_Add (NXL.List, &v); + List_Add(NXL.List, &v); - for (i = 0; i < ep->mesh.NbLayer; i++){ - for (j = 0; j < ep->mesh.NbElmLayer[i]; j++){ - newv = Create_Vertex (++THEM->MaxPointNum, v->Pos.X, - v->Pos.Y, v->Pos.Z, v->lc, v->u); - ep->Extrude (i, j + 1, newv->Pos.X, newv->Pos.Y, newv->Pos.Z); + for(i = 0; i < ep->mesh.NbLayer; i++) { + for(j = 0; j < ep->mesh.NbElmLayer[i]; j++) { + newv = Create_Vertex(++THEM->MaxPointNum, v->Pos.X, + v->Pos.Y, v->Pos.Z, v->lc, v->u); + ep->Extrude(i, j + 1, newv->Pos.X, newv->Pos.Y, newv->Pos.Z); - if (Vertex_Bound && (pV = (Vertex **) Tree_PQuery (Vertex_Bound, &newv))){ - Free_Vertex (&newv,0); - List_Add (NXL.List, pV); + if(Vertex_Bound && (pV = (Vertex **) Tree_PQuery(Vertex_Bound, &newv))) { + Free_Vertex(&newv, 0); + List_Add(NXL.List, pV); } - else{ - List_Add (NXL.List, &newv); - Tree_Insert (THEM->Vertices, &newv); - Tree_Insert (Vertex_Bound, &newv); + else { + List_Add(NXL.List, &newv); + Tree_Insert(THEM->Vertices, &newv); + Tree_Insert(Vertex_Bound, &newv); } } } - List_Add(v->Extruded_Points, &NXL); + List_Add(v->Extruded_Points, &NXL); } -void Extrude_Surface1 (Surface * s){ +void Extrude_Surface1(Surface * s) +{ THES = s; - Tree_Action (s->Vertices, Extrude_Vertex); - if(!ep->mesh.Recombine) Tree_Action (s->Simplexes, Extrude_Simplex_Phase1); + Tree_Action(s->Vertices, Extrude_Vertex); + if(!ep->mesh.Recombine) + Tree_Action(s->Simplexes, Extrude_Simplex_Phase1); } -void Extrude_Surface2 (Surface * s){ +void Extrude_Surface2(Surface * s) +{ THES = s; - Tree_Action (s->Simplexes, Extrude_Simplex_Phase2); + Tree_Action(s->Simplexes, Extrude_Simplex_Phase2); } -void Extrude_Surface3 (Surface * s){ +void Extrude_Surface3(Surface * s) +{ THES = s; - Tree_Action (s->Simplexes, Extrude_Simplex_Phase3); + Tree_Action(s->Simplexes, Extrude_Simplex_Phase3); } -void Create_Tri(Vertex *v1, Vertex *v2, Vertex *v3){ +void Create_Tri(Vertex * v1, Vertex * v2, Vertex * v3) +{ Simplex *s; if(CTX.mesh.allow_degenerated_extrude || - (v1->Num != v2->Num && v1->Num != v3->Num && v2->Num != v3->Num)){ - s = Create_Simplex (v1, v2, v3, NULL); + (v1->Num != v2->Num && v1->Num != v3->Num && v2->Num != v3->Num)) { + s = Create_Simplex(v1, v2, v3, NULL); s->iEnt = THES->Num; - s->Num = -s->Num; //Tag triangles to re-extrude - Tree_Add (THES->Simplexes, &s); + s->Num = -s->Num; //Tag triangles to re-extrude + Tree_Add(THES->Simplexes, &s); } } -void Extrude_Seg (Vertex * V1, Vertex * V2){ +void Extrude_Seg(Vertex * V1, Vertex * V2) +{ int i, j, k; Vertex *v1, *v2, *v3, *v4; Simplex *s; List_T *L1, *L2; - L1 = getnxl(V1,DIM); - L2 = getnxl(V2,DIM); + L1 = getnxl(V1, DIM); + L2 = getnxl(V2, DIM); k = 0; - for (i = 0; i < ep->mesh.NbLayer; i++){ - for (j = 0; j < ep->mesh.NbElmLayer[i]; j++){ - List_Read (L1, k, &v1); - List_Read (L2, k, &v2); - List_Read (L1, k + 1, &v3); - List_Read (L2, k + 1, &v4); - if(ep->mesh.Recombine){ - if(CTX.mesh.allow_degenerated_extrude) - s = Create_Quadrangle(v1,v2,v4,v3); - else if(v1->Num == v2->Num || v2->Num == v4->Num) - s = Create_Simplex (v1, v4, v3, NULL); - else if(v1->Num == v3->Num || v3->Num == v4->Num) - s = Create_Simplex (v1, v2, v4, NULL); - else if(v1->Num == v4->Num || v2->Num == v3->Num){ - Msg(GERROR, "Uncoherent quadrangle (nodes %d %d %d %d)", - v1->Num,v2->Num,v3->Num,v4->Num); - return; - } - else - s = Create_Quadrangle(v1,v2,v4,v3); - s->iEnt = THES->Num; - s->Num = -s->Num; //Tag quadrangles to re-extrude - Tree_Add(THES->Simplexes,&s); - - // This is horrible - THEM->Statistics[8] += 1; + for(i = 0; i < ep->mesh.NbLayer; i++) { + for(j = 0; j < ep->mesh.NbElmLayer[i]; j++) { + List_Read(L1, k, &v1); + List_Read(L2, k, &v2); + List_Read(L1, k + 1, &v3); + List_Read(L2, k + 1, &v4); + if(ep->mesh.Recombine) { + if(CTX.mesh.allow_degenerated_extrude) + s = Create_Quadrangle(v1, v2, v4, v3); + else if(v1->Num == v2->Num || v2->Num == v4->Num) + s = Create_Simplex(v1, v4, v3, NULL); + else if(v1->Num == v3->Num || v3->Num == v4->Num) + s = Create_Simplex(v1, v2, v4, NULL); + else if(v1->Num == v4->Num || v2->Num == v3->Num) { + Msg(GERROR, "Uncoherent quadrangle (nodes %d %d %d %d)", + v1->Num, v2->Num, v3->Num, v4->Num); + return; + } + else + s = Create_Quadrangle(v1, v2, v4, v3); + s->iEnt = THES->Num; + s->Num = -s->Num; //Tag quadrangles to re-extrude + Tree_Add(THES->Simplexes, &s); + + // This is horrible + THEM->Statistics[8] += 1; } - else{ - if (are_exist (v3, v2, Tree_Ares)){ - Create_Tri(v3, v2, v1); + else { + if(are_exist(v3, v2, Tree_Ares)) { + Create_Tri(v3, v2, v1); Create_Tri(v3, v4, v2); } - else{ + else { Create_Tri(v3, v4, v1); Create_Tri(v1, v4, v2); } @@ -674,10 +712,11 @@ void Extrude_Seg (Vertex * V1, Vertex * V2){ k++; } } - + } -void Extrude_Curve (void *data, void *dum){ +void Extrude_Curve(void *data, void *dum) +{ Curve **pC, *c; Vertex *v1, *v2; int i; @@ -686,82 +725,90 @@ void Extrude_Curve (void *data, void *dum){ //if (c->Num < 0) return; - for (i = 0; i < List_Nbr (c->Vertices) - 1; i++){ - List_Read (c->Vertices, i, &v1); - List_Read (c->Vertices, i + 1, &v2); - Extrude_Seg (v1, v2); + for(i = 0; i < List_Nbr(c->Vertices) - 1; i++) { + List_Read(c->Vertices, i, &v1); + List_Read(c->Vertices, i + 1, &v2); + Extrude_Seg(v1, v2); } } -void copy_mesh (Curve * from, Curve * to, int direction){ +void copy_mesh(Curve * from, Curve * to, int direction) +{ List_T *list = from->Vertices; Vertex *vi, *v, **vexist; int nb = List_Nbr(to->Vertices); - if(nb){ + if(nb) { if(nb != List_Nbr(from->Vertices)) Msg(GERROR, "Uncompatible extrusion of curve %d into curve %d", - from->Num, to->Num); + from->Num, to->Num); return; } - to->Vertices = List_Create (List_Nbr(from->Vertices), 2, sizeof (Vertex *)); + to->Vertices = List_Create(List_Nbr(from->Vertices), 2, sizeof(Vertex *)); v = to->beg; - if ((vexist = (Vertex **) Tree_PQuery (THEM->Vertices, &v))){ + if((vexist = (Vertex **) Tree_PQuery(THEM->Vertices, &v))) { (*vexist)->u = to->ubeg; - if ((*vexist)->ListCurves) List_Add ((*vexist)->ListCurves, &to); - List_Add (to->Vertices, vexist); + if((*vexist)->ListCurves) + List_Add((*vexist)->ListCurves, &to); + List_Add(to->Vertices, vexist); } - else{ + else { vi = Create_Vertex(v->Num, v->Pos.X, v->Pos.Y, v->Pos.Z, v->lc, to->ubeg); Tree_Insert(THEM->Vertices, &vi); - vi->ListCurves = List_Create (1, 1, sizeof (Curve *)); + vi->ListCurves = List_Create(1, 1, sizeof(Curve *)); List_Add(vi->ListCurves, &to); List_Add(to->Vertices, &vi); } - for (int i = 1; i < List_Nbr(list)-1; i++){ - if(direction < 0) - List_Read (list, List_Nbr(list)-1-i, &v); + for(int i = 1; i < List_Nbr(list) - 1; i++) { + if(direction < 0) + List_Read(list, List_Nbr(list) - 1 - i, &v); else - List_Read (list, i, &v); - vi = Create_Vertex (++THEM->MaxPointNum, v->Pos.X, - v->Pos.Y, v->Pos.Z, v->lc, (direction>0)?v->u:(1.-v->u)); - ep->Extrude (ep->mesh.NbLayer - 1, ep->mesh.NbElmLayer[ep->mesh.NbLayer - 1], - vi->Pos.X, vi->Pos.Y, vi->Pos.Z); - if(!comparePosition(&vi,&v)){ - Free_Vertex(&vi,0); + List_Read(list, i, &v); + vi = Create_Vertex(++THEM->MaxPointNum, v->Pos.X, + v->Pos.Y, v->Pos.Z, v->lc, + (direction > 0) ? v->u : (1. - v->u)); + ep->Extrude(ep->mesh.NbLayer - 1, + ep->mesh.NbElmLayer[ep->mesh.NbLayer - 1], vi->Pos.X, + vi->Pos.Y, vi->Pos.Z); + if(!comparePosition(&vi, &v)) { + Free_Vertex(&vi, 0); vi = v; } - Tree_Insert (THEM->Vertices, &vi); - if(!vi->ListCurves) vi->ListCurves = List_Create (1, 1, sizeof (Curve *)); + Tree_Insert(THEM->Vertices, &vi); + if(!vi->ListCurves) + vi->ListCurves = List_Create(1, 1, sizeof(Curve *)); List_Add(vi->ListCurves, &to); List_Add(to->Vertices, &vi); } v = to->end; - if ((vexist = (Vertex **) Tree_PQuery (THEM->Vertices, &v))){ + if((vexist = (Vertex **) Tree_PQuery(THEM->Vertices, &v))) { (*vexist)->u = to->uend; - if ((*vexist)->ListCurves) List_Add ((*vexist)->ListCurves, &to); - List_Add (to->Vertices, vexist); + if((*vexist)->ListCurves) + List_Add((*vexist)->ListCurves, &to); + List_Add(to->Vertices, vexist); } - else{ - vi = Create_Vertex (v->Num, v->Pos.X, v->Pos.Y, v->Pos.Z, v->lc, to->uend); - Tree_Insert (THEM->Vertices, &vi); - vi->ListCurves = List_Create (1, 1, sizeof (Curve *)); - List_Add (vi->ListCurves, &to); - List_Add (to->Vertices, &vi); + else { + vi = Create_Vertex(v->Num, v->Pos.X, v->Pos.Y, v->Pos.Z, v->lc, to->uend); + Tree_Insert(THEM->Vertices, &vi); + vi->ListCurves = List_Create(1, 1, sizeof(Curve *)); + List_Add(vi->ListCurves, &to); + List_Add(to->Vertices, &vi); } } -int Extrude_Mesh (Curve * c){ +int Extrude_Mesh(Curve * c) +{ int i; Vertex *v, *pV, **vexist; List_T *L; - if (!c->Extrude || !c->Extrude->mesh.ExtrudeMesh) return false; + if(!c->Extrude || !c->Extrude->mesh.ExtrudeMesh) + return false; InitExtrude(); THEC = c; @@ -769,251 +816,273 @@ int Extrude_Mesh (Curve * c){ NUM = c->Num; ep = c->Extrude; - if (ep->geo.Mode == EXTRUDED_ENTITY){ - Extrude_Vertex (&c->beg, NULL); - L = getnxl(c->beg,DIM); - c->Vertices = List_Create (List_Nbr(L), 2, sizeof (Vertex *)); + if(ep->geo.Mode == EXTRUDED_ENTITY) { + Extrude_Vertex(&c->beg, NULL); + L = getnxl(c->beg, DIM); + c->Vertices = List_Create(List_Nbr(L), 2, sizeof(Vertex *)); v = c->beg; - if ((vexist = (Vertex **) Tree_PQuery (THEM->Vertices, &v))){ + if((vexist = (Vertex **) Tree_PQuery(THEM->Vertices, &v))) { (*vexist)->u = c->ubeg; - if ((*vexist)->ListCurves) List_Add ((*vexist)->ListCurves, &c); - List_Add (c->Vertices, vexist); + if((*vexist)->ListCurves) + List_Add((*vexist)->ListCurves, &c); + List_Add(c->Vertices, vexist); } - else{ - pV = Create_Vertex (v->Num, v->Pos.X, v->Pos.Y, v->Pos.Z, v->lc, 0.0); - pV->ListCurves = List_Create (1, 1, sizeof (Curve *)); - List_Add (pV->ListCurves, &c); + else { + pV = Create_Vertex(v->Num, v->Pos.X, v->Pos.Y, v->Pos.Z, v->lc, 0.0); + pV->ListCurves = List_Create(1, 1, sizeof(Curve *)); + List_Add(pV->ListCurves, &c); Tree_Insert(THEM->Vertices, &pV); List_Add(c->Vertices, &pV); } - for (i = 1; i < List_Nbr(L)-1; i++){ - List_Read (L, i, &v); - if (!v->ListCurves) v->ListCurves = List_Create(1, 1, sizeof (Curve *)); + for(i = 1; i < List_Nbr(L) - 1; i++) { + List_Read(L, i, &v); + if(!v->ListCurves) + v->ListCurves = List_Create(1, 1, sizeof(Curve *)); List_Add(v->ListCurves, &c); Tree_Insert(THEM->Vertices, &v); v->u = (double)i / (double)List_Nbr(L); - List_Add (c->Vertices, &v); + List_Add(c->Vertices, &v); } v = c->end; - if ((vexist = (Vertex **) Tree_PQuery (THEM->Vertices, &v))){ + if((vexist = (Vertex **) Tree_PQuery(THEM->Vertices, &v))) { (*vexist)->u = c->uend; - if ((*vexist)->ListCurves) List_Add ((*vexist)->ListCurves, &c); - List_Add (c->Vertices, vexist); + if((*vexist)->ListCurves) + List_Add((*vexist)->ListCurves, &c); + List_Add(c->Vertices, vexist); } - else{ - pV = Create_Vertex (v->Num, v->Pos.X, v->Pos.Y, v->Pos.Z, v->lc, 0.0); - pV->ListCurves = List_Create (1, 1, sizeof (Curve *)); - List_Add (pV->ListCurves, &c); + else { + pV = Create_Vertex(v->Num, v->Pos.X, v->Pos.Y, v->Pos.Z, v->lc, 0.0); + pV->ListCurves = List_Create(1, 1, sizeof(Curve *)); + List_Add(pV->ListCurves, &c); Tree_Insert(THEM->Vertices, &pV); List_Add(c->Vertices, &pV); } return true; } - else{ + else { Curve *cc = FindCurve(abs(ep->geo.Source), THEM); - if(!cc) return false; + if(!cc) + return false; copy_mesh(cc, c, sign(ep->geo.Source)); return true; } } -void copy_mesh (Surface * from, Surface * to){ - List_T *list = Tree2List (from->Simplexes); +void copy_mesh(Surface * from, Surface * to) +{ + List_T *list = Tree2List(from->Simplexes); Simplex *s, *news; Vertex **pV, *vi[4], *v; int nb = Tree_Nbr(to->Simplexes); - if(nb){ + if(nb) { if(nb != Tree_Nbr(from->Simplexes)) Msg(GERROR, "Uncompatible extrusion of surface %d into surface %d", - from->Num, to->Num); + from->Num, to->Num); return; } - for (int i = 0; i < List_Nbr(list); i++){ - List_Read (list, i, &s); - for (int j = 0; j < 4; j++){ - if(s->V[j]){ - v = s->V[j]; - vi[j] = Create_Vertex(++THEM->MaxPointNum, v->Pos.X, - v->Pos.Y, v->Pos.Z, v->lc, v->u); - ep->Extrude(ep->mesh.NbLayer - 1, ep->mesh.NbElmLayer[ep->mesh.NbLayer - 1], - vi[j]->Pos.X, vi[j]->Pos.Y, vi[j]->Pos.Z); - if (Vertex_Bound && (pV = (Vertex **) Tree_PQuery(Vertex_Bound, &vi[j]))){ - Free_Vertex(&vi[j],0); - vi[j] = *pV; - } - else{ - Tree_Insert(THEM->Vertices, &vi[j]); - Tree_Insert(Vertex_Bound, &vi[j]); - } + for(int i = 0; i < List_Nbr(list); i++) { + List_Read(list, i, &s); + for(int j = 0; j < 4; j++) { + if(s->V[j]) { + v = s->V[j]; + vi[j] = Create_Vertex(++THEM->MaxPointNum, v->Pos.X, + v->Pos.Y, v->Pos.Z, v->lc, v->u); + ep->Extrude(ep->mesh.NbLayer - 1, + ep->mesh.NbElmLayer[ep->mesh.NbLayer - 1], vi[j]->Pos.X, + vi[j]->Pos.Y, vi[j]->Pos.Z); + if(Vertex_Bound + && (pV = (Vertex **) Tree_PQuery(Vertex_Bound, &vi[j]))) { + Free_Vertex(&vi[j], 0); + vi[j] = *pV; + } + else { + Tree_Insert(THEM->Vertices, &vi[j]); + Tree_Insert(Vertex_Bound, &vi[j]); + } } - else{ - vi[j] = NULL; + else { + vi[j] = NULL; } - } - if(vi[3]){ - news = Create_Quadrangle (vi[0], vi[1], vi[2], vi[3]); + } + if(vi[3]) { + news = Create_Quadrangle(vi[0], vi[1], vi[2], vi[3]); // This is horrible THEM->Statistics[8] += 1; } else - news = Create_Simplex (vi[0], vi[1], vi[2], NULL); + news = Create_Simplex(vi[0], vi[1], vi[2], NULL); news->iEnt = to->Num; - Tree_Add (to->Simplexes, &news); + Tree_Add(to->Simplexes, &news); } - List_Delete (list); + List_Delete(list); } -void AddVertsInSurf(void *a, void *b){ - Simplex *s=*(Simplex**)a; - for(int i=0;i<4;i++) - if(s->V[i]) Tree_Replace(THES->Vertices, &s->V[i]); +void AddVertsInSurf(void *a, void *b) +{ + Simplex *s = *(Simplex **) a; + for(int i = 0; i < 4; i++) + if(s->V[i]) + Tree_Replace(THES->Vertices, &s->V[i]); } -int Extrude_Mesh (Surface * s){ +int Extrude_Mesh(Surface * s) +{ int i; Vertex *v1; Curve *c; extern int FACE_DIMENSION; - if (!s->Extrude || !s->Extrude->mesh.ExtrudeMesh) return false; + if(!s->Extrude || !s->Extrude->mesh.ExtrudeMesh) + return false; - InitExtrude (); + InitExtrude(); THES = s; DIM = 2; NUM = s->Num; ep = s->Extrude; FACE_DIMENSION = 2; - if (ep->geo.Mode == EXTRUDED_ENTITY){ - c = FindCurve (abs(ep->geo.Source), THEM); - if (!c) return false; - for (i = 0; i < List_Nbr (c->Vertices); i++){ - List_Read (c->Vertices, i, &v1); - Extrude_Vertex (&v1, NULL); + if(ep->geo.Mode == EXTRUDED_ENTITY) { + c = FindCurve(abs(ep->geo.Source), THEM); + if(!c) + return false; + for(i = 0; i < List_Nbr(c->Vertices); i++) { + List_Read(c->Vertices, i, &v1); + Extrude_Vertex(&v1, NULL); } - Extrude_Curve (&c, NULL); + Extrude_Curve(&c, NULL); } - else{ - Surface *ss = FindSurface (ep->geo.Source, THEM); - if (!ss) return false; - copy_mesh (ss, s); + else { + Surface *ss = FindSurface(ep->geo.Source, THEM); + if(!ss) + return false; + copy_mesh(ss, s); } - + Tree_Action(s->Simplexes, AddVertsInSurf); return true; } -static Tree_T* tmp; +static Tree_T *tmp; -void Free_NegativeSimplex (void *a, void *b){ - Simplex *s = *(Simplex**)a; - if(s){ - if(s->Num>=0){ - Tree_Add (tmp, &s); +void Free_NegativeSimplex(void *a, void *b) +{ + Simplex *s = *(Simplex **) a; + if(s) { + if(s->Num >= 0) { + Tree_Add(tmp, &s); } - else{ + else { delete s; s = NULL; } } } -int Extrude_Mesh (Volume * v){ +int Extrude_Mesh(Volume * v) +{ ep = v->Extrude; - if (ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY) return true; - else return false; + if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY) + return true; + else + return false; } -int Extrude_Mesh (Tree_T * Volumes){ - int i, j, extrude=0; +int Extrude_Mesh(Tree_T * Volumes) +{ + int i, j, extrude = 0; Surface *s; List_T *list; - InitExtrude (); + InitExtrude(); DIM = 3; List_T *vol = Tree2List(Volumes); - for (int ivol = 0; ivol < List_Nbr(vol); ivol++){ + for(int ivol = 0; ivol < List_Nbr(vol); ivol++) { List_Read(vol, ivol, &THEV); ep = THEV->Extrude; - if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY) extrude = 1; + if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY) + extrude = 1; } - if(!extrude) return false; + if(!extrude) + return false; Msg(STATUS2, "Mesh 3D... (initial)"); - for (int ivol = 0; ivol < List_Nbr (vol); ivol++){ + for(int ivol = 0; ivol < List_Nbr(vol); ivol++) { List_Read(vol, ivol, &THEV); ep = THEV->Extrude; NUM = THEV->Num; - if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY){ - s = FindSurface (ep->geo.Source, THEM); - if(s){ - Msg(STATUS3, "Meshing Volume %d", NUM); - Extrude_Surface1 (s); + if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY) { + s = FindSurface(ep->geo.Source, THEM); + if(s) { + Msg(STATUS3, "Meshing Volume %d", NUM); + Extrude_Surface1(s); } } } j = 0; - do{ - TEST_IS_ALL_OK=0; - for (int ivol = 0; ivol < List_Nbr (vol); ivol++){ + do { + TEST_IS_ALL_OK = 0; + for(int ivol = 0; ivol < List_Nbr(vol); ivol++) { List_Read(vol, ivol, &THEV); ep = THEV->Extrude; NUM = THEV->Num; - if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY && - !ep->mesh.Recombine){ - s = FindSurface (ep->geo.Source, THEM); - if(s) Extrude_Surface2 (s); + if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY && + !ep->mesh.Recombine) { + s = FindSurface(ep->geo.Source, THEM); + if(s) + Extrude_Surface2(s); } } - Msg(STATUS3, "Swapping %d", TEST_IS_ALL_OK); - if(TEST_IS_ALL_OK == j){ - if(j) Msg(GERROR, "Unable to swap all edges: try Recombine..."); + Msg(STATUS3, "Swapping %d", TEST_IS_ALL_OK); + if(TEST_IS_ALL_OK == j) { + if(j) + Msg(GERROR, "Unable to swap all edges: try Recombine..."); break; } j = TEST_IS_ALL_OK; - }while(TEST_IS_ALL_OK); + } while(TEST_IS_ALL_OK); - Msg(STATUS2, "Mesh 3D... (Final)"); + Msg(STATUS2, "Mesh 3D... (Final)"); - for (int ivol = 0; ivol < List_Nbr (vol); ivol++){ + for(int ivol = 0; ivol < List_Nbr(vol); ivol++) { List_Read(vol, ivol, &THEV); ep = THEV->Extrude; NUM = THEV->Num; - if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY){ - s = FindSurface (ep->geo.Source, THEM); - if(s){ - Msg(STATUS3, "Meshing Volume %d", NUM); - Extrude_Surface3 (s); + if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY) { + s = FindSurface(ep->geo.Source, THEM); + if(s) { + Msg(STATUS3, "Meshing Volume %d", NUM); + Extrude_Surface3(s); } } } - list= List_Create(100,100,sizeof(Surface*)); - for (int ivol = 0; ivol < List_Nbr (vol); ivol++){ + list = List_Create(100, 100, sizeof(Surface *)); + for(int ivol = 0; ivol < List_Nbr(vol); ivol++) { List_Read(vol, ivol, &THEV); ep = THEV->Extrude; - if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY && - !ep->mesh.Recombine){ - for (i = 0; i < List_Nbr (THEV->Surfaces); i++){ - List_Read(THEV->Surfaces, i, &s); - if(!List_Search(list, &s, compareSurface)) - List_Add(list, &s); + if(ep && ep->mesh.ExtrudeMesh && ep->geo.Mode == EXTRUDED_ENTITY && + !ep->mesh.Recombine) { + for(i = 0; i < List_Nbr(THEV->Surfaces); i++) { + List_Read(THEV->Surfaces, i, &s); + if(!List_Search(list, &s, compareSurface)) + List_Add(list, &s); } } } - for(i = 0; i<List_Nbr(list); i++){ - List_Read (list, i, &s); - tmp = Tree_Create (sizeof (Simplex *), compareQuality); + for(i = 0; i < List_Nbr(list); i++) { + List_Read(list, i, &s); + tmp = Tree_Create(sizeof(Simplex *), compareQuality); Tree_Action(s->Simplexes, Free_NegativeSimplex); Tree_Delete(s->Simplexes); s->Simplexes = tmp; @@ -1027,4 +1096,3 @@ int Extrude_Mesh (Tree_T * Volumes){ return true; } - diff --git a/Mesh/3D_Extrude_Old.cpp b/Mesh/3D_Extrude_Old.cpp index 79c4508a2aaea8d84768fe3d3b6db3254521f157..ba57e750e02193c8c2c82dbafcea658e5ce82d03 100644 --- a/Mesh/3D_Extrude_Old.cpp +++ b/Mesh/3D_Extrude_Old.cpp @@ -1,4 +1,4 @@ -// $Id: 3D_Extrude_Old.cpp,v 1.22 2003-01-23 20:19:21 geuzaine Exp $ +// $Id: 3D_Extrude_Old.cpp,v 1.23 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -52,589 +52,621 @@ #include "Context.h" #include "Create.h" -extern Context_T CTX ; -extern Mesh *LOCAL, *THEM; +extern Context_T CTX; +extern Mesh *LOCAL, *THEM; static Tree_T *Tree_Ares, *Tree_Swaps; -Surface *THES; -Volume *THEV; -int TEST_IS_ALL_OK, NbLayer; -int NbElmLayer [MAXLAYERS]; -int ZonLayer [MAXLAYERS]; -int LineLayer [MAXLAYERS+1]; -int SurfLayer [MAXLAYERS+1]; -double hLayer [MAXLAYERS]; -double parLayer [MAXLAYERS]; - - -typedef struct { - int a,b; -}nxn; - -static int compnxn(const void *a, const void *b){ - nxn *q,*w; - q = (nxn*)a; - w = (nxn*)b; - if(q->a > w->a)return 1; - if(q->a < w->a)return -1; - if(q->b > w->b)return 1; - if(q->b < w->b)return -1; +Surface *THES; +Volume *THEV; +int TEST_IS_ALL_OK, NbLayer; +int NbElmLayer[MAXLAYERS]; +int ZonLayer[MAXLAYERS]; +int LineLayer[MAXLAYERS + 1]; +int SurfLayer[MAXLAYERS + 1]; +double hLayer[MAXLAYERS]; +double parLayer[MAXLAYERS]; + + +typedef struct +{ + int a, b; +} +nxn; + +static int compnxn(const void *a, const void *b) +{ + nxn *q, *w; + q = (nxn *) a; + w = (nxn *) b; + if(q->a > w->a) + return 1; + if(q->a < w->a) + return -1; + if(q->b > w->b) + return 1; + if(q->b < w->b) + return -1; return 0; } -static void InitExtrudeParams (void){ +static void InitExtrudeParams(void) +{ FILE *file; int i; printf("Number of layers: "); - scanf("%d",&NbLayer); - if(NbLayer>MAXLAYERS) Msg(FATAL, "Max number of layer (%d) exceeded", MAXLAYERS); - - file = fopen("xtrude","w"); - - if(file) fprintf(file, "%d\n", NbLayer); - for(i=0;i<NbLayer;i++){ - printf("Number of elements in layer %d: ",i+1); - scanf("%d",&NbElmLayer[i]); - if(file) fprintf(file, "%d\n", NbElmLayer[i]); - - printf("Depth of layer %d: ",i+1); - scanf("%lf",&hLayer[i]); - if(file) fprintf(file, "%g\n", hLayer[i]); - - printf("Progresion ratio for layer %d: ",i+1); - scanf("%lf",&parLayer[i]); - if(file) fprintf(file, "%g\n", parLayer[i]); + scanf("%d", &NbLayer); + if(NbLayer > MAXLAYERS) + Msg(FATAL, "Max number of layer (%d) exceeded", MAXLAYERS); + + file = fopen("xtrude", "w"); + + if(file) + fprintf(file, "%d\n", NbLayer); + for(i = 0; i < NbLayer; i++) { + printf("Number of elements in layer %d: ", i + 1); + scanf("%d", &NbElmLayer[i]); + if(file) + fprintf(file, "%d\n", NbElmLayer[i]); + + printf("Depth of layer %d: ", i + 1); + scanf("%lf", &hLayer[i]); + if(file) + fprintf(file, "%g\n", hLayer[i]); + + printf("Progresion ratio for layer %d: ", i + 1); + scanf("%lf", &parLayer[i]); + if(file) + fprintf(file, "%g\n", parLayer[i]); } - - if(file){ + + if(file) { fflush(file); fclose(file); } - Tree_Ares = Tree_Create(sizeof(nxn),compnxn); - Tree_Swaps = Tree_Create(sizeof(nxn),compnxn); + Tree_Ares = Tree_Create(sizeof(nxn), compnxn); + Tree_Swaps = Tree_Create(sizeof(nxn), compnxn); } -static int are_exist(Vertex *v1,Vertex *v2, Tree_T *t){ +static int are_exist(Vertex * v1, Vertex * v2, Tree_T * t) +{ nxn n; - n.a = IMAX(v1->Num,v2->Num); - n.b = IMIN(v1->Num,v2->Num); - return Tree_Search(t,&n); + n.a = IMAX(v1->Num, v2->Num); + n.b = IMIN(v1->Num, v2->Num); + return Tree_Search(t, &n); } -static void are_cree(Vertex *v1,Vertex *v2, Tree_T *t){ +static void are_cree(Vertex * v1, Vertex * v2, Tree_T * t) +{ nxn n; - n.a = IMAX(v1->Num,v2->Num); - n.b = IMIN(v1->Num,v2->Num); - Tree_Replace(t,&n); + n.a = IMAX(v1->Num, v2->Num); + n.b = IMIN(v1->Num, v2->Num); + Tree_Replace(t, &n); } -static void are_del(Vertex *v1,Vertex *v2, Tree_T *t){ +static void are_del(Vertex * v1, Vertex * v2, Tree_T * t) +{ nxn n; - n.a = IMAX(v1->Num,v2->Num); - n.b = IMIN(v1->Num,v2->Num); - Tree_Suppress(t,&n); + n.a = IMAX(v1->Num, v2->Num); + n.b = IMIN(v1->Num, v2->Num); + Tree_Suppress(t, &n); } -static void Extrude_Simplex_Phase1 (void *data , void *dum){ - - Simplex **pS , *s; - int i,j,k; - Vertex *v1,*v2,*v3,*v4,*v5,*v6; +static void Extrude_Simplex_Phase1(void *data, void *dum) +{ + Simplex **pS, *s; + int i, j, k; + Vertex *v1, *v2, *v3, *v4, *v5, *v6; - pS = (Simplex**)data; + pS = (Simplex **) data; s = *pS; k = 0; - for(i=0;i<NbLayer;i++){ - for(j=0;j<NbElmLayer[i];j++){ - List_Read(s->V[0]->Extruded_Points,k,&v1); - List_Read(s->V[1]->Extruded_Points,k,&v2); - List_Read(s->V[2]->Extruded_Points,k,&v3); - List_Read(s->V[0]->Extruded_Points,k+1,&v4); - List_Read(s->V[1]->Extruded_Points,k+1,&v5); - List_Read(s->V[2]->Extruded_Points,k+1,&v6); + for(i = 0; i < NbLayer; i++) { + for(j = 0; j < NbElmLayer[i]; j++) { + List_Read(s->V[0]->Extruded_Points, k, &v1); + List_Read(s->V[1]->Extruded_Points, k, &v2); + List_Read(s->V[2]->Extruded_Points, k, &v3); + List_Read(s->V[0]->Extruded_Points, k + 1, &v4); + List_Read(s->V[1]->Extruded_Points, k + 1, &v5); + List_Read(s->V[2]->Extruded_Points, k + 1, &v6); k++; - if(!are_exist(v1,v5,Tree_Ares))are_cree(v2,v4,Tree_Ares); - if(!are_exist(v5,v3,Tree_Ares))are_cree(v2,v6,Tree_Ares); - if(!are_exist(v4,v3,Tree_Ares))are_cree(v1,v6,Tree_Ares); + if(!are_exist(v1, v5, Tree_Ares)) + are_cree(v2, v4, Tree_Ares); + if(!are_exist(v5, v3, Tree_Ares)) + are_cree(v2, v6, Tree_Ares); + if(!are_exist(v4, v3, Tree_Ares)) + are_cree(v1, v6, Tree_Ares); } - } + } } -static void Extrude_Simplex_Phase3 (void *data , void *dum){ - - Simplex **pS , *s, *news; - Prism *newp; +static void Extrude_Simplex_Phase3(void *data, void *dum) +{ + Simplex **pS, *s, *news; + Prism *newp; Hexahedron *newh; - int i,j,k; - Vertex *v1,*v2,*v3,*v4,*v5,*v6,*v7,*v8; + int i, j, k; + Vertex *v1, *v2, *v3, *v4, *v5, *v6, *v7, *v8; - pS = (Simplex**)data; + pS = (Simplex **) data; s = *pS; - if(s->V[3] && !CTX.mesh.oldxtrude_recombine){ - Msg(GERROR, "Non recombined extrusion impossible with quadrangles (use -recombine)"); + if(s->V[3] && !CTX.mesh.oldxtrude_recombine) { + Msg(GERROR, + "Non recombined extrusion impossible with quadrangles (use -recombine)"); } k = 0; - for(i=0;i<=NbLayer;i++){ - if(SurfLayer[i]){ - List_Read(s->V[0]->Extruded_Points,k,&v1); - List_Read(s->V[1]->Extruded_Points,k,&v2); - List_Read(s->V[2]->Extruded_Points,k,&v3); - news = Create_Simplex(v1,v2,v3,NULL); - if(s->V[3]){ - List_Read(s->V[3]->Extruded_Points,k,&v4); - news->V[3] = v4; + for(i = 0; i <= NbLayer; i++) { + if(SurfLayer[i]) { + List_Read(s->V[0]->Extruded_Points, k, &v1); + List_Read(s->V[1]->Extruded_Points, k, &v2); + List_Read(s->V[2]->Extruded_Points, k, &v3); + news = Create_Simplex(v1, v2, v3, NULL); + if(s->V[3]) { + List_Read(s->V[3]->Extruded_Points, k, &v4); + news->V[3] = v4; } news->iEnt = SurfLayer[i]; - Tree_Add(THEV->Simp_Surf,&news); + Tree_Add(THEV->Simp_Surf, &news); } - for(j=0;j<NbElmLayer[i];j++){ + for(j = 0; j < NbElmLayer[i]; j++) { k++; } } - + k = 0; - for(i=0;i<NbLayer;i++){ - for(j=0;j<NbElmLayer[i];j++){ - - if(s->V[3]){ - List_Read(s->V[0]->Extruded_Points,k,&v1); - List_Read(s->V[1]->Extruded_Points,k,&v2); - List_Read(s->V[2]->Extruded_Points,k,&v3); - List_Read(s->V[3]->Extruded_Points,k,&v4); - List_Read(s->V[0]->Extruded_Points,k+1,&v5); - List_Read(s->V[1]->Extruded_Points,k+1,&v6); - List_Read(s->V[2]->Extruded_Points,k+1,&v7); - List_Read(s->V[3]->Extruded_Points,k+1,&v8); + for(i = 0; i < NbLayer; i++) { + for(j = 0; j < NbElmLayer[i]; j++) { + + if(s->V[3]) { + List_Read(s->V[0]->Extruded_Points, k, &v1); + List_Read(s->V[1]->Extruded_Points, k, &v2); + List_Read(s->V[2]->Extruded_Points, k, &v3); + List_Read(s->V[3]->Extruded_Points, k, &v4); + List_Read(s->V[0]->Extruded_Points, k + 1, &v5); + List_Read(s->V[1]->Extruded_Points, k + 1, &v6); + List_Read(s->V[2]->Extruded_Points, k + 1, &v7); + List_Read(s->V[3]->Extruded_Points, k + 1, &v8); } - else{ - List_Read(s->V[0]->Extruded_Points,k,&v1); - List_Read(s->V[1]->Extruded_Points,k,&v2); - List_Read(s->V[2]->Extruded_Points,k,&v3); - List_Read(s->V[0]->Extruded_Points,k+1,&v4); - List_Read(s->V[1]->Extruded_Points,k+1,&v5); - List_Read(s->V[2]->Extruded_Points,k+1,&v6); + else { + List_Read(s->V[0]->Extruded_Points, k, &v1); + List_Read(s->V[1]->Extruded_Points, k, &v2); + List_Read(s->V[2]->Extruded_Points, k, &v3); + List_Read(s->V[0]->Extruded_Points, k + 1, &v4); + List_Read(s->V[1]->Extruded_Points, k + 1, &v5); + List_Read(s->V[2]->Extruded_Points, k + 1, &v6); } k++; - if(ZonLayer[i]){ - if(CTX.mesh.oldxtrude_recombine){ - if(s->V[3]){ - newh = Create_Hexahedron(v1,v2,v3,v4,v5,v6,v7,v8); - newh->iEnt = ZonLayer[i]; - Tree_Add(THEV->Hexahedra,&newh); - } - else{ - newp = Create_Prism(v1,v2,v3,v4,v5,v6); - newp->iEnt = ZonLayer[i]; - Tree_Add(THEV->Prisms,&newp); - } - } - else{ - if(are_exist(v4,v2,Tree_Ares) && - are_exist(v5,v3,Tree_Ares) && - are_exist(v4,v3,Tree_Ares) ){ - news = Create_Simplex(v1,v2,v3,v4); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - news = Create_Simplex(v4,v5,v6,v3); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - news = Create_Simplex(v2,v4,v5,v3); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - } - if(are_exist(v4,v2,Tree_Ares) && - are_exist(v2,v6,Tree_Ares) && - are_exist(v4,v3,Tree_Ares) ){ - news = Create_Simplex(v1,v2,v3,v4); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - news = Create_Simplex(v4,v5,v6,v2); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - news = Create_Simplex(v4,v2,v6,v3); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - } - if(are_exist(v4,v2,Tree_Ares) && - are_exist(v2,v6,Tree_Ares) && - are_exist(v6,v1,Tree_Ares) ){ - news = Create_Simplex(v1,v2,v3,v6); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - news = Create_Simplex(v4,v5,v6,v2); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - news = Create_Simplex(v2,v4,v6,v1); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - } - if(are_exist(v5,v1,Tree_Ares) && - are_exist(v5,v3,Tree_Ares) && - are_exist(v4,v3,Tree_Ares) ){ - news = Create_Simplex(v1,v2,v3,v5); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - news = Create_Simplex(v4,v5,v6,v3); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - news = Create_Simplex(v1,v4,v5,v3); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - } - if(are_exist(v5,v1,Tree_Ares) && - are_exist(v5,v3,Tree_Ares) && - are_exist(v6,v1,Tree_Ares) ){ - news = Create_Simplex(v1,v2,v3,v5); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - news = Create_Simplex(v4,v5,v6,v1); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - news = Create_Simplex(v1,v3,v5,v6); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - } - if(are_exist(v5,v1,Tree_Ares) && - are_exist(v2,v6,Tree_Ares) && - are_exist(v6,v1,Tree_Ares) ){ - news = Create_Simplex(v1,v2,v3,v6); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - news = Create_Simplex(v4,v5,v6,v1); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - news = Create_Simplex(v1,v2,v5,v6); - news->iEnt = ZonLayer[i]; - Tree_Add(THEV->Simplexes,&news); - } - } + if(ZonLayer[i]) { + if(CTX.mesh.oldxtrude_recombine) { + if(s->V[3]) { + newh = Create_Hexahedron(v1, v2, v3, v4, v5, v6, v7, v8); + newh->iEnt = ZonLayer[i]; + Tree_Add(THEV->Hexahedra, &newh); + } + else { + newp = Create_Prism(v1, v2, v3, v4, v5, v6); + newp->iEnt = ZonLayer[i]; + Tree_Add(THEV->Prisms, &newp); + } + } + else { + if(are_exist(v4, v2, Tree_Ares) && + are_exist(v5, v3, Tree_Ares) && are_exist(v4, v3, Tree_Ares)) { + news = Create_Simplex(v1, v2, v3, v4); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v4, v5, v6, v3); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v2, v4, v5, v3); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + } + if(are_exist(v4, v2, Tree_Ares) && + are_exist(v2, v6, Tree_Ares) && are_exist(v4, v3, Tree_Ares)) { + news = Create_Simplex(v1, v2, v3, v4); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v4, v5, v6, v2); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v4, v2, v6, v3); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + } + if(are_exist(v4, v2, Tree_Ares) && + are_exist(v2, v6, Tree_Ares) && are_exist(v6, v1, Tree_Ares)) { + news = Create_Simplex(v1, v2, v3, v6); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v4, v5, v6, v2); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v2, v4, v6, v1); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + } + if(are_exist(v5, v1, Tree_Ares) && + are_exist(v5, v3, Tree_Ares) && are_exist(v4, v3, Tree_Ares)) { + news = Create_Simplex(v1, v2, v3, v5); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v4, v5, v6, v3); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v1, v4, v5, v3); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + } + if(are_exist(v5, v1, Tree_Ares) && + are_exist(v5, v3, Tree_Ares) && are_exist(v6, v1, Tree_Ares)) { + news = Create_Simplex(v1, v2, v3, v5); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v4, v5, v6, v1); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v1, v3, v5, v6); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + } + if(are_exist(v5, v1, Tree_Ares) && + are_exist(v2, v6, Tree_Ares) && are_exist(v6, v1, Tree_Ares)) { + news = Create_Simplex(v1, v2, v3, v6); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v4, v5, v6, v1); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + news = Create_Simplex(v1, v2, v5, v6); + news->iEnt = ZonLayer[i]; + Tree_Add(THEV->Simplexes, &news); + } + } } } - } + } } -static void Extrude_Simplex_Phase2 (void *data , void *dum){ - - Simplex **pS , *s; - int i,j,k; - Vertex *v1,*v2,*v3,*v4,*v5,*v6; +static void Extrude_Simplex_Phase2(void *data, void *dum) +{ + Simplex **pS, *s; + int i, j, k; + Vertex *v1, *v2, *v3, *v4, *v5, *v6; - pS = (Simplex**)data; + pS = (Simplex **) data; s = *pS; k = 0; - for(i=0;i<NbLayer;i++){ - for(j=0;j<NbElmLayer[i];j++){ - List_Read(s->V[0]->Extruded_Points,k,&v1); - List_Read(s->V[1]->Extruded_Points,k,&v2); - List_Read(s->V[2]->Extruded_Points,k,&v3); - List_Read(s->V[0]->Extruded_Points,k+1,&v4); - List_Read(s->V[1]->Extruded_Points,k+1,&v5); - List_Read(s->V[2]->Extruded_Points,k+1,&v6); + for(i = 0; i < NbLayer; i++) { + for(j = 0; j < NbElmLayer[i]; j++) { + List_Read(s->V[0]->Extruded_Points, k, &v1); + List_Read(s->V[1]->Extruded_Points, k, &v2); + List_Read(s->V[2]->Extruded_Points, k, &v3); + List_Read(s->V[0]->Extruded_Points, k + 1, &v4); + List_Read(s->V[1]->Extruded_Points, k + 1, &v5); + List_Read(s->V[2]->Extruded_Points, k + 1, &v6); k++; - if(are_exist(v4,v2,Tree_Ares) && - are_exist(v5,v3,Tree_Ares) && - are_exist(v1,v6,Tree_Ares)){ - TEST_IS_ALL_OK++; - if(!are_exist(v4,v2,Tree_Swaps)){ - are_del(v4,v2,Tree_Ares); - are_cree(v1,v5,Tree_Ares); - are_cree(v1,v5,Tree_Swaps); - are_cree(v4,v2,Tree_Swaps); - } - else if(!are_exist(v5,v3,Tree_Swaps)){ - are_del(v5,v3,Tree_Ares); - are_cree(v2,v6,Tree_Ares); - are_cree(v5,v3,Tree_Swaps); - are_cree(v2,v6,Tree_Swaps); - } - else if(!are_exist(v1,v6,Tree_Swaps)){ - are_del(v1,v6,Tree_Ares); - are_cree(v4,v3,Tree_Ares); - are_cree(v1,v6,Tree_Swaps); - are_cree(v4,v3,Tree_Swaps); - } + if(are_exist(v4, v2, Tree_Ares) && + are_exist(v5, v3, Tree_Ares) && are_exist(v1, v6, Tree_Ares)) { + TEST_IS_ALL_OK++; + if(!are_exist(v4, v2, Tree_Swaps)) { + are_del(v4, v2, Tree_Ares); + are_cree(v1, v5, Tree_Ares); + are_cree(v1, v5, Tree_Swaps); + are_cree(v4, v2, Tree_Swaps); + } + else if(!are_exist(v5, v3, Tree_Swaps)) { + are_del(v5, v3, Tree_Ares); + are_cree(v2, v6, Tree_Ares); + are_cree(v5, v3, Tree_Swaps); + are_cree(v2, v6, Tree_Swaps); + } + else if(!are_exist(v1, v6, Tree_Swaps)) { + are_del(v1, v6, Tree_Ares); + are_cree(v4, v3, Tree_Ares); + are_cree(v1, v6, Tree_Swaps); + are_cree(v4, v3, Tree_Swaps); + } } - else if(are_exist(v1,v5,Tree_Ares) && - are_exist(v2,v6,Tree_Ares) && - are_exist(v4,v3,Tree_Ares)){ - TEST_IS_ALL_OK++; - if(!are_exist(v1,v5,Tree_Swaps)){ - are_del(v1,v5,Tree_Ares); - are_cree(v4,v2,Tree_Ares); - are_cree(v1,v5,Tree_Swaps); - are_cree(v4,v2,Tree_Swaps); - } - else if(!are_exist(v2,v6,Tree_Swaps)){ - are_del(v2,v6,Tree_Ares); - are_cree(v5,v3,Tree_Ares); - are_cree(v5,v3,Tree_Swaps); - are_cree(v2,v6,Tree_Swaps); - } - else if(!are_exist(v4,v3,Tree_Swaps)){ - are_del(v4,v3,Tree_Ares); - are_cree(v1,v6,Tree_Ares); - are_cree(v1,v6,Tree_Swaps); - are_cree(v4,v3,Tree_Swaps); - } + else if(are_exist(v1, v5, Tree_Ares) && + are_exist(v2, v6, Tree_Ares) && are_exist(v4, v3, Tree_Ares)) { + TEST_IS_ALL_OK++; + if(!are_exist(v1, v5, Tree_Swaps)) { + are_del(v1, v5, Tree_Ares); + are_cree(v4, v2, Tree_Ares); + are_cree(v1, v5, Tree_Swaps); + are_cree(v4, v2, Tree_Swaps); + } + else if(!are_exist(v2, v6, Tree_Swaps)) { + are_del(v2, v6, Tree_Ares); + are_cree(v5, v3, Tree_Ares); + are_cree(v5, v3, Tree_Swaps); + are_cree(v2, v6, Tree_Swaps); + } + else if(!are_exist(v4, v3, Tree_Swaps)) { + are_del(v4, v3, Tree_Ares); + are_cree(v1, v6, Tree_Ares); + are_cree(v1, v6, Tree_Swaps); + are_cree(v4, v3, Tree_Swaps); + } } } - } + } } -static void Extrude_Vertex (void *data , void *dum){ +static void Extrude_Vertex(void *data, void *dum) +{ + Vertex **pV, *v, *newv; + int i, j; + double h, a; - Vertex **pV , *v, *newv; - int i,j; - double h,a; - - pV = (Vertex**)data; + pV = (Vertex **) data; v = *pV; - if(v->Extruded_Points)return; - v->Extruded_Points = List_Create(NbLayer,1,sizeof(Vertex*)); - List_Add(v->Extruded_Points,&v); + if(v->Extruded_Points) + return; + v->Extruded_Points = List_Create(NbLayer, 1, sizeof(Vertex *)); + List_Add(v->Extruded_Points, &v); h = 0.0; //printf("-extruding vertex %d %p\n", v->Num, v); - - for(i=0;i<NbLayer;i++){ + + for(i = 0; i < NbLayer; i++) { // Geometric progression ar^i // Sum of n (=NbElmLayer[i]) terms = hLayer[i] = a (r^n-1)/(r-1) if(parLayer[i] == 1.) - a = hLayer[i]/(double)NbElmLayer[i]; + a = hLayer[i] / (double)NbElmLayer[i]; else - a = hLayer[i] * (parLayer[i]-1.)/(pow(parLayer[i],NbElmLayer[i])-1.) ; + a = + hLayer[i] * (parLayer[i] - 1.) / (pow(parLayer[i], NbElmLayer[i]) - + 1.); - for(j=0;j<NbElmLayer[i];j++){ + for(j = 0; j < NbElmLayer[i]; j++) { //h += hLayer[i]/(double)NbElmLayer[i]; - - h += a*pow(parLayer[i],j); - newv = Create_Vertex(++THEM->MaxPointNum,v->Pos.X,v->Pos.Y,v->Pos.Z + h, v->lc , v->u ); - Tree_Add(THEM->Vertices,&newv); - List_Add(v->Extruded_Points,&newv); + h += a * pow(parLayer[i], j); + + newv = + Create_Vertex(++THEM->MaxPointNum, v->Pos.X, v->Pos.Y, v->Pos.Z + h, + v->lc, v->u); + Tree_Add(THEM->Vertices, &newv); + List_Add(v->Extruded_Points, &newv); } } } -static void Extrude_Surface1 (void *data , void *dum){ - Surface **pS , *s; - if(!NbLayer)return; - pS = (Surface**)data; +static void Extrude_Surface1(void *data, void *dum) +{ + Surface **pS, *s; + if(!NbLayer) + return; + pS = (Surface **) data; s = THES = *pS; - Tree_Action(s->Vertices,Extrude_Vertex); - if(!CTX.mesh.oldxtrude_recombine) Tree_Action(s->Simplexes,Extrude_Simplex_Phase1); + Tree_Action(s->Vertices, Extrude_Vertex); + if(!CTX.mesh.oldxtrude_recombine) + Tree_Action(s->Simplexes, Extrude_Simplex_Phase1); } -static void Extrude_Surface2 (void *data , void *dum){ - Surface **pS , *s; - if(!NbLayer)return; - pS = (Surface**)data; +static void Extrude_Surface2(void *data, void *dum) +{ + Surface **pS, *s; + if(!NbLayer) + return; + pS = (Surface **) data; s = THES = *pS; - Tree_Action(s->Simplexes,Extrude_Simplex_Phase2); + Tree_Action(s->Simplexes, Extrude_Simplex_Phase2); } -static void Extrude_Surface3 (void *data , void *dum){ - Surface **pS , *s; +static void Extrude_Surface3(void *data, void *dum) +{ + Surface **pS, *s; int i; - if(!NbLayer)return; - pS = (Surface**)data; + if(!NbLayer) + return; + pS = (Surface **) data; s = THES = *pS; /* Numerotation automatique des entites physiques */ Msg(INFO, "Extruding Surface %d", s->Num); - for(i=0;i<NbLayer;i++){ - ZonLayer[i] = (int)(3 * K1) + (int) ((i+1) * K2) + s->Num ; + for(i = 0; i < NbLayer; i++) { + ZonLayer[i] = (int)(3 * K1) + (int)((i + 1) * K2) + s->Num; } - SurfLayer[0] = s->Num ; - for(i=0;i<NbLayer;i++){ - SurfLayer[i+1] = (int)(2 * K1) + (int)((i+1) * K2) + s->Num ; + SurfLayer[0] = s->Num; + for(i = 0; i < NbLayer; i++) { + SurfLayer[i + 1] = (int)(2 * K1) + (int)((i + 1) * K2) + s->Num; } - Tree_Action(s->Simplexes,Extrude_Simplex_Phase3); + Tree_Action(s->Simplexes, Extrude_Simplex_Phase3); } -static void Extrude_Seg(Vertex *V1, Vertex *V2){ - - int i,j,k; - Vertex *v1,*v2,*v3,*v4; +static void Extrude_Seg(Vertex * V1, Vertex * V2) +{ + int i, j, k; + Vertex *v1, *v2, *v3, *v4; Simplex *s; //printf("-curve vertex %d %p %d %p\n", V1->Num, V1, V2->Num, V2); k = 0; - for(i=0;i<=NbLayer;i++){ - if(LineLayer[i]){ - List_Read(V1->Extruded_Points,k,&v1); - List_Read(V2->Extruded_Points,k,&v2); - s = Create_Simplex(v1,v2,NULL,NULL); + for(i = 0; i <= NbLayer; i++) { + if(LineLayer[i]) { + List_Read(V1->Extruded_Points, k, &v1); + List_Read(V2->Extruded_Points, k, &v2); + s = Create_Simplex(v1, v2, NULL, NULL); s->iEnt = LineLayer[i]; - Tree_Add(THEV->Simp_Surf,&s); + Tree_Add(THEV->Simp_Surf, &s); } - for(j=0;j<NbElmLayer[i];j++){ + for(j = 0; j < NbElmLayer[i]; j++) { k++; } } k = 0; - for(i=0;i<NbLayer;i++){ - for(j=0;j<NbElmLayer[i];j++){ - List_Read(V1->Extruded_Points,k,&v1); - List_Read(V2->Extruded_Points,k,&v2); - List_Read(V1->Extruded_Points,k+1,&v3); - List_Read(V2->Extruded_Points,k+1,&v4); - if(SurfLayer[i]){ - if(CTX.mesh.oldxtrude_recombine){ - s = Create_Simplex(v1,v2,v4,NULL); - s->V[3] = v3; - s->iEnt = SurfLayer[i]; - Tree_Add(THEV->Simp_Surf,&s); - } - else{ - if(are_exist(v3,v2,Tree_Ares)){ - s = Create_Simplex(v3,v2,v1,NULL); - s->iEnt = SurfLayer[i]; - Tree_Add(THEV->Simp_Surf,&s); - s = Create_Simplex(v3,v4,v2,NULL); - s->iEnt = SurfLayer[i]; - Tree_Add(THEV->Simp_Surf,&s); - } - else{ - s = Create_Simplex(v3,v4,v1,NULL); - s->iEnt = SurfLayer[i]; - Tree_Add(THEV->Simp_Surf,&s); - s = Create_Simplex(v1,v4,v2,NULL); - s->iEnt = SurfLayer[i]; - Tree_Add(THEV->Simp_Surf,&s); - } - } + for(i = 0; i < NbLayer; i++) { + for(j = 0; j < NbElmLayer[i]; j++) { + List_Read(V1->Extruded_Points, k, &v1); + List_Read(V2->Extruded_Points, k, &v2); + List_Read(V1->Extruded_Points, k + 1, &v3); + List_Read(V2->Extruded_Points, k + 1, &v4); + if(SurfLayer[i]) { + if(CTX.mesh.oldxtrude_recombine) { + s = Create_Simplex(v1, v2, v4, NULL); + s->V[3] = v3; + s->iEnt = SurfLayer[i]; + Tree_Add(THEV->Simp_Surf, &s); + } + else { + if(are_exist(v3, v2, Tree_Ares)) { + s = Create_Simplex(v3, v2, v1, NULL); + s->iEnt = SurfLayer[i]; + Tree_Add(THEV->Simp_Surf, &s); + s = Create_Simplex(v3, v4, v2, NULL); + s->iEnt = SurfLayer[i]; + Tree_Add(THEV->Simp_Surf, &s); + } + else { + s = Create_Simplex(v3, v4, v1, NULL); + s->iEnt = SurfLayer[i]; + Tree_Add(THEV->Simp_Surf, &s); + s = Create_Simplex(v1, v4, v2, NULL); + s->iEnt = SurfLayer[i]; + Tree_Add(THEV->Simp_Surf, &s); + } + } } k++; } - } + } } -static void Extrude_Curve (void *data , void *dum){ - Curve **pC , *c; - Vertex *v1,*v2; +static void Extrude_Curve(void *data, void *dum) +{ + Curve **pC, *c; + Vertex *v1, *v2; int i; - if(!NbLayer)return; - pC = (Curve**)data; + if(!NbLayer) + return; + pC = (Curve **) data; c = *pC; - - if (c->Num < 0) return; + + if(c->Num < 0) + return; /* Numerotation automatique des entites physiques */ Msg(INFO, "Extruding Curve %d", c->Num); - LineLayer[0] = c->Num ; - for(i=0;i<NbLayer;i++){ - SurfLayer[i] = (int)(1 * K1) + (int)((i+1) * K2) + c->Num ; - LineLayer[i+1] = (int)(5 * K1) + (int)((i+1) * K2) + c->Num ; + LineLayer[0] = c->Num; + for(i = 0; i < NbLayer; i++) { + SurfLayer[i] = (int)(1 * K1) + (int)((i + 1) * K2) + c->Num; + LineLayer[i + 1] = (int)(5 * K1) + (int)((i + 1) * K2) + c->Num; } - for(i=0;i<List_Nbr(c->Vertices)-1;i++){ - List_Read(c->Vertices,i,&v1); - List_Read(c->Vertices,i+1,&v2); - Extrude_Seg(v1,v2); - } + for(i = 0; i < List_Nbr(c->Vertices) - 1; i++) { + List_Read(c->Vertices, i, &v1); + List_Read(c->Vertices, i + 1, &v2); + Extrude_Seg(v1, v2); + } } -static void Extrude_Pnt(Vertex *V1){ - int i,j,k; - Vertex *v1,*v2; +static void Extrude_Pnt(Vertex * V1) +{ + int i, j, k; + Vertex *v1, *v2; Simplex *s; k = 0; - for(i=0;i<NbLayer;i++){ - for(j=0;j<NbElmLayer[i];j++){ - List_Read(V1->Extruded_Points,k,&v1); - List_Read(V1->Extruded_Points,k+1,&v2); - if(LineLayer[i]){ - s = Create_Simplex(v1,v2,NULL,NULL); - s->iEnt = LineLayer[i]; - Tree_Add(THEV->Simp_Surf,&s); + for(i = 0; i < NbLayer; i++) { + for(j = 0; j < NbElmLayer[i]; j++) { + List_Read(V1->Extruded_Points, k, &v1); + List_Read(V1->Extruded_Points, k + 1, &v2); + if(LineLayer[i]) { + s = Create_Simplex(v1, v2, NULL, NULL); + s->iEnt = LineLayer[i]; + Tree_Add(THEV->Simp_Surf, &s); } k++; } - } - + } + } -static void Extrude_Point (void *data , void *dum){ +static void Extrude_Point(void *data, void *dum) +{ Vertex **pV, *v, **pV2; int i; - if(!NbLayer)return; - pV = (Vertex**)data; + if(!NbLayer) + return; + pV = (Vertex **) data; v = *pV; - + /* Numerotation automatique des entites physiques */ Msg(INFO, "Extruding Vertex %d", v->Num); - for(i=0;i<NbLayer;i++){ - LineLayer[i] = (int)(4 * K1) + (int)((i+1) * K2) + v->Num ; + for(i = 0; i < NbLayer; i++) { + LineLayer[i] = (int)(4 * K1) + (int)((i + 1) * K2) + v->Num; } - if((pV2 = (Vertex**)Tree_PQuery(THEM->Vertices, pV))){ + if((pV2 = (Vertex **) Tree_PQuery(THEM->Vertices, pV))) { Extrude_Vertex(pV2, NULL); Extrude_Pnt(*pV2); } } -void FreeEP(void *a, void *b){ - Vertex *v = *((Vertex**)a); +void FreeEP(void *a, void *b) +{ + Vertex *v = *((Vertex **) a); Free_ExtrudedPoints(v->Extruded_Points); v->Extruded_Points = NULL; } -void Extrude_Mesh_Old(Mesh *M){ +void Extrude_Mesh_Old(Mesh * M) +{ int j; Mesh MM; InitExtrudeParams(); LOCAL = &MM; - THEM = M; + THEM = M; //clean up Extruded_Points stuff (in case another extrusion was //performed before) - Tree_Action(THEM->Vertices,FreeEP); + Tree_Action(THEM->Vertices, FreeEP); - Create_BgMesh (WITHPOINTS, .2, LOCAL); + Create_BgMesh(WITHPOINTS, .2, LOCAL); - Tree_Left(M->Volumes,&THEV); + Tree_Left(M->Volumes, &THEV); Tree_Action(M->Surfaces, Extrude_Surface1); - if(!CTX.mesh.oldxtrude_recombine){ + if(!CTX.mesh.oldxtrude_recombine) { j = 0; - do{ - TEST_IS_ALL_OK=0; - Tree_Action ( M->Surfaces , Extrude_Surface2 ); + do { + TEST_IS_ALL_OK = 0; + Tree_Action(M->Surfaces, Extrude_Surface2); Msg(INFO, "%d swaps", TEST_IS_ALL_OK); - if(TEST_IS_ALL_OK == j)break; + if(TEST_IS_ALL_OK == j) + break; j = TEST_IS_ALL_OK; - }while(TEST_IS_ALL_OK); + } while(TEST_IS_ALL_OK); } - Tree_Action ( M->Surfaces , Extrude_Surface3 ); - Tree_Action ( M->Curves , Extrude_Curve ); - Tree_Action ( M->Points , Extrude_Point ); + Tree_Action(M->Surfaces, Extrude_Surface3); + Tree_Action(M->Curves, Extrude_Curve); + Tree_Action(M->Points, Extrude_Point); } - diff --git a/Mesh/3D_Mesh.cpp b/Mesh/3D_Mesh.cpp index 824d8fa584c4d88fc6247f1acc5459bb30874431..7fe5c74d10b1e68b6fe647f4cd9f627ff35b860b 100644 --- a/Mesh/3D_Mesh.cpp +++ b/Mesh/3D_Mesh.cpp @@ -1,4 +1,4 @@ -// $Id: 3D_Mesh.cpp,v 1.47 2003-02-25 04:02:51 geuzaine Exp $ +// $Id: 3D_Mesh.cpp,v 1.48 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -42,9 +42,9 @@ #include "Create.h" #include "Context.h" -extern Mesh *THEM, *LOCAL; -extern Context_T CTX; -extern int FACE_DIMENSION; +extern Mesh *THEM, *LOCAL; +extern Context_T CTX; +extern int FACE_DIMENSION; static Tree_T *Tsd, *Sim_Sur_Le_Bord, *POINTS_TREE; static List_T *Simplexes_Destroyed, *Simplexes_New, *Suppress; @@ -55,119 +55,123 @@ static Tree_T *SimXFac; static double volume, LC3D; static int ZONEELIMINEE, Methode = 0; -Simplex MyNewBoundary; -int Alerte_Point_Scabreux; +Simplex MyNewBoundary; +int Alerte_Point_Scabreux; -inline void cgsmpl (Simplex *s, double &x, double &y, double &z) +inline void cgsmpl(Simplex * s, double &x, double &y, double &z) { //compiler sous linux avec -O2 et faire tourner bench/3d/sphere2.geo //->boum. Ne se produit pas si on accede a V[3] avant! //if(!s->V[3]) Msg(GERROR, "oups"); - x = 0.25 * ( s->V[0]->Pos.X + - s->V[1]->Pos.X + - s->V[2]->Pos.X + - s->V[3]->Pos.X); - y = 0.25 * ( s->V[0]->Pos.Y + - s->V[1]->Pos.Y + - s->V[2]->Pos.Y + - s->V[3]->Pos.Y); - z = 0.25 * ( s->V[0]->Pos.Z + - s->V[1]->Pos.Z + - s->V[2]->Pos.Z + - s->V[3]->Pos.Z); + x = 0.25 * (s->V[0]->Pos.X + + s->V[1]->Pos.X + s->V[2]->Pos.X + s->V[3]->Pos.X); + y = 0.25 * (s->V[0]->Pos.Y + + s->V[1]->Pos.Y + s->V[2]->Pos.Y + s->V[3]->Pos.Y); + z = 0.25 * (s->V[0]->Pos.Z + + s->V[1]->Pos.Z + s->V[2]->Pos.Z + s->V[3]->Pos.Z); } -struct closestSimplex +struct closestSimplex { - double X,Y,Z; - closestSimplex (double x, double y, double z) - : X(x),Y(y),Z(z){} - bool operator () (Simplex *a, Simplex *b) + double X, Y, Z; + closestSimplex(double x, double y, double z) + : X(x), Y(y), Z(z) { - double x1,y1,z1,x2,y2,z2; - cgsmpl (a,x1,y1,z1); - cgsmpl (b,x2,y2,z2); - double d1 = (x1-X)*(x1-X) + (y1-Y)*(y1-Y) + (z1-Z)*(z1-Z); - double d2 = (x2-X)*(x2-X) + (y2-Y)*(y2-Y) + (z2-Z)*(z2-Z); - return d1<d2; + } + bool operator () (Simplex * a, Simplex * b) + { + double x1, y1, z1, x2, y2, z2; + cgsmpl(a, x1, y1, z1); + cgsmpl(b, x2, y2, z2); + double d1 = + (x1 - X) * (x1 - X) + (y1 - Y) * (y1 - Y) + (z1 - Z) * (z1 - Z); + double d2 = + (x2 - X) * (x2 - X) + (y2 - Y) * (y2 - Y) + (z2 - Z) * (z2 - Z); + return d1 < d2; } }; -void DebugSimplexe (Simplex * s){ +void DebugSimplexe(Simplex * s) +{ int i; - fprintf (stderr, "Simplexe %p = %d %d %d %d \n", - s, s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + fprintf(stderr, "Simplexe %p = %d %d %d %d \n", + s, s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); - for (i = 0; i < 4; i++){ - if (s->S[i] != &MyNewBoundary) - printf (" face : %d %d %d -> Simplexe %p\n", - s->F[i].V[0]->Num, s->F[i].V[1]->Num, s->F[i].V[2]->Num, s->S[i]); + for(i = 0; i < 4; i++) { + if(s->S[i] != &MyNewBoundary) + printf(" face : %d %d %d -> Simplexe %p\n", + s->F[i].V[0]->Num, s->F[i].V[1]->Num, s->F[i].V[2]->Num, + s->S[i]); else - printf (" face : %d %d %d -> Simplexe Boundary\n", - s->F[i].V[0]->Num, s->F[i].V[1]->Num, s->F[i].V[2]->Num); + printf(" face : %d %d %d -> Simplexe Boundary\n", + s->F[i].V[0]->Num, s->F[i].V[1]->Num, s->F[i].V[2]->Num); } } -void VSIM (void *a, void *b){ +void VSIM(void *a, void *b) +{ Simplex *S; S = *(Simplex **) a; - if (S->V[3]) - volume += fabs (S->Volume_Simplexe ()); + if(S->V[3]) + volume += fabs(S->Volume_Simplexe()); } -void add_points (void *a, void *b){ - Tree_Insert (POINTS_TREE, a); +void add_points(void *a, void *b) +{ + Tree_Insert(POINTS_TREE, a); } -void add_points_2 (void *a, void *b){ - List_Add (POINTS_LIST, a); +void add_points_2(void *a, void *b) +{ + List_Add(POINTS_LIST, a); } -double Interpole_lcTetraedre (Simplex * s, Vertex * v){ +double Interpole_lcTetraedre(Simplex * s, Vertex * v) +{ double mat[3][3], rhs[3], sol[3], det; - s->matsimpl (mat); + s->matsimpl(mat); rhs[0] = v->Pos.X - s->V[0]->Pos.X; rhs[1] = v->Pos.Y - s->V[0]->Pos.Y; rhs[2] = v->Pos.Z - s->V[0]->Pos.Z; - sys3x3 (mat, rhs, sol, &det); - if (det == 0.0 || - (1. - sol[0] - sol[1] - sol[2]) > 1. || - (1. - sol[0] - sol[1] - sol[2]) < 0. || - sol[0] > 1. || - sol[1] > 1. || - sol[2] > 1. || - sol[0] < 0. || - sol[1] < 0. || - sol[2] < 0.){ - return DMAX (s->V[0]->lc, DMAX (s->V[1]->lc, DMAX (s->V[2]->lc, s->V[3]->lc))); + sys3x3(mat, rhs, sol, &det); + if(det == 0.0 || + (1. - sol[0] - sol[1] - sol[2]) > 1. || + (1. - sol[0] - sol[1] - sol[2]) < 0. || + sol[0] > 1. || + sol[1] > 1. || + sol[2] > 1. || sol[0] < 0. || sol[1] < 0. || sol[2] < 0.) { + return DMAX(s->V[0]->lc, + DMAX(s->V[1]->lc, DMAX(s->V[2]->lc, s->V[3]->lc))); //sol[0] = sol[1] = sol[2] = 0.25; } return (s->V[0]->lc * (1. - sol[0] - sol[1] - sol[2]) + - sol[0] * s->V[1]->lc + - sol[1] * s->V[2]->lc + - sol[2] * s->V[3]->lc); + sol[0] * s->V[1]->lc + sol[1] * s->V[2]->lc + sol[2] * s->V[3]->lc); } -Vertex *NewVertex (Simplex * s){ +Vertex *NewVertex(Simplex * s) +{ Vertex *v; - v = Create_Vertex (++THEM->MaxPointNum, s->Center.X, s->Center.Y, s->Center.Z, 1., 0.0); - v->lc = Interpole_lcTetraedre (s, v); + v = + Create_Vertex(++THEM->MaxPointNum, s->Center.X, s->Center.Y, s->Center.Z, + 1., 0.0); + v->lc = Interpole_lcTetraedre(s, v); return (v); } -int Pt_In_Volume (double X, double Y, double Z, Mesh * m, - double *l, double tol){ +int Pt_In_Volume(double X, double Y, double Z, Mesh * m, + double *l, double tol) +{ int i; Vertex V; double uvw[3]; @@ -178,24 +182,22 @@ int Pt_In_Volume (double X, double Y, double Z, Mesh * m, V.Pos.Y = Y; V.Pos.Z = Z; - if (!(m->BGM.Typ == ONFILE) && !m->BGM.bgm){ + if(!(m->BGM.Typ == ONFILE) && !m->BGM.bgm) { *l = -1.0; return (1); } - B = LaBrique (&m->Grid, X, Y, Z); + B = LaBrique(&m->Grid, X, Y, Z); - if (B.N < 0){ + if(B.N < 0) { return (0); } - for (i = 0; i < List_Nbr (B.pT); i++){ - List_Read (B.pT, i, &s); - if (s->Pt_In_Simplexe (&V, uvw, tol)){ + for(i = 0; i < List_Nbr(B.pT); i++) { + List_Read(B.pT, i, &s); + if(s->Pt_In_Simplexe(&V, uvw, tol)) { *l = (1. - uvw[0] - uvw[1] - uvw[2]) * s->V[0]->lc - + uvw[0] * s->V[1]->lc - + uvw[1] * s->V[2]->lc - + uvw[2] * s->V[3]->lc; + + uvw[0] * s->V[1]->lc + uvw[1] * s->V[2]->lc + uvw[2] * s->V[3]->lc; return (1); } } @@ -203,23 +205,23 @@ int Pt_In_Volume (double X, double Y, double Z, Mesh * m, return (0); } -inline int Pt_In_Circum (Simplex * s, Vertex * v){ +inline int Pt_In_Circum(Simplex * s, Vertex * v) +{ double d1, d2, eps; /* Determine si un point est dans le cercle circonscrit a un simplexe */ d1 = s->Radius; - d2 = sqrt (DSQR (v->Pos.X - s->Center.X) + - DSQR (v->Pos.Y - s->Center.Y) + - DSQR (v->Pos.Z - s->Center.Z)); + d2 = sqrt(DSQR(v->Pos.X - s->Center.X) + + DSQR(v->Pos.Y - s->Center.Y) + DSQR(v->Pos.Z - s->Center.Z)); - eps = fabs (d1 - d2) / (d1 + d2); + eps = fabs(d1 - d2) / (d1 + d2); - if (eps < 1.e-12){ + if(eps < 1.e-12) { return (0); // return 1 ? 0 ? } - - if (d2 < d1) + + if(d2 < d1) return (1); return (0); @@ -227,22 +229,26 @@ inline int Pt_In_Circum (Simplex * s, Vertex * v){ struct SimplexInteriorCheck { - bool operator() ( Simplex * s , double x[3], double u[3]) + bool operator() (Simplex * s, double x[3], double u[3]) { - Vertex v(x[0],x[1],x[2]); - return Pt_In_Circum (s, &v); + Vertex v(x[0], x[1], x[2]); + return Pt_In_Circum(s, &v); } }; struct SimplexInBox { double sizeBox; - SimplexInBox(double sb) : sizeBox(sb) {} - void operator() ( Simplex * s , double min[3], double max[3]) + SimplexInBox(double sb):sizeBox(sb) + { + } + void operator() (Simplex * s, double min[3], double max[3]) { double ss; - if(sizeBox > s->Radius) ss = s->Radius; - else ss = sizeBox; + if(sizeBox > s->Radius) + ss = s->Radius; + else + ss = sizeBox; min[0] = s->Center.X - ss; max[0] = s->Center.X + ss; min[1] = s->Center.Y - ss; @@ -256,42 +262,46 @@ struct SimplexInBox Recursive search; */ -Simplex *SearchPointByNeighbor (Vertex *v, Simplex *s, Tree_T *visited, int depth) +Simplex *SearchPointByNeighbor(Vertex * v, Simplex * s, Tree_T * visited, + int depth) { - if(depth > 150)return 0; - if(Tree_Search(visited,&s))return 0; - Tree_Add(visited,&s); - if(Pt_In_Circum (s,v)) return s; + if(depth > 150) + return 0; + if(Tree_Search(visited, &s)) + return 0; + Tree_Add(visited, &s); + if(Pt_In_Circum(s, v)) + return s; Simplex *S[4]; - int k=0; - for( int i = 0 ; i < 4 ; i++ ) - { - if (s->S[i] != &MyNewBoundary) - { - S[k++] = s->S[i]; - } - } - std::sort(S,S+k,closestSimplex(v->Pos.X,v->Pos.Y,v->Pos.Z)); - for( int i = 0 ; i < k ; i++ ) - { - Simplex *q = SearchPointByNeighbor (v,S[i],visited, depth+1); - if (q) return q; + int k = 0; + for(int i = 0; i < 4; i++) { + if(s->S[i] != &MyNewBoundary) { + S[k++] = s->S[i]; } + } + std::sort(S, S + k, closestSimplex(v->Pos.X, v->Pos.Y, v->Pos.Z)); + for(int i = 0; i < k; i++) { + Simplex *q = SearchPointByNeighbor(v, S[i], visited, depth + 1); + if(q) + return q; + } return 0; } -void Action_First_Simplexes (void *a, void *b){ +void Action_First_Simplexes(void *a, void *b) +{ Simplex **q; - if (!THES){ + if(!THES) { q = (Simplex **) a; - if (Pt_In_Circum (*q, THEV)){ + if(Pt_In_Circum(*q, THEV)) { THES = *q; } } } -void LiS (void *a, void *b){ +void LiS(void *a, void *b) +{ int j, N; SxF SXF, *pSXF; Simplex **pS, *S; @@ -300,22 +310,23 @@ void LiS (void *a, void *b){ S = *pS; N = (S->V[3]) ? 4 : 3; - for (j = 0; j < N; j++){ + for(j = 0; j < N; j++) { SXF.F = S->F[j]; - if ((pSXF = (SxF *) Tree_PQuery (SimXFac, &SXF))){ + if((pSXF = (SxF *) Tree_PQuery(SimXFac, &SXF))) { /* Creation du lien */ S->S[j] = pSXF->S; pSXF->S->S[pSXF->NumFaceSimpl] = S; } - else{ + else { SXF.S = S; SXF.NumFaceSimpl = j; - Tree_Add (SimXFac, &SXF); + Tree_Add(SimXFac, &SXF); } } } -void RzS (void *a, void *b){ +void RzS(void *a, void *b) +{ int j, N; Simplex **pS, *S; pS = (Simplex **) a; @@ -323,8 +334,8 @@ void RzS (void *a, void *b){ N = (S->V[3]) ? 4 : 3; - for (j = 0; j < N; j++){ - if ((S->S[j]) == NULL){ + for(j = 0; j < N; j++) { + if((S->S[j]) == NULL) { S->S[j] = &MyNewBoundary; } } @@ -332,77 +343,81 @@ void RzS (void *a, void *b){ /* Cree les liens entre les simplexes, c.a.d recherche les voisins */ -void Link_Simplexes (List_T * Sim, Tree_T * Tim){ +void Link_Simplexes(List_T * Sim, Tree_T * Tim) +{ Simplex *S; int i; - SimXFac = Tree_Create (sizeof (SxF), compareSxF); - if (Sim){ - for (i = 0; i < List_Nbr (Sim); i++){ - List_Read (Sim, i, &S); - LiS (&S, NULL); + SimXFac = Tree_Create(sizeof(SxF), compareSxF); + if(Sim) { + for(i = 0; i < List_Nbr(Sim); i++) { + List_Read(Sim, i, &S); + LiS(&S, NULL); } - for (i = 0; i < List_Nbr (Sim); i++){ - List_Read (Sim, i, &S); - RzS (&S, NULL); + for(i = 0; i < List_Nbr(Sim); i++) { + List_Read(Sim, i, &S); + RzS(&S, NULL); } } - else{ - Tree_Action (Tim, LiS); - Tree_Action (Tim, RzS); + else { + Tree_Action(Tim, LiS); + Tree_Action(Tim, RzS); } - Tree_Delete (SimXFac); + Tree_Delete(SimXFac); } -void Box_6_Tetraedron (List_T * P, Mesh * m){ +void Box_6_Tetraedron(List_T * P, Mesh * m) +{ #define FACT 1.1 #define LOIN 0.2 int i, j; static int pts[8][3] = { {0, 0, 0}, - {1, 0, 0}, - {1, 1, 0}, - {0, 1, 0}, - {0, 0, 1}, - {1, 0, 1}, - {1, 1, 1}, - {0, 1, 1}}; + {1, 0, 0}, + {1, 1, 0}, + {0, 1, 0}, + {0, 0, 1}, + {1, 0, 1}, + {1, 1, 1}, + {0, 1, 1} + }; static int tet[6][4] = { {1, 5, 2, 4}, - {2, 5, 6, 4}, - {4, 5, 6, 8}, - {6, 4, 8, 7}, - {6, 4, 7, 3}, - {2, 3, 4, 6}}; - double Xm=0., Ym=0., Zm=0., XM=0., YM=0., ZM=0., Xc, Yc, Zc; + {2, 5, 6, 4}, + {4, 5, 6, 8}, + {6, 4, 8, 7}, + {6, 4, 7, 3}, + {2, 3, 4, 6} + }; + double Xm = 0., Ym = 0., Zm = 0., XM = 0., YM = 0., ZM = 0., Xc, Yc, Zc; Simplex *S, *ps; Vertex *V, *v, *pv; List_T *smp; - smp = List_Create (8, 1, sizeof (Simplex *)); + smp = List_Create(8, 1, sizeof(Simplex *)); - V = (Vertex *) Malloc (8 * sizeof (Vertex)); + V = (Vertex *) Malloc(8 * sizeof(Vertex)); - for (i = 0; i < List_Nbr (P); i++){ - List_Read (P, i, &v); - if (!i){ + for(i = 0; i < List_Nbr(P); i++) { + List_Read(P, i, &v); + if(!i) { Xm = XM = v->Pos.X; Ym = YM = v->Pos.Y; Zm = ZM = v->Pos.Z; } - else{ - Xm = DMIN (Xm, v->Pos.X); - XM = DMAX (XM, v->Pos.X); - Ym = DMIN (Ym, v->Pos.Y); - YM = DMAX (YM, v->Pos.Y); - Zm = DMIN (Zm, v->Pos.Z); - ZM = DMAX (ZM, v->Pos.Z); + else { + Xm = DMIN(Xm, v->Pos.X); + XM = DMAX(XM, v->Pos.X); + Ym = DMIN(Ym, v->Pos.Y); + YM = DMAX(YM, v->Pos.Y); + Zm = DMIN(Zm, v->Pos.Z); + ZM = DMAX(ZM, v->Pos.Z); } } - if (Xm == XM) + if(Xm == XM) XM = Xm + 1.; - if (Ym == YM) + if(Ym == YM) YM = Ym + 1.; - if (Zm == ZM) + if(Zm == ZM) ZM = Zm + 1.; Xc = XM - Xm; @@ -423,7 +438,7 @@ void Box_6_Tetraedron (List_T * P, Mesh * m){ /* Longueur Caracteristique */ - LC3D = sqrt (Xc * Xc + Yc * Yc + Zc * Zc); + LC3D = sqrt(Xc * Xc + Yc * Yc + Zc * Zc); /* Points de la boite de 1 a 8 @@ -431,7 +446,7 @@ void Box_6_Tetraedron (List_T * P, Mesh * m){ | /| /| | / | / | | / | / | - 5|/___|________/6 | + 5|/___|________/6 | | 4|________|___|3 | / | / | / Y | / @@ -441,106 +456,111 @@ void Box_6_Tetraedron (List_T * P, Mesh * m){ */ - for (i = 0; i < 8; i++){ - if (pts[i][0]) + for(i = 0; i < 8; i++) { + if(pts[i][0]) V[i].Pos.X = Xm - LOIN * Xc; else V[i].Pos.X = XM + LOIN * Xc; - - if (pts[i][1]) + + if(pts[i][1]) V[i].Pos.Y = Ym - LOIN * Yc; else V[i].Pos.Y = YM + LOIN * Yc; - - if (pts[i][2]) + + if(pts[i][2]) V[i].Pos.Z = Zm - LOIN * Zc; else V[i].Pos.Z = ZM + LOIN * Zc; - + V[i].Num = -(++THEM->MaxPointNum); pv = &V[i]; pv->lc = 1.0; pv->Mov = NULL; - Tree_Replace (m->Vertices, &pv); + Tree_Replace(m->Vertices, &pv); } /* 6 Tetraedres forment le maillage de la boite */ - for (i = 0; i < 6; i++){ - S = Create_Simplex (&V[tet[i][0] - 1], &V[tet[i][1] - 1], - &V[tet[i][2] - 1], &V[tet[i][3] - 1]); - List_Add (smp, &S); - } - - Link_Simplexes (smp, NULL); - for (i = 0; i < List_Nbr (smp); i++){ - List_Read (smp, i, &ps); - for (j = 0; j < 4; j++) - if (ps->S[j] == NULL) + for(i = 0; i < 6; i++) { + S = Create_Simplex(&V[tet[i][0] - 1], &V[tet[i][1] - 1], + &V[tet[i][2] - 1], &V[tet[i][3] - 1]); + List_Add(smp, &S); + } + + Link_Simplexes(smp, NULL); + for(i = 0; i < List_Nbr(smp); i++) { + List_Read(smp, i, &ps); + for(j = 0; j < 4; j++) + if(ps->S[j] == NULL) ps->S[j] = &MyNewBoundary; - Tree_Replace (m->Simplexes, &ps); + Tree_Replace(m->Simplexes, &ps); } - + } -void Fill_Sim_Des (void *a, void *b){ +void Fill_Sim_Des(void *a, void *b) +{ Simplex **S; S = (Simplex **) a; - if (Pt_In_Circum (*S, THEV)) - List_Add (Simplexes_Destroyed, a); + if(Pt_In_Circum(*S, THEV)) + List_Add(Simplexes_Destroyed, a); } -void TStoLS (void *a, void *b){ - List_Add (Simplexes_Destroyed, a); +void TStoLS(void *a, void *b) +{ + List_Add(Simplexes_Destroyed, a); } -void TAtoLA (void *a, void *b){ - List_Add (Simplexes_New, a); +void TAtoLA(void *a, void *b) +{ + List_Add(Simplexes_New, a); } -void CrSi (void *a, void *b){ +void CrSi(void *a, void *b) +{ SxF *S; Simplex *s; S = (SxF *) a; - if (S->NumFaceSimpl == 1){ - s = Create_Simplex (THEV, S->F.V[0], S->F.V[1], S->F.V[2]); + if(S->NumFaceSimpl == 1) { + s = Create_Simplex(THEV, S->F.V[0], S->F.V[1], S->F.V[2]); s->iEnt = ZONEELIMINEE; - THEM->Metric->setSimplexQuality (s); - List_Add (Simplexes_New, &s); + THEM->Metric->setSimplexQuality(s); + List_Add(Simplexes_New, &s); } - else if (S->NumFaceSimpl != 2){ + else if(S->NumFaceSimpl != 2) { Msg(WARNING, "Huh! Panic in CrSi"); } } -void NewSimplexes (Mesh * m, List_T * Sim, List_T * news){ +void NewSimplexes(Mesh * m, List_T * Sim, List_T * news) +{ int i, j; Tree_T *SimXFac; Simplex *S; SxF SXF, *pSXF; - SimXFac = Tree_Create (sizeof (SxF), compareSxF); + SimXFac = Tree_Create(sizeof(SxF), compareSxF); - for (i = 0; i < List_Nbr (Sim); i++){ - List_Read (Sim, i, &S); - if (!i) + for(i = 0; i < List_Nbr(Sim); i++) { + List_Read(Sim, i, &S); + if(!i) ZONEELIMINEE = S->iEnt; else { - if (S->iEnt != ZONEELIMINEE){ + if(S->iEnt != ZONEELIMINEE) { Msg(WARNING, "Huh! The elimination failed %d %d", S->iEnt, ZONEELIMINEE); } } - for (j = 0; j < 4; j++){ + for(j = 0; j < 4; j++) { SXF.F = S->F[j]; - if ((pSXF = (SxF *) Tree_PQuery (SimXFac, &SXF))){ + if((pSXF = (SxF *) Tree_PQuery(SimXFac, &SXF))) { (pSXF->NumFaceSimpl)++; } - else{ + else { SXF.NumFaceSimpl = 1; - Tree_Add (SimXFac, &SXF); + Tree_Add(SimXFac, &SXF); } } } @@ -548,8 +568,8 @@ void NewSimplexes (Mesh * m, List_T * Sim, List_T * news){ /* Les faces non communes sont obligatoirement a la frontiere ... -> Nouveaux simplexes */ - Tree_Action (SimXFac, CrSi); - Tree_Delete (SimXFac); + Tree_Action(SimXFac, CrSi); + Tree_Delete(SimXFac); } @@ -558,21 +578,22 @@ void NewSimplexes (Mesh * m, List_T * Sim, List_T * news){ Invariant : Le simplexe est a eliminer Le simplexe n'est pas encore considere */ -int recur_bowyer (Simplex * s){ +int recur_bowyer(Simplex * s) +{ int i; - Tree_Insert (Tsd, &s); - for (i = 0; i < 4; i++){ - if (s->S[i] && s->S[i] != &MyNewBoundary && !Tree_Query (Tsd, &s->S[i])){ - if (Pt_In_Circum (s->S[i], THEV) && (s->iEnt == s->S[i]->iEnt)){ - recur_bowyer (s->S[i]); + Tree_Insert(Tsd, &s); + for(i = 0; i < 4; i++) { + if(s->S[i] && s->S[i] != &MyNewBoundary && !Tree_Query(Tsd, &s->S[i])) { + if(Pt_In_Circum(s->S[i], THEV) && (s->iEnt == s->S[i]->iEnt)) { + recur_bowyer(s->S[i]); } - else{ - if (s->iEnt != s->S[i]->iEnt){ - //Msg(WARNING, "Point scabreux %d", s->S[i]->Num); + else { + if(s->iEnt != s->S[i]->iEnt) { + //Msg(WARNING, "Point scabreux %d", s->S[i]->Num); Alerte_Point_Scabreux = 1; } - Tree_Insert (Sim_Sur_Le_Bord, &s->S[i]); + Tree_Insert(Sim_Sur_Le_Bord, &s->S[i]); } } } @@ -581,195 +602,212 @@ int recur_bowyer (Simplex * s){ -bool Bowyer_Watson (Mesh * m, Vertex * v, Simplex * S, int force){ +bool Bowyer_Watson(Mesh * m, Vertex * v, Simplex * S, int force) +{ int i; Simplex *s; double volumeold, volumenew; THEV = v; - double x = (S->V[0]->Pos.X + S->V[1]->Pos.X + S->V[2]->Pos.X + S->V[3]->Pos.X) / 4.; - double y = (S->V[0]->Pos.Y + S->V[1]->Pos.Y + S->V[2]->Pos.Y + S->V[3]->Pos.Y) / 4.; - double z = (S->V[0]->Pos.Z + S->V[1]->Pos.Z + S->V[2]->Pos.Z + S->V[3]->Pos.Z) / 4.; + double x = + (S->V[0]->Pos.X + S->V[1]->Pos.X + S->V[2]->Pos.X + S->V[3]->Pos.X) / 4.; + double y = + (S->V[0]->Pos.Y + S->V[1]->Pos.Y + S->V[2]->Pos.Y + S->V[3]->Pos.Y) / 4.; + double z = + (S->V[0]->Pos.Z + S->V[1]->Pos.Z + S->V[2]->Pos.Z + S->V[3]->Pos.Z) / 4.; - if (force) - THEM->Metric->Identity (); + if(force) + THEM->Metric->Identity(); else - THEM->Metric->setMetric (x, y, z); + THEM->Metric->setMetric(x, y, z); - Tsd = Tree_Create (sizeof (Simplex *), compareSimplex); - Sim_Sur_Le_Bord = Tree_Create (sizeof (Simplex *), compareSimplex); - List_Reset (Simplexes_Destroyed); - List_Reset (Simplexes_New); + Tsd = Tree_Create(sizeof(Simplex *), compareSimplex); + Sim_Sur_Le_Bord = Tree_Create(sizeof(Simplex *), compareSimplex); + List_Reset(Simplexes_Destroyed); + List_Reset(Simplexes_New); - if (Methode){ - Tree_Action (m->Simplexes, Fill_Sim_Des); + if(Methode) { + Tree_Action(m->Simplexes, Fill_Sim_Des); } - else{ - recur_bowyer (S); + else { + recur_bowyer(S); } - - Tree_Action (Tsd, TStoLS); - NewSimplexes (m, Simplexes_Destroyed, Simplexes_New); + + Tree_Action(Tsd, TStoLS); + NewSimplexes(m, Simplexes_Destroyed, Simplexes_New); /* calcul des volumes des simplexes crees */ - if (Alerte_Point_Scabreux || !CTX.mesh.speed_max){ + if(Alerte_Point_Scabreux || !CTX.mesh.speed_max) { volume = 0.0; - for (i = 0; i < List_Nbr (Simplexes_Destroyed); i++){ - VSIM (List_Pointer (Simplexes_Destroyed, i), NULL); + for(i = 0; i < List_Nbr(Simplexes_Destroyed); i++) { + VSIM(List_Pointer(Simplexes_Destroyed, i), NULL); } volumeold = volume; volume = 0.0; - for (i = 0; i < List_Nbr (Simplexes_New); i++){ - VSIM (List_Pointer (Simplexes_New, i), NULL); + for(i = 0; i < List_Nbr(Simplexes_New); i++) { + VSIM(List_Pointer(Simplexes_New, i), NULL); } volumenew = volume; } - else{ + else { volumeold = 1.0; volumenew = 1.0; } /* critere du volume */ - if ((fabs (volumeold - volumenew) / (volumeold + volumenew)) > 1.e-8){ - if (Tree_Suppress (m->Simplexes, &S)){ + if((fabs(volumeold - volumenew) / (volumeold + volumenew)) > 1.e-8) { + if(Tree_Suppress(m->Simplexes, &S)) { S->Quality = 0.0; - Tree_Add (m->Simplexes, &S); + Tree_Add(m->Simplexes, &S); } - if(force){ - List_Reset (Simplexes_Destroyed); - List_Reset (Simplexes_New); - Tree_Delete (Sim_Sur_Le_Bord); - Tree_Delete (Tsd); + if(force) { + List_Reset(Simplexes_Destroyed); + List_Reset(Simplexes_New); + Tree_Delete(Sim_Sur_Le_Bord); + Tree_Delete(Tsd); //printf(" Aie Aie Aie volume changed %g -> %g\n",volumeold,volumenew); return false; } } - else{ - Tree_Add (m->Vertices, &THEV); - for (i = 0; i < List_Nbr (Simplexes_New); i++){ + else { + Tree_Add(m->Vertices, &THEV); + for(i = 0; i < List_Nbr(Simplexes_New); i++) { Simplex *theNewS; - List_Read (Simplexes_New, i, &theNewS); + List_Read(Simplexes_New, i, &theNewS); /* if(force) - { - double xc = theNewS->Center.X; - double yc = theNewS->Center.Y; - double zc = theNewS->Center.Z; - double rd = theNewS->Radius; - cgsmpl (theNewS,x,y,z); - THEM->Metric->setMetric (x, y, z); - THEM->Metric->setSimplexQuality (theNewS); - theNewS->Center.X = xc; - theNewS->Center.Y = yc; - theNewS->Center.Z = zc; - theNewS->Radius = rd; - }*/ - Tree_Add (m->Simplexes, &theNewS); + { + double xc = theNewS->Center.X; + double yc = theNewS->Center.Y; + double zc = theNewS->Center.Z; + double rd = theNewS->Radius; + cgsmpl (theNewS,x,y,z); + THEM->Metric->setMetric (x, y, z); + THEM->Metric->setSimplexQuality (theNewS); + theNewS->Center.X = xc; + theNewS->Center.Y = yc; + theNewS->Center.Z = zc; + theNewS->Radius = rd; + } */ + Tree_Add(m->Simplexes, &theNewS); } - + /* Suppression des simplexes elimines */ - - for (i = 0; i < List_Nbr (Simplexes_Destroyed); i++){ - List_Read (Simplexes_Destroyed, i, &s); - if (!Tree_Suppress (m->Simplexes, &s)) + + for(i = 0; i < List_Nbr(Simplexes_Destroyed); i++) { + List_Read(Simplexes_Destroyed, i, &s); + if(!Tree_Suppress(m->Simplexes, &s)) Msg(GERROR, "Impossible to delete simplex"); - Free_Simplex (&s,0); + Free_Simplex(&s, 0); } - + /* Creation des liens entre nouveaux simplexes */ - - Tree_Action (Sim_Sur_Le_Bord, TAtoLA); - Link_Simplexes (Simplexes_New, m->Simplexes); + + Tree_Action(Sim_Sur_Le_Bord, TAtoLA); + Link_Simplexes(Simplexes_New, m->Simplexes); } - Tree_Delete (Sim_Sur_Le_Bord); - Tree_Delete (Tsd); + Tree_Delete(Sim_Sur_Le_Bord); + Tree_Delete(Tsd); return true; } -void Convex_Hull_Mesh (List_T * Points, Mesh * m){ +void Convex_Hull_Mesh(List_T * Points, Mesh * m) +{ int i, j, N, n; - N = List_Nbr (Points); - n = IMAX (N / 20, 1); + N = List_Nbr(Points); + n = IMAX(N / 20, 1); //clock_t t1 = clock(); - Box_6_Tetraedron (Points, m); - List_Sort (Points, comparePosition); + Box_6_Tetraedron(Points, m); + List_Sort(Points, comparePosition); int Nb1 = 0, Nb2 = 0, Nb3 = 0; - for (i = 0; i < N; i++){ + for(i = 0; i < N; i++) { THES = NULL; - List_Read (Points, i, &THEV); - if (Simplexes_New) - for (j = 0; j < List_Nbr (Simplexes_New); j++) - { - Simplex *simp; - List_Read (Simplexes_New, j, &simp); - if(Pt_In_Circum(simp,THEV)) - { - THES = simp; - break; - } - } - - if(THES) Nb1 ++; - - if(!THES) - { - if (Simplexes_New && List_Nbr (Simplexes_New)) - { - Tree_T *visited = Tree_Create (sizeof (Simplex *), compareSimplex); - Simplex *simp; - List_Read (Simplexes_New, 0, &simp); - THES = SearchPointByNeighbor (THEV, simp, visited,0); - Tree_Delete(visited); - } - if(THES) Nb2 ++; + List_Read(Points, i, &THEV); + if(Simplexes_New) + for(j = 0; j < List_Nbr(Simplexes_New); j++) { + Simplex *simp; + List_Read(Simplexes_New, j, &simp); + if(Pt_In_Circum(simp, THEV)) { + THES = simp; + break; + } } + if(THES) + Nb1++; - if (!THES){ - Tree_Action (m->Simplexes, Action_First_Simplexes); - if(THES) Nb3 ++; + if(!THES) { + if(Simplexes_New && List_Nbr(Simplexes_New)) { + Tree_T *visited = Tree_Create(sizeof(Simplex *), compareSimplex); + Simplex *simp; + List_Read(Simplexes_New, 0, &simp); + THES = SearchPointByNeighbor(THEV, simp, visited, 0); + Tree_Delete(visited); + } + if(THES) + Nb2++; } - if (i % n == n - 1){ + + if(!THES) { + Tree_Action(m->Simplexes, Action_First_Simplexes); + if(THES) + Nb3++; + } + + if(i % n == n - 1) { volume = 0.0; - Tree_Action (m->Simplexes, VSIM); - Msg(STATUS3, "Nod=%d/%d Elm=%d", i+1,N,Tree_Nbr(m->Simplexes)); - Msg(STATUS1, "Vol=%g (%d %d %d)",volume,Nb1,Nb2,Nb3); + Tree_Action(m->Simplexes, VSIM); + Msg(STATUS3, "Nod=%d/%d Elm=%d", i + 1, N, Tree_Nbr(m->Simplexes)); + Msg(STATUS1, "Vol=%g (%d %d %d)", volume, Nb1, Nb2, Nb3); } - if (!THES){ - Msg(WARNING, "Vertex (%g,%g,%g) in no simplex", THEV->Pos.X,THEV->Pos.Y,THEV->Pos.Z); - THEV->Pos.X += CTX.mesh.rand_factor * LC3D * (1.-(double)rand()/(double)RAND_MAX); - THEV->Pos.Y += CTX.mesh.rand_factor * LC3D * (1.-(double)rand()/(double)RAND_MAX); - THEV->Pos.Z += CTX.mesh.rand_factor * LC3D * (1.-(double)rand()/(double)RAND_MAX); - Tree_Action (m->Simplexes, Action_First_Simplexes); + if(!THES) { + Msg(WARNING, "Vertex (%g,%g,%g) in no simplex", THEV->Pos.X, + THEV->Pos.Y, THEV->Pos.Z); + THEV->Pos.X += + CTX.mesh.rand_factor * LC3D * (1. - + (double)rand() / (double)RAND_MAX); + THEV->Pos.Y += + CTX.mesh.rand_factor * LC3D * (1. - + (double)rand() / (double)RAND_MAX); + THEV->Pos.Z += + CTX.mesh.rand_factor * LC3D * (1. - + (double)rand() / (double)RAND_MAX); + Tree_Action(m->Simplexes, Action_First_Simplexes); } - bool ca_marche = Bowyer_Watson (m, THEV, THES, 1); + bool ca_marche = Bowyer_Watson(m, THEV, THES, 1); int count = 0; - while(!ca_marche){ - count ++; - double dx = CTX.mesh.rand_factor * LC3D * (1.-(double)rand()/(double)RAND_MAX); - double dy = CTX.mesh.rand_factor * LC3D * (1.-(double)rand()/(double)RAND_MAX); - double dz = CTX.mesh.rand_factor * LC3D * (1.-(double)rand()/(double)RAND_MAX); + while(!ca_marche) { + count++; + double dx = + CTX.mesh.rand_factor * LC3D * (1. - + (double)rand() / (double)RAND_MAX); + double dy = + CTX.mesh.rand_factor * LC3D * (1. - + (double)rand() / (double)RAND_MAX); + double dz = + CTX.mesh.rand_factor * LC3D * (1. - + (double)rand() / (double)RAND_MAX); THEV->Pos.X += dx; THEV->Pos.Y += dy; THEV->Pos.Z += dz; THES = NULL; - Tree_Action (m->Simplexes, Action_First_Simplexes); - ca_marche = Bowyer_Watson (m, THEV, THES, 1); + Tree_Action(m->Simplexes, Action_First_Simplexes); + ca_marche = Bowyer_Watson(m, THEV, THES, 1); THEV->Pos.X -= dx; THEV->Pos.Y -= dy; - THEV->Pos.Z -= dz; - if(count > 5){ + THEV->Pos.Z -= dz; + if(count > 5) { N++; - List_Add(POINTS_LIST,&THEV); + List_Add(POINTS_LIST, &THEV); Msg(WARNING, "Unable to add point %d (will try it later)", THEV->Num); break; } @@ -781,45 +819,51 @@ void Convex_Hull_Mesh (List_T * Points, Mesh * m){ // ,N,(double)(t2-t1)/CLOCKS_PER_SEC); } -void suppress_vertex (void *data, void *dum){ +void suppress_vertex(void *data, void *dum) +{ Vertex **pv; pv = (Vertex **) data; - if ((*pv)->Num < 0) - List_Add (Suppress, pv); + if((*pv)->Num < 0) + List_Add(Suppress, pv); } -void suppress_simplex (void *data, void *dum){ +void suppress_simplex(void *data, void *dum) +{ Simplex **pv; pv = (Simplex **) data; - if ((*pv)->iEnt == 0) List_Add (Suppress, pv); + if((*pv)->iEnt == 0) + List_Add(Suppress, pv); } -void add_in_bgm (void *a, void *b){ +void add_in_bgm(void *a, void *b) +{ Simplex **s, *S; s = (Simplex **) a; S = *s; - List_Add (LLL, S); + List_Add(LLL, S); } -void Bgm_With_Points (Mesh * bgm){ +void Bgm_With_Points(Mesh * bgm) +{ int i; Simplex *s; - bgm->BGM.bgm = List_Create (Tree_Nbr (bgm->Simplexes), 10, sizeof (Simplex)); + bgm->BGM.bgm = List_Create(Tree_Nbr(bgm->Simplexes), 10, sizeof(Simplex)); LLL = bgm->BGM.bgm; - Tree_Action (bgm->Simplexes, add_in_bgm); - for (i = 0; i < List_Nbr (LLL); i++){ - s = (Simplex *) List_Pointer (LLL, i); - AddSimplexInGrid (bgm, s, BOITE); + Tree_Action(bgm->Simplexes, add_in_bgm); + for(i = 0; i < List_Nbr(LLL); i++) { + s = (Simplex *) List_Pointer(LLL, i); + AddSimplexInGrid(bgm, s, BOITE); } } -void Create_BgMesh (int Type, double lc, Mesh * m){ +void Create_BgMesh(int Type, double lc, Mesh * m) +{ m->BGM.Typ = Type; - switch (Type){ + switch (Type) { case CONSTANT: m->BGM.lc = lc; break; @@ -831,7 +875,8 @@ void Create_BgMesh (int Type, double lc, Mesh * m){ } } -void Maillage_Volume (void *data, void *dum){ +void Maillage_Volume(void *data, void *dum) +{ Volume *v, **pv; Mesh M; Surface S, *s; @@ -846,160 +891,165 @@ void Maillage_Volume (void *data, void *dum){ pv = (Volume **) data; v = *pv; - if(v->Dirty){ + if(v->Dirty) { Msg(INFO, "Not meshing dirty Volume %d", v->Num); return; } - if (Extrude_Mesh (v)){ + if(Extrude_Mesh(v)) { } - else if (MeshTransfiniteVolume (v)){ + else if(MeshTransfiniteVolume(v)) { } - else if (v->Typ == 99999){ + else if(v->Typ == 99999) { - Simplexes_New = List_Create (10, 10, sizeof (Simplex *)); - Simplexes_Destroyed = List_Create (10, 10, sizeof (Simplex *)); + Simplexes_New = List_Create(10, 10, sizeof(Simplex *)); + Simplexes_Destroyed = List_Create(10, 10, sizeof(Simplex *)); LOCAL = &M; - Create_BgMesh (THEM->BGM.Typ, .2, LOCAL); + Create_BgMesh(THEM->BGM.Typ, .2, LOCAL); s = &S; - - POINTS_TREE = Tree_Create (sizeof (Vertex *), comparePosition); - POINTS_LIST = List_Create (100, 100, sizeof (Vertex *)); + + POINTS_TREE = Tree_Create(sizeof(Vertex *), comparePosition); + POINTS_LIST = List_Create(100, 100, sizeof(Vertex *)); LOCAL->Simplexes = v->Simplexes; LOCAL->Vertices = v->Vertices; - - for (i = 0; i < List_Nbr (v->Surfaces); i++){ - List_Read (v->Surfaces, i, &s); - Tree_Action (s->Vertices, add_points); + + for(i = 0; i < List_Nbr(v->Surfaces); i++) { + List_Read(v->Surfaces, i, &s); + Tree_Action(s->Vertices, add_points); } - Tree_Action (POINTS_TREE, add_points_2); - Tree_Delete (POINTS_TREE); - - N = List_Nbr (POINTS_LIST); + Tree_Action(POINTS_TREE, add_points_2); + Tree_Delete(POINTS_TREE); + + N = List_Nbr(POINTS_LIST); n = N / 30 + 1; - if(!N) return; - + if(!N) + return; + /* Creation d'un maillage initial respectant la frontiere */ - + Msg(STATUS2, "Mesh 3D... (initial)"); - - Convex_Hull_Mesh (POINTS_LIST, LOCAL); - - if(!Coherence (v, LOCAL)) - Msg(GERROR, "Surface recovery failed (send a bug report with the geo file to <gmsh@geuz.org>!)"); - - Link_Simplexes (NULL, LOCAL->Simplexes); - - if(CTX.mesh.initial_only==3){ + + Convex_Hull_Mesh(POINTS_LIST, LOCAL); + + if(!Coherence(v, LOCAL)) + Msg(GERROR, + "Surface recovery failed (send a bug report with the geo file to <gmsh@geuz.org>!)"); + + Link_Simplexes(NULL, LOCAL->Simplexes); + + if(CTX.mesh.initial_only == 3) { POINTS_TREE = THEM->Vertices; - Tree_Action (v->Vertices, add_points); + Tree_Action(v->Vertices, add_points); POINTS_TREE = THEM->Simplexes; - Tree_Action (v->Simplexes, add_points); - return; + Tree_Action(v->Simplexes, add_points); + return; } - + /* Suppression des noeuds de num < 0 */ - - Suppress = List_Create (10, 10, sizeof (Vertex *)); - Tree_Action (v->Vertices, suppress_vertex); - for (i = 0; i < List_Nbr (Suppress); i++){ - Tree_Suppress (v->Vertices, List_Pointer (Suppress, i)); + + Suppress = List_Create(10, 10, sizeof(Vertex *)); + Tree_Action(v->Vertices, suppress_vertex); + for(i = 0; i < List_Nbr(Suppress); i++) { + Tree_Suppress(v->Vertices, List_Pointer(Suppress, i)); } - List_Delete (Suppress); + List_Delete(Suppress); /* Suppression des elements dont le num de vol == 0 (cad qui n'appartiennent a auncun volume defini) */ - Suppress = List_Create (10, 10, sizeof (Simplex *)); - Tree_Action (v->Simplexes, suppress_simplex); - for (i = 0; i < List_Nbr (Suppress); i++){ - Tree_Suppress (v->Simplexes, List_Pointer (Suppress, i)); + Suppress = List_Create(10, 10, sizeof(Simplex *)); + Tree_Action(v->Simplexes, suppress_simplex); + for(i = 0; i < List_Nbr(Suppress); i++) { + Tree_Suppress(v->Simplexes, List_Pointer(Suppress, i)); } - - List_Delete (Suppress); - - if (Tree_Nbr (LOCAL->Simplexes) == 0) return; + + List_Delete(Suppress); + + if(Tree_Nbr(LOCAL->Simplexes) == 0) + return; /* Si il reste quelque chose a mailler en volume : */ Msg(STATUS2, "Mesh 3D... (final)"); - + v->Simplexes = LOCAL->Simplexes; - - Bgm_With_Points (LOCAL); + + Bgm_With_Points(LOCAL); POINTS_TREE = THEM->Simplexes; - - Tree_Right (LOCAL->Simplexes, &simp); + + Tree_Right(LOCAL->Simplexes, &simp); i = 0; - while (simp->Quality > CONV_VALUE){ - newv = NewVertex (simp); + while(simp->Quality > CONV_VALUE) { + newv = NewVertex(simp); //double l; //while(!Pt_In_Volume(newv->Pos.X,newv->Pos.Y,newv->Pos.Z,LOCAL,&l,0.0)){ - - while (!simp->Pt_In_Simplexe (newv, uvw, 1.e-5) && - (simp->S[0] == &MyNewBoundary || - !simp->S[0]->Pt_In_Simplexe (newv, uvw, 1.e-5)) && - (simp->S[1] == &MyNewBoundary || - !simp->S[1]->Pt_In_Simplexe (newv, uvw, 1.e-5)) && - (simp->S[2] == &MyNewBoundary || - !simp->S[2]->Pt_In_Simplexe (newv, uvw, 1.e-5)) && - (simp->S[3] == &MyNewBoundary || - !simp->S[3]->Pt_In_Simplexe (newv, uvw, 1.e-5))) { - Tree_Suppress (LOCAL->Simplexes, &simp); + + while(!simp->Pt_In_Simplexe(newv, uvw, 1.e-5) && + (simp->S[0] == &MyNewBoundary || + !simp->S[0]->Pt_In_Simplexe(newv, uvw, 1.e-5)) && + (simp->S[1] == &MyNewBoundary || + !simp->S[1]->Pt_In_Simplexe(newv, uvw, 1.e-5)) && + (simp->S[2] == &MyNewBoundary || + !simp->S[2]->Pt_In_Simplexe(newv, uvw, 1.e-5)) && + (simp->S[3] == &MyNewBoundary || + !simp->S[3]->Pt_In_Simplexe(newv, uvw, 1.e-5))) { + Tree_Suppress(LOCAL->Simplexes, &simp); simp->Quality = 0.1; - Tree_Insert (LOCAL->Simplexes, &simp); - Tree_Right (LOCAL->Simplexes, &simp); - if (simp->Quality < CONV_VALUE) + Tree_Insert(LOCAL->Simplexes, &simp); + Tree_Right(LOCAL->Simplexes, &simp); + if(simp->Quality < CONV_VALUE) break; - newv = NewVertex (simp); + newv = NewVertex(simp); } - if (simp->Quality < CONV_VALUE) + if(simp->Quality < CONV_VALUE) break; i++; - if (i % n == n - 1){ + if(i % n == n - 1) { volume = 0.0; - Tree_Action (LOCAL->Simplexes, VSIM); + Tree_Action(LOCAL->Simplexes, VSIM); Msg(STATUS3, "Nod=%d Elm=%d", - Tree_Nbr (LOCAL->Vertices), Tree_Nbr (LOCAL->Simplexes)); - Msg(STATUS1, "Vol(%g) Conv(%g->%g)", volume, simp->Quality, CONV_VALUE); + Tree_Nbr(LOCAL->Vertices), Tree_Nbr(LOCAL->Simplexes)); + Msg(STATUS1, "Vol(%g) Conv(%g->%g)", volume, simp->Quality, + CONV_VALUE); } - Bowyer_Watson (LOCAL, newv, simp, 0); - Tree_Right (LOCAL->Simplexes, &simp); + Bowyer_Watson(LOCAL, newv, simp, 0); + Tree_Right(LOCAL->Simplexes, &simp); } - + POINTS_TREE = THEM->Vertices; - Tree_Action (v->Vertices, add_points); + Tree_Action(v->Vertices, add_points); POINTS_TREE = THEM->Simplexes; - Tree_Action (v->Simplexes, add_points); - - if (CTX.mesh.quality){ - extern void SwapEdges3D (Mesh * M, Volume * v, double GammaPrescribed, bool order); + Tree_Action(v->Simplexes, add_points); + + if(CTX.mesh.quality) { + extern void SwapEdges3D(Mesh * M, Volume * v, double GammaPrescribed, + bool order); Msg(STATUS3, "Swapping edges (1st pass)"); - SwapEdges3D (THEM, v, CTX.mesh.quality, true); + SwapEdges3D(THEM, v, CTX.mesh.quality, true); Msg(STATUS3, "Swapping edges (2nd pass)"); - SwapEdges3D (THEM, v, CTX.mesh.quality, false); + SwapEdges3D(THEM, v, CTX.mesh.quality, false); Msg(STATUS3, "Swapping edges (last pass)"); - SwapEdges3D (THEM, v, CTX.mesh.quality, true); + SwapEdges3D(THEM, v, CTX.mesh.quality, true); } - if (CTX.mesh.nb_smoothing){ + if(CTX.mesh.nb_smoothing) { /* - Msg(STATUS3, "Laplacian smoothing"); - tnxe = Tree_Create (sizeof (NXE), compareNXE); - create_NXE (v->Vertices, v->Simplexes, tnxe); - for (int i = 0; i < CTX.mesh.nb_smoothing; i++) - Tree_Action (tnxe, ActionLiss); - delete_NXE (tnxe); - Msg(STATUS3, "Swapping edges (last pass)"); - SwapEdges3D (THEM, v, 0.5, true); - */ + Msg(STATUS3, "Laplacian smoothing"); + tnxe = Tree_Create (sizeof (NXE), compareNXE); + create_NXE (v->Vertices, v->Simplexes, tnxe); + for (int i = 0; i < CTX.mesh.nb_smoothing; i++) + Tree_Action (tnxe, ActionLiss); + delete_NXE (tnxe); + Msg(STATUS3, "Swapping edges (last pass)"); + SwapEdges3D (THEM, v, 0.5, true); + */ } - if (CTX.mesh.degree == 2) - Degre2 (THEM->Vertices, THEM->VertexEdges, v->Simplexes, NULL, NULL); + if(CTX.mesh.degree == 2) + Degre2(THEM->Vertices, THEM->VertexEdges, v->Simplexes, NULL, NULL); List_Delete(Simplexes_New); List_Delete(Simplexes_Destroyed); diff --git a/Mesh/3D_Mesh_Old.cpp b/Mesh/3D_Mesh_Old.cpp index 59160695bc6cad2d73836b3192dfd7920ab60257..d7fc2baf3e23b155e435998861e1694fe83088ad 100644 --- a/Mesh/3D_Mesh_Old.cpp +++ b/Mesh/3D_Mesh_Old.cpp @@ -1,4 +1,4 @@ -// $Id: 3D_Mesh_Old.cpp,v 1.5 2003-01-23 20:19:22 geuzaine Exp $ +// $Id: 3D_Mesh_Old.cpp,v 1.6 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -40,9 +40,9 @@ #include "Create.h" #include "Context.h" -extern Mesh *THEM, *LOCAL; -extern Context_T CTX; -extern int FACE_DIMENSION; +extern Mesh *THEM, *LOCAL; +extern Context_T CTX; +extern int FACE_DIMENSION; static Tree_T *Tsd, *Sim_Sur_Le_Bord, *POINTS_TREE; static List_T *Simplexes_Destroyed, *Simplexes_New, *Suppress; @@ -53,81 +53,87 @@ static Tree_T *SimXFac; static double volume, LC3D; static int ZONEELIMINEE, Methode = 0; -Simplex MyNewBoundary; -int Alerte_Point_Scabreux; +Simplex MyNewBoundary; +int Alerte_Point_Scabreux; -void DebugSimplexe (Simplex * s){ +void DebugSimplexe(Simplex * s) +{ int i; - fprintf (stderr, "Simplexe %p = %d %d %d %d \n", - s, s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); + fprintf(stderr, "Simplexe %p = %d %d %d %d \n", + s, s->V[0]->Num, s->V[1]->Num, s->V[2]->Num, s->V[3]->Num); - for (i = 0; i < 4; i++){ - if (s->S[i] != &MyNewBoundary) - printf (" face : %d %d %d -> Simplexe %p\n", - s->F[i].V[0]->Num, s->F[i].V[1]->Num, s->F[i].V[2]->Num, s->S[i]); + for(i = 0; i < 4; i++) { + if(s->S[i] != &MyNewBoundary) + printf(" face : %d %d %d -> Simplexe %p\n", + s->F[i].V[0]->Num, s->F[i].V[1]->Num, s->F[i].V[2]->Num, + s->S[i]); else - printf (" face : %d %d %d -> Simplexe Boundary\n", - s->F[i].V[0]->Num, s->F[i].V[1]->Num, s->F[i].V[2]->Num); + printf(" face : %d %d %d -> Simplexe Boundary\n", + s->F[i].V[0]->Num, s->F[i].V[1]->Num, s->F[i].V[2]->Num); } } -void VSIM (void *a, void *b){ +void VSIM(void *a, void *b) +{ Simplex *S; S = *(Simplex **) a; - if (S->V[3]) - volume += fabs (S->Volume_Simplexe ()); + if(S->V[3]) + volume += fabs(S->Volume_Simplexe()); } -void add_points (void *a, void *b){ - Tree_Insert (POINTS_TREE, a); +void add_points(void *a, void *b) +{ + Tree_Insert(POINTS_TREE, a); } -void add_points_2 (void *a, void *b){ - List_Add (POINTS, a); +void add_points_2(void *a, void *b) +{ + List_Add(POINTS, a); } -double Interpole_lcTetraedre (Simplex * s, Vertex * v){ +double Interpole_lcTetraedre(Simplex * s, Vertex * v) +{ double mat[3][3], rhs[3], sol[3], det; - s->matsimpl (mat); + s->matsimpl(mat); rhs[0] = v->Pos.X - s->V[0]->Pos.X; rhs[1] = v->Pos.Y - s->V[0]->Pos.Y; rhs[2] = v->Pos.Z - s->V[0]->Pos.Z; - sys3x3 (mat, rhs, sol, &det); - if (det == 0.0 || - (1. - sol[0] - sol[1] - sol[2]) > 1. || - (1. - sol[0] - sol[1] - sol[2]) < 0. || - sol[0] > 1. || - sol[1] > 1. || - sol[2] > 1. || - sol[0] < 0. || - sol[1] < 0. || - sol[2] < 0.){ - return DMAX (s->V[0]->lc, DMAX (s->V[1]->lc, DMAX (s->V[2]->lc, s->V[3]->lc))); + sys3x3(mat, rhs, sol, &det); + if(det == 0.0 || + (1. - sol[0] - sol[1] - sol[2]) > 1. || + (1. - sol[0] - sol[1] - sol[2]) < 0. || + sol[0] > 1. || + sol[1] > 1. || + sol[2] > 1. || sol[0] < 0. || sol[1] < 0. || sol[2] < 0.) { + return DMAX(s->V[0]->lc, + DMAX(s->V[1]->lc, DMAX(s->V[2]->lc, s->V[3]->lc))); //sol[0] = sol[1] = sol[2] = 0.25; } return (s->V[0]->lc * (1. - sol[0] - sol[1] - sol[2]) + - sol[0] * s->V[1]->lc + - sol[1] * s->V[2]->lc + - sol[2] * s->V[3]->lc); + sol[0] * s->V[1]->lc + sol[1] * s->V[2]->lc + sol[2] * s->V[3]->lc); } -Vertex *NewVertex (Simplex * s){ +Vertex *NewVertex(Simplex * s) +{ Vertex *v; - v = Create_Vertex (++THEM->MaxPointNum, s->Center.X, s->Center.Y, s->Center.Z, 1., 0.0); - v->lc = Interpole_lcTetraedre (s, v); + v = + Create_Vertex(++THEM->MaxPointNum, s->Center.X, s->Center.Y, s->Center.Z, + 1., 0.0); + v->lc = Interpole_lcTetraedre(s, v); return (v); } -int Pt_In_Volume (double X, double Y, double Z, Mesh * m, - double *l, double tol){ +int Pt_In_Volume(double X, double Y, double Z, Mesh * m, + double *l, double tol) +{ int i; Vertex V; double uvw[3]; @@ -138,24 +144,22 @@ int Pt_In_Volume (double X, double Y, double Z, Mesh * m, V.Pos.Y = Y; V.Pos.Z = Z; - if (!(m->BGM.Typ == ONFILE) && !m->BGM.bgm){ + if(!(m->BGM.Typ == ONFILE) && !m->BGM.bgm) { *l = -1.0; return (1); } - B = LaBrique (&m->Grid, X, Y, Z); + B = LaBrique(&m->Grid, X, Y, Z); - if (B.N < 0){ + if(B.N < 0) { return (0); } - for (i = 0; i < List_Nbr (B.pT); i++){ - List_Read (B.pT, i, &s); - if (s->Pt_In_Simplexe (&V, uvw, tol)){ + for(i = 0; i < List_Nbr(B.pT); i++) { + List_Read(B.pT, i, &s); + if(s->Pt_In_Simplexe(&V, uvw, tol)) { *l = (1. - uvw[0] - uvw[1] - uvw[2]) * s->V[0]->lc - + uvw[0] * s->V[1]->lc - + uvw[1] * s->V[2]->lc - + uvw[2] * s->V[3]->lc; + + uvw[0] * s->V[1]->lc + uvw[1] * s->V[2]->lc + uvw[2] * s->V[3]->lc; return (1); } } @@ -163,40 +167,42 @@ int Pt_In_Volume (double X, double Y, double Z, Mesh * m, return (0); } -int Pt_In_Circum (Simplex * s, Vertex * v){ +int Pt_In_Circum(Simplex * s, Vertex * v) +{ double d1, d2, eps; /* Determine si un point est dans le cercle circonscrit a un simplexe */ d1 = s->Radius; - d2 = sqrt (DSQR (v->Pos.X - s->Center.X) + - DSQR (v->Pos.Y - s->Center.Y) + - DSQR (v->Pos.Z - s->Center.Z)); + d2 = sqrt(DSQR(v->Pos.X - s->Center.X) + + DSQR(v->Pos.Y - s->Center.Y) + DSQR(v->Pos.Z - s->Center.Z)); - eps = fabs (d1 - d2) / (d1 + d2); + eps = fabs(d1 - d2) / (d1 + d2); - if (eps < 1.e-12){ + if(eps < 1.e-12) { return (0); // return 1 ? 0 ? } - - if (d2 < d1) + + if(d2 < d1) return (1); return (0); } -void Action_First_Simplexes (void *a, void *b){ +void Action_First_Simplexes(void *a, void *b) +{ Simplex **q; - if (!THES){ + if(!THES) { q = (Simplex **) a; - if (Pt_In_Circum (*q, THEV)){ + if(Pt_In_Circum(*q, THEV)) { THES = *q; } } } -void LiS (void *a, void *b){ +void LiS(void *a, void *b) +{ int j, N; SxF SXF, *pSXF; Simplex **pS, *S; @@ -205,22 +211,23 @@ void LiS (void *a, void *b){ S = *pS; N = (S->V[3]) ? 4 : 3; - for (j = 0; j < N; j++){ + for(j = 0; j < N; j++) { SXF.F = S->F[j]; - if ((pSXF = (SxF *) Tree_PQuery (SimXFac, &SXF))){ + if((pSXF = (SxF *) Tree_PQuery(SimXFac, &SXF))) { /* Creation du lien */ S->S[j] = pSXF->S; pSXF->S->S[pSXF->NumFaceSimpl] = S; } - else{ + else { SXF.S = S; SXF.NumFaceSimpl = j; - Tree_Add (SimXFac, &SXF); + Tree_Add(SimXFac, &SXF); } } } -void RzS (void *a, void *b){ +void RzS(void *a, void *b) +{ int j, N; Simplex **pS, *S; pS = (Simplex **) a; @@ -228,8 +235,8 @@ void RzS (void *a, void *b){ N = (S->V[3]) ? 4 : 3; - for (j = 0; j < N; j++){ - if ((S->S[j]) == NULL){ + for(j = 0; j < N; j++) { + if((S->S[j]) == NULL) { S->S[j] = &MyNewBoundary; } } @@ -237,77 +244,81 @@ void RzS (void *a, void *b){ /* Cree les liens entre les simplexes, c.a.d recherche les voisins */ -void Link_Simplexes (List_T * Sim, Tree_T * Tim){ +void Link_Simplexes(List_T * Sim, Tree_T * Tim) +{ Simplex *S; int i; - SimXFac = Tree_Create (sizeof (SxF), compareSxF); - if (Sim){ - for (i = 0; i < List_Nbr (Sim); i++){ - List_Read (Sim, i, &S); - LiS (&S, NULL); + SimXFac = Tree_Create(sizeof(SxF), compareSxF); + if(Sim) { + for(i = 0; i < List_Nbr(Sim); i++) { + List_Read(Sim, i, &S); + LiS(&S, NULL); } - for (i = 0; i < List_Nbr (Sim); i++){ - List_Read (Sim, i, &S); - RzS (&S, NULL); + for(i = 0; i < List_Nbr(Sim); i++) { + List_Read(Sim, i, &S); + RzS(&S, NULL); } } - else{ - Tree_Action (Tim, LiS); - Tree_Action (Tim, RzS); + else { + Tree_Action(Tim, LiS); + Tree_Action(Tim, RzS); } - Tree_Delete (SimXFac); + Tree_Delete(SimXFac); } -void Box_6_Tetraedron (List_T * P, Mesh * m){ +void Box_6_Tetraedron(List_T * P, Mesh * m) +{ #define FACT 1.1 #define LOIN 0.2 int i, j; static int pts[8][3] = { {0, 0, 0}, - {1, 0, 0}, - {1, 1, 0}, - {0, 1, 0}, - {0, 0, 1}, - {1, 0, 1}, - {1, 1, 1}, - {0, 1, 1}}; + {1, 0, 0}, + {1, 1, 0}, + {0, 1, 0}, + {0, 0, 1}, + {1, 0, 1}, + {1, 1, 1}, + {0, 1, 1} + }; static int tet[6][4] = { {1, 5, 2, 4}, - {2, 5, 6, 4}, - {4, 5, 6, 8}, - {6, 4, 8, 7}, - {6, 4, 7, 3}, - {2, 3, 4, 6}}; + {2, 5, 6, 4}, + {4, 5, 6, 8}, + {6, 4, 8, 7}, + {6, 4, 7, 3}, + {2, 3, 4, 6} + }; double Xm, Ym, Zm, XM, YM, ZM, Xc, Yc, Zc; Simplex *S, *ps; Vertex *V, *v, *pv; List_T *smp; - smp = List_Create (8, 1, sizeof (Simplex *)); + smp = List_Create(8, 1, sizeof(Simplex *)); - V = (Vertex *) Malloc (8 * sizeof (Vertex)); + V = (Vertex *) Malloc(8 * sizeof(Vertex)); - for (i = 0; i < List_Nbr (P); i++){ - List_Read (P, i, &v); - if (!i){ + for(i = 0; i < List_Nbr(P); i++) { + List_Read(P, i, &v); + if(!i) { Xm = XM = v->Pos.X; Ym = YM = v->Pos.Y; Zm = ZM = v->Pos.Z; } - else{ - Xm = DMIN (Xm, v->Pos.X); - XM = DMAX (XM, v->Pos.X); - Ym = DMIN (Ym, v->Pos.Y); - YM = DMAX (YM, v->Pos.Y); - Zm = DMIN (Zm, v->Pos.Z); - ZM = DMAX (ZM, v->Pos.Z); + else { + Xm = DMIN(Xm, v->Pos.X); + XM = DMAX(XM, v->Pos.X); + Ym = DMIN(Ym, v->Pos.Y); + YM = DMAX(YM, v->Pos.Y); + Zm = DMIN(Zm, v->Pos.Z); + ZM = DMAX(ZM, v->Pos.Z); } } - if (Xm == XM) + if(Xm == XM) XM = Xm + 1.; - if (Ym == YM) + if(Ym == YM) YM = Ym + 1.; - if (Zm == ZM) + if(Zm == ZM) ZM = Zm + 1.; Xc = XM - Xm; @@ -328,7 +339,7 @@ void Box_6_Tetraedron (List_T * P, Mesh * m){ /* Longueur Caracteristique */ - LC3D = sqrt (Xc * Xc + Yc * Yc + Zc * Zc); + LC3D = sqrt(Xc * Xc + Yc * Yc + Zc * Zc); /* Points de la boite de 1 a 8 @@ -336,7 +347,7 @@ void Box_6_Tetraedron (List_T * P, Mesh * m){ | /| /| | / | / | | / | / | - 5|/___|________/6 | + 5|/___|________/6 | | 4|________|___|3 | / | / | / Y | / @@ -346,106 +357,111 @@ void Box_6_Tetraedron (List_T * P, Mesh * m){ */ - for (i = 0; i < 8; i++){ - if (pts[i][0]) + for(i = 0; i < 8; i++) { + if(pts[i][0]) V[i].Pos.X = Xm - LOIN * Xc; else V[i].Pos.X = XM + LOIN * Xc; - - if (pts[i][1]) + + if(pts[i][1]) V[i].Pos.Y = Ym - LOIN * Yc; else V[i].Pos.Y = YM + LOIN * Yc; - - if (pts[i][2]) + + if(pts[i][2]) V[i].Pos.Z = Zm - LOIN * Zc; else V[i].Pos.Z = ZM + LOIN * Zc; - + V[i].Num = -(++THEM->MaxPointNum); pv = &V[i]; pv->lc = 1.0; pv->Mov = NULL; - Tree_Replace (m->Vertices, &pv); + Tree_Replace(m->Vertices, &pv); } /* 6 Tetraedres forment le maillage de la boite */ - for (i = 0; i < 6; i++){ - S = Create_Simplex (&V[tet[i][0] - 1], &V[tet[i][1] - 1], - &V[tet[i][2] - 1], &V[tet[i][3] - 1]); - List_Add (smp, &S); - } - - Link_Simplexes (smp, NULL); - for (i = 0; i < List_Nbr (smp); i++){ - List_Read (smp, i, &ps); - for (j = 0; j < 4; j++) - if (ps->S[j] == NULL) + for(i = 0; i < 6; i++) { + S = Create_Simplex(&V[tet[i][0] - 1], &V[tet[i][1] - 1], + &V[tet[i][2] - 1], &V[tet[i][3] - 1]); + List_Add(smp, &S); + } + + Link_Simplexes(smp, NULL); + for(i = 0; i < List_Nbr(smp); i++) { + List_Read(smp, i, &ps); + for(j = 0; j < 4; j++) + if(ps->S[j] == NULL) ps->S[j] = &MyNewBoundary; - Tree_Replace (m->Simplexes, &ps); + Tree_Replace(m->Simplexes, &ps); } - + } -void Fill_Sim_Des (void *a, void *b){ +void Fill_Sim_Des(void *a, void *b) +{ Simplex **S; S = (Simplex **) a; - if (Pt_In_Circum (*S, THEV)) - List_Add (Simplexes_Destroyed, a); + if(Pt_In_Circum(*S, THEV)) + List_Add(Simplexes_Destroyed, a); } -void TStoLS (void *a, void *b){ - List_Add (Simplexes_Destroyed, a); +void TStoLS(void *a, void *b) +{ + List_Add(Simplexes_Destroyed, a); } -void TAtoLA (void *a, void *b){ - List_Add (Simplexes_New, a); +void TAtoLA(void *a, void *b) +{ + List_Add(Simplexes_New, a); } -void CrSi (void *a, void *b){ +void CrSi(void *a, void *b) +{ SxF *S; Simplex *s; S = (SxF *) a; - if (S->NumFaceSimpl == 1){ - s = Create_Simplex (THEV, S->F.V[0], S->F.V[1], S->F.V[2]); + if(S->NumFaceSimpl == 1) { + s = Create_Simplex(THEV, S->F.V[0], S->F.V[1], S->F.V[2]); s->iEnt = ZONEELIMINEE; - THEM->Metric->setSimplexQuality (s); - List_Add (Simplexes_New, &s); + THEM->Metric->setSimplexQuality(s); + List_Add(Simplexes_New, &s); } - else if (S->NumFaceSimpl != 2){ + else if(S->NumFaceSimpl != 2) { Msg(WARNING, "Huh! Panic in CrSi"); } } -void NewSimplexes (Mesh * m, List_T * Sim, List_T * news){ +void NewSimplexes(Mesh * m, List_T * Sim, List_T * news) +{ int i, j; Tree_T *SimXFac; Simplex *S; SxF SXF, *pSXF; - SimXFac = Tree_Create (sizeof (SxF), compareSxF); + SimXFac = Tree_Create(sizeof(SxF), compareSxF); - for (i = 0; i < List_Nbr (Sim); i++){ - List_Read (Sim, i, &S); - if (!i) + for(i = 0; i < List_Nbr(Sim); i++) { + List_Read(Sim, i, &S); + if(!i) ZONEELIMINEE = S->iEnt; else { - if (S->iEnt != ZONEELIMINEE){ + if(S->iEnt != ZONEELIMINEE) { Msg(WARNING, "Huh! The elimination failed %d %d", S->iEnt, ZONEELIMINEE); } } - for (j = 0; j < 4; j++){ + for(j = 0; j < 4; j++) { SXF.F = S->F[j]; - if ((pSXF = (SxF *) Tree_PQuery (SimXFac, &SXF))){ + if((pSXF = (SxF *) Tree_PQuery(SimXFac, &SXF))) { (pSXF->NumFaceSimpl)++; } - else{ + else { SXF.NumFaceSimpl = 1; - Tree_Add (SimXFac, &SXF); + Tree_Add(SimXFac, &SXF); } } } @@ -453,8 +469,8 @@ void NewSimplexes (Mesh * m, List_T * Sim, List_T * news){ /* Les faces non communes sont obligatoirement a la frontiere ... -> Nouveaux simplexes */ - Tree_Action (SimXFac, CrSi); - Tree_Delete (SimXFac); + Tree_Action(SimXFac, CrSi); + Tree_Delete(SimXFac); } @@ -463,177 +479,196 @@ void NewSimplexes (Mesh * m, List_T * Sim, List_T * news){ Invariant : Le simplexe est a eliminer Le simplexe n'est pas encore considere */ -int recur_bowyer (Simplex * s){ +int recur_bowyer(Simplex * s) +{ int i; - Tree_Insert (Tsd, &s); - for (i = 0; i < 4; i++){ - if (s->S[i] && s->S[i] != &MyNewBoundary && !Tree_Query (Tsd, &s->S[i])){ - if (Pt_In_Circum (s->S[i], THEV) && (s->iEnt == s->S[i]->iEnt)){ - recur_bowyer (s->S[i]); + Tree_Insert(Tsd, &s); + for(i = 0; i < 4; i++) { + if(s->S[i] && s->S[i] != &MyNewBoundary && !Tree_Query(Tsd, &s->S[i])) { + if(Pt_In_Circum(s->S[i], THEV) && (s->iEnt == s->S[i]->iEnt)) { + recur_bowyer(s->S[i]); } - else{ - if (s->iEnt != s->S[i]->iEnt){ - //Msg(WARNING, "Point scabreux %d", s->S[i]->Num); + else { + if(s->iEnt != s->S[i]->iEnt) { + //Msg(WARNING, "Point scabreux %d", s->S[i]->Num); Alerte_Point_Scabreux = 1; } - Tree_Insert (Sim_Sur_Le_Bord, &s->S[i]); + Tree_Insert(Sim_Sur_Le_Bord, &s->S[i]); } } } return 1; } -bool Bowyer_Watson (Mesh * m, Vertex * v, Simplex * S, int force){ +bool Bowyer_Watson(Mesh * m, Vertex * v, Simplex * S, int force) +{ int i; Simplex *s; double volumeold, volumenew; THEV = v; - double x = (S->V[0]->Pos.X + S->V[1]->Pos.X + S->V[2]->Pos.X + S->V[3]->Pos.X) / 4.; - double y = (S->V[0]->Pos.Y + S->V[1]->Pos.Y + S->V[2]->Pos.Y + S->V[3]->Pos.Y) / 4.; - double z = (S->V[0]->Pos.Z + S->V[1]->Pos.Z + S->V[2]->Pos.Z + S->V[3]->Pos.Z) / 4.; + double x = + (S->V[0]->Pos.X + S->V[1]->Pos.X + S->V[2]->Pos.X + S->V[3]->Pos.X) / 4.; + double y = + (S->V[0]->Pos.Y + S->V[1]->Pos.Y + S->V[2]->Pos.Y + S->V[3]->Pos.Y) / 4.; + double z = + (S->V[0]->Pos.Z + S->V[1]->Pos.Z + S->V[2]->Pos.Z + S->V[3]->Pos.Z) / 4.; - if (force) - THEM->Metric->Identity (); + if(force) + THEM->Metric->Identity(); else - THEM->Metric->setMetric (x, y, z); + THEM->Metric->setMetric(x, y, z); - Tsd = Tree_Create (sizeof (Simplex *), compareSimplex); - Sim_Sur_Le_Bord = Tree_Create (sizeof (Simplex *), compareSimplex); - List_Reset (Simplexes_Destroyed); - List_Reset (Simplexes_New); + Tsd = Tree_Create(sizeof(Simplex *), compareSimplex); + Sim_Sur_Le_Bord = Tree_Create(sizeof(Simplex *), compareSimplex); + List_Reset(Simplexes_Destroyed); + List_Reset(Simplexes_New); - if (Methode){ - Tree_Action (m->Simplexes, Fill_Sim_Des); + if(Methode) { + Tree_Action(m->Simplexes, Fill_Sim_Des); } - else{ - recur_bowyer (S); + else { + recur_bowyer(S); } - - Tree_Action (Tsd, TStoLS); - NewSimplexes (m, Simplexes_Destroyed, Simplexes_New); + + Tree_Action(Tsd, TStoLS); + NewSimplexes(m, Simplexes_Destroyed, Simplexes_New); /* calcul des volumes des simplexes crees */ - if (Alerte_Point_Scabreux || !CTX.mesh.speed_max){ + if(Alerte_Point_Scabreux || !CTX.mesh.speed_max) { volume = 0.0; - for (i = 0; i < List_Nbr (Simplexes_Destroyed); i++){ - VSIM (List_Pointer (Simplexes_Destroyed, i), NULL); + for(i = 0; i < List_Nbr(Simplexes_Destroyed); i++) { + VSIM(List_Pointer(Simplexes_Destroyed, i), NULL); } volumeold = volume; volume = 0.0; - for (i = 0; i < List_Nbr (Simplexes_New); i++){ - VSIM (List_Pointer (Simplexes_New, i), NULL); + for(i = 0; i < List_Nbr(Simplexes_New); i++) { + VSIM(List_Pointer(Simplexes_New, i), NULL); } volumenew = volume; } - else{ + else { volumeold = 1.0; volumenew = 1.0; } /* critere du volume */ - if ((fabs (volumeold - volumenew) / (volumeold + volumenew)) > 1.e-8){ - if (Tree_Suppress (m->Simplexes, &S)){ + if((fabs(volumeold - volumenew) / (volumeold + volumenew)) > 1.e-8) { + if(Tree_Suppress(m->Simplexes, &S)) { S->Quality = 0.0; - Tree_Add (m->Simplexes, &S); + Tree_Add(m->Simplexes, &S); } - if(force){ - List_Reset (Simplexes_Destroyed); - List_Reset (Simplexes_New); - Tree_Delete (Sim_Sur_Le_Bord); - Tree_Delete (Tsd); + if(force) { + List_Reset(Simplexes_Destroyed); + List_Reset(Simplexes_New); + Tree_Delete(Sim_Sur_Le_Bord); + Tree_Delete(Tsd); //printf(" Aie Aie Aie volume changed %g -> %g\n",volumeold,volumenew); return false; } } - else{ - Tree_Add (m->Vertices, &THEV); - for (i = 0; i < List_Nbr (Simplexes_New); i++){ - Tree_Add (m->Simplexes, List_Pointer (Simplexes_New, i)); + else { + Tree_Add(m->Vertices, &THEV); + for(i = 0; i < List_Nbr(Simplexes_New); i++) { + Tree_Add(m->Simplexes, List_Pointer(Simplexes_New, i)); } - + /* Suppression des simplexes elimines */ - - for (i = 0; i < List_Nbr (Simplexes_Destroyed); i++){ - List_Read (Simplexes_Destroyed, i, &s); - if (!Tree_Suppress (m->Simplexes, &s)) + + for(i = 0; i < List_Nbr(Simplexes_Destroyed); i++) { + List_Read(Simplexes_Destroyed, i, &s); + if(!Tree_Suppress(m->Simplexes, &s)) Msg(GERROR, "Impossible to delete simplex"); - Free_Simplex (&s,0); + Free_Simplex(&s, 0); } - + /* Creation des liens entre nouveaux simplexes */ - - Tree_Action (Sim_Sur_Le_Bord, TAtoLA); - Link_Simplexes (Simplexes_New, m->Simplexes); + + Tree_Action(Sim_Sur_Le_Bord, TAtoLA); + Link_Simplexes(Simplexes_New, m->Simplexes); } - Tree_Delete (Sim_Sur_Le_Bord); - Tree_Delete (Tsd); + Tree_Delete(Sim_Sur_Le_Bord); + Tree_Delete(Tsd); return true; } -void Convex_Hull_Mesh (List_T * Points, Mesh * m){ +void Convex_Hull_Mesh(List_T * Points, Mesh * m) +{ int i, j, N, n; int Nbr_OK = 0, Nbr_NOTOK = 0; - N = List_Nbr (Points); - n = IMAX (N / 20, 1); + N = List_Nbr(Points); + n = IMAX(N / 20, 1); - Box_6_Tetraedron (Points, m); + Box_6_Tetraedron(Points, m); // List_Sort (Points, comparePosition); - for (i = 0; i < N; i++){ + for(i = 0; i < N; i++) { THES = NULL; - List_Read (Points, i, &THEV); + List_Read(Points, i, &THEV); - if (Simplexes_New) - for (j = 0; j < List_Nbr (Simplexes_New); j++){ - Action_First_Simplexes (List_Pointer (Simplexes_New, j), NULL); + if(Simplexes_New) + for(j = 0; j < List_Nbr(Simplexes_New); j++) { + Action_First_Simplexes(List_Pointer(Simplexes_New, j), NULL); } - - if (!THES){ - Tree_Action (m->Simplexes, Action_First_Simplexes); + + if(!THES) { + Tree_Action(m->Simplexes, Action_First_Simplexes); Nbr_OK++; } - else{ + else { Nbr_NOTOK++; } - if (i % n == n - 1){ + if(i % n == n - 1) { volume = 0.0; - Tree_Action (m->Simplexes, VSIM); - Msg(STATUS3, "Nod=%d/%d Elm=%d", i+1,N,Tree_Nbr(m->Simplexes)); - Msg(STATUS1, "Vol=%g",volume); + Tree_Action(m->Simplexes, VSIM); + Msg(STATUS3, "Nod=%d/%d Elm=%d", i + 1, N, Tree_Nbr(m->Simplexes)); + Msg(STATUS1, "Vol=%g", volume); } - if (!THES){ - Msg(WARNING, "Vertex (%g,%g,%g) in no simplex", THEV->Pos.X,THEV->Pos.Y,THEV->Pos.Z); - THEV->Pos.X += CTX.mesh.rand_factor * LC3D * (1.-(double)rand()/(double)RAND_MAX); - THEV->Pos.Y += CTX.mesh.rand_factor * LC3D * (1.-(double)rand()/(double)RAND_MAX); - THEV->Pos.Z += CTX.mesh.rand_factor * LC3D * (1.-(double)rand()/(double)RAND_MAX); - Tree_Action (m->Simplexes, Action_First_Simplexes); + if(!THES) { + Msg(WARNING, "Vertex (%g,%g,%g) in no simplex", THEV->Pos.X, + THEV->Pos.Y, THEV->Pos.Z); + THEV->Pos.X += + CTX.mesh.rand_factor * LC3D * (1. - + (double)rand() / (double)RAND_MAX); + THEV->Pos.Y += + CTX.mesh.rand_factor * LC3D * (1. - + (double)rand() / (double)RAND_MAX); + THEV->Pos.Z += + CTX.mesh.rand_factor * LC3D * (1. - + (double)rand() / (double)RAND_MAX); + Tree_Action(m->Simplexes, Action_First_Simplexes); } - bool ca_marche = Bowyer_Watson (m, THEV, THES, 1); + bool ca_marche = Bowyer_Watson(m, THEV, THES, 1); int count = 0; - while(!ca_marche){ - count ++; - double dx = CTX.mesh.rand_factor * LC3D * (1.-(double)rand()/(double)RAND_MAX); - double dy = CTX.mesh.rand_factor * LC3D * (1.-(double)rand()/(double)RAND_MAX); - double dz = CTX.mesh.rand_factor * LC3D * (1.-(double)rand()/(double)RAND_MAX); + while(!ca_marche) { + count++; + double dx = + CTX.mesh.rand_factor * LC3D * (1. - + (double)rand() / (double)RAND_MAX); + double dy = + CTX.mesh.rand_factor * LC3D * (1. - + (double)rand() / (double)RAND_MAX); + double dz = + CTX.mesh.rand_factor * LC3D * (1. - + (double)rand() / (double)RAND_MAX); THEV->Pos.X += dx; THEV->Pos.Y += dy; THEV->Pos.Z += dz; THES = NULL; - Tree_Action (m->Simplexes, Action_First_Simplexes); - ca_marche = Bowyer_Watson (m, THEV, THES, 1); + Tree_Action(m->Simplexes, Action_First_Simplexes); + ca_marche = Bowyer_Watson(m, THEV, THES, 1); THEV->Pos.X -= dx; THEV->Pos.Y -= dy; - THEV->Pos.Z -= dz; - if(count > 5){ + THEV->Pos.Z -= dz; + if(count > 5) { N++; - List_Add(POINTS,&THEV); + List_Add(POINTS, &THEV); Msg(WARNING, "Unable to add point %d (will try it later)", THEV->Num); break; } @@ -641,45 +676,51 @@ void Convex_Hull_Mesh (List_T * Points, Mesh * m){ } } -void suppress_vertex (void *data, void *dum){ +void suppress_vertex(void *data, void *dum) +{ Vertex **pv; pv = (Vertex **) data; - if ((*pv)->Num < 0) - List_Add (Suppress, pv); + if((*pv)->Num < 0) + List_Add(Suppress, pv); } -void suppress_simplex (void *data, void *dum){ +void suppress_simplex(void *data, void *dum) +{ Simplex **pv; pv = (Simplex **) data; - if ((*pv)->iEnt == 0) List_Add (Suppress, pv); + if((*pv)->iEnt == 0) + List_Add(Suppress, pv); } -void add_in_bgm (void *a, void *b){ +void add_in_bgm(void *a, void *b) +{ Simplex **s, *S; s = (Simplex **) a; S = *s; - List_Add (LLL, S); + List_Add(LLL, S); } -void Bgm_With_Points (Mesh * bgm){ +void Bgm_With_Points(Mesh * bgm) +{ int i; Simplex *s; - bgm->BGM.bgm = List_Create (Tree_Nbr (bgm->Simplexes), 10, sizeof (Simplex)); + bgm->BGM.bgm = List_Create(Tree_Nbr(bgm->Simplexes), 10, sizeof(Simplex)); LLL = bgm->BGM.bgm; - Tree_Action (bgm->Simplexes, add_in_bgm); - for (i = 0; i < List_Nbr (LLL); i++){ - s = (Simplex *) List_Pointer (LLL, i); - AddSimplexInGrid (bgm, s, BOITE); + Tree_Action(bgm->Simplexes, add_in_bgm); + for(i = 0; i < List_Nbr(LLL); i++) { + s = (Simplex *) List_Pointer(LLL, i); + AddSimplexInGrid(bgm, s, BOITE); } } -void Create_BgMesh (int Type, double lc, Mesh * m){ +void Create_BgMesh(int Type, double lc, Mesh * m) +{ m->BGM.Typ = Type; - switch (Type){ + switch (Type) { case CONSTANT: m->BGM.lc = lc; break; @@ -691,7 +732,8 @@ void Create_BgMesh (int Type, double lc, Mesh * m){ } } -void Maillage_Volume (void *data, void *dum){ +void Maillage_Volume(void *data, void *dum) +{ Volume *v, **pv; Mesh M; Surface S, *s; @@ -706,161 +748,166 @@ void Maillage_Volume (void *data, void *dum){ pv = (Volume **) data; v = *pv; - if(v->Dirty){ + if(v->Dirty) { Msg(INFO, "Not meshing dirty Volume %d", v->Num); return; } - if (Extrude_Mesh (v)){ + if(Extrude_Mesh(v)) { } - else if (MeshTransfiniteVolume (v)){ + else if(MeshTransfiniteVolume(v)) { } - else if (v->Typ == 99999){ + else if(v->Typ == 99999) { - Simplexes_New = List_Create (10, 10, sizeof (Simplex *)); - Simplexes_Destroyed = List_Create (10, 10, sizeof (Simplex *)); + Simplexes_New = List_Create(10, 10, sizeof(Simplex *)); + Simplexes_Destroyed = List_Create(10, 10, sizeof(Simplex *)); LOCAL = &M; - Create_BgMesh (THEM->BGM.Typ, .2, LOCAL); + Create_BgMesh(THEM->BGM.Typ, .2, LOCAL); s = &S; - - POINTS_TREE = Tree_Create (sizeof (Vertex *), comparePosition); - POINTS = List_Create (100, 100, sizeof (Vertex *)); + + POINTS_TREE = Tree_Create(sizeof(Vertex *), comparePosition); + POINTS = List_Create(100, 100, sizeof(Vertex *)); LOCAL->Simplexes = v->Simplexes; LOCAL->Vertices = v->Vertices; - - for (i = 0; i < List_Nbr (v->Surfaces); i++){ - List_Read (v->Surfaces, i, &s); - Tree_Action (s->Vertices, add_points); + + for(i = 0; i < List_Nbr(v->Surfaces); i++) { + List_Read(v->Surfaces, i, &s); + Tree_Action(s->Vertices, add_points); } - Tree_Action (POINTS_TREE, add_points_2); - Tree_Delete (POINTS_TREE); - - N = List_Nbr (POINTS); + Tree_Action(POINTS_TREE, add_points_2); + Tree_Delete(POINTS_TREE); + + N = List_Nbr(POINTS); n = N / 30 + 1; - if(!N) return; - + if(!N) + return; + /* Creation d'un maillage initial respectant la frontiere */ - + Msg(STATUS2, "Mesh 3D... (initial)"); - - Convex_Hull_Mesh (POINTS, LOCAL); - - if(!Coherence (v, LOCAL)) - Msg(GERROR, "Surface recovery failed (send a bug report with the geo file to <gmsh@geuz.org>!)"); - - Link_Simplexes (NULL, LOCAL->Simplexes); - - if(CTX.mesh.initial_only==3){ + + Convex_Hull_Mesh(POINTS, LOCAL); + + if(!Coherence(v, LOCAL)) + Msg(GERROR, + "Surface recovery failed (send a bug report with the geo file to <gmsh@geuz.org>!)"); + + Link_Simplexes(NULL, LOCAL->Simplexes); + + if(CTX.mesh.initial_only == 3) { POINTS_TREE = THEM->Vertices; - Tree_Action (v->Vertices, add_points); + Tree_Action(v->Vertices, add_points); POINTS_TREE = THEM->Simplexes; - Tree_Action (v->Simplexes, add_points); - return; + Tree_Action(v->Simplexes, add_points); + return; } - + /* Suppression des noeuds de num < 0 */ - - Suppress = List_Create (10, 10, sizeof (Vertex *)); - Tree_Action (v->Vertices, suppress_vertex); - for (i = 0; i < List_Nbr (Suppress); i++){ - Tree_Suppress (v->Vertices, List_Pointer (Suppress, i)); + + Suppress = List_Create(10, 10, sizeof(Vertex *)); + Tree_Action(v->Vertices, suppress_vertex); + for(i = 0; i < List_Nbr(Suppress); i++) { + Tree_Suppress(v->Vertices, List_Pointer(Suppress, i)); } - List_Delete (Suppress); + List_Delete(Suppress); /* Suppression des elements dont le num de vol == 0 (cad qui n'appartiennent a auncun volume defini) */ - Suppress = List_Create (10, 10, sizeof (Simplex *)); - Tree_Action (v->Simplexes, suppress_simplex); - for (i = 0; i < List_Nbr (Suppress); i++){ - Tree_Suppress (v->Simplexes, List_Pointer (Suppress, i)); + Suppress = List_Create(10, 10, sizeof(Simplex *)); + Tree_Action(v->Simplexes, suppress_simplex); + for(i = 0; i < List_Nbr(Suppress); i++) { + Tree_Suppress(v->Simplexes, List_Pointer(Suppress, i)); } - - List_Delete (Suppress); - - if (Tree_Nbr (LOCAL->Simplexes) == 0) return; + + List_Delete(Suppress); + + if(Tree_Nbr(LOCAL->Simplexes) == 0) + return; /* Si il reste quelque chose a mailler en volume : */ Msg(STATUS2, "Mesh 3D... (final)"); - + v->Simplexes = LOCAL->Simplexes; - - Bgm_With_Points (LOCAL); + + Bgm_With_Points(LOCAL); POINTS_TREE = THEM->Simplexes; - - Tree_Right (LOCAL->Simplexes, &simp); + + Tree_Right(LOCAL->Simplexes, &simp); i = 0; - while (simp->Quality > CONV_VALUE){ - newv = NewVertex (simp); + while(simp->Quality > CONV_VALUE) { + newv = NewVertex(simp); //double l; //while(!Pt_In_Volume(newv->Pos.X,newv->Pos.Y,newv->Pos.Z,LOCAL,&l,0.0)){ - - while (!simp->Pt_In_Simplexe (newv, uvw, 1.e-5) && - (simp->S[0] == &MyNewBoundary || - !simp->S[0]->Pt_In_Simplexe (newv, uvw, 1.e-5)) && - (simp->S[1] == &MyNewBoundary || - !simp->S[1]->Pt_In_Simplexe (newv, uvw, 1.e-5)) && - (simp->S[2] == &MyNewBoundary || - !simp->S[2]->Pt_In_Simplexe (newv, uvw, 1.e-5)) && - (simp->S[3] == &MyNewBoundary || - !simp->S[3]->Pt_In_Simplexe (newv, uvw, 1.e-5))) { - Tree_Suppress (LOCAL->Simplexes, &simp); + + while(!simp->Pt_In_Simplexe(newv, uvw, 1.e-5) && + (simp->S[0] == &MyNewBoundary || + !simp->S[0]->Pt_In_Simplexe(newv, uvw, 1.e-5)) && + (simp->S[1] == &MyNewBoundary || + !simp->S[1]->Pt_In_Simplexe(newv, uvw, 1.e-5)) && + (simp->S[2] == &MyNewBoundary || + !simp->S[2]->Pt_In_Simplexe(newv, uvw, 1.e-5)) && + (simp->S[3] == &MyNewBoundary || + !simp->S[3]->Pt_In_Simplexe(newv, uvw, 1.e-5))) { + Tree_Suppress(LOCAL->Simplexes, &simp); simp->Quality = 0.1; - Tree_Insert (LOCAL->Simplexes, &simp); - Tree_Right (LOCAL->Simplexes, &simp); - if (simp->Quality < CONV_VALUE) + Tree_Insert(LOCAL->Simplexes, &simp); + Tree_Right(LOCAL->Simplexes, &simp); + if(simp->Quality < CONV_VALUE) break; - newv = NewVertex (simp); + newv = NewVertex(simp); } - if (simp->Quality < CONV_VALUE) + if(simp->Quality < CONV_VALUE) break; i++; - if (i % n == n - 1){ + if(i % n == n - 1) { volume = 0.0; - Tree_Action (LOCAL->Simplexes, VSIM); + Tree_Action(LOCAL->Simplexes, VSIM); Msg(STATUS3, "Nod=%d Elm=%d", - Tree_Nbr (LOCAL->Vertices), Tree_Nbr (LOCAL->Simplexes)); - Msg(STATUS1, "Vol(%g) Conv(%g->%g)", volume, simp->Quality, CONV_VALUE); + Tree_Nbr(LOCAL->Vertices), Tree_Nbr(LOCAL->Simplexes)); + Msg(STATUS1, "Vol(%g) Conv(%g->%g)", volume, simp->Quality, + CONV_VALUE); double adv = 100. * (CONV_VALUE / simp->Quality); } - Bowyer_Watson (LOCAL, newv, simp, 0); - Tree_Right (LOCAL->Simplexes, &simp); + Bowyer_Watson(LOCAL, newv, simp, 0); + Tree_Right(LOCAL->Simplexes, &simp); } - + POINTS_TREE = THEM->Vertices; - Tree_Action (v->Vertices, add_points); + Tree_Action(v->Vertices, add_points); POINTS_TREE = THEM->Simplexes; - Tree_Action (v->Simplexes, add_points); - - if (CTX.mesh.quality){ - extern void SwapEdges3D (Mesh * M, Volume * v, double GammaPrescribed, bool order); + Tree_Action(v->Simplexes, add_points); + + if(CTX.mesh.quality) { + extern void SwapEdges3D(Mesh * M, Volume * v, double GammaPrescribed, + bool order); Msg(STATUS3, "Swapping edges (1st pass)"); - SwapEdges3D (THEM, v, CTX.mesh.quality, true); + SwapEdges3D(THEM, v, CTX.mesh.quality, true); Msg(STATUS3, "Swapping edges (2nd pass)"); - SwapEdges3D (THEM, v, CTX.mesh.quality, false); + SwapEdges3D(THEM, v, CTX.mesh.quality, false); Msg(STATUS3, "Swapping edges (last pass)"); - SwapEdges3D (THEM, v, CTX.mesh.quality, true); + SwapEdges3D(THEM, v, CTX.mesh.quality, true); } - if (CTX.mesh.nb_smoothing){ + if(CTX.mesh.nb_smoothing) { /* - Msg(STATUS3, "Laplacian smoothing"); - tnxe = Tree_Create (sizeof (NXE), compareNXE); - create_NXE (v->Vertices, v->Simplexes, tnxe); - for (int i = 0; i < CTX.mesh.nb_smoothing; i++) - Tree_Action (tnxe, ActionLiss); - delete_NXE (tnxe); - Msg(STATUS3, "Swapping edges (last pass)"); - SwapEdges3D (THEM, v, 0.5, true); - */ + Msg(STATUS3, "Laplacian smoothing"); + tnxe = Tree_Create (sizeof (NXE), compareNXE); + create_NXE (v->Vertices, v->Simplexes, tnxe); + for (int i = 0; i < CTX.mesh.nb_smoothing; i++) + Tree_Action (tnxe, ActionLiss); + delete_NXE (tnxe); + Msg(STATUS3, "Swapping edges (last pass)"); + SwapEdges3D (THEM, v, 0.5, true); + */ } - if (CTX.mesh.degree == 2) - Degre2 (THEM->Vertices, THEM->VertexEdges, v->Simplexes, NULL, NULL); + if(CTX.mesh.degree == 2) + Degre2(THEM->Vertices, THEM->VertexEdges, v->Simplexes, NULL, NULL); List_Delete(Simplexes_New); List_Delete(Simplexes_Destroyed); @@ -871,10 +918,13 @@ void Maillage_Volume (void *data, void *dum){ THEM->Statistics[10] += Tree_Nbr(v->Hexahedra); THEM->Statistics[11] += Tree_Nbr(v->Prisms); - if(v->Typ == 99999){ - Gamma_Maillage (THEM, &THEM->Statistics[17], &THEM->Statistics[18], &THEM->Statistics[19]); - Eta_Maillage (THEM, &THEM->Statistics[20], &THEM->Statistics[21], &THEM->Statistics[22]); - R_Maillage (THEM, &THEM->Statistics[23], &THEM->Statistics[24], &THEM->Statistics[25]); + if(v->Typ == 99999) { + Gamma_Maillage(THEM, &THEM->Statistics[17], &THEM->Statistics[18], + &THEM->Statistics[19]); + Eta_Maillage(THEM, &THEM->Statistics[20], &THEM->Statistics[21], + &THEM->Statistics[22]); + R_Maillage(THEM, &THEM->Statistics[23], &THEM->Statistics[24], + &THEM->Statistics[25]); } } diff --git a/Mesh/3D_SMesh.cpp b/Mesh/3D_SMesh.cpp index a39ad5c6d606871fb06f322cf3d4a3f2284f1122..b557eaadab4a56dddba6299619be1a02f995d9be 100644 --- a/Mesh/3D_SMesh.cpp +++ b/Mesh/3D_SMesh.cpp @@ -1,4 +1,4 @@ -// $Id: 3D_SMesh.cpp,v 1.15 2003-01-23 20:19:22 geuzaine Exp $ +// $Id: 3D_SMesh.cpp,v 1.16 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -47,32 +47,67 @@ #include "Interpolation.h" #include "Create.h" -extern Mesh *THEM; - -int index2d (int flag, int M, int N, int m, int n){ - switch(flag){ - case 0 : return(n + N*m); - case 1 : return(M*N - M*(n+1) + m); - case 2 : return(M*N - (n+N*m) - 1); - case 3 : return(M + n*M - m - 1); - case 4 : return(N + m*N - n - 1); - case 5 : return(M*N - (m+M*n) - 1); - case 6 : return(M*N - N*(m+1) + n); - case 7 : return(m + M*n); - default : return 0; +extern Mesh *THEM; + +int index2d(int flag, int M, int N, int m, int n) +{ + switch (flag) { + case 0: + return (n + N * m); + case 1: + return (M * N - M * (n + 1) + m); + case 2: + return (M * N - (n + N * m) - 1); + case 3: + return (M + n * M - m - 1); + case 4: + return (N + m * N - n - 1); + case 5: + return (M * N - (m + M * n) - 1); + case 6: + return (M * N - N * (m + 1) + n); + case 7: + return (m + M * n); + default: + return 0; } } -void index_uv (int flag, Vertex * ver, double *u, double *v){ - switch (flag){ - case 0: *u = ver->us[0]; *v = ver->us[1]; break; - case 1: *u = ver->us[1]; *v = 1. - ver->us[0]; break; - case 2: *u = 1. - ver->us[0]; *v = 1. - ver->us[1]; break; - case 3: *u = 1. - ver->us[1]; *v = ver->us[0]; break; - case 4: *u = ver->us[0]; *v = 1. - ver->us[1]; break; - case 5: *u = 1. - ver->us[1]; *v = 1. - ver->us[0]; break; - case 6: *u = 1. - ver->us[0]; *v = ver->us[1]; break; - case 7: *u = ver->us[1]; *v = ver->us[0]; break; +void index_uv(int flag, Vertex * ver, double *u, double *v) +{ + switch (flag) { + case 0: + *u = ver->us[0]; + *v = ver->us[1]; + break; + case 1: + *u = ver->us[1]; + *v = 1. - ver->us[0]; + break; + case 2: + *u = 1. - ver->us[0]; + *v = 1. - ver->us[1]; + break; + case 3: + *u = 1. - ver->us[1]; + *v = ver->us[0]; + break; + case 4: + *u = ver->us[0]; + *v = 1. - ver->us[1]; + break; + case 5: + *u = 1. - ver->us[1]; + *v = 1. - ver->us[0]; + break; + case 6: + *u = 1. - ver->us[0]; + *v = ver->us[1]; + break; + case 7: + *u = ver->us[1]; + *v = ver->us[0]; + break; } } @@ -129,53 +164,63 @@ void index_uv (int flag, Vertex * ver, double *u, double *v){ list[(i+1) + N1*(j+1) + N1*N2*(k+1)], \ list[(i+1) + N1*(j+1) + N1*N2*(k)]) -int MeshTransfiniteVolume (Volume *vol) { - int i,j,k,flag,nbs,nbp,nbg; - int nbtet=0, nbpri=0, nbhex=0; - Surface *G[6],*GG[6]; - Vertex V,**vexist,*pV,*CP[4],**list; - double u,v,w,dum; - int F_flag[6]; - int N1,N2,N3; - Vertex *F[6],*C[12],*Stmp[8],*S[8]; +int MeshTransfiniteVolume(Volume * vol) +{ + int i, j, k, flag, nbs, nbp, nbg; + int nbtet = 0, nbpri = 0, nbhex = 0; + Surface *G[6], *GG[6]; + Vertex V, **vexist, *pV, *CP[4], **list; + double u, v, w, dum; + int F_flag[6]; + int N1, N2, N3; + Vertex *F[6], *C[12], *Stmp[8], *S[8]; Hexahedron *hexa; - Prism *prism; - Simplex *simp; - int NbFacesFound=0 ; + Prism *prism; + Simplex *simp; + int NbFacesFound = 0; - static int tab1hex[] = {0,1,5,4, 1,2,6,5, 3,2,6,7, 0,3,7,4, 0,1,2,3, 4,5,6,7}; - static int tab2[] = {0,1,2,3, 1,2,3,0, 2,3,0,1, 3,0,1,2, - 3,2,1,0, 2,1,0,3, 1,0,3,2, 0,3,2,1}; + static int tab1hex[] = + { 0, 1, 5, 4, 1, 2, 6, 5, 3, 2, 6, 7, 0, 3, 7, 4, 0, 1, 2, 3, 4, 5, 6, +7 }; + static int tab2[] = { 0, 1, 2, 3, 1, 2, 3, 0, 2, 3, 0, 1, 3, 0, 1, 2, + 3, 2, 1, 0, 2, 1, 0, 3, 1, 0, 3, 2, 0, 3, 2, 1 + }; + + if(vol->Method != TRANSFINI) + return (0); - if (vol->Method != TRANSFINI) return(0); - nbs = List_Nbr(vol->Surfaces); - - if(nbs == 5) nbp = 6; - else if(nbs == 6) nbp = 8; - else return(0); + + if(nbs == 5) + nbp = 6; + else if(nbs == 6) + nbp = 8; + else + return (0); Msg(STATUS3, "Meshing Volume %d", vol->Num); - for(i=0;i<6;i++) G[i] = NULL ; - - for(i=0;i<nbp;i++){ + for(i = 0; i < 6; i++) + G[i] = NULL; + + for(i = 0; i < nbp; i++) { V.Num = vol->ipar[i]; pV = &V; - if((vexist = (Vertex**)Tree_PQuery(THEM->Vertices,&pV)) == NULL) { + if((vexist = (Vertex **) Tree_PQuery(THEM->Vertices, &pV)) == NULL) { Msg(WARNING, "Unknown control point %d in Transfinite Volume %d", - V.Num,vol->Num); - return(0); + V.Num, vol->Num); + return (0); } - else{ - Stmp[i]=*vexist; + else { + Stmp[i] = *vexist; } - } - - if(nbp == 8){ - for(i=0;i<8;i++) S[i]=Stmp[i]; } - else if(nbp == 6){ + + if(nbp == 8) { + for(i = 0; i < 8; i++) + S[i] = Stmp[i]; + } + else if(nbp == 6) { S[0] = S[3] = Stmp[0]; S[1] = Stmp[1]; S[2] = Stmp[2]; @@ -185,347 +230,404 @@ int MeshTransfiniteVolume (Volume *vol) { } /* - for(i=0;i<8;i++) printf("S[%d]=%d \n", i, S[i]->Num); - */ + for(i=0;i<8;i++) printf("S[%d]=%d \n", i, S[i]->Num); + */ + + for(i = 0; i < nbs; i++) + List_Read(vol->Surfaces, i, &GG[i]); - for(i=0;i<nbs;i++) List_Read(vol->Surfaces,i,&GG[i]); - - for(i=0;i<nbs;i++){ + for(i = 0; i < nbs; i++) { nbg = List_Nbr(GG[i]->Generatrices); - for(j=0;j<nbg;j++){ + for(j = 0; j < nbg; j++) { V.Num = GG[i]->ipar[j]; pV = &V; - if((vexist = (Vertex**)Tree_PQuery(THEM->Vertices,&pV)) == NULL) { + if((vexist = (Vertex **) Tree_PQuery(THEM->Vertices, &pV)) == NULL) { Msg(WARNING, "Unknown control point %d in Transfinite Surface %d", - V.Num,GG[i]->Num); - return(0); + V.Num, GG[i]->Num); + return (0); } - else{ - CP[j]=*vexist; + else { + CP[j] = *vexist; } - } - - if(nbg == 3) CP[3] = CP[0]; - - for(flag=0;flag<8;flag++){ - for(k=0;k<6;k++){ - if(S[tab1hex[4*k ]]->Num == CP[tab2[4*flag ]]->Num && - S[tab1hex[4*k+1]]->Num == CP[tab2[4*flag+1]]->Num && - S[tab1hex[4*k+2]]->Num == CP[tab2[4*flag+2]]->Num && - S[tab1hex[4*k+3]]->Num == CP[tab2[4*flag+3]]->Num ){ - G[k]=GG[i]; - F_flag[k]=flag; + } + + if(nbg == 3) + CP[3] = CP[0]; + + for(flag = 0; flag < 8; flag++) { + for(k = 0; k < 6; k++) { + if(S[tab1hex[4 * k]]->Num == CP[tab2[4 * flag]]->Num && + S[tab1hex[4 * k + 1]]->Num == CP[tab2[4 * flag + 1]]->Num && + S[tab1hex[4 * k + 2]]->Num == CP[tab2[4 * flag + 2]]->Num && + S[tab1hex[4 * k + 3]]->Num == CP[tab2[4 * flag + 3]]->Num) { + G[k] = GG[i]; + F_flag[k] = flag; NbFacesFound++; /* - printf("TR3D: (k=%d) face trouvee %d (flag = %d) : nodes %d %d %d %d \n", - k,GG[i]->Num, flag, - S[tab1hex[4*k ]]->Num, - S[tab1hex[4*k+1]]->Num, - S[tab1hex[4*k+2]]->Num, - S[tab1hex[4*k+3]]->Num); - */ + printf("TR3D: (k=%d) face trouvee %d (flag = %d) : nodes %d %d %d %d \n", + k,GG[i]->Num, flag, + S[tab1hex[4*k ]]->Num, + S[tab1hex[4*k+1]]->Num, + S[tab1hex[4*k+2]]->Num, + S[tab1hex[4*k+3]]->Num); + */ } } } } if(nbs == 6 && NbFacesFound != 6) { - Msg(WARNING, "Wrong definition of hexahedric Transfinite Volume %d", - vol->Num); - return(0); + Msg(WARNING, "Wrong definition of hexahedric Transfinite Volume %d", + vol->Num); + return (0); } if(nbs == 5 && NbFacesFound != 5) { - Msg(WARNING1, "Wrong definition of prismatic Transfinite Volume %d", vol->Num); + Msg(WARNING1, "Wrong definition of prismatic Transfinite Volume %d", + vol->Num); Msg(WARNING2, "Possibly because the first and fourth points are not the"); - Msg(WARNING3, "degenerated ones"); - return(0); + Msg(WARNING3, "degenerated ones"); + return (0); } - if(nbs == 6){ - for(i=0;i<6;i++){ + if(nbs == 6) { + for(i = 0; i < 6; i++) { if(G[i] == NULL) { Msg(WARNING, "Wrong definition of hexahedric Transfinite Volume %d", - vol->Num); - return(0); + vol->Num); + return (0); } } } - else if(nbs == 5){ - for(i=0;i<6;i++){ + else if(nbs == 5) { + for(i = 0; i < 6; i++) { if(i != 3) { if(G[i] == NULL) { - Msg(WARNING1, "Wrong definition of prismatic Transfinite Volume %d", vol->Num); - Msg(WARNING2, "Possibly because the first and fourth points are not the"); - Msg(WARNING3, "degenerated ones"); - return(0); + Msg(WARNING1, "Wrong definition of prismatic Transfinite Volume %d", + vol->Num); + Msg(WARNING2, + "Possibly because the first and fourth points are not the"); + Msg(WARNING3, "degenerated ones"); + return (0); } } } } - - N1 = (F_flag[4] % 2 == 0) ? G[4]->Nu : G[4]->Nv ; - N2 = (F_flag[4] % 2 == 0) ? G[4]->Nv : G[4]->Nu ; - N3 = (F_flag[0] % 2 == 0) ? G[0]->Nv : G[0]->Nu ; + + N1 = (F_flag[4] % 2 == 0) ? G[4]->Nu : G[4]->Nv; + N2 = (F_flag[4] % 2 == 0) ? G[4]->Nv : G[4]->Nu; + N3 = (F_flag[0] % 2 == 0) ? G[0]->Nv : G[0]->Nu; /* - printf("N1(%d) N2(%d) N3(%d)\n", N1,N2,N3); - */ - - list = (Vertex**)Malloc(N1*N2*N3*sizeof(Vertex*)); - - for(i=0;i<N1;i++){ - - for(j=0;j<N2;j++){ - - List_Read(G[4]->TrsfVertices, index2d(F_flag[4],N1,N2, i, 0 ), &C[0]); - List_Read(G[4]->TrsfVertices, index2d(F_flag[4],N1,N2, N1-1, j ), &C[1]); - List_Read(G[4]->TrsfVertices, index2d(F_flag[4],N1,N2, i, N2-1), &C[2]); - List_Read(G[4]->TrsfVertices, index2d(F_flag[4],N1,N2, 0, j ), &C[3]); - List_Read(G[5]->TrsfVertices, index2d(F_flag[5],N1,N2, i, 0 ), &C[4]); - List_Read(G[5]->TrsfVertices, index2d(F_flag[5],N1,N2, N1-1, j ), &C[5]); - List_Read(G[5]->TrsfVertices, index2d(F_flag[5],N1,N2, i, N2-1), &C[6]); - List_Read(G[5]->TrsfVertices, index2d(F_flag[5],N1,N2, 0, j ), &C[7]); - - List_Read(G[4]->TrsfVertices, index2d(F_flag[4],N1,N2, i, j), &F[4]); - List_Read(G[5]->TrsfVertices, index2d(F_flag[5],N1,N2, i, j), &F[5]); - - index_uv(F_flag[4],F[4],&u,&v); - - for(k=0;k<N3;k++){ - - List_Read(G[0]->TrsfVertices, index2d(F_flag[0],N1,N3, 0, k), &C[8]); - List_Read(G[0]->TrsfVertices, index2d(F_flag[0],N1,N3, N1-1, k), &C[9]); - List_Read(G[2]->TrsfVertices, index2d(F_flag[2],N1,N3, N1-1, k), &C[10]); - List_Read(G[2]->TrsfVertices, index2d(F_flag[2],N1,N3, 0, k), &C[11]); - - List_Read(G[0]->TrsfVertices, index2d(F_flag[0],N1,N3, i, k), &F[0]); - List_Read(G[1]->TrsfVertices, index2d(F_flag[1],N2,N3, j, k), &F[1]); - List_Read(G[2]->TrsfVertices, index2d(F_flag[2],N1,N3, i, k), &F[2]); - if(nbs==6) - List_Read(G[3]->TrsfVertices, index2d(F_flag[3],N2,N3, j, k), &F[3]); + printf("N1(%d) N2(%d) N3(%d)\n", N1,N2,N3); + */ + + list = (Vertex **) Malloc(N1 * N2 * N3 * sizeof(Vertex *)); + + for(i = 0; i < N1; i++) { + + for(j = 0; j < N2; j++) { + + List_Read(G[4]->TrsfVertices, index2d(F_flag[4], N1, N2, i, 0), &C[0]); + List_Read(G[4]->TrsfVertices, index2d(F_flag[4], N1, N2, N1 - 1, j), + &C[1]); + List_Read(G[4]->TrsfVertices, index2d(F_flag[4], N1, N2, i, N2 - 1), + &C[2]); + List_Read(G[4]->TrsfVertices, index2d(F_flag[4], N1, N2, 0, j), &C[3]); + List_Read(G[5]->TrsfVertices, index2d(F_flag[5], N1, N2, i, 0), &C[4]); + List_Read(G[5]->TrsfVertices, index2d(F_flag[5], N1, N2, N1 - 1, j), + &C[5]); + List_Read(G[5]->TrsfVertices, index2d(F_flag[5], N1, N2, i, N2 - 1), + &C[6]); + List_Read(G[5]->TrsfVertices, index2d(F_flag[5], N1, N2, 0, j), &C[7]); + + List_Read(G[4]->TrsfVertices, index2d(F_flag[4], N1, N2, i, j), &F[4]); + List_Read(G[5]->TrsfVertices, index2d(F_flag[5], N1, N2, i, j), &F[5]); + + index_uv(F_flag[4], F[4], &u, &v); + + for(k = 0; k < N3; k++) { + + List_Read(G[0]->TrsfVertices, index2d(F_flag[0], N1, N3, 0, k), + &C[8]); + List_Read(G[0]->TrsfVertices, index2d(F_flag[0], N1, N3, N1 - 1, k), + &C[9]); + List_Read(G[2]->TrsfVertices, index2d(F_flag[2], N1, N3, N1 - 1, k), + &C[10]); + List_Read(G[2]->TrsfVertices, index2d(F_flag[2], N1, N3, 0, k), + &C[11]); + + List_Read(G[0]->TrsfVertices, index2d(F_flag[0], N1, N3, i, k), + &F[0]); + List_Read(G[1]->TrsfVertices, index2d(F_flag[1], N2, N3, j, k), + &F[1]); + List_Read(G[2]->TrsfVertices, index2d(F_flag[2], N1, N3, i, k), + &F[2]); + if(nbs == 6) + List_Read(G[3]->TrsfVertices, index2d(F_flag[3], N2, N3, j, k), + &F[3]); else if(nbs == 5) - F[3]=C[8]; - - index_uv(F_flag[0],F[0],&dum,&w); - - if(i && j && k && i != N1-1 && j != N2-1 && k != N3-1){ - V = TransfiniteHex(*F[0],*F[1],*F[2],*F[3],*F[4],*F[5], - *C[0],*C[1],*C[2],*C[3],*C[4],*C[5], - *C[6],*C[7],*C[8],*C[9],*C[10],*C[11], - *S[0],*S[1],*S[2],*S[3],*S[4],*S[5],*S[6],*S[7], - u,v,w); - list[i+N1*j+N1*N2*k] = Create_Vertex(++THEM->MaxPointNum, - V.Pos.X,V.Pos.Y,V.Pos.Z,V.lc,0.0); + F[3] = C[8]; + + index_uv(F_flag[0], F[0], &dum, &w); + + if(i && j && k && i != N1 - 1 && j != N2 - 1 && k != N3 - 1) { + V = TransfiniteHex(*F[0], *F[1], *F[2], *F[3], *F[4], *F[5], + *C[0], *C[1], *C[2], *C[3], *C[4], *C[5], + *C[6], *C[7], *C[8], *C[9], *C[10], *C[11], + *S[0], *S[1], *S[2], *S[3], *S[4], *S[5], *S[6], + *S[7], u, v, w); + list[i + N1 * j + N1 * N2 * k] = + Create_Vertex(++THEM->MaxPointNum, V.Pos.X, V.Pos.Y, V.Pos.Z, + V.lc, 0.0); /* - printf(" NEW node : %f %f %f\n", list[i+N1*j+N1*N2*k]->Pos.X, - list[i+N1*j+N1*N2*k]->Pos.Y, list[i+N1*j+N1*N2*k]->Pos.Z); - */ + printf(" NEW node : %f %f %f\n", list[i+N1*j+N1*N2*k]->Pos.X, + list[i+N1*j+N1*N2*k]->Pos.Y, list[i+N1*j+N1*N2*k]->Pos.Z); + */ } - else if(!i){ - list[i+N1*j+N1*N2*k] = F[3]; + else if(!i) { + list[i + N1 * j + N1 * N2 * k] = F[3]; } - else if(!j){ - list[i+N1*j+N1*N2*k] = F[0]; + else if(!j) { + list[i + N1 * j + N1 * N2 * k] = F[0]; } - else if(!k){ - list[i+N1*j+N1*N2*k] = F[4]; + else if(!k) { + list[i + N1 * j + N1 * N2 * k] = F[4]; } - else if(i == N1-1){ - list[i+N1*j+N1*N2*k] = F[1]; + else if(i == N1 - 1) { + list[i + N1 * j + N1 * N2 * k] = F[1]; } - else if(j == N2-1){ - list[i+N1*j+N1*N2*k] = F[2]; + else if(j == N2 - 1) { + list[i + N1 * j + N1 * N2 * k] = F[2]; } - else if(k == N3-1){ - list[i+N1*j+N1*N2*k] = F[5]; + else if(k == N3 - 1) { + list[i + N1 * j + N1 * N2 * k] = F[5]; } - + } } } - - for(i=0;i<N1;i++){ - for(j=0;j<N2;j++){ - for(k=0;k<N3;k++){ - Tree_Replace(THEM->Vertices,&list[i+N1*j+N1*N2*k]); - Tree_Replace(vol->Vertices,&list[i+N1*j+N1*N2*k]); + + for(i = 0; i < N1; i++) { + for(j = 0; j < N2; j++) { + for(k = 0; k < N3; k++) { + Tree_Replace(THEM->Vertices, &list[i + N1 * j + N1 * N2 * k]); + Tree_Replace(vol->Vertices, &list[i + N1 * j + N1 * N2 * k]); } } - } + } - if(nbs == 6){ - for(i=0;i<N1-1;i++){ - for(j=0;j<N2-1;j++){ - for(k=0;k<N3-1;k++){ - if(G[0]->Recombine && G[1]->Recombine && G[2]->Recombine && + if(nbs == 6) { + for(i = 0; i < N1 - 1; i++) { + for(j = 0; j < N2 - 1; j++) { + for(k = 0; k < N3 - 1; k++) { + if(G[0]->Recombine && G[1]->Recombine && G[2]->Recombine && G[3]->Recombine && G[4]->Recombine && G[5]->Recombine) { - hexa = CREATE_HEX; hexa->iEnt = vol->Num; Tree_Replace(vol->Hexahedra,&hexa); + hexa = CREATE_HEX; + hexa->iEnt = vol->Num; + Tree_Replace(vol->Hexahedra, &hexa); nbhex++; } - else if (!G[0]->Recombine && G[1]->Recombine && !G[2]->Recombine && - G[3]->Recombine && G[4]->Recombine && G[5]->Recombine) { - prism = Create_Prism(list[(i) + N1*(j) + N1*N2*(k)], - list[(i+1) + N1*(j) + N1*N2*(k)], - list[(i) + N1*(j) + N1*N2*(k+1)], - list[(i) + N1*(j+1) + N1*N2*(k)], - list[(i+1) + N1*(j+1) + N1*N2*(k)], - list[(i) + N1*(j+1) + N1*N2*(k+1)]); + else if(!G[0]->Recombine && G[1]->Recombine && !G[2]->Recombine && + G[3]->Recombine && G[4]->Recombine && G[5]->Recombine) { + prism = Create_Prism(list[(i) + N1 * (j) + N1 * N2 * (k)], + list[(i + 1) + N1 * (j) + N1 * N2 * (k)], + list[(i) + N1 * (j) + N1 * N2 * (k + 1)], + list[(i) + N1 * (j + 1) + N1 * N2 * (k)], + list[(i + 1) + N1 * (j + 1) + N1 * N2 * (k)], + list[(i) + N1 * (j + 1) + + N1 * N2 * (k + 1)]); prism->iEnt = vol->Num; - Tree_Replace(vol->Prisms,&prism); - - prism = Create_Prism(list[(i+1) + N1*(j) + N1*N2*(k+1)], - list[(i) + N1*(j) + N1*N2*(k+1)], - list[(i+1) + N1*(j) + N1*N2*(k)], - list[(i+1) + N1*(j+1) + N1*N2*(k+1)], - list[(i) + N1*(j+1) + N1*N2*(k+1)], - list[(i+1) + N1*(j+1) + N1*N2*(k)]); + Tree_Replace(vol->Prisms, &prism); + + prism = Create_Prism(list[(i + 1) + N1 * (j) + N1 * N2 * (k + 1)], + list[(i) + N1 * (j) + N1 * N2 * (k + 1)], + list[(i + 1) + N1 * (j) + N1 * N2 * (k)], + list[(i + 1) + N1 * (j + 1) + + N1 * N2 * (k + 1)], + list[(i) + N1 * (j + 1) + N1 * N2 * (k + 1)], + list[(i + 1) + N1 * (j + 1) + + N1 * N2 * (k)]); prism->iEnt = vol->Num; - Tree_Replace(vol->Prisms,&prism); + Tree_Replace(vol->Prisms, &prism); - nbpri +=2 ; + nbpri += 2; } - else if (G[0]->Recombine && !G[1]->Recombine && G[2]->Recombine && - !G[3]->Recombine && G[4]->Recombine && G[5]->Recombine) { - prism = Create_Prism(list[(i+1) + N1*(j) + N1*N2*(k)], - list[(i+1) + N1*(j+1) + N1*N2*(k)], - list[(i+1) + N1*(j) + N1*N2*(k+1)], - list[(i) + N1*(j) + N1*N2*(k)], - list[(i) + N1*(j+1) + N1*N2*(k)], - list[(i) + N1*(j) + N1*N2*(k+1)]); + else if(G[0]->Recombine && !G[1]->Recombine && G[2]->Recombine && + !G[3]->Recombine && G[4]->Recombine && G[5]->Recombine) { + prism = Create_Prism(list[(i + 1) + N1 * (j) + N1 * N2 * (k)], + list[(i + 1) + N1 * (j + 1) + N1 * N2 * (k)], + list[(i + 1) + N1 * (j) + N1 * N2 * (k + 1)], + list[(i) + N1 * (j) + N1 * N2 * (k)], + list[(i) + N1 * (j + 1) + N1 * N2 * (k)], + list[(i) + N1 * (j) + N1 * N2 * (k + 1)]); prism->iEnt = vol->Num; - Tree_Replace(vol->Prisms,&prism); - - prism = Create_Prism(list[(i+1) + N1*(j+1) + N1*N2*(k+1)], - list[(i+1) + N1*(j) + N1*N2*(k+1)], - list[(i+1) + N1*(j+1) + N1*N2*(k)], - list[(i) + N1*(j+1) + N1*N2*(k+1)], - list[(i) + N1*(j) + N1*N2*(k+1)], - list[(i) + N1*(j+1) + N1*N2*(k)]); + Tree_Replace(vol->Prisms, &prism); + + prism = + Create_Prism(list[(i + 1) + N1 * (j + 1) + N1 * N2 * (k + 1)], + list[(i + 1) + N1 * (j) + N1 * N2 * (k + 1)], + list[(i + 1) + N1 * (j + 1) + N1 * N2 * (k)], + list[(i) + N1 * (j + 1) + N1 * N2 * (k + 1)], + list[(i) + N1 * (j) + N1 * N2 * (k + 1)], + list[(i) + N1 * (j + 1) + N1 * N2 * (k)]); prism->iEnt = vol->Num; - Tree_Replace(vol->Prisms,&prism); + Tree_Replace(vol->Prisms, &prism); - nbpri += 2 ; + nbpri += 2; } - else if (G[0]->Recombine && G[1]->Recombine && G[2]->Recombine && - G[3]->Recombine && !G[4]->Recombine && !G[5]->Recombine) { - prism = CREATE_PRISM_1; prism->iEnt = vol->Num; Tree_Replace(vol->Prisms,&prism); - prism = CREATE_PRISM_2; prism->iEnt = vol->Num; Tree_Replace(vol->Prisms,&prism); + else if(G[0]->Recombine && G[1]->Recombine && G[2]->Recombine && + G[3]->Recombine && !G[4]->Recombine && !G[5]->Recombine) { + prism = CREATE_PRISM_1; + prism->iEnt = vol->Num; + Tree_Replace(vol->Prisms, &prism); + prism = CREATE_PRISM_2; + prism->iEnt = vol->Num; + Tree_Replace(vol->Prisms, &prism); nbpri += 2; } - else if (!G[0]->Recombine && !G[1]->Recombine && !G[2]->Recombine && - !G[3]->Recombine && !G[4]->Recombine && !G[5]->Recombine) { - simp = CREATE_SIM_1; simp->iEnt = vol->Num; Tree_Replace(vol->Simplexes,&simp); - simp = CREATE_SIM_2; simp->iEnt = vol->Num; Tree_Replace(vol->Simplexes,&simp); - simp = CREATE_SIM_3; simp->iEnt = vol->Num; Tree_Replace(vol->Simplexes,&simp); - simp = CREATE_SIM_4; simp->iEnt = vol->Num; Tree_Replace(vol->Simplexes,&simp); - simp = CREATE_SIM_5; simp->iEnt = vol->Num; Tree_Replace(vol->Simplexes,&simp); - simp = CREATE_SIM_6; simp->iEnt = vol->Num; Tree_Replace(vol->Simplexes,&simp); + else if(!G[0]->Recombine && !G[1]->Recombine && !G[2]->Recombine && + !G[3]->Recombine && !G[4]->Recombine && !G[5]->Recombine) { + simp = CREATE_SIM_1; + simp->iEnt = vol->Num; + Tree_Replace(vol->Simplexes, &simp); + simp = CREATE_SIM_2; + simp->iEnt = vol->Num; + Tree_Replace(vol->Simplexes, &simp); + simp = CREATE_SIM_3; + simp->iEnt = vol->Num; + Tree_Replace(vol->Simplexes, &simp); + simp = CREATE_SIM_4; + simp->iEnt = vol->Num; + Tree_Replace(vol->Simplexes, &simp); + simp = CREATE_SIM_5; + simp->iEnt = vol->Num; + Tree_Replace(vol->Simplexes, &simp); + simp = CREATE_SIM_6; + simp->iEnt = vol->Num; + Tree_Replace(vol->Simplexes, &simp); nbtet += 6; } - else{ - Msg(WARNING, "Wrong surface recombining in Transfinite Volume %d", - vol->Num); - return(0); + else { + Msg(WARNING, "Wrong surface recombining in Transfinite Volume %d", + vol->Num); + return (0); } } } - } + } } - else if (nbs == 5){ - for(j=0;j<N2-1;j++){ - for(k=0;k<N3-1;k++){ - if( ( G[0]->Recombine && G[1]->Recombine && G[2]->Recombine && - G[4]->Recombine && G[5]->Recombine) || - ( G[0]->Recombine && G[1]->Recombine && G[2]->Recombine && - !G[4]->Recombine && !G[5]->Recombine) ){ - prism = Create_Prism(list[ N1*(j) + N1*N2*(k)], - list[1 + N1*(j) + N1*N2*(k)], - list[1 + N1*(j+1) + N1*N2*(k)], - list[ N1*(j) + N1*N2*(k+1)], - list[1 + N1*(j) + N1*N2*(k+1)], - list[1 + N1*(j+1) + N1*N2*(k+1)]); + else if(nbs == 5) { + for(j = 0; j < N2 - 1; j++) { + for(k = 0; k < N3 - 1; k++) { + if((G[0]->Recombine && G[1]->Recombine && G[2]->Recombine && + G[4]->Recombine && G[5]->Recombine) || + (G[0]->Recombine && G[1]->Recombine && G[2]->Recombine && + !G[4]->Recombine && !G[5]->Recombine)) { + prism = Create_Prism(list[N1 * (j) + N1 * N2 * (k)], + list[1 + N1 * (j) + N1 * N2 * (k)], + list[1 + N1 * (j + 1) + N1 * N2 * (k)], + list[N1 * (j) + N1 * N2 * (k + 1)], + list[1 + N1 * (j) + N1 * N2 * (k + 1)], + list[1 + N1 * (j + 1) + N1 * N2 * (k + 1)]); prism->iEnt = vol->Num; - Tree_Replace(vol->Prisms,&prism); - + Tree_Replace(vol->Prisms, &prism); + nbpri++; } else if(!G[0]->Recombine && !G[1]->Recombine && !G[2]->Recombine && - !G[4]->Recombine && !G[5]->Recombine){ - simp = Create_Simplex(list[ + N1*(j) + N1*N2*(k)], - list[1 + N1*(j) + N1*N2*(k)], - list[1 + N1*(j+1) + N1*N2*(k)], - list[ + N1*(j) + N1*N2*(k+1)]); + !G[4]->Recombine && !G[5]->Recombine) { + simp = Create_Simplex(list[+N1 * (j) + N1 * N2 * (k)], + list[1 + N1 * (j) + N1 * N2 * (k)], + list[1 + N1 * (j + 1) + N1 * N2 * (k)], + list[+N1 * (j) + N1 * N2 * (k + 1)]); simp->iEnt = vol->Num; - Tree_Replace(vol->Simplexes,&simp); - - simp = Create_Simplex(list[1 + N1*(j) + N1*N2*(k)], - list[1 + N1*(j+1) + N1*N2*(k)], - list[ + N1*(j) + N1*N2*(k+1)], - list[1 + N1*(j) + N1*N2*(k+1)]); + Tree_Replace(vol->Simplexes, &simp); + + simp = Create_Simplex(list[1 + N1 * (j) + N1 * N2 * (k)], + list[1 + N1 * (j + 1) + N1 * N2 * (k)], + list[+N1 * (j) + N1 * N2 * (k + 1)], + list[1 + N1 * (j) + N1 * N2 * (k + 1)]); simp->iEnt = vol->Num; - Tree_Replace(vol->Simplexes,&simp); - - simp = Create_Simplex(list[ + N1*(j) + N1*N2*(k+1)], - list[1 + N1*(j+1) + N1*N2*(k+1)], - list[1 + N1*(j) + N1*N2*(k+1)], - list[1 + N1*(j+1) + N1*N2*(k)]); + Tree_Replace(vol->Simplexes, &simp); + + simp = Create_Simplex(list[+N1 * (j) + N1 * N2 * (k + 1)], + list[1 + N1 * (j + 1) + N1 * N2 * (k + 1)], + list[1 + N1 * (j) + N1 * N2 * (k + 1)], + list[1 + N1 * (j + 1) + N1 * N2 * (k)]); simp->iEnt = vol->Num; - Tree_Replace(vol->Simplexes,&simp); - + Tree_Replace(vol->Simplexes, &simp); + nbtet += 2; } - else{ - Msg(WARNING, "Wrong surface recombining in Transfinite Volume %d", - vol->Num); - return(0); + else { + Msg(WARNING, "Wrong surface recombining in Transfinite Volume %d", + vol->Num); + return (0); } } } - for(i=1;i<N1-1;i++){ - for(j=0;j<N2-1;j++){ - for(k=0;k<N3-1;k++){ + for(i = 1; i < N1 - 1; i++) { + for(j = 0; j < N2 - 1; j++) { + for(k = 0; k < N3 - 1; k++) { if(G[0]->Recombine && G[1]->Recombine && G[2]->Recombine && - G[4]->Recombine && G[5]->Recombine){ - hexa = CREATE_HEX; hexa->iEnt = vol->Num; Tree_Replace(vol->Hexahedra,&hexa); + G[4]->Recombine && G[5]->Recombine) { + hexa = CREATE_HEX; + hexa->iEnt = vol->Num; + Tree_Replace(vol->Hexahedra, &hexa); - nbhex ++; + nbhex++; } else if(G[0]->Recombine && G[1]->Recombine && G[2]->Recombine && - !G[4]->Recombine && !G[5]->Recombine){ - prism = CREATE_PRISM_1; prism->iEnt = vol->Num; Tree_Replace(vol->Prisms,&prism); - prism = CREATE_PRISM_2; prism->iEnt = vol->Num; Tree_Replace(vol->Prisms,&prism); + !G[4]->Recombine && !G[5]->Recombine) { + prism = CREATE_PRISM_1; + prism->iEnt = vol->Num; + Tree_Replace(vol->Prisms, &prism); + prism = CREATE_PRISM_2; + prism->iEnt = vol->Num; + Tree_Replace(vol->Prisms, &prism); nbpri += 2; } else if(!G[0]->Recombine && !G[1]->Recombine && !G[2]->Recombine && - !G[4]->Recombine && !G[5]->Recombine){ - simp = CREATE_SIM_1; simp->iEnt = vol->Num; Tree_Replace(vol->Simplexes,&simp); - simp = CREATE_SIM_2; simp->iEnt = vol->Num; Tree_Replace(vol->Simplexes,&simp); - simp = CREATE_SIM_3; simp->iEnt = vol->Num; Tree_Replace(vol->Simplexes,&simp); - simp = CREATE_SIM_4; simp->iEnt = vol->Num; Tree_Replace(vol->Simplexes,&simp); - simp = CREATE_SIM_5; simp->iEnt = vol->Num; Tree_Replace(vol->Simplexes,&simp); - simp = CREATE_SIM_6; simp->iEnt = vol->Num; Tree_Replace(vol->Simplexes,&simp); + !G[4]->Recombine && !G[5]->Recombine) { + simp = CREATE_SIM_1; + simp->iEnt = vol->Num; + Tree_Replace(vol->Simplexes, &simp); + simp = CREATE_SIM_2; + simp->iEnt = vol->Num; + Tree_Replace(vol->Simplexes, &simp); + simp = CREATE_SIM_3; + simp->iEnt = vol->Num; + Tree_Replace(vol->Simplexes, &simp); + simp = CREATE_SIM_4; + simp->iEnt = vol->Num; + Tree_Replace(vol->Simplexes, &simp); + simp = CREATE_SIM_5; + simp->iEnt = vol->Num; + Tree_Replace(vol->Simplexes, &simp); + simp = CREATE_SIM_6; + simp->iEnt = vol->Num; + Tree_Replace(vol->Simplexes, &simp); nbtet += 6; } - else{ - Msg(WARNING, "Wrong surface recombining in Transfinite Volume %d", - vol->Num); - return(0); + else { + Msg(WARNING, "Wrong surface recombining in Transfinite Volume %d", + vol->Num); + return (0); } } } } } - return(1); + return (1); } - diff --git a/Mesh/Create.cpp b/Mesh/Create.cpp index 9918f24cd92a1db6084fe644f5289dfc62203aef..8cd1c5cbfa66102156a9bebed9b82998a30d80e2 100644 --- a/Mesh/Create.cpp +++ b/Mesh/Create.cpp @@ -1,4 +1,4 @@ -// $Id: Create.cpp,v 1.40 2003-01-23 20:19:22 geuzaine Exp $ +// $Id: Create.cpp,v 1.41 2003-03-01 22:36:41 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -28,26 +28,29 @@ #include "Context.h" #include "Create.h" -extern Mesh *THEM; -extern Context_T CTX; +extern Mesh *THEM; +extern Context_T CTX; -int compareNXE (const void *a, const void *b){ +int compareNXE(const void *a, const void *b) +{ NXE *q, *w; q = (NXE *) a; w = (NXE *) b; - return (compareVertex (&q->v, &w->v)); + return (compareVertex(&q->v, &w->v)); } -int compareFxE (const void *a, const void *b){ +int compareFxE(const void *a, const void *b) +{ FxE *q, *w; q = (FxE *) a; w = (FxE *) b; - return (compareFace (&q->Sorted, &w->Sorted)); + return (compareFace(&q->Sorted, &w->Sorted)); } -int compareSurfaceLoop (const void *a, const void *b){ +int compareSurfaceLoop(const void *a, const void *b) +{ SurfaceLoop **q, **w; q = (SurfaceLoop **) a; @@ -55,7 +58,8 @@ int compareSurfaceLoop (const void *a, const void *b){ return ((*q)->Num - (*w)->Num); } -int compareEdgeLoop (const void *a, const void *b){ +int compareEdgeLoop(const void *a, const void *b) +{ EdgeLoop **q, **w; q = (EdgeLoop **) a; @@ -63,7 +67,8 @@ int compareEdgeLoop (const void *a, const void *b){ return ((*q)->Num - (*w)->Num); } -int compareHexahedron (const void *a, const void *b){ +int compareHexahedron(const void *a, const void *b) +{ Hexahedron **q, **w; q = (Hexahedron **) a; @@ -71,7 +76,8 @@ int compareHexahedron (const void *a, const void *b){ return ((*q)->Num - (*w)->Num); } -int comparePrism (const void *a, const void *b){ +int comparePrism(const void *a, const void *b) +{ Prism **q, **w; q = (Prism **) a; @@ -79,7 +85,8 @@ int comparePrism (const void *a, const void *b){ return ((*q)->Num - (*w)->Num); } -int comparePyramid (const void *a, const void *b){ +int comparePyramid(const void *a, const void *b) +{ Pyramid **q, **w; q = (Pyramid **) a; @@ -87,7 +94,8 @@ int comparePyramid (const void *a, const void *b){ return ((*q)->Num - (*w)->Num); } -int compareQuality (const void *a, const void *b){ +int compareQuality(const void *a, const void *b) +{ double d; Simplex **q, **w; @@ -95,14 +103,15 @@ int compareQuality (const void *a, const void *b){ w = (Simplex **) b; d = (*q)->Quality - (*w)->Quality; - if (d > 0) + if(d > 0) return (1); - if (d < 0) + if(d < 0) return (-1); return ((*q)->Num - (*w)->Num); } -int compareCurve (const void *a, const void *b){ +int compareCurve(const void *a, const void *b) +{ Curve **q, **w; q = (Curve **) a; @@ -110,7 +119,8 @@ int compareCurve (const void *a, const void *b){ return ((*q)->Num - (*w)->Num); } -int compareAttractor (const void *a, const void *b){ +int compareAttractor(const void *a, const void *b) +{ Attractor **q, **w; q = (Attractor **) a; @@ -118,7 +128,8 @@ int compareAttractor (const void *a, const void *b){ return ((*q)->Num - (*w)->Num); } -int compareSurface (const void *a, const void *b){ +int compareSurface(const void *a, const void *b) +{ Surface **q, **w; q = (Surface **) a; @@ -126,7 +137,8 @@ int compareSurface (const void *a, const void *b){ return ((*q)->Num - (*w)->Num); } -int compareVolume (const void *a, const void *b){ +int compareVolume(const void *a, const void *b) +{ Volume **q, **w; q = (Volume **) a; @@ -134,19 +146,21 @@ int compareVolume (const void *a, const void *b){ return ((*q)->Num - (*w)->Num); } -int compareSxF (const void *a, const void *b){ +int compareSxF(const void *a, const void *b) +{ SxF *q, *w; q = (SxF *) a; w = (SxF *) b; - return compareFace (&q->F, &w->F); + return compareFace(&q->F, &w->F); } -Attractor * Create_Attractor (int Num, double lc1, double lc2, double Radius, - Vertex * v, Curve * c, Surface * s){ +Attractor *Create_Attractor(int Num, double lc1, double lc2, double Radius, + Vertex * v, Curve * c, Surface * s) +{ Attractor *pA; - pA = (Attractor *) Malloc (sizeof (Attractor)); + pA = (Attractor *) Malloc(sizeof(Attractor)); pA->v = v; pA->c = c; pA->s = s; @@ -156,51 +170,55 @@ Attractor * Create_Attractor (int Num, double lc1, double lc2, double Radius, return pA; } -void Add_SurfaceLoop (int Num, List_T * intlist, Mesh * M){ +void Add_SurfaceLoop(int Num, List_T * intlist, Mesh * M) +{ SurfaceLoop *pSL; int i, j; - pSL = (SurfaceLoop *) Malloc (sizeof (SurfaceLoop)); - pSL->Surfaces = List_Create (List_Nbr (intlist), 1, sizeof (int)); + pSL = (SurfaceLoop *) Malloc(sizeof(SurfaceLoop)); + pSL->Surfaces = List_Create(List_Nbr(intlist), 1, sizeof(int)); pSL->Num = Num; - THEM->MaxSurfaceLoopNum = IMAX(THEM->MaxSurfaceLoopNum,Num); - for (i = 0; i < List_Nbr (intlist); i++){ - List_Read (intlist, i, &j); - List_Add (pSL->Surfaces, &j); + THEM->MaxSurfaceLoopNum = IMAX(THEM->MaxSurfaceLoopNum, Num); + for(i = 0; i < List_Nbr(intlist); i++) { + List_Read(intlist, i, &j); + List_Add(pSL->Surfaces, &j); } - Tree_Add (M->SurfaceLoops, &pSL); + Tree_Add(M->SurfaceLoops, &pSL); } -void Add_PhysicalGroup (int Num, int typ, List_T * intlist, Mesh * M){ +void Add_PhysicalGroup(int Num, int typ, List_T * intlist, Mesh * M) +{ PhysicalGroup *p; int i, j; - p = (PhysicalGroup *) Malloc (sizeof (PhysicalGroup)); - p->Entities = List_Create (List_Nbr (intlist), 1, sizeof (int)); + p = (PhysicalGroup *) Malloc(sizeof(PhysicalGroup)); + p->Entities = List_Create(List_Nbr(intlist), 1, sizeof(int)); p->Num = Num; - THEM->MaxPhysicalNum = IMAX(THEM->MaxPhysicalNum,Num); + THEM->MaxPhysicalNum = IMAX(THEM->MaxPhysicalNum, Num); p->Typ = typ; - p->Visible = VIS_GEOM|VIS_MESH; - for (i = 0; i < List_Nbr (intlist); i++){ - List_Read (intlist, i, &j); - List_Add (p->Entities, &j); + p->Visible = VIS_GEOM | VIS_MESH; + for(i = 0; i < List_Nbr(intlist); i++) { + List_Read(intlist, i, &j); + List_Add(p->Entities, &j); } - List_Add (M->PhysicalGroups, &p); + List_Add(M->PhysicalGroups, &p); } -void Add_EdgeLoop (int Num, List_T * intlist, Mesh * M){ +void Add_EdgeLoop(int Num, List_T * intlist, Mesh * M) +{ EdgeLoop *pEL; int i, j; - pEL = (EdgeLoop *) Malloc (sizeof (EdgeLoop)); - pEL->Curves = List_Create (List_Nbr (intlist), 1, sizeof (int)); + pEL = (EdgeLoop *) Malloc(sizeof(EdgeLoop)); + pEL->Curves = List_Create(List_Nbr(intlist), 1, sizeof(int)); pEL->Num = Num; - THEM->MaxLineLoopNum = IMAX(THEM->MaxLineLoopNum,Num); - for (i = 0; i < List_Nbr (intlist); i++){ - List_Read (intlist, i, &j); - List_Add (pEL->Curves, &j); + THEM->MaxLineLoopNum = IMAX(THEM->MaxLineLoopNum, Num); + for(i = 0; i < List_Nbr(intlist); i++) { + List_Read(intlist, i, &j); + List_Add(pEL->Curves, &j); } - Tree_Add (M->EdgeLoops, &pEL); + Tree_Add(M->EdgeLoops, &pEL); } -void End_Curve (Curve * c){ +void End_Curve(Curve * c) +{ double R2, mat[3][3], R, A3, A1, A4; Vertex *v[4], v0, v2, v3; double f1, f2, dir32[3], dir12[3], n[3], m[3], dir42[3]; @@ -208,10 +226,9 @@ void End_Curve (Curve * c){ int i; Curve *Curve; - if (c->Typ == MSH_SEGM_CIRC || - c->Typ == MSH_SEGM_CIRC_INV || - c->Typ == MSH_SEGM_ELLI || - c->Typ == MSH_SEGM_ELLI_INV){ + if(c->Typ == MSH_SEGM_CIRC || + c->Typ == MSH_SEGM_CIRC_INV || + c->Typ == MSH_SEGM_ELLI || c->Typ == MSH_SEGM_ELLI_INV) { Curve = c; @@ -220,32 +237,32 @@ void End_Curve (Curve * c){ // v[2] = last point // v[3] = major axis point - if (List_Nbr (Curve->Control_Points) == 4) - List_Read (Curve->Control_Points, 2, &v[3]); + if(List_Nbr(Curve->Control_Points) == 4) + List_Read(Curve->Control_Points, 2, &v[3]); else v[3] = NULL; - - if (Curve->Typ == MSH_SEGM_CIRC_INV || - Curve->Typ == MSH_SEGM_ELLI_INV){ - List_Read (Curve->Control_Points, 0, &v[2]); - List_Read (Curve->Control_Points, 1, &v[1]); - if (!v[3]) - List_Read (Curve->Control_Points, 2, &v[0]); + + if(Curve->Typ == MSH_SEGM_CIRC_INV || Curve->Typ == MSH_SEGM_ELLI_INV) { + List_Read(Curve->Control_Points, 0, &v[2]); + List_Read(Curve->Control_Points, 1, &v[1]); + if(!v[3]) + List_Read(Curve->Control_Points, 2, &v[0]); else - List_Read (Curve->Control_Points, 3, &v[0]); + List_Read(Curve->Control_Points, 3, &v[0]); } - else{ - List_Read (Curve->Control_Points, 0, &v[0]); - List_Read (Curve->Control_Points, 1, &v[1]); - if (!v[3]) - List_Read (Curve->Control_Points, 2, &v[2]); + else { + List_Read(Curve->Control_Points, 0, &v[0]); + List_Read(Curve->Control_Points, 1, &v[1]); + if(!v[3]) + List_Read(Curve->Control_Points, 2, &v[2]); else - List_Read (Curve->Control_Points, 3, &v[2]); + List_Read(Curve->Control_Points, 3, &v[2]); } direction(v[1], v[0], dir12); direction(v[1], v[2], dir32); - if(v[3]) direction(v[1], v[3], dir42); + if(v[3]) + direction(v[1], v[3], dir42); // v0 = vector center->first pt // v2 = vector center->last pt @@ -257,7 +274,7 @@ void End_Curve (Curve * c){ v2.Pos.X = dir32[0]; v2.Pos.Y = dir32[1]; v2.Pos.Z = dir32[2]; - if (v[3]){ + if(v[3]) { v3.Pos.X = dir42[0]; v3.Pos.Y = dir42[1]; v3.Pos.Z = dir42[2]; @@ -268,7 +285,7 @@ void End_Curve (Curve * c){ prodve(dir12, dir32, n); norme(n); // use provided plane if unable to compute it from input points... - if (fabs (n[0]) < 1.e-5 && fabs (n[1]) < 1.e-5 && fabs (n[2]) < 1.e-5){ + if(fabs(n[0]) < 1.e-5 && fabs(n[1]) < 1.e-5 && fabs(n[2]) < 1.e-5) { n[0] = Curve->Circle.n[0]; n[1] = Curve->Circle.n[1]; n[2] = Curve->Circle.n[2]; @@ -276,7 +293,7 @@ void End_Curve (Curve * c){ } prodve(n, dir12, m); norme(m); - + mat[2][0] = Curve->Circle.invmat[0][2] = n[0]; mat[2][1] = Curve->Circle.invmat[1][2] = n[1]; mat[2][2] = Curve->Circle.invmat[2][2] = n[2]; @@ -288,8 +305,8 @@ void End_Curve (Curve * c){ mat[0][2] = Curve->Circle.invmat[2][0] = dir12[2]; // assume circle in z=0 plane - if(CTX.geom.old_circle){ - if(n[0] == 0.0 && n[1] == 0.0){ + if(CTX.geom.old_circle) { + if(n[0] == 0.0 && n[1] == 0.0) { mat[2][0] = Curve->Circle.invmat[0][2] = 0; mat[2][1] = Curve->Circle.invmat[1][2] = 0; mat[2][2] = Curve->Circle.invmat[2][2] = 1; @@ -304,83 +321,87 @@ void End_Curve (Curve * c){ Projette(&v0, mat); Projette(&v2, mat); - if(v[3]) Projette(&v3, mat); + if(v[3]) + Projette(&v3, mat); - R = sqrt(v0.Pos.X * v0.Pos.X + v0.Pos.Y * v0.Pos.Y); + R = sqrt(v0.Pos.X * v0.Pos.X + v0.Pos.Y * v0.Pos.Y); R2 = sqrt(v2.Pos.X * v2.Pos.X + v2.Pos.Y * v2.Pos.Y); - if(!R || !R2) // check radius + if(!R || !R2) // check radius Msg(GERROR, "Zero radius in Circle/Ellipse %d", c->Num); - else if(!v[3] && fabs((R-R2)/(R+R2))>0.1) // check cocircular pts (allow 10% error) - Msg(GERROR, "Control points of Circle %d are not cocircular %g %g", c->Num, R,R2); + else if(!v[3] && fabs((R - R2) / (R + R2)) > 0.1) // check cocircular pts (allow 10% error) + Msg(GERROR, "Control points of Circle %d are not cocircular %g %g", + c->Num, R, R2); // A1 = angle first pt // A3 = angle last pt // A4 = angle major axis - if (v[3]){ + if(v[3]) { A4 = myatan2(v3.Pos.Y, v3.Pos.X); A4 = angle_02pi(A4); - double x1 = v0.Pos.X * cos (A4) + v0.Pos.Y * sin(A4); - double y1 = -v0.Pos.X * sin (A4) + v0.Pos.Y * cos(A4); - double x3 = v2.Pos.X * cos (A4) + v2.Pos.Y * sin(A4); - double y3 = -v2.Pos.X * sin (A4) + v2.Pos.Y * cos(A4); + double x1 = v0.Pos.X * cos(A4) + v0.Pos.Y * sin(A4); + double y1 = -v0.Pos.X * sin(A4) + v0.Pos.Y * cos(A4); + double x3 = v2.Pos.X * cos(A4) + v2.Pos.Y * sin(A4); + double y3 = -v2.Pos.X * sin(A4) + v2.Pos.Y * cos(A4); sys[0][0] = x1 * x1; sys[0][1] = y1 * y1; sys[1][0] = x3 * x3; sys[1][1] = y3 * y3; rhs[0] = 1; rhs[1] = 1; - sys2x2 (sys, rhs, sol); - if(sol[0] <= 0 || sol[1] <= 0){ - Msg(GERROR, "Ellipse %d is wrong", Curve->Num); - A1 = A3 = 0.; - f1 = f2 = R ; + sys2x2(sys, rhs, sol); + if(sol[0] <= 0 || sol[1] <= 0) { + Msg(GERROR, "Ellipse %d is wrong", Curve->Num); + A1 = A3 = 0.; + f1 = f2 = R; } - else{ - f1 = sqrt(1./sol[0]); - f2 = sqrt(1./sol[1]); - // myasin() permet de contourner les problemes de precision - // sur y1/f2 ou y3/f2, qui peuvent legerement etre hors de - // [-1,1] - if(x1 < 0) - A1 = -myasin(y1/f2) + A4 + Pi; - else - A1 = myasin(y1/f2) + A4; - if(x3 < 0) - A3 = -myasin(y3/f2) + A4 + Pi; - else - A3 = myasin(y3/f2) + A4; + else { + f1 = sqrt(1. / sol[0]); + f2 = sqrt(1. / sol[1]); + // myasin() permet de contourner les problemes de precision + // sur y1/f2 ou y3/f2, qui peuvent legerement etre hors de + // [-1,1] + if(x1 < 0) + A1 = -myasin(y1 / f2) + A4 + Pi; + else + A1 = myasin(y1 / f2) + A4; + if(x3 < 0) + A3 = -myasin(y3 / f2) + A4 + Pi; + else + A3 = myasin(y3 / f2) + A4; } } - else{ + else { A1 = myatan2(v0.Pos.Y, v0.Pos.X); A3 = myatan2(v2.Pos.Y, v2.Pos.X); A4 = 0.; f1 = f2 = R; } - A1 = angle_02pi(A1); + A1 = angle_02pi(A1); A3 = angle_02pi(A3); - if(A1 >= A3) A3 += 2*Pi; + if(A1 >= A3) + A3 += 2 * Pi; //printf("f1=%g f2=%g a1=%g a3=%g a4=%g\n", - // f1, f2, A1*180./M_PI, A3*180./Pi, A4*180./Pi); + // f1, f2, A1*180./M_PI, A3*180./Pi, A4*180./Pi); Curve->Circle.t1 = A1; Curve->Circle.t2 = A3; Curve->Circle.incl = A4; Curve->Circle.f1 = f1; Curve->Circle.f2 = f2; - - for (i = 0; i < 4; i++) + + for(i = 0; i < 4; i++) Curve->Circle.v[i] = v[i]; } - if (c->cp) Free (c->cp); - c->cp = (float *) Malloc (4 * List_Nbr (c->Control_Points) * sizeof (float)); - for (i = 0; i < List_Nbr (c->Control_Points); i++){ - List_Read (c->Control_Points, i, &v[0]); + if(c->cp) + Free(c->cp); + c->cp = (float *)Malloc(4 * List_Nbr(c->Control_Points) * sizeof(float)); + for(i = 0; i < List_Nbr(c->Control_Points); i++) { + List_Read(c->Control_Points, i, &v[0]); c->cp[4 * i] = v[0]->Pos.X; c->cp[4 * i + 1] = v[0]->Pos.Y; c->cp[4 * i + 2] = v[0]->Pos.Z; @@ -389,16 +410,17 @@ void End_Curve (Curve * c){ } -void End_Surface (Surface * s){ +void End_Surface(Surface * s) +{ int i; Vertex *v; - if (!s->Control_Points || !List_Nbr(s->Control_Points)) + if(!s->Control_Points || !List_Nbr(s->Control_Points)) return; - s->cp = (float *) Malloc (4 * List_Nbr (s->Control_Points) * sizeof (float)); - for (i = 0; i < List_Nbr (s->Control_Points); i++){ - List_Read (s->Control_Points, i, &v); + s->cp = (float *)Malloc(4 * List_Nbr(s->Control_Points) * sizeof(float)); + for(i = 0; i < List_Nbr(s->Control_Points); i++) { + List_Read(s->Control_Points, i, &v); s->cp[4 * i] = v->Pos.X; s->cp[4 * i + 1] = v->Pos.Y; s->cp[4 * i + 2] = v->Pos.Z; @@ -409,87 +431,91 @@ void End_Surface (Surface * s){ -Curve *Create_Curve (int Num, int Typ, int Order, List_T * Liste, - List_T * Knots, int p1, int p2, double u1, double u2){ +Curve *Create_Curve(int Num, int Typ, int Order, List_T * Liste, + List_T * Knots, int p1, int p2, double u1, double u2) +{ Curve *pC; Vertex *v; int i, j, iPnt; double d; double matcr[4][4] = { {-0.5, 1.5, -1.5, 0.5}, - {1.0, -2.5, 2.0, -0.5}, - {-0.5, 0.0, 0.5, 0.0}, - {0.0, 1.0, 0.0, 0.0} }; + {1.0, -2.5, 2.0, -0.5}, + {-0.5, 0.0, 0.5, 0.0}, + {0.0, 1.0, 0.0, 0.0} + }; double matbs[4][4] = { {-1.0, 3, -3, 1}, - {3, -6, 3.0, 0}, - {-3, 0.0, 3, 0.0}, - {1, 4, 1, 0.0} }; + {3, -6, 3.0, 0}, + {-3, 0.0, 3, 0.0}, + {1, 4, 1, 0.0} + }; double matbez[4][4] = { {-1.0, 3, -3, 1}, - {3, -6, 3.0, 0}, - {-3, 3.0, 0, 0.0}, - {1, 0, 0, 0.0} }; + {3, -6, 3.0, 0}, + {-3, 3.0, 0, 0.0}, + {1, 0, 0, 0.0} + }; - pC = (Curve *) Malloc (sizeof (Curve)); + pC = (Curve *) Malloc(sizeof(Curve)); pC->Dirty = 0; pC->Color.type = 0; - pC->Visible = VIS_GEOM|VIS_MESH; + pC->Visible = VIS_GEOM | VIS_MESH; pC->cp = NULL; pC->Vertices = NULL; pC->Extrude = NULL; pC->Typ = Typ; pC->Num = Num; - THEM->MaxLineNum = IMAX(THEM->MaxLineNum,Num); - pC->Simplexes = Tree_Create (sizeof (Simplex *), compareSimplex); - pC->TrsfSimplexes = List_Create (1, 10, sizeof (Simplex *)); + THEM->MaxLineNum = IMAX(THEM->MaxLineNum, Num); + pC->Simplexes = Tree_Create(sizeof(Simplex *), compareSimplex); + pC->TrsfSimplexes = List_Create(1, 10, sizeof(Simplex *)); pC->Method = LIBRE; pC->degre = Order; pC->Circle.n[0] = 0.0; pC->Circle.n[1] = 0.0; pC->Circle.n[2] = 1.0; - for(i=0;i<4;i++){ + for(i = 0; i < 4; i++) { pC->ipar[i] = 0; pC->dpar[i] = 0.0; } - if (Typ == MSH_SEGM_SPLN){ - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) + if(Typ == MSH_SEGM_SPLN) { + for(i = 0; i < 4; i++) + for(j = 0; j < 4; j++) pC->mat[i][j] = matcr[i][j]; } - else if (Typ == MSH_SEGM_BSPLN){ - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) + else if(Typ == MSH_SEGM_BSPLN) { + for(i = 0; i < 4; i++) + for(j = 0; j < 4; j++) pC->mat[i][j] = matbs[i][j] / 6.0; } - else if (Typ == MSH_SEGM_BEZIER){ - for (i = 0; i < 4; i++) - for (j = 0; j < 4; j++) + else if(Typ == MSH_SEGM_BEZIER) { + for(i = 0; i < 4; i++) + for(j = 0; j < 4; j++) pC->mat[i][j] = matbez[i][j]; } pC->ubeg = u1; pC->uend = u2; - if (Knots){ - pC->k = (float *) malloc (List_Nbr (Knots) * sizeof (float)); + if(Knots) { + pC->k = (float *)malloc(List_Nbr(Knots) * sizeof(float)); double kmin = .0, kmax = 1.; - List_Read (Knots, 0, &kmin); - List_Read (Knots, List_Nbr (Knots) - 1, &kmax); + List_Read(Knots, 0, &kmin); + List_Read(Knots, List_Nbr(Knots) - 1, &kmax); pC->ubeg = kmin; pC->uend = kmax; - for (i = 0; i < List_Nbr (Knots); i++){ - List_Read (Knots, i, &d); - pC->k[i] = (float) d; + for(i = 0; i < List_Nbr(Knots); i++) { + List_Read(Knots, i, &d); + pC->k[i] = (float)d; } } else pC->k = NULL; - if (Liste){ - pC->Control_Points = List_Create (List_Nbr (Liste), 1, sizeof (Vertex *)); - for (j = 0; j < List_Nbr (Liste); j++){ - List_Read (Liste, j, &iPnt); - if ((v = FindPoint (iPnt, THEM))) - List_Add (pC->Control_Points, &v); + if(Liste) { + pC->Control_Points = List_Create(List_Nbr(Liste), 1, sizeof(Vertex *)); + for(j = 0; j < List_Nbr(Liste); j++) { + List_Read(Liste, j, &iPnt); + if((v = FindPoint(iPnt, THEM))) + List_Add(pC->Control_Points, &v); else Msg(FATAL, "Unknown control point %d in Curve %d", iPnt, pC->Num); } @@ -499,37 +525,39 @@ Curve *Create_Curve (int Num, int Typ, int Order, List_T * Liste, return pC; } - if (p1 < 0){ - List_Read (pC->Control_Points, 0, &pC->beg); - List_Read (pC->Control_Points, List_Nbr (pC->Control_Points) - 1, &pC->end); + if(p1 < 0) { + List_Read(pC->Control_Points, 0, &pC->beg); + List_Read(pC->Control_Points, List_Nbr(pC->Control_Points) - 1, &pC->end); } else { - if ((v = FindPoint (p1, THEM))){ + if((v = FindPoint(p1, THEM))) { pC->beg = v; Msg(INFO, "Curve %d first control point %d ", pC->Num, v->Num); } - else{ - List_Read (pC->Control_Points, 0, &pC->beg); + else { + List_Read(pC->Control_Points, 0, &pC->beg); Msg(GERROR, "Unknown control point %d in Curve %d", p1, pC->Num); } - if ((v = FindPoint (p2, THEM))){ + if((v = FindPoint(p2, THEM))) { pC->end = v; Msg(INFO, "Curve %d first control point %d ", pC->Num, v->Num); } - else{ - List_Read (pC->Control_Points, List_Nbr (pC->Control_Points) - 1, &pC->end); + else { + List_Read(pC->Control_Points, List_Nbr(pC->Control_Points) - 1, + &pC->end); Msg(GERROR, "Unknown control point %d in Curve %d", p2, pC->Num); } } - End_Curve (pC); + End_Curve(pC); return pC; } -void Free_Curve(void *a, void *b){ - Curve *pC = *(Curve**)a; - if(pC){ +void Free_Curve(void *a, void *b) +{ + Curve *pC = *(Curve **) a; + if(pC) { List_Delete(pC->Vertices); Tree_Action(pC->Simplexes, Free_Simplex); Tree_Delete(pC->Simplexes); @@ -542,29 +570,31 @@ void Free_Curve(void *a, void *b){ } } -Surface * Create_Surface (int Num, int Typ){ +Surface *Create_Surface(int Num, int Typ) +{ Surface *pS; int i; - pS = (Surface *) Malloc (sizeof (Surface)); + pS = (Surface *) Malloc(sizeof(Surface)); pS->Dirty = 0; pS->Color.type = 0; - pS->Visible = VIS_GEOM|VIS_MESH; + pS->Visible = VIS_GEOM | VIS_MESH; pS->Num = Num; - THEM->MaxSurfaceNum = IMAX(THEM->MaxSurfaceNum,Num); + THEM->MaxSurfaceNum = IMAX(THEM->MaxSurfaceNum, Num); pS->Typ = Typ; pS->Method = LIBRE; - for(i=0;i<5;i++) pS->ipar[i] = 0; + for(i = 0; i < 5; i++) + pS->ipar[i] = 0; pS->Recombine = 0; pS->RecombineAngle = 30; - pS->Simplexes = Tree_Create (sizeof (Simplex *), compareQuality); - pS->TrsfSimplexes = List_Create (1, 10, sizeof (Simplex *)); - pS->Vertices = Tree_Create (sizeof (Vertex *), compareVertex); - pS->TrsfVertices = List_Create (1, 10, sizeof (Vertex *)); - pS->Contours = List_Create (1, 1, sizeof (List_T *)); + pS->Simplexes = Tree_Create(sizeof(Simplex *), compareQuality); + pS->TrsfSimplexes = List_Create(1, 10, sizeof(Simplex *)); + pS->Vertices = Tree_Create(sizeof(Vertex *), compareVertex); + pS->TrsfVertices = List_Create(1, 10, sizeof(Vertex *)); + pS->Contours = List_Create(1, 1, sizeof(List_T *)); pS->Orientations = NULL; pS->Support = pS; - pS->Control_Points = List_Create (1, 10, sizeof (Vertex *)); + pS->Control_Points = List_Create(1, 10, sizeof(Vertex *)); pS->Generatrices = NULL; pS->Edges = NULL; pS->Extrude = NULL; @@ -572,9 +602,10 @@ Surface * Create_Surface (int Num, int Typ){ return (pS); } -void Free_Surface(void *a, void *b){ - Surface *pS = *(Surface**)a; - if(pS){ +void Free_Surface(void *a, void *b) +{ + Surface *pS = *(Surface **) a; + if(pS) { Tree_Action(pS->Simplexes, Free_Simplex); Tree_Delete(pS->Simplexes); List_Delete(pS->TrsfSimplexes); @@ -583,8 +614,8 @@ void Free_Surface(void *a, void *b){ List_Delete(pS->Contours); List_Delete(pS->Control_Points); List_Delete(pS->Generatrices); - if(pS->Edges){ - Tree_Action(pS->Edges,Free_Edge); + if(pS->Edges) { + Tree_Action(pS->Edges, Free_Edge); Tree_Delete(pS->Edges); } Free(pS); @@ -592,60 +623,64 @@ void Free_Surface(void *a, void *b){ } } -Volume * Create_Volume (int Num, int Typ){ +Volume *Create_Volume(int Num, int Typ) +{ Volume *pV; int i; - pV = (Volume *) Malloc (sizeof (Volume)); + pV = (Volume *) Malloc(sizeof(Volume)); pV->Dirty = 0; pV->Color.type = 0; - pV->Visible = VIS_GEOM|VIS_MESH; + pV->Visible = VIS_GEOM | VIS_MESH; pV->Num = Num; - THEM->MaxVolumeNum = IMAX(THEM->MaxVolumeNum,Num); + THEM->MaxVolumeNum = IMAX(THEM->MaxVolumeNum, Num); pV->Typ = Typ; pV->Method = LIBRE; - for(i=0;i<8;i++) pV->ipar[i] = 0; - pV->Surfaces = List_Create (1, 2, sizeof (Surface *)); - pV->Simplexes = Tree_Create (sizeof (Simplex *), compareQuality); - pV->Vertices = Tree_Create (sizeof (Vertex *), compareVertex); - pV->Hexahedra = Tree_Create (sizeof (Hexahedron *), compareHexahedron); - pV->Prisms = Tree_Create (sizeof (Prism *), comparePrism); - pV->Pyramids = Tree_Create (sizeof (Pyramid *), comparePyramid); - pV->Simp_Surf = Tree_Create(sizeof(Simplex*),compareSimplex);// for old extrusion mesh generator + for(i = 0; i < 8; i++) + pV->ipar[i] = 0; + pV->Surfaces = List_Create(1, 2, sizeof(Surface *)); + pV->Simplexes = Tree_Create(sizeof(Simplex *), compareQuality); + pV->Vertices = Tree_Create(sizeof(Vertex *), compareVertex); + pV->Hexahedra = Tree_Create(sizeof(Hexahedron *), compareHexahedron); + pV->Prisms = Tree_Create(sizeof(Prism *), comparePrism); + pV->Pyramids = Tree_Create(sizeof(Pyramid *), comparePyramid); + pV->Simp_Surf = Tree_Create(sizeof(Simplex *), compareSimplex); // for old extrusion mesh generator pV->Extrude = NULL; pV->Edges = NULL; pV->Faces = NULL; return pV; } -void Free_Volume(void *a, void *b){ - - Volume *pV = *(Volume**)a; - if(pV){ - List_Delete(pV->Surfaces); //surfaces freed elsewhere +void Free_Volume(void *a, void *b) +{ + Volume *pV = *(Volume **) a; + if(pV) { + List_Delete(pV->Surfaces); //surfaces freed elsewhere Tree_Action(pV->Simplexes, Free_Simplex); Tree_Delete(pV->Simplexes); Tree_Delete(pV->Simp_Surf); // for old extrusion mesh generator - Tree_Delete(pV->Vertices); //vertices freed elsewhere + Tree_Delete(pV->Vertices); //vertices freed elsewhere Tree_Action(pV->Hexahedra, Free_Hexahedron); Tree_Delete(pV->Hexahedra); Tree_Action(pV->Prisms, Free_Prism); Tree_Delete(pV->Prisms); Tree_Action(pV->Pyramids, Free_Pyramid); Tree_Delete(pV->Pyramids); - Tree_Action(pV->Edges,Free_Edge); + Tree_Action(pV->Edges, Free_Edge); Tree_Delete(pV->Edges); Tree_Delete(pV->Faces); Free(pV); pV = NULL; - } + } } -Hexahedron * Create_Hexahedron (Vertex * v1, Vertex * v2, Vertex * v3, Vertex * v4, - Vertex * v5, Vertex * v6, Vertex * v7, Vertex * v8){ +Hexahedron *Create_Hexahedron(Vertex * v1, Vertex * v2, Vertex * v3, + Vertex * v4, Vertex * v5, Vertex * v6, + Vertex * v7, Vertex * v8) +{ Hexahedron *h; - h = (Hexahedron *) Malloc (sizeof (Hexahedron)); + h = (Hexahedron *) Malloc(sizeof(Hexahedron)); h->iEnt = -1; h->Num = ++THEM->MaxSimplexNum; h->Visible = VIS_MESH; @@ -662,19 +697,21 @@ Hexahedron * Create_Hexahedron (Vertex * v1, Vertex * v2, Vertex * v3, Vertex * return (h); } -void Free_Hexahedron(void *a, void *b){ - Hexahedron *pH = *(Hexahedron**)a; - if(pH){ +void Free_Hexahedron(void *a, void *b) +{ + Hexahedron *pH = *(Hexahedron **) a; + if(pH) { Free(pH); pH = NULL; } } -Prism * Create_Prism (Vertex * v1, Vertex * v2, Vertex * v3, - Vertex * v4, Vertex * v5, Vertex * v6){ +Prism *Create_Prism(Vertex * v1, Vertex * v2, Vertex * v3, + Vertex * v4, Vertex * v5, Vertex * v6) +{ Prism *p; - p = (Prism *) Malloc (sizeof (Prism)); + p = (Prism *) Malloc(sizeof(Prism)); p->iEnt = -1; p->Num = ++THEM->MaxSimplexNum; p->Visible = VIS_MESH; @@ -689,19 +726,21 @@ Prism * Create_Prism (Vertex * v1, Vertex * v2, Vertex * v3, return (p); } -void Free_Prism(void *a, void *b){ - Prism *pP = *(Prism**)a; - if(pP){ +void Free_Prism(void *a, void *b) +{ + Prism *pP = *(Prism **) a; + if(pP) { Free(pP); pP = NULL; } } -Pyramid * Create_Pyramid (Vertex * v1, Vertex * v2, Vertex * v3, - Vertex * v4, Vertex * v5){ +Pyramid *Create_Pyramid(Vertex * v1, Vertex * v2, Vertex * v3, + Vertex * v4, Vertex * v5) +{ Pyramid *p; - p = (Pyramid *) Malloc (sizeof (Pyramid)); + p = (Pyramid *) Malloc(sizeof(Pyramid)); p->iEnt = -1; p->Num = ++THEM->MaxSimplexNum; p->Visible = VIS_MESH; @@ -715,9 +754,10 @@ Pyramid * Create_Pyramid (Vertex * v1, Vertex * v2, Vertex * v3, return (p); } -void Free_Pyramid(void *a, void *b){ - Pyramid *p = *(Pyramid**)a; - if(p){ +void Free_Pyramid(void *a, void *b) +{ + Pyramid *p = *(Pyramid **) a; + if(p) { Free(p); p = NULL; } diff --git a/Mesh/CrossData.cpp b/Mesh/CrossData.cpp index 699bdb6ea83bf24c079914ff5d7c979c96587002..a8f5f8010084a46c800685aae33a1e27e54d992a 100644 --- a/Mesh/CrossData.cpp +++ b/Mesh/CrossData.cpp @@ -1,4 +1,4 @@ -// $Id: CrossData.cpp,v 1.9 2003-01-23 20:19:22 geuzaine Exp $ +// $Id: CrossData.cpp,v 1.10 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -35,41 +35,44 @@ NXE::~NXE() // if(Liste)List_Delete(Liste); } -void Delete_NXE (void *data, void *dummy) +void Delete_NXE(void *data, void *dummy) { - NXE *pnxe = (NXE*)data; - if(pnxe->Liste)List_Delete(pnxe->Liste); + NXE *pnxe = (NXE *) data; + if(pnxe->Liste) + List_Delete(pnxe->Liste); } -void AddTable (void *data, void *dummy){ +void AddTable(void *data, void *dummy) +{ Simplex *s; NXE nxe, *pnxe; int i; s = *(Simplex **) data; - for (i = 0; i < 4; i++){ - if (s->V[i]){ + for(i = 0; i < 4; i++) { + if(s->V[i]) { nxe.v = s->V[i]; - if ((pnxe = (NXE *) Tree_PQuery (TreeTemp, &nxe))){ - List_Add (pnxe->Liste, &s); + if((pnxe = (NXE *) Tree_PQuery(TreeTemp, &nxe))) { + List_Add(pnxe->Liste, &s); } - else{ - nxe.Liste = List_Create (1, 1, sizeof (Simplex *)); - List_Add (nxe.Liste, &s); - Tree_Add (TreeTemp, &nxe); + else { + nxe.Liste = List_Create(1, 1, sizeof(Simplex *)); + List_Add(nxe.Liste, &s); + Tree_Add(TreeTemp, &nxe); } } } } -void create_NXE (Tree_T * TreeAllNod, Tree_T * TreeAllElg, - Tree_T * TreeAllNXE){ +void create_NXE(Tree_T * TreeAllNod, Tree_T * TreeAllElg, Tree_T * TreeAllNXE) +{ TreeTemp = TreeAllNXE; - Tree_Action (TreeAllElg, AddTable); + Tree_Action(TreeAllElg, AddTable); } -void delete_NXE (Tree_T * TreeAllNXE){ - Tree_Action (TreeAllNXE, Delete_NXE); - Tree_Delete (TreeAllNXE); +void delete_NXE(Tree_T * TreeAllNXE) +{ + Tree_Action(TreeAllNXE, Delete_NXE); + Tree_Delete(TreeAllNXE); } diff --git a/Mesh/Edge.cpp b/Mesh/Edge.cpp index d9ac7a50b6a37fae8fdd42b7528080b5c042e30c..fe2558a322a22ad350b2e571f15b889b69c887df 100644 --- a/Mesh/Edge.cpp +++ b/Mesh/Edge.cpp @@ -1,4 +1,4 @@ -// $Id: Edge.cpp,v 1.10 2003-01-23 20:19:22 geuzaine Exp $ +// $Id: Edge.cpp,v 1.11 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -25,148 +25,165 @@ #include "Edge.h" #include "Tools.h" -static int edges_quad[4][2] = { {0, 1}, - {1, 2}, - {2, 3}, - {3, 0} }; -static int edges_tetra[6][2] = { {0, 1}, - {1, 2}, - {2, 0}, - {3, 0}, - {3, 2}, - {3, 1} }; -static int edges_non[3] = {2, 0, 1}; - -int compareedge (const void *a, const void *b){ +static int edges_quad[4][2] = { + {0, 1}, + {1, 2}, + {2, 3}, + {3, 0} +}; +static int edges_tetra[6][2] = { + {0, 1}, + {1, 2}, + {2, 0}, + {3, 0}, + {3, 2}, + {3, 1} +}; +static int edges_non[3] = { 2, 0, 1 }; + +int compareedge(const void *a, const void *b) +{ int i1, i2, j1, j2; Edge *q, *w; q = (Edge *) a; w = (Edge *) b; - i1 = IMAX (q->V[0]->Num, q->V[1]->Num); - i2 = IMAX (w->V[0]->Num, w->V[1]->Num); - j1 = IMIN (q->V[0]->Num, q->V[1]->Num); - j2 = IMIN (w->V[0]->Num, w->V[1]->Num); + i1 = IMAX(q->V[0]->Num, q->V[1]->Num); + i2 = IMAX(w->V[0]->Num, w->V[1]->Num); + j1 = IMIN(q->V[0]->Num, q->V[1]->Num); + j2 = IMIN(w->V[0]->Num, w->V[1]->Num); - if (i1 < i2) + if(i1 < i2) return (1); - if (i1 > i2) + if(i1 > i2) return (-1); - if (j1 < j2) + if(j1 < j2) return (1); - if (j1 > j2) + if(j1 > j2) return (-1); return 0; } -int compareedge_angle (const void *a, const void *b){ +int compareedge_angle(const void *a, const void *b) +{ Edge *q, *w; q = (Edge *) a; w = (Edge *) b; - if (q->a >= w->a) + if(q->a >= w->a) return (1); return (-1); } -void EdgesContainer::AddEdges (Simplex * s, bool EdgesInVolume){ +void EdgesContainer::AddEdges(Simplex * s, bool EdgesInVolume) +{ int N, i, j; Edge E, *pE; int edges[6][2]; - if (s->V[3] && EdgesInVolume){ + if(s->V[3] && EdgesInVolume) { N = 6; - for (i = 0; i < N; i++) - for (j = 0; j < 2; j++) + for(i = 0; i < N; i++) + for(j = 0; j < 2; j++) edges[i][j] = edges_tetra[i][j]; } - else if (s->V[3]){ + else if(s->V[3]) { N = 4; - for (i = 0; i < N; i++) - for (j = 0; j < 2; j++) + for(i = 0; i < N; i++) + for(j = 0; j < 2; j++) edges[i][j] = edges_quad[i][j]; } - else if (s->V[2]){ + else if(s->V[2]) { N = 3; - for (i = 0; i < N; i++) - for (j = 0; j < 2; j++) + for(i = 0; i < N; i++) + for(j = 0; j < 2; j++) edges[i][j] = edges_tetra[i][j]; } - else{ + else { N = 1; - for (i = 0; i < N; i++) - for (j = 0; j < 2; j++) + for(i = 0; i < N; i++) + for(j = 0; j < 2; j++) edges[i][j] = edges_tetra[i][j]; } - for (i = 0; i < N; i++){ + for(i = 0; i < N; i++) { E.V[0] = s->V[edges[i][0]]; E.V[1] = s->V[edges[i][1]]; - if ((pE = (Edge *) Tree_PQuery (AllEdges, &E))){ - List_Add (pE->Simplexes, &s); - if (N == 3) + if((pE = (Edge *) Tree_PQuery(AllEdges, &E))) { + List_Add(pE->Simplexes, &s); + if(N == 3) pE->O[1] = s->V[edges_non[i]]; } - else{ - E.Simplexes = List_Create (2, 1, sizeof (Simplex *)); - if (N == 3) + else { + E.Simplexes = List_Create(2, 1, sizeof(Simplex *)); + if(N == 3) E.O[0] = s->V[edges_non[i]]; - if (N == 3) + if(N == 3) E.O[1] = NULL; - List_Add (E.Simplexes, &s); + List_Add(E.Simplexes, &s); E.newv = NULL; - Tree_Replace (AllEdges, &E); + Tree_Replace(AllEdges, &E); } } } -EdgesContainer::EdgesContainer (Tree_T * Simplexes, bool EdgesInVolume){ - AllEdges = Tree_Create (sizeof (Edge), compareedge); - AddTree (Simplexes, EdgesInVolume); +EdgesContainer::EdgesContainer(Tree_T * Simplexes, bool EdgesInVolume) +{ + AllEdges = Tree_Create(sizeof(Edge), compareedge); + AddTree(Simplexes, EdgesInVolume); } -EdgesContainer::EdgesContainer (List_T * Surfaces){ - AllEdges = Tree_Create (sizeof (Edge), compareedge); +EdgesContainer::EdgesContainer(List_T * Surfaces) +{ + AllEdges = Tree_Create(sizeof(Edge), compareedge); Surface *s; - for (int i = 0; i < List_Nbr (Surfaces); i++){ - List_Read (Surfaces, i, &s); - AddTree (s->Simplexes, false); - } + for(int i = 0; i < List_Nbr(Surfaces); i++) { + List_Read(Surfaces, i, &s); + AddTree(s->Simplexes, false); + } } -void EdgesContainer::AddTree (Tree_T * Simplexes, bool EdgesInVolume){ +void EdgesContainer::AddTree(Tree_T * Simplexes, bool EdgesInVolume) +{ Simplex *s; - List_T *temp = Tree2List (Simplexes); - for (int i = 0; i < List_Nbr (temp); i++){ - List_Read (temp, i, &s); - AddEdges (s, EdgesInVolume); + List_T *temp = Tree2List(Simplexes); + for(int i = 0; i < List_Nbr(temp); i++) { + List_Read(temp, i, &s); + AddEdges(s, EdgesInVolume); } - List_Delete (temp); + List_Delete(temp); } -void Free_Edge (void *a, void *b) +void Free_Edge(void *a, void *b) { - Edge *e = (Edge*)a; - if(e->Liste)List_Delete(e->Liste); - if(e->Simplexes)List_Delete(e->Simplexes); - if(e->Points)List_Delete(e->Points); + Edge *e = (Edge *) a; + if(e->Liste) + List_Delete(e->Liste); + if(e->Simplexes) + List_Delete(e->Simplexes); + if(e->Points) + List_Delete(e->Points); } -EdgesContainer::~EdgesContainer (){ - Tree_Action (AllEdges,Free_Edge); - Tree_Delete (AllEdges); +EdgesContainer::~EdgesContainer() +{ + Tree_Action(AllEdges, Free_Edge); + Tree_Delete(AllEdges); } -bool EdgesContainer::Search (Vertex * v1, Vertex * v2){ + +bool EdgesContainer::Search(Vertex * v1, Vertex * v2) +{ Edge E; E.V[0] = v1; E.V[1] = v2; - if (!Tree_Search (AllEdges, &E)) + if(!Tree_Search(AllEdges, &E)) return false; return true; } -void EdgesContainer::SwapEdge (Vertex * V[2]){ +void EdgesContainer::SwapEdge(Vertex * V[2]) +{ Edge *e, E; Simplex *s, *s1, *s2; int i, j; @@ -174,39 +191,39 @@ void EdgesContainer::SwapEdge (Vertex * V[2]){ E.V[0] = V[0]; E.V[1] = V[1]; - e = (Edge *) Tree_PQuery (AllEdges, &E); + e = (Edge *) Tree_PQuery(AllEdges, &E); E = *e; - if (!e) + if(!e) return; - List_Read (e->Simplexes, 0, &s1); - List_Read (e->Simplexes, 1, &s2); + List_Read(e->Simplexes, 0, &s1); + List_Read(e->Simplexes, 1, &s2); - for (i = 0; i < 3; i++){ - if (s1->S[i] == s2){ - s1->ExtractOppositeEdges (i, p, q); - if (!s1->SwapEdge (i)) + for(i = 0; i < 3; i++) { + if(s1->S[i] == s2) { + s1->ExtractOppositeEdges(i, p, q); + if(!s1->SwapEdge(i)) return; - Tree_Suppress (AllEdges, &E); + Tree_Suppress(AllEdges, &E); E.V[0] = q[0]; E.V[1] = q[1]; - Tree_Add (AllEdges, &E); - + Tree_Add(AllEdges, &E); + E.V[0] = q[0]; E.V[1] = p[0]; - e = (Edge *) Tree_PQuery (AllEdges, &E); - for (j = 0; j < 2; j++){ - List_Read (e->Simplexes, j, &s); - if (s == s2) - List_Write (e->Simplexes, j, &s1); + e = (Edge *) Tree_PQuery(AllEdges, &E); + for(j = 0; j < 2; j++) { + List_Read(e->Simplexes, j, &s); + if(s == s2) + List_Write(e->Simplexes, j, &s1); } - + E.V[0] = q[1]; E.V[1] = p[1]; - e = (Edge *) Tree_PQuery (AllEdges, &E); - for (j = 0; j < 2; j++){ - List_Read (e->Simplexes, j, &s); - if (s == s1) - List_Write (e->Simplexes, j, &s2); + e = (Edge *) Tree_PQuery(AllEdges, &E); + for(j = 0; j < 2; j++) { + List_Read(e->Simplexes, j, &s); + if(s == s1) + List_Write(e->Simplexes, j, &s2); } V[0] = q[0]; V[1] = q[1]; diff --git a/Mesh/Generator.cpp b/Mesh/Generator.cpp index 087ac1b6515c345a795c5db99a7cc922c3dafad3..0e1fbdaa348ba0b68296c5b50ca7262d646d120e 100644 --- a/Mesh/Generator.cpp +++ b/Mesh/Generator.cpp @@ -1,4 +1,4 @@ -// $Id: Generator.cpp,v 1.38 2003-01-23 20:19:22 geuzaine Exp $ +// $Id: Generator.cpp,v 1.39 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -26,128 +26,142 @@ #include "Context.h" #include "OpenFile.h" -extern Mesh *THEM; +extern Mesh *THEM; extern Context_T CTX; -void GetStatistics (double s[50]){ +void GetStatistics(double s[50]) +{ int i; - if(!THEM){ - for (i = 0; i < 50; i++) s[i] = 0.; + if(!THEM) { + for(i = 0; i < 50; i++) + s[i] = 0.; } - else{ - THEM->Statistics[0] = Tree_Nbr (THEM->Points); - THEM->Statistics[1] = Tree_Nbr (THEM->Curves); - THEM->Statistics[2] = Tree_Nbr (THEM->Surfaces); - THEM->Statistics[3] = Tree_Nbr (THEM->Volumes); + else { + THEM->Statistics[0] = Tree_Nbr(THEM->Points); + THEM->Statistics[1] = Tree_Nbr(THEM->Curves); + THEM->Statistics[2] = Tree_Nbr(THEM->Surfaces); + THEM->Statistics[3] = Tree_Nbr(THEM->Volumes); Mesh_Quality(THEM); - for (i = 0; i < 50; i++) s[i] = THEM->Statistics[i]; + for(i = 0; i < 50; i++) + s[i] = THEM->Statistics[i]; } } -void ApplyLcFactor_Point(void *a, void *b){ - Vertex *v = *(Vertex**)a; - if(v->lc <= 0.0){ - Msg(GERROR, "Wrong characteristic length (%g <= 0) for Point %d, defaulting to 1.0", +void ApplyLcFactor_Point(void *a, void *b) +{ + Vertex *v = *(Vertex **) a; + if(v->lc <= 0.0) { + Msg(GERROR, + "Wrong characteristic length (%g <= 0) for Point %d, defaulting to 1.0", v->lc, v->Num); - v->lc = 1.0 ; + v->lc = 1.0; } v->lc *= CTX.mesh.lc_factor; } -void ApplyLcFactor_Attractor(void *a, void *b){ - Attractor *v = *(Attractor**)a; +void ApplyLcFactor_Attractor(void *a, void *b) +{ + Attractor *v = *(Attractor **) a; v->lc1 *= CTX.mesh.lc_factor; v->lc2 *= CTX.mesh.lc_factor; } -void ApplyLcFactor(Mesh *M){ +void ApplyLcFactor(Mesh * M) +{ Tree_Action(M->Points, ApplyLcFactor_Point); List_Action(M->Metric->Attractors, ApplyLcFactor_Attractor); } -void Maillage_Dimension_0 (Mesh * M){ - for (int i = 0; i < 50; i++) +void Maillage_Dimension_0(Mesh * M) +{ + for(int i = 0; i < 50; i++) M->Statistics[i] = 0.0; - for (int i = 0; i < NB_HISTOGRAM; i++) + for(int i = 0; i < NB_HISTOGRAM; i++) M->Histogram[0][i] = M->Histogram[1][i] = M->Histogram[2][i] = 0; // This is the default type of BGM (lc associated with // points of the geometry). It can be changed to // - ONFILE by loading a view containing a bgmesh // - CONSTANT // - FUNCTION - Create_BgMesh (WITHPOINTS, .2, M); + Create_BgMesh(WITHPOINTS, .2, M); } -void Maillage_Dimension_1 (Mesh * M){ +void Maillage_Dimension_1(Mesh * M) +{ double t1, t2; t1 = Cpu(); - Tree_Action (M->Curves, Maillage_Curve); + Tree_Action(M->Curves, Maillage_Curve); t2 = Cpu(); M->Statistics[13] = t2 - t1; } -void Maillage_Dimension_2 (Mesh * M){ +void Maillage_Dimension_2(Mesh * M) +{ int i; Curve *c, *neew, C; - double t1, t2, shortest=1.e300; + double t1, t2, shortest = 1.e300; t1 = Cpu(); // create reverse 1D meshes - List_T *Curves = Tree2List (M->Curves); - for (i = 0; i < List_Nbr (Curves); i++){ - List_Read (Curves, i, &c); - if (c->Num > 0){ - if(c->l < shortest) shortest = c->l ; + List_T *Curves = Tree2List(M->Curves); + for(i = 0; i < List_Nbr(Curves); i++) { + List_Read(Curves, i, &c); + if(c->Num > 0) { + if(c->l < shortest) + shortest = c->l; neew = &C; neew->Num = -c->Num; - Tree_Query (M->Curves, &neew); - neew->Vertices = List_Create (List_Nbr (c->Vertices), 1, sizeof (Vertex *)); - List_Invert (c->Vertices, neew->Vertices); + Tree_Query(M->Curves, &neew); + neew->Vertices = + List_Create(List_Nbr(c->Vertices), 1, sizeof(Vertex *)); + List_Invert(c->Vertices, neew->Vertices); } } - List_Delete (Curves); + List_Delete(Curves); Msg(DEBUG, "Shortest curve has length %g", shortest); // mesh 2D - - Tree_Action (M->Surfaces, Maillage_Surface); - t2 = Cpu(); + Tree_Action(M->Surfaces, Maillage_Surface); + + t2 = Cpu(); M->Statistics[14] = t2 - t1; } -void Maillage_Dimension_3 (Mesh * M){ +void Maillage_Dimension_3(Mesh * M) +{ Volume *v; double t1, t2; Volume *vol; t1 = Cpu(); - v = Create_Volume (99999, 99999); + v = Create_Volume(99999, 99999); - List_T *list = Tree2List (M->Volumes); - for (int i = 0; i < List_Nbr (list); i++){ - List_Read (list, i, &vol); - if ((!vol->Extrude || !vol->Extrude->mesh.ExtrudeMesh) && - (vol->Method != TRANSFINI)){ - for (int j = 0; j < List_Nbr (vol->Surfaces); j++){ - List_Replace (v->Surfaces, List_Pointer (vol->Surfaces, j), compareSurface); + List_T *list = Tree2List(M->Volumes); + for(int i = 0; i < List_Nbr(list); i++) { + List_Read(list, i, &vol); + if((!vol->Extrude || !vol->Extrude->mesh.ExtrudeMesh) && + (vol->Method != TRANSFINI)) { + for(int j = 0; j < List_Nbr(vol->Surfaces); j++) { + List_Replace(v->Surfaces, List_Pointer(vol->Surfaces, j), + compareSurface); } } } - List_Delete (list); - Tree_Insert (M->Volumes, &v); + List_Delete(list); + Tree_Insert(M->Volumes, &v); - if(CTX.mesh.oldxtrude){ - Extrude_Mesh_Old(M); // old automatic extrusion algorithm + if(CTX.mesh.oldxtrude) { + Extrude_Mesh_Old(M); // old automatic extrusion algorithm } - else{ - Extrude_Mesh(M->Volumes); // new extrusion - Tree_Action(M->Volumes, Maillage_Volume); // delaunay of remaining parts + else { + Extrude_Mesh(M->Volumes); // new extrusion + Tree_Action(M->Volumes, Maillage_Volume); // delaunay of remaining parts } t2 = Cpu(); @@ -156,7 +170,8 @@ void Maillage_Dimension_3 (Mesh * M){ } -void Init_Mesh (Mesh * M, int all){ +void Init_Mesh(Mesh * M, int all) +{ THEM = M; M->MaxPointNum = 0; @@ -169,64 +184,64 @@ void Init_Mesh (Mesh * M, int all){ M->MaxSimplexNum = 0; ExitExtrude(); - - if (M->Vertices){ - Tree_Action (M->Vertices, Free_Vertex); - Tree_Delete (M->Vertices); + + if(M->Vertices) { + Tree_Action(M->Vertices, Free_Vertex); + Tree_Delete(M->Vertices); } - if (M->VertexEdges){ - Tree_Action (M->VertexEdges, Free_Vertex); - Tree_Delete (M->VertexEdges); + if(M->VertexEdges) { + Tree_Action(M->VertexEdges, Free_Vertex); + Tree_Delete(M->VertexEdges); } - if (M->Simplexes){ + if(M->Simplexes) { // Tree_Action (M->Simplexes, Free_Simplex); //produit des crashes innatendus... // normal, cette memoire est dupliquee // dans les volumes. Je crois qu'on a besoin // des 2, ce truc ne provoque pas de leaks. - Tree_Delete (M->Simplexes); + Tree_Delete(M->Simplexes); } - if (M->Points){ - Tree_Action (M->Points, Free_Vertex); - Tree_Delete (M->Points); + if(M->Points) { + Tree_Action(M->Points, Free_Vertex); + Tree_Delete(M->Points); } - if (M->Curves){ - Tree_Action (M->Curves, Free_Curve); - Tree_Delete (M->Curves); + if(M->Curves) { + Tree_Action(M->Curves, Free_Curve); + Tree_Delete(M->Curves); } - if (M->SurfaceLoops){ + if(M->SurfaceLoops) { //Tree_Action (M->SurfaceLoops, Free_SurfaceLoop); - Tree_Delete (M->SurfaceLoops); + Tree_Delete(M->SurfaceLoops); } - if (M->EdgeLoops){ + if(M->EdgeLoops) { //Tree_Action (M->EdgeLoops, Free_EdgeLoop); - Tree_Delete (M->EdgeLoops); + Tree_Delete(M->EdgeLoops); } - if (M->Surfaces){ - Tree_Action (M->Surfaces, Free_Surface); - Tree_Delete (M->Surfaces); + if(M->Surfaces) { + Tree_Action(M->Surfaces, Free_Surface); + Tree_Delete(M->Surfaces); } - if (M->Volumes){ - Tree_Action (M->Volumes, Free_Volume); //produit des crashes innatendus... - Tree_Delete (M->Volumes); + if(M->Volumes) { + Tree_Action(M->Volumes, Free_Volume); //produit des crashes innatendus... + Tree_Delete(M->Volumes); } - if (M->PhysicalGroups){ + if(M->PhysicalGroups) { //Tree_Action (M->PhysicalGroups, Free_PhysicalGroup); - List_Delete (M->PhysicalGroups); + List_Delete(M->PhysicalGroups); } - if (M->Metric){ + if(M->Metric) { delete M->Metric; } - - M->Vertices = Tree_Create (sizeof (Vertex *), compareVertex); - M->VertexEdges = Tree_Create (sizeof (Vertex *), compareVertex); - M->Simplexes = Tree_Create (sizeof (Simplex *), compareSimplex); - M->Points = Tree_Create (sizeof (Vertex *), compareVertex); - M->Curves = Tree_Create (sizeof (Curve *), compareCurve); - M->SurfaceLoops = Tree_Create (sizeof (SurfaceLoop *), compareSurfaceLoop); - M->EdgeLoops = Tree_Create (sizeof (EdgeLoop *), compareEdgeLoop); - M->Surfaces = Tree_Create (sizeof (Surface *), compareSurface); - M->Volumes = Tree_Create (sizeof (Volume *), compareVolume); - M->PhysicalGroups = List_Create (5, 5, sizeof (PhysicalGroup *)); + + M->Vertices = Tree_Create(sizeof(Vertex *), compareVertex); + M->VertexEdges = Tree_Create(sizeof(Vertex *), compareVertex); + M->Simplexes = Tree_Create(sizeof(Simplex *), compareSimplex); + M->Points = Tree_Create(sizeof(Vertex *), compareVertex); + M->Curves = Tree_Create(sizeof(Curve *), compareCurve); + M->SurfaceLoops = Tree_Create(sizeof(SurfaceLoop *), compareSurfaceLoop); + M->EdgeLoops = Tree_Create(sizeof(EdgeLoop *), compareEdgeLoop); + M->Surfaces = Tree_Create(sizeof(Surface *), compareSurface); + M->Volumes = Tree_Create(sizeof(Volume *), compareVolume); + M->PhysicalGroups = List_Create(5, 5, sizeof(PhysicalGroup *)); M->Metric = new GMSHMetric; M->BGM.bgm = NULL; @@ -235,63 +250,62 @@ void Init_Mesh (Mesh * M, int all){ CTX.mesh.changed = 1; } -void mai3d (Mesh * M, int Asked){ +void mai3d(Mesh * M, int Asked) +{ double t1, t2; int oldstatus; - if(CTX.threads_lock){ + if(CTX.threads_lock) { Msg(INFO, "I'm busy! Ask me that later..."); return; } - M->MeshParams.DelaunayAlgorithm = CTX.mesh.algo ; - M->MeshParams.NbSmoothing = CTX.mesh.nb_smoothing ; - M->MeshParams.InteractiveDelaunay = CTX.mesh.interactive ; + M->MeshParams.DelaunayAlgorithm = CTX.mesh.algo; + M->MeshParams.NbSmoothing = CTX.mesh.nb_smoothing; + M->MeshParams.InteractiveDelaunay = CTX.mesh.interactive; oldstatus = M->status; // re-read data - if ((Asked > oldstatus && Asked >= 0 && oldstatus < 0) || - (Asked < oldstatus)){ - OpenProblem (CTX.filename); + if((Asked > oldstatus && Asked >= 0 && oldstatus < 0) || + (Asked < oldstatus)) { + OpenProblem(CTX.filename); M->status = 0; } - CTX.threads_lock = 1 ; - + CTX.threads_lock = 1; + // 1D mesh - - if ((Asked > oldstatus && Asked > 0 && oldstatus < 1) || - (Asked < oldstatus && Asked > 0)){ + + if((Asked > oldstatus && Asked > 0 && oldstatus < 1) || + (Asked < oldstatus && Asked > 0)) { Msg(STATUS2, "Mesh 1D..."); t1 = Cpu(); - if(M->status > 1) - { - OpenProblem (CTX.filename); - } + if(M->status > 1) { + OpenProblem(CTX.filename); + } - Maillage_Dimension_1 (M); + Maillage_Dimension_1(M); t2 = Cpu(); Msg(STATUS2, "Mesh 1D complete (%g s)", t2 - t1); M->status = 1; } - + // 2D mesh - - if ((Asked > oldstatus && Asked > 1 && oldstatus < 2) || - (Asked < oldstatus && Asked > 1)){ + + if((Asked > oldstatus && Asked > 1 && oldstatus < 2) || + (Asked < oldstatus && Asked > 1)) { Msg(STATUS2, "Mesh 2D..."); t1 = Cpu(); - if(M->status == 3) - { - OpenProblem (CTX.filename); - Maillage_Dimension_1 (M); - } + if(M->status == 3) { + OpenProblem(CTX.filename); + Maillage_Dimension_1(M); + } - Maillage_Dimension_2 (M); + Maillage_Dimension_2(M); t2 = Cpu(); Msg(STATUS2, "Mesh 2D complete (%g s)", t2 - t1); M->status = 2; @@ -299,16 +313,16 @@ void mai3d (Mesh * M, int Asked){ // 3D mesh - if ((Asked > oldstatus && Asked > 2 && oldstatus < 3) || - (Asked < oldstatus && Asked > 2)){ + if((Asked > oldstatus && Asked > 2 && oldstatus < 3) || + (Asked < oldstatus && Asked > 2)) { Msg(STATUS2, "Mesh 3D..."); t1 = Cpu(); - Maillage_Dimension_3 (M); + Maillage_Dimension_3(M); t2 = Cpu(); Msg(STATUS2, "Mesh 3D complete (%g s)", t2 - t1); M->status = 3; } - CTX.threads_lock = 0 ; + CTX.threads_lock = 0; CTX.mesh.changed = 1; } diff --git a/Mesh/Interpolation.cpp b/Mesh/Interpolation.cpp index 7083c0f0a4565517fb629a66d438d39f4e99c26b..65bf57d2a90f8ed31d8fb2bcb0287423f4015f0d 100644 --- a/Mesh/Interpolation.cpp +++ b/Mesh/Interpolation.cpp @@ -1,4 +1,4 @@ -// $Id: Interpolation.cpp,v 1.20 2003-01-23 20:19:22 geuzaine Exp $ +// $Id: Interpolation.cpp,v 1.21 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -31,8 +31,8 @@ extern Mesh *THEM; // Curves -Vertex InterpolateCurve (Curve * Curve, double u, int derivee){ - +Vertex InterpolateCurve(Curve * Curve, double u, int derivee) +{ int N, i, j; Vertex D[2], V; Vertex *v[5]; @@ -42,29 +42,29 @@ Vertex InterpolateCurve (Curve * Curve, double u, int derivee){ V.u = u; - if (derivee){ - D[0] = InterpolateCurve (Curve, u, 0); - D[1] = InterpolateCurve (Curve, u + eps, 0); + if(derivee) { + D[0] = InterpolateCurve(Curve, u, 0); + D[1] = InterpolateCurve(Curve, u + eps, 0); V.Pos.X = (D[1].Pos.X - D[0].Pos.X) / eps; V.Pos.Y = (D[1].Pos.Y - D[0].Pos.Y) / eps; V.Pos.Z = (D[1].Pos.Z - D[0].Pos.Z) / eps; return V; } - switch (Curve->Typ){ + switch (Curve->Typ) { case MSH_SEGM_LINE: - N = List_Nbr (Curve->Control_Points); - i = (int) ((double) (N - 1) * u); - while (i >= N - 1) + N = List_Nbr(Curve->Control_Points); + i = (int)((double)(N - 1) * u); + while(i >= N - 1) i--; - while (i < 0) + while(i < 0) i++; - t1 = (double) (i) / (double) (N - 1); - t2 = (double) (i + 1) / (double) (N - 1); + t1 = (double)(i) / (double)(N - 1); + t2 = (double)(i + 1) / (double)(N - 1); t = (u - t1) / (t2 - t1); - List_Read (Curve->Control_Points, i, &v[1]); - List_Read (Curve->Control_Points, i + 1, &v[2]); + List_Read(Curve->Control_Points, i, &v[1]); + List_Read(Curve->Control_Points, i + 1, &v[2]); V.Pos.X = v[1]->Pos.X + t * (v[2]->Pos.X - v[1]->Pos.X); V.Pos.Y = v[1]->Pos.Y + t * (v[2]->Pos.Y - v[1]->Pos.Y); V.Pos.Z = v[1]->Pos.Z + t * (v[2]->Pos.Z - v[1]->Pos.Z); @@ -73,181 +73,180 @@ Vertex InterpolateCurve (Curve * Curve, double u, int derivee){ return V; case MSH_SEGM_PARAMETRIC: - V.Pos.X = evaluate_scalarfunction ("t", u, Curve->functu); - V.Pos.Y = evaluate_scalarfunction ("t", u, Curve->functv); - V.Pos.Z = evaluate_scalarfunction ("t", u, Curve->functw); + V.Pos.X = evaluate_scalarfunction("t", u, Curve->functu); + V.Pos.Y = evaluate_scalarfunction("t", u, Curve->functv); + V.Pos.Z = evaluate_scalarfunction("t", u, Curve->functw); V.w = (1. - u) * Curve->beg->w + u * Curve->end->w; V.lc = (1. - u) * Curve->beg->lc + u * Curve->end->lc; return V; - + case MSH_SEGM_CIRC: case MSH_SEGM_CIRC_INV: case MSH_SEGM_ELLI: case MSH_SEGM_ELLI_INV: - if (Curve->Typ == MSH_SEGM_CIRC_INV || - Curve->Typ == MSH_SEGM_ELLI_INV){ + if(Curve->Typ == MSH_SEGM_CIRC_INV || Curve->Typ == MSH_SEGM_ELLI_INV) { V.u = 1. - u; u = V.u; } - + teta = Curve->Circle.t1 - (Curve->Circle.t1 - Curve->Circle.t2) * u; /* pour les ellipses */ teta -= Curve->Circle.incl; - - V.Pos.X = - Curve->Circle.f1 * cos (teta) * cos (Curve->Circle.incl) - - Curve->Circle.f2 * sin (teta) * sin (Curve->Circle.incl); - V.Pos.Y = - Curve->Circle.f1 * cos (teta) * sin (Curve->Circle.incl) + - Curve->Circle.f2 * sin (teta) * cos (Curve->Circle.incl); + + V.Pos.X = + Curve->Circle.f1 * cos(teta) * cos(Curve->Circle.incl) - + Curve->Circle.f2 * sin(teta) * sin(Curve->Circle.incl); + V.Pos.Y = + Curve->Circle.f1 * cos(teta) * sin(Curve->Circle.incl) + + Curve->Circle.f2 * sin(teta) * cos(Curve->Circle.incl); V.Pos.Z = 0.0; - Projette (&V, Curve->Circle.invmat); + Projette(&V, Curve->Circle.invmat); V.Pos.X += Curve->Circle.v[1]->Pos.X; V.Pos.Y += Curve->Circle.v[1]->Pos.Y; V.Pos.Z += Curve->Circle.v[1]->Pos.Z; - V.w = (1. - u) * Curve->beg->w + u * Curve->end->w ; - V.lc = (1. - u) * Curve->beg->lc + u * Curve->end->lc ; + V.w = (1. - u) * Curve->beg->w + u * Curve->end->w; + V.lc = (1. - u) * Curve->beg->lc + u * Curve->end->lc; return V; - + case MSH_SEGM_BSPLN: case MSH_SEGM_BEZIER: - return InterpolateUBS (Curve, u, derivee); - + return InterpolateUBS(Curve, u, derivee); + case MSH_SEGM_NURBS: - return InterpolateNurbs (Curve, u, derivee); + return InterpolateNurbs(Curve, u, derivee); case MSH_SEGM_SPLN: - N = List_Nbr (Curve->Control_Points); + N = List_Nbr(Curve->Control_Points); /* - 0 i P i+1 N-1 - vfirst*---------*---------*----X-----*----------*----------* vlast - 0 t1 absc t2 1 - 0 t 1 + 0 i P i+1 N-1 + vfirst*---------*---------*----X-----*----------*----------* vlast + 0 t1 absc t2 1 + 0 t 1 - Splines uniformes -> Le point se trouve entre v[1] et v[2] - -> Calcul de l'abcisse curviligne locale t ( entre 0 et 1 ) + Splines uniformes -> Le point se trouve entre v[1] et v[2] + -> Calcul de l'abcisse curviligne locale t ( entre 0 et 1 ) - 0 -> t1 - 1 -> t2 - u -> t + 0 -> t1 + 1 -> t2 + u -> t - Splines Lineiques -> Multilines - */ + Splines Lineiques -> Multilines + */ - i = (int) ((double) (N - 1) * u); - if (i < 0) + i = (int)((double)(N - 1) * u); + if(i < 0) i = 0; - if (i >= N - 1) + if(i >= N - 1) i = N - 2; - - t1 = (double) (i) / (double) (N - 1); - t2 = (double) (i + 1) / (double) (N - 1); - + + t1 = (double)(i) / (double)(N - 1); + t2 = (double)(i + 1) / (double)(N - 1); + t = (u - t1) / (t2 - t1); - - List_Read (Curve->Control_Points, i, &v[1]); - List_Read (Curve->Control_Points, i + 1, &v[2]); - - V.lc = (1. - t) * v[1]->lc + t * v[2]->lc ; - V.w = (1. - t) * v[1]->w + t * v[2]->w ; - - if (!i){ + + List_Read(Curve->Control_Points, i, &v[1]); + List_Read(Curve->Control_Points, i + 1, &v[2]); + + V.lc = (1. - t) * v[1]->lc + t * v[2]->lc; + V.w = (1. - t) * v[1]->w + t * v[2]->w; + + if(!i) { v[0] = &temp1; v[0]->Pos.X = 2. * v[1]->Pos.X - v[2]->Pos.X; v[0]->Pos.Y = 2. * v[1]->Pos.Y - v[2]->Pos.Y; v[0]->Pos.Z = 2. * v[1]->Pos.Z - v[2]->Pos.Z; } - else{ - List_Read (Curve->Control_Points, i - 1, &v[0]); + else { + List_Read(Curve->Control_Points, i - 1, &v[0]); } - - if (i == N - 2){ + + if(i == N - 2) { v[3] = &temp2; v[3]->Pos.X = 2. * v[2]->Pos.X - v[1]->Pos.X; v[3]->Pos.Y = 2. * v[2]->Pos.Y - v[1]->Pos.Y; v[3]->Pos.Z = 2. * v[2]->Pos.Z - v[1]->Pos.Z; } - else{ - List_Read (Curve->Control_Points, i + 2, &v[3]); + else { + List_Read(Curve->Control_Points, i + 2, &v[3]); } - - if (derivee){ + + if(derivee) { T[3] = 0.; T[2] = 1.; T[1] = 2. * t; T[0] = 3. * t * t; } - else{ + else { T[3] = 1.; T[2] = t; T[1] = t * t; T[0] = t * t * t; } - + V.Pos.X = V.Pos.Y = V.Pos.Z = W = 0.0; - for (i = 0; i < 4; i++){ + for(i = 0; i < 4; i++) { vec[i] = 0.0; } - + /* X */ - for (i = 0; i < 4; i++){ - for (j = 0; j < 4; j++){ - vec[i] += Curve->mat[i][j] * v[j]->Pos.X; - } + for(i = 0; i < 4; i++) { + for(j = 0; j < 4; j++) { + vec[i] += Curve->mat[i][j] * v[j]->Pos.X; + } } - for (j = 0; j < 4; j++){ + for(j = 0; j < 4; j++) { V.Pos.X += T[j] * vec[j]; vec[j] = 0.0; } /* Y */ - for (i = 0; i < 4; i++){ - for (j = 0; j < 4; j++){ + for(i = 0; i < 4; i++) { + for(j = 0; j < 4; j++) { vec[i] += Curve->mat[i][j] * v[j]->Pos.Y; } } - for (j = 0; j < 4; j++){ + for(j = 0; j < 4; j++) { V.Pos.Y += T[j] * vec[j]; vec[j] = 0.0; } /* Z */ - for (i = 0; i < 4; i++){ - for (j = 0; j < 4; j++){ + for(i = 0; i < 4; i++) { + for(j = 0; j < 4; j++) { vec[i] += Curve->mat[i][j] * v[j]->Pos.Z; } } - for (j = 0; j < 4; j++){ + for(j = 0; j < 4; j++) { V.Pos.Z += T[j] * vec[j]; vec[j] = 0.0; } - + /* W */ - for (i = 0; i < 4; i++){ - for (j = 0; j < 4; j++){ + for(i = 0; i < 4; i++) { + for(j = 0; j < 4; j++) { vec[i] += Curve->mat[i][j] * v[j]->lc; } } - for (j = 0; j < 4; j++){ + for(j = 0; j < 4; j++) { W += T[j] * vec[j]; } - if (derivee){ + if(derivee) { V.Pos.X /= (t2 - t1); V.Pos.Y /= (t2 - t1); V.Pos.Z /= (t2 - t1); } - else{ + else { // V.Pos.X /= W; // V.Pos.Y /= W; // V.Pos.Z /= W; } return V; - default : + default: Msg(FATAL, "Unknown curve type in interpolation"); return V; } @@ -263,21 +262,21 @@ Vertex InterpolateCurve (Curve * Curve, double u, int derivee){ #define TRAN_QUA(c1,c2,c3,c4,s1,s2,s3,s4,u,v) \ (1.-u)*c4+u*c2+(1.-v)*c1+v*c3-((1.-u)*(1.-v)*s1+u*(1.-v)*s2+u*v*s3+(1.-u)*v*s4) -Vertex TransfiniteQua (Vertex c1, Vertex c2, Vertex c3, Vertex c4, - Vertex s1, Vertex s2, Vertex s3, Vertex s4, - double u, double v){ +Vertex TransfiniteQua(Vertex c1, Vertex c2, Vertex c3, Vertex c4, + Vertex s1, Vertex s2, Vertex s3, Vertex s4, + double u, double v) +{ Vertex V; - V.lc = TRAN_QUA (c1.lc, c2.lc, c3.lc, c4.lc, - s1.lc, s2.lc, s3.lc, s4.lc, u, v); - V.w = TRAN_QUA (c1.w, c2.w, c3.w, c4.w, - s1.w, s2.w, s3.w, s4.w, u, v); - V.Pos.X = TRAN_QUA (c1.Pos.X, c2.Pos.X, c3.Pos.X, c4.Pos.X, - s1.Pos.X, s2.Pos.X, s3.Pos.X, s4.Pos.X, u, v); - V.Pos.Y = TRAN_QUA (c1.Pos.Y, c2.Pos.Y, c3.Pos.Y, c4.Pos.Y, - s1.Pos.Y, s2.Pos.Y, s3.Pos.Y, s4.Pos.Y, u, v); - V.Pos.Z = TRAN_QUA (c1.Pos.Z, c2.Pos.Z, c3.Pos.Z, c4.Pos.Z, - s1.Pos.Z, s2.Pos.Z, s3.Pos.Z, s4.Pos.Z, u, v); + V.lc = TRAN_QUA(c1.lc, c2.lc, c3.lc, c4.lc, + s1.lc, s2.lc, s3.lc, s4.lc, u, v); + V.w = TRAN_QUA(c1.w, c2.w, c3.w, c4.w, s1.w, s2.w, s3.w, s4.w, u, v); + V.Pos.X = TRAN_QUA(c1.Pos.X, c2.Pos.X, c3.Pos.X, c4.Pos.X, + s1.Pos.X, s2.Pos.X, s3.Pos.X, s4.Pos.X, u, v); + V.Pos.Y = TRAN_QUA(c1.Pos.Y, c2.Pos.Y, c3.Pos.Y, c4.Pos.Y, + s1.Pos.Y, s2.Pos.Y, s3.Pos.Y, s4.Pos.Y, u, v); + V.Pos.Z = TRAN_QUA(c1.Pos.Z, c2.Pos.Z, c3.Pos.Z, c4.Pos.Z, + s1.Pos.Z, s2.Pos.Z, s3.Pos.Z, s4.Pos.Z, u, v); return (V); } @@ -286,30 +285,31 @@ Vertex TransfiniteQua (Vertex c1, Vertex c2, Vertex c3, Vertex c4, #define TRAN_TRI(c1,c2,c3,s1,s2,s3,u,v) u*c2+(1.-v)*c1+v*c3-(u*(1.-v)*s2+u*v*s3); -Vertex TransfiniteTri (Vertex c1, Vertex c2, Vertex c3, - Vertex s1, Vertex s2, Vertex s3, - double u, double v){ +Vertex TransfiniteTri(Vertex c1, Vertex c2, Vertex c3, + Vertex s1, Vertex s2, Vertex s3, double u, double v) +{ Vertex V; - V.lc = TRAN_TRI (c1.lc, c2.lc, c3.lc, s1.lc, s2.lc, s3.lc, u, v); - V.w = TRAN_TRI (c1.w, c2.w, c3.w, s1.w, s2.w, s3.w, u, v); - V.Pos.X = TRAN_TRI (c1.Pos.X, c2.Pos.X, c3.Pos.X, - s1.Pos.X, s2.Pos.X, s3.Pos.X, u, v); - V.Pos.Y = TRAN_TRI (c1.Pos.Y, c2.Pos.Y, c3.Pos.Y, - s1.Pos.Y, s2.Pos.Y, s3.Pos.Y, u, v); - V.Pos.Z = TRAN_TRI (c1.Pos.Z, c2.Pos.Z, c3.Pos.Z, - s1.Pos.Z, s2.Pos.Z, s3.Pos.Z, u, v); + V.lc = TRAN_TRI(c1.lc, c2.lc, c3.lc, s1.lc, s2.lc, s3.lc, u, v); + V.w = TRAN_TRI(c1.w, c2.w, c3.w, s1.w, s2.w, s3.w, u, v); + V.Pos.X = TRAN_TRI(c1.Pos.X, c2.Pos.X, c3.Pos.X, + s1.Pos.X, s2.Pos.X, s3.Pos.X, u, v); + V.Pos.Y = TRAN_TRI(c1.Pos.Y, c2.Pos.Y, c3.Pos.Y, + s1.Pos.Y, s2.Pos.Y, s3.Pos.Y, u, v); + V.Pos.Z = TRAN_TRI(c1.Pos.Z, c2.Pos.Z, c3.Pos.Z, + s1.Pos.Z, s2.Pos.Z, s3.Pos.Z, u, v); return (V); } -void TransfiniteSph (Vertex S, Vertex center, Vertex * T){ +void TransfiniteSph(Vertex S, Vertex center, Vertex * T) +{ double r, s, dirx, diry, dirz; - r = sqrt (DSQR (S.Pos.X - center.Pos.X) + DSQR (S.Pos.Y - center.Pos.Y) - + DSQR (S.Pos.Z - center.Pos.Z)); + r = sqrt(DSQR(S.Pos.X - center.Pos.X) + DSQR(S.Pos.Y - center.Pos.Y) + + DSQR(S.Pos.Z - center.Pos.Z)); - s = sqrt (DSQR (T->Pos.X - center.Pos.X) + DSQR (T->Pos.Y - center.Pos.Y) - + DSQR (T->Pos.Z - center.Pos.Z)); + s = sqrt(DSQR(T->Pos.X - center.Pos.X) + DSQR(T->Pos.Y - center.Pos.Y) + + DSQR(T->Pos.Z - center.Pos.Z)); dirx = (T->Pos.X - center.Pos.X) / s; diry = (T->Pos.Y - center.Pos.Y) / s; @@ -320,150 +320,161 @@ void TransfiniteSph (Vertex S, Vertex center, Vertex * T){ T->Pos.Z = center.Pos.Z + r * dirz; } -Vertex InterpolateSurface (Surface * s, double u, double v, - int derivee, int u_v){ +Vertex InterpolateSurface(Surface * s, double u, double v, + int derivee, int u_v) +{ Vertex *c1, *c2, T, D[4], V[4], *S[4]; Curve *C[4]; int i, issphere; double eps = 1.e-6; - if (derivee){ - if (u_v == 1){ - if (u - eps < 0.0){ - D[0] = InterpolateSurface (s, u, v, 0, 0); - D[1] = InterpolateSurface (s, u + eps, v, 0, 0); + if(derivee) { + if(u_v == 1) { + if(u - eps < 0.0) { + D[0] = InterpolateSurface(s, u, v, 0, 0); + D[1] = InterpolateSurface(s, u + eps, v, 0, 0); } - else{ - D[0] = InterpolateSurface (s, u - eps, v, 0, 0); - D[1] = InterpolateSurface (s, u, v, 0, 0); + else { + D[0] = InterpolateSurface(s, u - eps, v, 0, 0); + D[1] = InterpolateSurface(s, u, v, 0, 0); } } - else if (u_v == 2){ - if (v - eps < 0.0){ - D[0] = InterpolateSurface (s, u, v, 0, 0); - D[1] = InterpolateSurface (s, u, v + eps, 0, 0); + else if(u_v == 2) { + if(v - eps < 0.0) { + D[0] = InterpolateSurface(s, u, v, 0, 0); + D[1] = InterpolateSurface(s, u, v + eps, 0, 0); } - else{ - D[0] = InterpolateSurface (s, u, v - eps, 0, 0); - D[1] = InterpolateSurface (s, u, v, 0, 0); + else { + D[0] = InterpolateSurface(s, u, v - eps, 0, 0); + D[1] = InterpolateSurface(s, u, v, 0, 0); } } - else{ + else { Msg(WARNING, "Arbitrary InterpolateSurface for derivative not done"); /* - double epsc = eps * cos (t); - double epss = eps * sin (t); - if (v - epss < 0.0 && u - epsc < 0.0){ - D[0] = InterpolateSurface (s, u, v, 0, 0); - D[1] = InterpolateSurface (s, u + epsc, v + epss, 0, 0); - } - else if (v - epss < 0.0){ - D[0] = InterpolateSurface (s, u - epsc, v, 0, 0); - D[1] = InterpolateSurface (s, u, v + epss, 0, 0); - } - else if (u - epsc < 0.0){ - D[0] = InterpolateSurface (s, u, v - epss, 0, 0); - D[1] = InterpolateSurface (s, u + epsc, v, 0, 0); - } - else{ - D[0] = InterpolateSurface (s, u - epsc, v - epss, 0, 0); - D[1] = InterpolateSurface (s, u, v, 0, 0); - } - */ + double epsc = eps * cos (t); + double epss = eps * sin (t); + if (v - epss < 0.0 && u - epsc < 0.0){ + D[0] = InterpolateSurface (s, u, v, 0, 0); + D[1] = InterpolateSurface (s, u + epsc, v + epss, 0, 0); + } + else if (v - epss < 0.0){ + D[0] = InterpolateSurface (s, u - epsc, v, 0, 0); + D[1] = InterpolateSurface (s, u, v + epss, 0, 0); + } + else if (u - epsc < 0.0){ + D[0] = InterpolateSurface (s, u, v - epss, 0, 0); + D[1] = InterpolateSurface (s, u + epsc, v, 0, 0); + } + else{ + D[0] = InterpolateSurface (s, u - epsc, v - epss, 0, 0); + D[1] = InterpolateSurface (s, u, v, 0, 0); + } + */ } T.Pos.X = (D[1].Pos.X - D[0].Pos.X) / eps; T.Pos.Y = (D[1].Pos.Y - D[0].Pos.Y) / eps; T.Pos.Z = (D[1].Pos.Z - D[0].Pos.Z) / eps; return T; } - - Vertex x (u, v, .0); + + Vertex x(u, v, .0); Vertex *xx = &x, *dum; - if (s->Extrude && s->Extrude->geo.Mode == EXTRUDED_ENTITY && - s->Typ != MSH_SURF_PLAN){ - Curve *c = FindCurve (s->Extrude->geo.Source, THEM); - Vertex v1 = InterpolateCurve (c, u, 0); - s->Extrude->Extrude (v, v1.Pos.X, v1.Pos.Y, v1.Pos.Z); + if(s->Extrude && s->Extrude->geo.Mode == EXTRUDED_ENTITY && + s->Typ != MSH_SURF_PLAN) { + Curve *c = FindCurve(s->Extrude->geo.Source, THEM); + Vertex v1 = InterpolateCurve(c, u, 0); + s->Extrude->Extrude(v, v1.Pos.X, v1.Pos.Y, v1.Pos.Z); return v1; } - switch (s->Typ){ - + switch (s->Typ) { + case MSH_SURF_PLAN: - Calcule_Z_Plan (&xx, &dum); + Calcule_Z_Plan(&xx, &dum); //Projette_Inverse(&xx, &dum); return x; case MSH_SURF_REGL: issphere = 1; - for (i = 0; i < 4; i++){ - List_Read (s->Generatrices, i, &C[i]); - if (C[i]->Typ != MSH_SEGM_CIRC && C[i]->Typ != MSH_SEGM_CIRC_INV){ + for(i = 0; i < 4; i++) { + List_Read(s->Generatrices, i, &C[i]); + if(C[i]->Typ != MSH_SEGM_CIRC && C[i]->Typ != MSH_SEGM_CIRC_INV) { issphere = 0; } - else if (issphere){ - if (!i){ - List_Read (C[i]->Control_Points, 1, &c1); + else if(issphere) { + if(!i) { + List_Read(C[i]->Control_Points, 1, &c1); } - else{ - List_Read (C[i]->Control_Points, 1, &c2); - if (compareVertex (&c1, &c2)) + else { + List_Read(C[i]->Control_Points, 1, &c2); + if(compareVertex(&c1, &c2)) issphere = 0; } } } - + S[0] = C[0]->beg; S[1] = C[1]->beg; S[2] = C[2]->beg; S[3] = C[3]->beg; - V[0] = InterpolateCurve (C[0], C[0]->ubeg + (C[0]->uend - C[0]->ubeg) * u, 0); - V[1] = InterpolateCurve (C[1], C[1]->ubeg + (C[1]->uend - C[1]->ubeg) * v, 0); - V[2] = InterpolateCurve (C[2], C[2]->ubeg + (C[2]->uend - C[2]->ubeg) * (1. - u), 0); - V[3] = InterpolateCurve (C[3], C[3]->ubeg + (C[3]->uend - C[3]->ubeg) * (1. - v), 0); - - T = TransfiniteQua (V[0], V[1], V[2], V[3], *S[0], *S[1], *S[2], *S[3], u, v); - if (issphere) TransfiniteSph (*S[0], *c1, &T); + V[0] = + InterpolateCurve(C[0], C[0]->ubeg + (C[0]->uend - C[0]->ubeg) * u, 0); + V[1] = + InterpolateCurve(C[1], C[1]->ubeg + (C[1]->uend - C[1]->ubeg) * v, 0); + V[2] = + InterpolateCurve(C[2], + C[2]->ubeg + (C[2]->uend - C[2]->ubeg) * (1. - u), 0); + V[3] = + InterpolateCurve(C[3], + C[3]->ubeg + (C[3]->uend - C[3]->ubeg) * (1. - v), 0); + + T = + TransfiniteQua(V[0], V[1], V[2], V[3], *S[0], *S[1], *S[2], *S[3], u, + v); + if(issphere) + TransfiniteSph(*S[0], *c1, &T); return (T); - + case MSH_SURF_NURBS: - return InterpolateNurbsSurface (s, u, v); + return InterpolateNurbsSurface(s, u, v); case MSH_SURF_TRIC: issphere = 1; - for (i = 0; i < 3; i++){ - List_Read (s->Generatrices, i, &C[i]); - if (C[i]->Typ != MSH_SEGM_CIRC && C[i]->Typ != MSH_SEGM_CIRC_INV){ + for(i = 0; i < 3; i++) { + List_Read(s->Generatrices, i, &C[i]); + if(C[i]->Typ != MSH_SEGM_CIRC && C[i]->Typ != MSH_SEGM_CIRC_INV) { issphere = 0; } - else if (issphere){ - if (!i){ - List_Read (C[i]->Control_Points, 1, &c1); + else if(issphere) { + if(!i) { + List_Read(C[i]->Control_Points, 1, &c1); } - else{ - List_Read (C[i]->Control_Points, 1, &c2); - if (compareVertex (&c1, &c2)) + else { + List_Read(C[i]->Control_Points, 1, &c2); + if(compareVertex(&c1, &c2)) issphere = 0; } } } - + S[0] = C[0]->beg; S[1] = C[1]->beg; S[2] = C[2]->beg; - V[0] = InterpolateCurve (C[0], u, 0); - V[1] = InterpolateCurve (C[1], v, 0); - V[2] = InterpolateCurve (C[2], 1. - u, 0); - - T = TransfiniteTri (V[0], V[1], V[2], *S[0], *S[1], *S[2], u, v); - if (issphere) TransfiniteSph (*S[0], *c1, &T); + V[0] = InterpolateCurve(C[0], u, 0); + V[1] = InterpolateCurve(C[1], v, 0); + V[2] = InterpolateCurve(C[2], 1. - u, 0); + + T = TransfiniteTri(V[0], V[1], V[2], *S[0], *S[1], *S[2], u, v); + if(issphere) + TransfiniteSph(*S[0], *c1, &T); return (T); - default : + default: Msg(FATAL, "Unknown surface type in interpolation"); return T; } @@ -486,70 +497,73 @@ Vertex InterpolateSurface (Surface * s, double u, double v, #define TRAN_HEX(f1,f2,f3,f4,f5,f6,c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,s1,s2,s3,s4,s5,s6,s7,s8,u,v,w) (1-u)*f4+u*f2+(1-v)*f1+v*f3+(1-w)*f5+w*f6-((1-u)*(1-v)*c9+(1-u)*v*c12+u*(1-v)*c10+u*v*c11)-((1-v)*(1-w)*c1+(1-v)*w*c5+v*(1-w)*c3+v*w*c7)-((1-u)*(1-w)*c4+(1-w)*u*c2+w*(1-u)*c8+u*w*c6)+(1-u)*(1-v)*(1-w)*s1+u*(1-v)*(1-w)*s2+u*v*(1-w)*s3+(1-u)*v*(1-w)*s4+(1-u)*(1-v)*w*s5+u*(1-v)*w*s6+u*v*w*s7+(1-u)*v*w*s8 -Vertex TransfiniteHex (Vertex f1, Vertex f2, Vertex f3, Vertex f4, Vertex f5, Vertex f6, - Vertex c1, Vertex c2, Vertex c3, Vertex c4, Vertex c5, Vertex c6, - Vertex c7, Vertex c8, Vertex c9, Vertex c10, Vertex c11, Vertex c12, - Vertex s1, Vertex s2, Vertex s3, Vertex s4, - Vertex s5, Vertex s6, Vertex s7, Vertex s8, - double u, double v, double w){ +Vertex TransfiniteHex(Vertex f1, Vertex f2, Vertex f3, Vertex f4, Vertex f5, + Vertex f6, Vertex c1, Vertex c2, Vertex c3, Vertex c4, + Vertex c5, Vertex c6, Vertex c7, Vertex c8, Vertex c9, + Vertex c10, Vertex c11, Vertex c12, Vertex s1, + Vertex s2, Vertex s3, Vertex s4, Vertex s5, Vertex s6, + Vertex s7, Vertex s8, double u, double v, double w) +{ Vertex V; - V.lc = TRAN_HEX (f1.lc, f2.lc, f3.lc, f4.lc, f5.lc, f6.lc, - c1.lc, c2.lc, c3.lc, c4.lc, c5.lc, c6.lc, - c7.lc, c8.lc, c9.lc, c10.lc, c11.lc, c12.lc, - s1.lc, s2.lc, s3.lc, s4.lc, s5.lc, s6.lc, s7.lc, s8.lc, - u, v, w); - - V.Pos.X = TRAN_HEX (f1.Pos.X, f2.Pos.X, f3.Pos.X, f4.Pos.X, f5.Pos.X, f6.Pos.X, - c1.Pos.X, c2.Pos.X, c3.Pos.X, c4.Pos.X, c5.Pos.X, c6.Pos.X, - c7.Pos.X, c8.Pos.X, c9.Pos.X, c10.Pos.X, c11.Pos.X, c12.Pos.X, - s1.Pos.X, s2.Pos.X, s3.Pos.X, s4.Pos.X, - s5.Pos.X, s6.Pos.X, s7.Pos.X, s8.Pos.X, - u, v, w); - - V.Pos.Y = TRAN_HEX (f1.Pos.Y, f2.Pos.Y, f3.Pos.Y, f4.Pos.Y, f5.Pos.Y, f6.Pos.Y, - c1.Pos.Y, c2.Pos.Y, c3.Pos.Y, c4.Pos.Y, c5.Pos.Y, c6.Pos.Y, - c7.Pos.Y, c8.Pos.Y, c9.Pos.Y, c10.Pos.Y, c11.Pos.Y, c12.Pos.Y, - s1.Pos.Y, s2.Pos.Y, s3.Pos.Y, s4.Pos.Y, - s5.Pos.Y, s6.Pos.Y, s7.Pos.Y, s8.Pos.Y, - u, v, w); - - V.Pos.Z = TRAN_HEX (f1.Pos.Z, f2.Pos.Z, f3.Pos.Z, f4.Pos.Z, f5.Pos.Z, f6.Pos.Z, - c1.Pos.Z, c2.Pos.Z, c3.Pos.Z, c4.Pos.Z, c5.Pos.Z, c6.Pos.Z, - c7.Pos.Z, c8.Pos.Z, c9.Pos.Z, c10.Pos.Z, c11.Pos.Z, c12.Pos.Z, - s1.Pos.Z, s2.Pos.Z, s3.Pos.Z, s4.Pos.Z, - s5.Pos.Z, s6.Pos.Z, s7.Pos.Z, s8.Pos.Z, - u, v, w); + V.lc = TRAN_HEX(f1.lc, f2.lc, f3.lc, f4.lc, f5.lc, f6.lc, + c1.lc, c2.lc, c3.lc, c4.lc, c5.lc, c6.lc, + c7.lc, c8.lc, c9.lc, c10.lc, c11.lc, c12.lc, + s1.lc, s2.lc, s3.lc, s4.lc, s5.lc, s6.lc, s7.lc, s8.lc, + u, v, w); + + V.Pos.X = + TRAN_HEX(f1.Pos.X, f2.Pos.X, f3.Pos.X, f4.Pos.X, f5.Pos.X, f6.Pos.X, + c1.Pos.X, c2.Pos.X, c3.Pos.X, c4.Pos.X, c5.Pos.X, c6.Pos.X, + c7.Pos.X, c8.Pos.X, c9.Pos.X, c10.Pos.X, c11.Pos.X, c12.Pos.X, + s1.Pos.X, s2.Pos.X, s3.Pos.X, s4.Pos.X, s5.Pos.X, s6.Pos.X, + s7.Pos.X, s8.Pos.X, u, v, w); + + V.Pos.Y = + TRAN_HEX(f1.Pos.Y, f2.Pos.Y, f3.Pos.Y, f4.Pos.Y, f5.Pos.Y, f6.Pos.Y, + c1.Pos.Y, c2.Pos.Y, c3.Pos.Y, c4.Pos.Y, c5.Pos.Y, c6.Pos.Y, + c7.Pos.Y, c8.Pos.Y, c9.Pos.Y, c10.Pos.Y, c11.Pos.Y, c12.Pos.Y, + s1.Pos.Y, s2.Pos.Y, s3.Pos.Y, s4.Pos.Y, s5.Pos.Y, s6.Pos.Y, + s7.Pos.Y, s8.Pos.Y, u, v, w); + + V.Pos.Z = + TRAN_HEX(f1.Pos.Z, f2.Pos.Z, f3.Pos.Z, f4.Pos.Z, f5.Pos.Z, f6.Pos.Z, + c1.Pos.Z, c2.Pos.Z, c3.Pos.Z, c4.Pos.Z, c5.Pos.Z, c6.Pos.Z, + c7.Pos.Z, c8.Pos.Z, c9.Pos.Z, c10.Pos.Z, c11.Pos.Z, c12.Pos.Z, + s1.Pos.Z, s2.Pos.Z, s3.Pos.Z, s4.Pos.Z, s5.Pos.Z, s6.Pos.Z, + s7.Pos.Z, s8.Pos.Z, u, v, w); return (V); } -void Normal2Surface (Surface * s, double u, double v, double n[3]){ +void Normal2Surface(Surface * s, double u, double v, double n[3]) +{ Vertex du, dv; double t1[3], t2[3]; - du = InterpolateSurface (s, u, v, 1, 1); - dv = InterpolateSurface (s, u, v, 1, 2); + du = InterpolateSurface(s, u, v, 1, 1); + dv = InterpolateSurface(s, u, v, 1, 2); t1[0] = du.Pos.X; t1[1] = du.Pos.Y; t1[2] = du.Pos.Z; t2[0] = dv.Pos.X; t2[1] = dv.Pos.Y; t2[2] = dv.Pos.Z; - prodve (t1, t2, n); - norme (n); + prodve(t1, t2, n); + norme(n); } -void HessianNormal2Surface (Surface * s, double u, double v, double n[3]){ +void HessianNormal2Surface(Surface * s, double u, double v, double n[3]) +{ Vertex du, dv; double t1[3], t2[3]; - du = InterpolateSurface (s, u, v, 1, 1); - dv = InterpolateSurface (s, u, v, 1, 2); + du = InterpolateSurface(s, u, v, 1, 1); + dv = InterpolateSurface(s, u, v, 1, 2); t1[0] = du.Pos.X; t1[1] = du.Pos.Y; t1[2] = du.Pos.Z; t2[0] = dv.Pos.X; t2[1] = dv.Pos.Y; t2[2] = dv.Pos.Z; - prodve (t1, t2, n); - norme (n); + prodve(t1, t2, n); + norme(n); } diff --git a/Mesh/MeshQuality.cpp b/Mesh/MeshQuality.cpp index e258d43df67a9d45f465c7a520c6443cc6607c2a..2d23e01c99adc3c2d965e92f499a77834bd57aaf 100644 --- a/Mesh/MeshQuality.cpp +++ b/Mesh/MeshQuality.cpp @@ -1,4 +1,4 @@ -// $Id: MeshQuality.cpp,v 1.10 2003-01-23 20:19:22 geuzaine Exp $ +// $Id: MeshQuality.cpp,v 1.11 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -35,112 +35,133 @@ static double GAMMAMAX, GAMMAMIN, GAMMA; static int NbCalcGamma, *Histogram; -void CalculateGamma (void *a, void *b){ +void CalculateGamma(void *a, void *b) +{ Simplex *s = *(Simplex **) a; - double gamma = s->GammaShapeMeasure (); + double gamma = s->GammaShapeMeasure(); NbCalcGamma++; - GAMMAMAX = DMAX (GAMMAMAX, gamma); + GAMMAMAX = DMAX(GAMMAMAX, gamma); GAMMA += gamma; - GAMMAMIN = DMIN (GAMMAMIN, gamma); - for(int i=0; i<NB_HISTOGRAM; i++) - if(gamma > i/(double)NB_HISTOGRAM && gamma < (i+1)/(double)NB_HISTOGRAM) + GAMMAMIN = DMIN(GAMMAMIN, gamma); + for(int i = 0; i < NB_HISTOGRAM; i++) + if(gamma > i / (double)NB_HISTOGRAM + && gamma < (i + 1) / (double)NB_HISTOGRAM) Histogram[i]++; } -void CalculateEta (void *a, void *b){ +void CalculateEta(void *a, void *b) +{ Simplex *s = *(Simplex **) a; - double gamma = s->EtaShapeMeasure (); + double gamma = s->EtaShapeMeasure(); NbCalcGamma++; - GAMMAMAX = DMAX (GAMMAMAX, gamma); + GAMMAMAX = DMAX(GAMMAMAX, gamma); GAMMA += gamma; - GAMMAMIN = DMIN (GAMMAMIN, gamma); - for(int i=0; i<NB_HISTOGRAM; i++) - if(gamma > i/(double)NB_HISTOGRAM && gamma < (i+1)/(double)NB_HISTOGRAM) + GAMMAMIN = DMIN(GAMMAMIN, gamma); + for(int i = 0; i < NB_HISTOGRAM; i++) + if(gamma > i / (double)NB_HISTOGRAM + && gamma < (i + 1) / (double)NB_HISTOGRAM) Histogram[i]++; } -void CalculateR (void *a, void *b){ +void CalculateR(void *a, void *b) +{ Simplex *s = *(Simplex **) a; - double gamma = s->RhoShapeMeasure (); + double gamma = s->RhoShapeMeasure(); NbCalcGamma++; - GAMMAMAX = DMAX (GAMMAMAX, gamma); + GAMMAMAX = DMAX(GAMMAMAX, gamma); GAMMA += gamma; - GAMMAMIN = DMIN (GAMMAMIN, gamma); - for(int i=0; i<NB_HISTOGRAM; i++) - if(gamma > i/(double)NB_HISTOGRAM && gamma < (i+1)/(double)NB_HISTOGRAM) + GAMMAMIN = DMIN(GAMMAMIN, gamma); + for(int i = 0; i < NB_HISTOGRAM; i++) + if(gamma > i / (double)NB_HISTOGRAM + && gamma < (i + 1) / (double)NB_HISTOGRAM) Histogram[i]++; } -static void g(void *a, void *b){ - Volume *v = *(Volume**)a; - Tree_Action (v->Simplexes, CalculateGamma); +static void g(void *a, void *b) +{ + Volume *v = *(Volume **) a; + Tree_Action(v->Simplexes, CalculateGamma); Msg(DEBUG, "Gamma computed in volume %d (%d values)", v->Num, NbCalcGamma); } -void Gamma_Maillage (Mesh * m, double *gamma, double *gammamax, double *gammamin){ +void Gamma_Maillage(Mesh * m, double *gamma, double *gammamax, + double *gammamin) +{ GAMMA = 0.0; GAMMAMAX = 0.0; GAMMAMIN = 1.0; NbCalcGamma = 0; Histogram = m->Histogram[0]; - for(int i=0; i<NB_HISTOGRAM; i++) Histogram[i] = 0; - Tree_Action (m->Volumes, g); - if(!NbCalcGamma) NbCalcGamma = 1; - *gamma = GAMMA / (double) NbCalcGamma; + for(int i = 0; i < NB_HISTOGRAM; i++) + Histogram[i] = 0; + Tree_Action(m->Volumes, g); + if(!NbCalcGamma) + NbCalcGamma = 1; + *gamma = GAMMA / (double)NbCalcGamma; *gammamax = GAMMAMAX; *gammamin = GAMMAMIN; } -static void e(void *a, void *b){ - Volume *v = *(Volume**)a; - Tree_Action (v->Simplexes, CalculateEta); +static void e(void *a, void *b) +{ + Volume *v = *(Volume **) a; + Tree_Action(v->Simplexes, CalculateEta); Msg(DEBUG, "Eta computed in volume %d (%d values)", v->Num, NbCalcGamma); } -void Eta_Maillage (Mesh * m, double *gamma, double *gammamax, double *gammamin){ +void Eta_Maillage(Mesh * m, double *gamma, double *gammamax, double *gammamin) +{ GAMMA = 0.0; GAMMAMAX = 0.0; GAMMAMIN = 1.0; NbCalcGamma = 0; Histogram = m->Histogram[1]; - for(int i=0; i<NB_HISTOGRAM; i++) Histogram[i] = 0; - Tree_Action (m->Volumes, e); - if(!NbCalcGamma) NbCalcGamma = 1; - *gamma = GAMMA / (double) NbCalcGamma; + for(int i = 0; i < NB_HISTOGRAM; i++) + Histogram[i] = 0; + Tree_Action(m->Volumes, e); + if(!NbCalcGamma) + NbCalcGamma = 1; + *gamma = GAMMA / (double)NbCalcGamma; *gammamax = GAMMAMAX; *gammamin = GAMMAMIN; } -static void r(void *a, void *b){ - Volume *v = *(Volume**)a; - Tree_Action (v->Simplexes, CalculateR); +static void r(void *a, void *b) +{ + Volume *v = *(Volume **) a; + Tree_Action(v->Simplexes, CalculateR); Msg(DEBUG, "Rho computed in volume %d (%d values)", v->Num, NbCalcGamma); } -void R_Maillage (Mesh * m, double *gamma, double *gammamax, double *gammamin){ +void R_Maillage(Mesh * m, double *gamma, double *gammamax, double *gammamin) +{ GAMMA = 0.0; GAMMAMAX = 0.0; GAMMAMIN = 1.0; NbCalcGamma = 0; Histogram = m->Histogram[2]; - for(int i=0; i<NB_HISTOGRAM; i++) Histogram[i] = 0; - Tree_Action (m->Volumes, r); - if(!NbCalcGamma) NbCalcGamma = 1; - *gamma = GAMMA / (double) NbCalcGamma; + for(int i = 0; i < NB_HISTOGRAM; i++) + Histogram[i] = 0; + Tree_Action(m->Volumes, r); + if(!NbCalcGamma) + NbCalcGamma = 1; + *gamma = GAMMA / (double)NbCalcGamma; *gammamax = GAMMAMAX; *gammamin = GAMMAMIN; } -void Mesh_Quality(Mesh *m){ - Gamma_Maillage (m, &m->Statistics[17], &m->Statistics[18], &m->Statistics[19]); - Eta_Maillage (m, &m->Statistics[20], &m->Statistics[21], &m->Statistics[22]); - R_Maillage (m, &m->Statistics[23], &m->Statistics[24], &m->Statistics[25]); +void Mesh_Quality(Mesh * m) +{ + Gamma_Maillage(m, &m->Statistics[17], &m->Statistics[18], + &m->Statistics[19]); + Eta_Maillage(m, &m->Statistics[20], &m->Statistics[21], &m->Statistics[22]); + R_Maillage(m, &m->Statistics[23], &m->Statistics[24], &m->Statistics[25]); } -void Print_Histogram(int *h){ - for(int i=0;i<NB_HISTOGRAM;i++) - Msg(DIRECT, "%g %d", (i+1)/(double)NB_HISTOGRAM, h[i]); +void Print_Histogram(int *h) +{ + for(int i = 0; i < NB_HISTOGRAM; i++) + Msg(DIRECT, "%g %d", (i + 1) / (double)NB_HISTOGRAM, h[i]); } - diff --git a/Mesh/Metric.cpp b/Mesh/Metric.cpp index 939158782d82d455bd6b51c9062ec2b02b56a0e1..ee33ea385881af92bc8ed7859abc1120e00080b5 100644 --- a/Mesh/Metric.cpp +++ b/Mesh/Metric.cpp @@ -1,4 +1,4 @@ -// $Id: Metric.cpp,v 1.16 2003-02-25 04:02:51 geuzaine Exp $ +// $Id: Metric.cpp,v 1.17 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -28,419 +28,391 @@ #include "Matrix.h" #include "Interpolation.h" -Matrix3x3 Matrix3x3::operator * (const Matrix3x3 &autre) -{ +Matrix3x3 Matrix3x3::operator *(const Matrix3x3 & autre) +{ Matrix3x3 m(0.); - for(int i=0;i<3;i++) - { - for(int j=0;j<3;j++) - { - for(int k=0;k<3;k++) - m.mat[i][j] += mat[i][k] * autre.mat[k][j]; - if (fabs(m.mat[i][j]) < 1.e-15)m.mat[i][j] = 0.0; - } + for(int i = 0; i < 3; i++) { + for(int j = 0; j < 3; j++) { + for(int k = 0; k < 3; k++) + m.mat[i][j] += mat[i][k] * autre.mat[k][j]; + if(fabs(m.mat[i][j]) < 1.e-15) + m.mat[i][j] = 0.0; } + } return m; } void Matrix3x3::setMetric() { - Matrix3x3 rot (eVec[0],eVec[1],eVec[2]); - Matrix3x3 rotT (eVec[0],eVec[1],eVec[2]); - Matrix3x3 Id (0.0); + Matrix3x3 rot(eVec[0], eVec[1], eVec[2]); + Matrix3x3 rotT(eVec[0], eVec[1], eVec[2]); + Matrix3x3 Id(0.0); rotT.transpose(); Id.Identity(1.0); - for(int i=0;i<3;i++)Id.mat[i][i] = eVal[i]; + for(int i = 0; i < 3; i++) + Id.mat[i][i] = eVal[i]; Matrix3x3 kk = (Id * rot); Matrix3x3 m = rotT * kk; /* - Msg(INFO,"rot: %g %g %g %g %g %g %g %g %g \n ", - rot[0][0], rot[0][1], rot[0][2], - rot[1][0], rot[1][1], rot[1][2], - rot[2][0], rot[2][1], rot[2][2]); - Msg(INFO,"rotT: %g %g %g %g %g %g %g %g %g \n ", - rotT[0][0], rotT[0][1], rotT[0][2], - rotT[1][0], rotT[1][1], rotT[1][2], - rotT[2][0], rotT[2][1], rotT[2][2]); - Msg(INFO,"id: %g %g %g %g %g %g %g %g %g \n ", - Id[0][0], Id[0][1], Id[0][2], - Id[1][0], Id[1][1], Id[1][2], - Id[2][0], Id[2][1], Id[2][2]); - - Msg(INFO,"kk: %g %g %g %g %g %g %g %g %g \n ", - kk[0][0], kk[0][1], kk[0][2], - kk[1][0], kk[1][1], kk[1][2], - kk[2][0], kk[2][1], kk[2][2]); - - Msg(INFO,"m: %g %g %g %g %g %g %g %g %g \n ", - m[0][0], m[0][1], m[0][2], - m[1][0], m[1][1], m[1][2], - m[2][0], m[2][1], m[2][2]); - */ - for(int i=0;i<3;i++) - for(int j=0;j<3;j++) + Msg(INFO,"rot: %g %g %g %g %g %g %g %g %g \n ", + rot[0][0], rot[0][1], rot[0][2], + rot[1][0], rot[1][1], rot[1][2], + rot[2][0], rot[2][1], rot[2][2]); + Msg(INFO,"rotT: %g %g %g %g %g %g %g %g %g \n ", + rotT[0][0], rotT[0][1], rotT[0][2], + rotT[1][0], rotT[1][1], rotT[1][2], + rotT[2][0], rotT[2][1], rotT[2][2]); + Msg(INFO,"id: %g %g %g %g %g %g %g %g %g \n ", + Id[0][0], Id[0][1], Id[0][2], + Id[1][0], Id[1][1], Id[1][2], + Id[2][0], Id[2][1], Id[2][2]); + + Msg(INFO,"kk: %g %g %g %g %g %g %g %g %g \n ", + kk[0][0], kk[0][1], kk[0][2], + kk[1][0], kk[1][1], kk[1][2], + kk[2][0], kk[2][1], kk[2][2]); + + Msg(INFO,"m: %g %g %g %g %g %g %g %g %g \n ", + m[0][0], m[0][1], m[0][2], + m[1][0], m[1][1], m[1][2], + m[2][0], m[2][1], m[2][2]); + */ + for(int i = 0; i < 3; i++) + for(int j = 0; j < 3; j++) mat[i][j] = m.mat[i][j]; } -GMSHMetric::GMSHMetric () +GMSHMetric::GMSHMetric() { - Identity (); - Attractors = List_Create (2, 2, sizeof (Attractor *)); + Identity(); + Attractors = List_Create(2, 2, sizeof(Attractor *)); limite_aniso = 3000.; min_cos = 0.0095; quality_measure = QUALITY_SIMPLEX_BASED; } -Matrix3x3 GMSHMetric :: Intersect2Metrics (Matrix3x3 *m1[2]) +Matrix3x3 GMSHMetric::Intersect2Metrics(Matrix3x3 * m1[2]) { double lmax = 0.; - int im=0,ic=0,io=0; - Vector3 cmax(0.,0,0,0); + int im = 0, ic = 0, io = 0; + Vector3 cmax(0., 0, 0, 0); Matrix3x3 res(0.0); - for(int i=0;i<3;i++) - { - for(int j=0;j<2;j++) - { - Vector3 v(0.0); - double l; - m1[j]->getEigen(i,v,l); - // cout << i << " " << j << " " << l << endl; - if(l>lmax) - { - ic = i; - lmax = l; - cmax = v; - im = j; - io = (j==0)?1:0; - } - } + for(int i = 0; i < 3; i++) { + for(int j = 0; j < 2; j++) { + Vector3 v(0.0); + double l; + m1[j]->getEigen(i, v, l); + // cout << i << " " << j << " " << l << endl; + if(l > lmax) { + ic = i; + lmax = l; + cmax = v; + im = j; + io = (j == 0) ? 1 : 0; + } } - + } + // cout << "lmax " << lmax << endl; - res.setEigen (ic, cmax[0],cmax[1], cmax[2], lmax); - - for(int i=0;i<3;i++) - { - if(i != ic) - { - Vector3 v(0.0); - double l; - m1[im]->getEigen(i,v,l); - double l2 = m1[io]->quadraticFormEval(v); - // cout << l << " " << l2 << endl; - res.setEigen(i,v[0],v[1],v[2],(l2>l)?l2:l); - } - } + res.setEigen(ic, cmax[0], cmax[1], cmax[2], lmax); + + for(int i = 0; i < 3; i++) { + if(i != ic) { + Vector3 v(0.0); + double l; + m1[im]->getEigen(i, v, l); + double l2 = m1[io]->quadraticFormEval(v); + // cout << l << " " << l2 << endl; + res.setEigen(i, v[0], v[1], v[2], (l2 > l) ? l2 : l); + } + } // cout << "gives " << endl; // res.print(); // cout<<endl; res.setMetric(); return res; - + } double GMSHMetric:: -Local_Metric_Of_Attractors ( double X, double Y, double Z, - double metric[3][3]) +Local_Metric_Of_Attractors(double X, double Y, double Z, double metric[3][3]) { - int i; Attractor *a; - double u, x1, x2, d=0.; - Vertex v1 (X, Y, Z), v2,metr; - - Matrix3x3 myOldMetric (0.,m); - - for (i = 0; i < List_Nbr (Attractors); i++) - { - Matrix3x3 myMetric (0.); - List_Read (Attractors, i, &a); - if (a->v) - { - d = sqrt ((X - a->v->Pos.X) * (X - a->v->Pos.X) + - (Y - a->v->Pos.Y) * (Y - a->v->Pos.Y) + - (Z - a->v->Pos.Z) * (Z - a->v->Pos.Z)); - metr = Vertex(1.,0.,0.); - } - if (a->c) - { - ProjectPointOnCurve (a->c, &v1, &v2, &metr); - d = sqrt ((X - v2.Pos.X) * (X - v2.Pos.X) + - (Y - v2.Pos.Y) * (Y - v2.Pos.Y) + - (Z - v2.Pos.Z) * (Z - v2.Pos.Z)); - - } - double d1 = d * a->Radius; - if(fabs(d1) < a->Radius * 1.e-6)d1 = 0.0; - u = exp (-(d1 * d1)); - x1 = (1. - u) + u * a->lc1; - x2 = (1. - u) + u * a->lc2; - // cout << " dist from "<< X << " " << Y << " = " << d << endl; - if (u > 1.e-2) - { - if (a->v) - { - double q11 = 1. / (x1 * x1); - double q22 = 1. / (x2 * x2); - //double q12 = 1. / (x1 * x2); - - myMetric.setEigen (0,1.,0.,0.,q11); - myMetric.setEigen (1,0.,1.,0.,q22); - myMetric.setEigen (2,0.,0.,1.,q11); - myMetric.setMetric(); - } - else if (a->c) - { - double xx=0.0,yy=0.0,zz=0.0; - if (metr.Pos.X != 0.0 || metr.Pos.Y != 0.0) - zz = 1.0; - else if (metr.Pos.Y == 0.0) - yy = 1.0; - else - xx = 1.0; - - Vertex z (xx, yy, zz); - Vertex d2 = metr % z; - metr.norme (); - d2.norme (); - Vertex d3 = metr % d2; - d3.norme (); - - myMetric.setEigen (0,metr.Pos.X,metr.Pos.Y,metr.Pos.Z,1./(x1*x1)); - myMetric.setEigen (1,d2.Pos.X,d2.Pos.Y,d2.Pos.Z,1./(x2*x2)); - myMetric.setEigen (2,d3.Pos.X,d3.Pos.Y,d3.Pos.Z,1./(x1*x1)); - myMetric.setMetric(); - /* - Msg(INFO,"%d %12.5E heigens : %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E \n ", a->c->Num,d, - metr.Pos.X, metr.Pos.Y, metr.Pos.Z, - d2.Pos.X,d2.Pos.Y,d2.Pos.Z, - d3.Pos.X,d3.Pos.Y,d3.Pos.Z); - - Msg(INFO,"heigenv : %12.5E %12.5E \n",x1,x2); - - Msg(INFO,"curve Metric: %g %g %g %g %g %g %g %g %g \n ", - myMetric[0][0], myMetric[0][1], myMetric[0][2], - myMetric[1][0], myMetric[1][1], myMetric[1][2], - myMetric[2][0], myMetric[2][1], myMetric[2][2]); - */ - } - Matrix3x3 *M[2]; - M[0] = &myMetric; - M[1] = &myOldMetric; - myOldMetric = Intersect2Metrics(M); - // myOldMetric = myMetric; - } + double u, x1, x2, d = 0.; + Vertex v1(X, Y, Z), v2, metr; + + Matrix3x3 myOldMetric(0., m); + + for(i = 0; i < List_Nbr(Attractors); i++) { + Matrix3x3 myMetric(0.); + List_Read(Attractors, i, &a); + if(a->v) { + d = sqrt((X - a->v->Pos.X) * (X - a->v->Pos.X) + + (Y - a->v->Pos.Y) * (Y - a->v->Pos.Y) + + (Z - a->v->Pos.Z) * (Z - a->v->Pos.Z)); + metr = Vertex(1., 0., 0.); + } + if(a->c) { + ProjectPointOnCurve(a->c, &v1, &v2, &metr); + d = sqrt((X - v2.Pos.X) * (X - v2.Pos.X) + + (Y - v2.Pos.Y) * (Y - v2.Pos.Y) + + (Z - v2.Pos.Z) * (Z - v2.Pos.Z)); + + } + double d1 = d * a->Radius; + if(fabs(d1) < a->Radius * 1.e-6) + d1 = 0.0; + u = exp(-(d1 * d1)); + x1 = (1. - u) + u * a->lc1; + x2 = (1. - u) + u * a->lc2; + // cout << " dist from "<< X << " " << Y << " = " << d << endl; + if(u > 1.e-2) { + if(a->v) { + double q11 = 1. / (x1 * x1); + double q22 = 1. / (x2 * x2); + //double q12 = 1. / (x1 * x2); + + myMetric.setEigen(0, 1., 0., 0., q11); + myMetric.setEigen(1, 0., 1., 0., q22); + myMetric.setEigen(2, 0., 0., 1., q11); + myMetric.setMetric(); + } + else if(a->c) { + double xx = 0.0, yy = 0.0, zz = 0.0; + if(metr.Pos.X != 0.0 || metr.Pos.Y != 0.0) + zz = 1.0; + else if(metr.Pos.Y == 0.0) + yy = 1.0; + else + xx = 1.0; + + Vertex z(xx, yy, zz); + Vertex d2 = metr % z; + metr.norme(); + d2.norme(); + Vertex d3 = metr % d2; + d3.norme(); + + myMetric.setEigen(0, metr.Pos.X, metr.Pos.Y, metr.Pos.Z, + 1. / (x1 * x1)); + myMetric.setEigen(1, d2.Pos.X, d2.Pos.Y, d2.Pos.Z, 1. / (x2 * x2)); + myMetric.setEigen(2, d3.Pos.X, d3.Pos.Y, d3.Pos.Z, 1. / (x1 * x1)); + myMetric.setMetric(); + /* + Msg(INFO,"%d %12.5E heigens : %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E %12.5E \n ", a->c->Num,d, + metr.Pos.X, metr.Pos.Y, metr.Pos.Z, + d2.Pos.X,d2.Pos.Y,d2.Pos.Z, + d3.Pos.X,d3.Pos.Y,d3.Pos.Z); + + Msg(INFO,"heigenv : %12.5E %12.5E \n",x1,x2); + + Msg(INFO,"curve Metric: %g %g %g %g %g %g %g %g %g \n ", + myMetric[0][0], myMetric[0][1], myMetric[0][2], + myMetric[1][0], myMetric[1][1], myMetric[1][2], + myMetric[2][0], myMetric[2][1], myMetric[2][2]); + */ + } + Matrix3x3 *M[2]; + M[0] = &myMetric; + M[1] = &myOldMetric; + myOldMetric = Intersect2Metrics(M); + // myOldMetric = myMetric; } - myOldMetric.copy(m); + } + myOldMetric.copy(m); return 1.0; } -void GMSHMetric:: -setMetric (double u, - double v, - Surface * s) +void GMSHMetric:: setMetric(double u, double v, Surface * s) { - double a, b, c; // ellipse axx+byy+cxy=1 - double l1, l2; // 2 eigenvalues - - Identity (); - Vertex p = InterpolateSurface (s, u, v, 0, 0); - if (s->Typ != MSH_SURF_PLAN && s->Typ != MSH_SURF_REGL && s->Typ != MSH_SURF_TRIC) - { - Vertex du = InterpolateSurface (s, u, v, 1, 1); - Vertex dv = InterpolateSurface (s, u, v, 1, 2); - - a = du * du; - b = dv * dv; - c = du * dv; - - m[0][0] = a; - m[1][1] = b; + double a, b, c; // ellipse axx+byy+cxy=1 + double l1, l2; // 2 eigenvalues + + Identity(); + Vertex p = InterpolateSurface(s, u, v, 0, 0); + if(s->Typ != MSH_SURF_PLAN && s->Typ != MSH_SURF_REGL + && s->Typ != MSH_SURF_TRIC) { + Vertex du = InterpolateSurface(s, u, v, 1, 1); + Vertex dv = InterpolateSurface(s, u, v, 1, 2); + + a = du * du; + b = dv * dv; + c = du * dv; + + m[0][0] = a; + m[1][1] = b; + m[0][1] = c; + m[1][0] = c; + + l1 = 0.5 * ((a + b) + sqrt((a - b) * (a - b) + 4. * c * c)); + l2 = 0.5 * ((a + b) - sqrt((a - b) * (a - b) + 4. * c * c)); + + if(l1 == 0.0 && l2 == 0.0) + Identity(); + + else if(sqrt(l1 / l2) > limite_aniso) { + // on limite les rapports de metrique a limite_ansio + double r = limite_aniso * limite_aniso * (l2 / l1); + m[0][0] = a / r; + m[1][1] = b * r; m[0][1] = c; m[1][0] = c; - - l1 = 0.5 * ((a + b) + sqrt ((a - b) * (a - b) + 4. * c * c)); - l2 = 0.5 * ((a + b) - sqrt ((a - b) * (a - b) + 4. * c * c)); - - if (l1 == 0.0 && l2 == 0.0) - Identity (); - - else if (sqrt (l1 / l2) > limite_aniso) - { - // on limite les rapports de metrique a limite_ansio - double r = limite_aniso * limite_aniso * (l2 / l1); - m[0][0] = a / r; - m[1][1] = b * r; - m[0][1] = c; - m[1][0] = c; - } } - Local_Metric_Of_Attractors (p.Pos.X, p.Pos.Y, p.Pos.Z, NULL); + } + Local_Metric_Of_Attractors(p.Pos.X, p.Pos.Y, p.Pos.Z, NULL); return; } -void GMSHMetric:: -setMetric (double x, - double y, - double z) +void GMSHMetric:: setMetric(double x, double y, double z) { - Identity (); - Local_Metric_Of_Attractors (x, y, z, NULL); + Identity(); + Local_Metric_Of_Attractors(x, y, z, NULL); return; } -void GMSHMetric:: -setMetricMin (double u, - double v, - Surface * s) +void GMSHMetric:: setMetricMin(double u, double v, Surface * s) { /*setMetric(u,v,s); return; */ - Identity (); - if (s->Typ != MSH_SURF_PLAN && s->Typ != MSH_SURF_REGL && s->Typ != MSH_SURF_TRIC) - { - Vertex du = InterpolateSurface (s, u, v, 1, 1); - Vertex dv = InterpolateSurface (s, u, v, 1, 2); - double d = (du * du > dv * dv) ? du * du : dv * dv; - m[0][0] = d; - m[1][1] = d; - } + Identity(); + if(s->Typ != MSH_SURF_PLAN && s->Typ != MSH_SURF_REGL + && s->Typ != MSH_SURF_TRIC) { + Vertex du = InterpolateSurface(s, u, v, 1, 1); + Vertex dv = InterpolateSurface(s, u, v, 1, 2); + double d = (du * du > dv * dv) ? du * du : dv * dv; + m[0][0] = d; + m[1][1] = d; + } return; } -double GMSHMetric:: -getWorstEdge (Simplex * s, Surface * surf, Vertex * v[2]) +double GMSHMetric:: getWorstEdge(Simplex * s, Surface * surf, Vertex * v[2]) { double l1, l2, l3, q1, q2, q3; v[0] = s->V[0]; v[1] = s->V[1]; - l1 = EdgeLengthOnSurface (surf, v, 1); + l1 = EdgeLengthOnSurface(surf, v, 1); v[0] = s->V[0]; v[1] = s->V[2]; - l2 = EdgeLengthOnSurface (surf, v, 1); + l2 = EdgeLengthOnSurface(surf, v, 1); v[0] = s->V[1]; v[1] = s->V[2]; - l3 = EdgeLengthOnSurface (surf, v, 1); + l3 = EdgeLengthOnSurface(surf, v, 1); q1 = 2. * l1 / (s->V[0]->lc + s->V[1]->lc); q2 = 2. * l2 / (s->V[0]->lc + s->V[2]->lc); q3 = 2. * l3 / (s->V[1]->lc + s->V[2]->lc); - if (q1 >= q2 && q1 >= q3) - { - v[0] = s->V[0]; - v[1] = s->V[1]; - return l1; - } - else if (q2 >= q3) - { - v[0] = s->V[0]; - v[1] = s->V[2]; - return l2; - } + if(q1 >= q2 && q1 >= q3) { + v[0] = s->V[0]; + v[1] = s->V[1]; + return l1; + } + else if(q2 >= q3) { + v[0] = s->V[0]; + v[1] = s->V[2]; + return l2; + } return l3; } -void GMSHMetric:: -setSimplexQuality (Simplex * s, Surface * surf) +void GMSHMetric:: setSimplexQuality(Simplex * s, Surface * surf) { - if (quality_measure == QUALITY_EDGES_BASED) - { - Vertex *v[2], vv; - double l1, l2, l3, q1, q2, q3; - v[0] = s->V[0]; - v[1] = s->V[1]; - vv = (*v[1]) - (*v[0]); - l1 = LengthVector (&vv); - v[0] = s->V[0]; - v[1] = s->V[2]; - vv = (*v[1]) - (*v[0]); - l2 = LengthVector (&vv); - v[0] = s->V[1]; - v[1] = s->V[2]; - vv = (*v[1]) - (*v[0]); - l3 = LengthVector (&vv); - - q1 = 2. * l1 / (s->V[0]->lc + s->V[1]->lc); - q2 = 2. * l2 / (s->V[0]->lc + s->V[2]->lc); - q3 = 2. * l3 / (s->V[1]->lc + s->V[2]->lc); - - s->Quality = DMAX (DMAX (q1, q2), q3) / (RacineDeTrois); - } - else - { - /* - Matrix3x3 myOldMetric (0.,m); - Identity(); - Local_Metric_Of_Attractors (s->V[0]->Pos.X,s->V[0]->Pos.Y,s->V[0]->Pos.Z,0); - Local_Metric_Of_Attractors (s->V[1]->Pos.X,s->V[1]->Pos.Y,s->V[1]->Pos.Z,0); - Local_Metric_Of_Attractors (s->V[2]->Pos.X,s->V[2]->Pos.Y,s->V[2]->Pos.Z,0); - */ - s->Center_Ellipsum_2D (m); - s->Quality = 3. * s->Radius / (s->V[0]->lc + s->V[1]->lc + s->V[2]->lc); - } + if(quality_measure == QUALITY_EDGES_BASED) { + Vertex *v[2], vv; + double l1, l2, l3, q1, q2, q3; + v[0] = s->V[0]; + v[1] = s->V[1]; + vv = (*v[1]) - (*v[0]); + l1 = LengthVector(&vv); + v[0] = s->V[0]; + v[1] = s->V[2]; + vv = (*v[1]) - (*v[0]); + l2 = LengthVector(&vv); + v[0] = s->V[1]; + v[1] = s->V[2]; + vv = (*v[1]) - (*v[0]); + l3 = LengthVector(&vv); + + q1 = 2. * l1 / (s->V[0]->lc + s->V[1]->lc); + q2 = 2. * l2 / (s->V[0]->lc + s->V[2]->lc); + q3 = 2. * l3 / (s->V[1]->lc + s->V[2]->lc); + + s->Quality = DMAX(DMAX(q1, q2), q3) / (RacineDeTrois); + } + else { + /* + Matrix3x3 myOldMetric (0.,m); + Identity(); + Local_Metric_Of_Attractors (s->V[0]->Pos.X,s->V[0]->Pos.Y,s->V[0]->Pos.Z,0); + Local_Metric_Of_Attractors (s->V[1]->Pos.X,s->V[1]->Pos.Y,s->V[1]->Pos.Z,0); + Local_Metric_Of_Attractors (s->V[2]->Pos.X,s->V[2]->Pos.Y,s->V[2]->Pos.Z,0); + */ + s->Center_Ellipsum_2D(m); + s->Quality = 3. * s->Radius / (s->V[0]->lc + s->V[1]->lc + s->V[2]->lc); + } } -void GMSHMetric:: -setSimplexQuality (Simplex * s) +void GMSHMetric:: setSimplexQuality(Simplex * s) { - if (quality_measure == QUALITY_EDGES_BASED) - { - Vertex *v[2], vv; - double l1, l2, l3, l4, l5, l6, q1, q2, q3, q4, q5, q6; - v[0] = s->V[0]; - v[1] = s->V[1]; - vv = (*v[1]) - (*v[0]); - l1 = LengthVector (&vv); - v[0] = s->V[0]; - v[1] = s->V[2]; - vv = (*v[1]) - (*v[0]); - l2 = LengthVector (&vv); - v[0] = s->V[1]; - v[1] = s->V[2]; - vv = (*v[1]) - (*v[0]); - l3 = LengthVector (&vv); - v[0] = s->V[0]; - v[1] = s->V[3]; - vv = (*v[1]) - (*v[0]); - l4 = LengthVector (&vv); - v[0] = s->V[1]; - v[1] = s->V[3]; - vv = (*v[1]) - (*v[0]); - l5 = LengthVector (&vv); - v[0] = s->V[2]; - v[1] = s->V[3]; - vv = (*v[1]) - (*v[0]); - l6 = LengthVector (&vv); - - q1 = 2. * l1 / (s->V[0]->lc + s->V[1]->lc); - q2 = 2. * l2 / (s->V[0]->lc + s->V[2]->lc); - q3 = 2. * l3 / (s->V[1]->lc + s->V[2]->lc); - q4 = 2. * l4 / (s->V[0]->lc + s->V[3]->lc); - q5 = 2. * l5 / (s->V[1]->lc + s->V[3]->lc); - q6 = 2. * l6 / (s->V[2]->lc + s->V[3]->lc); - - //s->Quality = (0.5/6.)*(q1+q2+q3+q4+q5+q6); - - //double qmax = (DMAX (q1, DMAX (q2, DMAX (q3, DMAX (q4, DMAX (q5, q6)))))); - - s->Quality = (q1 + q2 + q3 + q4 + q5 + q6) / (6. * RacineDeDeux); - } - else - { - //double x = (s->V[0]->Pos.X + s->V[1]->Pos.X + s->V[2]->Pos.X + s->V[3]->Pos.X) / 4.; - //double y = (s->V[0]->Pos.Y + s->V[1]->Pos.Y + s->V[2]->Pos.Y + s->V[3]->Pos.Y) / 4.; - // double z = (s->V[0]->Pos.Z + s->V[1]->Pos.Z + s->V[2]->Pos.Z + s->V[3]->Pos.Z) / 4.; - // setMetric(x,y,z); - s->Center_Ellipsum_3D (m); - s->Quality = 4. * s->Radius / (s->V[0]->lc + s->V[1]->lc + s->V[2]->lc + s->V[3]->lc); - } + if(quality_measure == QUALITY_EDGES_BASED) { + Vertex *v[2], vv; + double l1, l2, l3, l4, l5, l6, q1, q2, q3, q4, q5, q6; + v[0] = s->V[0]; + v[1] = s->V[1]; + vv = (*v[1]) - (*v[0]); + l1 = LengthVector(&vv); + v[0] = s->V[0]; + v[1] = s->V[2]; + vv = (*v[1]) - (*v[0]); + l2 = LengthVector(&vv); + v[0] = s->V[1]; + v[1] = s->V[2]; + vv = (*v[1]) - (*v[0]); + l3 = LengthVector(&vv); + v[0] = s->V[0]; + v[1] = s->V[3]; + vv = (*v[1]) - (*v[0]); + l4 = LengthVector(&vv); + v[0] = s->V[1]; + v[1] = s->V[3]; + vv = (*v[1]) - (*v[0]); + l5 = LengthVector(&vv); + v[0] = s->V[2]; + v[1] = s->V[3]; + vv = (*v[1]) - (*v[0]); + l6 = LengthVector(&vv); + + q1 = 2. * l1 / (s->V[0]->lc + s->V[1]->lc); + q2 = 2. * l2 / (s->V[0]->lc + s->V[2]->lc); + q3 = 2. * l3 / (s->V[1]->lc + s->V[2]->lc); + q4 = 2. * l4 / (s->V[0]->lc + s->V[3]->lc); + q5 = 2. * l5 / (s->V[1]->lc + s->V[3]->lc); + q6 = 2. * l6 / (s->V[2]->lc + s->V[3]->lc); + + //s->Quality = (0.5/6.)*(q1+q2+q3+q4+q5+q6); + + //double qmax = (DMAX (q1, DMAX (q2, DMAX (q3, DMAX (q4, DMAX (q5, q6)))))); + + s->Quality = (q1 + q2 + q3 + q4 + q5 + q6) / (6. * RacineDeDeux); + } + else { + //double x = (s->V[0]->Pos.X + s->V[1]->Pos.X + s->V[2]->Pos.X + s->V[3]->Pos.X) / 4.; + //double y = (s->V[0]->Pos.Y + s->V[1]->Pos.Y + s->V[2]->Pos.Y + s->V[3]->Pos.Y) / 4.; + // double z = (s->V[0]->Pos.Z + s->V[1]->Pos.Z + s->V[2]->Pos.Z + s->V[3]->Pos.Z) / 4.; + // setMetric(x,y,z); + s->Center_Ellipsum_3D(m); + s->Quality = + 4. * s->Radius / (s->V[0]->lc + s->V[1]->lc + s->V[2]->lc + + s->V[3]->lc); + } } double GMSHMetric::operator () (int i, int j) @@ -451,79 +423,74 @@ double GMSHMetric::operator () (int i, int j) double *GMSHMetric::operator[] (int i) { - if (i < 0 || i > 3) + if(i < 0 || i > 3) return m[0]; return m[i]; } -void GMSHMetric:: -Identity () +void GMSHMetric:: Identity() { m[0][0] = m[1][1] = m[2][2] = 1.0; m[1][0] = m[1][2] = m[0][1] = 0.0; m[2][0] = m[2][1] = m[0][2] = 0.0; } -void GMSHMetric:: -setMetric (double u, - Curve * c) +void GMSHMetric:: setMetric(double u, Curve * c) { - + ; } -double GMSHMetric:: -getLc (double u, Curve * c) +double GMSHMetric:: getLc(double u, Curve * c) { double l; - Identity (); - Vertex v = InterpolateCurve (c, u, 0); - Vertex du = InterpolateCurve (c, u, 1); - Local_Metric_Of_Attractors (v.Pos.X, v.Pos.Y, v.Pos.Z, NULL); - l = LengthVector (&du); + Identity(); + Vertex v = InterpolateCurve(c, u, 0); + Vertex du = InterpolateCurve(c, u, 1); + Local_Metric_Of_Attractors(v.Pos.X, v.Pos.Y, v.Pos.Z, NULL); + l = LengthVector(&du); /* - Msg(INFO,"GetLC : u = %g l=%g lc=%g return=%g\n", u, l, v.lc, l/v.lc); - Msg(INFO,"Metric: %g %g %g %g %g %g %g %g %g \n ", - m[0][0], m[0][1], m[0][2], - m[1][0], m[1][1], m[1][2], - m[2][0], m[2][1], m[2][2]); - Msg(INFO,"du = %g %g %g\n",du.Pos.X,du.Pos.Y,du.Pos.Z); - */ + Msg(INFO,"GetLC : u = %g l=%g lc=%g return=%g\n", u, l, v.lc, l/v.lc); + Msg(INFO,"Metric: %g %g %g %g %g %g %g %g %g \n ", + m[0][0], m[0][1], m[0][2], + m[1][0], m[1][1], m[1][2], + m[2][0], m[2][1], m[2][2]); + Msg(INFO,"du = %g %g %g\n",du.Pos.X,du.Pos.Y,du.Pos.Z); + */ return l / v.lc; } -double GMSHMetric:: -LengthVector (Vertex * v) +double GMSHMetric:: LengthVector(Vertex * v) { - double qqq = v->Pos.X * (v->Pos.X * m[0][0] + v->Pos.Y * m[0][1] + v->Pos.Z * m[0][2]) + - v->Pos.Y * (v->Pos.X * m[1][0] + v->Pos.Y * m[1][1] + v->Pos.Z * m[1][2]) + + double qqq = + v->Pos.X * (v->Pos.X * m[0][0] + v->Pos.Y * m[0][1] + + v->Pos.Z * m[0][2]) + v->Pos.Y * (v->Pos.X * m[1][0] + + v->Pos.Y * m[1][1] + + v->Pos.Z * m[1][2]) + v->Pos.Z * (v->Pos.X * m[2][0] + v->Pos.Y * m[2][1] + v->Pos.Z * m[2][2]); // Msg(INFO,"qqq = %g\n",qqq); - return sqrt (qqq); + return sqrt(qqq); } -double GMSHMetric:: -EdgeLengthOnSurface (Surface * s, Vertex * v[2], int cuts) +double GMSHMetric:: EdgeLengthOnSurface(Surface * s, Vertex * v[2], int cuts) { Vertex dv; - if (!s) - { - dv = (*v[1]) - (*v[0]); - return LengthVector (&dv); - } + if(!s) { + dv = (*v[1]) - (*v[0]); + return LengthVector(&dv); + } - dv.Pos.X = (v[1]->Pos.X - v[0]->Pos.X) / (double) cuts; - dv.Pos.Y = (v[1]->Pos.Y - v[0]->Pos.Y) / (double) cuts; + dv.Pos.X = (v[1]->Pos.X - v[0]->Pos.X) / (double)cuts; + dv.Pos.Y = (v[1]->Pos.Y - v[0]->Pos.Y) / (double)cuts; double l = 0.0, posu, posv; - for (int i = 0; i < cuts; i++) - { - posu = v[0]->Pos.X + dv.Pos.X * ((double) (i) + 0.5); - posv = v[0]->Pos.Y + dv.Pos.Y * ((double) (i) + 0.5); - setMetric (posu, posv, s); - l += LengthVector (&dv); - } + for(int i = 0; i < cuts; i++) { + posu = v[0]->Pos.X + dv.Pos.X * ((double)(i) + 0.5); + posv = v[0]->Pos.Y + dv.Pos.Y * ((double)(i) + 0.5); + setMetric(posu, posv, s); + l += LengthVector(&dv); + } return l; } diff --git a/Mesh/Nurbs.cpp b/Mesh/Nurbs.cpp index 35a336f8f25abd4fa082e8a4c88eca7c27e67ff5..b261660c11946c1f472d23ea1170e734910a5332 100644 --- a/Mesh/Nurbs.cpp +++ b/Mesh/Nurbs.cpp @@ -1,4 +1,4 @@ -// $Id: Nurbs.cpp,v 1.11 2003-01-23 20:19:22 geuzaine Exp $ +// $Id: Nurbs.cpp,v 1.12 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -24,121 +24,123 @@ // Cubic spline -Vertex InterpolateCubicSpline (Vertex * v[4], double t, double mat[4][4], - int derivee, double t1, double t2){ +Vertex InterpolateCubicSpline(Vertex * v[4], double t, double mat[4][4], + int derivee, double t1, double t2) +{ Vertex V; int i, j; double vec[4], T[4]; V.Pos.X = V.Pos.Y = V.Pos.Z = 0.0; - V.lc = (1-t) * v[1]->lc + t * v[2]->lc; - V.w = (1-t) * v[1]->w + t * v[2]->w; + V.lc = (1 - t) * v[1]->lc + t * v[2]->lc; + V.w = (1 - t) * v[1]->w + t * v[2]->w; - if (derivee){ + if(derivee) { T[3] = 0.; T[2] = 1.; T[1] = 2. * t; T[0] = 3. * t * t; } - else{ + else { T[3] = 1.; T[2] = t; T[1] = t * t; T[0] = t * t * t; } - for (i = 0; i < 4; i++){ + for(i = 0; i < 4; i++) { vec[i] = 0.0; } - + /* X */ - for (i = 0; i < 4; i++){ - for (j = 0; j < 4; j++){ - vec[i] += mat[i][j] * v[j]->Pos.X; - } + for(i = 0; i < 4; i++) { + for(j = 0; j < 4; j++) { + vec[i] += mat[i][j] * v[j]->Pos.X; + } } - for (j = 0; j < 4; j++){ + for(j = 0; j < 4; j++) { V.Pos.X += T[j] * vec[j]; vec[j] = 0.0; } /* Y */ - for (i = 0; i < 4; i++){ - for (j = 0; j < 4; j++){ + for(i = 0; i < 4; i++) { + for(j = 0; j < 4; j++) { vec[i] += mat[i][j] * v[j]->Pos.Y; } } - - for (j = 0; j < 4; j++){ + + for(j = 0; j < 4; j++) { V.Pos.Y += T[j] * vec[j]; vec[j] = 0.0; } - + /* Z */ - for (i = 0; i < 4; i++){ - for (j = 0; j < 4; j++){ + for(i = 0; i < 4; i++) { + for(j = 0; j < 4; j++) { vec[i] += mat[i][j] * v[j]->Pos.Z; } } - for (j = 0; j < 4; j++){ + for(j = 0; j < 4; j++) { V.Pos.Z += T[j] * vec[j]; vec[j] = 0.0; } - - if (derivee){ + + if(derivee) { V.Pos.X /= ((t2 - t1)); V.Pos.Y /= ((t2 - t1)); V.Pos.Z /= ((t2 - t1)); } - + return V; } // Uniform BSplines -Vertex InterpolateUBS (Curve * Curve, double u, int derivee){ - +Vertex InterpolateUBS(Curve * Curve, double u, int derivee) +{ int NbControlPoints, NbCurves, iCurve; double t, t1, t2; Vertex *v[4]; - NbControlPoints = List_Nbr (Curve->Control_Points); + NbControlPoints = List_Nbr(Curve->Control_Points); NbCurves = NbControlPoints - 3; - iCurve = (int) (u * (double) NbCurves) + 1; + iCurve = (int)(u * (double)NbCurves) + 1; - if (iCurve > NbCurves) + if(iCurve > NbCurves) iCurve = NbCurves; - t1 = (double) (iCurve - 1) / (double) (NbCurves); - t2 = (double) (iCurve) / (double) (NbCurves); + t1 = (double)(iCurve - 1) / (double)(NbCurves); + t2 = (double)(iCurve) / (double)(NbCurves); t = (u - t1) / (t2 - t1); - List_Read (Curve->Control_Points, iCurve - 1, &v[0]); - List_Read (Curve->Control_Points, iCurve, &v[1]); - List_Read (Curve->Control_Points, iCurve + 1, &v[2]); - List_Read (Curve->Control_Points, iCurve + 2, &v[3]); + List_Read(Curve->Control_Points, iCurve - 1, &v[0]); + List_Read(Curve->Control_Points, iCurve, &v[1]); + List_Read(Curve->Control_Points, iCurve + 1, &v[2]); + List_Read(Curve->Control_Points, iCurve + 2, &v[3]); - return InterpolateCubicSpline (v, t, Curve->mat, derivee, t1, t2); + return InterpolateCubicSpline(v, t, Curve->mat, derivee, t1, t2); } // Non Uniform BSplines -int findSpan (double u, int deg, int n, float *U){ - if (u >= U[n]) +int findSpan(double u, int deg, int n, float *U) +{ + if(u >= U[n]) return n - 1; - if (u <= U[0]) + if(u <= U[0]) return deg; int low = deg; int high = n + 1; int mid = (low + high) / 2; - while (u < U[mid] || u >= U[mid + 1]){ - if (u < U[mid]) + while(u < U[mid] || u >= U[mid + 1]) { + if(u < U[mid]) high = mid; else low = mid; @@ -147,8 +149,8 @@ int findSpan (double u, int deg, int n, float *U){ return mid; } -void basisFuns (double u, int i, int deg, float *U, double *N){ - +void basisFuns(double u, int i, int deg, float *U, double *N) +{ double left[1000]; double *right = &left[deg + 1]; @@ -157,11 +159,11 @@ void basisFuns (double u, int i, int deg, float *U, double *N){ //N.resize(deg+1) ; N[0] = 1.0; - for (int j = 1; j <= deg; j++){ + for(int j = 1; j <= deg; j++) { left[j] = u - U[i + 1 - j]; right[j] = U[i + j] - u; saved = 0.0; - for (int r = 0; r < j; r++){ + for(int r = 0; r < j; r++) { temp = N[r] / (right[r + 1] + left[j - r]); N[r] = saved + right[r + 1] * temp; saved = left[j - r] * temp; @@ -170,15 +172,17 @@ void basisFuns (double u, int i, int deg, float *U, double *N){ } } -Vertex InterpolateNurbs (Curve * Curve, double u, int derivee){ +Vertex InterpolateNurbs(Curve * Curve, double u, int derivee) +{ static double Nb[1000]; - int span = findSpan (u, Curve->degre, List_Nbr (Curve->Control_Points), Curve->k); + int span = + findSpan(u, Curve->degre, List_Nbr(Curve->Control_Points), Curve->k); Vertex p, *v; - basisFuns (u, span, Curve->degre, Curve->k, Nb); + basisFuns(u, span, Curve->degre, Curve->k, Nb); p.Pos.X = p.Pos.Y = p.Pos.Z = p.w = p.lc = 0.0; - for (int i = Curve->degre; i >= 0; --i){ - List_Read (Curve->Control_Points, span - Curve->degre + i, &v); + for(int i = Curve->degre; i >= 0; --i) { + List_Read(Curve->Control_Points, span - Curve->degre + i, &v); p.Pos.X += Nb[i] * v->Pos.X; p.Pos.Y += Nb[i] * v->Pos.Y; p.Pos.Z += Nb[i] * v->Pos.Z; @@ -188,22 +192,24 @@ Vertex InterpolateNurbs (Curve * Curve, double u, int derivee){ return p; } -Vertex InterpolateNurbsSurface (Surface * s, double u, double v){ - int uspan = findSpan (u, s->OrderU, s->Nu, s->ku); - int vspan = findSpan (v, s->OrderV, s->Nv, s->kv); +Vertex InterpolateNurbsSurface(Surface * s, double u, double v) +{ + int uspan = findSpan(u, s->OrderU, s->Nu, s->ku); + int vspan = findSpan(v, s->OrderV, s->Nv, s->kv); double Nu[1000], Nv[1000]; Vertex sp, temp[1000], *pv; - basisFuns (u, uspan, s->OrderU, s->ku, Nu); - basisFuns (v, vspan, s->OrderV, s->kv, Nv); + basisFuns(u, uspan, s->OrderU, s->ku, Nu); + basisFuns(v, vspan, s->OrderV, s->kv, Nv); int l, ll, kk; - for (l = 0; l <= s->OrderV; l++){ - temp[l].Pos.X = temp[l].Pos.Y = temp[l].Pos.Z = temp[l].w = temp[l].lc = 0.0; - for (int k = 0; k <= s->OrderU; k++){ + for(l = 0; l <= s->OrderV; l++) { + temp[l].Pos.X = temp[l].Pos.Y = temp[l].Pos.Z = temp[l].w = temp[l].lc = + 0.0; + for(int k = 0; k <= s->OrderU; k++) { kk = uspan - s->OrderU + k; ll = vspan - s->OrderV + l; - List_Read (s->Control_Points, kk + s->Nu * ll, &pv); + List_Read(s->Control_Points, kk + s->Nu * ll, &pv); temp[l].Pos.X += Nu[k] * pv->Pos.X; temp[l].Pos.Y += Nu[k] * pv->Pos.Y; temp[l].Pos.Z += Nu[k] * pv->Pos.Z; @@ -212,7 +218,7 @@ Vertex InterpolateNurbsSurface (Surface * s, double u, double v){ } } sp.Pos.X = sp.Pos.Y = sp.Pos.Z = sp.w = sp.lc = 0.0; - for (l = 0; l <= s->OrderV; l++){ + for(l = 0; l <= s->OrderV; l++) { sp.Pos.X += Nv[l] * temp[l].Pos.X; sp.Pos.Y += Nv[l] * temp[l].Pos.Y; sp.Pos.Z += Nv[l] * temp[l].Pos.Z; diff --git a/Mesh/Print_Mesh.cpp b/Mesh/Print_Mesh.cpp index f41516f927ef7806f0e5ce48a0d9e59edd851d1c..9149a799d6d9ec9fd63a447b91910965873246d9 100644 --- a/Mesh/Print_Mesh.cpp +++ b/Mesh/Print_Mesh.cpp @@ -1,4 +1,4 @@ -// $Id: Print_Mesh.cpp,v 1.38 2003-01-23 20:19:22 geuzaine Exp $ +// $Id: Print_Mesh.cpp,v 1.39 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -27,7 +27,7 @@ #include "Create.h" #include "Context.h" -extern Context_T CTX ; +extern Context_T CTX; // M S H F O R M A T @@ -52,105 +52,108 @@ static int MSH_VOL_NUM, MSH_SUR_NUM, MSH_LIN_NUM; static int MSH_NODE_NUM, MSH_ELEMENT_NUM, MSH_3D, MSH_ADD; static int MSH_PHYSICAL_NUM, MSH_PHYSICAL_ORI; -void print_msh_node (void *a, void *b){ +void print_msh_node(void *a, void *b) +{ Vertex **V; V = (Vertex **) a; - fprintf (mshfile, "%d %.16g %.16g %.16g\n", - (*V)->Num, - (*V)->Pos.X * CTX.mesh.scaling_factor, - (*V)->Pos.Y * CTX.mesh.scaling_factor, - (*V)->Pos.Z * CTX.mesh.scaling_factor); + fprintf(mshfile, "%d %.16g %.16g %.16g\n", + (*V)->Num, + (*V)->Pos.X * CTX.mesh.scaling_factor, + (*V)->Pos.Y * CTX.mesh.scaling_factor, + (*V)->Pos.Z * CTX.mesh.scaling_factor); } -void process_msh_nodes (Mesh * M){ +void process_msh_nodes(Mesh * M) +{ int i, j, Num; PhysicalGroup *p; Vertex *pv, **ppv, v; - for (i = 0; i < List_Nbr (M->PhysicalGroups); i++){ - List_Read (M->PhysicalGroups, i, &p); - if(p->Typ == MSH_PHYSICAL_POINT){ - for (j = 0; j < List_Nbr (p->Entities); j++){ - List_Read (p->Entities, j, &Num); + for(i = 0; i < List_Nbr(M->PhysicalGroups); i++) { + List_Read(M->PhysicalGroups, i, &p); + if(p->Typ == MSH_PHYSICAL_POINT) { + for(j = 0; j < List_Nbr(p->Entities); j++) { + List_Read(p->Entities, j, &Num); pv = &v; pv->Num = abs(Num); - if(!Tree_Search(M->Vertices, &pv)){ - if((ppv = (Vertex**)Tree_PQuery(M->Points, &pv))) - Tree_Add(M->Vertices, ppv); - } + if(!Tree_Search(M->Vertices, &pv)) { + if((ppv = (Vertex **) Tree_PQuery(M->Points, &pv))) + Tree_Add(M->Vertices, ppv); + } } } } - MSH_NODE_NUM = Tree_Nbr (M->Vertices) + Tree_Nbr (M->VertexEdges); + MSH_NODE_NUM = Tree_Nbr(M->Vertices) + Tree_Nbr(M->VertexEdges); - fprintf (mshfile, "$NOD\n"); - fprintf (mshfile, "%d\n", MSH_NODE_NUM); - Tree_Action (M->Vertices, print_msh_node); - Tree_Action (M->VertexEdges, print_msh_node); - fprintf (mshfile, "$ENDNOD\n"); + fprintf(mshfile, "$NOD\n"); + fprintf(mshfile, "%d\n", MSH_NODE_NUM); + Tree_Action(M->Vertices, print_msh_node); + Tree_Action(M->VertexEdges, print_msh_node); + fprintf(mshfile, "$ENDNOD\n"); } -void print_msh_simplex (void *a, void *b){ +void print_msh_simplex(void *a, void *b) +{ Simplex **S; int i, type, nbn, nbs = 0; S = (Simplex **) a; - if (MSH_VOL_NUM && (MSH_VOL_NUM != (*S)->iEnt)) + if(MSH_VOL_NUM && (MSH_VOL_NUM != (*S)->iEnt)) return; - if (MSH_SUR_NUM && (MSH_SUR_NUM != (*S)->iEnt)) + if(MSH_SUR_NUM && (MSH_SUR_NUM != (*S)->iEnt)) return; - if (MSH_LIN_NUM && (MSH_LIN_NUM != (*S)->iEnt)) + if(MSH_LIN_NUM && (MSH_LIN_NUM != (*S)->iEnt)) return; - if (!MSH_ADD){ + if(!MSH_ADD) { MSH_ELEMENT_NUM++; return; } - if (!(*S)->V[2]){ + if(!(*S)->V[2]) { nbn = 2; - if ((*S)->VSUP){ + if((*S)->VSUP) { type = LINE_2; nbs = 1; } else type = LINE; } - else if (!(*S)->V[3]){ + else if(!(*S)->V[3]) { nbn = 3; - if ((*S)->VSUP){ + if((*S)->VSUP) { type = TRIANGLE_2; nbs = 3; } else type = TRIANGLE; } - else{ + else { nbn = 4; - if (!MSH_3D){ - if ((*S)->VSUP){ + if(!MSH_3D) { + if((*S)->VSUP) { type = QUADRANGLE_2; nbs = 5; } else type = QUADRANGLE; } - else if ((*S)->VSUP){ + else if((*S)->VSUP) { type = TETRAHEDRON_2; nbs = 1; } else type = TETRAHEDRON; } - - if(type == TETRAHEDRON){ - if ((*S)->Volume_Simplexe () < 0){ + + if(type == TETRAHEDRON) { + if((*S)->Volume_Simplexe() < 0) { Vertex *temp; temp = (*S)->V[0]; (*S)->V[0] = (*S)->V[1]; @@ -158,152 +161,156 @@ void print_msh_simplex (void *a, void *b){ } } - fprintf (mshfile, "%d %d %d %d %d", - //MSH_PHYSICAL_NUM ? MSH_ELEMENT_NUM++ : (*S)->Num, type, - MSH_ELEMENT_NUM++, type, - MSH_PHYSICAL_NUM ? MSH_PHYSICAL_NUM : (*S)->iEnt, (*S)->iEnt, - nbn + nbs); - - if (MSH_PHYSICAL_ORI > 0){ - for (i = 0; i < nbn; i++) - fprintf (mshfile, " %d", (*S)->V[i]->Num); - for (i = 0; i < nbs; i++) - fprintf (mshfile, " %d", (*S)->VSUP[i]->Num); + fprintf(mshfile, "%d %d %d %d %d", + //MSH_PHYSICAL_NUM ? MSH_ELEMENT_NUM++ : (*S)->Num, type, + MSH_ELEMENT_NUM++, type, + MSH_PHYSICAL_NUM ? MSH_PHYSICAL_NUM : (*S)->iEnt, (*S)->iEnt, + nbn + nbs); + + if(MSH_PHYSICAL_ORI > 0) { + for(i = 0; i < nbn; i++) + fprintf(mshfile, " %d", (*S)->V[i]->Num); + for(i = 0; i < nbs; i++) + fprintf(mshfile, " %d", (*S)->VSUP[i]->Num); } - else{ - for (i = 0; i < nbn; i++) - fprintf (mshfile, " %d", (*S)->V[nbn - i - 1]->Num); - for (i = 0; i < nbs; i++) - fprintf (mshfile, " %d", (*S)->VSUP[nbs - i - 1]->Num); + else { + for(i = 0; i < nbn; i++) + fprintf(mshfile, " %d", (*S)->V[nbn - i - 1]->Num); + for(i = 0; i < nbs; i++) + fprintf(mshfile, " %d", (*S)->VSUP[nbs - i - 1]->Num); } - fprintf (mshfile, "\n"); + fprintf(mshfile, "\n"); } -void print_msh_hexahedron (void *a, void *b){ +void print_msh_hexahedron(void *a, void *b) +{ Hexahedron **H; int i, type, nbn, nbs = 0; H = (Hexahedron **) a; - if (MSH_VOL_NUM && (MSH_VOL_NUM != (*H)->iEnt)) + if(MSH_VOL_NUM && (MSH_VOL_NUM != (*H)->iEnt)) return; - if (!MSH_ADD){ + if(!MSH_ADD) { MSH_ELEMENT_NUM++; return; } nbn = 8; - if ((*H)->VSUP){ + if((*H)->VSUP) { type = HEXAHEDRON_2; nbs = 19; } else type = HEXAHEDRON; - fprintf (mshfile, "%d %d %d %d %d", - //MSH_PHYSICAL_NUM ? MSH_ELEMENT_NUM++ : (*H)->Num, type, - MSH_ELEMENT_NUM++, type, - MSH_PHYSICAL_NUM ? MSH_PHYSICAL_NUM : (*H)->iEnt, (*H)->iEnt, - nbn + nbs); + fprintf(mshfile, "%d %d %d %d %d", + //MSH_PHYSICAL_NUM ? MSH_ELEMENT_NUM++ : (*H)->Num, type, + MSH_ELEMENT_NUM++, type, + MSH_PHYSICAL_NUM ? MSH_PHYSICAL_NUM : (*H)->iEnt, (*H)->iEnt, + nbn + nbs); - for (i = 0; i < nbn; i++) - fprintf (mshfile, " %d", (*H)->V[i]->Num); - for (i = 0; i < nbs; i++) - fprintf (mshfile, " %d", (*H)->VSUP[i]->Num); + for(i = 0; i < nbn; i++) + fprintf(mshfile, " %d", (*H)->V[i]->Num); + for(i = 0; i < nbs; i++) + fprintf(mshfile, " %d", (*H)->VSUP[i]->Num); - fprintf (mshfile, "\n"); + fprintf(mshfile, "\n"); } -void print_msh_prism (void *a, void *b){ +void print_msh_prism(void *a, void *b) +{ Prism **P; int i, type, nbn, nbs = 0; P = (Prism **) a; - if (MSH_VOL_NUM && (MSH_VOL_NUM != (*P)->iEnt)) + if(MSH_VOL_NUM && (MSH_VOL_NUM != (*P)->iEnt)) return; - if (!MSH_ADD){ + if(!MSH_ADD) { MSH_ELEMENT_NUM++; return; } nbn = 6; - if ((*P)->VSUP){ + if((*P)->VSUP) { type = PRISM_2; nbs = 12; } - else{ + else { type = PRISM; } - fprintf (mshfile, "%d %d %d %d %d", - //MSH_PHYSICAL_NUM ? MSH_ELEMENT_NUM++ : (*P)->Num, type, - MSH_ELEMENT_NUM++, type, - MSH_PHYSICAL_NUM ? MSH_PHYSICAL_NUM : (*P)->iEnt, (*P)->iEnt, - nbn + nbs); + fprintf(mshfile, "%d %d %d %d %d", + //MSH_PHYSICAL_NUM ? MSH_ELEMENT_NUM++ : (*P)->Num, type, + MSH_ELEMENT_NUM++, type, + MSH_PHYSICAL_NUM ? MSH_PHYSICAL_NUM : (*P)->iEnt, (*P)->iEnt, + nbn + nbs); - for (i = 0; i < nbn; i++) - fprintf (mshfile, " %d", (*P)->V[i]->Num); - for (i = 0; i < nbs; i++) - fprintf (mshfile, " %d", (*P)->VSUP[i]->Num); + for(i = 0; i < nbn; i++) + fprintf(mshfile, " %d", (*P)->V[i]->Num); + for(i = 0; i < nbs; i++) + fprintf(mshfile, " %d", (*P)->VSUP[i]->Num); - fprintf (mshfile, "\n"); + fprintf(mshfile, "\n"); } -void print_msh_pyramid (void *a, void *b){ +void print_msh_pyramid(void *a, void *b) +{ Pyramid **P; int i, type, nbn, nbs = 0; P = (Pyramid **) a; - if (MSH_VOL_NUM && (MSH_VOL_NUM != (*P)->iEnt)) + if(MSH_VOL_NUM && (MSH_VOL_NUM != (*P)->iEnt)) return; - if (!MSH_ADD){ + if(!MSH_ADD) { MSH_ELEMENT_NUM++; return; } nbn = 5; - if ((*P)->VSUP){ + if((*P)->VSUP) { type = PYRAMID_2; nbs = 10; } - else{ + else { type = PYRAMID; } - fprintf (mshfile, "%d %d %d %d %d", - //MSH_PHYSICAL_NUM ? MSH_ELEMENT_NUM++ : (*P)->Num, type, - MSH_ELEMENT_NUM++, type, - MSH_PHYSICAL_NUM ? MSH_PHYSICAL_NUM : (*P)->iEnt, (*P)->iEnt, - nbn + nbs); + fprintf(mshfile, "%d %d %d %d %d", + //MSH_PHYSICAL_NUM ? MSH_ELEMENT_NUM++ : (*P)->Num, type, + MSH_ELEMENT_NUM++, type, + MSH_PHYSICAL_NUM ? MSH_PHYSICAL_NUM : (*P)->iEnt, (*P)->iEnt, + nbn + nbs); - for (i = 0; i < nbn; i++) - fprintf (mshfile, " %d", (*P)->V[i]->Num); - for (i = 0; i < nbs; i++) - fprintf (mshfile, " %d", (*P)->VSUP[i]->Num); + for(i = 0; i < nbn; i++) + fprintf(mshfile, " %d", (*P)->V[i]->Num); + for(i = 0; i < nbs; i++) + fprintf(mshfile, " %d", (*P)->VSUP[i]->Num); - fprintf (mshfile, "\n"); + fprintf(mshfile, "\n"); } -void print_msh_point (Vertex * V){ - - if (!MSH_ADD){ +void print_msh_point(Vertex * V) +{ + if(!MSH_ADD) { MSH_ELEMENT_NUM++; return; } - fprintf (mshfile, "%d %d %d %d 1 %d\n", - //MSH_PHYSICAL_NUM ? MSH_ELEMENT_NUM++ : V->Num, POINT, - MSH_ELEMENT_NUM++, POINT, - MSH_PHYSICAL_NUM ? MSH_PHYSICAL_NUM : V->Num, V->Num, V->Num); + fprintf(mshfile, "%d %d %d %d 1 %d\n", + //MSH_PHYSICAL_NUM ? MSH_ELEMENT_NUM++ : V->Num, POINT, + MSH_ELEMENT_NUM++, POINT, + MSH_PHYSICAL_NUM ? MSH_PHYSICAL_NUM : V->Num, V->Num, V->Num); } -void print_msh_elements (Mesh * M){ +void print_msh_elements(Mesh * M) +{ int i, j, k, Num; PhysicalGroup *p; @@ -312,92 +319,92 @@ void print_msh_elements (Mesh * M){ Curve *pc, c; Vertex *pv, v; - List_T *ListVolumes = Tree2List (M->Volumes); + List_T *ListVolumes = Tree2List(M->Volumes); - for (i = 0; i < List_Nbr (M->PhysicalGroups); i++){ - List_Read (M->PhysicalGroups, i, &p); + for(i = 0; i < List_Nbr(M->PhysicalGroups); i++) { + List_Read(M->PhysicalGroups, i, &p); MSH_PHYSICAL_NUM = p->Num; MSH_3D = 0; MSH_VOL_NUM = MSH_SUR_NUM = MSH_LIN_NUM = 0; - switch (p->Typ){ + switch (p->Typ) { case MSH_PHYSICAL_POINT: - for (j = 0; j < List_Nbr (p->Entities); j++){ + for(j = 0; j < List_Nbr(p->Entities); j++) { pv = &v; - List_Read (p->Entities, j, &Num); - pv->Num = abs (Num); - MSH_PHYSICAL_ORI = sign (Num); - if (Tree_Query (M->Vertices, &pv)) - print_msh_point (pv); + List_Read(p->Entities, j, &Num); + pv->Num = abs(Num); + MSH_PHYSICAL_ORI = sign(Num); + if(Tree_Query(M->Vertices, &pv)) + print_msh_point(pv); } break; case MSH_PHYSICAL_LINE: - if(CTX.mesh.oldxtrude){//for old extrusion mesh generator - for (k = 0; k < List_Nbr (ListVolumes); k++){ - List_Read (ListVolumes, k, &pV); - for (j = 0; j < List_Nbr (p->Entities); j++){ - List_Read (p->Entities, j, &Num); - MSH_LIN_NUM = abs (Num); - MSH_PHYSICAL_ORI = sign (Num); - Tree_Action (pV->Simp_Surf, print_msh_simplex); - } - } - break;//done + if(CTX.mesh.oldxtrude) { //for old extrusion mesh generator + for(k = 0; k < List_Nbr(ListVolumes); k++) { + List_Read(ListVolumes, k, &pV); + for(j = 0; j < List_Nbr(p->Entities); j++) { + List_Read(p->Entities, j, &Num); + MSH_LIN_NUM = abs(Num); + MSH_PHYSICAL_ORI = sign(Num); + Tree_Action(pV->Simp_Surf, print_msh_simplex); + } + } + break; //done } - - for (j = 0; j < List_Nbr (p->Entities); j++){ - pc = &c; - List_Read (p->Entities, j, &Num); - pc->Num = abs (Num); - MSH_PHYSICAL_ORI = sign (Num); - if (Tree_Query (M->Curves, &pc)) - Tree_Action (pc->Simplexes, print_msh_simplex); + + for(j = 0; j < List_Nbr(p->Entities); j++) { + pc = &c; + List_Read(p->Entities, j, &Num); + pc->Num = abs(Num); + MSH_PHYSICAL_ORI = sign(Num); + if(Tree_Query(M->Curves, &pc)) + Tree_Action(pc->Simplexes, print_msh_simplex); } break; - + case MSH_PHYSICAL_SURFACE: - if(CTX.mesh.oldxtrude){//for old extrusion mesh generator - for (k = 0; k < List_Nbr (ListVolumes); k++){ - List_Read (ListVolumes, k, &pV); - for (j = 0; j < List_Nbr (p->Entities); j++){ - List_Read (p->Entities, j, &Num); - MSH_SUR_NUM = abs (Num); - MSH_PHYSICAL_ORI = sign (Num); - Tree_Action (pV->Simp_Surf, print_msh_simplex); - } - } - break;//done + if(CTX.mesh.oldxtrude) { //for old extrusion mesh generator + for(k = 0; k < List_Nbr(ListVolumes); k++) { + List_Read(ListVolumes, k, &pV); + for(j = 0; j < List_Nbr(p->Entities); j++) { + List_Read(p->Entities, j, &Num); + MSH_SUR_NUM = abs(Num); + MSH_PHYSICAL_ORI = sign(Num); + Tree_Action(pV->Simp_Surf, print_msh_simplex); + } + } + break; //done } - - for (j = 0; j < List_Nbr (p->Entities); j++){ - ps = &s; - List_Read (p->Entities, j, &Num); - ps->Num = abs (Num); - MSH_PHYSICAL_ORI = sign (Num); - if (Tree_Query (M->Surfaces, &ps)) - Tree_Action (ps->Simplexes, print_msh_simplex); + + for(j = 0; j < List_Nbr(p->Entities); j++) { + ps = &s; + List_Read(p->Entities, j, &Num); + ps->Num = abs(Num); + MSH_PHYSICAL_ORI = sign(Num); + if(Tree_Query(M->Surfaces, &ps)) + Tree_Action(ps->Simplexes, print_msh_simplex); } break; - + case MSH_PHYSICAL_VOLUME: - for (k = 0; k < List_Nbr (ListVolumes); k++){ - List_Read (ListVolumes, k, &pV); - for (j = 0; j < List_Nbr (p->Entities); j++){ - List_Read (p->Entities, j, &Num); - MSH_3D = 1; - MSH_VOL_NUM = abs (Num); - MSH_PHYSICAL_ORI = sign (Num); - Tree_Action (pV->Simplexes, print_msh_simplex); - Tree_Action (pV->Hexahedra, print_msh_hexahedron); - Tree_Action (pV->Prisms, print_msh_prism); - Tree_Action (pV->Pyramids, print_msh_pyramid); + for(k = 0; k < List_Nbr(ListVolumes); k++) { + List_Read(ListVolumes, k, &pV); + for(j = 0; j < List_Nbr(p->Entities); j++) { + List_Read(p->Entities, j, &Num); + MSH_3D = 1; + MSH_VOL_NUM = abs(Num); + MSH_PHYSICAL_ORI = sign(Num); + Tree_Action(pV->Simplexes, print_msh_simplex); + Tree_Action(pV->Hexahedra, print_msh_hexahedron); + Tree_Action(pV->Prisms, print_msh_prism); + Tree_Action(pV->Pyramids, print_msh_pyramid); } } break; - - default : + + default: Msg(GERROR, "Unknown type of Physical group"); break; } @@ -406,39 +413,44 @@ void print_msh_elements (Mesh * M){ } -void print_all_msh_curves (void *a, void *b){ - Curve *c = *(Curve**)a; - Tree_Action (c->Simplexes, print_msh_simplex); +void print_all_msh_curves(void *a, void *b) +{ + Curve *c = *(Curve **) a; + Tree_Action(c->Simplexes, print_msh_simplex); } -void print_all_msh_surfaces (void *a, void *b){ - Surface *s = *(Surface**)a; - Tree_Action (s->Simplexes, print_msh_simplex); +void print_all_msh_surfaces(void *a, void *b) +{ + Surface *s = *(Surface **) a; + Tree_Action(s->Simplexes, print_msh_simplex); } -void print_all_msh_simpsurf (void *a, void *b){ - Volume *v = *(Volume**)a; - Tree_Action (v->Simp_Surf, print_msh_simplex); +void print_all_msh_simpsurf(void *a, void *b) +{ + Volume *v = *(Volume **) a; + Tree_Action(v->Simp_Surf, print_msh_simplex); } -void print_all_msh_volumes (void *a, void *b){ - Volume *v = *(Volume**)a; - Tree_Action (v->Simplexes, print_msh_simplex); - Tree_Action (v->Hexahedra, print_msh_hexahedron); - Tree_Action (v->Prisms, print_msh_prism); - Tree_Action (v->Pyramids, print_msh_pyramid); +void print_all_msh_volumes(void *a, void *b) +{ + Volume *v = *(Volume **) a; + Tree_Action(v->Simplexes, print_msh_simplex); + Tree_Action(v->Hexahedra, print_msh_hexahedron); + Tree_Action(v->Prisms, print_msh_prism); + Tree_Action(v->Pyramids, print_msh_pyramid); } -void print_all_msh_elements (Mesh * M){ +void print_all_msh_elements(Mesh * M) +{ MSH_PHYSICAL_NUM = 0; MSH_PHYSICAL_ORI = 1; MSH_LIN_NUM = MSH_SUR_NUM = MSH_VOL_NUM = 0; MSH_3D = 0; - if(CTX.mesh.oldxtrude){ + if(CTX.mesh.oldxtrude) { Tree_Action(M->Volumes, print_all_msh_simpsurf); } - else{ + else { Tree_Action(M->Curves, print_all_msh_curves); Tree_Action(M->Surfaces, print_all_msh_surfaces); } @@ -447,30 +459,31 @@ void print_all_msh_elements (Mesh * M){ Tree_Action(M->Volumes, print_all_msh_volumes); } -void process_msh_elements (Mesh * M){ +void process_msh_elements(Mesh * M) +{ MSH_ADD = 0; MSH_ELEMENT_NUM = 1; - if(!List_Nbr(M->PhysicalGroups) || CTX.mesh.save_all){ - Msg (INFO, "Saving all elements (discarding physical groups)"); - print_all_msh_elements (M); + if(!List_Nbr(M->PhysicalGroups) || CTX.mesh.save_all) { + Msg(INFO, "Saving all elements (discarding physical groups)"); + print_all_msh_elements(M); } else - print_msh_elements (M); + print_msh_elements(M); - fprintf (mshfile, "$ELM\n"); - fprintf (mshfile, "%d\n", MSH_ELEMENT_NUM - 1); + fprintf(mshfile, "$ELM\n"); + fprintf(mshfile, "%d\n", MSH_ELEMENT_NUM - 1); - if (MSH_ELEMENT_NUM == 1) - Msg (WARNING, "No elements to save"); + if(MSH_ELEMENT_NUM == 1) + Msg(WARNING, "No elements to save"); MSH_ADD = 1; MSH_ELEMENT_NUM = 1; if(!List_Nbr(M->PhysicalGroups) || CTX.mesh.save_all) - print_all_msh_elements (M); + print_all_msh_elements(M); else - print_msh_elements (M); - fprintf (mshfile, "$ENDELM\n"); + print_msh_elements(M); + fprintf(mshfile, "$ENDELM\n"); } @@ -492,7 +505,7 @@ void process_msh_elements (Mesh * M){ #define THINSHLL 91 #define THINSHLL2 92 #define QUAD 94 -#define QUAD2 95 // Ca c'est une impro !!! +#define QUAD2 95 // Ca c'est une impro !!! #define SOLIDFEM 111 #define WEDGE 112 #define BRICK 115 @@ -503,194 +516,198 @@ static FILE *unvfile; static Tree_T *tree; static int UNV_VOL_NUM; -void process_unv_nodes (Mesh * M){ +void process_unv_nodes(Mesh * M) +{ int nbnod; double x, y, z; int i, idnod; Vertex *v; - List_T *Nodes = Tree2List (M->Vertices); + List_T *Nodes = Tree2List(M->Vertices); - fprintf (unvfile, "%6d\n", -1); - fprintf (unvfile, "%6d\n", NODES); - nbnod = List_Nbr (Nodes); + fprintf(unvfile, "%6d\n", -1); + fprintf(unvfile, "%6d\n", NODES); + nbnod = List_Nbr(Nodes); - for (i = 0; i < nbnod; i++){ - List_Read (Nodes, i, &v); + for(i = 0; i < nbnod; i++) { + List_Read(Nodes, i, &v); idnod = v->Num; x = v->Pos.X * CTX.mesh.scaling_factor; y = v->Pos.Y * CTX.mesh.scaling_factor; z = v->Pos.Z * CTX.mesh.scaling_factor; - fprintf (unvfile, "%10d%10d%10d%10d\n", idnod, 1, 1, 11); - fprintf (unvfile, "%21.16fD+00 %21.16fD+00 %21.16fD+00\n", x, y, z); + fprintf(unvfile, "%10d%10d%10d%10d\n", idnod, 1, 1, 11); + fprintf(unvfile, "%21.16fD+00 %21.16fD+00 %21.16fD+00\n", x, y, z); } - List_Delete (Nodes); - Nodes = Tree2List (M->VertexEdges); - nbnod = List_Nbr (Nodes); + List_Delete(Nodes); + Nodes = Tree2List(M->VertexEdges); + nbnod = List_Nbr(Nodes); - for (i = 0; i < nbnod; i++){ - List_Read (Nodes, i, &v); + for(i = 0; i < nbnod; i++) { + List_Read(Nodes, i, &v); idnod = v->Num; x = v->Pos.X * CTX.mesh.scaling_factor; y = v->Pos.Y * CTX.mesh.scaling_factor; z = v->Pos.Z * CTX.mesh.scaling_factor; - fprintf (unvfile, "%10d%10d%10d%10d\n", idnod, 1, 1, 11); - fprintf (unvfile, "%21.16fD+00 %21.16fD+00 %21.16fD+00\n", x, y, z); + fprintf(unvfile, "%10d%10d%10d%10d\n", idnod, 1, 1, 11); + fprintf(unvfile, "%21.16fD+00 %21.16fD+00 %21.16fD+00\n", x, y, z); } - - fprintf (unvfile, "%6d\n", -1); + + fprintf(unvfile, "%6d\n", -1); } -int process_unv_2D_elements (Mesh * m){ - List_T *ListSurfaces = Tree2List (m->Surfaces); - List_T *ListVolumes = Tree2List (m->Volumes); +int process_unv_2D_elements(Mesh * m) +{ + List_T *ListSurfaces = Tree2List(m->Surfaces); + List_T *ListVolumes = Tree2List(m->Volumes); List_T *Elements; Volume *vol; - List_T *AllSurfaces = List_Create (2, 2, sizeof (Surface *)); + List_T *AllSurfaces = List_Create(2, 2, sizeof(Surface *)); Simplex *sx; Surface *s; int i, j, nsup, n, ntot, k, geo, fetyp; - for (i = 0; i < List_Nbr (ListVolumes); i++){ - List_Read (ListVolumes, i, &vol); - for (j = 0; j < List_Nbr (vol->Surfaces); j++){ - List_Read (vol->Surfaces, j, &s); - if (Tree_Nbr (s->Simplexes)) - List_Add (AllSurfaces, &s); + for(i = 0; i < List_Nbr(ListVolumes); i++) { + List_Read(ListVolumes, i, &vol); + for(j = 0; j < List_Nbr(vol->Surfaces); j++) { + List_Read(vol->Surfaces, j, &s); + if(Tree_Nbr(s->Simplexes)) + List_Add(AllSurfaces, &s); } } - for (i = 0; i < List_Nbr (ListSurfaces); i++){ - List_Read (ListSurfaces, i, &s); - if (!List_Search (AllSurfaces, &s, compareSurface)){ - Elements = Tree2List (s->Simplexes); - for (j = 0; j < List_Nbr (Elements); j++){ - List_Read (Elements, j, &sx); - if (sx->V[3]){ - if (sx->VSUP){ + for(i = 0; i < List_Nbr(ListSurfaces); i++) { + List_Read(ListSurfaces, i, &s); + if(!List_Search(AllSurfaces, &s, compareSurface)) { + Elements = Tree2List(s->Simplexes); + for(j = 0; j < List_Nbr(Elements); j++) { + List_Read(Elements, j, &sx); + if(sx->V[3]) { + if(sx->VSUP) { fetyp = QUAD; n = 4; nsup = 4; } - else{ + else { fetyp = QUAD; n = 4; nsup = 0; } } - else{ - if (sx->VSUP){ + else { + if(sx->VSUP) { fetyp = THINSHLL; n = 3; nsup = 3; } - else{ + else { fetyp = THINSHLL; nsup = 0; n = 3; } } geo = s->Num; - fprintf (unvfile, "%10d%10d%10d%10d%10d%10d\n", - /*ELEMENT_ID++ */ abs(sx->Num), fetyp, geo, geo, 7, n + nsup); - //'abs' since extrusion can tag triangles - // with a negative number + fprintf(unvfile, "%10d%10d%10d%10d%10d%10d\n", + /*ELEMENT_ID++ */ abs(sx->Num), fetyp, geo, geo, 7, n + nsup); + //'abs' since extrusion can tag triangles + // with a negative number ntot = 0; - for (k = 0; k < n; k++){ - fprintf (unvfile, "%10d", sx->V[k]->Num); - if (ntot % 8 == 7) - fprintf (unvfile, "\n"); + for(k = 0; k < n; k++) { + fprintf(unvfile, "%10d", sx->V[k]->Num); + if(ntot % 8 == 7) + fprintf(unvfile, "\n"); ntot++; } - for (k = 0; k < nsup; k++){ - fprintf (unvfile, "%10d", sx->VSUP[k]->Num); - if (ntot % 8 == 7) - fprintf (unvfile, "\n"); + for(k = 0; k < nsup; k++) { + fprintf(unvfile, "%10d", sx->VSUP[k]->Num); + if(ntot % 8 == 7) + fprintf(unvfile, "\n"); ntot++; } - if (ntot - 1 % 8 != 7) - fprintf (unvfile, "\n"); + if(ntot - 1 % 8 != 7) + fprintf(unvfile, "\n"); } - List_Delete (Elements); + List_Delete(Elements); } } - List_Delete (ListSurfaces); - List_Delete (ListVolumes); - List_Delete (AllSurfaces); + List_Delete(ListSurfaces); + List_Delete(ListVolumes); + List_Delete(AllSurfaces); return 0; } -int process_unv_1D_elements (Mesh * m){ - List_T *ListCurves = Tree2List (m->Curves); - List_T *AllCurves = List_Create (2, 2, sizeof (Surface *)); - List_T *ListSurfaces = Tree2List (m->Surfaces); +int process_unv_1D_elements(Mesh * m) +{ + List_T *ListCurves = Tree2List(m->Curves); + List_T *AllCurves = List_Create(2, 2, sizeof(Surface *)); + List_T *ListSurfaces = Tree2List(m->Surfaces); List_T *Elements; Simplex *sx; Curve *c; Surface *surf; int k, ntot, i, j, geo, fetyp, n, nsup; - for (i = 0; i < List_Nbr (ListSurfaces); i++){ - List_Read (ListSurfaces, i, &surf); - for (j = 0; j < List_Nbr (surf->Generatrices); j++){ - List_Read (surf->Generatrices, j, &c); - if (Tree_Nbr (c->Simplexes)) - List_Add (AllCurves, &c); - c = FindCurve (-c->Num, m); - if (Tree_Nbr (c->Simplexes)) - List_Add (AllCurves, &c); + for(i = 0; i < List_Nbr(ListSurfaces); i++) { + List_Read(ListSurfaces, i, &surf); + for(j = 0; j < List_Nbr(surf->Generatrices); j++) { + List_Read(surf->Generatrices, j, &c); + if(Tree_Nbr(c->Simplexes)) + List_Add(AllCurves, &c); + c = FindCurve(-c->Num, m); + if(Tree_Nbr(c->Simplexes)) + List_Add(AllCurves, &c); } } - for (i = 0; i < List_Nbr (ListCurves); i++){ - List_Read (ListCurves, i, &c); - if (!List_Search (AllCurves, &c, compareCurve)){ - Elements = Tree2List (c->Simplexes); - for (j = 0; j < List_Nbr (Elements); j++){ - List_Read (Elements, j, &sx); - if (sx->VSUP){ + for(i = 0; i < List_Nbr(ListCurves); i++) { + List_Read(ListCurves, i, &c); + if(!List_Search(AllCurves, &c, compareCurve)) { + Elements = Tree2List(c->Simplexes); + for(j = 0; j < List_Nbr(Elements); j++) { + List_Read(Elements, j, &sx); + if(sx->VSUP) { fetyp = BEAM2; n = 2; nsup = 2; } - else{ + else { fetyp = BEAM; n = 2; nsup = 0; } geo = c->Num; - fprintf (unvfile, "%10d%10d%10d%10d%10d%10d\n", - /*ELEMENT_ID++ */ sx->Num, fetyp, geo, geo, 7, n + nsup); + fprintf(unvfile, "%10d%10d%10d%10d%10d%10d\n", + /*ELEMENT_ID++ */ sx->Num, fetyp, geo, geo, 7, n + nsup); ntot = 0; - fprintf (unvfile, "%10d%10d%10d\n", 0, 0, 0); - for (k = 0; k < n; k++){ - fprintf (unvfile, "%10d", sx->V[k]->Num); - if (ntot % 8 == 7) - fprintf (unvfile, "\n"); + fprintf(unvfile, "%10d%10d%10d\n", 0, 0, 0); + for(k = 0; k < n; k++) { + fprintf(unvfile, "%10d", sx->V[k]->Num); + if(ntot % 8 == 7) + fprintf(unvfile, "\n"); ntot++; } - for (k = 0; k < nsup; k++){ - fprintf (unvfile, "%10d", sx->VSUP[k]->Num); - if (ntot % 8 == 7) - fprintf (unvfile, "\n"); + for(k = 0; k < nsup; k++) { + fprintf(unvfile, "%10d", sx->VSUP[k]->Num); + if(ntot % 8 == 7) + fprintf(unvfile, "\n"); ntot++; } - if (ntot - 1 % 8 != 7) - fprintf (unvfile, "\n"); + if(ntot - 1 % 8 != 7) + fprintf(unvfile, "\n"); } - - List_Delete (Elements); + + List_Delete(Elements); } } - List_Delete (AllCurves); - List_Delete (ListSurfaces); - List_Delete (ListCurves); + List_Delete(AllCurves); + List_Delete(ListSurfaces); + List_Delete(ListCurves); return 0; } -int process_unv_3D_elements (Mesh * m){ - List_T *ListVolumes = Tree2List (m->Volumes); +int process_unv_3D_elements(Mesh * m) +{ + List_T *ListVolumes = Tree2List(m->Volumes); List_T *Elements; Simplex *sx; Hexahedron *hx; @@ -698,168 +715,183 @@ int process_unv_3D_elements (Mesh * m){ Volume *v; int nb = 0, i, j, nsup, n, ntot, k, geo, fetyp; - for (i = 0; i < List_Nbr (ListVolumes); i++){ - List_Read (ListVolumes, i, &v); + for(i = 0; i < List_Nbr(ListVolumes); i++) { + List_Read(ListVolumes, i, &v); // TETRAEDRON - Elements = Tree2List (v->Simplexes); - for (j = 0; j < List_Nbr (Elements); j++){ - List_Read (Elements, j, &sx); - if (sx->VSUP){ + Elements = Tree2List(v->Simplexes); + for(j = 0; j < List_Nbr(Elements); j++) { + List_Read(Elements, j, &sx); + if(sx->VSUP) { fetyp = SOLIDFEM; n = 4; nsup = 6; } - else{ + else { fetyp = SOLIDFEM; nsup = 0; n = 4; } - if (sx->Volume_Simplexe () < 0){ + if(sx->Volume_Simplexe() < 0) { Vertex *temp; temp = sx->V[0]; sx->V[0] = sx->V[1]; sx->V[1] = temp; - if (sx->Volume_Simplexe () < 0) + if(sx->Volume_Simplexe() < 0) Msg(WARNING, "Negative volume for simplex %d", sx->Num); } geo = v->Num; - fprintf (unvfile, "%10d%10d%10d%10d%10d%10d\n", - ELEMENT_ID++, fetyp, geo, geo, 7, n + nsup); + fprintf(unvfile, "%10d%10d%10d%10d%10d%10d\n", + ELEMENT_ID++, fetyp, geo, geo, 7, n + nsup); ntot = 0; - for (k = 0; k < n; k++){ - fprintf (unvfile, "%10d", sx->V[k]->Num); - if (ntot % 8 == 7) - fprintf (unvfile, "\n"); + for(k = 0; k < n; k++) { + fprintf(unvfile, "%10d", sx->V[k]->Num); + if(ntot % 8 == 7) + fprintf(unvfile, "\n"); ntot++; } - for (k = 0; k < nsup; k++){ - fprintf (unvfile, "%10d", sx->VSUP[k]->Num); - if (ntot % 8 == 7) - fprintf (unvfile, "\n"); + for(k = 0; k < nsup; k++) { + fprintf(unvfile, "%10d", sx->VSUP[k]->Num); + if(ntot % 8 == 7) + fprintf(unvfile, "\n"); ntot++; } - if (ntot - 1 % 8 != 7) - fprintf (unvfile, "\n"); + if(ntot - 1 % 8 != 7) + fprintf(unvfile, "\n"); } - List_Delete (Elements); - nb += Tree_Nbr (v->Simplexes); - + List_Delete(Elements); + nb += Tree_Nbr(v->Simplexes); + // PRISMS - Elements = Tree2List (v->Prisms); - for (j = 0; j < List_Nbr (Elements); j++){ - List_Read (Elements, j, &px); - if (px->VSUP){ + Elements = Tree2List(v->Prisms); + for(j = 0; j < List_Nbr(Elements); j++) { + List_Read(Elements, j, &px); + if(px->VSUP) { fetyp = WEDGE; n = 6; nsup = 9; } - else{ + else { fetyp = WEDGE; nsup = 0; n = 6; } - + geo = v->Num; - fprintf (unvfile, "%10d%10d%10d%10d%10d%10d\n", - ELEMENT_ID++, fetyp, geo, geo, 7, n + nsup); + fprintf(unvfile, "%10d%10d%10d%10d%10d%10d\n", + ELEMENT_ID++, fetyp, geo, geo, 7, n + nsup); ntot = 0; - for (k = 0; k < n; k++){ - fprintf (unvfile, "%10d", px->V[k]->Num); - if (ntot % 8 == 7) - fprintf (unvfile, "\n"); + for(k = 0; k < n; k++) { + fprintf(unvfile, "%10d", px->V[k]->Num); + if(ntot % 8 == 7) + fprintf(unvfile, "\n"); ntot++; } - for (k = 0; k < nsup; k++){ - fprintf (unvfile, "%10d", px->VSUP[k]->Num); - if (ntot % 8 == 7) - fprintf (unvfile, "\n"); + for(k = 0; k < nsup; k++) { + fprintf(unvfile, "%10d", px->VSUP[k]->Num); + if(ntot % 8 == 7) + fprintf(unvfile, "\n"); ntot++; } - if (ntot - 1 % 8 != 7) - fprintf (unvfile, "\n"); + if(ntot - 1 % 8 != 7) + fprintf(unvfile, "\n"); } - List_Delete (Elements); - nb += Tree_Nbr (v->Prisms); - + List_Delete(Elements); + nb += Tree_Nbr(v->Prisms); + // HEXAHEDRA - Elements = Tree2List (v->Hexahedra); - for (j = 0; j < List_Nbr (Elements); j++){ - List_Read (Elements, j, &hx); - if (hx->VSUP){ + Elements = Tree2List(v->Hexahedra); + for(j = 0; j < List_Nbr(Elements); j++) { + List_Read(Elements, j, &hx); + if(hx->VSUP) { fetyp = BRICK; n = 8; nsup = 12; } - else{ + else { fetyp = BRICK; nsup = 0; n = 8; } - + geo = v->Num; - fprintf (unvfile, "%10d%10d%10d%10d%10d%10d\n", - ELEMENT_ID++, fetyp, geo, geo, 7, n + nsup); + fprintf(unvfile, "%10d%10d%10d%10d%10d%10d\n", + ELEMENT_ID++, fetyp, geo, geo, 7, n + nsup); ntot = 0; - for (k = 0; k < n; k++){ - fprintf (unvfile, "%10d", hx->V[k]->Num); - if (ntot % 8 == 7) - fprintf (unvfile, "\n"); + for(k = 0; k < n; k++) { + fprintf(unvfile, "%10d", hx->V[k]->Num); + if(ntot % 8 == 7) + fprintf(unvfile, "\n"); ntot++; } - for (k = 0; k < nsup; k++){ - fprintf (unvfile, "%10d", hx->VSUP[k]->Num); - if (ntot % 8 == 7) - fprintf (unvfile, "\n"); + for(k = 0; k < nsup; k++) { + fprintf(unvfile, "%10d", hx->VSUP[k]->Num); + if(ntot % 8 == 7) + fprintf(unvfile, "\n"); ntot++; } - if (ntot - 1 % 8 != 7) - fprintf (unvfile, "\n"); + if(ntot - 1 % 8 != 7) + fprintf(unvfile, "\n"); } - List_Delete (Elements); - nb += Tree_Nbr (v->Hexahedra); + List_Delete(Elements); + nb += Tree_Nbr(v->Hexahedra); } - List_Delete (ListVolumes); + List_Delete(ListVolumes); return nb; } -void add_unv_vertex (void *a, void *b){ +void add_unv_vertex(void *a, void *b) +{ Vertex *v; v = *(Vertex **) a; - if (Tree_Search (tree, &v->Num)) + if(Tree_Search(tree, &v->Num)) return; - Tree_Add (tree, &v->Num); - fprintf (unvfile, "%10d%10d%2d%2d%2d%2d%2d%2d\n", v->Num, 1, 0, 1, 0, 0, 0, 0); - fprintf (unvfile, "%21.16fD+00 %21.16fD+00 %21.16fD+00\n", 0., 1., 0.); - fprintf (unvfile, "%21.16fD+00 %21.16fD+00 %21.16fD+00\n", 0., 0., 0.); - fprintf (unvfile, "%10d%10d%10d%10d%10d%10d\n", 0, 0, 0, 0, 0, 0); + Tree_Add(tree, &v->Num); + fprintf(unvfile, "%10d%10d%2d%2d%2d%2d%2d%2d\n", v->Num, 1, 0, 1, 0, 0, 0, + 0); + fprintf(unvfile, "%21.16fD+00 %21.16fD+00 %21.16fD+00\n", 0., 1., 0.); + fprintf(unvfile, "%21.16fD+00 %21.16fD+00 %21.16fD+00\n", 0., 0., 0.); + fprintf(unvfile, "%10d%10d%10d%10d%10d%10d\n", 0, 0, 0, 0, 0, 0); } -void add_unv_simplex_vertices (void *a, void *b){ +void add_unv_simplex_vertices(void *a, void *b) +{ Simplex *s = *(Simplex **) a; - if(s->iEnt != UNV_VOL_NUM) return; - for(int i=0; i<4; i++) add_unv_vertex(&s->V[i],NULL); + if(s->iEnt != UNV_VOL_NUM) + return; + for(int i = 0; i < 4; i++) + add_unv_vertex(&s->V[i], NULL); } -void add_unv_hexahedron_vertices (void *a, void *b){ +void add_unv_hexahedron_vertices(void *a, void *b) +{ Hexahedron *h = *(Hexahedron **) a; - if(h->iEnt != UNV_VOL_NUM) return; - for(int i=0; i<8; i++) add_unv_vertex(&h->V[i],NULL); + if(h->iEnt != UNV_VOL_NUM) + return; + for(int i = 0; i < 8; i++) + add_unv_vertex(&h->V[i], NULL); } -void add_unv_prism_vertices (void *a, void *b){ +void add_unv_prism_vertices(void *a, void *b) +{ Prism *p = *(Prism **) a; - if(p->iEnt != UNV_VOL_NUM) return; - for(int i=0; i<6; i++) add_unv_vertex(&p->V[i],NULL); + if(p->iEnt != UNV_VOL_NUM) + return; + for(int i = 0; i < 6; i++) + add_unv_vertex(&p->V[i], NULL); } -void add_unv_pyramid_vertices (void *a, void *b){ +void add_unv_pyramid_vertices(void *a, void *b) +{ Pyramid *p = *(Pyramid **) a; - if(p->iEnt != UNV_VOL_NUM) return; - for(int i=0; i<5; i++) add_unv_vertex(&p->V[i],NULL); + if(p->iEnt != UNV_VOL_NUM) + return; + for(int i = 0; i < 5; i++) + add_unv_vertex(&p->V[i], NULL); } -void process_unv_groups (Mesh * m){ - int j, i, k; +void process_unv_groups(Mesh * m) +{ + int j, i, k; Volume *pV; Surface *ps, s; Curve *pc, c; @@ -867,147 +899,151 @@ void process_unv_groups (Mesh * m){ PhysicalGroup *p; List_T *ListVolumes; - for (i = 0; i < List_Nbr (m->PhysicalGroups); i++){ + for(i = 0; i < List_Nbr(m->PhysicalGroups); i++) { - List_Read (m->PhysicalGroups, i, &p); + List_Read(m->PhysicalGroups, i, &p); - fprintf (unvfile, "%6d\n", -1); - fprintf (unvfile, "%6d\n", GROUPOFNODES); - fprintf (unvfile, "%10d%10d\n", p->Num, 1); - fprintf (unvfile, "LOAD SET %2d\n", 1); + fprintf(unvfile, "%6d\n", -1); + fprintf(unvfile, "%6d\n", GROUPOFNODES); + fprintf(unvfile, "%10d%10d\n", p->Num, 1); + fprintf(unvfile, "LOAD SET %2d\n", 1); - tree = Tree_Create (sizeof (int), fcmp_absint); + tree = Tree_Create(sizeof(int), fcmp_absint); - switch(p->Typ){ - case MSH_PHYSICAL_VOLUME : - ListVolumes = Tree2List (m->Volumes); - for (k = 0; k < List_Nbr (ListVolumes); k++){ - List_Read (ListVolumes, k, &pV); - for (j = 0; j < List_Nbr(p->Entities); j++){ - List_Read (p->Entities, j, &UNV_VOL_NUM); - Tree_Action (pV->Simplexes, add_unv_simplex_vertices); - Tree_Action (pV->Hexahedra, add_unv_hexahedron_vertices); - Tree_Action (pV->Prisms, add_unv_prism_vertices); - Tree_Action (pV->Pyramids, add_unv_pyramid_vertices); + switch (p->Typ) { + case MSH_PHYSICAL_VOLUME: + ListVolumes = Tree2List(m->Volumes); + for(k = 0; k < List_Nbr(ListVolumes); k++) { + List_Read(ListVolumes, k, &pV); + for(j = 0; j < List_Nbr(p->Entities); j++) { + List_Read(p->Entities, j, &UNV_VOL_NUM); + Tree_Action(pV->Simplexes, add_unv_simplex_vertices); + Tree_Action(pV->Hexahedra, add_unv_hexahedron_vertices); + Tree_Action(pV->Prisms, add_unv_prism_vertices); + Tree_Action(pV->Pyramids, add_unv_pyramid_vertices); } } List_Delete(ListVolumes); break; - case MSH_PHYSICAL_SURFACE : - for (j = 0; j < List_Nbr(p->Entities); j++){ + case MSH_PHYSICAL_SURFACE: + for(j = 0; j < List_Nbr(p->Entities); j++) { ps = &s; - List_Read (p->Entities, j, &ps->Num); - if (Tree_Query (m->Surfaces, &ps)) - Tree_Action (ps->Vertices, add_unv_vertex); + List_Read(p->Entities, j, &ps->Num); + if(Tree_Query(m->Surfaces, &ps)) + Tree_Action(ps->Vertices, add_unv_vertex); } break; - case MSH_PHYSICAL_LINE : - for (j = 0; j < List_Nbr(p->Entities); j++){ + case MSH_PHYSICAL_LINE: + for(j = 0; j < List_Nbr(p->Entities); j++) { pc = &c; - List_Read (p->Entities, j, &pc->Num); - if (Tree_Query (m->Curves, &pc)) - for (k = 0; k < List_Nbr (pc->Vertices); k++) - add_unv_vertex (List_Pointer (pc->Vertices, k), NULL); + List_Read(p->Entities, j, &pc->Num); + if(Tree_Query(m->Curves, &pc)) + for(k = 0; k < List_Nbr(pc->Vertices); k++) + add_unv_vertex(List_Pointer(pc->Vertices, k), NULL); } break; - case MSH_PHYSICAL_POINT : - for (j = 0; j < List_Nbr(p->Entities); j++){ + case MSH_PHYSICAL_POINT: + for(j = 0; j < List_Nbr(p->Entities); j++) { pv = &v; - List_Read (p->Entities, j, &pv->Num); - if (Tree_Query (m->Vertices, &pv)) - add_unv_vertex (&pv, NULL); + List_Read(p->Entities, j, &pv->Num); + if(Tree_Query(m->Vertices, &pv)) + add_unv_vertex(&pv, NULL); } break; } Tree_Delete(tree); - fprintf (unvfile, "%6d\n", -1); + fprintf(unvfile, "%6d\n", -1); } } // G R E F F O R M A T -void ConsecutiveNodes (Mesh * M, Tree_T * ConstecutiveNTree, Tree_T * ConsecutiveETree); +void ConsecutiveNodes(Mesh * M, Tree_T * ConstecutiveNTree, + Tree_T * ConsecutiveETree); -static int compareFrozen (const void *a, const void *b){ +static int compareFrozen(const void *a, const void *b) +{ Vertex *q, *w; q = *(Vertex **) a; w = *(Vertex **) b; return w->Frozen - q->Frozen; } -int process_Gref_nodes (FILE * fGref, Mesh * M, - Tree_T * ConsecutiveNTree, Tree_T * ConsecutiveETree){ +int process_Gref_nodes(FILE * fGref, Mesh * M, + Tree_T * ConsecutiveNTree, Tree_T * ConsecutiveETree) +{ int i, nbtri; Vertex *v; Surface *s; Curve *c; List_T *ListSurfaces, *ListCurves, *Nodes; - ListCurves = Tree2List (M->Curves); - for (i = 0; i < List_Nbr (ListCurves); i++){ - List_Read (ListCurves, i, &c); - Degre2 (M->Vertices, M->VertexEdges, c->Simplexes, c, NULL); + ListCurves = Tree2List(M->Curves); + for(i = 0; i < List_Nbr(ListCurves); i++) { + List_Read(ListCurves, i, &c); + Degre2(M->Vertices, M->VertexEdges, c->Simplexes, c, NULL); } - List_Delete (ListCurves); + List_Delete(ListCurves); - ListSurfaces = Tree2List (M->Surfaces); + ListSurfaces = Tree2List(M->Surfaces); nbtri = 0; - for (i = 0; i < List_Nbr (ListSurfaces); i++){ - List_Read (ListSurfaces, i, &s); - Degre2 (M->Vertices, M->VertexEdges, s->Simplexes, NULL, s); - nbtri += Tree_Nbr (s->Simplexes); + for(i = 0; i < List_Nbr(ListSurfaces); i++) { + List_Read(ListSurfaces, i, &s); + Degre2(M->Vertices, M->VertexEdges, s->Simplexes, NULL, s); + nbtri += Tree_Nbr(s->Simplexes); } - List_Delete (ListSurfaces); + List_Delete(ListSurfaces); - ConsecutiveNodes (M, ConsecutiveNTree, ConsecutiveETree); + ConsecutiveNodes(M, ConsecutiveNTree, ConsecutiveETree); - fprintf (fGref, "%d %d %d\n", nbtri, Tree_Nbr (ConsecutiveNTree), - Tree_Nbr (ConsecutiveNTree) + Tree_Nbr (ConsecutiveETree)); + fprintf(fGref, "%d %d %d\n", nbtri, Tree_Nbr(ConsecutiveNTree), + Tree_Nbr(ConsecutiveNTree) + Tree_Nbr(ConsecutiveETree)); - Nodes = Tree2List (ConsecutiveNTree); - for (i = 0; i < List_Nbr (Nodes); i++){ - List_Read (Nodes, i, &v); - fprintf (fGref, "%21.16e ", v->Pos.X * CTX.mesh.scaling_factor); - if (i % 3 == 2) - fprintf (fGref, "\n"); + Nodes = Tree2List(ConsecutiveNTree); + for(i = 0; i < List_Nbr(Nodes); i++) { + List_Read(Nodes, i, &v); + fprintf(fGref, "%21.16e ", v->Pos.X * CTX.mesh.scaling_factor); + if(i % 3 == 2) + fprintf(fGref, "\n"); } - if ((List_Nbr (Nodes) - 1) % 3 != 2) - fprintf (fGref, "\n"); - for (i = 0; i < List_Nbr (Nodes); i++){ - List_Read (Nodes, i, &v); - fprintf (fGref, "%21.16e ", v->Pos.Y * CTX.mesh.scaling_factor); - if (i % 3 == 2) - fprintf (fGref, "\n"); + if((List_Nbr(Nodes) - 1) % 3 != 2) + fprintf(fGref, "\n"); + for(i = 0; i < List_Nbr(Nodes); i++) { + List_Read(Nodes, i, &v); + fprintf(fGref, "%21.16e ", v->Pos.Y * CTX.mesh.scaling_factor); + if(i % 3 == 2) + fprintf(fGref, "\n"); } - if ((List_Nbr (Nodes) - 1) % 3 != 2) - fprintf (fGref, "\n"); - i = Tree_Nbr (ConsecutiveNTree); - List_Delete (Nodes); + if((List_Nbr(Nodes) - 1) % 3 != 2) + fprintf(fGref, "\n"); + i = Tree_Nbr(ConsecutiveNTree); + List_Delete(Nodes); return i; } -int find_physicalentity (Vertex * v, Mesh * m){ +int find_physicalentity(Vertex * v, Mesh * m) +{ PhysicalGroup *p; Curve *c; int i, j; - for (i = 0; i < List_Nbr (m->PhysicalGroups); i++){ - List_Read (m->PhysicalGroups, i, &p); - if (p->Typ == MSH_PHYSICAL_POINT){ - if (List_Search (p->Entities, &v->Num, fcmp_absint)){ + for(i = 0; i < List_Nbr(m->PhysicalGroups); i++) { + List_Read(m->PhysicalGroups, i, &p); + if(p->Typ == MSH_PHYSICAL_POINT) { + if(List_Search(p->Entities, &v->Num, fcmp_absint)) { return p->Num; } } } - - if (v->ListCurves){ - for (i = 0; i < List_Nbr (m->PhysicalGroups); i++){ - List_Read (m->PhysicalGroups, i, &p); - if (p->Typ == MSH_PHYSICAL_LINE){ - for (j = 0; j < List_Nbr (v->ListCurves); j++){ - List_Read (v->ListCurves, j, &c); - if (List_Search (p->Entities, &c->Num, fcmp_absint)){ + + if(v->ListCurves) { + for(i = 0; i < List_Nbr(m->PhysicalGroups); i++) { + List_Read(m->PhysicalGroups, i, &p); + if(p->Typ == MSH_PHYSICAL_LINE) { + for(j = 0; j < List_Nbr(v->ListCurves); j++) { + List_Read(v->ListCurves, j, &c); + if(List_Search(p->Entities, &c->Num, fcmp_absint)) { return p->Num; } } @@ -1017,126 +1053,124 @@ int find_physicalentity (Vertex * v, Mesh * m){ return 0; } -void process_Gref_poundarybonditions (FILE * fGref, Mesh * M, - Tree_T * TRN, Tree_T * TRE){ +void process_Gref_poundarybonditions(FILE * fGref, Mesh * M, + Tree_T * TRN, Tree_T * TRE) +{ int i, ent; Vertex *v; - List_T *Nodes = Tree2List (TRN); - for (i = 0; i < List_Nbr (Nodes); i++){ - List_Read (Nodes, i, &v); - ent = find_physicalentity (v, M); - fprintf (fGref, "%d %d ", ent, ent); - if (i % 3 == 2) - fprintf (fGref, "\n"); + List_T *Nodes = Tree2List(TRN); + for(i = 0; i < List_Nbr(Nodes); i++) { + List_Read(Nodes, i, &v); + ent = find_physicalentity(v, M); + fprintf(fGref, "%d %d ", ent, ent); + if(i % 3 == 2) + fprintf(fGref, "\n"); } - if ((List_Nbr (Nodes) - 1) % 3 != 2) - fprintf (fGref, "\n"); - List_Delete (Nodes); - - Nodes = Tree2List (TRE); - for (i = 0; i < List_Nbr (Nodes); i++){ - List_Read (Nodes, i, &v); - ent = find_physicalentity (v, M); - fprintf (fGref, "%d %d ", ent, ent); - if (i % 3 == 2) - fprintf (fGref, "\n"); + if((List_Nbr(Nodes) - 1) % 3 != 2) + fprintf(fGref, "\n"); + List_Delete(Nodes); + + Nodes = Tree2List(TRE); + for(i = 0; i < List_Nbr(Nodes); i++) { + List_Read(Nodes, i, &v); + ent = find_physicalentity(v, M); + fprintf(fGref, "%d %d ", ent, ent); + if(i % 3 == 2) + fprintf(fGref, "\n"); } - if ((List_Nbr (Nodes) - 1) % 3 != 2) - fprintf (fGref, "\n"); - List_Delete (Nodes); + if((List_Nbr(Nodes) - 1) % 3 != 2) + fprintf(fGref, "\n"); + List_Delete(Nodes); } -void process_Gref_elements (FILE * fGref, Mesh * M, int nn){ +void process_Gref_elements(FILE * fGref, Mesh * M, int nn) +{ int i, j; Simplex *sx; Surface *s; List_T *Triangles; List_T *ListSurfaces; - ListSurfaces = Tree2List (M->Surfaces); - for (i = 0; i < List_Nbr (ListSurfaces); i++){ - List_Read (ListSurfaces, i, &s); - Triangles = Tree2List (s->Simplexes); - for (j = 0; j < List_Nbr (Triangles); j++){ - List_Read (Triangles, j, &sx); - if (!sx->V[3]) - fprintf (fGref, "%d %d %d\n", -sx->V[0]->Frozen, - -sx->V[1]->Frozen, -sx->V[2]->Frozen); + ListSurfaces = Tree2List(M->Surfaces); + for(i = 0; i < List_Nbr(ListSurfaces); i++) { + List_Read(ListSurfaces, i, &s); + Triangles = Tree2List(s->Simplexes); + for(j = 0; j < List_Nbr(Triangles); j++) { + List_Read(Triangles, j, &sx); + if(!sx->V[3]) + fprintf(fGref, "%d %d %d\n", -sx->V[0]->Frozen, + -sx->V[1]->Frozen, -sx->V[2]->Frozen); else - fprintf (fGref, "%d %d %d %d\n", -sx->V[0]->Frozen, - -sx->V[1]->Frozen, - -sx->V[2]->Frozen, - -sx->V[3]->Frozen); - + fprintf(fGref, "%d %d %d %d\n", -sx->V[0]->Frozen, + -sx->V[1]->Frozen, -sx->V[2]->Frozen, -sx->V[3]->Frozen); + } - List_Delete (Triangles); + List_Delete(Triangles); } - for (i = 0; i < List_Nbr (ListSurfaces); i++){ - List_Read (ListSurfaces, i, &s); - Triangles = Tree2List (s->Simplexes); - for (j = 0; j < List_Nbr (Triangles); j++){ - List_Read (Triangles, j, &sx); - if (!sx->V[3]) - fprintf (fGref, "%d %d %d\n", -sx->VSUP[0]->Frozen - nn, - -sx->VSUP[1]->Frozen - nn, - -sx->VSUP[2]->Frozen - nn); + for(i = 0; i < List_Nbr(ListSurfaces); i++) { + List_Read(ListSurfaces, i, &s); + Triangles = Tree2List(s->Simplexes); + for(j = 0; j < List_Nbr(Triangles); j++) { + List_Read(Triangles, j, &sx); + if(!sx->V[3]) + fprintf(fGref, "%d %d %d\n", -sx->VSUP[0]->Frozen - nn, + -sx->VSUP[1]->Frozen - nn, -sx->VSUP[2]->Frozen - nn); else - fprintf (fGref, "%d %d %d %d\n", -sx->VSUP[0]->Frozen - nn, - -sx->VSUP[1]->Frozen - nn, - -sx->VSUP[2]->Frozen - nn, - -sx->VSUP[3]->Frozen - nn); + fprintf(fGref, "%d %d %d %d\n", -sx->VSUP[0]->Frozen - nn, + -sx->VSUP[1]->Frozen - nn, + -sx->VSUP[2]->Frozen - nn, -sx->VSUP[3]->Frozen - nn); } - List_Delete (Triangles); + List_Delete(Triangles); } // Degres de Liberte - for (i = 0; i < List_Nbr (ListSurfaces); i++){ - List_Read (ListSurfaces, i, &s); - Triangles = Tree2List (s->Simplexes); - for (j = 0; j < List_Nbr (Triangles); j++){ - List_Read (Triangles, j, &sx); - if (!sx->V[3]) - fprintf (fGref, "%d %d %d %d %d %d %d %d %d %d %d %d\n", - -2 * sx->V[0]->Frozen - 1, - -2 * sx->V[0]->Frozen, - -2 * sx->VSUP[0]->Frozen - 1, - -2 * sx->VSUP[0]->Frozen, - -2 * sx->V[1]->Frozen - 1, - -2 * sx->V[1]->Frozen, - -2 * sx->VSUP[1]->Frozen - 1, - -2 * sx->VSUP[1]->Frozen, - -2 * sx->V[2]->Frozen - 1, - -2 * sx->V[2]->Frozen, - -2 * sx->VSUP[2]->Frozen - 1, - -2 * sx->VSUP[2]->Frozen); + for(i = 0; i < List_Nbr(ListSurfaces); i++) { + List_Read(ListSurfaces, i, &s); + Triangles = Tree2List(s->Simplexes); + for(j = 0; j < List_Nbr(Triangles); j++) { + List_Read(Triangles, j, &sx); + if(!sx->V[3]) + fprintf(fGref, "%d %d %d %d %d %d %d %d %d %d %d %d\n", + -2 * sx->V[0]->Frozen - 1, + -2 * sx->V[0]->Frozen, + -2 * sx->VSUP[0]->Frozen - 1, + -2 * sx->VSUP[0]->Frozen, + -2 * sx->V[1]->Frozen - 1, + -2 * sx->V[1]->Frozen, + -2 * sx->VSUP[1]->Frozen - 1, + -2 * sx->VSUP[1]->Frozen, + -2 * sx->V[2]->Frozen - 1, + -2 * sx->V[2]->Frozen, + -2 * sx->VSUP[2]->Frozen - 1, -2 * sx->VSUP[2]->Frozen); else - fprintf (fGref, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", - -2 * sx->V[0]->Frozen - 1, - -2 * sx->V[0]->Frozen, - -2 * sx->VSUP[0]->Frozen - 1, - -2 * sx->VSUP[0]->Frozen, - -2 * sx->V[1]->Frozen - 1, - -2 * sx->V[1]->Frozen, - -2 * sx->VSUP[1]->Frozen - 1, - -2 * sx->VSUP[1]->Frozen, - -2 * sx->V[2]->Frozen - 1, - -2 * sx->V[2]->Frozen, - -2 * sx->VSUP[2]->Frozen - 1, - -2 * sx->VSUP[2]->Frozen, - -2 * sx->V[3]->Frozen - 1, - -2 * sx->V[3]->Frozen, - -2 * sx->VSUP[3]->Frozen - 1, - -2 * sx->VSUP[3]->Frozen); + fprintf(fGref, "%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n", + -2 * sx->V[0]->Frozen - 1, + -2 * sx->V[0]->Frozen, + -2 * sx->VSUP[0]->Frozen - 1, + -2 * sx->VSUP[0]->Frozen, + -2 * sx->V[1]->Frozen - 1, + -2 * sx->V[1]->Frozen, + -2 * sx->VSUP[1]->Frozen - 1, + -2 * sx->VSUP[1]->Frozen, + -2 * sx->V[2]->Frozen - 1, + -2 * sx->V[2]->Frozen, + -2 * sx->VSUP[2]->Frozen - 1, + -2 * sx->VSUP[2]->Frozen, + -2 * sx->V[3]->Frozen - 1, + -2 * sx->V[3]->Frozen, + -2 * sx->VSUP[3]->Frozen - 1, -2 * sx->VSUP[3]->Frozen); } - List_Delete (Triangles); + List_Delete(Triangles); } - List_Delete (ListSurfaces); + List_Delete(ListSurfaces); } FILE *Greffile; -void ConsecutiveNodes (Mesh * M, Tree_T * ConsecutiveNTree, Tree_T * ConsecutiveETree){ +void ConsecutiveNodes(Mesh * M, Tree_T * ConsecutiveNTree, + Tree_T * ConsecutiveETree) +{ int i, j, k; Simplex *sx; Surface *s; @@ -1146,51 +1180,52 @@ void ConsecutiveNodes (Mesh * M, Tree_T * ConsecutiveNTree, Tree_T * Consecutive int newnum = 0, N; - ListSurfaces = Tree2List (M->Surfaces); - for (i = 0; i < List_Nbr (ListSurfaces); i++){ - List_Read (ListSurfaces, i, &s); - Triangles = Tree2List (s->Simplexes); - for (j = 0; j < List_Nbr (Triangles); j++){ - List_Read (Triangles, j, &sx); - if (!sx->V[3]) + ListSurfaces = Tree2List(M->Surfaces); + for(i = 0; i < List_Nbr(ListSurfaces); i++) { + List_Read(ListSurfaces, i, &s); + Triangles = Tree2List(s->Simplexes); + for(j = 0; j < List_Nbr(Triangles); j++) { + List_Read(Triangles, j, &sx); + if(!sx->V[3]) N = 3; else N = 4; - for (k = 0; k < N; k++){ - if (sx->V[k]->Frozen >= 0){ + for(k = 0; k < N; k++) { + if(sx->V[k]->Frozen >= 0) { sx->V[k]->Frozen = --newnum; - Tree_Insert (ConsecutiveNTree, &(sx->V[k])); + Tree_Insert(ConsecutiveNTree, &(sx->V[k])); } } } - List_Delete (Triangles); + List_Delete(Triangles); } nbnod = -newnum; - ListSurfaces = Tree2List (M->Surfaces); - for (i = 0; i < List_Nbr (ListSurfaces); i++){ - List_Read (ListSurfaces, i, &s); - Triangles = Tree2List (s->Simplexes); - for (j = 0; j < List_Nbr (Triangles); j++){ - List_Read (Triangles, j, &sx); - if (!sx->V[3]) + ListSurfaces = Tree2List(M->Surfaces); + for(i = 0; i < List_Nbr(ListSurfaces); i++) { + List_Read(ListSurfaces, i, &s); + Triangles = Tree2List(s->Simplexes); + for(j = 0; j < List_Nbr(Triangles); j++) { + List_Read(Triangles, j, &sx); + if(!sx->V[3]) N = 3; else N = 4; - for (k = 0; k < N; k++){ - if (sx->VSUP[k]->Frozen >= 0){ + for(k = 0; k < N; k++) { + if(sx->VSUP[k]->Frozen >= 0) { sx->VSUP[k]->Frozen = --newnum; - Tree_Insert (ConsecutiveETree, &(sx->VSUP[k])); + Tree_Insert(ConsecutiveETree, &(sx->VSUP[k])); } } } - List_Delete (Triangles); + List_Delete(Triangles); } nbedges = -newnum - nbnod; nbdof = nbnod + nbedges; Msg(INFO, "%d Dofs", nbdof); } -void EndConsecutiveNodes (Mesh * M){ +void EndConsecutiveNodes(Mesh * M) +{ int i, j, k; Simplex *sx; Surface *s; @@ -1198,91 +1233,98 @@ void EndConsecutiveNodes (Mesh * M){ List_T *ListSurfaces; int N; - ListSurfaces = Tree2List (M->Surfaces); - for (i = 0; i < List_Nbr (ListSurfaces); i++){ - List_Read (ListSurfaces, i, &s); - Triangles = Tree2List (s->Simplexes); - for (j = 0; j < List_Nbr (Triangles); j++){ - List_Read (Triangles, j, &sx); - if (!sx->V[3]) + ListSurfaces = Tree2List(M->Surfaces); + for(i = 0; i < List_Nbr(ListSurfaces); i++) { + List_Read(ListSurfaces, i, &s); + Triangles = Tree2List(s->Simplexes); + for(j = 0; j < List_Nbr(Triangles); j++) { + List_Read(Triangles, j, &sx); + if(!sx->V[3]) N = 3; else N = 4; - for (k = 0; k < N; k++) + for(k = 0; k < N; k++) sx->V[k]->Frozen = 0; - for (k = 0; k < N; k++) + for(k = 0; k < N; k++) sx->VSUP[k]->Frozen = 0; } - List_Delete (Triangles); + List_Delete(Triangles); } - List_Delete (ListSurfaces); + List_Delete(ListSurfaces); } // V R M L 1 F O R M A T static FILE *wrlfile; -static List_T *wrlnodes=NULL; +static List_T *wrlnodes = NULL; -void print_wrl_node (void *a, void *b){ +void print_wrl_node(void *a, void *b) +{ Vertex *V = *(Vertex **) a; fprintf(wrlfile, "%.16g %.16g %.16g,\n", - V->Pos.X * CTX.mesh.scaling_factor, - V->Pos.Y * CTX.mesh.scaling_factor, - V->Pos.Z * CTX.mesh.scaling_factor); + V->Pos.X * CTX.mesh.scaling_factor, + V->Pos.Y * CTX.mesh.scaling_factor, + V->Pos.Z * CTX.mesh.scaling_factor); List_Add(wrlnodes, &V->Num); } -void process_wrl_nodes (Mesh * M){ +void process_wrl_nodes(Mesh * M) +{ if(!wrlnodes) - wrlnodes = List_Create(Tree_Size(M->Vertices),100,sizeof(int)); + wrlnodes = List_Create(Tree_Size(M->Vertices), 100, sizeof(int)); else List_Reset(wrlnodes); - fprintf (wrlfile, "#VRML V1.0 ascii\n"); - fprintf (wrlfile, "#created by Gmsh\n"); - fprintf (wrlfile, "Coordinate3 {\n"); - fprintf (wrlfile, " point [\n"); + fprintf(wrlfile, "#VRML V1.0 ascii\n"); + fprintf(wrlfile, "#created by Gmsh\n"); + fprintf(wrlfile, "Coordinate3 {\n"); + fprintf(wrlfile, " point [\n"); Tree_Action(M->Vertices, print_wrl_node); - fprintf (wrlfile, " ]\n"); - fprintf (wrlfile, "}\n"); + fprintf(wrlfile, " ]\n"); + fprintf(wrlfile, "}\n"); } -void print_wrl_simplex (void *a, void *b){ +void print_wrl_simplex(void *a, void *b) +{ Simplex *S = *(Simplex **) a; - int i=0, j; - while(S->V[i]){ - j = List_ISearch(wrlnodes,&S->V[i]->Num,fcmp_int); - if(j < 0) + int i = 0, j; + while(S->V[i]) { + j = List_ISearch(wrlnodes, &S->V[i]->Num, fcmp_int); + if(j < 0) Msg(GERROR, "Unknown node %d in simplex %d", S->V[i]->Num, S->Num); - else + else fprintf(wrlfile, "%d,", j); i++; } fprintf(wrlfile, "-1,\n"); } -void print_all_wrl_curves (void *a, void *b){ - Curve *c = *(Curve**)a; - if(c->Num<0) return; +void print_all_wrl_curves(void *a, void *b) +{ + Curve *c = *(Curve **) a; + if(c->Num < 0) + return; fprintf(wrlfile, "DEF Curve%d IndexedLineSet {\n", c->Num); fprintf(wrlfile, " coordIndex [\n"); - Tree_Action (c->Simplexes, print_wrl_simplex); + Tree_Action(c->Simplexes, print_wrl_simplex); fprintf(wrlfile, " ]\n"); fprintf(wrlfile, "}\n"); } -void print_all_wrl_surfaces (void *a, void *b){ - Surface *s = *(Surface**)a; +void print_all_wrl_surfaces(void *a, void *b) +{ + Surface *s = *(Surface **) a; fprintf(wrlfile, "DEF Surface%d IndexedFaceSet {\n", s->Num); fprintf(wrlfile, " coordIndex [\n"); - Tree_Action (s->Simplexes, print_wrl_simplex); + Tree_Action(s->Simplexes, print_wrl_simplex); fprintf(wrlfile, " ]\n"); fprintf(wrlfile, "}\n"); } -void process_wrl_elements (Mesh * M){ +void process_wrl_elements(Mesh * M) +{ if(!wrlnodes) Msg(GERROR, "VRML node list does not exist"); - else{ + else { Tree_Action(M->Curves, print_all_wrl_curves); Tree_Action(M->Surfaces, print_all_wrl_surfaces); } @@ -1291,43 +1333,44 @@ void process_wrl_elements (Mesh * M){ // Public Print_Mesh routine -void Print_Mesh (Mesh * M, char *c, int Type){ +void Print_Mesh(Mesh * M, char *c, int Type) +{ char name[256]; - strcpy (name, M->name); + strcpy(name, M->name); - if (Type == FORMAT_MSH){ - c ? strcpy (name, c) : strcat (name, ".msh"); - mshfile = fopen (name, "w"); - if (!mshfile){ + if(Type == FORMAT_MSH) { + c ? strcpy(name, c) : strcat(name, ".msh"); + mshfile = fopen(name, "w"); + if(!mshfile) { Msg(GERROR, "Unable to open file '%s'", name); return; } Msg(INFO, "Writing file '%s'", name); - process_msh_nodes (M); - process_msh_elements (M); + process_msh_nodes(M); + process_msh_elements(M); Msg(INFO, "Msh ouput complete '%s' (%d Nodes, %d Elements)", - name, MSH_NODE_NUM, MSH_ELEMENT_NUM - 1); + name, MSH_NODE_NUM, MSH_ELEMENT_NUM - 1); Msg(STATUS2, "Wrote '%s'", name); - fclose (mshfile); + fclose(mshfile); } - else if (Type == FORMAT_VRML){ - c ? strcpy (name, c) : strcat (name, ".wrl"); - wrlfile = fopen (name, "w"); - if (!wrlfile){ + else if(Type == FORMAT_VRML) { + c ? strcpy(name, c) : strcat(name, ".wrl"); + wrlfile = fopen(name, "w"); + if(!wrlfile) { Msg(GERROR, "Unable to open file '%s'", name); return; } Msg(INFO, "Writing file '%s'", name); - process_wrl_nodes (M); - process_wrl_elements (M); + process_wrl_nodes(M); + process_wrl_elements(M); Msg(INFO, "VRML ouput complete '%s'", name); Msg(STATUS2, "Wrote '%s'", name); - fclose (wrlfile); + fclose(wrlfile); } - else if (Type == FORMAT_UNV){ - c ? strcpy (name, c) : strcat (name, ".unv"); - unvfile = fopen (name, "w"); - if (!unvfile){ + else if(Type == FORMAT_UNV) { + c ? strcpy(name, c) : strcat(name, ".unv"); + unvfile = fopen(name, "w"); + if(!unvfile) { Msg(GERROR, "Unable to open file '%s'", name); return; } @@ -1339,29 +1382,29 @@ void Print_Mesh (Mesh * M, char *c, int Type){ process_unv_3D_elements(M); process_unv_2D_elements(M); // process_1D_elements (M); - fprintf (unvfile, "%6d\n", -1); + fprintf(unvfile, "%6d\n", -1); process_unv_groups(M); - fclose (unvfile); + fclose(unvfile); Msg(INFO, "Unv ouput complete '%s'", name); Msg(STATUS2, "Wrote '%s'", name); } - else if (Type == FORMAT_GREF){ - c ? strcpy (name, c) : strcat (name, ".Gref"); - Tree_T *TRN = Tree_Create (sizeof (Vertex *), compareFrozen); - Tree_T *TRE = Tree_Create (sizeof (Vertex *), compareFrozen); - Greffile = fopen (name, "w"); - if (!Greffile){ + else if(Type == FORMAT_GREF) { + c ? strcpy(name, c) : strcat(name, ".Gref"); + Tree_T *TRN = Tree_Create(sizeof(Vertex *), compareFrozen); + Tree_T *TRE = Tree_Create(sizeof(Vertex *), compareFrozen); + Greffile = fopen(name, "w"); + if(!Greffile) { Msg(GERROR, "Unable to open file '%s'", name); return; } Msg(INFO, "Writing file '%s'", name); - process_Gref_nodes (Greffile, M, TRN, TRE); - process_Gref_elements (Greffile, M, Tree_Nbr (TRN)); - process_Gref_poundarybonditions (Greffile, M, TRN, TRE); - fclose (Greffile); - Tree_Delete (TRN); - Tree_Delete (TRE); - EndConsecutiveNodes (M); + process_Gref_nodes(Greffile, M, TRN, TRE); + process_Gref_elements(Greffile, M, Tree_Nbr(TRN)); + process_Gref_poundarybonditions(Greffile, M, TRN, TRE); + fclose(Greffile); + Tree_Delete(TRN); + Tree_Delete(TRE); + EndConsecutiveNodes(M); Msg(INFO, "Gref ouput complete '%s'", name); Msg(STATUS2, "Wrote '%s'", name); } diff --git a/Mesh/Read_Mesh.cpp b/Mesh/Read_Mesh.cpp index e6c140fdbc2f699c787a9f9667d7b10d8924e998..89df548a5403dfb32dea8352898c0ab7d06be25f 100644 --- a/Mesh/Read_Mesh.cpp +++ b/Mesh/Read_Mesh.cpp @@ -1,4 +1,4 @@ -// $Id: Read_Mesh.cpp,v 1.49 2003-02-25 04:02:51 geuzaine Exp $ +// $Id: Read_Mesh.cpp,v 1.50 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -45,35 +45,37 @@ extern Context_T CTX; #define HEX2 12 #define PRI2 13 #define PYR2 14 -#define PNT 15 +#define PNT 15 #define NB_NOD_MAX_ELM 20 -int comparePhysicalGroup(const void *a, const void *b){ +int comparePhysicalGroup(const void *a, const void *b) +{ PhysicalGroup *q, *w; int cmp; q = *(PhysicalGroup **) a; w = *(PhysicalGroup **) b; cmp = q->Typ - w->Typ; - + if(cmp) return cmp; else return (q->Num - w->Num); } -void addPhysicalGroup(Mesh *M, int Type, int Physical, int Elementary){ +void addPhysicalGroup(Mesh * M, int Type, int Physical, int Elementary) +{ PhysicalGroup PG, *pg, **ppg; pg = &PG; pg->Typ = Type; pg->Num = Physical; - if((ppg=(PhysicalGroup**)List_PQuery(M->PhysicalGroups, &pg, - comparePhysicalGroup))){ + if((ppg = (PhysicalGroup **) List_PQuery(M->PhysicalGroups, &pg, + comparePhysicalGroup))) { List_Replace((*ppg)->Entities, &Elementary, fcmp_int); } - else{ - List_T *tmp = List_Create(1,1,sizeof(int)); + else { + List_T *tmp = List_Create(1, 1, sizeof(int)); List_Add(tmp, &Elementary); Add_PhysicalGroup(Physical, Type, tmp, M); List_Delete(tmp); @@ -84,262 +86,293 @@ void addPhysicalGroup(Mesh *M, int Type, int Physical, int Elementary){ the geometry along with the mesh (since we make Tree_Insert for the geometrical entities). And that's what we want. */ -void Read_Mesh_MSH (Mesh *M, FILE *File_GEO){ - +void Read_Mesh_MSH(Mesh * M, FILE * File_GEO) +{ char String[256]; - int Nbr_Nodes, Nbr_Elements, i_Node, i_Element; - int Num, Type, Physical, Elementary, i, j, replace; - double x , y , z, lc1, lc2 ; - Vertex *vert , verts[NB_NOD_MAX_ELM] ,*vertsp[NB_NOD_MAX_ELM] , **vertspp; - Simplex *simp ; - Hexahedron *hex ; - Prism *pri ; - Pyramid *pyr ; - Curve C , *c , **cc; - Surface S , *s , **ss; - Volume V , *v , **vv; - Tree_T *Duplicates=NULL ; - - while (1) { - do { - fgets(String,sizeof(String), File_GEO) ; - if (feof(File_GEO)) break ; - } while (String[0] != '$') ; - - if (feof(File_GEO)) break ; + int Nbr_Nodes, Nbr_Elements, i_Node, i_Element; + int Num, Type, Physical, Elementary, i, j, replace; + double x, y, z, lc1, lc2; + Vertex *vert, verts[NB_NOD_MAX_ELM], *vertsp[NB_NOD_MAX_ELM], **vertspp; + Simplex *simp; + Hexahedron *hex; + Prism *pri; + Pyramid *pyr; + Curve C, *c, **cc; + Surface S, *s, **ss; + Volume V, *v, **vv; + Tree_T *Duplicates = NULL; + + while(1) { + do { + fgets(String, sizeof(String), File_GEO); + if(feof(File_GEO)) + break; + } while(String[0] != '$'); + + if(feof(File_GEO)) + break; /* P T S */ - if (!strncmp(&String[1], "PTS", 3)) { + if(!strncmp(&String[1], "PTS", 3)) { - fscanf(File_GEO, "%d", &Nbr_Nodes) ; + fscanf(File_GEO, "%d", &Nbr_Nodes); Msg(INFO, "%d Points", Nbr_Nodes); - for (i_Node = 0 ; i_Node < Nbr_Nodes ; i_Node++) { - fscanf(File_GEO, "%d %lf %lf %lf %lf %lf", &Num, &x, &y, &z, &lc1, &lc2) ; - vert = Create_Vertex (Num, x, y, z, lc1 , lc2); - Tree_Replace(M->Points, &vert) ; + for(i_Node = 0; i_Node < Nbr_Nodes; i_Node++) { + fscanf(File_GEO, "%d %lf %lf %lf %lf %lf", &Num, &x, &y, &z, &lc1, + &lc2); + vert = Create_Vertex(Num, x, y, z, lc1, lc2); + Tree_Replace(M->Points, &vert); } } /* N O E */ - if (!strncmp(&String[1], "NO", 2)) { /* $NOE or $NOD */ - - fscanf(File_GEO, "%d", &Nbr_Nodes) ; + if(!strncmp(&String[1], "NO", 2)) { /* $NOE or $NOD */ + + fscanf(File_GEO, "%d", &Nbr_Nodes); Msg(INFO, "%d Nodes", Nbr_Nodes); - + if(CTX.mesh.check_duplicates) - Duplicates = Tree_Create (sizeof (Vertex *), comparePosition); - for (i_Node = 0 ; i_Node < Nbr_Nodes ; i_Node++) { - fscanf(File_GEO, "%d %lf %lf %lf", &Num, &x, &y, &z) ; - vert = Create_Vertex (Num, x, y, z, 1.0 ,0.0); + Duplicates = Tree_Create(sizeof(Vertex *), comparePosition); + for(i_Node = 0; i_Node < Nbr_Nodes; i_Node++) { + fscanf(File_GEO, "%d %lf %lf %lf", &Num, &x, &y, &z); + vert = Create_Vertex(Num, x, y, z, 1.0, 0.0); Tree_Replace(M->Vertices, &vert); - if(CTX.mesh.check_duplicates){ - if((vertspp = (Vertex**)Tree_PQuery(Duplicates, &vert))) - Msg(GERROR, "Nodes %d and %d have identical coordinates (%g, %g, %g)", - Num, (*vertspp)->Num, x, y, z); - else - Tree_Add(Duplicates, &vert); - } + if(CTX.mesh.check_duplicates) { + if((vertspp = (Vertex **) Tree_PQuery(Duplicates, &vert))) + Msg(GERROR, + "Nodes %d and %d have identical coordinates (%g, %g, %g)", + Num, (*vertspp)->Num, x, y, z); + else + Tree_Add(Duplicates, &vert); + } } if(CTX.mesh.check_duplicates) - Tree_Delete(Duplicates); + Tree_Delete(Duplicates); } - + /* ELEMENTS */ - else if (!strncmp(&String[1], "ELM", 3)) { + else if(!strncmp(&String[1], "ELM", 3)) { - fscanf(File_GEO, "%d", &Nbr_Elements) ; + fscanf(File_GEO, "%d", &Nbr_Elements); Msg(INFO, "%d Elements", Nbr_Elements); if(CTX.mesh.check_duplicates) - Duplicates = Tree_Create (sizeof (Vertex *), comparePosition); - - for (i_Element = 0 ; i_Element < Nbr_Elements ; i_Element++) { - - fscanf(File_GEO, "%d %d %d %d %d", - &Num, &Type, &Physical, &Elementary, &Nbr_Nodes) ; - //jf: &Num, &Type, &Elementary, &Physical, &Nbr_Nodes) ; - - for (j = 0 ; j < Nbr_Nodes ; j++) - fscanf(File_GEO, "%d", &verts[j].Num) ; - - switch(Type){ - case LGN1: case LGN2: - c = &C; c->Num = abs(Elementary); - if(!(cc = (Curve**)Tree_PQuery(M->Curves, &c))){ - c = Create_Curve(abs(Elementary), MSH_SEGM_LINE, 0, NULL, - NULL, -1, -1, 0., 1.); - c->Dirty=1; - Tree_Add(M->Curves, &c); - addPhysicalGroup(M, MSH_PHYSICAL_LINE, Physical, abs(Elementary)); - } - else - c = *cc; - break; - case TRI1: case QUA1: case TRI2: case QUA2: - s = &S; s->Num = Elementary; - if(!(ss = (Surface**)Tree_PQuery(M->Surfaces, &s))){ - s = Create_Surface(Elementary, MSH_SURF_PLAN); - s->Dirty=1; - Tree_Add(M->Surfaces, &s); - addPhysicalGroup(M, MSH_PHYSICAL_SURFACE, Physical, Elementary); - } - else - s = *ss; - break; - case TET1: case HEX1: case PRI1: case PYR1: - case TET2: case HEX2: case PRI2: case PYR2: - v = &V; v->Num = Elementary; - if(!(vv = (Volume**)Tree_PQuery(M->Volumes, &v))){ - v = Create_Volume(Elementary, MSH_VOLUME); - v->Dirty=1; - Tree_Add(M->Volumes, &v); - addPhysicalGroup(M, MSH_PHYSICAL_VOLUME, Physical, Elementary); - } - else - v = *vv; - break; - default : - break; - } - - for(i=0 ; i<Nbr_Nodes ; i++) { - vertsp[i] = &verts[i]; - if(!(vertspp = (Vertex**)Tree_PQuery(M->Vertices, &vertsp[i]))) - Msg(GERROR, "Unknown vertex %d in element %d", verts[i].Num, Num); - else - vertsp[i] = *vertspp; - } - - if(CTX.mesh.check_duplicates){ - vert = Create_Vertex (Num, 0., 0., 0., 1.0 ,0.0); - for(i=0 ; i<Nbr_Nodes ; i++){ - vert->Pos.X += vertsp[i]->Pos.X ; - vert->Pos.Y += vertsp[i]->Pos.Y ; - vert->Pos.Z += vertsp[i]->Pos.Z ; - } - vert->Pos.X /= (double) Nbr_Nodes; - vert->Pos.Y /= (double) Nbr_Nodes; - vert->Pos.Z /= (double) Nbr_Nodes; - if((vertspp = (Vertex**)Tree_PQuery(Duplicates, &vert))) - Msg(GERROR, "Elements %d and %d have identical barycenters", - Num, (*vertspp)->Num); - else - Tree_Add(Duplicates, &vert); - } - - switch(Type){ - case LGN1: - simp = Create_Simplex(vertsp[0], vertsp[1], NULL , NULL); - simp->Num = Num ; - simp->iEnt = Elementary ; - Tree_Replace(c->Simplexes, &simp) ; - //NO!!! Tree_Replace(M->Simplexes, &simp) ; - break; - case TRI1: - simp = Create_Simplex(vertsp[0], vertsp[1], vertsp[2], NULL); - simp->Num = Num ; - simp->iEnt = Elementary ; - Tree_Replace(s->Simplexes, &simp) ; - replace = Tree_Replace(M->Simplexes, &simp) ; - if(!replace) M->Statistics[7]++; - break; - case QUA1: - simp = Create_Quadrangle(vertsp[0], vertsp[1], vertsp[2], vertsp[3]); - simp->Num = Num ; - simp->iEnt = Elementary ; - Tree_Replace(s->Simplexes, &simp) ; - replace = Tree_Replace(M->Simplexes, &simp) ; - if(!replace) { - M->Statistics[7]++;//since s->Simplexes holds quads, too :-( - M->Statistics[8]++; - } - break; - case TET1: - simp = Create_Simplex(vertsp[0], vertsp[1], vertsp[2], vertsp[3]); - simp->Num = Num ; - simp->iEnt = Elementary ; - Tree_Replace(v->Simplexes, &simp) ; - replace = Tree_Replace(M->Simplexes, &simp) ; - if(!replace) M->Statistics[9]++; - break; - case HEX1: - hex = Create_Hexahedron(vertsp[0], vertsp[1], vertsp[2], vertsp[3], - vertsp[4], vertsp[5], vertsp[6], vertsp[7]); - hex->Num = Num ; - hex->iEnt = Elementary ; - replace = Tree_Replace(v->Hexahedra, &hex) ; - if(!replace) M->Statistics[10]++; - break; - case PRI1: - pri = Create_Prism(vertsp[0], vertsp[1], vertsp[2], - vertsp[3], vertsp[4], vertsp[5]); - pri->Num = Num ; - pri->iEnt = Elementary ; - replace = Tree_Replace(v->Prisms, &pri) ; - if(!replace) M->Statistics[11]++; - break; - case PYR1: - pyr = Create_Pyramid(vertsp[0], vertsp[1], vertsp[2], - vertsp[3], vertsp[4]); - pyr->Num = Num ; - pyr->iEnt = Elementary ; - replace = Tree_Replace(v->Pyramids, &pyr) ; - if(!replace) M->Statistics[12]++; - break; - case PNT: - Tree_Replace(M->Points, &vertsp[0]) ; - break; - default : - Msg(WARNING, "Unknown type of element in Read_Mesh"); - break; - } + Duplicates = Tree_Create(sizeof(Vertex *), comparePosition); + + for(i_Element = 0; i_Element < Nbr_Elements; i_Element++) { + + fscanf(File_GEO, "%d %d %d %d %d", + &Num, &Type, &Physical, &Elementary, &Nbr_Nodes); + //jf: &Num, &Type, &Elementary, &Physical, &Nbr_Nodes) ; + + for(j = 0; j < Nbr_Nodes; j++) + fscanf(File_GEO, "%d", &verts[j].Num); + + switch (Type) { + case LGN1: + case LGN2: + c = &C; + c->Num = abs(Elementary); + if(!(cc = (Curve **) Tree_PQuery(M->Curves, &c))) { + c = Create_Curve(abs(Elementary), MSH_SEGM_LINE, 0, NULL, + NULL, -1, -1, 0., 1.); + c->Dirty = 1; + Tree_Add(M->Curves, &c); + addPhysicalGroup(M, MSH_PHYSICAL_LINE, Physical, abs(Elementary)); + } + else + c = *cc; + break; + case TRI1: + case QUA1: + case TRI2: + case QUA2: + s = &S; + s->Num = Elementary; + if(!(ss = (Surface **) Tree_PQuery(M->Surfaces, &s))) { + s = Create_Surface(Elementary, MSH_SURF_PLAN); + s->Dirty = 1; + Tree_Add(M->Surfaces, &s); + addPhysicalGroup(M, MSH_PHYSICAL_SURFACE, Physical, Elementary); + } + else + s = *ss; + break; + case TET1: + case HEX1: + case PRI1: + case PYR1: + case TET2: + case HEX2: + case PRI2: + case PYR2: + v = &V; + v->Num = Elementary; + if(!(vv = (Volume **) Tree_PQuery(M->Volumes, &v))) { + v = Create_Volume(Elementary, MSH_VOLUME); + v->Dirty = 1; + Tree_Add(M->Volumes, &v); + addPhysicalGroup(M, MSH_PHYSICAL_VOLUME, Physical, Elementary); + } + else + v = *vv; + break; + default: + break; + } + + for(i = 0; i < Nbr_Nodes; i++) { + vertsp[i] = &verts[i]; + if(!(vertspp = (Vertex **) Tree_PQuery(M->Vertices, &vertsp[i]))) + Msg(GERROR, "Unknown vertex %d in element %d", verts[i].Num, Num); + else + vertsp[i] = *vertspp; + } + + if(CTX.mesh.check_duplicates) { + vert = Create_Vertex(Num, 0., 0., 0., 1.0, 0.0); + for(i = 0; i < Nbr_Nodes; i++) { + vert->Pos.X += vertsp[i]->Pos.X; + vert->Pos.Y += vertsp[i]->Pos.Y; + vert->Pos.Z += vertsp[i]->Pos.Z; + } + vert->Pos.X /= (double)Nbr_Nodes; + vert->Pos.Y /= (double)Nbr_Nodes; + vert->Pos.Z /= (double)Nbr_Nodes; + if((vertspp = (Vertex **) Tree_PQuery(Duplicates, &vert))) + Msg(GERROR, "Elements %d and %d have identical barycenters", + Num, (*vertspp)->Num); + else + Tree_Add(Duplicates, &vert); + } + + switch (Type) { + case LGN1: + simp = Create_Simplex(vertsp[0], vertsp[1], NULL, NULL); + simp->Num = Num; + simp->iEnt = Elementary; + Tree_Replace(c->Simplexes, &simp); + //NO!!! Tree_Replace(M->Simplexes, &simp) ; + break; + case TRI1: + simp = Create_Simplex(vertsp[0], vertsp[1], vertsp[2], NULL); + simp->Num = Num; + simp->iEnt = Elementary; + Tree_Replace(s->Simplexes, &simp); + replace = Tree_Replace(M->Simplexes, &simp); + if(!replace) + M->Statistics[7]++; + break; + case QUA1: + simp = + Create_Quadrangle(vertsp[0], vertsp[1], vertsp[2], vertsp[3]); + simp->Num = Num; + simp->iEnt = Elementary; + Tree_Replace(s->Simplexes, &simp); + replace = Tree_Replace(M->Simplexes, &simp); + if(!replace) { + M->Statistics[7]++; //since s->Simplexes holds quads, too :-( + M->Statistics[8]++; + } + break; + case TET1: + simp = Create_Simplex(vertsp[0], vertsp[1], vertsp[2], vertsp[3]); + simp->Num = Num; + simp->iEnt = Elementary; + Tree_Replace(v->Simplexes, &simp); + replace = Tree_Replace(M->Simplexes, &simp); + if(!replace) + M->Statistics[9]++; + break; + case HEX1: + hex = Create_Hexahedron(vertsp[0], vertsp[1], vertsp[2], vertsp[3], + vertsp[4], vertsp[5], vertsp[6], vertsp[7]); + hex->Num = Num; + hex->iEnt = Elementary; + replace = Tree_Replace(v->Hexahedra, &hex); + if(!replace) + M->Statistics[10]++; + break; + case PRI1: + pri = Create_Prism(vertsp[0], vertsp[1], vertsp[2], + vertsp[3], vertsp[4], vertsp[5]); + pri->Num = Num; + pri->iEnt = Elementary; + replace = Tree_Replace(v->Prisms, &pri); + if(!replace) + M->Statistics[11]++; + break; + case PYR1: + pyr = Create_Pyramid(vertsp[0], vertsp[1], vertsp[2], + vertsp[3], vertsp[4]); + pyr->Num = Num; + pyr->iEnt = Elementary; + replace = Tree_Replace(v->Pyramids, &pyr); + if(!replace) + M->Statistics[12]++; + break; + case PNT: + Tree_Replace(M->Points, &vertsp[0]); + break; + default: + Msg(WARNING, "Unknown type of element in Read_Mesh"); + break; + } } - if(CTX.mesh.check_duplicates){ - Tree_Action(Duplicates, Free_Vertex); - Tree_Delete(Duplicates); + if(CTX.mesh.check_duplicates) { + Tree_Action(Duplicates, Free_Vertex); + Tree_Delete(Duplicates); } } do { - fgets(String, 256, File_GEO) ; - if (feof(File_GEO)) Msg(GERROR, "Prematured end of mesh file"); - } while (String[0] != '$') ; - - } - - if(Tree_Nbr(M->Volumes)){ - M->status = 3 ; - M->Statistics[6]=Tree_Nbr(M->Vertices); //incorrect, mais... + fgets(String, 256, File_GEO); + if(feof(File_GEO)) + Msg(GERROR, "Prematured end of mesh file"); + } while(String[0] != '$'); + } - else if(Tree_Nbr(M->Surfaces)){ - M->status = 2 ; - M->Statistics[5]=Tree_Nbr(M->Vertices); //incorrect, mais... + + if(Tree_Nbr(M->Volumes)) { + M->status = 3; + M->Statistics[6] = Tree_Nbr(M->Vertices); //incorrect, mais... } - else if(Tree_Nbr(M->Curves)){ - M->status = 1 ; - M->Statistics[4]=Tree_Nbr(M->Vertices); //incorrect, mais... + else if(Tree_Nbr(M->Surfaces)) { + M->status = 2; + M->Statistics[5] = Tree_Nbr(M->Vertices); //incorrect, mais... + } + else if(Tree_Nbr(M->Curves)) { + M->status = 1; + M->Statistics[4] = Tree_Nbr(M->Vertices); //incorrect, mais... } else if(Tree_Nbr(M->Points)) - M->status = 0 ; + M->status = 0; else - M->status = -1 ; + M->status = -1; } // Public Read_Mesh routine -void Read_Mesh_SMS (Mesh *m, FILE *File_GEO); - -void Read_Mesh (Mesh *M, FILE *File_GEO, int type){ - switch(type){ - case FORMAT_MSH : Read_Mesh_MSH(M,File_GEO); break; - case FORMAT_SMS : Read_Mesh_SMS(M,File_GEO); break; - default : Msg(WARNING, "Unkown mesh file format to read"); break; +void Read_Mesh_SMS(Mesh * m, FILE * File_GEO); + +void Read_Mesh(Mesh * M, FILE * File_GEO, int type) +{ + switch (type) { + case FORMAT_MSH: + Read_Mesh_MSH(M, File_GEO); + break; + case FORMAT_SMS: + Read_Mesh_SMS(M, File_GEO); + break; + default: + Msg(WARNING, "Unkown mesh file format to read"); + break; } } diff --git a/Mesh/SMS.cpp b/Mesh/SMS.cpp index dbeb77f92878df09a2b366eff56f41fffe40062e..cdeace605624cb00fd1ff2bf4e774699b6e9b581 100644 --- a/Mesh/SMS.cpp +++ b/Mesh/SMS.cpp @@ -1,4 +1,4 @@ -// $Id: SMS.cpp,v 1.11 2003-02-25 04:02:51 geuzaine Exp $ +// $Id: SMS.cpp,v 1.12 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -46,346 +46,341 @@ extern Context_T CTX; #define ENTITY_REGION 3 #define ENTITY_NONE 4 extern int FACE_DIMENSION; -void TRIE_MON_GARS2 (void *a, void *b) +void TRIE_MON_GARS2(void *a, void *b) { Simplex *s = *(Simplex **) a; - s->Fourre_Simplexe (s->V[0], s->V[1], s->V[2], s->V[3]); + s->Fourre_Simplexe(s->V[0], s->V[1], s->V[2], s->V[3]); } -void Read_VTK_File (char *file, Mesh *m) +void Read_VTK_File(char *file, Mesh * m) { - - FILE *in = fopen (file,"r"); - if(!in)return; - char line[256],dumline1[256],dumline2[256]; + FILE *in = fopen(file, "r"); + if(!in) + return; + char line[256], dumline1[256], dumline2[256]; int i; - int NbFaces,NbVertices,Vertex1,Vertex2,Vertex3,NbVerticesOnFace; - double x,y,z; - Vertex *v1,*v2,*v3,*v4; - - fgets(line,255,in); - fgets(line,255,in); - fgets(line,255,in); - fgets(line,255,in); - fgets(line,255,in); - sscanf(line,"%s %d %s",dumline1,&NbVertices,dumline2); - - Surface *surf = Create_Surface(1,MSH_SURF_DISCRETE); - surf->Generatrices = List_Create(1,1,sizeof(Curve*)); - Tree_Add(m->Surfaces,&surf); - - for(i=0;i<NbVertices;i++) - { - fscanf(in,"%le %le %le",&x,&y,&z); - Vertex *v = Create_Vertex(i,x,y,z,1.0,1.0); - Tree_Add(m->Vertices,&v); - Tree_Add(surf->Vertices,&v); - v->ListSurf = List_Create(1,1,sizeof(Surface*)); - List_Add(v->ListSurf,&surf); + int NbFaces, NbVertices, Vertex1, Vertex2, Vertex3, NbVerticesOnFace; + double x, y, z; + Vertex *v1, *v2, *v3, *v4; + + fgets(line, 255, in); + fgets(line, 255, in); + fgets(line, 255, in); + fgets(line, 255, in); + fgets(line, 255, in); + sscanf(line, "%s %d %s", dumline1, &NbVertices, dumline2); + + Surface *surf = Create_Surface(1, MSH_SURF_DISCRETE); + surf->Generatrices = List_Create(1, 1, sizeof(Curve *)); + Tree_Add(m->Surfaces, &surf); + + for(i = 0; i < NbVertices; i++) { + fscanf(in, "%le %le %le", &x, &y, &z); + Vertex *v = Create_Vertex(i, x, y, z, 1.0, 1.0); + Tree_Add(m->Vertices, &v); + Tree_Add(surf->Vertices, &v); + v->ListSurf = List_Create(1, 1, sizeof(Surface *)); + List_Add(v->ListSurf, &surf); + } + fscanf(in, "%s %d %d", dumline1, &NbFaces, &i); + for(int i = 0; i < NbFaces; i++) { + fscanf(in, "%d", &NbVerticesOnFace); + if(NbVerticesOnFace == 3) { + fscanf(in, "%d %d %d", &Vertex1, &Vertex2, &Vertex3); + v1 = FindVertex(Vertex1, m); + v2 = FindVertex(Vertex2, m); + v3 = FindVertex(Vertex3, m); + v4 = NULL; } - fscanf(in,"%s %d %d",dumline1,&NbFaces,&i); - for(int i=0;i<NbFaces;i++) - { - fscanf(in,"%d",&NbVerticesOnFace); - if(NbVerticesOnFace == 3) - { - fscanf(in,"%d %d %d", &Vertex1,&Vertex2,&Vertex3); - v1 = FindVertex(Vertex1,m); - v2 = FindVertex(Vertex2,m); - v3 = FindVertex(Vertex3,m); - v4 = NULL; - } - else - { - printf("no quads man !\n"); - exit(-1); - } - Simplex *s = Create_Simplex (v1,v2,v3,v4); - s->V[0] = v1; - s->V[1] = v2; - s->V[2] = v3; - s->Num = i; - s->iEnt = 1; - if((surf = FindSurface(1,m))) - { - } - else - { - surf = Create_Surface(1,MSH_SURF_DISCRETE); - surf->Generatrices = List_Create(1,1,sizeof(Curve*)); - Tree_Add(m->Surfaces,&surf); - } - Tree_Add(surf->Simplexes,&s); - } + else { + printf("no quads man !\n"); + exit(-1); + } + Simplex *s = Create_Simplex(v1, v2, v3, v4); + s->V[0] = v1; + s->V[1] = v2; + s->V[2] = v3; + s->Num = i; + s->iEnt = 1; + if((surf = FindSurface(1, m))) { + } + else { + surf = Create_Surface(1, MSH_SURF_DISCRETE); + surf->Generatrices = List_Create(1, 1, sizeof(Curve *)); + Tree_Add(m->Surfaces, &surf); + } + Tree_Add(surf->Simplexes, &s); + } FACE_DIMENSION = 2; - Tree_Action (surf->Simplexes, TRIE_MON_GARS2); - if(NbFaces)m->status = 2; + Tree_Action(surf->Simplexes, TRIE_MON_GARS2); + if(NbFaces) + m->status = 2; - Volume *vol = Create_Volume(1,MSH_VOLUME); - vol->Surfaces = List_Create(1,1,sizeof(Surface*)); - List_Add(vol->Surfaces,&surf); - Tree_Add(m->Volumes,&vol); + Volume *vol = Create_Volume(1, MSH_VOLUME); + vol->Surfaces = List_Create(1, 1, sizeof(Surface *)); + List_Add(vol->Surfaces, &surf); + Tree_Add(m->Volumes, &vol); - fclose (in); + fclose(in); } -void Read_Mesh_SMS (Mesh *m, FILE *in) +void Read_Mesh_SMS(Mesh * m, FILE * in) { char line[1023]; - int i,patch,nbPts; - int NbRegions,NbFaces,NbEdges,NbVertices,NbPoints, - GEntityType,GEntityId,EntityNbConnections,Dummy, - Edge1,Edge2,Edge3,Edge4,Face1,Face2,Face3,Face4; - int VertexId1,VertexId2,NbEdgesOnFace,NbFacesOnRegion; - double x,y,z,u,v; - List_T *AllEdges,*AllFaces; - Vertex *v1=NULL,*v2=NULL,*v3=NULL,*v4=NULL; - - - fscanf(in,"%s %d",line,&Dummy); - fscanf(in,"%d %d %d %d %d",&NbRegions,&NbFaces,&NbEdges,&NbVertices,&NbPoints); - - Msg(INFO,"reading a mesh in scorec format"); - Msg(INFO,"%d Vertices",NbVertices); - - for(i=0;i<NbVertices;i++) - { - fscanf(in,"%d",&GEntityId); - if(GEntityId) - { - fscanf(in,"%d %d %lf %lf %lf",&GEntityType,&EntityNbConnections,&x,&y,&z); - Vertex *vert = Create_Vertex(i,x,y,z,1.0,1.0); - Tree_Add(m->Vertices,&vert); - switch(GEntityType) - { - case 0: - Tree_Add(m->Points,&vert); - break; - case 1: - fscanf(in,"%le",&u); - break; - case 2: - fscanf(in,"%le %le %d",&u,&v,&patch); - break; - case 3: - break; - } - } + int i, patch, nbPts; + int NbRegions, NbFaces, NbEdges, NbVertices, NbPoints, + GEntityType, GEntityId, EntityNbConnections, Dummy, + Edge1, Edge2, Edge3, Edge4, Face1, Face2, Face3, Face4; + int VertexId1, VertexId2, NbEdgesOnFace, NbFacesOnRegion; + double x, y, z, u, v; + List_T *AllEdges, *AllFaces; + Vertex *v1 = NULL, *v2 = NULL, *v3 = NULL, *v4 = NULL; + + + fscanf(in, "%s %d", line, &Dummy); + fscanf(in, "%d %d %d %d %d", &NbRegions, &NbFaces, &NbEdges, &NbVertices, + &NbPoints); + + Msg(INFO, "reading a mesh in scorec format"); + Msg(INFO, "%d Vertices", NbVertices); + + for(i = 0; i < NbVertices; i++) { + fscanf(in, "%d", &GEntityId); + if(GEntityId) { + fscanf(in, "%d %d %lf %lf %lf", &GEntityType, &EntityNbConnections, &x, + &y, &z); + Vertex *vert = Create_Vertex(i, x, y, z, 1.0, 1.0); + Tree_Add(m->Vertices, &vert); + switch (GEntityType) { + case 0: + Tree_Add(m->Points, &vert); + break; + case 1: + fscanf(in, "%le", &u); + break; + case 2: + fscanf(in, "%le %le %d", &u, &v, &patch); + break; + case 3: + break; + } } - - Msg(INFO,"%d Edges",NbEdges); - AllEdges = List_Create(NbEdges,1,sizeof(Edge)); - Edge e; + } - for(int i=0;i<NbEdges;i++) - { - fscanf(in,"%d",&GEntityId); + Msg(INFO, "%d Edges", NbEdges); + AllEdges = List_Create(NbEdges, 1, sizeof(Edge)); + Edge e; - if(GEntityId) - { - fscanf(in,"%d %d %d %d %d",&GEntityType, &VertexId1,&VertexId2,&EntityNbConnections,&nbPts); - for(int j=0;j<nbPts;j++) - { - switch(GEntityType) - { - case 0: - break; - case 1: - fscanf(in,"%le",&u); - break; - case 2: - fscanf(in,"%le %le %d",&u,&v,&patch); - break; - case 3: - break; - } - } - e.Points = NULL; - Vertex *v1 = FindVertex(VertexId1-1,m); - Vertex *v2 = FindVertex(VertexId2-1,m); - e.V[0] = v1; - e.V[1] = v2; - List_Add(AllEdges,&e); - switch(GEntityType) - { - case ENTITY_EDGE : - Simplex *s = Create_Simplex(v1,v2,NULL,NULL); - Curve *c; - if((c = FindCurve(GEntityId,m))) - { - } - else - { - c = Create_Curve(GEntityId,MSH_SEGM_DISCRETE,1,NULL,NULL,-1,-1,0,1); - c->beg = v1; - c->end = v2; - Tree_Add(m->Curves,&c); - } - s->iEnt = GEntityId; - // List_Add(v1->ListCurves,&c); - // List_Add(v2->ListCurves,&c); - Tree_Add(c->Simplexes,&s); - s->Num = i; - } - } + for(int i = 0; i < NbEdges; i++) { + fscanf(in, "%d", &GEntityId); + + if(GEntityId) { + fscanf(in, "%d %d %d %d %d", &GEntityType, &VertexId1, &VertexId2, + &EntityNbConnections, &nbPts); + for(int j = 0; j < nbPts; j++) { + switch (GEntityType) { + case 0: + break; + case 1: + fscanf(in, "%le", &u); + break; + case 2: + fscanf(in, "%le %le %d", &u, &v, &patch); + break; + case 3: + break; + } + } + e.Points = NULL; + Vertex *v1 = FindVertex(VertexId1 - 1, m); + Vertex *v2 = FindVertex(VertexId2 - 1, m); + e.V[0] = v1; + e.V[1] = v2; + List_Add(AllEdges, &e); + switch (GEntityType) { + case ENTITY_EDGE: + Simplex * s = Create_Simplex(v1, v2, NULL, NULL); + Curve *c; + if((c = FindCurve(GEntityId, m))) { + } + else { + c = + Create_Curve(GEntityId, MSH_SEGM_DISCRETE, 1, NULL, NULL, -1, -1, + 0, 1); + c->beg = v1; + c->end = v2; + Tree_Add(m->Curves, &c); + } + s->iEnt = GEntityId; + // List_Add(v1->ListCurves,&c); + // List_Add(v2->ListCurves,&c); + Tree_Add(c->Simplexes, &s); + s->Num = i; + } } - - AllFaces = List_Create(NbFaces,1,sizeof(Simplex*)); + } - Volume *vol = Create_Volume(1,MSH_VOLUME); - vol->Surfaces = List_Create(1,1,sizeof(Surface*)); - Tree_Add(m->Volumes,&vol); - FACE_DIMENSION = 2; + AllFaces = List_Create(NbFaces, 1, sizeof(Simplex *)); - Msg(INFO,"%d Faces",NbFaces); - for(int i=0;i<NbFaces;i++) - { - fscanf(in,"%d",&GEntityId); - if(GEntityId) - { - fscanf(in,"%d %d",&GEntityType, &NbEdgesOnFace); - - - List_T *Lists[4] = {0,0,0,0}; + Volume *vol = Create_Volume(1, MSH_VOLUME); + vol->Surfaces = List_Create(1, 1, sizeof(Surface *)); + Tree_Add(m->Volumes, &vol); + FACE_DIMENSION = 2; - if(NbEdgesOnFace == 3) - { - fscanf(in,"%d %d %d %d",&Edge1,&Edge2,&Edge3,&nbPts); - List_Read(AllEdges,abs(Edge1)-1,&e); - Lists[0] = e.Points; - if(Edge1 > 0)v1 = e.V[0]; - else v1 = e.V[1]; - List_Read(AllEdges,abs(Edge2)-1,&e); - Lists[1] = e.Points; - if(Edge2 > 0)v2 = e.V[0]; - else v2 = e.V[1]; - List_Read(AllEdges,abs(Edge3)-1,&e); - Lists[2] = e.Points; - if(Edge3 > 0)v3 = e.V[0]; - else v3 = e.V[1]; - v4 = NULL; - } - else if(NbEdgesOnFace == 4) - { - fscanf(in,"%d %d %d %d %d",&Edge1,&Edge2,&Edge3,&Edge4,&nbPts); - List_Read(AllEdges,abs(Edge1)-1,&e); - if(Edge1 > 0)v1 = e.V[0]; - else v1 = e.V[1]; - List_Read(AllEdges,abs(Edge2)-1,&e); - if(Edge2 > 0)v2 = e.V[0]; - else v2 = e.V[1]; - List_Read(AllEdges,abs(Edge3)-1,&e); - if(Edge3 > 0)v3 = e.V[0]; - else v3 = e.V[1]; - List_Read(AllEdges,abs(Edge4)-1,&e); - if(Edge4 > 0)v4 = e.V[0]; - else v4 = e.V[1]; - } - else - { - Msg(FATAL, "Read mesh SMS exiting"); - } - for(int j=0;j<nbPts;j++) - { - switch(GEntityType) - { - case 0: - break; - case 1: - fscanf(in,"%le",&u); - break; - case 2: - fscanf(in,"%le %le %d",&u,&v,&patch); - break; - case 3: - break; - } - } + Msg(INFO, "%d Faces", NbFaces); + for(int i = 0; i < NbFaces; i++) { + fscanf(in, "%d", &GEntityId); + if(GEntityId) { + fscanf(in, "%d %d", &GEntityType, &NbEdgesOnFace); + + + List_T *Lists[4] = { 0, 0, 0, 0 }; + + if(NbEdgesOnFace == 3) { + fscanf(in, "%d %d %d %d", &Edge1, &Edge2, &Edge3, &nbPts); + List_Read(AllEdges, abs(Edge1) - 1, &e); + Lists[0] = e.Points; + if(Edge1 > 0) + v1 = e.V[0]; + else + v1 = e.V[1]; + List_Read(AllEdges, abs(Edge2) - 1, &e); + Lists[1] = e.Points; + if(Edge2 > 0) + v2 = e.V[0]; + else + v2 = e.V[1]; + List_Read(AllEdges, abs(Edge3) - 1, &e); + Lists[2] = e.Points; + if(Edge3 > 0) + v3 = e.V[0]; + else + v3 = e.V[1]; + v4 = NULL; + } + else if(NbEdgesOnFace == 4) { + fscanf(in, "%d %d %d %d %d", &Edge1, &Edge2, &Edge3, &Edge4, &nbPts); + List_Read(AllEdges, abs(Edge1) - 1, &e); + if(Edge1 > 0) + v1 = e.V[0]; + else + v1 = e.V[1]; + List_Read(AllEdges, abs(Edge2) - 1, &e); + if(Edge2 > 0) + v2 = e.V[0]; + else + v2 = e.V[1]; + List_Read(AllEdges, abs(Edge3) - 1, &e); + if(Edge3 > 0) + v3 = e.V[0]; + else + v3 = e.V[1]; + List_Read(AllEdges, abs(Edge4) - 1, &e); + if(Edge4 > 0) + v4 = e.V[0]; + else + v4 = e.V[1]; + } + else { + Msg(FATAL, "Read mesh SMS exiting"); + } + for(int j = 0; j < nbPts; j++) { + switch (GEntityType) { + case 0: + break; + case 1: + fscanf(in, "%le", &u); + break; + case 2: + fscanf(in, "%le %le %d", &u, &v, &patch); + break; + case 3: + break; + } + } - Simplex *s = Create_Simplex (v1,v2,v3,v4); - // s->curvedBounds(Edge1,Edge2,Edge3,Edge4,Lists,m->VertexEdges); - s->Num = i+1; - s->iEnt = GEntityId+10000; - Surface *surf; - List_Add(AllFaces,&s); - - switch(GEntityType) - { - case ENTITY_REGION : - break; - case ENTITY_FACE : - if((surf = FindSurface(GEntityId+10000,m))) - { - } - else - { - surf = Create_Surface(GEntityId+10000,MSH_SURF_DISCRETE); - if(!NbRegions)List_Add(vol->Surfaces,&surf); - surf->Generatrices = List_Create(1,1,sizeof(Curve*)); - Tree_Add(m->Surfaces,&surf); - } - Tree_Add(surf->Vertices,&s->V[0]); - Tree_Add(surf->Vertices,&s->V[1]); - Tree_Add(surf->Vertices,&s->V[2]); - Tree_Add(surf->Simplexes,&s); - } - } + Simplex *s = Create_Simplex(v1, v2, v3, v4); + // s->curvedBounds(Edge1,Edge2,Edge3,Edge4,Lists,m->VertexEdges); + s->Num = i + 1; + s->iEnt = GEntityId + 10000; + Surface *surf; + List_Add(AllFaces, &s); + + switch (GEntityType) { + case ENTITY_REGION: + break; + case ENTITY_FACE: + if((surf = FindSurface(GEntityId + 10000, m))) { + } + else { + surf = Create_Surface(GEntityId + 10000, MSH_SURF_DISCRETE); + if(!NbRegions) + List_Add(vol->Surfaces, &surf); + surf->Generatrices = List_Create(1, 1, sizeof(Curve *)); + Tree_Add(m->Surfaces, &surf); + } + Tree_Add(surf->Vertices, &s->V[0]); + Tree_Add(surf->Vertices, &s->V[1]); + Tree_Add(surf->Vertices, &s->V[2]); + Tree_Add(surf->Simplexes, &s); + } } - - - Msg(INFO,"%d Region",NbRegions); - - for(int i=0;i<NbRegions;i++) - { - fscanf(in,"%d",&GEntityId); - if(GEntityId) - { - fscanf(in,"%d",&NbFacesOnRegion); - Simplex *myS1,*myS2; - if(NbFacesOnRegion == 4) - { - fscanf(in,"%d %d %d %d %d",&Face1,&Face2,&Face3,&Face4,&Dummy); - List_Read(AllFaces,abs(Face1)-1,&myS1); - List_Read(AllFaces,abs(Face2)-1,&myS2); - v1 = myS1->V[0]; - v2 = myS1->V[1]; - v3 = myS1->V[2]; - for(int hh =0;hh<3;hh++)if(compareVertex(&v1,&myS2->V[hh]) && - compareVertex(&v2,&myS2->V[hh]) && - compareVertex(&v3,&myS2->V[hh]))v4=myS2->V[hh]; - } - if(!v1 || !v2 || !v3 || !v4) - { - printf("%d\n",NbFacesOnRegion); - printf("%p %p %p %p\n",v1,v2,v3,v4); - printf("%p %p %p \n",myS1->V[0],myS1->V[1],myS1->V[2]); - printf("%p %p %p \n",myS2->V[0],myS2->V[1],myS2->V[2]); - assert(1==0); - } - Simplex *s = Create_Simplex (v1,v2,v3,v4); + } + + + Msg(INFO, "%d Region", NbRegions); + + for(int i = 0; i < NbRegions; i++) { + fscanf(in, "%d", &GEntityId); + if(GEntityId) { + fscanf(in, "%d", &NbFacesOnRegion); + Simplex *myS1, *myS2; + if(NbFacesOnRegion == 4) { + fscanf(in, "%d %d %d %d %d", &Face1, &Face2, &Face3, &Face4, &Dummy); + List_Read(AllFaces, abs(Face1) - 1, &myS1); + List_Read(AllFaces, abs(Face2) - 1, &myS2); + v1 = myS1->V[0]; + v2 = myS1->V[1]; + v3 = myS1->V[2]; + for(int hh = 0; hh < 3; hh++) + if(compareVertex(&v1, &myS2->V[hh]) && + compareVertex(&v2, &myS2->V[hh]) && + compareVertex(&v3, &myS2->V[hh])) + v4 = myS2->V[hh]; + } + if(!v1 || !v2 || !v3 || !v4) { + printf("%d\n", NbFacesOnRegion); + printf("%p %p %p %p\n", v1, v2, v3, v4); + printf("%p %p %p \n", myS1->V[0], myS1->V[1], myS1->V[2]); + printf("%p %p %p \n", myS2->V[0], myS2->V[1], myS2->V[2]); + assert(1 == 0); + } + Simplex *s = Create_Simplex(v1, v2, v3, v4); - if((vol = FindVolume(GEntityId,m))) - { - } - else - { - vol = Create_Volume(GEntityId,MSH_VOLUME); - Tree_Add(m->Volumes,&vol); - } - s->iEnt = GEntityId; - Tree_Insert(vol->Simplexes,&s); - Tree_Insert(m->Simplexes,&s); - } - } + if((vol = FindVolume(GEntityId, m))) { + } + else { + vol = Create_Volume(GEntityId, MSH_VOLUME); + Tree_Add(m->Volumes, &vol); + } + s->iEnt = GEntityId; + Tree_Insert(vol->Simplexes, &s); + Tree_Insert(m->Simplexes, &s); + } + } List_Delete(AllFaces); - if(NbRegions)m->status = 3; - else if(NbFaces)m->status = 2; - else if(NbEdges)m->status = 1; - Msg(INFO,"Done."); + if(NbRegions) + m->status = 3; + else if(NbFaces) + m->status = 2; + else if(NbEdges) + m->status = 1; + Msg(INFO, "Done."); } + /* void Write_SMS_FILE (Mesh *m, char *filename) { @@ -547,22 +542,22 @@ void Write_SMS_FILE (Mesh *m, char *filename) } */ -int isTopologic (Vertex *v, List_T *curves) +int isTopologic(Vertex * v, List_T * curves) { Curve *c; - for(int i=0;i<List_Nbr(curves);i++) - { - List_Read(curves,i,&c); - if(!compareVertex(&v,&c->beg))return 1; - } + for(int i = 0; i < List_Nbr(curves); i++) { + List_Read(curves, i, &c); + if(!compareVertex(&v, &c->beg)) + return 1; + } return 0; } -void Write_DMG_FILE (Mesh *m, char *filename) +void Write_DMG_FILE(Mesh * m, char *filename) { - FILE *f = fopen (filename,"w"); - int i,j; - List_T *ll,*l; + FILE *f = fopen(filename, "w"); + int i, j; + List_T *ll, *l; Vertex *v; Curve *c; Surface *s; @@ -573,22 +568,19 @@ void Write_DMG_FILE (Mesh *m, char *filename) ll = Tree2List(m->Curves); k = 0; - for(i = 0;i<List_Nbr(l);i++) - { - List_Read(l,i,&v); - if(isTopologic(v,ll)) - { - k++; - } + for(i = 0; i < List_Nbr(l); i++) { + List_Read(l, i, &v); + if(isTopologic(v, ll)) { + k++; } + } // write first the global infos - fprintf(f,"%d %d %d %d \n" - ,Tree_Nbr(m->Volumes) - ,Tree_Nbr(m->Surfaces) - ,Tree_Nbr(m->Curves)/2 // the 2 is for the reverse curves - ,k); + fprintf(f, "%d %d %d %d \n", Tree_Nbr(m->Volumes) + , Tree_Nbr(m->Surfaces) + , Tree_Nbr(m->Curves) / 2 // the 2 is for the reverse curves + , k); // then write the bounding box @@ -599,83 +591,77 @@ void Write_DMG_FILE (Mesh *m, char *filename) m->Grid.max.Y = CTX.max[1]; m->Grid.max.Z = CTX.max[2]; - fprintf(f,"%12.5E %12.5E %12.5E \n",m->Grid.min.X,m->Grid.min.Y,m->Grid.min.Z); - fprintf(f,"%12.5E %12.5E %12.5E \n",m->Grid.max.X,m->Grid.max.Y,m->Grid.max.Z); + fprintf(f, "%12.5E %12.5E %12.5E \n", m->Grid.min.X, m->Grid.min.Y, + m->Grid.min.Z); + fprintf(f, "%12.5E %12.5E %12.5E \n", m->Grid.max.X, m->Grid.max.Y, + m->Grid.max.Z); // write the points k = 0; - for(i = 0;i<List_Nbr(l);i++) - { - List_Read(l,i,&v); - if(isTopologic(v,ll)) - { - v->Frozen = k++; - fprintf(f,"%d %12.5E %12.5E %12.5E \n",v->Frozen,v->Pos.X,v->Pos.Y,v->Pos.Z); - } + for(i = 0; i < List_Nbr(l); i++) { + List_Read(l, i, &v); + if(isTopologic(v, ll)) { + v->Frozen = k++; + fprintf(f, "%d %12.5E %12.5E %12.5E \n", v->Frozen, v->Pos.X, v->Pos.Y, + v->Pos.Z); } + } List_Delete(l); // write the curves l = ll; k = 0; - for(i = 0;i<List_Nbr(l);i++) - { - List_Read(l,i,&c); - if(c->Num > 0){ - c->ipar[3] = k; - Curve *cinv = FindCurve(-c->Num,m); - cinv->ipar[3] = k++; - fprintf(f,"%d %d %d \n",c->ipar[3],c->beg->Frozen,c->end->Frozen); - } + for(i = 0; i < List_Nbr(l); i++) { + List_Read(l, i, &c); + if(c->Num > 0) { + c->ipar[3] = k; + Curve *cinv = FindCurve(-c->Num, m); + cinv->ipar[3] = k++; + fprintf(f, "%d %d %d \n", c->ipar[3], c->beg->Frozen, c->end->Frozen); } + } List_Delete(l); // write the surfaces l = Tree2List(m->Surfaces); - - for(i = 0;i<List_Nbr(l);i++) - { - List_Read(l,i,&s); - - int numEdgeLoop[2000],iLoop=0; - Vertex *beg = NULL; - numEdgeLoop[iLoop] = 0; - int deb = 1; - for(j=0;j<List_Nbr(s->Generatrices);j++) - { - List_Read(s->Generatrices,j,&c); - if(deb) - { - beg = c->beg; - deb = 0; - } - Msg(INFO, "beg->%d end->%d", c->beg->Num, c->end->Num); - (numEdgeLoop[iLoop]) ++ ; - if(c->end == beg) - { - iLoop++; - numEdgeLoop[iLoop] = 0; - deb = 1; - } - } - s->ipar[3] = i; - fprintf(f,"%d %d\n",i,iLoop); - fprintf(stdout,"%d %d\n",i,iLoop); - int iEdge = 0; - for(k=0;k<iLoop;k++) - { - fprintf(f,"%d ",numEdgeLoop[k]); - fprintf(stdout,"%d ",numEdgeLoop[k]); - for(j=0;j<numEdgeLoop[k];j++) - { - List_Read(s->Generatrices,iEdge++,&c); - fprintf(f,"%d %d ",abs(c->ipar[3]),(c->Num>0)?1:-1); - fprintf(stdout,"%d %d ",abs(c->ipar[3]),(c->Num>0)?1:-1); - } - fprintf(f,"\n"); - fprintf(stdout,"\n"); - } + + for(i = 0; i < List_Nbr(l); i++) { + List_Read(l, i, &s); + + int numEdgeLoop[2000], iLoop = 0; + Vertex *beg = NULL; + numEdgeLoop[iLoop] = 0; + int deb = 1; + for(j = 0; j < List_Nbr(s->Generatrices); j++) { + List_Read(s->Generatrices, j, &c); + if(deb) { + beg = c->beg; + deb = 0; + } + Msg(INFO, "beg->%d end->%d", c->beg->Num, c->end->Num); + (numEdgeLoop[iLoop])++; + if(c->end == beg) { + iLoop++; + numEdgeLoop[iLoop] = 0; + deb = 1; + } + } + s->ipar[3] = i; + fprintf(f, "%d %d\n", i, iLoop); + fprintf(stdout, "%d %d\n", i, iLoop); + int iEdge = 0; + for(k = 0; k < iLoop; k++) { + fprintf(f, "%d ", numEdgeLoop[k]); + fprintf(stdout, "%d ", numEdgeLoop[k]); + for(j = 0; j < numEdgeLoop[k]; j++) { + List_Read(s->Generatrices, iEdge++, &c); + fprintf(f, "%d %d ", abs(c->ipar[3]), (c->Num > 0) ? 1 : -1); + fprintf(stdout, "%d %d ", abs(c->ipar[3]), (c->Num > 0) ? 1 : -1); + } + fprintf(f, "\n"); + fprintf(stdout, "\n"); } + } List_Delete(l); // write the volumes (2 b continued) diff --git a/Mesh/STL.cpp b/Mesh/STL.cpp index dcf682844681f4c3cfa331f5af3b7f87b620206a..708153dd97f78c3001842cf68328a8a540f96044 100644 --- a/Mesh/STL.cpp +++ b/Mesh/STL.cpp @@ -1,4 +1,4 @@ -// $Id: STL.cpp,v 1.8 2003-01-23 20:19:22 geuzaine Exp $ +// $Id: STL.cpp,v 1.9 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -25,69 +25,74 @@ extern Mesh *THEM; -STL_Data::STL_Data (){ - Vertices = Tree_Create (sizeof (Vertex *), comparePosition); - Simplexes = Tree_Create (sizeof (Simplex *), compareSimplex); +STL_Data::STL_Data() +{ + Vertices = Tree_Create(sizeof(Vertex *), comparePosition); + Simplexes = Tree_Create(sizeof(Simplex *), compareSimplex); LSimplexes = NULL; LVertices = NULL; } -STL_Data::~STL_Data (){ +STL_Data::~STL_Data() +{ } -void STL_Data::Add_Facet (double x1, double y1, double z1, - double x2, double y2, double z2, - double x3, double y3, double z3){ +void STL_Data::Add_Facet(double x1, double y1, double z1, + double x2, double y2, double z2, + double x3, double y3, double z3) +{ Vertex **ppv; - Vertex *v1 = Create_Vertex (Tree_Nbr (Vertices) + 1, x1, y1, z1, 1, 0); + Vertex *v1 = Create_Vertex(Tree_Nbr(Vertices) + 1, x1, y1, z1, 1, 0); - if ((ppv = (Vertex **) Tree_PQuery (Vertices, &v1))){ + if((ppv = (Vertex **) Tree_PQuery(Vertices, &v1))) { delete v1; v1 = *ppv; } - else{ - Tree_Add (Vertices, &v1); - Tree_Add (THEM->Points, &v1); + else { + Tree_Add(Vertices, &v1); + Tree_Add(THEM->Points, &v1); } - Vertex *v2 = Create_Vertex (Tree_Nbr (Vertices) + 1, x2, y2, z2, 1, 0); - if ((ppv = (Vertex **) Tree_PQuery (Vertices, &v2))){ + Vertex *v2 = Create_Vertex(Tree_Nbr(Vertices) + 1, x2, y2, z2, 1, 0); + if((ppv = (Vertex **) Tree_PQuery(Vertices, &v2))) { delete v2; v2 = *ppv; } - else{ - Tree_Add (Vertices, &v2); - Tree_Add (THEM->Points, &v2); + else { + Tree_Add(Vertices, &v2); + Tree_Add(THEM->Points, &v2); } - Vertex *v3 = Create_Vertex (Tree_Nbr (Vertices) + 1, x3, y3, z3, 1, 0); - if ((ppv = (Vertex **) Tree_PQuery (Vertices, &v3))){ + Vertex *v3 = Create_Vertex(Tree_Nbr(Vertices) + 1, x3, y3, z3, 1, 0); + if((ppv = (Vertex **) Tree_PQuery(Vertices, &v3))) { delete v3; v3 = *ppv; } - else{ - Tree_Add (Vertices, &v3); - Tree_Add (THEM->Points, &v3); + else { + Tree_Add(Vertices, &v3); + Tree_Add(THEM->Points, &v3); } - Simplex *s = Create_Simplex (v1, v2, v3, NULL); - Tree_Add (Simplexes, &s); + Simplex *s = Create_Simplex(v1, v2, v3, NULL); + Tree_Add(Simplexes, &s); } -void STL_Data::GetFacet (int ifac, int &v1, int &v2, int &v3){ +void STL_Data::GetFacet(int ifac, int &v1, int &v2, int &v3) +{ Simplex *s; - if (!LSimplexes) - LSimplexes = Tree2List (Simplexes); - List_Read (LSimplexes, ifac - 1, &s); + if(!LSimplexes) + LSimplexes = Tree2List(Simplexes); + List_Read(LSimplexes, ifac - 1, &s); v1 = s->V[0]->Num; v2 = s->V[1]->Num; v3 = s->V[2]->Num; } -void STL_Data::GetVertex (int i, double &x, double &y, double &z){ +void STL_Data::GetVertex(int i, double &x, double &y, double &z) +{ Vertex *v; - if (!LVertices) - LVertices = Tree2List (Vertices); - List_Read (LVertices, i - 1, &v); + if(!LVertices) + LVertices = Tree2List(Vertices); + List_Read(LVertices, i - 1, &v); x = v->Pos.X; y = v->Pos.Y; z = v->Pos.Z; diff --git a/Mesh/SecondOrder.cpp b/Mesh/SecondOrder.cpp index a02cc47b1fb7bbc1bd40a138b25a1e21e2eb9548..8232cb8668d854592e40e1cb874fccf2fdaeb202 100644 --- a/Mesh/SecondOrder.cpp +++ b/Mesh/SecondOrder.cpp @@ -1,4 +1,4 @@ -// $Id: SecondOrder.cpp,v 1.11 2003-01-23 20:19:22 geuzaine Exp $ +// $Id: SecondOrder.cpp,v 1.12 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -31,46 +31,50 @@ extern Mesh *THEM; static Surface *THES; static Curve *THEC; -Vertex *middlecurve (Vertex * v1, Vertex * v2){ +Vertex *middlecurve(Vertex * v1, Vertex * v2) +{ Vertex v, *pv; - if (!THEC) + if(!THEC) return NULL; - if ((v1->ListCurves && List_Nbr (v1->ListCurves) != 1) || - (v2->ListCurves && List_Nbr (v2->ListCurves) != 1)){ + if((v1->ListCurves && List_Nbr(v1->ListCurves) != 1) || + (v2->ListCurves && List_Nbr(v2->ListCurves) != 1)) { v.Pos.X = (v1->Pos.X + v2->Pos.X) * 0.5; v.Pos.Y = (v1->Pos.Y + v2->Pos.Y) * 0.5; v.Pos.Z = (v1->Pos.Z + v2->Pos.Z) * 0.5; } else - v = InterpolateCurve (THEC, 0.5 * (v1->u + v2->u), 0); + v = InterpolateCurve(THEC, 0.5 * (v1->u + v2->u), 0); - pv = Create_Vertex (++THEM->MaxPointNum, v.Pos.X, v.Pos.Y, v.Pos.Z, v.lc, v.u); + pv = + Create_Vertex(++THEM->MaxPointNum, v.Pos.X, v.Pos.Y, v.Pos.Z, v.lc, v.u); - if (!pv->ListCurves){ - pv->ListCurves = List_Create (1, 1, sizeof (Curve *)); + if(!pv->ListCurves) { + pv->ListCurves = List_Create(1, 1, sizeof(Curve *)); } - List_Add (pv->ListCurves, &THEC); + List_Add(pv->ListCurves, &THEC); return pv; } -Vertex *middleface (Vertex * v1, Vertex * v2){ +Vertex *middleface(Vertex * v1, Vertex * v2) +{ Vertex v, *pv; double U, V, U1, U2, V1, V2; - if (!THES) + if(!THES) return NULL; - if (THES->Typ == MSH_SURF_PLAN) + if(THES->Typ == MSH_SURF_PLAN) return NULL; - XYZtoUV ( THES , v1->Pos.X , v1->Pos.Y , v1->Pos.Z, &U1 , &V1 , 1.0); - XYZtoUV ( THES , v2->Pos.X , v2->Pos.Y , v2->Pos.Z, &U2 , &V2 , 1.0); + XYZtoUV(THES, v1->Pos.X, v1->Pos.Y, v1->Pos.Z, &U1, &V1, 1.0); + XYZtoUV(THES, v2->Pos.X, v2->Pos.Y, v2->Pos.Z, &U2, &V2, 1.0); - U = 0.5 *(U1+U2); - V = 0.5 *(V1+V2); - v = InterpolateSurface(THES,U,V,0,0); - pv = Create_Vertex(++THEM->MaxPointNum,v.Pos.X,v.Pos.Y,v.Pos.Z,v.lc,v.u); + U = 0.5 * (U1 + U2); + V = 0.5 * (V1 + V2); + v = InterpolateSurface(THES, U, V, 0, 0); + pv = + Create_Vertex(++THEM->MaxPointNum, v.Pos.X, v.Pos.Y, v.Pos.Z, v.lc, v.u); return pv; } @@ -79,7 +83,8 @@ extern int edges_quad[4][2]; static Tree_T *THET; extern int EdgesInVolume; -void PutMiddlePoint (void *a, void *b){ +void PutMiddlePoint(void *a, void *b) +{ Edge *ed; Simplex *s; Vertex *v; @@ -88,80 +93,81 @@ void PutMiddlePoint (void *a, void *b){ ed = (Edge *) a; - if (ed->newv) + if(ed->newv) v = ed->newv; - else if ((v = middlecurve (ed->V[0], ed->V[1]))); - else if ((v = middleface (ed->V[0], ed->V[1]))); + else if((v = middlecurve(ed->V[0], ed->V[1]))); + else if((v = middleface(ed->V[0], ed->V[1]))); else - v = Create_Vertex (++THEM->MaxPointNum, - 0.5 * (ed->V[0]->Pos.X + ed->V[1]->Pos.X), - 0.5 * (ed->V[0]->Pos.Y + ed->V[1]->Pos.Y), - 0.5 * (ed->V[0]->Pos.Z + ed->V[1]->Pos.Z), - 0.5 * (ed->V[0]->lc + ed->V[1]->lc), - 0.5 * (ed->V[0]->u + ed->V[1]->u)); + v = Create_Vertex(++THEM->MaxPointNum, + 0.5 * (ed->V[0]->Pos.X + ed->V[1]->Pos.X), + 0.5 * (ed->V[0]->Pos.Y + ed->V[1]->Pos.Y), + 0.5 * (ed->V[0]->Pos.Z + ed->V[1]->Pos.Z), + 0.5 * (ed->V[0]->lc + ed->V[1]->lc), + 0.5 * (ed->V[0]->u + ed->V[1]->u)); ed->newv = v; - Tree_Insert (THET, &v); - for (i = 0; i < List_Nbr (ed->Simplexes); i++){ - List_Read (ed->Simplexes, i, &s); - if (s->V[3] && EdgesInVolume){ - if (!s->VSUP) - s->VSUP = (Vertex **) Malloc (6 * sizeof (Vertex *)); + Tree_Insert(THET, &v); + for(i = 0; i < List_Nbr(ed->Simplexes); i++) { + List_Read(ed->Simplexes, i, &s); + if(s->V[3] && EdgesInVolume) { + if(!s->VSUP) + s->VSUP = (Vertex **) Malloc(6 * sizeof(Vertex *)); N = 6; - for (k = 0; k < N; k++) - for (j = 0; j < 2; j++) + for(k = 0; k < N; k++) + for(j = 0; j < 2; j++) edges[k][j] = edges_tetra[k][j]; } - else if (s->V[3]){ - if (!s->VSUP) - s->VSUP = (Vertex **) Malloc (4 * sizeof (Vertex *)); + else if(s->V[3]) { + if(!s->VSUP) + s->VSUP = (Vertex **) Malloc(4 * sizeof(Vertex *)); N = 4; - for (k = 0; k < N; k++) - for (j = 0; j < 2; j++) + for(k = 0; k < N; k++) + for(j = 0; j < 2; j++) edges[k][j] = edges_quad[k][j]; } - else if (s->V[2]){ - if (!s->VSUP) - s->VSUP = (Vertex **) Malloc (3 * sizeof (Vertex *)); + else if(s->V[2]) { + if(!s->VSUP) + s->VSUP = (Vertex **) Malloc(3 * sizeof(Vertex *)); N = 3; - for (k = 0; k < N; k++) - for (j = 0; j < 2; j++) + for(k = 0; k < N; k++) + for(j = 0; j < 2; j++) edges[k][j] = edges_tetra[k][j]; } - else{ - if (!s->VSUP) - s->VSUP = (Vertex **) Malloc (sizeof (Vertex *)); + else { + if(!s->VSUP) + s->VSUP = (Vertex **) Malloc(sizeof(Vertex *)); N = 1; - for (k = 0; k < N; k++) - for (j = 0; j < 2; j++) + for(k = 0; k < N; k++) + for(j = 0; j < 2; j++) edges[k][j] = edges_tetra[k][j]; } - for (j = 0; j < N; j++){ - if ((!compareVertex (&s->V[edges[j][0]], &ed->V[0]) && - !compareVertex (&s->V[edges[j][1]], &ed->V[1])) || - (!compareVertex (&s->V[edges[j][0]], &ed->V[1]) && - !compareVertex (&s->V[edges[j][1]], &ed->V[0]))){ + for(j = 0; j < N; j++) { + if((!compareVertex(&s->V[edges[j][0]], &ed->V[0]) && + !compareVertex(&s->V[edges[j][1]], &ed->V[1])) || + (!compareVertex(&s->V[edges[j][0]], &ed->V[1]) && + !compareVertex(&s->V[edges[j][1]], &ed->V[0]))) { s->VSUP[j] = v; } } } } -void Degre2 (Tree_T * AllNodes, Tree_T * TreeNodes, Tree_T * TreeElm, - Curve * c, Surface * s){ +void Degre2(Tree_T * AllNodes, Tree_T * TreeNodes, Tree_T * TreeElm, + Curve * c, Surface * s) +{ static Tree_T *TreeEdges = NULL; THES = s; THEC = c; THET = TreeNodes; - if (!TreeEdges) - TreeEdges = Tree_Create (sizeof (Edge), compareedge); + if(!TreeEdges) + TreeEdges = Tree_Create(sizeof(Edge), compareedge); - if (THES || THEC) + if(THES || THEC) EdgesInVolume = 0; - crEdges (TreeElm, TreeEdges); - Tree_Action (TreeEdges, PutMiddlePoint); + crEdges(TreeElm, TreeEdges); + Tree_Action(TreeEdges, PutMiddlePoint); EdgesInVolume = 1; } diff --git a/Mesh/Simplex.cpp b/Mesh/Simplex.cpp index 97cc12379a644a24b1d6162c997f35851d1bab99..6479c07e584eaa57359c3d5c6a6ef49029e1ecbf 100644 --- a/Mesh/Simplex.cpp +++ b/Mesh/Simplex.cpp @@ -1,4 +1,4 @@ -// $Id: Simplex.cpp,v 1.25 2003-01-23 20:19:22 geuzaine Exp $ +// $Id: Simplex.cpp,v 1.26 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -26,7 +26,7 @@ #include "Simplex.h" #include "Context.h" -extern Context_T CTX; +extern Context_T CTX; extern Mesh *THEM; int Simplex::TotalAllocated = 0; @@ -36,43 +36,46 @@ extern Simplex MyNewBoundary; int FACE_DIMENSION = 2; -Simplex::Simplex (){ +Simplex::Simplex() +{ TotalAllocated++; TotalNumber++; VSUP = NULL; V[0] = V[1] = V[2] = V[3] = NULL; S[0] = S[1] = S[2] = S[3] = NULL; iEnt = -1; - Quality = 0. ; + Quality = 0.; Num = TotalNumber; Visible = VIS_MESH; } -Simplex::Simplex (Vertex * v1, Vertex * v2, Vertex * v3, Vertex * v4){ +Simplex::Simplex(Vertex * v1, Vertex * v2, Vertex * v3, Vertex * v4) +{ TotalAllocated++; TotalNumber++; VSUP = NULL; S[0] = S[1] = S[2] = S[3] = NULL; - Quality = 0. ; - Fourre_Simplexe (v1, v2, v3, v4); + Quality = 0.; + Fourre_Simplexe(v1, v2, v3, v4); Num = TotalNumber; - THEM->MaxSimplexNum = IMAX(THEM->MaxSimplexNum,Num); + THEM->MaxSimplexNum = IMAX(THEM->MaxSimplexNum, Num); iEnt = -1; Visible = VIS_MESH; } -Simplex::~Simplex (){ +Simplex::~Simplex() +{ TotalAllocated--; } -int Simplex:: CircumCircle (double x1, double y1, - double x2, double y2, - double x3, double y3, - double *xc, double *yc){ +int Simplex::CircumCircle(double x1, double y1, + double x2, double y2, + double x3, double y3, double *xc, double *yc) +{ double d, a1, a2, a3; - d = 2. * (double) (y1 * (x2 - x3) + y2 * (x3 - x1) + y3 * (x1 - x2)); - if (d == 0.0){ + d = 2. * (double)(y1 * (x2 - x3) + y2 * (x3 - x1) + y3 * (x1 - x2)); + if(d == 0.0) { *xc = *yc = -99999.; Msg(WARNING, "Degenerated simplex"); return 0; @@ -81,99 +84,97 @@ int Simplex:: CircumCircle (double x1, double y1, a1 = x1 * x1 + y1 * y1; a2 = x2 * x2 + y2 * y2; a3 = x3 * x3 + y3 * y3; - *xc = (double) ((a1 * (y3 - y2) + a2 * (y1 - y3) + a3 * (y2 - y1)) / d); - *yc = (double) ((a1 * (x2 - x3) + a2 * (x3 - x1) + a3 * (x1 - x2)) / d); + *xc = (double)((a1 * (y3 - y2) + a2 * (y1 - y3) + a3 * (y2 - y1)) / d); + *yc = (double)((a1 * (x2 - x3) + a2 * (x3 - x1) + a3 * (x1 - x2)) / d); return 1; } -void Simplex::Center_Circum (){ +void Simplex::Center_Circum() +{ /* Calcul du centre de la boule circonscrite */ int i, N; double X[4], Y[4], Z[4]; double res[3]; - if (!V[3]) + if(!V[3]) N = 3; else N = 4; - for (i = 0; i < N; i++){ + for(i = 0; i < N; i++) { X[i] = V[i]->Pos.X; Y[i] = V[i]->Pos.Y; Z[i] = V[i]->Pos.Z; } - if (N == 3){ - CircumCircle (V[0]->Pos.X, V[0]->Pos.Y, - V[1]->Pos.X, V[1]->Pos.Y, - V[2]->Pos.X, V[2]->Pos.Y, - &Center.X, &Center.Y); + if(N == 3) { + CircumCircle(V[0]->Pos.X, V[0]->Pos.Y, + V[1]->Pos.X, V[1]->Pos.Y, + V[2]->Pos.X, V[2]->Pos.Y, &Center.X, &Center.Y); Center.Z = 0.0; - if (fabs (Center.X) > 1.e10) + if(fabs(Center.X) > 1.e10) Center.X = 1.e10; - if (fabs (Center.Y) > 1.e10) + if(fabs(Center.Y) > 1.e10) Center.Y = 1.e10; - Radius = sqrt ((X[0] - Center.X) * (X[0] - Center.X) + - (Y[0] - Center.Y) * (Y[0] - Center.Y)); + Radius = sqrt((X[0] - Center.X) * (X[0] - Center.X) + + (Y[0] - Center.Y) * (Y[0] - Center.Y)); } - else{ - center_tet (X, Y, Z, res); - + else { + center_tet(X, Y, Z, res); + Center.X = res[0]; Center.Y = res[1]; Center.Z = res[2]; - Radius = sqrt ((X[0] - Center.X) * (X[0] - Center.X) + - (Y[0] - Center.Y) * (Y[0] - Center.Y) + - (Z[0] - Center.Z) * (Z[0] - Center.Z)); + Radius = sqrt((X[0] - Center.X) * (X[0] - Center.X) + + (Y[0] - Center.Y) * (Y[0] - Center.Y) + + (Z[0] - Center.Z) * (Z[0] - Center.Z)); } } -int Simplex::Pt_In_Ellipse (Vertex * v, double Metric[3][3]){ +int Simplex::Pt_In_Ellipse(Vertex * v, double Metric[3][3]) +{ double eps, d1, d2, x[2]; - Center_Ellipsum_2D (Metric); + Center_Ellipsum_2D(Metric); x[0] = Center.X - v->Pos.X; x[1] = Center.Y - v->Pos.Y; d1 = Radius; - d2 = sqrt (x[0] * x[0] * Metric[0][0] - + x[1] * x[1] * Metric[1][1] - + 2. * x[0] * x[1] * Metric[0][1]); - - eps = fabs (d1 - d2) / (d1 + d2); - if (eps < 1.e-12) - { - return (1); // Ou Zero ??? - } - if (d2 < d1) + d2 = sqrt(x[0] * x[0] * Metric[0][0] + + x[1] * x[1] * Metric[1][1] + + 2. * x[0] * x[1] * Metric[0][1]); + + eps = fabs(d1 - d2) / (d1 + d2); + if(eps < 1.e-12) { + return (1); // Ou Zero ??? + } + if(d2 < d1) return 1; return 0; } -double Simplex::Volume_Simplexe2D (){ +double Simplex::Volume_Simplexe2D() +{ return ((V[1]->Pos.X - V[0]->Pos.X) * (V[2]->Pos.Y - V[1]->Pos.Y) - - (V[2]->Pos.X - V[1]->Pos.X) * - (V[1]->Pos.Y - V[0]->Pos.Y)); + (V[2]->Pos.X - V[1]->Pos.X) * (V[1]->Pos.Y - V[0]->Pos.Y)); } -void Simplex::center_tet (double X[4], double Y[4], double Z[4], double res[3]){ +void Simplex::center_tet(double X[4], double Y[4], double Z[4], double res[3]) +{ double mat[3][3], b[3], dum; int i; b[0] = X[1] * X[1] - X[0] * X[0] + - Y[1] * Y[1] - Y[0] * Y[0] + - Z[1] * Z[1] - Z[0] * Z[0]; + Y[1] * Y[1] - Y[0] * Y[0] + Z[1] * Z[1] - Z[0] * Z[0]; b[1] = X[2] * X[2] - X[1] * X[1] + - Y[2] * Y[2] - Y[1] * Y[1] + - Z[2] * Z[2] - Z[1] * Z[1]; + Y[2] * Y[2] - Y[1] * Y[1] + Z[2] * Z[2] - Z[1] * Z[1]; b[2] = X[3] * X[3] - X[2] * X[2] + - Y[3] * Y[3] - Y[2] * Y[2] + - Z[3] * Z[3] - Z[2] * Z[2]; + Y[3] * Y[3] - Y[2] * Y[2] + Z[3] * Z[3] - Z[2] * Z[2]; - for (i = 0; i < 3; i++) + for(i = 0; i < 3; i++) b[i] *= 0.5; mat[0][0] = X[1] - X[0]; @@ -186,16 +187,18 @@ void Simplex::center_tet (double X[4], double Y[4], double Z[4], double res[3]){ mat[2][1] = Y[3] - Y[2]; mat[2][2] = Z[3] - Z[2]; - if (!sys3x3 (mat, b, res, &dum)){ - Msg(WARNING, "Coplanar points in circum sphere computation"); - Msg(WARNING, "(%g,%g,%g) (%g,%g,%g) (%g,%g,%g) (%g,%g,%g)", - X[0],Y[0],Z[0], X[1],Y[1],Z[1], X[2],Y[2],Z[2], X[3],Y[3],Z[3] ); + if(!sys3x3(mat, b, res, &dum)) { + Msg(WARNING, "Coplanar points in circum sphere computation"); + Msg(WARNING, "(%g,%g,%g) (%g,%g,%g) (%g,%g,%g) (%g,%g,%g)", + X[0], Y[0], Z[0], X[1], Y[1], Z[1], X[2], Y[2], Z[2], X[3], Y[3], + Z[3]); res[0] = res[1] = res[2] = 10.0e10; } - + } -double Simplex::matsimpl (double mat[3][3]){ +double Simplex::matsimpl(double mat[3][3]) +{ mat[0][0] = V[1]->Pos.X - V[0]->Pos.X; mat[0][1] = V[2]->Pos.X - V[0]->Pos.X; mat[0][2] = V[3]->Pos.X - V[0]->Pos.X; @@ -210,80 +213,89 @@ double Simplex::matsimpl (double mat[3][3]){ mat[2][0] * (mat[0][1] * mat[1][2] - mat[1][1] * mat[0][2])); } -double Simplex::rhoin (){ +double Simplex::rhoin() +{ double s1, s2, s3, s4; - if (V[3]){ - s1 = fabs (AireFace (F[0].V)); - s2 = fabs (AireFace (F[1].V)); - s3 = fabs (AireFace (F[2].V)); - s4 = fabs (AireFace (F[3].V)); - return 3. * fabs (Volume_Simplexe ()) / (s1 + s2 + s3 + s4); + if(V[3]) { + s1 = fabs(AireFace(F[0].V)); + s2 = fabs(AireFace(F[1].V)); + s3 = fabs(AireFace(F[2].V)); + s4 = fabs(AireFace(F[3].V)); + return 3. * fabs(Volume_Simplexe()) / (s1 + s2 + s3 + s4); } - else{ + else { return 1.0; } } -double Simplex::lij (int i, int j){ - return sqrt (DSQR (V[i]->Pos.X - V[j]->Pos.X) + - DSQR (V[i]->Pos.Y - V[j]->Pos.Y) + - DSQR (V[i]->Pos.Z - V[j]->Pos.Z)); +double Simplex::lij(int i, int j) +{ + return sqrt(DSQR(V[i]->Pos.X - V[j]->Pos.X) + + DSQR(V[i]->Pos.Y - V[j]->Pos.Y) + + DSQR(V[i]->Pos.Z - V[j]->Pos.Z)); } -double Simplex::Volume_Simplexe (){ +double Simplex::Volume_Simplexe() +{ double mat[3][3]; - if (V[3]) - return (matsimpl (mat) / 6.); + if(V[3]) + return (matsimpl(mat) / 6.); else - return (surfsimpl ()); + return (surfsimpl()); } -double Simplex::EtaShapeMeasure (){ +double Simplex::EtaShapeMeasure() +{ int i, j; double lij2 = 0.0; - for (i = 0; i <= 3; i++){ - for (j = i + 1; j <= 3; j++){ - lij2 += DSQR (lij (i, j)); + for(i = 0; i <= 3; i++) { + for(j = i + 1; j <= 3; j++) { + lij2 += DSQR(lij(i, j)); } } - return 12. * pow (9./10. * DSQR (fabs (Volume_Simplexe ())), 1./3.) / (lij2); + return 12. * pow(9. / 10. * DSQR(fabs(Volume_Simplexe())), + 1. / 3.) / (lij2); } -double Simplex::RhoShapeMeasure (){ +double Simplex::RhoShapeMeasure() +{ int i, j; double minlij = 1.e25, maxlij = 0.0; - for (i = 0; i <= 3; i++){ - for (j = i + 1; j <= 3; j++){ - if (i != j){ - minlij = DMIN (minlij, fabs (lij (i, j))); - maxlij = DMAX (maxlij, fabs (lij (i, j))); + for(i = 0; i <= 3; i++) { + for(j = i + 1; j <= 3; j++) { + if(i != j) { + minlij = DMIN(minlij, fabs(lij(i, j))); + maxlij = DMAX(maxlij, fabs(lij(i, j))); } } } return minlij / maxlij; } -double Simplex::GammaShapeMeasure (){ +double Simplex::GammaShapeMeasure() +{ int i, j, N; double maxlij = 0.0; - if (V[3]) + if(V[3]) N = 4; else N = 3; - for (i = 0; i <= N - 1; i++){ - for (j = i + 1; j <= N - 1; j++){ - if (i != j) - maxlij = DMAX (maxlij, lij (i, j)); + for(i = 0; i <= N - 1; i++) { + for(j = i + 1; j <= N - 1; j++) { + if(i != j) + maxlij = DMAX(maxlij, lij(i, j)); } } - return 12. * rhoin () / (sqrt (6.) * maxlij); + return 12. * rhoin() / (sqrt(6.) * maxlij); } -void Simplex::Fourre_Simplexe (Vertex * v1, Vertex * v2, Vertex * v3, Vertex * v4){ +void Simplex::Fourre_Simplexe(Vertex * v1, Vertex * v2, Vertex * v3, + Vertex * v4) +{ int i, N; V[0] = v1; V[1] = v2; @@ -291,7 +303,7 @@ void Simplex::Fourre_Simplexe (Vertex * v1, Vertex * v2, Vertex * v3, Vertex * v V[3] = v4; VSUP = NULL; - if (!v3) { + if(!v3) { F[0].V[0] = (v1->Num > v2->Num) ? v2 : v1; F[0].V[1] = (v1->Num > v2->Num) ? v1 : v2; F[0].V[2] = NULL; @@ -305,90 +317,94 @@ void Simplex::Fourre_Simplexe (Vertex * v1, Vertex * v2, Vertex * v3, Vertex * v F[1].V[0] = v1; F[1].V[1] = v3; F[1].V[2] = v4; - if (FACE_DIMENSION == 1){ + if(FACE_DIMENSION == 1) { F[2].V[0] = v2; F[2].V[1] = v3; F[2].V[2] = v4; - + F[3].V[0] = v1; F[3].V[1] = v2; F[3].V[2] = v4; } - else{ + else { F[2].V[0] = v1; F[2].V[1] = v2; F[2].V[2] = v4; - + F[3].V[0] = v2; F[3].V[1] = v3; F[3].V[2] = v4; } - if (!v4){ + if(!v4) { N = 3; - if (FACE_DIMENSION == 1){ + if(FACE_DIMENSION == 1) { //qsort(F[0].V,3,sizeof(Vertex*),compareVertex); - Center_Circum (); - Quality = (double) N *Radius / (V[0]->lc + V[1]->lc + V[2]->lc - + ((V[3]) ? V[3]->lc : 0.0)); + Center_Circum(); + Quality = (double)N *Radius / (V[0]->lc + V[1]->lc + V[2]->lc + + ((V[3]) ? V[3]->lc : 0.0)); } - else{ - qsort (F[0].V, 3, sizeof (Vertex *), compareVertex); + else { + qsort(F[0].V, 3, sizeof(Vertex *), compareVertex); return; } } - else{ + else { N = 4; } - - Center_Circum (); - /* - extern Mesh *THEM, *LOCAL; - if (LOCAL && N == 4 && CTX.mesh.algo == DELAUNAY_ISO && THEM->BGM.Typ == ONFILE){ - Quality = fabs(Radius) / Lc_XYZ(Center.X, Center.Y, Center.Z, LOCAL); - if(Quality < 0.){ - Msg(WARNING, "Negative simplex quality !?"); - Quality = 4 * Radius / (V[0]->lc + V[1]->lc + V[2]->lc + V[3]->lc); - } - } - */ + Center_Circum(); - Quality = (double) N * Radius / (V[0]->lc + V[1]->lc + V[2]->lc - + ((V[3]) ? V[3]->lc : 0.0)); - - for (i = 0; i < N; i++) - qsort (F[i].V, N - 1, sizeof (Vertex *), compareVertex); + /* + extern Mesh *THEM, *LOCAL; + if (LOCAL && N == 4 && CTX.mesh.algo == DELAUNAY_ISO && THEM->BGM.Typ == ONFILE){ + Quality = fabs(Radius) / Lc_XYZ(Center.X, Center.Y, Center.Z, LOCAL); + if(Quality < 0.){ + Msg(WARNING, "Negative simplex quality !?"); + Quality = 4 * Radius / (V[0]->lc + V[1]->lc + V[2]->lc + V[3]->lc); + } + } + */ + + Quality = (double)N *Radius / (V[0]->lc + V[1]->lc + V[2]->lc + + ((V[3]) ? V[3]->lc : 0.0)); + + for(i = 0; i < N; i++) + qsort(F[i].V, N - 1, sizeof(Vertex *), compareVertex); //qsort(F,N,sizeof(Face),compareFace); } -Simplex *Create_Simplex (Vertex * v1, Vertex * v2, Vertex * v3, Vertex * v4){ +Simplex *Create_Simplex(Vertex * v1, Vertex * v2, Vertex * v3, Vertex * v4) +{ Simplex *s; - s = new Simplex (v1, v2, v3, v4); + s = new Simplex(v1, v2, v3, v4); return s; } -void Free_Simplex (void *a, void *b){ - Simplex *s = *(Simplex**)a; - if(s){ +void Free_Simplex(void *a, void *b) +{ + Simplex *s = *(Simplex **) a; + if(s) { delete s; s = NULL; } } // to avoid the renumbering of the nodes and all the 'Fourre_Simplex' stuff -Simplex *Create_Quadrangle (Vertex * v1, Vertex * v2, Vertex * v3, Vertex * v4){ +Simplex *Create_Quadrangle(Vertex * v1, Vertex * v2, Vertex * v3, Vertex * v4) +{ Simplex *s; - s = new Simplex (); - s->V[0] = v1 ; - s->V[1] = v2 ; - s->V[2] = v3 ; - s->V[3] = v4 ; + s = new Simplex(); + s->V[0] = v1; + s->V[1] = v2; + s->V[2] = v3; + s->V[3] = v4; return s; } -int compareSimplex (const void *a, const void *b){ +int compareSimplex(const void *a, const void *b) +{ Simplex **q, **w; /* Les simplexes sont definis une seule fois : @@ -400,26 +416,27 @@ int compareSimplex (const void *a, const void *b){ return ((*q)->Num - (*w)->Num); } -int Simplex::Pt_In_Simplexe (Vertex * v, double uvw[3], double tol){ +int Simplex::Pt_In_Simplexe(Vertex * v, double uvw[3], double tol) +{ double mat[3][3]; double b[3], dum; - matsimpl (mat); + matsimpl(mat); b[0] = v->Pos.X - V[0]->Pos.X; b[1] = v->Pos.Y - V[0]->Pos.Y; b[2] = v->Pos.Z - V[0]->Pos.Z; - sys3x3 (mat, b, uvw, &dum); - if (uvw[0] >= -tol && uvw[1] >= -tol && uvw[2] >= -tol && - uvw[0] <= 1. + tol && uvw[1] <= 1. + tol && uvw[2] <= 1. + tol && - 1. - uvw[0] - uvw[1] - uvw[2] > -tol) - { - return (1); - } + sys3x3(mat, b, uvw, &dum); + if(uvw[0] >= -tol && uvw[1] >= -tol && uvw[2] >= -tol && + uvw[0] <= 1. + tol && uvw[1] <= 1. + tol && uvw[2] <= 1. + tol && + 1. - uvw[0] - uvw[1] - uvw[2] > -tol) { + return (1); + } return (0); } -void Simplex::Center_Ellipsum_2D (double m[3][3]){ +void Simplex::Center_Ellipsum_2D(double m[3][3]) +{ double sys[2][2], x[2]; double rhs[2], a, b, d; double x1, y1, x2, y2, x3, y3; @@ -440,20 +457,25 @@ void Simplex::Center_Ellipsum_2D (double m[3][3]){ sys[1][0] = 2. * a * (x1 - x3) + 2. * b * (y1 - y3); sys[1][1] = 2. * d * (y1 - y3) + 2. * b * (x1 - x3); - rhs[0] = a * (x1 * x1 - x2 * x2) + d * (y1 * y1 - y2 * y2) + 2. * b * (x1 * y1 - x2 * y2); - rhs[1] = a * (x1 * x1 - x3 * x3) + d * (y1 * y1 - y3 * y3) + 2. * b * (x1 * y1 - x3 * y3); + rhs[0] = + a * (x1 * x1 - x2 * x2) + d * (y1 * y1 - y2 * y2) + 2. * b * (x1 * y1 - + x2 * y2); + rhs[1] = + a * (x1 * x1 - x3 * x3) + d * (y1 * y1 - y3 * y3) + 2. * b * (x1 * y1 - + x3 * y3); - sys2x2 (sys, rhs, x); + sys2x2(sys, rhs, x); Center.X = x[0]; Center.Y = x[1]; - Radius = sqrt ((x[0] - x1) * (x[0] - x1) * a - + (x[1] - y1) * (x[1] - y1) * d - + 2. * (x[0] - x1) * (x[1] - y1) * b); + Radius = sqrt((x[0] - x1) * (x[0] - x1) * a + + (x[1] - y1) * (x[1] - y1) * d + + 2. * (x[0] - x1) * (x[1] - y1) * b); } -void Simplex::Center_Ellipsum_3D (double m[3][3]){ +void Simplex::Center_Ellipsum_3D(double m[3][3]) +{ double sys[3][3], x[3]; double rhs[3], det; double x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4; @@ -471,17 +493,35 @@ void Simplex::Center_Ellipsum_3D (double m[3][3]){ y4 = V[3]->Pos.Y; z4 = V[3]->Pos.Z; - sys[0][0] = 2. * m[0][0] * (x1 - x2) + 2. * m[1][0] * (y1 - y2) + 2. * m[2][0] * (z1 - z2); - sys[0][1] = 2. * m[0][1] * (x1 - x2) + 2. * m[1][1] * (y1 - y2) + 2. * m[2][1] * (z1 - z2); - sys[0][2] = 2. * m[0][2] * (x1 - x2) + 2. * m[1][2] * (y1 - y2) + 2. * m[2][2] * (z1 - z2); - - sys[1][0] = 2. * m[0][0] * (x1 - x3) + 2. * m[1][0] * (y1 - y3) + 2. * m[2][0] * (z1 - z3); - sys[1][1] = 2. * m[0][1] * (x1 - x3) + 2. * m[1][1] * (y1 - y3) + 2. * m[2][1] * (z1 - z3); - sys[1][2] = 2. * m[0][2] * (x1 - x3) + 2. * m[1][2] * (y1 - y3) + 2. * m[2][2] * (z1 - z3); - - sys[2][0] = 2. * m[0][0] * (x1 - x4) + 2. * m[1][0] * (y1 - y4) + 2. * m[2][0] * (z1 - z4); - sys[2][1] = 2. * m[0][1] * (x1 - x4) + 2. * m[1][1] * (y1 - y4) + 2. * m[2][1] * (z1 - z4); - sys[2][2] = 2. * m[0][2] * (x1 - x4) + 2. * m[1][2] * (y1 - y4) + 2. * m[2][2] * (z1 - z4); + sys[0][0] = + 2. * m[0][0] * (x1 - x2) + 2. * m[1][0] * (y1 - y2) + 2. * m[2][0] * (z1 - + z2); + sys[0][1] = + 2. * m[0][1] * (x1 - x2) + 2. * m[1][1] * (y1 - y2) + 2. * m[2][1] * (z1 - + z2); + sys[0][2] = + 2. * m[0][2] * (x1 - x2) + 2. * m[1][2] * (y1 - y2) + 2. * m[2][2] * (z1 - + z2); + + sys[1][0] = + 2. * m[0][0] * (x1 - x3) + 2. * m[1][0] * (y1 - y3) + 2. * m[2][0] * (z1 - + z3); + sys[1][1] = + 2. * m[0][1] * (x1 - x3) + 2. * m[1][1] * (y1 - y3) + 2. * m[2][1] * (z1 - + z3); + sys[1][2] = + 2. * m[0][2] * (x1 - x3) + 2. * m[1][2] * (y1 - y3) + 2. * m[2][2] * (z1 - + z3); + + sys[2][0] = + 2. * m[0][0] * (x1 - x4) + 2. * m[1][0] * (y1 - y4) + 2. * m[2][0] * (z1 - + z4); + sys[2][1] = + 2. * m[0][1] * (x1 - x4) + 2. * m[1][1] * (y1 - y4) + 2. * m[2][1] * (z1 - + z4); + sys[2][2] = + 2. * m[0][2] * (x1 - x4) + 2. * m[1][2] * (y1 - y4) + 2. * m[2][2] * (z1 - + z4); rhs[0] = m[0][0] * (x1 * x1 - x2 * x2) + m[1][1] * (y1 * y1 - y2 * y2) @@ -502,23 +542,24 @@ void Simplex::Center_Ellipsum_3D (double m[3][3]){ + 2. * m[2][0] * (x1 * z1 - x4 * z4) + 2. * m[2][1] * (z1 * y1 - z4 * y4); - sys3x3 (sys, rhs, x, &det); + sys3x3(sys, rhs, x, &det); Center.X = x[0]; Center.Y = x[1]; Center.Z = x[2]; - Radius = sqrt ((x[0] - x1) * (x[0] - x1) * m[0][0] - + (x[1] - y1) * (x[1] - y1) * m[1][1] - + (x[2] - z1) * (x[2] - z1) * m[2][2] - + 2. * (x[0] - x1) * (x[1] - y1) * m[0][1] - + 2. * (x[0] - x1) * (x[2] - z1) * m[0][2] - + 2. * (x[1] - y1) * (x[2] - z1) * m[1][2] - ); + Radius = sqrt((x[0] - x1) * (x[0] - x1) * m[0][0] + + (x[1] - y1) * (x[1] - y1) * m[1][1] + + (x[2] - z1) * (x[2] - z1) * m[2][2] + + 2. * (x[0] - x1) * (x[1] - y1) * m[0][1] + + 2. * (x[0] - x1) * (x[2] - z1) * m[0][2] + + 2. * (x[1] - y1) * (x[2] - z1) * m[1][2] + ); } -int Simplex::Pt_In_Simplex_2D (Vertex * v){ +int Simplex::Pt_In_Simplex_2D(Vertex * v) +{ double Xmin, Xmax, Ymin, Ymax, Xtr[4], Ytr[4], A[2], B[2], X, Y, Signus[3]; int i; @@ -533,50 +574,50 @@ int Simplex::Pt_In_Simplex_2D (Vertex * v){ Ytr[1] = V[1]->Pos.Y; Ytr[2] = V[2]->Pos.Y; - for (i = 1; i < 3; i++){ + for(i = 1; i < 3; i++) { Xmin = (Xtr[i] < Xmin) ? Xtr[i] : Xmin; Xmax = (Xtr[i] > Xmax) ? Xtr[i] : Xmax; Ymin = (Ytr[i] < Ymin) ? Ytr[i] : Ymin; Ymax = (Ytr[i] > Ymax) ? Ytr[i] : Ymax; } - if (X > Xmax || X < Xmin || Y > Ymax || Y < Ymin) + if(X > Xmax || X < Xmin || Y > Ymax || Y < Ymin) return (0); - for (i = 0; i < 3; i++){ + for(i = 0; i < 3; i++) { A[0] = Xtr[i + 1] - Xtr[i]; A[1] = Ytr[i + 1] - Ytr[i]; B[0] = X - Xtr[i]; B[1] = Y - Ytr[i]; Signus[i] = A[0] * B[1] - A[1] * B[0]; } - for (i = 0; i < 2; i++){ - if ((Signus[i] * Signus[i + 1]) < 0) + for(i = 0; i < 2; i++) { + if((Signus[i] * Signus[i + 1]) < 0) return 0; } return 1; } -void Simplex::ExportLcField (FILE * f){ - if (!V[3]){ - fprintf (f, "ST(%f,%f,%f,%f,%f,%f,%f,%f,%f){%12.5E,%12.5E,%12.5E};\n" - ,V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z - ,V[1]->Pos.X, V[1]->Pos.Y, V[1]->Pos.Z - ,V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z - ,V[0]->lc, V[1]->lc, V[2]->lc); +void Simplex::ExportLcField(FILE * f) +{ + if(!V[3]) { + fprintf(f, "ST(%f,%f,%f,%f,%f,%f,%f,%f,%f){%12.5E,%12.5E,%12.5E};\n", + V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y, + V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[0]->lc, + V[1]->lc, V[2]->lc); } - else{ - fprintf (f, "SS(%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f){%12.5E,%12.5E,%12.5E,%12.5E};\n" - ,V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z - ,V[1]->Pos.X, V[1]->Pos.Y, V[1]->Pos.Z - ,V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z - ,V[3]->Pos.X, V[3]->Pos.Y, V[3]->Pos.Z - ,V[0]->lc, V[1]->lc, V[2]->lc, V[3]->lc); + else { + fprintf(f, + "SS(%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f,%f){%12.5E,%12.5E,%12.5E,%12.5E};\n", + V[0]->Pos.X, V[0]->Pos.Y, V[0]->Pos.Z, V[1]->Pos.X, V[1]->Pos.Y, + V[1]->Pos.Z, V[2]->Pos.X, V[2]->Pos.Y, V[2]->Pos.Z, V[3]->Pos.X, + V[3]->Pos.Y, V[3]->Pos.Z, V[0]->lc, V[1]->lc, V[2]->lc, V[3]->lc); } - + } -double Simplex::AireFace (Vertex * V[3]){ +double Simplex::AireFace(Vertex * V[3]) +{ double a[3], b[3], c[3]; a[0] = V[2]->Pos.X - V[1]->Pos.X; @@ -587,108 +628,113 @@ double Simplex::AireFace (Vertex * V[3]){ b[1] = V[0]->Pos.Y - V[1]->Pos.Y; b[2] = V[0]->Pos.Z - V[1]->Pos.Z; - prodve (a, b, c); - return (0.5 * sqrt (c[0] * c[0] + c[1] * c[1] + c[2] * c[2])); + prodve(a, b, c); + return (0.5 * sqrt(c[0] * c[0] + c[1] * c[1] + c[2] * c[2])); } -double Simplex::surfsimpl (){ - return AireFace (V); +double Simplex::surfsimpl() +{ + return AireFace(V); } -bool Simplex::VertexIn (Vertex * v){ - if (!this || this == &MyNewBoundary) +bool Simplex::VertexIn(Vertex * v) +{ + if(!this || this == &MyNewBoundary) return false; int N = 4; - if (!V[3]) + if(!V[3]) N = 3; - for (int i = 0; i < N; i++) - if (!compareVertex (&V[i], &v)) + for(int i = 0; i < N; i++) + if(!compareVertex(&V[i], &v)) return true; return false; } -bool Simplex::EdgeIn (Vertex * v1, Vertex * v2, Vertex * v[2]){ - if (!this || this == &MyNewBoundary) +bool Simplex::EdgeIn(Vertex * v1, Vertex * v2, Vertex * v[2]) +{ + if(!this || this == &MyNewBoundary) return false; int N = 4; - if (!V[3]) + if(!V[3]) N = 3; int n = 0; - for (int i = 0; i < N; i++){ - if (compareVertex (&V[i], &v1) && compareVertex (&V[i], &v2)){ + for(int i = 0; i < N; i++) { + if(compareVertex(&V[i], &v1) && compareVertex(&V[i], &v2)) { v[n++] = V[i]; - if (n > 2) + if(n > 2) return false; } } return true; } -bool Simplex::ExtractOppositeEdges (int iFac, Vertex * p[2], Vertex * q[2]){ +bool Simplex::ExtractOppositeEdges(int iFac, Vertex * p[2], Vertex * q[2]) +{ Simplex *s1 = this; - if (!s1 || s1 == &MyNewBoundary || !s1->iEnt) + if(!s1 || s1 == &MyNewBoundary || !s1->iEnt) return false; Simplex *s2 = s1->S[iFac]; - if (!s2 || s2 == &MyNewBoundary || !s2->iEnt) + if(!s2 || s2 == &MyNewBoundary || !s2->iEnt) return false; int i, ip = 0, iq = 0; - for (i = 0; i < 3; i++) - if (s1->VertexIn (s2->V[i])) + for(i = 0; i < 3; i++) + if(s1->VertexIn(s2->V[i])) p[ip++] = s2->V[i]; else q[iq++] = s2->V[i]; - for (i = 0; i < 3; i++) - if (!s2->VertexIn (s1->V[i])) + for(i = 0; i < 3; i++) + if(!s2->VertexIn(s1->V[i])) q[iq++] = s1->V[i]; - if (ip != 2 || iq != 2){ + if(ip != 2 || iq != 2) { return false; } return true; } -bool Simplex::SwapEdge (int iFac){ +bool Simplex::SwapEdge(int iFac) +{ Simplex *s1 = NULL, *s2 = NULL, *s11 = NULL, *s21 = NULL; - Vertex *p[4] = {NULL, NULL, NULL, NULL}; - Vertex *q[4] = {NULL, NULL, NULL, NULL}; + Vertex *p[4] = { NULL, NULL, NULL, NULL }; + Vertex *q[4] = { NULL, NULL, NULL, NULL }; int i, ip, iq; s1 = this; - if (!s1 || s1 == &MyNewBoundary || !s1->iEnt) + if(!s1 || s1 == &MyNewBoundary || !s1->iEnt) return false; s2 = s1->S[iFac]; - if (!s2 || s2 == &MyNewBoundary || !s2->iEnt) + if(!s2 || s2 == &MyNewBoundary || !s2->iEnt) return false; ip = iq = 0; - for (i = 0; i < 3; i++) - if (s1->VertexIn (s2->V[i])) + for(i = 0; i < 3; i++) + if(s1->VertexIn(s2->V[i])) p[ip++] = s2->V[i]; else q[iq++] = s2->V[i]; - for (i = 0; i < 3; i++) - if (!s2->VertexIn (s1->V[i])) + for(i = 0; i < 3; i++) + if(!s2->VertexIn(s1->V[i])) q[iq++] = s1->V[i]; - if (ip != 2 || iq != 2){ + if(ip != 2 || iq != 2) { return false; } - for (i = 0; i < 3; i++) - if (s1->S[i]->VertexIn (p[1]) && s1->S[i]->VertexIn (q[1])) + for(i = 0; i < 3; i++) + if(s1->S[i]->VertexIn(p[1]) && s1->S[i]->VertexIn(q[1])) s11 = s1->S[i]; - for (i = 0; i < 3; i++) - if (s2->S[i]->VertexIn (p[0]) && s2->S[i]->VertexIn (q[0])) + for(i = 0; i < 3; i++) + if(s2->S[i]->VertexIn(p[0]) && s2->S[i]->VertexIn(q[0])) s21 = s2->S[i]; - if (!s11 || !s21) + if(!s11 || !s21) return false; - double vol1 = s1->Volume_Simplexe () + s2->Volume_Simplexe (); + double vol1 = s1->Volume_Simplexe() + s2->Volume_Simplexe(); s1->V[0] = p[0]; s1->V[1] = q[0]; @@ -697,10 +743,10 @@ bool Simplex::SwapEdge (int iFac){ s2->V[1] = q[0]; s2->V[2] = q[1]; - double vol2 = s1->Volume_Simplexe () + s2->Volume_Simplexe (); + double vol2 = s1->Volume_Simplexe() + s2->Volume_Simplexe(); - if (s1->Volume_Simplexe () == 0.0 || s2->Volume_Simplexe () == 0.0 || - fabs (fabs (vol1) - fabs (vol2)) > 1.e-5 * (fabs (vol1) + fabs (vol2))){ + if(s1->Volume_Simplexe() == 0.0 || s2->Volume_Simplexe() == 0.0 || + fabs(fabs(vol1) - fabs(vol2)) > 1.e-5 * (fabs(vol1) + fabs(vol2))) { s1->V[0] = p[0]; s1->V[1] = p[1]; s1->V[2] = q[1]; @@ -710,91 +756,94 @@ bool Simplex::SwapEdge (int iFac){ return false; } - for (i = 0; i < 3; i++) - if (s1->S[i] == s11) + for(i = 0; i < 3; i++) + if(s1->S[i] == s11) s1->S[i] = s21; - for (i = 0; i < 3; i++) - if (s2->S[i] == s21) + for(i = 0; i < 3; i++) + if(s2->S[i] == s21) s2->S[i] = s11; - if (s21 != &MyNewBoundary && s21 && s21->iEnt) - for (i = 0; i < 3; i++) - if (s21->S[i] == s2) + if(s21 != &MyNewBoundary && s21 && s21->iEnt) + for(i = 0; i < 3; i++) + if(s21->S[i] == s2) s21->S[i] = s1; - if (s11 != &MyNewBoundary && s11 && s11->iEnt) - for (i = 0; i < 3; i++) - if (s11->S[i] == s1) + if(s11 != &MyNewBoundary && s11 && s11->iEnt) + for(i = 0; i < 3; i++) + if(s11->S[i] == s1) s11->S[i] = s2; return true; } -bool Simplex::SwapFace (int iFac, List_T * newsimp, List_T * delsimp){ +bool Simplex::SwapFace(int iFac, List_T * newsimp, List_T * delsimp) +{ Simplex *s = S[iFac], *s1, *s2, *s3; Vertex *o[2]; int i; - if (!s || s == &MyNewBoundary || !s->iEnt) + if(!s || s == &MyNewBoundary || !s->iEnt) return false; - if (!this || this == &MyNewBoundary || !this->iEnt) + if(!this || this == &MyNewBoundary || !this->iEnt) return false; - for (i = 0; i < 4; i++) - if (!VertexIn (s->V[i])) + for(i = 0; i < 4; i++) + if(!VertexIn(s->V[i])) o[0] = s->V[i]; - for (i = 0; i < 4; i++) - if (!s->VertexIn (V[i])) + for(i = 0; i < 4; i++) + if(!s->VertexIn(V[i])) o[1] = V[i]; - s1 = Create_Simplex (s->F[iFac].V[0], s->F[iFac].V[1], o[0], o[1]); - s2 = Create_Simplex (s->F[iFac].V[1], s->F[iFac].V[2], o[0], o[1]); - s3 = Create_Simplex (s->F[iFac].V[2], s->F[iFac].V[0], o[0], o[1]); + s1 = Create_Simplex(s->F[iFac].V[0], s->F[iFac].V[1], o[0], o[1]); + s2 = Create_Simplex(s->F[iFac].V[1], s->F[iFac].V[2], o[0], o[1]); + s3 = Create_Simplex(s->F[iFac].V[2], s->F[iFac].V[0], o[0], o[1]); - double vol1 = s->Volume_Simplexe () + Volume_Simplexe (); - double vol2 = s1->Volume_Simplexe () + s2->Volume_Simplexe () + s3->Volume_Simplexe (); + double vol1 = s->Volume_Simplexe() + Volume_Simplexe(); + double vol2 = + s1->Volume_Simplexe() + s2->Volume_Simplexe() + s3->Volume_Simplexe(); - if (fabs (fabs (vol1) - fabs (vol2)) > 1.e-5 * (fabs (vol1) + fabs (vol2))){ + if(fabs(fabs(vol1) - fabs(vol2)) > 1.e-5 * (fabs(vol1) + fabs(vol2))) { delete s1; delete s2; delete s3; return false; } - - double gamma1 = GammaShapeMeasure (); - if (s1->GammaShapeMeasure () < gamma1 || - s2->GammaShapeMeasure () < gamma1 || - s3->GammaShapeMeasure () < gamma1) + double gamma1 = GammaShapeMeasure(); + + if(s1->GammaShapeMeasure() < gamma1 || + s2->GammaShapeMeasure() < gamma1 || s3->GammaShapeMeasure() < gamma1) return false; return true; } -int compareFace (const void *a, const void *b){ +int compareFace(const void *a, const void *b) +{ Face *q, *w; q = (Face *) a; w = (Face *) b; - if (!q->V[0] || !w->V[0]) - Msg(FATAL, "Bad face (are you trying to generate hexahedra with a Delaunay?!)"); + if(!q->V[0] || !w->V[0]) + Msg(FATAL, + "Bad face (are you trying to generate hexahedra with a Delaunay?!)"); - if (q->V[0]->Num > w->V[0]->Num) + if(q->V[0]->Num > w->V[0]->Num) return (1); - if (q->V[0]->Num < w->V[0]->Num) + if(q->V[0]->Num < w->V[0]->Num) return (-1); - if (q->V[1]->Num > w->V[1]->Num) + if(q->V[1]->Num > w->V[1]->Num) return (1); - if (q->V[1]->Num < w->V[1]->Num) + if(q->V[1]->Num < w->V[1]->Num) return (-1); - if (FACE_DIMENSION == 1 || !q->V[2] || !w->V[2]) + if(FACE_DIMENSION == 1 || !q->V[2] || !w->V[2]) return 0; - if (q->V[2]->Num > w->V[2]->Num) + if(q->V[2]->Num > w->V[2]->Num) return (1); - if (q->V[2]->Num < w->V[2]->Num) + if(q->V[2]->Num < w->V[2]->Num) return (-1); return (0); } diff --git a/Mesh/Smoothing.cpp b/Mesh/Smoothing.cpp index 7628c3760afd1f9dd44f76dd0c48b632cd849f04..4501cec330cd512c7cbfed46d89ff93317fddca0 100644 --- a/Mesh/Smoothing.cpp +++ b/Mesh/Smoothing.cpp @@ -1,4 +1,4 @@ -// $Id: Smoothing.cpp,v 1.9 2003-01-23 20:19:22 geuzaine Exp $ +// $Id: Smoothing.cpp,v 1.10 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -23,52 +23,54 @@ #include "Numeric.h" #include "Mesh.h" - -void AmelioreSurface_EliminationTripet (Surface * surf, Mesh * m, Tree_T * tnxe){ +void AmelioreSurface_EliminationTripet(Surface * surf, Mesh * m, + Tree_T * tnxe) +{ int i, j, k; - List_T *lnxe = Tree2List (tnxe); + List_T *lnxe = Tree2List(tnxe); Vertex *v1, *v2, *v3; - List_T *ListNoeuds = List_Create (2, 1, sizeof (Vertex *)); + List_T *ListNoeuds = List_Create(2, 1, sizeof(Vertex *)); Simplex *s[3], *news; NXE nxe; bool ok; - for (i = 0; i < List_Nbr (lnxe); i++){ - List_Read (lnxe, i, &nxe); - if (List_Nbr (nxe.Liste) == 3){ + for(i = 0; i < List_Nbr(lnxe); i++) { + List_Read(lnxe, i, &nxe); + if(List_Nbr(nxe.Liste) == 3) { ok = true; - if (nxe.v->ListCurves) + if(nxe.v->ListCurves) ok = false; - else{ - for (j = 0; j < 3; j++){ - List_Read (nxe.Liste, j, &s[j]); - if (!Tree_Search (surf->Simplexes, &s[j])) + else { + for(j = 0; j < 3; j++) { + List_Read(nxe.Liste, j, &s[j]); + if(!Tree_Search(surf->Simplexes, &s[j])) ok = false; - for (k = 0; k < 3; k++) - if (compareVertex (&nxe.v, &s[j]->V[k])) - List_Insert (ListNoeuds, &s[j]->V[k], compareVertex); + for(k = 0; k < 3; k++) + if(compareVertex(&nxe.v, &s[j]->V[k])) + List_Insert(ListNoeuds, &s[j]->V[k], compareVertex); } } - if (ok){ - List_Read (ListNoeuds, 0, &v1); - List_Read (ListNoeuds, 1, &v2); - List_Read (ListNoeuds, 2, &v3); - news = Create_Simplex (v1, v2, v3, 0); - Tree_Suppress (surf->Simplexes, &s[0]); - Tree_Suppress (surf->Simplexes, &s[1]); - Tree_Suppress (surf->Simplexes, &s[2]); - Tree_Suppress (m->Vertices, &nxe.v); - Tree_Add (surf->Simplexes, &news); + if(ok) { + List_Read(ListNoeuds, 0, &v1); + List_Read(ListNoeuds, 1, &v2); + List_Read(ListNoeuds, 2, &v3); + news = Create_Simplex(v1, v2, v3, 0); + Tree_Suppress(surf->Simplexes, &s[0]); + Tree_Suppress(surf->Simplexes, &s[1]); + Tree_Suppress(surf->Simplexes, &s[2]); + Tree_Suppress(m->Vertices, &nxe.v); + Tree_Add(surf->Simplexes, &news); } - List_Reset (ListNoeuds); + List_Reset(ListNoeuds); } } - List_Delete (ListNoeuds); - List_Delete (lnxe); + List_Delete(ListNoeuds); + List_Delete(lnxe); } -void ActionLiss (void *data, void *dummy){ +void ActionLiss(void *data, void *dummy) +{ List_T *nodes; NXE *pnxe; @@ -80,22 +82,22 @@ void ActionLiss (void *data, void *dummy){ pnxe = (NXE *) data; /* On Ne Lisse Point Les Points sur les courbes (quelle horreur) */ - if (pnxe->v->ListCurves) + if(pnxe->v->ListCurves) return; - nodes = List_Create (2, 2, sizeof (Vertex *)); + nodes = List_Create(2, 2, sizeof(Vertex *)); X = Y = Z = Sum = 0.0; double volume_before = 0.0; double min_quality_old = 1.0; - for (i = 0; i < List_Nbr (pnxe->Liste); i++){ - List_Read (pnxe->Liste, i, &s); - min_quality_old = DMIN (min_quality_old, s->GammaShapeMeasure ()); - volume_before += s->Volume_Simplexe (); + for(i = 0; i < List_Nbr(pnxe->Liste); i++) { + List_Read(pnxe->Liste, i, &s); + min_quality_old = DMIN(min_quality_old, s->GammaShapeMeasure()); + volume_before += s->Volume_Simplexe(); /* On Ne Lisse Point Les Points sur les surfaces quand les volumes sont mailles */ - if (s->V[3] && pnxe->v->ListSurf) + if(s->V[3] && pnxe->v->ListSurf) return; - for (j = 0; j < 4; j++){ - if (s->V[j] && compareVertex (&pnxe->v, &s->V[j])){ + for(j = 0; j < 4; j++) { + if(s->V[j] && compareVertex(&pnxe->v, &s->V[j])) { Sum += 0.5; X += s->V[j]->Pos.X * 0.5; Y += s->V[j]->Pos.Y * 0.5; @@ -103,31 +105,32 @@ void ActionLiss (void *data, void *dummy){ } } } - + double xold = pnxe->v->Pos.X; double yold = pnxe->v->Pos.Y; double zold = pnxe->v->Pos.Z; double a = 0.5; - if (Sum != 0.0){ + if(Sum != 0.0) { pnxe->v->Pos.X = a * (X / Sum) + (1. - a) * pnxe->v->Pos.X; pnxe->v->Pos.Y = a * (Y / Sum) + (1. - a) * pnxe->v->Pos.Y; pnxe->v->Pos.Z = a * (Z / Sum) + (1. - a) * pnxe->v->Pos.Z; } double min_quality_new = 1.0; - for (i = 0; i < List_Nbr (pnxe->Liste); i++){ - List_Read (pnxe->Liste, i, &s); - min_quality_new = DMIN (min_quality_new, s->GammaShapeMeasure ()); + for(i = 0; i < List_Nbr(pnxe->Liste); i++) { + List_Read(pnxe->Liste, i, &s); + min_quality_new = DMIN(min_quality_new, s->GammaShapeMeasure()); } - + double volume_after = 0.0; - for (i = 0; i < List_Nbr (pnxe->Liste); i++){ - List_Read (pnxe->Liste, i, &s); - volume_after += s->Volume_Simplexe (); + for(i = 0; i < List_Nbr(pnxe->Liste); i++) { + List_Read(pnxe->Liste, i, &s); + volume_after += s->Volume_Simplexe(); } - if (fabs (volume_after - volume_before) > 1.e-8 * fabs (volume_after + volume_before) - || min_quality_old > min_quality_new){ + if(fabs(volume_after - volume_before) > + 1.e-8 * fabs(volume_after + volume_before) + || min_quality_old > min_quality_new) { pnxe->v->Pos.X = xold; pnxe->v->Pos.Y = yold; pnxe->v->Pos.Z = zold; @@ -136,7 +139,8 @@ void ActionLiss (void *data, void *dummy){ } -void ActionLissSurf (void *data, void *dummy){ +void ActionLissSurf(void *data, void *dummy) +{ NXE *pnxe; Simplex *s; double X, Y, Z, Sum; @@ -147,18 +151,18 @@ void ActionLissSurf (void *data, void *dummy){ /* On Ne Lisse Point Les Points sur les courbes */ - if (pnxe->v->ListCurves) + if(pnxe->v->ListCurves) return; X = Y = Z = Sum = 0.0; - for (i = 0; i < List_Nbr (pnxe->Liste); i++){ - List_Read (pnxe->Liste, i, &s); + for(i = 0; i < List_Nbr(pnxe->Liste); i++) { + List_Read(pnxe->Liste, i, &s); /* - On Ne Lisse Point Les Points sur les surfaces quand les - volumes sont mailles - */ - for (j = 0; j < 4; j++){ - if (s->V[j] && compareVertex (&pnxe->v, &s->V[j])){ + On Ne Lisse Point Les Points sur les surfaces quand les + volumes sont mailles + */ + for(j = 0; j < 4; j++) { + if(s->V[j] && compareVertex(&pnxe->v, &s->V[j])) { Sum += 0.5; X += s->V[j]->Pos.X * 0.5; Y += s->V[j]->Pos.Y * 0.5; @@ -166,19 +170,20 @@ void ActionLissSurf (void *data, void *dummy){ } } } - if (Sum != 0.0){ + if(Sum != 0.0) { pnxe->v->Pos.X = X / Sum; pnxe->v->Pos.Y = Y / Sum; pnxe->v->Pos.Z = Z / Sum; } } -void RandomSwapEdges (Surface * s){ +void RandomSwapEdges(Surface * s) +{ int i; - List_T *AllTrg = Tree2List (s->Simplexes); + List_T *AllTrg = Tree2List(s->Simplexes); Simplex *t; - for (i = 0; i < List_Nbr (AllTrg); i++){ - List_Read (AllTrg, i, &t); - t->SwapEdge (1); + for(i = 0; i < List_Nbr(AllTrg); i++) { + List_Read(AllTrg, i, &t); + t->SwapEdge(1); } } diff --git a/Mesh/SwapEdge.cpp b/Mesh/SwapEdge.cpp index 3ea722ee1a99f009f2109468f6d106f5afade045..ec0b1928281ee0ae6959ee0bc7590c7f9114e852 100644 --- a/Mesh/SwapEdge.cpp +++ b/Mesh/SwapEdge.cpp @@ -1,4 +1,4 @@ -// $Id: SwapEdge.cpp,v 1.12 2003-02-25 04:02:51 geuzaine Exp $ +// $Id: SwapEdge.cpp,v 1.13 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -28,30 +28,31 @@ extern Simplex MyNewBoundary; extern int edges_tetra[6][2]; -int TrouveCoquille (Simplex * s, Vertex * Ed[2], - List_T * Coquille, Tree_T * TreeSimpl, - Vertex * Contour[100]){ +int TrouveCoquille(Simplex * s, Vertex * Ed[2], + List_T * Coquille, Tree_T * TreeSimpl, + Vertex * Contour[100]) +{ Simplex *stack[256], *actual; Vertex *other[2]; int K, i, N = 0; - List_T *Edges = List_Create (12, 2, sizeof (Edge)); + List_T *Edges = List_Create(12, 2, sizeof(Edge)); Edge E; stack[N++] = s; - while (N > 0){ + while(N > 0) { actual = stack[--N]; - if (!Tree_Search (TreeSimpl, &actual)){ - Tree_Add (TreeSimpl, &actual); - if (actual->EdgeIn (Ed[0], Ed[1], other)){ - List_Add (Coquille, &actual); - if (actual != s) + if(!Tree_Search(TreeSimpl, &actual)) { + Tree_Add(TreeSimpl, &actual); + if(actual->EdgeIn(Ed[0], Ed[1], other)) { + List_Add(Coquille, &actual); + if(actual != s) actual->Radius = -1.; E.V[0] = other[0]; E.V[1] = other[1]; - List_Add (Edges, &E); - for (i = 0; i < 4; i++){ - if (actual->S[i] && actual->S[i] != &MyNewBoundary) + List_Add(Edges, &E); + for(i = 0; i < 4; i++) { + if(actual->S[i] && actual->S[i] != &MyNewBoundary) stack[N++] = actual->S[i]; else return 0; @@ -60,40 +61,41 @@ int TrouveCoquille (Simplex * s, Vertex * Ed[2], } } - List_Read (Edges, 0, &E); + List_Read(Edges, 0, &E); N = 0; Contour[N++] = E.V[0]; Contour[N++] = E.V[1]; - List_Suppress (Edges, &E, compareedge); + List_Suppress(Edges, &E, compareedge); K = 0; - while (List_Nbr (Edges)){ - if (K++ > Tree_Nbr (TreeSimpl)) + while(List_Nbr(Edges)) { + if(K++ > Tree_Nbr(TreeSimpl)) return 0; - for (i = 0; i < List_Nbr (Edges); i++){ - List_Read (Edges, i, &E); - if (!compareVertex (&Contour[N - 1], &E.V[0]) && - compareVertex (&Contour[N - 2], &E.V[1])){ + for(i = 0; i < List_Nbr(Edges); i++) { + List_Read(Edges, i, &E); + if(!compareVertex(&Contour[N - 1], &E.V[0]) && + compareVertex(&Contour[N - 2], &E.V[1])) { Contour[N++] = E.V[1]; - List_Suppress (Edges, &E, compareedge); + List_Suppress(Edges, &E, compareedge); break; } - if (!compareVertex (&Contour[N - 1], &E.V[1]) && - compareVertex (&Contour[N - 2], &E.V[0])){ + if(!compareVertex(&Contour[N - 1], &E.V[1]) && + compareVertex(&Contour[N - 2], &E.V[0])) { Contour[N++] = E.V[0]; - List_Suppress (Edges, &E, compareedge); + List_Suppress(Edges, &E, compareedge); break; } } - + } - if (!compareVertex (&Contour[0], &Contour[N - 1])) + if(!compareVertex(&Contour[0], &Contour[N - 1])) return N - 1; return 0; } -bool FindBestPattern (int N, Vertex * Contour[100], Vertex * Ed[2], - List_T * Coquille, List_T * Pattern){ +bool FindBestPattern(int N, Vertex * Contour[100], Vertex * Ed[2], + List_T * Coquille, List_T * Pattern) +{ int i, j, k, kk, tri[3]; Simplex *s, *Pat[100]; double old_volume, new_volume; @@ -106,7 +108,7 @@ bool FindBestPattern (int N, Vertex * Contour[100], Vertex * Ed[2], SwapPattern6 *x6; SwapPattern7 *x7; SwapPatternN *xN; - switch (N){ + switch (N) { case 3: x3 = new SwapPattern3; sp = x3; @@ -116,27 +118,27 @@ bool FindBestPattern (int N, Vertex * Contour[100], Vertex * Ed[2], sp = x4; break; case 5: - if (stop) + if(stop) return false; x5 = new SwapPattern5; sp = x5; break; case 6: - if (stop) + if(stop) return false; x6 = new SwapPattern6; sp = x6; break; case 7: - if (stop) + if(stop) return false; x7 = new SwapPattern7; sp = x7; break; default: - if (stop) + if(stop) return false; - xN = new SwapPatternN (N); + xN = new SwapPatternN(N); sp = xN; break; } @@ -144,99 +146,98 @@ bool FindBestPattern (int N, Vertex * Contour[100], Vertex * Ed[2], old_volume = 0.0; worst_tet_old = 1.; int IENT = 0; - for (k = 0; k < List_Nbr (Coquille); k++){ - List_Read (Coquille, k, &s); + for(k = 0; k < List_Nbr(Coquille); k++) { + List_Read(Coquille, k, &s); IENT = s->iEnt; - old_volume += fabs (s->Volume_Simplexe ()); - worst_tet_old = DMIN (worst_tet_old, s->GammaShapeMeasure ()); + old_volume += fabs(s->Volume_Simplexe()); + worst_tet_old = DMIN(worst_tet_old, s->GammaShapeMeasure()); } - for (i = 0; i < sp->GetNbPatterns (); i++){ - for (j = 0; j < sp->GetNbRotations (i); j++){ + for(i = 0; i < sp->GetNbPatterns(); i++) { + for(j = 0; j < sp->GetNbRotations(i); j++) { new_volume = 0.; worst_tet_new = 1.; kk = 0; - for (k = 0; k < sp->GetNbTriangles (); k++){ - sp->GetTriangle (i, k, tri); - s = Create_Simplex (Contour[tri[0]], - Contour[tri[1]], - Contour[tri[2]], - Ed[0]); + for(k = 0; k < sp->GetNbTriangles(); k++) { + sp->GetTriangle(i, k, tri); + s = Create_Simplex(Contour[tri[0]], + Contour[tri[1]], Contour[tri[2]], Ed[0]); s->iEnt = IENT; Pat[kk++] = s; - new_volume += fabs (s->Volume_Simplexe ()); - worst_tet_new = DMIN (worst_tet_new, s->GammaShapeMeasure ()); - s = Create_Simplex (Contour[tri[0]], - Contour[tri[1]], - Contour[tri[2]], - Ed[1]); + new_volume += fabs(s->Volume_Simplexe()); + worst_tet_new = DMIN(worst_tet_new, s->GammaShapeMeasure()); + s = Create_Simplex(Contour[tri[0]], + Contour[tri[1]], Contour[tri[2]], Ed[1]); s->iEnt = IENT; Pat[kk++] = s; - new_volume += fabs (s->Volume_Simplexe ()); - worst_tet_new = DMIN (worst_tet_new, s->GammaShapeMeasure ()); + new_volume += fabs(s->Volume_Simplexe()); + worst_tet_new = DMIN(worst_tet_new, s->GammaShapeMeasure()); } - if (fabs (new_volume - old_volume) > 1.e-5 * fabs (new_volume + old_volume)) + if(fabs(new_volume - old_volume) > + 1.e-5 * fabs(new_volume + old_volume)) Msg(WARNING, "Edge swapping failed"); - if (fabs (new_volume - old_volume) > 1.e-5 * fabs (new_volume + old_volume) - || worst_tet_new < worst_tet_old){ - for (k = 0; k < 2 * sp->GetNbTriangles (); k++){ + if(fabs(new_volume - old_volume) > 1.e-5 * fabs(new_volume + old_volume) + || worst_tet_new < worst_tet_old) { + for(k = 0; k < 2 * sp->GetNbTriangles(); k++) { delete Pat[k]; } } - else{ - for (k = 0; k < List_Nbr (Pattern); k++){ - List_Read (Pattern, k, &s); + else { + for(k = 0; k < List_Nbr(Pattern); k++) { + List_Read(Pattern, k, &s); delete s; } - List_Reset (Pattern); - for (k = 0; k < 2 * sp->GetNbTriangles (); k++){ - List_Add (Pattern, &Pat[k]); + List_Reset(Pattern); + for(k = 0; k < 2 * sp->GetNbTriangles(); k++) { + List_Add(Pattern, &Pat[k]); } worst_tet_old = worst_tet_new; } } } - + delete sp; - return true ; + return true; } -bool SwapEdge (Mesh * M, Volume * v, Simplex * s, int iEdge){ +bool SwapEdge(Mesh * M, Volume * v, Simplex * s, int iEdge) +{ int i; Vertex *Contour[100]; Vertex *Ed[2]; Simplex *simp; - Tree_T *TreeSimpl = Tree_Create (sizeof (Simplex *), compareSimplex); - List_T *Coquille = List_Create (10, 10, sizeof (Simplex *)); + Tree_T *TreeSimpl = Tree_Create(sizeof(Simplex *), compareSimplex); + List_T *Coquille = List_Create(10, 10, sizeof(Simplex *)); Ed[0] = s->V[edges_tetra[iEdge][0]]; Ed[1] = s->V[edges_tetra[iEdge][1]]; - int N = TrouveCoquille (s, Ed, Coquille, TreeSimpl, Contour); + int N = TrouveCoquille(s, Ed, Coquille, TreeSimpl, Contour); - List_T *Pattern = List_Create (2 * N - 4, 1, sizeof (Simplex *)); + List_T *Pattern = List_Create(2 * N - 4, 1, sizeof(Simplex *)); - FindBestPattern (N, Contour, Ed, Coquille, Pattern); + FindBestPattern(N, Contour, Ed, Coquille, Pattern); - if (List_Nbr (Pattern)){ - for (i = 0; i < List_Nbr (Coquille); i++){ - List_Read (Coquille, i, &simp); - Tree_Suppress (v->Simplexes, &simp); - Tree_Suppress (TreeSimpl, &simp); + if(List_Nbr(Pattern)) { + for(i = 0; i < List_Nbr(Coquille); i++) { + List_Read(Coquille, i, &simp); + Tree_Suppress(v->Simplexes, &simp); + Tree_Suppress(TreeSimpl, &simp); } - for (i = 0; i < List_Nbr (Pattern); i++){ - List_Read (Pattern, i, &simp); - Tree_Add (v->Simplexes, &simp); - Tree_Add (TreeSimpl, &simp); + for(i = 0; i < List_Nbr(Pattern); i++) { + List_Read(Pattern, i, &simp); + Tree_Add(v->Simplexes, &simp); + Tree_Add(TreeSimpl, &simp); } - Link_Simplexes (NULL, TreeSimpl /*v->Simplexes */ ); + Link_Simplexes(NULL, TreeSimpl /*v->Simplexes */ ); } - Tree_Delete (TreeSimpl); - List_Delete (Coquille); - List_Delete (Pattern); - return true ; + Tree_Delete(TreeSimpl); + List_Delete(Coquille); + List_Delete(Pattern); + return true; } -int GetWorstEdge (Simplex * s, EdgesContainer & ec, bool order){ +int GetWorstEdge(Simplex * s, EdgesContainer & ec, bool order) +{ Vertex *v11, *v12; Vertex *v21, *v22; v11 = s->V[edges_tetra[0][0]]; @@ -245,9 +246,9 @@ int GetWorstEdge (Simplex * s, EdgesContainer & ec, bool order){ v22 = s->V[edges_tetra[4][1]]; Vertex d11 = *(v12) - *(v11); Vertex d12 = *(v22) - *(v21); - d12.norme (); - d11.norme (); - double prosc1 = fabs (d11 * d12); + d12.norme(); + d11.norme(); + double prosc1 = fabs(d11 * d12); v11 = s->V[edges_tetra[1][0]]; v12 = s->V[edges_tetra[1][1]]; @@ -255,9 +256,9 @@ int GetWorstEdge (Simplex * s, EdgesContainer & ec, bool order){ v22 = s->V[edges_tetra[3][1]]; Vertex d21 = *(v12) - *(v11); Vertex d22 = *(v22) - *(v21); - d22.norme (); - d21.norme (); - double prosc2 = fabs (d21 * d22); + d22.norme(); + d21.norme(); + double prosc2 = fabs(d21 * d22); v11 = s->V[edges_tetra[2][0]]; v12 = s->V[edges_tetra[2][1]]; @@ -265,56 +266,57 @@ int GetWorstEdge (Simplex * s, EdgesContainer & ec, bool order){ v22 = s->V[edges_tetra[5][1]]; Vertex d31 = *(v12) - *(v11); Vertex d32 = *(v22) - *(v21); - d32.norme (); - d31.norme (); - double prosc3 = fabs (d31 * d32); + d32.norme(); + d31.norme(); + double prosc3 = fabs(d31 * d32); - if (prosc1 < prosc2 && prosc1 < prosc3){ - if (!order && !ec.Search (s->V[edges_tetra[0][0]], s->V[edges_tetra[0][1]])) + if(prosc1 < prosc2 && prosc1 < prosc3) { + if(!order && !ec.Search(s->V[edges_tetra[0][0]], s->V[edges_tetra[0][1]])) return 0; - if (!ec.Search (s->V[edges_tetra[4][0]], s->V[edges_tetra[4][1]])) + if(!ec.Search(s->V[edges_tetra[4][0]], s->V[edges_tetra[4][1]])) return 4; - if (!ec.Search (s->V[edges_tetra[0][0]], s->V[edges_tetra[0][1]])) + if(!ec.Search(s->V[edges_tetra[0][0]], s->V[edges_tetra[0][1]])) return 0; return -1; } - if (prosc2 < prosc1 && prosc2 < prosc3){ - if (!order && !ec.Search (s->V[edges_tetra[1][0]], s->V[edges_tetra[1][1]])) + if(prosc2 < prosc1 && prosc2 < prosc3) { + if(!order && !ec.Search(s->V[edges_tetra[1][0]], s->V[edges_tetra[1][1]])) return 1; - if (!ec.Search (s->V[edges_tetra[3][0]], s->V[edges_tetra[3][1]])) + if(!ec.Search(s->V[edges_tetra[3][0]], s->V[edges_tetra[3][1]])) return 3; - if (!ec.Search (s->V[edges_tetra[1][0]], s->V[edges_tetra[1][1]])) + if(!ec.Search(s->V[edges_tetra[1][0]], s->V[edges_tetra[1][1]])) return 1; return -1; } - if (prosc3 < prosc2 && prosc3 < prosc1){ - if (!order && !ec.Search (s->V[edges_tetra[2][0]], s->V[edges_tetra[2][1]])) + if(prosc3 < prosc2 && prosc3 < prosc1) { + if(!order && !ec.Search(s->V[edges_tetra[2][0]], s->V[edges_tetra[2][1]])) return 2; - if (!ec.Search (s->V[edges_tetra[5][0]], s->V[edges_tetra[5][1]])) + if(!ec.Search(s->V[edges_tetra[5][0]], s->V[edges_tetra[5][1]])) return 5; - if (!ec.Search (s->V[edges_tetra[2][0]], s->V[edges_tetra[2][1]])) + if(!ec.Search(s->V[edges_tetra[2][0]], s->V[edges_tetra[2][1]])) return 2; return -1; } return -1; } -void SwapEdges3D (Mesh * M, Volume * v, double GammaPrescribed, bool order){ - List_T *list = Tree2List (v->Simplexes); - List_T *srfs = Tree2List (M->Surfaces); - if (!List_Nbr (srfs)) +void SwapEdges3D(Mesh * M, Volume * v, double GammaPrescribed, bool order) +{ + List_T *list = Tree2List(v->Simplexes); + List_T *srfs = Tree2List(M->Surfaces); + if(!List_Nbr(srfs)) return; - EdgesContainer ec (srfs); + EdgesContainer ec(srfs); Simplex *s; - for (int i = 0; i < List_Nbr (list); i++){ - List_Read (list, i, &s); - if (s->GammaShapeMeasure () < GammaPrescribed){ - int iEdge = GetWorstEdge (s, ec, order); - if (iEdge >= 0) - SwapEdge (M, v, s, iEdge); + for(int i = 0; i < List_Nbr(list); i++) { + List_Read(list, i, &s); + if(s->GammaShapeMeasure() < GammaPrescribed) { + int iEdge = GetWorstEdge(s, ec, order); + if(iEdge >= 0) + SwapEdge(M, v, s, iEdge); } } - List_Delete (srfs); - List_Delete (list); + List_Delete(srfs); + List_Delete(list); } diff --git a/Mesh/Utils.cpp b/Mesh/Utils.cpp index 63f1505530b06ac057533191b2becad89e1b3458..94387d20f287391436f81ebfcf69378116494bdd 100644 --- a/Mesh/Utils.cpp +++ b/Mesh/Utils.cpp @@ -1,4 +1,4 @@ -// $Id: Utils.cpp,v 1.16 2003-02-25 04:02:51 geuzaine Exp $ +// $Id: Utils.cpp,v 1.17 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -36,13 +36,15 @@ extern Context_T CTX; -void direction (Vertex * v1, Vertex * v2, double d[3]){ +void direction(Vertex * v1, Vertex * v2, double d[3]) +{ d[0] = v2->Pos.X - v1->Pos.X; d[1] = v2->Pos.Y - v1->Pos.Y; d[2] = v2->Pos.Z - v1->Pos.Z; } -void Projette (Vertex * v, double mat[3][3]){ +void Projette(Vertex * v, double mat[3][3]) +{ double X, Y, Z; X = v->Pos.X * mat[0][0] + v->Pos.Y * mat[0][1] + v->Pos.Z * mat[0][2]; @@ -60,42 +62,46 @@ void Projette (Vertex * v, double mat[3][3]){ cercle! En attendant mieux, il y a donc un test de coherence supplementaire pour les surfaces non-planes. */ -void MeanPlane(List_T *points, Surface *s){ - int i, j, min, ndata, na; +void MeanPlane(List_T * points, Surface * s) +{ + int i, j, min, ndata, na; double res[4], ex[3], t1[3], t2[3], svd[3]; Vertex *v; - double xm=0., ym=0., zm=0.; + double xm = 0., ym = 0., zm = 0.; ndata = List_Nbr(points); na = 3; - for (i=0; i<ndata; i++){ + for(i = 0; i < ndata; i++) { List_Read(points, i, &v); xm += v->Pos.X; ym += v->Pos.Y; zm += v->Pos.Z; } - xm/=(double)ndata; - ym/=(double)ndata; - zm/=(double)ndata; + xm /= (double)ndata; + ym /= (double)ndata; + zm /= (double)ndata; #if defined(HAVE_GSL) gsl_matrix *U = gsl_matrix_alloc(ndata, na); gsl_matrix *V = gsl_matrix_alloc(na, na); gsl_vector *W = gsl_vector_alloc(na); gsl_vector *TMPVEC = gsl_vector_alloc(na); - for (i=0; i<ndata; i++){ + for(i = 0; i < ndata; i++) { List_Read(points, i, &v); - gsl_matrix_set(U, i, 0, v->Pos.X-xm); - gsl_matrix_set(U, i, 1, v->Pos.Y-ym); - gsl_matrix_set(U, i, 2, v->Pos.Z-zm); + gsl_matrix_set(U, i, 0, v->Pos.X - xm); + gsl_matrix_set(U, i, 1, v->Pos.Y - ym); + gsl_matrix_set(U, i, 2, v->Pos.Z - zm); } - gsl_linalg_SV_decomp(U,V,W,TMPVEC); + gsl_linalg_SV_decomp(U, V, W, TMPVEC); svd[0] = gsl_vector_get(W, 0); svd[1] = gsl_vector_get(W, 1); svd[2] = gsl_vector_get(W, 2); - if(fabs(svd[0])<fabs(svd[1]) && fabs(svd[0])<fabs(svd[2])) min=0; - else if(fabs(svd[1])<fabs(svd[0]) && fabs(svd[1])<fabs(svd[2])) min=1; - else min=2; + if(fabs(svd[0]) < fabs(svd[1]) && fabs(svd[0]) < fabs(svd[2])) + min = 0; + else if(fabs(svd[1]) < fabs(svd[0]) && fabs(svd[1]) < fabs(svd[2])) + min = 1; + else + min = 2; res[0] = gsl_matrix_get(V, 0, min); res[1] = gsl_matrix_get(V, 1, min); res[2] = gsl_matrix_get(V, 2, min); @@ -105,19 +111,22 @@ void MeanPlane(List_T *points, Surface *s){ gsl_vector_free(W); gsl_vector_free(TMPVEC); #else - double **U = dmatrix(1,ndata,1,na); - double **V = dmatrix(1,na,1,na); - double *W = dvector(1,na); - for (i=0; i<ndata; i++){ + double **U = dmatrix(1, ndata, 1, na); + double **V = dmatrix(1, na, 1, na); + double *W = dvector(1, na); + for(i = 0; i < ndata; i++) { List_Read(points, i, &v); - U[i+1][1] = v->Pos.X-xm; - U[i+1][2] = v->Pos.Y-ym; - U[i+1][3] = v->Pos.Z-zm; + U[i + 1][1] = v->Pos.X - xm; + U[i + 1][2] = v->Pos.Y - ym; + U[i + 1][3] = v->Pos.Z - zm; } - dsvdcmp(U,ndata,na,W,V); - if(fabs(W[1])<fabs(W[2]) && fabs(W[1])<fabs(W[3])) min=1; - else if(fabs(W[2])<fabs(W[1]) && fabs(W[2])<fabs(W[3])) min=2; - else min=3; + dsvdcmp(U, ndata, na, W, V); + if(fabs(W[1]) < fabs(W[2]) && fabs(W[1]) < fabs(W[3])) + min = 1; + else if(fabs(W[2]) < fabs(W[1]) && fabs(W[2]) < fabs(W[3])) + min = 2; + else + min = 3; svd[0] = W[1]; svd[1] = W[2]; svd[2] = W[3]; @@ -125,63 +134,65 @@ void MeanPlane(List_T *points, Surface *s){ res[1] = V[2][min]; res[2] = V[3][min]; norme(res); - free_dmatrix(U,1,ndata,1,na); - free_dmatrix(V,1,na,1,na); - free_dvector(W,1,na); + free_dmatrix(U, 1, ndata, 1, na); + free_dmatrix(V, 1, na, 1, na); + free_dvector(W, 1, na); #endif // check coherence of results for non-plane surfaces - if(s->Typ != MSH_SURF_PLAN){ + if(s->Typ != MSH_SURF_PLAN) { double res2[3], c[3], cosc, sinc, angplan; - double eps=1.e-3; + double eps = 1.e-3; Vertex v1, v2, v3; - v1 = InterpolateSurface(s,0.5,0.5,0,0); - v2 = InterpolateSurface(s,0.5+eps,0.5,0,0); - v3 = InterpolateSurface(s,0.5,0.5+eps,0,0); - t1[0] = v2.Pos.X-v1.Pos.X; - t1[1] = v2.Pos.Y-v1.Pos.Y; - t1[2] = v2.Pos.Z-v1.Pos.Z; - t2[0] = v3.Pos.X-v1.Pos.X; - t2[1] = v3.Pos.Y-v1.Pos.Y; - t2[2] = v3.Pos.Z-v1.Pos.Z; + v1 = InterpolateSurface(s, 0.5, 0.5, 0, 0); + v2 = InterpolateSurface(s, 0.5 + eps, 0.5, 0, 0); + v3 = InterpolateSurface(s, 0.5, 0.5 + eps, 0, 0); + t1[0] = v2.Pos.X - v1.Pos.X; + t1[1] = v2.Pos.Y - v1.Pos.Y; + t1[2] = v2.Pos.Z - v1.Pos.Z; + t2[0] = v3.Pos.X - v1.Pos.X; + t2[1] = v3.Pos.Y - v1.Pos.Y; + t2[2] = v3.Pos.Z - v1.Pos.Z; norme(t1); norme(t2); prodve(t1, t2, res2); norme(res2); - prodve (res, res2, c); - prosca (res, res2, &cosc); - sinc = sqrt (c[0] * c[0] + c[1] * c[1] + c[2] * c[2]); - angplan = myatan2 (sinc, cosc); - angplan = angle_02pi(angplan)*180./Pi; - if((angplan>70 && angplan<110) || - (angplan>260 && angplan<280)){ + prodve(res, res2, c); + prosca(res, res2, &cosc); + sinc = sqrt(c[0] * c[0] + c[1] * c[1] + c[2] * c[2]); + angplan = myatan2(sinc, cosc); + angplan = angle_02pi(angplan) * 180. / Pi; + if((angplan > 70 && angplan < 110) || (angplan > 260 && angplan < 280)) { Msg(INFO, "SVD failed (angle=%g): using rough algo...", angplan); - res[0]=res2[0]; - res[1]=res2[1]; - res[2]=res2[2]; + res[0] = res2[0]; + res[1] = res2[1]; + res[2] = res2[2]; goto end; } } - + ex[0] = ex[1] = ex[2] = 0.0; - if(res[0]==0.) + if(res[0] == 0.) ex[0] = 1.0; - else if(res[1]==0.) + else if(res[1] == 0.) ex[1] = 1.0; else ex[2] = 1.0; prodve(res, ex, t1); norme(t1); - prodve (t1, res, t2); + prodve(t1, res, t2); norme(t2); end: - res[3] = (xm*res[0]+ym*res[1]+zm*res[2]); + res[3] = (xm * res[0] + ym * res[1] + zm * res[2]); - for(i=0; i<3; i++) s->plan[0][i] = t1[i]; - for(i=0; i<3; i++) s->plan[1][i] = t2[i]; - for(i=0; i<3; i++) s->plan[2][i] = res[i]; + for(i = 0; i < 3; i++) + s->plan[0][i] = t1[i]; + for(i = 0; i < 3; i++) + s->plan[1][i] = t2[i]; + for(i = 0; i < 3; i++) + s->plan[2][i] = res[i]; s->a = res[0]; s->b = res[1]; @@ -189,36 +200,37 @@ end: s->d = res[3]; Msg(DEBUG1, "Surface: %d", s->Num); - Msg(DEBUG2, "SVD : %g,%g,%g (min=%d)", svd[0],svd[1],svd[2],min); + Msg(DEBUG2, "SVD : %g,%g,%g (min=%d)", svd[0], svd[1], svd[2], min); Msg(DEBUG2, "Plane : (%g x + %g y + %g z = %g)", s->a, s->b, s->c, s->d); Msg(DEBUG2, "Normal : (%g , %g , %g )", s->a, s->b, s->c); Msg(DEBUG3, "t1 : (%g , %g , %g )", t1[0], t1[1], t1[2]); Msg(DEBUG3, "t2 : (%g , %g , %g )", t2[0], t2[1], t2[2]); - for(i=0;i<3;i++){ - for(j=0;j<3;j++){ + for(i = 0; i < 3; i++) { + for(j = 0; j < 3; j++) { s->invplan[i][j] = s->plan[j][i]; } } //check coherence for plane surfaces - if(s->Typ==MSH_SURF_PLAN){ + if(s->Typ == MSH_SURF_PLAN) { Curve *c; - for(i=0;i<List_Nbr(s->Generatrices);i++) { - List_Read(s->Generatrices,i,&c); - if(c->Num>0){ - List_Read(s->Generatrices,i,&c); - for(j=0;j<List_Nbr(c->Control_Points);j++){ - List_Read(c->Control_Points,j,&v); - double d = s->a*v->Pos.X+s->b*v->Pos.Y+s->c*v->Pos.Z-s->d; - if(fabs(d)>CTX.lc*1.e-3){ - Msg(GERROR1, "Plane surface %d (%gx+%gy+%gz+%g=0) is not plane!", - s->Num, s->a, s->b, s->c, s->d); - Msg(GERROR3, "Control point %d = (%g,%g,%g), val=%g", - v->Num, v->Pos.X, v->Pos.Y, v->Pos.Z, d); - return; - } - } + for(i = 0; i < List_Nbr(s->Generatrices); i++) { + List_Read(s->Generatrices, i, &c); + if(c->Num > 0) { + List_Read(s->Generatrices, i, &c); + for(j = 0; j < List_Nbr(c->Control_Points); j++) { + List_Read(c->Control_Points, j, &v); + double d = + s->a * v->Pos.X + s->b * v->Pos.Y + s->c * v->Pos.Z - s->d; + if(fabs(d) > CTX.lc * 1.e-3) { + Msg(GERROR1, "Plane surface %d (%gx+%gy+%gz+%g=0) is not plane!", + s->Num, s->a, s->b, s->c, s->d); + Msg(GERROR3, "Control point %d = (%g,%g,%g), val=%g", + v->Num, v->Pos.X, v->Pos.Y, v->Pos.Z, d); + return; + } + } } } } @@ -229,27 +241,28 @@ end: #define Precision 1.e-10 #define MaxIter 50 -void find_bestuv (Surface * s, double X, double Y, - double *U, double *V, double *Z, int N){ - double d, mina, min=0., minu=0., minv=0., Unew, Vnew; +void find_bestuv(Surface * s, double X, double Y, + double *U, double *V, double *Z, int N) +{ + double d, mina, min = 0., minu = 0., minv = 0., Unew, Vnew; static int i, j; Vertex P; - d = 1. / (double) N; + d = 1. / (double)N; - for (i = 0; i <= N; i++){ - for (j = 0; j <= N; j++){ - Unew = ((double) i) * d; - Vnew = ((double) j) * d; - P = InterpolateSurface (s, Unew, Vnew, 0, 0); - if (!i && !j){ - min = myhypot (X - P.Pos.X, Y - P.Pos.Y); + for(i = 0; i <= N; i++) { + for(j = 0; j <= N; j++) { + Unew = ((double)i) * d; + Vnew = ((double)j) * d; + P = InterpolateSurface(s, Unew, Vnew, 0, 0); + if(!i && !j) { + min = myhypot(X - P.Pos.X, Y - P.Pos.Y); minu = Unew; minv = Vnew; *Z = P.Pos.Z; } - else{ - if ((mina = myhypot (X - P.Pos.X, Y - P.Pos.Y)) < min){ + else { + if((mina = myhypot(X - P.Pos.X, Y - P.Pos.Y)) < min) { min = mina; minu = Unew; minv = Vnew; @@ -262,14 +275,15 @@ void find_bestuv (Surface * s, double X, double Y, *V = minv; } -void invert_singular_matrix3x3(double _M[3][3], double _I[3][3]){ - int i, j, k, n = 3; +void invert_singular_matrix3x3(double _M[3][3], double _I[3][3]) +{ + int i, j, k, n = 3; double _T[3][3]; - for(i=1 ; i<=n ; i++){ - for(j=1 ; j<=n ; j++){ - _I[i-1][j-1] = 0.0 ; - _T[i-1][j-1] = 0.0 ; + for(i = 1; i <= n; i++) { + for(j = 1; j <= n; j++) { + _I[i - 1][j - 1] = 0.0; + _T[i - 1][j - 1] = 0.0; } } @@ -278,24 +292,25 @@ void invert_singular_matrix3x3(double _M[3][3], double _I[3][3]){ gsl_matrix *V = gsl_matrix_alloc(3, 3); gsl_vector *W = gsl_vector_alloc(3); gsl_vector *TMPVEC = gsl_vector_alloc(3); - for(i=1 ; i<=n ; i++){ - for(j=1 ; j<=n ; j++){ - gsl_matrix_set(M, i-1, j-1, _M[i-1][j-1]); + for(i = 1; i <= n; i++) { + for(j = 1; j <= n; j++) { + gsl_matrix_set(M, i - 1, j - 1, _M[i - 1][j - 1]); } } - gsl_linalg_SV_decomp(M,V,W,TMPVEC); - for(i=1 ; i<=n ; i++){ - for(j=1 ; j<=n ; j++){ - double ww = gsl_vector_get(W, i-1); - if(fabs(ww) > 1.e-16){ //singular value precision - _T[i-1][j-1] += gsl_matrix_get(M, j-1, i-1) / ww ; + gsl_linalg_SV_decomp(M, V, W, TMPVEC); + for(i = 1; i <= n; i++) { + for(j = 1; j <= n; j++) { + double ww = gsl_vector_get(W, i - 1); + if(fabs(ww) > 1.e-16) { //singular value precision + _T[i - 1][j - 1] += gsl_matrix_get(M, j - 1, i - 1) / ww; } } } - for(i=1 ; i<=n ; i++){ - for(j=1 ; j<=n ; j++){ - for(k=1 ; k<=n ; k++){ - _I[i-1][j-1] += gsl_matrix_get(V, i-1, k-1) * _T[k-1][j-1] ; + for(i = 1; i <= n; i++) { + for(j = 1; j <= n; j++) { + for(k = 1; k <= n; k++) { + _I[i - 1][j - 1] += + gsl_matrix_get(V, i - 1, k - 1) * _T[k - 1][j - 1]; } } } @@ -304,113 +319,116 @@ void invert_singular_matrix3x3(double _M[3][3], double _I[3][3]){ gsl_vector_free(W); gsl_vector_free(TMPVEC); #else - double **M = dmatrix(1,3,1,3); - double **V = dmatrix(1,3,1,3); - double *W = dvector(1,3); - for(i=1 ; i<=n ; i++){ - for(j=1 ; j<=n ; j++){ - M[i][j] = _M[i-1][j-1]; + double **M = dmatrix(1, 3, 1, 3); + double **V = dmatrix(1, 3, 1, 3); + double *W = dvector(1, 3); + for(i = 1; i <= n; i++) { + for(j = 1; j <= n; j++) { + M[i][j] = _M[i - 1][j - 1]; } - } + } dsvdcmp(M, n, n, W, V); - for(i=1 ; i<=n ; i++){ - for(j=1 ; j<=n ; j++){ - if(fabs(W[i]) > 1.e-16){ //singular value precision - _T[i-1][j-1] += M[j][i] / W[i] ; + for(i = 1; i <= n; i++) { + for(j = 1; j <= n; j++) { + if(fabs(W[i]) > 1.e-16) { //singular value precision + _T[i - 1][j - 1] += M[j][i] / W[i]; } } } - for(i=1 ; i<=n ; i++){ - for(j=1 ; j<=n ; j++){ - for(k=1 ; k<=n ; k++){ - _I[i-1][j-1] += V[i][k] * _T[k-1][j-1] ; + for(i = 1; i <= n; i++) { + for(j = 1; j <= n; j++) { + for(k = 1; k <= n; k++) { + _I[i - 1][j - 1] += V[i][k] * _T[k - 1][j - 1]; } } } - free_dmatrix(M,1,n,1,n); - free_dmatrix(V,1,n,1,n); - free_dvector(W,1,n); + free_dmatrix(M, 1, n, 1, n); + free_dmatrix(V, 1, n, 1, n); + free_dvector(W, 1, n); #endif } -void XYZtoUV (Surface *s, double X, double Y, double Z, double *U, double *V, - double relax) { - double Unew,Vnew,err; - int iter; - Vertex D_u,D_v,P; - double mat[3][3], jac[3][3] ; +void XYZtoUV(Surface * s, double X, double Y, double Z, double *U, double *V, + double relax) +{ + double Unew, Vnew, err; + int iter; + Vertex D_u, D_v, P; + double mat[3][3], jac[3][3]; double umin, umax, vmin, vmax; - if (s->Typ == MSH_SURF_NURBS){ + if(s->Typ == MSH_SURF_NURBS) { umin = s->ku[0]; umax = s->ku[s->OrderU + s->Nu]; vmin = s->kv[0]; vmax = s->kv[s->OrderV + s->Nv]; } - else{ + else { umin = vmin = 0.0; umax = vmax = 1.0; } *U = *V = 0.487; err = 1.0; - iter = 1; + iter = 1; - while ( err > Precision && iter < MaxIter ){ - P = InterpolateSurface(s, *U, *V, 0, 0); + while(err > Precision && iter < MaxIter) { + P = InterpolateSurface(s, *U, *V, 0, 0); D_u = InterpolateSurface(s, *U, *V, 1, 1); D_v = InterpolateSurface(s, *U, *V, 1, 2); - mat[0][0] = D_u.Pos.X; - mat[0][1] = D_u.Pos.Y; - mat[0][2] = D_u.Pos.Z; - mat[1][0] = D_v.Pos.X; - mat[1][1] = D_v.Pos.Y; - mat[1][2] = D_v.Pos.Z; - mat[2][0] = 0.; - mat[2][1] = 0.; - mat[2][2] = 0.; + mat[0][0] = D_u.Pos.X; + mat[0][1] = D_u.Pos.Y; + mat[0][2] = D_u.Pos.Z; + mat[1][0] = D_v.Pos.X; + mat[1][1] = D_v.Pos.Y; + mat[1][2] = D_v.Pos.Z; + mat[2][0] = 0.; + mat[2][1] = 0.; + mat[2][2] = 0.; invert_singular_matrix3x3(mat, jac); - Unew = *U + relax * - (jac[0][0]*(X-P.Pos.X) + jac[1][0]*(Y-P.Pos.Y) + jac[2][0]*(Z-P.Pos.Z)) ; - Vnew = *V + relax * - (jac[0][1]*(X-P.Pos.X) + jac[1][1]*(Y-P.Pos.Y) + jac[2][1]*(Z-P.Pos.Z)) ; + Unew = *U + relax * + (jac[0][0] * (X - P.Pos.X) + jac[1][0] * (Y - P.Pos.Y) + + jac[2][0] * (Z - P.Pos.Z)); + Vnew = + *V + relax * (jac[0][1] * (X - P.Pos.X) + jac[1][1] * (Y - P.Pos.Y) + + jac[2][1] * (Z - P.Pos.Z)); - err = DSQR(Unew - *U) + DSQR(Vnew - *V) ; + err = DSQR(Unew - *U) + DSQR(Vnew - *V); - iter++; + iter++; *U = Unew; *V = Vnew; } if(iter == MaxIter || - (Unew > umax || Vnew > vmax || Unew < umin || Vnew < vmin)){ + (Unew > umax || Vnew > vmax || Unew < umin || Vnew < vmin)) { if(relax < 1.e-12) Msg(GERROR, "Could not converge: surface mesh will be wrong"); - else{ - Msg(INFO, "Relaxation factor = %g", 0.75*relax); - XYZtoUV (s, X, Y, Z, U, V, 0.75*relax); + else { + Msg(INFO, "Relaxation factor = %g", 0.75 * relax); + XYZtoUV(s, X, Y, Z, U, V, 0.75 * relax); } } } -void XYtoUV (Surface * s, double *X, double *Y, - double *U, double *V, double *Z, double relax){ - - double det, Unew=0., Vnew=0., err, mat[2][2], jac[2][2]; +void XYtoUV(Surface * s, double *X, double *Y, + double *U, double *V, double *Z, double relax) +{ + double det, Unew = 0., Vnew = 0., err, mat[2][2], jac[2][2]; int iter; Vertex D_u, D_v, P; double umin, umax, vmin, vmax; - if (s->Typ == MSH_SURF_NURBS){ + if(s->Typ == MSH_SURF_NURBS) { umin = s->ku[0]; umax = s->ku[s->OrderU + s->Nu]; vmin = s->kv[0]; vmax = s->kv[s->OrderV + s->Nv]; } - else{ + else { umin = vmin = 0.0; umax = vmax = 1.0; } @@ -419,17 +437,17 @@ void XYtoUV (Surface * s, double *X, double *Y, err = 1.0; iter = 1; - while (err > Precision && iter < MaxIter){ - P = InterpolateSurface (s, *U, *V, 0, 0); - D_u = InterpolateSurface (s, *U, *V, 1, 1); - D_v = InterpolateSurface (s, *U, *V, 1, 2); + while(err > Precision && iter < MaxIter) { + P = InterpolateSurface(s, *U, *V, 0, 0); + D_u = InterpolateSurface(s, *U, *V, 1, 1); + D_v = InterpolateSurface(s, *U, *V, 1, 2); mat[0][0] = D_u.Pos.X; mat[0][1] = D_u.Pos.Y; mat[1][0] = D_v.Pos.X; mat[1][1] = D_v.Pos.Y; det = mat[0][0] * mat[1][1] - mat[0][1] * mat[1][0]; - - if (det == 0.0){ + + if(det == 0.0) { iter = MaxIter; break; } @@ -438,93 +456,101 @@ void XYtoUV (Surface * s, double *X, double *Y, jac[0][1] = -mat[0][1] / det; jac[1][0] = -mat[1][0] / det; jac[1][1] = mat[0][0] / det; - - Unew = *U + relax * (jac[0][0] * (*X - P.Pos.X) + jac[1][0] * (*Y - P.Pos.Y)); - Vnew = *V + relax * (jac[0][1] * (*X - P.Pos.X) + jac[1][1] * (*Y - P.Pos.Y)); - - err = DSQR (Unew - *U) + DSQR (Vnew - *V); - + + Unew = + *U + relax * (jac[0][0] * (*X - P.Pos.X) + jac[1][0] * (*Y - P.Pos.Y)); + Vnew = + *V + relax * (jac[0][1] * (*X - P.Pos.X) + jac[1][1] * (*Y - P.Pos.Y)); + + err = DSQR(Unew - *U) + DSQR(Vnew - *V); + iter++; *U = Unew; *V = Vnew; } - + *Z = P.Pos.Z; int thresh = Unew > umax || Vnew > vmax || Unew < umin || Vnew < vmin; - if(iter == MaxIter || thresh){ - if(relax < 1.e-6){ + if(iter == MaxIter || thresh) { + if(relax < 1.e-6) { Msg(GERROR, "Could not converge: surface mesh will probably be wrong"); - if(Unew > umax) *U = umax; - if(Vnew > vmax) *V = vmax; - if(Unew < umin) *U = umin; - if(Vnew < vmin) *V = vmin; - find_bestuv (s, *X, *Y, U, V, Z, 30); - P = InterpolateSurface (s, *U, *V, 0, 0); + if(Unew > umax) + *U = umax; + if(Vnew > vmax) + *V = vmax; + if(Unew < umin) + *U = umin; + if(Vnew < vmin) + *V = vmin; + find_bestuv(s, *X, *Y, U, V, Z, 30); + P = InterpolateSurface(s, *U, *V, 0, 0); *X = P.Pos.X; *Y = P.Pos.Y; *Z = P.Pos.Z; } - else{ - Msg(INFO, "Relaxation factor = %g", 0.75*relax); - XYtoUV (s, X, Y, U, V, Z, 0.75*relax); + else { + Msg(INFO, "Relaxation factor = %g", 0.75 * relax); + XYtoUV(s, X, Y, U, V, Z, 0.75 * relax); } } } -int Oriente (List_T * cu, double n[3]){ +int Oriente(List_T * cu, double n[3]) +{ int N, i, a, b, c; double cosa, sina, sum, v[3], w[3], u[3]; Vertex *ver[3]; - N = List_Nbr (cu); + N = List_Nbr(cu); sum = 0.0; - for (i = 0; i < N; i++){ - if (i == N - 1){ + for(i = 0; i < N; i++) { + if(i == N - 1) { a = N - 1; b = 1; c = 2; } - else if (i == N - 2){ + else if(i == N - 2) { a = N - 2; b = N - 1; c = 1; } - else{ + else { a = i; b = i + 1; c = i + 2; } - List_Read (cu, a, &ver[0]); - List_Read (cu, b, &ver[1]); - List_Read (cu, c, &ver[2]); - + List_Read(cu, a, &ver[0]); + List_Read(cu, b, &ver[1]); + List_Read(cu, c, &ver[2]); + u[0] = ver[1]->Pos.X - ver[0]->Pos.X; u[1] = ver[1]->Pos.Y - ver[0]->Pos.Y; u[2] = ver[1]->Pos.Z - ver[0]->Pos.Z; - + v[0] = ver[2]->Pos.X - ver[1]->Pos.X; v[1] = ver[2]->Pos.Y - ver[1]->Pos.Y; v[2] = ver[2]->Pos.Z - ver[1]->Pos.Z; - norme (u); - norme (v); - prodve (u, v, w); - prosca (w, n, &sina); - prosca (u, v, &cosa); - sum += myatan2 (sina, cosa); + norme(u); + norme(v); + prodve(u, v, w); + prosca(w, n, &sina); + prosca(u, v, &cosa); + sum += myatan2(sina, cosa); } - if (sum < 0) + if(sum < 0) return (1); else return (0); } -double angle_3p (Vertex * V, Vertex * P1, Vertex * P2){ +double angle_3p(Vertex * V, Vertex * P1, Vertex * P2) +{ double PA[3], PB[3], angplan; double cosc, sinc, c[3]; @@ -536,20 +562,21 @@ double angle_3p (Vertex * V, Vertex * P1, Vertex * P2){ PB[1] = P2->Pos.Y - V->Pos.Y; PB[2] = P2->Pos.Z - V->Pos.Z; - norme (PA); - norme (PB); + norme(PA); + norme(PB); - prodve (PA, PB, c); + prodve(PA, PB, c); - prosca (PA, PB, &cosc); - sinc = sqrt (c[0] * c[0] + c[1] * c[1] + c[2] * c[2]); + prosca(PA, PB, &cosc); + sinc = sqrt(c[0] * c[0] + c[1] * c[1] + c[2] * c[2]); - angplan = myatan2 (sinc, cosc); + angplan = myatan2(sinc, cosc); return angplan; } -double angle_plan (Vertex * V, Vertex * P1, Vertex * P2, double n[3]){ +double angle_plan(Vertex * V, Vertex * P1, Vertex * P2, double n[3]) +{ double PA[3], PB[3], angplan; double cosc, sinc, c[3]; @@ -561,70 +588,75 @@ double angle_plan (Vertex * V, Vertex * P1, Vertex * P2, double n[3]){ PB[1] = P2->Pos.Y - V->Pos.Y; PB[2] = P2->Pos.Z - V->Pos.Z; - norme (PA); - norme (PB); + norme(PA); + norme(PB); - prodve (PA, PB, c); + prodve(PA, PB, c); - prosca (PA, PB, &cosc); - prosca (c, n, &sinc); - angplan = myatan2 (sinc, cosc); + prosca(PA, PB, &cosc); + prosca(c, n, &sinc); + angplan = myatan2(sinc, cosc); return angplan; } -double angle_3pts (Vertex * a, Vertex * b, Vertex * c){ +double angle_3pts(Vertex * a, Vertex * b, Vertex * c) +{ double L, prosca, angle; - L = myhypot ((a->Pos.X - b->Pos.X), (a->Pos.Y - b->Pos.Y)) * - myhypot ((b->Pos.X - c->Pos.X), (b->Pos.Y - c->Pos.Y)); + L = myhypot((a->Pos.X - b->Pos.X), (a->Pos.Y - b->Pos.Y)) * + myhypot((b->Pos.X - c->Pos.X), (b->Pos.Y - c->Pos.Y)); prosca = ((a->Pos.X - b->Pos.X) * (c->Pos.X - b->Pos.X) + (a->Pos.Y - b->Pos.Y) * (c->Pos.Y - b->Pos.Y)) / L; - angle = acos (prosca) * 180. / Pi ; + angle = acos(prosca) * 180. / Pi; return (angle); } -double trapeze (IntPoint * P1, IntPoint * P2){ +double trapeze(IntPoint * P1, IntPoint * P2) +{ return (0.5 * (P1->lc + P2->lc) * (P2->t - P1->t)); } -void RecursiveIntegration (IntPoint * from, IntPoint * to, double (*f) (double X), - List_T * pPoints, double Prec, int *depth){ +void RecursiveIntegration(IntPoint * from, IntPoint * to, + double (*f) (double X), List_T * pPoints, + double Prec, int *depth) +{ IntPoint P, p1; double err, val1, val2, val3; (*depth)++; P.t = 0.5 * (from->t + to->t); - P.lc = f (P.t); + P.lc = f(P.t); - val1 = trapeze (from, to); - val2 = trapeze (from, &P); - val3 = trapeze (&P, to); + val1 = trapeze(from, to); + val2 = trapeze(from, &P); + val3 = trapeze(&P, to); - err = fabs (val1 - val2 - val3); + err = fabs(val1 - val2 - val3); // Msg(INFO,"Int %22.15 E %22.15 E %22.15 E\n", val1,val2,val3); - if (((err < Prec) && (*depth > 1)) || (*depth > 25)){ - List_Read (pPoints, List_Nbr (pPoints) - 1, &p1); + if(((err < Prec) && (*depth > 1)) || (*depth > 25)) { + List_Read(pPoints, List_Nbr(pPoints) - 1, &p1); P.p = p1.p + val2; - List_Add (pPoints, &P); - - List_Read (pPoints, List_Nbr (pPoints) - 1, &p1); + List_Add(pPoints, &P); + + List_Read(pPoints, List_Nbr(pPoints) - 1, &p1); to->p = p1.p + val3; - List_Add (pPoints, to); + List_Add(pPoints, to); } - else{ - RecursiveIntegration (from, &P, f, pPoints, Prec, depth); - RecursiveIntegration (&P, to, f, pPoints, Prec, depth); + else { + RecursiveIntegration(from, &P, f, pPoints, Prec, depth); + RecursiveIntegration(&P, to, f, pPoints, Prec, depth); } (*depth)--; } -double Integration (double t1, double t2, double (*f) (double X), - List_T * pPoints, double Prec){ +double Integration(double t1, double t2, double (*f) (double X), + List_T * pPoints, double Prec) +{ int depth; IntPoint from, to; @@ -633,12 +665,12 @@ double Integration (double t1, double t2, double (*f) (double X), from.t = t1; from.lc = f(from.t); from.p = 0.0; - List_Add (pPoints, &from); + List_Add(pPoints, &from); to.t = t2; to.lc = f(to.t); - RecursiveIntegration (&from, &to, f, pPoints, Prec, &depth); - - List_Read (pPoints, List_Nbr (pPoints) - 1, &to); + RecursiveIntegration(&from, &to, f, pPoints, Prec, &depth); + + List_Read(pPoints, List_Nbr(pPoints) - 1, &to); return (to.p); } diff --git a/Mesh/Vertex.cpp b/Mesh/Vertex.cpp index 51688411032028c825ec1525087b5bcf1a4a33f2..abb5128a3c6eeb46d7b54cb8ec4faab902806b9e 100644 --- a/Mesh/Vertex.cpp +++ b/Mesh/Vertex.cpp @@ -1,4 +1,4 @@ -// $Id: Vertex.cpp,v 1.20 2003-01-23 20:19:22 geuzaine Exp $ +// $Id: Vertex.cpp,v 1.21 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -25,12 +25,13 @@ #include "Mesh.h" #include "Context.h" -extern Context_T CTX ; -extern Mesh *THEM ; +extern Context_T CTX; +extern Mesh *THEM; -Vertex::Vertex (){ +Vertex::Vertex() +{ Frozen = 0; - Visible = VIS_GEOM|VIS_MESH; + Visible = VIS_GEOM | VIS_MESH; Pos.X = 0.0; Pos.Y = 0.0; Pos.Z = 0.0; @@ -41,9 +42,10 @@ Vertex::Vertex (){ Extruded_Points = NULL; } -Vertex::Vertex (double X, double Y, double Z, double l, double W){ +Vertex::Vertex(double X, double Y, double Z, double l, double W) +{ Frozen = 0; - Visible = VIS_GEOM|VIS_MESH; + Visible = VIS_GEOM | VIS_MESH; Pos.X = X; Pos.Y = Y; Pos.Z = Z; @@ -55,9 +57,10 @@ Vertex::Vertex (double X, double Y, double Z, double l, double W){ Extruded_Points = NULL; } -void Vertex::norme (){ - double d = sqrt (Pos.X * Pos.X + Pos.Y * Pos.Y + Pos.Z * Pos.Z); - if (d == 0.0) +void Vertex::norme() +{ + double d = sqrt(Pos.X * Pos.X + Pos.Y * Pos.Y + Pos.Z * Pos.Z); + if(d == 0.0) return; Pos.X /= d; Pos.Y /= d; @@ -65,78 +68,91 @@ void Vertex::norme (){ } -Vertex Vertex::operator + (const Vertex & other){ - return Vertex (Pos.X + other.Pos.X, Pos.Y + - other.Pos.Y, Pos.Z + other.Pos.Z, lc, w); +Vertex Vertex::operator +(const Vertex & other) +{ + return Vertex(Pos.X + other.Pos.X, Pos.Y + + other.Pos.Y, Pos.Z + other.Pos.Z, lc, w); } -Vertex Vertex::operator - (const Vertex & other){ - return Vertex (Pos.X - other.Pos.X, Pos.Y - - other.Pos.Y, Pos.Z - other.Pos.Z, lc, w); +Vertex Vertex::operator -(const Vertex & other) +{ + return Vertex(Pos.X - other.Pos.X, Pos.Y - + other.Pos.Y, Pos.Z - other.Pos.Z, lc, w); } -Vertex Vertex::operator / (double d){ - return Vertex (Pos.X / d, Pos.Y / d, Pos.Z / d, lc, w); +Vertex Vertex::operator /(double d) +{ + return Vertex(Pos.X / d, Pos.Y / d, Pos.Z / d, lc, w); } -Vertex Vertex::operator * (double d){ - return Vertex (Pos.X * d, Pos.Y * d, Pos.Z * d, lc, w); + +Vertex Vertex::operator *(double d) +{ + return Vertex(Pos.X * d, Pos.Y * d, Pos.Z * d, lc, w); } -Vertex Vertex::operator % (Vertex & autre){ // cross product - return Vertex (Pos.Y * autre.Pos.Z - Pos.Z * autre.Pos.Y, - -(Pos.X * autre.Pos.Z - Pos.Z * autre.Pos.X), - Pos.X * autre.Pos.Y - Pos.Y * autre.Pos.X, lc, w); +Vertex Vertex::operator %(Vertex & autre) +{ // cross product + return Vertex(Pos.Y * autre.Pos.Z - Pos.Z * autre.Pos.Y, + -(Pos.X * autre.Pos.Z - Pos.Z * autre.Pos.X), + Pos.X * autre.Pos.Y - Pos.Y * autre.Pos.X, lc, w); } -double Vertex::operator * (const Vertex & other){ +double Vertex::operator *(const Vertex & other) +{ return Pos.X * other.Pos.X + Pos.Y * other.Pos.Y + Pos.Z * other.Pos.Z; } -Vertex *Create_Vertex (int Num, double X, double Y, double Z, double lc, double u){ +Vertex *Create_Vertex(int Num, double X, double Y, double Z, double lc, + double u) +{ Vertex *pV; - pV = new Vertex (X, Y, Z, lc); + pV = new Vertex(X, Y, Z, lc); pV->w = 1.0; pV->Num = Num; - THEM->MaxPointNum = IMAX(THEM->MaxPointNum,Num); + THEM->MaxPointNum = IMAX(THEM->MaxPointNum, Num); pV->u = u; return pV; } -void Delete_Vertex ( Vertex *pV ){ - if(pV){ +void Delete_Vertex(Vertex * pV) +{ + if(pV) { List_Delete(pV->ListSurf); List_Delete(pV->ListCurves); - if(CTX.mesh.oldxtrude){//old automatic extrusion algorithm + if(CTX.mesh.oldxtrude) { //old automatic extrusion algorithm List_Delete(pV->Extruded_Points); } - else{ + else { Free_ExtrudedPoints(pV->Extruded_Points); } delete pV; } } -void Free_Vertex (void *a, void *b){ - Vertex *v = *(Vertex**)a; - if(v){ +void Free_Vertex(void *a, void *b) +{ + Vertex *v = *(Vertex **) a; + if(v) { Delete_Vertex(v); v = NULL; } } -int compareVertex (const void *a, const void *b){ +int compareVertex(const void *a, const void *b) +{ int i, j; Vertex **q, **w; q = (Vertex **) a; w = (Vertex **) b; - i = abs ((*q)->Num); - j = abs ((*w)->Num); + i = abs((*q)->Num); + j = abs((*w)->Num); return (i - j); } -int comparePosition (const void *a, const void *b){ +int comparePosition(const void *a, const void *b) +{ int i, j; Vertex **q, **w; // TOLERANCE ! WARNING WARNING @@ -147,26 +163,26 @@ int comparePosition (const void *a, const void *b){ i = ((*q)->Num); j = ((*w)->Num); - if ((*q)->Pos.X - (*w)->Pos.X > eps) + if((*q)->Pos.X - (*w)->Pos.X > eps) return (1); - if ((*q)->Pos.X - (*w)->Pos.X < -eps) + if((*q)->Pos.X - (*w)->Pos.X < -eps) return (-1); - if ((*q)->Pos.Y - (*w)->Pos.Y > eps) + if((*q)->Pos.Y - (*w)->Pos.Y > eps) return (1); - if ((*q)->Pos.Y - (*w)->Pos.Y < -eps) + if((*q)->Pos.Y - (*w)->Pos.Y < -eps) return (-1); - if ((*q)->Pos.Z - (*w)->Pos.Z > eps) + if((*q)->Pos.Z - (*w)->Pos.Z > eps) return (1); - if ((*q)->Pos.Z - (*w)->Pos.Z < -eps) + if((*q)->Pos.Z - (*w)->Pos.Z < -eps) return (-1); - if (i != j){ + if(i != j) { /* - *w = *q; - printf("Les points %d et %d sont a la meme position\n",i,j); - printf("%12.5E %12.5E %12.5E\n",(*w)->Pos.X,(*w)->Pos.Y,(*w)->Pos.Z); - printf("%12.5E %12.5E %12.5E\n",(*q)->Pos.X,(*q)->Pos.Y,(*q)->Pos.Z); - */ + *w = *q; + printf("Les points %d et %d sont a la meme position\n",i,j); + printf("%12.5E %12.5E %12.5E\n",(*w)->Pos.X,(*w)->Pos.Y,(*w)->Pos.Z); + printf("%12.5E %12.5E %12.5E\n",(*q)->Pos.X,(*q)->Pos.Y,(*q)->Pos.Z); + */ } return 0; diff --git a/Numeric/Numeric.cpp b/Numeric/Numeric.cpp index 6c81749e02fe59e3bc8e4cc3831cd1cf1b283713..ccf7aacb17741d73527515783eb53c59c4439b17 100644 --- a/Numeric/Numeric.cpp +++ b/Numeric/Numeric.cpp @@ -1,4 +1,4 @@ -// $Id: Numeric.cpp,v 1.6 2003-02-18 21:19:13 geuzaine Exp $ +// $Id: Numeric.cpp,v 1.7 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -26,85 +26,102 @@ #include "Numeric.h" // Check GSL version. We need at least 1.2, since all versions >= -// 1.1.1 have a buggy SVD routine (caused an infinite loop--fixed on -// Sun Jun 16 11:45:29 2002 in GSL's cvs tree). We check this at run -// time since Gmsh could be distributed with the gsl could be -// dynamically linked. +// 1.1.1 have a buggy SVD routine (infinite loop fixed on Sun Jun 16 +// 11:45:29 2002 in GSL's cvs tree). We check this at run time since +// Gmsh could be distributed with the gsl dynamically linked. #if defined(HAVE_GSL) + #include <gsl/gsl_version.h> #include <gsl/gsl_errno.h> -void new_handler(const char * reason, const char * file, int line, int gsl_errno){ +void new_handler(const char *reason, const char *file, int line, + int gsl_errno) +{ Msg(GERROR, "GSL: %s (%s, line %d)", reason, file, line); } -int check_gsl(){ +int check_gsl() +{ // check version int major, minor; sscanf(gsl_version, "%d.%d", &major, &minor); - if(major < 1 || (major == 1 && minor < 2)){ - Msg(FATAL1, "Your GSL version (%d.%d.X) has a bug in the singular value", major, minor); - Msg(FATAL3, "decomposition code. Please upgrade to version 1.2 or above."); + if(major < 1 || (major == 1 && minor < 2)) { + Msg(FATAL1, "Your GSL version (%d.%d.X) has a bug in the singular value", + major, minor); + Msg(FATAL3, + "decomposition code. Please upgrade to version 1.2 or above."); return 0; } // set new error handler gsl_set_error_handler(&new_handler); return 1; } + #else -int check_gsl(){ +int check_gsl() +{ return 1; } #endif -// How ? GSL_VERSION is a string "maj.min" or "maj.min.patch" - -double myatan2 (double a, double b){ - if (a == 0.0 && b == 0) +double myatan2(double a, double b) +{ + if(a == 0.0 && b == 0) return 0.0; - return atan2 (a, b); + return atan2(a, b); } -double myasin(double a){ - if(a<=-1.) return -Pi/2.; - else if(a>=1.) return Pi/2.; - else return asin(a); +double myasin(double a) +{ + if(a <= -1.) + return -Pi / 2.; + else if(a >= 1.) + return Pi / 2.; + else + return asin(a); } -void prodve (double a[3], double b[3], double c[3]){ +void prodve(double a[3], double b[3], double c[3]) +{ c[2] = a[0] * b[1] - a[1] * b[0]; c[1] = -a[0] * b[2] + a[2] * b[0]; c[0] = a[1] * b[2] - a[2] * b[1]; } -void prosca (double a[3], double b[3], double *c){ +void prosca(double a[3], double b[3], double *c) +{ *c = a[0] * b[0] + a[1] * b[1] + a[2] * b[2]; } -void norme (double a[3]){ +void norme(double a[3]) +{ double mod; - mod = sqrt (a[0] * a[0] + a[1] * a[1] + a[2] * a[2]); - if (mod == 0.0) + mod = sqrt(a[0] * a[0] + a[1] * a[1] + a[2] * a[2]); + if(mod == 0.0) return; a[0] /= mod; a[1] /= mod; a[2] /= mod; } -int sys2x2 (double mat[2][2], double b[2], double res[2]){ +int sys2x2(double mat[2][2], double b[2], double res[2]) +{ double det, ud, norm; int i; - norm = DSQR (mat[0][0]) + DSQR (mat[1][1]) + DSQR (mat[0][1]) + DSQR (mat[1][0]); + norm = + DSQR(mat[0][0]) + DSQR(mat[1][1]) + DSQR(mat[0][1]) + DSQR(mat[1][0]); det = mat[0][0] * mat[1][1] - mat[1][0] * mat[0][1]; // TOLERANCE ! WARNING WARNING - if (norm == 0.0 || fabs (det) / norm < 1.e-12){ - if(norm) Msg(DEBUG, "Assuming 2x2 matrix is singular (det/norm == %g)", fabs(det)/norm); - res[0] = res[1] = 0.0 ; + if(norm == 0.0 || fabs(det) / norm < 1.e-12) { + if(norm) + Msg(DEBUG, "Assuming 2x2 matrix is singular (det/norm == %g)", + fabs(det) / norm); + res[0] = res[1] = 0.0; return 0; } ud = 1. / det; @@ -112,12 +129,13 @@ int sys2x2 (double mat[2][2], double b[2], double res[2]){ res[0] = b[0] * mat[1][1] - mat[0][1] * b[1]; res[1] = mat[0][0] * b[1] - mat[1][0] * b[0]; - for (i = 0; i < 2; i++) + for(i = 0; i < 2; i++) res[i] *= ud; return (1); } -int sys3x3 (double mat[3][3], double b[3], double res[3], double *det){ +int sys3x3(double mat[3][3], double b[3], double res[3], double *det) +{ double ud; int i; @@ -125,8 +143,8 @@ int sys3x3 (double mat[3][3], double b[3], double res[3], double *det){ mat[0][1] * (mat[1][0] * mat[2][2] - mat[1][2] * mat[2][0]) + mat[0][2] * (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0]); - if (*det == 0.0){ - res[0] = res[1] = res[2] = 0.0 ; + if(*det == 0.0) { + res[0] = res[1] = res[2] = 0.0; return (0); } @@ -144,47 +162,52 @@ int sys3x3 (double mat[3][3], double b[3], double res[3], double *det){ mat[0][1] * (mat[1][0] * b[2] - b[1] * mat[2][0]) + b[0] * (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0]); - for (i = 0; i < 3; i++) + for(i = 0; i < 3; i++) res[i] *= ud; return (1); } -int sys3x3_with_tol (double mat[3][3], double b[3], double res[3], double *det){ +int sys3x3_with_tol(double mat[3][3], double b[3], double res[3], double *det) +{ int out; double norm; - out = sys3x3(mat,b,res,det); - norm = - DSQR (mat[0][0]) + DSQR (mat[0][1]) + DSQR (mat[0][2]) + - DSQR (mat[1][0]) + DSQR (mat[1][1]) + DSQR (mat[1][2]) + - DSQR (mat[2][0]) + DSQR (mat[2][1]) + DSQR (mat[2][2]) ; + out = sys3x3(mat, b, res, det); + norm = + DSQR(mat[0][0]) + DSQR(mat[0][1]) + DSQR(mat[0][2]) + + DSQR(mat[1][0]) + DSQR(mat[1][1]) + DSQR(mat[1][2]) + + DSQR(mat[2][0]) + DSQR(mat[2][1]) + DSQR(mat[2][2]); // TOLERANCE ! WARNING WARNING - if (norm == 0.0 || fabs (*det) / norm < 1.e-12){ - if(norm) Msg(DEBUG, "Assuming 3x3 matrix is singular (det/norm == %g)", fabs(*det)/norm); - res[0] = res[1] = res[2] = 0.0 ; + if(norm == 0.0 || fabs(*det) / norm < 1.e-12) { + if(norm) + Msg(DEBUG, "Assuming 3x3 matrix is singular (det/norm == %g)", + fabs(*det) / norm); + res[0] = res[1] = res[2] = 0.0; return 0; } - return out ; + return out; } -int det3x3 (double mat[3][3], double *det){ +int det3x3(double mat[3][3], double *det) +{ *det = mat[0][0] * (mat[1][1] * mat[2][2] - mat[1][2] * mat[2][1]) - mat[0][1] * (mat[1][0] * mat[2][2] - mat[1][2] * mat[2][0]) + mat[0][2] * (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0]); return 1; } -int inv3x3 (double mat[3][3], double inv[3][3], double *det){ +int inv3x3(double mat[3][3], double inv[3][3], double *det) +{ double ud; *det = mat[0][0] * (mat[1][1] * mat[2][2] - mat[1][2] * mat[2][1]) - mat[0][1] * (mat[1][0] * mat[2][2] - mat[1][2] * mat[2][0]) + mat[0][2] * (mat[1][0] * mat[2][1] - mat[1][1] * mat[2][0]); - if (*det == 0.0) + if(*det == 0.0) return (0); ud = 1. / (*det); @@ -202,10 +225,11 @@ int inv3x3 (double mat[3][3], double inv[3][3], double *det){ } -double angle_02pi (double A3){ +double angle_02pi(double A3) +{ double DP = 2 * Pi; - while (A3 > DP || A3 < 0.){ - if (A3 > 0) + while(A3 > DP || A3 < 0.) { + if(A3 > 0) A3 -= DP; else A3 += DP; @@ -213,40 +237,42 @@ double angle_02pi (double A3){ return A3; } -double InterpolateIso(double *X, double *Y, double *Z, - double *Val, double V, int I1, int I2, - double *XI, double *YI ,double *ZI){ - if(Val[I1] == Val[I2]){ - *XI = X[I1]; - *YI = Y[I1]; - *ZI = Z[I1]; +double InterpolateIso(double *X, double *Y, double *Z, + double *Val, double V, int I1, int I2, + double *XI, double *YI, double *ZI) +{ + if(Val[I1] == Val[I2]) { + *XI = X[I1]; + *YI = Y[I1]; + *ZI = Z[I1]; return 0; } - else{ - double coef = (V - Val[I1])/(Val[I2]-Val[I1]); - *XI= coef*(X[I2]-X[I1]) + X[I1]; - *YI= coef*(Y[I2]-Y[I1]) + Y[I1]; - *ZI= coef*(Z[I2]-Z[I1]) + Z[I1]; + else { + double coef = (V - Val[I1]) / (Val[I2] - Val[I1]); + *XI = coef * (X[I2] - X[I1]) + X[I1]; + *YI = coef * (Y[I2] - Y[I1]) + Y[I1]; + *ZI = coef * (Z[I2] - Z[I1]) + Z[I1]; return coef; } } -void gradSimplex (double *x, double *y, double *z, double *v, double *grad){ +void gradSimplex(double *x, double *y, double *z, double *v, double *grad) +{ // p = p1 * (1-u-v-w) + p2 u + p3 v + p4 w double mat[3][3]; - double det,b[3]; - mat[0][0] = x[1]-x[0]; - mat[1][0] = x[2]-x[0]; - mat[2][0] = x[3]-x[0]; - mat[0][1] = y[1]-y[0]; - mat[1][1] = y[2]-y[0]; - mat[2][1] = y[3]-y[0]; - mat[0][2] = z[1]-z[0]; - mat[1][2] = z[2]-z[0]; - mat[2][2] = z[3]-z[0]; - b[0] = v[1]-v[0]; - b[1] = v[2]-v[0]; - b[2] = v[3]-v[0]; - sys3x3 (mat, b, grad, &det); + double det, b[3]; + mat[0][0] = x[1] - x[0]; + mat[1][0] = x[2] - x[0]; + mat[2][0] = x[3] - x[0]; + mat[0][1] = y[1] - y[0]; + mat[1][1] = y[2] - y[0]; + mat[2][1] = y[3] - y[0]; + mat[0][2] = z[1] - z[0]; + mat[1][2] = z[2] - z[0]; + mat[2][2] = z[3] - z[0]; + b[0] = v[1] - v[0]; + b[1] = v[2] - v[0]; + b[2] = v[3] - v[0]; + sys3x3(mat, b, grad, &det); } diff --git a/Numeric/gsl_brent.cpp b/Numeric/gsl_brent.cpp index 860613a547ec4c4d41f2552567277c6a8b7985e3..88be04b65edf5bcc47fac64b2ecf59c0acb556af 100644 --- a/Numeric/gsl_brent.cpp +++ b/Numeric/gsl_brent.cpp @@ -1,4 +1,4 @@ -// $Id: gsl_brent.cpp,v 1.4 2003-03-01 22:22:27 geuzaine Exp $ +// $Id: gsl_brent.cpp,v 1.5 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -28,10 +28,10 @@ #include <gsl/gsl_math.h> #include <gsl/gsl_min.h> -static double (*nrfunc)(double); - -double fn1 (double x, void * params){ +static double (*nrfunc) (double); +double fn1(double x, void *params) +{ double val = nrfunc(x); return val; } @@ -41,45 +41,47 @@ double fn1 (double x, void * params){ // Returns the minimum betwen ax and bx to a given tol using brent's // method. -double brent(double ax, double bx, double cx, - double (*f)(double), double tol, double *xmin){ +double brent(double ax, double bx, double cx, + double (*f) (double), double tol, double *xmin) +{ int status; int iter = 0; - double a, b, c; // a < b < c + double a, b, c; // a < b < c const gsl_min_fminimizer_type *T; gsl_min_fminimizer *s; gsl_function F; // gsl wants a<b b = bx; - if(ax < cx){ + if(ax < cx) { a = ax; c = cx; } - else{ + else { a = ax; c = cx; } // if a-b < tol, return func(a) - if(fabs(c-a) < tol){ + if(fabs(c - a) < tol) { *xmin = ax; - return(f(*xmin)); + return (f(*xmin)); } - + nrfunc = f; - + F.function = &fn1; F.params = 0; - + T = gsl_min_fminimizer_brent; s = gsl_min_fminimizer_alloc(T); gsl_min_fminimizer_set(s, &F, b, a, c); - - do{ + + do { iter++; status = gsl_min_fminimizer_iterate(s); - if(status) break; // solver problem + if(status) + break; // solver problem b = gsl_min_fminimizer_x_minimum(s); a = gsl_min_fminimizer_x_lower(s); c = gsl_min_fminimizer_x_upper(s); @@ -88,10 +90,10 @@ double brent(double ax, double bx, double cx, while(status == GSL_CONTINUE && iter < MAXITER); if(status != GSL_SUCCESS) - Msg(GERROR, "MIN1D not converged: f(%g) = %g",b,fn1(b,NULL)); + Msg(GERROR, "MIN1D not converged: f(%g) = %g", b, fn1(b, NULL)); *xmin = b; - gsl_min_fminimizer_free (s); + gsl_min_fminimizer_free(s); return fn1(b, NULL); } @@ -106,63 +108,82 @@ double brent(double ax, double bx, double cx, #define MYLIMIT_ 100.0 #define MYTINY_ 1.0e-20 -void mnbrak(double *ax, double *bx, double *cx, double *fa, double *fb, double *fc, - double (*func)(double)) +void mnbrak(double *ax, double *bx, double *cx, double *fa, double *fb, + double *fc, double (*func) (double)) { - double ulim,u,r,q,fu; + double ulim, u, r, q, fu; //Msg(INFO, "--MNBRAK1 : ax %12.5E bx = %12.5E",*ax,*bx); - *fa=(*func)(*ax); - *fb=(*func)(*bx); - if (*fb > *fa) { + *fa = (*func) (*ax); + *fb = (*func) (*bx); + if(*fb > *fa) { double tmp; - tmp = *ax; *ax = *bx; *bx = tmp; - tmp = *fb; *fb = *fa; *fa = tmp; + tmp = *ax; + *ax = *bx; + *bx = tmp; + tmp = *fb; + *fb = *fa; + *fa = tmp; } //Msg(INFO, "--MNBRAK2 : ax %12.5E bx = %12.5E",*ax,*bx); - *cx = *bx + MYGOLD_*(*bx-*ax); - *fc = (*func)(*cx); - while (*fb > *fc) { - r=(*bx-*ax)*(*fb-*fc); - q=(*bx-*cx)*(*fb-*fa); - u=(*bx)-((*bx-*cx)*q-(*bx-*ax)*r)/(2.0*SIGN(MAX(fabs(q-r),MYTINY_),q-r)); + *cx = *bx + MYGOLD_ * (*bx - *ax); + *fc = (*func) (*cx); + while(*fb > *fc) { + r = (*bx - *ax) * (*fb - *fc); + q = (*bx - *cx) * (*fb - *fa); + u = + (*bx) - ((*bx - *cx) * q - + (*bx - *ax) * r) / (2.0 * SIGN(MAX(fabs(q - r), MYTINY_), + q - r)); //Msg(INFO, "--MNBRAK : %12.5E %12.5E %12.5E %12.5E %12.5E",*ax,*fa,*fb,*fc,u); - ulim = *bx + MYLIMIT_*(*cx-*bx); - if ((*bx-u)*(u-*cx) > 0.0) { - fu=(*func)(u); - if (fu < *fc) { - *ax = *bx; - *bx = u; - *fa = *fb; - *fb = fu; - return; - } else if (fu > *fb) { - *cx = u; - *fc = fu; - return; + ulim = *bx + MYLIMIT_ * (*cx - *bx); + if((*bx - u) * (u - *cx) > 0.0) { + fu = (*func) (u); + if(fu < *fc) { + *ax = *bx; + *bx = u; + *fa = *fb; + *fb = fu; + return; + } + else if(fu > *fb) { + *cx = u; + *fc = fu; + return; } - u = *cx + MYGOLD_*(*cx-*bx); - fu = (*func)(u); - } else if ((*cx-u)*(u-ulim) > 0.0) { - fu=(*func)(u); - if (fu < *fc) { - *bx = *cx; *cx = u; u = *cx + MYGOLD_*(*cx-*bx); - *fb = *fc; *fc = fu; fu = (*func)(u); + u = *cx + MYGOLD_ * (*cx - *bx); + fu = (*func) (u); + } + else if((*cx - u) * (u - ulim) > 0.0) { + fu = (*func) (u); + if(fu < *fc) { + *bx = *cx; + *cx = u; + u = *cx + MYGOLD_ * (*cx - *bx); + *fb = *fc; + *fc = fu; + fu = (*func) (u); } - } else if ((u-ulim)*(ulim-*cx) >= 0.0) { + } + else if((u - ulim) * (ulim - *cx) >= 0.0) { u = ulim; - fu = (*func)(u); - } else { - u = *cx + MYGOLD_*(*cx-*bx); - fu = (*func)(u); + fu = (*func) (u); + } + else { + u = *cx + MYGOLD_ * (*cx - *bx); + fu = (*func) (u); } - *ax = *bx; *bx = *cx; *cx = u; - *fa = *fb; *fb = *fc; *fc = fu; + *ax = *bx; + *bx = *cx; + *cx = u; + *fa = *fb; + *fb = *fc; + *fc = fu; //Msg(INFO, "MNBRAK : %12.5E %12.5E %12.5E",*ax,*bx,*cx); } diff --git a/Numeric/gsl_newt.cpp b/Numeric/gsl_newt.cpp index 74e9218c0d617ecc4879f0d8fd6b7c8b9647c619..a94a3f004bc1d50055a3fd34eb710b0d9b8973aa 100644 --- a/Numeric/gsl_newt.cpp +++ b/Numeric/gsl_newt.cpp @@ -1,4 +1,4 @@ -// $Id: gsl_newt.cpp,v 1.7 2003-02-25 04:02:52 geuzaine Exp $ +// $Id: gsl_newt.cpp,v 1.8 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -37,76 +37,85 @@ #define MAXITER 10000 #define PREC 1.e-8 -int nrdim; +int nrdim; double nru[MAX_DIM_NEWT], nrv[MAX_DIM_NEWT]; -static void (*nrfunc)(int n, double x[],double y[]); +static void (*nrfunc) (int n, double x[], double y[]); struct gsl_dummy{;}; -void convert_vector_from_gsl(const gsl_vector *gv, double * v){ +void convert_vector_from_gsl(const gsl_vector * gv, double *v) +{ int i, m; - m=gv->size; - for (i=0;i<m;i++){ - v[i+1]=gsl_vector_get(gv,i); + m = gv->size; + for(i = 0; i < m; i++) { + v[i + 1] = gsl_vector_get(gv, i); } } -void convert_vector_to_gsl(double *v, int n, gsl_vector *gv){ +void convert_vector_to_gsl(double *v, int n, gsl_vector * gv) +{ int i; - for (i=0;i<n;i++){ - gsl_vector_set (gv, i, v[i+1]); + for(i = 0; i < n; i++) { + gsl_vector_set(gv, i, v[i + 1]); } } -int gslfunc(const gsl_vector *xx, void *params, gsl_vector *f){ - convert_vector_from_gsl(xx,nru); - (*nrfunc)(nrdim,nru,nrv); +int gslfunc(const gsl_vector * xx, void *params, gsl_vector * f) +{ + convert_vector_from_gsl(xx, nru); + (*nrfunc) (nrdim, nru, nrv); // Msg(INFO, "f(%lf,%lf) = %lf %lf\n",nru[1],nru[2],nrv[1],nrv[2]); - convert_vector_to_gsl(nrv,nrdim,f); + convert_vector_to_gsl(nrv, nrdim, f); return GSL_SUCCESS; } // Warning: for compatibility with the old newt from NR, x[] and the // arguments of func() are indexed from 1 to n... -void newt(double x[], int n, int *check, void (*func)(int, double [],double [])){ +void newt(double x[], int n, int *check, + void (*func) (int, double[], double[])) +{ const gsl_multiroot_fsolver_type *T; gsl_multiroot_fsolver *s; int status; size_t iter = 0; - struct gsl_dummy p = {}; - gsl_multiroot_function f = {&gslfunc, n, &p}; - gsl_vector *xx = gsl_vector_alloc (n); + struct gsl_dummy p = { }; + gsl_multiroot_function f = { &gslfunc, n, &p }; + gsl_vector *xx = gsl_vector_alloc(n); - if(n > MAX_DIM_NEWT-1) Msg(FATAL, "Maximum Newton dimension exceeded\n"); + if(n > MAX_DIM_NEWT - 1) + Msg(FATAL, "Maximum Newton dimension exceeded\n"); nrdim = n; nrfunc = func; - convert_vector_to_gsl(x,n,xx); + convert_vector_to_gsl(x, n, xx); T = gsl_multiroot_fsolver_hybrid; s = gsl_multiroot_fsolver_alloc(T, 2); gsl_multiroot_fsolver_set(s, &f, xx); - do{ + do { iter++; status = gsl_multiroot_fsolver_iterate(s); - // Msg(INFO, "status %d %d %d %lf %lf\n",status,n,iter,gsl_vector_get(s->x,0),gsl_vector_get(s->x,1)); - if(status) break; // solver problem - status = gsl_multiroot_test_residual(s->f, n*PREC); + // Msg(INFO, "status %d %d %d %lf %lf\n", + // status,n,iter,gsl_vector_get(s->x,0),gsl_vector_get(s->x,1)); + if(status) + break; // solver problem + status = gsl_multiroot_test_residual(s->f, n * PREC); } while(status == GSL_CONTINUE && iter < MAXITER); - if (status == GSL_CONTINUE){ - *check=1; // problem !!! + if(status == GSL_CONTINUE) { + *check = 1; // problem !!! } - else{ - // Msg(INFO, "status %d %d %d %lf %lf\n",status,n,iter,gsl_vector_get(s->x,0),gsl_vector_get(s->x,1)); - convert_vector_from_gsl(s->x,x); - *check=0; // converged + else { + // Msg(INFO, "status %d %d %d %lf %lf\n", + // status,n,iter,gsl_vector_get(s->x,0),gsl_vector_get(s->x,1)); + convert_vector_from_gsl(s->x, x); + *check = 0; // converged } gsl_multiroot_fsolver_free(s); - gsl_vector_free(xx); + gsl_vector_free(xx); } #endif diff --git a/Parallel/ParUtil.cpp b/Parallel/ParUtil.cpp index ca63c89784a6a201943284dd6b77a530670dbe03..1c580c23d6e840fcffe5ff45c0813adf8e8eab26 100644 --- a/Parallel/ParUtil.cpp +++ b/Parallel/ParUtil.cpp @@ -1,4 +1,4 @@ -// $Id: ParUtil.cpp,v 1.5 2003-01-23 20:19:23 geuzaine Exp $ +// $Id: ParUtil.cpp,v 1.6 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -29,25 +29,26 @@ #include <sys/time.h> #endif -ParUtil* ParUtil::Instance() +ParUtil *ParUtil::Instance() { - if(!instance) - { - instance = new ParUtil; - } + if(!instance) { + instance = new ParUtil; + } return instance; } -ParUtil::~ParUtil() +ParUtil::~ParUtil() { + ; } -ParUtil::ParUtil() +ParUtil::ParUtil() { + ; } -void ParUtil::init(int &argc, char **&argv) { - +void ParUtil::init(int &argc, char **&argv) +{ #ifdef PARALLEL int namelen; char name[1024]; @@ -55,39 +56,38 @@ void ParUtil::init(int &argc, char **&argv) { MPI_Comm_rank(MPI_COMM_WORLD, &myrank); MPI_Comm_size(MPI_COMM_WORLD, &mysize); - - MPI_Errhandler_set(MPI_COMM_WORLD,MPI_ERRORS_RETURN); - MPI_Get_processor_name(name,&namelen); - procName = new char[namelen+1]; - strcpy(procName,name); + + MPI_Errhandler_set(MPI_COMM_WORLD, MPI_ERRORS_RETURN); + MPI_Get_processor_name(name, &namelen); + procName = new char[namelen + 1]; + strcpy(procName, name); #endif } double ParUtil::wTime() const { - #ifdef PARALLEL - return MPI_Wtime(); + return MPI_Wtime(); #else struct timeval tp; struct timezone tzp; double timeval; - - gettimeofday(&tp,&tzp); - - timeval = (double) tp.tv_sec; - timeval = timeval + (double) ((double) .000001 * (double) tp.tv_usec); - - return(timeval); + + gettimeofday(&tp, &tzp); + + timeval = (double)tp.tv_sec; + timeval = timeval + (double)((double).000001 * (double)tp.tv_usec); + + return (timeval); #endif } void ParUtil::processorName(char *name) const { #ifdef PARALLEL - strcpy(name,procName); + strcpy(name, procName); #else - strcpy(name,"localhost"); + strcpy(name, "localhost"); #endif } @@ -116,5 +116,4 @@ void ParUtil::Barrier(int line, const char *fn) #endif } -ParUtil* ParUtil::instance = 0; - +ParUtil *ParUtil::instance = 0; diff --git a/Parser/FunctionManager.cpp b/Parser/FunctionManager.cpp index b11d20da4fcf4881f82fac4fcd232ce09b4df81e..89e06330c95c4da28ec510da9677f59aa8d2bcc3 100644 --- a/Parser/FunctionManager.cpp +++ b/Parser/FunctionManager.cpp @@ -1,4 +1,4 @@ -// $Id: FunctionManager.cpp,v 1.17 2003-01-23 20:19:23 geuzaine Exp $ +// $Id: FunctionManager.cpp,v 1.18 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -28,19 +28,18 @@ using namespace std; struct ltstr { - bool operator()(const char* s1, const char* s2) const + bool operator() (const char *s1, const char *s2)const { return strcmp(s1, s2) < 0; } }; -class File_Position +class File_Position { - public : - int lineno; - fpos_t position; - FILE *file; - char filename[256]; + public:int lineno; + fpos_t position; + FILE *file; + char filename[256]; }; // Pour utiliser un namespace global sur SGI, il faut compiler avec @@ -50,12 +49,12 @@ class File_Position class mystack { public: - stack<File_Position> s; + stack < File_Position > s; }; + class mymap { -public : - map<char*,File_Position,ltstr> m; + public: map < char *, File_Position, ltstr > m; }; FunctionManager *FunctionManager::instance = 0; @@ -66,56 +65,55 @@ FunctionManager::FunctionManager() calls = new mystack; } -FunctionManager* FunctionManager::Instance() +FunctionManager *FunctionManager::Instance() { - if(!instance) - { - instance = new FunctionManager; - } + if(!instance) { + instance = new FunctionManager; + } return instance; } -int FunctionManager::enterFunction(char *name, FILE **f, char *filename, int &lno) const +int FunctionManager::enterFunction(char *name, FILE ** f, char *filename, + int &lno) const { - if(functions->m.find(name) == functions->m.end())return 0; + if(functions->m.find(name) == functions->m.end()) + return 0; File_Position fpold; fpold.lineno = lno; - strcpy(fpold.filename,filename); + strcpy(fpold.filename, filename); fpold.file = *f; - fgetpos(fpold.file,&fpold.position); + fgetpos(fpold.file, &fpold.position); calls->s.push(fpold); File_Position fp = (functions->m)[name]; - fsetpos(fp.file,&fp.position); + fsetpos(fp.file, &fp.position); *f = fp.file; strcpy(filename, fp.filename); lno = fp.lineno; return 1; } -int FunctionManager::leaveFunction(FILE **f, char *filename, int &lno) +int FunctionManager::leaveFunction(FILE ** f, char *filename, int &lno) { - if(!calls->s.size())return 0; + if(!calls->s.size()) + return 0; File_Position fp; fp = calls->s.top(); calls->s.pop(); - fsetpos(fp.file,&fp.position); + fsetpos(fp.file, &fp.position); *f = fp.file; strcpy(filename, fp.filename); lno = fp.lineno; return 1; } -int FunctionManager::createFunction(char *name, FILE *f, char *filename, int lno) +int FunctionManager::createFunction(char *name, FILE * f, char *filename, + int lno) { File_Position fp; fp.file = f; strcpy(fp.filename, filename); fp.lineno = lno; - fgetpos(fp.file,&fp.position); + fgetpos(fp.file, &fp.position); (functions->m)[name] = fp; return 1; } - - - - diff --git a/Parser/OpenFile.cpp b/Parser/OpenFile.cpp index 78016b76c9210a5927112b6b91d9217c50a07f65..5f65317ec57b1ca919b4846edd497e4b33a7f68f 100644 --- a/Parser/OpenFile.cpp +++ b/Parser/OpenFile.cpp @@ -1,4 +1,4 @@ -// $Id: OpenFile.cpp,v 1.41 2003-02-27 05:06:46 geuzaine Exp $ +// $Id: OpenFile.cpp,v 1.42 2003-03-01 22:36:42 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -39,47 +39,49 @@ extern GUI *WID; #endif -extern Mesh *THEM, M; -extern Context_T CTX; +extern Mesh *THEM, M; +extern Context_T CTX; -int ParseFile(char *f, int silent){ +int ParseFile(char *f, int silent) +{ char String[256]; int status; - strncpy(yyname,f,255); - yyerrorstate=0; - yylineno=1; + strncpy(yyname, f, 255); + yyerrorstate = 0; + yylineno = 1; - if(!(yyin = fopen(yyname,"r"))) + if(!(yyin = fopen(yyname, "r"))) return 0; - - if(!silent) Msg(STATUS2, "Loading '%s'", yyname); + + if(!silent) + Msg(STATUS2, "Loading '%s'", yyname); fpos_t position; fgetpos(yyin, &position); - fgets(String, sizeof(String), yyin) ; + fgets(String, sizeof(String), yyin); fsetpos(yyin, &position); - if(!strncmp(String, "$PTS", 4) || - !strncmp(String, "$NO", 3) || - !strncmp(String, "$ELM", 4)){ - if(THEM->status < 0) mai3d(THEM, 0); + if(!strncmp(String, "$PTS", 4) || + !strncmp(String, "$NO", 3) || !strncmp(String, "$ELM", 4)) { + if(THEM->status < 0) + mai3d(THEM, 0); Read_Mesh(THEM, yyin, FORMAT_MSH); status = THEM->status; } - else if(!strncmp(String, "sms", 3)) - { - if(THEM->status < 0) mai3d(THEM, 0); + else if(!strncmp(String, "sms", 3)) { + if(THEM->status < 0) + mai3d(THEM, 0); Read_Mesh(THEM, yyin, FORMAT_SMS); status = THEM->status; } - else if(!strncmp(String, "$PostFormat", 11) || - !strncmp(String, "$View", 5)){ + else if(!strncmp(String, "$PostFormat", 11) || !strncmp(String, "$View", 5)) { ReadView(yyin, yyname); status = 0; } - else{ - while(!feof(yyin)) yyparse(); + else { + while(!feof(yyin)) + yyparse(); if(THEM) status = THEM->status; else @@ -87,68 +89,75 @@ int ParseFile(char *f, int silent){ } fclose(yyin); - if(!silent) Msg(STATUS2, "Loaded '%s'", yyname); + if(!silent) + Msg(STATUS2, "Loaded '%s'", yyname); return status; } -void ParseString(char *str){ +void ParseString(char *str) +{ FILE *f; - if(!str)return; - if((f = fopen(CTX.tmp_filename,"w"))){ - fprintf(f,"%s\n", str); + if(!str) + return; + if((f = fopen(CTX.tmp_filename, "w"))) { + fprintf(f, "%s\n", str); fclose(f); - ParseFile(CTX.tmp_filename,0); + ParseFile(CTX.tmp_filename, 0); } } -int MergeProblem(char *name){ +int MergeProblem(char *name) +{ char ext[5]; - if(strlen(name) > 4){ - strncpy(ext,&name[strlen(name)-4],5); + if(strlen(name) > 4) { + strncpy(ext, &name[strlen(name) - 4], 5); } - else{ + else { strcpy(ext, ""); } // a image file is used as an input, we transform it onto // a post pro file that could be used as a background mesh - if(!strcmp(ext,".ppm") ||!strcmp(ext,".pnm")){ + if(!strcmp(ext, ".ppm") || !strcmp(ext, ".pnm")) { #if defined(HAVE_FLTK) - read_pnm (name); + read_pnm(name); #endif return 1; } - else{ - return ParseFile(name,0); + else { + return ParseFile(name, 0); } } -void MergeProblemWithBoundingBox(char *name){ +void MergeProblemWithBoundingBox(char *name) +{ int nb = List_Nbr(CTX.post.list); int status = MergeProblem(name); - if(List_Nbr(CTX.post.list) > nb){ + if(List_Nbr(CTX.post.list) > nb) { // if we merged a view, use it - CalculateMinMax(NULL, ((Post_View*)List_Pointer - (CTX.post.list,List_Nbr(CTX.post.list)-1))->BBox); + CalculateMinMax(NULL, ((Post_View *) List_Pointer + (CTX.post.list, + List_Nbr(CTX.post.list) - 1))->BBox); } else if(!status) { // else, if we did not read a mesh, use the geomnetry - CalculateMinMax(THEM->Points,NULL); + CalculateMinMax(THEM->Points, NULL); } - else{ + else { // else, use the mesh - CalculateMinMax(THEM->Vertices,NULL); + CalculateMinMax(THEM->Vertices, NULL); } } -void OpenProblem(char *name){ +void OpenProblem(char *name) +{ char ext[6]; - if(CTX.threads_lock){ + if(CTX.threads_lock) { Msg(INFO, "I'm busy! Ask me that later..."); return; } @@ -162,31 +171,32 @@ void OpenProblem(char *name){ ParseString(TheOptString); - strncpy(CTX.filename,name,255); - strncpy(CTX.base_filename,name,255); + strncpy(CTX.filename, name, 255); + strncpy(CTX.base_filename, name, 255); - if(strlen(name) > 4){ - strncpy(ext,&name[strlen(name)-4],5); + if(strlen(name) > 4) { + strncpy(ext, &name[strlen(name) - 4], 5); } - else{ + else { strcpy(ext, ""); } - if(!strcmp(ext,".geo") || !strcmp(ext,".GEO") || - !strcmp(ext,".msh") || !strcmp(ext,".MSH") || - !strcmp(ext,".stl") || !strcmp(ext,".STL") || - !strcmp(ext,".sms") || !strcmp(ext,".SMS") || - !strcmp(ext,".ppm") || !strcmp(ext,".pnm") || - !strcmp(ext,".pos") || !strcmp(ext,".POS")){ - CTX.base_filename[strlen(name)-4] = '\0'; + if(!strcmp(ext, ".geo") || !strcmp(ext, ".GEO") || + !strcmp(ext, ".msh") || !strcmp(ext, ".MSH") || + !strcmp(ext, ".stl") || !strcmp(ext, ".STL") || + !strcmp(ext, ".sms") || !strcmp(ext, ".SMS") || + !strcmp(ext, ".ppm") || !strcmp(ext, ".pnm") || + !strcmp(ext, ".pos") || !strcmp(ext, ".POS")) { + CTX.base_filename[strlen(name) - 4] = '\0'; } - else{ - strcat(CTX.filename,".geo"); + else { + strcat(CTX.filename, ".geo"); } - strncpy(THEM->name, CTX.base_filename,255); + strncpy(THEM->name, CTX.base_filename, 255); #if defined(HAVE_FLTK) - if(!CTX.batch) WID->set_title(CTX.filename); + if(!CTX.batch) + WID->set_title(CTX.filename); #endif int status = MergeProblem(CTX.filename); @@ -195,66 +205,71 @@ void OpenProblem(char *name){ CTX.threads_lock = 0; - if(!status){ - mai3d(THEM,0); + if(!status) { + mai3d(THEM, 0); Maillage_Dimension_0(&M); } #if defined(HAVE_FLTK) - if(!CTX.batch) WID->reset_visibility(); - ZeroHighlight(&M); + if(!CTX.batch) + WID->reset_visibility(); + ZeroHighlight(&M); #endif - - if(!Tree_Nbr(THEM->Points) && !Tree_Nbr(THEM->Points) && List_Nbr(CTX.post.list)){ + + if(!Tree_Nbr(THEM->Points) && !Tree_Nbr(THEM->Points) + && List_Nbr(CTX.post.list)) { // if there are no points or vertices and there is a view, use it - CalculateMinMax(NULL, ((Post_View*)List_Pointer - (CTX.post.list,List_Nbr(CTX.post.list)-1))->BBox); + CalculateMinMax(NULL, ((Post_View *) List_Pointer + (CTX.post.list, + List_Nbr(CTX.post.list) - 1))->BBox); } - else if(!status){ + else if(!status) { // else, if we don't have a mesh, use the geometry - CalculateMinMax(THEM->Points,NULL); + CalculateMinMax(THEM->Points, NULL); } - else{ + else { // else, suppose we have a mesh (or use a default bbox if empty) - CalculateMinMax(THEM->Vertices,NULL); + CalculateMinMax(THEM->Vertices, NULL); } } // replace "/cygwin/x/" with "x:/" -void decygwin(char *in, char *out){ +void decygwin(char *in, char *out) +{ unsigned int i = 0, j = 0; - while(i<strlen(in)){ - if(!strncmp(in+i, "/cygdrive/", 10)){ - out[j++] = in[i+10]; // drive letter + while(i < strlen(in)) { + if(!strncmp(in + i, "/cygdrive/", 10)) { + out[j++] = in[i + 10]; // drive letter out[j++] = ':'; out[j++] = '/'; i += 12; } - else{ + else { out[j++] = in[i++]; } - } - out[j]='\0'; + } + out[j] = '\0'; } -void SystemCall(char *command){ +void SystemCall(char *command) +{ #if defined(WIN32) && defined(HAVE_FLTK) - STARTUPINFO suInfo; // Process startup information - PROCESS_INFORMATION prInfo; // Process information - + STARTUPINFO suInfo; // Process startup information + PROCESS_INFORMATION prInfo; // Process information + memset(&suInfo, 0, sizeof(suInfo)); suInfo.cb = sizeof(suInfo); - - char copy[strlen(command)+1]; + + char copy[strlen(command) + 1]; decygwin(command, copy); Msg(INFO, "Calling '%s'", copy); CreateProcess(NULL, copy, NULL, NULL, FALSE, - NORMAL_PRIORITY_CLASS, NULL, NULL, &suInfo, &prInfo); + NORMAL_PRIORITY_CLASS, NULL, NULL, &suInfo, &prInfo); #else - if(!system(NULL)){ + if(!system(NULL)) { Msg(GERROR, "Could not find /bin/sh: aborting system call"); return; } diff --git a/Plugin/CutMap.cpp b/Plugin/CutMap.cpp index 8888066f753196f6977f1e41518b3ef3d65c7d1e..7ff0e0cff66e1dda57c02ddc945009464ee4a1be 100644 --- a/Plugin/CutMap.cpp +++ b/Plugin/CutMap.cpp @@ -1,4 +1,4 @@ -// $Id: CutMap.cpp,v 1.28 2003-01-23 20:19:25 geuzaine Exp $ +// $Id: CutMap.cpp,v 1.29 2003-03-01 22:36:43 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -26,55 +26,57 @@ extern Context_T CTX; StringXNumber CutMapOptions_Number[] = { - { GMSH_FULLRC, "A" , NULL , 1. }, - { GMSH_FULLRC, "iView" , NULL , -1. }, - { GMSH_FULLRC, "iField" , NULL , 0. } + {GMSH_FULLRC, "A", NULL, 1.}, + {GMSH_FULLRC, "iView", NULL, -1.}, + {GMSH_FULLRC, "iField", NULL, 0.} }; extern "C" { - GMSH_Plugin *GMSH_RegisterCutMapPlugin () + GMSH_Plugin *GMSH_RegisterCutMapPlugin() { - return new GMSH_CutMapPlugin (); + return new GMSH_CutMapPlugin(); } } GMSH_CutMapPlugin::GMSH_CutMapPlugin() { + ; } void GMSH_CutMapPlugin::getName(char *name) const { - strcpy(name,"Cut map"); + strcpy(name, "Cut map"); } -void GMSH_CutMapPlugin::getInfos(char *author, char *copyright, char *help_text) const +void GMSH_CutMapPlugin::getInfos(char *author, char *copyright, + char *help_text) const { strcpy(author, "J.-F. Remacle (remacle@scorec.rpi.edu)"); strcpy(copyright, "DGR (www.multiphysics.com)"); - strcpy(help_text, - "Extracts the isovalue surface of value A from a\n" - "3D scalar map and draw ith component of the field on the iso.\n" + strcpy(help_text, + "Extracts the isovalue surface of value A from a\n" + "3D scalar map and draw ith component of the field on the iso.\n" "Script name: Plugin(CutMap)."); } int GMSH_CutMapPlugin::getNbOptions() const { - return sizeof(CutMapOptions_Number)/sizeof(StringXNumber); + return sizeof(CutMapOptions_Number) / sizeof(StringXNumber); } -StringXNumber *GMSH_CutMapPlugin:: GetOption (int iopt) +StringXNumber *GMSH_CutMapPlugin::GetOption(int iopt) { return &CutMapOptions_Number[iopt]; } -void GMSH_CutMapPlugin::CatchErrorMessage (char *errorMessage) const +void GMSH_CutMapPlugin::CatchErrorMessage(char *errorMessage) const { - strcpy(errorMessage,"CutMap failed..."); + strcpy(errorMessage, "CutMap failed..."); } -double GMSH_CutMapPlugin :: levelset (double x, double y, double z, double val) const +double GMSH_CutMapPlugin::levelset(double x, double y, double z, double val) const { // we must look into the map for A - Map(x,y,z) // this is the case when the map is the same as the view, @@ -82,24 +84,24 @@ double GMSH_CutMapPlugin :: levelset (double x, double y, double z, double val) return CutMapOptions_Number[0].def - val; } -Post_View *GMSH_CutMapPlugin::execute (Post_View *v) +Post_View *GMSH_CutMapPlugin::execute(Post_View * v) { Post_View *vv; - + int iView = (int)CutMapOptions_Number[1].def; _ith_field_to_draw_on_the_iso = (int)CutMapOptions_Number[2].def; _orientation = ORIENT_MAP; if(v && iView < 0) vv = v; - else{ - if(!v && iView < 0) iView = 0; - if(!(vv = (Post_View*)List_Pointer_Test(CTX.post.list,iView))){ - Msg(WARNING,"View[%d] does not exist",iView); + else { + if(!v && iView < 0) + iView = 0; + if(!(vv = (Post_View *) List_Pointer_Test(CTX.post.list, iView))) { + Msg(WARNING, "View[%d] does not exist", iView); return 0; } } return GMSH_LevelsetPlugin::execute(vv); } - diff --git a/Plugin/CutPlane.cpp b/Plugin/CutPlane.cpp index a0388c777b2e8880812b781efbeaa73864d0ec92..4a7754c28cd1de8af0f502f8c587b7671bb1f092 100644 --- a/Plugin/CutPlane.cpp +++ b/Plugin/CutPlane.cpp @@ -1,4 +1,4 @@ -// $Id: CutPlane.cpp,v 1.24 2003-01-23 20:19:25 geuzaine Exp $ +// $Id: CutPlane.cpp,v 1.25 2003-03-01 22:36:43 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -26,65 +26,65 @@ extern Context_T CTX; StringXNumber CutPlaneOptions_Number[] = { - { GMSH_FULLRC, "A" , NULL , 1. }, - { GMSH_FULLRC, "B" , NULL , 0. }, - { GMSH_FULLRC, "C" , NULL , 0. }, - { GMSH_FULLRC, "D" , NULL , 0.01 }, - { GMSH_FULLRC, "iView" , NULL , -1. } + {GMSH_FULLRC, "A", NULL, 1.}, + {GMSH_FULLRC, "B", NULL, 0.}, + {GMSH_FULLRC, "C", NULL, 0.}, + {GMSH_FULLRC, "D", NULL, 0.01}, + {GMSH_FULLRC, "iView", NULL, -1.} }; extern "C" { - GMSH_Plugin *GMSH_RegisterCutPlanePlugin () + GMSH_Plugin *GMSH_RegisterCutPlanePlugin() { - return new GMSH_CutPlanePlugin (); + return new GMSH_CutPlanePlugin(); } } GMSH_CutPlanePlugin::GMSH_CutPlanePlugin() { + ; } void GMSH_CutPlanePlugin::getName(char *name) const { - strcpy(name,"Cut plane"); + strcpy(name, "Cut plane"); } -void GMSH_CutPlanePlugin::getInfos(char *author, char *copyright, char *help_text) const +void GMSH_CutPlanePlugin::getInfos(char *author, char *copyright, + char *help_text) const { - strcpy(author,"J.-F. Remacle (remacle@scorec.rpi.edu)"); - strcpy(copyright,"DGR (www.multiphysics.com)"); + strcpy(author, "J.-F. Remacle (remacle@scorec.rpi.edu)"); + strcpy(copyright, "DGR (www.multiphysics.com)"); strcpy(help_text, - "Cuts a 3D scalar view with the plane\n" - "A*X + B*Y + C*Z + D = 0.\n" - "Script name: Plugin(CutPlane)."); + "Cuts a 3D scalar view with the plane\n" + "A*X + B*Y + C*Z + D = 0.\n" "Script name: Plugin(CutPlane)."); } int GMSH_CutPlanePlugin::getNbOptions() const { - return sizeof(CutPlaneOptions_Number)/sizeof(StringXNumber); + return sizeof(CutPlaneOptions_Number) / sizeof(StringXNumber); } -StringXNumber* GMSH_CutPlanePlugin:: GetOption (int iopt) +StringXNumber *GMSH_CutPlanePlugin::GetOption(int iopt) { - return &CutPlaneOptions_Number[iopt]; + return &CutPlaneOptions_Number[iopt]; } -void GMSH_CutPlanePlugin::CatchErrorMessage (char *errorMessage) const +void GMSH_CutPlanePlugin::CatchErrorMessage(char *errorMessage) const { - strcpy(errorMessage,"CutPlane failed..."); + strcpy(errorMessage, "CutPlane failed..."); } -double GMSH_CutPlanePlugin :: levelset (double x, double y, double z, double val) const +double GMSH_CutPlanePlugin::levelset(double x, double y, double z, double val) const { return CutPlaneOptions_Number[0].def * x + CutPlaneOptions_Number[1].def * y + - CutPlaneOptions_Number[2].def * z + - CutPlaneOptions_Number[3].def ; + CutPlaneOptions_Number[2].def * z + CutPlaneOptions_Number[3].def; } -Post_View *GMSH_CutPlanePlugin::execute (Post_View *v) +Post_View *GMSH_CutPlanePlugin::execute(Post_View * v) { Post_View *vv; @@ -96,14 +96,14 @@ Post_View *GMSH_CutPlanePlugin::execute (Post_View *v) if(v && iView < 0) vv = v; - else{ - if(!v && iView < 0) iView = 0; - if(!(vv = (Post_View*)List_Pointer_Test(CTX.post.list,iView))){ - Msg(WARNING,"View[%d] does not exist",iView); + else { + if(!v && iView < 0) + iView = 0; + if(!(vv = (Post_View *) List_Pointer_Test(CTX.post.list, iView))) { + Msg(WARNING, "View[%d] does not exist", iView); return 0; } } return GMSH_LevelsetPlugin::execute(vv); } - diff --git a/Plugin/CutSphere.cpp b/Plugin/CutSphere.cpp index ebec058f395e9e44ba43fd025af445d6901f34ec..cef00427e355739243abff7702ad79793cba5f9a 100644 --- a/Plugin/CutSphere.cpp +++ b/Plugin/CutSphere.cpp @@ -1,4 +1,4 @@ -// $Id: CutSphere.cpp,v 1.23 2003-01-23 20:19:25 geuzaine Exp $ +// $Id: CutSphere.cpp,v 1.24 2003-03-01 22:36:43 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -27,66 +27,69 @@ extern Context_T CTX; StringXNumber CutSphereOptions_Number[] = { - { GMSH_FULLRC, "Xc" , NULL , 0. }, - { GMSH_FULLRC, "Yc" , NULL , 0. }, - { GMSH_FULLRC, "Zc" , NULL , 0. }, - { GMSH_FULLRC, "R" , NULL , 0.25 }, - { GMSH_FULLRC, "iView" , NULL , -1. } + {GMSH_FULLRC, "Xc", NULL, 0.}, + {GMSH_FULLRC, "Yc", NULL, 0.}, + {GMSH_FULLRC, "Zc", NULL, 0.}, + {GMSH_FULLRC, "R", NULL, 0.25}, + {GMSH_FULLRC, "iView", NULL, -1.} }; extern "C" { - GMSH_Plugin *GMSH_RegisterCutSpherePlugin () + GMSH_Plugin *GMSH_RegisterCutSpherePlugin() { - return new GMSH_CutSpherePlugin (); + return new GMSH_CutSpherePlugin(); } } GMSH_CutSpherePlugin::GMSH_CutSpherePlugin() { + ; } void GMSH_CutSpherePlugin::getName(char *name) const { - strcpy(name,"Cut sphere"); + strcpy(name, "Cut sphere"); } -void GMSH_CutSpherePlugin::getInfos(char *author, char *copyright, char *help_text) const +void GMSH_CutSpherePlugin::getInfos(char *author, char *copyright, + char *help_text) const { - strcpy(author,"J.-F. Remacle (remacle@scorec.rpi.edu)"); - strcpy(copyright,"DGR (www.multiphysics.com)"); + strcpy(author, "J.-F. Remacle (remacle@scorec.rpi.edu)"); + strcpy(copyright, "DGR (www.multiphysics.com)"); strcpy(help_text, - "Cuts a 3D scalar view with the sphere\n" - "(X-Xc)^2 + (Y-Yc)^2 + (Z-Zc)^2 = R^2.\n" - "Script name: Plugin(CutSphere)."); + "Cuts a 3D scalar view with the sphere\n" + "(X-Xc)^2 + (Y-Yc)^2 + (Z-Zc)^2 = R^2.\n" + "Script name: Plugin(CutSphere)."); } int GMSH_CutSpherePlugin::getNbOptions() const { - return sizeof(CutSphereOptions_Number)/sizeof(StringXNumber); + return sizeof(CutSphereOptions_Number) / sizeof(StringXNumber); } -StringXNumber* GMSH_CutSpherePlugin:: GetOption (int iopt) +StringXNumber *GMSH_CutSpherePlugin::GetOption(int iopt) { return &CutSphereOptions_Number[iopt]; } -void GMSH_CutSpherePlugin::CatchErrorMessage (char *errorMessage) const +void GMSH_CutSpherePlugin::CatchErrorMessage(char *errorMessage) const { - strcpy(errorMessage,"CutSphere failed..."); + strcpy(errorMessage, "CutSphere failed..."); } -double GMSH_CutSpherePlugin :: levelset (double x, double y, double z, double val) const +double GMSH_CutSpherePlugin::levelset(double x, double y, double z, + double val) const { double a = CutSphereOptions_Number[0].def; double b = CutSphereOptions_Number[1].def; double c = CutSphereOptions_Number[2].def; double r = CutSphereOptions_Number[3].def; - return (x-a)*(x-a) + (y-b)*(y-b) + (z-c)*(z-c) - r*r; + return (x - a) * (x - a) + (y - b) * (y - b) + (z - c) * (z - c) - r * r; } -Post_View *GMSH_CutSpherePlugin::execute (Post_View *v) +Post_View *GMSH_CutSpherePlugin::execute(Post_View * v) { Post_View *vv; @@ -98,14 +101,14 @@ Post_View *GMSH_CutSpherePlugin::execute (Post_View *v) if(v && iView < 0) vv = v; - else{ - if(!v && iView < 0) iView = 0; - if(!(vv = (Post_View*)List_Pointer_Test(CTX.post.list,iView))){ - Msg(WARNING,"View[%d] does not exist",iView); + else { + if(!v && iView < 0) + iView = 0; + if(!(vv = (Post_View *) List_Pointer_Test(CTX.post.list, iView))) { + Msg(WARNING, "View[%d] does not exist", iView); return 0; } } return GMSH_LevelsetPlugin::execute(vv); } - diff --git a/Plugin/Harmonic2Time.cpp b/Plugin/Harmonic2Time.cpp index ba1d01f12e057dbb7a21e218303b86f02703c8c6..27defb7c95f2b56fe5a484c30c6ecc7d91b94adb 100644 --- a/Plugin/Harmonic2Time.cpp +++ b/Plugin/Harmonic2Time.cpp @@ -1,4 +1,4 @@ -// $Id: Harmonic2Time.cpp,v 1.2 2003-01-23 20:19:25 geuzaine Exp $ +// $Id: Harmonic2Time.cpp,v 1.3 2003-03-01 22:36:43 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -29,79 +29,82 @@ extern Context_T CTX; StringXNumber Harmonic2TimeOptions_Number[] = { - { GMSH_FULLRC, "realPart" , NULL , 0. }, - { GMSH_FULLRC, "imaginaryPart" , NULL , 1. }, - { GMSH_FULLRC, "nbSteps" , NULL , 20. }, - { GMSH_FULLRC, "iView" , NULL , -1. } + {GMSH_FULLRC, "realPart", NULL, 0.}, + {GMSH_FULLRC, "imaginaryPart", NULL, 1.}, + {GMSH_FULLRC, "nbSteps", NULL, 20.}, + {GMSH_FULLRC, "iView", NULL, -1.} }; extern "C" { - GMSH_Plugin *GMSH_RegisterHarmonic2TimePlugin () + GMSH_Plugin *GMSH_RegisterHarmonic2TimePlugin() { - return new GMSH_Harmonic2TimePlugin (); + return new GMSH_Harmonic2TimePlugin(); } } GMSH_Harmonic2TimePlugin::GMSH_Harmonic2TimePlugin() { + ; } void GMSH_Harmonic2TimePlugin::getName(char *name) const { - strcpy(name,""); + strcpy(name, ""); } -void GMSH_Harmonic2TimePlugin::getInfos(char *author, char *copyright, char *help_text) const +void GMSH_Harmonic2TimePlugin::getInfos(char *author, char *copyright, + char *help_text) const { strcpy(author, "C. Geuzaine (geuz@geuz.org)"); strcpy(copyright, "DGR (www.multiphysics.com)"); - strcpy(help_text, - "Harmonic2Time takes the values in the time\n" - "steps 'realPart' and 'imaginaryPart' of the\n" - "view 'iView', and creates a new view\n" - "containing 'iView[realPart] * cos(p) -\n" - "iView[imaginaryPart] * sin(p)', with\n" - "'p=2*pi*k/nbSteps', 'k=0...nbSteps'\n" - "Script name: Plugin(Harmonic2Time)."); + strcpy(help_text, + "Harmonic2Time takes the values in the time\n" + "steps 'realPart' and 'imaginaryPart' of the\n" + "view 'iView', and creates a new view\n" + "containing 'iView[realPart] * cos(p) -\n" + "iView[imaginaryPart] * sin(p)', with\n" + "'p=2*pi*k/nbSteps', 'k=0...nbSteps'\n" + "Script name: Plugin(Harmonic2Time)."); } int GMSH_Harmonic2TimePlugin::getNbOptions() const { - return sizeof(Harmonic2TimeOptions_Number)/sizeof(StringXNumber); + return sizeof(Harmonic2TimeOptions_Number) / sizeof(StringXNumber); } -StringXNumber *GMSH_Harmonic2TimePlugin:: GetOption (int iopt) +StringXNumber *GMSH_Harmonic2TimePlugin::GetOption(int iopt) { return &Harmonic2TimeOptions_Number[iopt]; } -void GMSH_Harmonic2TimePlugin::CatchErrorMessage (char *errorMessage) const +void GMSH_Harmonic2TimePlugin::CatchErrorMessage(char *errorMessage) const { - strcpy(errorMessage,"Harmonic2Time failed..."); + strcpy(errorMessage, "Harmonic2Time failed..."); } -static void harmonic2time(Post_View *vv, Post_View *View, - int rIndex, int iIndex, int nbSteps){ +static void harmonic2time(Post_View * vv, Post_View * View, + int rIndex, int iIndex, int nbSteps) +{ int i, j, k; double val, valr, vali, p; - for(i = 0 ; i < nbSteps ; i++){ - p = Deux_Pi * i / (nbSteps-1); - for(j = 0 ; j < VIEW_NB_ELEMENT_TYPES ; j++){ - for(k = 0 ; k < VIEW_MAX_ELEMENT_NODES ; k++){ - if(vv->get_val(j, k, rIndex, &valr) && - vv->get_val(j, k, iIndex, &vali)){ - val = valr * cos(p) - vali * sin(p); - View->add_val(j, k, i, val); - } + for(i = 0; i < nbSteps; i++) { + p = Deux_Pi * i / (nbSteps - 1); + for(j = 0; j < VIEW_NB_ELEMENT_TYPES; j++) { + for(k = 0; k < VIEW_MAX_ELEMENT_NODES; k++) { + if(vv->get_val(j, k, rIndex, &valr) && + vv->get_val(j, k, iIndex, &vali)) { + val = valr * cos(p) - vali * sin(p); + View->add_val(j, k, i, val); + } } } } } -Post_View *GMSH_Harmonic2TimePlugin::execute (Post_View *v) +Post_View *GMSH_Harmonic2TimePlugin::execute(Post_View * v) { Post_View *vv, *View; int rIndex, iIndex, nbSteps, iView; @@ -113,20 +116,21 @@ Post_View *GMSH_Harmonic2TimePlugin::execute (Post_View *v) if(v && iView < 0) vv = v; - else{ - if(!v && iView < 0) iView = 0; - if(!(vv = (Post_View*)List_Pointer_Test(CTX.post.list,iView))){ - Msg(WARNING,"View[%d] does not exist",iView); + else { + if(!v && iView < 0) + iView = 0; + if(!(vv = (Post_View *) List_Pointer_Test(CTX.post.list, iView))) { + Msg(WARNING, "View[%d] does not exist", iView); return 0; } } - - if(MIN(rIndex,iIndex)>=0 && vv->NbTimeStep >= MAX(rIndex,iIndex)){ + + if(MIN(rIndex, iIndex) >= 0 && vv->NbTimeStep >= MAX(rIndex, iIndex)) { View = BeginView(1); - harmonic2time(vv,View,rIndex, iIndex, nbSteps); + harmonic2time(vv, View, rIndex, iIndex, nbSteps); char name[1024], filename[1024]; - sprintf(name,"h2t-%s",vv->Name); - sprintf(filename,"h2t-%s",vv->FileName); + sprintf(name, "h2t-%s", vv->Name); + sprintf(filename, "h2t-%s", vv->FileName); EndView(View, 1, filename, name); Msg(INFO, "Created view '%s'", name); return View; @@ -135,11 +139,12 @@ Post_View *GMSH_Harmonic2TimePlugin::execute (Post_View *v) return 0; } -void GMSH_Harmonic2TimePlugin::Run () +void GMSH_Harmonic2TimePlugin::Run() { execute(0); } -void GMSH_Harmonic2TimePlugin::Save () +void GMSH_Harmonic2TimePlugin::Save() { + ; } diff --git a/Plugin/LevelsetPlugin.cpp b/Plugin/LevelsetPlugin.cpp index 5cdef1ebe1f8daff18b528e5991ca573509c9345..7dbd6370b9f43d6f63af50a4f872f2643a792dcf 100644 --- a/Plugin/LevelsetPlugin.cpp +++ b/Plugin/LevelsetPlugin.cpp @@ -1,4 +1,4 @@ -// $Id: LevelsetPlugin.cpp,v 1.29 2003-01-25 01:31:29 geuzaine Exp $ +// $Id: LevelsetPlugin.cpp,v 1.30 2003-03-01 22:36:44 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -30,14 +30,14 @@ GMSH_LevelsetPlugin::GMSH_LevelsetPlugin() { processed = 0; _ith_field_to_draw_on_the_iso = 0; - _orientation = ORIENT_NONE; + _orientation = ORIENT_NONE; _ref[0] = _ref[1] = _ref[2] = 0.; - strcpy (OutputFileName,"levelset.pos"); + strcpy(OutputFileName, "levelset.pos"); } -void GMSH_LevelsetPlugin::Save () +void GMSH_LevelsetPlugin::Save() { - if(processed){ + if(processed) { Msg(INFO, "Writing file '%s'", OutputFileName); WriteView(0, processed, OutputFileName); Msg(INFO, "Levelset ouput complete '%s'", OutputFileName); @@ -45,27 +45,29 @@ void GMSH_LevelsetPlugin::Save () } } -void GMSH_LevelsetPlugin::Run () -{ - execute (0); +void GMSH_LevelsetPlugin::Run() +{ + execute(0); } -Post_View *GMSH_LevelsetPlugin::execute (Post_View *v) +Post_View *GMSH_LevelsetPlugin::execute(Post_View * v) { // This plugin creates a new view which is the result of a cut of // the actual view with a levelset. - int nb, singleOutputView=1, edtet[6][2] = {{0,1},{0,2},{0,3},{1,2},{1,3},{2,3}}; + int nb, singleOutputView = 1, edtet[6][2] = + { {0, 1}, {0, 2}, {0, 3}, {1, 2}, {1, 3}, {2, 3} }; double *X, *Y, *Z, *Vals, levels[6], coef; double Xp[6], Yp[6], Zp[6], myVals[6]; double Xpi[6], Ypi[6], Zpi[6], myValsi[6]; double test; - if(v->NbSS){ + if(v->NbSS) { - Post_View **View = (Post_View**)Malloc(v->NbTimeStep* sizeof(Post_View*)); + Post_View **View = + (Post_View **) Malloc(v->NbTimeStep * sizeof(Post_View *)); - switch(_orientation){ + switch (_orientation) { case ORIENT_PLANE: case ORIENT_SPHERE: // We know the levelset is spatially "fixed", so we can create a @@ -77,145 +79,161 @@ Post_View *GMSH_LevelsetPlugin::execute (Post_View *v) default: // Each time step will give rise to a new view singleOutputView = 0; - for(int ts=0 ; ts<v->NbTimeStep ; ts++) - View[ts] = BeginView(1); + for(int ts = 0; ts < v->NbTimeStep; ts++) + View[ts] = BeginView(1); break; } // for all scalar tets - nb = List_Nbr(v->SS) / v->NbSS ; - for(int i=0 ; i<List_Nbr(v->SS) ; i+=nb){ - X = (double*)List_Pointer_Fast(v->SS,i); - Y = (double*)List_Pointer_Fast(v->SS,i+4); - Z = (double*)List_Pointer_Fast(v->SS,i+8); + nb = List_Nbr(v->SS) / v->NbSS; + for(int i = 0; i < List_Nbr(v->SS); i += nb) { + X = (double *)List_Pointer_Fast(v->SS, i); + Y = (double *)List_Pointer_Fast(v->SS, i + 4); + Z = (double *)List_Pointer_Fast(v->SS, i + 8); // for all time steps - for(int ts=0 ; ts<v->NbTimeStep ; ts++){ - Vals = (double*)List_Pointer_Fast(v->SS,i+12+(4*ts)); - for(int j=0 ; j<4 ; j++) - levels[j] = levelset(X[j],Y[j],Z[j],Vals[j]); - int nx = 0; - for(int k=0 ; k<6 ; k++){ - if(levels[edtet[k][0]] * levels[edtet[k][1]] <= 0.0){ - coef = InterpolateIso(X,Y,Z,levels,0.0, - edtet[k][0],edtet[k][1], - &Xp[nx],&Yp[nx],&Zp[nx]); - myVals[nx] = what_to_draw(Xp[nx],Yp[nx],Zp[nx], - edtet[k][0],edtet[k][1],coef,Vals); - nx++; - } - } - - if(nx == 4){ - double xx = Xp[3]; - double yy = Yp[3]; - double zz = Zp[3]; - double vv = myVals[3]; - Xp[3] = Xp[2]; - Yp[3] = Yp[2]; - Zp[3] = Zp[2]; - myVals[3] = myVals[2]; - Xp[2] = xx; - Yp[2] = yy; - Zp[2] = zz; - myVals[2] = vv; - } - - if(nx == 3 || nx == 4){ - - if(!ts || !singleOutputView){ // test this only once for "fixed" views - double v1[3] = {Xp[2]-Xp[0],Yp[2]-Yp[0],Zp[2]-Zp[0]}; - double v2[3] = {Xp[1]-Xp[0],Yp[1]-Yp[0],Zp[1]-Zp[0]}; - double gr[3]; - double n[3]; - prodve(v1,v2,n); - switch(_orientation){ - case ORIENT_MAP: - gradSimplex(X,Y,Z,Vals,gr); - prosca(gr,n,&test); - break; - case ORIENT_PLANE: - prosca(n,_ref,&test); - break; - case ORIENT_SPHERE: - gr[0] = Xp[0]-_ref[0]; - gr[1] = Yp[0]-_ref[1]; - gr[2] = Zp[0]-_ref[2]; - prosca(gr,n,&test); - break; - default: - test = 0.; - break; - } - } - - if(test>0){ - for(int k=0;k<nx;k++){ - Xpi[k] = Xp[k]; - Ypi[k] = Yp[k]; - Zpi[k] = Zp[k]; - myValsi[k] = myVals[k]; - } - for(int k=0;k<nx;k++){ - Xp[k] = Xpi[nx-k-1]; - Yp[k] = Ypi[nx-k-1]; - Zp[k] = Zpi[nx-k-1]; - myVals[k] = myValsi[nx-k-1]; - } - } - - if(singleOutputView){ - if(nx == 3){ - if(!ts){ // for the first time step only - for(int k=0 ; k<3 ; k++) List_Add(View[0]->ST, &Xp[k]); - for(int k=0 ; k<3 ; k++) List_Add(View[0]->ST, &Yp[k]); - for(int k=0 ; k<3 ; k++) List_Add(View[0]->ST, &Zp[k]); - View[0]->NbST++; - } - for(int k=0 ; k<3 ; k++) List_Add(View[0]->ST, &myVals[k]); - } - if(nx == 4){ - if(!ts){ // for the first time step only - for(int k=0 ; k<4 ; k++) List_Add(View[0]->SQ, &Xp[k]); - for(int k=0 ; k<4 ; k++) List_Add(View[0]->SQ, &Yp[k]); - for(int k=0 ; k<4 ; k++) List_Add(View[0]->SQ, &Zp[k]); - View[0]->NbSQ++; - } - for(int k=0 ; k<4 ; k++) List_Add(View[0]->SQ, &myVals[k]); - } - } - else{ - if(nx == 3){ - for(int k=0 ; k<3 ; k++) List_Add(View[ts]->ST, &Xp[k]); - for(int k=0 ; k<3 ; k++) List_Add(View[ts]->ST, &Yp[k]); - for(int k=0 ; k<3 ; k++) List_Add(View[ts]->ST, &Zp[k]); - for(int k=0 ; k<3 ; k++) List_Add(View[ts]->ST, &myVals[k]); - View[ts]->NbST++; - } - if(nx == 4){ - for(int k=0 ; k<4 ; k++) List_Add(View[ts]->SQ, &Xp[k]); - for(int k=0 ; k<4 ; k++) List_Add(View[ts]->SQ, &Yp[k]); - for(int k=0 ; k<4 ; k++) List_Add(View[ts]->SQ, &Zp[k]); - for(int k=0 ; k<4 ; k++) List_Add(View[ts]->SQ, &myVals[k]); - View[ts]->NbSQ++; - } - } - - } + for(int ts = 0; ts < v->NbTimeStep; ts++) { + Vals = (double *)List_Pointer_Fast(v->SS, i + 12 + (4 * ts)); + for(int j = 0; j < 4; j++) + levels[j] = levelset(X[j], Y[j], Z[j], Vals[j]); + int nx = 0; + for(int k = 0; k < 6; k++) { + if(levels[edtet[k][0]] * levels[edtet[k][1]] <= 0.0) { + coef = InterpolateIso(X, Y, Z, levels, 0.0, + edtet[k][0], edtet[k][1], + &Xp[nx], &Yp[nx], &Zp[nx]); + myVals[nx] = what_to_draw(Xp[nx], Yp[nx], Zp[nx], + edtet[k][0], edtet[k][1], coef, Vals); + nx++; + } + } + + if(nx == 4) { + double xx = Xp[3]; + double yy = Yp[3]; + double zz = Zp[3]; + double vv = myVals[3]; + Xp[3] = Xp[2]; + Yp[3] = Yp[2]; + Zp[3] = Zp[2]; + myVals[3] = myVals[2]; + Xp[2] = xx; + Yp[2] = yy; + Zp[2] = zz; + myVals[2] = vv; + } + + if(nx == 3 || nx == 4) { + + if(!ts || !singleOutputView) { // test this only once for "fixed" views + double v1[3] = { Xp[2] - Xp[0], Yp[2] - Yp[0], Zp[2] - Zp[0] }; + double v2[3] = { Xp[1] - Xp[0], Yp[1] - Yp[0], Zp[1] - Zp[0] }; + double gr[3]; + double n[3]; + prodve(v1, v2, n); + switch (_orientation) { + case ORIENT_MAP: + gradSimplex(X, Y, Z, Vals, gr); + prosca(gr, n, &test); + break; + case ORIENT_PLANE: + prosca(n, _ref, &test); + break; + case ORIENT_SPHERE: + gr[0] = Xp[0] - _ref[0]; + gr[1] = Yp[0] - _ref[1]; + gr[2] = Zp[0] - _ref[2]; + prosca(gr, n, &test); + break; + default: + test = 0.; + break; + } + } + + if(test > 0) { + for(int k = 0; k < nx; k++) { + Xpi[k] = Xp[k]; + Ypi[k] = Yp[k]; + Zpi[k] = Zp[k]; + myValsi[k] = myVals[k]; + } + for(int k = 0; k < nx; k++) { + Xp[k] = Xpi[nx - k - 1]; + Yp[k] = Ypi[nx - k - 1]; + Zp[k] = Zpi[nx - k - 1]; + myVals[k] = myValsi[nx - k - 1]; + } + } + + if(singleOutputView) { + if(nx == 3) { + if(!ts) { // for the first time step only + for(int k = 0; k < 3; k++) + List_Add(View[0]->ST, &Xp[k]); + for(int k = 0; k < 3; k++) + List_Add(View[0]->ST, &Yp[k]); + for(int k = 0; k < 3; k++) + List_Add(View[0]->ST, &Zp[k]); + View[0]->NbST++; + } + for(int k = 0; k < 3; k++) + List_Add(View[0]->ST, &myVals[k]); + } + if(nx == 4) { + if(!ts) { // for the first time step only + for(int k = 0; k < 4; k++) + List_Add(View[0]->SQ, &Xp[k]); + for(int k = 0; k < 4; k++) + List_Add(View[0]->SQ, &Yp[k]); + for(int k = 0; k < 4; k++) + List_Add(View[0]->SQ, &Zp[k]); + View[0]->NbSQ++; + } + for(int k = 0; k < 4; k++) + List_Add(View[0]->SQ, &myVals[k]); + } + } + else { + if(nx == 3) { + for(int k = 0; k < 3; k++) + List_Add(View[ts]->ST, &Xp[k]); + for(int k = 0; k < 3; k++) + List_Add(View[ts]->ST, &Yp[k]); + for(int k = 0; k < 3; k++) + List_Add(View[ts]->ST, &Zp[k]); + for(int k = 0; k < 3; k++) + List_Add(View[ts]->ST, &myVals[k]); + View[ts]->NbST++; + } + if(nx == 4) { + for(int k = 0; k < 4; k++) + List_Add(View[ts]->SQ, &Xp[k]); + for(int k = 0; k < 4; k++) + List_Add(View[ts]->SQ, &Yp[k]); + for(int k = 0; k < 4; k++) + List_Add(View[ts]->SQ, &Zp[k]); + for(int k = 0; k < 4; k++) + List_Add(View[ts]->SQ, &myVals[k]); + View[ts]->NbSQ++; + } + } + + } } } - char name[1024],filename[1024]; - if(singleOutputView){ - sprintf(name,"cut-%s",v->Name); - sprintf(filename,"cut-%s",v->FileName); + char name[1024], filename[1024]; + if(singleOutputView) { + sprintf(name, "cut-%s", v->Name); + sprintf(filename, "cut-%s", v->FileName); EndView(View[0], 1, filename, name); } - else{ - for(int ts=0 ; ts<v->NbTimeStep ; ts++){ - sprintf(name,"cut-%s-%d",v->Name, ts); - sprintf(filename,"cut-%s-%d",v->FileName, ts); - EndView(View[ts], 1, filename, name); + else { + for(int ts = 0; ts < v->NbTimeStep; ts++) { + sprintf(name, "cut-%s-%d", v->Name, ts); + sprintf(filename, "cut-%s-%d", v->FileName, ts); + EndView(View[ts], 1, filename, name); } } @@ -226,28 +244,22 @@ Post_View *GMSH_LevelsetPlugin::execute (Post_View *v) return processed; } - + return 0; } -double GMSH_LevelsetPlugin::what_to_draw (double x, double y, double z, - int p1, int p2, - double coef, double *Vals) const +double GMSH_LevelsetPlugin::what_to_draw(double x, double y, double z, + int p1, int p2, + double coef, double *Vals) const { // This very dangerous, since there is no test to check if enough // values are avaiable in the view - int offset = _ith_field_to_draw_on_the_iso * 4; + int offset = _ith_field_to_draw_on_the_iso * 4; // TEST JF, this would draw y coord on the iso //return y; p2 += offset; p1 += offset; - return coef * (Vals[p2] - Vals[p1]) + Vals[p1]; + return coef * (Vals[p2] - Vals[p1]) + Vals[p1]; } - - - - - - diff --git a/Plugin/Plugin.cpp b/Plugin/Plugin.cpp index 5bd2198d2c561c3df97125827730ec85ad6a30f3..819d76a4a1274cf91cd5b583d39d28c24aa5efc5 100644 --- a/Plugin/Plugin.cpp +++ b/Plugin/Plugin.cpp @@ -1,4 +1,4 @@ -// $Id: Plugin.cpp,v 1.36 2003-02-17 16:32:37 geuzaine Exp $ +// $Id: Plugin.cpp,v 1.37 2003-03-01 22:36:44 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -47,61 +47,71 @@ const char *GMSH_PluginEntry = "GMSH_RegisterPlugin"; GMSH_PluginManager *GMSH_PluginManager::instance = 0; -GMSH_PluginManager::GMSH_PluginManager(){ +GMSH_PluginManager::GMSH_PluginManager() +{ } -GMSH_PluginManager::~GMSH_PluginManager(){ - for(iter it = allPlugins.begin(); - it != allPlugins.end(); - ++it) delete (*it).second; +GMSH_PluginManager::~GMSH_PluginManager() +{ + for(iter it = allPlugins.begin(); it != allPlugins.end(); ++it) + delete(*it).second; } -GMSH_Plugin* GMSH_PluginManager::find (char *pluginName){ +GMSH_Plugin *GMSH_PluginManager::find(char *pluginName) +{ iter it = allPlugins.find(pluginName); - if (it == allPlugins.end()) return 0; + if(it == allPlugins.end()) + return 0; return (*it).second; } -void GMSH_PluginManager::Action( char *pluginName, char *action, void *data){ - GMSH_Plugin * plugin = find(pluginName); - if(!plugin){ +void GMSH_PluginManager::Action(char *pluginName, char *action, void *data) +{ + GMSH_Plugin *plugin = find(pluginName); + if(!plugin) { throw 1; } - if(!strcmp(action,"Run")){ + if(!strcmp(action, "Run")) { plugin->Run(); } - else if(!strcmp(action,"Save")){ + else if(!strcmp(action, "Save")) { plugin->Save(); } - else{ + else { throw 1; } } -void GMSH_PluginManager::SetPluginOption (char *pluginName, char *option, char *value){ +void GMSH_PluginManager::SetPluginOption(char *pluginName, char *option, + char *value) +{ GMSH_Plugin *plugin = find(pluginName); - if(!plugin) throw "Unknown plugin name" ; + if(!plugin) + throw "Unknown plugin name"; - if(!strcmp(option,"OutputFileName")) - strcpy(plugin->OutputFileName,value); - else if(!strcmp(option,"InputFileName")) - strcpy(plugin->InputFileName,value); + if(!strcmp(option, "OutputFileName")) + strcpy(plugin->OutputFileName, value); + else if(!strcmp(option, "InputFileName")) + strcpy(plugin->InputFileName, value); else throw "Unknown plugin option name"; } -void GMSH_PluginManager::SetPluginOption (char *pluginName, char *option, double value){ +void GMSH_PluginManager::SetPluginOption(char *pluginName, char *option, + double value) +{ GMSH_Plugin *plugin = find(pluginName); - if(!plugin) throw "Unknown plugin name"; + if(!plugin) + throw "Unknown plugin name"; - for(int i=0 ; i<plugin->getNbOptions();i++){ + for(int i = 0; i < plugin->getNbOptions(); i++) { StringXNumber *sxn; // get the ith option of the plugin sxn = plugin->GetOption(i); // look if it's the good option name - if(!strcmp (sxn->str,option)){ + if(!strcmp(sxn->str, option)) { sxn->def = value; return; } @@ -109,60 +119,71 @@ void GMSH_PluginManager::SetPluginOption (char *pluginName, char *option, double throw "Unknown plugin option name"; } -GMSH_PluginManager* GMSH_PluginManager::Instance(){ - if(!instance){ +GMSH_PluginManager *GMSH_PluginManager::Instance() +{ + if(!instance) { instance = new GMSH_PluginManager; } return instance; } -void GMSH_PluginManager::RegisterDefaultPlugins(){ - allPlugins.insert(std::pair<char*,GMSH_Plugin*>("CutMap", - GMSH_RegisterCutMapPlugin())); - allPlugins.insert(std::pair<char*,GMSH_Plugin*>("CutPlane", - GMSH_RegisterCutPlanePlugin())); - allPlugins.insert(std::pair<char*,GMSH_Plugin*>("CutSphere", - GMSH_RegisterCutSpherePlugin())); - allPlugins.insert(std::pair<char*,GMSH_Plugin*>("Skin", - GMSH_RegisterSkinPlugin())); - allPlugins.insert(std::pair<char*,GMSH_Plugin*>("Smooth", - GMSH_RegisterSmoothPlugin())); - allPlugins.insert(std::pair<char*,GMSH_Plugin*>("Transform", - GMSH_RegisterTransformPlugin())); - allPlugins.insert(std::pair<char*,GMSH_Plugin*>("Triangulate", - GMSH_RegisterTriangulatePlugin())); - allPlugins.insert(std::pair<char*,GMSH_Plugin*>("SphericalRaise", - GMSH_RegisterSphericalRaisePlugin())); +void GMSH_PluginManager::RegisterDefaultPlugins() +{ + allPlugins.insert(std::pair < char *, GMSH_Plugin * >("CutMap", + GMSH_RegisterCutMapPlugin + ())); + allPlugins.insert(std::pair < char *, + GMSH_Plugin * >("CutPlane", + GMSH_RegisterCutPlanePlugin())); + allPlugins.insert(std::pair < char *, + GMSH_Plugin * >("CutSphere", + GMSH_RegisterCutSpherePlugin())); + allPlugins.insert(std::pair < char *, + GMSH_Plugin * >("Skin", GMSH_RegisterSkinPlugin())); + allPlugins.insert(std::pair < char *, + GMSH_Plugin * >("Smooth", GMSH_RegisterSmoothPlugin())); + allPlugins.insert(std::pair < char *, + GMSH_Plugin * >("Transform", + GMSH_RegisterTransformPlugin())); + allPlugins.insert(std::pair < char *, + GMSH_Plugin * >("Triangulate", + GMSH_RegisterTriangulatePlugin())); + allPlugins.insert(std::pair < char *, + GMSH_Plugin * >("SphericalRaise", + GMSH_RegisterSphericalRaisePlugin())); #if defined(HAVE_FLTK) struct dirent **list; char ext[6]; - char *homeplugins = getenv ("GMSHPLUGINSHOME"); - if(!homeplugins) return; + char *homeplugins = getenv("GMSHPLUGINSHOME"); + if(!homeplugins) + return; #if (FL_MAJOR_VERSION == 1 || FL_MAJOR_VERSION == 2) && (FL_MINOR_VERSION == 0) - int nbFiles = filename_list(homeplugins,&list); + int nbFiles = filename_list(homeplugins, &list); #else - int nbFiles = fl_filename_list(homeplugins,&list); + int nbFiles = fl_filename_list(homeplugins, &list); #endif - if(nbFiles <= 0) return; - for(int i=0;i<nbFiles;i++){ + if(nbFiles <= 0) + return; + for(int i = 0; i < nbFiles; i++) { char *name = list[i]->d_name; - if(strlen(name) > 3){ - strcpy(ext,name+(strlen(name)-3)); - if(!strcmp(ext,".so") || !strcmp(ext,"dll")){ - AddPlugin(homeplugins,name); + if(strlen(name) > 3) { + strcpy(ext, name + (strlen(name) - 3)); + if(!strcmp(ext, ".so") || !strcmp(ext, "dll")) { + AddPlugin(homeplugins, name); } } } - for(int i=0;i<nbFiles;i++)free(list[i]); - free (list); + for(int i = 0; i < nbFiles; i++) + free(list[i]); + free(list); #endif } -void GMSH_PluginManager::AddPlugin( char *dirName, char *pluginName){ - +void GMSH_PluginManager::AddPlugin(char *dirName, char *pluginName) +{ #if defined(_NO_DLL) || !defined(HAVE_FLTK) - Msg(WARNING,"No dynamic plugin loading on this platform"); + Msg(WARNING, "No dynamic plugin loading on this platform"); return; #else char dynamic_lib[1024]; @@ -170,38 +191,36 @@ void GMSH_PluginManager::AddPlugin( char *dirName, char *pluginName){ char plugin_author[256]; char plugin_copyright[256]; char plugin_help[256]; - class GMSH_Plugin* (*RegisterPlugin)(void); - sprintf(dynamic_lib,"%s/%s",dirName,pluginName); - Msg(INFO,"Opening Plugin '%s'",dynamic_lib); - void *hlib = dlopen (dynamic_lib,RTLD_NOW); + class GMSH_Plugin *(*RegisterPlugin) (void); + sprintf(dynamic_lib, "%s/%s", dirName, pluginName); + Msg(INFO, "Opening Plugin '%s'", dynamic_lib); + void *hlib = dlopen(dynamic_lib, RTLD_NOW); char *err = dlerror(); - if(hlib == NULL){ - Msg(WARNING,"Error in opening %s (dlerror = %s)",dynamic_lib,err); + if(hlib == NULL) { + Msg(WARNING, "Error in opening %s (dlerror = %s)", dynamic_lib, err); return; } - RegisterPlugin = (class GMSH_Plugin* (*)(void)) dlsym(hlib,GMSH_PluginEntry); + RegisterPlugin = + (class GMSH_Plugin * (*)(void))dlsym(hlib, GMSH_PluginEntry); err = dlerror(); - if(err != NULL){ - Msg(WARNING,"Symbol '%s' missing in plugin '%s' (dlerror = %s)", - GMSH_PluginEntry,pluginName,err); + if(err != NULL) { + Msg(WARNING, "Symbol '%s' missing in plugin '%s' (dlerror = %s)", + GMSH_PluginEntry, pluginName, err); return; } GMSH_Plugin *p = RegisterPlugin(); p->hlib = hlib; p->getName(plugin_name); - p->getInfos(plugin_author,plugin_copyright,plugin_help); - if(allPlugins.find(plugin_name) != allPlugins.end()){ - Msg(WARNING,"Plugin '%s' multiply defined",pluginName); + p->getInfos(plugin_author, plugin_copyright, plugin_help); + if(allPlugins.find(plugin_name) != allPlugins.end()) { + Msg(WARNING, "Plugin '%s' multiply defined", pluginName); return; } - allPlugins.insert(std::pair<char*,GMSH_Plugin*>(plugin_name,p)); - Msg(INFO,"Plugin name : %s",plugin_name); - Msg(INFO,"Plugin author : %s",plugin_author); - Msg(INFO,"Plugin copyright : %s",plugin_copyright); - Msg(INFO,"Plugin help : %s",plugin_help); + allPlugins.insert(std::pair < char *, GMSH_Plugin * >(plugin_name, p)); + Msg(INFO, "Plugin name : %s", plugin_name); + Msg(INFO, "Plugin author : %s", plugin_author); + Msg(INFO, "Plugin copyright : %s", plugin_copyright); + Msg(INFO, "Plugin help : %s", plugin_help); #endif } - - - diff --git a/Plugin/Skin.cpp b/Plugin/Skin.cpp index 592b637e3fd8f661080fc328ea8ec60d12b74d3e..f69a098d8c0dfc1e2ada79d0e15b08f8d74d3b7a 100644 --- a/Plugin/Skin.cpp +++ b/Plugin/Skin.cpp @@ -1,4 +1,4 @@ -// $Id: Skin.cpp,v 1.15 2003-01-23 20:19:26 geuzaine Exp $ +// $Id: Skin.cpp,v 1.16 2003-03-01 22:36:44 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -30,12 +30,12 @@ extern Context_T CTX; StringXNumber SkinOptions_Number[] = { - { GMSH_FULLRC, "iView" , NULL , -1. } + {GMSH_FULLRC, "iView", NULL, -1.} }; extern "C" { - GMSH_Plugin *GMSH_RegisterSkinPlugin () + GMSH_Plugin *GMSH_RegisterSkinPlugin() { return new GMSH_SkinPlugin(); } @@ -43,108 +43,137 @@ extern "C" GMSH_SkinPlugin::GMSH_SkinPlugin() { + ; } void GMSH_SkinPlugin::getName(char *name) const { - strcpy(name,"Skin"); + strcpy(name, "Skin"); } void GMSH_SkinPlugin::getInfos(char *author, char *copyright, char *help_text) const { strcpy(author, "C. Geuzaine (geuz@geuz.org)"); strcpy(copyright, "DGR (www.multiphysics.com)"); - strcpy(help_text, - "Gets the skin (i.e. the boundary) of a view,\n" - "eliminating all interior drawing.\n" - "Script name: Plugin(Skin).\n"); + strcpy(help_text, + "Gets the skin (i.e. the boundary) of a view,\n" + "eliminating all interior drawing.\n" + "Script name: Plugin(Skin).\n"); } int GMSH_SkinPlugin::getNbOptions() const { - return sizeof(SkinOptions_Number)/sizeof(StringXNumber); + return sizeof(SkinOptions_Number) / sizeof(StringXNumber); } -StringXNumber *GMSH_SkinPlugin:: GetOption (int iopt) +StringXNumber *GMSH_SkinPlugin::GetOption(int iopt) { return &SkinOptions_Number[iopt]; } -void GMSH_SkinPlugin::CatchErrorMessage (char *errorMessage) const +void GMSH_SkinPlugin::CatchErrorMessage(char *errorMessage) const { - strcpy(errorMessage,"Skin failed..."); + strcpy(errorMessage, "Skin failed..."); } -static List_T * List; -static int * NbList, NbNod, NbComp, NbTime; +static List_T *List; +static int *NbList, NbNod, NbComp, NbTime; -typedef struct{ +typedef struct +{ double Coord[9]; double *Val; -} Elm; +} +Elm; -static int fcmpElm(const void *a, const void *b){ - Elm *e1=(Elm*)a, *e2=(Elm*)b; - double s1, s2, TOL=CTX.lc*1.e-12; +static int fcmpElm(const void *a, const void *b) +{ + Elm *e1 = (Elm *) a, *e2 = (Elm *) b; + double s1, s2, TOL = CTX.lc * 1.e-12; int i; - - s1 = s2 = 0.0 ; - for(i=0;i<NbNod-1;i++){ s1 += e1->Coord[i]; s2 += e2->Coord[i]; } - if(s1-s2 > TOL) return 1; else if(s1-s2 < -TOL) return -1; - s1 = s2 = 0.0 ; - for(i=0;i<NbNod-1;i++){ s1 += e1->Coord[NbNod-1+i]; s2 += e2->Coord[NbNod-1+i]; } - if(s1-s2 > TOL) return 1; else if(s1-s2 < -TOL) return -1; - s1 = s2 = 0.0 ; - for(i=0;i<NbNod-1;i++){ s1 += e1->Coord[2*(NbNod-1)+i]; s2 += e2->Coord[2*(NbNod-1)+i]; } - if(s1-s2 > TOL) return 1; else if(s1-s2 < -TOL) return -1; + + s1 = s2 = 0.0; + for(i = 0; i < NbNod - 1; i++) { + s1 += e1->Coord[i]; + s2 += e2->Coord[i]; + } + if(s1 - s2 > TOL) + return 1; + else if(s1 - s2 < -TOL) + return -1; + s1 = s2 = 0.0; + for(i = 0; i < NbNod - 1; i++) { + s1 += e1->Coord[NbNod - 1 + i]; + s2 += e2->Coord[NbNod - 1 + i]; + } + if(s1 - s2 > TOL) + return 1; + else if(s1 - s2 < -TOL) + return -1; + s1 = s2 = 0.0; + for(i = 0; i < NbNod - 1; i++) { + s1 += e1->Coord[2 * (NbNod - 1) + i]; + s2 += e2->Coord[2 * (NbNod - 1) + i]; + } + if(s1 - s2 > TOL) + return 1; + else if(s1 - s2 < -TOL) + return -1; return 0; } -static void getElm(int *Nod, double *Coord, double *Val, Elm *Elm){ +static void getElm(int *Nod, double *Coord, double *Val, Elm * Elm) +{ int i, j, k; - Elm->Val = (double*)Malloc((NbNod-1)*NbComp*NbTime*sizeof(double)); - for(i=0; i<NbNod-1; i++) Elm->Coord[i] = Coord[Nod[i]]; //x - for(i=0; i<NbNod-1; i++) Elm->Coord[NbNod-1+i] = Coord[NbNod + Nod[i]]; //y - for(i=0; i<NbNod-1; i++) Elm->Coord[2*(NbNod-1)+i] = Coord[2*NbNod + Nod[i]]; //z - for(i=0; i<NbTime; i++) - for(j=0; j<NbNod-1; j++) - for(k=0; k<NbComp; k++) - Elm->Val[(NbNod-1)*NbComp*i+NbComp*j+k] = - Val[NbNod*NbComp*i+NbComp*Nod[j]+k]; + Elm->Val = (double *)Malloc((NbNod - 1) * NbComp * NbTime * sizeof(double)); + for(i = 0; i < NbNod - 1; i++) + Elm->Coord[i] = Coord[Nod[i]]; //x + for(i = 0; i < NbNod - 1; i++) + Elm->Coord[NbNod - 1 + i] = Coord[NbNod + Nod[i]]; //y + for(i = 0; i < NbNod - 1; i++) + Elm->Coord[2 * (NbNod - 1) + i] = Coord[2 * NbNod + Nod[i]]; //z + for(i = 0; i < NbTime; i++) + for(j = 0; j < NbNod - 1; j++) + for(k = 0; k < NbComp; k++) + Elm->Val[(NbNod - 1) * NbComp * i + NbComp * j + k] = + Val[NbNod * NbComp * i + NbComp * Nod[j] + k]; } -static void addInView(void *a, void *b){ +static void addInView(void *a, void *b) +{ int i, k; - Elm *e = (Elm*)a; - for(i=0; i<3*(NbNod-1); i++) List_Add(List, &e->Coord[i]); - for(i=0; i<NbTime; i++) - for(k=0;k<(NbNod-1)*NbComp;k++) - List_Add(List, &e->Val[(NbNod-1)*NbComp*i+k]); + Elm *e = (Elm *) a; + for(i = 0; i < 3 * (NbNod - 1); i++) + List_Add(List, &e->Coord[i]); + for(i = 0; i < NbTime; i++) + for(k = 0; k < (NbNod - 1) * NbComp; k++) + List_Add(List, &e->Val[(NbNod - 1) * NbComp * i + k]); Free(e->Val); (*NbList)++; } -static void skinSimplex(List_T *Simp, int NbSimp){ +static void skinSimplex(List_T * Simp, int NbSimp) +{ double *Coords, *Vals; int i, j; - int FacesTet[4][3] = {{0,1,2},{0,1,3},{0,2,3},{1,2,3}}; - int EdgesTri[3][2] = {{0,1},{1,2},{2,0}}; + int FacesTet[4][3] = { {0, 1, 2}, {0, 1, 3}, {0, 2, 3}, {1, 2, 3} }; + int EdgesTri[3][2] = { {0, 1}, {1, 2}, {2, 0} }; Elm e, *pe; - Tree_T * Skin = Tree_Create(sizeof(Elm), fcmpElm); - for(i = 0 ; i < List_Nbr(Simp) ; i+=NbSimp){ - Coords = (double*)List_Pointer_Fast(Simp,i); - Vals = (double*)List_Pointer_Fast(Simp,i+3*NbNod); - for(j=0 ; j<NbNod ; j++){ - getElm(NbNod == 4 ? FacesTet[j] : EdgesTri[j],Coords,Vals,&e); - if(!(pe=(Elm*)Tree_PQuery(Skin, &e))) - Tree_Add(Skin, &e); - else{ - Free(pe->Val); - Free(e.Val); - Tree_Suppress(Skin, &e); + Tree_T *Skin = Tree_Create(sizeof(Elm), fcmpElm); + for(i = 0; i < List_Nbr(Simp); i += NbSimp) { + Coords = (double *)List_Pointer_Fast(Simp, i); + Vals = (double *)List_Pointer_Fast(Simp, i + 3 * NbNod); + for(j = 0; j < NbNod; j++) { + getElm(NbNod == 4 ? FacesTet[j] : EdgesTri[j], Coords, Vals, &e); + if(!(pe = (Elm *) Tree_PQuery(Skin, &e))) + Tree_Add(Skin, &e); + else { + Free(pe->Val); + Free(e.Val); + Tree_Suppress(Skin, &e); } } } @@ -152,7 +181,7 @@ static void skinSimplex(List_T *Simp, int NbSimp){ Tree_Delete(Skin); } -Post_View *GMSH_SkinPlugin::execute (Post_View *v) +Post_View *GMSH_SkinPlugin::execute(Post_View * v) { Post_View *vv, *View; @@ -160,37 +189,50 @@ Post_View *GMSH_SkinPlugin::execute (Post_View *v) if(v && iView < 0) vv = v; - else{ - if(!v && iView < 0) iView = 0; - if(!(vv = (Post_View*)List_Pointer_Test(CTX.post.list,iView))){ - Msg(WARNING,"View[%d] does not exist",iView); + else { + if(!v && iView < 0) + iView = 0; + if(!(vv = (Post_View *) List_Pointer_Test(CTX.post.list, iView))) { + Msg(WARNING, "View[%d] does not exist", iView); return 0; } } - if(vv->NbSS || vv->NbVS || vv->NbST || vv->NbVT){ + if(vv->NbSS || vv->NbVS || vv->NbST || vv->NbVT) { View = BeginView(1); NbTime = vv->NbTimeStep; - if(vv->NbSS){ - List = View->ST; NbList = &View->NbST; NbNod = 4; NbComp = 1; + if(vv->NbSS) { + List = View->ST; + NbList = &View->NbST; + NbNod = 4; + NbComp = 1; skinSimplex(vv->SS, List_Nbr(vv->SS) / vv->NbSS); } - if(vv->NbVS){ - List = View->VT; NbList = &View->NbVT; NbNod = 4; NbComp = 3; - skinSimplex(vv->VS, List_Nbr(vv->VS) / vv->NbVS) ; + if(vv->NbVS) { + List = View->VT; + NbList = &View->NbVT; + NbNod = 4; + NbComp = 3; + skinSimplex(vv->VS, List_Nbr(vv->VS) / vv->NbVS); } - if(vv->NbST){ - List = View->SL; NbList = &View->NbSL; NbNod = 3; NbComp = 1; + if(vv->NbST) { + List = View->SL; + NbList = &View->NbSL; + NbNod = 3; + NbComp = 1; skinSimplex(vv->ST, List_Nbr(vv->ST) / vv->NbST); } - if(vv->NbVT){ - List = View->VL; NbList = &View->NbVL; NbNod = 3; NbComp = 3; - skinSimplex(vv->VT, List_Nbr(vv->VT) / vv->NbVT) ; + if(vv->NbVT) { + List = View->VL; + NbList = &View->NbVL; + NbNod = 3; + NbComp = 3; + skinSimplex(vv->VT, List_Nbr(vv->VT) / vv->NbVT); } - if(View->NbST || View->NbVT || View->NbSL || View->NbVL){ + if(View->NbST || View->NbVT || View->NbSL || View->NbVL) { char name[1024], filename[1024]; - sprintf(name,"skin-%s",vv->Name); - sprintf(filename,"skin-%s",vv->FileName); + sprintf(name, "skin-%s", vv->Name); + sprintf(filename, "skin-%s", vv->FileName); EndView(View, 1, filename, name); Msg(INFO, "Created view '%s'", name); return View; @@ -202,11 +244,12 @@ Post_View *GMSH_SkinPlugin::execute (Post_View *v) return 0; } -void GMSH_SkinPlugin::Run () +void GMSH_SkinPlugin::Run() { execute(0); } -void GMSH_SkinPlugin::Save () +void GMSH_SkinPlugin::Save() { + ; } diff --git a/Plugin/Smooth.cpp b/Plugin/Smooth.cpp index 341054c2be13a466f5b57cc20101a2ea305cce62..2422ab12c241f692cd38084a4067b5bf3bf0388e 100644 --- a/Plugin/Smooth.cpp +++ b/Plugin/Smooth.cpp @@ -1,4 +1,4 @@ -// $Id: Smooth.cpp,v 1.11 2003-01-23 20:19:26 geuzaine Exp $ +// $Id: Smooth.cpp,v 1.12 2003-03-01 22:36:44 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -28,12 +28,12 @@ extern Context_T CTX; StringXNumber SmoothOptions_Number[] = { - { GMSH_FULLRC, "iView" , NULL , -1. } + {GMSH_FULLRC, "iView", NULL, -1.} }; extern "C" { - GMSH_Plugin *GMSH_RegisterSmoothPlugin () + GMSH_Plugin *GMSH_RegisterSmoothPlugin() { return new GMSH_SmoothPlugin(); } @@ -42,48 +42,51 @@ extern "C" GMSH_SmoothPlugin::GMSH_SmoothPlugin() { + ; } void GMSH_SmoothPlugin::getName(char *name) const { - strcpy(name,"Smooth"); + strcpy(name, "Smooth"); } -void GMSH_SmoothPlugin::getInfos(char *author, char *copyright, char *help_text) const +void GMSH_SmoothPlugin::getInfos(char *author, char *copyright, + char *help_text) const { strcpy(author, "C. Geuzaine (geuz@geuz.org)"); strcpy(copyright, "DGR (www.multiphysics.com)"); - strcpy(help_text, - "Smoothes a discontinuous view by averaging all the values at each node.\n" - "Script name: Plugin(Smooth)."); + strcpy(help_text, + "Smoothes a discontinuous view by averaging all the values at each node.\n" + "Script name: Plugin(Smooth)."); } int GMSH_SmoothPlugin::getNbOptions() const { - return sizeof(SmoothOptions_Number)/sizeof(StringXNumber); + return sizeof(SmoothOptions_Number) / sizeof(StringXNumber); } -StringXNumber *GMSH_SmoothPlugin:: GetOption (int iopt) +StringXNumber *GMSH_SmoothPlugin::GetOption(int iopt) { return &SmoothOptions_Number[iopt]; } -void GMSH_SmoothPlugin::CatchErrorMessage (char *errorMessage) const +void GMSH_SmoothPlugin::CatchErrorMessage(char *errorMessage) const { - strcpy(errorMessage,"Smooth failed..."); + strcpy(errorMessage, "Smooth failed..."); } -Post_View *GMSH_SmoothPlugin::execute (Post_View *v) +Post_View *GMSH_SmoothPlugin::execute(Post_View * v) { Post_View *vv; int iView = (int)SmoothOptions_Number[0].def; if(v && iView < 0) vv = v; - else{ - if(!v && iView < 0) iView = 0; - if(!(vv = (Post_View*)List_Pointer_Test(CTX.post.list,iView))){ - Msg(WARNING,"View[%d] does not exist",iView); + else { + if(!v && iView < 0) + iView = 0; + if(!(vv = (Post_View *) List_Pointer_Test(CTX.post.list, iView))) { + Msg(WARNING, "View[%d] does not exist", iView); return 0; } } @@ -92,11 +95,12 @@ Post_View *GMSH_SmoothPlugin::execute (Post_View *v) return vv; } -void GMSH_SmoothPlugin::Run () +void GMSH_SmoothPlugin::Run() { execute(0); } -void GMSH_SmoothPlugin::Save () +void GMSH_SmoothPlugin::Save() { + ; } diff --git a/Plugin/SphericalRaise.cpp b/Plugin/SphericalRaise.cpp index b6d70f152ee1265e9c8595cc5feb24ae03eb85e3..80dcbef59f49958e589b2fcce5c485683038c463 100644 --- a/Plugin/SphericalRaise.cpp +++ b/Plugin/SphericalRaise.cpp @@ -1,4 +1,4 @@ -// $Id: SphericalRaise.cpp,v 1.4 2003-01-23 20:19:26 geuzaine Exp $ +// $Id: SphericalRaise.cpp,v 1.5 2003-03-01 22:36:44 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -29,68 +29,73 @@ extern Context_T CTX; StringXNumber SphericalRaiseOptions_Number[] = { - { GMSH_FULLRC, "Xc" , NULL , 0. }, - { GMSH_FULLRC, "Yc" , NULL , 0. }, - { GMSH_FULLRC, "Zc" , NULL , 0. }, - { GMSH_FULLRC, "Raise" , NULL , 1. }, - { GMSH_FULLRC, "iView" , NULL , -1. } + {GMSH_FULLRC, "Xc", NULL, 0.}, + {GMSH_FULLRC, "Yc", NULL, 0.}, + {GMSH_FULLRC, "Zc", NULL, 0.}, + {GMSH_FULLRC, "Raise", NULL, 1.}, + {GMSH_FULLRC, "iView", NULL, -1.} }; extern "C" { - GMSH_Plugin *GMSH_RegisterSphericalRaisePlugin () + GMSH_Plugin *GMSH_RegisterSphericalRaisePlugin() { - return new GMSH_SphericalRaisePlugin (); + return new GMSH_SphericalRaisePlugin(); } } GMSH_SphericalRaisePlugin::GMSH_SphericalRaisePlugin() { + ; } void GMSH_SphericalRaisePlugin::getName(char *name) const { - strcpy(name,"Spherical raise"); + strcpy(name, "Spherical raise"); } -void GMSH_SphericalRaisePlugin::getInfos(char *author, char *copyright, char *help_text) const +void GMSH_SphericalRaisePlugin::getInfos(char *author, char *copyright, + char *help_text) const { strcpy(author, "C. Geuzaine (geuz@geuz.org)"); strcpy(copyright, "DGR (www.multiphysics.com)"); - strcpy(help_text, - "SphericalRaise transforms the coordinates\n" - "of the elements in a view according to the\n" - "elements' associated values. Instead of\n" - "transforming the coordinates along the X,\n" - "Y, Z axes (as in Options->Offset->Raise),\n" - "the raise is applied along the radius of\n" - "a sphere centered at (Xc, Yc, Zc).\n" - "Script name: Plugin(SphericalRaise)."); + strcpy(help_text, + "SphericalRaise transforms the coordinates\n" + "of the elements in a view according to the\n" + "elements' associated values. Instead of\n" + "transforming the coordinates along the X,\n" + "Y, Z axes (as in Options->Offset->Raise),\n" + "the raise is applied along the radius of\n" + "a sphere centered at (Xc, Yc, Zc).\n" + "Script name: Plugin(SphericalRaise)."); } int GMSH_SphericalRaisePlugin::getNbOptions() const { - return sizeof(SphericalRaiseOptions_Number)/sizeof(StringXNumber); + return sizeof(SphericalRaiseOptions_Number) / sizeof(StringXNumber); } -StringXNumber *GMSH_SphericalRaisePlugin:: GetOption (int iopt) +StringXNumber *GMSH_SphericalRaisePlugin::GetOption(int iopt) { return &SphericalRaiseOptions_Number[iopt]; } -void GMSH_SphericalRaisePlugin::CatchErrorMessage (char *errorMessage) const +void GMSH_SphericalRaisePlugin::CatchErrorMessage(char *errorMessage) const { - strcpy(errorMessage,"SphericalRaise failed..."); + strcpy(errorMessage, "SphericalRaise failed..."); } -static void sphericalRaiseList(Post_View *v, List_T *list, int nbelm, int nbvert, - double center[3], double raise){ - double *x,*y,*z,*val,d[3],coef; +static void sphericalRaiseList(Post_View * v, List_T * list, int nbelm, + int nbvert, double center[3], double raise) +{ + double *x, *y, *z, *val, d[3], coef; int nb, i, j; - if(nbelm) v->Changed=1; - else return; + if(nbelm) + v->Changed = 1; + else + return; // for each element // for each node @@ -99,26 +104,27 @@ static void sphericalRaiseList(Post_View *v, List_T *list, int nbelm, int nbvert // get nodal value val at xyz // compute (x,y,z)_new = (x,y,z)_old + raise*val*(dx,dy,dz) - nb = List_Nbr(list) / nbelm ; - for(i = 0 ; i < List_Nbr(list) ; i+=nb){ - x = (double*)List_Pointer_Fast(list,i); - y = (double*)List_Pointer_Fast(list,i+nbvert); - z = (double*)List_Pointer_Fast(list,i+2*nbvert); - val = (double*)List_Pointer_Fast(list,i+3*nbvert); - for(j=0; j<nbvert; j++){ - d[0] = x[j]-center[0]; - d[1] = y[j]-center[1]; - d[2] = z[j]-center[2]; + nb = List_Nbr(list) / nbelm; + for(i = 0; i < List_Nbr(list); i += nb) { + x = (double *)List_Pointer_Fast(list, i); + y = (double *)List_Pointer_Fast(list, i + nbvert); + z = (double *)List_Pointer_Fast(list, i + 2 * nbvert); + val = (double *)List_Pointer_Fast(list, i + 3 * nbvert); + for(j = 0; j < nbvert; j++) { + d[0] = x[j] - center[0]; + d[1] = y[j] - center[1]; + d[2] = z[j] - center[2]; norme(d); - coef = raise*val[j]; - x[j] += coef*d[0]; - y[j] += coef*d[1]; - z[j] += coef*d[2]; + coef = raise * val[j]; + x[j] += coef * d[0]; + y[j] += coef * d[1]; + z[j] += coef * d[2]; } } } -static void sphericalRaise(Post_View *v, double center[3], double raise){ +static void sphericalRaise(Post_View * v, double center[3], double raise) +{ sphericalRaiseList(v, v->SP, v->NbSP, 1, center, raise); sphericalRaiseList(v, v->SL, v->NbSL, 2, center, raise); sphericalRaiseList(v, v->ST, v->NbST, 3, center, raise); @@ -129,7 +135,7 @@ static void sphericalRaise(Post_View *v, double center[3], double raise){ sphericalRaiseList(v, v->SY, v->NbSY, 5, center, raise); } -Post_View *GMSH_SphericalRaisePlugin::execute (Post_View *v) +Post_View *GMSH_SphericalRaisePlugin::execute(Post_View * v) { Post_View *vv; double center[3], raise; @@ -143,23 +149,25 @@ Post_View *GMSH_SphericalRaisePlugin::execute (Post_View *v) if(v && iView < 0) vv = v; - else{ - if(!v && iView < 0) iView = 0; - if(!(vv = (Post_View*)List_Pointer_Test(CTX.post.list,iView))){ - Msg(WARNING,"View[%d] does not exist",iView); + else { + if(!v && iView < 0) + iView = 0; + if(!(vv = (Post_View *) List_Pointer_Test(CTX.post.list, iView))) { + Msg(WARNING, "View[%d] does not exist", iView); return 0; } } - - sphericalRaise(vv,center,raise); + + sphericalRaise(vv, center, raise); return vv; } -void GMSH_SphericalRaisePlugin::Run () +void GMSH_SphericalRaisePlugin::Run() { execute(0); } -void GMSH_SphericalRaisePlugin::Save () +void GMSH_SphericalRaisePlugin::Save() { + ; } diff --git a/Plugin/Transform.cpp b/Plugin/Transform.cpp index b90957cabaee31b22305a38425a0b20801a36868..e205b0e6565991497330e973b0bf16dc6fbc0e62 100644 --- a/Plugin/Transform.cpp +++ b/Plugin/Transform.cpp @@ -1,4 +1,4 @@ -// $Id: Transform.cpp,v 1.14 2003-01-23 20:19:26 geuzaine Exp $ +// $Id: Transform.cpp,v 1.15 2003-03-01 22:36:44 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -28,62 +28,64 @@ extern Context_T CTX; StringXNumber TransformOptions_Number[] = { - { GMSH_FULLRC, "A11" , NULL , 1. }, - { GMSH_FULLRC, "A12" , NULL , 0. }, - { GMSH_FULLRC, "A13" , NULL , 0. }, - { GMSH_FULLRC, "A21" , NULL , 0. }, - { GMSH_FULLRC, "A22" , NULL , 1. }, - { GMSH_FULLRC, "A23" , NULL , 0. }, - { GMSH_FULLRC, "A31" , NULL , 0. }, - { GMSH_FULLRC, "A32" , NULL , 0. }, - { GMSH_FULLRC, "A33" , NULL , 1. }, - { GMSH_FULLRC, "iView" , NULL , -1. } + {GMSH_FULLRC, "A11", NULL, 1.}, + {GMSH_FULLRC, "A12", NULL, 0.}, + {GMSH_FULLRC, "A13", NULL, 0.}, + {GMSH_FULLRC, "A21", NULL, 0.}, + {GMSH_FULLRC, "A22", NULL, 1.}, + {GMSH_FULLRC, "A23", NULL, 0.}, + {GMSH_FULLRC, "A31", NULL, 0.}, + {GMSH_FULLRC, "A32", NULL, 0.}, + {GMSH_FULLRC, "A33", NULL, 1.}, + {GMSH_FULLRC, "iView", NULL, -1.} }; extern "C" { - GMSH_Plugin *GMSH_RegisterTransformPlugin () + GMSH_Plugin *GMSH_RegisterTransformPlugin() { - return new GMSH_TransformPlugin (); + return new GMSH_TransformPlugin(); } } GMSH_TransformPlugin::GMSH_TransformPlugin() { + ; } void GMSH_TransformPlugin::getName(char *name) const { - strcpy(name,"Transform"); + strcpy(name, "Transform"); } -void GMSH_TransformPlugin::getInfos(char *author, char *copyright, char *help_text) const +void GMSH_TransformPlugin::getInfos(char *author, char *copyright, + char *help_text) const { strcpy(author, "C. Geuzaine (geuz@geuz.org)"); strcpy(copyright, "DGR (www.multiphysics.com)"); - strcpy(help_text, - "Transforms a view by the matrix\n" - "[ [A11 A12 A13] [A21 A22 A23] [A31 A32 A33] ].\n" - "Script name: Plugin(Transform)."); + strcpy(help_text, + "Transforms a view by the matrix\n" + "[ [A11 A12 A13] [A21 A22 A23] [A31 A32 A33] ].\n" + "Script name: Plugin(Transform)."); } int GMSH_TransformPlugin::getNbOptions() const { - return sizeof(TransformOptions_Number)/sizeof(StringXNumber); + return sizeof(TransformOptions_Number) / sizeof(StringXNumber); } -StringXNumber *GMSH_TransformPlugin:: GetOption (int iopt) +StringXNumber *GMSH_TransformPlugin::GetOption(int iopt) { return &TransformOptions_Number[iopt]; } -void GMSH_TransformPlugin::CatchErrorMessage (char *errorMessage) const +void GMSH_TransformPlugin::CatchErrorMessage(char *errorMessage) const { - strcpy(errorMessage,"Transform failed..."); + strcpy(errorMessage, "Transform failed..."); } -Post_View *GMSH_TransformPlugin::execute (Post_View *v) +Post_View *GMSH_TransformPlugin::execute(Post_View * v) { Post_View *vv; double mat[3][3]; @@ -102,24 +104,26 @@ Post_View *GMSH_TransformPlugin::execute (Post_View *v) if(v && iView < 0) vv = v; - else{ - if(!v && iView < 0) iView = 0; - if(!(vv = (Post_View*)List_Pointer_Test(CTX.post.list,iView))){ - Msg(WARNING,"View[%d] does not exist",iView); + else { + if(!v && iView < 0) + iView = 0; + if(!(vv = (Post_View *) List_Pointer_Test(CTX.post.list, iView))) { + Msg(WARNING, "View[%d] does not exist", iView); return 0; } } - + vv->transform(mat); vv->Changed = 1; return vv; } -void GMSH_TransformPlugin::Run () +void GMSH_TransformPlugin::Run() { execute(0); } -void GMSH_TransformPlugin::Save () +void GMSH_TransformPlugin::Save() { + ; } diff --git a/Plugin/Triangulate.cpp b/Plugin/Triangulate.cpp index 49af6dac99d5287c4ba8e86f1789854672bfbb8a..a514648e42a9f24749a24b93c3f84a98e2b1be62 100644 --- a/Plugin/Triangulate.cpp +++ b/Plugin/Triangulate.cpp @@ -1,4 +1,4 @@ -// $Id: Triangulate.cpp,v 1.9 2003-02-12 00:52:39 geuzaine Exp $ +// $Id: Triangulate.cpp,v 1.10 2003-03-01 22:36:44 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -36,12 +36,12 @@ extern Context_T CTX; StringXNumber TriangulateOptions_Number[] = { - { GMSH_FULLRC, "iView" , NULL , -1. } + {GMSH_FULLRC, "iView", NULL, -1.} }; extern "C" { - GMSH_Plugin *GMSH_RegisterTriangulatePlugin () + GMSH_Plugin *GMSH_RegisterTriangulatePlugin() { return new GMSH_TriangulatePlugin(); } @@ -49,41 +49,44 @@ extern "C" GMSH_TriangulatePlugin::GMSH_TriangulatePlugin() { + ; } void GMSH_TriangulatePlugin::getName(char *name) const { - strcpy(name,"Triangulate"); + strcpy(name, "Triangulate"); } -void GMSH_TriangulatePlugin::getInfos(char *author, char *copyright, char *help_text) const +void GMSH_TriangulatePlugin::getInfos(char *author, char *copyright, + char *help_text) const { strcpy(author, "C. Geuzaine (geuz@geuz.org)"); strcpy(copyright, "DGR (www.multiphysics.com)"); - strcpy(help_text, - "Triangulates a scalar point view\n" - "and outputs a scalar triangle view.\n" - "Script name: Plugin(Triangulate).\n"); + strcpy(help_text, + "Triangulates a scalar point view\n" + "and outputs a scalar triangle view.\n" + "Script name: Plugin(Triangulate).\n"); } int GMSH_TriangulatePlugin::getNbOptions() const { - return sizeof(TriangulateOptions_Number)/sizeof(StringXNumber); + return sizeof(TriangulateOptions_Number) / sizeof(StringXNumber); } -StringXNumber *GMSH_TriangulatePlugin:: GetOption (int iopt) +StringXNumber *GMSH_TriangulatePlugin::GetOption(int iopt) { return &TriangulateOptions_Number[iopt]; } -void GMSH_TriangulatePlugin::CatchErrorMessage (char *errorMessage) const +void GMSH_TriangulatePlugin::CatchErrorMessage(char *errorMessage) const { - strcpy(errorMessage,"Triangulate failed..."); + strcpy(errorMessage, "Triangulate failed..."); } #if !defined(HAVE_TRIANGLE) -void Triangulate(Post_View *vin, Post_View *vout){ +void Triangulate(Post_View * vin, Post_View * vout) +{ Msg(GERROR, "Triangle is not compiled in this version of Gmsh"); } @@ -92,66 +95,67 @@ void Triangulate(Post_View *vin, Post_View *vout){ #define ANSI_DECLARATORS #define REAL double -extern "C" { +extern "C" +{ #include "triangle.h" } -void Triangulate(Post_View *vin, Post_View *vout){ - int nb, i, j=0, j0, j1, j2; +void Triangulate(Post_View * vin, Post_View * vout) +{ + int nb, i, j = 0, j0, j1, j2; Surface *s; Vertex *v; struct triangulateio in, out; - List_T *points = List_Create(vin->NbSP,1,sizeof(Vertex*)); - nb = List_Nbr(vin->SP)/vin->NbSP ; + List_T *points = List_Create(vin->NbSP, 1, sizeof(Vertex *)); + nb = List_Nbr(vin->SP) / vin->NbSP; - for(i = 0 ; i < List_Nbr(vin->SP) ; i+=nb){ + for(i = 0; i < List_Nbr(vin->SP); i += nb) { v = Create_Vertex(j++, - *(double*)List_Pointer_Fast(vin->SP,i), - *(double*)List_Pointer_Fast(vin->SP,i+1), - *(double*)List_Pointer_Fast(vin->SP,i+2), - 1., 0.); + *(double *)List_Pointer_Fast(vin->SP, i), + *(double *)List_Pointer_Fast(vin->SP, i + 1), + *(double *)List_Pointer_Fast(vin->SP, i + 2), 1., 0.); List_Add(points, &v); } - s = Create_Surface(1,MSH_SURF_PLAN); + s = Create_Surface(1, MSH_SURF_PLAN); MeanPlane(points, s); - for(i=0;i<List_Nbr(points);i++){ + for(i = 0; i < List_Nbr(points); i++) { List_Read(points, i, &v); - Projette (v, s->plan); + Projette(v, s->plan); } - Free_Surface(&s,NULL); + Free_Surface(&s, NULL); in.numberofpoints = List_Nbr(points); in.pointlist = (REAL *) Malloc(in.numberofpoints * 2 * sizeof(REAL)); in.numberofpointattributes = 0; in.pointattributelist = NULL; - in.pointmarkerlist = NULL; + in.pointmarkerlist = NULL; in.numberofsegments = 0; - in.segmentlist = NULL; + in.segmentlist = NULL; in.segmentmarkerlist = NULL; in.numberofregions = 0; - in.regionlist = NULL; + in.regionlist = NULL; in.numberofholes = 0; in.holelist = NULL; - j=0; - for(i=0;i<List_Nbr(points);i++){ + j = 0; + for(i = 0; i < List_Nbr(points); i++) { List_Read(points, i, &v); in.pointlist[j] = v->Pos.X; - in.pointlist[j+1] = v->Pos.Y; - j+=2; + in.pointlist[j + 1] = v->Pos.Y; + j += 2; } - for(i=0;i<List_Nbr(points);i++){ + for(i = 0; i < List_Nbr(points); i++) { List_Read(points, i, &v); - Free_Vertex(&v,NULL); + Free_Vertex(&v, NULL); } List_Delete(points); - out.pointlist = NULL; + out.pointlist = NULL; out.pointattributelist = NULL; out.pointmarkerlist = NULL; out.trianglelist = NULL; @@ -162,26 +166,27 @@ void Triangulate(Post_View *vin, Post_View *vout){ out.edgelist = NULL; out.edgemarkerlist = NULL; - char opts[128]="z"; - if(CTX.verbosity < 3) strcat(opts, "Q"); + char opts[128] = "z"; + if(CTX.verbosity < 3) + strcat(opts, "Q"); triangulate(opts, &in, &out, NULL); Free(in.pointlist); Free(out.pointlist); - for (i = 0; i < out.numberoftriangles; i++) { + for(i = 0; i < out.numberoftriangles; i++) { j0 = out.trianglelist[i * out.numberofcorners + 0]; j1 = out.trianglelist[i * out.numberofcorners + 1]; j2 = out.trianglelist[i * out.numberofcorners + 2]; - for(j=0;j<3;j++){ - List_Add(vout->ST, List_Pointer(vin->SP,(j0*nb)+j)); - List_Add(vout->ST, List_Pointer(vin->SP,(j1*nb)+j)); - List_Add(vout->ST, List_Pointer(vin->SP,(j2*nb)+j)); + for(j = 0; j < 3; j++) { + List_Add(vout->ST, List_Pointer(vin->SP, (j0 * nb) + j)); + List_Add(vout->ST, List_Pointer(vin->SP, (j1 * nb) + j)); + List_Add(vout->ST, List_Pointer(vin->SP, (j2 * nb) + j)); } - for(j=0;j<vin->NbTimeStep;j++){ - List_Add(vout->ST, List_Pointer(vin->SP,(j0*nb)+3+j)); - List_Add(vout->ST, List_Pointer(vin->SP,(j1*nb)+3+j)); - List_Add(vout->ST, List_Pointer(vin->SP,(j2*nb)+3+j)); + for(j = 0; j < vin->NbTimeStep; j++) { + List_Add(vout->ST, List_Pointer(vin->SP, (j0 * nb) + 3 + j)); + List_Add(vout->ST, List_Pointer(vin->SP, (j1 * nb) + 3 + j)); + List_Add(vout->ST, List_Pointer(vin->SP, (j2 * nb) + 3 + j)); } vout->NbST++; } @@ -192,7 +197,7 @@ void Triangulate(Post_View *vin, Post_View *vout){ #endif // !HAVE_TRIANGLE -Post_View *GMSH_TriangulatePlugin::execute (Post_View *v) +Post_View *GMSH_TriangulatePlugin::execute(Post_View * v) { Post_View *vv, *View; @@ -200,36 +205,38 @@ Post_View *GMSH_TriangulatePlugin::execute (Post_View *v) if(v && iView < 0) vv = v; - else{ - if(!v && iView < 0) iView = 0; - if(!(vv = (Post_View*)List_Pointer_Test(CTX.post.list,iView))){ - Msg(WARNING,"View[%d] does not exist",iView); + else { + if(!v && iView < 0) + iView = 0; + if(!(vv = (Post_View *) List_Pointer_Test(CTX.post.list, iView))) { + Msg(WARNING, "View[%d] does not exist", iView); return 0; } } - if(vv->NbSP > 2){ + if(vv->NbSP > 2) { View = BeginView(1); - Triangulate(vv,View); + Triangulate(vv, View); char name[1024], filename[1024]; - sprintf(name,"triangulate-%s",vv->Name); - sprintf(filename,"triangulate-%s",vv->FileName); + sprintf(name, "triangulate-%s", vv->Name); + sprintf(filename, "triangulate-%s", vv->FileName); EndView(View, 1, filename, name); Msg(INFO, "Created view '%s'", name); return View; } - else{ + else { Msg(WARNING, "No scalar points to triangulate in view '%s'", vv->Name); return 0; } } -void GMSH_TriangulatePlugin::Run () +void GMSH_TriangulatePlugin::Run() { execute(0); } -void GMSH_TriangulatePlugin::Save () +void GMSH_TriangulatePlugin::Save() { + ; } diff --git a/doc/README.devel b/doc/README.devel index 30153fc6bedefb95e4e54d87a752a938e125e495..8932dbd3226f34e70cf4dacd6db2aa2f694214c3 100644 --- a/doc/README.devel +++ b/doc/README.devel @@ -3,7 +3,8 @@ Some easy rules to make the code easy to read/debug/maintain: - please enable full warnings for your compiler (e.g. gcc -Wall) - always use Msg() to print information/errors/etc. -- indent your files and, if working on Windows, suppress the tabs (untabify) +- indent your files using ../utils/gmshindent +- if working on Windows, don't leave tabs in your files (../utils/untabify) How to add an option in the graphical user interface? diff --git a/doc/README.indent b/doc/README.indent index d24c8680cc57d6487f5110029b64d8a7e397f17f..5383d8aee329e0a7c769b419bd1a598e5fd6d8a0 100644 --- a/doc/README.indent +++ b/doc/README.indent @@ -1,8 +1,9 @@ -All code should be preferably formatted using: +All code should be preferably formatted using ../utils/gmshindent -indent --braces-on-if-line --cuddle-do-while --honour-newlines --no-space-after-casts --no-space-after-function-call-names --no-space-after-for --no-space-after-if --no-space-after-while --no-tabs --dont-format-comments --comment-indentation1 */*.cpp +indent --braces-on-if-line --cuddle-do-while --honour-newlines --no-space-after-casts --no-space-after-function-call-names --no-space-after-for --no-space-after-if --no-space-after-while --no-tabs --dont-format-comments --comment-indentation1 --dont-break-procedure-type */*.cpp -Do we want the return type on the same line as the function name? Then, use ---dont-break-procedure-type \ No newline at end of file +If we don't want the return type on the same line as the function name, just remove + +--dont-break-procedure-type diff --git a/doc/VERSIONS b/doc/VERSIONS index ed58fd02e59cf254d4fe4321eec83135d6db6136..5081e0a8a8194323a7582800e01fc147a76e6b9d 100644 --- a/doc/VERSIONS +++ b/doc/VERSIONS @@ -1,4 +1,6 @@ -$Date: 2003-03-01 22:24:06 $ +$Date: 2003-03-01 22:36:44 $ + +New in 1.41: general code cleanup (indent); New in 1.40: various small bug fixes (mainly GSL-related); diff --git a/doc/gmsh.html b/doc/gmsh.html index 0ddb8760c6cab081a5b4e283b9d80bda3655e38f..20493cc3eef6a658cf61339365ba7763bc9efc3a 100644 --- a/doc/gmsh.html +++ b/doc/gmsh.html @@ -26,7 +26,7 @@ generator with built-in pre- and post-processing facilities</h1> <p> <h3 align="center">Christophe Geuzaine and Jean-Fran�ois Remacle</h3> <p> -<h3 align=center>Version <a href="doc/VERSIONS">1.40</a>, ? March 2003</h3> +<h3 align=center>Version <a href="doc/VERSIONS">1.41</a>, ? March 2003</h3> <p> <center> <a href="#Description">Description</a> | @@ -203,18 +203,18 @@ available for Windows, Mac OS X and Linux. The tutorial and demo files are included in the archives. <ul> -<li><a href="/gmsh/bin/gmsh-1.40.0-Windows.zip">Windows zip archive (95/98/NT/XP)</a> -<li><a href="/gmsh/bin/gmsh-1.40.0-1.i386.rpm">Linux RPM (i386, Red Hat >= 6.2 and compatible)</a> -<li><a href="/gmsh/bin/gmsh-1.40.0-Linux.tgz">Linux tarball (i386, glibc 2.1)</a> -<li><a href="/gmsh/bin/gmsh-1.40.0-MacOSX.tgz">Mac OS X tarball (Mac OS X 10.2)</a> -<li><a href="/gmsh/bin/gmsh-1.40.0-source.tgz">Source tarball</a> +<li><a href="/gmsh/bin/gmsh-1.41.0-Windows.zip">Windows zip archive (95/98/NT/XP)</a> +<li><a href="/gmsh/bin/gmsh-1.41.0-1.i386.rpm">Linux RPM (i386, Red Hat >= 6.2 and compatible)</a> +<li><a href="/gmsh/bin/gmsh-1.41.0-Linux.tgz">Linux tarball (i386, glibc 2.1)</a> +<li><a href="/gmsh/bin/gmsh-1.41.0-MacOSX.tgz">Mac OS X tarball (Mac OS X 10.2)</a> +<li><a href="/gmsh/bin/gmsh-1.41.0-source.tgz">Source tarball</a> <a href="#fltk-footnote" name="fltk-footmark"><sup>2</sup></a> <!-- -<li><a href="/gmsh/bin/gmsh-1.40.0-OSF1.tgz">Compaq Tru64 tarball (OSF 4.0)</a> -<li><a href="/gmsh/bin/gmsh-1.40.0-SunOS.tgz">Sun tarball (SunOS 5.8)</a> -<li><a href="/gmsh/bin/gmsh-1.40.0-AIX.tgz">IBM tarball (AIX)</a> -<li><a href="/gmsh/bin/gmsh-1.40.0-IRIX.tgz">SGI IRIX tarball (IRIX 6.5)</a> -<li><a href="/gmsh/bin/gmsh-1.40.0-HP-UX.tgz">HP tarball (HPUX 10.20)</a> +<li><a href="/gmsh/bin/gmsh-1.41.0-OSF1.tgz">Compaq Tru64 tarball (OSF 4.0)</a> +<li><a href="/gmsh/bin/gmsh-1.41.0-SunOS.tgz">Sun tarball (SunOS 5.8)</a> +<li><a href="/gmsh/bin/gmsh-1.41.0-AIX.tgz">IBM tarball (AIX)</a> +<li><a href="/gmsh/bin/gmsh-1.41.0-IRIX.tgz">SGI IRIX tarball (IRIX 6.5)</a> +<li><a href="/gmsh/bin/gmsh-1.41.0-HP-UX.tgz">HP tarball (HPUX 10.20)</a> --> </ul> <p> diff --git a/utils/GmshClient.c b/utils/GmshClient.c index 3d42ca01aab090b08180ba647b38a3d53df4410c..f9c0cb5f072ae9726067cf5a76127cfa082bc2aa 100644 --- a/utils/GmshClient.c +++ b/utils/GmshClient.c @@ -1,4 +1,4 @@ -/* $Id: GmshClient.c,v 1.4 2003-01-23 20:19:26 geuzaine Exp $ */ +/* $Id: GmshClient.c,v 1.5 2003-03-01 22:36:44 geuzaine Exp $ */ /* Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle @@ -35,35 +35,40 @@ /* private functions */ -static void Socket_SendData(int socket, void *buffer, int bytes){ +static void Socket_SendData(int socket, void *buffer, int bytes) +{ int sofar, remaining, len; char *buf; - buf = (char*)buffer; + buf = (char *)buffer; sofar = 0; remaining = bytes; do { len = write(socket, buf + sofar, remaining); sofar += len; remaining -= len; - } while (remaining>0); + } while(remaining > 0); } -static long Socket_GetTime(){ +static long Socket_GetTime() +{ struct timeval tp; gettimeofday(&tp, (struct timezone *)0); return (long)tp.tv_sec * 1000000 + (long)tp.tv_usec; } -static void Socket_Idle(double delay){ +static void Socket_Idle(double delay) +{ long t1 = Socket_GetTime(); - while(1){ - if(Socket_GetTime() - t1 > 1.e6*delay) break; + while(1) { + if(Socket_GetTime() - t1 > 1.e6 * delay) + break; } } /* public interface */ -int Gmsh_Connect(char *sockname){ +int Gmsh_Connect(char *sockname) +{ struct sockaddr_un addr; int len, sock; int tries; @@ -74,27 +79,30 @@ int Gmsh_Connect(char *sockname){ /* create socket */ sock = socket(PF_UNIX, SOCK_STREAM, 0); - if (sock<0) return -1; /* Error: Couldn't create socket */ + if(sock < 0) + return -1; /* Error: Couldn't create socket */ /* try to connect socket to given name */ strcpy(addr.sun_path, sockname); addr.sun_family = AF_UNIX; - len = strlen(addr.sun_path)+sizeof(addr.sun_family); - for (tries=0;tries<5;tries++) { - if (connect(sock, (struct sockaddr *)&addr, len) >= 0) return sock; + len = strlen(addr.sun_path) + sizeof(addr.sun_family); + for(tries = 0; tries < 5; tries++) { + if(connect(sock, (struct sockaddr *)&addr, len) >= 0) + return sock; } - - return -2; /* Error: Couldn't connect */ + + return -2; /* Error: Couldn't connect */ } -void Gmsh_SendString(int socket, int type, char str[]){ +void Gmsh_SendString(int socket, int type, char str[]) +{ int len = strlen(str); Socket_SendData(socket, &type, sizeof(int)); Socket_SendData(socket, &len, sizeof(int)); Socket_SendData(socket, str, len); } -void Gmsh_Disconnect(int sock){ +void Gmsh_Disconnect(int sock) +{ close(sock); } - diff --git a/utils/dxf2geo.c b/utils/dxf2geo.c index b0aa107afe578cd7bed88d79fdca834f9a927f94..3f979bd99ce2b94cecbf4e260233db622ec3896f 100644 --- a/utils/dxf2geo.c +++ b/utils/dxf2geo.c @@ -1,4 +1,4 @@ -// $Id: dxf2geo.c,v 1.3 2003-02-25 16:53:16 geuzaine Exp $ +// $Id: dxf2geo.c,v 1.4 2003-03-01 22:36:44 geuzaine Exp $ // // Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle // @@ -42,439 +42,578 @@ #define GEOTRI 3 #define GEOQUAD 4 -FILE *infile, *outfile; -char inname[80], outname[80], curobj[80], linbuf[BUFSIZE]; -long primitives = 0L, degenerates = 0L; -int groupcode, curcolor, ints[10], nump=1 , numc=1; -int cpt_vert_node=1, num_vert_node[1024]; -float curthick, xcoords[10], ycoords[10], zcoords[10], floats[10], angles[10]; -float max_x, max_y, max_z, min_x, min_y, min_z ; -float THETOL, THEROT=0., THETRANSX=0., THETRANSY=0. ; -Tree_T *Point_T, *Curve_T ; - -struct Point { - int num ; - float x,y,z ; -} ; - -int fcmpPoint (const void *a, const void *b){ - struct Point *q,*w; - - q = (struct Point*)a; - w = (struct Point*)b; - +FILE *infile, *outfile; +char inname[80], outname[80], curobj[80], linbuf[BUFSIZE]; +long primitives = 0L, degenerates = 0L; +int groupcode, curcolor, ints[10], nump = 1, numc = 1; +int cpt_vert_node = 1, num_vert_node[1024]; +float curthick, xcoords[10], ycoords[10], zcoords[10], floats[10], angles[10]; +float max_x, max_y, max_z, min_x, min_y, min_z; +float THETOL, THEROT = 0., THETRANSX = 0., THETRANSY = 0.; +Tree_T *Point_T, *Curve_T; + +struct Point +{ + int num; + float x, y, z; +}; + +int fcmpPoint(const void *a, const void *b) +{ + struct Point *q, *w; + + q = (struct Point *)a; + w = (struct Point *)b; + if(fabs(q->x - w->x) < THETOL && - fabs(q->y - w->y) < THETOL && - fabs(q->z - w->z) < THETOL) return 0; - - if(q->x > w->x) return(1); - if(q->x < w->x) return(-1); - if(q->y > w->y) return(1); - if(q->y < w->y) return(-1); - if(q->z > w->z) return(1); - if(q->z < w->z) return(-1); + fabs(q->y - w->y) < THETOL && fabs(q->z - w->z) < THETOL) + return 0; + + if(q->x > w->x) + return (1); + if(q->x < w->x) + return (-1); + if(q->y > w->y) + return (1); + if(q->y < w->y) + return (-1); + if(q->z > w->z) + return (1); + if(q->z < w->z) + return (-1); } -int addpoint(struct Point *p){ - struct Point *pp ; +int addpoint(struct Point *p) +{ + struct Point *pp; - if((pp = (struct Point*)Tree_PQuery(Point_T, p))) - return pp->num ; + if((pp = (struct Point *)Tree_PQuery(Point_T, p))) + return pp->num; - p->num = nump++ ; - Tree_Add(Point_T, p) ; - return p->num ; + p->num = nump++; + Tree_Add(Point_T, p); + return p->num; } -void writepoint(void *a, void *b){ - struct Point *p ; - float x, y ; +void writepoint(void *a, void *b) +{ + struct Point *p; + float x, y; + + p = (struct Point *)a; - p = (struct Point *) a ; + x = p->x; + y = p->y; - x = p->x ; - y = p->y ; - - p->x = cos(-THEROT*DEG2RAD) * x + sin(-THEROT*DEG2RAD) * y ; - p->y = -sin(-THEROT*DEG2RAD) * x + cos(-THEROT*DEG2RAD) * y; + p->x = cos(-THEROT * DEG2RAD) * x + sin(-THEROT * DEG2RAD) * y; + p->y = -sin(-THEROT * DEG2RAD) * x + cos(-THEROT * DEG2RAD) * y; - p->x += THETRANSX ; - p->y += THETRANSY ; + p->x += THETRANSX; + p->y += THETRANSY; - fprintf(outfile, "Point (%d) = {%g *u, %g *u, %g *u, lc} ;\n", - p->num, p->x, p->y, p->z) ; + fprintf(outfile, "Point (%d) = {%g *u, %g *u, %g *u, lc} ;\n", + p->num, p->x, p->y, p->z); } -struct Curve { - int num, type, a, b, c ; -} ; +struct Curve +{ + int num, type, a, b, c; +}; -int fcmpCurve (const void *a, const void *b){ - struct Curve *q,*w; +int fcmpCurve(const void *a, const void *b) +{ + struct Curve *q, *w; - q = (struct Curve*)a; - w = (struct Curve*)b; + q = (struct Curve *)a; + w = (struct Curve *)b; - if(q->num < w->num) return(-1); - return(1); + if(q->num < w->num) + return (-1); + return (1); } -void addcurve(struct Curve *c){ - c->num = numc++ ; - Tree_Add(Curve_T, c) ; +void addcurve(struct Curve *c) +{ + c->num = numc++; + Tree_Add(Curve_T, c); } -void writecurve(void *a, void *b){ - struct Curve *c ; +void writecurve(void *a, void *b) +{ + struct Curve *c; - c = (struct Curve *) a ; + c = (struct Curve *)a; - switch(c->type){ - case GEOLINE : - fprintf(outfile, "Line (%d) = {%d, %d} ;\n", - c->num, c->a, c->b) ; - break ; - case GEOCIRCLE : + switch (c->type) { + case GEOLINE: + fprintf(outfile, "Line (%d) = {%d, %d} ;\n", c->num, c->a, c->b); + break; + case GEOCIRCLE: fprintf(outfile, "Circle (%d) = {%d, %d, %d} ;\n", - c->num, c->a, c->b, c->c) ; - break ; + c->num, c->a, c->b, c->c); + break; } } -int checkdegen(int a, int b, int c){ /* check for degenerate triangle structure */ - if ( (xcoords[a] == xcoords[b] && - ycoords[a] == ycoords[b] && - zcoords[a] == zcoords[b]) || - (xcoords[b] == xcoords[c] && - ycoords[b] == ycoords[c] && - zcoords[b] == zcoords[c]) || - (xcoords[a] == xcoords[c] && - ycoords[a] == ycoords[c] && - zcoords[a] == zcoords[c]) ) - return(1); - return(0); +int checkdegen(int a, int b, int c) +{ /* check for degenerate triangle structure */ + if((xcoords[a] == xcoords[b] && + ycoords[a] == ycoords[b] && + zcoords[a] == zcoords[b]) || + (xcoords[b] == xcoords[c] && + ycoords[b] == ycoords[c] && + zcoords[b] == zcoords[c]) || + (xcoords[a] == xcoords[c] && + ycoords[a] == ycoords[c] && zcoords[a] == zcoords[c])) + return (1); + return (0); } -void addobj(void){ /* dump out current object we should have all info on */ - struct Point p, *pp ; - struct Curve c ; - int num[10]; - float tmp ; - - if (strstr(curobj, "POINT")){ - p.x = xcoords[0] ; p.y = ycoords[0] ; p.z = zcoords[0] ; addpoint(&p) ; +void addobj(void) +{ /* dump out current object we should have all info on */ + struct Point p, *pp; + struct Curve c; + int num[10]; + float tmp; + + if(strstr(curobj, "POINT")) { + p.x = xcoords[0]; + p.y = ycoords[0]; + p.z = zcoords[0]; + addpoint(&p); } - else if (strstr(curobj, "LINE") || strstr(curobj, "3DLINE")){ - if (xcoords[0] == xcoords[1] && ycoords[0] == ycoords[1] && zcoords[0] == zcoords[1]){ + else if(strstr(curobj, "LINE") || strstr(curobj, "3DLINE")) { + if(xcoords[0] == xcoords[1] && ycoords[0] == ycoords[1] + && zcoords[0] == zcoords[1]) { degenerates++; return; } - p.x = xcoords[0] ; p.y = ycoords[0] ; p.z = zcoords[0] ; num[0] = addpoint(&p) ; - p.x = xcoords[1] ; p.y = ycoords[1] ; p.z = zcoords[1] ; num[1] = addpoint(&p) ; - c.type = GEOLINE ; c.a = num[0] ; c.b = num[1] ; addcurve(&c) ; + p.x = xcoords[0]; + p.y = ycoords[0]; + p.z = zcoords[0]; + num[0] = addpoint(&p); + p.x = xcoords[1]; + p.y = ycoords[1]; + p.z = zcoords[1]; + num[1] = addpoint(&p); + c.type = GEOLINE; + c.a = num[0]; + c.b = num[1]; + addcurve(&c); } - else if (strstr(curobj, "CIRCLE")){ - p.x = xcoords[0] ; p.y = ycoords[0] ; p.z = zcoords[0] ; num[0] = addpoint(&p) ; - p.x = xcoords[0]-floats[0] ; p.y = ycoords[0] ; p.z = zcoords[0] ; - num[1] = addpoint(&p) ; - p.x = xcoords[0]+floats[0] ; p.y = ycoords[0] ; p.z = zcoords[0] ; - num[2] = addpoint(&p) ; - p.x = xcoords[0] ; p.y = ycoords[0]-floats[0] ; p.z = zcoords[0] ; - num[3] = addpoint(&p) ; - p.x = xcoords[0] ; p.y = ycoords[0]+floats[0] ; p.z = zcoords[0] ; - num[4] = addpoint(&p) ; - c.type = GEOCIRCLE ; c.a = num[2] ; c.b = num[0] ; c.c = num[4]; addcurve(&c) ; - c.type = GEOCIRCLE ; c.a = num[4] ; c.b = num[0] ; c.c = num[1]; addcurve(&c) ; - c.type = GEOCIRCLE ; c.a = num[1] ; c.b = num[0] ; c.c = num[3]; addcurve(&c) ; - c.type = GEOCIRCLE ; c.a = num[3] ; c.b = num[0] ; c.c = num[2]; addcurve(&c) ; + else if(strstr(curobj, "CIRCLE")) { + p.x = xcoords[0]; + p.y = ycoords[0]; + p.z = zcoords[0]; + num[0] = addpoint(&p); + p.x = xcoords[0] - floats[0]; + p.y = ycoords[0]; + p.z = zcoords[0]; + num[1] = addpoint(&p); + p.x = xcoords[0] + floats[0]; + p.y = ycoords[0]; + p.z = zcoords[0]; + num[2] = addpoint(&p); + p.x = xcoords[0]; + p.y = ycoords[0] - floats[0]; + p.z = zcoords[0]; + num[3] = addpoint(&p); + p.x = xcoords[0]; + p.y = ycoords[0] + floats[0]; + p.z = zcoords[0]; + num[4] = addpoint(&p); + c.type = GEOCIRCLE; + c.a = num[2]; + c.b = num[0]; + c.c = num[4]; + addcurve(&c); + c.type = GEOCIRCLE; + c.a = num[4]; + c.b = num[0]; + c.c = num[1]; + addcurve(&c); + c.type = GEOCIRCLE; + c.a = num[1]; + c.b = num[0]; + c.c = num[3]; + addcurve(&c); + c.type = GEOCIRCLE; + c.a = num[3]; + c.b = num[0]; + c.c = num[2]; + addcurve(&c); } - else if (strstr(curobj, "ARC")){ - p.x = xcoords[0] ; p.y = ycoords[0] ; p.z = zcoords[0] ; num[0] = addpoint(&p) ; - - p.x = xcoords[0]+floats[0]*cos(angles[0]*DEG2RAD) ; - p.y = ycoords[0]+floats[0]*sin(angles[0]*DEG2RAD) ; - p.z = zcoords[0] ; num[1] = addpoint(&p) ; - - p.x = xcoords[0]+floats[0]*cos(angles[1]*DEG2RAD) ; - p.y = ycoords[0]+floats[0]*sin(angles[1]*DEG2RAD) ; - p.z = zcoords[0] ; num[2] = addpoint(&p) ; - - if((angles[1]-angles[0] > 0 && angles[1]-angles[0] < 180) || - (angles[1]-angles[0] < 0 && angles[1]-angles[0] < -180)){ - c.type = GEOCIRCLE ; c.a = num[1] ; c.b = num[0] ; c.c = num[2]; addcurve(&c) ; + else if(strstr(curobj, "ARC")) { + p.x = xcoords[0]; + p.y = ycoords[0]; + p.z = zcoords[0]; + num[0] = addpoint(&p); + + p.x = xcoords[0] + floats[0] * cos(angles[0] * DEG2RAD); + p.y = ycoords[0] + floats[0] * sin(angles[0] * DEG2RAD); + p.z = zcoords[0]; + num[1] = addpoint(&p); + + p.x = xcoords[0] + floats[0] * cos(angles[1] * DEG2RAD); + p.y = ycoords[0] + floats[0] * sin(angles[1] * DEG2RAD); + p.z = zcoords[0]; + num[2] = addpoint(&p); + + if((angles[1] - angles[0] > 0 && angles[1] - angles[0] < 180) || + (angles[1] - angles[0] < 0 && angles[1] - angles[0] < -180)) { + c.type = GEOCIRCLE; + c.a = num[1]; + c.b = num[0]; + c.c = num[2]; + addcurve(&c); } - else{ - if(angles[1]-angles[0] > 0){ - p.x = xcoords[0]+floats[0]*cos((angles[1]-angles[0])*0.5*DEG2RAD) ; - p.y = ycoords[0]+floats[0]*sin((angles[1]-angles[0])*0.5*DEG2RAD) ; + else { + if(angles[1] - angles[0] > 0) { + p.x = + xcoords[0] + + floats[0] * cos((angles[1] - angles[0]) * 0.5 * DEG2RAD); + p.y = + ycoords[0] + + floats[0] * sin((angles[1] - angles[0]) * 0.5 * DEG2RAD); } - else{ - p.x = xcoords[0]+floats[0]*cos((angles[0]-angles[1])*0.5*DEG2RAD) ; - p.y = ycoords[0]+floats[0]*sin((angles[0]-angles[1])*0.5*DEG2RAD) ; + else { + p.x = + xcoords[0] + + floats[0] * cos((angles[0] - angles[1]) * 0.5 * DEG2RAD); + p.y = + ycoords[0] + + floats[0] * sin((angles[0] - angles[1]) * 0.5 * DEG2RAD); } - p.z = zcoords[0] ; num[3] = addpoint(&p) ; - c.type = GEOCIRCLE ; c.a = num[1] ; c.b = num[0] ; c.c = num[3]; addcurve(&c) ; - c.type = GEOCIRCLE ; c.a = num[3] ; c.b = num[0] ; c.c = num[2]; addcurve(&c) ; + p.z = zcoords[0]; + num[3] = addpoint(&p); + c.type = GEOCIRCLE; + c.a = num[1]; + c.b = num[0]; + c.c = num[3]; + addcurve(&c); + c.type = GEOCIRCLE; + c.a = num[3]; + c.b = num[0]; + c.c = num[2]; + addcurve(&c); } } - else if (strstr(curobj, "TRACE")){ /* 2 back-to-back triangles */ - if (checkdegen(0, 1, 2)){ + else if(strstr(curobj, "TRACE")) { /* 2 back-to-back triangles */ + if(checkdegen(0, 1, 2)) { degenerates++; return; } /* add triangle 0, 1, 2 */ - - if (checkdegen(0, 3, 2)){ + + if(checkdegen(0, 3, 2)) { degenerates++; return; } /* add triangle 0 3 2 */ } - else if (strstr(curobj, "SOLID")){ /* 1 or 2 triangles */ - if (checkdegen(0, 1, 2)){ + else if(strstr(curobj, "SOLID")) { /* 1 or 2 triangles */ + if(checkdegen(0, 1, 2)) { degenerates++; return; } /* add triangle 0, 1, 2 */ - if (xcoords[2] == xcoords[3] && ycoords[2] == ycoords[3] && zcoords[2] == zcoords[3]) - return; /* one triangle was enough... */ - - if (checkdegen(0, 3, 2)){ + if(xcoords[2] == xcoords[3] && ycoords[2] == ycoords[3] + && zcoords[2] == zcoords[3]) + return; /* one triangle was enough... */ + + if(checkdegen(0, 3, 2)) { degenerates++; return; } /* add triangle 0 3 2 */ } - else if (strstr(curobj, "TEXT")){ /* not implemented for now */ + else if(strstr(curobj, "TEXT")) { /* not implemented for now */ } - else if (strstr(curobj, "SHAPE")){ /* these look very hard */ + else if(strstr(curobj, "SHAPE")) { /* these look very hard */ } - else if (strstr(curobj, "BLOCK")){ /* these look very hard */ + else if(strstr(curobj, "BLOCK")) { /* these look very hard */ } - else if (strstr(curobj, "ENDBLK")){ /* these look very hard */ + else if(strstr(curobj, "ENDBLK")) { /* these look very hard */ } - else if (strstr(curobj, "INSERT")){ /* these look very hard */ + else if(strstr(curobj, "INSERT")) { /* these look very hard */ } - else if (strstr(curobj, "ATTDEF")){ /* not implemented for now */ + else if(strstr(curobj, "ATTDEF")) { /* not implemented for now */ } - else if (strstr(curobj, "ATTRIB")){ /* not implemented for now */ + else if(strstr(curobj, "ATTRIB")) { /* not implemented for now */ } - else if (strstr(curobj, "POLYLINE")){ /* these look fairly hard */ + else if(strstr(curobj, "POLYLINE")) { /* these look fairly hard */ } - else if (strstr(curobj, "VERTEX")){ /* these look fairly hard */ - if (ints[0] == 192) { - p.x = xcoords[0] ; p.y = ycoords[0] ; p.z = zcoords[0] ; - num_vert_node[cpt_vert_node] = addpoint(&p) ; + else if(strstr(curobj, "VERTEX")) { /* these look fairly hard */ + if(ints[0] == 192) { + p.x = xcoords[0]; + p.y = ycoords[0]; + p.z = zcoords[0]; + num_vert_node[cpt_vert_node] = addpoint(&p); // printf("cpt_vert-node = %d : new number = %d\n",cpt_vert_node,num_vert_node[cpt_vert_node]); - cpt_vert_node++ ; + cpt_vert_node++; } - else if (ints[0] == 128) { - c.type = GEOLINE ; c.a = num_vert_node[ints[1]] ; c.b = num_vert_node[ints[2]] ; addcurve(&c) ; - c.type = GEOLINE ; c.a = num_vert_node[ints[2]] ; c.b = num_vert_node[ints[3]] ; addcurve(&c) ; - if (ints[4] == 0 ) { - c.type = GEOLINE ; c.a = num_vert_node[ints[3]] ; c.b = num_vert_node[ints[1]] ; addcurve(&c) ; + else if(ints[0] == 128) { + c.type = GEOLINE; + c.a = num_vert_node[ints[1]]; + c.b = num_vert_node[ints[2]]; + addcurve(&c); + c.type = GEOLINE; + c.a = num_vert_node[ints[2]]; + c.b = num_vert_node[ints[3]]; + addcurve(&c); + if(ints[4] == 0) { + c.type = GEOLINE; + c.a = num_vert_node[ints[3]]; + c.b = num_vert_node[ints[1]]; + addcurve(&c); } else { - c.type = GEOLINE ; c.a = num_vert_node[ints[3]] ; c.b = num_vert_node[ints[4]] ; addcurve(&c) ; - c.type = GEOLINE ; c.a = num_vert_node[ints[4]] ; c.b = num_vert_node[ints[1]] ; addcurve(&c) ; + c.type = GEOLINE; + c.a = num_vert_node[ints[3]]; + c.b = num_vert_node[ints[4]]; + addcurve(&c); + c.type = GEOLINE; + c.a = num_vert_node[ints[4]]; + c.b = num_vert_node[ints[1]]; + addcurve(&c); } } - ints[0]=ints[1]=ints[2]=ints[3]=ints[4]=ints[5]=0; + ints[0] = ints[1] = ints[2] = ints[3] = ints[4] = ints[5] = 0; } - else if (strstr(curobj, "SEQEND")){ /* these look fairly hard */ + else if(strstr(curobj, "SEQEND")) { /* these look fairly hard */ } - else if (strstr(curobj, "3DFACE")){ /* 1 or 2 triangles */ -#if 0 //removed by David Colignon - if (checkdegen(0, 1, 2)){ + else if(strstr(curobj, "3DFACE")) { /* 1 or 2 triangles */ +#if 0 //removed by David Colignon + if(checkdegen(0, 1, 2)) { degenerates++; return; } /* add triangle 0 1 2 */ - - if (xcoords[2] == xcoords[3] && ycoords[2] == ycoords[3] && zcoords[2] == zcoords[3]) - return; /* one triangle was enough... */ - - if (checkdegen(0, 3, 2)){ + + if(xcoords[2] == xcoords[3] && ycoords[2] == ycoords[3] + && zcoords[2] == zcoords[3]) + return; /* one triangle was enough... */ + + if(checkdegen(0, 3, 2)) { degenerates++; return; } /* add triangle 0 3 2 */ -#else - p.x = xcoords[0] ; p.y = ycoords[0] ; p.z = zcoords[0] ; num[0] = addpoint(&p) ; - p.x = xcoords[1] ; p.y = ycoords[1] ; p.z = zcoords[1] ; num[1] = addpoint(&p) ; - p.x = xcoords[2] ; p.y = ycoords[2] ; p.z = zcoords[2] ; num[2] = addpoint(&p) ; - c.type = GEOLINE ; c.a = num[0] ; c.b = num[1] ; addcurve(&c) ; - c.type = GEOLINE ; c.a = num[1] ; c.b = num[2] ; addcurve(&c) ; - if (xcoords[3] == xcoords[2] && ycoords[3] == ycoords[2] && zcoords[3] == zcoords[2]){ - c.type = GEOLINE ; c.a = num[2] ; c.b = num[0] ; addcurve(&c) ; +#else + p.x = xcoords[0]; + p.y = ycoords[0]; + p.z = zcoords[0]; + num[0] = addpoint(&p); + p.x = xcoords[1]; + p.y = ycoords[1]; + p.z = zcoords[1]; + num[1] = addpoint(&p); + p.x = xcoords[2]; + p.y = ycoords[2]; + p.z = zcoords[2]; + num[2] = addpoint(&p); + c.type = GEOLINE; + c.a = num[0]; + c.b = num[1]; + addcurve(&c); + c.type = GEOLINE; + c.a = num[1]; + c.b = num[2]; + addcurve(&c); + if(xcoords[3] == xcoords[2] && ycoords[3] == ycoords[2] + && zcoords[3] == zcoords[2]) { + c.type = GEOLINE; + c.a = num[2]; + c.b = num[0]; + addcurve(&c); } else { - p.x = xcoords[3] ; p.y = ycoords[3] ; p.z = zcoords[3] ; num[3] = addpoint(&p) ; - c.type = GEOLINE ; c.a = num[2] ; c.b = num[3] ; addcurve(&c) ; - c.type = GEOLINE ; c.a = num[3] ; c.b = num[0] ; addcurve(&c) ; - } + p.x = xcoords[3]; + p.y = ycoords[3]; + p.z = zcoords[3]; + num[3] = addpoint(&p); + c.type = GEOLINE; + c.a = num[2]; + c.b = num[3]; + addcurve(&c); + c.type = GEOLINE; + c.a = num[3]; + c.b = num[0]; + addcurve(&c); + } #endif } - else if (strstr(curobj, "DIMENSION")){ /* not implemented for now */ + else if(strstr(curobj, "DIMENSION")) { /* not implemented for now */ } } -int getline(void){ /* read a group code and the next line from infile */ - fgets(linbuf, BUFSIZE, infile); /* get a line from .DXF */ - if (feof(infile)) - return(1); - sscanf(linbuf, "%3d", &groupcode); /* scan out group code */ - fgets(linbuf, BUFSIZE, infile); /* get a line from .DXF */ - if (feof(infile)) - return(1); - return(0); +int getline(void) +{ /* read a group code and the next line from infile */ + fgets(linbuf, BUFSIZE, infile); /* get a line from .DXF */ + if(feof(infile)) + return (1); + sscanf(linbuf, "%3d", &groupcode); /* scan out group code */ + fgets(linbuf, BUFSIZE, infile); /* get a line from .DXF */ + if(feof(infile)) + return (1); + return (0); } -int main(int argc, char *argv[]){ +int main(int argc, char *argv[]) +{ char *index; - + printf("dxf2geo, a 2D AutoCad DXF to Gmsh GEO file translator\n"); - if (argc < 3){ - printf("Usage: %s file[.dxf] tolerance [rotation] [xoffset] [yoffset]\n", argv[0]); + if(argc < 3) { + printf("Usage: %s file[.dxf] tolerance [rotation] [xoffset] [yoffset]\n", + argv[0]); exit(1); } - THETOL = atof(argv[2]) ; - if(argc > 3) THEROT = atof(argv[3]) ; - if(argc > 4) THETRANSX = atof(argv[4]) ; - if(argc > 5) THETRANSY = atof(argv[5]) ; + THETOL = atof(argv[2]); + if(argc > 3) + THEROT = atof(argv[3]); + if(argc > 4) + THETRANSX = atof(argv[4]); + if(argc > 5) + THETRANSY = atof(argv[5]); - strcpy(inname, argv[1]); /* make copy we can mess with */ - if (!strchr(inname, '.')) /* no dot present in filename? */ + strcpy(inname, argv[1]); /* make copy we can mess with */ + if(!strchr(inname, '.')) /* no dot present in filename? */ strcat(inname, ".dxf"); - if (!(infile = fopen(inname, "r"))){ + if(!(infile = fopen(inname, "r"))) { printf("Cannot open input file %s\n", inname); exit(1); } strcpy(outname, inname); index = strchr(outname, '.'); /* find the dot */ - strcpy(index, ".geo"); /* make new ext. .geo... */ + strcpy(index, ".geo"); /* make new ext. .geo... */ - if (!(outfile = fopen(outname, "w"))){ + if(!(outfile = fopen(outname, "w"))) { printf("Cannot create output file %s\n", outname); fclose(infile); exit(1); } ints[0] = ints[1] = ints[2] = ints[3] = ints[4] = ints[5] = 0; - curobj[0] = '\0'; /* not working on any object currently */ + curobj[0] = '\0'; /* not working on any object currently */ curcolor = 7; /* and it also doesn't have a color yet... */ - max_x = max_y = max_z = -10000000.0; /* init bounding limits */ - min_x = min_y = min_z = 10000000.0; - - Point_T = Tree_Create(sizeof(struct Point), fcmpPoint) ; - Curve_T = Tree_Create(sizeof(struct Curve), fcmpCurve) ; - -find: - while (!feof(infile)){ /* run file up to the "ENTITIES" section */ - if (getline()) goto stopit; - if (groupcode == 0){ /* file section mark */ - if (strstr(linbuf, "EOF")) goto stopit; - if (strstr(linbuf, "SECTION")){ - if (getline()) goto stopit; - if (groupcode != 2) continue; - if (strstr(linbuf, "ENTITIES")) break; + max_x = max_y = max_z = -10000000.0; /* init bounding limits */ + min_x = min_y = min_z = 10000000.0; + + Point_T = Tree_Create(sizeof(struct Point), fcmpPoint); + Curve_T = Tree_Create(sizeof(struct Curve), fcmpCurve); + +find: + while(!feof(infile)) { /* run file up to the "ENTITIES" section */ + if(getline()) + goto stopit; + if(groupcode == 0) { /* file section mark */ + if(strstr(linbuf, "EOF")) + goto stopit; + if(strstr(linbuf, "SECTION")) { + if(getline()) + goto stopit; + if(groupcode != 2) + continue; + if(strstr(linbuf, "ENTITIES")) + break; } } } - while (!feof(infile)){ /* scan ENTITIES section */ - if (getline()) /* get a group code and a line */ + while(!feof(infile)) { /* scan ENTITIES section */ + if(getline()) /* get a group code and a line */ break; - if (groupcode < 10){ /* cardinal group codes */ - switch(groupcode){ - case 0: /* start of entity, table, file sep */ - if (strstr(linbuf, "EOF")){ - addobj(); /* dump object */ - goto stopit; - } - if (strstr(linbuf, "ENDSEC")){ - addobj(); /* dump object */ - goto find; - } - addobj(); /* dump old object */ - curobj[0] = '\0'; /* reset object */ - curcolor = 7; - strcpy(curobj, linbuf); /* get new */ - break; - case 1: /* primary text value for entity (?)*/ - break; - case 2: /* block name, attribute tag, etc */ - case 3: /* other names */ + if(groupcode < 10) { /* cardinal group codes */ + switch (groupcode) { + case 0: /* start of entity, table, file sep */ + if(strstr(linbuf, "EOF")) { + addobj(); /* dump object */ + goto stopit; + } + if(strstr(linbuf, "ENDSEC")) { + addobj(); /* dump object */ + goto find; + } + addobj(); /* dump old object */ + curobj[0] = '\0'; /* reset object */ + curcolor = 7; + strcpy(curobj, linbuf); /* get new */ + break; + case 1: /* primary text value for entity (?) */ + break; + case 2: /* block name, attribute tag, etc */ + case 3: /* other names */ case 4: - break; - case 5: /* entity handle (hex string) */ - break; - case 6: /* line type name */ - break; - case 7: /* text style name */ - break; - case 8: /* layer name */ - break; - case 9: /* variable name ID (only in header)*/ - break; + break; + case 5: /* entity handle (hex string) */ + break; + case 6: /* line type name */ + break; + case 7: /* text style name */ + break; + case 8: /* layer name */ + break; + case 9: /* variable name ID (only in header) */ + break; } } - else if (groupcode >= 10 && groupcode < 19){ /* Some X coord */ - sscanf(linbuf, "%f", &(xcoords[groupcode-10])); - if (xcoords[groupcode-10] > max_x) - max_x = xcoords[groupcode-10]; - if (xcoords[groupcode-10] < min_x) - min_x = xcoords[groupcode-10]; + else if(groupcode >= 10 && groupcode < 19) { /* Some X coord */ + sscanf(linbuf, "%f", &(xcoords[groupcode - 10])); + if(xcoords[groupcode - 10] > max_x) + max_x = xcoords[groupcode - 10]; + if(xcoords[groupcode - 10] < min_x) + min_x = xcoords[groupcode - 10]; } - else if (groupcode >= 20 && groupcode < 29){ /* Some Y coord */ - sscanf(linbuf, "%f", &(ycoords[groupcode-20])); - if (ycoords[groupcode-20] > max_y) - max_y = ycoords[groupcode-20]; - if (ycoords[groupcode-20] < min_y) - min_y = ycoords[groupcode-20]; + else if(groupcode >= 20 && groupcode < 29) { /* Some Y coord */ + sscanf(linbuf, "%f", &(ycoords[groupcode - 20])); + if(ycoords[groupcode - 20] > max_y) + max_y = ycoords[groupcode - 20]; + if(ycoords[groupcode - 20] < min_y) + min_y = ycoords[groupcode - 20]; } - else if (groupcode >= 30 && groupcode < 38){ /* Some Z coord */ - sscanf(linbuf, "%f", &(zcoords[groupcode-30])); - if (zcoords[groupcode-30] > max_z) - max_z = zcoords[groupcode-30]; - if (zcoords[groupcode-30] < min_z) - min_z = zcoords[groupcode-30]; + else if(groupcode >= 30 && groupcode < 38) { /* Some Z coord */ + sscanf(linbuf, "%f", &(zcoords[groupcode - 30])); + if(zcoords[groupcode - 30] > max_z) + max_z = zcoords[groupcode - 30]; + if(zcoords[groupcode - 30] < min_z) + min_z = zcoords[groupcode - 30]; } - else if (groupcode == 38){ /* entity elevation if nonzero */ + else if(groupcode == 38) { /* entity elevation if nonzero */ } - else if (groupcode == 39){ /* entity thickness if nonzero */ + else if(groupcode == 39) { /* entity thickness if nonzero */ } - else if (groupcode >= 40 && groupcode < 49){ /* misc floats */ - sscanf(linbuf, "%f", &(floats[groupcode-40])); + else if(groupcode >= 40 && groupcode < 49) { /* misc floats */ + sscanf(linbuf, "%f", &(floats[groupcode - 40])); } - else if (groupcode == 49){ /* repeated value groups */ + else if(groupcode == 49) { /* repeated value groups */ } - else if (groupcode >= 50 && groupcode < 59){ /* misc angles */ - sscanf(linbuf, "%f", &(angles[groupcode-50])); + else if(groupcode >= 50 && groupcode < 59) { /* misc angles */ + sscanf(linbuf, "%f", &(angles[groupcode - 50])); } - else if (groupcode == 62){ /* Color number */ + else if(groupcode == 62) { /* Color number */ sscanf(linbuf, "%6d", &curcolor); } - else if (groupcode == 66){ /* "entities follow" flag */ + else if(groupcode == 66) { /* "entities follow" flag */ } - else if (groupcode >= 70 && groupcode < 79){ /* misc ints */ - sscanf(linbuf, "%d", &(ints[groupcode-70])); + else if(groupcode >= 70 && groupcode < 79) { /* misc ints */ + sscanf(linbuf, "%d", &(ints[groupcode - 70])); } - else if (groupcode == 210 || groupcode == 220 || groupcode == 230){ + else if(groupcode == 210 || groupcode == 220 || groupcode == 230) { /* X, Y, Z components of extrusion direction */ } } - -stopit: + +stopit: fclose(infile); fprintf(outfile, "/* Converted from AutoCad DXF file: %s */\n", inname); - fprintf(outfile, "/* Tolerance %g: %d points / %d curves */\n\n", - THETOL, Tree_Nbr(Point_T), Tree_Nbr(Curve_T)); + fprintf(outfile, "/* Tolerance %g: %d points / %d curves */\n\n", + THETOL, Tree_Nbr(Point_T), Tree_Nbr(Curve_T)); fprintf(outfile, "u = 1; \nlc = 1 ;\n\n"); Tree_Action(Point_T, writepoint); fprintf(outfile, "\n"); @@ -482,13 +621,13 @@ stopit: fprintf(outfile, "\n"); fflush(outfile); fclose(outfile); - printf("bounding box [%g,%g] [%g,%g] [%g,%g]\n", - min_x, max_x, min_y, max_y, min_z, max_z); - printf("tolerance %g: %d points / %d curves / %d degenerate entities removed\n", - THETOL, Tree_Nbr(Point_T), Tree_Nbr(Curve_T), degenerates); - Tree_Delete(Point_T) ; - Tree_Delete(Curve_T) ; + printf("bounding box [%g,%g] [%g,%g] [%g,%g]\n", + min_x, max_x, min_y, max_y, min_z, max_z); + printf + ("tolerance %g: %d points / %d curves / %d degenerate entities removed\n", + THETOL, Tree_Nbr(Point_T), Tree_Nbr(Curve_T), degenerates); + Tree_Delete(Point_T); + Tree_Delete(Curve_T); exit(0); - -} +} diff --git a/utils/endian.c b/utils/endian.c index 25ec8d9037fe1ba5d1a5634d3cc9d57d7fef0c48..b14b7e1876866b28314f228a699dd7621662ce9f 100644 --- a/utils/endian.c +++ b/utils/endian.c @@ -1,21 +1,22 @@ /* Are we little or big endian? From Harbison&Steele. */ -main () { - union{ +main() +{ + union + { long l; - char c[sizeof (long)]; - } u; + char c[sizeof(long)]; + } + u; u.l = 1; - if (u.c[0] == 1) - printf ("LittleEndian\n"); - else if (u.c[sizeof (long) - 1] == 1) - printf ("BigEndian\n"); + if(u.c[0] == 1) + printf("LittleEndian\n"); + else if(u.c[sizeof(long) - 1] == 1) + printf("BigEndian\n"); else - printf ("unknownEndian"); - - exit (u.c[sizeof (long) - 1] == 1); -} - + printf("unknownEndian"); + exit(u.c[sizeof(long) - 1] == 1); +} diff --git a/utils/message.c b/utils/message.c index 9b12df3b8fa3211a07a6453ed2710ca4f7126d4e..b7f33cd76d842a48e1363e99693b8571a358f1d8 100644 --- a/utils/message.c +++ b/utils/message.c @@ -1,13 +1,13 @@ - #include <stdlib.h> #include <stdio.h> #include <signal.h> #include <stdarg.h> -void Msg(int level, char *fmt, ...){ - va_list args; - va_start (args, fmt); - vfprintf(stderr, fmt, args); fprintf(stderr, "\n"); - va_end (args); +void Msg(int level, char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vfprintf(stderr, fmt, args); + fprintf(stderr, "\n"); + va_end(args); } - diff --git a/utils/mysolver.c b/utils/mysolver.c index 659cc723883b8f2f0e862b0748aa042b9455140f..cc5e1ff87604f314a373b7031f4fcfce59428db5 100644 --- a/utils/mysolver.c +++ b/utils/mysolver.c @@ -1,4 +1,4 @@ -/* $Id: mysolver.c,v 1.5 2003-01-23 20:19:26 geuzaine Exp $ */ +/* $Id: mysolver.c,v 1.6 2003-03-01 22:36:44 geuzaine Exp $ */ /* Copyright (C) 1997 - 2003 C. Geuzaine, J.-F. Remacle @@ -57,49 +57,55 @@ either output some valid option strings, or run a dummy computation and output a post-processing map. */ -typedef enum{options,run} action; +typedef enum { options, run } action; /* Let's now define some fake CPU intensive functions: */ -long worktime(){ +long worktime() +{ struct timeval tp; gettimeofday(&tp, (struct timezone *)0); return (long)tp.tv_sec * 1000000 + (long)tp.tv_usec; } -void work(){ +void work() +{ long t1 = worktime(); - while(1){ - if(worktime() - t1 > 1.e5) break; + while(1) { + if(worktime() - t1 > 1.e5) + break; } } /* And here we go with the main routine of the solver: */ -int main(int argc, char *argv[]){ +int main(int argc, char *argv[]) +{ action what; - int i=0, s; - char *name=NULL, *option=NULL, *socket=NULL, tmp[256]; + int i = 0, s; + char *name = NULL, *option = NULL, *socket = NULL, tmp[256]; FILE *file; /* 1. Loop through the command line arguments, remember the action the solver has to perform (what) and store the socket name, the option name and the problem name. */ - while(i<argc) { + while(i < argc) { if(argv[i][0] == '-') { - if(!strcmp(argv[i]+1, "socket")){ - i++; - if(argv[i]) socket = argv[i++]; + if(!strcmp(argv[i] + 1, "socket")) { + i++; + if(argv[i]) + socket = argv[i++]; } - else if(!strcmp(argv[i]+1, "options")){ - i++; - what = options; + else if(!strcmp(argv[i] + 1, "options")) { + i++; + what = options; } - else if(!strcmp(argv[i]+1, "run")){ - i++; - what = run; - if(argv[i]) option = argv[i++]; + else if(!strcmp(argv[i] + 1, "run")) { + i++; + what = run; + if(argv[i]) + option = argv[i++]; } } else @@ -108,7 +114,7 @@ int main(int argc, char *argv[]){ /* 2. If the '-socket' option was not given, we cannot connect to Gmsh... */ - if(!socket){ + if(!socket) { printf("No socket specified: running non-interactively...\n"); exit(1); } @@ -116,70 +122,70 @@ int main(int argc, char *argv[]){ /* 3. Try to connect to the socket given by the '-socket' command line option: */ - s = Gmsh_Connect(socket) ; - switch(s){ + s = Gmsh_Connect(socket); + switch (s) { /* 3.1. If the socket is <0, issue an error... */ - case -1 : + case -1: printf("Couldn't create socket %s\n", socket); break; - case -2 : + case -2: printf("Couldn't connect to socket %s\n", socket); break; - default : - + default: + /* 3.2. ...otherwise, send the GMSH_CLIENT_START command (together with the process ID of the solver), check if a problem name was specified, and decide what to do according to the 'what' variable: */ - + sprintf(tmp, "%d", getpid()); Gmsh_SendString(s, GMSH_CLIENT_START, tmp); - if(!name){ + if(!name) { Gmsh_SendString(s, GMSH_CLIENT_ERROR, "Missing file name"); Gmsh_Disconnect(s); exit(1); } - switch(what){ - + switch (what) { + /* 3.2.1. If what==options, the solver sends the valid options (here for the first option): */ - - case options : + + case options: Gmsh_SendString(s, GMSH_CLIENT_OPTION_1, "Val1"); Gmsh_SendString(s, GMSH_CLIENT_OPTION_1, "Val2"); Gmsh_SendString(s, GMSH_CLIENT_OPTION_1, "Val3"); break; - + /* 3.2.2. If what==run, the solver runs the chosen option, updates the progress message, issues some information data, produces a post-processing map and asks Gmsh to merge it: */ - case run : + case run: sprintf(tmp, "Running %s with option %s...", name, option); Gmsh_SendString(s, GMSH_CLIENT_INFO, tmp); - for(i=0 ; i<100 ; i++){ - sprintf(tmp, "%d %% complete", i); - Gmsh_SendString(s, GMSH_CLIENT_PROGRESS, tmp); - work(); + for(i = 0; i < 100; i++) { + sprintf(tmp, "%d %% complete", i); + Gmsh_SendString(s, GMSH_CLIENT_PROGRESS, tmp); + work(); } sprintf(tmp, "Done with %s!", name); - Gmsh_SendString(s, GMSH_CLIENT_INFO, tmp); - file = fopen ("mysolver.pos", "wb"); - if (!file){ - Gmsh_SendString(s, GMSH_CLIENT_ERROR, "Unable to open output file"); + Gmsh_SendString(s, GMSH_CLIENT_INFO, tmp); + file = fopen("mysolver.pos", "wb"); + if(!file) { + Gmsh_SendString(s, GMSH_CLIENT_ERROR, "Unable to open output file"); } - else{ - fprintf(file, "View \"%s\"{\n", option); - fprintf(file, "ST(0,0,0,1,0,0,0,1,0){0,1,2};\n"); - fprintf(file, "};\n"); - fclose(file); - Gmsh_SendString(s, GMSH_CLIENT_VIEW, "mysolver.pos"); + else { + fprintf(file, "View \"%s\"{\n", option); + fprintf(file, "ST(0,0,0,1,0,0,0,1,0){0,1,2};\n"); + fprintf(file, "};\n"); + fclose(file); + Gmsh_SendString(s, GMSH_CLIENT_VIEW, "mysolver.pos"); } break; } - + /* 3.3. We can now disconnect the solver from Gmsh: */ Gmsh_SendString(s, GMSH_CLIENT_STOP, "Goodbye!");