1 | /*!\file: Exp.cpp
|
---|
2 | * \brief Exp.cpp: write the vertex coordinates defined in a domain
|
---|
3 | * outline from Argus (.exp file). The first contour in the file is for
|
---|
4 | * the outside domain outline.
|
---|
5 | */
|
---|
6 | #include <stdio.h>
|
---|
7 | #include <math.h>
|
---|
8 |
|
---|
9 | #include "../MemOps/MemOps.h"
|
---|
10 | #include "../Exceptions/exceptions.h"
|
---|
11 | #include "./exp.h"
|
---|
12 |
|
---|
13 | int ExpWrite(int nprof,int* profnvertices,double** pprofx,double** pprofy,char* domainname){/*{{{*/
|
---|
14 |
|
---|
15 | /*I/O: */
|
---|
16 | FILE* fid=NULL;
|
---|
17 |
|
---|
18 | /*open domain outline file for writing: */
|
---|
19 | if((fid=fopen(domainname,"w"))==NULL) _error_("could not open domain file " << domainname);
|
---|
20 |
|
---|
21 | /*Start writing profiles: */
|
---|
22 | for(int counter=0;counter<nprof;counter++){
|
---|
23 |
|
---|
24 | /*Write header: */
|
---|
25 | fprintf(fid,"## Name:%s\n",domainname);
|
---|
26 | fprintf(fid,"## Icon:0\n");
|
---|
27 | fprintf(fid,"# Points Count Value\n");
|
---|
28 | fprintf(fid,"%u %s\n",profnvertices[counter] ,"1.");
|
---|
29 | fprintf(fid,"# X pos Y pos\n");
|
---|
30 |
|
---|
31 | /*Write vertices: */
|
---|
32 | for(int i=0;i<profnvertices[counter];i++){
|
---|
33 | fprintf(fid,"%lf\t%lf\n",pprofx[counter][i],pprofy[counter][i]);
|
---|
34 | }
|
---|
35 |
|
---|
36 | /*Write blank line: */
|
---|
37 | if(counter<nprof-1) fprintf(fid,"\n");
|
---|
38 | }
|
---|
39 |
|
---|
40 | /*close Exp file: */
|
---|
41 | fclose(fid);
|
---|
42 |
|
---|
43 | return 1;
|
---|
44 | }/*}}}*/
|
---|
45 | int IsInPolySerial(double* in,double* xc,double* yc,int numvertices,double* x,double* y,int nods, int edgevalue){ /*{{{*/
|
---|
46 |
|
---|
47 | double x0,y0;
|
---|
48 |
|
---|
49 | /*Go through all vertices of the mesh:*/
|
---|
50 | for(int i=0;i<nods;i++){
|
---|
51 | if (in[i]){
|
---|
52 | /*this vertex already is inside one of the contours, continue*/
|
---|
53 | continue;
|
---|
54 | }
|
---|
55 | /*pick up vertex: */
|
---|
56 | x0=x[i];
|
---|
57 | y0=y[i];
|
---|
58 | if (pnpoly(numvertices,xc,yc,x0,y0,edgevalue)){
|
---|
59 | in[i]=1.;
|
---|
60 | }
|
---|
61 | else{
|
---|
62 | in[i]=0.;
|
---|
63 | }
|
---|
64 | }
|
---|
65 |
|
---|
66 | return 1;
|
---|
67 | }
|
---|
68 | /*}}}*/
|
---|
69 | /*pnpoly{{{*/
|
---|
70 | int pnpoly(int npol, double *xp, double *yp, double x, double y, int edgevalue) {
|
---|
71 | int i, j, c = 0;
|
---|
72 | double n1, n2, normp, scalar;
|
---|
73 |
|
---|
74 | /*first test, are they colinear? if yes, is the point in the middle of the segment*/
|
---|
75 | if (edgevalue != 2 ){
|
---|
76 | for (i = 0, j = npol-1; i < npol; j = i++) {
|
---|
77 | n1=pow(yp[i]-yp[j],2.0)+pow(xp[i]-xp[j],2.0);
|
---|
78 | n2=pow(y-yp[j],2.0)+pow(x-xp[j],2.0);
|
---|
79 | normp=pow(n1*n2,0.5);
|
---|
80 | scalar=(yp[i]-yp[j])*(y-yp[j])+(xp[i]-xp[j])*(x-xp[j]);
|
---|
81 |
|
---|
82 | if (scalar == normp){
|
---|
83 | if (n2<=n1){
|
---|
84 | c = edgevalue;
|
---|
85 | return c;
|
---|
86 | }
|
---|
87 | }
|
---|
88 | }
|
---|
89 | }
|
---|
90 | /*second test : point is neither on a vertex, nor on a side, where is it ?*/
|
---|
91 | for (i = 0, j = npol-1; i < npol; j = i++) {
|
---|
92 | if ((((yp[i]<=y) && (y<yp[j])) ||
|
---|
93 | ((yp[j]<=y) && (y<yp[i]))) &&
|
---|
94 | (x < (xp[j] - xp[i]) * (y - yp[i]) / (yp[j] - yp[i]) + xp[i])){
|
---|
95 | c = !c;
|
---|
96 | }
|
---|
97 | }
|
---|
98 | return c;
|
---|
99 | }/*}}}*/
|
---|