Пример #1
0
int main (int argc, char* argv[])
{
    std::cerr << "This example works only with nathan.osg" << std::endl;

    osg::ArgumentParser psr(&argc, argv);

    osgViewer::Viewer viewer(psr);

    std::string file = "nathan.osg";
    if(argc >= 2) 
        file = psr[1];

    // replace the manager
    osg::Group* root = dynamic_cast<osg::Group*>(osgDB::readNodeFile(file));
    if (!root) {
        osg::notify(osg::FATAL) << "can't read file " << file << std::endl;
        return 1;
    }
    osgAnimation::AnimationManagerBase* animationManager = dynamic_cast<osgAnimation::AnimationManagerBase*>(root->getUpdateCallback());
    if(!animationManager) 
    {
        osg::notify(osg::FATAL) << "Did not find AnimationManagerBase updateCallback needed to animate elements" << std::endl;
        return 1;
    }

    osg::ref_ptr<osgAnimation::TimelineAnimationManager> tl = new osgAnimation::TimelineAnimationManager(*animationManager);
    root->setUpdateCallback(tl.get());
    
    ExampleTimelineUsage* callback = new ExampleTimelineUsage(tl.get());
    root->setEventCallback(callback);
    root->getUpdateCallback()->addNestedCallback(callback);
        


    // add the state manipulator
    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );
    
    // add the thread model handler
    viewer.addEventHandler(new osgViewer::ThreadingHandler);

    // add the window size toggle handler
    viewer.addEventHandler(new osgViewer::WindowSizeHandler);
        
    // add the stats handler
    viewer.addEventHandler(new osgViewer::StatsHandler);

    // add the help handler
    viewer.addEventHandler(new osgViewer::HelpHandler(psr.getApplicationUsage()));

    // add the LOD Scale handler
    viewer.addEventHandler(new osgViewer::LODScaleHandler);

    // add the screen capture handler
    viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);

    viewer.setSceneData(root);

    return viewer.run();
}
Пример #2
0
void hal_interrupt_status(void)
{
    int irq_status, irq_enable, timer_status, timer_value, timer_load;
    HAL_READ_UINT32(CYG_DEVICE_IRQ_Status, irq_status);
    HAL_READ_UINT32(CYG_DEVICE_IRQ_Enable, irq_enable);
    HAL_READ_UINT32(CYG_DEVICE_TIMER_LOAD, timer_load);
    HAL_READ_UINT32(CYG_DEVICE_TIMER_CURRENT, timer_value);
    HAL_READ_UINT32(CYG_DEVICE_TIMER_CONTROL, timer_status);    
    diag_printf("Interrupt: IRQ: %x.%x, TIMER: %x.%x.%x, psr: %x\n",
                irq_status, irq_enable, timer_status, timer_value,
                timer_load, psr());
}
Пример #3
0
void ExpressionEvaluator2::parse() {
	ExpressionASTLexer::InputStreamType
			input((const ANTLR_UINT8*)expr.c_str(), ANTLR_ENC_8BIT,
					expr.length(), NULL);
	ExpressionASTLexer lxr(&input);

	ExpressionASTParser::TokenStreamType tstream(ANTLR_SIZE_HINT, lxr.get_tokSource() );
	ExpressionASTParser psr(&tstream);
	psr.setSymbolTable(&st);

	exprAst = psr.expr();
}
Пример #4
0
double ExpressionEvaluator::evaluateExpression() {
	//std::cerr << "Expression:" << expr << std::endl;
	//st.dump();

	// TODO: There should be no need to recreate a new lexer and parser,
	// however the reset() methods of lexer and parser do not work (yet)
	// a possible solution could be to create an AST in the parser,
	// and then reuse the AST during evaluation
	ExpressionLexer::InputStreamType
			input((const ANTLR_UINT8*)expr.c_str(), ANTLR_ENC_8BIT,
					expr.length(), NULL);
	ExpressionLexer lxr(&input);

	ExpressionParser::TokenStreamType tstream(ANTLR_SIZE_HINT, lxr.get_tokSource() );
	ExpressionParser psr(&tstream);
	psr.setSymbolTable(&st);

	return psr.expr();
}
Пример #5
0
    bool LineExtract::ComputeLineDesc(LineFeature &lf, const cv::Mat &xGradient, const Mat &yGradient) {

        assert(!xGradient.empty() && ! yGradient.empty());
        lf.mDirection = lf.getGradient(xGradient, yGradient);
        int s = 5 * xGradient.cols / 800.0;
        double lineLen = (lf.mStartPt - lf.mEndPt).norm();
        vector<vector<double>> GDM;
        double step = setting::msld_sample_interval;
        for (int i = 0; i * step < lineLen; ++i) {
            vector<double> GDM_cols;
            GDM_cols.reserve(36);
            Vector2d pt = lf.mStartPt + (lf.mStartPt - lf.mEndPt) * (i * step / lineLen);

            bool fail = false;
            for (int j = -4; j <= 4; ++j) {
                pt += j * s * lf.mDirection;
                cv::Point2d cvpt(pt(0), pt(1));
                cv::Point2d gd(lf.mDirection(0), lf.mDirection(1));
                vector<double> psr(4);
                if (computeSubPSR(xGradient, yGradient, cvpt, s, gd, psr)) {
                    GDM_cols.push_back(psr[0]);
                    GDM_cols.push_back(psr[1]);
                    GDM_cols.push_back(psr[2]);
                    GDM_cols.push_back(psr[3]);
                } else {
                    fail = true;
                    break;
                }

            }
            if (fail == true) continue;
            GDM.push_back(GDM_cols);

        }
        cv::Mat MS(72, 1, CV_32F);
        if (GDM.size() == 0) {
            for (int i = 0; i < MS.rows; ++i)
                MS.at<double>(i, 0) = rand(); // if not computable, assign random num
            lf.mDescriptor = MS.clone();
            return 0;
        }

        double gauss[9] = {0.24142, 0.30046, 0.35127, 0.38579, 0.39804,
                           0.38579, 0.35127, 0.30046, 0.24142};
        for (int i = 0; i < 36; ++i) {
            double sum = 0, sum2 = 0, mean, std;
            for (int j = 0; j < GDM.size(); ++j) {
                GDM[j][i] = GDM[j][i] * gauss[i / 4];
                sum += GDM[j][i];
                sum2 += GDM[j][i] * GDM[j][i];
            }
            mean = sum / GDM.size();
            std = sqrt(sum2 / GDM.size() - mean * mean);
            MS.at<double>(i, 0) = mean;
            MS.at<double>(i + 36, 0) = std;
        }
        // normalize mean and std vector, respcectively
//        LOG(INFO) << MS << endl;
//        if ((cv::norm(MS.rowRange(36, 72)) < 1e-5) || (cv::norm(MS.rowRange(0, 36)) < 1e-5)) {
//            lf.mDescriptor = Mat();
//            return 0;
//        }
//        MS.rowRange(0, 36) = MS.rowRange(0, 36) / cv::norm(MS.rowRange(0, 36));
//        MS.rowRange(36, 72) = MS.rowRange(36, 72) / cv::norm(MS.rowRange(36, 72));
//        for (int i = 0; i < MS.rows; ++i) {
//            if (MS.at<double>(i, 0) > 0.4)
//                MS.at<double>(i, 0) = 0.4;
//        }
//        MS = MS / cv::norm(MS);
//        lf.mDescriptor = MS.clone();
        return 1;
    }
