21 "Computes vector representation of input raster image.";
23 static const string MODE_KW =
"mode";
24 static const string ALPHAMAX_KW =
"alphamax";
25 static const string TURDSIZE_KW =
"turdsize";
28 : m_mode (LINESTRING),
31 m_outputToConsole(false),
52 usageString +=
" potrace [options] <input-raster-file> [<output-vector-file>]";
57 "set the corner threshold parameter. The default value is 1. The smaller this value, the " 58 "more sharp corners will be produced. If this parameter is 0, then no smoothing will be " 59 "performed and the output is a polygon. If this parameter is greater than 1.3, then all " 60 "corners are suppressed and the output is completely smooth");
62 "Specifies whether to represent foreground-background boundary as polygons or line-strings" 63 ". Polygons are closed regions surrounding either null or non-null pixels. Most viewers " 64 "will represent polygons as solid blobs. Line-strings only outline the boundary but do not" 65 " maintain sense of \"insideness\"");
67 "Use the raster file provided as a mask to exclude any vertices found within 1 pixel of " 68 "a null mask pixel. Implies linestring mode since polygons may not be closed. The mask " 69 "should be a single-band image, but if multi-band, only band 0 will be referenced.");
81 if ( ap.
read(
"--alphamax", sp1))
84 if ( ap.
read(
"--mode", sp1))
87 if ( ap.
read(
"--mask", sp1))
95 if ( ap.
read(
"--turdsize", sp1))
126 else if (value.
contains(
"linestring"))
128 else if (!value.
empty())
130 xmsg <<
"ossimPotraceTool:"<<__LINE__<<
" Unallowed mode requested: <"<<value<<
">." 154 xmsg<<
"ossimPotraceTool:"<<__LINE__<<
" Null input image list encountered! ";
176 xmsg <<
"ossimPotraceTool:"<<__LINE__<<
" Null pointer returned from potrace_trace!";
212 vector<Path*> originalPaths;
213 vector<Path*> adjustedPaths;
223 for (
int segment=0; segment<path->
curve.
n; ++segment)
228 originalPaths.push_back(p);
232 free(delete_this_path);
237 for (
size_t i=0; i<originalPaths.size(); ++i)
239 Path* original = originalPaths[i];
240 bool outside =
false;
244 for (
size_t v=0; v<original->
vertices.size(); ++v)
252 adjustedPaths.push_back(adjusted);
255 adjusted->
vertices.push_back(imgPt);
281 vector<Path*>::iterator path_iter = adjustedPaths.begin();
282 while (path_iter != adjustedPaths.end())
285 Path* adjusted = *path_iter;
298 previous_path->
next = path;
300 potraceOutput->
plist = path;
302 int num_segments = (adjusted->
vertices.size()+1)/2;
303 path->
curve.
n = num_segments;
305 path->
curve.
tag =
new int[num_segments];
316 while (adj_v < adjusted->vertices.size())
321 imgPt = adjusted->
vertices[adj_v++];
327 if (adj_v == adjusted->
vertices.size())
336 imgPt = adjusted->
vertices[adj_v++];
350 previous_path = path;
367 for (
int segment=0; segment<path->
curve.
n;)
371 for (
int v=0; v<3; ++v)
379 imgPt.
x = path->
curve.
c[segment][v].
x;
380 imgPt.
y = path->
curve.
c[segment][v].
y;
396 value <<
"polygon|linestring (optional, defaults to polygon)";
397 kwl.
addPair(MODE_KW, value.str());
400 value<<
"<float> (optional, defaults to "<<
m_alphamax<<
")";
401 kwl.
addPair(ALPHAMAX_KW, value.str());
404 value<<
"<int> (optional, defaults to "<<
m_turdSize<<
")";
405 kwl.
addPair(TURDSIZE_KW, value.str());
407 kwl.
add(
"image_file0",
"<input-raster-file>");
408 kwl.
add(
"image_file1",
"<mask-file> (optional)");
419 potraceBitmap->
w = rect.
width();
420 potraceBitmap->
h = rect.
height();
421 int pixelsPerWord = 8 *
sizeof(
int*);
422 potraceBitmap->
dy = (int) ceil((
double)rect.
width()/pixelsPerWord);
425 unsigned long bufLength = potraceBitmap->
dy*potraceBitmap->
h;
432 unsigned long offset=0;
441 if (pt_lr.
x > rect.
lr().
x)
442 pt_lr.
x = rect.
lr().
x;
443 if (pt_lr.
y > rect.
lr().
y)
444 pt_lr.
y = rect.
lr().
y;
447 for (pt.
y=pt_ul.
y; pt.
y < pt_lr.
y; ++pt.
y)
449 offset = pt_ul.
x/pixelsPerWord + pt.
y*potraceBitmap->
dy;
450 for (pt.
x=pt_ul.
x; pt.
x<pt_lr.
x; )
453 unsigned long wordBuf = 0;
454 for (
int bitpos=pixelsPerWord-1; bitpos>=0; --bitpos)
456 unsigned long pixel = (tile->
getPix(pt) != null_pix) ? 1 : 0;
457 wordBuf |= pixel << bitpos;
462 potraceBitmap->
map[offset++] = wordBuf;
470 FILE* pbm = fopen(
"TEMP.pbm",
"w");
474 return potraceBitmap;
482 int pixelsPerWord = 8 *
sizeof(
int*);
483 unsigned long offset = image_pt.
x/pixelsPerWord + image_pt.
y*bitmap->
dy;
484 int shift = pixelsPerWord - (image_pt.
x % pixelsPerWord) - 1;
485 unsigned long wordBuf = bitmap->
map[offset];
486 unsigned long shifted = wordBuf >> shift;
487 shifted = shifted & 1;
500 xmsg <<
"ossimPotraceTool:"<<__LINE__<<
" Could not open output file <"<<
m_productFilename 511 if (vectorFile.fail())
513 xmsg <<
"ossimPotraceTool:"<<__LINE__<<
" Error encountered opening temporary vector file at: " 539 vertices.push_back(v1);
540 vertices.push_back(v2);
557 c = curve.
c[segment-1];
571 for (
int i=0; i<8; i++)
574 vertex.
x = s*s*s*v0.
x + 3*(s*s*t)*v1.
x + 3*(t*t*s)*v2.
x + t*t*t*v3.
x;
575 vertex.
y = s*s*s*v0.
y + 3*(s*s*t)*v1.
y + 3*(t*t*s)*v2.
y + t*t*t*v3.
y;
576 vertices.push_back(vertex);
int potrace_geojson(FILE *fout, potrace_path_t *plist, int as_polygons)
virtual ossim_uint32 getWidth() const
std::string getApplicationName() const
return the application name, as specified by argv[0]
void addCommandLineOption(const ossimString &option, const ossimString &explanation)
std::basic_ostringstream< char > ostringstream
Class for char output memory streams.
static const char * OUTPUT_FILE_KW
Represents serializable keyword/value map.
const std::string & findKey(const std::string &key) const
Find methods that take std::string(s).
std::basic_ifstream< char > ifstream
Class for char input file streams.
bool read(const std::string &str)
search for an occurance of a string in the argument list, on sucess remove that occurance from the li...
void getBoundingRect(ossimIrect &bounding_rect) const
Get the bounding rect of (0, 0) to (imageSize.x-1, imageSize.y-1).
ossim_uint32 height() const
bool contains(char aChar) const
virtual ossimRefPtr< ossimImageData > getNextTile(ossim_uint32 resLevel=0)
void addList(const ossimKeywordlist &src, bool overwrite=true)
struct potrace_path_s * childlist
virtual ossim_uint32 getHeight() const
void addPair(const std::string &key, const std::string &value, bool overwrite=true)
void setCommandLineUsage(const ossimString &explanation)
virtual ossim_float64 getPix(const ossimIpt &position, ossim_uint32 band=0) const
Will return the pixel at location position.
void potrace_writepbm(FILE *fout, potrace_bitmap_t *bm)
ossimApplicationUsage * getApplicationUsage()
potrace_state_t * potrace_trace(const potrace_param_t *param, const potrace_bitmap_t *bm)
const ossimIrect & expand(const ossimIpt &padding)
struct potrace_bitmap_s potrace_bitmap_t
unsigned long potrace_word
void add(const char *prefix, const ossimKeywordlist &kwl, bool overwrite=true)
struct potrace_path_s * next
bool localToWorld(const ossimDpt &local_pt, ossimGpt &world_pt) const
Exposes the 3D projection from image to world coordinates.
virtual const ossim_float64 * getNullPix() const
const char * chars() const
For backward compatibility.
struct potrace_privpath_s * priv
const ossimIpt & lr() const
ossim_uint32 width() const
virtual ossimRefPtr< ossimImageGeometry > getImageGeometry()
Returns the image geometry object associated with this tile source or NULL if not defined...
struct potrace_path_s * sibling
struct potrace_path_s potrace_path_t
potrace_param_t * potrace_param_default(void)
static const char * IMAGE_FILE_KW
virtual const ossimIpt & getOrigin() const
bool pointWithin(const ossimIpt &pt) const