Blame synfig-studio/src/synfigapp/vectorizer/centerlinevectorizer.cpp

Ankit Kumar Dwivedi 0944d7
/* === S Y N F I G ========================================================= */
Ankit Kumar Dwivedi b59311
/*!	\file centerlinevectorizer.cpp
Ankit Kumar Dwivedi b59311
**	\brief This is the entry point of centerline vectorization
Ankit Kumar Dwivedi 0944d7
**
Ankit Kumar Dwivedi 0944d7
**	$Id$
Ankit Kumar Dwivedi 0944d7
**
Ankit Kumar Dwivedi 0944d7
**	\legal
Ankit Kumar Dwivedi 0944d7
**	Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
Ankit Kumar Dwivedi 0944d7
**
Ankit Kumar Dwivedi 0944d7
**	This package is free software; you can redistribute it and/or
Ankit Kumar Dwivedi 0944d7
**	modify it under the terms of the GNU General Public License as
Ankit Kumar Dwivedi 0944d7
**	published by the Free Software Foundation; either version 2 of
Ankit Kumar Dwivedi 0944d7
**	the License, or (at your option) any later version.
Ankit Kumar Dwivedi 0944d7
**
Ankit Kumar Dwivedi 0944d7
**	This package is distributed in the hope that it will be useful,
Ankit Kumar Dwivedi 0944d7
**	but WITHOUT ANY WARRANTY; without even the implied warranty of
Ankit Kumar Dwivedi 0944d7
**	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Ankit Kumar Dwivedi 0944d7
**	General Public License for more details.
Ankit Kumar Dwivedi 0944d7
**	\endlegal
Ankit Kumar Dwivedi 0944d7
*/
Ankit Kumar Dwivedi 0944d7
/* ========================================================================= */
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi 0944d7
/* === H E A D E R S ======================================================= */
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi 0944d7
#ifdef USING_PCH
Ankit Kumar Dwivedi 0944d7
#	include "pch.h"
Ankit Kumar Dwivedi 0944d7
#else
Ankit Kumar Dwivedi 0944d7
#ifdef HAVE_CONFIG_H
Ankit Kumar Dwivedi 0944d7
#	include <config.h></config.h>
Ankit Kumar Dwivedi 0944d7
#endif
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi 0944d7
#include "centerlinevectorizer.h"
Ankit Kumar Dwivedi 989a09
#include "polygonizerclasses.h"
Ankit Kumar Dwivedi 85181c
#include <synfig layer.h=""></synfig>
ankit-kumar-dwivedi 471c96
#include <synfig debug="" log.h=""></synfig>
Ankit Kumar Dwivedi 0944d7
#endif
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi 0944d7
/* === U S I N G =========================================================== */
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi 0944d7
using namespace std;
Ankit Kumar Dwivedi 0944d7
using namespace etl;
a4bbdd
using namespace synfig;
Ankit Kumar Dwivedi 0944d7
using namespace studio;
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi 0944d7
/* === M A C R O S ========================================================= */
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi 0944d7
/* === G L O B A L S ======================================================= */
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi 0944d7
/* === P R O C E D U R E S ================================================= */
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi 0944d7
/* === M E T H O D S ======================================================= */
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi 295555
inline void deleteSkeletonList(SkeletonList *skeleton) {
Ankit Kumar Dwivedi 295555
  unsigned int i;
Ankit Kumar Dwivedi 295555
  for (i = 0; i < skeleton->size(); ++i) delete (*skeleton)[i];
Ankit Kumar Dwivedi 295555
Ankit Kumar Dwivedi 295555
  delete skeleton;
Ankit Kumar Dwivedi 295555
}
Ankit Kumar Dwivedi 295555
Ankit Kumar Dwivedi 295555
Ankit Kumar Dwivedi 0944d7
/* === E N T R Y P O I N T ================================================= */
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi 0944d7
//************************
Ankit Kumar Dwivedi 0944d7
//*    Vectorizer Main   *
Ankit Kumar Dwivedi 0944d7
//************************
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi b59311
// takes two arguments ( image layer handle, config )
ankit-kumar-dwivedi 2e10e1
ankit-kumar-dwivedi 2e10e1
std::vector< etl::handle<synfig::layer> > </synfig::layer>
ankit-kumar-dwivedi 05419c
VectorizerCore::centerlineVectorize(etl::handle<synfig::layer_bitmap> &image,const etl::handle<synfigapp::uiinterface> &ui_interface, </synfigapp::uiinterface></synfig::layer_bitmap>
ankit-kumar-dwivedi 05419c
const CenterlineConfiguration &configuration,const Gamma &gamma)
Ankit Kumar Dwivedi 0944d7
 {
ankit-kumar-dwivedi 471c96
  synfig::debug::Log::info("","Inside CenterlineVectorize");
Ankit Kumar Dwivedi 0944d7
  VectorizerCoreGlobals globals;
Ankit Kumar Dwivedi 0944d7
  globals.currConfig = &configuration;
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi 0944d7
  // step 2 
Ankit Kumar Dwivedi 0944d7
  // Extracts a polygonal, minimal yet faithful representation of image contours
Ankit Kumar Dwivedi 0944d7
  Contours polygons;
Ankit Kumar Dwivedi 989a09
  studio::polygonize(image, polygons, globals);
ankit-kumar-dwivedi 2e10e1
  ui_interface->amount_complete(3,10);
ankit-kumar-dwivedi 81bea2
  
Ankit Kumar Dwivedi 0944d7
  // step 3
Ankit Kumar Dwivedi 0944d7
  // The process of skeletonization reduces all objects in an image to lines, 
Ankit Kumar Dwivedi 0944d7
  //  without changing the essential structure of the image.
ankit-kumar-dwivedi 81bea2
  SkeletonList *skeletons = studio::skeletonize(polygons,ui_interface, globals);
ankit-kumar-dwivedi 2e10e1
  ui_interface->amount_complete(6,10);
Ankit Kumar Dwivedi c9b8a4
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi ea8c72
  // step 4
Ankit Kumar Dwivedi ea8c72
  // The raw skeleton data obtained from StraightSkeletonizer
luz.paz 7040b8
  // class need to be grouped in joints and sequences before proceeding further
Ankit Kumar Dwivedi d388d7
  studio::organizeGraphs(skeletons, globals);
ankit-kumar-dwivedi 2e10e1
  ui_interface->amount_complete(8,10);
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi 0944d7
Ankit Kumar Dwivedi 85181c
  std::vector< etl::handle<synfig::layer> > sortibleResult;</synfig::layer>
Ankit Kumar Dwivedi 0944d7
  
Ankit Kumar Dwivedi 32d730
  // step 5
Ankit Kumar Dwivedi 32d730
  // Take samples of image colors to associate each sequence to its corresponding
Ankit Kumar Dwivedi 32d730
  // palette color
Ankit Kumar Dwivedi 7e2215
  //studio::calculateSequenceColors(image, globals);  // Extract stroke colors here
Ankit Kumar Dwivedi 0944d7
ankit-kumar-dwivedi 81bea2
  // step 6
ankit-kumar-dwivedi 81bea2
  // Converts each forward or single Sequence of the image in its corresponding Stroke.
1387de
  studio::conversionToStrokes(sortibleResult, globals, image);
ankit-kumar-dwivedi 2e10e1
  ui_interface->amount_complete(9,10);
ankit-kumar-dwivedi 2e10e1
Ankit Kumar Dwivedi 2bdc68
  deleteSkeletonList(skeletons);
Ankit Kumar Dwivedi d5e0ef
  return sortibleResult;
Ankit Kumar Dwivedi 0944d7
}
a4bbdd
ankit-kumar-dwivedi 2e10e1
std::vector< etl::handle<synfig::layer> > </synfig::layer>
ankit-kumar-dwivedi 05419c
VectorizerCore::vectorize(const etl::handle<synfig::layer_bitmap> &img,const etl::handle<synfigapp::uiinterface> &ui_interface, const VectorizerConfiguration &c, const Gamma &gamma) </synfigapp::uiinterface></synfig::layer_bitmap>
Ankit Kumar Dwivedi 989a09
{
Ankit Kumar Dwivedi d5e0ef
  std::vector< etl::handle<synfig::layer> > result;</synfig::layer>
Ankit Kumar Dwivedi 989a09
Ankit Kumar Dwivedi 989a09
  if (c.m_outline)
Ankit Kumar Dwivedi 989a09
  {
Ankit Kumar Dwivedi d5e0ef
    return result;
Ankit Kumar Dwivedi 989a09
  }
Ankit Kumar Dwivedi 989a09
  else 
Ankit Kumar Dwivedi 989a09
  {
Ankit Kumar Dwivedi 989a09
    Handle img2(img);
ankit-kumar-dwivedi 2e10e1
    result = centerlineVectorize(img2, ui_interface,static_cast<const &="" centerlineconfiguration="">(c), gamma);</const>
ankit-kumar-dwivedi 2e10e1
    ui_interface->amount_complete(10,10);
ankit-kumar-dwivedi 2e10e1
Ankit Kumar Dwivedi d5e0ef
    return result;
Ankit Kumar Dwivedi b59311
    
Ankit Kumar Dwivedi 989a09
  }
Ankit Kumar Dwivedi 989a09
Ankit Kumar Dwivedi 989a09
}