Changeset 5895


Ignore:
Timestamp:
Oct 1, 2015 2:54:12 PM (9 years ago)
Author:
ldelgass
Message:

Initial support for parsing protocols in url strings: "local://" for files
transferred from client to cache dir, "file://" for server paths (default for
when no protocol is present), and "idata://" for idata collection/doi.

Location:
geovis/trunk
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • geovis/trunk/FileUtil.cpp

    r4376 r5895  
    5858    }
    5959}
     60
     61/**
     62 * \brief Get the file path part of a local:// URL
     63 *
     64 * This implementation assumes a relative path if there is no leading slash,
     65 * rather than assuming there is a server name.
     66 */
     67std::string GeoVis::getLocalFilePath(const std::string& url)
     68{
     69    std::string::size_type pos(url.find("://"));
     70
     71    if (pos != std::string::npos) {
     72        return url.substr(pos+3, std::string::npos);
     73    }
     74    return url;
     75}
  • geovis/trunk/FileUtil.h

    r4376 r5895  
    77#ifndef GEOVIS_FILEUTIL_H
    88#define GEOVIS_FILEUTIL_H
     9
     10#include <string>
    911
    1012#include <osgEarth/FileUtils>
     
    4547
    4648extern void removeDirectory(const char *path);
     49std::string getLocalFilePath(const std::string& url);
    4750
    4851}
  • geovis/trunk/RenderServer.cpp

    r5890 r5895  
    476476    g_renderer = NULL;
    477477    // Clean up cache directory after renderer's threads have finished
    478     removeDirectory(cacheDir.c_str());
     478    if (!cacheDir.empty()) {
     479        removeDirectory(cacheDir.c_str());
     480    }
    479481
    480482    TRACE("Exiting GeoVis Server");
  • geovis/trunk/Renderer.cpp

    r5890 r5895  
    1515#include <limits>
    1616#include <set>
     17#include <fstream>
     18#include <sstream>
    1719
    1820#include <sys/types.h>
     
    172174}
    173175
    174 std::string Renderer::getBaseImage()
     176std::string Renderer::getBaseImage() const
    175177{
    176178    std::ostringstream oss;
     
    179181}
    180182
    181 std::string Renderer::getPinIcon()
     183std::string Renderer::getPinIcon() const
    182184{
    183185    std::ostringstream oss;
     
    27192721            retStr = "";
    27202722        }
    2721     } else {
     2723    } else if (proto == "local") {
     2724        INFO("Local protocol: '%s'", getLocalFilePath(url).c_str());
     2725        std::ostringstream oss;
     2726        oss << getCacheDirectory() << "/" << getLocalFilePath(url);
     2727        retStr = oss.str();
     2728    } else if (proto == "file") {
     2729        INFO("File: '/%s'", osgDB::getServerFileName(url).c_str());
     2730        std::ostringstream oss;
     2731        oss << "/" <<  osgDB::getServerFileName(url);
     2732        retStr = oss.str();
     2733    } else if (proto == "idata") {
     2734        std::string fileName = osgDB::getServerFileName(url);
     2735        INFO("IData protocol: coll: '%s', '%s'", osgDB::getServerAddress(url).c_str(), fileName.c_str());
     2736        int collection = atoi(osgDB::getServerAddress(url).c_str());
     2737        {
     2738            std::ostringstream oss;
     2739            oss << getCacheDirectory() << "/" << fileName;
     2740            retStr = oss.str();
     2741            std::string dirPath = osgDB::getFilePath(retStr);
     2742            osgDB::makeDirectory(dirPath);
     2743        }
     2744        if (!osgDB::fileExists(retStr)) {
     2745            std::ostringstream oss;
     2746            oss << "//" << fileName;
     2747            IData::Buffer buf;
     2748            IData::getFile(collection, oss.str().c_str(), &buf);
     2749            std::ofstream file(retStr.c_str());
     2750            file.write((char *)buf.data, buf.size);
     2751            file.close();
     2752        }
     2753    } else {
     2754        INFO("Protocol: '%s' url: '%s'", proto.c_str(), url.c_str());
    27222755        retStr = url;
    27232756    }
  • geovis/trunk/Renderer.h

    r5888 r5895  
    151151    }
    152152
    153     std::string getCacheDirectory()
     153    std::string getCacheDirectory() const
    154154    {
    155155        return _cacheDir;
    156156    }
    157157
    158     std::string getBaseImage();
    159 
    160     std::string getPinIcon();
     158    void setupCache();
     159
     160    std::string getBaseImage() const;
     161
     162    std::string getPinIcon() const;
    161163
    162164    void setAttribution(const std::string& attrib);
     
    535537    typedef std::tr1::unordered_map<ColorMapId, osg::ref_ptr<osg::TransferFunction1D> > ColorMapHashmap;
    536538    typedef std::tr1::unordered_map<ViewpointId, osgEarth::Viewpoint> ViewpointHashmap;
    537 
    538     void setupCache();
    539539
    540540    void initAnnotations();
  • geovis/trunk/RendererCmd.cpp

    r5889 r5895  
    363363
    364364static int
     365CameraCenterOp(ClientData clientData, Tcl_Interp *interp, int objc,
     366               Tcl_Obj *const *objv)
     367{
     368    double x, y;
     369    if (Tcl_GetDoubleFromObj(interp, objv[2], &x) != TCL_OK ||
     370        Tcl_GetDoubleFromObj(interp, objv[3], &y) != TCL_OK) {
     371        return TCL_ERROR;
     372    }
     373    double zoom = 1.0;
     374    if (objc > 4) {
     375        if (Tcl_GetDoubleFromObj(interp, objv[4], &zoom) != TCL_OK) {
     376            return TCL_ERROR;
     377        }
     378    }
     379    double duration = 1.0;
     380    if (objc > 5) {
     381        if (Tcl_GetDoubleFromObj(interp, objv[5], &duration) != TCL_OK) {
     382            return TCL_ERROR;
     383        }
     384    }
     385
     386    osgEarth::Viewpoint vpt = g_renderer->getViewpoint();
     387#ifdef NEW_VIEWPOINT_API
     388    vpt.focalPoint()->x() = x;
     389    vpt.focalPoint()->y() = y;
     390    //vpt.focalPoint()->z() = mapPoint.z();
     391    vpt.range()->set(vpt.range()->getValue() * zoom, osgEarth::Units::METERS);
     392#else
     393    vpt.x() = x;
     394    vpt.y() = y;
     395    //vpt.z() = mapPoint.z();
     396    vpt.setRange(vpt.getRange() * zoom);
     397
     398#endif
     399    g_renderer->setViewpoint(vpt, duration);
     400
     401    return TCL_OK;
     402}
     403
     404static int
    365405CameraGetViewpointOp(ClientData clientData, Tcl_Interp *interp, int objc,
    366406                     Tcl_Obj *const *objv)
     
    633673
    634674static CmdSpec cameraOps[] = {
     675    {"center",  1, CameraCenterOp,           4, 6, "x y ?zoomFactor? ?duration?"},
    635676    {"delete",  2, CameraDeleteViewpointOp,  3, 3, "name"},
    636677    {"dist",    2, CameraSetDistanceOp,      3, 3, "distance"},
     
    896937        return TCL_ERROR;
    897938    }
     939    if (g_renderer->getCacheDirectory().empty()) {
     940        g_renderer->setupCache();
     941    }
     942    std::string dirPath = osgDB::getFilePath(path);
     943    std::string fileName = osgDB::getSimpleFileName(path);
    898944    std::ostringstream fullPath;
    899     //fullPath << "/tmp/" << path;
    900     fullPath << path;
     945    fullPath << g_renderer->getCacheDirectory() << "/" << dirPath;
     946    if (!dirPath.empty()) {
     947        INFO("Make dir: %s", fullPath.str().c_str());
     948        osgDB::makeDirectory(fullPath.str());
     949        fullPath << "/";
     950    }
     951    fullPath << fileName;
    901952    FILE *fp = fopen(fullPath.str().c_str(), "wb");
    902953    if (fp == NULL) {
     
    907958    fclose(fp);
    908959    free(data);
     960    INFO("Wrote %d bytes to %s", bytesWritten, fullPath.str().c_str());
    909961    return (bytesWritten == size) ? TCL_OK : TCL_ERROR;
    910962}
    911963
    912964static CmdSpec fileOps[] = {
    913     {"put",    1, FilePutOp, 5, 5, "name type size"}
     965    {"put",    1, FilePutOp, 5, 5, "path type size"}
    914966};
    915967static int nFileOps = NumCmdSpecs(fileOps);
  • geovis/trunk/idatatest.cpp

    r5873 r5895  
    33#include <iostream>
    44#include <fstream>
     5
     6#include <osgDB/FileNameUtils>
    57
    68#include "IData.h"
Note: See TracChangeset for help on using the changeset viewer.