Skip to content

Commit

Permalink
removed rotrect code
Browse files Browse the repository at this point in the history
  • Loading branch information
rtv committed Apr 4, 2012
1 parent f0e1c49 commit 102e412
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 146 deletions.
100 changes: 0 additions & 100 deletions libstage/stage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,24 +51,6 @@ const Color Color::magenta( 1,0,1 );
const Color Color::cyan( 0,1,1 );


// static inline uint8_t* pb_get_pixel( Fl_Shared_Image* img,
// const unsigned int x,
// const unsigned int y )
// {
// uint8_t* pixels = (uint8_t*)(img->data()[0]);
// const unsigned int index = (y * img->w() * img->d()) + (x * img->d());
// return( pixels + index );
// }

// // returns true if the value in the first channel is above threshold
// static inline bool pb_pixel_is_set( Fl_Shared_Image* img,
// const unsigned int x,
// const unsigned int y,
// const unsigned int threshold )
// {
// return( pb_get_pixel( img,x,y )[0] > threshold );
// }

// set all the pixels in a rectangle
static inline void pb_set_rect( Fl_Shared_Image* pb,
const unsigned int x, const unsigned int y,
Expand Down Expand Up @@ -99,88 +81,6 @@ static inline bool pixel_is_set( uint8_t* pixels,
return( (pixels + (y*width*depth) + x*depth)[0] > threshold );
}

int Stg::rotrects_from_image_file( const std::string& filename,
std::vector<rotrect_t>& rects )
{
// TODO: make this a parameter
const int threshold = 127;

Fl_Shared_Image *img = Fl_Shared_Image::get(filename.c_str());
if( img == NULL )
{
std::cerr << "failed to open file: " << filename << std::endl;

assert( img ); // easy access to this point in debugger
exit(-1);
}

//printf( "loaded image %s w %d h %d d %d count %d ld %d\n",
// filename, img->w(), img->h(), img->d(), img->count(), img->ld() );

const unsigned int width = img->w();
const unsigned height = img->h();
const unsigned int depth = img->d();
uint8_t* pixels = (uint8_t*)img->data()[0];

for(unsigned int y = 0; y < height; y++)
{
for(unsigned int x = 0; x < width; x++)
{
// skip blank (white) pixels
if( pixel_is_set( pixels, width, depth, x, y, threshold) )
continue;

// a rectangle starts from this point
const unsigned int startx = x;
const unsigned int starty = y;
unsigned int rheight = height; // assume full height for starters

// grow the width - scan along the line until we hit an empty (white) pixel
for( ; x < width && ! pixel_is_set( pixels, width, depth, x, y, threshold); x++ )
{
// look down to see how large a rectangle below we can make
unsigned int yy = y;
//while( ! pb_pixel_is_set(img,x,yy,threshold) && (yy < height-1) )
while( ! pixel_is_set( pixels, width, depth, x, yy, threshold) && (yy < height-1) )
yy++;

// now yy is the depth of a line of non-zero pixels
// downward we store the smallest depth - that'll be the
// height of the rectangle
if( yy-y < rheight ) rheight = yy-y; // shrink the height to fit
}

// whiten the pixels we have used in this rect
pb_set_rect( img, startx, starty, x-startx, rheight, 0xFF );

// y-invert all the rectangles because we're using conventional
// rather than graphics coordinates. this is much faster than
// inverting the original image.

rotrect_t latest;
latest.pose.x = startx;
latest.pose.y = height-1 - (starty + rheight);
latest.pose.a = 0.0;
latest.size.x = x - startx;
latest.size.y = rheight;

assert( latest.pose.x >= 0 );
assert( latest.pose.y >= 0 );
assert( latest.pose.x <= width );
assert( latest.pose.y <= height);

rects.push_back( latest );

//printf( "rect %d (%.2f %.2f %.2f %.2f %.2f\n",
// *rect_count,
// latest->x, latest->y, latest->a, latest->w, latest->h );

}
}

if( img ) img->release(); // frees all resources for this image
return 0; // ok
}

double direction( double a )
{
Expand Down
73 changes: 27 additions & 46 deletions libstage/stage.hh
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ namespace Stg
typedef Model* (*creator_t)( World*, Model*, const std::string& type );

/** Initialize the Stage library. Stage will parse the argument
array looking for parameters in the conventnioal way. */
array looking for parameters in the conventional way. */
void Init( int* argc, char** argv[] );

/** returns true iff Stg::Init() has been called. */
Expand Down Expand Up @@ -197,7 +197,7 @@ namespace Stg
class Color
{
public:
double r,g,b,a;
float r,g,b,a;

Color( double r, double g, double b, double a=1.0 );

Expand Down Expand Up @@ -240,8 +240,7 @@ namespace Stg
Size& Load( Worldfile* wf, int section, const char* keyword );
void Save( Worldfile* wf, int section, const char* keyword ) const;

void Zero()
{ x=y=z=0.0; }
void Zero() { x=y=z=0.0; }
};

/** Specify a 3 axis position, in x, y and heading. */
Expand Down Expand Up @@ -314,9 +313,11 @@ namespace Stg
}

// a < b iff a is closer to the origin than b
bool operator<( const Pose& other ) const
bool operator<( const Pose& p ) const
{
return( hypot( y, x ) < hypot( other.y, other.x ));
//return( hypot( y, x ) < hypot( otHer.y, other.x ));
// just compare the squared values to avoid the sqrt()
return( (y*y+x*x) < (p.y*p.y + p.x*p.x ));
}

bool operator==( const Pose& other ) const
Expand All @@ -333,13 +334,12 @@ namespace Stg
y!=other.y ||
z!=other.z ||
a!=other.a );
}

