From 81bea2652bb1893f36169418d3ef95067445ced4 Mon Sep 17 00:00:00 2001 From: ankit-kumar-dwivedi Date: Nov 29 2019 17:41:40 +0000 Subject: complete progress bar and code cleaning --- diff --git a/synfig-studio/src/synfigapp/vectorizer/centerlineskeletonizer.cpp b/synfig-studio/src/synfigapp/vectorizer/centerlineskeletonizer.cpp index 174d0bf..df17e0e 100644 --- a/synfig-studio/src/synfigapp/vectorizer/centerlineskeletonizer.cpp +++ b/synfig-studio/src/synfigapp/vectorizer/centerlineskeletonizer.cpp @@ -175,10 +175,7 @@ public: // NOTE: Timeline construction contains the most complex part of // vectorization; - // progress bar partial notification happens there, so thisVectorizer's signal - // emission methods must be passed and used. - void build(ContourFamily &polygons, VectorizationContext &context, - VectorizerCore *thisVectorizer); + void build(ContourFamily &polygons, VectorizationContext &context); }; //========================================================================== @@ -612,8 +609,7 @@ public: //-------------------------------------------------------------------------- -void Timeline::build(ContourFamily &polygons, VectorizationContext &context, - VectorizerCore *thisVectorizer) { +void Timeline::build(ContourFamily &polygons, VectorizationContext &context) { unsigned int i, j, current; std::vector nodesToBeTreated(context.m_totalNodes); synfig::Point3 momentum, ray; @@ -633,14 +629,10 @@ void Timeline::build(ContourFamily &polygons, VectorizationContext &context, // NOTE: are edge events to be computed BEFORE split ones? for (i = 0; i < nodesToBeTreated.size(); ++i) { - // Break calculation at user cancel press - if (thisVectorizer->isCanceled()) break; Event currentEvent(nodesToBeTreated[i].m_node, &context); // Notify event calculation - // if (!nodesToBeTreated[i].m_node->hasAttribute(ContourNode::LINEAR_ADDED)) - // thisVectorizer->emitPartialDone(); if (currentEvent.m_type != Event::failure && currentEvent.m_height < maxThickness) @@ -1592,8 +1584,7 @@ inline void Event::processSpecialEvent() //------------------------------- static SkeletonGraph *skeletonize(ContourFamily ®ionContours, - VectorizationContext &context, - VectorizerCore *thisVectorizer) { + VectorizationContext &context) { SkeletonGraph *output = context.m_output = new SkeletonGraph; context.prepareContours(regionContours); @@ -1607,20 +1598,7 @@ static SkeletonGraph *skeletonize(ContourFamily ®ionContours, if (maxThickness > 0.0) // if(!currConfig->m_outline) { Timeline &timeline = context.m_timeline; - timeline.build(regionContours, context, thisVectorizer); - - if (thisVectorizer->isCanceled()) { - // Bailing out - while (!timeline.empty()) timeline.pop(); - - context.m_nodesHeap.clear(); - context.m_edgesHeap.clear(); - - context.m_linearNodesHeap.clear(); - context.m_linearEdgesHeap.clear(); - - return output; - } + timeline.build(regionContours, context); // Process timeline while (!timeline.empty()) { @@ -1685,12 +1663,11 @@ static SkeletonGraph *skeletonize(ContourFamily ®ionContours, //-------------------------------------------------------------------------- -SkeletonList* studio::skeletonize(Contours &contours, VectorizerCore *thisVectorizer, - VectorizerCoreGlobals &g) { +SkeletonList* studio::skeletonize(Contours &contours, const etl::handle &ui_interface, VectorizerCoreGlobals &g) { VectorizationContext context(&g); SkeletonList *res = new SkeletonList; - unsigned int i, j; + unsigned int i, j,contours_size = contours.size(); // Find overall number of nodes unsigned int overallNodes = 0; @@ -1698,12 +1675,11 @@ SkeletonList* studio::skeletonize(Contours &contours, VectorizerCore *thisVector for (j = 0; j < contours[i].size(); ++j) overallNodes += contours[i][j].size(); - //thisVectorizer->setOverallPartials(overallNodes); - - for (i = 0; i < contours.size(); ++i) { - res->push_back(skeletonize(contours[i], context, thisVectorizer)); - if (thisVectorizer->isCanceled()) break; + for (i = 0; i push_back(skeletonize(contours[i], context)); + float partial = 30.0 + ((i/(float)contours_size)*30.0); + ui_interface->amount_complete(partial,100); } return res; diff --git a/synfig-studio/src/synfigapp/vectorizer/centerlinevectorizer.cpp b/synfig-studio/src/synfigapp/vectorizer/centerlinevectorizer.cpp index 8f8cac8..3c29d9b 100644 --- a/synfig-studio/src/synfigapp/vectorizer/centerlinevectorizer.cpp +++ b/synfig-studio/src/synfigapp/vectorizer/centerlinevectorizer.cpp @@ -82,21 +82,13 @@ VectorizerCore::centerlineVectorize(etl::handle &image,con Contours polygons; studio::polygonize(image, polygons, globals); ui_interface->amount_complete(3,10); + // step 3 // The process of skeletonization reduces all objects in an image to lines, // without changing the essential structure of the image. - - // Most time-consuming part of vectorization, 'this' is passed to inform of - // partial progresses - SkeletonList *skeletons = studio::skeletonize(polygons, this, globals); + SkeletonList *skeletons = studio::skeletonize(polygons,ui_interface, globals); ui_interface->amount_complete(6,10); - if (isCanceled()) - { - // Clean and return 0 at cancel command - deleteSkeletonList(skeletons); - std::cout<<"CenterlineVectorize cancelled\n"; - } // step 4 // The raw skeleton data obtained from StraightSkeletonizer @@ -104,19 +96,16 @@ VectorizerCore::centerlineVectorize(etl::handle &image,con studio::organizeGraphs(skeletons, globals); ui_interface->amount_complete(8,10); -// // junctionRecovery(polygons); //Da' problemi per maxThickness > sortibleResult; -// TVectorImageP result; // step 5 // Take samples of image colors to associate each sequence to its corresponding // palette color //studio::calculateSequenceColors(image, globals); // Extract stroke colors here -// // step 6 -// // Converts each forward or single Sequence of the image in its corresponding Stroke. + // step 6 + // Converts each forward or single Sequence of the image in its corresponding Stroke. studio::conversionToStrokes(sortibleResult, globals, image); ui_interface->amount_complete(9,10); @@ -131,16 +120,12 @@ VectorizerCore::vectorize(const etl::handle &img,const etl if (c.m_outline) { - std::cout<<"newOutlineVectorize called/n"; - // vi = newOutlineVectorize(img, static_cast(c), plt); return result; } else { Handle img2(img); - result = centerlineVectorize(img2, ui_interface,static_cast(c), gamma); - std::cout<<"After centerlineVectorize result.size(): "<amount_complete(10,10); return result;