void WitnessSet::write_dehomogenized_coordinates(boost::filesystem::path filename) const
{

	
	vec_mp result; init_vec_mp(result,1);
	
	
	FILE *OUT = safe_fopen_write(filename.c_str()); // open the output file.
	
	fprintf(OUT,"%zu\n\n",num_points()); // print the header line
	for (unsigned int ii=0; ii<num_points(); ++ii) {
		if (this->num_synth_vars()>0) {
			dehomogenize(&result,point(ii), num_natty_vars_);
		}
		else{
			dehomogenize(&result,point(ii));
		}
		
		for (int jj=0; jj<num_natty_vars_-1; jj++) {
			print_mp(OUT, 0, &result->coord[jj]);
			fprintf(OUT, "\n");
		}
		fprintf(OUT,"\n");
	}
	
	fclose(OUT);
	
	clear_vec_mp(result);
	return;
}
void WitnessSet::print_to_screen() const
{
	
	vec_mp dehom;  init_vec_mp(dehom,1); dehom->size = 1;
	
	std::stringstream varname;
	
	std::cout << "witness set has " << num_vars_ << " total variables, " << num_natty_vars_ << " natural variables." << std::endl;
	
	
	std::cout << "dim " << dim_ << ", comp " << comp_num_ << std::endl;
	std::cout << "input file name " << input_filename_ << std::endl;

	
	printf("******\n%zu points\n******\n",num_points());
	std::cout << color::green();
	for (unsigned ii=0; ii<num_points(); ii++) {
		
		dehomogenize(&dehom, point(ii), num_natty_vars_);
		
		varname << "point_" << ii;
		
		print_point_to_screen_matlab(dehom,varname.str());
		varname.str("");
	}
	std::cout << color::console_default();
	
	std::cout << color::blue();
	printf("******\n%zu linears\n******\n",num_linears());
	
	for (unsigned ii=0; ii<num_linears(); ii++) {
		varname << "linear_" << ii;
		print_point_to_screen_matlab(linear(ii),varname.str());
		varname.str("");
	}
	std::cout << color::console_default();
	
	std::cout << color::cyan();
	printf("******\n%zu patches\n******\n",num_patches());
	
	for (unsigned ii=0; ii<num_patches(); ii++) {
		varname << "patch_" << ii;
		print_point_to_screen_matlab(patch(ii),varname.str());
		varname.str("");
	}
	std::cout << color::console_default();
	
	std::cout << "variable names:\n";
	for (unsigned ii=0; ii< num_var_names(); ii++) {
		std::cout << name(ii) << "\n";
	}
	printf("\n\n");
	
	
	clear_vec_mp(dehom);
}
void WitnessSet::sort_for_real(tracker_config_t * T)
{
	

	
	
	int *real_indicator = new int[num_points()];
	int counter = 0;
	
	vec_mp result; init_vec_mp(result,num_natty_vars_-1);
	result->size = num_natty_vars_-1;
	
	for (unsigned int ii=0; ii<num_points(); ii++) {
		vec_mp & curr_point = point(ii);
		for (int jj=1; jj<num_natty_vars_; jj++) {
			div_mp(&result->coord[jj-1], &curr_point->coord[jj], &curr_point->coord[0]);
		}
		real_indicator[ii] = checkForReal_mp(result, T->real_threshold);
		
		if (real_indicator[ii]==1) {
			counter++;
		}
	}
	
	
	vec_mp *tempvec = (vec_mp *)br_malloc(counter * sizeof(vec_mp));
	
	counter = 0;  // reset
	for (unsigned int ii=0; ii<num_points(); ii++) {
		vec_mp & curr_point = point(ii);
		if (real_indicator[ii]==1) {
			
			init_vec_mp2(tempvec[counter],this->num_vars_,1024); tempvec[counter]->size = this->num_vars_;
			vec_cp_mp(tempvec[counter],curr_point);
			counter++;
		}
		else{
			
		}
	}
	
	clear_vec_mp(result);
	
	
	for (unsigned int ii=0; ii<num_points(); ii++) {
		clear_vec_mp(point(ii));
	}
	free(pts_mp_);
	
	pts_mp_ = tempvec;
	num_pts_ = counter;
	
	delete[] real_indicator;
	return;
}
Exemple #4
0
static void
init_delete_point(F_line *obj, int type, int x, int y, F_point *p, F_point *q)
{
    int		    n;

    switch (type) {
    case O_POLYLINE:
	cur_l = (F_line *) obj;
	/* the search routine will ensure we don't have a box */
	n = num_points(cur_l->points);
	if (cur_l->type == T_POLYGON) {
	    if (n <= 4) {	/* count first pt twice for closed object */
		put_msg("A polygon cannot have less than 3 points");
		beep();
		return;
	    }
	} else if (n <= 1) {
	    /* alternative would be to remove the dot altogether */
	    put_msg("A dot must have at least 1 point");
	    beep();
	    return;
	}
	linepoint_deleting(cur_l, p, q);
	break;
    case O_SPLINE:
	cur_s = (F_spline *) obj;
	n = num_points(cur_s->points);
	if (closed_spline(cur_s)) {
	    if (n <= CLOSED_SPLINE_MIN_NUM_POINTS) {
		put_msg("A closed spline cannot have less than %d points",
			CLOSED_SPLINE_MIN_NUM_POINTS);
		beep();
		return;
	    }
	} else if (n <= OPEN_SPLINE_MIN_NUM_POINTS) {
		put_msg("A spline cannot have less than %d points",
			OPEN_SPLINE_MIN_NUM_POINTS);
		beep();
		return;
	    }
	splinepoint_deleting(cur_s, p, q);
	break;
    default:
	return;
    }
}
void WitnessSet::send(ParallelismConfig & mpi_config, int target) const
{
    //send all the data to the other party
    

//
//	
//	std::vector< std::string > variable_names;
//	
//	boost::filesystem::path input_filename;
//	function input_file;
//	// end data members
    
    int *buffer = (int *) br_malloc(8*sizeof(int));
    buffer[0] = dimension();
    buffer[1] = component_number();
    buffer[2] = incidence_number();
    buffer[3] = num_variables();
    buffer[4] = num_natural_variables();
    buffer[5] = num_points();
    buffer[6] = num_linears();
    buffer[7] = num_patches();
    
    MPI_Send(buffer, 8, MPI_INT, WITNESS_SET, target, mpi_config.comm());
    
    free(buffer);
    
    for (unsigned int ii=0; ii<num_linears(); ii++) {
        send_vec_mp( linear(ii),target);
    }
    for (unsigned int ii=0; ii<num_patches(); ii++) {
        send_vec_mp( patch(ii),target);
    }
    for (unsigned int ii=0; ii<num_points(); ii++) {
        send_vec_mp( point(ii) ,target);
    }
    
    char * namebuffer = (char *) br_malloc(1024*sizeof(char));
    
	
    free(namebuffer);
    return;
}
void WitnessSet::write_homogeneous_coordinates(boost::filesystem::path filename) const
{

	
	FILE *OUT  = safe_fopen_write(filename.c_str()); // open the output file
	
	
	fprintf(OUT,"%zu\n\n",num_points()); // print the header line
	
	for (unsigned int ii=0; ii<num_points(); ++ii) {
		vec_mp &curr_point = point(ii);
		for ( int jj=0; jj< curr_point->size; jj++) {
			print_mp(OUT,0,&( curr_point->coord[jj]));
			fprintf(OUT,"\n");
		}
		fprintf(OUT,"\n");
	}
	
	fclose(OUT); // close the output file
	
	return;
}
void WitnessSet::only_first_vars(int num_vars)
{
	
	vec_mp tempvec;  init_vec_mp2(tempvec, num_vars, 1024);
	tempvec->size = num_vars;
	
	for (unsigned int ii=0; ii<num_points(); ii++) {
		vec_mp & curr_point = point(ii);
		
		for (int jj=0; jj<num_vars; jj++) {
			set_mp(&tempvec->coord[jj], &curr_point->coord[jj]);
		}
		
		change_size_vec_mp(curr_point, num_vars);  curr_point->size = num_vars;
		vec_cp_mp(curr_point, tempvec);
	}
	
	
	this->num_vars_ = num_vars;
	
	int patch_size_counter = 0, trim_from_here =  0;
	for (unsigned int ii=0; ii<num_patches(); ii++) {
		patch_size_counter += patch(ii)->size;
		if (patch_size_counter == num_vars)
		{
			trim_from_here = ii+1;
		}
	}
	
	if (trim_from_here==0) {
		std::cerr << "problem: the sum of the patch sizes never equalled the number of variables to trim to...\nhence, the trimming operation could not complete." << std::endl;
		this->print_to_screen();
		deliberate_segfault();
	}
	
	for (unsigned int ii=trim_from_here; ii<num_patches(); ii++) {
		clear_vec_mp(patch(ii));
	}
	
	patch_mp_ = (vec_mp *) br_realloc(patch_mp_, trim_from_here* sizeof(vec_mp));
	num_patches_ = trim_from_here;
	
	for (unsigned int ii=0; ii<num_linears(); ii++) {
		linear(ii)->size = num_vars;
	}
	
	clear_vec_mp(tempvec);
	return;
}
Exemple #8
0
 double area() const 
 {
     double sum = 0.0;
     double x(0);
     double y(0);
     rewind(0);
     double xs = x;
     double ys = y;
     for (unsigned i=0;i<num_points();++i)
     {
         double x0,y0;
         vertex(&x0,&y0);
         sum += x * y0 - y * x0;
         x = x0;
         y = y0;
     }
     return (sum + x * ys - y * xs) * 0.5;
 }
