osg::Node* createLineDrawables()
{
    LineGroup* group = new LineGroup();

    group->addCullCallback(new InstallViewportSizeUniform());

    float x = 10;
    LineDrawable* strip = new LineDrawable(GL_LINE_STRIP);
    strip->setLineWidth(8);
    strip->setColor(osg::Vec4(1,1,1,1));
    addVerts(strip, x, 10);
    group->addChild(strip);

    x += 20;
    LineDrawable* loop = new LineDrawable(GL_LINE_LOOP);
    loop->setLineWidth(8);
    loop->setColor(osg::Vec4(1,1,0,1));
    addVerts(loop, x, 10);
    group->addChild(loop);

    x += 20;
    LineDrawable* stippled = new LineDrawable(GL_LINE_STRIP);
    stippled->setLineWidth(4);
    stippled->setStipplePattern(0xff00);
    stippled->setColor(osg::Vec4(0,1,0,1));
    addVerts(stippled, x, 10);
    group->addChild(stippled);
    
    x += 20;
    LineDrawable* segments = new LineDrawable(GL_LINES);
    segments->setLineWidth(3);
    segments->setColor(osg::Vec4(0,1,1,1));
    addVerts(segments, x, 10);
    group->addChild(segments);

    x += 20;
    LineDrawable* firstCount = new LineDrawable(GL_LINE_STRIP);
    firstCount->setLineWidth(5);
    firstCount->setColor(osg::Vec4(1,0,1,1));
    addVerts(firstCount, x, 10);
    firstCount->addUpdateCallback(new TestFirstCount());
    group->addChild(firstCount);
    
    x += 20;
    osg::ref_ptr<osg::Node> node = makeGeometryForImport(x, 10);
    group->import(node.get());

    return group;
}
// ------------------------------------------------------------------------
double imageCost(PatchParams &params, TestData::Pointer &data,
                 VectorType &point, VectorType &normal, ClassifierMap &classifiers,
                 LengthData::Pointer &lengths, bool save)
{
    typedef TestData::LineGroup LineGroup;
    LineGroup testLines;
    data->ExtractTestLines(normal, point, testLines);

    FlipChecker::Pointer checker = FlipChecker::New();

    LineGroup::iterator lineIt = testLines.begin();
    double totalCost = 0;
    while(lineIt != testLines.end())
    {
        double minValue = 1000;
        unsigned int minIndex = 0;

        if(lineIt->second.size() == 0)
        {
            totalCost += minValue;
            lineIt++;
            continue;
        }

        const std::string type = lineIt->first;

        bool flipImage = checker->FlipImage("MV-" + lineIt->first, data->GetId());
        bool flipPoints = checker->FlipPoints("MV-" + lineIt->first, data->GetId());

        if((type == "2C" || type == "3C") && flipImage)
        {
            flipPoints = !flipPoints;
        }

        TestData::ImageGroup images;
        data->GetImageGroup(type, images);

        for(unsigned int i = 0; i < lineIt->second.size(); i++)
        {
            // create a valve line from the data
            TestData::LineType line = lineIt->second[i];

            ValveLine<3>::Pointer alignedValve = ValveLine<3>::New();
            createAlignedValve(line, images.image, alignedValve, flipImage, flipPoints);

            double pointDist = alignedValve->GetP1().EuclideanDistanceTo(alignedValve->GetP2());
            double lengthProb = lengths->Predict("MV-" + type, params.timeStep, pointDist);
            double lengthCost = -log(std::max(lengthProb, 0.00000001));

            double lineSum = 0.0;
            for(unsigned int j = 0; j < 2; j++)
            {

                MatrixType feature;
                extractLBPFeature(params, alignedValve, alignedValve->GetPoint(j+1), feature);

                SVMClassifier::IntMatrixType classes;
                MatrixType probs;
                classifiers["MV-"+type][j]->PredictProbability(feature, classes, probs);

                double prob = probs(0,1);
                double cost = -log(std::max(prob, 0.000000001));

                lineSum += cost;

            }

            std::cout << "Costs: " << type << " " << lineSum << " " << lengthCost << std::endl;
            lineSum += lengthCost;

            if(lineSum < minValue)
            {
                minIndex = i;
                minValue = lineSum;
            }
        }

        // save the min index
        if(save)
        {
            TestData::LineType fline = lineIt->second[minIndex];
            ValveLine<3>::Pointer toSave = ValveLine<3>::New();
            createAlignedValve(fline, images.image, toSave, flipImage, flipPoints);
            ValveWriter<3>::Pointer writer = ValveWriter<3>::New();
            writer->SetFileName(type);
            writer->SetInput(toSave);
            writer->Write();
        }

        lineIt++;

        totalCost += minValue;

    }

    if(totalCost < 0.0) totalCost = 1000;

    return totalCost;

}
示例#3
0
osg::Node* createDrawables()
{
    // You need a viewport uniform for the lines to work.
    // MapNode installs one automatically, but we're not using MapNode
    // in this example.
    osg::Group* group = new osg::Group();
    group->addCullCallback(new InstallViewportSizeUniform());

    float x = 10;
    float y = 10;

    LineDrawable* strip = new LineDrawable(GL_LINE_STRIP);
    strip->setLineWidth(8);
    strip->setColor(osg::Vec4(1,1,1,1));
    addVerts(strip, x, y);
    group->addChild(strip);

    x += 20;
    LineDrawable* loop = new LineDrawable(GL_LINE_LOOP);
    loop->setLineWidth(1);
    loop->setColor(osg::Vec4(1,1,0,1));
    addVerts(loop, x, y);
    group->addChild(loop);

    x += 20;
    LineDrawable* stippled = new LineDrawable(GL_LINE_STRIP);
    stippled->setLineWidth(4);
    stippled->setStipplePattern(0xff00);
    stippled->setColor(osg::Vec4(0,1,0,1));
    addVerts(stippled, x, y);
    group->addChild(stippled);
    
    x += 20;
    LineDrawable* segments = new LineDrawable(GL_LINES);
    segments->setLineWidth(3);
    segments->setColor(osg::Vec4(0,1,1,1));
    addVerts(segments, x, y);
    group->addChild(segments);

    x += 20;
    LineDrawable* firstCount = new LineDrawable(GL_LINE_STRIP);
    firstCount->setLineWidth(5);
    firstCount->setColor(osg::Vec4(1,0,1,1));
    addVerts(firstCount, x, y);
    firstCount->addUpdateCallback(new TestFirstCount());
    group->addChild(firstCount);
    
    x += 20;
    osg::ref_ptr<osg::Node> node = makeGeometryForImport(x, y);
    LineGroup* lines = new LineGroup();
    lines->import(node.get());
    group->addChild(lines);

    x += 20;
    LineDrawable* points = new LineDrawable(GL_POINTS);
    addVerts(points, x, y);
    group->addChild(points);

    x = 20;
    y -= 20;
    for(unsigned i=0; i<10; ++i)
    {
        LineDrawable* across = new LineDrawable(GL_LINES);
        across->pushVertex(osg::Vec3(x, 0, y));
        across->pushVertex(osg::Vec3(x+100, 0, y));
        across->setLineWidth((float)(i+1));
        across->finish();
        group->addChild(across);
        y -= (i+2);
    }

    x = 20;
    y -= 20;
    LineDrawable* star = makeStar(x, y, 10);
    star->setColor(osg::Vec4(1,1,1,1));
    star->setLineWidth(1.0f);
    group->addChild(star);

    x += 40;
    LineDrawable* star2 = makeStar(x, y, 10);
    star2->setColor(osg::Vec4(1,.5,0,1));
    star2->setLineWidth(2.0f);
    group->addChild(star2);

    x += 40;
    LineDrawable* star3 = makeStar(x, y, 10);
    star3->setColor(osg::Vec4(1,1,0,1));
    star3->setLineWidth(3.0f);
    group->addChild(star3);

    y -= 40;
    x = 20;
    PointDrawable* grid = makeGridOfPoints(x, y);
    grid->setPointSize(3.0f);
    grid->setColor(osg::Vec4(0,1,1,1));
    group->addChild(grid);

    x += 50;
    PointDrawable* grid2 = makeGridOfPoints(x, y);
    grid2->setPointSize(20.0f);
    GLUtils::setPointSmooth(grid2->getOrCreateStateSet(), 1);
    group->addChild(grid2);

    return group;
}