bool test_29() { bool state = true; IP_Address ip0("2001:0db8:85a3:0000:0000:8a2e:0370:7334"); OS::get_singleton()->print("ip0 is %ls\n", String(ip0).c_str()); IP_Address ip(0x0123, 0x4567, 0x89ab, 0xcdef, true); OS::get_singleton()->print("ip6 is %ls\n", String(ip).c_str()); IP_Address ip2("fe80::52e5:49ff:fe93:1baf"); OS::get_singleton()->print("ip6 is %ls\n", String(ip2).c_str()); IP_Address ip3("::ffff:192.168.0.1"); OS::get_singleton()->print("ip6 is %ls\n", String(ip3).c_str()); String ip4 = "192.168.0.1"; bool success = ip4.is_valid_ip_address(); OS::get_singleton()->print("Is valid ipv4: %ls, %s\n", ip4.c_str(), success ? "OK" : "FAIL"); state = state && success; ip4 = "192.368.0.1"; success = (!ip4.is_valid_ip_address()); OS::get_singleton()->print("Is invalid ipv4: %ls, %s\n", ip4.c_str(), success ? "OK" : "FAIL"); state = state && success; String ip6 = "2001:0db8:85a3:0000:0000:8a2e:0370:7334"; success = ip6.is_valid_ip_address(); OS::get_singleton()->print("Is valid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL"); state = state && success; ip6 = "2001:0db8:85j3:0000:0000:8a2e:0370:7334"; success = (!ip6.is_valid_ip_address()); OS::get_singleton()->print("Is invalid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL"); state = state && success; ip6 = "2001:0db8:85f345:0000:0000:8a2e:0370:7334"; success = (!ip6.is_valid_ip_address()); OS::get_singleton()->print("Is invalid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL"); state = state && success; ip6 = "2001:0db8::0:8a2e:370:7334"; success = (ip6.is_valid_ip_address()); OS::get_singleton()->print("Is valid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL"); state = state && success; ip6 = "::ffff:192.168.0.1"; success = (ip6.is_valid_ip_address()); OS::get_singleton()->print("Is valid ipv6: %ls, %s\n", ip6.c_str(), success ? "OK" : "FAIL"); state = state && success; return state; };
std::tuple<I0, I1, O> operator()(I0 begin0, iterator_difference_t<I0> n0, I1 begin1, iterator_difference_t<I1> n1, O out, C r = C{}, P0 p0 = P0{}, P1 p1 = P1{}) const { using T = std::tuple<I0, I1, O>; auto &&ir = invokable(r); auto &&ip0 = invokable(p0); auto &&ip1 = invokable(p1); auto n0orig = n0; auto n1orig = n1; auto b0 = uncounted(begin0); auto b1 = uncounted(begin1); while(true) { if(0 == n0) { auto res = copy_n(b1, n1, out); begin0 = recounted(begin0, b0, n0orig); begin1 = recounted(begin1, res.first, n1orig); return T{begin0, begin1, res.second}; } if(0 == n1) { auto res = copy_n(b0, n0, out); begin0 = recounted(begin0, res.first, n0orig); begin1 = recounted(begin1, b1, n1orig); return T{begin0, begin1, res.second}; } if(ir(ip1(*b1), ip0(*b0))) { *out = *b1; ++b1; ++out; --n1; } else { *out = *b0; ++b0; ++out; --n0; } } }
/********************* Geometrical funcs *********************/ bool GeometricalFunctions::get_d_spheres_intersections(size_t num_dim,size_t* spheres_indices,double* q1,double* q2) { // prepare memory _planes_normals = new double*[num_dim]; _B = new double[num_dim]; _ortho_basis = new double*[num_dim]; _ortho_tmp = new double[num_dim]; _I = new double[num_dim]; _p1 = new double[num_dim]; // point of the d-planes intersectio size_t ip0 (spheres_indices[0]),ip1; for (size_t isphere = 0; isphere < num_dim - 1; isphere++) { _planes_normals[isphere] = new double[num_dim]; ip1 = spheres_indices[isphere + 1]; double dot(0.0); for (size_t idim = 0; idim < num_dim; idim++) { _planes_normals[isphere][idim] = _spheres[ip1][idim] - _spheres[ip0][idim]; double xm = 0.5 * (_spheres[ip1][idim] + _spheres[ip0][idim]); dot += _planes_normals[isphere][idim]*xm; } _B[isphere] = dot; } // get the direction of the d vector normal to the d-1 vectors // orthonormal basis for (size_t k = 0; k < num_dim - 1; k++) { _ortho_basis[k] = new double[num_dim]; for (size_t idim = 0; idim < num_dim; idim++) _ortho_basis[k][idim] = _planes_normals[k][idim]; for (size_t j = 0; j < k; j++) { double dot = 0.0; for (size_t idim = 0; idim < num_dim; idim++) dot += _ortho_basis[j][idim]*_planes_normals[k][idim]; _ortho_tmp[j] = dot; for (size_t idim = 0; idim < num_dim; idim++) _ortho_basis[k][idim] -= _ortho_tmp[j]*_ortho_basis[j][idim]; } double sum = 0.0; for (size_t idim = 0; idim < num_dim; idim++) sum += _ortho_basis[k][idim]*_ortho_basis[k][idim]; // normailze sum = sqrt(sum); for (size_t idim = 0; idim < num_dim; idim++) _ortho_basis[k][idim]/=sum; } // random vector as the d vector , then normalize _planes_normals[num_dim-1] = new double[num_dim]; while (true) { for (size_t idim = 0; idim < num_dim; idim++) _planes_normals[num_dim-1][idim] = generate_a_random_number(); size_t k = num_dim - 1; _ortho_basis[k] = new double[num_dim]; for (size_t idim = 0; idim < num_dim; idim++) _ortho_basis[k][idim] = _planes_normals[k][idim]; for (size_t j = 0; j < k; j++) { double dot = 0.0; for (size_t idim = 0; idim < num_dim; idim++) dot += _ortho_basis[j][idim]*_planes_normals[k][idim]; _ortho_tmp[j] = dot; for (size_t idim = 0; idim < num_dim; idim++) _ortho_basis[k][idim] -= _ortho_tmp[j]*_ortho_basis[j][idim]; } double sum = 0.0; for (size_t idim = 0; idim < num_dim; idim++) sum += _ortho_basis[k][idim]*_ortho_basis[k][idim]; // normailze sum = sqrt(sum); if(sum < 1E-10) continue; // try again for (size_t idim = 0; idim < num_dim; idim++) { _ortho_basis[k][idim]/=sum; _I[idim] = _ortho_basis[k][idim]; } break; // done } double* tmp_ptr = _planes_normals[num_dim - 1]; _planes_normals[num_dim - 1] = _ortho_basis[num_dim - 1]; _ortho_basis[num_dim - 1] = tmp_ptr; double dot = 0.0; for (size_t idim = 0; idim < num_dim; idim++) dot += _spheres[ip0][idim]*_planes_normals[num_dim - 1][idim]; _B[num_dim - 1] = dot; _pivot = new int[num_dim]; LU_decompose_pivot(_planes_normals,_pivot,num_dim); solver_pivot(_planes_normals,_B,_pivot,num_dim,_p1); // line sphere intersection // u = -(I.(o-c)) +- sqrt( (I.(o-c))^2 - (o-c)^2 + r^2 ) // o line first point // I line unit vector // c sphere centre double a(0.0),b(0.0),c(0.0); for (size_t idim = 0; idim < num_dim; idim++) { double fc = _p1[idim] - _spheres[spheres_indices[0]][idim]; //(o - c) a += fc * _I[idim]; // (o - c).I b += fc*fc; // (o - c).(o - c) } c = a*a; // a2 double r = _spheres[spheres_indices[0]][num_dim]; double disc = c - b + r*r; if(disc < 0.0) // no intersection between the d-spheres { // clear memory delete [] _B; delete [] _I; delete [] _p1; delete [] _ortho_tmp; delete [] _pivot; for (size_t idim = 0; idim < num_dim; idim++) { delete [] _planes_normals[idim]; delete [] _ortho_basis[idim]; } return false; } // intersection point between the d-spheres exist a*= -1; double disc_sq = sqrt(disc); double u1 = a + disc_sq; double u2 = a - disc_sq; for (size_t idim = 0; idim < num_dim; idim++) { q1[idim] = _p1[idim] + u1 * _I[idim]; q2[idim] = _p1[idim] + u2 * _I[idim]; } // clear memory delete [] _B; delete [] _I; delete [] _p1; delete [] _ortho_tmp; delete [] _pivot; for (size_t idim = 0; idim < num_dim; idim++) { delete [] _planes_normals[idim]; delete [] _ortho_basis[idim]; } return true; }
bool rspfNitfRpcModel::parseImageHeader(const rspfNitfImageHeader* ih) { if (getRpcData(ih) == false) { if (traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << "rspfNitfRpcModel::parseFile DEBUG:" << "\nError parsing rpc tags. Aborting with error." << std::endl; } setErrorStatus(); return false; } rspfString os = ih->getImageMagnification(); if ( os.contains("/") ) { os = os.after("/"); rspf_float64 d = os.toFloat64(); if (d) { theDecimation = 1.0 / d; } } theImageID = ih->getImageId(); rspfIrect imageRect = ih->getImageRect(); theImageSize.line = static_cast<rspf_int32>(imageRect.height() / theDecimation); theImageSize.samp = static_cast<rspf_int32>(imageRect.width() / theDecimation); getSensorID(ih); theRefImgPt.line = theImageSize.line/2.0; theRefImgPt.samp = theImageSize.samp/2.0; theRefGndPt.lat = theLatOffset; theRefGndPt.lon = theLonOffset; theRefGndPt.hgt = theHgtOffset; theImageClipRect = rspfDrect(0.0, 0.0, theImageSize.samp-1, theImageSize.line-1); rspfGpt v0, v1, v2, v3; rspfDpt ip0 (0.0, 0.0); rspfRpcModel::lineSampleHeightToWorld(ip0, theHgtOffset, v0); rspfDpt ip1 (theImageSize.samp-1.0, 0.0); rspfRpcModel::lineSampleHeightToWorld(ip1, theHgtOffset, v1); rspfDpt ip2 (theImageSize.samp-1.0, theImageSize.line-1.0); rspfRpcModel::lineSampleHeightToWorld(ip2, theHgtOffset, v2); rspfDpt ip3 (0.0, theImageSize.line-1.0); rspfRpcModel::lineSampleHeightToWorld(ip3, theHgtOffset, v3); theBoundGndPolygon = rspfPolygon (rspfDpt(v0), rspfDpt(v1), rspfDpt(v2), rspfDpt(v3)); updateModel(); rspfRpcModel::lineSampleHeightToWorld(theRefImgPt, theHgtOffset, theRefGndPt); if ( theRefGndPt.isLatNan() || theRefGndPt.isLonNan() ) { if (traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << "rspfNitfRpcModel::rspfNitfRpcModel DEBUG:" << "\nGround Reference Point not valid." << " Aborting with error..." << std::endl; } setErrorStatus(); return false; } try { computeGsd(); } catch (const rspfException& e) { if (traceDebug()) { rspfNotify(rspfNotifyLevel_DEBUG) << "rspfNitfRpcModel::rspfNitfRpcModel DEBUG:\n" << e.what() << std::endl; } } if (traceExec()) { rspfNotify(rspfNotifyLevel_DEBUG) << "DEBUG rspfNitfRpcModel::parseFile: returning..." << std::endl; } return true; }
bool ossimNitfRsmModel::parseImageHeader(const ossimNitfImageHeader* ih) { static const char MODULE[] = "ossimNitfRsmModel::getRsmData"; if (traceExec()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " entering..." << std::endl; } bool status = false; if ( getRsmData(ih) ) { theImageID = m_iid.trim(); ossimIrect imageRect = ih->getImageRect(); // Fetch Image Size: theImageSize.line = static_cast<ossim_int32>(imageRect.height()); theImageSize.samp = static_cast<ossim_int32>(imageRect.width()); // Assign other data members: theRefImgPt.line = theImageSize.line/2.0; theRefImgPt.samp = theImageSize.samp/2.0; // Assign the bounding image space rectangle: theImageClipRect = ossimDrect(0.0, 0.0, theImageSize.samp-1, theImageSize.line-1); ossimGpt v0, v1, v2, v3; ossimDpt ip0 (0.0, 0.0); lineSampleHeightToWorld(ip0, m_znrmo, v0); ossimDpt ip1 (theImageSize.samp-1.0, 0.0); lineSampleHeightToWorld(ip1, m_znrmo, v1); ossimDpt ip2 (theImageSize.samp-1.0, theImageSize.line-1.0); lineSampleHeightToWorld(ip2, m_znrmo, v2); ossimDpt ip3 (0.0, theImageSize.line-1.0); lineSampleHeightToWorld(ip3, m_znrmo, v3); theBoundGndPolygon = ossimPolygon (ossimDpt(v0), ossimDpt(v1), ossimDpt(v2), ossimDpt(v3)); updateModel(); // Set the ground reference point. lineSampleHeightToWorld(theRefImgPt, m_znrmo, theRefGndPt); // Height could have nan if elevation is not set so check lat, lon individually. if ( ( theRefGndPt.isLatNan() == false ) && ( theRefGndPt.isLonNan() == false ) ) { //--- // This will set theGSD and theMeanGSD. This model doesn't need these but // others do. //--- try { computeGsd(); // Set return status. status = true; } catch (const ossimException& e) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimNitfRpcModel::ossimNitfRpcModel DEBUG:\n" << e.what() << std::endl; } setErrorStatus(); } } else { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimNitfRpcModel::ossimNitfRpcModel DEBUG:" << "\nGround Reference Point not valid(has nans)." << " Aborting with error..." << std::endl; } setErrorStatus(); } } else { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimNitfRpcModel::parseFile DEBUG:" << "\nError parsing rsm tags. Aborting with error." << std::endl; } setErrorStatus(); } if (traceExec()) { ossimNotify(ossimNotifyLevel_DEBUG) << MODULE << " exit status: " << ( status ? "true" : "false" ) << "\n"; } return status; } // End: ossimNitfRsmModel::parseImageHeader(const ossimNitfImageHeader* ih)
bool ossimNitfRpcModel::parseImageHeader(const ossimNitfImageHeader* ih) { // Do this first so we don't waste time if not rpc image. if (getRpcData(ih) == false) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimNitfRpcModel::parseFile DEBUG:" << "\nError parsing rpc tags. Aborting with error." << std::endl; } setErrorStatus(); return false; } //--- // Get the decimation if any from the header "IMAG" field. // // Look for string like: // "/2" = 1/2 // "/4 = 1/4 // ... // "/16 = 1/16 // If it is full resolution it should be "1.0" //--- ossimString os = ih->getImageMagnification(); if ( os.contains("/") ) { os = os.after("/"); ossim_float64 d = os.toFloat64(); if (d) { theDecimation = 1.0 / d; } } //*** // Fetch Image ID: //*** theImageID = ih->getImageId(); ossimIrect imageRect = ih->getImageRect(); //--- // Fetch Image Size: //--- theImageSize.line = static_cast<ossim_int32>(imageRect.height() / theDecimation); theImageSize.samp = static_cast<ossim_int32>(imageRect.width() / theDecimation); // Search for the STDID Tag to fetch mission (satellite) name: getSensorID(ih); //*** // Assign other data members: //*** theRefImgPt.line = theImageSize.line/2.0; theRefImgPt.samp = theImageSize.samp/2.0; theRefGndPt.lat = theLatOffset; theRefGndPt.lon = theLonOffset; theRefGndPt.hgt = theHgtOffset; //*** // Assign the bounding image space rectangle: //*** theImageClipRect = ossimDrect(0.0, 0.0, theImageSize.samp-1, theImageSize.line-1); //--- // Assign the bounding ground polygon: // // NOTE: We will use the base ossimRpcModel for transformation since all // of our calls are in full image space (not decimated). //--- ossimGpt v0, v1, v2, v3; ossimDpt ip0 (0.0, 0.0); ossimRpcModel::lineSampleHeightToWorld(ip0, theHgtOffset, v0); ossimDpt ip1 (theImageSize.samp-1.0, 0.0); ossimRpcModel::lineSampleHeightToWorld(ip1, theHgtOffset, v1); ossimDpt ip2 (theImageSize.samp-1.0, theImageSize.line-1.0); ossimRpcModel::lineSampleHeightToWorld(ip2, theHgtOffset, v2); ossimDpt ip3 (0.0, theImageSize.line-1.0); ossimRpcModel::lineSampleHeightToWorld(ip3, theHgtOffset, v3); theBoundGndPolygon = ossimPolygon (ossimDpt(v0), ossimDpt(v1), ossimDpt(v2), ossimDpt(v3)); updateModel(); // Set the ground reference point. ossimRpcModel::lineSampleHeightToWorld(theRefImgPt, theHgtOffset, theRefGndPt); if ( theRefGndPt.isLatNan() || theRefGndPt.isLonNan() ) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimNitfRpcModel::ossimNitfRpcModel DEBUG:" << "\nGround Reference Point not valid." << " Aborting with error..." << std::endl; } setErrorStatus(); return false; } //--- // This will set theGSD and theMeanGSD. This model doesn't need these but // others do. //--- try { computeGsd(); } catch (const ossimException& e) { if (traceDebug()) { ossimNotify(ossimNotifyLevel_DEBUG) << "ossimNitfRpcModel::ossimNitfRpcModel DEBUG:\n" << e.what() << std::endl; } } if (traceExec()) { ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimNitfRpcModel::parseFile: returning..." << std::endl; } return true; }
//***************************************************************************** // METHOD: ossimIkonosRpcModel::finishConstruction() // //***************************************************************************** void ossimIkonosRpcModel::finishConstruction() { if (traceExec()) { ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel finishConstruction(): entering..." << std::endl; } //*** // Assign other data members: //*** thePolyType = B; // This may not be true for early RPC imagery theRefImgPt.line = theLineOffset; theRefImgPt.samp = theSampOffset; theRefGndPt.lat = theLatOffset; theRefGndPt.lon = theLonOffset; theRefGndPt.hgt = theHgtOffset; //*** // Assign the bounding image space rectangle: //*** theImageClipRect = ossimDrect(0.0, 0.0, theImageSize.samp-1, theImageSize.line-1); //--- // NOTE: We must call "updateModel()" to set parameter used by base // ossimRpcModel prior to calling lineSampleHeightToWorld or all // the world points will be same. //--- updateModel(); //*** // Assign the bounding ground polygon: //*** ossimGpt v0, v1, v2, v3; ossimDpt ip0 (0.0, 0.0); lineSampleHeightToWorld(ip0, 0.0, v0); ossimDpt ip1 (theImageSize.samp-1.0, 0.0); lineSampleHeightToWorld(ip1, 0.0, v1); ossimDpt ip2 (theImageSize.samp-1.0, theImageSize.line-1.0); lineSampleHeightToWorld(ip2, 0.0, v2); ossimDpt ip3 (0.0, theImageSize.line-1.0); lineSampleHeightToWorld(ip3, 0.0, v3); theBoundGndPolygon = ossimPolygon (ossimDpt(v0), ossimDpt(v1), ossimDpt(v2), ossimDpt(v3)); //--- // Call compute gsd: // // This will set theGSD and theMeanGSD using lineSampleHeightToWorld on // three image points. Previously this was pulled from metadata. Some of // which was in US Survey feet and not converted to meters. This method // is more accurate as it uses the sensor model to compute. //--- try { // Method throws ossimException. computeGsd(); } catch (const ossimException& e) { ossimNotify(ossimNotifyLevel_WARN) << "ossimIkonosRpcModel finishConstruction Caught Exception:\n" << e.what() << std::endl; } if (traceExec()) { ossimNotify(ossimNotifyLevel_DEBUG) << "DEBUG ossimIkonosRpcModel finishConstruction(): returning..." << std::endl; } }