Exemple #9
0
 box2d<double> envelope() const
 {
     box2d<double> result;
     double x(0);
     double y(0);
     rewind(0);
     for (unsigned i=0;i<num_points();++i)
     {
         vertex(&x,&y);
         if (i==0)
         {
             result.init(x,y,x,y);
         }
         else
         {
             result.expand_to_include(x,y);
         }
     }
     return result;
 }
Exemple #10
0
void WitnessSet::write_dehomogenized_coordinates(boost::filesystem::path filename,std::set<unsigned int> indices) const
{
	
	for (auto ii=indices.begin(); ii!=indices.end(); ++ii) {
		if (*ii >= this->num_points()) {
			std::cout << "requested to print out-of-range point index " << *ii << " to a dehomogenized file." << std::endl;
			std::cout << "[this WitnessSet contains " << num_points() << " points.]" << std::endl;
			br_exit(66190);
		}
	}
	
	
	
	
	vec_mp result; init_vec_mp(result,1);
	
	
	FILE *OUT = safe_fopen_write(filename.c_str()); // open the output file.
	
	fprintf(OUT,"%lu\n\n",indices.size()); // print the header line
	for (auto ii=indices.begin(); ii!=indices.end(); ++ii) {
		if (this->num_synth_vars()>0) {
			dehomogenize(&result,this->point(*ii), num_natty_vars_);
		}
		else{
			dehomogenize(&result,this->point(*ii));
		}
		
		for (int jj=0; jj<num_natty_vars_-1; jj++) {
			print_mp(OUT, 0, &result->coord[jj]);
			fprintf(OUT, "\n");
		}
		fprintf(OUT,"\n");
	}
	
	fclose(OUT);
	
	clear_vec_mp(result);
	return;
}
Exemple #11
0
void
line_spline(F_line *l, int type_value)
{
    F_spline	   *s;

    if (num_points(l->points) < CLOSED_SPLINE_MIN_NUM_POINTS) {
	put_msg("Not enough points for a spline");
	beep();
	return;
    }

    if ((s = create_spline()) == NULL)
        return;
    s->type = type_value;

    if (l->type == T_POLYGON)
	s->points = copy_points(l->points->next);
    else
	s->points = copy_points(l->points);

    s->style = l->style;
    s->thickness = l->thickness;
    s->pen_color = l->pen_color;
    s->fill_color = l->fill_color;
    s->depth = l->depth;
    s->style_val = l->style_val;
    s->cap_style = l->cap_style;
    s->pen_style = l->pen_style;
    s->fill_style = l->fill_style;
    s->sfactors = NULL;
    s->next = NULL;

    if (l->for_arrow) {
	s->for_arrow = create_arrow();
	s->for_arrow->type = l->for_arrow->type;
	s->for_arrow->style = l->for_arrow->style;
	s->for_arrow->thickness = l->for_arrow->thickness;
	s->for_arrow->wd = l->for_arrow->wd;
	s->for_arrow->ht = l->for_arrow->ht;
    } else {
	s->for_arrow = NULL;
    }
    if (l->back_arrow) {
	s->back_arrow = create_arrow();
	s->back_arrow->type = l->back_arrow->type;
	s->back_arrow->style = l->back_arrow->style;
	s->back_arrow->thickness = l->back_arrow->thickness;
	s->back_arrow->wd = l->back_arrow->wd;
	s->back_arrow->ht = l->back_arrow->ht;
    } else {
	s->back_arrow = NULL;
    }
    /* A spline must have an s parameter for each point */
    if (!make_sfactors(s)) {
	free_spline(&s);
	return;
    }

    /* Get rid of the line and draw the new spline */
    delete_line(l);
    /* now put back the new spline */
    mask_toggle_splinemarker(s);
    list_add_spline(&objects.splines, s);
    redisplay_spline(s);
    set_action_object(F_CONVERT, O_POLYLINE);
    set_latestspline(s);
    set_modifiedflag();
}
Exemple #12
0
void WitnessSet::merge(const WitnessSet & W_in, tracker_config_t * T)
{
	
	//error checking first
	if ( (num_vars_==0) && (W_in.num_vars_!=0) && (num_points()==0)) {
		num_vars_ = W_in.num_vars_;
		num_natty_vars_ = W_in.num_natty_vars_;
	}

	
	
	
	if (W_in.num_natty_vars_ != this->num_natty_vars_) {
		std::stringstream ss;
		ss << "merging two witness sets with differing numbers of natural variables. "<< W_in.num_natural_variables() <<" merging set, "<< this->num_natural_variables() << " existing\n",
		throw std::logic_error(ss.str());
	}
	
	//just mindlessly add the linears.  up to user to ensure linears get merged correctly.  no way to know what they want...
	for (unsigned int ii = 0; ii<W_in.num_linears(); ii++) {
		WitnessSet::add_linear(W_in.linear(ii));
	}
	
	
	for (unsigned int ii = 0; ii<W_in.num_points(); ii++) {
		int is_new = 1;
		vec_mp & in_point = W_in.point(ii);
		for (unsigned int jj = 0; jj<num_points(); jj++){
			vec_mp & curr_point = this->point(jj);
			
			//cache the sizes
			int in_size = in_point->size;
			int curr_size = curr_point->size;
			
			
			in_point->size = this->num_natural_variables();
			curr_point->size = this->num_natural_variables();
			
			if (isSamePoint_homogeneous_input(curr_point, in_point, T->final_tol_times_mult)) {
				is_new = 0;
				
				in_point->size = in_size;
				curr_point->size = curr_size;
				break;
			}
			
			// restore the sizes
			in_point->size = in_size;
			curr_point->size = curr_size;
		}
		
		if (is_new==1)
			WitnessSet::add_point( (in_point) );
	}
	
	
	for (unsigned int ii = 0; ii<W_in.num_patches(); ii++) {
		int is_new = 1;
		
		for (unsigned int jj = 0; jj<this->num_patches(); jj++){
			if ( this->patch(jj)->size ==  W_in.patch(ii)->size) {
				if (isSamePoint_inhomogeneous_input(patch(jj), W_in.patch(ii), T->final_tol_times_mult)) {
					is_new = 0;
					break;
				}
			}
		}
		
		if (is_new==1)
			WitnessSet::add_patch(W_in.patch(ii));
	}
	
	
	
	return;
}//re: merge_witness_sets
Exemple #13
0
void WitnessSet::sort_for_inside_sphere(comp_mp radius, vec_mp center)
{
	
	
	
	
	int num_good_pts = 0;
	
	
	std::vector<int> is_ok;
	
	vec_mp temp_vec; init_vec_mp(temp_vec,0);
	comp_mp temp; init_mp(temp);
	
	for (unsigned int ii = 0; ii<num_points(); ++ii) {
		
		
		
		dehomogenize(&temp_vec, point(ii),num_natty_vars_);
		temp_vec->size = center->size;
		
		norm_of_difference(temp->r, temp_vec, center);
		if ( mpf_cmp(temp->r, radius->r) < 0   ){
			is_ok.push_back(1);
			num_good_pts++;
		}
		else
		{
			is_ok.push_back(0);
		}
		
		
		
	}
	
	
	
	vec_mp *transferme = (vec_mp *)br_malloc(num_good_pts*sizeof(vec_mp));
	int counter = 0;
	for (unsigned int ii=0; ii<num_points(); ++ii) {
		if (is_ok[ii]==1) {
			init_vec_mp2(transferme[counter],0,1024);  transferme[counter]->size = 0;
			vec_cp_mp(transferme[counter], point(ii));
			counter++;
		}
	}
	
	if (counter!= num_good_pts) {
		printf("counter mismatch\n");
		br_exit(271);
	}
	
	for (unsigned int ii=0; ii<num_points(); ii++) {
		clear_vec_mp(point(ii));
	}
	free(pts_mp_);
	
	
	num_pts_ = num_good_pts;
	pts_mp_ = transferme;
	
	clear_vec_mp(temp_vec);
	clear_mp(temp);
	return;
}
Exemple #14
0
// T is necessary for the tolerances.
void WitnessSet::sort_for_unique(tracker_config_t * T)
{
	
	if (num_vars_==0) {
		throw std::logic_error("sorting witness set with 0 variables for uniqueness");
	}
	
	int curr_uniqueness;
	int num_good_pts = 0;
	std::vector<int> is_unique;
	
	for (unsigned int ii = 0; ii<num_points(); ++ii) {
		vec_mp &curr_point = point(ii);
		
		curr_uniqueness = 1;
		
		int prev_size_1 = curr_point->size;  curr_point->size = num_natty_vars_; // cache and change to natural number
		
		for (unsigned int jj=ii+1; jj<num_points(); ++jj) {
			vec_mp & inner_point = point(jj);
			int prev_size_2 = inner_point->size; inner_point->size = num_natty_vars_; // cache and change to natural number
			if ( isSamePoint_homogeneous_input(curr_point,inner_point,T->final_tol_times_mult) ){
				curr_uniqueness = 0;
			}
			inner_point->size = prev_size_2; // restore
		}
		curr_point->size = prev_size_1; // restore
		
		if (curr_uniqueness==1) {
			is_unique.push_back(1);
			num_good_pts++;
		}
		else {
			is_unique.push_back(0);
		}
		
	}
	
	
	
	vec_mp *transferme = (vec_mp *)br_malloc(num_good_pts*sizeof(vec_mp));
	int counter = 0;
	for (unsigned int ii=0; ii<num_points(); ++ii) {
		if (is_unique[ii]==1) {
			
			init_vec_mp2(transferme[counter],num_vars_,1024);  transferme[counter]->size = num_vars_;
			vec_cp_mp(transferme[counter], point(ii));
			counter++;
		}
	}
	
	if (counter!= num_good_pts) {
		std::logic_error("counter mismatch");
	}
	
	if (num_points()>0) {
		for (unsigned int ii=0; ii<num_points(); ii++) {
			clear_vec_mp(point(ii));
		}
		free(pts_mp_);
	}
	
	
	num_pts_ = num_good_pts;
	pts_mp_ = transferme;
	
	return;
}
Exemple #15
0
void WitnessSet::print_to_file(boost::filesystem::path filename) const
{
	// print back into the same format we parse from.
	
	
	FILE *OUT = safe_fopen_write(filename);
	
	
	fprintf(OUT, "%zu %d %d\n\n", num_points(), dim_, comp_num_);
	


	for (unsigned int ii=0; ii < num_points(); ii++) {
		vec_mp & curr_point = point(ii);
		//print the witness points into file
		for (int jj=0; jj < curr_point->size; ++jj) {
			mpf_out_str(OUT,10,0,curr_point->coord[jj].r); // 10 is the base
			fprintf(OUT," ");
			mpf_out_str(OUT,10,0,curr_point->coord[jj].i);
			fprintf(OUT,"\n");
		}
		fprintf(OUT,"\n");
	}
	fprintf(OUT,"\n");
	
	
	
	
	fprintf(OUT, "%zu %d\n", num_linears(), num_vars_);
	
	
	for (unsigned int ii=0; ii < num_linears(); ii++) {

		for (int jj=0; jj < linear(ii)->size; jj++) {
			mpf_out_str(OUT,10,0,linear(ii)->coord[jj].r); // 10 is the base
			fprintf(OUT," ");
			mpf_out_str(OUT,10,0,linear(ii)->coord[jj].i);
			fprintf(OUT,"\n");
		}
		
		fprintf(OUT,"\n");
	}
	fprintf(OUT,"\n");
	
	
	
	fprintf(OUT, "%zu %d\n", num_patches(), num_vars_);
	
	for (unsigned int ii=0; ii < num_patches(); ii++) {
		
		vec_mp & curr_patch = patch(ii);
		
		//read the patch into memory
		for (int jj=0; jj < curr_patch->size; jj++) {
			mpf_out_str(OUT,10,0,curr_patch->coord[jj].r); // 10 is the base
			fprintf(OUT," ");
			mpf_out_str(OUT,10,0,curr_patch->coord[jj].i);
			fprintf(OUT,"\n");
		}
		
		fprintf(OUT,"\n");
	}
	fprintf(OUT,"\n");
	fclose(OUT);
	
	
	
	
	
	return;
}