diff --git a/DiagramRecognizer/DiagramRecognizer b/DiagramRecognizer/DiagramRecognizer new file mode 100755 index 0000000..f307475 Binary files /dev/null and b/DiagramRecognizer/DiagramRecognizer differ diff --git a/DiagramRecognizer/DiagramRecognizer.pro b/DiagramRecognizer/DiagramRecognizer.pro index b75983b..4824c21 100644 --- a/DiagramRecognizer/DiagramRecognizer.pro +++ b/DiagramRecognizer/DiagramRecognizer.pro @@ -19,7 +19,17 @@ SOURCES += main.cpp\ simpleFormsInitializer.cpp \ recognizers/mixedGesturesManager.cpp \ recognizers/nearestPosGridGesturesManager.cpp \ - recognizers/rectangleGesturesManager.cpp + recognizers/rectangleGesturesManager.cpp \ + newfigure.cpp \ + segmentator.cpp \ + connectedComponent.cpp \ + graph.cpp \ + field.cpp \ + eFigure.cpp \ + eLink.cpp \ + section.cpp \ + figure.cpp \ + link.cpp HEADERS += \ geometricForms.h \ @@ -28,17 +38,25 @@ HEADERS += \ recognizers/curveKeyBuilder.h \ output.h \ component.h \ - figure.h \ - edge.h \ diagramRecognizer.h \ formSegmentator.h \ simpleFormsInitializer.h \ recognizers/mixedGesturesManager.h \ - recognizers/nearestPosGridGesturesmanager.h \ - recognizers/rectangleGesturesManager.h + recognizers/nearestPosGridGesturesManager.h \ + recognizers/rectangleGesturesManager.h \ + segmentator.h \ + connectedComponent.h \ + graph.h \ + field.h \ + eLink.h \ + eFigure.h \ + section.h \ + figure.h \ + link.h FORMS += OTHER_FILES += \ readme.txt \ - Conception.jpg + Conception.jpg \ + test1.txt diff --git a/DiagramRecognizer/DiagramRecognizer.pro.user b/DiagramRecognizer/DiagramRecognizer.pro.user new file mode 100644 index 0000000..ecdeab3 --- /dev/null +++ b/DiagramRecognizer/DiagramRecognizer.pro.user @@ -0,0 +1,255 @@ + + + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + qt2 + + + + QmlJS + + QmlJSGlobal + + + 2 + System + false + 4 + false + true + 1 + true + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop-Qt 4.8.4 in PATH (System) + Desktop-Qt 4.8.4 in PATH (System) + {80cdbbb9-93f9-4f50-a8cf-e65d092db33a} + 1 + 0 + 0 + + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + -r -w + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + -r -w clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Qt 4.8.4 in PATH (System) Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + /home/kraychik/Desktop/tools/DiagramRecognizer-build-desktop-Qt_4_8_4_in_PATH__System__Release + false + + + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + false + -r -w + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + + -w + -r + + true + -r -w clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Qt 4.8.4 in PATH (System) Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + /home/kraychik/Desktop/tools/DiagramRecognizer-build-desktop-Qt_4_8_4_in_PATH__System__Debug + false + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + No deployment + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + + false + false + false + false + true + 0.01 + 10 + true + 25 + + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + DiagramRecognizer + + Qt4ProjectManager.Qt4RunConfiguration:/home/Kraychik/Desktop/proj/tools/DiagramRecognizer/DiagramRecognizer.pro + 2 + + DiagramRecognizer.pro + false + false + + + 3768 + true + false + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.EnvironmentId + {c6d051b5-09f3-4d37-9c54-be836a6eed6b} + + + ProjectExplorer.Project.Updater.FileVersion + 12 + + diff --git a/DiagramRecognizer/DiagramRecognizer.pro.user.2.6pre1 b/DiagramRecognizer/DiagramRecognizer.pro.user.2.6pre1 new file mode 100644 index 0000000..569eea7 --- /dev/null +++ b/DiagramRecognizer/DiagramRecognizer.pro.user.2.6pre1 @@ -0,0 +1,242 @@ + + + + + + ProjectExplorer.Project.ActiveTarget + 0 + + + ProjectExplorer.Project.EditorSettings + + true + false + true + + Cpp + + qt2 + + + + QmlJS + + QmlJSGlobal + + + 2 + System + false + 4 + false + true + 1 + true + 0 + true + 0 + 8 + true + 1 + true + true + true + false + + + + ProjectExplorer.Project.PluginSettings + + + + ProjectExplorer.Project.Target.0 + + Desktop + Desktop + Qt4ProjectManager.Target.DesktopTarget + 1 + 0 + 0 + + ProjectExplorer.ToolChain.Gcc:{b4c9d09d-a2cc-4a44-a379-778ac272b427} + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Qt 4.8.4 in PATH (System) Release + + Qt4ProjectManager.Qt4BuildConfiguration + 0 + /home/kraychik/Desktop/tools/DiagramRecognizer-build-desktop-Qt_4_8_4_in_PATH__System__Release + 2 + false + + + ProjectExplorer.ToolChain.Gcc:{b4c9d09d-a2cc-4a44-a379-778ac272b427} + + + true + qmake + + QtProjectManager.QMakeBuildStep + false + true + + false + + + true + Make + + Qt4ProjectManager.MakeStep + false + + + + 2 + Build + + ProjectExplorer.BuildSteps.Build + + + + true + Make + + Qt4ProjectManager.MakeStep + true + clean + + + 1 + Clean + + ProjectExplorer.BuildSteps.Clean + + 2 + false + + Qt 4.8.4 in PATH (System) Debug + + Qt4ProjectManager.Qt4BuildConfiguration + 2 + /home/kraychik/Desktop/tools/DiagramRecognizer-build-desktop-Qt_4_8_4_in_PATH__System__Debug + 2 + false + + 2 + + + 0 + Deploy + + ProjectExplorer.BuildSteps.Deploy + + 1 + No deployment + + ProjectExplorer.DefaultDeployConfiguration + + 1 + + true + + false + false + false + false + true + 0.01 + 10 + true + 25 + + true + valgrind + + 0 + 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + + DiagramRecognizer + + Qt4ProjectManager.Qt4RunConfiguration + 2 + + DiagramRecognizer.pro + false + false + + + 3768 + true + false + true + + 1 + + + + ProjectExplorer.Project.TargetCount + 1 + + + ProjectExplorer.Project.Updater.EnvironmentId + {c6d051b5-09f3-4d37-9c54-be836a6eed6b} + + + ProjectExplorer.Project.Updater.FileVersion + 11 + + diff --git a/DiagramRecognizer/Makefile b/DiagramRecognizer/Makefile new file mode 100644 index 0000000..d7ed67d --- /dev/null +++ b/DiagramRecognizer/Makefile @@ -0,0 +1,446 @@ +############################################################################# +# Makefile for building: DiagramRecognizer +# Generated by qmake (2.01a) (Qt 4.8.4) on: ?? ??? 25 17:20:16 2013 +# Project: DiagramRecognizer.pro +# Template: app +# Command: /usr/bin/qmake-qt4 -spec /usr/lib/qt4/mkspecs/linux-g++ CONFIG+=debug CONFIG+=declarative_debug -o Makefile DiagramRecognizer.pro +############################################################################# + +####### Compiler, tools and options + +CC = gcc +CXX = g++ +DEFINES = -DQT_GUI_LIB -DQT_CORE_LIB -DQT_SHARED +CFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES) +CXXFLAGS = -pipe -g -Wall -W -D_REENTRANT $(DEFINES) +INCPATH = -I/usr/lib/qt4/mkspecs/linux-g++ -I. -I/usr/include/QtCore -I/usr/include/QtGui -I/usr/include -I. +LINK = g++ +LFLAGS = +LIBS = $(SUBLIBS) -L/usr/lib -lQtGui -lQtCore -lpthread +AR = ar cqs +RANLIB = +QMAKE = /usr/bin/qmake-qt4 +TAR = tar -cf +COMPRESS = gzip -9f +COPY = cp -f +SED = sed +COPY_FILE = $(COPY) +COPY_DIR = $(COPY) -r +STRIP = +INSTALL_FILE = install -m 644 -p +INSTALL_DIR = $(COPY_DIR) +INSTALL_PROGRAM = install -m 755 -p +DEL_FILE = rm -f +SYMLINK = ln -f -s +DEL_DIR = rmdir +MOVE = mv -f +CHK_DIR_EXISTS= test -d +MKDIR = mkdir -p + +####### Output directory + +OBJECTS_DIR = ./ + +####### Files + +SOURCES = main.cpp \ + bitmap.cpp \ + output.cpp \ + component.cpp \ + diagramRecognizer.cpp \ + formSegmentator.cpp \ + simpleFormsInitializer.cpp \ + recognizers/mixedGesturesManager.cpp \ + recognizers/nearestPosGridGesturesManager.cpp \ + recognizers/rectangleGesturesManager.cpp \ + newfigure.cpp \ + segmentator.cpp \ + connectedComponent.cpp \ + graph.cpp \ + field.cpp \ + eFigure.cpp \ + eLink.cpp \ + section.cpp \ + figure.cpp \ + link.cpp moc_output.cpp \ + moc_diagramRecognizer.cpp +OBJECTS = main.o \ + bitmap.o \ + output.o \ + component.o \ + diagramRecognizer.o \ + formSegmentator.o \ + simpleFormsInitializer.o \ + mixedGesturesManager.o \ + nearestPosGridGesturesManager.o \ + rectangleGesturesManager.o \ + newfigure.o \ + segmentator.o \ + connectedComponent.o \ + graph.o \ + field.o \ + eFigure.o \ + eLink.o \ + section.o \ + figure.o \ + link.o \ + moc_output.o \ + moc_diagramRecognizer.o +DIST = /usr/lib/qt4/mkspecs/common/unix.conf \ + /usr/lib/qt4/mkspecs/common/linux.conf \ + /usr/lib/qt4/mkspecs/common/gcc-base.conf \ + /usr/lib/qt4/mkspecs/common/gcc-base-unix.conf \ + /usr/lib/qt4/mkspecs/common/g++-base.conf \ + /usr/lib/qt4/mkspecs/common/g++-unix.conf \ + /usr/lib/qt4/mkspecs/qconfig.pri \ + /usr/lib/qt4/mkspecs/features/qt_functions.prf \ + /usr/lib/qt4/mkspecs/features/qt_config.prf \ + /usr/lib/qt4/mkspecs/features/exclusive_builds.prf \ + /usr/lib/qt4/mkspecs/features/default_pre.prf \ + /usr/lib/qt4/mkspecs/features/debug.prf \ + /usr/lib/qt4/mkspecs/features/default_post.prf \ + /usr/lib/qt4/mkspecs/features/declarative_debug.prf \ + /usr/lib/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \ + /usr/lib/qt4/mkspecs/features/warn_on.prf \ + /usr/lib/qt4/mkspecs/features/qt.prf \ + /usr/lib/qt4/mkspecs/features/unix/thread.prf \ + /usr/lib/qt4/mkspecs/features/moc.prf \ + /usr/lib/qt4/mkspecs/features/resources.prf \ + /usr/lib/qt4/mkspecs/features/uic.prf \ + /usr/lib/qt4/mkspecs/features/yacc.prf \ + /usr/lib/qt4/mkspecs/features/lex.prf \ + /usr/lib/qt4/mkspecs/features/include_source_dir.prf \ + DiagramRecognizer.pro +QMAKE_TARGET = DiagramRecognizer +DESTDIR = +TARGET = DiagramRecognizer + +first: all +####### Implicit rules + +.SUFFIXES: .o .c .cpp .cc .cxx .C + +.cpp.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cc.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.cxx.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.C.o: + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o "$@" "$<" + +.c.o: + $(CC) -c $(CFLAGS) $(INCPATH) -o "$@" "$<" + +####### Build rules + +all: Makefile $(TARGET) + +$(TARGET): $(OBJECTS) + $(LINK) $(LFLAGS) -o $(TARGET) $(OBJECTS) $(OBJCOMP) $(LIBS) + { test -n "$(DESTDIR)" && DESTDIR="$(DESTDIR)" || DESTDIR=.; } && test $$(gdb --version | sed -e 's,[^0-9]\+\([0-9]\)\.\([0-9]\).*,\1\2,;q') -gt 72 && gdb --nx --batch --quiet -ex 'set confirm off' -ex "save gdb-index $$DESTDIR" -ex quit '$(TARGET)' && test -f $(TARGET).gdb-index && objcopy --add-section '.gdb_index=$(TARGET).gdb-index' --set-section-flags '.gdb_index=readonly' '$(TARGET)' '$(TARGET)' && rm -f $(TARGET).gdb-index || true + +Makefile: DiagramRecognizer.pro /usr/lib/qt4/mkspecs/linux-g++/qmake.conf /usr/lib/qt4/mkspecs/common/unix.conf \ + /usr/lib/qt4/mkspecs/common/linux.conf \ + /usr/lib/qt4/mkspecs/common/gcc-base.conf \ + /usr/lib/qt4/mkspecs/common/gcc-base-unix.conf \ + /usr/lib/qt4/mkspecs/common/g++-base.conf \ + /usr/lib/qt4/mkspecs/common/g++-unix.conf \ + /usr/lib/qt4/mkspecs/qconfig.pri \ + /usr/lib/qt4/mkspecs/features/qt_functions.prf \ + /usr/lib/qt4/mkspecs/features/qt_config.prf \ + /usr/lib/qt4/mkspecs/features/exclusive_builds.prf \ + /usr/lib/qt4/mkspecs/features/default_pre.prf \ + /usr/lib/qt4/mkspecs/features/debug.prf \ + /usr/lib/qt4/mkspecs/features/default_post.prf \ + /usr/lib/qt4/mkspecs/features/declarative_debug.prf \ + /usr/lib/qt4/mkspecs/features/unix/gdb_dwarf_index.prf \ + /usr/lib/qt4/mkspecs/features/warn_on.prf \ + /usr/lib/qt4/mkspecs/features/qt.prf \ + /usr/lib/qt4/mkspecs/features/unix/thread.prf \ + /usr/lib/qt4/mkspecs/features/moc.prf \ + /usr/lib/qt4/mkspecs/features/resources.prf \ + /usr/lib/qt4/mkspecs/features/uic.prf \ + /usr/lib/qt4/mkspecs/features/yacc.prf \ + /usr/lib/qt4/mkspecs/features/lex.prf \ + /usr/lib/qt4/mkspecs/features/include_source_dir.prf \ + /usr/lib/libQtGui.prl \ + /usr/lib/libQtCore.prl + $(QMAKE) -spec /usr/lib/qt4/mkspecs/linux-g++ CONFIG+=debug CONFIG+=declarative_debug -o Makefile DiagramRecognizer.pro +/usr/lib/qt4/mkspecs/common/unix.conf: +/usr/lib/qt4/mkspecs/common/linux.conf: +/usr/lib/qt4/mkspecs/common/gcc-base.conf: +/usr/lib/qt4/mkspecs/common/gcc-base-unix.conf: +/usr/lib/qt4/mkspecs/common/g++-base.conf: +/usr/lib/qt4/mkspecs/common/g++-unix.conf: +/usr/lib/qt4/mkspecs/qconfig.pri: +/usr/lib/qt4/mkspecs/features/qt_functions.prf: +/usr/lib/qt4/mkspecs/features/qt_config.prf: +/usr/lib/qt4/mkspecs/features/exclusive_builds.prf: +/usr/lib/qt4/mkspecs/features/default_pre.prf: +/usr/lib/qt4/mkspecs/features/debug.prf: +/usr/lib/qt4/mkspecs/features/default_post.prf: +/usr/lib/qt4/mkspecs/features/declarative_debug.prf: +/usr/lib/qt4/mkspecs/features/unix/gdb_dwarf_index.prf: +/usr/lib/qt4/mkspecs/features/warn_on.prf: +/usr/lib/qt4/mkspecs/features/qt.prf: +/usr/lib/qt4/mkspecs/features/unix/thread.prf: +/usr/lib/qt4/mkspecs/features/moc.prf: +/usr/lib/qt4/mkspecs/features/resources.prf: +/usr/lib/qt4/mkspecs/features/uic.prf: +/usr/lib/qt4/mkspecs/features/yacc.prf: +/usr/lib/qt4/mkspecs/features/lex.prf: +/usr/lib/qt4/mkspecs/features/include_source_dir.prf: +/usr/lib/libQtGui.prl: +/usr/lib/libQtCore.prl: +qmake: FORCE + @$(QMAKE) -spec /usr/lib/qt4/mkspecs/linux-g++ CONFIG+=debug CONFIG+=declarative_debug -o Makefile DiagramRecognizer.pro + +dist: + @$(CHK_DIR_EXISTS) .tmp/DiagramRecognizer1.0.0 || $(MKDIR) .tmp/DiagramRecognizer1.0.0 + $(COPY_FILE) --parents $(SOURCES) $(DIST) .tmp/DiagramRecognizer1.0.0/ && $(COPY_FILE) --parents geometricForms.h bitmap.h abstractRecognizer.h recognizers/curveKeyBuilder.h output.h component.h diagramRecognizer.h formSegmentator.h simpleFormsInitializer.h recognizers/mixedGesturesManager.h recognizers/nearestPosGridGesturesManager.h recognizers/rectangleGesturesManager.h segmentator.h connectedComponent.h graph.h field.h eLink.h eFigure.h section.h figure.h link.h .tmp/DiagramRecognizer1.0.0/ && $(COPY_FILE) --parents main.cpp bitmap.cpp output.cpp component.cpp diagramRecognizer.cpp formSegmentator.cpp simpleFormsInitializer.cpp recognizers/mixedGesturesManager.cpp recognizers/nearestPosGridGesturesManager.cpp recognizers/rectangleGesturesManager.cpp newfigure.cpp segmentator.cpp connectedComponent.cpp graph.cpp field.cpp eFigure.cpp eLink.cpp section.cpp figure.cpp link.cpp .tmp/DiagramRecognizer1.0.0/ && (cd `dirname .tmp/DiagramRecognizer1.0.0` && $(TAR) DiagramRecognizer1.0.0.tar DiagramRecognizer1.0.0 && $(COMPRESS) DiagramRecognizer1.0.0.tar) && $(MOVE) `dirname .tmp/DiagramRecognizer1.0.0`/DiagramRecognizer1.0.0.tar.gz . && $(DEL_FILE) -r .tmp/DiagramRecognizer1.0.0 + + +clean:compiler_clean + -$(DEL_FILE) $(OBJECTS) + -$(DEL_FILE) *~ core *.core + + +####### Sub-libraries + +distclean: clean + -$(DEL_FILE) $(TARGET) + -$(DEL_FILE) Makefile + + +check: first + +mocclean: compiler_moc_header_clean compiler_moc_source_clean + +mocables: compiler_moc_header_make_all compiler_moc_source_make_all + +compiler_moc_header_make_all: moc_output.cpp moc_diagramRecognizer.cpp +compiler_moc_header_clean: + -$(DEL_FILE) moc_output.cpp moc_diagramRecognizer.cpp +moc_output.cpp: component.h \ + geometricForms.h \ + bitmap.h \ + formSegmentator.h \ + output.h + /usr/lib/qt4/bin/moc $(DEFINES) $(INCPATH) output.h -o moc_output.cpp + +moc_diagramRecognizer.cpp: bitmap.h \ + geometricForms.h \ + component.h \ + formSegmentator.h \ + abstractRecognizer.h \ + paintManager.h \ + field.h \ + link.h \ + eLink.h \ + eFigure.h \ + section.h \ + figure.h \ + diagramRecognizer.h + /usr/lib/qt4/bin/moc $(DEFINES) $(INCPATH) diagramRecognizer.h -o moc_diagramRecognizer.cpp + +compiler_rcc_make_all: +compiler_rcc_clean: +compiler_image_collection_make_all: qmake_image_collection.cpp +compiler_image_collection_clean: + -$(DEL_FILE) qmake_image_collection.cpp +compiler_moc_source_make_all: +compiler_moc_source_clean: +compiler_uic_make_all: +compiler_uic_clean: +compiler_yacc_decl_make_all: +compiler_yacc_decl_clean: +compiler_yacc_impl_make_all: +compiler_yacc_impl_clean: +compiler_lex_make_all: +compiler_lex_clean: +compiler_clean: compiler_moc_header_clean + +####### Compile + +main.o: main.cpp diagramRecognizer.h \ + bitmap.h \ + geometricForms.h \ + component.h \ + formSegmentator.h \ + abstractRecognizer.h \ + paintManager.h \ + field.h \ + link.h \ + eLink.h \ + eFigure.h \ + section.h \ + figure.h \ + graph.h \ + eItems.h \ + connectedComponent.h \ + segmentator.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o main.o main.cpp + +bitmap.o: bitmap.cpp bitmap.h \ + geometricForms.h \ + component.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o bitmap.o bitmap.cpp + +output.o: output.cpp output.h \ + component.h \ + geometricForms.h \ + bitmap.h \ + formSegmentator.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o output.o output.cpp + +component.o: component.cpp component.h \ + geometricForms.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o component.o component.cpp + +diagramRecognizer.o: diagramRecognizer.cpp diagramRecognizer.h \ + bitmap.h \ + geometricForms.h \ + component.h \ + formSegmentator.h \ + abstractRecognizer.h \ + paintManager.h \ + field.h \ + link.h \ + eLink.h \ + eFigure.h \ + section.h \ + figure.h \ + simpleFormsInitializer.h \ + recognizers/mixedGesturesManager.h \ + output.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o diagramRecognizer.o diagramRecognizer.cpp + +formSegmentator.o: formSegmentator.cpp formSegmentator.h \ + bitmap.h \ + geometricForms.h \ + component.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o formSegmentator.o formSegmentator.cpp + +simpleFormsInitializer.o: simpleFormsInitializer.cpp simpleFormsInitializer.h \ + geometricForms.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o simpleFormsInitializer.o simpleFormsInitializer.cpp + +mixedGesturesManager.o: recognizers/mixedGesturesManager.cpp recognizers/mixedGesturesManager.h \ + abstractRecognizer.h \ + geometricForms.h \ + paintManager.h \ + recognizers/rectangleGesturesManager.h \ + recognizers/nearestPosGridGesturesManager.h \ + recognizers/curveKeyBuilder.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o mixedGesturesManager.o recognizers/mixedGesturesManager.cpp + +nearestPosGridGesturesManager.o: recognizers/nearestPosGridGesturesManager.cpp recognizers/nearestPosGridGesturesManager.h \ + abstractRecognizer.h \ + geometricForms.h \ + paintManager.h \ + recognizers/curveKeyBuilder.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o nearestPosGridGesturesManager.o recognizers/nearestPosGridGesturesManager.cpp + +rectangleGesturesManager.o: recognizers/rectangleGesturesManager.cpp recognizers/rectangleGesturesManager.h \ + abstractRecognizer.h \ + geometricForms.h \ + paintManager.h \ + recognizers/curveKeyBuilder.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o rectangleGesturesManager.o recognizers/rectangleGesturesManager.cpp + +newfigure.o: newfigure.cpp component.h \ + geometricForms.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o newfigure.o newfigure.cpp + +segmentator.o: segmentator.cpp segmentator.h \ + figure.h \ + eFigure.h \ + section.h \ + component.h \ + geometricForms.h \ + eLink.h \ + link.h \ + graph.h \ + eItems.h \ + connectedComponent.h \ + field.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o segmentator.o segmentator.cpp + +connectedComponent.o: connectedComponent.cpp connectedComponent.h \ + component.h \ + geometricForms.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o connectedComponent.o connectedComponent.cpp + +graph.o: graph.cpp graph.h \ + eItems.h \ + component.h \ + geometricForms.h \ + connectedComponent.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o graph.o graph.cpp + +field.o: field.cpp link.h \ + eLink.h \ + component.h \ + geometricForms.h \ + eFigure.h \ + section.h \ + figure.h \ + field.h \ + segmentator.h \ + graph.h \ + eItems.h \ + connectedComponent.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o field.o field.cpp + +eFigure.o: eFigure.cpp eFigure.h \ + section.h \ + component.h \ + geometricForms.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o eFigure.o eFigure.cpp + +eLink.o: eLink.cpp eLink.h \ + component.h \ + geometricForms.h \ + eFigure.h \ + section.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o eLink.o eLink.cpp + +section.o: section.cpp section.h \ + component.h \ + geometricForms.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o section.o section.cpp + +figure.o: figure.cpp figure.h \ + eFigure.h \ + section.h \ + component.h \ + geometricForms.h \ + eLink.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o figure.o figure.cpp + +link.o: link.cpp link.h \ + eLink.h \ + component.h \ + geometricForms.h \ + eFigure.h \ + section.h + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o link.o link.cpp + +moc_output.o: moc_output.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_output.o moc_output.cpp + +moc_diagramRecognizer.o: moc_diagramRecognizer.cpp + $(CXX) -c $(CXXFLAGS) $(INCPATH) -o moc_diagramRecognizer.o moc_diagramRecognizer.cpp + +####### Install + +install: FORCE + +uninstall: FORCE + +FORCE: + diff --git a/DiagramRecognizer/abstractRecognizer.h b/DiagramRecognizer/abstractRecognizer.h index 2e0cb3a..22d1fb6 100644 --- a/DiagramRecognizer/abstractRecognizer.h +++ b/DiagramRecognizer/abstractRecognizer.h @@ -4,7 +4,7 @@ #include #include #include "geometricForms.h" -#include "paintmanager.h" +#include "paintManager.h" class GesturesManager { diff --git a/DiagramRecognizer/component.cpp b/DiagramRecognizer/component.cpp index 466543f..7a004ec 100644 --- a/DiagramRecognizer/component.cpp +++ b/DiagramRecognizer/component.cpp @@ -155,3 +155,121 @@ bool Component::isNegligible() const } return true; } + +bool Component::intersects(Component *comp1, Component *comp2) +{ + Component::Iterator itr1, itr2; + for (itr1 = comp1->begin(); itr1 != comp1->end(); itr1++) + { + for (itr2 = comp2->begin(); itr2 != comp2->end(); itr2++) + { + if (*itr1 == *itr2) + { + return true; + } + } + } + return false; +} +SquarePos Component::intersectsAt(Component *comp1, Component *comp2) +{ + SquarePos beg1 = comp1->first(); + SquarePos beg2 = comp2->first(); + SquarePos end1 = comp1->last(); + SquarePos end2 = comp2->last(); + if (beg1 == beg2) { return beg1; } + if (beg1 == end2) { return beg1; } + if (end1 == beg2) { return end1; } + if (end1 == end2) { return end1; } + return SquarePos(-1, -1); //such point does't exist; no intersection +} +bool Component::getIsFixed() const { return isFixed; } +bool Component::setIsFixed(bool value) { isFixed = value; } +SquarePos Component::center() const +{ + SquarePos res(0, 0); + int x = 0; + int y = 0; + int len = 0; + for (Component::const_iterator i = this->begin(); i != this->end(); i++) + { + x += (*i).first; + y += (*i).second; + len++; + } + res.first= x / len; + res.second = y / len; + return res; +} +SquarePos Component::getAnotherSide(SquarePos const & point) const +{ + SquarePos begin = this->first(); + SquarePos end = this->last(); + if (begin == point) { return end; } + else if (end == point) { return begin; } + else { return SquarePos(-1, -1); } +} +bool Component::isClosed() const +{ + return first() == last(); +} +SquarePos Component::center(QList < Component *> *comps) +{ + SquarePos res(0, 0); + int x = 0; + int y = 0; + int len = 0; + for (QList < Component *>::const_iterator itr = comps->begin(); itr != comps->end(); itr++) + { + for (Component::const_iterator i = (*itr)->begin(); i != (*itr)->end(); i++) + { + x += (*i).first; + y += (*i).second; + len++; + } + } + res.first= x / len; + res.second = y / len; + return res; +} + +QList < Component *>::iterator Component::getOuterComponent(QList < Component *> *comps) +{ + Component *cur; + int minX, minY; + int globMinX, globMinY; + QList < Component *>::iterator res; + globMinX = (*((*(comps->begin()))->begin())).first; + globMinY = (*((*(comps->begin()))->begin())).second; + for (QList < Component *>::iterator i = comps->begin(); i != comps->end(); i++) + { + cur = *i; + minX = (*(cur->begin())).first; + minY = (*(cur->begin())).second; + for (Component::const_iterator itr = cur->begin(); itr != cur->end(); itr++) + { + minX = (minX < (*itr).first) ? minX : (*itr).first; + minY = (minY < (*itr).second) ? minY : (*itr).second; + } + if (minX < globMinX) + { + globMinX = minX; + globMinY = minY; + res = i; + } + else + { + if (minY < globMinY) + { + globMinX = minX; + globMinY = minY; + res = i; + } + } + } + return res; +} +QList < Component *> *Component::prioritetSort(QList < Component *> *comps) +{ + return new QList < Component *>(); +} diff --git a/DiagramRecognizer/component.h b/DiagramRecognizer/component.h index 73e8e63..5d4a45f 100644 --- a/DiagramRecognizer/component.h +++ b/DiagramRecognizer/component.h @@ -7,6 +7,7 @@ class Component : public QList { public: + int num; Component(); void insertPos(SquarePos const & pos); void analyze(); @@ -17,8 +18,21 @@ class Component : public QList bool hasSelfIntersection() const; PathVector figure(int xMin, int yMin) const; bool isNegligible() const; + bool getIsFixed() const; + bool setIsFixed(bool value); + SquarePos center() const; //finds center of the component + SquarePos getAnotherSide(const SquarePos & point) const; //returns another side of the component + bool isClosed() const; + //finds any outer component (for example, left-upper one) + static QList < Component *>::iterator getOuterComponent(QList < Component *> *comps); + //finds the center of the list of components + static SquarePos center(QList < Component *> *comps); + static QList < Component *> *prioritetSort(QList < Component *> *comps); + static bool intersects(Component *comp1, Component *comp2); + static SquarePos intersectsAt(Component *comp1, Component *comp2); private: + bool isFixed; bool isNeighbours(SquarePos const & pos1, SquarePos const & pos2) const; static int mNextID; bool mHasSelfIntersection; diff --git a/DiagramRecognizer/connectedComponent.cpp b/DiagramRecognizer/connectedComponent.cpp new file mode 100644 index 0000000..a97aaff --- /dev/null +++ b/DiagramRecognizer/connectedComponent.cpp @@ -0,0 +1,49 @@ +#pragma once; +#include + +CComponent::CComponent() +{ + mComps = new QList < Component *> (); +} +CComponent::CComponent(QList < Component *> *components) : mComps(components) { } +CComponent::~CComponent() +{ + delete mComps; +} +int CComponent::size() const { return mComps->size(); } +void CComponent::removeAll(Component *component) +{ + mComps->removeAll(component); +} +QList < Component *> *CComponent::getIntersectionList(Component *curComponent) //old version; better to delete +{ + QList < Component *> *result = new QList < Component *>(); + for (QList < Component *>::iterator itr = mComps->begin(); itr != mComps->end(); itr++) + { + if (Component::intersects(*itr, curComponent)) + { + result->push_front(*itr); + } + } + return result; +} +QList < Component *> *CComponent::getIntersectionList(QList < Component *> *comps) +{ +} +/*QList < Component *> *getIntersectionList(Component *curComponent, Segmentator *segmentator) //new version +{ +QList < Component *> *result = new QList < Component *>(segmentator->mInterList[curComponent]); + for (QList < Component *>::iteartor itr = result->begin(); itr != result->end(); itr++) + { + if (!comps->contains(*itr)) + { + result->erase(itr); + } + } + return res; +}*/ +void CComponent::addComponent(Component *newComponent) +{ + mComps->push_front(newComponent); +} +QList < Component *> *CComponent::getComponents() const { return mComps; } diff --git a/DiagramRecognizer/connectedComponent.h b/DiagramRecognizer/connectedComponent.h new file mode 100644 index 0000000..ea179e3 --- /dev/null +++ b/DiagramRecognizer/connectedComponent.h @@ -0,0 +1,19 @@ +#pragma once; +#include +#include + +class CComponent //connected component +{ +public: + CComponent(); + CComponent(QList < Component *> *components); + ~CComponent(); + int size() const; + void removeAll(Component *component); + QList < Component *> *getIntersectionList(Component *curComponent); + QList < Component *> *getIntersectionList(QList < Component *> *comps); + void addComponent(Component *newComponent); + QList < Component *> *getComponents() const; +private: + QList < Component *> *mComps; +}; diff --git a/DiagramRecognizer/diagramrecognizer.cpp b/DiagramRecognizer/diagramRecognizer.cpp similarity index 83% rename from DiagramRecognizer/diagramrecognizer.cpp rename to DiagramRecognizer/diagramRecognizer.cpp index 5d625c8..ede6e8c 100644 --- a/DiagramRecognizer/diagramrecognizer.cpp +++ b/DiagramRecognizer/diagramRecognizer.cpp @@ -4,6 +4,7 @@ #include "simpleFormsInitializer.h" #include "recognizers/mixedGesturesManager.h" #include "output.h" +#include "field.h" #include #include @@ -77,16 +78,30 @@ void DiagramRecognizer::recognizeDiagram() //mRecognized = true; mFormSegmentator = new FormSegmentator(mBitmap); mFormSegmentator->uniteComponents(); + QList objects = mFormSegmentator->getObjects(); + QList < Component *> *objs = new QList < Component *>(); + foreach (Component obj, objects) + { + Component *newComp = new Component(obj); + objs->push_back(newComp); + } + Field f(objs); mDiagram.clear(); - foreach (Component const &object, objects) { + foreach (Component *object, *objs) { PathVector recognizedObject = mAbstractRecognizer->recognizeObject( - object.figure(mBitmap->xLeft(), mBitmap->yUpper())); + (*object).figure(mBitmap->xLeft(), mBitmap->yUpper())); mDiagram.append(recognizedObject); } - foreach (Component const &edge, mFormSegmentator->getEdges()) { + /*foreach (Component const &edge, mFormSegmentator->getEdges()) { mDiagram.append(edge.figure(mBitmap->xLeft(), mBitmap->yUpper())); + }*/ + foreach (ELink *edge, *(f.getLinks())) + { + Component *comp = edge->getComponent(); + mDiagram.append((*comp).figure(mBitmap->xLeft(), mBitmap->yUpper())); } + delete objs; emit print(mDiagram, mBitmap, mFormSegmentator); } diff --git a/DiagramRecognizer/diagramrecognizer.h b/DiagramRecognizer/diagramRecognizer.h similarity index 86% rename from DiagramRecognizer/diagramrecognizer.h rename to DiagramRecognizer/diagramRecognizer.h index 4940a1e..3270d94 100644 --- a/DiagramRecognizer/diagramrecognizer.h +++ b/DiagramRecognizer/diagramRecognizer.h @@ -1,9 +1,9 @@ #pragma once #include "bitmap.h" -#include "formsegmentator.h" +#include "formSegmentator.h" #include "abstractRecognizer.h" #include - +#include class DiagramRecognizer : public QWidget { @@ -27,5 +27,5 @@ public slots: bool mRecognized; QPoint mComponentPoint; GesturesManager *mGesturesManager; - AbstractRecognizer *mAbstractRecognizer; + AbstractRecognizer *mAbstractRecognizer; }; diff --git a/DiagramRecognizer/diagramRecognizer.ui b/DiagramRecognizer/diagramRecognizer.ui new file mode 100644 index 0000000..9bf5967 --- /dev/null +++ b/DiagramRecognizer/diagramRecognizer.ui @@ -0,0 +1,89 @@ + + + DiagramRecognizer + + + + 0 + 0 + 550 + 538 + + + + DiagramRecognizer + + + + + + + Qt::Vertical + + + + 20 + 415 + + + + + + + + QFrame::StyledPanel + + + QFrame::Raised + + + + + + clear + + + + + + + recognize + + + + + + + recognize image + + + + + + + + + + + + 0 + 0 + 550 + 21 + + + + + + TopToolBarArea + + + false + + + + + + + + diff --git a/DiagramRecognizer/eFigure.cpp b/DiagramRecognizer/eFigure.cpp new file mode 100644 index 0000000..1b1fbe5 --- /dev/null +++ b/DiagramRecognizer/eFigure.cpp @@ -0,0 +1,61 @@ +#pragma once; +#include + +EFigure::EFigure() +{ + mShell = new QList < Component *>(); + mSections = new QList < Section *>(); + mId = 0; +} +EFigure::EFigure(QList < Component *> *shell) +{ + mShell = new QList < Component *>(*shell); + mSections = new QList < Section *>(); + mId = 0; +} +EFigure::EFigure(QList < Component *> *shell, QList < Section *> *sections) +{ + mShell = new QList < Component *>(*shell); + mSections = new QList < Section *>(*sections); + mId= 0; +} +EFigure::EFigure(QList < Component *> *shell, QList < Section *> *sections, int id) +{ + mShell = new QList < Component *>(*shell); + mSections = new QList < Section *>(*sections); + mId = id; +} +EFigure::EFigure(QList < Component *> *shell, int id) +{ + mShell = new QList < Component *>(*shell); + mSections = new QList < Section *>(); + mId = id; +} +EFigure::EFigure(EFigure *figure) +{ + mShell = new QList < Component *>(*(figure->getShell())); + mSections = new QList < Section *>(); + for (QList < Section *>::const_iterator i = figure->getSections()->begin(); i != figure->getSections()->end(); i++) + { + mSections->push_back(new Section(*i)); + } + mId = figure->getId(); +} + +EFigure::~EFigure() +{ + delete mShell; + delete mSections; +} + +void EFigure::addSection(QList < Component *> *comps) +{ + mSections->push_back(new Section(comps)); +} +void EFigure::addSection(Section *section) +{ + mSections->push_back(section); +} +QList < Component *> *EFigure::getShell() const { return mShell; } +QList < Section *> *EFigure::getSections() const { return mSections; } +int EFigure::getId() const { return mId; } diff --git a/DiagramRecognizer/eFigure.h b/DiagramRecognizer/eFigure.h new file mode 100644 index 0000000..b02bd97 --- /dev/null +++ b/DiagramRecognizer/eFigure.h @@ -0,0 +1,25 @@ +#pragma once; +#include +#include + +class EFigure +{ +public: + EFigure(); + EFigure(QList < Component *> *shell); + EFigure(QList < Component *> *shell, QList < Section *> *sections); + EFigure(QList < Component *> *shell, QList < Section *> *sections, int id); + EFigure(QList < Component *> *shell, int id); + EFigure(EFigure *figure); + ~EFigure(); + void addSection(QList < Component *> *comps); + void addSection(Section *section); + QList < Component *> *getShell() const; + QList < Section *> *getSections() const; + int getId() const; + +private: + QList < Component *> *mShell; + QList < Section *> *mSections; + int mId; //id in database +}; diff --git a/DiagramRecognizer/eItems.cpp b/DiagramRecognizer/eItems.cpp new file mode 100644 index 0000000..6a5e9ed --- /dev/null +++ b/DiagramRecognizer/eItems.cpp @@ -0,0 +1,80 @@ +#pragma once; +#include + +Recognizer::Recognizer() { } +int Recognizer::getType(QList < Component *> *shell) { return 0; } + +Section::Section() +{ + mComps = new QList < Component *>(); +} +Section::Section(QList < Component *> *components) +{ + mComps = new QList < Component *>(*components); +} +QList < Component *> * Section::getComps() const +{ + return mComps; +} + +EFigure::EFigure() +{ + mShell = new QList < Component *>(); + mSections = new QList < Section *>(); + mId = 0; +} +EFigure::EFigure(QList < Component *> *shell) +{ + mShell = shell; + mSections = new QList < Section *>(); + mId = 0; +} +EFigure::EFigure(QList < Component *> *shell, QList < Section *> *sections) +{ + mShell = shell; + mSections = sections; + mId= 0; +} +EFigure::EFigure(QList < Component *> *shell, QList < Section *> *sections, int id) +{ + mShell = shell; + mSections = sections; + mId = id; +} +EFigure::EFigure(QList < Component *> *shell, int id) +{ + mShell = shell; + mSections = new QList < Section *>(); + mId = id; +} +void EFigure::addSection(QList < Component *> *comps) +{ + mSections->push_front(new Section(comps)); +} +void EFigure::addSection(Section *section) +{ + mSections->push_front(section); +} +QList < Component *> *EFigure::getShell() const { return mShell; } +QList < Section *> *EFigure::getSections() const { return mSections; } + +ELink::ELink() +{ + mComponent = new Component(); + mFigure1 = mFigure2 = 0; //null +} +ELink::ELink(Component *component) +{ + mComponent = component; + mFigure1 = mFigure2 = 0; //null +} +ELink::ELink(Component *component, EFigure *figure1, EFigure *figure2) +{ + mComponent = component; + mFigure1 = figure1; + mFigure2 = figure2; +} +Component *ELink::getComponent() const { return mComponent; } +EFigure *ELink::getFigure1() const { return mFigure1; } +EFigure *ELink::getFigure2() const { return mFigure2; } + diff --git a/DiagramRecognizer/eItems.h b/DiagramRecognizer/eItems.h new file mode 100644 index 0000000..8f9d7c2 --- /dev/null +++ b/DiagramRecognizer/eItems.h @@ -0,0 +1,5 @@ +#pragma once; +#include +#include +#include + diff --git a/DiagramRecognizer/eLink.cpp b/DiagramRecognizer/eLink.cpp new file mode 100644 index 0000000..b3415e3 --- /dev/null +++ b/DiagramRecognizer/eLink.cpp @@ -0,0 +1,41 @@ +#pragma once; +#include + +ELink::ELink() +{ + mComponent = new Component(); + mFigure1 = mFigure2 = 0; //null +} +ELink::ELink(Component *component) +{ + mComponent = component; + mFigure1 = mFigure2 = 0; //null +} +ELink::ELink(Component *component, EFigure *figure1, EFigure *figure2) +{ + mComponent = component; + mFigure1 = figure1; + mFigure2 = figure2; +} +ELink::ELink(Component *component, EFigure *figure) +{ + mComponent = component; + mFigure1 = figure; + mFigure2 = 0; +} +ELink::ELink(ELink *eLink) +{ + mComponent = eLink->getComponent(); + mFigure1 = eLink->getFigure1(); + mFigure2 = eLink->getFigure2(); +} + +ELink::~ELink() +{ + delete mFigure1; + delete mFigure2; +} + +Component *ELink::getComponent() const { return mComponent; } +EFigure *ELink::getFigure1() const { return mFigure1; } +EFigure *ELink::getFigure2() const { return mFigure2; } diff --git a/DiagramRecognizer/eLink.h b/DiagramRecognizer/eLink.h new file mode 100644 index 0000000..2ef1d2a --- /dev/null +++ b/DiagramRecognizer/eLink.h @@ -0,0 +1,20 @@ +#pragma once; +#include +#include + +class ELink +{ +public: + ELink(); + ELink(Component *component); + ELink(Component *component, EFigure *figure1, EFigure *figure2); + ELink(Component *component, EFigure *figure); + ELink(ELink *eLink); + ~ELink(); + Component *getComponent() const; + EFigure *getFigure1() const; + EFigure *getFigure2() const; +private: + Component *mComponent; + EFigure *mFigure1, *mFigure2; +}; diff --git a/DiagramRecognizer/edge.h b/DiagramRecognizer/edge.h deleted file mode 100644 index 8a1b1cd..0000000 --- a/DiagramRecognizer/edge.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -class Edge : public Component -{ -public: - Edge() - : figure1(NULL), figure2 : (NULL) - {} - Edge(Figure *fig1, Figure *fig2) - : figure1(fig1), figure2(fig2) - {} -private: - Figure *figure1, *figure2; -}; diff --git a/DiagramRecognizer/field.cpp b/DiagramRecognizer/field.cpp new file mode 100644 index 0000000..06d0ec7 --- /dev/null +++ b/DiagramRecognizer/field.cpp @@ -0,0 +1,130 @@ +#pragma once; +#include +#include +#include +#include +#include +Field::Field() +{ + mFigures = new QList < EFigure *>(); + mLinks = new QList < ELink *>(); + mComponents = new QList < Component *>(); +} +Field::Field(QList < Component *> *components) +{ + if (components->empty()) + { + mFigures = new QList < EFigure *>(); + mLinks = new QList < ELink *>(); + mComponents = new QList < Component *>(); + return; + } + mComponents = new QList < Component *>(*components); + mFigures = new QList < EFigure *>(); + mLinks = new QList < ELink *>(); + Segmentator *segmentator = new Segmentator(mComponents); + segmentator->makeSegmentation(); + foreach(EFigure *fig, *(segmentator->getFigures())) + { + mFigures->push_back(new EFigure(fig)); + } + foreach(ELink *link, *(segmentator->getLinks())) + { + mLinks->push_back(new ELink(link)); + } + delete segmentator; +} +Field::~Field() +{ + for (QList < EFigure *>::const_iterator i = mFigures->begin(); i != mFigures->end(); i++) + { + delete *i; + } + delete mFigures; + for (QList < ELink *>::const_iterator i = mLinks->begin(); i != mLinks->end(); i++) + { + delete *i; + } + delete mLinks; + delete mComponents; +} +bool Field::pointInContur(SquarePos & point, QList < Component *> *comps) +{ + if (comps->empty()) { return false; } + std::set < SquarePos> border; + SquarePos up = (*((*(comps->begin()))->begin())); //any SquarePos; for instance the first one + SquarePos down(up); + SquarePos left(up); + SquarePos right(up); + for (QList < Component *>::const_iterator i = comps->begin(); i != comps->end(); i++) + { + for (QList < SquarePos >::const_iterator itr = (*i)->begin(); itr != (*i)->end(); itr++) + { + SquarePos curPoint(*itr); + border.insert(curPoint); + if (up.first > curPoint.first) { up = curPoint; } + if (down.first < curPoint.first) { down = curPoint; } + if (left.second > curPoint.second) { left = curPoint; } + if (right.second < curPoint.second) { right = curPoint; } + } + } + std::set < SquarePos > black; + std::set < SquarePos > gray; + gray.insert(point); + if (border.find(point) != border.end()) { return true; } + int delta[3] = { -1, 0, 1}; + while(!gray.empty()) + { + SquarePos curPos = *(gray.begin()); + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + if (i == 1 && j == 1) { continue; } + SquarePos newPos(curPos.first + delta[i], curPos.second + delta[j]); + if ((border.find(newPos) == border.end()) && (black.find(newPos) == black.end())) + { + if ((newPos.first <= up.first) || (newPos.first >= down.first) || (newPos.second <= left.second) || (newPos.second >= right.second)) + { + return false; + } + gray.insert(newPos); + } + } + } + gray.erase(curPos); + black.insert(curPos); + } + return true; +} +bool Field::compInContur(Component *comp, QList < Component *> *comps) +{ + SquarePos point(comp->at(comp->size() / 2)); + return Field::pointInContur(point, comps); +} + +bool Field::compInContur(Component *comp, std::set *comps) +{ + SquarePos point(comp->at(comp->size() / 2)); + QList < Component *> *compList = new QList < Component *>(); + for (std::set::iterator i = comps->begin(); i != comps->end(); i++) + { + compList->push_back(*i); + } + bool res = Field::pointInContur(point, compList); + delete compList; + return res; +} + +QList < Component *> *Field::getComponents() const +{ + return mComponents; +} +QList < EFigure *> *Field::getFigures() const +{ + return mFigures; +} +QList *Field::getLinks() const +{ + return mLinks; +} diff --git a/DiagramRecognizer/field.h b/DiagramRecognizer/field.h new file mode 100644 index 0000000..6362f11 --- /dev/null +++ b/DiagramRecognizer/field.h @@ -0,0 +1,23 @@ +#pragma once; +#include +#include +#include + +class Field +{ +public: + Field(); + Field(QList < Component *> *components); + ~Field(); + QList < EFigure *> *getFigures() const; + QList < ELink *> *getLinks() const; + QList < Component *> *getComponents() const; + static bool pointInContur(SquarePos & point, QList < Component *> *comps); + static bool compInContur(Component *comp, QList < Component *> *comps); + static bool compInContur(Component *comp, std::set *comps); + +private: + QList < EFigure *> *mFigures; + QList < ELink *> *mLinks; + QList < Component *> *mComponents; //list of all components +}; diff --git a/DiagramRecognizer/figure.cpp b/DiagramRecognizer/figure.cpp new file mode 100644 index 0000000..7122fd8 --- /dev/null +++ b/DiagramRecognizer/figure.cpp @@ -0,0 +1,2 @@ +#pragma once; +#include diff --git a/DiagramRecognizer/figure.h b/DiagramRecognizer/figure.h index 253081e..c0312bb 100644 --- a/DiagramRecognizer/figure.h +++ b/DiagramRecognizer/figure.h @@ -1,12 +1,8 @@ -#pragma once +#pragma once; +#include +#include -class Figure : public Component +class Figure { -public: - Figure(abstractRec...); //recognize figure, declear its type - int getType() const; - void setType(int value); - -private: - int type; + //QList< EItem *> *items; }; diff --git a/DiagramRecognizer/formsegmentator.cpp b/DiagramRecognizer/formSegmentator.cpp similarity index 100% rename from DiagramRecognizer/formsegmentator.cpp rename to DiagramRecognizer/formSegmentator.cpp diff --git a/DiagramRecognizer/formsegmentator.h b/DiagramRecognizer/formSegmentator.h similarity index 100% rename from DiagramRecognizer/formsegmentator.h rename to DiagramRecognizer/formSegmentator.h diff --git a/DiagramRecognizer/geometricForms.h b/DiagramRecognizer/geometricForms.h index 865fc42..74088e9 100644 --- a/DiagramRecognizer/geometricForms.h +++ b/DiagramRecognizer/geometricForms.h @@ -27,6 +27,12 @@ struct SquarePos second = y; } + SquarePos(SquarePos const & pos) + { + first = pos.first; + second = pos.second; + } + int first; int second; @@ -35,6 +41,11 @@ struct SquarePos return std::max(abs(first - pos.first), abs(second - pos.second)); } + int length() const + { + return first*first + second*second; + } + int distP1(SquarePos const & pos) const { return abs(first - pos.first) + abs(second - pos.second); @@ -44,6 +55,40 @@ struct SquarePos { return pos.first == first && pos.second == second; } + + bool operator != (SquarePos const pos) const + { + return ! operator == (pos); + } + + bool operator < (SquarePos const & pos) const + { + if (first < pos.first) { return true; } + else if (first > pos.first) { return false; } + else + { + if (second < pos.second) { return true; } + else { return false; } + } + } + + bool operator > (SquarePos const & pos) const + { + return !((operator ==(pos)) && (operator <(pos))); + } + SquarePos operator +(SquarePos pos) const + { + return SquarePos(first + pos.first, second + pos.second); + } + SquarePos operator -(SquarePos pos) const + { + return SquarePos(first - pos.first, second - pos.second); + } + SquarePos operator =(SquarePos pos) + { + first = pos.first; + second = pos.second; + } }; typedef QList Key; diff --git a/DiagramRecognizer/graph.cpp b/DiagramRecognizer/graph.cpp new file mode 100644 index 0000000..1934c6c --- /dev/null +++ b/DiagramRecognizer/graph.cpp @@ -0,0 +1,367 @@ +#pragma once; +#include +#include +#include +#include +#include + +Graph::Graph() +{ + mMatrix = new IMatrix(); + mInterList = new InterList(); + mIList = new IList(); + mNodes = new std::set(); + mEdges = new std::set(); +} +Graph::Graph(QList < Component *> *comps) +{ + initGraph(comps); +} +Graph::Graph(Graph &graph) +{ + mMatrix = new IMatrix(*(graph.getMatrix())); + mInterList = new InterList(*(graph.getInterList())); + mIList = new IList(*(graph.getIList())); + mNodes = new std::set(*(graph.getNodes())); + mEdges = new std::set(*graph.getEdges()); +} +Graph::Graph(Graph &graph, int deep) +{ + if (deep == 0) + { + Graph(graph); + return; + } + mNodes = new std::set(*(graph.getNodes())); + mEdges = new std::set(*graph.getEdges()); + mInterList = new InterList(); + mIList = new IList(); + mMatrix = new IMatrix(); + for (std::set::const_iterator i = mEdges->begin(); i != mEdges->end(); i++) + { + QList *newList = new QList(*(graph.getInterList(*i))); + mInterList->insert(std::pair *>(*i, newList)); + } + for (std::set::const_iterator i = mNodes->begin(); i != mNodes->end(); i++) + { + std::set *newList = new std::set(*(graph.getIList(*i))); + mIList->insert(std::pair *>(*i, newList)); + } +} + +Graph::Graph(Graph *graph) +{ + mMatrix = new IMatrix(*(graph->getMatrix())); + mInterList = new InterList(*(graph->getInterList())); + mIList = new IList(*(graph->getIList())); + mNodes = new std::set(*(graph->getNodes())); + mEdges = new std::set(*graph->getEdges()); +} +Graph::~Graph() +{ + for (std::set::const_iterator i = mEdges->begin(); i != mEdges->end(); i++) + { + delete mInterList->at(*i); + } + for (std::set::const_iterator i = mNodes->begin(); i != mNodes->end(); i++) + { + delete mIList->at(*i); + } + delete mInterList; + delete mIList; + delete mNodes; + delete mEdges; + delete mMatrix; + +} + +/*QList < Component *> *Graph::depthSearch(Component *component) +{ + std::stack < Component *> *s = new std::stack < Component *>(); + QList < Component *> *res = new QList < Component *>(); + s->push(component); + component->setIsFixed(true); + while (!s->empty()) + { + component = s->top(); + s->pop(); + for (QList < Component *>::iterator itr = mComps->begin(); itr != mComps->end(); itr++) + { + if ((*itr)->getIsFixed()) { continue; } + if (intersects(component, *itr)) + { + s->push(*itr); + (*itr)->setIsFixed(true); + res->push_front(*itr); + } + } + } + for (QList < Component *>::iterator itr = mComps->begin(); itr != mComps->end(); itr++) + { + (*itr)->setIsFixed(false); + } + delete s; + return res; +}*/ + +QList < QList < Component *> *> *Graph::cSegmentation(QList < Component *> *comps, Graph &graph) //splits all components into connected components +{ + std::stack s; + QList < QList < Component *> *> *res = new QList < QList < Component *> *>(); + QList < Component *> *copy = new QList < Component *> (*comps); + Component *cur; + std::set marked; + QList < Component *> *curList; + while (!copy->empty()) + { + curList = new QList < Component *>(); + s.push(copy->first()); + copy->removeFirst(); + curList->clear(); + //marked.clear(); + marked.insert(s.top()); + curList->push_back(s.top()); + while (!s.empty()) + { + QList < Component *> *list = graph.getInterList(s.top()); + bool wereIn = false; + for (QList < Component *>::iterator i = list->begin(); i != list->end(); i++) + { + if (marked.find(*i) != marked.end()) { continue; } + wereIn = true; + s.push(*i); + curList->push_back(*i); + int index = copy->indexOf(*i); + copy->removeAt(index); + marked.insert(*i); + } + if (!wereIn) + { + s.pop(); + } + } + res->push_back(curList); + } + delete copy; + return res; +} + +bool Graph::intersects(Component *comp1, Component *comp2) const +{ + return mMatrix->at(std::pair(comp1, comp2)); +} +IMatrix *Graph::getMatrix() const { return mMatrix; } +InterList *Graph::getInterList() const { return mInterList; } +QList < Component *> *Graph::getInterList(Component *component) const +{ + if (mInterList->find(component) == mInterList->end()) { return 0; } + return mInterList->at(component); +} +std::set < Component * > *Graph::getIList(SquarePos const & node) const +{ + if (mIList->find(node) == mIList->end()) { return 0; } + return mIList->at(node); +} +IList *Graph::getIList() const +{ + return mIList; +} +std::set < SquarePos > *Graph::getNodes() const +{ + return mNodes; +} +std::set < Component *> *Graph::getEdges() const +{ + return mEdges; +} +SquarePos Graph::intersectsAt(Component *comp1, Component *comp2) const +{ + if (!intersects(comp1, comp2)) { return SquarePos(-1, -1); } + if (comp1->first() == comp2->first()) { return comp1->first(); } + if (comp1->first() == comp2->last()) { return comp1->first(); } + if (comp1->last() == comp2->first()) { return comp1->last(); } + if (comp1->last() == comp2->last()) { return comp1->last(); } +} +void Graph::initGraph(QList < Component *> *comps) +{ + mIList = new IList(); + mInterList = new InterList(); + //mMatrix = new std::map, bool>(); + mMatrix = new IMatrix(); + mEdges = new std::set(); + std::set < SquarePos > *nodes = new std::set < SquarePos >(); + for (QList < Component *>::iterator i = comps->begin(); i != comps->end(); i++) + { + mEdges->insert(*i); + QList < Component *> *curList = new QList < Component *>(); + for (QList < Component *>::iterator itr = comps->begin(); itr != comps->end(); itr++) + { + nodes->insert((*itr)->first()); + nodes->insert((*itr)->last()); + SquarePos point = Component::intersectsAt(*i, *itr); + //if (Component::intersects(*i, *itr)) + if (point != SquarePos(-1, -1)) + { + if (*itr != *i) + { + curList->push_front(*itr); + //nodes->insert(point); + } + //std::pair p1 = std::pair(*i, *itr); + mMatrix->insert(std::pair, bool>(std::pair(*i, *itr), true)); + } + else + { + mMatrix->insert(std::pair, bool>(std::pair(*i, *itr), false)); + } + } + mInterList->insert(std::pair *>(*i, curList)); + } + mNodes = nodes; + for (std::set::iterator curNode = mNodes->begin(); curNode != mNodes->end(); curNode++) + { + std::set < Component *> *newList = new std::set < Component *>(); + for (QList < Component *>::iterator i = comps->begin(); i != comps->end(); i++) + { + SquarePos begin = (*i)->first(); + SquarePos end = (*i)->last(); + if ((begin == *curNode) || (end == *curNode)) + { + newList->insert(*i); + } + } + mIList->insert(std::pair * >(*curNode, newList)); + } + /*for (IList::const_iterator i = mIList->begin(); i != mIList->end(); i++) + { + qDebug() << "Node: " << (*i).first.first << " " << (*i).first.second; + std::set *list = (*i).second; + for (std::set < Component *>::const_iterator i = list->begin(); i != list->end(); i++) + { + qDebug() << (*i)->num; + } + }*/ +} +bool Graph::mIListIsEmpty() const +{ + for (IList::const_iterator i = mIList->begin(); i != mIList->end(); i++) + { + std::set < Component * > *list = (*i).second; + if (!list->empty()) { return false; } + } + return true; +} +bool Graph::mInterListIsEmpty() const +{ + for (InterList::const_iterator i = mInterList->begin(); i != mInterList->end(); i++) + { + QList < Component * > *list = (*i).second; + if (!list->empty()) { return false; } + } + return true; +} +void Graph::eraseEdge(Component *edge) //works only for the first graph type +{ + IMatrix *matrix = getMatrix(); + QList < Component *> *list = getInterList(edge); + if (list == 0) { return; } + mEdges->erase(edge); + //mInterList->erase(std::pair *>(edge, list)); + mInterList->erase(edge); + for (QList < Component *>::iterator i = list->begin(); i != list->end(); i++) + { + QList < Component *> *list2 = getInterList(*i); + for (QList < Component *>::iterator itr = list2->begin(); itr != list2->end(); itr++) + { + if (*itr == edge) + { + list2->erase(itr); + break; + } + } + } + for (QList < Component *>::iterator i = list->begin(); i != list->end(); i++) + { + /*matrix->erase(std::pair, bool>(std::pair(*i, edge), true)); + matrix->erase(std::pair, bool>(std::pair(edge, *i), true)); + matrix->insert(std::pair, bool>(std::pair(edge, *i), false)); + matrix->insert(std::pair, bool>(std::pair(*i, edge), false));*/ + matrix->erase(std::pair(*i, edge)); + matrix->erase(std::pair(edge, *i)); + matrix->insert(std::pair, bool>(std::pair(edge, *i), false)); + matrix->insert(std::pair, bool>(std::pair(*i, edge), false)); + } + SquarePos beg = edge->first(); + SquarePos end = edge->last(); + std::set *set = getIList(beg); + set->erase(edge); + set = getIList(end); + set->erase(edge); +} +void Graph::operator =(Graph &graph) +{ + delete mIList; + delete mInterList; + delete mNodes; + delete mEdges; + delete mMatrix; + mMatrix = new IMatrix(*(graph.getMatrix())); + mInterList = new InterList(*(graph.getInterList())); + mIList = new IList(*(graph.getIList())); + mNodes = new std::set(*(graph.getNodes())); + mEdges = new std::set(*graph.getEdges()); +} + +void Graph::insertEdge(Component *edge) +{ + InterList *intList = getInterList(); + QList < Component *> *newList = new QList < Component *>(); + mEdges->insert(edge); + mNodes->insert(edge->first()); + mNodes->insert(edge->last()); + bool finish; + for (std::set::iterator i = mEdges->begin(); i != mEdges->end(); i++) + { + finish = false; + Component *cur = *i; + SquarePos pos = Component::intersectsAt(cur, edge); + if (pos == SquarePos(-1, -1)) { finish = true; } + mMatrix->insert(std::pair, bool>(std::pair(edge, cur), !finish)); + mMatrix->insert(std::pair, bool>(std::pair(cur, edge), !finish)); + if (finish) { continue; } + if (cur == edge) { continue; } + QList < Component *> *list = getInterList(cur); + list->push_back(edge); + newList->push_back(cur); + } + for (std::set::iterator i = mEdges->begin(); i != mEdges->end(); i++) + { + SquarePos beg = edge->first(); + SquarePos end = edge->last(); + std::set *sList = getIList(beg); + if (sList == 0) + { + std::set *newSet = new std::set(); + newSet->insert(edge); + mIList->insert(std::pair *>(beg, newSet)); + } + else + { + sList->insert(edge); + //mIList->insert(std::pair *>(beg, sList)); + } + sList = getIList(end); + if (sList == 0) + { + std::set *newSet = new std::set(); + newSet->insert(edge); + mIList->insert(std::pair *>(end, newSet)); + } + else + { + sList->insert(edge); + //mIList->insert(std::pair *>(beg, sList)); + } + } + intList->insert(std::pair *>(edge, newList)); +} diff --git a/DiagramRecognizer/graph.h b/DiagramRecognizer/graph.h new file mode 100644 index 0000000..37d20f9 --- /dev/null +++ b/DiagramRecognizer/graph.h @@ -0,0 +1,47 @@ +#pragma once; +#include +#include +#include +#include + +typedef std::map < Component *, QList < Component *> *> InterList; +typedef std::map , bool> IMatrix; +typedef std::map *> IList; + +class Graph +{ +public: + Graph(); + Graph(QList < Component *> *comps); + Graph(Graph & graph); //copies + Graph(Graph & graph, int deep); //copies + Graph(Graph *graph); //copies + ~Graph(); + //QList < Component *> *depthSearch(Component *component); + //QList < CComponent *> *cSegmentation(QList < Component *> *comps); //splits all components into connected components + bool intersects(Component *comp1, Component *comp2) const; + IMatrix *getMatrix() const ; + InterList *getInterList() const; + QList < Component *> *getInterList(Component *component) const; + std::set < Component * > *getIList(SquarePos const & node) const; + IList *getIList() const; + std::set < SquarePos > *getNodes() const; + SquarePos intersectsAt(Component *comp1, Component *comp2) const; + bool mIListIsEmpty() const; + bool mInterListIsEmpty() const; + void eraseEdge(Component *edge); + void insertEdge(Component *edge); //not tested + void operator =(Graph &graph); + static QList < QList < Component *> *> *cSegmentation(QList *comps, Graph &graph); + std::set *getEdges() const; + + +private: + void initGraph(QList < Component *> *comps); + IMatrix *mMatrix; + InterList *mInterList; + IList *mIList; + std::set *mEdges; + std::set *mNodes; + +}; diff --git a/DiagramRecognizer/link.cpp b/DiagramRecognizer/link.cpp new file mode 100644 index 0000000..37384ff --- /dev/null +++ b/DiagramRecognizer/link.cpp @@ -0,0 +1,2 @@ +#pragma once; +#include diff --git a/DiagramRecognizer/link.h b/DiagramRecognizer/link.h new file mode 100644 index 0000000..c6660eb --- /dev/null +++ b/DiagramRecognizer/link.h @@ -0,0 +1,11 @@ +#pragma once; +#include + +class Link : public ELink +{ +public: + Link() : ELink() { } + Link(Component *component) : ELink (component) { } + Link(ELink *eLink) : ELink (eLink) { } + Link(Link *link) : ELink ((ELink *)link) { } +}; diff --git a/DiagramRecognizer/main.cpp b/DiagramRecognizer/main.cpp index f2203a0..81082d7 100644 --- a/DiagramRecognizer/main.cpp +++ b/DiagramRecognizer/main.cpp @@ -1,12 +1,21 @@ #include -#include "diagramrecognizer.h" +#include "diagramRecognizer.h" +#include +#include +#include +#include +#include +#include +#include "recognizers/mixedGesturesManager.h" +#include "simpleFormsInitializer.h" +#include -int main(int argc, char *argv[]) +int main(int argc, char **argv) { - QApplication a(argc, argv); - DiagramRecognizer widget; - widget.setGeometry(100, 100, 500, 355); - widget.show(); + QApplication a(argc, argv); + DiagramRecognizer widget; + widget.setGeometry(100, 100, 500, 355); + widget.show(); - return a.exec(); + return a.exec(); } diff --git a/DiagramRecognizer/moc_diagramRecognizer.cpp b/DiagramRecognizer/moc_diagramRecognizer.cpp new file mode 100644 index 0000000..9bde0dd --- /dev/null +++ b/DiagramRecognizer/moc_diagramRecognizer.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** Meta object code from reading C++ file 'diagramRecognizer.h' +** +** Created by: The Qt Meta Object Compiler version 63 (Qt 4.8.4) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "diagramRecognizer.h" +#if !defined(Q_MOC_OUTPUT_REVISION) +#error "The header file 'diagramRecognizer.h' doesn't include ." +#elif Q_MOC_OUTPUT_REVISION != 63 +#error "This file was generated using the moc from 4.8.4. It" +#error "cannot be used with the include files from this version of Qt." +#error "(The moc has changed too much.)" +#endif + +QT_BEGIN_MOC_NAMESPACE +static const uint qt_meta_data_DiagramRecognizer[] = { + + // content: + 6, // revision + 0, // classname + 0, 0, // classinfo + 4, 14, // methods + 0, 0, // properties + 0, 0, // enums/sets + 0, 0, // constructors + 0, // flags + 1, // signalCount + + // signals: signature, parameters, type, tag, flags + 53, 19, 18, 18, 0x05, + + // slots: signature, parameters, type, tag, flags + 96, 18, 18, 18, 0x0a, + 104, 18, 18, 18, 0x0a, + 116, 18, 18, 18, 0x0a, + + 0 // eod +}; + +static const char qt_meta_stringdata_DiagramRecognizer[] = { + "DiagramRecognizer\0\0mDiagram,mBitmap,mFormSegmentator\0" + "print(PathVector,Bitmap*,FormSegmentator*)\0" + "clear()\0recognize()\0recognizeImage()\0" +}; + +void DiagramRecognizer::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) +{ + if (_c == QMetaObject::InvokeMetaMethod) { + Q_ASSERT(staticMetaObject.cast(_o)); + DiagramRecognizer *_t = static_cast(_o); + switch (_id) { + case 0: _t->print((*reinterpret_cast< PathVector(*)>(_a[1])),(*reinterpret_cast< Bitmap*(*)>(_a[2])),(*reinterpret_cast< FormSegmentator*(*)>(_a[3]))); break; + case 1: _t->clear(); break; + case 2: _t->recognize(); break; + case 3: _t->recognizeImage(); break; + default: ; + } + } +} + +const QMetaObjectExtraData DiagramRecognizer::staticMetaObjectExtraData = { + 0, qt_static_metacall +}; + +const QMetaObject DiagramRecognizer::staticMetaObject = { + { &QWidget::staticMetaObject, qt_meta_stringdata_DiagramRecognizer, + qt_meta_data_DiagramRecognizer, &staticMetaObjectExtraData } +}; + +#ifdef Q_NO_DATA_RELOCATION +const QMetaObject &DiagramRecognizer::getStaticMetaObject() { return staticMetaObject; } +#endif //Q_NO_DATA_RELOCATION + +const QMetaObject *DiagramRecognizer::metaObject() const +{ + return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; +} + +void *DiagramRecognizer::qt_metacast(const char *_clname) +{ + if (!_clname) return 0; + if (!strcmp(_clname, qt_meta_stringdata_DiagramRecognizer)) + return static_cast(const_cast< DiagramRecognizer*>(this)); + return QWidget::qt_metacast(_clname); +} + +int DiagramRecognizer::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +{ + _id = QWidget::qt_metacall(_c, _id, _a); + if (_id < 0) + return _id; + if (_c == QMetaObject::InvokeMetaMethod) { + if (_id < 4) + qt_static_metacall(this, _c, _id, _a); + _id -= 4; + } + return _id; +} + +// SIGNAL 0 +void DiagramRecognizer::print(PathVector _t1, Bitmap * _t2, FormSegmentator * _t3) +{ + void *_a[] = { 0, const_cast(reinterpret_cast(&_t1)), const_cast(reinterpret_cast(&_t2)), const_cast(reinterpret_cast(&_t3)) }; + QMetaObject::activate(this, &staticMetaObject, 0, _a); +} +QT_END_MOC_NAMESPACE diff --git a/DiagramRecognizer/moc_output.cpp b/DiagramRecognizer/moc_output.cpp new file mode 100644 index 0000000..9eeeaa4 --- /dev/null +++ b/DiagramRecognizer/moc_output.cpp @@ -0,0 +1,93 @@ +/**************************************************************************** +** Meta object code from reading C++ file 'output.h' +** +** Created by: The Qt Meta Object Compiler version 63 (Qt 4.8.4) +** +** WARNING! All changes made in this file will be lost! +*****************************************************************************/ + +#include "output.h" +#if !defined(Q_MOC_OUTPUT_REVISION) +#error "The header file 'output.h' doesn't include ." +#elif Q_MOC_OUTPUT_REVISION != 63 +#error "This file was generated using the moc from 4.8.4. It" +#error "cannot be used with the include files from this version of Qt." +#error "(The moc has changed too much.)" +#endif + +QT_BEGIN_MOC_NAMESPACE +static const uint qt_meta_data_Output[] = { + + // content: + 6, // revision + 0, // classname + 0, 0, // classinfo + 1, 14, // methods + 0, 0, // properties + 0, 0, // enums/sets + 0, 0, // constructors + 0, // flags + 0, // signalCount + + // slots: signature, parameters, type, tag, flags + 55, 8, 7, 7, 0x0a, + + 0 // eod +}; + +static const char qt_meta_stringdata_Output[] = { + "Output\0\0RecognizedDiagram,newBitmap,newFormSegmentator\0" + "draw(PathVector,Bitmap*,FormSegmentator*)\0" +}; + +void Output::qt_static_metacall(QObject *_o, QMetaObject::Call _c, int _id, void **_a) +{ + if (_c == QMetaObject::InvokeMetaMethod) { + Q_ASSERT(staticMetaObject.cast(_o)); + Output *_t = static_cast(_o); + switch (_id) { + case 0: _t->draw((*reinterpret_cast< PathVector(*)>(_a[1])),(*reinterpret_cast< Bitmap*(*)>(_a[2])),(*reinterpret_cast< FormSegmentator*(*)>(_a[3]))); break; + default: ; + } + } +} + +const QMetaObjectExtraData Output::staticMetaObjectExtraData = { + 0, qt_static_metacall +}; + +const QMetaObject Output::staticMetaObject = { + { &QWidget::staticMetaObject, qt_meta_stringdata_Output, + qt_meta_data_Output, &staticMetaObjectExtraData } +}; + +#ifdef Q_NO_DATA_RELOCATION +const QMetaObject &Output::getStaticMetaObject() { return staticMetaObject; } +#endif //Q_NO_DATA_RELOCATION + +const QMetaObject *Output::metaObject() const +{ + return QObject::d_ptr->metaObject ? QObject::d_ptr->metaObject : &staticMetaObject; +} + +void *Output::qt_metacast(const char *_clname) +{ + if (!_clname) return 0; + if (!strcmp(_clname, qt_meta_stringdata_Output)) + return static_cast(const_cast< Output*>(this)); + return QWidget::qt_metacast(_clname); +} + +int Output::qt_metacall(QMetaObject::Call _c, int _id, void **_a) +{ + _id = QWidget::qt_metacall(_c, _id, _a); + if (_id < 0) + return _id; + if (_c == QMetaObject::InvokeMetaMethod) { + if (_id < 1) + qt_static_metacall(this, _c, _id, _a); + _id -= 1; + } + return _id; +} +QT_END_MOC_NAMESPACE diff --git a/DiagramRecognizer/newfigure.cpp b/DiagramRecognizer/newfigure.cpp new file mode 100644 index 0000000..e69de29 diff --git a/DiagramRecognizer/output.h b/DiagramRecognizer/output.h index e467329..f89efda 100644 --- a/DiagramRecognizer/output.h +++ b/DiagramRecognizer/output.h @@ -3,7 +3,7 @@ #include "component.h" #include #include "bitmap.h" -#include "formsegmentator.h" +#include "formSegmentator.h" #include class Output : public QWidget diff --git a/DiagramRecognizer/paintmanager.cpp b/DiagramRecognizer/paintManager.cpp similarity index 100% rename from DiagramRecognizer/paintmanager.cpp rename to DiagramRecognizer/paintManager.cpp diff --git a/DiagramRecognizer/paintmanager.h b/DiagramRecognizer/paintManager.h similarity index 100% rename from DiagramRecognizer/paintmanager.h rename to DiagramRecognizer/paintManager.h diff --git a/DiagramRecognizer/readme.txt b/DiagramRecognizer/readme.txt deleted file mode 100644 index 04d799c..0000000 --- a/DiagramRecognizer/readme.txt +++ /dev/null @@ -1,38 +0,0 @@ -Hello world! - -We have made new architecture. Actually we have just changed some names and added few classes :) -So now we have a class for each stage. -First of all lets talk about basics. We call fragment(arc) without selfintersection - component. -United components are figures or edges. Set of figures connected by edges - diagram. - -There are 7 stages in our plans: -1. Recognize image and take contour. -2. Divide contour into components. -3. Unite components into figures and edges. -4-5. Recognize figures and edges. Study system. -6. Output. -7. Create database. - -Existing prototype provide these stages by these classes. -1. bitmap -2. component -3. formSegmentator -4-5. abstractRecognizer and recognizers folder. (for now it hasn't any study system) -6. output (captain obvious) -7. simpleFormInitializer. - -So if you are trying to write code for "1. Recognize image and take contour.", you have to do it in bitmap. -Existing algorithm can't fit our needs, so don't fear to delete some written code(but do it only in your class). - -This is our conception: -digramRecognizer is the main class. It will call other classes and receive their results. -For example, it will take image, send it to bitmap class, that will recognize this image and return a grid. -Then diagramRecognizer will send grid with contour to component class, that will divide this cintour into components. -So it will return pathVector with all components of contour and so on. -Please check the whole conception in the Conception.jpg - -At the end we will have 7 independent classes and each of them can work on their own. - -Best wishes, - -Alexey Kor, George Kraychik diff --git a/DiagramRecognizer/recognizers/mixedGesturesManager.cpp b/DiagramRecognizer/recognizers/mixedGesturesManager.cpp new file mode 100644 index 0000000..23cd617 --- /dev/null +++ b/DiagramRecognizer/recognizers/mixedGesturesManager.cpp @@ -0,0 +1,40 @@ +#include "mixedGesturesManager.h" +#include "rectangleGesturesManager.h" +#include "nearestPosGridGesturesManager.h" +#include "curveKeyBuilder.h" + +double const weight1 = 0.2; +double const weight2 = 1 - weight1; + +MixedGesturesManager::MixedGesturesManager() +{ +} + +double MixedGesturesManager::maxDistance(QString const &) const +{ + return 150; //1000 +} +bool MixedGesturesManager::isMultistroke() const +{ + return true; +} + +double MixedGesturesManager::distance(QPair const & key1, + MixedKey const & key2) const +{ + double dist1 = + (new RectangleGesturesManager())->distance(key1.first, key2.first); + double dist2 = + (new NearestPosGridGesturesManager)->distance(key1.second, key2.second); + return dist1 * weight1 + dist2 * weight2; +} + +MixedKey MixedGesturesManager::key( + PathVector const & path) const +{ + double * key1 = (new RectangleGesturesManager())->key(path); + double * key2 = (new NearestPosGridGesturesManager)->key(path); + return MixedKey(key1, key2); +} + + diff --git a/DiagramRecognizer/recognizers/mixedGesturesManager.h b/DiagramRecognizer/recognizers/mixedGesturesManager.h new file mode 100644 index 0000000..31b5bb9 --- /dev/null +++ b/DiagramRecognizer/recognizers/mixedGesturesManager.h @@ -0,0 +1,58 @@ +#pragma once +#include "abstractRecognizer.h" +#include "geometricForms.h" + +class MixedGesturesManager : public GesturesRecognizer +{ +public: + MixedGesturesManager(); + double maxDistance(QString const &) const; + bool isMultistroke() const; + double distance(MixedKey const & key1, + MixedKey const & key2) const; + MixedKey key(PathVector const &path) const; +}; + +class MixedClassifier +{ +public: + MixedClassifier(const PathVector &path) + { + MixedGesturesManager gManager; + mKey = gManager.key(path); + } + + MixedClassifier(){} + + double distance(const MixedClassifier &classifier) + { + MixedKey key = classifier.key(); + MixedGesturesManager gManager; + return gManager.distance(key, mKey); + } + MixedClassifier getPoint(MixedClassifier const & centre, double centreWeight) + { + double * key1 = centre.key().first; + double * key2 = centre.key().second; + double * finalKey1 = new double[gridSize * gridSize]; + double * finalKey2 = new double[gridSize * gridSize]; + for (int i = 0; i < gridSize * gridSize; i ++) + { + finalKey1[i] = (key1[i] * centreWeight + mKey.first[i]) / (centreWeight + 1); + finalKey2[i] = (key2[i] * centreWeight + mKey.second[i]) / (centreWeight + 1); + } + return MixedClassifier(MixedKey(finalKey1, finalKey2)); + } + + MixedKey key() const + { + return mKey; + } + +private: + MixedClassifier(MixedKey const & key) + { + mKey = key; + } + MixedKey mKey; +}; diff --git a/DiagramRecognizer/recognizers/nearestPosGridGesturesManager.cpp b/DiagramRecognizer/recognizers/nearestPosGridGesturesManager.cpp new file mode 100644 index 0000000..0342b62 --- /dev/null +++ b/DiagramRecognizer/recognizers/nearestPosGridGesturesManager.cpp @@ -0,0 +1,55 @@ +#include "nearestPosGridGesturesManager.h" +#include "curveKeyBuilder.h" +#include "stdlib.h" + +NearestPosGridGesturesManager::NearestPosGridGesturesManager() +{ +} + +double NearestPosGridGesturesManager::maxDistance(QString const &) const +{ + return 1000; +} +bool NearestPosGridGesturesManager::isMultistroke() const +{ + return true; +} + +double NearestPosGridGesturesManager::distance(double * const &key1, + double * const &key2) const +{ + double norm = 0; + double sum = 0; + for (int i = 0; i < gridSize * gridSize; i ++) { + double dif = abs(key1[i] - key2[i]); + sum += dif; + norm = std::max(norm, dif); + } + //return norm / (gridSize * gridSize); + return norm + sum / (gridSize * gridSize); +} + +double * NearestPosGridGesturesManager::key(PathVector const &path) const +{ + Key key = KeyBuilder::key(path, gridSize, gridSize); + double * finalKey = new double[gridSize * gridSize]; + for (int i = 0; i < gridSize * gridSize; i ++) { + finalKey[i] = gridSize; + } + if (key.isEmpty()) { + return finalKey; + } + for (int i = 0; i < gridSize; i ++) { + for (int j = 0; j < gridSize; j ++) { + double dist = abs(key.at(0).first - i) + abs(key.at(0).second - j); + foreach (SquarePos const &pos, key) { + double norm = abs(pos.first - i) + abs(pos.second - j); + dist = std::min(dist, norm); + } + finalKey[i * gridSize + j] = dist; + } + } + return finalKey; +} + + diff --git a/DiagramRecognizer/recognizers/nearestPosGridGesturesManager.h b/DiagramRecognizer/recognizers/nearestPosGridGesturesManager.h new file mode 100644 index 0000000..b5a448d --- /dev/null +++ b/DiagramRecognizer/recognizers/nearestPosGridGesturesManager.h @@ -0,0 +1,13 @@ +#pragma once +#include "abstractRecognizer.h" +#include "geometricForms.h" + +class NearestPosGridGesturesManager : public GesturesRecognizer +{ +public: + NearestPosGridGesturesManager(); + double maxDistance(QString const &objectName) const; + bool isMultistroke() const; + double distance(double * const &key1, double * const &key2) const; + double * key(PathVector const &path) const; +}; diff --git a/DiagramRecognizer/recognizers/rectangleGesturesManager.cpp b/DiagramRecognizer/recognizers/rectangleGesturesManager.cpp new file mode 100644 index 0000000..5c9d78d --- /dev/null +++ b/DiagramRecognizer/recognizers/rectangleGesturesManager.cpp @@ -0,0 +1,50 @@ +#include "rectangleGesturesManager.h" +#include "curveKeyBuilder.h" +#include "QDebug" +#include "cmath" + +RectangleGesturesManager::RectangleGesturesManager() +{ +} + +double RectangleGesturesManager::maxDistance(QString const &) const +{ + return 1000; +} +bool RectangleGesturesManager::isMultistroke() const +{ + return true; +} + +double RectangleGesturesManager::distance(double * const &key1, + double * const &key2) const +{ + double norm = 0; + double sum = 0; + for (int i = 0; i < gridSize * gridSize; i ++) { + sum += std::abs(key1[i] - key2[i]); + norm = std::max(norm, std::abs(key1[i] - key2[i])); + } + return sum / (gridSize * gridSize); +} + +double * RectangleGesturesManager::key(PathVector const &path) const +{ + Key key = KeyBuilder::key(path, gridSize, gridSize); + double * finalKey = new double[gridSize * gridSize]; + for (int i = 0; i < gridSize * gridSize; i ++) { + finalKey[i] = key.size(); + } + for (int k = 0; k < key.size(); k ++) + { + SquarePos pos = key.at(k); + for (int i = 0; i < pos.first; i ++) { + for (int j = 0; j < pos.second; j ++) { + finalKey[i * gridSize + j] --; + } + } + } + return finalKey; +} + + diff --git a/DiagramRecognizer/recognizers/rectangleGesturesManager.h b/DiagramRecognizer/recognizers/rectangleGesturesManager.h new file mode 100644 index 0000000..c34f2e9 --- /dev/null +++ b/DiagramRecognizer/recognizers/rectangleGesturesManager.h @@ -0,0 +1,13 @@ +#pragma once +#include "abstractRecognizer.h" +#include "geometricForms.h" + +class RectangleGesturesManager : public GesturesRecognizer +{ +public: + RectangleGesturesManager(); + double maxDistance(QString const &objectName) const; + bool isMultistroke() const; + double distance(double * const & key1, double * const & key2) const; + double * key(PathVector const & path) const; +}; diff --git a/DiagramRecognizer/section.cpp b/DiagramRecognizer/section.cpp new file mode 100644 index 0000000..b8d2418 --- /dev/null +++ b/DiagramRecognizer/section.cpp @@ -0,0 +1,132 @@ +#pragma once; +#include "section.h" +#include "abstractRecognizer.h" +#include "recognizers/mixedGesturesManager.h" +#include "simpleFormsInitializer.h" +#include "graph.h" + +Recognizer::Recognizer() { } +int Recognizer::getType(QList *shell) +{ + AbstractRecognizer *abstractRecognizer = new AbstractRecognizer(new MixedGesturesManager(), + SimpleFormsInitializer::initialForms()); + + Component *newComp = new Component(); + foreach (Component *component, *shell) + { + newComp->append(*component); + } + if (abstractRecognizer->recognizeObject(newComp->figure(-1000, -1000)).empty()) + { + delete newComp; + return 0; + } + delete newComp; + return 1; + /*std::set sPos; + std::set finish; + int count = 0; + for (QList < Component *>::const_iterator i = shell->begin(); i != shell->end(); i++) + { + Component *cur = *i; + SquarePos first = cur->first(); + SquarePos last = cur->last(); + if ((finish.find(first) != finish.end()) || (finish.find(last) != finish.end())) + { + return false; + } + if (sPos.find(first) != sPos.end()) + { + finish.insert(first); + count++; + } + if (sPos.find(last) != sPos.end()) + { + finish.insert(last); + count++; + } + if (first == last) + { + count++; + } + sPos.insert(first); + sPos.insert(last); + } + if (shell->size() != count) { return false; } + sPos.clear(); + for (QList < Component *>::const_iterator i = shell->begin(); i != shell->end(); i++) + { + foreach(SquarePos pos, *(*i)) + { + sPos.insert(pos); + } + } + SquarePos minUpper(*(sPos.begin())); + for (std::set::iterator i = sPos.begin(); i != sPos.end(); i++) + { + if (*i < minUpper) { minUpper = *i; } + } + SquarePos cur = minUpper; + SquarePos delta[4] = {SquarePos(0, 1), SquarePos(1, 0), SquarePos(0, -1), SquarePos(-1, 0) }; + bool was = false; + count = 0; + SquarePos start = cur; + for (int i = 0; i < 4; i++) + { + was = false; + while (sPos.find(cur + delta[i]) != sPos.end()) + { + //if (start == cur) { break; } + cur = cur + delta[i]; + was = true; + if ((cur == start) && (count == 3)) { return true; } + if (cur == start) { return false; } + } + if (!was) { return false; } + count++; + } + return false;*/ +} +Component *Recognizer::reverse(Component *comp) +{ + Component *res = new Component(); + for (int i = 0; i < comp->size(); i++) + { + res->push_back(comp->last()); + comp->removeLast(); + } + delete comp; + return res; +} + +Section::Section() +{ + mComps = new QList < Component *>(); + mType = 0; +} +Section::Section(QList < Component *> *components) +{ + mComps = new QList < Component *>(*components); + setType(Recognizer::getType(components)); +} +Section::Section(Section *section) +{ + mComps = new QList < Component *>(*section->getComps()); + mType = section->getType(); +} +Section::~Section() +{ + delete mComps; +} +QList < Component *> * Section::getComps() const +{ + return mComps; +} +int Section::getType() const +{ + return mType; +} +void Section::setType(int value) +{ + mType = value; +} diff --git a/DiagramRecognizer/section.h b/DiagramRecognizer/section.h new file mode 100644 index 0000000..d87eba3 --- /dev/null +++ b/DiagramRecognizer/section.h @@ -0,0 +1,27 @@ +#pragma once; +#include "component.h" +#include + +class Recognizer //doesn't exist here; somewhere else +{ +public: + Recognizer(); + static int getType(QList *shell); + static Component *reverse(Component *comp); +}; + +class Section +{ +public: + Section(); + Section(QList < Component *> *components); + Section(Section *section); + ~Section(); + QList < Component *> *getComps() const; + int getType() const; + void setType(int value); + +private: + QList < Component *> *mComps; + int mType; +}; diff --git a/DiagramRecognizer/segmentator.cpp b/DiagramRecognizer/segmentator.cpp new file mode 100644 index 0000000..eba7fe4 --- /dev/null +++ b/DiagramRecognizer/segmentator.cpp @@ -0,0 +1,734 @@ +#pragma once; +#include +#include +#include +#include + +Segmentator::Segmentator() +{ + mComps = new QList < Component *>(); + mGraph = new Graph(); +} +Segmentator::Segmentator(QList < Component *> *components) +{ + mComps = new QList < Component *>(*components); + mGraph = new Graph(components); +} +Segmentator::~Segmentator() +{ + for (QList < EFigure *>::const_iterator i = mFigures->begin(); i != mFigures->end(); i++) + { + delete *i; + } + delete mFigures; + for (QList < ELink *>::const_iterator i = mLinks->begin(); i != mLinks->end(); i++) + { + delete *i; + } + delete mLinks; + delete mComps; + delete mGraph; +} +void Segmentator::makeSegmentation() +{ + ESegmentator *eSegmentator = new ESegmentator(mComps); + eSegmentator->eSegmentation(); + //ASegmentator *aSegmentator = new ASegmentator(eSegmentator); + //aSegmentator->aSegmentation(); + //figures = new QList < EFigure *> (*(eSegmentator->getFigures())); + //links = new QList < ELink *> (*(eSegmentator->getLinks())); + mFigures = new QList < EFigure *>(); + foreach(EFigure *fig, *(eSegmentator->getFigures())) + { + mFigures->push_back(new EFigure(fig)); + } + mLinks = new QList < ELink *>(); + foreach(ELink *link, *(eSegmentator->getLinks())) + { + mLinks->push_back(new ELink(link)); + } + delete eSegmentator; + //delete aSegmentator; +} +QList < Component *> *Segmentator::getComponents() const +{ + return mComps; +} +QList < EFigure *> *Segmentator::getFigures() const +{ + return mFigures; +} +QList < ELink *> *Segmentator::getLinks() const +{ + return mLinks; +} +Graph *Segmentator::getGraph() const +{ + return mGraph; +} +int Segmentator::dist(Component *comp, SquarePos point) +{ + int sum = 0; + int dx, dy; + for (Component::const_iterator i = comp->begin(); i != comp->end(); i++) + { + dx = (*i).first - point.first; + dy = (*i).second - point.second; + sum += dx*dx + dy*dy; + } + return sum; +} + +/*QList < Component *> *Segmentator::getOuterShell(QList < Component *> *comps, Graph *graph) //comps are connected +{ + std::set *set1 = new std::set < Component *>(); + std::set *set2 = new std::set < Component *>(); + for (QList < Component *>::const_iterator i = comps->begin(); i != comps->end(); i++) + { + set1->insert(*i); + } + QList < Component *> *res = new QList < Component *>(); + int maxDist = -1; + int curDist; + SquarePos center = Component::center(comps); + QList < Component *> *curList; + QList < Component *>::iterator resItr = res->begin(); + + QList < Component *>::const_iterator beg = Component::getOuterComponent(comps); + QList < Component *>::const_iterator itr = beg; + SquarePos s1 = (*itr)->first(); + SquarePos s2 = (*itr)->last(); + res->push_front(*itr); + set1->erase(*itr); + maxDist = -1; + curList = graph->getInterList(*itr); + for (QList < Component *>::const_iterator i = curList->begin(); i != curList->end(); i++) + { + if (set1->find(*i) != set1->end()) //if found + { + curDist = Segmentator::dist(*i, center); + if (curDist > maxDist) + { + maxDist = curDist; + itr = i; + } + } + } + if (maxDist == -1) + { + return res; + } + res->push_front(*itr); + set2->insert(*itr); + resItr++; + set1->erase(*itr); + SquarePos tmp1 = (*itr)->first(); + SquarePos tmp2 = (*itr)->last(); + if ((s1 == tmp1) || (s1 == tmp2)) + { + s1 = s2; + } + while (true) + { + maxDist = -1; + curList = graph->getInterList(*itr); + for (QList < Component *>::const_iterator i = curList->begin(); i != curList->end(); i++) + { + if (set1->find(*i) != set1->end()) + { + curDist = Segmentator::dist(*i, center); + if (curDist > maxDist) + { + maxDist = curDist; + itr = i; + } + } + } + if (maxDist == -1) + { + for (QList < Component *>::const_iterator i = curList->begin(); i != curList->end(); i++) + { + if (set2->find(*i) != set2->end()) + { + curDist = Segmentator::dist(*i, center); + if (curDist > maxDist) + { + maxDist = curDist; + itr = i; + } + } + } + } + res->push_front(*itr); + set2->insert(*itr); + resItr++; + set1->erase(*itr); + SquarePos d1 = (*itr)->first(); + SquarePos d2 = (*itr)->last(); + if ((d1 == s1) || (d2 == s1)) + { + break; + } + if (*beg == *itr) { break; } //not needed; better delete + } + //res->erase(res->begin()); + return res; +}*/ +bool Segmentator::areConnected(std::set *comps, Graph & graph) +{ + std::stack s; + s.push(*(comps->begin())); + std::set marked; + marked.insert(s.top()); + while (!s.empty()) + { + bool wereInFor = false; + QList < Component *> *list = graph.getInterList(s.top()); + for (QList < Component *>::iterator i = list->begin(); i != list->end(); i++) + { + if (wereInFor) { break; } + Component *cur = *i; + if (comps->find(cur) == comps->end()) { continue; } + if (marked.find(cur) != marked.end()) { continue; } + wereInFor = true; + s.push(cur); + marked.insert(cur); + } + if (!wereInFor) + { + s.pop(); + } + } + return comps->size() == marked.size(); +} + +std::set < Component *> *Segmentator::extractBridge(std::set < Component *> *comps, Graph &graph) +{ + std::set *result = new std::set(); + std::set *copy = new std::set(*comps); + for (std::set < Component *>::iterator i = comps->begin(); i != comps->end(); i++) + { + Component *cur = *i; + copy->erase(cur); + SquarePos beg = cur->first(); + SquarePos end = cur->last(); + std::set *list1 = graph.getIList(beg); + std::set *list2 = graph.getIList(end); + if (list1->size() == 1 || list2->size() == 1) + { + result->insert(cur); + copy->insert(cur); + continue; + } + if (!Segmentator::areConnected(copy, graph)) + { + result->insert(cur); + } + copy->insert(cur); + } + delete copy; + return result; +} + +QList < Component *> *Segmentator::getOuterShell(QList < Component *> *components, Graph & graph) //comps are connected +{ + std::set *comps = Segmentator::QListToSet(components); + /*for (QList < Component *>::iterator i = components->begin(); i != components->end(); i++) + { + comps->insert(*i); + }*/ + for (QList::iterator i = components->begin(); i != components->end(); i++) + { + Component *curComp = *i; + comps->erase(curComp); + if (!Field::compInContur(curComp, comps)) + { + comps->insert(curComp); + } + } + QList < Component *> *compsList = Segmentator::SetToQList(comps); + /*for (std::set < Component *>::const_iterator i = comps->begin(); i != comps->end(); i++) + { + compsList->push_back(*i); + }*/ + delete comps; + return compsList; + /*std::stack s; + s.push((*(comps->begin()))->first()); + SquarePos start = s.top(); + std::set markedEdges; + QList < Component *> *result = new QList < Component *>(); + while(true) + { + bool wereInFor = false; + std::set < Component *> *list = graph.getIList(s.top()); + for (std::set < Component *>::iterator i = list->begin(); i != list->end(); i++) + { + if (wereInFor) { break; } + Component *curEdge = *i; + if (markedEdges.find(curEdge) != markedEdges.end()) { continue; } + if (comps->find(curEdge) == comps->end()) { continue; } + wereInFor = true; + SquarePos anotherSide = curEdge->getAnotherSide(s.top()); + s.push(anotherSide); + result->push_back(curEdge); + markedEdges.insert(curEdge); + comps->erase(curEdge); + } + if (!wereInFor) + { + s.pop(); + result->push_back(result->last()); + } + if (s.empty() || start == s.top()) { break; } + } + for (std::set::iterator i = comps->begin(); i != comps->end(); i++) + { + result->push_back(*i); + } + delete comps; + return result;*/ +} +void Segmentator::clearInnerEdges(QList *edges, Graph & graph) +{ + std::set < SquarePos> border; + for (QList::const_iterator i = edges->begin(); i != edges->end(); i++) + { + border.insert((*i)->first()); + border.insert((*i)->last()); + } + IList *map = graph.getIList(); + for (IList::iterator i = map->begin(); i != map->end(); i++) + { + std::set < Component * > *list = (*i).second; + for (std::set < Component * >::iterator itr = list->begin(); itr != list->end(); itr++) + { + if (Field::compInContur(*itr, edges)) + { + list->erase(itr); + } + } + SquarePos pos = (*i).first; + map->erase(i); + map->insert(std::pair *>(pos, list)); + } +} + +void Segmentator::buildCycle(Component *comp, Graph & graph, QList < Component *> &newEdges) +{ + newEdges.clear(); + if (graph.mInterListIsEmpty()) { return; } + std::stack s; + std::set finalNodes; + newEdges.push_back(comp); + //s.push(comp->first()); + finalNodes.insert(comp->first()); + s.push(comp->last()); + //finalNodes.insert(s.top()); + std::set marked; + marked.insert(comp); + bool finishWhile = false; + while (!s.empty()) + { + std::set *list = graph.getIList(s.top()); + bool wereInFor = false; + for (std::set::iterator i = list->begin(); i != list->end(); i++) + { + if (wereInFor) { break; } + Component *cur = *i; + SquarePos anotherSide = cur->getAnotherSide(s.top()); + if (marked.find(cur) != marked.end()) { continue; } + wereInFor = true; + s.push(anotherSide); + marked.insert(cur); + newEdges.push_back(cur); + if (finalNodes.find(anotherSide) != finalNodes.end()) //was found + { + finishWhile = true; + break; + } + } + if (finishWhile) { break; } + if (!wereInFor) + { + newEdges.removeLast(); + s.pop(); + } + } +} + +QList < Component *> *Segmentator::getInnerShell(Component *comp, QList < Component *> *comps, Graph &graph) //comps are connected +{ + if ((comps->size() == 1) && (comps->first() == comp)) { return comps; } + if ((comps->size() == 1) && (comps->first() != comp)) { return 0; } + if ((graph.getNodes()->size() == 2) && (comps->size() == 2)) { return new QList < Component *>(*comps); } + Graph cGraph(graph, 1); + std::set *compsSet = Segmentator::QListToSet(comps); + QList < Component *> cComps(*comps); + QList < Component *> newEdges; + QList < Component *> *edges; + //std::set *edges = new std::set(); + std::set finalNodes; + QList < Component *> *res = new QList < Component *>(); + cGraph.eraseEdge(comp); + Segmentator::buildCycle(comp, cGraph, newEdges); + edges = new QList(newEdges); + for (std::set::iterator i = compsSet->begin(); i != compsSet->end(); i++) + { + Component *cur = *i; + if (!Field::compInContur(cur, edges)) + { + cGraph.eraseEdge(cur); + //compsSet->erase(cur); + } + } + while (true) + { + for (QList < Component *>::iterator i = edges->begin(); i != edges->end(); i++) + { + Component *cur = *i; + if (cur == comp) { continue; } + //Graph oldGraph(cGraph); + cGraph.eraseEdge(cur); + Segmentator::buildCycle(comp, cGraph, newEdges); + if (!newEdges.empty()) { break; } + //cGraph = oldGraph; + cGraph.insertEdge(cur); + } + if (newEdges.empty()) { break; } + delete edges; + edges = new QList(newEdges); + for (std::set::iterator i = compsSet->begin(); i != compsSet->end(); i++) + { + Component *cur = *i; + if (!Field::compInContur(cur, edges)) + { + cGraph.eraseEdge(cur); + compsSet->erase(cur); + } + } + /*for (QList < Component *>::iterator i = edges->begin(); i != edges->end(); i++) + { + cGraph.eraseEdge(*i); + }*/ + } + return edges; +} + +QList *Segmentator::priorSort(QList *comps) +{ + return comps; +} +QList < Component *> *Segmentator::priorSort(std::set &set) +{ + QList < Component *> *newList = new QList < Component *>(); + foreach(Component *cur, set) + { + newList->push_back(cur); + } + return newList; +} + +std::set *Segmentator::QListToSet(QList < Component *> *comps) +{ + std::set *set = new std::set(); + for (QList < Component *>::const_iterator i = comps->begin(); i != comps->end(); i++) + { + set->insert(*i); + } + return set; +} +QList < Component *> *Segmentator::SetToQList(std::set *comps) +{ + QList < Component *> *list = new QList < Component *>(); + for (std::set < Component *>::const_iterator i = comps->begin(); i != comps->end(); i++) + { + list->push_back(*i); + } + return list; +} + +Segmentator::ASegmentator::ASegmentator() +{ + mFigures = new QList < Figure *>(); + mLinks = new QList < Link *>(); +} +Segmentator::ASegmentator::ASegmentator(ESegmentator *eSegmentator) : eSegmentator(eSegmentator) { } +void Segmentator::ASegmentator::aSegmentation() +{ + +} +Segmentator::ESegmentator *Segmentator::ASegmentator::getESegmentator() const +{ + return eSegmentator; +} +QList < Figure *> *Segmentator::ASegmentator::getFigures() const +{ + return mFigures; +} + +QList < Link *> *Segmentator::ASegmentator::getLinks() const +{ + return mLinks; +} +Segmentator::ESegmentator::ESegmentator() +{ + mComps = new QList(); + mFigures = new QList < EFigure *>(); + mLinks = new QList < ELink *>(); + mGraph = new Graph(); +} +Segmentator::ESegmentator::~ESegmentator() +{ + for (QList < EFigure *>::const_iterator i = mFigures->begin(); i != mFigures->end(); i++) + { + delete *i; + } + delete mFigures; + for (QList < ELink *>::const_iterator i = mLinks->begin(); i != mLinks->end(); i++) + { + delete *i; + } + delete mLinks; + delete mComps; + delete mGraph; +} + +Segmentator::ESegmentator::ESegmentator(QList *cComp) +{ + mComps = new QList < Component *>(*cComp); + mFigures = new QList < EFigure *>(); + mLinks = new QList < ELink *>(); + mGraph = new Graph(mComps); +} +void Segmentator::ESegmentator::eSegmentation() //splits connected component into elementary items (figures and links) +{ + QList < EFigure *> *figures = new QList < EFigure *>(); + QList < ELink *> *links = new QList < ELink *>(); + Graph graph(*mGraph, 1); + bool res = makeESegmentation(mComps, figures, links, graph); + this->mFigures = figures; + this->mLinks = links; + if (!res) { return; } //if error accured + makeSectionSegmentation(); +} +void Segmentator::ESegmentator::makeSectionSegmentation() +{ + for (QList < EFigure *>::const_iterator i = mFigures->begin(); i != mFigures->end(); i++) + { + segmentateSection(*i); + } +} +//CComponent *getCComp() { return mCComp; } +QList < Component *> *Segmentator::ESegmentator::getCComp() const { return mComps; } +QList < EFigure *> *Segmentator::ESegmentator::getFigures() const { return mFigures; } +QList< ELink *> *Segmentator::ESegmentator::getLinks() const { return mLinks; } +Graph *Segmentator::ESegmentator::getGraph() const { return mGraph; } + +void Segmentator::ESegmentator::segmentateSection(EFigure *figure) +{ + QList < Component *> *comps = new QList < Component *>(); + for (QList < Component *>::iterator i = mComps->begin(); i != mComps->end(); i++) + { + if (Field::compInContur(*i, figure->getShell())) + { + comps->push_back(*i); + } + } + if (comps->size() == figure->getShell()->size()) + { + figure->addSection(figure->getShell()); + return; + } + Graph graph(comps); + std::set outer; + std::set inner; + QList < Component *> *globShell = new QList < Component *>(*(figure->getShell())); + while (!comps->empty()) + { + outer.clear(); + inner.clear(); + QList < Component *> *shell = Segmentator::getInnerShell(globShell->first(), comps, graph); + for (QList < Component *>::const_iterator i = shell->begin(); i != shell->end(); i++) + { + Component *cur = *i; + int index = globShell->indexOf(cur); + if (index != -1) + { + outer.insert(cur); + } + else + { + inner.insert(cur); + } + } + figure->addSection(shell); + for (std::set::const_iterator i = outer.begin(); i != outer.end(); i++) + { + Component *cur = *i; + int index = comps->indexOf(cur); + comps->removeAt(index); + graph.eraseEdge(cur); + index = globShell->indexOf(cur); + globShell->removeAt(index); + } + for (std::set::const_iterator i = inner.begin(); i != inner.end(); i++) + { + globShell->push_back(*i); + } + } + delete comps; + delete globShell; +} +CComponent *Segmentator::ESegmentator::filter(CComponent *comps) //filters fixed components + { + CComponent *res = new CComponent(); + for (QList < Component *>::iterator itr = comps->getComponents()->begin(); itr != comps->getComponents()->end(); itr++) + { + if (!(*itr)->getIsFixed()) + { + res->addComponent(*itr); + } + } + delete comps; + return res; +} +bool Segmentator::ESegmentator::makeESegmentation(QList < Component *> *comps, QList < EFigure *> *&figures, QList < ELink *> *&links, Graph &graph) //comps are connected +{ + QList < EFigure *> *newFigures = new QList < EFigure *>(); + QList < ELink *> *newLinks = new QList < ELink *>(); + QList < QList < Component *> *> *connComps = Graph::cSegmentation(comps, graph); + if (connComps->size() > 1) + { + bool res; + QList < EFigure *> *newFigs = new QList < EFigure *>(); + QList < ELink *> *newLks = new QList < ELink *>(); + for (QList < QList < Component *> *>::const_iterator i = connComps->begin(); i != connComps->end(); i++) + { + newFigures->clear(); + newLinks->clear(); + Graph newGraph(*i); + res = makeESegmentation(*i, newFigures, newLinks, newGraph); + if (!res) + { + for (QList < QList < Component *> *>::const_iterator itr = connComps->begin(); itr != connComps->end(); itr++) + { + delete *itr; + } + delete newFigs; + delete newLks; + delete connComps; + return false; + } + newFigs->append(*newFigures); + newLks->append(*newLinks); + } + figures->append(*newFigs); + links->append(*newLks); + delete newFigs; + delete newLks; + for (QList < QList < Component *> *>::const_iterator itr = connComps->begin(); itr != connComps->end(); itr++) + { + delete *itr; + } + delete connComps; + return true; + } + QList < Component *> *shell = Segmentator::getOuterShell(comps, graph); + int type = Recognizer::getType(shell); + if (type != 0) + { + EFigure *newFigure = new EFigure(shell); + figures->push_back(newFigure); + return true; + } + std::set potLinks; //potential Links + for (QList < Component *>::iterator i = shell->begin(); i != shell->end(); i++) + { + Component *cur = (*i); + if (cur->isClosed()) { continue; } + SquarePos beg = cur->first(); + SquarePos end = cur->last(); + std::set *list = graph.getIList(beg); + int size = list->size(); + foreach (Component *comp, *list) + { + if (comp->isClosed()) { size++; } + } + bool begOk = size >= 3; + list = graph.getIList(end); + size = list->size(); + foreach (Component *comp, *list) + { + if (comp->isClosed()) { size++; } + } + bool endOk = size >= 3; + if (begOk && endOk) + { + potLinks.insert(cur); + } + } + std::set *shellSet = Segmentator::QListToSet(comps); + std::set *curLinks = Segmentator::extractBridge(shellSet, graph); + delete shell; + delete shellSet; + for (std::set::const_iterator i = curLinks->begin(); i != curLinks->end(); i++) + { + if (potLinks.find(*i) == potLinks.end()) + { + //delete shell; + //delete shellSet; + return false; + } + } + QList < Component *> *copyComps = new QList < Component *>(*comps); + if (curLinks->size() > 0) + { + for (std::set::iterator i = curLinks->begin(); i != curLinks->end(); i++) + { + Component *cur = *i; + int index = copyComps->indexOf(cur); + copyComps->removeAt(index); + graph.eraseEdge(cur); + } + //delete curLinks; + bool res = makeESegmentation(copyComps, newFigures, newLinks, graph); + if (!res) + { + delete curLinks; + return false; + } + for (std::set::iterator i = curLinks->begin(); i != curLinks->end(); i++) + { + Component *cur = *i; + links->push_back(new ELink(cur)); + } + //delete curLinks; + figures->append(*newFigures); + links->append(*newLinks); + return true; + } + delete curLinks; + QList < Component *> *sComps = Segmentator::priorSort(potLinks); + for (QList::iterator i = sComps->begin(); i != sComps->end(); i++) + { + Component *cur = *i; + int index = copyComps->indexOf(cur); + copyComps->removeAt(index); + Graph newGraph(graph, 1); + newGraph.eraseEdge(cur); + bool res = makeESegmentation(copyComps, newFigures, newLinks, newGraph); + copyComps->push_back(cur); + if (res) + { + newLinks->push_back(new ELink(cur)); + links->append(*newLinks); + //links->push_back(new ELink(cur)); + figures->append(*newFigures); + delete sComps; + return true; + } + } + delete sComps; + return false; +} diff --git a/DiagramRecognizer/segmentator.h b/DiagramRecognizer/segmentator.h new file mode 100644 index 0000000..a660f7a --- /dev/null +++ b/DiagramRecognizer/segmentator.h @@ -0,0 +1,76 @@ +#pragma once; +#include +#include +#include +#include +#include + +class Segmentator +{ +public: + friend class ESegmentator; + friend class ASegmentator; + Segmentator(); + Segmentator(QList < Component *> *components); + ~Segmentator(); + void makeSegmentation(); + Graph *getGraph() const; + QList < Component *> *getComponents() const; + QList < EFigure *> *getFigures() const; + QList < ELink *> *getLinks() const; + static bool areConnected(std::set *comps, Graph & graph); //should be private + static std::set *extractBridge(std::set < Component *> *comps, Graph & graph); //should be private + class ESegmentator + { + public: + ESegmentator(); + ESegmentator(QList *cComp); + ~ESegmentator(); + void eSegmentation(); + void makeSectionSegmentation(); + void segmentateSection(EFigure *figure); //should be private + QList < Component *> *getCComp() const; + QList < EFigure *> *getFigures() const; + QList < ELink *> *getLinks() const; + Graph *getGraph() const; + private: + QList < Component *> *mComps; //inner connected components + QList < EFigure *> *mFigures; //elementary figures + QList < ELink *> *mLinks; //elementary links + Graph *mGraph; + CComponent *filter(CComponent *comps); + bool makeESegmentation(QList *comps, QList *&figures, QList *&links, Graph &graph); + }; + class ASegmentator + { + public: + ASegmentator(); + ASegmentator(ESegmentator *eSegmentator); + void aSegmentation(); + ESegmentator *getESegmentator() const; + QList < Figure *> *getFigures() const; + QList < Link *> *getLinks() const; + private: + ESegmentator *eSegmentator; + QList < Figure *> *mFigures; + QList < Link *> *mLinks; + }; + +private: + static int dist(Component *comp, SquarePos point); +public: + static QList *getOuterShell(QList < Component *> *comps, Graph &graph); + static QList < Component *> *getInnerShell(Component *comp, QList *comps, Graph &graph); +private: + static void buildCycle(Component *comp, Graph & graph, QList &newEdges); + static void clearInnerEdges(QList < Component *> *edges, Graph & graph); + static std::set *QListToSet(QList < Component *> *comps); + static QList < Component *> *SetToQList(std::set *comps); + static QList *priorSort(QList *comps); + static QList < Component *> *priorSort(std::set &set); + //static Component *chooseLink(std::set &comps, Graph &graph); + QList < EFigure *> *mFigures; + QList < ELink *> *mLinks; + QList < Component *> *mComps; //list of all components + Graph *mGraph; +}; diff --git a/DiagramRecognizer/simpleformsinitializer.cpp b/DiagramRecognizer/simpleFormsInitializer.cpp similarity index 100% rename from DiagramRecognizer/simpleformsinitializer.cpp rename to DiagramRecognizer/simpleFormsInitializer.cpp diff --git a/DiagramRecognizer/simpleformsinitializer.h b/DiagramRecognizer/simpleFormsInitializer.h similarity index 100% rename from DiagramRecognizer/simpleformsinitializer.h rename to DiagramRecognizer/simpleFormsInitializer.h diff --git a/DiagramRecognizer/test.txt~ b/DiagramRecognizer/test.txt~ new file mode 100644 index 0000000..802218c --- /dev/null +++ b/DiagramRecognizer/test.txt~ @@ -0,0 +1,14 @@ +1 4 +1 1 +1 2 +1 3 +1 4 +2 3 +3 3 +3 4 +3 5 +3 3 +3 3 +4 3 +5 3 +0 0 diff --git a/DiagramRecognizer/test2.txt~ b/DiagramRecognizer/test2.txt~ new file mode 100644 index 0000000..c4e6e07 --- /dev/null +++ b/DiagramRecognizer/test2.txt~ @@ -0,0 +1,51 @@ +1 9 +4 2 +4 1 +3 1 +2 1 +1 1 +1 2 +1 3 +1 4 +2 4 +5 5 +2 4 +2 5 +2 6 +2 7 +2 8 +2 5 +4 2 +4 3 +4 4 +3 4 +2 4 +3 7 +2 8 +1 8 +1 9 +1 10 +2 10 +3 10 +3 9 +4 6 +4 2 +5 2 +6 2 +6 3 +6 4 +6 5 +8 8 +6 5 +6 6 +6 7 +6 8 +6 9 +5 9 +4 9 +3 9 +6 3 +2 8 +3 8 +3 9 +0 0 diff --git a/DiagramRecognizer/test4.txt~ b/DiagramRecognizer/test4.txt~ new file mode 100644 index 0000000..9789049 --- /dev/null +++ b/DiagramRecognizer/test4.txt~ @@ -0,0 +1,47 @@ +1 6 +1 3 +1 2 +1 1 +2 1 +3 1 +4 1 +7 5 +4 1 +5 1 +6 1 +6 2 +6 3 +2 4 +4 3 +4 4 +4 5 +4 6 +3 6 +6 3 +6 4 +6 5 +6 6 +5 6 +4 6 +4 7 +1 3 +1 4 +1 5 +1 6 +2 6 +3 6 +4 6 +5 4 +1 3 +2 3 +3 3 +4 3 +6 3 +4 3 +5 3 +6 3 +8 3 +4 1 +4 2 +4 3 +0 0 diff --git a/DiagramRecognizer/test5.txt~ b/DiagramRecognizer/test5.txt~ new file mode 100644 index 0000000..f31787a --- /dev/null +++ b/DiagramRecognizer/test5.txt~ @@ -0,0 +1,64 @@ +1 3 +4 4 +4 3 +4 2 +2 3 +4 4 +4 5 +4 6 +3 3 +3 4 +2 4 +1 4 +0 0 + +1 4 +1 1 +1 2 +1 3 +1 4 +2 7 +1 4 +2 4 +3 4 +4 4 +4 3 +4 2 +4 1 +3 4 +1 1 +2 1 +3 1 +4 1 +0 0 + +1 3 +1 1 +1 2 +1 3 +2 3 +3 3 +3 2 +3 1 +3 3 +1 1 +2 1 +3 1 +4 3 +3 3 +2 3 +1 3 +0 0 + +1 7 +1 1 +1 2 +1 3 +2 3 +3 3 +3 2 +3 1 +0 0 +2 1 +1 1 +0 0 diff --git a/DiagramRecognizer/test9.txt~ b/DiagramRecognizer/test9.txt~ new file mode 100644 index 0000000..c7dc207 --- /dev/null +++ b/DiagramRecognizer/test9.txt~ @@ -0,0 +1,186 @@ +1 7 +8 1 +7 1 +6 1 +5 1 +4 1 +4 2 +4 3 +2 6 +4 3 +3 3 +3 4 +3 5 +3 6 +4 6 +3 4 +4 3 +5 3 +5 4 +5 5 +4 5 +8 1 +8 0 +9 0 +10 0 +10 1 +5 5 +8 1 +8 2 +9 2 +10 2 +10 1 +6 5 +4 6 +4 7 +4 8 +4 9 +4 10 +7 18 +10 1 +11 1 +12 1 +13 1 +14 1 +15 1 +15 2 +15 3 +15 4 +15 5 +15 6 +15 7 +15 8 +15 9 +15 10 +15 11 +14 11 +13 11 +8 4 +12 9 +13 9 +13 10 +13 11 +9 3 +13 11 +13 12 +13 13 +10 4 +13 13 +13 14 +13 15 +12 15 +11 3 +11 13 +12 13 +13 13 +12 3 +11 11 +11 12 +11 13 +13 4 +11 13 +11 14 +11 15 +12 15 +14 10 +8 16 +8 17 +8 18 +9 18 +10 18 +11 18 +12 18 +12 17 +12 16 +12 15 +15 6 +4 10 +5 10 +6 10 +7 10 +8 10 +8 11 +16 3 +6 13 +7 13 +8 13 +17 4 +3 13 +4 13 +5 13 +6 13 +18 3 +1 13 +2 13 +3 13 +19 4 +3 13 +3 14 +3 15 +3 16 +20 4 +6 13 +6 14 +6 15 +6 16 +21 4 +8 13 +8 14 +8 15 +8 16 +22 3 +6 16 +7 16 +8 16 +23 4 +3 16 +4 16 +5 16 +6 16 +24 6 +1 13 +1 14 +1 15 +1 16 +2 16 +3 16 +26 7 +4 10 +3 10 +2 10 +1 10 +1 11 +1 12 +1 13 +27 3 +5 5 +5 6 +4 6 +28 12 +5 5 +6 5 +7 5 +8 5 +9 5 +10 5 +11 5 +12 5 +12 6 +12 7 +12 8 +12 9 +25 4 +8 11 +9 11 +10 11 +11 11 +29 4 +12 9 +11 9 +11 10 +11 11 +30 3 +8 11 +8 12 +8 13 +0 0