Пример #1
0
QString ChordRest::durationUserName()
      {
      QString duration = tr("Duration");
      QString tupletType = "";
      if(tuplet()) {
              switch (tuplet()->ratio().numerator()) {
                  case 2:
                        tupletType += " " + tr("Duplet");
                        break;
                  case 3:
                        tupletType += " " + tr("Triplet");
                        break;
                  case 4:
                        tupletType += " " + tr("Quadruplet");
                        break;
                  case 5:
                        tupletType += " " + tr("Quintuplet");
                        break;
                  case 6:
                        tupletType += " " + tr("Sextuplet");
                        break;
                  case 7:
                        tupletType += " " + tr("Septuplet");
                        break;
                  case 8:
                        tupletType += " " + tr("Octuplet");
                        break;
                  case 9:
                        tupletType += " " + tr("Nonuplet");
                        break;
                  default:
                        tupletType += " " + tr("Custom Tuplet");
                  }
            }
      QString dotString = "";

      switch (dots()) {
            case 1:
                  dotString += " " + tr("Dotted");
                  break;
            case 2:
                  dotString += " " + tr("Double dotted");
                  break;
            case 3:
                  dotString += " " + tr("Triple dotted");
                  break;
            }
      return QString("%1:%2%3 %4").arg(duration).arg(tupletType).arg(dotString).arg(durationType().durationTypeUserName());
      }
Пример #2
0
int main(int argc, char **argv){
  if (argc != 2) err("USAGE: ./morsecodetranslater <output.s>");

  char *s = calloc(MAX_STRING_LENGTH, sizeof(char));

  printf("Please enter the text you want to put into morse code:");
  
  fgets(s, MAX_STRING_LENGTH, stdin);
  int *code = calloc(LONGEST_MORSECODE * MAX_STRING_LENGTH, sizeof(int));
  dots(s, code);

  createAssembly(argv[1], code, (int) strlen(s));

  //for (int i = 0; i < MAX_STRING_LENGTH; i++){
  //  printf("%i", code[i]);
  //}
}
Пример #3
0
void captcha(unsigned char im[70*200], unsigned char l[6]) {
	unsigned i;
	unsigned char swr[200];
	uint8_t s1,s2;

	int f=open("/dev/urandom",O_RDONLY);
	read(f,l,5); read(f,swr,200); read(f,dr,sizeof(dr)); read(f,&s1,1); read(f,&s2,1);
	close(f);

	memset(im,0xff,200*70); s1=s1&0x7f; s2=s2&0x3f;
	int p=30;
	for (i = 0; i < 5; i++) {
		l[i] = l[i] % NUM_GLYPHS;
		p=letter(l[i],p,im,swr,s1,s2);
		l[i] = letters[l[i]];
	}
	line(im,swr,s1); dots(im); blur(im);
	l[5] = 0;
}
Пример #4
0
int main(int argc, char **argv)
{
  Aria::init();
  ArServerBase server;
  ArGlobalFunctor2<ArServerClient *, ArNetPacket *> sendEmptyCB(&sendEmpty);
  if (!server.open(7272))
  {
    printf("Could not open server port\n");
    exit(1);
  }

  ArServerInfoDrawings drawing(&server);

  ArDrawingData arrows("polyarrow", ArColor(0, 0, 255), 5, 50);
  ArDrawingData dots("polydots", ArColor(0, 255, 0), 12, 50);
  drawing.addDrawing(&arrows, "arrows", &sendEmptyCB);
  drawing.addDrawing(&dots, "dots", &sendEmptyCB);
  server.run();

}
Пример #5
0
// Return most qualified name for the current host
static const char *_fullhostname(const char *most_qualified_host)
{
    // Try local name
    if (most_qualified_host == 0)
	most_qualified_host = hostname();

#if HAVE_GETHOSTBYNAME
    struct hostent *h = gethostbyname(most_qualified_host);
    if (h)
    {
	// Try official name
	if (dots(h->h_name) > dots(most_qualified_host))
	    most_qualified_host = (char *)h->h_name;

	// Try aliases
	for (int i = 0; h->h_aliases[i] != 0; i++)
	    if (dots(h->h_aliases[i]) > dots(most_qualified_host))
		most_qualified_host = h->h_aliases[i];

	if (dots(most_qualified_host) == 0)
	{
	    // Unqualified host - try network addresses
	    if (h->h_addrtype == AF_INET)
	    {
		for (int j = 0; h->h_addr_list[j] != 0; j++)
		{
		    static char num_host[128];
		    num_host[0] = '\0';
		    for (int i = 0; i < (int)h->h_length; i++)
			sprintf(num_host + strlen(num_host), i ? ".%d" : "%d",
				int((unsigned char)(h->h_addr_list[j][i])));

		    if (dots(num_host) > dots(most_qualified_host))
			most_qualified_host = num_host;
		}
	    }
	}
    }
#endif

    // Return most qualified host name
    return most_qualified_host;
}
Пример #6
0
void captcha_render(unsigned char im[70*200], const unsigned char lts[6])
{
	unsigned i;
	unsigned char swr[200];
	uint8_t s1,s2;

	int f=open("/dev/urandom",O_RDONLY);
	read(f,swr,200); read(f,dr,sizeof(dr)); read(f,&s1,1); read(f,&s2,1);
	close(f);

	memset(im,0xff,200*70); s1=s1&0x7f; s2=s2&0x3f;
	int p=30;
	for (i = 0; i < 5; i++) {
		unsigned l;
		for (l = 0; l < sizeof(letters) / sizeof(*letters) - 1; l++)
			if (letters[l] == lts[i])
				break;
		if (l == sizeof(letters) / sizeof(*letters) - 1)
			l = 0;
		p = letter(l,p,im,swr,s1,s2);
	}
	line(im,swr,s1); dots(im); blur(im);
}
Пример #7
0
btVector3 btConvexShape::localGetSupportVertexWithoutMarginNonVirtual (const btVector3& localDir) const
{
	switch (m_shapeType)
	{
    case SPHERE_SHAPE_PROXYTYPE:
	{
		return btVector3(0,0,0);
    }
	case BOX_SHAPE_PROXYTYPE:
	{
		btBoxShape* convexShape = (btBoxShape*)this;
		const btVector3& halfExtents = convexShape->getImplicitShapeDimensions();

		return btVector3(btFsels(localDir.x(), halfExtents.x(), -halfExtents.x()),
			btFsels(localDir.y(), halfExtents.y(), -halfExtents.y()),
			btFsels(localDir.z(), halfExtents.z(), -halfExtents.z()));
	}
	case TRIANGLE_SHAPE_PROXYTYPE:
	{
		btTriangleShape* triangleShape = (btTriangleShape*)this;
		btVector3 dir(localDir.getX(),localDir.getY(),localDir.getZ());
		btVector3* vertices = &triangleShape->m_vertices1[0];
		btVector3 dots(dir.dot(vertices[0]), dir.dot(vertices[1]), dir.dot(vertices[2]));
		btVector3 sup = vertices[dots.maxAxis()];
		return btVector3(sup.getX(),sup.getY(),sup.getZ());
	}
	case CYLINDER_SHAPE_PROXYTYPE:
	{
		btCylinderShape* cylShape = (btCylinderShape*)this;
		//mapping of halfextents/dimension onto radius/height depends on how cylinder local orientation is (upAxis)

		btVector3 halfExtents = cylShape->getImplicitShapeDimensions();
		btVector3 v(localDir.getX(),localDir.getY(),localDir.getZ());
		int cylinderUpAxis = cylShape->getUpAxis();
		int XX(1),YY(0),ZZ(2);

		switch (cylinderUpAxis)
		{
		case 0:
		{
			XX = 1;
			YY = 0;
			ZZ = 2;
		}
		break;
		case 1:
		{
			XX = 0;
			YY = 1;
			ZZ = 2;	
		}
		break;
		case 2:
		{
			XX = 0;
			YY = 2;
			ZZ = 1;
			
		}
		break;
		default:
			btAssert(0);
		break;
		};

		btScalar radius = halfExtents[XX];
		btScalar halfHeight = halfExtents[cylinderUpAxis];

		btVector3 tmp;
		btScalar d ;

		btScalar s = btSqrt(v[XX] * v[XX] + v[ZZ] * v[ZZ]);
		if (s != btScalar(0.0))
		{
			d = radius / s;  
			tmp[XX] = v[XX] * d;
			tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
			tmp[ZZ] = v[ZZ] * d;
			return btVector3(tmp.getX(),tmp.getY(),tmp.getZ());
		} else {
			tmp[XX] = radius;
			tmp[YY] = v[YY] < 0.0 ? -halfHeight : halfHeight;
			tmp[ZZ] = btScalar(0.0);
			return btVector3(tmp.getX(),tmp.getY(),tmp.getZ());
		}
	}
	case CAPSULE_SHAPE_PROXYTYPE:
	{
		btVector3 vec0(localDir.getX(),localDir.getY(),localDir.getZ());

		btCapsuleShape* capsuleShape = (btCapsuleShape*)this;
		btScalar halfHeight = capsuleShape->getHalfHeight();
		int capsuleUpAxis = capsuleShape->getUpAxis();

		btScalar radius = capsuleShape->getRadius();
		btVector3 supVec(0,0,0);

		btScalar maxDot(btScalar(-BT_LARGE_FLOAT));

		btVector3 vec = vec0;
		btScalar lenSqr = vec.length2();
		if (lenSqr < btScalar(0.0001))
		{
			vec.setValue(1,0,0);
		} else
		{
			btScalar rlen = btScalar(1.) / btSqrt(lenSqr );
			vec *= rlen;
		}
		btVector3 vtx;
		btScalar newDot;
		{
			btVector3 pos(0,0,0);
			pos[capsuleUpAxis] = halfHeight;

			//vtx = pos +vec*(radius);
			vtx = pos +vec*capsuleShape->getLocalScalingNV()*(radius) - vec * capsuleShape->getMarginNV();
			newDot = vec.dot(vtx);
			

			if (newDot > maxDot)
			{
				maxDot = newDot;
				supVec = vtx;
			}
		}
		{
			btVector3 pos(0,0,0);
			pos[capsuleUpAxis] = -halfHeight;

			//vtx = pos +vec*(radius);
			vtx = pos +vec*capsuleShape->getLocalScalingNV()*(radius) - vec * capsuleShape->getMarginNV();
			newDot = vec.dot(vtx);
			if (newDot > maxDot)
			{
				maxDot = newDot;
				supVec = vtx;
			}
		}
		return btVector3(supVec.getX(),supVec.getY(),supVec.getZ());	
	}
	case CONVEX_POINT_CLOUD_SHAPE_PROXYTYPE:
	{
		btConvexPointCloudShape* convexPointCloudShape = (btConvexPointCloudShape*)this;
		btVector3* points = convexPointCloudShape->getUnscaledPoints ();
		int numPoints = convexPointCloudShape->getNumPoints ();
		return convexHullSupport (localDir, points, numPoints,convexPointCloudShape->getLocalScalingNV());
	}
	case CONVEX_HULL_SHAPE_PROXYTYPE:
	{
		btConvexHullShape* convexHullShape = (btConvexHullShape*)this;
		btVector3* points = convexHullShape->getUnscaledPoints();
		int numPoints = convexHullShape->getNumPoints ();
		return convexHullSupport (localDir, points, numPoints,convexHullShape->getLocalScalingNV());
	}
    default:
#ifndef __SPU__
		return this->localGetSupportingVertexWithoutMargin (localDir);
#else
		btAssert (0);
#endif
	}

	// should never reach here
	btAssert (0);
	return btVector3 (btScalar(0.0f), btScalar(0.0f), btScalar(0.0f));
}
Пример #8
0
/**
 * Initializes all the elements in the Saved Game screen.
 * @param game Pointer to the core game.
 */
