void ofxStreetView::urlResponse(ofHttpResponse & response){ cout << "Status: " << response.status << endl; cout << "Request_url: " << response.request.url << endl; if((response.status==200) && (response.request.url == data_url )&& (!bDataLoaded)){ panoImages.clear(); ofxXmlSettings XML; XML.loadFromBuffer(response.data); pano_id = XML.getAttribute("panorama:data_properties", "pano_id", ""); text = XML.getValue("panorama:data_properties:text", ""); street_range = XML.getValue("panorama:data_properties:street_range", ""); region = XML.getValue("panorama:data_properties:region", ""); country = XML.getValue("panorama:data_properties:country", ""); lat = XML.getAttribute("panorama:data_properties", "original_lat", 0.0); lon = XML.getAttribute("panorama:data_properties", "original_lng", 0.0); elevation = XML.getAttribute("panorama:data_properties", "elevation_wgs84_m", -1); num_zoom_levels = XML.getAttribute("panorama:data_properties", "num_zoom_levels", 0); if(zoom>num_zoom_levels){ zoom = num_zoom_levels; } pano_yaw_deg = XML.getAttribute("panorama:projection_properties", "pano_yaw_deg", 0.0); tilt_yaw_deg = XML.getAttribute("panorama:projection_properties", "tilt_yaw_deg", 0.0); tilt_pitch_deg = XML.getAttribute("panorama:projection_properties", "tilt_pitch_deg", 0.0); //Get the base64 encoded data depth_map_base64 = XML.getValue("panorama:model:depth_map", ""); XML.pushTag("panorama"); XML.pushTag("annotation_properties"); int nLinks = XML.getNumTags("link"); for (int i = 0; i < nLinks; i++) { Link l; l.pano_id = XML.getAttribute("link", "pano_id", ""); l.yaw_deg = XML.getAttribute("link", "yaw_deg", 0.0f); links.push_back(l); XML.removeTag("link",0); } XML.popTag(); XML.popTag(); // Decode the depth map ( Credits to Paul Wagener https://github.com/PaulWagener/Streetview-Explorer ) // The depth map is encoded as a series of pixels in a 512x256 image. Each pixels refers // to a depthMapPlane which are also encoded in the data. Each depthMapPlane has three elements: // The x,y,z normals and the closest distance the plane has to the origin. This uniquely // identifies the plane in 3d space. // if(depth_map_base64 != ""){ //Decode base64 vector<unsigned char> depth_map_compressed(depth_map_base64.length()); int compressed_length = decode_base64(&depth_map_compressed[0], &depth_map_base64[0]); //Uncompress data with zlib //TODO: decompress in a loop so we can accept any size unsigned long length = 512 * 256 + 5000; vector<unsigned char> depth_map(length); int zlib_return = uncompress(&depth_map[0], &length, &depth_map_compressed[0], compressed_length); if (zlib_return != Z_OK) throw "zlib decompression of the depth map failed"; //Load standard data const int headersize = depth_map[0]; const int numPanos = depth_map[1] | (depth_map[2] << 8); mapWidth = depth_map[3] | (depth_map[4] << 8); mapHeight = depth_map[5] | (depth_map[6] << 8); const int panoIndicesOffset = depth_map[7]; if (headersize != 8 || panoIndicesOffset != 8) throw "Unexpected depth map header"; //Load depthMapIndices depthmapIndices = vector<unsigned char>(mapHeight * mapWidth); memcpy(&depthmapIndices[0], &depth_map[panoIndicesOffset], mapHeight * mapWidth); //Load depthMapPlanes depthmapPlanes = vector<DepthMapPlane> (numPanos); memcpy(&depthmapPlanes[0], &depth_map[panoIndicesOffset + mapHeight * mapWidth], numPanos * sizeof (struct DepthMapPlane)); } bDataLoaded = true; if(bTexture){ downloadPanorama(); } } else if(response.request.url.find("http://cbk0.google.com/cbk?output=tile&panoid="+pano_id) == 0){ ofImage img; img.loadImage(response.data); panoImages.push_back(img); } }
/*----------------------------------------------------------------------------*/ System Surface::allocate_system() { const int n = 4*w*h; const int m = w*h; const long double w2 = (long double)(w)/2.; const long double h2 = (long double)(h)/2.; const long double sqrt_L1 = sqrtl(LAMBDA_1); const long double sqrt_1ML1 = sqrtl(1.-LAMBDA_1); const long double sqrt_L2 = sqrtl(LAMBDA_2); // builds B long double *b = new long double[n]; for(int u=0; u<w; u++) for(int v=0; v<h; v++) { int i = u * h + v; b[i] = sqrt_L1 * mu(u,v) * depth_map(u,v); } for(int i=m; i<n; i++) b[i] = 0.; Zvect *B = new Zvect(n, b); // builds A SparseMat *A = new SparseMat(n,m); // part 1 for(int u=0; u<w; u++) for(int v=0; v<h; v++) { int i = u * h + v; A->add_coeff(i, i, sqrt_L1*mu(u,v)); } // part 2 long double dx_filter[] = {-1./12., 0. , 1./12., -4./12., 0. , 4./12., -1./12., 0. , 1./12.}; for(int u=0; u<w; u++) for(int v=0; v<h; v++) { int j = u * h + v; int i = m + j; long double x = ((long double)(u)-w2)/fx; long double y = ((long double)(v)-h2)/fy; const vec& n = caracs(u,v).n; long double dx_weight = sqrt_1ML1 * (n[2] - (n[0]*x + n[1]*y)); A->add_row_coeff(i, make_filter(u,v, dx_filter, dx_weight)); A->add_coeff(i, j, -sqrt_1ML1 * n[0] / fx); } // part 3 long double dy_filter[] = { 1./12., 4./12. , 1./12., 0., 0. , 0., -1./12., -4./12. , -1./12.,}; for(int u=0; u<w; u++) for(int v=0; v<h; v++) { int j = u * h + v; int i = 2*m + j; long double x = ((long double)(u)-w2)/fx; long double y = ((long double)(v)-h2)/fy; const vec& n = caracs(u,v).n; long double dy_weight = sqrt_1ML1 * (n[2] - (n[0]*x + n[1]*y)); A->add_row_coeff(i, make_filter(u,v, dy_filter, dy_weight)); A->add_coeff(i, j, -sqrt_1ML1 * n[1] / fy); } // part 4 long double laplacian_filter[] = { -1., -1. , -1., -1., 8. , -1., -1., -1. , -1.}; for(int u=0; u<w; u++) for(int v=0; v<h; v++) { int i = 3*m + u * h + v; A->add_row_coeff(i, make_filter(u,v, laplacian_filter, sqrt_L2)); } return pair<SparseMat*, Zvect*>(A,B); }