Esempio n. 1
0
void ScanWizard::SetPage(const QString &pageTitle)
{
    LOG(VB_CHANSCAN, LOG_INFO, QString("SetPage(%1)").arg(pageTitle));
    if (pageTitle != ChannelScannerGUI::kTitle)
    {
        scannerPane->quitScanning();
        return;
    }

    QMap<QString,QString> start_chan;
    DTVTunerType parse_type = DTVTunerType::kTunerTypeUnknown;

    uint    cardid    = configPane->GetCardID();
    QString inputname = configPane->GetInputName();
    uint    sourceid  = configPane->GetSourceID();
    int     scantype  = configPane->GetScanType();
    bool    do_scan   = true;

    LOG(VB_CHANSCAN, LOG_INFO, LOC + "SetPage(): " +
        QString("type(%1) cardid(%2) inputname(%3)")
            .arg(scantype).arg(cardid).arg(inputname));

    if (scantype == ScanTypeSetting::DVBUtilsImport)
    {
        scannerPane->ImportDVBUtils(sourceid, lastHWCardType,
                                    configPane->GetFilename());
    }
    else if (scantype == ScanTypeSetting::NITAddScan_DVBT)
    {
        start_chan = configPane->GetStartChan();
        parse_type = DTVTunerType::kTunerTypeDVBT;
    }
    else if (scantype == ScanTypeSetting::NITAddScan_DVBS)
    {
        start_chan = configPane->GetStartChan();
        parse_type = DTVTunerType::kTunerTypeDVBS1;
    }
    else if (scantype == ScanTypeSetting::NITAddScan_DVBS2)
    {
        start_chan = configPane->GetStartChan();
        parse_type = DTVTunerType::kTunerTypeDVBS2;
    }
    else if (scantype == ScanTypeSetting::NITAddScan_DVBC)
    {
        start_chan = configPane->GetStartChan();
        parse_type = DTVTunerType::kTunerTypeDVBC;
    }
    else if (scantype == ScanTypeSetting::IPTVImport)
    {
        do_scan = false;
        scannerPane->ImportM3U(cardid, inputname, sourceid);
    }
    else if ((scantype == ScanTypeSetting::FullScan_ATSC)     ||
             (scantype == ScanTypeSetting::FullTransportScan) ||
             (scantype == ScanTypeSetting::TransportScan)     ||
             (scantype == ScanTypeSetting::CurrentTransportScan) ||
             (scantype == ScanTypeSetting::FullScan_DVBC)     ||
             (scantype == ScanTypeSetting::FullScan_DVBT)     ||
             (scantype == ScanTypeSetting::FullScan_Analog))
    {
        ;
    }
    else if (scantype == ScanTypeSetting::ExistingScanImport)
    {
        do_scan = false;
        uint scanid = configPane->GetScanID();
        ScanDTVTransportList transports = LoadScan(scanid);
        ChannelImporter ci(true, true, true, true, false,
                           configPane->DoFreeToAirOnly(),
                           configPane->GetServiceRequirements());
        ci.Process(transports);
    }
    else
    {
        do_scan = false;
        LOG(VB_CHANSCAN, LOG_ERR, LOC + "SetPage(): " +
            QString("type(%1) src(%2) cardid(%3) not handled")
                .arg(scantype).arg(sourceid).arg(cardid));

        MythPopupBox::showOkPopup(
            GetMythMainWindow(), tr("ScanWizard"),
            tr("Programmer Error, see console"));
    }

    // Just verify what we get from the UI...
    DTVMultiplex tuning;
    if ((parse_type != DTVTunerType::kTunerTypeUnknown) &&
        !tuning.ParseTuningParams(
            parse_type,
            start_chan["frequency"],      start_chan["inversion"],
            start_chan["symbolrate"],     start_chan["fec"],
            start_chan["polarity"],
            start_chan["coderate_hp"],    start_chan["coderate_lp"],
            start_chan["constellation"],  start_chan["trans_mode"],
            start_chan["guard_interval"], start_chan["hierarchy"],
            start_chan["modulation"],     start_chan["bandwidth"],
            start_chan["mod_sys"],        start_chan["rolloff"]))
    {
        MythPopupBox::showOkPopup(
            GetMythMainWindow(), tr("ScanWizard"),
            tr("Error parsing parameters"));

        do_scan = false;
    }

    if (do_scan)
    {
        QString table_start, table_end;
        configPane->GetFrequencyTableRange(table_start, table_end);

        scannerPane->Scan(
            configPane->GetScanType(),            configPane->GetCardID(),
            configPane->GetInputName(),           configPane->GetSourceID(),
            configPane->DoIgnoreSignalTimeout(),  configPane->DoFollowNIT(),
            configPane->DoTestDecryption(),       configPane->DoFreeToAirOnly(),
            configPane->GetServiceRequirements(),
            // stuff needed for particular scans
            configPane->GetMultiplex(),         start_chan,
            configPane->GetFrequencyStandard(), configPane->GetModulation(),
            configPane->GetFrequencyTable(),
            table_start, table_end);
    }
}
Esempio n. 2
0
std::vector<Particle*> ParticleGenerator::readFile(int* length, auto_ptr<input_t>& inp, int* uid) {
	LOG4CXX_TRACE(loggerPG, "ParticleGenerator called to generate particles");
	
std::vector<Particle*> partlist;

	float dist = 0;
	double x[] = {0,0,0};
	double v[] = {1,1,1};
	int type = -1;
	int nature = -1;
	double epsilon = -1.0;
	double sigma = -1.0;
	int count_uid = *uid;
	for(input_t::sphere_const_iterator si (inp->sphere().begin()); si != inp->sphere().end(); ++si) {
		float max_dist = std::pow(si->radius(), 2); 
		v[0] = si->velocity().x();
		v[1] = si->velocity().y();
		v[2] = si->velocity().z();
		type = si->type();
		nature = si->nature();
		epsilon = si->epsilon();
		sigma = si->sigma();
		LOG4CXX_INFO(loggerPG, "Generate a Sphere");
	    ASSERT_WITH_MESSAGE(loggerPG, (epsilon>0), "Invalid epsilon. Please specify first " << epsilon);
	    ASSERT_WITH_MESSAGE(loggerPG, (sigma>0), "Invalid delta_t. Please specify first " << sigma);
					
		for(float d1 = si->position().x()-si->radius()*si->distance(); d1 < si->position().x()+si->radius()*si->distance(); d1+=si->distance()) {
			x[0] = d1;
			for(float d2 = si->position().y()-si->radius()*si->distance(); d2 < si->position().y()+si->radius()*si->distance(); d2 +=si->distance()) {
				x[1] = d2;
				
				for(float d3 = si->position().z()-si->radius()*si->distance(); d3 < si->position().z()+si->radius()*si->distance(); d3 +=si->distance()) {
					if(inp->dimensions() == 2) {
						d3 = si->position().z();
					}
					
					x[2] = d3;
					dist = 
						std::pow(si->position().x()-d1,2)+
						std::pow(si->position().y()-d2,2)+
						std::pow(si->position().z()-d3,2);
					if(dist <= max_dist) {
						Particle* p = new Particle(x,v,si->mass());

						p->setType(type);
						p->setNature(nature);
						p->setEpsilon(epsilon);
						p->setSigma(sigma);
						p->setUid(count_uid);
						count_uid++;
						utils::Vector<double, 3> velo = v;
						MaxwellBoltzmannDistribution(*p,velo.L2Norm(),inp->dimensions(), false);

						partlist.push_back(p);
					}
					if(inp->dimensions() == 2) {
						break;
					}
				}
			}
		}
	}
	LOG4CXX_INFO(loggerPG, "Generated " << partlist.size() << " Particles for Spheres");
	int num_particles = 0;

	for (input_t::cuboid_const_iterator ci (inp->cuboid ().begin ());ci != inp->cuboid ().end ();++ci){
		num_particles += ci->number().x() * ci->number().y() * ci->number().z();
    }

	for (input_t::cuboid_const_iterator ci (inp->cuboid ().begin ());ci != inp->cuboid ().end ();++ci){
		v[0] = ci->velocity().x();
		v[1] = ci->velocity().y();
		v[2] = ci->velocity().z();
		type = ci->type();
		nature = ci->nature();
		epsilon = ci->epsilon();
		sigma = ci->sigma();
	    LOG4CXX_INFO(loggerPG, "Generate Cuboids");
	    ASSERT_WITH_MESSAGE(loggerPG, (epsilon>0), "Invalid epsilon. Please specify first " << epsilon);
	    ASSERT_WITH_MESSAGE(loggerPG, (sigma>0), "Invalid delta_t. Please specify first " << sigma);

		for(int d1 = 0; d1 < ci->number().x(); d1++) {
			x[0] = d1*ci->distance()+ci->position().x();
			for(int d2 = 0; d2 < ci->number().y(); d2++) {
				x[1] = d2*ci->distance()+ci->position().y();
				for(int d3 = 0; d3 < ci->number().z(); d3++) {
					x[2] = d3*ci->distance()+ci->position().z();

					Particle* p = new Particle(x,v,ci->mass());

					p->setType(type);
					p->setNature(nature);
					p->setEpsilon(epsilon);
					p->setSigma(sigma);
					p->setUid(count_uid);
					count_uid++;
					utils::Vector<double, 3> velo = v;
					MaxwellBoltzmannDistribution(*p,velo.L2Norm(),inp->dimensions(), false);

					partlist.push_back(p);
				}
			}
		}
	}


	LOG4CXX_INFO(loggerPG, "Generated overall " << partlist.size() << " Particles");
	
	*length =partlist.size();
	return partlist;
}
Esempio n. 3
0
bool Sensor2DeviceImpl::setTrackingReport(const TrackingReport& data)
{
    TrackingImpl ci(data);
    return GetInternalDevice()->SetFeatureReport(ci.Buffer, TrackingImpl::PacketSize);
}
Esempio n. 4
0
void
LSLocateFluidInterface::setLevelSetPatchData(int D_idx,
                                             Pointer<HierarchyMathOps> hier_math_ops,
                                             double /*time*/,
                                             bool initial_time)
{
    Pointer<PatchHierarchy<NDIM> > patch_hierarchy = hier_math_ops->getPatchHierarchy();
    const int coarsest_ln = 0;
    const int finest_ln = patch_hierarchy->getFinestLevelNumber();

    // If not the intial time, set the level set to the current value maintained by the integrator
    if (!initial_time)
    {
        VariableDatabase<NDIM>* var_db = VariableDatabase<NDIM>::getDatabase();
        const int ls_current_idx =
            var_db->mapVariableAndContextToIndex(d_ls_var, d_adv_diff_solver->getCurrentContext());
        HierarchyCellDataOpsReal<NDIM, double> hier_cc_data_ops(patch_hierarchy, coarsest_ln, finest_ln);

        hier_cc_data_ops.copyData(D_idx, ls_current_idx);

        return;
    }

    // Set the initial condition for locating the interface
    const double& R = d_init_circle.R;
    const IBTK::Vector& X0 = d_init_circle.X0;
    const double& film_height = d_init_film.height;
    const int height_dim = NDIM - 1;

    for (int ln = coarsest_ln; ln <= finest_ln; ++ln)
    {
        Pointer<PatchLevel<NDIM> > level = patch_hierarchy->getPatchLevel(ln);
        for (PatchLevel<NDIM>::Iterator p(level); p; p++)
        {
            Pointer<Patch<NDIM> > patch = level->getPatch(p());
            const Box<NDIM>& patch_box = patch->getBox();
            Pointer<CellData<NDIM, double> > D_data = patch->getPatchData(D_idx);
            for (Box<NDIM>::Iterator it(patch_box); it; it++)
            {
                CellIndex<NDIM> ci(it());

                // Get physical coordinates
                IBTK::Vector coord = IBTK::Vector::Zero();
                Pointer<CartesianPatchGeometry<NDIM> > patch_geom = patch->getPatchGeometry();
                const double* patch_X_lower = patch_geom->getXLower();
                const hier::Index<NDIM>& patch_lower_idx = patch_box.lower();
                const double* const patch_dx = patch_geom->getDx();
                for (int d = 0; d < NDIM; ++d)
                {
                    coord[d] = patch_X_lower[d] + patch_dx[d] * (static_cast<double>(ci(d) - patch_lower_idx(d)) + 0.5);
                }

                // Distance from the bubble
                const double distance_bubble =
                    std::sqrt(std::pow((coord[0] - X0(0)), 2.0) + std::pow((coord[1] - X0(1)), 2.0)
#if (NDIM == 3)
                              + std::pow((coord[2] - X0(2)), 2.0)
#endif
                                  ) -
                    R;

                // Distance from the film
                const double distance_film = coord[height_dim] - film_height;

                if (distance_film <= 0)
                {
                    // If within the film, set LS as the negative distance away
                    (*D_data)(ci) = distance_film;
                }
                else if (distance_bubble <= 0)
                {
                    // If within the bubble, again set the LS as the negative distance away
                    (*D_data)(ci) = distance_bubble;
                }
                else
                {
                    // Otherwise, set the distance as the minimum between the two
                    (*D_data)(ci) = std::min(distance_bubble, distance_film);
                }
            }
        }
    }
    return;
} // setLevelSetPatchData
Esempio n. 5
0
void	ConstraintDemo::initPhysics()
{
    setTexturing(true);
    setShadows(true);

    setCameraDistance(26.f);
    m_Time = 0;

    setupEmptyDynamicsWorld();

    m_dynamicsWorld->setDebugDrawer(&gDebugDrawer);


    //btCollisionShape* groundShape = new btBoxShape(btVector3(btScalar(50.),btScalar(40.),btScalar(50.)));
    btCollisionShape* groundShape = new btStaticPlaneShape(btVector3(0,1,0),40);

    m_collisionShapes.push_back(groundShape);
    btTransform groundTransform;
    groundTransform.setIdentity();
    groundTransform.setOrigin(btVector3(0,-56,0));
    btRigidBody* groundBody;
    groundBody= localCreateRigidBody(0, groundTransform, groundShape);



    btCollisionShape* shape = new btBoxShape(btVector3(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS));
    m_collisionShapes.push_back(shape);
    btTransform trans;
    trans.setIdentity();
    trans.setOrigin(btVector3(0,20,0));

    float mass = 1.f;

#if ENABLE_ALL_DEMOS
///gear constraint demo

#define THETA SIMD_PI/4.f
#define L_1 (2 - tan(THETA))
#define L_2 (1 / cos(THETA))
#define RATIO L_2 / L_1

    btRigidBody* bodyA=0;
    btRigidBody* bodyB=0;

    {
        btCollisionShape* cylA = new btCylinderShape(btVector3(0.2,0.25,0.2));
        btCollisionShape* cylB = new btCylinderShape(btVector3(L_1,0.025,L_1));
        btCompoundShape* cyl0 = new btCompoundShape();
        cyl0->addChildShape(btTransform::getIdentity(),cylA);
        cyl0->addChildShape(btTransform::getIdentity(),cylB);

        btScalar mass = 6.28;
        btVector3 localInertia;
        cyl0->calculateLocalInertia(mass,localInertia);
        btRigidBody::btRigidBodyConstructionInfo ci(mass,0,cyl0,localInertia);
        ci.m_startWorldTransform.setOrigin(btVector3(-8,1,-8));

        btRigidBody* body = new btRigidBody(ci);//1,0,cyl0,localInertia);
        m_dynamicsWorld->addRigidBody(body);
        body->setLinearFactor(btVector3(0,0,0));
        body->setAngularFactor(btVector3(0,1,0));
        bodyA = body;
    }

    {
        btCollisionShape* cylA = new btCylinderShape(btVector3(0.2,0.26,0.2));
        btCollisionShape* cylB = new btCylinderShape(btVector3(L_2,0.025,L_2));
        btCompoundShape* cyl0 = new btCompoundShape();
        cyl0->addChildShape(btTransform::getIdentity(),cylA);
        cyl0->addChildShape(btTransform::getIdentity(),cylB);

        btScalar mass = 6.28;
        btVector3 localInertia;
        cyl0->calculateLocalInertia(mass,localInertia);
        btRigidBody::btRigidBodyConstructionInfo ci(mass,0,cyl0,localInertia);
        ci.m_startWorldTransform.setOrigin(btVector3(-10,2,-8));


        btQuaternion orn(btVector3(0,0,1),-THETA);
        ci.m_startWorldTransform.setRotation(orn);

        btRigidBody* body = new btRigidBody(ci);//1,0,cyl0,localInertia);
        body->setLinearFactor(btVector3(0,0,0));
        btHingeConstraint* hinge = new btHingeConstraint(*body,btVector3(0,0,0),btVector3(0,1,0),true);
        m_dynamicsWorld->addConstraint(hinge);
        bodyB= body;
        body->setAngularVelocity(btVector3(0,3,0));

        m_dynamicsWorld->addRigidBody(body);
    }

    btVector3	axisA(0,1,0);
    btVector3	axisB(0,1,0);
    btQuaternion orn(btVector3(0,0,1),-THETA);
    btMatrix3x3 mat(orn);
    axisB = mat.getRow(1);

    btGearConstraint* gear = new btGearConstraint(*bodyA,*bodyB, axisA,axisB,RATIO);
    m_dynamicsWorld->addConstraint(gear,true);


#endif


#if ENABLE_ALL_DEMOS
    //point to point constraint with a breaking threshold
    {
        trans.setIdentity();
        trans.setOrigin(btVector3(1,30,-5));
        localCreateRigidBody( mass,trans,shape);
        trans.setOrigin(btVector3(0,0,-5));

        btRigidBody* body0 = localCreateRigidBody( mass,trans,shape);
        trans.setOrigin(btVector3(2*CUBE_HALF_EXTENTS,20,0));
        mass = 1.f;
        //	btRigidBody* body1 = 0;//localCreateRigidBody( mass,trans,shape);
        btVector3 pivotInA(CUBE_HALF_EXTENTS,CUBE_HALF_EXTENTS,0);
        btTypedConstraint* p2p = new btPoint2PointConstraint(*body0,pivotInA);
        m_dynamicsWorld->addConstraint(p2p);
        p2p ->setBreakingImpulseThreshold(10.2);
        p2p->setDbgDrawSize(btScalar(5.f));
    }
#endif



#if ENABLE_ALL_DEMOS
    //point to point constraint (ball socket)
    {
        btRigidBody* body0 = localCreateRigidBody( mass,trans,shape);
        trans.setOrigin(btVector3(2*CUBE_HALF_EXTENTS,20,0));

        mass = 1.f;
//		btRigidBody* body1 = 0;//localCreateRigidBody( mass,trans,shape);
//		btRigidBody* body1 = localCreateRigidBody( 0.0,trans,0);
        //body1->setActivationState(DISABLE_DEACTIVATION);
        //body1->setDamping(0.3,0.3);

        btVector3 pivotInA(CUBE_HALF_EXTENTS,-CUBE_HALF_EXTENTS,-CUBE_HALF_EXTENTS);
        btVector3 axisInA(0,0,1);

        //	btVector3 pivotInB = body1 ? body1->getCenterOfMassTransform().inverse()(body0->getCenterOfMassTransform()(pivotInA)) : pivotInA;
//		btVector3 axisInB = body1?
//			(body1->getCenterOfMassTransform().getBasis().inverse()*(body1->getCenterOfMassTransform().getBasis() * axisInA)) :
        body0->getCenterOfMassTransform().getBasis() * axisInA;

#define P2P
#ifdef P2P
        btTypedConstraint* p2p = new btPoint2PointConstraint(*body0,pivotInA);
        //btTypedConstraint* p2p = new btPoint2PointConstraint(*body0,*body1,pivotInA,pivotInB);
        //btTypedConstraint* hinge = new btHingeConstraint(*body0,*body1,pivotInA,pivotInB,axisInA,axisInB);
        m_dynamicsWorld->addConstraint(p2p);
        p2p->setDbgDrawSize(btScalar(5.f));
#else
        btHingeConstraint* hinge = new btHingeConstraint(*body0,pivotInA,axisInA);

        //use zero targetVelocity and a small maxMotorImpulse to simulate joint friction
        //float	targetVelocity = 0.f;
        //float	maxMotorImpulse = 0.01;
        float	targetVelocity = 1.f;
        float	maxMotorImpulse = 1.0f;
        hinge->enableAngularMotor(true,targetVelocity,maxMotorImpulse);
        m_dynamicsWorld->addConstraint(hinge);
        hinge->setDbgDrawSize(btScalar(5.f));
#endif //P2P




    }
#endif

#if ENABLE_ALL_DEMOS
    //create a slider, using the generic D6 constraint
    {
        mass = 1.f;
        btVector3 sliderWorldPos(0,10,0);
        btVector3 sliderAxis(1,0,0);
        btScalar angle=0.f;//SIMD_RADS_PER_DEG * 10.f;
        btMatrix3x3 sliderOrientation(btQuaternion(sliderAxis ,angle));
        trans.setIdentity();
        trans.setOrigin(sliderWorldPos);
        //trans.setBasis(sliderOrientation);
        sliderTransform = trans;

        d6body0 = localCreateRigidBody( mass,trans,shape);
        d6body0->setActivationState(DISABLE_DEACTIVATION);
        btRigidBody* fixedBody1 = localCreateRigidBody(0,trans,0);
        m_dynamicsWorld->addRigidBody(fixedBody1);

        btTransform frameInA, frameInB;
        frameInA = btTransform::getIdentity();
        frameInB = btTransform::getIdentity();
        frameInA.setOrigin(btVector3(0., 5., 0.));
        frameInB.setOrigin(btVector3(0., 5., 0.));

//		bool useLinearReferenceFrameA = false;//use fixed frame B for linear llimits
        bool useLinearReferenceFrameA = true;//use fixed frame A for linear llimits
        spSlider6Dof = new btGeneric6DofConstraint(*fixedBody1, *d6body0,frameInA,frameInB,useLinearReferenceFrameA);
        spSlider6Dof->setLinearLowerLimit(lowerSliderLimit);
        spSlider6Dof->setLinearUpperLimit(hiSliderLimit);

        //range should be small, otherwise singularities will 'explode' the constraint
//		spSlider6Dof->setAngularLowerLimit(btVector3(-1.5,0,0));
//		spSlider6Dof->setAngularUpperLimit(btVector3(1.5,0,0));
//		spSlider6Dof->setAngularLowerLimit(btVector3(0,0,0));
//		spSlider6Dof->setAngularUpperLimit(btVector3(0,0,0));
        spSlider6Dof->setAngularLowerLimit(btVector3(-SIMD_PI,0,0));
        spSlider6Dof->setAngularUpperLimit(btVector3(1.5,0,0));

        spSlider6Dof->getTranslationalLimitMotor()->m_enableMotor[0] = true;
        spSlider6Dof->getTranslationalLimitMotor()->m_targetVelocity[0] = -5.0f;
        spSlider6Dof->getTranslationalLimitMotor()->m_maxMotorForce[0] = 0.1f;


        m_dynamicsWorld->addConstraint(spSlider6Dof);
        spSlider6Dof->setDbgDrawSize(btScalar(5.f));

    }
#endif
#if ENABLE_ALL_DEMOS
    {   // create a door using hinge constraint attached to the world
        btCollisionShape* pDoorShape = new btBoxShape(btVector3(2.0f, 5.0f, 0.2f));
        m_collisionShapes.push_back(pDoorShape);
        btTransform doorTrans;
        doorTrans.setIdentity();
        doorTrans.setOrigin(btVector3(-5.0f, -2.0f, 0.0f));
        btRigidBody* pDoorBody = localCreateRigidBody( 1.0, doorTrans, pDoorShape);
        pDoorBody->setActivationState(DISABLE_DEACTIVATION);
        const btVector3 btPivotA(10.f +  2.1f, -2.0f, 0.0f ); // right next to the door slightly outside
        btVector3 btAxisA( 0.0f, 1.0f, 0.0f ); // pointing upwards, aka Y-axis

        spDoorHinge = new btHingeConstraint( *pDoorBody, btPivotA, btAxisA );

//		spDoorHinge->setLimit( 0.0f, SIMD_PI_2 );
        // test problem values
//		spDoorHinge->setLimit( -SIMD_PI, SIMD_PI*0.8f);

//		spDoorHinge->setLimit( 1.f, -1.f);
//		spDoorHinge->setLimit( -SIMD_PI*0.8f, SIMD_PI);
//		spDoorHinge->setLimit( -SIMD_PI*0.8f, SIMD_PI, 0.9f, 0.3f, 0.0f);
//		spDoorHinge->setLimit( -SIMD_PI*0.8f, SIMD_PI, 0.9f, 0.01f, 0.0f); // "sticky limits"
        spDoorHinge->setLimit( -SIMD_PI * 0.25f, SIMD_PI * 0.25f );
//		spDoorHinge->setLimit( 0.0f, 0.0f );
        m_dynamicsWorld->addConstraint(spDoorHinge);
        spDoorHinge->setDbgDrawSize(btScalar(5.f));

        //doorTrans.setOrigin(btVector3(-5.0f, 2.0f, 0.0f));
        //btRigidBody* pDropBody = localCreateRigidBody( 10.0, doorTrans, shape);
    }
#endif
#if ENABLE_ALL_DEMOS
    {   // create a generic 6DOF constraint

        btTransform tr;
        tr.setIdentity();
        tr.setOrigin(btVector3(btScalar(10.), btScalar(6.), btScalar(0.)));
        tr.getBasis().setEulerZYX(0,0,0);
//		btRigidBody* pBodyA = localCreateRigidBody( mass, tr, shape);
        btRigidBody* pBodyA = localCreateRigidBody( 0.0, tr, shape);
//		btRigidBody* pBodyA = localCreateRigidBody( 0.0, tr, 0);
        pBodyA->setActivationState(DISABLE_DEACTIVATION);

        tr.setIdentity();
        tr.setOrigin(btVector3(btScalar(0.), btScalar(6.), btScalar(0.)));
        tr.getBasis().setEulerZYX(0,0,0);
        btRigidBody* pBodyB = localCreateRigidBody(mass, tr, shape);
//		btRigidBody* pBodyB = localCreateRigidBody(0.f, tr, shape);
        pBodyB->setActivationState(DISABLE_DEACTIVATION);

        btTransform frameInA, frameInB;
        frameInA = btTransform::getIdentity();
        frameInA.setOrigin(btVector3(btScalar(-5.), btScalar(0.), btScalar(0.)));
        frameInB = btTransform::getIdentity();
        frameInB.setOrigin(btVector3(btScalar(5.), btScalar(0.), btScalar(0.)));

        btGeneric6DofConstraint* pGen6DOF = new btGeneric6DofConstraint(*pBodyA, *pBodyB, frameInA, frameInB, true);
//		btGeneric6DofConstraint* pGen6DOF = new btGeneric6DofConstraint(*pBodyA, *pBodyB, frameInA, frameInB, false);
        pGen6DOF->setLinearLowerLimit(btVector3(-10., -2., -1.));
        pGen6DOF->setLinearUpperLimit(btVector3(10., 2., 1.));
//		pGen6DOF->setLinearLowerLimit(btVector3(-10., 0., 0.));
//		pGen6DOF->setLinearUpperLimit(btVector3(10., 0., 0.));
//		pGen6DOF->setLinearLowerLimit(btVector3(0., 0., 0.));
//		pGen6DOF->setLinearUpperLimit(btVector3(0., 0., 0.));

//		pGen6DOF->getTranslationalLimitMotor()->m_enableMotor[0] = true;
//		pGen6DOF->getTranslationalLimitMotor()->m_targetVelocity[0] = 5.0f;
//		pGen6DOF->getTranslationalLimitMotor()->m_maxMotorForce[0] = 0.1f;


//		pGen6DOF->setAngularLowerLimit(btVector3(0., SIMD_HALF_PI*0.9, 0.));
//		pGen6DOF->setAngularUpperLimit(btVector3(0., -SIMD_HALF_PI*0.9, 0.));
//		pGen6DOF->setAngularLowerLimit(btVector3(0., 0., -SIMD_HALF_PI));
//		pGen6DOF->setAngularUpperLimit(btVector3(0., 0., SIMD_HALF_PI));

        pGen6DOF->setAngularLowerLimit(btVector3(-SIMD_HALF_PI * 0.5f, -0.75, -SIMD_HALF_PI * 0.8f));
        pGen6DOF->setAngularUpperLimit(btVector3(SIMD_HALF_PI * 0.5f, 0.75, SIMD_HALF_PI * 0.8f));
//		pGen6DOF->setAngularLowerLimit(btVector3(0.f, -0.75, SIMD_HALF_PI * 0.8f));
//		pGen6DOF->setAngularUpperLimit(btVector3(0.f, 0.75, -SIMD_HALF_PI * 0.8f));
//		pGen6DOF->setAngularLowerLimit(btVector3(0.f, -SIMD_HALF_PI * 0.8f, SIMD_HALF_PI * 1.98f));
//		pGen6DOF->setAngularUpperLimit(btVector3(0.f, SIMD_HALF_PI * 0.8f,  -SIMD_HALF_PI * 1.98f));



//		pGen6DOF->setAngularLowerLimit(btVector3(-0.75,-0.5, -0.5));
//		pGen6DOF->setAngularUpperLimit(btVector3(0.75,0.5, 0.5));
//		pGen6DOF->setAngularLowerLimit(btVector3(-0.75,0., 0.));
//		pGen6DOF->setAngularUpperLimit(btVector3(0.75,0., 0.));
//		pGen6DOF->setAngularLowerLimit(btVector3(0., -0.7,0.));
//		pGen6DOF->setAngularUpperLimit(btVector3(0., 0.7, 0.));
//		pGen6DOF->setAngularLowerLimit(btVector3(-1., 0.,0.));
//		pGen6DOF->setAngularUpperLimit(btVector3(1., 0., 0.));

        m_dynamicsWorld->addConstraint(pGen6DOF, true);
        pGen6DOF->setDbgDrawSize(btScalar(5.f));
    }
#endif
#if ENABLE_ALL_DEMOS
    {   // create a ConeTwist constraint

        btTransform tr;
        tr.setIdentity();
        tr.setOrigin(btVector3(btScalar(-10.), btScalar(5.), btScalar(0.)));
        tr.getBasis().setEulerZYX(0,0,0);
        btRigidBody* pBodyA = localCreateRigidBody( 1.0, tr, shape);
//		btRigidBody* pBodyA = localCreateRigidBody( 0.0, tr, shape);
        pBodyA->setActivationState(DISABLE_DEACTIVATION);

        tr.setIdentity();
        tr.setOrigin(btVector3(btScalar(-10.), btScalar(-5.), btScalar(0.)));
        tr.getBasis().setEulerZYX(0,0,0);
        btRigidBody* pBodyB = localCreateRigidBody(0.0, tr, shape);
//		btRigidBody* pBodyB = localCreateRigidBody(1.0, tr, shape);

        btTransform frameInA, frameInB;
        frameInA = btTransform::getIdentity();
        frameInA.getBasis().setEulerZYX(0, 0, SIMD_PI_2);
        frameInA.setOrigin(btVector3(btScalar(0.), btScalar(-5.), btScalar(0.)));
        frameInB = btTransform::getIdentity();
        frameInB.getBasis().setEulerZYX(0,0,  SIMD_PI_2);
        frameInB.setOrigin(btVector3(btScalar(0.), btScalar(5.), btScalar(0.)));

        m_ctc = new btConeTwistConstraint(*pBodyA, *pBodyB, frameInA, frameInB);
//		m_ctc->setLimit(btScalar(SIMD_PI_4), btScalar(SIMD_PI_4), btScalar(SIMD_PI) * 0.8f);
//		m_ctc->setLimit(btScalar(SIMD_PI_4*0.6f), btScalar(SIMD_PI_4), btScalar(SIMD_PI) * 0.8f, 1.0f); // soft limit == hard limit
        m_ctc->setLimit(btScalar(SIMD_PI_4*0.6f), btScalar(SIMD_PI_4), btScalar(SIMD_PI) * 0.8f, 0.5f);
        m_dynamicsWorld->addConstraint(m_ctc, true);
        m_ctc->setDbgDrawSize(btScalar(5.f));
        // s_bTestConeTwistMotor = true; // use only with old solver for now
        s_bTestConeTwistMotor = false;
    }
#endif
#if ENABLE_ALL_DEMOS
    {   // Hinge connected to the world, with motor (to hinge motor with new and old constraint solver)
        btTransform tr;
        tr.setIdentity();
        tr.setOrigin(btVector3(btScalar(0.), btScalar(0.), btScalar(0.)));
        btRigidBody* pBody = localCreateRigidBody( 1.0, tr, shape);
        pBody->setActivationState(DISABLE_DEACTIVATION);
        const btVector3 btPivotA( 10.0f, 0.0f, 0.0f );
        btVector3 btAxisA( 0.0f, 0.0f, 1.0f );

        btHingeConstraint* pHinge = new btHingeConstraint( *pBody, btPivotA, btAxisA );
//		pHinge->enableAngularMotor(true, -1.0, 0.165); // use for the old solver
        pHinge->enableAngularMotor(true, -1.0f, 1.65f); // use for the new SIMD solver
        m_dynamicsWorld->addConstraint(pHinge);
        pHinge->setDbgDrawSize(btScalar(5.f));
    }
#endif

#if ENABLE_ALL_DEMOS
    {
        // create a universal joint using generic 6DOF constraint
        // create two rigid bodies
        // static bodyA (parent) on top:
        btTransform tr;
        tr.setIdentity();
        tr.setOrigin(btVector3(btScalar(20.), btScalar(4.), btScalar(0.)));
        btRigidBody* pBodyA = localCreateRigidBody( 0.0, tr, shape);
        pBodyA->setActivationState(DISABLE_DEACTIVATION);
        // dynamic bodyB (child) below it :
        tr.setIdentity();
        tr.setOrigin(btVector3(btScalar(20.), btScalar(0.), btScalar(0.)));
        btRigidBody* pBodyB = localCreateRigidBody(1.0, tr, shape);
        pBodyB->setActivationState(DISABLE_DEACTIVATION);
        // add some (arbitrary) data to build constraint frames
        btVector3 parentAxis(1.f, 0.f, 0.f);
        btVector3 childAxis(0.f, 0.f, 1.f);
        btVector3 anchor(20.f, 2.f, 0.f);

        btUniversalConstraint* pUniv = new btUniversalConstraint(*pBodyA, *pBodyB, anchor, parentAxis, childAxis);
        pUniv->setLowerLimit(-SIMD_HALF_PI * 0.5f, -SIMD_HALF_PI * 0.5f);
        pUniv->setUpperLimit(SIMD_HALF_PI * 0.5f,  SIMD_HALF_PI * 0.5f);
        // add constraint to world
        m_dynamicsWorld->addConstraint(pUniv, true);
        // draw constraint frames and limits for debugging
        pUniv->setDbgDrawSize(btScalar(5.f));
    }
#endif

#if ENABLE_ALL_DEMOS
    {   // create a generic 6DOF constraint with springs

        btTransform tr;
        tr.setIdentity();
        tr.setOrigin(btVector3(btScalar(-20.), btScalar(16.), btScalar(0.)));
        tr.getBasis().setEulerZYX(0,0,0);
        btRigidBody* pBodyA = localCreateRigidBody( 0.0, tr, shape);
        pBodyA->setActivationState(DISABLE_DEACTIVATION);

        tr.setIdentity();
        tr.setOrigin(btVector3(btScalar(-10.), btScalar(16.), btScalar(0.)));
        tr.getBasis().setEulerZYX(0,0,0);
        btRigidBody* pBodyB = localCreateRigidBody(1.0, tr, shape);
        pBodyB->setActivationState(DISABLE_DEACTIVATION);

        btTransform frameInA, frameInB;
        frameInA = btTransform::getIdentity();
        frameInA.setOrigin(btVector3(btScalar(10.), btScalar(0.), btScalar(0.)));
        frameInB = btTransform::getIdentity();
        frameInB.setOrigin(btVector3(btScalar(0.), btScalar(0.), btScalar(0.)));

        btGeneric6DofSpringConstraint* pGen6DOFSpring = new btGeneric6DofSpringConstraint(*pBodyA, *pBodyB, frameInA, frameInB, true);
        pGen6DOFSpring->setLinearUpperLimit(btVector3(5., 0., 0.));
        pGen6DOFSpring->setLinearLowerLimit(btVector3(-5., 0., 0.));

        pGen6DOFSpring->setAngularLowerLimit(btVector3(0.f, 0.f, -1.5f));
        pGen6DOFSpring->setAngularUpperLimit(btVector3(0.f, 0.f, 1.5f));

        m_dynamicsWorld->addConstraint(pGen6DOFSpring, true);
        pGen6DOFSpring->setDbgDrawSize(btScalar(5.f));

        pGen6DOFSpring->enableSpring(0, true);
        pGen6DOFSpring->setStiffness(0, 39.478f);
        pGen6DOFSpring->setDamping(0, 0.5f);
        pGen6DOFSpring->enableSpring(5, true);
        pGen6DOFSpring->setStiffness(5, 39.478f);
        pGen6DOFSpring->setDamping(0, 0.3f);
        pGen6DOFSpring->setEquilibriumPoint();
    }
#endif
#if ENABLE_ALL_DEMOS
    {
        // create a Hinge2 joint
        // create two rigid bodies
        // static bodyA (parent) on top:
        btTransform tr;
        tr.setIdentity();
        tr.setOrigin(btVector3(btScalar(-20.), btScalar(4.), btScalar(0.)));
        btRigidBody* pBodyA = localCreateRigidBody( 0.0, tr, shape);
        pBodyA->setActivationState(DISABLE_DEACTIVATION);
        // dynamic bodyB (child) below it :
        tr.setIdentity();
        tr.setOrigin(btVector3(btScalar(-20.), btScalar(0.), btScalar(0.)));
        btRigidBody* pBodyB = localCreateRigidBody(1.0, tr, shape);
        pBodyB->setActivationState(DISABLE_DEACTIVATION);
        // add some data to build constraint frames
        btVector3 parentAxis(0.f, 1.f, 0.f);
        btVector3 childAxis(1.f, 0.f, 0.f);
        btVector3 anchor(-20.f, 0.f, 0.f);
        btHinge2Constraint* pHinge2 = new btHinge2Constraint(*pBodyA, *pBodyB, anchor, parentAxis, childAxis);
        pHinge2->setLowerLimit(-SIMD_HALF_PI * 0.5f);
        pHinge2->setUpperLimit( SIMD_HALF_PI * 0.5f);
        // add constraint to world
        m_dynamicsWorld->addConstraint(pHinge2, true);
        // draw constraint frames and limits for debugging
        pHinge2->setDbgDrawSize(btScalar(5.f));
    }
#endif
#if  ENABLE_ALL_DEMOS
    {
        // create a Hinge joint between two dynamic bodies
        // create two rigid bodies
        // static bodyA (parent) on top:
        btTransform tr;
        tr.setIdentity();
        tr.setOrigin(btVector3(btScalar(-20.), btScalar(-2.), btScalar(0.)));
        btRigidBody* pBodyA = localCreateRigidBody( 1.0f, tr, shape);
        pBodyA->setActivationState(DISABLE_DEACTIVATION);
        // dynamic bodyB:
        tr.setIdentity();
        tr.setOrigin(btVector3(btScalar(-30.), btScalar(-2.), btScalar(0.)));
        btRigidBody* pBodyB = localCreateRigidBody(10.0, tr, shape);
        pBodyB->setActivationState(DISABLE_DEACTIVATION);
        // add some data to build constraint frames
        btVector3 axisA(0.f, 1.f, 0.f);
        btVector3 axisB(0.f, 1.f, 0.f);
        btVector3 pivotA(-5.f, 0.f, 0.f);
        btVector3 pivotB( 5.f, 0.f, 0.f);
        spHingeDynAB = new btHingeConstraint(*pBodyA, *pBodyB, pivotA, pivotB, axisA, axisB);
        spHingeDynAB->setLimit(-SIMD_HALF_PI * 0.5f, SIMD_HALF_PI * 0.5f);
        // add constraint to world
        m_dynamicsWorld->addConstraint(spHingeDynAB, true);
        // draw constraint frames and limits for debugging
        spHingeDynAB->setDbgDrawSize(btScalar(5.f));
    }
#endif

#if ENABLE_ALL_DEMOS
    {   // 6DOF connected to the world, with motor
        btTransform tr;
        tr.setIdentity();
        tr.setOrigin(btVector3(btScalar(10.), btScalar(-15.), btScalar(0.)));
        btRigidBody* pBody = localCreateRigidBody( 1.0, tr, shape);
        pBody->setActivationState(DISABLE_DEACTIVATION);
        btTransform frameB;
        frameB.setIdentity();
        btGeneric6DofConstraint* pGen6Dof = new btGeneric6DofConstraint( *pBody, frameB, false );
        m_dynamicsWorld->addConstraint(pGen6Dof);
        pGen6Dof->setDbgDrawSize(btScalar(5.f));

        pGen6Dof->setAngularLowerLimit(btVector3(0,0,0));
        pGen6Dof->setAngularUpperLimit(btVector3(0,0,0));
        pGen6Dof->setLinearLowerLimit(btVector3(-10., 0, 0));
        pGen6Dof->setLinearUpperLimit(btVector3(10., 0, 0));

        pGen6Dof->getTranslationalLimitMotor()->m_enableMotor[0] = true;
        pGen6Dof->getTranslationalLimitMotor()->m_targetVelocity[0] = 5.0f;
        pGen6Dof->getTranslationalLimitMotor()->m_maxMotorForce[0] = 0.1f;
    }
#endif



}
Esempio n. 6
0
  void OCR::performOCR(PipelineData* pipeline_data)
  {
    const int SPACE_CHAR_CODE = 32;
    
    timespec startTime;
    getTimeMonotonic(&startTime);

    postProcessor.clear();

    // Don't waste time on OCR processing if it is impossible to get sufficient characters
    int total_char_spaces = 0;
    for (unsigned int i = 0; i < pipeline_data->charRegions.size(); i++)
      total_char_spaces += pipeline_data->charRegions[i].size();
    if (total_char_spaces < config->postProcessMinCharacters)
    {
      pipeline_data->disqualify_reason = "Insufficient character boxes detected.  No OCR performed.";
      pipeline_data->disqualified = true;
      return;
    }

    for (unsigned int i = 0; i < pipeline_data->thresholds.size(); i++)
    {
      // Make it black text on white background
      bitwise_not(pipeline_data->thresholds[i], pipeline_data->thresholds[i]);
      tesseract.SetImage((uchar*) pipeline_data->thresholds[i].data, 
                          pipeline_data->thresholds[i].size().width, pipeline_data->thresholds[i].size().height, 
                          pipeline_data->thresholds[i].channels(), pipeline_data->thresholds[i].step1());

      int absolute_charpos = 0;
      for (unsigned int line_idx = 0; line_idx < pipeline_data->charRegions.size(); line_idx++)
      {
        for (unsigned int j = 0; j < pipeline_data->charRegions[line_idx].size(); j++)
        {
          Rect expandedRegion = expandRect( pipeline_data->charRegions[line_idx][j], 2, 2, pipeline_data->thresholds[i].cols, pipeline_data->thresholds[i].rows) ;

          tesseract.SetRectangle(expandedRegion.x, expandedRegion.y, expandedRegion.width, expandedRegion.height);
          tesseract.Recognize(NULL);

          tesseract::ResultIterator* ri = tesseract.GetIterator();
          tesseract::PageIteratorLevel level = tesseract::RIL_SYMBOL;
          do
          {
            const char* symbol = ri->GetUTF8Text(level);
            float conf = ri->Confidence(level);

            bool dontcare;
            int fontindex = 0;
            int pointsize = 0;
            const char* fontName = ri->WordFontAttributes(&dontcare, &dontcare, &dontcare, &dontcare, &dontcare, &dontcare, &pointsize, &fontindex);

            // Ignore NULL pointers, spaces, and characters that are way too small to be valid
            if(symbol != 0 && symbol[0] != SPACE_CHAR_CODE && pointsize >= config->ocrMinFontSize)
            {
              postProcessor.addLetter(string(symbol), line_idx, absolute_charpos, conf);

              if (this->config->debugOcr)
                printf("charpos%d line%d: threshold %d:  symbol %s, conf: %f font: %s (index %d) size %dpx", absolute_charpos, line_idx, i, symbol, conf, fontName, fontindex, pointsize);

              bool indent = false;
              tesseract::ChoiceIterator ci(*ri);
              do
              {
                const char* choice = ci.GetUTF8Text();

                postProcessor.addLetter(string(choice), line_idx, absolute_charpos, ci.Confidence());

                if (this->config->debugOcr)
                {
                  if (indent) printf("\t\t ");
                  printf("\t- ");
                  printf("%s conf: %f\n", choice, ci.Confidence());
                }

                indent = true;
              }
              while(ci.Next());
              
            }

            if (this->config->debugOcr)
              printf("---------------------------------------------\n");

            delete[] symbol;
          }
          while((ri->Next(level)));

          delete ri;
          
          absolute_charpos++;
        }
      }
    }

    if (config->debugTiming)
    {
      timespec endTime;
      getTimeMonotonic(&endTime);
      cout << "OCR Time: " << diffclock(startTime, endTime) << "ms." << endl;
    }
  }