trace.cpp revision 858615d1932c56e345ea988a0fe971bf17f68845
/*
* A generic interface for plugging different
* autotracers into Inkscape.
*
* Authors:
* Bob Jamison <rjamison@earthlink.net>
* Jon A. Cruz <jon@joncruz.org>
* Abhishek Sharma
*
* Copyright (C) 2004-2006 Bob Jamison
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#include "trace/potrace/inkscape-potrace.h"
#include "inkscape.h"
#include "desktop.h"
#include "document.h"
#include "document-undo.h"
#include "message-stack.h"
#include "selection.h"
#include "xml/attribute-record.h"
#include "sp-item.h"
#include "sp-shape.h"
#include "sp-image.h"
#include "verbs.h"
#include "display/cairo-utils.h"
#include "display/drawing-shape.h"
#include "siox.h"
#include "imagemap-gdk.h"
namespace Inkscape {
namespace Trace {
{
if (!desktop)
{
g_warning("Trace: No active desktop");
return NULL;
}
if (!sel)
{
char *msg = _("Select an <b>image</b> to trace");
//g_warning(msg);
return NULL;
}
if (sioxEnabled)
{
sioxShapes.clear();
/*
First, things are selected top-to-bottom, so we need to invert
them as bottom-to-top so that we can discover the image and any
SPItems above it
*/
{
if (!SP_IS_ITEM(*i))
{
continue;
}
}
{
if (SP_IS_IMAGE(item))
{
if (img) //we want only one
{
char *msg = _("Select only one <b>image</b> to trace");
return NULL;
}
}
else // if (img) //# items -after- the image in tree (above it in Z)
{
if (SP_IS_SHAPE(item))
{
}
}
}
{
char *msg = _("Select one image and one or more shapes above it");
return NULL;
}
return img;
}
else
//### SIOX not enabled. We want exactly one image selected
{
if (!item)
{
//g_warning(msg);
return NULL;
}
if (!SP_IS_IMAGE(item))
{
char *msg = _("Select an <b>image</b> to trace");
//g_warning(msg);
return NULL;
}
return img;
}
}
class TraceSioxObserver : public SioxObserver
{
public:
/**
*
*/
TraceSioxObserver (void *contextArg) :
{}
/**
*
*/
virtual ~TraceSioxObserver ()
{ }
/**
* Informs the observer how much has been completed.
* Return false if the processing should be aborted.
*/
virtual bool progress(float /*percentCompleted*/)
{
//Tracer *tracer = (Tracer *)context;
//## Allow the GUI to update
return true;
}
/**
* Send an error string to the Observer. Processing will
* be halted.
*/
{
//Tracer *tracer = (Tracer *)context;
}
};
Glib::RefPtr<Gdk::Pixbuf> Tracer::sioxProcessImage(SPImage *img, Glib::RefPtr<Gdk::Pixbuf>origPixbuf)
{
if (!sioxEnabled)
return origPixbuf;
if (origPixbuf == lastOrigPixbuf)
return lastSioxPixbuf;
//g_message("siox: start");
//Convert from gdk, so a format we know. By design, the pixel
//format in PackedPixelMap is identical to what is needed by SIOX
if (!desktop)
{
}
if (!sel)
{
char *msg = _("Select an <b>image</b> to trace");
//g_warning(msg);
}
//g_message("img: %d %d %d %d\n", aImg->bbox.x0, aImg->bbox.y0,
// aImg->bbox.x1, aImg->bbox.y1);
{
}
//g_message("%d arena items\n", arenaItems.size());
//PackedPixelMap *dumpMap = PackedPixelMapCreate(
// simage.getWidth(), simage.getHeight());
//g_message("siox: start selection");
{
{
//Get absolute X,Y position
//point *= imgMat;
//point = desktop->doc2dt(point);
//g_message("x:%f y:%f\n", point[0], point[1]);
bool weHaveAHit = false;
{
{
weHaveAHit = true;
break;
}
}
if (weHaveAHit)
{
//g_message("hit!\n");
//dumpMap->setPixelLong(dumpMap, col, row, 0L);
}
else
{
//g_message("miss!\n");
//dumpMap->setPixelLong(dumpMap, col, row,
// simage.getPixel(col, row));
}
}
}
//g_message("siox: selection done");
//dumpMap->writePPM(dumpMap, "siox1.ppm");
//dumpMap->destroy(dumpMap);
//## ok we have our pixel buf
TraceSioxObserver observer(this);
{
}
//result.writePPM("siox2.ppm");
//g_message("siox: done");
return newPixbuf;
}
{
if (!img)
}
if (sioxEnabled)
{
if (!sioxPixbuf)
{
return pixbuf;
}
else
{
return sioxPixbuf;
}
}
else
{
return pixbuf;
}
}
//#########################################################################
//# T R A C E
//#########################################################################
{
}
void Tracer::traceThread()
{
//## Remember. NEVER leave this method without setting
//## engine back to NULL
//## Prepare our kill flag. We will watch this later to
//## see if the main thread wants us to stop
keepGoing = true;
if (!desktop)
{
g_warning("Trace: No active desktop\n");
return;
}
if (!SP_ACTIVE_DOCUMENT)
{
char *msg = _("Trace: No active document");
//g_warning(msg);
return;
}
doc->ensureUpToDate();
if (!img)
{
return;
}
}
if (!pixbuf)
{
char *msg = _("Trace: Image has no bitmap data");
//g_warning(msg);
return;
}
//printf("nrPaths:%d\n", results.size());
//### Check if we should stop
{
return;
}
//### Get pointers to the <image> and its parent
//XML Tree being used directly here while it shouldn't be.
//### Get some information for the new transform()
double x = 0.0;
double y = 0.0;
double width = 0.0;
double height = 0.0;
double dval = 0.0;
x = dval;
y = dval;
//# Convolve scale, translation, and the original transform
//#OK. Now let's start making new nodes
//# if more than 1, make a <g>roup of <path>s
if (nrPaths > 1)
{
}
long totalNodeCount = 0L;
{
if (nrPaths > 1)
else
//### Apply the transform from the image to the new shape
if (reprobj)
{
}
if (nrPaths == 1)
{
}
}
// If we have a group, then focus on, then forget it
if (nrPaths > 1)
{
}
//## inform the document, so we can undo
}
{
//Check if we are already running
if (engine)
return;
#if HAVE_THREADS
//Ensure that thread support is running
if (!Glib::thread_supported())
Glib::thread_init();
//Create our thread and run it
#else
traceThread();
#endif
}
{
//## Inform Trace's working thread
keepGoing = false;
if (engine)
{
}
}
} // namespace Trace
} // namespace Inkscape
//#########################################################################
//# E N D O F F I L E
//#########################################################################