ListLoadOriginalState::ListLoadOriginalState()
{
	_screen = false;

	// Create objects
	_window = new Window(this, 320, 200, 0, 0);
	_btnNew = new TextButton(80, 16, 60, 172);
	_btnCancel = new TextButton(80, 16, 180, 172);
	_txtTitle = new Text(310, 17, 5, 7);
	_txtName = new Text(160, 9, 36, 24);
	_txtTime = new Text(30, 9, 195, 24);
	_txtDate = new Text(90, 9, 225, 24);

	// Set palette
	setInterface("saveMenus");

	add(_window, "window", "saveMenus");
	add(_btnNew, "button", "saveMenus");
	add(_btnCancel, "button", "saveMenus");
	add(_txtTitle, "text", "saveMenus");
	add(_txtName, "text", "saveMenus");
	add(_txtTime, "text", "saveMenus");
	add(_txtDate, "text", "saveMenus");

	int y = 34;
	for (int i = 0; i < SaveConverter::NUM_SAVES; ++i)
	{
		_btnSlot[i] = new TextButton(24, 12, 10, y-2);
		_txtSlotName[i] = new Text(160, 9, 36, y);
		_txtSlotTime[i] = new Text(30, 9, 195, y);
		_txtSlotDate[i] = new Text(90, 9, 225, y);

		add(_btnSlot[i], "button", "saveMenus");
		add(_txtSlotName[i], "list", "saveMenus");
		add(_txtSlotTime[i], "list", "saveMenus");
		add(_txtSlotDate[i], "list", "saveMenus");

		y += 14;
	}

	centerAllSurfaces();

	// Set up objects
	_window->setBackground(_game->getMod()->getSurface("BACK01.SCR"));

	_btnNew->setText(tr("STR_OPENXCOM"));
	_btnNew->onMouseClick((ActionHandler)&ListLoadOriginalState::btnNewClick);
	_btnNew->onKeyboardPress((ActionHandler)&ListLoadOriginalState::btnNewClick, Options::keyCancel);

	_btnCancel->setText(tr("STR_CANCEL_UC"));
	_btnCancel->onMouseClick((ActionHandler)&ListLoadOriginalState::btnCancelClick);
	_btnCancel->onKeyboardPress((ActionHandler)&ListLoadOriginalState::btnCancelClick, Options::keyCancel);

	_txtTitle->setBig();
	_txtTitle->setAlign(ALIGN_CENTER);
	_txtTitle->setText(tr("STR_SELECT_GAME_TO_LOAD"));

	_txtName->setText(tr("STR_NAME"));

	_txtTime->setText(tr("STR_TIME"));

	_txtDate->setText(tr("STR_DATE"));

	std::wstring dots(80, '.');
	SaveConverter::getList(_game->getLanguage(), _saves);
	for (int i = 0; i < SaveConverter::NUM_SAVES; ++i)
	{
		std::wostringstream ss;
		ss << (i + 1);
		_btnSlot[i]->setText(ss.str());
		_btnSlot[i]->onMouseClick((ActionHandler)&ListLoadOriginalState::btnSlotClick);

		_txtSlotName[i]->setText(_saves[i].name + dots);
		_txtSlotTime[i]->setText(_saves[i].time);
		_txtSlotDate[i]->setText(_saves[i].date);
	}
}
Пример #9
0
void Rest::layout()
      {
      int lines = staff()->lines();

      switch(durationType().type()) {
            case Duration::V_64TH:
            case Duration::V_32ND:
                  dotline = -3;
                  break;
            case Duration::V_256TH:
            case Duration::V_128TH:
                  dotline = -5;
                  break;
            default:
                  dotline = -1;
                  break;
            }
      qreal _spatium = spatium();
      int line        = lrint(userOff().y() / _spatium); //  + ((staff()->lines()-1) * 2);
      int lineOffset  = 0;

      if (measure()->mstaff(staffIdx())->hasVoices) {
            // move rests in a multi voice context
            bool up = (voice() == 0) || (voice() == 2);       // TODO: use style values
            switch(durationType().type()) {
                  case Duration::V_LONG:
                        lineOffset = up ? -3 : 5;
                        break;
                  case Duration::V_BREVE:
                        lineOffset = up ? -3 : 5;
                        break;
                  case Duration::V_MEASURE:
                  case Duration::V_WHOLE:
                        lineOffset = up ? -4 : 6;
                        break;
                  case Duration::V_HALF:
                        lineOffset = up ? -4 : 4;
                        break;
                  case Duration::V_QUARTER:
                        lineOffset = up ? -4 : 4;
                        break;
                  case Duration::V_EIGHT:
                        lineOffset = up ? -4 : 4;
                        break;
                  case Duration::V_16TH:
                        lineOffset = up ? -6 : 4;
                        break;
                  case Duration::V_32ND:
                        lineOffset = up ? -6 : 6;
                        break;
                  case Duration::V_64TH:
                        lineOffset = up ? -8 : 6;
                        break;
                  case Duration::V_128TH:
                        lineOffset = up ? -8 : 8;
                        break;
                  case Duration::V_256TH:             // not available
                        lineOffset = up ? -10 : 6;
                        break;
                  default:
                        break;
                  }
            }
      else {
            switch(durationType().type()) {
                  case Duration::V_LONG:
                  case Duration::V_BREVE:
                  case Duration::V_MEASURE:
                  case Duration::V_WHOLE:
                        if (lines == 1)
                              lineOffset = -2;
                        break;
                  case Duration::V_HALF:
                  case Duration::V_QUARTER:
                  case Duration::V_EIGHT:
                  case Duration::V_16TH:
                  case Duration::V_32ND:
                  case Duration::V_64TH:
                  case Duration::V_128TH:
                  case Duration::V_256TH:             // not available
                        if (lines == 1)
                              lineOffset = -4;
                        break;
                  default:
                        break;
                  }
            }

      int yo;
      _sym = getSymbol(durationType().type(), line + lineOffset/2, lines, &yo);
      setYoff(qreal(yo) + qreal(lineOffset) * .5);
      layoutArticulations();
      setPos(0.0, yoff() * _spatium);

      Spatium rs;
      if (dots()) {
            rs = Spatium(score()->styleS(ST_dotNoteDistance)
               + dots() * score()->styleS(ST_dotDotDistance));
            }
      Segment* s = segment();
      if (s && s->measure() && s->measure()->multiMeasure()) {
            qreal _spatium = spatium();
            qreal h = _spatium * 6.5;
            qreal w = point(score()->styleS(ST_minMMRestWidth));
            setbbox(QRectF(-w * .5, -h + 2 * _spatium, w, h));
            }
      else {
            if (dots()) {
                  rs = Spatium(score()->styleS(ST_dotNoteDistance)
                     + dots() * score()->styleS(ST_dotDotDistance));
                  }
            setbbox(symbols[score()->symIdx()][_sym].bbox(magS()));
            }
      _space.setLw(point(_extraLeadingSpace));
      _space.setRw(width() + point(_extraTrailingSpace + rs));
//      adjustReadPos();
      }
