correction of the image distance field generation

This commit is contained in:
Edouard DUPIN 2012-09-06 18:39:06 +02:00
parent bfba3999b5
commit b3f1a97a28
2 changed files with 17 additions and 7 deletions

View File

@ -306,12 +306,14 @@ void draw::Image::DistanceField(Vector2D<int32_t> pos, Vector2D<int32_t> size)
{ {
Grid grid1(size); Grid grid1(size);
Grid grid2(size); Grid grid2(size);
grid1.SetOutsideVal(50); grid1.SetOutsideVal(500000);
grid2.SetOutsideVal(50); grid2.SetOutsideVal(500000);
grid1.SetErrorVal(0);
grid2.SetErrorVal(500000);
Vector2D<int32_t> tmpPos; Vector2D<int32_t> tmpPos;
for(tmpPos.y=0 ; tmpPos.y<size.x ; tmpPos.y++ ) { for(tmpPos.y=0 ; tmpPos.y<size.y ; tmpPos.y++ ) {
for(tmpPos.x=0 ; tmpPos.x<size.y ; tmpPos.x++ ) { for(tmpPos.x=0 ; tmpPos.x<size.x ; tmpPos.x++ ) {
draw::Color tmpColor = Get(pos+tmpPos); draw::Color tmpColor = Get(pos+tmpPos);
// Points inside get marked with a x/y of zero. // Points inside get marked with a x/y of zero.
// Points outside get marked with an infinitely large distance. // Points outside get marked with an infinitely large distance.
@ -329,8 +331,8 @@ void draw::Image::DistanceField(Vector2D<int32_t> pos, Vector2D<int32_t> size)
GenerateSDF( grid1 ); GenerateSDF( grid1 );
GenerateSDF( grid2 ); GenerateSDF( grid2 );
for(tmpPos.y=0 ; tmpPos.y<size.x ; tmpPos.y++ ) { for(tmpPos.y=0 ; tmpPos.y<size.y ; tmpPos.y++ ) {
for(tmpPos.x=0 ; tmpPos.x<size.y ; tmpPos.x++ ) { for(tmpPos.x=0 ; tmpPos.x<size.x ; tmpPos.x++ ) {
Vector2D<int32_t> elem1 = grid1.Get(tmpPos); Vector2D<int32_t> elem1 = grid1.Get(tmpPos);
Vector2D<int32_t> elem2 = grid2.Get(tmpPos); Vector2D<int32_t> elem2 = grid2.Get(tmpPos);
// Calculate the actual distance from the x/y // Calculate the actual distance from the x/y

View File

@ -50,10 +50,12 @@ class Grid
Vector2D<int32_t> m_size; Vector2D<int32_t> m_size;
etk::Vector<Vector2D<int32_t> > m_data; etk::Vector<Vector2D<int32_t> > m_data;
int32_t m_outsideVal; int32_t m_outsideVal;
int32_t m_errorVal;
Grid(Vector2D<int32_t> size) Grid(Vector2D<int32_t> size)
{ {
m_size = size; m_size = size;
m_outsideVal = 20; m_outsideVal = 20;
m_errorVal = 0;
// basic element : // basic element :
Vector2D<int32_t> tmpPoint(0,0); Vector2D<int32_t> tmpPoint(0,0);
// preallocate data with a basic bg elements : // preallocate data with a basic bg elements :
@ -64,6 +66,10 @@ class Grid
{ {
m_outsideVal = newVal; m_outsideVal = newVal;
} }
void SetErrorVal(int32_t newVal)
{
m_errorVal = newVal;
}
void SetInide(Vector2D<int32_t> pos) void SetInide(Vector2D<int32_t> pos)
{ {
if( pos.x>=0 && pos.x<m_size.x if( pos.x>=0 && pos.x<m_size.x
@ -88,7 +94,7 @@ class Grid
&& pos.y>0 && pos.y<m_size.y) { && pos.y>0 && pos.y<m_size.y) {
return m_data[pos.x+pos.y*m_size.x]; return m_data[pos.x+pos.y*m_size.x];
} }
return Vector2D<int32_t>(0,0); return Vector2D<int32_t>(m_errorVal,m_errorVal);
}; };
void Set(Vector2D<int32_t> pos, Vector2D<int32_t> val) void Set(Vector2D<int32_t> pos, Vector2D<int32_t> val)
@ -238,6 +244,8 @@ namespace draw
// generate the distant field from the alpha value of the Image // generate the distant field from the alpha value of the Image
void DistanceField(void); void DistanceField(void);
void DistanceField(Vector2D<int32_t> pos, Vector2D<int32_t> size); void DistanceField(Vector2D<int32_t> pos, Vector2D<int32_t> size);
void SaveFile(const char * file) {};
private: private: