Python, OpenGL to pick geometry only defined in the script
You can use the functions from mathutils.geometry to deal with geometry


intersect_ray_tri
tesselate_polygon


further you can use the functions from view3d_utils to deal with viewport coordinates

From the template operator_modal_view3d_raycast.py:

def main(context, event, ray_max=1000.0):
    """Run this function on left mouse, execute the ray cast"""
    # get the context arguments
    scene = context.scene
    region = context.region
    rv3d = context.region_data
    coord = event.mouse_region_x, event.mouse_region_y

    # get the ray from the viewport and mouse
    view_vector = view3d_utils.region_2d_to_vector_3d(region, rv3d, coord)
    ray_origin = view3d_utils.region_2d_to_origin_3d(region, rv3d, coord)

    ray_target = ray_origin + (view_vector * ray_max)