void TestSimulationMakerFromFile::testModelsFromFileOneLevel() {
    createSimulation("models_from_file.xml");
    Models all = sim->seekDescendants<Model*>("*");
    QCOMPARE(all.size(), 2*4+1+1);
    QVERIFY(sim->peekOneDescendant<Model*>("A"));
    QVERIFY(sim->peekOneDescendant<Model*>("D/stat"));
    QCOMPARE(sim->seekOneDescendant<Model*>("A")->pullValue<int>("farmRealId"),
             474840);
    QCOMPARE(sim->seekOneDescendant<Model*>("D")->pullValue<QString>("soilType"),
             QString("Clay"));
    delete sim;
}
void TestSimulationMakerFromFile::testModelInstances() {
    createSimulation("model_instances.xml");
    Models all = sim->seekDescendants<Model*>("*");
    QCOMPARE(all.size(), 3*(4*4+3)+1);
    QVERIFY(sim->peekOneChild<Model*>("generations(1)"));
    QVERIFY(sim->peekOneDescendant<Model*>("generations(2)/egg"));
    QVERIFY(sim->peekOneDescendant<Model*>("generations(3)/pupa"));
    QVERIFY(sim->peekOneDescendant<Model*>("generations(1)/larva(1)"));
    QVERIFY(sim->peekOneDescendant<Model*>("generations(2)/larva(2)/kidney"));
    QVERIFY(sim->peekOneDescendant<Model*>("generations(3)/larva(4)/ovary(2)"));

    delete sim;
}
void TestSimulationMakerFromFile::testModelsFromCondensedFileParameterKey() {
    createSimulation("models_from_condensed_file_parameter_key.xml");

    Models all = sim->seekDescendants<Model*>("*");
    QCOMPARE(all.size(), 1+1+4*5);

    Model *crop = sim->seekOneDescendant<Model*>("landscape/C/WBarley");
    QCOMPARE(crop->pullValue<double>("nitrogenNorm"), 130.);

    crop = sim->seekOneDescendant<Model*>("landscape/D/SBarley");
    QCOMPARE(crop->pullValue<double>("nitrogenNorm"), 90.);

    delete sim;
}
void TestSimulationMakerFromFile::testModelsFromFileCondensed() {
    createSimulation("models_from_file_condensed.xml");

    Models all = sim->seekDescendants<Model*>("*");
    QCOMPARE(all.size(), 1+1+4*5);
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A/Oats"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A/stat"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/C/stat"));

    Model *crop = sim->peekOneDescendant<Model*>("landscape/B/WBarley");
    QCOMPARE(crop->pullValue<int>("Area"), 40);
    crop = sim->peekOneDescendant<Model*>("landscape/D/SBarley");
    QCOMPARE(crop->pullValue<int>("Area"), 15);

    delete sim;
}
void TestSimulationMakerFromFile::testModelsFromFileTwoLevels() {
    createSimulation("models_from_file_nested.xml");

    Models all = sim->seekDescendants<Model*>("*");
    QCOMPARE(all.size(), 1+1+4+7+4);
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A/Oats"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A/stat"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/C/stat"));

    try {
        Model *crop = sim->seekOneDescendant<Model*>("landscape/B/WBarley");
        QCOMPARE(crop->pullValue<int>("Area"), 40);
    }
    catch (Exception &ex) {
        QString msg = "Unexpected exception. " + ex.message();
        QFAIL(qPrintable(msg));
    }

    delete sim;
}
void TestSimulationMakerFromFile::testModelsFromFileThreeLevels()
{
    createSimulation("models_from_file_nested_twice.xml");
    Models all = sim->seekDescendants<Model*>("*");
//        std::cout << "\n";
//        for (int i = 0; i < all.size(); ++i)
//            std::cout << i << " " << qPrintable(all[i]->fullLabel()) << "\n";
//        std::cout << "\n";
    QCOMPARE(all.size(), 1+1+1+4+7+4+16);
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A/Oats/Harvest"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/A/stat"));
    QVERIFY(sim->peekOneDescendant<Model*>("landscape/C/stat"));

    Model *harvest = sim->peekOneDescendant<Model*>("landscape/A/Oats/Harvest");
    QCOMPARE(harvest->pullValue<QDate>("Date"), QDate(2010,8,15));

    delete sim;
