FundamentalMatrixModel::FundamentalMatrixModel()
{
    parameters.resize( get_num_parameters() );
    return;
}
Example #2
0
void HomographyModel::estimate_from_minimal_set(const vector< ScoredMatch> &data_points)
{ // given m points estimate the parameters vector

    // based on vxl rrel_homography2d_est :: fit_from_minimal_set
    if ( data_points.size() < get_num_points_to_estimate())
        throw runtime_error("Not enough points to estimate the HomographyModel parameters");

    vnl_matrix< double > A(9, 9, 0.0);
    for ( int i=0; i < get_num_points_to_estimate(); i+=1 )
    { // for i = 0,1,2,3
        vgl_homg_point_2d<double> from_point(data_points[i].feature_a->x, data_points[i].feature_a->y);
        vgl_homg_point_2d<double> to_point(data_points[i].feature_b->x, data_points[i].feature_b->y);

        if (false)
        { // just for debugging
            printf("from_points[%i] -> to_points[%i] ==", i,i);
            cout << from_point << " -> " << to_point << endl;
        }

        A( 2*i, 0 ) = A( 2*i+1, 3 ) = from_point.x() * to_point.w();
        A( 2*i, 1 ) = A( 2*i+1, 4 ) = from_point.y() * to_point.w();
        A( 2*i, 2 ) = A( 2*i+1, 5 ) = from_point.w() * to_point.w();
        A( 2*i, 6 ) = -1 * from_point.x() * to_point.x();
        A( 2*i, 7 ) = -1 * from_point.y() * to_point.x();
        A( 2*i, 8 ) = -1 * from_point.w() * to_point.x();
        A( 2*i+1, 6 ) = -1 * from_point.x() * to_point.y();
        A( 2*i+1, 7 ) = -1 * from_point.y() * to_point.y();
        A( 2*i+1, 8 ) = -1 * from_point.w() * to_point.y();
    }


    vnl_svd<double> svd( A, 1.0e-8 );

    if (false)
    { // just for debugging

        cout << "A == " << A << endl;
        cout << "svd(A) == " << svd << endl;
    }


    const unsigned int homog_dof_ = 8;
    if ( svd.rank() < homog_dof_ )
    {
        // singular fit
        if (true)
        { // just for debugging
            cout << "svd.rank() == " << svd.rank() << endl;

            for ( unsigned int i=0; i<get_num_points_to_estimate(); ++i )
            {
                vgl_homg_point_2d<double> from_point(data_points[i].feature_a->x, data_points[i].feature_a->y);
                vgl_homg_point_2d<double> to_point(data_points[i].feature_b->x, data_points[i].feature_b->y);

                cout << "from->to point[i]-> " << from_point << "->" << to_point << endl;
            }

        }

        throw runtime_error("HomographyModel::estimate_from_minimal_set failed");
    }

    vnl_vector<double> params = svd.nullvector();
    parameters.resize(get_num_parameters());

    if (params.size() != parameters.size() )
    {
        throw runtime_error("HomographyModel::estimate_from_minimal_set internal error");
    }

    for ( unsigned int i=0; i<get_num_parameters(); i+=1 )
    {
        parameters[i] = params[i]; // copy the result
    }

   if ( false ) {
	    cout << "HomographyModel parameters: " << parameters << endl;
   }
   
    return;
} // end of 'HomographyModel::estimate_from_minimal_set'
Example #3
0
void generateSymbolTable(tree *node){
int i = 0, check = 0, rettype, func;
static int scope = 0, pos = 1;
tree *child;

	if(node->nodeKind == DECL){
		scope = 0;
	}
	if(node->nodeKind == VARDECL){
			if(scope == 0){
				if(node->isArray == 1){
					if(ST_Insert_Array(hashtbl, node->children[1]->strval, pos++, scope, node->children[0]->val, node->children[2]->val, 1) == -1){
						error++;
                        	                printf("Line:%d Multiple array declaration of %s in the global scope\n", node->children[1]->lineno, node->children[1]->strval);
                                	        return;
                                        }
//	                                printf("Inserting Array %s of type %d limit %d pos %d and scope %d\n", node->children[1]->strval, node->children[0]->val, node->children[2]->val, pos, scope);
				}else{
//					printf("Inserting %s of type %d pos %d and scope %d\n", node->children[1]->strval, node->children[0]->val, pos, scope);
					if(ST_Insert(hashtbl, node->children[1]->strval, pos++, scope, node->children[0]->val) == -1){
						error++;
	 	                        	printf("Line:%d Multiple variable declaration of %s in the global scope\n", node->children[1]->lineno, node->children[1]->strval);
						return;
					} 
				}
			}else{
				if(node->isArray == 1){
                                        if(ST_Insert_Array(hashtbl, node->children[1]->strval, 0, scope, node->children[0]->val, node->children[2]->val, 1) == -1){
						error++;
                                                printf("Line:%d Multiple array declaration of %s in the local scope\n", node->children[1]->lineno, node->children[1]->strval);
                                                return;
                                        }
//                                      printf("Inserting Array %s of type %d limit %d pos %d and scope %d\n", node->children[1]->strval, node->children[0]->val, node->children[2]->val, pos, scope);
                                }else{
					if(ST_Insert(hashtbl, node->children[1]->strval, 0, scope, node->children[0]->val) == -1){
						error++;
        	                        	printf("Line:%d Multiple variable declaration of %s in the local scope\n", node->children[1]->lineno,  node->children[1]->strval);
						return;
				 	}
//				printf("Inserting %s of type %d pos 0 and scope %d\n", node->children[1]->strval, node->children[0]->val, scope);
				}
		
			}
	}
		
	if(node->nodeKind == FUNDECL){
			scope = 0;
			count = 0;
//			printf("Inserting %s of type %d pos %d and scope %d\n", node->children[1]->strval, node->children[0]->val, pos, scope);
			if(node->children[2]->nodeKind == FORMALDECLLIST){
				get_num_parameters(node->children[2]);
//				printf("Total parameters in %s function is %d\n", node->children[1]->strval, count);
				if(ST_Insert_Function(hashtbl, node->children[1]->strval, pos++, scope, node->children[0]->val, count, node->children[2]) == -1){
						error++;
					printf("Line:%d Multiple declaration of function %s \n", node->children[1]->lineno, node->children[1]->strval);
					return;
				}
				scope = pos-1;
			}
			else{
				if(ST_Insert(hashtbl, node->children[1]->strval, pos++, scope, node->children[0]->val) == -1){
						error++;
                                	printf("Line:%d Multiple declaration of function %s \n", node->children[1]->lineno, node->children[1]->strval);
	                                return;
                        	}
				scope = pos-1;
			}
        }
	if(node->nodeKind == FORMALDECL){
			if(ST_Insert(hashtbl, node->children[1]->strval, 0, scope, node->children[0]->val) == -1){
						error++;
                                printf("Line:%d Multiple declaration of variable %s in the same scope\n", node->children[1]->lineno, node->children[1]->strval);
				return;
			}
//			printf("Inserting %s of type %d pos 0 and scope %d\n", node->children[1]->strval, node->children[0]->val, scope);
	}
	if(node->nodeKind == ASSIGNSTMT){		
			if(node->children[0]->nodeKind == VAR){
				if((ST_Lookup(hashtbl, node->children[0]->children[0]->strval, scope)) == -1){
						error++;
	                                printf("Line:%d Undefined Variable %s\n", node->children[0]->children[0]->lineno, node->children[0]->children[0]->strval);
        	                        return;
                	        }
				if(node->children[0]->numChildren > 1){
					if(node->children[0]->children[1]->nodeKind == ADDEXPR){
						if(ST_IndexExists(hashtbl, node->children[0]->children[0]->strval, scope) == 1)
							CheckProperIndexType(node->children[1], node->children[0], scope);
						else{
						error++;
							printf("Line:%d Accessing scalar variable %s as an array\n", node->children[0]->children[0]->lineno, node->children[0]->children[0]->strval);
							return;
						}
					}
				}
				lreturn = ST_LookupReturnValue(hashtbl, node->children[0]->children[0]->strval, scope);
				RetValueExpr(node->children[2], scope);
			}
	}
	if(node->nodeKind == VAR){
			if((ST_Lookup(hashtbl, node->children[0]->strval, scope)) == -1){
						error++;
				printf("Line:%d Undeclared Variable %s\n", node->children[0]->lineno, node->children[0]->strval);
				return;
			}
//			printf("%s is present in symbol table\n", node->children[0]->strval);
			if(node->numChildren > 1){
				if(node->children[1]->nodeKind == ADDEXPR){
					if(ST_IndexExists(hashtbl, node->children[0]->strval, scope) == 1)
						CheckProperIndexType(node->children[1], node->children[0], scope);	
					else{
						error++;
						printf("Line:%d Accessing scalar variable %s as an array\n", node->children[0]->lineno, node->children[0]->strval);
						return;
					}
				}
			}
	}
	if(node->nodeKind == FUNCCALLEXPR){
			if((ST_Lookup(hashtbl, node->children[0]->strval, scope)) == -1){
						error++;
        	        	printf("Line:%d Undeclared Function %s\n", node->children[0]->lineno, node->children[0]->strval);
                	        return;
                        }
			if(node->numChildren == 1){
				 func = ST_FunctionParamMatch(hashtbl, node->children[0]->strval, scope, 0);
                                        if(func == 1){
						error++;
                                                printf("Line:%d Too few parameters for function:%s\n", node->children[0]->lineno, node->children[0]->strval);
                                                return;
                                        }
                                        else if(func == 2){
						error++;
                                                printf("Line:%d Too many parameters for function:%s\n", node->children[0]->lineno, node->children[0]->strval);
                                                return;
                                        }else{
					}			
			}
			if(node->numChildren > 1){
				if(node->children[1]->nodeKind == ARGLIST){
					funccount = 0;
					getparam(node->children[1], scope);
					func = ST_FunctionParamMatch(hashtbl, node->children[0]->strval, scope, funccount);
					if(func == 1){
						error++;
						printf("Line:%d Too few parameters for function:%s\n", node->children[0]->lineno, node->children[0]->strval);
						return;
					}
					else if(func == 2){
						error++;
						printf("Line:%d Too many parameters for function:%s\n", node->children[0]->lineno, node->children[0]->strval);
						return;
					}else{
						//Get_Types(node->children[1], scope);
						if((ST_GenerateSignatureCheck(hashtbl, node->children[0]->strval, scope, fun)) == -1){
						error++;
							printf("Line:%d Mismatch in arguments to the function %s\n", node->children[0]->lineno, node->children[0]->strval);
							return;
						}
					}		
				}
			}
	}	
	for(i = 0; i < node->numChildren; i++)
		generateSymbolTable(getChild(node, i));

}
Example #4
0
HomographyModel::HomographyModel()
{
    parameters.resize( get_num_parameters() );
    return;
}
Example #5
0
void get_num_parameters(tree *node){
int i;
if(node->nodeKind == FORMALDECL) count++;
for(i = 0; i < node->numChildren; i++)
	get_num_parameters(getChild(node, i));
}