Beispiel #1
0
 result_type max BOOST_PREVENT_MACRO_SUBSTITUTION () const { return (base().max)(); }
Beispiel #2
0
 result_type operator()() { return base()(); }
Beispiel #3
0
void 
gather_interface_dies(root_die& root, 
	set<iterator_base>& out, type_set& dedup_types_out, 
	std::function<bool(const iterator_base&)> pred)
{
	/* We want to deduplicate the types that we output, as we go. 
	 * CARE: what about anonymous types? We might want to generate names for them 
	 * based on their offset, in which case deduplication isn't transparent. 
	 * For this reason we output dedup_types_out separately from the DIEs.
	 * However, everything in dedup_types_out is also in out (FIXME: is this a good idea?) */
	auto toplevel_seq = root.grandchildren();
	type_set& types = dedup_types_out;
	/* FIXME: it needn't be just grandchildren. */
	for (auto i_d = std::move(toplevel_seq.first); i_d != toplevel_seq.second; ++i_d)
	{
		if (pred(i_d.base().base()))
		{
			// looks like a goer -- add it to the objs
			out.insert(i_d.base().base());
			
			/* utility that will come in handy */
			auto add_all_types = [&types, &root](iterator_df<type_die> outer_t) {
				walk_type(outer_t, iterator_base::END, 
					[&types, &root](iterator_df<type_die> t, iterator_df<program_element_die> reason) -> bool {
						if (!t) return false; // void case
						auto memb = reason.as_a<member_die>();
						if (memb && memb->get_declaration() && *memb->get_declaration()
							&& memb->get_external() && *memb->get_external())
						{
							// static member vars don't get added nor recursed on
							return false;
						}
						// apart from that, insert all nonvoids....
						auto inserted = types.insert(t);
						if (!inserted.second)
						{
							// cerr << "Type was already present: " << *t 
							// 	<< " (or something equal to it: " << *inserted.first
							// 	<< ")" << endl;
							// cerr << "Attributes: " << t->copy_attrs(root) << endl;
							return false; // was already present
						}
						else
						{
							cerr << "Inserted new type: " << *t << endl;
							// cerr << "Attributes: " << t->copy_attrs(root) << endl;
							return true;
						}
					}
				);
			};
			
			/* Also output everything that this depends on. We have to case-split
			 * for now. */
			if (i_d.base().base().is_a<subprogram_die>())
			{
				// make sure we have all the relevant types in our set
				auto i_subp = i_d.base().base().as_a<subprogram_die>();
				if (i_subp->find_type()) add_all_types(i_subp->find_type());
				auto fps = i_subp->children().subseq_of<formal_parameter_die>();
				for (auto i_fp = std::move(fps.first); i_fp != fps.second; ++i_fp)
				{
					auto outer_t = i_fp->find_type();
					add_all_types(outer_t);
				}
			}
			else if (i_d.base().base().is_a<variable_die>())
			{
				add_all_types(i_d.base().base().as_a<variable_die>()->get_type());
			}
			else if (i_d.base().base().is_a<type_die>())
			{
				/* Just walk it. */
				add_all_types(i_d.base().base().as_a<type_die>());
			}
		} // end if pred
	} // end for
	
	/* Now we've gathered everything. Make sure everything in "types" is in 
	 * "out". */
	for (auto i_d = types.begin(); i_d != types.end(); ++i_d)
	{
		out.insert(*i_d);
	}
	
	/* Check that everything that's in "out", if it is a type, is also in 
	 * types. */
	for (auto i_d = out.begin(); i_d != out.end(); ++i_d)
	{
		if (i_d->is_a<type_die>() && !i_d->is_a<subprogram_die>())
		{
			if (types.find(i_d->as_a<type_die>()) == types.end())
			{
				cerr << "BUG: didn't find " << i_d->summary() << " in types list." << endl;
			}
		}
	}
}
int smp::collision_checker_costmap<typeparams,NUM_DIMENSIONS>
::check_collision_state (state_t *state_in) {


    double x_i, y_i, theta_i;

    x_i = (*state_in)[0];
    y_i = (*state_in)[1];
    theta_i = (*state_in)[2];


    tf::Pose source;

    tf::Quaternion q= tf::createQuaternionFromRPY(0,0,theta_i);

    tf::Matrix3x3 base(q);

    source.setOrigin(tf::Vector3(x_i,y_i,0));

    source.setBasis(base);

    /// Apply the proper transform
    tf::Pose result=transform_*source;

    double x_bot = result.getOrigin().x();
    double y_bot = result.getOrigin().y();
    double orient_bot = tf::getYaw( result.getRotation());

    // ROS_INFO("From (%f,%f,%f) to (%f,%f,%f) ", x_i, y_i, theta_i, x_bot, y_bot, orient_bot);

    std::vector<geometry_msgs::Point> footprint_spec;

    footprint_spec.clear();

    // Given a pose, build the oriented footprint of the robot.
    costmap_ros_->getOrientedFootprint(x_bot , y_bot , orient_bot, footprint_spec);

    // ROS_INFO("CollisionCheckerState Size of the footprint_spec %d", (int )footprint_spec.size());
    geometry_msgs::Point robot_point;

    robot_point.x = x_bot;
    robot_point.y = y_bot;
    robot_point.z = 0;


    double cost = world_model_->footprintCost(robot_point, footprint_spec, inscribed_radius_, circumscribed_radius_);



    if( cost < 0 || cost > LEVEL_OBSTACLE_ ){

                // ROS_ERROR("Collisions");
                return 0;
      }else{

          // ROS_INFO("Cost of collisions %f, point cost %f", cost, world_model_->pointCost(x_i, y_i));
      }



  return 1;
}
Beispiel #5
0
/*!
    Align and divide an interval

   \param maxNumSteps Max. number of steps
   \param x1 First limit of the interval (In/Out)
   \param x2 Second limit of the interval (In/Out)
   \param stepSize Step size (Out)

   \sa QwtScaleEngine::setAttribute()
*/
void QwtLogScaleEngine::autoScale( int maxNumSteps,
    double &x1, double &x2, double &stepSize ) const
{
    if ( x1 > x2 )
        qSwap( x1, x2 );

    const double logBase = base();

    QwtInterval interval( x1 / qPow( logBase, lowerMargin() ),
        x2 * qPow( logBase, upperMargin() ) );

    if ( interval.maxValue() / interval.minValue() < logBase )
    {
        // scale width is less than one step -> try to build a linear scale

        QwtLinearScaleEngine linearScaler;
        linearScaler.setAttributes( attributes() );
        linearScaler.setReference( reference() );
        linearScaler.setMargins( lowerMargin(), upperMargin() );

        linearScaler.autoScale( maxNumSteps, x1, x2, stepSize );

        QwtInterval linearInterval = QwtInterval( x1, x2 ).normalized();
        linearInterval = linearInterval.limited( LOG_MIN, LOG_MAX );

        if ( linearInterval.maxValue() / linearInterval.minValue() < logBase )
        {
            // the aligned scale is still less than one step
            if ( stepSize < 0.0 )
                stepSize = -qwtLog( logBase, qAbs( stepSize ) );
            else
                stepSize = qwtLog( logBase, stepSize );

            return;
        }
    }

    double logRef = 1.0;
    if ( reference() > LOG_MIN / 2 )
        logRef = qMin( reference(), LOG_MAX / 2 );

    if ( testAttribute( QwtScaleEngine::Symmetric ) )
    {
        const double delta = qMax( interval.maxValue() / logRef,
            logRef / interval.minValue() );
        interval.setInterval( logRef / delta, logRef * delta );
    }

    if ( testAttribute( QwtScaleEngine::IncludeReference ) )
        interval = interval.extend( logRef );

    interval = interval.limited( LOG_MIN, LOG_MAX );

    if ( interval.width() == 0.0 )
        interval = buildInterval( interval.minValue() );

    stepSize = divideInterval( qwtLogInterval( logBase, interval ).width(), 
        qMax( maxNumSteps, 1 ) );
    if ( stepSize < 1.0 )
        stepSize = 1.0;

    if ( !testAttribute( QwtScaleEngine::Floating ) )
        interval = align( interval, stepSize );

    x1 = interval.minValue();
    x2 = interval.maxValue();

    if ( testAttribute( QwtScaleEngine::Inverted ) )
    {
        qSwap( x1, x2 );
        stepSize = -stepSize;
    }
}
Beispiel #6
0
/*!
   \brief Calculate minor/medium ticks for major ticks

   \param majorTicks Major ticks
   \param maxMinorSteps Maximum number of minor steps
   \param stepSize Step size
   \param minorTicks Array to be filled with the calculated minor ticks
   \param mediumTicks Array to be filled with the calculated medium ticks
*/
void QwtLogScaleEngine::buildMinorTicks(
    const QList<double> &majorTicks,
    int maxMinorSteps, double stepSize,
    QList<double> &minorTicks,
    QList<double> &mediumTicks ) const
{
    const double logBase = base();

    if ( stepSize < 1.1 )          // major step width is one base
    {
        double minStep = divideInterval( stepSize, maxMinorSteps + 1 );
        if ( minStep == 0.0 )
            return;
        
        const int numSteps = qRound( stepSize / minStep ); 

        int mediumTickIndex = -1;
        if ( ( numSteps > 2 ) && ( numSteps % 2 == 0 ) )
            mediumTickIndex = numSteps / 2;

        for ( int i = 0; i < majorTicks.count() - 1; i++ )
        {
            const double v = majorTicks[i];
            const double s = logBase / numSteps;

            if ( s >= 1.0 )
            {
                for ( int j = 2; j < numSteps; j++ )
                {
                    minorTicks += v * j * s;
                }
            }
            else
            {
                for ( int j = 1; j < numSteps; j++ )
                {
                    const double tick = v + j * v * ( logBase - 1 ) / numSteps;
                    if ( j == mediumTickIndex )
                        mediumTicks += tick;
                    else
                        minorTicks += tick;
                }
            }
        }
    }
    else
    {
        double minStep = divideInterval( stepSize, maxMinorSteps );
        if ( minStep == 0.0 )
            return;

        if ( minStep < 1.0 )
            minStep = 1.0;

        // # subticks per interval
        int numTicks = qRound( stepSize / minStep ) - 1;

        // Do the minor steps fit into the interval?
        if ( qwtFuzzyCompare( ( numTicks +  1 ) * minStep,
            stepSize, stepSize ) > 0 )
        {
            numTicks = 0;
        }

        if ( numTicks < 1 )
            return; 

        int mediumTickIndex = -1;
        if ( ( numTicks > 2 ) && ( numTicks % 2 ) )
            mediumTickIndex = numTicks / 2;

        // substep factor = base^substeps
        const qreal minFactor = qMax( qPow( logBase, minStep ), qreal( logBase ) );

        for ( int i = 0; i < majorTicks.count(); i++ )
        {
            double tick = majorTicks[i];
            for ( int j = 0; j < numTicks; j++ )
            {
                tick *= minFactor;

                if ( j == mediumTickIndex )
                    mediumTicks += tick;
                else
                    minorTicks += tick;
            }
        }
    }
}
std::error_code OrcX86_64::emitIndirectStubsBlock(IndirectStubsInfo &StubsInfo,
                                                  unsigned MinStubs,
                                                  void *InitialPtrVal) {
  // Stub format is:
  //
  // .section __orc_stubs
  // stub1:
  //                 jmpq    *ptr1(%rip)
  //                 .byte   0xC4         ; <- Invalid opcode padding.
  //                 .byte   0xF1
  // stub2:
  //                 jmpq    *ptr2(%rip)
  //
  // ...
  //
  // .section __orc_ptrs
  // ptr1:
  //                 .quad 0x0
  // ptr2:
  //                 .quad 0x0
  //
  // ...

  const unsigned StubSize = IndirectStubsInfo::StubSize;

  // Emit at least MinStubs, rounded up to fill the pages allocated.
  unsigned PageSize = sys::Process::getPageSize();
  unsigned NumPages = ((MinStubs * StubSize) + (PageSize - 1)) / PageSize;
  unsigned NumStubs = (NumPages * PageSize) / StubSize;

  // Allocate memory for stubs and pointers in one call.
  std::error_code EC;
  auto StubsMem =
    sys::OwningMemoryBlock(
      sys::Memory::allocateMappedMemory(2 * NumPages * PageSize, nullptr,
                                        sys::Memory::MF_READ |
                                        sys::Memory::MF_WRITE,
                                        EC));

  if (EC)
    return EC;

  // Create separate MemoryBlocks representing the stubs and pointers.
  sys::MemoryBlock StubsBlock(StubsMem.base(), NumPages * PageSize);
  sys::MemoryBlock PtrsBlock(static_cast<char*>(StubsMem.base()) +
                               NumPages * PageSize,
                             NumPages * PageSize);

  // Populate the stubs page stubs and mark it executable.
  uint64_t *Stub = reinterpret_cast<uint64_t*>(StubsBlock.base());
  uint64_t PtrOffsetField =
    static_cast<uint64_t>(NumPages * PageSize - 6) << 16;
  for (unsigned I = 0; I < NumStubs; ++I)
    Stub[I] = 0xF1C40000000025ff | PtrOffsetField;

  if (auto EC = sys::Memory::protectMappedMemory(StubsBlock,
                                                 sys::Memory::MF_READ |
                                                 sys::Memory::MF_EXEC))
    return EC;

  // Initialize all pointers to point at FailureAddress.
  void **Ptr = reinterpret_cast<void**>(PtrsBlock.base());
  for (unsigned I = 0; I < NumStubs; ++I)
    Ptr[I] = InitialPtrVal;

  StubsInfo = IndirectStubsInfo(NumStubs, std::move(StubsMem));

  return std::error_code();
}
RBScene* ParseTreeModel::render(ProjectModel* project,
                                       DeviceState* device,
                                       SkinDocument* doc, const QString* file)
{
    scene->clear();

    /* Setting the background */
    scene->setBackgroundBrush(QBrush(QPixmap(":/render/scenebg.png")));

    /* Preparing settings */
    QMap<QString, QString> settings;
    if(project)
        settings = project->getSettings();

    /* Setting themebase if it can't be derived from the project */
    if(settings.value("themebase", "") == "" && file && QFile::exists(*file))
    {
        QDir base(*file);
        base.cdUp();
        settings.insert("themebase", base.canonicalPath());
    }

    /* Finding imagebase and determining remote/wps status */
    bool remote = false;
    bool wps = false;
    if(file)
    {
        QString skinFile = *file;
        QStringList decomp = skinFile.split("/");
        skinFile = decomp[decomp.count() - 1];
        skinFile.chop(skinFile.length() - skinFile.lastIndexOf("."));
        settings.insert("imagepath", settings.value("themebase","") + "/wps/" +
                        skinFile);

        decomp = file->split(".");
        QString extension = decomp.last();
        if(extension[0] == 'r')
            remote = true;
        if(extension.right(3).toLower() == "wps"
           || extension.right(3).toLower() == "fms")
            wps = true;
    }

    /* Rendering SBS, if necessary */
    RBScreen* screen = 0;
    if(wps && device->data("rendersbs").toBool())
    {
        QString sbsFile = settings.value(remote ? "rsbs" : "sbs", "");
        sbsFile.replace("/.rockbox" , settings.value("themebase",""));

        if(QFile::exists(sbsFile))
        {
            QFile sbs(sbsFile);
            sbs.open(QFile::ReadOnly | QFile::Text);

            if(sbsModel)
                sbsModel->deleteLater();
            sbsModel = new ParseTreeModel(QString(sbs.readAll()).toAscii());

            if(sbsModel->root != 0)
            {
                RBRenderInfo sbsInfo(sbsModel, project, doc, &settings, device,
                                     screen);

                screen = new RBScreen(sbsInfo, remote);
                scene->addItem(screen);

                sbsInfo = RBRenderInfo(sbsModel, project, doc, &settings,
                                       device, screen);
                sbsModel->root->render(sbsInfo);
                screen->endSbsRender();

                setChildrenUnselectable(screen);
            }
        }
    }

    RBRenderInfo info(this, project, doc, &settings, device, screen);

    /* Adding the screen */
    if(!screen)
    {
        screen = new RBScreen(info, remote);
        scene->addItem(screen);
    }

    scene->setScreenSize(screen->boundingRect());

    info = RBRenderInfo(this, project, doc,  &settings, device, screen);


    /* Rendering the tree */
    if(root)
        root->render(info);

    return scene;
}
void CBasicTreeSquareDrawer::DrawQuad (int x,int y)
{
	int treesX = td->treesX;
	CBasicTreeDrawer::TreeSquareStruct* tss=&td->trees[y*treesX+x];

	float3 dif;
	dif.x=camera->pos.x-(x*SQUARE_SIZE*TREE_SQUARE_SIZE + SQUARE_SIZE*TREE_SQUARE_SIZE/2);
	dif.y=0;
	dif.z=camera->pos.z-(y*SQUARE_SIZE*TREE_SQUARE_SIZE + SQUARE_SIZE*TREE_SQUARE_SIZE/2);
	float dist=dif.Length();
	dif/=dist;
	
	if(dist<SQUARE_SIZE*TREE_SQUARE_SIZE*treeDistance*2 && dist>SQUARE_SIZE*TREE_SQUARE_SIZE*(treeDistance)){//far trees
		tss->lastSeenFar=gs->frameNum;
		if(!tss->farDisplist || dif.dot(tss->viewVector)<0.97){
			va=GetVertexArray();
			va->Initialize();
			tss->viewVector=dif;
			if(!tss->farDisplist)
				tss->farDisplist=glGenLists(1);
			float3 up(0,1,0);
			float3 side=up.cross(dif);

			for(std::map<int,CBasicTreeDrawer::TreeStruct>::iterator ti=tss->trees.begin();ti!=tss->trees.end();++ti){
				CBasicTreeDrawer::TreeStruct* ts=&ti->second;
				if(ts->type<8){
					float3 base(ts->pos);
					float height=MAX_TREE_HEIGHT;
					float width=MAX_TREE_HEIGHT*0.3;

					SetArray(0,0,base+side*width);
					SetArray(0,0.25,base+side*width+float3(0,height,0));
					SetArray(0.5f,0.25,base-side*width+float3(0,height,0));
					SetArray(0.5f,0,base-side*width);
				} else {
					float3 base(ts->pos);
					float height=MAX_TREE_HEIGHT;
					float width=MAX_TREE_HEIGHT*0.3;

					SetArray(0,0.25,base+side*width);
					SetArray(0,0.5,base+side*width+float3(0,height,0));
					SetArray(0.25f,0.5,base-side*width+float3(0,height,0));
					SetArray(0.25f,0.25,base-side*width);
				}
			}
			glNewList(td->trees[y*treesX+x].farDisplist,GL_COMPILE);
			va->DrawArrayT(GL_QUADS);
			glEndList();
		}
		if(dist>SQUARE_SIZE*TREE_SQUARE_SIZE*(treeDistance*2-1)){
			float trans=(SQUARE_SIZE*TREE_SQUARE_SIZE*treeDistance*2-dist)/(SQUARE_SIZE*TREE_SQUARE_SIZE);
			glEnable(GL_BLEND);
			glColor4f(1,1,1,trans);
			glAlphaFunc(GL_GREATER,(SQUARE_SIZE*TREE_SQUARE_SIZE*treeDistance*2-dist)/(SQUARE_SIZE*TREE_SQUARE_SIZE*2));
		} else {
			glColor4f(1,1,1,1);			
			glDisable(GL_BLEND);
			glAlphaFunc(GL_GREATER,0.5f);
		}
		glCallList(tss->farDisplist);
	}
	
	if(dist<SQUARE_SIZE*TREE_SQUARE_SIZE*treeDistance){	//midle distance trees
		tss->lastSeen=gs->frameNum;
		if(!tss->displist){
			va=GetVertexArray();
			va->Initialize();
			tss->displist=glGenLists(1);

			for(std::map<int,CBasicTreeDrawer::TreeStruct>::iterator ti=tss->trees.begin();ti!=tss->trees.end();++ti){
				CBasicTreeDrawer::TreeStruct* ts=&ti->second;
				if(ts->type<8){
					float3 base(ts->pos);
					float height=MAX_TREE_HEIGHT;
					float width=MAX_TREE_HEIGHT*0.3;

					SetArray(0,0,base+float3(width,0,0));
					SetArray(0,0.25,base+float3(width,height,0));
					SetArray(0.5f,0.25,base+float3(-width,height,0));
					SetArray(0.5f,0,base+float3(-width,0,0));

					SetArray(0,0,base+float3(0,0,width));
					SetArray(0,0.25,base+float3(0,height,width));
					SetArray(0.5f,0.25,base+float3(0,height,-width));
					SetArray(0.5f,0,base+float3(0,0,-width));

					width*=1.2f;
					SetArray(0.5,0,base+float3(width,height*0.25,0));
					SetArray(0.5,0.25,base+float3(0,height*0.25,-width));
					SetArray(1,0.25,base+float3(-width,height*0.25,0));
					SetArray(1,0,base+float3(0,height*0.25,width));
				} else {
					float3 base(ts->pos);
					float height=MAX_TREE_HEIGHT;
					float width=MAX_TREE_HEIGHT*0.3;

					SetArray(0,0.25,base+float3(width,0,0));
					SetArray(0,0.5,base+float3(width,height,0));
					SetArray(0.25f,0.5,base+float3(-width,height,0));
					SetArray(0.25f,0.25,base+float3(-width,0,0));

					SetArray(0.25f,0.25,base+float3(0,0,width));
					SetArray(0.25f,0.5,base+float3(0,height,width));
					SetArray(0.5f,0.5,base+float3(0,height,-width));
					SetArray(0.5f,0.25,base+float3(0,0,-width));

					width*=1.2f;
					SetArray(0.5,0.25,base+float3(width,height*0.3,0));
					SetArray(0.5,0.5,base+float3(0,height*0.3,-width));
					SetArray(1,0.5,base+float3(-width,height*0.3,0));
					SetArray(1,0.25,base+float3(0,height*0.3,width));
				}
			}
			glNewList(tss->displist,GL_COMPILE);
			va->DrawArrayT(GL_QUADS);
			glEndList();
		}
		glColor4f(1,1,1,1);			
		glDisable(GL_BLEND);
		glAlphaFunc(GL_GREATER,0.5f);
		glCallList(tss->displist);
	}
}