//    std::cout << "\n";
//    for (int i = 0; i < all.size(); ++i)
//        std::cout << i << " " << qPrintable(all[i]->fullLabel()) << "\n";
//    std::cout << "\n";
}
Beispiel #7
0
int main(int argc, char** argv)
{
    osg::ArgumentParser arguments(&argc, argv);

    // construct the viewer.
    osgViewer::CompositeViewer viewer(arguments);
    
    if (arguments.argc()<=1)
    {
        std::cout<<"Please supply an image filename on the commnand line."<<std::endl;
        return 1;
    }
    
    std::string filename = arguments[1];
    osg::ref_ptr<osg::Image> image = osgDB::readImageFile(filename);
    
    if (!image)
    {
        std::cout<<"Error: unable able to read image from "<<filename<<std::endl;
        return 1;
    }

    osg::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
    if (!wsi) 
    {
        osg::notify(osg::NOTICE)<<"Error, no WindowSystemInterface available, cannot create windows."<<std::endl;
        return 1;
    }


    unsigned int width, height;
    wsi->getScreenResolution(osg::GraphicsContext::ScreenIdentifier(0), width, height);

    osg::ref_ptr<osg::GraphicsContext::Traits> traits = new osg::GraphicsContext::Traits;
    traits->x = 0;
    traits->y = 0;
    traits->width = width;
    traits->height = height;
    traits->windowDecoration = false;
    traits->doubleBuffer = true;
    
    osg::ref_ptr<osg::GraphicsContext> gc = osg::GraphicsContext::createGraphicsContext(traits.get());
    if (!gc)
    {
        std::cout<<"Error: GraphicsWindow has not been created successfully."<<std::endl;
    }

    gc->setClearColor(osg::Vec4(0.0f,0.0f,0.0f,1.0f));
    gc->setClearMask(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

    osg::ref_ptr<osgGA::TrackballManipulator> trackball = new osgGA::TrackballManipulator;
    
    typedef std::vector< osg::ref_ptr<osg::Node> > Models;
    
    Models models;
    models.push_back(creatQuad("no compression", image.get(), osg::Texture::USE_IMAGE_DATA_FORMAT, osg::Texture::LINEAR));
    models.push_back(creatQuad("ARB compression", image.get(), osg::Texture::USE_ARB_COMPRESSION, osg::Texture::LINEAR));
    models.push_back(creatQuad("DXT1 compression", image.get(), osg::Texture::USE_S3TC_DXT1_COMPRESSION, osg::Texture::LINEAR));
    models.push_back(creatQuad("DXT3 compression", image.get(), osg::Texture::USE_S3TC_DXT3_COMPRESSION, osg::Texture::LINEAR));
    models.push_back(creatQuad("DXT5 compression", image.get(), osg::Texture::USE_S3TC_DXT5_COMPRESSION, osg::Texture::LINEAR));
    
    int numX = 1;
    int numY = 1;

    // compute the number of views up and across that are need
    {
        float aspectRatio = float(width)/float(height);
        float multiplier = sqrtf(float(models.size())/aspectRatio);;
        float multiplier_x = multiplier*aspectRatio;
        float multiplier_y = multiplier;


        if ((multiplier_x/ceilf(multiplier_x)) > (multiplier_y/ceilf(multiplier_y)))
        {
            numX = int(ceilf(multiplier_x));
            numY = int(ceilf(float(models.size())/float(numX)));
        }
        else
        {
            numY = int(ceilf(multiplier_y));
            numX = int(ceilf(float(models.size())/float(numY)));
        }
    }

    // populate the view with the required view to view each model.
    for(unsigned int i=0; i<models.size(); ++i)
    {
        osgViewer::View* view = new osgViewer::View;
        
        int xCell = i % numX;
        int yCell = i / numX;

        int vx = int((float(xCell)/float(numX)) * float(width));
        int vy = int((float(yCell)/float(numY)) * float(height));
        int vw =  int(float(width) / float(numX));
        int vh =  int(float(height) / float(numY));

        view->setSceneData(models[i].get());
        view->getCamera()->setProjectionMatrixAsPerspective(30.0, double(vw) / double(vh), 1.0, 1000.0);
        view->getCamera()->setViewport(new osg::Viewport(vx, vy, vw, vh));    
        view->getCamera()->setGraphicsContext(gc.get());
        view->getCamera()->setClearMask(0);
        view->setCameraManipulator(trackball.get());

        viewer.addView(view);
    }

    return viewer.run();
}