Changeset 4636
- Timestamp:
- Sep 19, 2014, 12:04:45 PM (10 years ago)
- Location:
- geovis/trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
geovis/trunk/RenderServer.h
r4629 r4636 21 21 class Stats; 22 22 23 #define GEOVIS_VERSION_STRING "0. 5.0"23 #define GEOVIS_VERSION_STRING "0.6.0" 24 24 25 25 #define MSECS_ELAPSED(t1, t2) \ -
geovis/trunk/Renderer.cpp
r4635 r4636 12 12 #include <cstdlib> 13 13 14 #include <limits> 14 15 #include <set> 15 16 … … 986 987 } 987 988 989 bool Renderer::worldToScreen(std::vector<osg::Vec3d>& coords, bool invertY) 990 { 991 if (!_viewer.valid()) { 992 ERROR("No viewer"); 993 return false; 994 } 995 osg::Camera *cam = _viewer->getCamera(); 996 osg::Matrixd MVP = cam->getViewMatrix() * cam->getProjectionMatrix(); 997 const osg::Viewport *viewport = cam->getViewport(); 998 for (std::vector<osg::Vec3d>::iterator itr = coords.begin(); 999 itr != coords.end(); ++itr) { 1000 // Get clip coords 1001 osg::Vec4d pt; 1002 pt = osg::Vec4d(*itr, 1.0) * MVP; 1003 // Clip 1004 if (pt.x() < -pt.w() || 1005 pt.x() > pt.w() || 1006 pt.y() < -pt.w() || 1007 pt.y() > pt.w() || 1008 pt.z() < -pt.w() || 1009 pt.z() > pt.w()) { 1010 // Outside frustum 1011 TRACE("invalid pt: %g,%g,%g,%g", pt.x(), pt.y(), pt.z(), pt.w()); 1012 itr->set(std::numeric_limits<double>::quiet_NaN(), 1013 std::numeric_limits<double>::quiet_NaN(), 1014 std::numeric_limits<double>::quiet_NaN()); 1015 continue; 1016 } 1017 TRACE("clip pt: %g,%g,%g,%g", pt.x(), pt.y(), pt.z(), pt.w()); 1018 // Perspective divide: now NDC 1019 pt /= pt.w(); 1020 #if 1 1021 itr->x() = viewport->x() + viewport->width() * 0.5 + pt.x() * viewport->width() * 0.5; 1022 itr->y() = viewport->y() + viewport->height() * 0.5 + pt.y() * viewport->height() * 0.5; 1023 //double near = 0; 1024 //double far = 1; 1025 //itr->z() = (far + near) * 0.5 + (far - near) * 0.5 * pt.z(); 1026 itr->z() = 0.5 + 0.5 * pt.z(); 1027 #else 1028 *itr = osg::Vec3d(pt.x(), pt.y(), pt.z()) * viewport->computeWindowMatrix(); 1029 #endif 1030 if (invertY) { 1031 itr->y() = viewport->height() - itr->y(); 1032 } 1033 TRACE("screen: %g,%g,%g", itr->x(), itr->y(), itr->z()); 1034 } 1035 return true; 1036 } 1037 988 1038 /** 989 1039 * \brief Map screen mouse coordinates to map coordinates … … 1009 1059 osg::Vec3d world; 1010 1060 if (_mapNode->getTerrain()->getWorldCoordsUnderMouse(_viewer->asView(), mouseX, mouseY, world)) { 1011 map.fromWorld( _mapNode->getMapSRS(), world);1061 map.fromWorld(getMapSRS(), world); 1012 1062 return true; 1013 1063 } -
geovis/trunk/Renderer.h
r4635 r4636 129 129 virtual ~Renderer(); 130 130 131 void setResourcePath( std::string& path)131 void setResourcePath(const std::string& path) 132 132 { 133 133 TRACE("Set resource path to %s", path.c_str()); … … 375 375 bool worldToScreen(const osg::Vec3d& world, osg::Vec3d *screen, 376 376 bool invertY = true); 377 378 bool worldToScreen(std::vector<osg::Vec3d>& coords, bool invertY = true); 377 379 378 380 void setMaximumFrameRateInHertz(double rate) -
geovis/trunk/RendererCmd.cpp
r4635 r4636 767 767 return (*proc) (clientData, interp, objc, objv); 768 768 } 769 #if 1 769 770 770 static int 771 771 MapCoordsOp(ClientData clientData, Tcl_Interp *interp, int objc, … … 815 815 // altmode absolute 816 816 coordVec.push_back(osg::Vec3d(mapPoint.x(), mapPoint.y(), mapPoint.z())); 817 #if 0818 if (outSRS != NULL) {819 mapPoint = mapPoint.transform(outSRS);820 if (!mapPoint.isValid()) {821 Tcl_DecrRefCount(listObjPtr);822 Tcl_AppendResult(interp, "Could not transform map point to requested SRS", (char*)NULL);823 return TCL_ERROR;824 }825 }826 Tcl_Obj *objPtr = Tcl_NewDoubleObj(mapPoint.x());827 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);828 objPtr = Tcl_NewDoubleObj(mapPoint.y());829 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);830 objPtr = Tcl_NewDoubleObj(mapPoint.z());831 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);832 #endif833 817 } else { 834 818 coordVec.push_back(osg::Vec3d(std::numeric_limits<double>::quiet_NaN(), 835 819 std::numeric_limits<double>::quiet_NaN(), 836 820 std::numeric_limits<double>::quiet_NaN())); 837 #if 0838 Tcl_Obj *objPtr = Tcl_NewStringObj("NaN", 3);839 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);840 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);841 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr);842 #endif843 821 } 844 822 } … … 873 851 return TCL_OK; 874 852 } 875 #else 876 static int 877 MapCoordsOp(ClientData clientData, Tcl_Interp *interp, int objc, 878 Tcl_Obj *const *objv) 879 { 880 int x, y; 881 if (Tcl_GetIntFromObj(interp, objv[3], &x) != TCL_OK || 882 Tcl_GetIntFromObj(interp, objv[4], &y) != TCL_OK) { 883 return TCL_ERROR; 884 } 885 886 osgEarth::GeoPoint mapPoint; 887 size_t length; 888 char mesg[512]; 889 if (g_renderer->mapMouseCoords(x, y, mapPoint)) { 890 std::string srsInit; 891 std::string verticalDatum; 892 if (objc > 5) { 893 srsInit = Tcl_GetString(objv[5]); 894 if (objc > 6) { 895 verticalDatum = Tcl_GetString(objv[6]); 896 } 897 osgEarth::SpatialReference *outSRS = 898 osgEarth::SpatialReference::get(srsInit, verticalDatum); 899 if (outSRS == NULL) { 900 Tcl_AppendResult(interp, "bad SRS \"", srsInit.c_str(), "\"", (char*)NULL); 901 return TCL_ERROR; 902 } 903 mapPoint = mapPoint.transform(outSRS); 904 if (!mapPoint.isValid()) { 905 Tcl_AppendResult(interp, "Could not transform map point to requested SRS", (char*)NULL); 906 return TCL_ERROR; 907 } 908 } 909 // send coords to client 910 length = snprintf(mesg, sizeof(mesg), 911 "nv>map coords %s %g %g %g %d %d {%s} {%s}\n", 912 Tcl_GetString(objv[2]), //g_stats.nCommands, 913 mapPoint.x(), mapPoint.y(), mapPoint.z(), 914 x, y, 915 mapPoint.getSRS()->getHorizInitString().c_str(), 916 mapPoint.getSRS()->getVertInitString().c_str()); 917 918 queueResponse(mesg, length, Response::VOLATILE); 919 } else { 920 // Out of range 921 length = snprintf(mesg, sizeof(mesg), 922 "nv>map coords %s invalid %d %d\n", 923 Tcl_GetString(objv[2]), //g_stats.nCommands, 924 x, y); 925 926 queueResponse(mesg, length, Response::VOLATILE); 927 } 928 return TCL_OK; 929 } 930 #endif 853 931 854 static int 932 855 MapGraticuleOp(ClientData clientData, Tcl_Interp *interp, int objc, … … 1946 1869 Tcl_Obj *const *objv) 1947 1870 { 1948 double x, y, z; 1949 if (Tcl_GetDoubleFromObj(interp, objv[3], &x) != TCL_OK || 1950 Tcl_GetDoubleFromObj(interp, objv[4], &y) != TCL_OK || 1951 Tcl_GetDoubleFromObj(interp, objv[5], &z) != TCL_OK) { 1952 return TCL_ERROR; 1953 } 1871 int tokenLength; 1872 const char *token = Tcl_GetStringFromObj(objv[2], &tokenLength); 1873 int numCoords; 1874 Tcl_Obj **coords; 1875 if (Tcl_ListObjGetElements(interp, objv[3], &numCoords, &coords) != TCL_OK) { 1876 return TCL_ERROR; 1877 } 1878 if (numCoords == 0) { 1879 Tcl_AppendResult(interp, "no x,y,z coordinates in list", (char *)NULL); 1880 return TCL_ERROR; 1881 } 1882 if (numCoords % 3 != 0) { 1883 Tcl_AppendResult(interp, "invalid number of coordinates in list", 1884 (char *)NULL); 1885 return TCL_ERROR; 1886 } 1887 1954 1888 const osgEarth::SpatialReference *srs = NULL; 1955 if (objc < 7) {1889 if (objc < 5) { 1956 1890 srs = g_renderer->getMapSRS(); 1957 1891 if (srs == NULL) { … … 1960 1894 } 1961 1895 } else { 1962 std::string srsInit(Tcl_GetString(objv[ 6]));1896 std::string srsInit(Tcl_GetString(objv[4])); 1963 1897 std::string verticalDatum; 1964 if (objc > 7) {1965 verticalDatum = Tcl_GetString(objv[ 7]);1898 if (objc > 5) { 1899 verticalDatum = Tcl_GetString(objv[5]); 1966 1900 } 1967 1901 srs = osgEarth::SpatialReference::get(srsInit, verticalDatum); … … 1971 1905 } 1972 1906 } 1973 // ALTMODE_RELATIVE is height above terrain, ALTMODE_ABSOLUTE means 1974 // relative to the vertical datum 1975 osgEarth::GeoPoint mapPoint(srs, x, y, z, osgEarth::ALTMODE_ABSOLUTE); 1976 size_t length; 1977 char mesg[256]; 1978 osg::Vec3d world; 1979 osg::Vec3d screen; 1980 if (g_renderer->getWorldCoords(mapPoint, &world) && 1981 g_renderer->worldToScreen(world, &screen)) { 1982 // send coords to client 1983 length = snprintf(mesg, sizeof(mesg), 1984 "nv>screen coords %s %g %g %g %g %g %g\n", 1985 Tcl_GetString(objv[2]), 1986 screen.x(), screen.y(), screen.z(), 1987 x, y, z); 1988 1989 queueResponse(mesg, length, Response::VOLATILE); 1990 } else { 1991 // Out of range 1992 length = snprintf(mesg, sizeof(mesg), 1993 "nv>screen coords %s invalid %g %g %g\n", 1994 Tcl_GetString(objv[2]), 1995 x, y, z); 1996 1997 queueResponse(mesg, length, Response::VOLATILE); 1998 } 1907 Tcl_Obj *listObjPtr = Tcl_NewListObj(0, (Tcl_Obj **)NULL); 1908 std::vector<osg::Vec3d> coordVec; 1909 for (int i = 0; i < numCoords; i += 3) { 1910 double x, y, z; 1911 if (Tcl_GetDoubleFromObj(interp, coords[i], &x) != TCL_OK || 1912 Tcl_GetDoubleFromObj(interp, coords[i+1], &y) != TCL_OK || 1913 Tcl_GetDoubleFromObj(interp, coords[i+2], &z) != TCL_OK) { 1914 return TCL_ERROR; 1915 } 1916 // ALTMODE_RELATIVE is height above terrain, ALTMODE_ABSOLUTE means 1917 // relative to the vertical datum 1918 osgEarth::GeoPoint mapPoint(srs, x, y, z, osgEarth::ALTMODE_ABSOLUTE); 1919 osg::Vec3d world; 1920 if (g_renderer->getWorldCoords(mapPoint, &world)) { 1921 coordVec.push_back(world); 1922 } else { 1923 coordVec.push_back(osg::Vec3d(std::numeric_limits<double>::quiet_NaN(), 1924 std::numeric_limits<double>::quiet_NaN(), 1925 std::numeric_limits<double>::quiet_NaN())); 1926 } 1927 } 1928 g_renderer->worldToScreen(coordVec); 1929 for (std::vector<osg::Vec3d>::iterator itr = coordVec.begin(); 1930 itr != coordVec.end(); ++itr) { 1931 Tcl_Obj *objPtr = Tcl_NewDoubleObj(itr->x()); 1932 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr); 1933 objPtr = Tcl_NewDoubleObj(itr->y()); 1934 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr); 1935 objPtr = Tcl_NewDoubleObj(itr->z()); 1936 Tcl_ListObjAppendElement(interp, listObjPtr, objPtr); 1937 } 1938 // send coords to client 1939 int listLength; 1940 const char *string = Tcl_GetStringFromObj(listObjPtr, &listLength); 1941 size_t length = listLength + tokenLength + 22; 1942 char *mesg = new char[length]; 1943 length = snprintf(mesg, length, "nv>screen coords %s {%s}\n", token, string); 1944 Tcl_DecrRefCount(listObjPtr); 1945 queueResponse(mesg, length, Response::VOLATILE); 1946 delete [] mesg; 1999 1947 return TCL_OK; 2000 1948 } … … 2017 1965 static CmdSpec screenOps[] = { 2018 1966 {"bgcolor", 1, ScreenBgColorOp, 5, 5, "r g b"}, 2019 {"coords", 1, ScreenCoordsOp, 6, 8, "token x y z?srs? ?verticalDatum?"},1967 {"coords", 1, ScreenCoordsOp, 4, 6, "token coords ?srs? ?verticalDatum?"}, 2020 1968 {"size", 1, ScreenSizeOp, 4, 4, "width height"} 2021 1969 }; -
geovis/trunk/geovis_protocol.txt
r4629 r4636 90 90 91 91 screen bgcolor <r> <g> <b> 92 screen coords <token> < x> <y> <z> <?srs?> <?verticalDatum?>92 screen coords <token> <coordList> <?srs?> <?verticalDatum?> 93 93 Transate map coordinates to screen/mouse coordinates. 94 94 <token> - String token, included in response 95 < x>,<y>,<z> - Map coordinates. If srs not given, these are in the map's96 coordinate system.95 <coordList> - A list of x,y,z map coordinates. If <srs> is not given, 96 these are in the map's coordinate system. 97 97 <srs> - Optional horizontal srs init string for coordinate system of 98 98 x,y,z … … 115 115 == Map Commands == 116 116 117 map coords <token> < x> <y> <?srs?> <?verticalDatum?>117 map coords <token> <coordList> <?srs?> <?verticalDatum?> 118 118 Translate screen/mouse coordinates into map coordinates. 119 119 <token> - String token, included in response 120 < x>,<y> - Screen/mouse coordinates120 <coordList> - A list of x,y screen/mouse coordinates 121 121 <srs> - Optional horizontal srs init string for coordinate system to return 122 122 <verticalDatum> - Optional vertical srs init string for coordinate system to … … 209 209 nv>image -type image -bytes <nbytes> 210 210 <binary RGB data> 211 nv>map coords <token> <mapX> <mapY> <mapZ> <screenX> <screenY> <?srs?> <?verticalDatum?> 212 Reply to query of map coordinates from screen coordinates. srs of the map 213 coordinates may be included if not in map's native coordinate system 214 nv>map coords <token> invalid <mouseX> <mouseY> 215 Reply indicating an off-map click/query 216 nv>screen coords <token> <screenX> <screenY> <screenZ> <mapX> <mapY> <mapZ> 217 Reply to query of screen coordinates from map coordinates 218 nv>screen coords <token> invalid <mapX> <mapY> <mapZ> 219 Reply indicating requested point is out of the view frustum 211 nv>map coords <token> <mapCoordList> <?srs?> <?verticalDatum?> 212 Reply to query of map coordinates from screen coordinates. The mapCoordList 213 is a list of x,y,z map coordinates. The srs of the map coordinates may be 214 included if not in map's native coordinate system. NaN in the results 215 indicates off-map input coordinates. 216 nv>screen coords <token> <screenCoordList> 217 Reply to query of screen coordinates from map coordinates. The 218 screenCoordList is a list of x,y,z screen coordinates (z is the depth). NaN 219 in the results indicates a point outside the view frustum or invalid input 220 map coordinate 220 221 nv>ok -token <seqnum> 221 222 Reply indicated commands through <seqnum> (numbered beginning at 0) have been
Note: See TracChangeset
for help on using the changeset viewer.