void realign::realignPeriodically() { vector <baseType> along(vl->size()); baseType timeFirstRun; in >> timeFirstRun; // cout << "timeFirstRun: " << timeFirstRun << endl; // cout << "time: " << dynNode::time << endl; for (unsigned int i = 0; i < vl->size(); i++ ) in >>along[i]; meanVar dist = calculateDist(along); if (counter==skip) { counter = 0; out << dynNode::time << " " << setprecision(20) << dist.mean << " " << sqrt(dist.var) << endl; cout << "vorher:" << setprecision(20) << dist.mean << " " << sqrt(dist.var) << endl; realignNow(along, eps, dist); meanVar newDist = calculateDist(along); cout << "nachher:" << setprecision(20) << newDist.mean << " " << sqrt(newDist.var) << endl; } else { counter++; out << "#" << setprecision(20) << dynNode::time << " " << dist.mean << " " << sqrt(dist.var) << endl; } }
void slice_torus (struct msscene *ms, struct surface *current_surface, double fine_pixel, double probe_radius, struct face *fac) { int k, j, i, nfocus, near1, naif; double anginc, bigrad; double focus[3], vect1[3], vect2[3], vect[3], qvect[3]; double dtq, tcv[3]; double *foci = (double *) NULL; char message[MAXLINE]; struct leaf *lf; struct circle *cir1, *cir2, *cir3; struct circle *lfcir, *torcir; struct variety *vty, *atm1, *atm2; struct arc *a, *nxta; struct arc *torarc; struct vertex *torvtx[2]; struct vertex *qvtx; struct vertex *conevtx; struct cycle *cyc; struct edge *edg; struct cept *ex; vty = fac -> vty; if (vty -> type != TORUS) { ex = new_cept (GEOMETRY_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "slice_torus"); add_source (ex, "msrender.c"); add_long (ex, "variety type", (long) vty -> type); return; } if (vty -> tube) { slice_elbow (ms, current_surface, fine_pixel, fac); return; } if (debug >= 2) { sprintf (message,"render saddle face for atoms %5d %5d", vty -> atmnum[0], vty -> atmnum[1]); inform(message); } /* get pointers to atom varieties */ atm1 = *(current_surface -> variety_handles + fac -> vty -> atmnum[0] - 1); atm2 = *(current_surface -> variety_handles + fac -> vty -> atmnum[1] - 1); /* check versus window */ bigrad = distance (atm1 -> center, atm2 -> center) + atm1 -> radii[0] + atm2 -> radii[0]; for (k = 0; k < 3; k++) { if (vty -> center[k] + bigrad < ms -> window[0][k]) return; if (vty -> center[k] - bigrad > ms -> window[1][k]) return; } /* leaf circle */ lfcir = allocate_circle (); if (error()) { add_object (tail_cept, CIRCLE, "leaf circle"); add_function (tail_cept, "slice_torus"); return; } /* leaf */ lf = allocate_leaf (); if (error()) { add_object (tail_cept, LEAF, "leaf"); add_function (tail_cept, "slice_sphere"); return; } /* torus circle radius, center, axis */ torcir = new_circle (vty -> center, vty -> radii[0], vty -> axis); if (torcir == NULL) { add_object (tail_cept, CIRCLE, "torus circle"); add_function (tail_cept, "slice_circle"); return; } /* torus arc */ torarc = allocate_arc (); if (error()) { add_object (tail_cept, ARC, "torus arc"); add_function (tail_cept, "slice_torus"); add_source (tail_cept, "msrender.c"); return; } for (j = 0; j < 2; j++) { torvtx[j] = allocate_vertex (); if (error()) { add_object (tail_cept, VERTEX, "torus vertex"); add_function (tail_cept, "slice_torus"); add_source (tail_cept, "msrender.c"); return; } } torarc -> cir = torcir; /* copy atom numbers from variety to leaf */ for (k = 0; k < MAXPA; k++) lf -> atmnum[k] = fac -> vty -> atmnum[k]; /* set up leaf fields */ lf -> cir = lfcir; lf -> shape = fac -> shape; lf -> type = fac -> vty -> type; lf -> fac = fac; lf -> cep = 0; lf -> clip_ep = 0; lf -> side = OUTSIDE; lf -> comp = fac -> comp; lf -> input_hue = fac -> input_hue; /* both endpoints of saddle face leaf are always accessible */ for (j = 0; j < 2; j++) lf -> where[j] = ACCESSIBLE; /* angular increment for rotation of leaf about torus axis */ anginc = fine_pixel / (vty -> radii[0]); /* next we need endpoints for torus arc */ /* get them from concave arcs bounding saddle face */ /* intialization */ cir1 = NULL; cir2 = NULL; cir3 = NULL; qvtx = NULL; conevtx = NULL; near1 = 0; /* look for concave arcs */ naif = 0; for (cyc = fac -> first_cycle; cyc != NULL; cyc = cyc -> next) for (edg = cyc -> first_edge; edg != NULL; edg = edg -> next) { naif++; a = edg -> arcptr; if (a -> shape == CONVEX) { cir3 = a -> cir; continue; } if (edg -> next == NULL) nxta = cyc -> first_edge -> arcptr; else nxta = edg -> next -> arcptr; if (along (edg, vty -> axis)) cir2 = a -> cir; else cir1 = a -> cir; /* check for cusp vertex */ if (a -> shape == CONCAVE && nxta -> shape == CONCAVE) { /* cusp point joints two concave arcs */ qvtx = a -> vtx[1-edg->orn]; } } dtq = probe_radius * probe_radius - vty -> radii[0] * vty -> radii[0]; /* later: note: check PI in bubbles */ if (naif == 1) { if (dtq <= 0.0) { ex = new_cept (GEOMETRY_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "slice_torus"); add_source (ex, "msrender.c"); add_message(ex, "toroidal face with only one arc, but not cone"); return; } if (cir3 == NULL) { ex = new_cept (GEOMETRY_ERROR, INCONSISTENCY, FATAL_SEVERITY); add_function (ex, "slice_torus"); add_source (ex, "msrender.c"); add_message(ex, "toroidal face with only one arc, but no contact circle"); return; } /* cone */ qvtx = allocate_vertex (); if (error()) { add_object (tail_cept, VERTEX, "CUSP VERTEX"); add_function (tail_cept, "slice_torus"); add_source (tail_cept, "msrender.c"); return; } conevtx = qvtx; dtq = sqrt (dtq); for (k = 0; k < 3; k++) tcv[k] = cir3 -> center[k] - torcir -> center[k]; normalize (tcv); for (k = 0; k < 3; k++) qvtx -> center[k] = torcir -> center[k] + dtq * tcv[k]; /* hope this is enough */ } if (cir1 == NULL) informd2 ("cir1 null"); if (cir2 == NULL) informd2 ("cir2 null"); if (qvtx != NULL) informd2 ("cusp present"); /* check for cusp vertex */ if (qvtx != NULL) { for (k = 0; k < 3; k++) qvect[k] = qvtx -> center[k] - vty -> center[k]; near1 = (dot_product (qvect, vty -> axis) < 0.0); } /* check for hoop saddle face */ if (cir1 == NULL || cir2 == NULL) { for (j = 0; j < 2; j++) torarc -> vtx[j] = NULL; informd2 ("complete toroidal hoop"); } else { /* concave arc circle centers are endpoints of sphere rolling */ for (k = 0; k < 3; k++) { torvtx[0] -> center[k] = cir1 -> center[k]; torvtx[1] -> center[k] = cir2 -> center[k]; } for (j = 0; j < 2; j++) torarc -> vtx[j] = torvtx[j]; sprintf (message, "saddle rendering (from): %8.3f %8.3f %8.3f", cir1 -> center[0], cir1 -> center[1], cir1 -> center[2]); informd2 (message); sprintf (message, "saddle rendering (to) : %8.3f %8.3f %8.3f", cir2 -> center[0], cir2 -> center[1], cir2 -> center[2]); informd2 (message); } /* the probe sphere centers are the foci of the leaves */ nfocus = render_sub_arc (torarc, &foci, anginc); if (nfocus < 2) { ex = new_cept (LOGIC_ERROR, MSUNDERFLOW, FATAL_SEVERITY); add_function (ex, "slice_torus"); add_source (ex, "msrender.c"); add_long (ex, "number of foci", (long) nfocus); return; } sprintf (message, "nfocus = %d", nfocus); informd2 (message); /* create leaves */ for (i = 0; i < nfocus; i++) { for (k = 0; k < 3; k++) { focus[k] = (*(foci + 3 * i + k)); lfcir -> center[k] = focus[k]; lf -> focus[k] = focus[k]; } /* unit vectors from focus toward atoms */ for (k = 0; k < 3; k++) { vect1[k] = atm1 -> center[k] - focus[k]; vect2[k] = atm2 -> center[k] - focus[k]; } /* correct for cusp vertex */ if (qvtx != NULL) { if (near1) for (k = 0; k < 3; k++) vect2[k] = qvtx -> center[k] - focus[k]; else for (k = 0; k < 3; k++) vect1[k] = qvtx -> center[k] - focus[k]; } /* normalize vectors to unit length */ normalize (vect1); normalize (vect2); /* leaf circle radius is probe radius */ lfcir -> radius = probe_radius; /* set up endpoints of leaf */ for (k = 0; k < 3; k++) { lf -> ends[0][k] = focus[k] + lfcir -> radius * vect1[k]; lf -> ends[1][k] = focus[k] + lfcir -> radius * vect2[k]; } /* compute leaf circle axis */ for (k = 0; k < 3; k++) vect[k] = focus[k] - vty -> center[k]; cross (vty -> axis, vect, lfcir -> axis); normalize (lfcir -> axis); /* clip and render leaf */ clip_leaf (ms, current_surface, fine_pixel, lf); if (error()) return; } /* return temporary memory */ if (!free_doubles (foci, 0, VERTS)) { ex = new_cept (MEMORY_ERROR, FREEING, FATAL_SEVERITY); add_variable (ex, VERTS, "foci"); add_function (ex, "slice_torus"); add_source (ex, "msrender.c"); return; } free_leaf (lf); free_arc (torarc); free_circle (torcir); free_circle (lfcir); for (j = 0; j < 2; j++) free_vertex (torvtx[j]); if (conevtx != NULL) free_vertex (conevtx); return; }