Exemple #1
0
void SkinParser::convertPosition( string position, string xOffset,
                          string yOffset, string xMargin,
                          string yMargin, int width, int height,
                          int refWidth, int refHeight, int* p_x, int* p_y )
{
    int iPosition = getPosition( position );
    if( iPosition == POS_UNDEF )
        return;

    int i_xOffset = getDimension( xOffset, refWidth );
    int i_yOffset = getDimension( yOffset, refHeight );
    int i_xMargin = getDimension( xMargin, refWidth );
    int i_yMargin = getDimension( yMargin, refHeight );

   // compute *p_x
   if( iPosition & POS_LEFT )
       *p_x = i_xMargin;
   else if( iPosition & POS_RIGHT )
       *p_x = refWidth - width - i_xMargin;
   else
       *p_x = ( refWidth - width ) / 2;

   // compute *p_y
   if( iPosition & POS_TOP )
       *p_y = i_yMargin;
   else if( iPosition & POS_BOTTOM )
       *p_y = refHeight - height - i_yMargin;
   else
       *p_y = ( refHeight - height ) / 2;

    // add offset
    *p_x += i_xOffset;
    *p_y += i_yOffset;
}
void ompl::base::ProjectionEvaluator::checkCellSizes() const
{
    if (getDimension() <= 0)
        throw Exception("Dimension of projection needs to be larger than 0");
    if (cellSizes_.size() != getDimension())
        throw Exception("Number of dimensions in projection space does not match number of cell sizes");
}
Puzzle* getPuzzle(char* name) {
	FILE* fp = fopen(name, "r");
	if (fp == NULL)	errorout(ERROR_404, "Wrong directory or name for puzzle config.");
	Puzzle* puzzle = (Puzzle*) malloc(sizeof(Puzzle));
	if (puzzle == NULL) errorout(ERROR_MEM, "Could not create Puzzle.");
	
	if ((puzzle->length = (int*) malloc(AXES*sizeof(int))) == NULL)	errorout(ERROR_MEM, "Could not create lengths.");
	
	getDimension(puzzle, fp, ROW);	//get 1st line - L = number of rows
	getDimension(puzzle, fp, COL);	//get 2nd line - C = number of columns
	checkblankln(fp);				//3rd line - must be blank

	if ((puzzle->line = (Line**) malloc(AXES*sizeof(Line*))) == NULL)	errorout(ERROR_MEM, "Could not create lines.");	
	if ((puzzle->line[ROW] = (Line*) malloc(puzzle->length[COL]*sizeof(Line))) == NULL)	errorout(ERROR_MEM, "Could not create rows.");
	if ((puzzle->line[COL] = (Line*) malloc(puzzle->length[ROW]*sizeof(Line))) == NULL)	errorout(ERROR_MEM, "Could not create cols.");

	readBlockLenghtsRow(puzzle, fp);	//next L lines have row block lengths
	checkblankln(fp);				//get (3+L+1)th line - must be blank
	readBlockLenghtsCol(puzzle, fp);	//next C lines have col block lengths
	checkblankln(fp);				//get (3+L+1+C+1)th line - must be blank

	char buffer[BUFFERSIZE];
	if (fgets(buffer, sizeof(buffer), fp) != NULL) {	//file must end after previous blank line
		errorout(ERROR_BADFORMAT, "File did not end when expected.");
	}

	return puzzle;
}
Exemple #4
0
/// get a string representing all the values of this property
std::string OfxhProperty::getStringValue() const
{
    if(getDimension() == 1)
        return getStringValueAt(0);
    if(getDimension() == 0)
        return "";
    return boost::algorithm::join(getStringValues(), ", ");
}
Exemple #5
0
void ompl::base::MorseProjection::defaultCellSizes(void)
{
    cellSizes_.resize(getDimension());
    for (unsigned int i = 0; i < getDimension(); i++)
    {
        cellSizes_[i] = 1.0;
    }
}
Exemple #6
0
    Vect& Vect::operator-=(const Vect& p)
{
    assert (getDimension() == p.getDimension());

    for (int i=0; i<getDimension(); i++)
        setCoordinate(i, getCoordinate(i)-p.getCoordinate(i));

    return *this;
}
Exemple #7
0
Sample UniformSampler::getNextSample()
{
	Sample seed(getDimension());
	for(int i=0;i<getDimension();i++)seed[i]=0.0;
	Sample aux=getNextNormalizedSample(iteration, seed, 1.0);
	iteration++;
	for(int j=0;j<getDimension();j++)
		normalizedSample[j]=aux[j];
	return computeSample();
}
void itsProblem::setBoundsMaximaAll(double max)
{
    vector<double> v;
    v.reserve(getDimension());

    for(unsigned int i=0; i < getDimension(); i++ ) {
        v.push_back(max);
    }
    setBoundsMaxima(v);
}
void itsProblem::setBoundsMaxima(vector<double> maxima)
{
    if(maxima.size() != getDimension() ) {
        ostringstream msg;
        msg << "ErrorSize: number of bounds (" << maxima.size() 
            << ") does not correspond to dimension  (" << getDimension() << ")";
        throw Exception_Size_Match(msg.str(), EXCEPTION_INFOS );
    } else {
        this->boundsMaxima = maxima;
    }
}
 void OMPLRNStateSpace::OMPLToExoticaState(const ompl::base::State *state,
     Eigen::VectorXd &q) const
 {
   if (!state)
   {
     throw_pretty("Invalid state!");
   }
   if (q.rows() != (int) getDimension()) q.resize((int) getDimension());
   memcpy(q.data(),
       state->as<OMPLRNStateSpace::StateType>()->getRNSpace().values,
       sizeof(double) * q.rows());
 }
