| #pragma once |
| |
| #ifndef TVECTORIMAGE_INCLUDED |
| #define TVECTORIMAGE_INCLUDED |
| |
| #include <memory> |
| |
| #include "timage.h" |
| |
| |
| #include "traster.h" |
| #include "tstream.h" |
| |
| #include <set> |
| |
| #undef DVAPI |
| #undef DVVAR |
| #ifdef TVECTORIMAGE_EXPORTS |
| #define DVAPI DV_EXPORT_API |
| #define DVVAR DV_EXPORT_VAR |
| #else |
| #define DVAPI DV_IMPORT_API |
| #define DVVAR DV_IMPORT_VAR |
| #endif |
| |
| |
| #define DISEGNO_OUTLINE 0 |
| |
| |
| |
| class TVectorImageP; |
| class TStroke; |
| class TRegion; |
| class TRegionId; |
| class TColorStyle; |
| class TVectorRenderData; |
| class TRegionId; |
| class TFilledRegionInf; |
| namespace TThread { |
| class Mutex; |
| } |
| |
| |
| |
| #define REGION_COMPUTING_PRECISION 128.0 |
| |
| const double c_newAutocloseTolerance = 1.15; |
| |
| |
| |
| class VIStroke; |
| |
| |
| |
| |
| |
| |
| class DVAPI TVectorImage final : public TImage { |
| class Imp; |
| int pickGroup(const TPointD &pos, bool onEnteredGroup) const; |
| |
| public: |
| std::unique_ptr<Imp> m_imp; |
| |
| struct IntersectionBranch { |
| int m_strokeIndex; |
| int m_style; |
| double m_w; |
| UINT m_currInter; |
| UINT m_nextBranch; |
| bool m_gettingOut; |
| }; |
| |
| TVectorImage(bool loaded = false); |
| virtual ~TVectorImage(); |
| |
| TImage::Type getType() const override { return VECTOR; } |
| |
| |
| |
| |
| void validateRegions(bool state = false); |
| |
| |
| |
| bool areValidRegions(); |
| |
| |
| TVectorImageP clone() const; |
| |
| |
| TImage *cloneImage() const override; |
| |
| |
| void transform(const TAffine &aff, bool doChangeThickness = false); |
| |
| |
| |
| void putRegion(TRegion *region); |
| |
| |
| UINT getRegionCount() const; |
| |
| TRegion *getRegion(UINT index) const; |
| |
| TRegion *getRegion(TRegionId) const; |
| |
| |
| TRegion *findRegion(const TRegion ®ion) const; |
| |
| |
| void findRegions(const TRectD &rect); |
| |
| |
| UINT getStrokeCount() const; |
| |
| TStroke *getStroke(UINT index) const; |
| |
| VIStroke *getVIStroke(UINT index) const; |
| |
| VIStroke *getStrokeById(int id) const; |
| |
| |
| int getStrokeIndexById(int id) const; |
| |
| |
| int getStrokeIndex(TStroke *stroke) const; |
| |
| |
| |
| void group(int fromIndex, int count); |
| |
| |
| |
| int ungroup(int index); |
| |
| bool isStrokeGrouped(UINT index) const { return getGroupDepth(index) > 0; } |
| |
| |
| |
| |
| int getGroupDepth(UINT index) const; |
| |
| |
| |
| |
| bool sameSubGroup(int strokeIndex0, int strokeIndex1) const; |
| |
| int getCommonGroupDepth(int strokeIndex0, int strokeIndex1) const; |
| |
| |
| |
| |
| |
| |
| int areDifferentGroup(UINT index1, bool isRegion1, UINT index2, |
| bool isRegion2) const; |
| |
| |
| |
| bool sameParentGroupStrokes(UINT index1, UINT index2) const { |
| int ret = areDifferentGroup(index1, false, index2, false); |
| return (ret == -1 || ret >= 1); |
| } |
| |
| bool sameGroup(UINT index1, UINT index2) const { |
| return areDifferentGroup(index1, false, index2, false) == -1; |
| } |
| |
| bool sameGroupStrokeAndRegion(UINT strokeIndex, UINT regionIndex) const { |
| return areDifferentGroup(strokeIndex, false, regionIndex, true) == -1; |
| } |
| |
| |
| bool inCurrentGroup(int strokeIndex) const; |
| bool canEnterGroup(int strokeIndex) const; |
| bool selectable(int strokeIndex) const; |
| bool enterGroup(int index); |
| |
| |
| |
| int exitGroup(); |
| bool isEnteredGroupStroke(int index) const; |
| bool canMoveStrokes(int strokeIndex, int count, int moveBefore) const; |
| |
| int isInsideGroup() const; |
| |
| int pickGroup(const TPointD &pos) const; |
| int getGroupByStroke(UINT index) const; |
| int getGroupByRegion(UINT index) const; |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| bool getNearestStroke(const TPointD &p, |
| |
| |
| double &outw, UINT &strokeIndex, double &dist2, |
| bool inCurrentGroup = true) const; |
| |
| |
| static void enableStrokeStyle(int index, bool enable); |
| |
| static bool isStrokeStyleEnabled(int index); |
| |
| |
| |
| TStroke *removeStroke(int index, bool doComputeRegions = true); |
| |
| |
| |
| void removeStrokes(const std::vector<int> &tobeRemoved, bool deleteThem, |
| bool recomputeRegions); |
| |
| |
| void deleteStroke(int index); |
| |
| void deleteStroke(VIStroke *stroke); |
| |
| |
| |
| int addStroke(TStroke *, bool discardPoints = true); |
| int addStrokeToGroup(TStroke *stroke, int strokeIndex); |
| |
| void replaceStroke(int index, TStroke *newStroke); |
| |
| |
| void insertStrokeAt(VIStroke *vs, int strokeIndex, |
| bool recomputeRegions = true); |
| |
| |
| |
| |
| |
| void moveStrokes(int fromIndex, int count, int moveBefore); |
| |
| void findRegions(); |
| |
| |
| |
| |
| #if defined(LINUX) || defined(FREEBSD) || defined(MACOSX) |
| void render(const TVectorRenderData &rd, TRaster32P &ras); |
| #endif |
| |
| |
| |
| TRaster32P render(bool onlyStrokes); |
| |
| |
| TRegion *getRegion(const TPointD &p); |
| |
| |
| |
| int fill(const TPointD &p, int styleId, bool onlyEmpty = false); |
| |
| |
| |
| |
| |
| |
| bool selectFill(const TRectD &selectArea, TStroke *s, int styleId, |
| bool onlyUnfilled, bool fillAreas, bool fillLines); |
| |
| |
| void areaFill(TStroke *stroke, int styleIndex, bool onlyUnfilled); |
| |
| |
| int fillStrokes(const TPointD &p, int newStyleId); |
| |
| |
| bool isComputedRegionAlmostOnce() const; |
| |
| |
| TRectD getBBox() const override; |
| |
| |
| |
| |
| void notifyChangedStrokes(const std::vector<int> &strokeIndexArray, |
| const std::vector<TStroke *> &oldStrokeArray, |
| bool areFlipped = false); |
| |
| |
| void notifyChangedStrokes(int strokeIndex, TStroke *oldStroke = 0, |
| bool isFlipped = false); |
| |
| UINT getFillData(std::unique_ptr<IntersectionBranch[]> &v); |
| void setFillData(std::unique_ptr<IntersectionBranch[]> const &v, UINT size, |
| bool doComputeRegions = true); |
| |
| void drawAutocloses(const TVectorRenderData &rd) const; |
| |
| |
| |
| |
| |
| |
| void enableRegionComputing(bool enabled, bool notIntersectingStrokes); |
| |
| |
| |
| |
| void enableMinimizeEdges(bool enabled); |
| |
| |
| |
| |
| |
| TVectorImageP splitSelected(bool removeFlag); |
| |
| |
| int mergeImage(const TVectorImageP &img, const TAffine &affine, |
| bool sameStrokeId = true); |
| |
| int mergeImage(const TVectorImageP &img, const TAffine &affine, |
| const std::map<int, int> &styleTable, |
| bool sameStrokeId = true); |
| |
| void mergeImage(const std::vector<const TVectorImage *> &images); |
| |
| |
| void insertImage(const TVectorImageP &img, |
| const std::vector<int> &dstIndices); |
| TVectorImageP splitImage(const std::vector<int> &indices, bool removeFlag); |
| |
| |
| void getUsedStyles(std::set<int> &styles) const; |
| |
| void reassignStyles(std::map<int, int> &table); |
| |
| |
| |
| static void transferStrokeColors(TVectorImageP sourceImage, int sourceStroke, |
| TVectorImageP destinationImage, |
| int destinationStroke); |
| |
| |
| void setEdgeColors(int strokeIndex, int leftColorIndex, int rightColorIndex); |
| |
| |
| |
| |
| |
| |
| |
| |
| void splitStroke(int strokeIndex, |
| const std::vector<DoublePair> &sortedWRanges); |
| VIStroke *joinStroke(int index1, int index2, int cpIndex1, int cpIndex2, |
| bool isSmooth); |
| VIStroke *extendStroke(int index, const TThickPoint &p, int cpIndex, |
| bool isSmooth); |
| |
| |
| |
| |
| TStroke *removeEndpoints(int strokeIndex); |
| |
| |
| |
| |
| void restoreEndpoints(int index, TStroke *oldStroke); |
| |
| |
| void setAutocloseTolerance(double val); |
| |
| double getAutocloseTolerance() const; |
| |
| |
| |
| void recomputeRegionsIfNeeded(); |
| |
| |
| |
| void eraseStyleIds(const std::vector<int> styleIds); |
| |
| TThread::Mutex *getMutex() const; |
| |
| #ifdef _DEBUG |
| void checkIntersections(); |
| #endif |
| |
| void computeRegion(const TPointD &p, int styleId); |
| |
| #ifdef NEW_REGION_FILL |
| void resetRegionFinder(); |
| #endif |
| |
| private: |
| TVectorImage(const TVectorImage &); |
| TVectorImage &operator=(const TVectorImage &); |
| }; |
| |
| DVAPI VIStroke *cloneVIStroke(VIStroke *vs); |
| DVAPI void deleteVIStroke(VIStroke *vs); |
| |
| DVAPI void getClosingPoints(const TRectD &rect, double fac, |
| const TVectorImageP &vi, |
| std::vector<std::pair<int, double>> &startPoints, |
| std::vector<std::pair<int, double>> &endPoints); |
| |
| |
| |
| #ifdef _WIN32 |
| template class DVAPI TSmartPointerT<TVectorImage>; |
| template class DVAPI TDerivedSmartPointerT<TVectorImage, TImage>; |
| #endif |
| |
| class DVAPI TVectorImageP final |
| : public TDerivedSmartPointerT<TVectorImage, TImage> { |
| public: |
| TVectorImageP() {} |
| TVectorImageP(TVectorImage *image) : DerivedSmartPointer(image) {} |
| TVectorImageP(TImageP image) : DerivedSmartPointer(image) {} |
| #if !defined(_WIN32) |
| TVectorImageP(TImage *image) : DerivedSmartPointer(TImageP(image)) {} |
| #endif |
| operator TImageP() { return TImageP(m_pointer); } |
| }; |
| |
| |
| |
| |
| #if defined(LINUX) || defined(FREEBSD) |
| DVAPI void hardRenderVectorImage(const TVectorRenderData &rd, TRaster32P &r, |
| const TVectorImageP &vimg); |
| #endif |
| |
| |
| |
| |
| class DVAPI TInputStreamInterface { |
| public: |
| TInputStreamInterface() {} |
| virtual ~TInputStreamInterface() {} |
| |
| virtual TInputStreamInterface &operator>>(double &) = 0; |
| virtual TInputStreamInterface &operator>>(int &) = 0; |
| virtual TInputStreamInterface &operator>>(std::string &) = 0; |
| virtual TInputStreamInterface &operator>>(UCHAR &) = 0; |
| virtual TInputStreamInterface &operator>>(USHORT &) = 0; |
| virtual TInputStreamInterface &operator>>(TRaster32P &) = 0; |
| virtual TInputStreamInterface &operator>>(TPixel32 &pixel); |
| |
| virtual VersionNumber versionNumber() const { return VersionNumber(); } |
| }; |
| |
| |
| |
| class DVAPI TOutputStreamInterface { |
| public: |
| TOutputStreamInterface() {} |
| virtual ~TOutputStreamInterface() {} |
| |
| virtual TOutputStreamInterface &operator<<(double) = 0; |
| virtual TOutputStreamInterface &operator<<(int) = 0; |
| virtual TOutputStreamInterface &operator<<(std::string) = 0; |
| virtual TOutputStreamInterface &operator<<(UCHAR) = 0; |
| virtual TOutputStreamInterface &operator<<(USHORT) = 0; |
| virtual TOutputStreamInterface &operator<<(const TRaster32P &) = 0; |
| virtual TOutputStreamInterface &operator<<(const TPixel32 &pixel); |
| }; |
| |
| #if DISEGNO_OUTLINE == 1 |
| extern int CurrStrokeIndex; |
| #include "tvectorimage.h" |
| extern const TVectorImage *CurrVimg; |
| #else |
| #ifndef DISEGNO_OUTLINE |
| *&^&%^^$%&^%$(^( |
| #endif |
| #endif |
| |
| #endif |