示例#1
0
void update_all_code_references_in_value(caValue* value, Branch* oldBranch, Branch* newBranch)
{
    for (ValueIterator it(value); it.unfinished(); it.advance()) {
        caValue* val = *it;
        if (is_ref(val)) {
            set_term_ref(val, translate_term_across_branches(as_term_ref(val),
                oldBranch, newBranch));
            
        } else if (is_branch(val)) {

            // If this is just a reference to 'oldBranch' then simply update it to 'newBranch'.
            if (as_branch(val) == oldBranch)
                set_branch(val, newBranch);

            // Noop on null branch.
            if (as_branch(val) == NULL)
                continue;

            // Noop if branch has no owner.
            Term* oldTerm = as_branch(val)->owningTerm;
            if (oldTerm == NULL)
                continue;

            Term* newTerm = translate_term_across_branches(oldTerm, oldBranch, newBranch);
            if (newTerm == NULL) {
                set_branch(val, NULL);
                continue;
            }

            set_branch(val, newTerm->nestedContents);
        }
    }
}
示例#2
0
void Term__function(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL)
        return circa_output_error(stack, "NULL reference");
    set_branch(circa_output(stack, 0), function_contents(as_function(t->function)));
}
示例#3
0
void Term__contents(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL) {
        circa_output_error(stack, "NULL reference");
        return;
    }
    set_branch(circa_output(stack, 0), t->nestedContents);
}
示例#4
0
void Term__parent(caStack* stack)
{
    Term* t = as_term_ref(circa_input(stack, 0));
    if (t == NULL) {
        circa_output_error(stack, "NULL reference");
        return;
    }
    set_branch(circa_output(stack, 0), t->owningBranch);
}
示例#5
0
void branch_ref(caStack* stack)
{
    Term* input0 = (Term*) circa_caller_input_term(stack, 0);
    Branch* branch = input0->nestedContents;
    if (branch != NULL) {
        gc_mark_object_referenced(&branch->header);
    }
    set_branch(circa_output(stack, 0), branch);
}
示例#6
0
void Branch__functions(caStack* stack)
{
    Branch* branch = as_branch(circa_input(stack, 0));
    if (branch == NULL)
        return circa_output_error(stack, "NULL branch");

    caValue* output = circa_output(stack, 0);
    set_list(output, 0);

    for (BranchIteratorFlat it(branch); it.unfinished(); it.advance()) {
        Term* term = *it;
        if (is_function(term)) {
            set_branch(list_append(output), function_contents(as_function(term)));
        }
    }
}
示例#7
0
int main ( int narg, char **argv ) {
	
	// parse command line ----------------------------------------------
	po::options_description general_opt ( "Allowed options are: " );
	general_opt.add_options()
		( "help,h", "display this message." )
		( "initial,i", po::value< std::string >(), "Initial skeleton pgm filename." )
		( "reduced,r", po::value< std::string >(), "Reduced skeleton pgm filename." )
		( "label,l", po::value< std::string >(), "(part of the) Reduced skeleton being labeled pgm filename." )
		( "selection,s", po::value< std::string >()->multitoken(), "Catch branch touching the given components\' labels of the reduced skeleton.")
		( "output,o", po::value< std::string >(), "Extended labeled skeleton pgm filename.");

	bool parseOK = true ;
	po::variables_map vm;
	try {
		po::store(po::parse_command_line(narg, argv, general_opt), vm);  
	} catch ( const std::exception& ex ) {
		parseOK = false ;
		std::cerr<< "Error checking program options: "<< ex.what()<< endl;
		return -1 ;
	}

	po::notify ( vm );
	if (!parseOK || vm.count ( "help" ) ||narg<=1 ) {
		errorAndHelp( general_opt ) ;
		return -1 ;
	}
	if ( ! vm.count("initial") ) missingParam( "initial" ) ;
	if ( ! vm.count("label") ) missingParam( "label" ) ;
	if ( ! vm.count("reduced") ) missingParam( "reduced" ) ;
	if ( ! vm.count("output") ) missingParam( "output" ) ;
	
	std::string initialSkelFile = vm["initial"].as<std::string>() ;
	std::string reducedSkelFile = vm["reduced"].as<std::string>() ;
	std::string reducedLabelSkelFile = vm["label"].as<std::string>() ;
	std::string outputSkelFile  = vm["output"].as<std::string>() ;
	
	QList< tlabel > Labels ;
	if ( vm.count( "selection" ) ) {
		QStringList selectedLabels = QString( "%1").arg( vm["selection"].as< std::string >().c_str() ).split( " ", QString::SkipEmptyParts) ;
		while ( !selectedLabels.isEmpty() )
			Labels.append( (tlabel)selectedLabels.takeAt(0).toInt() ) ;
		qSort( Labels.begin(), Labels.end(), qLess<tlabel>() ) ;
		
		std::cout<<"Selection : ";
		for ( QList< tlabel >::ConstIterator lbl = Labels.begin() ; lbl != Labels.end() ; lbl++ )
			std::cout<<"["<<(int) *lbl<<"] " ;
		std::cout<<std::endl;
	}
	
	BillonTpl< tlabel > *labelReducedSkel ;
	BillonTpl< arma::u8 > *initialSkel,
	                      *reducedSkel ;
	{
		Pgm3dFactory< tlabel > factory ;
		labelReducedSkel = factory.read( QString(reducedLabelSkelFile.c_str()) ) ;
	}
	{
		Pgm3dFactory< arma::u8 > factory ;
		initialSkel = factory.read( QString(initialSkelFile.c_str()) ) ;
		if ( initialSkel->max() > 1 ) *initialSkel /= initialSkel->max() ;
		reducedSkel = factory.read( QString(reducedSkelFile.c_str()) ) ;
		if ( reducedSkel->max() > 1 ) *reducedSkel /= reducedSkel->max() ;
	}
	
	QList< uint * > touching ;
	make_branch( initialSkel, reducedSkel, labelReducedSkel, touching ) ;
	delete reducedSkel ;
	
	ConnexComponentExtractor< arma::u8, tlabelbranch > CCE ;
	BillonTpl< tlabelbranch > * labelBranch = CCE.run( *initialSkel ) ;
	IOPgm3d< tlabelbranch, qtlabelbranch, false >::write( *labelBranch, "/tmp/whois429.pgm3d" ) ;
	delete initialSkel ;
	
	QMap< tlabelbranch, tlabel > NewLabelBranch ;
	QMap< tlabel, QList<tlabel> > edges ;
	set_branch( touching, labelReducedSkel, labelBranch, NewLabelBranch, Labels,edges ) ;
	attach_branch( labelReducedSkel, labelBranch, NewLabelBranch, Labels ) ;
	
	IOPgm3d< tlabel, qtlabel, false >::write( *labelReducedSkel, QString(outputSkelFile.c_str() ) ) ;
	
	while ( !touching.isEmpty() ) {
		delete [] touching.takeFirst() ;
	}
	delete labelReducedSkel ;
	delete labelBranch ;
	
	return 0 ;
}