void RadioButton::render(Graphics* graphics) {
    int x = getLocation().x;
    int y = getLocation().y;

    int w = getDimension().w;
    int h = getDimension().h;

    paintBackground(graphics);

    paintButtonIcon(graphics, isSelected(), isStatePressed(), isStateHover(), x, y, min(w, h));
    label->setDimension(label->getDimension().x, h);
    label->render(graphics);
}
void itsProblem::setBoundsMinima(vector<double> minima)
{
    if(minima.size() != getDimension() ) {
        ostringstream msg;
        msg << "ErrorSize: number of bounds (" << minima.size() 
            << ") does not correspond to dimension  (" << getDimension() << ")";
        throw Exception_Size_Match(msg.str(), EXCEPTION_INFOS );
    } else {
        this->boundsMinima = minima;
    }
#ifdef DEBUG
clog << "itsProblem::setBoundsMinima() minima=" << print(getBoundsMinima()) << endl;
#endif
}
Exemple #13
0
//RECURSIVE METHOD - 2003 IEEE ICRA Lindermann
Sample UniformSampler::getNextNormalizedSample(int n, Sample base, double factor)
{
	int i;
	Sample sample=base;
	int index=n%L_n;
	int nextN=n/L_n;
	for(i=0;i<getDimension();i++)sample[i]=sample[i]+L[index][i]*factor;
	if(nextN==0) //return sample+Vector2D(factor/4,factor/4);
	{
		for(i=0;i<getDimension();i++)sample[i]=sample[i]+factor/4; //Shukarev Correction
		return sample;
	}
	else return getNextNormalizedSample(nextN,sample,factor/2.0);
}
void itsProblem::setBounds(vector<vector<double> > bounds)
{
    vector<double> mins, maxs;
    mins.reserve(getDimension());
    maxs.reserve(getDimension());

    for(unsigned int i=0; i < getDimension(); i++) {
        mins.push_back(bounds[i][0]);
        maxs.push_back(bounds[i][1]);
    }
    
    setBoundsMinima(mins);
    setBoundsMaxima(maxs);
}
void itsProblem::setBoundsMinimaAll(double min)
{
    // empty vector
    vector<double> v;
    v.reserve(getDimension());

    // fill with min
    for(unsigned int i=0; i < getDimension(); i++ ) {
        v.push_back(min);
    }

    // update
    setBoundsMinima(v);
}
 void OMPLRNStateSpace::ExoticaToOMPLState(const Eigen::VectorXd &q,
     ompl::base::State *state) const
 {
   if (!state)
   {
     throw_pretty("Invalid state!");
   }
   if (q.rows() != (int) getDimension())
   {
     throw_pretty(
         "State vector ("<<q.rows()<<") and internal state ("<<(int)getDimension()<<") dimension disagree");
   }
   memcpy(state->as<OMPLRNStateSpace::StateType>()->getRNSpace().values,
       q.data(), sizeof(double) * q.rows());
 }
