Example #1
0
int delete_variable(variable* p)
{
	if(p==NULL) return 0;
	delete_variable(p->next);
	delete_qualifier(p->qualifiers);
	delete_curve(p->curves);
	delete_drange(p->dranges);
	delete_location(p->location_data);
	delete_orientation(p->orientation_data);
	free(p->length);
	free(p->kind);
	free(p->name);
	free(p->qualifier);
	free(p->id);
	free(p->range_min);
	free(p->range_max);
	free(p->default_value);
	free(p->precision);
	free(p->units);
	free(p->accuracy);
	free(p->scale_factor);
	free(p->scale_units);
	free(p->format);
	free(p->description);
	free(p->interface_name);
	free(p->interface_id);
	free(p->r_low);
	free(p->r_high);
	free(p->y_low);
	free(p->y_high);
	free(p->invalid_value);
	free(p);
	return 1;
}
Example #2
0
EXPORT void clip_interface2d(
	INTERFACE	*intfc)
{
	CURVE		**c;
	NODE		**n;
	RECT_GRID	*grid = &topological_grid(intfc);
	int		dim = intfc->dim,i;
	double 		eps = HUGE_VAL;

	for (i = 0; i < dim; i++)
	    eps = min(eps,grid->h[i]);
	eps *= 0.01;/*TOLERANCE*/

	for (i = 0; i < dim; i++)
	{
	    grid->L[i] -= eps;
	    grid->U[i] += eps;
	}

			/* delete curve: */
	for(;;)
	{
	    for(c = intfc->curves;*c;c++)
	    {
	    	if (exterior_curve(*c,grid) == YES)
		    break;
	    }
	    if (*c)
	    {
	    	(void) delete_curve(*c);
	    }
	    else
		break;
	}

			/* delete node: */
	for(;;)
	{
	    for(n = intfc->nodes;*n;n++)
	    {
	    	if ((*n)->in_curves != NULL || (*n)->out_curves != NULL)
	    		continue;
	    	if (exterior_point((*n)->posn,grid) == YES)
	    	    break;
	    }
	    if (*n)
	    {
	    	(void) delete_node(*n);
	    }
	    else break;
	}
}		/*end clip_interface2d*/
Example #3
0
int IncreaseR1()
{
	if (curve) {
	   Update_flags |= UF_WORLD_CHANGED;
	   delete_curve();
	   r1scale += F1_0;
	   generate_curve(r1scale, r4scale);
      diagnostic_message("R1 vector increased.");
	   mine_changed = 1;
		warn_if_concave_segments();
	}
	return 1;
}
Example #4
0
int DeleteCurve()
{
// fix_bogus_uvs_all();
set_average_light_on_curside();

	if (curve) {
	   Update_flags |= UF_WORLD_CHANGED;
	   delete_curve();
	   curve = 0;
	   mine_changed = 1;
      diagnostic_message("Curve Deleted.");
		warn_if_concave_segments();
	}
	return 1;
}
Example #5
0
LOCAL 	void insert_cuts_and_bdry2d(
	INTERFACE	*intfc,	/* an orginal intfc	*/
	double		**pc)	/* given corners of the subdomain */
{
	COMPONENT	comp;
	CROSS		*cross;
	CURVE		**cc, *c[4];
	CURVE		**curves1, **curves2;
	POINT		*p;
	INTERFACE	*sav_intfc;
	NODE		*n, **nn, *bn[4];
	int		i;

	sav_intfc = current_interface();
	set_current_interface(intfc);
	comp = (intfc->modified) ? long_component(pc[0],intfc) :
			component(pc[0],intfc);

redo_curve_list:
	for (cc = intfc->curves; cc && *cc; cc++)
	{
	    if (is_bdry(*cc))
	    {
	    	(void) delete_curve(*cc);
	    	goto redo_curve_list;
	    }
	}
	for (nn = intfc->nodes; nn && *nn; nn++)
	{
	    if (is_bdry(*nn))
	    {
	    	int num_in, num_out;
	    	if (num_curves_at_node(*nn,&num_in,&num_out) == 0)
	    	    (void) delete_node(*nn);
	    	else
	    	    set_not_bdry(*nn);
	    }
	}
	bn[0] = make_node(Point(pc[0]));
	bn[1] = make_node(Point(pc[2]));
	bn[2] = make_node(Point(pc[3]));
	bn[3] = make_node(Point(pc[1]));
	for (i = 0; i < 4; i++)
	{
	    c[i] = make_curve(NO_COMP,NO_COMP,bn[i],bn[(i+1)%4]);
	    set_is_bdry(c[0]);
	}

	if (intersections(intfc,&cross,YES) == FUNCTION_FAILED)
	{
	    screen("ERROR in insert_cuts_and_bdry2d(), "
	           "intersections() failed\n");
	    clean_up(ERROR);
	}

	if (cross == NULL)
	{
	    for (i = 0; i < 4; i++)
	    {
	    	positive_component(c[i]) = comp;
	    	negative_component(c[i]) = exterior_component(intfc);
	    }
	    return;
	}
	for (; cross != NULL; cross = cross->next)
	{
	    p = cross->p;
	    if (insert_point_in_bond(p,cross->b1,cross->c1)!=FUNCTION_SUCCEEDED)
	    {
	        screen("ERROR in insert_cuts_and_bdry2d(), "
		       "insert_point_in_bond() failed\n");
	        clean_up(ERROR);
	    }
	    rcl_after_insert_point(cross,p,cross->b1);
	    curves1 = split_curve(p,cross->b1,cross->c1,
	    		          positive_component(cross->c1),
	    		          negative_component(cross->c1),
	    		          positive_component(cross->c1),
	    		          negative_component(cross->c1));
	    rcl_after_split(cross,p,cross->b1,cross->c1,curves1);
	    if (insert_point_in_bond(p,cross->b2,cross->c2)!=FUNCTION_SUCCEEDED)
	    {
	        screen("ERROR in insert_cuts_and_bdry2d(), "
		       "insert_point_in_bond() failed\n");
	        clean_up(ERROR);
	    }
	    rcl_after_insert_point(cross,p,cross->b2);
	    curves2 = split_curve(p,cross->b2,cross->c2,
	    		          positive_component(cross->c2),
	    		          negative_component(cross->c2),
	    		          positive_component(cross->c2),
	    		          negative_component(cross->c2));
	    rcl_after_split(cross,p,cross->b2,cross->c2,curves1);
	    n = curves2[0]->end;
	    change_node_of_curve(curves2[0],
				NEGATIVE_ORIENTATION,curves1[0]->end);
	    change_node_of_curve(curves2[1],
				POSITIVE_ORIENTATION,curves1[0]->end);
	    (void) delete_node(n);
	}

	set_current_interface(sav_intfc);
	return;
}		/*end insert_cuts_and_bdry2d*/
Example #6
0
void generate_banked_curve(fix maxscale, vms_equation coeffs) {
    vms_vector vec_dir, tvec, b4r4t;
    vms_vector coord,prev_point;
    fix enddist, nextdist;
    int firstsegflag;
    fixang rangle, uangle, angle, scaled_ang=0;
    fix t;

    if (CurveNumSegs) {

		const vcsegptr_t cursegp = Cursegp;
		extract_up_vector_from_segment(cursegp, b4r4t);
    uangle = vm_vec_delta_ang( b4r4t, r4t, r4 );
    if (uangle >= F1_0 * 1/8) uangle -= F1_0 * 1/4;
    if (uangle >= F1_0 * 1/8) uangle -= F1_0 * 1/4;
    if (uangle <= -F1_0 * 1/8) uangle += F1_0 * 1/4;
    if (uangle <= -F1_0 * 1/8) uangle += F1_0 * 1/4;

		extract_right_vector_from_segment(cursegp, b4r4t);
    rangle = vm_vec_delta_ang( b4r4t, r4t, r4 );
    if (rangle >= F1_0/8) rangle -= F1_0/4;
    if (rangle >= F1_0/8) rangle -= F1_0/4;
    if (rangle <= -F1_0/8) rangle += F1_0/4;
    if (rangle <= -F1_0/8) rangle += F1_0/4;

    angle = uangle;
    if (abs(rangle) < abs(uangle)) angle = rangle;

	delete_curve();

    coord = prev_point = p1;

#define MAGIC_NUM 0.707*F1_0

    if (maxscale)
        scaled_ang = fixdiv(angle,fixmul(maxscale,MAGIC_NUM));

    t=0; 
    tvec = r1save;
    firstsegflag = 1;
    enddist = F1_0; nextdist = 0;
    while ( enddist > fixmul( nextdist, 1.5*F1_0 )) {
            vms_matrix  rotmat;
            if (firstsegflag==1)
                firstsegflag=0;
            else
				extract_forward_vector_from_segment(cursegp, tvec);
            nextdist = vm_vec_mag(tvec);                                   // nextdist := distance to next point
            t = curve_dist(&coeffs, 3, t, prev_point, nextdist);               // t = argument at which function is forward vector magnitude units away from prev_point (in 3-space, not along curve)
            coord = evaluate_curve(&coeffs, 3, t);                                          // coord := point about forward vector magnitude units away from prev_point
            enddist = vm_vec_dist(coord, p4);                  // enddist := distance from current to end point, vec_dir used as a temporary variable
            //vm_vec_normalize(vm_vec_sub(&vec_dir, &coord, &prev_point));
            vm_vec_normalized_dir(vec_dir, coord, prev_point);
			if (!med_attach_segment(Cursegp, vmsegptr(&New_segment), Curside, AttachSide))
			{
				med_extract_matrix_from_segment(cursegp, &rotmat);                   // rotmat := matrix describing orientation of Cursegp
			const auto tdest = vm_vec_rotate(vec_dir,rotmat);	// tdest := vec_dir in reference frame of Cursegp
			vec_dir = tdest;
            const auto rotmat2 = vm_vec_ang_2_matrix(vec_dir,scaled_ang);

			med_rotate_segment( Cursegp, rotmat2 );
			prev_point = coord;
            Curside = Side_opposite[AttachSide];

            CurveSegs[CurveNumSegs]=Cursegp;
            CurveNumSegs++;
        }
      }
    }
}
Example #7
0
variable* merge_variables(variable* a,variable* b)
{
	if(a==NULL) return b;
	if(b==NULL) return a;
	/* The else if blocks are required to prevent a possible memory leak occuring when a attribute
	 in the xTEDS is specified multiple times, this isn't really enforceable in the xTEDS schema
	 unless an exhaustive list of all permutations of attribute orders was specified in the grammar*/
	if(a->length==NULL) a->length = b->length;
	  else if(b->length!=NULL) free(b->length);
	
	if(a->kind==NULL) a->kind = b->kind;
	  else if(b->kind!=NULL) free(b->kind);
	
	if(a->name==NULL) a->name = b->name;
	  else if(b->name!=NULL) free(b->name);
	
	if(a->qualifier==NULL) a->qualifier = b->qualifier;
	  else if(b->qualifier!=NULL) free(b->qualifier);
	
	if(a->id==NULL) a->id = b->id;
	  else if(b->id!=NULL) free(b->id);
	
	if(a->range_min==NULL) a->range_min = b->range_min;
	  else if(b->range_min!=NULL) free(b->range_min);
	
	if(a->range_max==NULL) a->range_max = b->range_max;
	  else if(b->range_max!=NULL) free(b->range_max);
	
	if(a->default_value==NULL) a->default_value = b->default_value;
	  else if(b->default_value!=NULL) free(b->default_value);
	
	if(a->precision==NULL) a->precision = b->precision;
	  else if(b->precision!=NULL) free(b->precision);
	
	if(a->units==NULL) a->units = b->units;
	  else if(b->units!=NULL) free(b->units);
	
	if(a->accuracy==NULL) a->accuracy = b->accuracy;
	  else if(b->accuracy!=NULL) free(b->accuracy);
	
	if(a->scale_factor==NULL) a->scale_factor = b->scale_factor;
	  else if(b->scale_factor!=NULL) free(b->scale_factor);
	
	if(a->scale_units==NULL) a->scale_units = b->scale_units;
	  else if(b->scale_units!=NULL) free(b->scale_units);
	
	if(a->format==NULL) a->format = b->format;
	  else if(b->format!=NULL) free(b->format);
	
	if(a->description==NULL) a->description = b->description;
	  else if(b->description!=NULL) free(b->description);
	
	if(a->qualifiers==NULL) a->qualifiers = b->qualifiers;
	  else if(b->qualifiers!=NULL) free(b->qualifiers);
	
	if(a->curves==NULL) a->curves = b->curves;
	  else if(b->curves!=NULL) delete_curve(b->curves);
	
	if(a->dranges==NULL) a->dranges = b->dranges;
	  else if(b->dranges!=NULL) delete_drange(b->dranges);
	
	if(a->location_data==NULL) a->location_data = b->location_data;
	  else if(b->location_data!=NULL) delete_location(b->location_data);
	
	if (a->r_low == NULL) a->r_low = b->r_low;
	  else if(b->r_low!=NULL) free(b->r_low);
	
	if (a->r_high == NULL) a->r_high = b->r_high;
	  else if(b->r_high!=NULL) free(b->r_high);
	
	if (a->y_low == NULL) a->y_low = b->y_low;
	  else if(b->y_low!=NULL) free(b->y_low);
	
	if (a->y_high == NULL) a->y_high = b->y_high;
	  else if(b->y_high!=NULL) free(b->y_high);
	
	if (a->invalid_value == NULL) a->invalid_value = b->invalid_value;
	  else if(b->invalid_value!=NULL) free(b->invalid_value);
	
	a->orientation_data = link_orientations(a->orientation_data,b->orientation_data);
	free(b);
	/*Keep a reference to this variable tree for VarInfoParser*/
	var_result = a;
	return a;
}
Example #8
0
/*ARGSUSED*/
EXPORT	boolean consistent_propagated_loop_orientations(
	double		dt,
	double		*dt_frac,
	Front		*fr,
	POINTER		wave)
{
	static const double AREA_FAC = 0.01;	/*TOLERANCE*/
	static const int   num_attempts = 5;	/*TOLERANCE*/
	CURVE	**c,*oldc,*newc;
	NODE	*oldn, *newn;
	double	dt_f, dT;
	double	A_old, A_new;
	double	min_area = AREA_FAC*fr->rect_grid->h[0]*fr->rect_grid->h[1];
	boolean	status = YES;
	int	i;

	debug_print("orient_consistency",
	      "Entered consistent_propagated_loop_orientations()\n");

	for (c = fr->interf->curves; c && *c; ++c)
	{
	    oldc = *c;
	    if (!is_closed_curve(oldc))
		continue;
	    newc = correspond_curve(oldc);

	    /*TODO: this needs to be solved correctly.*/
	    if ((newc == NULL) || (newc->interface == NULL) ||
	        (!is_closed_curve(newc)))
	    	continue;
	    if (newc->num_points > 20)
	    	continue;	/* sufficiently long curve cannot fully flip */

	    A_old = area_of_closed_curve(oldc);
	    A_new = area_of_closed_curve(newc);

	    if (debugging("orient_consistency"))
	    	(void) printf("A_old = %g, A_new = %g\n",A_old,A_new);

	    if (A_old*A_new > 0.0)
		continue;

	    status = NO;
	    if (debugging("orient_consistency"))
	    {
	    	(void) printf("Loop %llu inverted after propagation\n",
	    		      (long long unsigned int)curve_number(oldc));
	    	(void) printf("Old loop\n");
	    	print_curve(oldc);
	    	(void) printf("Propagated loop\n");
	    	print_curve(newc);
	    }

	    /* Determine dt_frac */

	    if (A_old < min_area)
	    {
	    	*dt_frac *= 0.9;
	    	continue;
	    }

	    dt_f = 1.0;
	    oldn = oldc->start;	newn = newc->start;
	    for (i = 0; i < num_attempts; ++i)
	    {
	    	dt_f *= 0.5;
	    	dT = dt_f * dt;
	    	if (fr->curve_propagate != NULL) 
	    	    curve_propagate(fr,wave,oldc,newc,dT);
		(void) closed_node_propagate(fr,wave,oldn,newn,dT);
		A_new = area_of_closed_curve(newc);

		if (debugging("orient_consistency"))
		{
	            (void) printf("In loop, dt_f = %g, dT = %g, ",dt_f,dT);
		    (void) printf("A_old = %g, A_new = %g\n",A_old,A_new);
		}
		if (A_old*A_new >= 0.0)
		    break;
	    }
	    if (i == num_attempts)
	    {
	        (void) printf("WARNING in "
			      "consistent_propagated_loop_orientations(), "
		              "cannot produce consistent loop "
		              "orientations by reduction of time step\n");
		(void) printf("modifying interface\n");
		(void) delete_curve(newc);
		status = YES;
		continue;
	    }
	    *dt_frac = min(*dt_frac,dt_f);

		/* Restore newc to original state ? 			*/
		/* This is unnecessary if reduce time step is called,   */
		/* as the newc->interface will be deleted, but this	*/
		/* may be desirable for consistency reasons if future	*/
		/* resolutions solve this problem without having to	*/
		/* reduce the time step.  For now this section is	*/
		/* commented out.					*/

	}
	debug_print("orient_consistency",
		"Left consistent_propagated_loop_orientations()\n");
	return status;
}		/*end consistent_propagated_loop_orientation*/