trace.cpp revision aa09636cf6013bccc1414407fb9af04f652b4032
/*
* 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 <selection.h>
#include <xml/attribute-record.h>
#include <sp-item.h>
#include <sp-shape.h>
#include <sp-image.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\n");
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;
}
}
{
if (!sioxEnabled)
return origPixbuf;
//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"));
return NULL;
}
if (!sel)
{
char *msg = _("Select an <b>image</b> to trace");
//g_warning(msg);
return NULL;
}
//g_message("img: %d %d %d %d\n", aImg->bbox.x0, aImg->bbox.y0,
// aImg->bbox.x1, aImg->bbox.y1);
{
//### Create ArenaItems and set transform
//nr_arena_item_set_transform(aItem, item->transform);
//g_message("%d %d %d %d\n", aItem->bbox.x0, aItem->bbox.y0,
// aItem->bbox.x1, aItem->bbox.y1);
}
//g_message("%d arena items\n", arenaItems.size());
{
{
//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");
}
else
{
}
}
}
//dumpMap->writePPM(dumpMap, "siox1.ppm");
//## ok we have our pixel buf
{
g_warning(_("Invalid SIOX result"));
return NULL;
}
//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);
*/
return newPixbuf;
}
/**
*
*/
{
if (!img)
return NULL;
if (!pixbuf)
return NULL;
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;
}
if (!img)
{
return;
}
if (!pixbuf)
{
char *msg = _("Trace: Image has no bitmap data");
//g_warning(msg);
return;
}
int nrPaths;
//printf("nrPaths:%d\n", nrPaths);
//### 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)
{
}
}
//release our pixbuf
delete results;
// 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
//#########################################################################