1 #pragma once 2 3 #ifndef VECTORIZERPOPUP_H 4 #define VECTORIZERPOPUP_H 5 6 #include <memory> 7 8 // TnzCore includes 9 #include "tvectorimage.h" 10 11 // TnzLib includes 12 #include "toonz/txshsimplelevel.h" 13 #include "toonz/tcenterlinevectorizer.h" 14 15 // TnzQt includes 16 #include "toonzqt/dvdialog.h" 17 18 // Qt includes 19 #include <QWidget> 20 #include <QThread> 21 22 //==================================================== 23 24 // Forward declarations 25 26 class QComboBox; 27 class QPushButton; 28 class QLabel; 29 class QSlider; 30 class QShowEvent; 31 class QHideEvent; 32 class ProgressDialog; 33 class TXshSimpleLevel; 34 class Vectorizer; 35 class TSceneHandle; 36 class OverwriteDialog; 37 class VectorizerSwatchArea; 38 39 namespace DVGui { 40 class IntField; 41 class MeasuredDoubleLineEdit; 42 class ColorField; 43 class CheckBox; 44 } // namespace DVGui 45 46 //==================================================== 47 48 //***************************************************************************** 49 // VectorizerPopup declaration 50 //***************************************************************************** 51 52 /*! 53 \brief The "Convert-To-Vector Settings" popup window. 54 55 \details Vectorization interface is segmented among 3 main classes: \p 56 VectorizerPopup, 57 \p Vectorizer, and \p VectorizerCore. \p VectorizerPopup represents 58 the 59 outermost layer, providing a suitable user interface to choose 60 between 61 available vectorization modes and options, and displays a progress 62 dialog 63 to inform about the status of the underlying process. 64 65 In order to launch a suitable vectorization process, an Xsheet or 66 scene 67 cast selection must be active; then the \p show() method should be 68 called to 69 let the user choose the preferred vectorization options. Each 70 parameter 71 set is passed down to a \p VectorizerConfiguration class, so see 72 there for 73 more detailed explanations. The \p apply() method can be 74 alternatively 75 called for default options, avoiding user interaction. 76 77 During the process, the progress bar dialog is set on modal 78 behaviour, in 79 order to prevent the user from modifying or removing the frames to 80 be 81 vectorized. 82 83 \sa The \p VectorizerConfiguration, \p Vectorizer and \p VectorizerCore 84 classes. 85 */ 86 87 class VectorizerPopup final : public DVGui::Dialog { 88 Q_OBJECT 89 90 public: 91 #if QT_VERSION >= 0x050500 92 VectorizerPopup(QWidget *parent = 0, Qt::WindowFlags flags = Qt::Tool); 93 #else 94 VectorizerPopup(QWidget *parent = 0, Qt::WFlags flags = Qt::Tool); 95 #endif 96 97 bool apply(); //!< The main vectorization method - prepares input 98 //! configuration and runs the vectorization thread. 99 bool isLevelToConvert(TXshSimpleLevel *level); //!< Verifies if specified 100 //! level supports 101 //! vectorization. 102 103 signals: 104 105 void valuesChanged(); 106 107 public slots: 108 109 void onOk(); //!< Invokes \p apply(), and closes the popup once done. 110 111 private: 112 QComboBox *m_typeMenu; 113 QPushButton *m_okBtn; 114 QFrame *m_paramsWidget; 115 QGridLayout *m_paramsLayout; 116 117 // Centerline Options 118 119 QLabel *m_cThresholdLabel; 120 DVGui::IntField *m_cThreshold; 121 122 QLabel *m_cAccuracyLabel; 123 DVGui::IntField *m_cAccuracy; 124 125 QLabel *m_cDespecklingLabel; 126 DVGui::IntField *m_cDespeckling; 127 128 QLabel *m_cMaxThicknessLabel; 129 DVGui::IntField *m_cMaxThickness; 130 131 QLabel *m_cThicknessRatioLabel; 132 // DVGui::IntField* m_cThicknessRatio; 133 134 QLabel *m_cThicknessRatioFirstLabel; 135 DVGui::MeasuredDoubleLineEdit *m_cThicknessRatioFirst; 136 137 QLabel *m_cThicknessRatioLastLabel; 138 DVGui::MeasuredDoubleLineEdit *m_cThicknessRatioLast; 139 140 DVGui::CheckBox *m_cMakeFrame; 141 142 DVGui::CheckBox *m_cPaintFill; 143 144 DVGui::CheckBox *m_cAlignBoundaryStrokesDirection; 145 146 DVGui::Separator *m_cNaaSourceSeparator; 147 148 DVGui::CheckBox *m_cNaaSource; 149 150 // Outline Options 151 152 QLabel *m_oDespecklingLabel; 153 DVGui::IntField *m_oDespeckling; 154 155 QLabel *m_oAccuracyLabel; 156 DVGui::IntField *m_oAccuracy; 157 158 QLabel *m_oPaintFillLabel; 159 DVGui::CheckBox *m_oPaintFill; 160 161 DVGui::CheckBox *m_oAlignBoundaryStrokesDirection; 162 163 DVGui::Separator *m_oCornersSeparator; 164 165 QLabel *m_oAdherenceLabel; 166 DVGui::IntField *m_oAdherence; 167 168 QLabel *m_oAngleLabel; 169 DVGui::IntField *m_oAngle; 170 171 QLabel *m_oRelativeLabel; 172 DVGui::IntField *m_oRelative; 173 174 DVGui::Separator *m_oFullColorSeparator; 175 176 QLabel *m_oMaxColorsLabel; 177 DVGui::IntField *m_oMaxColors; 178 179 QLabel *m_oTransparentColorLabel; 180 DVGui::ColorField *m_oTransparentColor; 181 182 DVGui::Separator *m_oTlvSeparator; 183 184 QLabel *m_oToneThresholdLabel; 185 DVGui::IntField *m_oToneThreshold; 186 187 // Other stuff 188 189 Vectorizer *m_vectorizer; 190 191 VectorizerSwatchArea *m_swatchArea; 192 DVGui::ProgressDialog *m_progressDialog; 193 194 int m_currFrame; 195 196 TSceneHandle *m_sceneHandle; 197 198 private: 199 VectorizerParameters *getParameters() const; 200 201 void setType( 202 bool outline); //!< Changes the window appearance depending on \p m_type. 203 204 void loadConfiguration( 205 bool isOutline); //!< Loads VectorizerConfiguration into the popup. 206 void loadRanges(int outline); 207 208 void updateVisibility(); 209 210 void showEvent(QShowEvent *) override; 211 void hideEvent(QHideEvent *) override; 212 213 private slots: 214 215 void onTypeChange(int type); //!< Stores the active vectorization \p type 216 //! name, and calls \p setType(). 217 218 void onFrameName(QString frameName); 219 void onFrameDone(int frameCount); 220 221 void onPartialDone(int partial, int total); //!< Partial progress \p partial 222 //! of \p total was done for 223 //! current frame. 224 void onFinished(); 225 226 void updateSceneSettings(); 227 void refreshPopup(); 228 229 void onValueEdited(bool isDrag = false); onValueEdited(const TPixel32 &,bool isDrag)230 void onValueEdited(const TPixel32 &, bool isDrag) { onValueEdited(isDrag); } 231 232 void populateVisibilityMenu(); 233 void visibilityToggled(); 234 235 void saveParameters(); 236 void loadParameters(); 237 void resetParameters(); 238 }; 239 240 //***************************************************************************** 241 // Vectorizer declaration 242 //***************************************************************************** 243 244 /*! 245 \brief The thread encapsulating a core vectorization process. 246 247 \details The \p Vectorizer class serves as a medium between Xsheets and the 248 low-level 249 vectorization methods: each frame of the input level is processed by 250 \p VectorizerCore methods and the output is then stored on free 251 xsheet cells. 252 253 Signals are also excanghed through this class, ensuring basic 254 communications 255 between the invoker (typically \p VectorizerPopup) and the \p 256 VectorizerCore 257 class. 258 259 Since vectorization is typically a complex and resource-consuming 260 task, 261 \p Vectorizer also inherits a \p QThread in order to avoid system 262 freezes. 263 264 \sa The \p VectorizerPopup, \p VectorizerConfiguration and \p 265 VectorizerCore 266 classes. 267 */ 268 269 class Vectorizer final : public QThread { 270 Q_OBJECT 271 272 public: 273 Vectorizer(); 274 ~Vectorizer(); 275 getVectorizedLevel()276 TXshSimpleLevel *getVectorizedLevel() const { return m_vLevel.getPointer(); } 277 278 void setLevel(const TXshSimpleLevelP &level); //!< Stores current level and 279 //! creates a new vector level. 280 setParameters(const VectorizerParameters & params)281 void setParameters( 282 const VectorizerParameters ¶ms) //! Stores vectorizer parameters. 283 { 284 m_params = params; 285 } 286 setFids(const std::vector<TFrameId> & fids)287 void setFids(const std::vector<TFrameId> 288 &fids) //! Stores the frame ids to be processed. 289 { 290 m_fids = fids, std::sort(m_fids.begin(), m_fids.end()); 291 } 292 isCanceled()293 bool isCanceled() { 294 return m_isCanceled; 295 } //!< Tells whether vectorization was canceled. 296 297 signals: 298 299 //! Frame name is emitted at beginning of a frame vectorization 300 //! to be displayed above the progress bar 301 void frameName(QString); 302 void frameDone(int); 303 304 //! Forwards the VectorizerCore::partialDone(int,int) signal. 305 void partialDone(int, int); 306 307 //! Transmits a user cancel downward to VectorizerCore. 308 void transmitCancel(); 309 310 void configurationChanged(); 311 312 public slots: 313 cancel()314 void cancel() { m_isCanceled = true; } 315 316 protected: 317 /*! \details Remember that \b each of the above \a set methods \b must 318 be called before invoking run(). */ 319 320 void run() override; //!< Starts the vectorization thread (see QThread 321 //! documentation). 322 323 private: 324 TXshSimpleLevelP m_level; //!< Input level to vectorize (only one level at a 325 //! time is dealt here). 326 VectorizerParameters m_params; //!< Vectorizer options to be applied 327 328 TXshSimpleLevelP m_vLevel; //!< Output vectorized level 329 std::vector<TFrameId> m_fids; //!< Frame ids of the input \b m_level 330 331 std::unique_ptr<OverwriteDialog> 332 m_dialog; //!< Dialog to be shown for overwrite resolution. 333 334 bool m_isCanceled, //!< User cancels set this flag to true 335 m_dialogShown; //!< Whether \p m_dialog was shown for current 336 //! vectorization. 337 338 private: 339 int doVectorize(); //!< Start vectorization of input frames. 340 341 //! Makes connections to low-level partial progress signals and cancel slots, 342 //! and invokes the low-level vectorization of \b img. 343 TVectorImageP doVectorize(TImageP img, TPalette *palette, 344 const VectorizerConfiguration &conf); 345 }; 346 347 #endif // VECTORIZERPOPUP_H 348