Пример #10
0
void
p_original_dotty(
		FILE	*stream, char *buffer,
		char	*split_pea, int pea_margin,
		int	haricot)
{
	int	line_pos = 0;
	int	split_pea_size = 0;
	char  *pea;

	split_pea_size = strlen(split_pea);
	
	switch (haricot)
	{
		case	DOT_MODE_QUOTE:
			fputc('\"',stream);
			line_pos++;
			break;
		default:
			break;
	}

	for( pea = buffer; *pea; )
	{
		if ( *pea == '\n' )
		{	/* split required HERE */
			switch (haricot)
			{
				case	DOT_MODE_DOTS:
				{
					if ( line_pos < LINE_LENGTH )
						dots(stream, LINE_LENGTH-line_pos);
					else
						newline(stream);
					newline(stream);
					dots(stream, LINE_LENGTH);
					newline(stream);
					line_pos=0;
					break;
				}
				case	DOT_MODE_QUOTE:
				{
					fputc('\"', stream);
					newline(stream);
					fputc('\"', stream);
					line_pos=1;
					break;
				}
				default:
					newline(stream);
					line_pos=0;
					break;
			}
			pea++;
      /* check for MAGIC_PEA, and put newlines in if we would truncate */
			if ((*pea == MAGIC_PEA) && (line % PAGE_LENGTH)>=PAGE_TRUNCATE )
      		{
				pea++;  /* skip magic pea */
				while (line % PAGE_LENGTH)
					newline(stream);
			}
		}
		else if (split_pea && !strncmp(pea, split_pea, split_pea_size) )
		{	/* split required HERE */
			int i;

			/* put bit of split string header */
			for( i=pea_margin; i; i-- )
			{
				fputc(*pea++,stream);
				line_pos++;
			}

/* and SKIP the separator */
			pea++;

			switch (haricot)
			{
				case	DOT_MODE_DOTS:
				{
					if ( line_pos < LINE_LENGTH )
						dots(stream, LINE_LENGTH-line_pos);
					else
						newline(stream);
					newline(stream);
					dots(stream, LINE_LENGTH);
					newline(stream);
					line_pos=0;
					break;
				}
				case	DOT_MODE_QUOTE:
				{
					fputc('\"', stream);
					newline(stream);
					fputc('\"', stream);
					line_pos=1;
					break;
				}
				default:
					newline(stream);
					line_pos=0;
					break;
			}
		}
		else
		if (*pea == MAGIC_PEA)
		{
			pea++;
		} else
		{
			fputc(*pea++,stream);
			line_pos++;
		}
	}
}
Пример #11
0
void Rest::layout()
      {
      _space.setLw(0.0);

      if (parent() && measure() && measure()->multiMeasure()) {
            _space.setRw(point(score()->styleS(ST_minMMRestWidth)));
            return;
            }

      rxpos() = 0.0;
      if (staff() && staff()->isTabStaff()) {
            StaffTypeTablature* tab = (StaffTypeTablature*)staff()->staffType();
            // if rests are shown and note values are shown as duration symbols
            if(tab->showRests() &&tab->genDurations()) {
                  // symbol needed; if not exist, create, if exists, update duration
                  if (!_tabDur)
                        _tabDur = new TabDurationSymbol(score(), tab, durationType().type(), dots());
                  else
                        _tabDur->setDuration(durationType().type(), dots(), tab);
                  _tabDur->setParent(this);
// needed?        _tabDur->setTrack(track());
                  _tabDur->layout();
                  setbbox(_tabDur->bbox());
                  setPos(0.0, 0.0);             // no rest is drawn: reset any position might be set for it
                  _space.setLw(0.0);
                  _space.setRw(width());
                  return;
                  }
            // if no rests or no duration symbols, delete any dur. symbol and chain into standard staff mngmt
            // this is to ensure horiz space is reserved for rest, even if they are not diplayed
            // Rest::draw() will skip their drawing, if not needed
            if(_tabDur) {
                  delete _tabDur;
                  _tabDur = 0;
                  }
            }

      switch(durationType().type()) {
            case TDuration::V_64TH:
            case TDuration::V_32ND:
                  dotline = -3;
                  break;
            case TDuration::V_256TH:
            case TDuration::V_128TH:
                  dotline = -5;
                  break;
            default:
                  dotline = -1;
                  break;
            }
      qreal _spatium = spatium();
      int stepOffset = 0;
      if (staff())
            stepOffset = staff()->staffType()->stepOffset();
      int line       = lrint(userOff().y() / _spatium); //  + ((staff()->lines()-1) * 2);
      qreal lineDist = staff() ? staff()->staffType()->lineDistance().val() : 1.0;
      int lineOffset = 0;

      int lines = staff() ? staff()->lines() : 5;
      if (segment() && measure() && measure()->mstaff(staffIdx())->hasVoices) {
            // move rests in a multi voice context
            bool up = (voice() == 0) || (voice() == 2);       // TODO: use style values
            switch(durationType().type()) {
                  case TDuration::V_LONG:
                        lineOffset = up ? -3 : 5;
                        break;
                  case TDuration::V_BREVE:
                        lineOffset = up ? -3 : 5;
                        break;
                  case TDuration::V_MEASURE:
                        if (duration() >= Fraction(2, 1))    // breve symbol
                              lineOffset = up ? -3 : 5;
                        // fall through
                  case TDuration::V_WHOLE:
                        lineOffset = up ? -4 : 6;
                        break;
                  case TDuration::V_HALF:
                        lineOffset = up ? -4 : 4;
                        break;
                  case TDuration::V_QUARTER:
                        lineOffset = up ? -4 : 4;
                        break;
                  case TDuration::V_EIGHT:
                        lineOffset = up ? -4 : 4;
                        break;
                  case TDuration::V_16TH:
                        lineOffset = up ? -6 : 4;
                        break;
                  case TDuration::V_32ND:
                        lineOffset = up ? -6 : 6;
                        break;
                  case TDuration::V_64TH:
                        lineOffset = up ? -8 : 6;
                        break;
                  case TDuration::V_128TH:
                        lineOffset = up ? -8 : 8;
                        break;
                  case TDuration::V_256TH:             // not available
                        lineOffset = up ? -10 : 6;
                        break;
                  default:
                        break;
                  }
            }
      else {
            switch(durationType().type()) {
                  case TDuration::V_LONG:
                  case TDuration::V_BREVE:
                  case TDuration::V_MEASURE:
                  case TDuration::V_WHOLE:
                        if (lines == 1)
                              lineOffset = -2;
                        break;
                  case TDuration::V_HALF:
                  case TDuration::V_QUARTER:
                  case TDuration::V_EIGHT:
                  case TDuration::V_16TH:
                  case TDuration::V_32ND:
                  case TDuration::V_64TH:
                  case TDuration::V_128TH:
                  case TDuration::V_256TH:             // not available
                        if (lines == 1)
                              lineOffset = -4;
                        break;
                  default:
                        break;
                  }
            }

      int yo;
      _sym = getSymbol(durationType().type(), line + lineOffset/2, lines, &yo);
      layoutArticulations();
      rypos() = (qreal(yo) + qreal(lineOffset + stepOffset) * .5) * lineDist * _spatium;

      Spatium rs;
      if (dots()) {
            rs = Spatium(score()->styleS(ST_dotNoteDistance)
               + dots() * score()->styleS(ST_dotDotDistance));
            }
      if (dots()) {
            rs = Spatium(score()->styleS(ST_dotNoteDistance)
               + dots() * score()->styleS(ST_dotDotDistance));
            }
      setbbox(symbols[score()->symIdx()][_sym].bbox(magS()));
      _space.setRw(width() + point(rs));
      }
