From: ishmal Date: Sun, 26 Mar 2006 04:00:16 +0000 (+0000) Subject: most of region selection completed X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=56f61e36105050ffd48acd3984664d9994231456;p=inkscape.git most of region selection completed --- diff --git a/src/trace/siox.cpp b/src/trace/siox.cpp index b210606b1..be1dd3995 100644 --- a/src/trace/siox.cpp +++ b/src/trace/siox.cpp @@ -926,7 +926,7 @@ static std::vector createSignature(std::vector &input, //## S I O X S E G M E N T A T O R (originally SioxSegmentator.java) //######################################################################## -//### NOTE: Doxygen comments are in siox-segmentator.h +//### NOTE: Doxygen comments are in siox.h /** Confidence corresponding to a certain foreground region (equals one). */ const float SioxSegmentator::CERTAIN_FOREGROUND_CONFIDENCE=1.0f; diff --git a/src/trace/trace.cpp b/src/trace/trace.cpp index f28b42d2b..2e46dd854 100644 --- a/src/trace/trace.cpp +++ b/src/trace/trace.cpp @@ -15,14 +15,18 @@ #include "trace/potrace/inkscape-potrace.h" #include +#include #include #include -#include "message-stack.h" +#include #include #include #include -#include "sp-item.h" -#include "sp-image.h" +#include +#include +#include +#include +#include //for intersection boolop #include "siox.h" #include "imagemap-gdk.h" @@ -57,8 +61,9 @@ Tracer::getSelectedSPImage() { SPImage *img = NULL; GSList const *list = sel->itemList(); - sioxItems.clear(); std::vector items; + 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 @@ -89,19 +94,23 @@ Tracer::getSelectedSPImage() } else if (img) //# items -after- the image in tree (above it in Z) { - sioxItems.push_back(item); + if (SP_IS_SHAPE(item)) + { + SPShape *shape = SP_SHAPE(item); + sioxShapes.push_back(shape); + } } } - if (!img || sioxItems.size() < 1) + if (!img || sioxShapes.size() < 1) { - char *msg = _("Select one image and one or more items above it"); + char *msg = _("Select one image and one or more shapes above it"); SP_DT_MSGSTACK(desktop)->flash(Inkscape::ERROR_MESSAGE, msg); return NULL; } return img; } else - //### No SIOX. We want exactly one image selected + //### SIOX not enabled. We want exactly one image selected { SPItem *item = sel->singleItem(); if (!item) @@ -158,6 +167,92 @@ Tracer::sioxProcessImage(SPImage *img, GdkPixbuf *origPixbuf) unsigned long *imgBuf = ppMap->pixels; float *confidenceMatrix = new float[ppMap->width * ppMap->height]; + Inkscape::XML::Node *imgRepr = SP_OBJECT(img)->repr; + /* + //## Make a Rect overlaying the image + Inkscape::XML::Node *parent = imgRepr->parent(); + + Inkscape::XML::Node *rect = sp_repr_new("svg:rect"); + Inkscape::Util::List attr = + imgRepr->attributeList(); + for ( ; attr ; attr++) + { + rect->setAttribute(g_quark_to_string(attr->key), attr->value, false); + } + + + //Inkscape::XML::Node *rect = imgRepr->duplicate(); + parent->appendChild(rect); + Inkscape::GC::release(rect); + */ + + //### element + double x = 0.0; + double y = 0.0; + double width = 0.0; + double height = 0.0; + double dval = 0.0; + + if (sp_repr_get_double(imgRepr, "x", &dval)) + x = dval; + if (sp_repr_get_double(imgRepr, "y", &dval)) + y = dval; + + if (sp_repr_get_double(imgRepr, "width", &dval)) + width = dval; + if (sp_repr_get_double(imgRepr, "height", &dval)) + height = dval; + + double iwidth = (double)ppMap->width; + double iheight = (double)ppMap->height; + + double iwscale = width / iwidth; + double ihscale = height / iheight; + + SPDesktop *desktop = SP_ACTIVE_DESKTOP; + + unsigned long cmIndex = 0; + for (int row=0 ; rowheight ; row++) + { + double ypos = y + ihscale * (double) row; + for (int col=0 ; colwidth ; col++) + { + //Get absolute X,Y position + double xpos = x + iwscale * (double)col; + NR::Point point(xpos, ypos); + point *= img->transform; + point = desktop->doc2dt(point); + std::vector::iterator iter; + g_message("x:%f y:%f\n", point[0], point[1]); + SPItem *itemOverPoint = desktop->item_at_point(point, false, NULL); + int weHaveAHit = false; + if (itemOverPoint) + { + printf("searching\n"); + for (iter = sioxShapes.begin() ; iter!=sioxShapes.end() ; iter++) + { + SPShape *shape = *iter; + if (shape == itemOverPoint) + { + weHaveAHit = true; + break; + } + } + } + if (weHaveAHit) + { + g_message("hit!\n"); + confidenceMatrix[cmIndex] = + org::siox::SioxSegmentator::CERTAIN_FOREGROUND_CONFIDENCE; + } + else + { + confidenceMatrix[cmIndex] = + org::siox::SioxSegmentator::CERTAIN_BACKGROUND_CONFIDENCE; + } + cmIndex++; + } + } //## ok we have our pixel buf org::siox::SioxSegmentator ss(ppMap->width, ppMap->height, NULL, 0); diff --git a/src/trace/trace.h b/src/trace/trace.h index 6de2d8c1a..d59ad13a6 100644 --- a/src/trace/trace.h +++ b/src/trace/trace.h @@ -27,6 +27,7 @@ #include #include +#include struct SPImage; struct SPItem; @@ -230,7 +231,7 @@ private: SPImage *getSelectedSPImage(); - std::vector sioxItems; + std::vector sioxShapes; bool sioxEnabled;