Example #1
0
void
RWSegmentVector::addSegmentIfTerminalNode(RWTree* aNode,
					  std::vector<Point>& myChain)
{
  if ((aNode->leftChild() != 0) || (aNode->rightChild() != 0))
    {
      if (aNode->leftChild() != 0)
	{
	  addSegmentIfTerminalNode(aNode->leftChild(), myChain);
	}

      if (aNode->rightChild() != 0)
	{
	  addSegmentIfTerminalNode(aNode->rightChild(), myChain);
	}
    }
  else
    {
      Segment newSeg(myChain[aNode->firstIdx()],
		     myChain[aNode->lastIdx()]);
      push_back(newSeg);
      _significance.push_back(aNode->significance());
      _indexes.push_back(aNode->firstIdx());
    }
}
/*private*/
auto_ptr<TaggedLineSegment>
TaggedLineStringSimplifier::flatten(size_t start, size_t end)
{
	// make a new segment for the simplified geometry
	const Coordinate& p0 = linePts->getAt(start);
	const Coordinate& p1 = linePts->getAt(end);
	auto_ptr<TaggedLineSegment> newSeg(new TaggedLineSegment(p0, p1));
	// update the indexes
	remove(line, start, end);
	outputIndex->add(newSeg.get());
	return newSeg;
}
Example #3
0
bool PolyLine2::AddPoint( const Vec2& pt, bool bNoSelfCross )
{
    int nP = GetNPoints();
    if (bNoSelfCross && nP > 0)
    {
        int nSeg = GetNSegments() - 2;
        Seg2 newSeg( pt, GetPoint( nP - 1 ) );
        for (int i = 0; i < nSeg; i++)
        {
            if (newSeg.intersects( GetEdge( i ) )) return false;
        }
    }
    m_Points.push_back( pt );
    return true;
}
Example #4
0
void LoadTestSettings::loadSegmentsElement(TiXmlElement *pElement)
{
	for (TiXmlElement *pItem = pElement->FirstChildElement(); pItem; pItem = pItem->NextSiblingElement())
	{
		if (pItem->ValueStr() == "seg")
		{
			std::string content;
			if (pItem->GetText())
				content = pItem->GetText();
			
			std::string threadsAttr = pItem->Attribute("threads");
			
			if (!content.empty() && !threadsAttr.empty())
			{
				int threads = atoi(threadsAttr.c_str());
				int duration = atoi(content.c_str());
				
				LoadTestProfileSeg newSeg(threads, duration);
				
				addProfile(newSeg);
			}
		}
	}	
}
/*private*/
void
TaggedLineStringSimplifier::simplifySection(size_t i,
		size_t j, size_t depth)
{
	depth += 1;

#if GEOS_DEBUG
	std::cerr << "TaggedLineStringSimplifier[" << this << "] "
	          << " simplifying section " << i << "-" << j
	          << std::endl;
#endif

	vector<size_t> sectionIndex(2);

	if((i+1) == j)
	{

#if GEOS_DEBUG
		std::cerr << "single segment, no flattening" 
		          << std::endl;
#endif

		auto_ptr<TaggedLineSegment> newSeg(new
			TaggedLineSegment(*(line->getSegment(i))));

		line->addToResult(newSeg);
		// leave this segment in the input index, for efficiency
		return;
	}

	bool isValidToSimplify = true;

	/**
	 * Following logic ensures that there is enough points in the
	 * output line.
	 * If there is already more points than the minimum, there's
	 * nothing to check.
	 * Otherwise, if in the worst case there wouldn't be enough points,
	 * don't flatten this segment (which avoids the worst case scenario)
	 */
	if (line->getResultSize() < line->getMinimumSize())
	{
		size_t worstCaseSize = depth + 1;
		if (worstCaseSize < line->getMinimumSize())
			isValidToSimplify = false;
	}

	double distance;

	// pass distance by ref
	size_t furthestPtIndex = findFurthestPoint(linePts, i, j, distance);

#if GEOS_DEBUG
	std::cerr << "furthest point " << furthestPtIndex 
	          << " at distance " << distance
	          << std::endl;
#endif

	// flattening must be less than distanceTolerance
	if ( distance > distanceTolerance ) isValidToSimplify = false;

	// test if flattened section would cause intersection
	LineSegment candidateSeg(linePts->getAt(i), linePts->getAt(j));

	sectionIndex[0] = i;
	sectionIndex[1] = j;

	if (hasBadIntersection(line, sectionIndex, candidateSeg))
			isValidToSimplify = false;

	if (isValidToSimplify)
	{

		auto_ptr<TaggedLineSegment> newSeg = flatten(i, j);

#if GEOS_DEBUG
		std::cerr << "isValidToSimplify, adding seg " 
			  << newSeg->p0 << ", " << newSeg->p1
			  << " to TaggedLineSegment["<<line<<"] result "
			  << std::endl;
#endif

		line->addToResult(newSeg);
		return;
	}

	simplifySection(i, furthestPtIndex, depth);
	simplifySection(furthestPtIndex, j, depth);
 
}
Example #6
0
// Connect the current end segment to the start point.
void TrackGen::ConnectToEnd()
{
	float arcToBelowStart = FindArcBetweenPoints(_segmentList.at(_segmentList.size()-1)->GetEndPos(), glm::vec2(-100, -300));
	float distanceToBelowStart = std::sqrtf(((_segmentList.at(_segmentList.size()-1)->GetEndPos().x * _segmentList.at(_segmentList.size()-1)->GetEndPos().x) - (-100*-100)) + ((_segmentList.at(_segmentList.size()-1)->GetEndPos().y * _segmentList.at(_segmentList.size()-1)->GetEndPos().y) - (-100*-100)));

	if (arcToBelowStart < 0)
		arcToBelowStart+= 360;

	// Create initial curve in direction just below start.
	CreateCurveSegment("lft", _cumulativeArc-arcToBelowStart+1, NumberGeneration(_weibullRadiusShape, _weibullRadiusScale));

	// Straight segment to point just below start.
	distanceToBelowStart = glm::distance(_segmentList.back()->GetEndPos(), glm::vec2(-100, -300));
	CreateSegment(distanceToBelowStart);

	// Increment through new radiuses until X = 0 (in line with the start point).
	float newRadius = 0.01f;
	CurveSegment newSeg("lft", _cumulativeArc, newRadius, 0, 0);
	newSeg.SetStartPos(_segmentList.back()->GetEndPos());
	newSeg.FindEndPos(_cumulativeArc);

	arcToBelowStart = FindArcBetweenPoints(_segmentList.at(_segmentList.size()-1)->GetEndPos(), glm::vec2(0, -300));
	glm::vec2 flag = newSeg.GetEndPos();

	
	while (flag.x < -0.01f)
	{
		newSeg.FindEndPos(_cumulativeArc);
		flag = newSeg.GetEndPos();
		newRadius+=0.01f;
		newSeg = CurveSegment("lft", _cumulativeArc, newRadius, 0, 0);
		newSeg.SetStartPos(_segmentList[_segmentList.size()-1]->GetEndPos());
		if (newRadius > 360)
		{
			_returnCode = true;
			return;
		}
	}

	

	CreateCurveSegment("lft", newSeg.GetArc(), newSeg.GetRadius());
	
	/*
	newRadius = 0.01f;
	StraightSegment* newStraightSeg = new StraightSegment(newRadius, 0, 0);
	newStraightSeg->SetStartPos(_segmentList[_segmentList.size()-1]->GetEndPos());
	newStraightSeg->FindEndPos(cumulativeArc);
	flag = newStraightSeg->GetEndPos();
	while (flag.y < -0.01f)
	{
		newStraightSeg->FindEndPos(cumulativeArc);
		flag = newStraightSeg->GetEndPos();
		newRadius+=0.01;
		newStraightSeg = new StraightSegment(newRadius, 0, 0);
		newStraightSeg->SetStartPos(_segmentList[_segmentList.size()-1]->GetEndPos());
		if (newRadius > 360)
		{
			returnCode = 1;
			return;
		}
	}
	*/
	CreateSegment(abs(_segmentList.back()->GetEndPos().y));
}
Example #7
0
// whatever this means... it's OLD.
//#warning "loadRow is currently in an intermediate phase..."
void loadRow(uint16_t rowNum)
{


#if(defined(ROW_SEG_BUFFER) && ROW_SEG_BUFFER)
 #if (defined(SEG_RACER) && SEG_RACER)
	racer_loadRow(rowNum);
 #elif (defined(SEG_HFM) && SEG_HFM)
 	segHFM_loadRow(rowNum);
 #elif (defined(SEG_QUESTION) && SEG_QUESTION)
 	segQuestion_loadRow(rowNum);
 #elif (defined(SEG_SINE) && SEG_SINE)
 	segSine_loadRow(rowNum);
 #elif (defined(SEG_LINE) && SEG_LINE)
	//Left here for an example...
	// Draws a diagonal line 
	//OLD NOTE:
	//syncing issues due to recursion overflowing the stack???
	// Apparently was
	   
	//Isn't BLAH = 1 necessary so we don't get a row with no data?
	// *looks* like it's working, but I dunno...
	#define BLAH 0

	segClear();
	newSeg(3,0x06, (6<<4) | 3);									//W
	newSeg((rowNum&0xff) | BLAH, 0x06, (4<<4) | 0);				//R
	newSeg(1,0x06, (6<<4) | 3);									//W
	newSeg((255-(rowNum&0xff)) | BLAH, 0x06, (4<<4) | 0 );	//R
	newSeg(3,0x06, (6<<4) | 3);									//W
	segTerminate();

 #elif (defined(SEG_TET) && SEG_TET)
	//This isn't particularly functional, anymore
	// it used to be an intermediate stage between rowBuffer and 
	//  rowSegBuffer... Left here for an example of how it could be done...
  #if(!defined(SEG_STRETCH))
	#define SEG_STRETCH 5 //(((NUM_PSEGS-6)+RB_WIDTH-1)/RB_WIDTH)
  #endif
	//3-5 = white + cyan
	//6 = letters alternating with above
	//7-9 = ditto, stretched

#define TET_VSTRETCH	16
	if(rowNum == 0)
	{
		//Probably not best to put this here, as we're still in the interrupt
		// extra-long calculations might cause syncing issues with displays
		// that require rows to be a constant time
		tetUpdate();
	}
	if(rowNum % TET_VSTRETCH == 0)
	{
		uint8_t i;
		for(i=0; i<RB_WIDTH; i++)
			rowBuffer[i] = fb_to_rb(_K);
		//	rowBuffer[i] = fb_to_rb((i+rowNum/TET_VSTRETCH)&0x3f);
		
		tet_drawRow(rowNum/TET_VSTRETCH, rowBuffer);
	}
	segClear();

	//Good for syncing to have white on both borders...
	newSeg(3, 0x06, (6<<4) | 3);
	
	uint16_t i;
	//TET_OVERLAY alternates rows between the TETRIS board and
	// an rgb "gradient" The only purpose is to test the idea of
	// using the high vertical-resolution to essentially increase the
	// number of colors available to a low-resolution image
	// sort of like "dithering" in the ol' days of 256 colors in Windows
	// but easy to implement in this case with very little overhead 
	// row-by-row
	// The effect, from a ways back, looks like the colors are blended
	// (like the Text and Game-board are translucent)
#define TET_OVERLAY TRUE

	//TET_GRADIENT takes that a step further and attempts to create a
	// gradient between each color in that rgb-gradient.
	// It's not as pretty as I'd hoped... though it makes sense...
	// first we're alternating between TET's color and the background color
	// then the background color is (roughly) alternating between a couple
	// colors, several rows between...
	// so if a color is stretched 16 rows vertically, that only leaves 8
	// rows for the color-gradient... might work better over more gradual
	// color-changes
#define TET_GRADIENT TRUE

#if (defined(TET_OVERLAY) && TET_OVERLAY)
	if(rowNum & 0x01)
	{
#endif
	for(i=0; i<RB_WIDTH; i++)
	{
		//i+1 because we don't want to overwrite the white border...
		rbpix_to_seg(rowBuffer[i], i+1, SEG_STRETCH);
	}

#if (defined(TET_OVERLAY) && TET_OVERLAY)
	}
	else
	{
		#define ROWS_PER 64//(V_COUNT/NUM_COLORS)

		uint8_t fbColor;

#if (defined(TET_GRADIENT) && TET_GRADIENT)
		static hfm_t hfmGradient;
		if(rowNum%ROWS_PER == 0)
			hfm_setup(&hfmGradient, 0, ROWS_PER/2-4);

		//It's worth it to experiment with changing the range of the 
		// hfmGradient, ('-4' above and '+4' below).
		// to try to avoid one or two stray spikes
		// (e.g. power = 1, maxPower = 15, there'll be one bright row
		//  and 14 dark, it sticks out like a sore-thumb)
		//  These values are experimental, and entirely dependent on the
		//  values used...

		hfm_setPower(&hfmGradient, (rowNum/2)%(ROWS_PER/2)+4);

		if(hfm_nextOutput(&hfmGradient))
			fbColor = rgbGradient(ROWS_PER-1 - rowNum/(ROWS_PER)+16-1);
		else
#endif
			fbColor = rgbGradient(ROWS_PER-1 - rowNum/(ROWS_PER)+16);

		addSegfb(RB_WIDTH*SEG_STRETCH, (fbColor));
		//newSeg(SEG_STRETCH, fb_to_seg((rowNum*64/768)&0x3f));

	}
#endif
	//white...
	newSeg(3, 0x06, (6<<4) | 3);
	segTerminate();
 #elif (defined(SEG_GRADIENT) && SEG_GRADIENT)
	static hfm_t hfmGradient;
#define ROWS_PER	(255)	//(V_COUNT/3) == 256

	if(rowNum%ROWS_PER == 0)
		hfm_setup(&hfmGradient, 0, ROWS_PER);

	uint8_t color;

	uint16_t power;

	if(rowNum < ROWS_PER/16)
		rowNum = 0;
	else
		rowNum -= ROWS_PER/16;

	//Since there are four shades, there will be three gradients...
	if(rowNum < ROWS_PER)
	{
		//The ROWS_PER/16 stuff is to help alleviate sharp color-spikes
		// which occur early-on... see the explanation in SEG_TET.
		color = 0;
		//hfm_setPower(&hfmGradient, 
		power = (rowNum); // + ROWS_PER/16);
	}
	else if(rowNum < ROWS_PER*2)
	{
		color = 1;
		//hfm_setPower(&hfmGradient, 
		power = rowNum-(ROWS_PER); // + ROWS_PER/16;
	}
	else
	{
		color = 2;
		//hfm_setPower(&hfmGradient, 
		power = rowNum-(ROWS_PER*2); // + ROWS_PER/16;
	}


	if(power < ROWS_PER/16)
		power = 0;

	hfm_setPower(&hfmGradient, (power <= 255) ? power : 255);

	if(hfm_nextOutput(&hfmGradient))
		color++;

	color |= color<<2 | color<<4;

	segClear();
	addSegfb(3, _W);
	addSegfb(NUM_PSEGS-6, color); 
	addSegfb(3, _W);
	segTerminate();
 #elif(defined(SEG_GRADIENT2) && SEG_GRADIENT2)
#error "Heh, never did implement this..."
 #else
	#error "Gotta select a SEG_... option, or create your own"
 #endif //SEG_ selection
#endif //ROW_SEG_BUFFER
}