Пример #12
0
extern void aprstat_wxgraph(maptool_pIMAGE * img, aprsdecode_pOPHIST op,
                unsigned long stime, unsigned short * what,
                struct aprstat_LASTVAL * lastval)
{
   aprsdecode_pFRAMEHIST fr;
   unsigned long Maxx;
   unsigned long step;
   unsigned long xt;
   unsigned long xi;
   float XStep;
   float yax1;
   float yax0;
   float vh;
   struct WX min0;
   struct WX max0;
   char hh[256];
   char h[256];
   char s[256];
   struct aprsdecode_DAT dat;
   float temp[1440];
   float hyg[1440];
   float baro[1440];
   float winds[1440];
   float windd[1440];
   float gust[1440];
   float rain1[1440];
   float rain24[1440];
   float rain0[1440];
   float lumi[1440];
   unsigned short have;
   char dirvalid;
   struct WX * anonym;
   if (op==0 || op->frames==0) {
      /*OR (op^.lastinftyp<100)*/
      return;
   }
   Maxx = dynmaxx(8UL, 320UL, 720UL);
   XStep = X2C_DIVR((float)Maxx,1440.0f);
   *img = 0;
   for (xi = 0UL; xi<=1439UL; xi++) {
      temp[xi] = (-1.E+4f);
      hyg[xi] = (-1.E+4f);
      baro[xi] = (-1.E+4f);
      winds[xi] = (-1.E+4f);
      windd[xi] = (-1.E+4f);
      gust[xi] = (-1.E+4f);
      rain1[xi] = (-1.E+4f);
      rain24[xi] = (-1.E+4f);
      rain0[xi] = (-1.E+4f);
      lumi[xi] = (-1.E+4f);
   } /* end for */
   { /* with */
      struct WX * anonym = &max0;
      anonym->temp = (-1.E+4f);
      anonym->hyg = (-1.E+4f);
      anonym->baro = (-1.E+4f);
      anonym->wind = (-1.E+4f);
      anonym->rain = (-1.E+4f);
      anonym->lumi = (-1.E+4f);
      anonym->siev = (-1.E+4f);
   }
   dirvalid = 0;
   min0.temp = X2C_max_real;
   min0.baro = X2C_max_real;
   memset((char *)lastval,(char)0,sizeof(struct aprstat_LASTVAL));
   fr = op->frames;
   do {
      if (((fr->time0>stime-86400UL && fr->time0<=stime)
                && aprsdecode_Decode(fr->vardat->raw, 500ul,
                &dat)>=0L) && dat.sym=='_') {
         xt = aprsdecode_trunc((float)(fr->time0-(stime-86400UL))
                *1.6666666666667E-2f);
         if (xt>=1440UL) xt = 1439UL;
         vh = X2C_DIVR(dat.wx.temp-32.0f,1.8f);
         if (vh>=(-99.0f) && vh<=99.0f) {
            temp[xt] = vh;
            if (vh>max0.temp) max0.temp = vh;
            if (vh<min0.temp) min0.temp = vh;
            lastval->temp = vh;
         }
         if (dat.wx.hygro>=0.0f && dat.wx.hygro<=100.0f) {
            hyg[xt] = dat.wx.hygro;
            if (dat.wx.hygro>max0.hyg) max0.hyg = dat.wx.hygro;
            lastval->hyg = dat.wx.hygro;
         }
         vh = dat.wx.baro*0.1f;
         if (vh>=900.0f && vh<=1100.0f) {
            baro[xt] = vh;
            if (vh>max0.baro) max0.baro = vh;
            if (vh<min0.baro) min0.baro = vh;
            lastval->baro = vh;
         }
         vh = dat.wx.rain24*0.254f;
         if (vh>=0.0f && vh<300.0f) {
            rain24[xt] = vh;
            if (vh>max0.rain) max0.rain = vh;
            lastval->rain24 = vh;
         }
         vh = dat.wx.raintoday*0.254f;
         if (vh>=0.0f && vh<300.0f) {
            rain0[xt] = vh;
            if (vh>max0.rain) max0.rain = vh;
         }
         vh = dat.wx.rain1*0.254f;
         if (vh>=0.0f && vh<300.0f) {
            rain1[xt] = vh;
            if (vh>max0.rain) max0.rain = vh;
            lastval->rain = vh;
         }
         if (dat.wx.lum>=0.0f && dat.wx.lum<=2000.0f) {
            lumi[xt] = dat.wx.lum;
            if (dat.wx.lum>max0.lumi) max0.lumi = dat.wx.lum;
            lastval->lumi = dat.wx.lum;
         }
         if (dat.wx.sievert>=0.0f && dat.wx.sievert<1000.0f) {
            /*        siev[xt]:=dat.wx.sievert; */
            if (dat.wx.sievert>max0.siev) max0.siev = dat.wx.sievert;
            lastval->siev = dat.wx.sievert;
         }
         if (dat.course>0UL && dat.course<=360UL) {
            lastval->winddir = (float)(dat.course%360UL);
            windd[xt] = lastval->winddir;
            dirvalid = 1;
         }
         vh = (float)dat.speed*1.609f;
         if (vh>=0.0f && vh<=1000.0f) {
            winds[xt] = vh;
            lastval->winds = vh;
            if (vh>max0.wind) max0.wind = vh;
         }
         vh = dat.wx.gust*1.609f;
         if (vh>=0.0f && vh<=1000.0f) {
            gust[xt] = vh;
            lastval->gust = vh;
            if (vh>max0.wind) max0.wind = vh;
         }
      }
      fr = fr->next;
   } while (fr);
   aprstext_DateLocToStr(stime, h, 256ul);
   aprsstr_Append(h, 256ul, " ", 2ul);
   aprsstr_Append(h, 256ul, op->call, 9ul);
   have = 0U;
   if (max0.temp!=(-1.E+4f)) {
      have |= 0x1U;
      if ((0x1U & *what)) {
         if (!newimg(Maxx, img)) return;
         scale(temp, 1440ul, min0.temp, max0.temp, 120.0f, 10.0f, &yax0,
                &yax1, &step);
         aprsstr_FixToStr(lastval->temp, 2UL, s, 256ul);
         aprsstr_Append(s, 256ul, "\177C ", 4ul);
         aprsstr_Append(s, 256ul, h, 256ul);
         paper(img, yax0, yax1, step, 8UL, Maxx, 120UL, s, 256ul);
         timeline(stime, img, Maxx);
         dots(XStep, img, temp, 1440ul, 1, 200UL, 700UL, 40UL);
      }
   }
   if (max0.baro!=(-1.E+4f)) {
      have |= 0x2U;
      if ((0x2U & *what)) {
         if (!newimg(Maxx, img)) return;
         scale(baro, 1440ul, min0.baro, max0.baro, 120.0f, 2.0f, &yax0,
                &yax1, &step);
         aprsstr_FixToStr(lastval->baro, 2UL, s, 256ul);
         aprsstr_Append(s, 256ul, "hPa ", 5ul);
         aprsstr_Append(s, 256ul, h, 256ul);
         paper(img, yax0, yax1, step, 8UL, Maxx, 120UL, s, 256ul);
         timeline(stime, img, Maxx);
         dots(XStep, img, baro, 1440ul, 1, 500UL, 400UL, 500UL);
      }
   }
   if (max0.wind!=(-1.E+4f) && max0.wind>0.0f) {
      have |= 0x8U;
      if ((0x8U & *what)) {
         if (!newimg(Maxx, img)) return;
         scale(winds, 1440ul, (-1.E+4f), max0.wind, 120.0f, 20.0f, &yax0,
                &yax1, &step);
         scale(gust, 1440ul, (-1.E+4f), max0.wind, 120.0f, 20.0f, &yax0,
                &yax1, &step);
         s[0U] = 0;
         if (lastval->winds!=0.0f || lastval->gust==0.0f) {
            aprsstr_FixToStr(lastval->winds, 2UL, hh, 256ul);
            aprsstr_Append(hh, 256ul, "km/h Wind  ", 12ul);
            aprsstr_Append(s, 256ul, hh, 256ul);
         }
         if (lastval->gust!=0.0f) {
            aprsstr_FixToStr(lastval->gust, 2UL, hh, 256ul);
            aprsstr_Append(hh, 256ul, "km/h Gust  ", 12ul);
            aprsstr_Append(s, 256ul, hh, 256ul);
         }
         aprsstr_Append(s, 256ul, h, 256ul);
         paper(img, yax0, yax1, step, 8UL, Maxx, 120UL, s, 256ul);
         timeline(stime, img, Maxx);
         dots(XStep, img, winds, 1440ul, 1, 100UL, 500UL, 700UL);
         dots(XStep, img, gust, 1440ul, 1, 600UL, 100UL, 0UL);
      }
      if (dirvalid) {
         have |= 0x10U;
         if ((0x10U & *what)) {
            if (!newimg(Maxx, img)) return;
            scale(windd, 1440ul, (-1.E+4f), 360.0f, 120.0f, 365.0f, &yax0,
                &yax1, &step);
            aprsstr_FixToStr(lastval->winddir, 0UL, s, 256ul);
            aprsstr_Append(s, 256ul, "deg Wind Direction ", 20ul);
            aprsstr_Append(s, 256ul, h, 256ul);
            paper(img, yax0, yax1, 90UL, 8UL, Maxx, 120UL, s, 256ul);
            timeline(stime, img, Maxx);
            dots(XStep, img, windd, 1440ul, 0, 200UL, 700UL, 700UL);
         }
      }
   }
   if (max0.hyg!=(-1.E+4f)) {
      have |= 0x4U;
      if ((0x4U & *what)) {
         if (!newimg(Maxx, img)) return;
         scale(hyg, 1440ul, (-1.E+4f), 100.0f, 120.0f, 101.0f, &yax0, &yax1,
                &step);
         aprsstr_FixToStr(lastval->hyg, 0UL, s, 256ul);
         aprsstr_Append(s, 256ul, "% Humidty ", 11ul);
         aprsstr_Append(s, 256ul, h, 256ul);
         paper(img, yax0, yax1, step, 8UL, Maxx, 120UL, s, 256ul);
         timeline(stime, img, Maxx);
         dots(XStep, img, hyg, 1440ul, 1, 0UL, 500UL, 700UL);
      }
   }
   if (max0.lumi!=(-1.E+4f)) {
      have |= 0x40U;
      if ((0x40U & *what)) {
         if (!newimg(Maxx, img)) return;
         scale(lumi, 1440ul, (-1.E+4f), max0.lumi, 120.0f, 50.0f, &yax0,
                &yax1, &step);
         aprsstr_FixToStr(lastval->lumi, 0UL, s, 256ul);
         aprsstr_Append(s, 256ul, "W/m^2 Luminosity ", 18ul);
         aprsstr_Append(s, 256ul, h, 256ul);
         paper(img, yax0, yax1, step, 8UL, Maxx, 120UL, s, 256ul);
         timeline(stime, img, Maxx);
         dots(XStep, img, lumi, 1440ul, 1, 600UL, 600UL, 0UL);
      }
   }
   if (max0.rain!=(-1.E+4f)) {
      have |= 0x20U;
      if ((0x20U & *what)) {
         if (!newimg(Maxx, img)) return;
         scale(rain1, 1440ul, (-1.E+4f), max0.rain, 120.0f, 5.0f, &yax0,
                &yax1, &step);
         scale(rain24, 1440ul, (-1.E+4f), max0.rain, 120.0f, 5.0f, &yax0,
                &yax1, &step);
         scale(rain0, 1440ul, (-1.E+4f), max0.rain, 120.0f, 5.0f, &yax0,
                &yax1, &step);
         aprsstr_FixToStr(lastval->rain, 2UL, s, 256ul);
         aprsstr_Append(s, 256ul, "mm Rain ", 9ul);
         aprsstr_Append(s, 256ul, h, 256ul);
         paper(img, yax0, yax1, step, 8UL, Maxx, 120UL, s, 256ul);
         timeline(stime, img, Maxx);
         dots(XStep, img, rain1, 1440ul, 1, 500UL, 100UL, 0UL);
         dots(XStep, img, rain24, 1440ul, 1, 50UL, 600UL, 50UL);
         dots(XStep, img, rain0, 1440ul, 1, 100UL, 100UL, 700UL);
      }
   }
   if (max0.siev>0.0f) have |= 0x400U;
   *what = have;
/*
  IF img<>NIL THEN DISPOSE(img) END;
*/
} /* end wxgraph() */
Пример #13
0
RenderQueue* BREW::CreateWindowDrawable( SharedPtr<const Window> window ) const {
	RenderQueue* queue( new RenderQueue );
	sf::Color background_color( GetProperty<sf::Color>( "BackgroundColor", window ) );
	sf::Color border_color( GetProperty<sf::Color>( "BorderColor", window ) );
	sf::Color title_background_color( GetProperty<sf::Color>( "TitleBackgroundColor", window ) );
	sf::Color title_text_color( GetProperty<sf::Color>( "Color", window ) );
	int border_color_shift( GetProperty<int>( "BorderColorShift", window ) );
	float border_width( GetProperty<float>( "BorderWidth", window ) );
	float title_padding( GetProperty<float>( "TitlePadding", window ) );
	float shadow_distance( GetProperty<float>( "ShadowDistance", window ) );
	float handle_size( GetProperty<float>( "HandleSize", window ) );
	sf::Uint8 shadow_alpha( GetProperty<sf::Uint8>( "ShadowAlpha", window ) );
	unsigned int title_font_size( GetProperty<unsigned int>( "FontSize", window ) );
	const sf::Font& title_font( *GetResourceManager().GetFont( GetProperty<std::string>( "FontName", window ) ) );
	float title_size( GetFontLineHeight( title_font, title_font_size ) + 2 * title_padding );

	if( window->HasStyle( Window::SHADOW ) ) {
		// Shadow.
		sf::Color shadow_color( 0, 0, 0, shadow_alpha );

		sf::FloatRect shadow_rect(
			shadow_distance,
			shadow_distance,
			window->GetAllocation().width,
			window->GetAllocation().height
		);

		queue->Add(
			Renderer::Get().CreateRect(
				shadow_rect,
				shadow_color
			)
		);
	}

	if( window->HasStyle( Window::BACKGROUND ) ) {
		// Pane.
		queue->Add(
			Renderer::Get().CreatePane(
				sf::Vector2f( 0.f, 0.f ),
				sf::Vector2f( window->GetAllocation().width, window->GetAllocation().height ),
				border_width,
				background_color,
				border_color,
				border_color_shift
			)
		);
	}

	if( window->HasStyle( Window::RESIZE ) ) {
		queue->Add(
			Renderer::Get().CreateTriangle(
				sf::Vector2f( window->GetAllocation().width, window->GetAllocation().height - handle_size ),
				sf::Vector2f( window->GetAllocation().width - handle_size, window->GetAllocation().height ),
				sf::Vector2f( window->GetAllocation().width, window->GetAllocation().height ),
				title_background_color
			)
		);
	}


	if( !window->HasStyle( Window::TITLEBAR ) ) {
		title_size = 0;
	}

	if( title_size > 0 ) {
		queue->Add(
			Renderer::Get().CreateRect(
				sf::FloatRect(
					border_width + .1f,
					border_width + .1f,
					window->GetAllocation().width - 2 * border_width,
					title_size
				),
				title_background_color
			)
		);

		// Find out visible text, count in "...".
		float avail_width( window->GetAllocation().width - 2.f * border_width - 2.f * title_padding );

		sf::Text title_text( window->GetTitle(), title_font, title_font_size );

		if( title_text.getLocalBounds().width > avail_width ) {
			sf::Text dots( "...", title_font, title_font_size );
			const sf::String& title_string( window->GetTitle() );
			sf::String visible_title;

			avail_width = window->GetAllocation().width - 2.f * border_width - 2.f * title_padding - dots.getLocalBounds().width;

			for( std::size_t ch_index = 0; ch_index < title_string.getSize(); ++ch_index ) {
				avail_width -= static_cast<float>( title_font.getGlyph( title_string[ch_index], title_font_size, false ).advance );

				if( avail_width < 0.f ) {
					visible_title += "...";
					break;
				}

				visible_title += title_string[ch_index];
			}

			title_text.setString( visible_title );
		}

		// Calculate title text position.
		sf::Vector2f title_position(
			border_width + title_padding,
			border_width + title_size / 2.f - static_cast<float>( title_font_size ) / 2.f
		);

		title_text.setPosition( title_position );
		title_text.setColor( title_text_color );

		queue->Add( Renderer::Get().CreateText( title_text ) );
	}

	return queue;
}
Пример #14
0
tabuleiro *aleatorio(tabuleiro *tab,int before){
	int lin,col,i,l,com=0,barexist,barconess, posicoes;
	int linhas[100],comb[100];
	char tmp[100][100],local[100][100];
	tabuleiro *f, *w, *z, *x;

	


	for(lin=0;lin!=tab->tamanho[0];lin++){
		barexist=0;
		posicoes=0;
		for(col=0;col!=tab->tamanho[1];col++){
			if(caniboat(tab,lin,col)) posicoes++;
			else if(tab->quadro[lin][col]!='~' && tab->quadro[lin][col]!='.') barexist++;
		}
		barconess=tab->linhas[lin]-barexist;
		comb[lin]=combinacoes(posicoes,barconess);
	}


	for(i=0;i!=tab->tamanho[0];i++)
		linhas[i]=i;



	ordena(comb,linhas,0,tab->tamanho[0]);



	for(i=0;comb[i]==0;i++);

	l=linhas[i];
	com=0;








	for(lin=0;lin!=tab->tamanho[0];lin++)
	   	for(col=0;col!=tab->tamanho[1];col++)
	   		tmp[lin][col]=tab->quadro[lin][col];


		do{
			if(verifica(tab)==2) ;
			else if(verifica(tab)==0){

				for(lin=0;lin!=tab->tamanho[0];lin++)
	   				for(col=0;col!=tab->tamanho[1];col++)
	   					tab->quadro[lin][col]=tmp[lin][col];

	   				++com;

					if(com>=comb[i]) {com=0; l=linhas[++i];}

	   				tab=aleoaux(tab,l,com);
	   			}

	  	    else if(verifica(tab)==1){

	  	    	++com;

				if(com>=comb[i]) {com=0; l=linhas[++i];}



	  	    	tab=aleoaux(tab,l,com);
	  	    } 			

			do{
				for(lin=0;lin!=tab->tamanho[0];lin++)
	   				for(col=0;col!=tab->tamanho[1];col++)
	   					local[lin][col]=tab->quadro[lin][col];
	   	

        	f=aloca(tab);
        	w=verigual(tab,estra1(f));


        	f=aloca(w);
        	z=verigual(w,estra2(f));


        	f=aloca(z);
        	x=verigual(z,estra3(f));

        	f=aloca(x);
        	tab=verigual(x,estra4(f));



		}while(changes(local,tab) && verifica(tab)!=2);


		if(verifica(tab)==0){
			for(lin=0;lin!=tab->tamanho[0];lin++)
	   				for(col=0;col!=tab->tamanho[1];col++)
	   					tmp[lin][col]=tab->quadro[lin][col];

		}




		if(before==1){
			for(lin=0;lin!=tab->tamanho[0];lin++)
	   				for(col=0;col!=tab->tamanho[1];col++)
	   					tmp[lin][col]=tab->quadro[lin][col];

	   	return tab;

		}
		else if(verifica(tab)!=2 && i+1==tab->tamanho[0]) tab=aleatorio(tab,1);

		if(dots(tab) || verifica(tab)!=2) {
			for(lin=0;lin!=tab->tamanho[0];lin++)
	   				for(col=0;col!=tab->tamanho[1];col++)
	   					tmp[lin][col]=tab->quadro[lin][col];

	   	return tab;

		}

	}while(verifica(tab)!=2);


   return tab;
}
Пример #15
0
void Rest::layout()
      {
      _space.setLw(0.0);

      if (parent() && measure() && measure()->isMMRest()) {
            _space.setRw(point(score()->styleS(StyleIdx::minMMRestWidth)));

            static const qreal verticalLineWidth = .2;
            qreal _spatium = spatium();
            qreal h        = _spatium * (2 + verticalLineWidth);
            qreal w        = _mmWidth + _spatium * verticalLineWidth*.5;
            bbox().setRect(-_spatium * verticalLineWidth*.5, -h * .5, w, h);

            // text
            qreal y  = -_spatium * 2.5 - staff()->height() *.5;
            addbbox(QRectF(0, y, w, _spatium * 2));         // approximation
            return;
            }

      rxpos() = 0.0;
      if (staff() && staff()->isTabStaff()) {
            StaffType* tab = staff()->staffType();
            // if rests are shown and note values are shown as duration symbols
            if (tab->showRests() && tab->genDurations()) {
                  TDuration::DurationType type = durationType().type();
                  int                     dots = durationType().dots();
                  // if rest is whole measure, convert into actual type and dot values
                  if (type == TDuration::DurationType::V_MEASURE) {
                        int       ticks = measure()->ticks();
                        TDuration dur   = TDuration(Fraction::fromTicks(ticks)).type();
                        type = dur.type();
                        dots = dur.dots();
                        }
                  // symbol needed; if not exist, create, if exists, update duration
                  if (!_tabDur)
                        _tabDur = new TabDurationSymbol(score(), tab, type, dots);
                  else
                        _tabDur->setDuration(type, dots, tab);
                  _tabDur->setParent(this);
// needed?        _tabDur->setTrack(track());
                  _tabDur->layout();
                  setbbox(_tabDur->bbox());
                  setPos(0.0, 0.0);             // no rest is drawn: reset any position might be set for it
                  _space.setLw(0.0);
                  _space.setRw(width());
                  return;
                  }
            // if no rests or no duration symbols, delete any dur. symbol and chain into standard staff mngmt
            // this is to ensure horiz space is reserved for rest, even if they are not diplayed
            // Rest::draw() will skip their drawing, if not needed
            if(_tabDur) {
                  delete _tabDur;
                  _tabDur = 0;
                  }
            }

      switch(durationType().type()) {
            case TDuration::DurationType::V_64TH:
            case TDuration::DurationType::V_32ND:
                  dotline = -3;
                  break;
            case TDuration::DurationType::V_1024TH:
            case TDuration::DurationType::V_512TH:
            case TDuration::DurationType::V_256TH:
            case TDuration::DurationType::V_128TH:
                  dotline = -5;
                  break;
            default:
                  dotline = -1;
                  break;
            }
      qreal _spatium = spatium();
      int stepOffset = 0;
      if (staff())
            stepOffset = staff()->staffType()->stepOffset();
      int line       = lrint(userOff().y() / _spatium); //  + ((staff()->lines()-1) * 2);
      qreal lineDist = staff() ? staff()->staffType()->lineDistance().val() : 1.0;

      int lines = staff() ? staff()->lines() : 5;
      int lineOffset = computeLineOffset();

      int yo;
      _sym = getSymbol(durationType().type(), line + lineOffset/2, lines, &yo);
      layoutArticulations();
      rypos() = (qreal(yo) + qreal(lineOffset + stepOffset) * .5) * lineDist * _spatium;

      Spatium rs;
      if (dots()) {
            rs = Spatium(score()->styleS(StyleIdx::dotNoteDistance)
               + dots() * score()->styleS(StyleIdx::dotDotDistance));
            }
      if (dots()) {
            rs = Spatium(score()->styleS(StyleIdx::dotNoteDistance)
               + dots() * score()->styleS(StyleIdx::dotDotDistance));
            }
      setbbox(symBbox(_sym));
      _space.setRw(width() + point(rs));
      }
