예제 #1
0
// centered partial derivative of 2D signal in x
//
void MLSignal::partialDiffX()
{
	int i, j;
	float * pr; // input row ptr
	float * prOut; 	
	
	MLSample* pIn = getCopy();
	MLSample* pOut = mDataAligned;
	int width = mWidth;
	int height = mHeight;
	
	for(j = 0; j < height; ++j) 
	{
		// row ptrs
		pr = (pIn + row(j));
		prOut = (pOut + row(j));
		
		i = 0; // left side
		{
			prOut[i] = (pr[i+1]) / 2.f;		
		}
			
		for(i = 1; i < width - 1; ++i) 
		{
			prOut[i] = (pr[i+1] - pr[i-1]) / 2.f;
		}
		
		i = width - 1; // right side
		{
			prOut[i] = (-pr[i-1]) / 2.f;		
		}
	}
}
예제 #2
0
// builds expansion graph of i-th biconnected component of the original graph
void ExpansionGraph::init(int i)
{
	OGDF_ASSERT(0 <= i);
	OGDF_ASSERT(i <= m_component.high());

	// remove previous component
	for(node v : nodes) {
		node vOrig = m_vOrig[v];
		if (vOrig)
			m_vCopy[vOrig] = nullptr;
	}
	clear();


	// create new component
	SListConstIterator<edge> it;
	for(it = m_component[i].begin(); it.valid(); ++it)
	{
		edge e = *it;

		edge eCopy = newEdge(getCopy(e->source()),getCopy(e->target()));
		m_eOrig[eCopy] = e;
	}

	// expand vertices
	for(node v : nodes)
	{
		if (original(v) && v->indeg() >= 1 && v->outdeg() >= 1) {
			node vPrime = newNode();
			m_vRep[vPrime] = m_vOrig[v];

			SListPure<edge> edges;
			v->outEdges(edges);

			SListConstIterator<edge> it;
			for(it = edges.begin(); it.valid(); ++it)
				moveSource(*it,vPrime);

			newEdge(v,vPrime);
		}
	}
}
예제 #3
0
void MLMultiProc::dumpProc(int indent)
{
	const int copies = (int)mCopies.size();	

	debug() << ml::stringUtils::spaceStr(indent) << getName() << " (multiproc " << (void *)&(*this) << ")\n";

	for(int i=0; i<copies; i++)
	{
	debug() << ml::stringUtils::spaceStr(indent) <<  " copy " << i + 1 << ": \n";
	
		getCopy(i)->dumpProc(indent + 1);
	}
}
예제 #4
0
TetrisPiece TetrisPiece::rotateCCW()
{
	// O pieces don't get rotated, so just return the current piece
	if(my_type == TetrisPiece::O)
		return getCopy();//return this;

	int oldX = 0, oldY = 0, lowX=3;
	std::vector<Point> new_blocks;

	//if it's an I block you need to do special rotation
	if(my_type == TetrisPiece::I)
	{
		if(isHorizI())
		{
			new_blocks.push_back(newPoint(1,0));
			new_blocks.push_back(newPoint(1,1));
			new_blocks.push_back(newPoint(1,2));
			new_blocks.push_back(newPoint(1,3));
		}
		else
		{
			new_blocks.push_back(newPoint(0,1));
			new_blocks.push_back(newPoint(1,1));
			new_blocks.push_back(newPoint(2,1));
			new_blocks.push_back(newPoint(3,1));
		}

		return TetrisPiece(new_blocks, my_type, my_location.x,
				my_location.y);
	}

	// if it's not an I or an O, rotate using this algorithm
	for(std::vector<Point>::iterator it = my_blocks.begin(),
			end = my_blocks.end() ; it != end ; ++it)
	{
		oldX = it->x;
		oldY = it->y;

		if(3 - oldY < lowX)
			lowX = 3 - oldY;

		new_blocks.push_back(newPoint(3-oldY,oldX));
	}

	// move it to the left
	for(std::vector<Point>::iterator it = new_blocks.begin(),
			end = new_blocks.end() ; it != end ; ++it)
		it->x -= lowX;

	return TetrisPiece(new_blocks, my_type, my_location.x, my_location.y);
}
예제 #5
0
TetrisPiece TetrisPiece::rotateCW()
{
	// O pieces don't get rotated, so just return the current piece
	if(my_type == TetrisPiece::O)
		return getCopy();//return this;

	int oldX = 0, oldY = 0, lowY=3;
	std::vector<Point> new_blocks;

	// if it's an I block you need to do special rotation
	if(my_type == TetrisPiece::I)
	{
		if(isHorizI())
		{
			new_blocks.push_back(newPoint(1,0));
			new_blocks.push_back(newPoint(1,1));
			new_blocks.push_back(newPoint(1,2));
			new_blocks.push_back(newPoint(1,3));
		}
		else
		{
			new_blocks.push_back(newPoint(0,1));
			new_blocks.push_back(newPoint(1,1));
			new_blocks.push_back(newPoint(2,1));
			new_blocks.push_back(newPoint(3,1));
		}

		return TetrisPiece(new_blocks, my_type, my_location.x,
				my_location.y);
	}

	// if it's not an I or O, do rotation as normal
	for(std::vector<Point>::iterator it = my_blocks.begin(),
			end = my_blocks.end() ; it != end; ++it)
	{
		oldX = it->x;
		oldY = it->y;

		if(3 - oldX < lowY)
			lowY = 3 - oldX;

		new_blocks.push_back(newPoint(oldY,3-oldX));
	}

	// move to lower left corner
	for(std::vector<Point>::iterator it = new_blocks.begin(),
			end = new_blocks.end() ; it != end ; ++it)
		it->y -= lowY;

	return TetrisPiece(new_blocks, my_type, my_location.x, my_location.y);
}
예제 #6
0
// builds expansion graph of graph G
// for debugging purposes only
void ExpansionGraph::init(const Graph &G)
{
	// remove previous component
	for(node v : nodes) {
		node vOrig = m_vOrig[v];
		if (vOrig)
			m_vCopy[vOrig] = nullptr;
	}
	clear();


	// create new component
	for(node v : G.nodes)
		getCopy(v);

	for(edge e : G.edges)
	{
		edge eCopy = newEdge(getCopy(e->source()),getCopy(e->target()));
		m_eOrig[eCopy] = e;
	}

	// expand vertices
	for(node v : nodes)
	{
		if (original(v) && v->indeg() >= 1 && v->outdeg() >= 1) {
			node vPrime = newNode();

			SListPure<edge> edges;
			v->outEdges(edges);

			SListConstIterator<edge> it;
			for(it = edges.begin(); it.valid(); ++it)
				moveSource(*it,vPrime);

			newEdge(v,vPrime);
		}
	}
}
예제 #7
0
// centered partial derivative of 2D signal in y
//
void MLSignal::partialDiffY()
{
	int i, j;
	float * pr1, * pr2, * pr3; // input row ptrs
	float * prOut; 	
	
	MLSample* pIn = getCopy();
	MLSample* pOut = mDataAligned;
	int width = mWidth;
	int height = mHeight;
	
	j = 0; // top row
	{
		pr2 = (pIn + row(j));
		pr3 = (pIn + row(j + 1));
		prOut = (pOut + row(j));

		for(i = 0; i < width; ++i) 
		{
			prOut[i] = (pr3[i]) / 2.f;
		}
	}

	for(j = 1; j < height - 1; ++j) // center rows
	{
		pr1 = (pIn + row(j - 1));
		pr2 = (pIn + row(j));
		pr3 = (pIn + row(j + 1));
		prOut = (pOut + row(j));
		
		for(i = 0; i < width; ++i) 
		{
			prOut[i] = (pr3[i] - pr1[i]) / 2.f;
		}
	}
	
	j = height - 1;	// bottom row
	{
		pr1 = (pIn + row(j - 1));
		pr2 = (pIn + row(j));
		prOut = (pOut + row(j));
		
		for(i = 0; i < width; ++i) 
		{
			prOut[i] = (-pr1[i]) / 2.f;
		}
	}
}
예제 #8
0
// convolve a 1D signal with a 3-point impulse response.
void MLSignal::convolve3x1(const MLSample km, const MLSample k, const MLSample kp)
{
    // TODO SSE
	int width = mWidth;
	MLSample* pIn = getCopy();
    
    // left
    mDataAligned[0] = k*pIn[0] + kp*pIn[1];
    
    // center
    for(int i=1; i<width - 1; ++i)
    {
        mDataAligned[i] = km*pIn[i - 1] + k*pIn[i] + kp*pIn[i + 1];
    }
    
    // right
    mDataAligned[width - 1] = km*pIn[width - 2] + k*pIn[width - 1];
}
예제 #9
0
void MLSignal::convolve5x1(const MLSample kmm, const MLSample km, const MLSample k, const MLSample kp, const MLSample kpp)
{
    // TODO SSE
	int width = mWidth;
	MLSample* pIn = getCopy();
    
    // left
    mDataAligned[0] = k*pIn[0] + kp*pIn[1] + kpp*pIn[2];
    mDataAligned[1] = km*pIn[0] + k*pIn[1] + kp*pIn[2] + kpp*pIn[3];
    
    // center
    for(int i=2; i<width - 2; ++i)
    {
        mDataAligned[i] = kmm*pIn[i - 2] + km*pIn[i - 1] + k*pIn[i] + kp*pIn[i + 1] + kpp*pIn[i + 2];
    }
    
    // right
    mDataAligned[width - 2] = kmm*pIn[width - 4] + km*pIn[width - 3] + k*pIn[width - 2] + kp*pIn[width - 1];
    mDataAligned[width - 1] = kmm*pIn[width - 4] + km*pIn[width - 3] + k*pIn[width - 2];
}
예제 #10
0
void BlockHeaderRef::pprint(ostream & os, int nIndent, bool pBigendian) const
{
   getCopy().pprint(os, nIndent, pBigendian);
}
예제 #11
0
파일: Image.cpp 프로젝트: AnatoliDubko/CV
Image Image::getNormalized() const {
	auto result = getCopy();
	result.normalize();
	return result;
}
예제 #12
0
파일: Image.cpp 프로젝트: AnatoliDubko/CV
Image Image::getResized(const int height, const int width) const
{
	auto result = getCopy();
	result.resize(height, width);
	return result;
}
예제 #13
0
// an operator for 2D signals only
// convolve signal with coefficients, duplicating samples at border. 
void MLSignal::convolve3x3rb(const MLSample kc, const MLSample ke, const MLSample kk)
{
	int i, j;
	float f;
	float * pr1, * pr2, * pr3; // input row ptrs
	float * prOut; 	
	
	MLSample* pIn = getCopy();
	MLSample* pOut = mDataAligned;
	int width = mWidth;
	int height = mHeight;
	
	j = 0;	// top row
	{
		// row ptrs
		pr2 = (pIn + row(j));
		pr3 = (pIn + row(j + 1));
		prOut = (pOut + row(j));
		
		i = 0; // top left corner
		{
			f = ke * (pr2[i+1] + pr3[i] + pr2[i] + pr2[i]);
			f += kk * (pr3[i+1] + pr2[i+1] + pr3[i] + pr2[i]);
			f += kc * pr2[i];
			prOut[i] = f;		
		}
			
		for(i = 1; i < width - 1; i++) // top side
		{
			f = ke * (pr2[i-1] + pr2[i+1] + pr3[i] + pr2[i]);
			f += kk * (pr3[i-1] + pr3[i+1] + pr2[i-1] + pr2[i+1]);
			f += kc * pr2[i];
			prOut[i] = f;
		}
		
		i = width - 1; // top right corner
		{
			f = ke * (pr2[i-1] + pr3[i] + pr2[i] + pr2[i]);
			f += kk * (pr3[i-1] + pr2[i-1] + pr3[i] + pr2[i]);
			f += kc * pr2[i];
			prOut[i] = f;		
		}
	}
	for(j = 1; j < height - 1; j++) // center rows
	{
		// row ptrs
		pr1 = (pIn + row(j - 1));
		pr2 = (pIn + row(j));
		pr3 = (pIn + row(j + 1));
		prOut = (pOut + row(j));
		
		i = 0; // left side
		{
			f = ke * (pr1[i] + pr2[i+1] + pr3[i] + pr2[i]);
			f += kk * (pr1[i+1] + pr3[i+1] + pr1[i] + pr3[i]);
			f += kc * pr2[i];
			prOut[i] = f;		
		}
			
		for(i = 1; i < width - 1; i++) // center
		{
			f = ke * (pr2[i-1] + pr1[i] + pr2[i+1] + pr3[i]);
			f += kk * (pr1[i-1] + pr1[i+1] + pr3[i-1] + pr3[i+1]);
			f += kc * pr2[i];
			prOut[i] = f;
		}
		
		i = width - 1; // right side
		{
			f = ke * (pr2[i-1] + pr1[i] + pr3[i] + pr2[i]);
			f += kk * (pr1[i-1] + pr3[i-1] + pr1[i] + pr3[i]);
			f += kc * pr2[i];
			prOut[i] = f;		
		}
	}
	j = height - 1;	// bottom row
	{
		// row ptrs
		pr1 = (pIn + row(j - 1));
		pr2 = (pIn + row(j));
		prOut = (pOut + row(j));
		
		i = 0; // bottom left corner
		{
			f = ke * (pr1[i] + pr2[i+1] + pr2[i] + pr2[i]);
			f += kk * (pr1[i+1] + pr1[i] + pr2[i+1] + pr2[i]);
			f += kc * pr2[i];
			prOut[i] = f;		
		}
			
		for(i = 1; i < width - 1; i++) // bottom side
		{
			f = ke * (pr2[i-1] + pr1[i] + pr2[i+1] + pr2[i]);
			f += kk * (pr1[i-1] + pr1[i+1] + pr2[i-1] + pr2[i+1]);
			f += kc * pr2[i];
			prOut[i] = f;
		}
		
		i = width - 1; // bottom right corner
		{
			f = ke * (pr2[i-1] + pr1[i] + pr2[i] + pr2[i]);
			f += kk * (pr1[i-1] + pr1[i] + pr2[i-1] + pr2[i]);
			f += kc * pr2[i];
			prOut[i] = f;		
		}
	}
}
예제 #14
0
// an operator for 2D signals only
void MLSignal::variance3x3()
{
	MLSample* pIn = getCopy();
	MLSample* pOut = mDataAligned;
	int i, j;
	float f;
	float * pr1, * pr2, * pr3; // input row ptrs
	float * prOut; 		
	int width = mWidth;
	int height = mHeight;
	float c, x1, x2, x3, x4, x5, x6, x7, x8;
	
	i = 0;	// top row
	{
		// row ptrs
		pr2 = (pIn + row(i));
		pr3 = (pIn + row(i + 1));
		prOut = (pOut + row(i));
		
		j = 0; // top left corner
		{
			c = pr2[j]; x5 = pr2[j+1];
			x7 = pr3[j]; x8 = pr3[j+1];
			
			x5 -= c;
			x7 -= c; x8 -= c;
			
			x5 *= x5;
			x7 *= x7; x8 *= x8;
			
			f = x5 + x7 + x8;
			f /= 3.f;
			prOut[j] = sqrtf(f);
		}
		for(j = 1; j < width - 1; j++) // top side
		{
			x4 = pr2[j-1]; c = pr2[j]; x5 = pr2[j+1];
			x6 = pr3[j-1]; x7 = pr3[j]; x8 = pr3[j+1];
			
			x4 -= c; x5 -= c;
			x6 -= c; x7 -= c; x8 -= c;
			
			x4 *= x4; x5 *= x5;
			x6 *= x6; x7 *= x7; x8 *= x8;
			
			f = x4 + x5 + x6 + x7 + x8;
			f /= 5.f;
			prOut[j] = sqrtf(f);
		}		
		j = width - 1; // top right corner
		{
			x4 = pr2[j-1]; c = pr2[j];
			x6 = pr3[j-1]; x7 = pr3[j];
			
			x4 -= c;
			x6 -= c; x7 -= c; 
			
			x4 *= x4; 
			x6 *= x6; x7 *= x7; 
			
			f = x4 + x6 + x7;
			f /= 3.f;
			prOut[j] = sqrtf(f);
		}
	}
	for(i = 1; i < height - 1; i++) // center rows
	{
		// row ptrs
		pr1 = (pIn + row(i - 1));
		pr2 = (pIn + row(i));
		pr3 = (pIn + row(i + 1));
		prOut = (pOut + row(i));
		
		j = 0; // left side
		{
			x2 = pr1[j]; x3 = pr1[j+1];
			c = pr2[j]; x5 = pr2[j+1];
			x7 = pr3[j]; x8 = pr3[j+1];
			
			x2 -= c; x3 -= c;
			x5 -= c;
			x7 -= c; x8 -= c;
			
			x2 *= x2; x3 *= x3;
			x5 *= x5;
			x7 *= x7; x8 *= x8;
			
			f = x2 + x3 + x5 + x7 + x8;
			f /= 5.f;
			prOut[j] = sqrtf(f);
		}
		for(j = 1; j < width - 1; j++) // center
		{
			x1 = pr1[j-1]; x2 = pr1[j]; x3 = pr1[j+1];
			x4 = pr2[j-1]; c = pr2[j]; x5 = pr2[j+1];
			x6 = pr3[j-1]; x7 = pr3[j]; x8 = pr3[j+1];
			
			x1 -= c; x2 -= c; x3 -= c;
			x4 -= c; x5 -= c;
			x6 -= c; x7 -= c; x8 -= c;
			
			x1 *= x1; x2 *= x2; x3 *= x3;
			x4 *= x4; x5 *= x5;
			x6 *= x6; x7 *= x7; x8 *= x8;
			
			f = x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8;
			f /= 8.f;
			prOut[j] = sqrtf(f);
		}
		
		j = width - 1; // right side
		{
			x1 = pr1[j-1]; x2 = pr1[j]; 
			x4 = pr2[j-1]; c = pr2[j]; 
			x6 = pr3[j-1]; x7 = pr3[j]; 
			
			x1 -= c; x2 -= c;
			x4 -= c; 
			x6 -= c; x7 -= c; 
			
			x1 *= x1; x2 *= x2; 
			x4 *= x4; 
			x6 *= x6; x7 *= x7;
			
			f = x1 + x2 + x4 + x6 + x7;
			f /= 5.f;
			prOut[j] = sqrtf(f);
		}
	}
	i = height - 1;	// bottom row
	{
		// row ptrs
		pr1 = (pIn + row(i - 1));
		pr2 = (pIn + row(i));
		prOut = (pOut + row(i));
		
		j = 0; // bottom left corner
		{
			x2 = pr1[j]; x3 = pr1[j+1];
			c = pr2[j]; x5 = pr2[j+1];
			
			x2 -= c; x3 -= c;
			x5 -= c;
			
			x2 *= x2; x3 *= x3;
			x5 *= x5;
			
			f = x2 + x3 + x5 ;
			f /= 3.f;
			prOut[j] = sqrtf(f);
		}
			
		for(j = 1; j < width - 1; j++) // bottom side
		{
			x1 = pr1[j-1]; x2 = pr1[j]; x3 = pr1[j+1];
			x4 = pr2[j-1]; c = pr2[j]; x5 = pr2[j+1];
			
			x1 -= c; x2 -= c; x3 -= c;
			x4 -= c; x5 -= c;
			
			x1 *= x1; x2 *= x2; x3 *= x3;
			x4 *= x4; x5 *= x5;
			
			f = x1 + x2 + x3 + x4 + x5 ;
			f /= 5.f;
			prOut[j] = sqrtf(f);
		}
		
		j = width - 1; // bottom right corner
		{
			x1 = pr1[j-1]; x2 = pr1[j]; 
			x4 = pr2[j-1]; c = pr2[j]; 
			
			x1 -= c; x2 -= c;
			x4 -= c;
			
			x1 *= x1; x2 *= x2; 
			x4 *= x4; 
						
			f = x1 + x2 + x4 ;
			f /= 3.f;
			prOut[j] = sqrtf(f);
		}
	}
}