meters_t Distance2D( const Pose& other ) const
{
return hypot( x-other.x, y-other.y );
}
}

meters_t Distance( const Pose& other ) const
{
return hypot( x-other.x, y-other.y );
}
};


Expand All @@ -363,18 +363,18 @@ namespace Stg
Velocity()
{ /*empty*/ }

/** Print velocity in human-readable format on stdout, with a
prefix string
@param prefix Character string to prepend to output, or NULL.
*/

Velocity& Load( Worldfile* wf, int section, const char* keyword )
{
Pose::Load( wf, section, keyword );
return *this;
Pose::Load( wf, section, keyword );
return *this;
}

/** Print velocity in human-readable format on stdout, with a
prefix string
@param prefix Character string to prepend to output, or NULL.
*/
virtual void Print( const char* prefix ) const
{
if( prefix )
Expand Down Expand Up @@ -601,13 +601,8 @@ namespace Stg
Size size;
} rotrect_t; // rotated rectangle

/** load the image file [filename] and convert it to an array of
rectangles, filling in the number of rects, width and
height. The vector [rects] is populated with rectangles.
*/
int rotrects_from_image_file( const std::string& filename,
std::vector<rotrect_t>& rects );

/** load the image file [filename] and convert it to a vector of polygons
*/
int polys_from_image_file( const std::string& filename,
std::vector<std::vector<point_t> >& polys );

Expand Down Expand Up @@ -1218,7 +1213,7 @@ namespace Stg
friend class Canvas;
friend class Cell;
public:

/** Block Constructor. A model's body is a list of these
blocks. The point data is copied, so pts can safely be freed
after constructing the block.*/
Expand Down Expand Up @@ -1275,8 +1270,8 @@ namespace Stg
unsigned int width, unsigned int height,
meters_t cellwidth, meters_t cellheight );

private:
BlockGroup* group; ///< The BlockGroup to which this Block belongs.
private:
std::vector<point_t> pts; ///< points defining a polygon.
Bounds local_z; ///< z extent in local coords.
Bounds global_z; ///< z extent in global coordinates.
Expand All @@ -1301,8 +1296,10 @@ namespace Stg
private:
std::vector<Block> blocks; ///< Contains the blocks in this group.
int displaylist; ///< OpenGL displaylist that renders this blockgroup.
Model& mod;

public: Model& mod;

private:
void AppendBlock( const Block& block );

void CalcSize();
Expand Down Expand Up @@ -1499,7 +1496,7 @@ namespace Stg
friend class Option;

private:

Canvas* canvas;
std::vector<Option*> drawOptions;
FileManager* fileMan; ///< Used to load and save worldfiles
Expand Down Expand Up @@ -2319,12 +2316,6 @@ namespace Stg
/** set the pose of model in global coordinates */
void SetGlobalPose( const Pose& gpose );

/** Enable update of model pose according to velocity state */
// void VelocityEnable();

/** Disable update of model pose according to velocity state */
//void VelocityDisable();

/** set a model's pose in its parent's coordinate system */
void SetPose( const Pose& pose );

Expand Down Expand Up @@ -2454,13 +2445,6 @@ namespace Stg

static std::map< std::string, creator_t> name_map;

// class Neighbors
// {
// Model *left, *right, *up, *down;
// public:
// Neighbors() : left(NULL), right(NULL), up(NULL), down(NULL) {}
// } nbors; // instance

protected:
virtual void Startup();
virtual void Shutdown();
Expand All @@ -2469,8 +2453,6 @@ namespace Stg


// BLOBFINDER MODEL --------------------------------------------------------


/// %ModelBlobfinder class
class ModelBlobfinder : public Model
{
Expand Down Expand Up @@ -2971,7 +2953,6 @@ namespace Stg
// destructor
~ModelPosition();


/** Get (a copy of) the model's velocity in its local reference
frame. */
Velocity GetVelocity() const { return velocity; }
Expand Down

0 comments on commit 102e412

Please sign in to comment.