const std::string IMDWorkspace::toString() const {
  std::ostringstream os;
  os << id() << "\n"
     << "Title: " + getTitle() << "\n";
  for (size_t i = 0; i < getNumDims(); i++) {
    const auto &dim = getDimension(i);
    os << "Dim " << i << ": (" << dim->getName() << ") " << dim->getMinimum()
       << " to " << dim->getMaximum() << " in " << dim->getNBins() << " bins";
    // Also show the dimension ID string, if different than name
    if (dim->getDimensionId() != dim->getName())
      os << ". Id=" << dim->getDimensionId();
    os << "\n";
  }
  if (hasOriginalWorkspace()) {
    os << "Binned from '" << getOriginalWorkspace()->getName();
  }
  os << "\n";
  if (this->getConvention() == "Crystallography")
    os << "Crystallography: kf-ki";
  else
    os << "Inelastic: ki-kf";
  os << "\n";

  return os.str();
}
    // Move the entries to a larger table.
    FTABLE* FTABLE::larger()
    {
        assert(isMutable());

        uint32_t oldN = mask+1;
        uint32_t newMask = (oldN << 1) - 1;
        FTABLE* ftab = new // placement constructor
            (new char[sizeof(FTABLE)+(newMask+1)*sizeof(entry_t*)])
            FTABLE(getDimension(), nbEntries, newMask, noPartition);
        base_resetSmall(ftab->table, (newMask+1)*(sizeof(void*)/sizeof(int)));

        ftab->all = all;
        for(uint32_t i = 0; i < oldN; ++i) if (table[i])
        {
            cindex_t j = table[i]->id & newMask;
            while(ftab->table[j])
            {
                j = (j + 1) & newMask;
            }
            ftab->table[j] = table[i];
        }

        all.nil();
        delete [] ((char*)this);
        return ftab;
    }
void
GeoMultiProperty::setGenericValue(const MaxTypeT &eval, const SizeT index )
{
    UInt16 dim = getDimension();
    bool norm = getNormalize();
    UInt32 stride = getStride() ? getStride() : getFormatSize() * dim;    
    UInt8 *data = editData() + stride * index;

#define setValNormCase(vectype)                                 \
{                                                               \
vectype ival;                                                   \
if(norm)                                                        \
{                                                               \
    GeoConvertNormalize::convertIn(ival, eval,               \
        TypeTraits<vectype::ValueType>::getMax(), 0);           \
}                                                               \
else                                                            \
{                                                               \
    GeoConvert::convertIn(ival, eval);                       \
}                                                               \
for (UInt16 i = 0; i < dim; ++i)                                \
    reinterpret_cast<vectype::ValueType*>(data)[i] =            \
        ival[i];                                                \
}

#define setValCase(vectype)                                     \
{                                                               \
vectype ival;                                                   \
GeoConvert::convertIn(ival, eval);                           \
for (UInt16 i = 0; i < dim; ++i)                                \
    reinterpret_cast<vectype::ValueType*>(data)[i] =            \
        ival[i];                                                \
}
    
    switch(getFormat())
    {
        case GL_BYTE:                   setValNormCase(Vec4b );
            break;
        case GL_UNSIGNED_BYTE:          setValNormCase(Vec4ub);
            break;
        case GL_SHORT:                  setValNormCase(Vec4s );
            break;
        case GL_UNSIGNED_SHORT:         setValNormCase(Vec4us);
            break;
/*    case GL_INT:                    setValNormCase(Vec4i );
      break;
    case GL_UNSIGNED_INT:           setValNormCase(Vec4ui);
      break;
 */    
        case GL_FLOAT:                  setValCase    (Vec4f );
            break;
#ifndef OSG_OGL_NO_DOUBLE
        case GL_DOUBLE:                 setValCase    (Vec4d );
            break;
#endif
    }

#undef setValNormCase
#undef setValCase
}
Exemple #20
0
/** \function pidtonid
 *  finds nids for pids 1 to CmiNumPes and stores them in an array
 *  correspondingly also creates an array for nids to pids
 */
void pidtonid(int numpes) {
  CmiLock(cray_lock);
  if (pid2nid != NULL) {
      CmiUnlock(cray_lock);
      return;          /* did once already */
  }

  getDimension(&maxNID,&maxX,&maxY,&maxZ);
  int numCores = CmiNumCores();
  
  pid2nid = (int *)malloc(sizeof(int) * numpes);

#if XT4_TOPOLOGY || XT5_TOPOLOGY || XE6_TOPOLOGY
  int i, nid, ret;
  CmiAssert(rca_coords == NULL);
  rca_coords = (rca_mesh_coord_t *)malloc(sizeof(rca_mesh_coord_t)*(maxNID+1));
  for (i=0; i<maxNID; i++) {
    rca_coords[i].mesh_x = rca_coords[i].mesh_y = rca_coords[i].mesh_z = -1;
  }
  for (i=0; i<numpes; i++) {
    PMI_Get_nid(CmiGetNodeGlobal(CmiNodeOf(i),CmiMyPartition()), &nid);
    pid2nid[i] = nid;
    CmiAssert(nid < maxNID);
    ret = rca_get_meshcoord(nid, &rca_coords[nid]);
    CmiAssert(ret != -1);
  }
#endif
  CmiUnlock(cray_lock);
}
Exemple #21
0
std::vector<std::string> OfxhProperty::getStringValues() const
{
    std::vector<std::string> res;
    for(unsigned int i = 0; i < getDimension(); ++i)
        res.push_back(getStringValueAt(i));
    return res;
}
Exemple #22
0
/*public*/
bool
Geometry::getCentroid(Coordinate& ret) const
{
	if ( isEmpty() ) { return false; }

	Coordinate c;

	int dim=getDimension();
	if(dim==0) {
		CentroidPoint cent; 
		cent.add(this);
		if ( ! cent.getCentroid(c) )
				return false;
	} else if (dim==1) {
		CentroidLine cent;
		cent.add(this);
		if ( ! cent.getCentroid(c) ) 
			return false;
	} else {
		CentroidArea cent;
		cent.add(this);
		if ( ! cent.getCentroid(c) )
			return false;
	}

	getPrecisionModel()->makePrecise(c);
	ret=c;

	return true;
}
	void SuperFunTime::draw(gcn::Graphics *graphics)
	{
		// Draw border?
		gcn::Color faceColor = getBaseColor();
		gcn::Color highlightColor, shadowColor;
		int alpha = getBaseColor().a;
		
		highlightColor = faceColor + 0x303030;
		highlightColor.a = alpha;
		shadowColor = faceColor - 0x303030;
		shadowColor.a = alpha;
		
		graphics->setColor(faceColor);
		graphics->fillRectangle(gcn::Rectangle(1, 1, getDimension().width-1, getHeight() - 1));
		
		graphics->setColor(shadowColor);
		graphics->drawLine(0, 0, getWidth() - 1, 0);
		graphics->drawLine(0, 1, 0, getHeight() - 1);
		
		graphics->setColor(highlightColor);
		graphics->drawLine(getWidth() - 1, 1, getWidth() - 1, getHeight() - 1);
		graphics->drawLine(1, getHeight() - 1, getWidth() - 1, getHeight() - 1);
		
		graphics->setFont(getFont());
		graphics->setColor(gcn::Color(0, 0, 0));
		
		// Draw me
		
		for ( runner_list::iterator iter = _images.begin(); iter != _images.end(); iter++ )
			graphics->drawImage((*iter)->image, (*iter)->x, (*iter)->y);
	}