Пример #16
0
SparseWeightMatrix linear_weight_matrix(const RandomAccessIterator& begin, const RandomAccessIterator& end,
                                        const Neighbors& neighbors, PairwiseCallback callback,
                                        const ScalarType shift, const ScalarType trace_shift)
{
	timed_context context("KLLE weight computation");
	const IndexType k = neighbors[0].size();

	SparseTriplets sparse_triplets;
	sparse_triplets.reserve((k*k+2*k+1)*(end-begin));

#pragma omp parallel shared(begin,end,neighbors,callback,sparse_triplets) default(none)
	{
		IndexType index_iter;
		DenseMatrix gram_matrix = DenseMatrix::Zero(k,k);
		DenseVector dots(k);
		DenseVector rhs = DenseVector::Ones(k);
		DenseVector weights;
		SparseTriplets local_triplets;
		local_triplets.reserve(k*k+2*k+1);

		//RESTRICT_ALLOC;
#pragma omp for nowait
		for (index_iter=0; index_iter<static_cast<IndexType>(end-begin); index_iter++)
		{
			ScalarType kernel_value = callback.kernel(begin[index_iter],begin[index_iter]);
			const LocalNeighbors& current_neighbors = neighbors[index_iter];

			for (IndexType i=0; i<k; ++i)
				dots[i] = callback.kernel(begin[index_iter], begin[current_neighbors[i]]);

			for (IndexType i=0; i<k; ++i)
			{
				for (IndexType j=i; j<k; ++j)
					gram_matrix(i,j) = kernel_value - dots(i) - dots(j) +
					                   callback.kernel(begin[current_neighbors[i]],begin[current_neighbors[j]]);
			}

			ScalarType trace = gram_matrix.trace();
			gram_matrix.diagonal().array() += trace_shift*trace;
			weights = gram_matrix.selfadjointView<Eigen::Upper>().ldlt().solve(rhs);
			weights /= weights.sum();

			SparseTriplet diagonal_triplet(index_iter,index_iter,1.0+shift);
			local_triplets.push_back(diagonal_triplet);
			for (IndexType i=0; i<k; ++i)
			{
				SparseTriplet row_side_triplet(current_neighbors[i],index_iter,-weights[i]);
				SparseTriplet col_side_triplet(index_iter,current_neighbors[i],-weights[i]);
				local_triplets.push_back(row_side_triplet);
				local_triplets.push_back(col_side_triplet);
				for (IndexType j=0; j<k; ++j)
				{
					SparseTriplet cross_triplet(current_neighbors[i],current_neighbors[j],weights(i)*weights(j));
					local_triplets.push_back(cross_triplet);
				}
			}

#pragma omp critical
			{
				copy(local_triplets.begin(),local_triplets.end(),back_inserter(sparse_triplets));
			}

			local_triplets.clear();
		}
		//UNRESTRICT_ALLOC;
	}

	return sparse_matrix_from_triplets(sparse_triplets, end-begin, end-begin);
}