Пример #6
0
int main (int argc, char* argv[])
{
    std::cerr << "This example works better with nathan.osg" << std::endl;

    osg::ArgumentParser psr(&argc, argv);

    osgViewer::Viewer viewer(psr);

    bool hardware = true;
    int maxChar = 10;
    while (psr.read("--software")) { hardware = false; }
    while (psr.read("--number", maxChar)) {}

    osg::ref_ptr<osg::Node> node = osgDB::readRefNodeFiles(psr);
    osg::ref_ptr<osg::Group> root = dynamic_cast<osg::Group*>(node.get());
    if (!root)
    {
        std::cout << psr.getApplicationName() <<": No data loaded" << std::endl;
        return 1;
    }

    {
        osgAnimation::AnimationManagerBase* animationManager = dynamic_cast<osgAnimation::AnimationManagerBase*>(root->getUpdateCallback());
        if(!animationManager)
        {
            osg::notify(osg::FATAL) << "no AnimationManagerBase found, updateCallback need to animate elements" << std::endl;
            return 1;
        }
    }


    osg::ref_ptr<osg::Group> scene = new osg::Group;

    // add the state manipulator
    viewer.addEventHandler( new osgGA::StateSetManipulator(viewer.getCamera()->getOrCreateStateSet()) );

    // add the thread model handler
    viewer.addEventHandler(new osgViewer::ThreadingHandler);

    // add the window size toggle handler
    viewer.addEventHandler(new osgViewer::WindowSizeHandler);

    // add the stats handler
    viewer.addEventHandler(new osgViewer::StatsHandler);

    // add the help handler
    viewer.addEventHandler(new osgViewer::HelpHandler(psr.getApplicationUsage()));

    // add the LOD Scale handler
    viewer.addEventHandler(new osgViewer::LODScaleHandler);

    // add the screen capture handler
    viewer.addEventHandler(new osgViewer::ScreenCaptureHandler);

    viewer.setSceneData(scene.get());

    viewer.realize();

    double xChar = maxChar;
    double yChar = xChar * 9.0/16;
    for (double  i = 0.0; i < xChar; i++) {
        for (double  j = 0.0; j < yChar; j++) {

            osg::ref_ptr<osg::Group> c = createCharacterInstance(root.get(), hardware);
            osg::MatrixTransform* tr = new osg::MatrixTransform;
            tr->setMatrix(osg::Matrix::translate( 2.0 * (i - xChar * .5),
                                                  0.0,
                                                  2.0 * (j - yChar * .5)));
            tr->addChild(c.get());
            scene->addChild(tr);
        }
    }
    std::cout << "created " << xChar * yChar << " instance"  << std::endl;


    return viewer.run();
}