Exemple #1
0
void test_bsp__cube_bsp_can_return_poly_list_of_equal_length(void) {
	// We test that when we get a list of polygons from a BSP tree of a cube
	// and assert that we have the same number of polygons as when we started.
	//
	// A cube is nice here because no faces need to be split, so polygon
	// counts before and after remain the same.
	char cube_path[] = CLAR_FIXTURE_PATH "cube.stl";
	stl_object *stl_cube = stl_read_file(cube_path, 0);
	klist_t(poly) *cube_polys = kl_init(poly);
	cl_assert(stl_cube != NULL);
	cl_assert(stl_cube->facet_count > 0);

	for(int i = 0; i < stl_cube->facet_count; i++) {
		stl_facet *face = &stl_cube->facets[i];
		poly_t *poly = poly_make_triangle(face->vertices[0], face->vertices[1], face->vertices[2]);
		*kl_pushp(poly, cube_polys) = poly;
		cl_assert(poly);
	}

	bsp_node_t *cube_bsp = alloc_bsp_node();
	cl_assert(cube_bsp != NULL);
	cl_assert(bsp_build(cube_bsp, cube_polys, 1) == cube_bsp);
	klist_t(poly) *results = bsp_to_polygons(cube_bsp, 0, NULL);

	cl_assert_equal_i(results->size, stl_cube->facet_count);

	if(stl_cube) stl_free(stl_cube);
	if(results) kl_destroy(poly, results);
	kl_destroy(poly, cube_polys);
}
// ---------------------------------------------------------------------------
// 
// ------------
bool bvDefPaletteQuick::read(){
_bTrace_("bvDefPaletteQuick::read",true);
bool	made=false,b=false;
	if(!_root){
		make();
		made=true;
	}
	
_tm_("make passé");
bGenericXMLBaseElement* chld;
bGenericXMLBaseElement* elt;
bvDefPaletteQuickStyle*	stl;
char					val[_values_length_max_];
int						i;
	
	for(;;){
// Identification		
_tm_("Identification");
		chld=_gapp->classMgr()->NthElement(_root,1,"styleidentification");
		if(!chld){
			break;
		}
		elt=_gapp->classMgr()->NthElement(chld,1,"name");
		if(!elt){
			break;
		}
		elt->getvalue(_name);
		elt=_gapp->classMgr()->NthElement(chld,1,"version");
		if(!elt){
			break;
		}
		elt->getvalue(_vers);
		if(strlen(_vers)==0){
			strcpy(_vers,"3.0.0");
		}
		
// Globals
_tm_("Globals");
		chld=_gapp->classMgr()->NthElement(_root,1,"globals");
		if(!chld){
			break;
		}
		
		elt=_gapp->classMgr()->NthElement(chld,1,"classfield");
		if(!elt){
			break;
		}
		elt->getvalue(val);
		_fld=_tp->fields()->get_index(val);
		if(_fld==0){
			_fld=kOBJ_SubType_;
		}
		if(_fld!=kOBJ_SubType_){
			stl_free();
			stl_alloc();
		}
		
		elt=_gapp->classMgr()->NthElement(chld,1,"scaleref");
		if(!elt){
			break;
		}
		elt->getvalue(val);
		_sref=matof(val);
		elt=_gapp->classMgr()->NthElement(chld,1,"unitcoef");
		if(!elt){
			break;
		}
		elt->getvalue(val);
		_coef=matof(val);
		elt=_gapp->classMgr()->NthElement(chld,1,"sort");
		if(!elt){
			break;
		}
		elt->getvalue(val);
		_sort=atoi(val);
		elt=_gapp->classMgr()->NthElement(chld,1,"passcount");
		if(!elt){
			break;
		}
		elt->getvalue(val);
		_pssmax=atoi(val);
		
// Condition		
_tm_("Condition");
		chld=_gapp->classMgr()->NthElement(_root,1,"condition");
		if(!chld){
			break;
		}
		if(chld->countelements()>0){
			elt=chld->getelement(1);
			elt->getclassname(val);
			for(i=1;i<=nsvdef_op_max;i++){
				if(!strcmp(val,nsvdef_op_list[i])){
					chld=elt;
					if(chld->countelements()==2){
						elt=chld->getelement(1);
						elt->getvalue(val);
						_cfld=_tp->fields()->get_index(val);
						if(_cfld){
							elt=chld->getelement(2);
							elt->getvalue(_cval);
						}
					}
					else{
						_cfld=0;
					}
					break;
				}
			}
			if(i==nsvdef_op_max+1){
				_cfld=0;
			}
			else{
				_cop=i;
			}
		}
		else{
			_cfld=0;
		}
_tm_("_cop="+_cop);
		
// StyleRuns
_tm_("StyleRuns");
// Load des styles et init du flag cmyk
		for(int i=1;i<=_styles.count();i++){
			_styles.get(i,&stl);
			stl->load(_root);
			if(_cmyk==false){
				_cmyk=(stl->_cc==5);
			}
		}
// Remise de tous les styles sur la même colorimétrie
		for(int i=1;i<=_styles.count();i++){
			_styles.get(i,&stl);
			stl->_cc=(_cmyk)?5:4;
		}
		
        b=true;
        
		break;
	}
	
	if(made){
		_gapp->classMgr()->ReleaseXMLInstance(_root);
		_root=NULL;
	}
	
	return(b);
}