void AlgMultiArranque::recuperarCentroides () {
	for (unsigned int i = 0; i < getClusters().size(); ++i) {
		for (int j = 0; j < getDimension(); ++j) {
			getClusters()[i]->getCaracteristicas()[j] = _centroidesFin[i][j];
		}
	}
}
void CGUITTFont::draw(const core::stringw& text, const core::rect<s32>& position, video::SColor color, bool hcenter, bool vcenter, const core::rect<s32>* clip)
{
	if (!Driver)
		return;

	// Clear the glyph pages of their render information.
	for (u32 i = 0; i < Glyph_Pages.size(); ++i)
	{
		Glyph_Pages[i]->render_positions.clear();
		Glyph_Pages[i]->render_source_rects.clear();
	}

	// Set up some variables.
	core::dimension2d<s32> textDimension;
	core::position2d<s32> offset = position.UpperLeftCorner;

	// Determine offset positions.
	if (hcenter || vcenter)
	{
		textDimension = getDimension(text.c_str());

		if (hcenter)
			offset.X = ((position.getWidth() - textDimension.Width) >> 1) + offset.X;

		if (vcenter)
			offset.Y = ((position.getHeight() - textDimension.Height) >> 1) + offset.Y;
	}
CubatureControlVolume<SpT,PT,WT>::
CubatureControlVolume(const shards::CellTopology cellTopology) {

    // define primary cell topology with given one
    primaryCellTopo_ = cellTopology;

    // subcell is defined either hex or quad according to dimension
    switch (primaryCellTopo_.getDimension()) {
    case 2:
        subcvCellTopo_ = shards::CellTopology(shards::getCellTopologyData<shards::Quadrilateral<4> >());
        break;
    case 3:
        subcvCellTopo_ = shards::CellTopology(shards::getCellTopologyData<shards::Hexahedron<8> >());
        break;
    }

    // computation order is always one;
    degree_ = 1;

    // create subcell cubature points and weights and cache them
    const ordinal_type subcvDegree = 2;
    auto subcvCubature = DefaultCubatureFactory::create<SpT,PT,WT>(subcvCellTopo_, subcvDegree);

    const auto numSubcvPoints = subcvCubature->getNumPoints();
    const auto subcvDim       = subcvCubature->getDimension();

    subcvCubaturePoints_  = Kokkos::DynRankView<PT,SpT>("CubatureControlVolume::subcvCubaturePoints_",
                            numSubcvPoints, subcvDim);
    subcvCubatureWeights_ = Kokkos::DynRankView<WT,SpT>("CubatureControlVolume::subcvCubatureWeights_",
                            numSubcvPoints);

    subcvCubature->getCubature(subcvCubaturePoints_,
                               subcvCubatureWeights_);
}
void ompl::base::RealVectorIdentityProjectionEvaluator::defaultCellSizes()
{
    bounds_ = space_->as<RealVectorStateSpace>()->getBounds();
    cellSizes_.resize(getDimension());
    for (unsigned int i = 0; i < cellSizes_.size(); ++i)
        cellSizes_[i] = (bounds_.high[i] - bounds_.low[i]) / magic::PROJECTION_DIMENSION_SPLITS;
}
Exemple #28
0
void 
Quilt::download( Backend &backend )
{
    if( getDimension() == 2 ) {
	REAL *ps  = cpts; 
	ps += qspec[0].offset;
	ps += qspec[1].offset;
	ps += qspec[0].index * qspec[0].order * qspec[0].stride;
	ps += qspec[1].index * qspec[1].order * qspec[1].stride;
	backend.surfpts( mapdesc->getType(), ps, 
		  qspec[0].stride,
		  qspec[1].stride,
		  qspec[0].order,
		  qspec[1].order,
		  qspec[0].breakpoints[qspec[0].index],
		  qspec[0].breakpoints[qspec[0].index+1],
		  qspec[1].breakpoints[qspec[1].index],
		  qspec[1].breakpoints[qspec[1].index+1] );
    } else {
	REAL *ps  = cpts; 
	ps += qspec[0].offset;
	ps += qspec[0].index * qspec[0].order * qspec[0].stride;
	backend.curvpts( mapdesc->getType(), ps, 
		      qspec[0].stride,
		      qspec[0].order,
		      qspec[0].breakpoints[qspec[0].index],
		      qspec[0].breakpoints[qspec[0].index+1] );
    }
}
void AlgMultiArranque::guardarCentroides (vector<Cluster*>& centr) {
	for (unsigned int i = 0; i < centr.size(); ++i) {
		for (int j = 0; j < getDimension(); ++j) {
			_centroidesFin[i][j] = centr[i]->getCaracteristicas()[j];
		}
	}
}
Exemple #30
0
void Window::checkIfIsOffScreen(bool partially, bool entirely)
{
    // Move the window onto screen if it has become off screen
    // For instance, because of resolution change...

    // First of all, don't deal when a window hasn't got
    // any size initialized yet...
    if (getWidth() == 0 && getHeight() == 0)
        return;

    // Made partially the default behaviour
    if (!partially && !entirely)
        partially = true;

  // Keep guichan window inside screen (supports resizing any side)

    gcn::Rectangle winDimension =  getDimension();

    if (winDimension.x < 0)
    {
        winDimension.width += winDimension.x;
        winDimension.x = 0;
    }
    if (winDimension.y < 0)
    {
        winDimension.height += winDimension.y;
        winDimension.y = 0;
    }

    // Look if the window is partially off-screen limits...
    if (partially)
    {
        if (winDimension.x + winDimension.width > graphics->getWidth())
        {
            winDimension.x = graphics->getWidth() - winDimension.width;
        }

        if (winDimension.y + winDimension.height > graphics->getHeight())
        {
            winDimension.y = graphics->getHeight() - winDimension.height;
        }
        setDimension(winDimension);
        return;
    }

    if (entirely)
    {
        if (winDimension.x > graphics->getWidth())
        {
            winDimension.x = graphics->getWidth() - winDimension.width;
        }

        if (winDimension.y > graphics->getHeight())
        {
            winDimension.y = graphics->getHeight() - winDimension.height;
        }
    }
    setDimension(winDimension);
}