trace.cpp revision 2b635337710b879262acf4906dd85ee99b69f474
/**
* A generic interface for plugging different
* autotracers into Inkscape.
*
* Authors:
* Bob Jamison <rjamison@earthlink.net>
*
* 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 <desktop-handles.h>
#include <document.h>
#include <message-stack.h>
#include <gtkmm.h>
#include <selection.h>
#include <xml/attribute-record.h>
#include <sp-item.h>
#include <sp-shape.h>
#include <sp-image.h>
#include <libnr/nr-matrix-ops.h>
#include <display/nr-arena.h>
#include <display/nr-arena-shape.h>
#include "siox.h"
#include "imagemap-gdk.h"
namespace Inkscape
{
namespace Trace
{
/**
* Get the selected image. Also check for any SPItems over it, in
* case the user wants SIOX pre-processing.
*/
SPImage *
{
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
*/
{
{
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;
}
};
/**
* Process a GdkPixbuf, according to which areas have been
* obscured in the GUI.
*/
{
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)
{
g_warning(_("Trace: No active 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);
{
g_warning(_("Invalid SIOX result"));
}
//result.writePPM("siox2.ppm");
/* Free Arena and ArenaItem */
/*
std::vector<NRArenaItem *>::iterator aIter;
for (aIter = arenaItems.begin() ; aIter!=arenaItems.end() ; aIter++)
{
NRArenaItem *arenaItem = *aIter;
nr_arena_item_unref(arenaItem);
}
nr_object_unref((NRObject *) arena);
*/
//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
//#########################################################################
/**
* Whether we want to enable SIOX subimage selection
*/
{
}
/**
* Threaded method that does single bitmap--->path conversion
*/
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->ensure_up_to_date();
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
//### 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
}
/**
* Main tracing method
*/
{
//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
}
/**
* Abort the thread that is executing trace()
*/
{
//## Inform Trace's working thread
keepGoing = false;
if (engine)
{
}
}
} // namespace Trace
} // namespace Inkscape
//#########################################################################
//# E N D O F F I L E
//#########################################################################