├── .gitignore ├── README.md ├── data ├── README.md └── script_realsense.m ├── gaps ├── LICENSE.txt ├── Makefile ├── README.txt ├── apps │ ├── Makefile │ └── depth2depth │ │ ├── Makefile │ │ ├── depth2depth.cpp │ │ └── normal.cpp ├── lib │ └── x86_64 │ │ └── libgaps.a ├── makefiles │ ├── Makefile.apps │ ├── Makefile.pkgs │ └── Makefile.std └── pkgs │ ├── CSparse │ ├── CSparse.h │ ├── Makefile │ ├── README.txt │ ├── cs.h │ ├── cs_add.c │ ├── cs_amd.c │ ├── cs_chol.c │ ├── cs_cholsol.c │ ├── cs_compress.c │ ├── cs_counts.c │ ├── cs_cumsum.c │ ├── cs_dfs.c │ ├── cs_dmperm.c │ ├── cs_droptol.c │ ├── cs_dropzeros.c │ ├── cs_dupl.c │ ├── cs_entry.c │ ├── cs_ereach.c │ ├── cs_etree.c │ ├── cs_fkeep.c │ ├── cs_gaxpy.c │ ├── cs_happly.c │ ├── cs_house.c │ ├── cs_ipvec.c │ ├── cs_leaf.c │ ├── cs_load.c │ ├── cs_lsolve.c │ ├── cs_ltsolve.c │ ├── cs_lu.c │ ├── cs_lusol.c │ ├── cs_malloc.c │ ├── cs_maxtrans.c │ ├── cs_multiply.c │ ├── cs_norm.c │ ├── cs_permute.c │ ├── cs_pinv.c │ ├── cs_post.c │ ├── cs_print.c │ ├── cs_pvec.c │ ├── cs_qr.c │ ├── cs_qrsol.c │ ├── cs_randperm.c │ ├── cs_reach.c │ ├── cs_scatter.c │ ├── cs_scc.c │ ├── cs_schol.c │ ├── cs_spsolve.c │ ├── cs_sqr.c │ ├── cs_symperm.c │ ├── cs_tdfs.c │ ├── cs_transpose.c │ ├── cs_updown.c │ ├── cs_usolve.c │ ├── cs_util.c │ └── cs_utsolve.c │ ├── Makefile │ ├── R2Shapes │ ├── Makefile │ ├── R2Affine.cpp │ ├── R2Affine.h │ ├── R2Align.cpp │ ├── R2Align.h │ ├── R2Arc.cpp │ ├── R2Arc.h │ ├── R2Box.cpp │ ├── R2Box.h │ ├── R2Circle.cpp │ ├── R2Circle.h │ ├── R2Cont.cpp │ ├── R2Cont.h │ ├── R2Crdsys.cpp │ ├── R2Crdsys.h │ ├── R2Curve.cpp │ ├── R2Curve.h │ ├── R2Diad.cpp │ ├── R2Diad.h │ ├── R2Dist.cpp │ ├── R2Dist.h │ ├── R2Draw.cpp │ ├── R2Draw.h │ ├── R2Grid.cpp │ ├── R2Grid.h │ ├── R2Halfspace.cpp │ ├── R2Halfspace.h │ ├── R2Image.cpp │ ├── R2Image.h │ ├── R2Io.cpp │ ├── R2Io.h │ ├── R2Isect.cpp │ ├── R2Isect.h │ ├── R2Kdtree.cpp │ ├── R2Kdtree.h │ ├── R2Line.cpp │ ├── R2Line.h │ ├── R2Parall.cpp │ ├── R2Parall.h │ ├── R2Perp.cpp │ ├── R2Perp.h │ ├── R2Point.cpp │ ├── R2Point.h │ ├── R2Polygon.cpp │ ├── R2Polygon.h │ ├── R2Polyline.cpp │ ├── R2Polyline.h │ ├── R2Ray.cpp │ ├── R2Ray.h │ ├── R2Relate.cpp │ ├── R2Relate.h │ ├── R2Shape.cpp │ ├── R2Shape.h │ ├── R2Shapes.cpp │ ├── R2Shapes.h │ ├── R2Shapes.vcxproj │ ├── R2Shapes.vcxproj.filters │ ├── R2Solid.cpp │ ├── R2Solid.h │ ├── R2Span.cpp │ ├── R2Span.h │ ├── R2Vector.cpp │ ├── R2Vector.h │ ├── R2Xform.cpp │ ├── R2Xform.h │ ├── R3Matrix.cpp │ └── R3Matrix.h │ ├── RNBasics │ ├── Makefile │ ├── RNArray.I │ ├── RNArray.cpp │ ├── RNArray.h │ ├── RNBase.cpp │ ├── RNBase.h │ ├── RNBasics.cpp │ ├── RNBasics.h │ ├── RNBasics.vcxproj │ ├── RNBasics.vcxproj.filters │ ├── RNCompat.h │ ├── RNError.cpp │ ├── RNError.h │ ├── RNExtern.h │ ├── RNFile.cpp │ ├── RNFile.h │ ├── RNFlags.cpp │ ├── RNFlags.h │ ├── RNGrfx.I │ ├── RNGrfx.cpp │ ├── RNGrfx.h │ ├── RNHeap.cpp │ ├── RNHeap.h │ ├── RNIntval.cpp │ ├── RNIntval.h │ ├── RNMap.cpp │ ├── RNMap.h │ ├── RNMem.cpp │ ├── RNMem.h │ ├── RNQueue.I │ ├── RNQueue.cpp │ ├── RNQueue.h │ ├── RNRgb.cpp │ ├── RNRgb.h │ ├── RNScalar.cpp │ ├── RNScalar.h │ ├── RNSvd.cpp │ ├── RNSvd.h │ ├── RNTime.cpp │ ├── RNTime.h │ ├── RNType.cpp │ ├── RNType.h │ ├── json.cpp │ └── json.h │ ├── RNMath │ ├── Makefile │ ├── RNAlgebraic.cpp │ ├── RNAlgebraic.h │ ├── RNDenseLUMatrix.cpp │ ├── RNDenseLUMatrix.h │ ├── RNDenseMatrix.cpp │ ├── RNDenseMatrix.h │ ├── RNEquation.cpp │ ├── RNEquation.h │ ├── RNLapack.h │ ├── RNMath.cpp │ ├── RNMath.h │ ├── RNMatrix.cpp │ ├── RNMatrix.h │ ├── RNPolynomial.cpp │ ├── RNPolynomial.h │ ├── RNSystemOfEquations.cpp │ ├── RNSystemOfEquations.h │ ├── RNVector.cpp │ └── RNVector.h │ ├── jpeg │ ├── Makefile │ ├── jcapimin.c │ ├── jcapistd.c │ ├── jccoefct.c │ ├── jccolor.c │ ├── jcdctmgr.c │ ├── jchuff.c │ ├── jchuff.h │ ├── jcinit.c │ ├── jcmainct.c │ ├── jcmarker.c │ ├── jcmaster.c │ ├── jcomapi.c │ ├── jconfig.h │ ├── jcparam.c │ ├── jcphuff.c │ ├── jcprepct.c │ ├── jcsample.c │ ├── jctrans.c │ ├── jdapimin.c │ ├── jdapistd.c │ ├── jdatadst.c │ ├── jdatasrc.c │ ├── jdcoefct.c │ ├── jdcolor.c │ ├── jdct.h │ ├── jddctmgr.c │ ├── jdhuff.c │ ├── jdhuff.h │ ├── jdinput.c │ ├── jdmainct.c │ ├── jdmarker.c │ ├── jdmaster.c │ ├── jdmerge.c │ ├── jdphuff.c │ ├── jdpostct.c │ ├── jdsample.c │ ├── jdtrans.c │ ├── jerror.c │ ├── jerror.h │ ├── jfdctflt.c │ ├── jfdctfst.c │ ├── jfdctint.c │ ├── jidctflt.c │ ├── jidctfst.c │ ├── jidctint.c │ ├── jidctred.c │ ├── jinclude.h │ ├── jmemmgr.c │ ├── jmemnobs.c │ ├── jmemsys.h │ ├── jmorecfg.h │ ├── jpeg.vcxproj │ ├── jpeg.vcxproj.filters │ ├── jpegint.h │ ├── jpeglib.h │ ├── jquant1.c │ ├── jquant2.c │ ├── jutils.c │ ├── jversion.h │ └── libjpeg.doc │ └── png │ ├── Makefile │ ├── PNG-LICENSE.txt │ ├── PNG-README.txt │ ├── ZLIB_README.txt │ ├── adler32.c │ ├── compress.c │ ├── config.h │ ├── crc32.c │ ├── crc32.h │ ├── deflate.c │ ├── deflate.h │ ├── example.c │ ├── gzclose.c │ ├── gzguts.h │ ├── gzlib.c │ ├── gzread.c │ ├── gzwrite.c │ ├── infback.c │ ├── inffast.c │ ├── inffast.h │ ├── inffixed.h │ ├── inflate.c │ ├── inflate.h │ ├── inftrees.c │ ├── inftrees.h │ ├── minigzip.c │ ├── png.c │ ├── png.h │ ├── png.vcxproj │ ├── png.vcxproj.filters │ ├── pngconf.h │ ├── pngerror.c │ ├── pngget.c │ ├── pngmem.c │ ├── pngpread.c │ ├── pngpriv.h │ ├── pngread.c │ ├── pngrio.c │ ├── pngrtran.c │ ├── pngrutil.c │ ├── pngset.c │ ├── pngtest.c │ ├── pngtrans.c │ ├── pngwio.c │ ├── pngwrite.c │ ├── pngwtran.c │ ├── pngwutil.c │ ├── trees.c │ ├── trees.h │ ├── uncompr.c │ ├── zconf.h │ ├── zlib.h │ ├── zutil.c │ └── zutil.h ├── matlab ├── GenerateOcclusionWeight.m ├── composeDepth.m ├── demo_realsense.m └── evalDepth.m ├── pre_calc_result └── README.md ├── pre_train_model └── README.md ├── results └── realsense │ ├── realsense_004_1.png │ ├── realsense_012_1.png │ ├── realsense_026_1.png │ ├── realsense_030_1.png │ └── realsense_046_1.png └── torch ├── BatchIterator.lua ├── BatchIterator_matterport.lua ├── BatchIterator_scannet.lua ├── README.md ├── config.lua ├── config_matterport.lua ├── config_scannet.lua ├── data_list ├── mp_test_list_horizontal.txt ├── mp_train_list_noup.txt ├── realsense_list.txt ├── scannet_test_list_small.txt ├── scannet_train_list.txt ├── sync_test_list_small.txt └── sync_train_list.txt ├── main_test_bound_matterport.lua ├── main_test_bound_realsense.lua ├── main_test_bound_scannet.lua ├── main_test_matterport.lua ├── main_test_realsense.lua ├── main_test_scannet.lua ├── main_train_bound.lua ├── main_train_matterport.lua ├── main_train_scannet.lua ├── model_deep.lua ├── model_deep_new.lua ├── result ├── bound_realsense_test_bound │ ├── realsense_004_bound_est.png │ ├── realsense_012_bound_est.png │ ├── realsense_026_bound_est.png │ ├── realsense_030_bound_est.png │ └── realsense_046_bound_est.png ├── bound_realsense_weight │ ├── realsense_004_weight.png │ ├── realsense_012_weight.png │ ├── realsense_026_weight.png │ ├── realsense_030_weight.png │ └── realsense_046_weight.png └── normal_scannet_realsense_test │ ├── realsense_004_normal_est.h5 │ ├── realsense_012_normal_est.h5 │ ├── realsense_026_normal_est.h5 │ ├── realsense_030_normal_est.h5 │ └── realsense_046_normal_est.h5 ├── utils.lua ├── utils_matterport.lua └── utils_scannet.lua /.gitignore: -------------------------------------------------------------------------------- 1 | *.zip 2 | *.t7 3 | *.DS* 4 | *.mat 5 | ._* 6 | -------------------------------------------------------------------------------- /data/README.md: -------------------------------------------------------------------------------- 1 | # Training Data 2 | 3 | We provide a small dataset collected by Intel Realsense for quick testing: 4 | - realsense.zip: http://deepcompletion.cs.princeton.edu/public/data/realsense.zip 5 | 6 | Here is a list of data you may get upon SUNCG/Matterport3D/ScanNet access: 7 | - matterport_render_depth.zip: The depth rendered from mesh reconstruction for scenes from Matterport3D. The images are 16bit PNG with 4000 x depth in meters. (Require access to Matterport3D) 8 | - matterport_render_normal.zip: The surface normal for the rendered depth from Matterport3D. The image are 16bit PNG with [0,65535] mapping to [-1,+1] for three directions. (Require access to Matterport3D) 9 | - scannet_render_depth.zip: The depth rendered from mesh reconstruction for scenes from ScanNet. The same as matterport. (Require access to ScanNet) 10 | - scannet_render_normal.zip: The surface normal for the rendered depth from ScanNet. The same as matterport. (Require access to ScanNet) 11 | - pbrs_boundary.zip: The boundary ground truth for physically based rendering in SUNCG-RGBD dataset. The images are 16bit PNG with 0 for no boundary, 1 for occlusion, 2 for crease. (Require access to SUNCG) -------------------------------------------------------------------------------- /data/script_realsense.m: -------------------------------------------------------------------------------- 1 | % Realsense raw depth can be very noisy. Depth error on sparse pixels can 2 | % be very wrong. Remove signals on boundary. 3 | 4 | root_dir = './realsense/'; 5 | fp = fopen('../torch/data_list/realsense_list.txt'); 6 | temp = textscan(fp, '%s'); 7 | data_list = temp{1}; 8 | fclose(fp); 9 | 10 | for a = 1:length(data_list) 11 | fprintf('%d\n', a); 12 | 13 | depth = imread([data_list{a} '_depth.png']); 14 | 15 | valid = depth>0; 16 | dist = bwdist(~valid); 17 | depth(dist<1.5) = 0; 18 | depth = imdilate(depth, ones(3,3)); 19 | imwrite(depth, [data_list{a} '_depth_open.png']); 20 | end -------------------------------------------------------------------------------- /gaps/LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (C) Thomas Funkhouser 2 | 3 | The code in this zip file is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. 4 | 5 | This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 6 | -------------------------------------------------------------------------------- /gaps/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for GAPS 3 | # 4 | 5 | 6 | 7 | # 8 | # Make targets 9 | # 10 | 11 | opt: 12 | $(MAKE) target "TARGET=$@" 13 | 14 | debug: 15 | $(MAKE) target "TARGET=$@" 16 | 17 | mesa: 18 | $(MAKE) target "TARGET=$@" 19 | 20 | clean: 21 | $(MAKE) target "TARGET=$@" 22 | 23 | target: 24 | cd pkgs; $(MAKE) $(TARGET) 25 | cd apps; $(MAKE) $(TARGET) 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /gaps/README.txt: -------------------------------------------------------------------------------- 1 | This directory contains all code for the GAPS software library 2 | required for the depth2depth application. 3 | There are several subdirectories: 4 | 5 | pkgs - source and include files for all packages (software libraries). 6 | apps - source files for the depth2depth application. 7 | makefiles - unix-style make file definitions 8 | lib - archive library (.lib) files (created during compilation). 9 | bin - executable files (created during compilation). 10 | 11 | If you are using linux or cygwin and have gcc and OpenGL development 12 | libraries installed, or if you are using MAC OS X with the xcode 13 | development environment, you should be able to compile all the code by 14 | typing "make clean; make" in this directory. For other development 15 | platforms, you should edit the shared compilation settings in the 16 | makefiles/Makefiles.std to meet your needs. 17 | 18 | The software is distributed under the GNU General Public License. 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /gaps/apps/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for GAPS apps 3 | # 4 | 5 | opt: 6 | $(MAKE) target "TARGET=$@" 7 | 8 | debug: 9 | $(MAKE) target "TARGET=$@" 10 | 11 | mesa: 12 | $(MAKE) target "TARGET=$@" 13 | 14 | clean: 15 | $(MAKE) target "TARGET=$@" 16 | 17 | target: 18 | cd depth2depth; $(MAKE) $(TARGET) 19 | -------------------------------------------------------------------------------- /gaps/apps/depth2depth/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Application name 3 | # 4 | 5 | NAME=depth2depth 6 | 7 | 8 | 9 | # 10 | # With Ceres 11 | # 12 | 13 | #USER_LIBS=-L/usr/local/lib -lceres -lccolamd -lcamd -lcolamd -lamd -Wl,-Bdynamic -lcxsparse -lccolamd -lcamd -lcolamd -lcholmod -lamd -llapack -lopenblas -Wl,-Bstatic -lcxsparse -Wl,-Bdynamic -lgomp -lglog -lgflags -lgfortran -lhdf5 -ldl -lm 14 | 15 | #USER_LIBS=-L/usr/local/lib -lceres -lgflags -lglog -lcamd -lcholmod -lccolamd -lcolamd -lcamd -lamd -lmetis -lcxsparse -lsuitesparseconfig -fopenmp -lpthread -lgomp -llapack -lopenblas -lgfortran -lhdf5 -ldl -lm 16 | 17 | 18 | 19 | # 20 | # Without Ceres 21 | # 22 | 23 | USER_LIBS=-lhdf5 24 | 25 | USER_CFLAGS=-DRN_USE_CSPARSE 26 | 27 | 28 | 29 | # 30 | # Source files 31 | # 32 | 33 | CCSRCS=$(NAME).cpp 34 | 35 | 36 | 37 | # 38 | # Libraries 39 | # 40 | 41 | PKG_LIBS=-lR2Shapes -lRNMath -lRNBasics -ljpeg -lpng -lCSparse 42 | 43 | 44 | 45 | # 46 | # Include standard makefile 47 | # 48 | 49 | include ../../makefiles/Makefile.apps 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | -------------------------------------------------------------------------------- /gaps/lib/x86_64/libgaps.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/gaps/lib/x86_64/libgaps.a -------------------------------------------------------------------------------- /gaps/makefiles/Makefile.apps: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for GAPS applications 3 | # 4 | 5 | 6 | 7 | # 8 | # Before this Makefile is included ... 9 | # $(NAME) should be module name 10 | # $(CCSRCS) should list C++ source files 11 | # $(CSRCS) should list C source files 12 | # 13 | # For example ... 14 | # NAME=foo 15 | # CCSRCS=$(NAME).cpp \ 16 | # foo1.cpp foo2.cpp foo3.cpp 17 | # CSRCS=foo4.c foo5.c 18 | # 19 | 20 | 21 | # 22 | # Set up compiler options, etc. 23 | # 24 | 25 | include ../../makefiles/Makefile.std 26 | 27 | 28 | 29 | 30 | # 31 | # Set up target app 32 | # 33 | 34 | EXE = $(EXE_DIR)/$(NAME) 35 | 36 | 37 | 38 | # 39 | # Set up link options 40 | # 41 | 42 | BASE_LDFLAGS=$(USER_LDFLAGS) -L$(LIB_DIR) 43 | DEBUG_LDFLAGS=$(BASE_LDFLAGS) -g 44 | OPT_LDFLAGS=$(BASE_LDFLAGS) -O 45 | LDFLAGS=$(DEBUG_LDFLAGS) 46 | 47 | 48 | # 49 | # Set up libs 50 | # 51 | 52 | ifeq ("$(findstring CYGWIN,$(OS))", "CYGWIN") 53 | #OPENGL_LIBS=-lglut32 -lglu32 -lopengl32 54 | #OPENGL_LIBS=-lfglut -lglu32 -lopengl32 -lwinmm -lgdi32 55 | OPENGL_LIBS=-lglu32 -lopengl32 -lwinmm -lgdi32 56 | else ifeq ("$(OS)","Darwin") 57 | #OPENGL_LIBS=-framework GLUT -framework opengl 58 | OPENGL_LIBS=-framework opengl 59 | else 60 | #OPENGL_LIBS=-lglut -lGLU -lGL -lX11 -lm 61 | #OPENGL_LIBS=-pthread -lfglut -lGLU -lGL -lX11 -lm 62 | OPENGL_LIBS=-pthread -lGLU -lGL -lX11 -lm 63 | endif 64 | LIBS=$(PKG_LIBS) $(USER_LIBS) $(OPENGL_LIBS) 65 | 66 | 67 | 68 | # 69 | # Make targets 70 | # 71 | 72 | opt: 73 | $(MAKE) $(EXE) "CFLAGS=$(OPT_CFLAGS)" "LDFLAGS=$(OPT_LDFLAGS)" 74 | 75 | debug: 76 | $(MAKE) $(EXE) "CFLAGS=$(DEBUG_CFLAGS)" "LDFLAGS=$(DEBUG_LDFLAGS)" 77 | 78 | mesa: 79 | $(MAKE) $(EXE) "CFLAGS=$(OPT_CFLAGS) -DUSE_MESA" "LDFLAGS=$(OPT_LDFLAGS)" "LIBS=$(PKG_LIBS) $(USER_LIBS) -lOSMesa $(OPENGL_LIBS)" 80 | 81 | $(EXE): $(OBJS) $(LIB_DIR)/*.a 82 | mkdir -p $(EXE_DIR) 83 | $(CC) -o $(EXE) $(LDFLAGS) $(USER_OBJS) $(OBJS) $(LIBS) 84 | 85 | release: 86 | mkdir -p $(RELEASE_DIR)/apps 87 | mkdir $(RELEASE_DIR)/apps/$(NAME)1 88 | cp *\.[!o]* $(RELEASE_DIR)/apps/$(NAME)1 89 | cp Makefile $(RELEASE_DIR)/apps/$(NAME)1 90 | # cp $(NAME).vcxproj $(RELEASE_DIR)/apps/$(NAME)1 91 | rm -r -f $(RELEASE_DIR)/apps/$(NAME) 92 | mv $(RELEASE_DIR)/apps/$(NAME)1 $(RELEASE_DIR)/apps/$(NAME) 93 | 94 | clean: 95 | - rm -f *~ *.o $(EXE) 96 | 97 | 98 | 99 | # 100 | # Dependencies 101 | # 102 | 103 | PKG_LIBS += $(foreach pkg, $(PKG_DEPENDENCIES), -l$(pkg)) 104 | PKG_LIST=$(subst -l,,$(PKG_LIBS)) 105 | $(OBJS) : Makefile $(wildcard *.h) $(foreach pkg, $(PKG_LIST), ../../pkgs/$(pkg)/*.h) $(USER_DEPENDENCIES) 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /gaps/makefiles/Makefile.pkgs: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for GAPS packages 3 | # 4 | 5 | 6 | 7 | # 8 | # Before this Makefile is included ... 9 | # $(NAME) should be module name 10 | # $(CCSRCS) should list C++ source files 11 | # $(CSRCS) should list C source files 12 | # 13 | # For example ... 14 | # NAME=foo 15 | # CCSRCS=$(NAME).cpp \ 16 | # foo1.cpp foo2.cpp foo3.cpp 17 | # CSRCS=foo4.c foo5.c 18 | # 19 | 20 | 21 | # 22 | # Set up compiler options, etc. 23 | # 24 | 25 | include ../../makefiles/Makefile.std 26 | 27 | 28 | 29 | # 30 | # Set up target name 31 | # 32 | 33 | LIB=$(LIB_DIR)/lib$(NAME).a 34 | 35 | 36 | 37 | # 38 | # Make targets 39 | # 40 | 41 | opt: 42 | $(MAKE) $(LIB) "CFLAGS=$(OPT_CFLAGS)" 43 | 44 | debug: 45 | $(MAKE) $(LIB) "CFLAGS=$(DEBUG_CFLAGS)" 46 | 47 | mesa: 48 | $(MAKE) $(LIB) "CFLAGS=$(OPT_CFLAGS) -DUSE_MESA" 49 | 50 | $(LIB): $(CCSRCS) $(CSRCS) $(OSRCS) $(OBJS) $(DEPENDENCIES) 51 | mkdir -p $(LIB_DIR) 52 | rm -f $(LIB) 53 | ar ur $(LIB) $(OBJS) $(USER_OBJS) 54 | 55 | release: 56 | mkdir -p $(RELEASE_DIR)/pkgs 57 | mkdir $(RELEASE_DIR)/pkgs/$(NAME)1 58 | cp *\.[!o]* $(RELEASE_DIR)/pkgs/$(NAME)1 59 | cp Makefile $(RELEASE_DIR)/pkgs/$(NAME)1 60 | # cp $(NAME).vcxproj $(RELEASE_DIR)/pkgs/$(NAME)1 61 | rm -r -f $(RELEASE_DIR)/pkgs/$(NAME) 62 | mv $(RELEASE_DIR)/pkgs/$(NAME)1 $(RELEASE_DIR)/pkgs/$(NAME) 63 | 64 | clean: 65 | - rm -f *~ *.o $(LIB) 66 | 67 | 68 | 69 | # 70 | # Dependencies 71 | # 72 | 73 | $(OBJS) : Makefile *.h $(foreach pkg, $(PKG_DEPENDENCIES), ../$(pkg)/*.h) $(USER_DEPENDENCIES) 74 | 75 | 76 | 77 | -------------------------------------------------------------------------------- /gaps/makefiles/Makefile.std: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile setup for GAPS 3 | # 4 | 5 | 6 | 7 | # 8 | # Targets 9 | # 10 | 11 | OBJS=$(CCSRCS:.cpp=.o) $(CSRCS:.c=.o) 12 | INCS=$(HSRCS) $(CCSRCS:.cpp=.h) $(CSRCS:.c=.h) 13 | 14 | 15 | 16 | # 17 | # Get the operating system and architecture type 18 | # 19 | 20 | OS=$(shell uname -s) 21 | ARCH=$(shell uname -m) 22 | 23 | 24 | 25 | # 26 | # C flags 27 | # 28 | 29 | #ifeq ("$(findstring CYGWIN,$(OS))", "CYGWIN") 30 | #OS_CFLAGS=-Wl,-stack_size,0x100000000 31 | #endif 32 | 33 | CC=g++ 34 | BASE_CFLAGS=$(USER_CFLAGS) $(OS_CFLAGS) -Wall -I. -I../../pkgs 35 | DEBUG_CFLAGS=$(BASE_CFLAGS) -g 36 | OPT_CFLAGS=$(BASE_CFLAGS) -O3 -DNDEBUG 37 | CFLAGS=$(DEBUG_CFLAGS) 38 | 39 | #ifeq ("$(OS)","Darwin") 40 | # BASE_CFLAGS=$(USER_CFLAGS) $(OS_CFLAGS) -Wall -I. -I../../pkgs -Wno-deprecated-declarations 41 | #endif 42 | 43 | 44 | 45 | # 46 | # Directories 47 | # 48 | 49 | RELEASE_DIR=../../release 50 | EXE_DIR=../../bin/$(ARCH) 51 | LIB_DIR=../../lib/$(ARCH) 52 | 53 | 54 | 55 | # 56 | # Default rules 57 | # 58 | 59 | .SUFFIXES: .cpp .C .c .o 60 | 61 | .cpp.o: 62 | $(CC) $(CFLAGS) -c $< 63 | 64 | .C.o: 65 | $(CC) $(CFLAGS) -c $< 66 | 67 | .c.o: 68 | gcc $(CFLAGS) -c $< 69 | 70 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/CSparse.h: -------------------------------------------------------------------------------- 1 | #ifndef ___CS_PARSE_INCLUDED__ 2 | #define ___CS_PARSE_INCLUDED__ 3 | 4 | extern "C" { 5 | #include "CSparse/cs.h" 6 | }; 7 | 8 | #endif 9 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Package name and list of source files. 3 | # 4 | 5 | NAME=CSparse 6 | CSRCS= cs_add.c cs_amd.c cs_chol.c cs_cholsol.c cs_counts.c cs_cumsum.c \ 7 | cs_droptol.c cs_dropzeros.c cs_dupl.c cs_entry.c \ 8 | cs_etree.c cs_fkeep.c cs_gaxpy.c cs_happly.c cs_house.c cs_ipvec.c \ 9 | cs_lsolve.c cs_ltsolve.c cs_lu.c cs_lusol.c cs_util.c cs_multiply.c \ 10 | cs_permute.c cs_pinv.c cs_post.c cs_pvec.c cs_qr.c cs_qrsol.c \ 11 | cs_scatter.c cs_schol.c cs_sqr.c cs_symperm.c cs_tdfs.c cs_malloc.c \ 12 | cs_transpose.c cs_compress.c cs_usolve.c cs_utsolve.c cs_scc.c \ 13 | cs_maxtrans.c cs_dmperm.c cs_updown.c cs_print.c cs_norm.c cs_load.c \ 14 | cs_dfs.c cs_reach.c cs_spsolve.c cs_ereach.c cs_leaf.c cs_randperm.c 15 | 16 | 17 | 18 | # 19 | # R3 library makefile 20 | # 21 | 22 | include ../../makefiles/Makefile.pkgs 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/README.txt: -------------------------------------------------------------------------------- 1 | This version of CSparse was downloaded from: 2 | http://people.sc.fsu.edu/~jburkardt/c_src/csparse/csparse.html 3 | 4 | CSPARSE: a Concise Sparse matrix package. 5 | Copyright (c) 2006, Timothy A. Davis. 6 | http://www.cise.ufl.edu/research/sparse/CSparse 7 | 8 | CSPARSE is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version. 9 | 10 | CSPARSE is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. 11 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_add.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* C = alpha*A + beta*B */ 3 | cs *cs_add (const cs *A, const cs *B, double alpha, double beta) 4 | { 5 | int p, j, nz = 0, anz, *Cp, *Ci, *Bp, m, n, bnz, *w, values ; 6 | double *x, *Bx, *Cx ; 7 | cs *C ; 8 | if (!CS_CSC (A) || !CS_CSC (B)) return (NULL) ; /* check inputs */ 9 | if (A->m != B->m || A->n != B->n) return (NULL) ; 10 | m = A->m ; anz = A->p [A->n] ; 11 | n = B->n ; Bp = B->p ; Bx = B->x ; bnz = Bp [n] ; 12 | w = cs_calloc (m, sizeof (int)) ; /* get workspace */ 13 | values = (A->x != NULL) && (Bx != NULL) ; 14 | x = values ? cs_malloc (m, sizeof (double)) : NULL ; /* get workspace */ 15 | C = cs_spalloc (m, n, anz + bnz, values, 0) ; /* allocate result*/ 16 | if (!C || !w || (values && !x)) return (cs_done (C, w, x, 0)) ; 17 | Cp = C->p ; Ci = C->i ; Cx = C->x ; 18 | for (j = 0 ; j < n ; j++) 19 | { 20 | Cp [j] = nz ; /* column j of C starts here */ 21 | nz = cs_scatter (A, j, alpha, w, x, j+1, C, nz) ; /* alpha*A(:,j)*/ 22 | nz = cs_scatter (B, j, beta, w, x, j+1, C, nz) ; /* beta*B(:,j) */ 23 | if (values) for (p = Cp [j] ; p < nz ; p++) Cx [p] = x [Ci [p]] ; 24 | } 25 | Cp [n] = nz ; /* finalize the last column of C */ 26 | cs_sprealloc (C, 0) ; /* remove extra space from C */ 27 | return (cs_done (C, w, x, 1)) ; /* success; free workspace, return C */ 28 | } 29 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_chol.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* L = chol (A, [pinv parent cp]), pinv is optional */ 3 | csn *cs_chol (const cs *A, const css *S) 4 | { 5 | double d, lki, *Lx, *x, *Cx ; 6 | int top, i, p, k, n, *Li, *Lp, *cp, *pinv, *s, *c, *parent, *Cp, *Ci ; 7 | cs *L, *C, *E ; 8 | csn *N ; 9 | if (!CS_CSC (A) || !S || !S->cp || !S->parent) return (NULL) ; 10 | n = A->n ; 11 | N = cs_calloc (1, sizeof (csn)) ; /* allocate result */ 12 | c = cs_malloc (2*n, sizeof (int)) ; /* get int workspace */ 13 | x = cs_malloc (n, sizeof (double)) ; /* get double workspace */ 14 | cp = S->cp ; pinv = S->pinv ; parent = S->parent ; 15 | C = pinv ? cs_symperm (A, pinv, 1) : ((cs *) A) ; 16 | E = pinv ? C : NULL ; /* E is alias for A, or a copy E=A(p,p) */ 17 | if (!N || !c || !x || !C) return (cs_ndone (N, E, c, x, 0)) ; 18 | s = c + n ; 19 | Cp = C->p ; Ci = C->i ; Cx = C->x ; 20 | N->L = L = cs_spalloc (n, n, cp [n], 1, 0) ; /* allocate result */ 21 | if (!L) return (cs_ndone (N, E, c, x, 0)) ; 22 | Lp = L->p ; Li = L->i ; Lx = L->x ; 23 | for (k = 0 ; k < n ; k++) Lp [k] = c [k] = cp [k] ; 24 | for (k = 0 ; k < n ; k++) /* compute L(k,:) for L*L' = C */ 25 | { 26 | /* --- Nonzero pattern of L(k,:) ------------------------------------ */ 27 | top = cs_ereach (C, k, parent, s, c) ; /* find pattern of L(k,:) */ 28 | x [k] = 0 ; /* x (0:k) is now zero */ 29 | for (p = Cp [k] ; p < Cp [k+1] ; p++) /* x = full(triu(C(:,k))) */ 30 | { 31 | if (Ci [p] <= k) x [Ci [p]] = Cx [p] ; 32 | } 33 | d = x [k] ; /* d = C(k,k) */ 34 | x [k] = 0 ; /* clear x for k+1st iteration */ 35 | /* --- Triangular solve --------------------------------------------- */ 36 | for ( ; top < n ; top++) /* solve L(0:k-1,0:k-1) * x = C(:,k) */ 37 | { 38 | i = s [top] ; /* s [top..n-1] is pattern of L(k,:) */ 39 | lki = x [i] / Lx [Lp [i]] ; /* L(k,i) = x (i) / L(i,i) */ 40 | x [i] = 0 ; /* clear x for k+1st iteration */ 41 | for (p = Lp [i] + 1 ; p < c [i] ; p++) 42 | { 43 | x [Li [p]] -= Lx [p] * lki ; 44 | } 45 | d -= lki * lki ; /* d = d - L(k,i)*L(k,i) */ 46 | p = c [i]++ ; 47 | Li [p] = k ; /* store L(k,i) in column i */ 48 | Lx [p] = lki ; 49 | } 50 | /* --- Compute L(k,k) ----------------------------------------------- */ 51 | if (d <= 0) return (cs_ndone (N, E, c, x, 0)) ; /* not pos def */ 52 | p = c [k]++ ; 53 | Li [p] = k ; /* store L(k,k) = sqrt (d) in column k */ 54 | Lx [p] = sqrt (d) ; 55 | } 56 | Lp [n] = cp [n] ; /* finalize L */ 57 | return (cs_ndone (N, E, c, x, 1)) ; /* success: free E,s,x; return N */ 58 | } 59 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_cholsol.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* x=A\b where A is symmetric positive definite; b overwritten with solution */ 3 | int cs_cholsol (int order, const cs *A, double *b) 4 | { 5 | double *x ; 6 | css *S ; 7 | csn *N ; 8 | int n, ok ; 9 | if (!CS_CSC (A) || !b) return (0) ; /* check inputs */ 10 | n = A->n ; 11 | S = cs_schol (order, A) ; /* ordering and symbolic analysis */ 12 | N = cs_chol (A, S) ; /* numeric Cholesky factorization */ 13 | x = cs_malloc (n, sizeof (double)) ; /* get workspace */ 14 | ok = (S && N && x) ; 15 | if (ok) 16 | { 17 | cs_ipvec (S->pinv, b, x, n) ; /* x = P*b */ 18 | cs_lsolve (N->L, x) ; /* x = L\x */ 19 | cs_ltsolve (N->L, x) ; /* x = L'\x */ 20 | cs_pvec (S->pinv, x, b, n) ; /* b = P'*x */ 21 | } 22 | cs_free (x) ; 23 | cs_sfree (S) ; 24 | cs_nfree (N) ; 25 | return (ok) ; 26 | } 27 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_compress.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* C = compressed-column form of a triplet matrix T */ 3 | cs *cs_compress (const cs *T) 4 | { 5 | int m, n, nz, p, k, *Cp, *Ci, *w, *Ti, *Tj ; 6 | double *Cx, *Tx ; 7 | cs *C ; 8 | if (!CS_TRIPLET (T)) return (NULL) ; /* check inputs */ 9 | m = T->m ; n = T->n ; Ti = T->i ; Tj = T->p ; Tx = T->x ; nz = T->nz ; 10 | C = cs_spalloc (m, n, nz, Tx != NULL, 0) ; /* allocate result */ 11 | w = cs_calloc (n, sizeof (int)) ; /* get workspace */ 12 | if (!C || !w) return (cs_done (C, w, NULL, 0)) ; /* out of memory */ 13 | Cp = C->p ; Ci = C->i ; Cx = C->x ; 14 | for (k = 0 ; k < nz ; k++) w [Tj [k]]++ ; /* column counts */ 15 | cs_cumsum (Cp, w, n) ; /* column pointers */ 16 | for (k = 0 ; k < nz ; k++) 17 | { 18 | Ci [p = w [Tj [k]]++] = Ti [k] ; /* A(i,j) is the pth entry in C */ 19 | if (Cx) Cx [p] = Tx [k] ; 20 | } 21 | return (cs_done (C, w, NULL, 1)) ; /* success; free w and return C */ 22 | } 23 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_counts.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* column counts of LL'=A or LL'=A'A, given parent & post ordering */ 3 | #define HEAD(k,j) (ata ? head [k] : j) 4 | #define NEXT(J) (ata ? next [J] : -1) 5 | static void init_ata (cs *AT, const int *post, int *w, int **head, int **next) 6 | { 7 | int i, k, p, m = AT->n, n = AT->m, *ATp = AT->p, *ATi = AT->i ; 8 | *head = w+4*n, *next = w+5*n+1 ; 9 | for (k = 0 ; k < n ; k++) w [post [k]] = k ; /* invert post */ 10 | for (i = 0 ; i < m ; i++) 11 | { 12 | for (k = n, p = ATp[i] ; p < ATp[i+1] ; p++) k = CS_MIN (k, w [ATi[p]]); 13 | (*next) [i] = (*head) [k] ; /* place row i in linked list k */ 14 | (*head) [k] = i ; 15 | } 16 | } 17 | int *cs_counts (const cs *A, const int *parent, const int *post, int ata) 18 | { 19 | int i, j, k, n, m, J, s, p, q, jleaf, *ATp, *ATi, *maxfirst, *prevleaf, 20 | *ancestor, *head = NULL, *next = NULL, *colcount, *w, *first, *delta ; 21 | cs *AT ; 22 | if (!CS_CSC (A) || !parent || !post) return (NULL) ; /* check inputs */ 23 | m = A->m ; n = A->n ; 24 | s = 4*n + (ata ? (n+m+1) : 0) ; 25 | delta = colcount = cs_malloc (n, sizeof (int)) ; /* allocate result */ 26 | w = cs_malloc (s, sizeof (int)) ; /* get workspace */ 27 | AT = cs_transpose (A, 0) ; /* AT = A' */ 28 | if (!AT || !colcount || !w) return (cs_idone (colcount, AT, w, 0)) ; 29 | ancestor = w ; maxfirst = w+n ; prevleaf = w+2*n ; first = w+3*n ; 30 | for (k = 0 ; k < s ; k++) w [k] = -1 ; /* clear workspace w [0..s-1] */ 31 | for (k = 0 ; k < n ; k++) /* find first [j] */ 32 | { 33 | j = post [k] ; 34 | delta [j] = (first [j] == -1) ? 1 : 0 ; /* delta[j]=1 if j is a leaf */ 35 | for ( ; j != -1 && first [j] == -1 ; j = parent [j]) first [j] = k ; 36 | } 37 | ATp = AT->p ; ATi = AT->i ; 38 | if (ata) init_ata (AT, post, w, &head, &next) ; 39 | for (i = 0 ; i < n ; i++) ancestor [i] = i ; /* each node in its own set */ 40 | for (k = 0 ; k < n ; k++) 41 | { 42 | j = post [k] ; /* j is the kth node in postordered etree */ 43 | if (parent [j] != -1) delta [parent [j]]-- ; /* j is not a root */ 44 | for (J = HEAD (k,j) ; J != -1 ; J = NEXT (J)) /* J=j for LL'=A case */ 45 | { 46 | for (p = ATp [J] ; p < ATp [J+1] ; p++) 47 | { 48 | i = ATi [p] ; 49 | q = cs_leaf (i, j, first, maxfirst, prevleaf, ancestor, &jleaf); 50 | if (jleaf >= 1) delta [j]++ ; /* A(i,j) is in skeleton */ 51 | if (jleaf == 2) delta [q]-- ; /* account for overlap in q */ 52 | } 53 | } 54 | if (parent [j] != -1) ancestor [j] = parent [j] ; 55 | } 56 | for (j = 0 ; j < n ; j++) /* sum up delta's of each child */ 57 | { 58 | if (parent [j] != -1) colcount [parent [j]] += colcount [j] ; 59 | } 60 | return (cs_idone (colcount, AT, w, 1)) ; /* success: free workspace */ 61 | } 62 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_cumsum.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* p [0..n] = cumulative sum of c [0..n-1], and then copy p [0..n-1] into c */ 3 | double cs_cumsum (int *p, int *c, int n) 4 | { 5 | int i, nz = 0 ; 6 | double nz2 = 0 ; 7 | if (!p || !c) return (-1) ; /* check inputs */ 8 | for (i = 0 ; i < n ; i++) 9 | { 10 | p [i] = nz ; 11 | nz += c [i] ; 12 | nz2 += c [i] ; /* also in double to avoid int overflow */ 13 | c [i] = p [i] ; /* also copy p[0..n-1] back into c[0..n-1]*/ 14 | } 15 | p [n] = nz ; 16 | return (nz2) ; /* return sum (c [0..n-1]) */ 17 | } 18 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_dfs.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* depth-first-search of the graph of a matrix, starting at node j */ 3 | int cs_dfs (int j, cs *G, int top, int *xi, int *pstack, const int *pinv) 4 | { 5 | int i, p, p2, done, jnew, head = 0, *Gp, *Gi ; 6 | if (!CS_CSC (G) || !xi || !pstack) return (-1) ; /* check inputs */ 7 | Gp = G->p ; Gi = G->i ; 8 | xi [0] = j ; /* initialize the recursion stack */ 9 | while (head >= 0) 10 | { 11 | j = xi [head] ; /* get j from the top of the recursion stack */ 12 | jnew = pinv ? (pinv [j]) : j ; 13 | if (!CS_MARKED (Gp, j)) 14 | { 15 | CS_MARK (Gp, j) ; /* mark node j as visited */ 16 | pstack [head] = (jnew < 0) ? 0 : CS_UNFLIP (Gp [jnew]) ; 17 | } 18 | done = 1 ; /* node j done if no unvisited neighbors */ 19 | p2 = (jnew < 0) ? 0 : CS_UNFLIP (Gp [jnew+1]) ; 20 | for (p = pstack [head] ; p < p2 ; p++) /* examine all neighbors of j */ 21 | { 22 | i = Gi [p] ; /* consider neighbor node i */ 23 | if (CS_MARKED (Gp, i)) continue ; /* skip visited node i */ 24 | pstack [head] = p ; /* pause depth-first search of node j */ 25 | xi [++head] = i ; /* start dfs at node i */ 26 | done = 0 ; /* node j is not done */ 27 | break ; /* break, to start dfs (i) */ 28 | } 29 | if (done) /* depth-first search at node j is done */ 30 | { 31 | head-- ; /* remove j from the recursion stack */ 32 | xi [--top] = j ; /* and place in the output stack */ 33 | } 34 | } 35 | return (top) ; 36 | } 37 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_droptol.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | static int cs_tol (int i, int j, double aij, void *tol) 3 | { 4 | return (fabs (aij) > *((double *) tol)) ; 5 | } 6 | int cs_droptol (cs *A, double tol) 7 | { 8 | return (cs_fkeep (A, &cs_tol, &tol)) ; /* keep all large entries */ 9 | } 10 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_dropzeros.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | static int cs_nonzero (int i, int j, double aij, void *other) 3 | { 4 | return (aij != 0) ; 5 | } 6 | int cs_dropzeros (cs *A) 7 | { 8 | return (cs_fkeep (A, &cs_nonzero, NULL)) ; /* keep all nonzero entries */ 9 | } 10 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_dupl.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* remove duplicate entries from A */ 3 | int cs_dupl (cs *A) 4 | { 5 | int i, j, p, q, nz = 0, n, m, *Ap, *Ai, *w ; 6 | double *Ax ; 7 | if (!CS_CSC (A)) return (0) ; /* check inputs */ 8 | m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ; 9 | w = cs_malloc (m, sizeof (int)) ; /* get workspace */ 10 | if (!w) return (0) ; /* out of memory */ 11 | for (i = 0 ; i < m ; i++) w [i] = -1 ; /* row i not yet seen */ 12 | for (j = 0 ; j < n ; j++) 13 | { 14 | q = nz ; /* column j will start at q */ 15 | for (p = Ap [j] ; p < Ap [j+1] ; p++) 16 | { 17 | i = Ai [p] ; /* A(i,j) is nonzero */ 18 | if (w [i] >= q) 19 | { 20 | Ax [w [i]] += Ax [p] ; /* A(i,j) is a duplicate */ 21 | } 22 | else 23 | { 24 | w [i] = nz ; /* record where row i occurs */ 25 | Ai [nz] = i ; /* keep A(i,j) */ 26 | Ax [nz++] = Ax [p] ; 27 | } 28 | } 29 | Ap [j] = q ; /* record start of column j */ 30 | } 31 | Ap [n] = nz ; /* finalize A */ 32 | cs_free (w) ; /* free workspace */ 33 | return (cs_sprealloc (A, 0)) ; /* remove extra space from A */ 34 | } 35 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_entry.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* add an entry to a triplet matrix; return 1 if ok, 0 otherwise */ 3 | int cs_entry (cs *T, int i, int j, double x) 4 | { 5 | if (!CS_TRIPLET (T) || i < 0 || j < 0) return (0) ; /* check inputs */ 6 | if (T->nz >= T->nzmax && !cs_sprealloc (T,2*(T->nzmax))) return (0) ; 7 | if (T->x) T->x [T->nz] = x ; 8 | T->i [T->nz] = i ; 9 | T->p [T->nz++] = j ; 10 | T->m = CS_MAX (T->m, i+1) ; 11 | T->n = CS_MAX (T->n, j+1) ; 12 | return (1) ; 13 | } 14 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_ereach.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* find nonzero pattern of Cholesky L(k,1:k-1) using etree and triu(A(:,k)) */ 3 | int cs_ereach (const cs *A, int k, const int *parent, int *s, int *w) 4 | { 5 | int i, p, n, len, top, *Ap, *Ai ; 6 | if (!CS_CSC (A) || !parent || !s || !w) return (-1) ; /* check inputs */ 7 | top = n = A->n ; Ap = A->p ; Ai = A->i ; 8 | CS_MARK (w, k) ; /* mark node k as visited */ 9 | for (p = Ap [k] ; p < Ap [k+1] ; p++) 10 | { 11 | i = Ai [p] ; /* A(i,k) is nonzero */ 12 | if (i > k) continue ; /* only use upper triangular part of A */ 13 | for (len = 0 ; !CS_MARKED (w,i) ; i = parent [i]) /* traverse up etree*/ 14 | { 15 | s [len++] = i ; /* L(k,i) is nonzero */ 16 | CS_MARK (w, i) ; /* mark i as visited */ 17 | } 18 | while (len > 0) s [--top] = s [--len] ; /* push path onto stack */ 19 | } 20 | for (p = top ; p < n ; p++) CS_MARK (w, s [p]) ; /* unmark all nodes */ 21 | CS_MARK (w, k) ; /* unmark node k */ 22 | return (top) ; /* s [top..n-1] contains pattern of L(k,:)*/ 23 | } 24 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_etree.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* compute the etree of A (using triu(A), or A'A without forming A'A */ 3 | int *cs_etree (const cs *A, int ata) 4 | { 5 | int i, k, p, m, n, inext, *Ap, *Ai, *w, *parent, *ancestor, *prev ; 6 | if (!CS_CSC (A)) return (NULL) ; /* check inputs */ 7 | m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; 8 | parent = cs_malloc (n, sizeof (int)) ; /* allocate result */ 9 | w = cs_malloc (n + (ata ? m : 0), sizeof (int)) ; /* get workspace */ 10 | if (!w || !parent) return (cs_idone (parent, NULL, w, 0)) ; 11 | ancestor = w ; prev = w + n ; 12 | if (ata) for (i = 0 ; i < m ; i++) prev [i] = -1 ; 13 | for (k = 0 ; k < n ; k++) 14 | { 15 | parent [k] = -1 ; /* node k has no parent yet */ 16 | ancestor [k] = -1 ; /* nor does k have an ancestor */ 17 | for (p = Ap [k] ; p < Ap [k+1] ; p++) 18 | { 19 | i = ata ? (prev [Ai [p]]) : (Ai [p]) ; 20 | for ( ; i != -1 && i < k ; i = inext) /* traverse from i to k */ 21 | { 22 | inext = ancestor [i] ; /* inext = ancestor of i */ 23 | ancestor [i] = k ; /* path compression */ 24 | if (inext == -1) parent [i] = k ; /* no anc., parent is k */ 25 | } 26 | if (ata) prev [Ai [p]] = k ; 27 | } 28 | } 29 | return (cs_idone (parent, NULL, w, 1)) ; 30 | } 31 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_fkeep.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* drop entries for which fkeep(A(i,j)) is false; return nz if OK, else -1 */ 3 | int cs_fkeep (cs *A, int (*fkeep) (int, int, double, void *), void *other) 4 | { 5 | int j, p, nz = 0, n, *Ap, *Ai ; 6 | double *Ax ; 7 | if (!CS_CSC (A) || !fkeep) return (-1) ; /* check inputs */ 8 | n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ; 9 | for (j = 0 ; j < n ; j++) 10 | { 11 | p = Ap [j] ; /* get current location of col j */ 12 | Ap [j] = nz ; /* record new location of col j */ 13 | for ( ; p < Ap [j+1] ; p++) 14 | { 15 | if (fkeep (Ai [p], j, Ax ? Ax [p] : 1, other)) 16 | { 17 | if (Ax) Ax [nz] = Ax [p] ; /* keep A(i,j) */ 18 | Ai [nz++] = Ai [p] ; 19 | } 20 | } 21 | } 22 | Ap [n] = nz ; /* finalize A */ 23 | cs_sprealloc (A, 0) ; /* remove extra space from A */ 24 | return (nz) ; 25 | } 26 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_gaxpy.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* y = A*x+y */ 3 | int cs_gaxpy (const cs *A, const double *x, double *y) 4 | { 5 | int p, j, n, *Ap, *Ai ; 6 | double *Ax ; 7 | if (!CS_CSC (A) || !x || !y) return (0) ; /* check inputs */ 8 | n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ; 9 | for (j = 0 ; j < n ; j++) 10 | { 11 | for (p = Ap [j] ; p < Ap [j+1] ; p++) 12 | { 13 | y [Ai [p]] += Ax [p] * x [j] ; 14 | } 15 | } 16 | return (1) ; 17 | } 18 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_happly.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* apply the ith Householder vector to x */ 3 | int cs_happly (const cs *V, int i, double beta, double *x) 4 | { 5 | int p, *Vp, *Vi ; 6 | double *Vx, tau = 0 ; 7 | if (!CS_CSC (V) || !x) return (0) ; /* check inputs */ 8 | Vp = V->p ; Vi = V->i ; Vx = V->x ; 9 | for (p = Vp [i] ; p < Vp [i+1] ; p++) /* tau = v'*x */ 10 | { 11 | tau += Vx [p] * x [Vi [p]] ; 12 | } 13 | tau *= beta ; /* tau = beta*(v'*x) */ 14 | for (p = Vp [i] ; p < Vp [i+1] ; p++) /* x = x - v*tau */ 15 | { 16 | x [Vi [p]] -= Vx [p] * tau ; 17 | } 18 | return (1) ; 19 | } 20 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_house.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* create a Householder reflection [v,beta,s]=house(x), overwrite x with v, 3 | * where (I-beta*v*v')*x = s*e1. See Algo 5.1.1, Golub & Van Loan, 3rd ed. */ 4 | double cs_house (double *x, double *beta, int n) 5 | { 6 | double s, sigma = 0 ; 7 | int i ; 8 | if (!x || !beta) return (-1) ; /* check inputs */ 9 | for (i = 1 ; i < n ; i++) sigma += x [i] * x [i] ; 10 | if (sigma == 0) 11 | { 12 | s = fabs (x [0]) ; /* s = |x(0)| */ 13 | (*beta) = (x [0] <= 0) ? 2 : 0 ; 14 | x [0] = 1 ; 15 | } 16 | else 17 | { 18 | s = sqrt (x [0] * x [0] + sigma) ; /* s = norm (x) */ 19 | x [0] = (x [0] <= 0) ? (x [0] - s) : (-sigma / (x [0] + s)) ; 20 | (*beta) = -1. / (s * x [0]) ; 21 | } 22 | return (s) ; 23 | } 24 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_ipvec.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* x(p) = b, for dense vectors x and b; p=NULL denotes identity */ 3 | int cs_ipvec (const int *p, const double *b, double *x, int n) 4 | { 5 | int k ; 6 | if (!x || !b) return (0) ; /* check inputs */ 7 | for (k = 0 ; k < n ; k++) x [p ? p [k] : k] = b [k] ; 8 | return (1) ; 9 | } 10 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_leaf.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* consider A(i,j), node j in ith row subtree and return lca(jprev,j) */ 3 | int cs_leaf (int i, int j, const int *first, int *maxfirst, int *prevleaf, 4 | int *ancestor, int *jleaf) 5 | { 6 | int q, s, sparent, jprev ; 7 | if (!first || !maxfirst || !prevleaf || !ancestor || !jleaf) return (-1) ; 8 | *jleaf = 0 ; 9 | if (i <= j || first [j] <= maxfirst [i]) return (-1) ; /* j not a leaf */ 10 | maxfirst [i] = first [j] ; /* update max first[j] seen so far */ 11 | jprev = prevleaf [i] ; /* jprev = previous leaf of ith subtree */ 12 | prevleaf [i] = j ; 13 | *jleaf = (jprev == -1) ? 1: 2 ; /* j is first or subsequent leaf */ 14 | if (*jleaf == 1) return (i) ; /* if 1st leaf, q = root of ith subtree */ 15 | for (q = jprev ; q != ancestor [q] ; q = ancestor [q]) ; 16 | for (s = jprev ; s != q ; s = sparent) 17 | { 18 | sparent = ancestor [s] ; /* path compression */ 19 | ancestor [s] = q ; 20 | } 21 | return (q) ; /* q = least common ancester (jprev,j) */ 22 | } 23 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_load.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* load a triplet matrix from a file */ 3 | cs *cs_load (FILE *f) 4 | { 5 | int i, j ; 6 | double x ; 7 | cs *T ; 8 | if (!f) return (NULL) ; /* check inputs */ 9 | T = cs_spalloc (0, 0, 1, 1, 1) ; /* allocate result */ 10 | while (fscanf (f, "%d %d %lg\n", &i, &j, &x) == 3) 11 | { 12 | if (!cs_entry (T, i, j, x)) return (cs_spfree (T)) ; 13 | } 14 | return (T) ; 15 | } 16 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_lsolve.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* solve Lx=b where x and b are dense. x=b on input, solution on output. */ 3 | int cs_lsolve (const cs *L, double *x) 4 | { 5 | int p, j, n, *Lp, *Li ; 6 | double *Lx ; 7 | if (!CS_CSC (L) || !x) return (0) ; /* check inputs */ 8 | n = L->n ; Lp = L->p ; Li = L->i ; Lx = L->x ; 9 | for (j = 0 ; j < n ; j++) 10 | { 11 | x [j] /= Lx [Lp [j]] ; 12 | for (p = Lp [j]+1 ; p < Lp [j+1] ; p++) 13 | { 14 | x [Li [p]] -= Lx [p] * x [j] ; 15 | } 16 | } 17 | return (1) ; 18 | } 19 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_ltsolve.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* solve L'x=b where x and b are dense. x=b on input, solution on output. */ 3 | int cs_ltsolve (const cs *L, double *x) 4 | { 5 | int p, j, n, *Lp, *Li ; 6 | double *Lx ; 7 | if (!CS_CSC (L) || !x) return (0) ; /* check inputs */ 8 | n = L->n ; Lp = L->p ; Li = L->i ; Lx = L->x ; 9 | for (j = n-1 ; j >= 0 ; j--) 10 | { 11 | for (p = Lp [j]+1 ; p < Lp [j+1] ; p++) 12 | { 13 | x [j] -= Lx [p] * x [Li [p]] ; 14 | } 15 | x [j] /= Lx [Lp [j]] ; 16 | } 17 | return (1) ; 18 | } 19 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_lusol.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* x=A\b where A is unsymmetric; b overwritten with solution */ 3 | int cs_lusol (int order, const cs *A, double *b, double tol) 4 | { 5 | double *x ; 6 | css *S ; 7 | csn *N ; 8 | int n, ok ; 9 | if (!CS_CSC (A) || !b) return (0) ; /* check inputs */ 10 | n = A->n ; 11 | S = cs_sqr (order, A, 0) ; /* ordering and symbolic analysis */ 12 | N = cs_lu (A, S, tol) ; /* numeric LU factorization */ 13 | x = cs_malloc (n, sizeof (double)) ; /* get workspace */ 14 | ok = (S && N && x) ; 15 | if (ok) 16 | { 17 | cs_ipvec (N->pinv, b, x, n) ; /* x = b(p) */ 18 | cs_lsolve (N->L, x) ; /* x = L\x */ 19 | cs_usolve (N->U, x) ; /* x = U\x */ 20 | cs_ipvec (S->q, x, b, n) ; /* b(q) = x */ 21 | } 22 | cs_free (x) ; 23 | cs_sfree (S) ; 24 | cs_nfree (N) ; 25 | return (ok) ; 26 | } 27 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_malloc.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | #ifdef MATLAB_MEX_FILE 3 | #define malloc mxMalloc 4 | #define free mxFree 5 | #define realloc mxRealloc 6 | #define calloc mxCalloc 7 | #endif 8 | 9 | /* wrapper for malloc */ 10 | void *cs_malloc (int n, size_t size) 11 | { 12 | return (malloc (CS_MAX (n,1) * size)) ; 13 | } 14 | 15 | /* wrapper for calloc */ 16 | void *cs_calloc (int n, size_t size) 17 | { 18 | return (calloc (CS_MAX (n,1), size)) ; 19 | } 20 | 21 | /* wrapper for free */ 22 | void *cs_free (void *p) 23 | { 24 | if (p) free (p) ; /* free p if it is not already NULL */ 25 | return (NULL) ; /* return NULL to simplify the use of cs_free */ 26 | } 27 | 28 | /* wrapper for realloc */ 29 | void *cs_realloc (void *p, int n, size_t size, int *ok) 30 | { 31 | void *pnew ; 32 | pnew = realloc (p, CS_MAX (n,1) * size) ; /* realloc the block */ 33 | *ok = (pnew != NULL) ; /* realloc fails if pnew is NULL */ 34 | return ((*ok) ? pnew : p) ; /* return original p if failure */ 35 | } 36 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_multiply.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* C = A*B */ 3 | cs *cs_multiply (const cs *A, const cs *B) 4 | { 5 | int p, j, nz = 0, anz, *Cp, *Ci, *Bp, m, n, bnz, *w, values, *Bi ; 6 | double *x, *Bx, *Cx ; 7 | cs *C ; 8 | if (!CS_CSC (A) || !CS_CSC (B)) return (NULL) ; /* check inputs */ 9 | if (A->n != B->m) return (NULL) ; 10 | m = A->m ; anz = A->p [A->n] ; 11 | n = B->n ; Bp = B->p ; Bi = B->i ; Bx = B->x ; bnz = Bp [n] ; 12 | w = cs_calloc (m, sizeof (int)) ; /* get workspace */ 13 | values = (A->x != NULL) && (Bx != NULL) ; 14 | x = values ? cs_malloc (m, sizeof (double)) : NULL ; /* get workspace */ 15 | C = cs_spalloc (m, n, anz + bnz, values, 0) ; /* allocate result */ 16 | if (!C || !w || (values && !x)) return (cs_done (C, w, x, 0)) ; 17 | Cp = C->p ; 18 | for (j = 0 ; j < n ; j++) 19 | { 20 | if (nz + m > C->nzmax && !cs_sprealloc (C, 2*(C->nzmax)+m)) 21 | { 22 | return (cs_done (C, w, x, 0)) ; /* out of memory */ 23 | } 24 | Ci = C->i ; Cx = C->x ; /* C->i and C->x may be reallocated */ 25 | Cp [j] = nz ; /* column j of C starts here */ 26 | for (p = Bp [j] ; p < Bp [j+1] ; p++) 27 | { 28 | nz = cs_scatter (A, Bi [p], Bx ? Bx [p] : 1, w, x, j+1, C, nz) ; 29 | } 30 | if (values) for (p = Cp [j] ; p < nz ; p++) Cx [p] = x [Ci [p]] ; 31 | } 32 | Cp [n] = nz ; /* finalize the last column of C */ 33 | cs_sprealloc (C, 0) ; /* remove extra space from C */ 34 | return (cs_done (C, w, x, 1)) ; /* success; free workspace, return C */ 35 | } 36 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_norm.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* 1-norm of a sparse matrix = max (sum (abs (A))), largest column sum */ 3 | double cs_norm (const cs *A) 4 | { 5 | int p, j, n, *Ap ; 6 | double *Ax, norm = 0, s ; 7 | if (!CS_CSC (A) || !A->x) return (-1) ; /* check inputs */ 8 | n = A->n ; Ap = A->p ; Ax = A->x ; 9 | for (j = 0 ; j < n ; j++) 10 | { 11 | for (s = 0, p = Ap [j] ; p < Ap [j+1] ; p++) s += fabs (Ax [p]) ; 12 | norm = CS_MAX (norm, s) ; 13 | } 14 | return (norm) ; 15 | } 16 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_permute.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* C = A(p,q) where p and q are permutations of 0..m-1 and 0..n-1. */ 3 | cs *cs_permute (const cs *A, const int *pinv, const int *q, int values) 4 | { 5 | int t, j, k, nz = 0, m, n, *Ap, *Ai, *Cp, *Ci ; 6 | double *Cx, *Ax ; 7 | cs *C ; 8 | if (!CS_CSC (A)) return (NULL) ; /* check inputs */ 9 | m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ; 10 | C = cs_spalloc (m, n, Ap [n], values && Ax != NULL, 0) ; /* alloc result */ 11 | if (!C) return (cs_done (C, NULL, NULL, 0)) ; /* out of memory */ 12 | Cp = C->p ; Ci = C->i ; Cx = C->x ; 13 | for (k = 0 ; k < n ; k++) 14 | { 15 | Cp [k] = nz ; /* column k of C is column q[k] of A */ 16 | j = q ? (q [k]) : k ; 17 | for (t = Ap [j] ; t < Ap [j+1] ; t++) 18 | { 19 | if (Cx) Cx [nz] = Ax [t] ; /* row i of A is row pinv[i] of C */ 20 | Ci [nz++] = pinv ? (pinv [Ai [t]]) : Ai [t] ; 21 | } 22 | } 23 | Cp [n] = nz ; /* finalize the last column of C */ 24 | return (cs_done (C, NULL, NULL, 1)) ; 25 | } 26 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_pinv.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* pinv = p', or p = pinv' */ 3 | int *cs_pinv (int const *p, int n) 4 | { 5 | int k, *pinv ; 6 | if (!p) return (NULL) ; /* p = NULL denotes identity */ 7 | pinv = cs_malloc (n, sizeof (int)) ; /* allocate result */ 8 | if (!pinv) return (NULL) ; /* out of memory */ 9 | for (k = 0 ; k < n ; k++) pinv [p [k]] = k ;/* invert the permutation */ 10 | return (pinv) ; /* return result */ 11 | } 12 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_post.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* post order a forest */ 3 | int *cs_post (const int *parent, int n) 4 | { 5 | int j, k = 0, *post, *w, *head, *next, *stack ; 6 | if (!parent) return (NULL) ; /* check inputs */ 7 | post = cs_malloc (n, sizeof (int)) ; /* allocate result */ 8 | w = cs_malloc (3*n, sizeof (int)) ; /* get workspace */ 9 | if (!w || !post) return (cs_idone (post, NULL, w, 0)) ; 10 | head = w ; next = w + n ; stack = w + 2*n ; 11 | for (j = 0 ; j < n ; j++) head [j] = -1 ; /* empty linked lists */ 12 | for (j = n-1 ; j >= 0 ; j--) /* traverse nodes in reverse order*/ 13 | { 14 | if (parent [j] == -1) continue ; /* j is a root */ 15 | next [j] = head [parent [j]] ; /* add j to list of its parent */ 16 | head [parent [j]] = j ; 17 | } 18 | for (j = 0 ; j < n ; j++) 19 | { 20 | if (parent [j] != -1) continue ; /* skip j if it is not a root */ 21 | k = cs_tdfs (j, k, head, next, post, stack) ; 22 | } 23 | return (cs_idone (post, NULL, w, 1)) ; /* success; free w, return post */ 24 | } 25 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_print.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* print a sparse matrix */ 3 | int cs_print (const cs *A, int brief) 4 | { 5 | int p, j, m, n, nzmax, nz, *Ap, *Ai ; 6 | double *Ax ; 7 | if (!A) { printf ("(null)\n") ; return (0) ; } 8 | m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ; 9 | nzmax = A->nzmax ; nz = A->nz ; 10 | printf ("CSparse Version %d.%d.%d, %s. %s\n", CS_VER, CS_SUBVER, 11 | CS_SUBSUB, CS_DATE, CS_COPYRIGHT) ; 12 | if (nz < 0) 13 | { 14 | printf ("%d-by-%d, nzmax: %d nnz: %d, 1-norm: %g\n", m, n, nzmax, 15 | Ap [n], cs_norm (A)) ; 16 | for (j = 0 ; j < n ; j++) 17 | { 18 | printf (" col %d : locations %d to %d\n", j, Ap [j], Ap [j+1]-1); 19 | for (p = Ap [j] ; p < Ap [j+1] ; p++) 20 | { 21 | printf (" %d : %g\n", Ai [p], Ax ? Ax [p] : 1) ; 22 | if (brief && p > 20) { printf (" ...\n") ; return (1) ; } 23 | } 24 | } 25 | } 26 | else 27 | { 28 | printf ("triplet: %d-by-%d, nzmax: %d nnz: %d\n", m, n, nzmax, nz) ; 29 | for (p = 0 ; p < nz ; p++) 30 | { 31 | printf (" %d %d : %g\n", Ai [p], Ap [p], Ax ? Ax [p] : 1) ; 32 | if (brief && p > 20) { printf (" ...\n") ; return (1) ; } 33 | } 34 | } 35 | return (1) ; 36 | } 37 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_pvec.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* x = b(p), for dense vectors x and b; p=NULL denotes identity */ 3 | int cs_pvec (const int *p, const double *b, double *x, int n) 4 | { 5 | int k ; 6 | if (!x || !b) return (0) ; /* check inputs */ 7 | for (k = 0 ; k < n ; k++) x [k] = b [p ? p [k] : k] ; 8 | return (1) ; 9 | } 10 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_qrsol.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* x=A\b where A can be rectangular; b overwritten with solution */ 3 | int cs_qrsol (int order, const cs *A, double *b) 4 | { 5 | double *x ; 6 | css *S ; 7 | csn *N ; 8 | cs *AT = NULL ; 9 | int k, m, n, ok ; 10 | if (!CS_CSC (A) || !b) return (0) ; /* check inputs */ 11 | n = A->n ; 12 | m = A->m ; 13 | if (m >= n) 14 | { 15 | S = cs_sqr (order, A, 1) ; /* ordering and symbolic analysis */ 16 | N = cs_qr (A, S) ; /* numeric QR factorization */ 17 | x = cs_calloc (S ? S->m2 : 1, sizeof (double)) ; /* get workspace */ 18 | ok = (S && N && x) ; 19 | if (ok) 20 | { 21 | cs_ipvec (S->pinv, b, x, m) ; /* x(0:m-1) = b(p(0:m-1) */ 22 | for (k = 0 ; k < n ; k++) /* apply Householder refl. to x */ 23 | { 24 | cs_happly (N->L, k, N->B [k], x) ; 25 | } 26 | cs_usolve (N->U, x) ; /* x = R\x */ 27 | cs_ipvec (S->q, x, b, n) ; /* b(q(0:n-1)) = x(0:n-1) */ 28 | } 29 | } 30 | else 31 | { 32 | AT = cs_transpose (A, 1) ; /* Ax=b is underdetermined */ 33 | S = cs_sqr (order, AT, 1) ; /* ordering and symbolic analysis */ 34 | N = cs_qr (AT, S) ; /* numeric QR factorization of A' */ 35 | x = cs_calloc (S ? S->m2 : 1, sizeof (double)) ; /* get workspace */ 36 | ok = (AT && S && N && x) ; 37 | if (ok) 38 | { 39 | cs_pvec (S->q, b, x, m) ; /* x(q(0:m-1)) = b(0:m-1) */ 40 | cs_utsolve (N->U, x) ; /* x = R'\x */ 41 | for (k = m-1 ; k >= 0 ; k--) /* apply Householder refl. to x */ 42 | { 43 | cs_happly (N->L, k, N->B [k], x) ; 44 | } 45 | cs_pvec (S->pinv, x, b, n) ; /* b(0:n-1) = x(p(0:n-1)) */ 46 | } 47 | } 48 | cs_free (x) ; 49 | cs_sfree (S) ; 50 | cs_nfree (N) ; 51 | cs_spfree (AT) ; 52 | return (ok) ; 53 | } 54 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_randperm.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* return a random permutation vector, the identity perm, or p = n-1:-1:0. 3 | * seed = -1 means p = n-1:-1:0. seed = 0 means p = identity. otherwise 4 | * p = random permutation. */ 5 | int *cs_randperm (int n, int seed) 6 | { 7 | int *p, k, j, t ; 8 | if (seed == 0) return (NULL) ; /* return p = NULL (identity) */ 9 | p = cs_malloc (n, sizeof (int)) ; /* allocate result */ 10 | if (!p) return (NULL) ; /* out of memory */ 11 | for (k = 0 ; k < n ; k++) p [k] = n-k-1 ; 12 | if (seed == -1) return (p) ; /* return reverse permutation */ 13 | srand (seed) ; /* get new random number seed */ 14 | for (k = 0 ; k < n ; k++) 15 | { 16 | j = k + (rand ( ) % (n-k)) ; /* j = rand int in range k to n-1 */ 17 | t = p [j] ; /* swap p[k] and p[j] */ 18 | p [j] = p [k] ; 19 | p [k] = t ; 20 | } 21 | return (p) ; 22 | } 23 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_reach.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* xi [top...n-1] = nodes reachable from graph of G*P' via nodes in B(:,k). 3 | * xi [n...2n-1] used as workspace */ 4 | int cs_reach (cs *G, const cs *B, int k, int *xi, const int *pinv) 5 | { 6 | int p, n, top, *Bp, *Bi, *Gp ; 7 | if (!CS_CSC (G) || !CS_CSC (B) || !xi) return (-1) ; /* check inputs */ 8 | n = G->n ; Bp = B->p ; Bi = B->i ; Gp = G->p ; 9 | top = n ; 10 | for (p = Bp [k] ; p < Bp [k+1] ; p++) 11 | { 12 | if (!CS_MARKED (Gp, Bi [p])) /* start a dfs at unmarked node i */ 13 | { 14 | top = cs_dfs (Bi [p], G, top, xi, xi+n, pinv) ; 15 | } 16 | } 17 | for (p = top ; p < n ; p++) CS_MARK (Gp, xi [p]) ; /* restore G */ 18 | return (top) ; 19 | } 20 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_scatter.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* x = x + beta * A(:,j), where x is a dense vector and A(:,j) is sparse */ 3 | int cs_scatter (const cs *A, int j, double beta, int *w, double *x, int mark, 4 | cs *C, int nz) 5 | { 6 | int i, p, *Ap, *Ai, *Ci ; 7 | double *Ax ; 8 | if (!CS_CSC (A) || !w || !CS_CSC (C)) return (-1) ; /* check inputs */ 9 | Ap = A->p ; Ai = A->i ; Ax = A->x ; Ci = C->i ; 10 | for (p = Ap [j] ; p < Ap [j+1] ; p++) 11 | { 12 | i = Ai [p] ; /* A(i,j) is nonzero */ 13 | if (w [i] < mark) 14 | { 15 | w [i] = mark ; /* i is new entry in column j */ 16 | Ci [nz++] = i ; /* add i to pattern of C(:,j) */ 17 | if (x) x [i] = beta * Ax [p] ; /* x(i) = beta*A(i,j) */ 18 | } 19 | else if (x) x [i] += beta * Ax [p] ; /* i exists in C(:,j) already */ 20 | } 21 | return (nz) ; 22 | } 23 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_scc.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* find the strongly connected components of a square matrix */ 3 | csd *cs_scc (cs *A) /* matrix A temporarily modified, then restored */ 4 | { 5 | int n, i, k, b, nb = 0, top, *xi, *pstack, *p, *r, *Ap, *ATp, *rcopy, *Blk ; 6 | cs *AT ; 7 | csd *D ; 8 | if (!CS_CSC (A)) return (NULL) ; /* check inputs */ 9 | n = A->n ; Ap = A->p ; 10 | D = cs_dalloc (n, 0) ; /* allocate result */ 11 | AT = cs_transpose (A, 0) ; /* AT = A' */ 12 | xi = cs_malloc (2*n+1, sizeof (int)) ; /* get workspace */ 13 | if (!D || !AT || !xi) return (cs_ddone (D, AT, xi, 0)) ; 14 | Blk = xi ; rcopy = pstack = xi + n ; 15 | p = D->p ; r = D->r ; ATp = AT->p ; 16 | top = n ; 17 | for (i = 0 ; i < n ; i++) /* first dfs(A) to find finish times (xi) */ 18 | { 19 | if (!CS_MARKED (Ap, i)) top = cs_dfs (i, A, top, xi, pstack, NULL) ; 20 | } 21 | for (i = 0 ; i < n ; i++) CS_MARK (Ap, i) ; /* restore A; unmark all nodes*/ 22 | top = n ; 23 | nb = n ; 24 | for (k = 0 ; k < n ; k++) /* dfs(A') to find strongly connnected comp */ 25 | { 26 | i = xi [k] ; /* get i in reverse order of finish times */ 27 | if (CS_MARKED (ATp, i)) continue ; /* skip node i if already ordered */ 28 | r [nb--] = top ; /* node i is the start of a component in p */ 29 | top = cs_dfs (i, AT, top, p, pstack, NULL) ; 30 | } 31 | r [nb] = 0 ; /* first block starts at zero; shift r up */ 32 | for (k = nb ; k <= n ; k++) r [k-nb] = r [k] ; 33 | D->nb = nb = n-nb ; /* nb = # of strongly connected components */ 34 | for (b = 0 ; b < nb ; b++) /* sort each block in natural order */ 35 | { 36 | for (k = r [b] ; k < r [b+1] ; k++) Blk [p [k]] = b ; 37 | } 38 | for (b = 0 ; b <= nb ; b++) rcopy [b] = r [b] ; 39 | for (i = 0 ; i < n ; i++) p [rcopy [Blk [i]]++] = i ; 40 | return (cs_ddone (D, AT, xi, 1)) ; 41 | } 42 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_schol.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* ordering and symbolic analysis for a Cholesky factorization */ 3 | css *cs_schol (int order, const cs *A) 4 | { 5 | int n, *c, *post, *P ; 6 | cs *C ; 7 | css *S ; 8 | if (!CS_CSC (A)) return (NULL) ; /* check inputs */ 9 | n = A->n ; 10 | S = cs_calloc (1, sizeof (css)) ; /* allocate result S */ 11 | if (!S) return (NULL) ; /* out of memory */ 12 | P = cs_amd (order, A) ; /* P = amd(A+A'), or natural */ 13 | S->pinv = cs_pinv (P, n) ; /* find inverse permutation */ 14 | cs_free (P) ; 15 | if (order && !S->pinv) return (cs_sfree (S)) ; 16 | C = cs_symperm (A, S->pinv, 0) ; /* C = spones(triu(A(P,P))) */ 17 | S->parent = cs_etree (C, 0) ; /* find etree of C */ 18 | post = cs_post (S->parent, n) ; /* postorder the etree */ 19 | c = cs_counts (C, S->parent, post, 0) ; /* find column counts of chol(C) */ 20 | cs_free (post) ; 21 | cs_spfree (C) ; 22 | S->cp = cs_malloc (n+1, sizeof (int)) ; /* allocate result S->cp */ 23 | S->unz = S->lnz = cs_cumsum (S->cp, c, n) ; /* find column pointers for L */ 24 | cs_free (c) ; 25 | return ((S->lnz >= 0) ? S : cs_sfree (S)) ; 26 | } 27 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_spsolve.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* solve Gx=b(:,k), where G is either upper (lo=0) or lower (lo=1) triangular */ 3 | int cs_spsolve (cs *G, const cs *B, int k, int *xi, double *x, const int *pinv, 4 | int lo) 5 | { 6 | int j, J, p, q, px, top, n, *Gp, *Gi, *Bp, *Bi ; 7 | double *Gx, *Bx ; 8 | if (!CS_CSC (G) || !CS_CSC (B) || !xi || !x) return (-1) ; 9 | Gp = G->p ; Gi = G->i ; Gx = G->x ; n = G->n ; 10 | Bp = B->p ; Bi = B->i ; Bx = B->x ; 11 | top = cs_reach (G, B, k, xi, pinv) ; /* xi[top..n-1]=Reach(B(:,k)) */ 12 | for (p = top ; p < n ; p++) x [xi [p]] = 0 ; /* clear x */ 13 | for (p = Bp [k] ; p < Bp [k+1] ; p++) x [Bi [p]] = Bx [p] ; /* scatter B */ 14 | for (px = top ; px < n ; px++) 15 | { 16 | j = xi [px] ; /* x(j) is nonzero */ 17 | J = pinv ? (pinv [j]) : j ; /* j maps to col J of G */ 18 | if (J < 0) continue ; /* column J is empty */ 19 | x [j] /= Gx [lo ? (Gp [J]) : (Gp [J+1]-1)] ;/* x(j) /= G(j,j) */ 20 | p = lo ? (Gp [J]+1) : (Gp [J]) ; /* lo: L(j,j) 1st entry */ 21 | q = lo ? (Gp [J+1]) : (Gp [J+1]-1) ; /* up: U(j,j) last entry */ 22 | for ( ; p < q ; p++) 23 | { 24 | x [Gi [p]] -= Gx [p] * x [j] ; /* x(i) -= G(i,j) * x(j) */ 25 | } 26 | } 27 | return (top) ; /* return top of stack */ 28 | } 29 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_symperm.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* C = A(p,p) where A and C are symmetric the upper part stored; pinv not p */ 3 | cs *cs_symperm (const cs *A, const int *pinv, int values) 4 | { 5 | int i, j, p, q, i2, j2, n, *Ap, *Ai, *Cp, *Ci, *w ; 6 | double *Cx, *Ax ; 7 | cs *C ; 8 | if (!CS_CSC (A)) return (NULL) ; /* check inputs */ 9 | n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ; 10 | C = cs_spalloc (n, n, Ap [n], values && (Ax != NULL), 0) ; /* alloc result*/ 11 | w = cs_calloc (n, sizeof (int)) ; /* get workspace */ 12 | if (!C || !w) return (cs_done (C, w, NULL, 0)) ; /* out of memory */ 13 | Cp = C->p ; Ci = C->i ; Cx = C->x ; 14 | for (j = 0 ; j < n ; j++) /* count entries in each column of C */ 15 | { 16 | j2 = pinv ? pinv [j] : j ; /* column j of A is column j2 of C */ 17 | for (p = Ap [j] ; p < Ap [j+1] ; p++) 18 | { 19 | i = Ai [p] ; 20 | if (i > j) continue ; /* skip lower triangular part of A */ 21 | i2 = pinv ? pinv [i] : i ; /* row i of A is row i2 of C */ 22 | w [CS_MAX (i2, j2)]++ ; /* column count of C */ 23 | } 24 | } 25 | cs_cumsum (Cp, w, n) ; /* compute column pointers of C */ 26 | for (j = 0 ; j < n ; j++) 27 | { 28 | j2 = pinv ? pinv [j] : j ; /* column j of A is column j2 of C */ 29 | for (p = Ap [j] ; p < Ap [j+1] ; p++) 30 | { 31 | i = Ai [p] ; 32 | if (i > j) continue ; /* skip lower triangular part of A*/ 33 | i2 = pinv ? pinv [i] : i ; /* row i of A is row i2 of C */ 34 | Ci [q = w [CS_MAX (i2, j2)]++] = CS_MIN (i2, j2) ; 35 | if (Cx) Cx [q] = Ax [p] ; 36 | } 37 | } 38 | return (cs_done (C, w, NULL, 1)) ; /* success; free workspace, return C */ 39 | } 40 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_tdfs.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* depth-first search and postorder of a tree rooted at node j */ 3 | int cs_tdfs (int j, int k, int *head, const int *next, int *post, int *stack) 4 | { 5 | int i, p, top = 0 ; 6 | if (!head || !next || !post || !stack) return (-1) ; /* check inputs */ 7 | stack [0] = j ; /* place j on the stack */ 8 | while (top >= 0) /* while (stack is not empty) */ 9 | { 10 | p = stack [top] ; /* p = top of stack */ 11 | i = head [p] ; /* i = youngest child of p */ 12 | if (i == -1) 13 | { 14 | top-- ; /* p has no unordered children left */ 15 | post [k++] = p ; /* node p is the kth postordered node */ 16 | } 17 | else 18 | { 19 | head [p] = next [i] ; /* remove i from children of p */ 20 | stack [++top] = i ; /* start dfs on child node i */ 21 | } 22 | } 23 | return (k) ; 24 | } 25 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_transpose.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* C = A' */ 3 | cs *cs_transpose (const cs *A, int values) 4 | { 5 | int p, q, j, *Cp, *Ci, n, m, *Ap, *Ai, *w ; 6 | double *Cx, *Ax ; 7 | cs *C ; 8 | if (!CS_CSC (A)) return (NULL) ; /* check inputs */ 9 | m = A->m ; n = A->n ; Ap = A->p ; Ai = A->i ; Ax = A->x ; 10 | C = cs_spalloc (n, m, Ap [n], values && Ax, 0) ; /* allocate result */ 11 | w = cs_calloc (m, sizeof (int)) ; /* get workspace */ 12 | if (!C || !w) return (cs_done (C, w, NULL, 0)) ; /* out of memory */ 13 | Cp = C->p ; Ci = C->i ; Cx = C->x ; 14 | for (p = 0 ; p < Ap [n] ; p++) w [Ai [p]]++ ; /* row counts */ 15 | cs_cumsum (Cp, w, m) ; /* row pointers */ 16 | for (j = 0 ; j < n ; j++) 17 | { 18 | for (p = Ap [j] ; p < Ap [j+1] ; p++) 19 | { 20 | Ci [q = w [Ai [p]]++] = j ; /* place A(i,j) as entry C(j,i) */ 21 | if (Cx) Cx [q] = Ax [p] ; 22 | } 23 | } 24 | return (cs_done (C, w, NULL, 1)) ; /* success; free w and return C */ 25 | } 26 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_updown.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* sparse Cholesky update/downdate, L*L' + sigma*w*w' (sigma = +1 or -1) */ 3 | int cs_updown (cs *L, int sigma, const cs *C, const int *parent) 4 | { 5 | int n, p, f, j, *Lp, *Li, *Cp, *Ci ; 6 | double *Lx, *Cx, alpha, beta = 1, delta, gamma, w1, w2, *w, beta2 = 1 ; 7 | if (!CS_CSC (L) || !CS_CSC (C) || !parent) return (0) ; /* check inputs */ 8 | Lp = L->p ; Li = L->i ; Lx = L->x ; n = L->n ; 9 | Cp = C->p ; Ci = C->i ; Cx = C->x ; 10 | if ((p = Cp [0]) >= Cp [1]) return (1) ; /* return if C empty */ 11 | w = cs_malloc (n, sizeof (double)) ; /* get workspace */ 12 | if (!w) return (0) ; /* out of memory */ 13 | f = Ci [p] ; 14 | for ( ; p < Cp [1] ; p++) f = CS_MIN (f, Ci [p]) ; /* f = min (find (C)) */ 15 | for (j = f ; j != -1 ; j = parent [j]) w [j] = 0 ; /* clear workspace w */ 16 | for (p = Cp [0] ; p < Cp [1] ; p++) w [Ci [p]] = Cx [p] ; /* w = C */ 17 | for (j = f ; j != -1 ; j = parent [j]) /* walk path f up to root */ 18 | { 19 | p = Lp [j] ; 20 | alpha = w [j] / Lx [p] ; /* alpha = w(j) / L(j,j) */ 21 | beta2 = beta*beta + sigma*alpha*alpha ; 22 | if (beta2 <= 0) break ; /* not positive definite */ 23 | beta2 = sqrt (beta2) ; 24 | delta = (sigma > 0) ? (beta / beta2) : (beta2 / beta) ; 25 | gamma = sigma * alpha / (beta2 * beta) ; 26 | Lx [p] = delta * Lx [p] + ((sigma > 0) ? (gamma * w [j]) : 0) ; 27 | beta = beta2 ; 28 | for (p++ ; p < Lp [j+1] ; p++) 29 | { 30 | w1 = w [Li [p]] ; 31 | w [Li [p]] = w2 = w1 - alpha * Lx [p] ; 32 | Lx [p] = delta * Lx [p] + gamma * ((sigma > 0) ? w1 : w2) ; 33 | } 34 | } 35 | cs_free (w) ; 36 | return (beta2 > 0) ; 37 | } 38 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_usolve.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* solve Ux=b where x and b are dense. x=b on input, solution on output. */ 3 | int cs_usolve (const cs *U, double *x) 4 | { 5 | int p, j, n, *Up, *Ui ; 6 | double *Ux ; 7 | if (!CS_CSC (U) || !x) return (0) ; /* check inputs */ 8 | n = U->n ; Up = U->p ; Ui = U->i ; Ux = U->x ; 9 | for (j = n-1 ; j >= 0 ; j--) 10 | { 11 | x [j] /= Ux [Up [j+1]-1] ; 12 | for (p = Up [j] ; p < Up [j+1]-1 ; p++) 13 | { 14 | x [Ui [p]] -= Ux [p] * x [j] ; 15 | } 16 | } 17 | return (1) ; 18 | } 19 | -------------------------------------------------------------------------------- /gaps/pkgs/CSparse/cs_utsolve.c: -------------------------------------------------------------------------------- 1 | #include "cs.h" 2 | /* solve U'x=b where x and b are dense. x=b on input, solution on output. */ 3 | int cs_utsolve (const cs *U, double *x) 4 | { 5 | int p, j, n, *Up, *Ui ; 6 | double *Ux ; 7 | if (!CS_CSC (U) || !x) return (0) ; /* check inputs */ 8 | n = U->n ; Up = U->p ; Ui = U->i ; Ux = U->x ; 9 | for (j = 0 ; j < n ; j++) 10 | { 11 | for (p = Up [j] ; p < Up [j+1]-1 ; p++) 12 | { 13 | x [j] -= Ux [p] * x [Ui [p]] ; 14 | } 15 | x [j] /= Ux [Up [j+1]-1] ; 16 | } 17 | return (1) ; 18 | } 19 | -------------------------------------------------------------------------------- /gaps/pkgs/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Makefile for GAPS pkgs 3 | # 4 | 5 | 6 | # 7 | # Library file names 8 | # 9 | 10 | ARCH=$(shell uname -m) 11 | LIB_DIR=../lib/$(ARCH) 12 | LIB=$(LIB_DIR)/libgaps.a 13 | PKG_LIBS= \ 14 | $(LIB_DIR)/libR2Shapes.a \ 15 | $(LIB_DIR)/libRNMath.a \ 16 | $(LIB_DIR)/libRNBasics.a \ 17 | $(LIB_DIR)/libCSparse.a \ 18 | $(LIB_DIR)/libjpeg.a \ 19 | $(LIB_DIR)/libpng.a 20 | 21 | 22 | # 23 | # Make targets 24 | # 25 | 26 | opt: 27 | $(MAKE) target "TARGET=$@" 28 | rm -f $(LIB) 29 | ar ur $(LIB) $(PKG_LIBS) 30 | 31 | debug: 32 | $(MAKE) target "TARGET=$@" 33 | rm -f $(LIB) 34 | ar ur $(LIB) $(PKG_LIBS) 35 | 36 | mesa: 37 | $(MAKE) target "TARGET=$@" 38 | 39 | clean: 40 | $(MAKE) target "TARGET=$@" 41 | 42 | target: 43 | cd RNBasics; $(MAKE) $(TARGET) 44 | cd RNMath; $(MAKE) $(TARGET) 45 | cd R2Shapes; $(MAKE) $(TARGET) 46 | cd CSparse; $(MAKE) $(TARGET) 47 | cd jpeg; $(MAKE) $(TARGET) 48 | cd png; $(MAKE) $(TARGET) 49 | 50 | 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Package name 3 | # 4 | 5 | NAME=R2Shapes 6 | 7 | 8 | 9 | # 10 | # List of source files 11 | # 12 | 13 | CCSRCS=R2Shapes.cpp \ 14 | R2Draw.cpp R2Io.cpp R2Kdtree.cpp \ 15 | R2Dist.cpp R2Cont.cpp R2Isect.cpp R2Parall.cpp R2Perp.cpp R2Relate.cpp R2Align.cpp \ 16 | R2Grid.cpp \ 17 | R2Polyline.cpp R2Arc.cpp R2Curve.cpp \ 18 | R2Polygon.cpp R2Circle.cpp R2Box.cpp R2Solid.cpp \ 19 | R2Shape.cpp \ 20 | R2Affine.cpp R2Xform.cpp R2Crdsys.cpp R2Diad.cpp R3Matrix.cpp \ 21 | R2Halfspace.cpp R2Span.cpp R2Ray.cpp R2Line.cpp R2Point.cpp R2Vector.cpp \ 22 | R2Image.cpp 23 | 24 | 25 | # 26 | # Dependencies 27 | # 28 | 29 | PKG_DEPENDENCIES = RNBasics jpeg png 30 | 31 | 32 | 33 | # 34 | # PKG makefile 35 | # 36 | 37 | include ../../makefiles/Makefile.pkgs 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Align.h: -------------------------------------------------------------------------------- 1 | // Include file for alignment utility functions 2 | 3 | 4 | 5 | // Functions to align RNArray of points 6 | 7 | R2Point R2Centroid(const RNArray& points, const RNScalar *weights = NULL); 8 | R2Diad R2PrincipleAxes(const R2Point& centroid, const RNArray& points, const RNScalar *weights = NULL, RNScalar *variances = NULL); 9 | RNLength R2AverageDistance(const R2Point& center, const RNArray& points, const RNScalar *weights = NULL); 10 | R2Affine R2NormalizationTransformation(const RNArray& points, 11 | RNBoolean align_center = TRUE, RNBoolean align_rotation = TRUE, int align_scale = 1); 12 | RNScalar R2AlignError(const RNArray& points1, const RNArray& points2, 13 | const R3Matrix& matrix = R3identity_matrix, const RNScalar* weights = NULL); 14 | R3Matrix R2AlignPoints(const RNArray& points1, const RNArray& points2, const RNScalar* weights = NULL, 15 | RNBoolean align_center = TRUE, RNBoolean align_rotation = TRUE, int align_scale = 1); 16 | 17 | 18 | 19 | // Functions to align C array of points 20 | 21 | R2Point R2Centroid(int npoints, R2Point *points, const RNScalar *weights = NULL); 22 | R2Diad R2PrincipleAxes(const R2Point& centroid, int npoints, R2Point *points, const RNScalar *weights = NULL, RNScalar *variances = NULL); 23 | RNLength R2AverageDistance(const R2Point& center, int npoints, R2Point *points, const RNScalar *weights = NULL); 24 | R2Affine R2NormalizationTransformation(int npoints, R2Point *points, 25 | RNBoolean align_center = TRUE, RNBoolean align_rotation = TRUE, int align_scale = 1); 26 | RNScalar R2AlignError(int npoints, R2Point *points1, R2Point *points2, 27 | const R3Matrix& matrix = R3identity_matrix, RNScalar* weights = NULL); 28 | R3Matrix R2AlignPoints(int npoints, R2Point *points1, R2Point *points2, const RNScalar* weights = NULL, 29 | RNBoolean align_center = TRUE, RNBoolean align_rotation = TRUE, int align_scale = 1); 30 | 31 | 32 | 33 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Circle.h: -------------------------------------------------------------------------------- 1 | /* Include file for the R2 circle class */ 2 | 3 | 4 | 5 | /* Initialization functions */ 6 | 7 | int R2InitCircle(); 8 | void R2StopCircle(); 9 | 10 | 11 | 12 | /* Class definition */ 13 | 14 | class R2Circle : public R2Solid { 15 | public: 16 | // Constructor functions 17 | R2Circle(void); 18 | R2Circle(const R2Circle& circle); 19 | R2Circle(const R2Point& center, RNLength radius); 20 | 21 | // Circle property functions/operators 22 | const R2Point& Center(void) const; 23 | const RNLength Radius(void) const; 24 | const RNBoolean IsEmpty(void) const; 25 | const RNBoolean IsFinite(void) const; 26 | 27 | // Shape property functions/operators 28 | virtual const RNBoolean IsPoint(void) const; 29 | virtual const RNBoolean IsLinear(void) const ; 30 | virtual const RNBoolean IsConvex(void) const ; 31 | virtual const RNArea Area(void) const; 32 | virtual const R2Point Centroid(void) const; 33 | virtual const R2Shape& BShape(void) const; 34 | virtual const R2Box BBox(void) const; 35 | virtual const R2Circle BCircle(void) const; 36 | 37 | // Manipulation functions/operators 38 | virtual void Empty(void); 39 | virtual void Translate(const R2Vector& vector); 40 | virtual void Reposition(const R2Point& center); 41 | virtual void Resize(RNLength radius); 42 | virtual void Transform(const R2Transformation& transformation); 43 | 44 | // Draw functions/operators 45 | virtual void Draw(const R2DrawFlags draw_flags = R2_DEFAULT_DRAW_FLAGS) const; 46 | 47 | private: 48 | R2Point center; 49 | RNLength radius; 50 | }; 51 | 52 | 53 | 54 | /* Public variables */ 55 | 56 | extern const R2Circle R2null_circle; 57 | extern const R2Circle R2zero_circle; 58 | extern const R2Circle R2unit_circle; 59 | extern const R2Circle R2infinite_circle; 60 | 61 | extern const int R2circle_npoints; 62 | extern RNAngle R2circle_angles[]; 63 | extern R2Point R2circle_points[]; 64 | 65 | 66 | 67 | /* Inline functions */ 68 | 69 | inline const R2Point& R2Circle:: 70 | Center(void) const 71 | { 72 | // Return circle center 73 | return center; 74 | } 75 | 76 | 77 | 78 | inline const RNLength R2Circle:: 79 | Radius(void) const 80 | { 81 | // Return circle radius 82 | return radius; 83 | } 84 | 85 | 86 | 87 | inline const RNBoolean R2Circle:: 88 | IsEmpty(void) const 89 | { 90 | // Return whether the circle is null 91 | return (radius < 0.0); 92 | } 93 | 94 | 95 | 96 | inline const RNBoolean R2Circle:: 97 | IsFinite(void) const 98 | { 99 | // Return whether the circle has finite radius 100 | return RNIsFinite(radius); 101 | } 102 | 103 | 104 | 105 | 106 | 107 | 108 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Crdsys.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for the GAPS coordinatesystem class */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "R2Shapes/R2Shapes.h" 8 | 9 | 10 | 11 | /* Public variables */ 12 | 13 | const R2CoordSystem R2xy_coordinate_system(R2Point(0.0, 0.0), R2Diad(R2Vector(1.0, 0.0), R2Vector(0.0, 1.0))); 14 | 15 | 16 | 17 | /* Public functions */ 18 | 19 | int R2InitCoordinateSystem() 20 | { 21 | /* Return success */ 22 | return TRUE; 23 | } 24 | 25 | 26 | 27 | void R2StopCoordinateSystem() 28 | { 29 | } 30 | 31 | 32 | 33 | R2CoordSystem:: 34 | R2CoordSystem(void) 35 | { 36 | } 37 | 38 | 39 | 40 | R2CoordSystem:: 41 | R2CoordSystem(const R2CoordSystem& cs) 42 | : origin(cs.origin), 43 | axes(cs.axes) 44 | { 45 | } 46 | 47 | 48 | 49 | R2CoordSystem:: 50 | R2CoordSystem(const R2Point& origin, const R2Diad& axes) 51 | : origin(origin), 52 | axes(axes) 53 | { 54 | } 55 | 56 | 57 | 58 | const R3Matrix R2CoordSystem:: 59 | Matrix(void) const 60 | { 61 | // Return matrix (std -> cs) 62 | R3Matrix m(R3identity_matrix); 63 | m.Translate(origin.Vector()); 64 | m.Transform(axes.Matrix()); 65 | return m; 66 | } 67 | 68 | 69 | 70 | const R3Matrix R2CoordSystem:: 71 | InverseMatrix(void) const 72 | { 73 | // Return matrix (cs -> std) 74 | R3Matrix m(axes.InverseMatrix()); 75 | m.Translate(-origin.Vector()); 76 | return m; 77 | } 78 | 79 | 80 | 81 | void R2CoordSystem:: 82 | SetOrigin(const R2Point& origin) 83 | { 84 | // Set origin 85 | this->origin = origin; 86 | } 87 | 88 | 89 | 90 | void R2CoordSystem:: 91 | SetAxes(const R2Diad& axes) 92 | { 93 | // Set axes 94 | this->axes = axes; 95 | } 96 | 97 | 98 | 99 | void R2CoordSystem:: 100 | Translate(const R2Vector& offset) 101 | { 102 | // Translate origin 103 | origin.Translate(offset); 104 | } 105 | 106 | 107 | 108 | void R2CoordSystem:: 109 | Rotate(RNAngle radians) 110 | { 111 | // Rotate axes only 112 | axes.Rotate(radians); 113 | // Normalize to avoid accumulation of error ??? 114 | axes.Normalize(); 115 | } 116 | 117 | 118 | 119 | void R2CoordSystem:: 120 | Mirror (const R2Line& line) 121 | { 122 | // Mirror origin and axes 123 | origin.Mirror(line); 124 | axes.Mirror(line); 125 | } 126 | 127 | 128 | 129 | void R2CoordSystem:: 130 | Transform (const R2Transformation& transformation) 131 | { 132 | // Transform origin and axes 133 | origin.Transform(transformation); 134 | axes.Transform(transformation); 135 | // Normalize to avoid accumulation of error ??? 136 | axes.Normalize(); 137 | } 138 | 139 | 140 | 141 | void R2CoordSystem:: 142 | InverseTransform (const R2Transformation& transformation) 143 | { 144 | // Transform origin and axes 145 | origin.InverseTransform(transformation); 146 | axes.InverseTransform(transformation); 147 | // Normalize to avoid accumulation of error ??? 148 | axes.Normalize(); 149 | } 150 | 151 | 152 | 153 | 154 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Crdsys.h: -------------------------------------------------------------------------------- 1 | /* Include file for the GAPS coordinate system class */ 2 | 3 | 4 | 5 | /* Initialization functions */ 6 | 7 | int R2InitCoordinateSystem(); 8 | void R2StopCoordinateSystem(); 9 | 10 | 11 | 12 | /* Class definition */ 13 | 14 | class R2CoordSystem /* : public R2Base */ { 15 | public: 16 | // Constructor functions 17 | R2CoordSystem(void); 18 | R2CoordSystem(const R2CoordSystem& cs); 19 | R2CoordSystem(const R2Point& origin, const R2Diad& axes); 20 | 21 | // Property functions/operators 22 | const R2Point& Origin(void) const; 23 | const R2Diad& Axes(void) const; 24 | const R3Matrix Matrix(void) const; 25 | const R3Matrix InverseMatrix(void) const; 26 | const RNBoolean operator==(const R2CoordSystem& cs) const; 27 | const RNBoolean operator!=(const R2CoordSystem& cs) const; 28 | 29 | // Manipulation functions/operators 30 | void Translate(const R2Vector& offset); 31 | void Rotate(RNAngle radians); 32 | void Mirror(const R2Line& line); 33 | void Transform(const R2Transformation& transformation); 34 | void InverseTransform(const R2Transformation& transformation); 35 | void SetOrigin(const R2Point& origin); 36 | void SetAxes(const R2Diad& axes); 37 | 38 | // Draw functions/operators 39 | void Draw(void) const; 40 | void Outline(void) const; 41 | 42 | private: 43 | R2Point origin; 44 | R2Diad axes; 45 | }; 46 | 47 | 48 | 49 | /* Public variables */ 50 | 51 | extern const R2CoordSystem R2xy_coordinate_system; 52 | 53 | 54 | 55 | /* Inline functions */ 56 | 57 | inline const R2Point& R2CoordSystem:: 58 | Origin(void) const 59 | { 60 | // Return origin 61 | return origin; 62 | } 63 | 64 | 65 | 66 | inline const R2Diad& R2CoordSystem:: 67 | Axes(void) const 68 | { 69 | // Return axes diad 70 | return axes; 71 | } 72 | 73 | 74 | 75 | inline const RNBoolean R2CoordSystem:: 76 | operator==(const R2CoordSystem& cs) const 77 | { 78 | // Return whether coordinate system is equal 79 | return (origin == cs.origin) && (axes == cs.axes); 80 | } 81 | 82 | 83 | 84 | inline const RNBoolean R2CoordSystem:: 85 | operator!=(const R2CoordSystem& cs) const 86 | { 87 | // Return whether coordinate system is not equal 88 | return !(*this == cs); 89 | } 90 | 91 | 92 | 93 | inline void R2CoordSystem:: 94 | Outline(void) const 95 | { 96 | // Draw coordinate system 97 | Draw(); 98 | } 99 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Curve.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for the R2 curve class */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "R2Shapes/R2Shapes.h" 8 | 9 | 10 | 11 | /* Public functions */ 12 | 13 | int 14 | R2InitCurve() 15 | { 16 | /* Return success */ 17 | return TRUE; 18 | } 19 | 20 | 21 | 22 | void 23 | R2StopCurve() 24 | { 25 | } 26 | 27 | 28 | 29 | R2Curve:: 30 | R2Curve(void) 31 | { 32 | } 33 | 34 | 35 | 36 | R2Curve:: 37 | ~R2Curve(void) 38 | { 39 | } 40 | 41 | 42 | 43 | const RNBoolean R2Curve:: 44 | IsCurve(void) const 45 | { 46 | // All curve shapes are curves 47 | return TRUE; 48 | } 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Curve.h: -------------------------------------------------------------------------------- 1 | /* Include file for the R2 curve class */ 2 | 3 | 4 | 5 | /* Initialization functions */ 6 | 7 | int R2InitCurve(); 8 | void R2StopCurve(); 9 | 10 | 11 | 12 | /* Class definition */ 13 | 14 | class R2Curve : public R2Shape { 15 | public: 16 | // Constructors/destructors ??? 17 | R2Curve(void); 18 | ~R2Curve(void); 19 | 20 | // Shape property functions/operators 21 | const RNBoolean IsCurve(void) const; 22 | 23 | // Curve property functions/operators 24 | // virtual const R2Point Start(void) const = 0; 25 | // virtual const R2Point End(void) const = 0; 26 | }; 27 | 28 | 29 | 30 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Diad.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for the GAPS diad class */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "R2Shapes/R2Shapes.h" 8 | 9 | 10 | 11 | /* Public variables */ 12 | 13 | const R2Diad R2xy_diad(R2Vector(1.0, 0.0), R2Vector(0.0, 1.0)); 14 | 15 | 16 | 17 | /* Public functions */ 18 | 19 | int R2InitDiad() 20 | { 21 | /* Return success */ 22 | return TRUE; 23 | } 24 | 25 | 26 | 27 | void R2StopDiad() 28 | { 29 | } 30 | 31 | 32 | 33 | R2Diad:: 34 | R2Diad(void) 35 | { 36 | } 37 | 38 | 39 | 40 | R2Diad:: 41 | R2Diad(const R2Diad& diad) 42 | { 43 | axis[0] = diad.axis[0]; 44 | axis[1] = diad.axis[1]; 45 | } 46 | 47 | 48 | 49 | R2Diad:: 50 | R2Diad(const R2Vector& xaxis, const R2Vector& yaxis) 51 | { 52 | // Just checking ... 53 | assert(xaxis.IsNormalized()); 54 | assert(yaxis.IsNormalized()); 55 | assert(R2Perpendicular(xaxis, yaxis)); 56 | 57 | // Assign axes 58 | axis[0] = xaxis; 59 | axis[1] = yaxis; 60 | } 61 | 62 | 63 | 64 | const R3Matrix R2Diad:: 65 | Matrix(void) const 66 | { 67 | // Return change of basis matrix (std -> diad) 68 | return R3Matrix(axis[0].X(), axis[1].X(), 0.0, 69 | axis[0].Y(), axis[1].Y(), 0.0, 70 | 0.0, 0.0, 1.0); 71 | } 72 | 73 | 74 | 75 | const R3Matrix R2Diad:: 76 | InverseMatrix(void) const 77 | { 78 | // Return change of basis matrix (diad -> std) 79 | return R3Matrix(axis[0].X(), axis[0].Y(), 0.0, 80 | axis[1].X(), axis[1].Y(), 0.0, 81 | 0.0, 0.0, 1.0); 82 | } 83 | 84 | 85 | 86 | void R2Diad:: 87 | Normalize(void) 88 | { 89 | // Normalize each axis 90 | axis[0].Normalize(); 91 | axis[1].Normalize(); 92 | } 93 | 94 | 95 | 96 | void R2Diad:: 97 | Rotate(RNAngle radians) 98 | { 99 | // Mirror each axis 100 | axis[0].Rotate(radians); 101 | axis[1].Rotate(radians); 102 | } 103 | 104 | 105 | 106 | void R2Diad:: 107 | Mirror(const R2Line& line) 108 | { 109 | // Mirror each axis 110 | axis[0].Mirror(line); 111 | axis[1].Mirror(line); 112 | } 113 | 114 | 115 | 116 | void R2Diad:: 117 | Transform(const R2Transformation& transformation) 118 | { 119 | // Transform each axis 120 | axis[0].Transform(transformation); 121 | axis[1].Transform(transformation); 122 | } 123 | 124 | 125 | 126 | void R2Diad:: 127 | InverseTransform(const R2Transformation& transformation) 128 | { 129 | // Transform each axis 130 | axis[0].InverseTransform(transformation); 131 | axis[1].InverseTransform(transformation); 132 | } 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Diad.h: -------------------------------------------------------------------------------- 1 | /* Include file for the GAPS diad class */ 2 | 3 | 4 | 5 | /* Initialization functions */ 6 | 7 | int R2InitDiad(); 8 | void R2StopDiad(); 9 | 10 | 11 | 12 | /* Class definition */ 13 | 14 | class R2Diad /* : public R2Base */ { 15 | public: 16 | // Constructor functions 17 | R2Diad(void); 18 | R2Diad(const R2Diad& diad); 19 | R2Diad(const R2Vector& xaxis, const R2Vector& yaxis); 20 | 21 | // Property functions/operators 22 | const R3Matrix Matrix(void) const; 23 | const R3Matrix InverseMatrix(void) const; 24 | const R2Vector& Axis(RNDimension dim) const; 25 | const R2Vector& operator[](RNDimension dim) const; 26 | const RNBoolean operator==(const R2Diad& diad) const; 27 | const RNBoolean operator!=(const R2Diad& diad) const; 28 | 29 | // Manipulation functions/operators 30 | void Normalize(void); 31 | void Rotate(RNAngle radians); 32 | void Mirror(const R2Line& line); 33 | void Transform(const R2Transformation& transformation); 34 | void InverseTransform(const R2Transformation& transformation); 35 | R2Diad& operator=(const R2Diad& diad); 36 | 37 | // Draw functions/operators 38 | void Draw(void) const; 39 | void Outline(void) const; 40 | 41 | private: 42 | R2Vector axis[2]; 43 | }; 44 | 45 | 46 | 47 | /* Public variables */ 48 | 49 | extern const R2Diad R2xy_diad; 50 | 51 | 52 | 53 | /* Inline functions */ 54 | 55 | inline const R2Vector& R2Diad:: 56 | Axis(RNDimension dim) const 57 | { 58 | // Return axis vector 59 | assert((dim >= RN_X) && (dim <= RN_Y)); 60 | return axis[dim]; 61 | } 62 | 63 | 64 | 65 | inline const R2Vector& R2Diad:: 66 | operator[](RNDimension dim) const 67 | { 68 | // Return axis vector 69 | return Axis(dim); 70 | } 71 | 72 | 73 | 74 | inline const RNBoolean R2Diad:: 75 | operator==(const R2Diad& diad) const 76 | { 77 | // Return whether diad is equal 78 | // We can check only one of the three since everything is orthonormal 79 | return (axis[0] == diad.axis[0]); 80 | } 81 | 82 | 83 | 84 | inline const RNBoolean R2Diad:: 85 | operator!=(const R2Diad& diad) const 86 | { 87 | // Return whether diad is not equal 88 | return !(*this == diad); 89 | } 90 | 91 | 92 | 93 | inline void R2Diad:: 94 | Outline(void) const 95 | { 96 | // Draw diad 97 | Draw(); 98 | } 99 | 100 | 101 | 102 | inline R2Diad& R2Diad:: 103 | operator=(const R2Diad& diad) 104 | { 105 | axis[0] = diad.axis[0]; 106 | axis[1] = diad.axis[1]; 107 | return *this; 108 | } 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Draw.h: -------------------------------------------------------------------------------- 1 | /* Include file for R2 draw utility */ 2 | 3 | 4 | 5 | inline void 6 | R2LoadPoint(const R2Point& point) 7 | { 8 | // Load vertex 9 | R2LoadPoint(point.Coords()); 10 | } 11 | 12 | 13 | 14 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Halfspace.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for the GAPS halfspace class */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "R2Shapes/R2Shapes.h" 8 | 9 | 10 | 11 | /* Public variables */ 12 | 13 | const R2Halfspace R2null_halfspace(0.0, 0.0, 0.0); 14 | const R2Halfspace R2posx_halfspace(1.0, 0.0, 0.0); 15 | const R2Halfspace R2posy_halfspace(0.0, 1.0, 0.0); 16 | const R2Halfspace R2negx_halfspace(-1.0, 0.0, 0.0); 17 | const R2Halfspace R2negy_halfspace(0.0, -1.0, 0.0); 18 | 19 | 20 | 21 | /* Public functions */ 22 | 23 | int 24 | R2InitHalfspace() 25 | { 26 | /* Return success */ 27 | return TRUE; 28 | } 29 | 30 | 31 | 32 | void 33 | R2StopHalfspace() 34 | { 35 | } 36 | 37 | 38 | 39 | R2Halfspace:: 40 | R2Halfspace (void) 41 | { 42 | } 43 | 44 | 45 | 46 | R2Halfspace:: 47 | R2Halfspace (const R2Halfspace& halfspace) 48 | : line(halfspace.line) 49 | { 50 | } 51 | 52 | 53 | 54 | R2Halfspace:: 55 | R2Halfspace(RNScalar a, RNScalar b, RNScalar c) 56 | : line(a, b, c) 57 | { 58 | } 59 | 60 | 61 | 62 | R2Halfspace:: 63 | R2Halfspace(const RNScalar a[3]) 64 | : line(a) 65 | { 66 | } 67 | 68 | 69 | 70 | R2Halfspace:: 71 | R2Halfspace(const R2Point& point, const R2Vector& normal) 72 | : line(point, R2Vector(-normal.Y(), normal.X())) 73 | { 74 | } 75 | 76 | 77 | 78 | R2Halfspace:: 79 | R2Halfspace(const R2Point& point1, const R2Point& point2) 80 | : line(point1, point2) 81 | { 82 | } 83 | 84 | 85 | 86 | R2Halfspace:: 87 | R2Halfspace(const R2Line& line, int ) 88 | : line(line) 89 | { 90 | } 91 | 92 | 93 | 94 | void R2Halfspace:: 95 | Mirror (const R2Line& line) 96 | { 97 | // Mirror halfspace with respect to line 98 | this->line.Mirror(line); 99 | } 100 | 101 | 102 | 103 | void R2Halfspace:: 104 | Transform (const R2Transformation& transformation) 105 | { 106 | // Transform halfspace 107 | line.Transform(transformation); 108 | } 109 | 110 | 111 | 112 | void R2Halfspace:: 113 | InverseTransform (const R2Transformation& transformation) 114 | { 115 | // Transform halfspace 116 | line.InverseTransform(transformation); 117 | } 118 | 119 | 120 | 121 | 122 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Io.h: -------------------------------------------------------------------------------- 1 | /* Include file for input/output utility */ 2 | 3 | 4 | 5 | /* Function declarations */ 6 | 7 | RNArray *R2ReadSpans(RNArray& spans, const char *filename); 8 | RNArray *R2ReadWiseFile(RNArray& spans, const char *filename); 9 | RNArray *R2ReadXFigFile(RNArray& spans, const char *filename); 10 | 11 | 12 | 13 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Kdtree.h: -------------------------------------------------------------------------------- 1 | // Include file for KDTree class 2 | 3 | #ifndef __R2KDTREE__H__ 4 | #define __R2KDTREE__H__ 5 | 6 | 7 | 8 | // Node declaration 9 | 10 | template 11 | class R2KdtreeNode; 12 | 13 | 14 | 15 | // Class declaration 16 | 17 | template 18 | class R2Kdtree { 19 | public: 20 | // Constructor/destructors 21 | R2Kdtree(const R2Box& bbox, int position_offset = 0); 22 | R2Kdtree(const RNArray& points, int position_offset = 0); 23 | R2Kdtree(const RNArray& points, R2Point (*position_callback)(PtrType, void *), void *data); 24 | ~R2Kdtree(void); 25 | 26 | // Property functions 27 | const R2Box& BBox(void) const; 28 | int NNodes(void) const; 29 | 30 | // Search for closest to a point 31 | PtrType FindClosest(PtrType point, RNLength min_distance = 0, RNLength max_distance = RN_INFINITY, RNLength *closest_distance = NULL) const; 32 | PtrType FindClosest(const R2Point& position, RNLength min_distance = 0, RNLength max_distance = RN_INFINITY, RNLength *closest_distance = NULL) const; 33 | 34 | // Search for all within some distance to a point 35 | int FindAll(PtrType point, RNLength min_distance, RNLength max_distance, RNArray& points) const; 36 | int FindAll(const R2Point& position, RNLength min_distance, RNLength max_distance, RNArray& points) const; 37 | 38 | public: 39 | // Internal search functions 40 | void FindClosest(R2KdtreeNode *node, const R2Box& node_box, const R2Point& position, 41 | RNLength min_distance_squared, RNLength max_distance_squared, 42 | PtrType& closest_point, RNLength& closest_distance_squared) const; 43 | void FindAll(R2KdtreeNode *node, const R2Box& node_box, const R2Point& position, 44 | RNLength min_distance_squared, RNLength max_distance_squared, RNArray& points) const; 45 | 46 | // Internal manipulation functions 47 | void InsertPoints(R2KdtreeNode *node, const R2Box& node_box, PtrType *points, int npoints); 48 | int PartitionPoints(PtrType *points, int npoints, RNDimension dim, int imin, int imax); 49 | 50 | // Internal visualization functions 51 | void Outline(R2KdtreeNode *node, const R2Box& bbox) const; 52 | void Outline(void) const; 53 | 54 | // Internal debugging functions 55 | void PrintDebugInfo(void) const; 56 | int PrintBalance(R2KdtreeNode *node, int depth) const; 57 | 58 | // Internal point extraction function 59 | const R2Point Position(PtrType point) const { 60 | if (position_offset >= 0) return *((R2Point *) ((unsigned char *) point + position_offset)); 61 | else if (position_callback) return (*position_callback)(point, position_callback_data); 62 | else { fprintf(stderr, "Invalid position callback\n"); abort(); return R2null_point; } 63 | } ; 64 | 65 | public: 66 | // Internal data 67 | R2Box bbox; 68 | int position_offset; 69 | R2Point (*position_callback)(PtrType, void *); 70 | void *position_callback_data; 71 | R2KdtreeNode *root; 72 | int nnodes; 73 | }; 74 | 75 | 76 | 77 | // Include templated definitions 78 | 79 | #include "R2Kdtree.cpp" 80 | 81 | 82 | #endif 83 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Parall.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for GAPS parallel utility */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "R2Shapes/R2Shapes.h" 8 | 9 | 10 | 11 | RNBoolean R2Parallel(const R2Vector& vector1, const R2Vector& vector2) 12 | { 13 | // Return whether two vectors are coincident (or anti-coincident) 14 | if ((RNIsEqual(vector1.X(), vector2.X())) && 15 | (RNIsEqual(vector1.Y(), vector2.Y()))) return TRUE; 16 | if ((RNIsEqual(vector1.X(), -vector2.X())) && 17 | (RNIsEqual(vector1.Y(), -vector2.Y()))) return TRUE; 18 | return FALSE; 19 | } 20 | 21 | 22 | 23 | RNBoolean R2Parallel(const R2Vector& vector, const R2Line& line) 24 | { 25 | // Return whether vector and line are parallel 26 | return R2Parallel(vector, line.Vector()); 27 | } 28 | 29 | 30 | 31 | RNBoolean R2Parallel(const R2Vector& vector, const R2Ray& ray) 32 | { 33 | // Return whether vector and ray are parallel 34 | return R2Parallel(vector, ray.Vector()); 35 | } 36 | 37 | 38 | 39 | RNBoolean R2Parallel(const R2Vector& vector, const R2Span& span) 40 | { 41 | // Return whether vector and span are parallel 42 | return R2Parallel(vector, span.Vector()); 43 | } 44 | 45 | 46 | 47 | RNBoolean R2Parallel(const R2Line& line1, const R2Line& line2) 48 | { 49 | // Return whether line1 and line2 are parallel 50 | return R2Parallel(line1.Vector(), line2.Vector()); 51 | } 52 | 53 | 54 | 55 | RNBoolean R2Parallel(const R2Line& line, const R2Ray& ray) 56 | { 57 | // Return whether line and ray are parallel 58 | return R2Parallel(line.Vector(), ray.Vector()); 59 | } 60 | 61 | 62 | 63 | RNBoolean R2Parallel(const R2Line& line, const R2Span& span) 64 | { 65 | // Return whether line and span are parallel 66 | return R2Parallel(line.Vector(), span.Vector()); 67 | } 68 | 69 | 70 | 71 | RNBoolean R2Parallel(const R2Ray& ray1, const R2Ray& ray2) 72 | { 73 | // Return whether ray1 and ray2 are parallel 74 | return R2Parallel(ray1.Vector(), ray2.Vector()); 75 | } 76 | 77 | 78 | 79 | RNBoolean R2Parallel(const R2Ray& ray, const R2Span& span) 80 | { 81 | // Return whether ray and span are parallel 82 | return R2Parallel(ray.Vector(), span.Vector()); 83 | } 84 | 85 | 86 | 87 | RNBoolean R2Parallel(const R2Span& span1, const R2Span& span2) 88 | { 89 | // Return whether span1 and span2 are parallel 90 | return R2Parallel(span1.Vector(), span2.Vector()); 91 | } 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Parall.h: -------------------------------------------------------------------------------- 1 | /* Include file for GAPS parallel utility */ 2 | 3 | 4 | 5 | /* Function declarations */ 6 | 7 | RNBoolean R2Parallel(const R2Vector& vector1, const R2Vector& vector2); 8 | RNBoolean R2Parallel(const R2Vector& vector, const R2Line& line); 9 | RNBoolean R2Parallel(const R2Vector& vector, const R2Ray& ray); 10 | RNBoolean R2Parallel(const R2Vector& vector, const R2Span& span); 11 | 12 | RNBoolean R2Parallel(const R2Line& line, const R2Vector& vector); 13 | RNBoolean R2Parallel(const R2Line& line1, const R2Line& line2); 14 | RNBoolean R2Parallel(const R2Line& line, const R2Ray& ray); 15 | RNBoolean R2Parallel(const R2Line& line, const R2Span& span); 16 | 17 | RNBoolean R2Parallel(const R2Ray& ray, const R2Vector& vector); 18 | RNBoolean R2Parallel(const R2Ray& ray, const R2Line& line); 19 | RNBoolean R2Parallel(const R2Ray& ray1, const R2Ray& ray2); 20 | RNBoolean R2Parallel(const R2Ray& ray, const R2Span& span); 21 | 22 | RNBoolean R2Parallel(const R2Span& span, const R2Vector& vector); 23 | RNBoolean R2Parallel(const R2Span& span, const R2Line& line); 24 | RNBoolean R2Parallel(const R2Span& span, const R2Ray& ray); 25 | RNBoolean R2Parallel(const R2Span& span1, const R2Span& span2); 26 | 27 | 28 | 29 | /* Inline functions */ 30 | 31 | inline RNBoolean R2Parallel(const R2Line& line, const R2Vector& vector) 32 | { 33 | // Parallel is commutative 34 | return R2Parallel(vector, line); 35 | } 36 | 37 | 38 | 39 | inline RNBoolean R2Parallel(const R2Ray& ray, const R2Vector& vector) 40 | { 41 | // Parallel is commutative 42 | return R2Parallel(vector, ray); 43 | } 44 | 45 | 46 | 47 | inline RNBoolean R2Parallel(const R2Ray& ray, const R2Line& line) 48 | { 49 | // Parallel is commutative 50 | return R2Parallel(line, ray); 51 | } 52 | 53 | 54 | 55 | inline RNBoolean R2Parallel(const R2Span& span, const R2Vector& vector) 56 | { 57 | // Parallel is commutative 58 | return R2Parallel(vector, span); 59 | } 60 | 61 | 62 | 63 | inline RNBoolean R2Parallel(const R2Span& span, const R2Line& line) 64 | { 65 | // Parallel is commutative 66 | return R2Parallel(line, span); 67 | } 68 | 69 | 70 | 71 | inline RNBoolean R2Parallel(const R2Span& span, const R2Ray& ray) 72 | { 73 | // Parallel is commutative 74 | return R2Parallel(ray, span); 75 | } 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Perp.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for GAPS perpendicular utility */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "R2Shapes/R2Shapes.h" 8 | 9 | 10 | 11 | RNBoolean R2Perpendicular(const R2Vector& vector1, const R2Vector& vector2) 12 | { 13 | // Normalized vectors ??? 14 | // Return whether vector1 and vector2 are perpendicular 15 | return RNIsZero(vector1.Dot(vector2)); 16 | } 17 | 18 | 19 | 20 | RNBoolean R2Perpendicular(const R2Vector& vector, const R2Line& line) 21 | { 22 | // Return whether vector and line are perpendicular 23 | return R2Perpendicular(vector, line.Vector()); 24 | } 25 | 26 | 27 | 28 | RNBoolean R2Perpendicular(const R2Vector& vector, const R2Ray& ray) 29 | { 30 | // Return whether vector and ray are perpendicular 31 | return R2Perpendicular(vector, ray.Vector()); 32 | } 33 | 34 | 35 | 36 | RNBoolean R2Perpendicular(const R2Vector& vector, const R2Span& span) 37 | { 38 | // Return whether vector and span are perpendicular 39 | return R2Perpendicular(vector, span.Vector()); 40 | } 41 | 42 | 43 | 44 | RNBoolean R2Perpendicular(const R2Line& line1, const R2Line& line2) 45 | { 46 | // Return whether line1 and line2 are perpendicular 47 | return R2Perpendicular(line1.Vector(), line2.Vector()); 48 | } 49 | 50 | 51 | 52 | RNBoolean R2Perpendicular(const R2Line& line, const R2Ray& ray) 53 | { 54 | // Return whether line and ray are perpendicular 55 | return R2Perpendicular(line.Vector(), ray.Vector()); 56 | } 57 | 58 | 59 | 60 | RNBoolean R2Perpendicular(const R2Line& line, const R2Span& span) 61 | { 62 | // Return whether line and span are perpendicular 63 | return R2Perpendicular(line.Vector(), span.Vector()); 64 | } 65 | 66 | 67 | 68 | RNBoolean R2Perpendicular(const R2Ray& ray1, const R2Ray& ray2) 69 | { 70 | // Return whether ray1 and ray2 are perpendicular 71 | return R2Perpendicular(ray1.Vector(), ray2.Vector()); 72 | } 73 | 74 | 75 | 76 | RNBoolean R2Perpendicular(const R2Ray& ray, const R2Span& span) 77 | { 78 | // Return whether ray and span are perpendicular 79 | return R2Perpendicular(ray.Vector(), span.Vector()); 80 | } 81 | 82 | 83 | 84 | RNBoolean R2Perpendicular(const R2Span& span1, const R2Span& span2) 85 | { 86 | // Return whether span1 and span2 are perpendicular 87 | return R2Perpendicular(span1.Vector(), span2.Vector()); 88 | } 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Perp.h: -------------------------------------------------------------------------------- 1 | /* Include file for GAPS perpendicular utility */ 2 | 3 | 4 | 5 | /* Function declarations */ 6 | 7 | RNBoolean R2Perpendicular(const R2Vector& vector1, const R2Vector& vector2); 8 | RNBoolean R2Perpendicular(const R2Vector& vector, const R2Line& line); 9 | RNBoolean R2Perpendicular(const R2Vector& vector, const R2Ray& ray); 10 | RNBoolean R2Perpendicular(const R2Vector& vector, const R2Span& span); 11 | 12 | RNBoolean R2Perpendicular(const R2Line& line, const R2Vector& vector); 13 | RNBoolean R2Perpendicular(const R2Line& line1, const R2Line& line2); 14 | RNBoolean R2Perpendicular(const R2Line& line, const R2Ray& ray); 15 | RNBoolean R2Perpendicular(const R2Line& line, const R2Span& span); 16 | 17 | RNBoolean R2Perpendicular(const R2Ray& ray, const R2Vector& vector); 18 | RNBoolean R2Perpendicular(const R2Ray& ray, const R2Line& line); 19 | RNBoolean R2Perpendicular(const R2Ray& ray1, const R2Ray& ray2); 20 | RNBoolean R2Perpendicular(const R2Ray& ray, const R2Span& span); 21 | 22 | RNBoolean R2Perpendicular(const R2Span& span, const R2Vector& vector); 23 | RNBoolean R2Perpendicular(const R2Span& span, const R2Line& line); 24 | RNBoolean R2Perpendicular(const R2Span& span, const R2Ray& ray); 25 | RNBoolean R2Perpendicular(const R2Span& span1, const R2Span& span2); 26 | 27 | 28 | 29 | /* Inline functions */ 30 | 31 | inline RNBoolean R2Perpendicular(const R2Line& line, const R2Vector& vector) 32 | { 33 | // Perpendicular is commutative 34 | return R2Perpendicular(vector, line); 35 | } 36 | 37 | 38 | 39 | inline RNBoolean R2Perpendicular(const R2Ray& ray, const R2Vector& vector) 40 | { 41 | // Perpendicular is commutative 42 | return R2Perpendicular(vector, ray); 43 | } 44 | 45 | 46 | 47 | inline RNBoolean R2Perpendicular(const R2Ray& ray, const R2Line& line) 48 | { 49 | // Perpendicular is commutative 50 | return R2Perpendicular(line, ray); 51 | } 52 | 53 | 54 | 55 | inline RNBoolean R2Perpendicular(const R2Span& span, const R2Vector& vector) 56 | { 57 | // Perpendicular is commutative 58 | return R2Perpendicular(vector, span); 59 | } 60 | 61 | 62 | 63 | inline RNBoolean R2Perpendicular(const R2Span& span, const R2Line& line) 64 | { 65 | // Perpendicular is commutative 66 | return R2Perpendicular(line, span); 67 | } 68 | 69 | 70 | 71 | inline RNBoolean R2Perpendicular(const R2Span& span, const R2Ray& ray) 72 | { 73 | // Perpendicular is commutative 74 | return R2Perpendicular(ray, span); 75 | } 76 | 77 | 78 | 79 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Polyline.h: -------------------------------------------------------------------------------- 1 | /* Include file for the R2 polyline class */ 2 | 3 | 4 | 5 | /* Initialization functions */ 6 | 7 | int R2InitPolyline(); 8 | void R2StopPolyline(); 9 | 10 | 11 | 12 | /* Class definition */ 13 | 14 | class R2Polyline : public R2Curve { 15 | public: 16 | // Constructor functions 17 | R2Polyline(void); 18 | R2Polyline(const R2Polyline& polyline); 19 | R2Polyline(const RNArray& points); 20 | R2Polyline(const R2Point *points, int npoints); 21 | ~R2Polyline(void); 22 | 23 | // Polyline property functions/operators 24 | const int NPoints(void) const; 25 | const R2Point& Point(int k) const; 26 | const RNBoolean IsEmpty(void) const; 27 | const RNBoolean IsFinite(void) const; 28 | const R2Point& operator[](int k) const; 29 | const R2Point ClosestPoint(const R2Point& point) const; 30 | 31 | // Shape property functions/operators 32 | virtual const RNBoolean IsPoint(void) const; 33 | virtual const RNBoolean IsLinear(void) const ; 34 | virtual const RNLength Length(void) const; 35 | virtual const R2Point Centroid(void) const; 36 | virtual const R2Shape& BShape(void) const; 37 | virtual const R2Box BBox(void) const; 38 | virtual const R2Circle BCircle(void) const; 39 | 40 | // Point properties 41 | R2Vector Normal(int k, RNLength radius = 0) const; 42 | R2Line Tangent(int k, RNLength radius = 0) const; 43 | RNAngle InteriorAngle(int k, RNLength radius = 0) const; 44 | RNScalar Curvature(int k, RNLength radius = 0) const; 45 | 46 | // Manipulation functions/operators 47 | virtual void Empty(void); 48 | virtual void Transform(const R2Transformation& transformation); 49 | 50 | // Draw functions/operators 51 | virtual void Draw(const R2DrawFlags draw_flags = R2_DEFAULT_DRAW_FLAGS) const; 52 | virtual void Print(FILE *fp = stdout) const; 53 | 54 | private: 55 | R2Point *points; 56 | int npoints; 57 | R2Box bbox; 58 | }; 59 | 60 | 61 | 62 | /* Inline functions */ 63 | 64 | inline const int R2Polyline:: 65 | NPoints(void) const 66 | { 67 | // Return number of points 68 | return npoints; 69 | } 70 | 71 | 72 | 73 | inline const R2Point& R2Polyline:: 74 | Point(int k) const 75 | { 76 | // Return Kth point 77 | return points[k]; 78 | } 79 | 80 | 81 | 82 | inline const RNBoolean R2Polyline:: 83 | IsEmpty(void) const 84 | { 85 | // Return whether the polyline is null 86 | return (npoints == 0); 87 | } 88 | 89 | 90 | 91 | inline const RNBoolean R2Polyline:: 92 | IsFinite(void) const 93 | { 94 | // Return whether the polyline has finite extent 95 | return bbox.IsFinite(); 96 | } 97 | 98 | 99 | 100 | 101 | inline const R2Point& R2Polyline:: 102 | operator[](int k) const 103 | { 104 | // Return Kth point 105 | return Point(k); 106 | } 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Ray.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for the GAPS ray class */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "R2Shapes/R2Shapes.h" 8 | 9 | 10 | 11 | /* Public variables */ 12 | 13 | const R2Ray R2null_ray(0.0, 0.0, 0.0, 0.0); 14 | const R2Ray R2posx_ray(0.0, 0.0, 1.0, 0.0); 15 | const R2Ray R2posy_ray(0.0, 0.0, 0.0, 1.0); 16 | const R2Ray R2negx_ray(0.0, 0.0, -1.0, 0.0); 17 | const R2Ray R2negy_ray(0.0, 0.0, 0.0, -1.0); 18 | 19 | 20 | 21 | /* Public functions */ 22 | 23 | int R2InitRay() 24 | { 25 | /* Return success */ 26 | return TRUE; 27 | } 28 | 29 | 30 | 31 | void R2StopRay() 32 | { 33 | } 34 | 35 | 36 | 37 | R2Ray:: 38 | R2Ray(void) 39 | { 40 | } 41 | 42 | 43 | 44 | R2Ray:: 45 | R2Ray(const R2Ray& ray) 46 | : line(ray.line), 47 | start(ray.start) 48 | { 49 | } 50 | 51 | 52 | 53 | R2Ray:: 54 | R2Ray(const R2Point& point, const R2Vector& vector, RNBoolean normalized) 55 | : line(point, vector, normalized), 56 | start(point) 57 | { 58 | } 59 | 60 | 61 | 62 | R2Ray:: 63 | R2Ray(const R2Point& point1, const R2Point& point2) 64 | : line(point1, point2), 65 | start(point1) 66 | { 67 | } 68 | 69 | 70 | 71 | R2Ray:: 72 | R2Ray(RNCoord x1, RNCoord y1, RNCoord x2, RNCoord y2) 73 | : line(x1, y1, x2, y2), 74 | start(x1, y1) 75 | { 76 | } 77 | 78 | 79 | 80 | const R2Point R2Ray:: 81 | Point(RNScalar t) const 82 | { 83 | // Return point along span 84 | return (Start() + Vector() * t); 85 | } 86 | 87 | 88 | 89 | const RNScalar R2Ray:: 90 | T(const R2Point& point) const 91 | { 92 | // Return parametric value of closest point on ray 93 | RNScalar denom = Vector().Dot(Vector()); 94 | if (RNIsZero(denom)) return 0.0; 95 | R2Vector topoint = point - Start(); 96 | return (Vector().Dot(topoint) / denom); 97 | } 98 | 99 | 100 | 101 | void R2Ray:: 102 | Mirror (const R2Line& mirror) 103 | { 104 | // Mirror ray across line 105 | line.Mirror(mirror); 106 | start.Mirror(mirror); 107 | } 108 | 109 | 110 | 111 | void R2Ray:: 112 | Project (const R2Line& target) 113 | { 114 | // Project ray onto target line 115 | line.Project(target); 116 | start.Project(target); 117 | } 118 | 119 | 120 | 121 | void R2Ray:: 122 | Transform (const R2Transformation& transformation) 123 | { 124 | // Transform line and point 125 | line.Transform(transformation); 126 | start.Transform(transformation); 127 | } 128 | 129 | 130 | 131 | void R2Ray:: 132 | InverseTransform (const R2Transformation& transformation) 133 | { 134 | // Transform line and point 135 | line.InverseTransform(transformation); 136 | start.InverseTransform(transformation); 137 | } 138 | 139 | 140 | 141 | 142 | 143 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Relate.h: -------------------------------------------------------------------------------- 1 | /* Include file for R2 miscelleaneous relationship utility */ 2 | 3 | 4 | 5 | /* Miscellaneous relationship function declarations */ 6 | 7 | RNAngle R2InteriorAngle(const R2Vector& vector1, const R2Vector& vector2); 8 | RNAngle R2InteriorAngle(const R2Vector& vector, const R2Line& line); 9 | RNAngle R2InteriorAngle(const R2Vector& vector, const R2Ray& ray); 10 | RNAngle R2InteriorAngle(const R2Vector& vector, const R2Span& span); 11 | 12 | RNArea R2IntersectionArea(const R2Box& box1, const R2Box& box2); 13 | RNArea R2IntersectionArea(const R2Circle& circle1, const R2Circle& circle2); 14 | 15 | RNBoolean R2Abuts(const R2Box& box1, const R2Box& box2); 16 | 17 | int R2Splits(const R2Line& line, const R2Span& span); 18 | int R2Splits(const R2Line& line, const R2Span& span, R2Span *below_result, R2Span *above_result = NULL); 19 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Shape.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for the R2 shape class */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "R2Shapes/R2Shapes.h" 8 | 9 | 10 | 11 | /* Public draw flags */ 12 | 13 | const R2DrawFlags R2_EDGES_DRAW_FLAG (0x001); 14 | const R2DrawFlags R2_SURFACES_DRAW_FLAG (0x002); 15 | const R2DrawFlags R2_NULL_DRAW_FLAGS (0x000); 16 | const R2DrawFlags R2_EVERYTHING_DRAW_FLAGS (0xFFF); 17 | const R2DrawFlags R2_DEFAULT_DRAW_FLAGS (R2_EVERYTHING_DRAW_FLAGS); 18 | 19 | 20 | 21 | /* Public functions */ 22 | 23 | int 24 | R2InitShape() 25 | { 26 | /* Return success */ 27 | return TRUE; 28 | } 29 | 30 | 31 | 32 | void 33 | R2StopShape() 34 | { 35 | } 36 | 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Shape.h: -------------------------------------------------------------------------------- 1 | /* Include file for the R2 shape class */ 2 | 3 | 4 | 5 | /* Initialization functions */ 6 | 7 | int R2InitShape(); 8 | void R2StopShape(); 9 | 10 | 11 | 12 | /* Draw flags definition */ 13 | 14 | typedef RNFlags R2DrawFlags; 15 | extern const R2DrawFlags R2_EDGES_DRAW_FLAG; 16 | extern const R2DrawFlags R2_SURFACES_DRAW_FLAG; 17 | extern const R2DrawFlags R2_NULL_DRAW_FLAGS; 18 | extern const R2DrawFlags R2_EVERYTHING_DRAW_FLAGS; 19 | extern const R2DrawFlags R2_DEFAULT_DRAW_FLAGS; 20 | 21 | 22 | 23 | /* Class definition */ 24 | 25 | class R2Shape /* : public R2Base */ { 26 | public: 27 | // Constructors/destructors 28 | virtual ~R2Shape(void) {}; 29 | 30 | // Draw functions/operators 31 | virtual void Draw(const R2DrawFlags draw_flags = R2_DEFAULT_DRAW_FLAGS) const = 0; 32 | void Outline(void) const { Draw(R2_EDGES_DRAW_FLAG); }; 33 | }; 34 | 35 | 36 | 37 | /* Shape type enumeration ??? */ 38 | 39 | enum { 40 | R2_POINT_CLASS_ID = 1, 41 | R2_LINE_CLASS_ID = 2, 42 | R2_RAY_CLASS_ID = 3, 43 | R2_SPAN_CLASS_ID = 4, 44 | R2_POLYGON_CLASS_ID = 6 45 | }; 46 | 47 | 48 | 49 | 50 | 51 | 52 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Shapes.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for GAPS shapes module */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "R2Shapes.h" 8 | 9 | 10 | 11 | /* Private variables */ 12 | 13 | static int R2shapes_active_count = 0; 14 | 15 | 16 | 17 | int R2InitShapes(void) 18 | { 19 | // Check whether are already initialized 20 | if ((R2shapes_active_count++) > 0) return TRUE; 21 | 22 | // Initialize dependencies 23 | if (!RNInitBasics()) return FALSE; 24 | 25 | // Initialize submodules 26 | if (!R2InitCircle()) return FALSE; 27 | 28 | // return OK status 29 | return TRUE; 30 | } 31 | 32 | 33 | 34 | void R2StopShapes(void) 35 | { 36 | // Check whether have been initialized 37 | if ((--R2shapes_active_count) > 0) return; 38 | 39 | // Stop submodules 40 | R2StopCircle(); 41 | 42 | // Stop dependencies 43 | RNStopBasics(); 44 | } 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Shapes.h: -------------------------------------------------------------------------------- 1 | /* Include file for R2 shapes module */ 2 | 3 | #ifndef __R2__SHAPES__H__ 4 | #define __R2__SHAPES__H__ 5 | 6 | 7 | 8 | /* Dependency include files */ 9 | 10 | #include "RNBasics/RNBasics.h" 11 | 12 | 13 | 14 | /* Class declarations */ 15 | 16 | class R2Vector; 17 | class R2Point; 18 | class R2Line; 19 | class R2Ray; 20 | class R2Span; 21 | class R2Halfspace; 22 | class R3Matrix; 23 | class R2Diad; 24 | class R2CoordSystem; 25 | class R2Transformation; 26 | class R2Affine; 27 | class R2Arc; 28 | class R2Polyline; 29 | class R2Box; 30 | class R2Circle; 31 | class R2Polygon; 32 | class R2Grid; 33 | 34 | 35 | 36 | /* Image include files */ 37 | 38 | #include "R2Shapes/R2Image.h" 39 | 40 | 41 | 42 | /* Primitive shape include files */ 43 | 44 | #include "R2Shapes/R2Vector.h" 45 | #include "R2Shapes/R2Point.h" 46 | #include "R2Shapes/R2Line.h" 47 | #include "R2Shapes/R2Ray.h" 48 | #include "R2Shapes/R2Span.h" 49 | #include "R2Shapes/R2Halfspace.h" 50 | 51 | 52 | 53 | /* Transformation include files */ 54 | 55 | #include "R2Shapes/R3Matrix.h" 56 | #include "R2Shapes/R2Diad.h" 57 | #include "R2Shapes/R2Crdsys.h" 58 | #include "R2Shapes/R2Xform.h" 59 | #include "R2Shapes/R2Affine.h" 60 | 61 | 62 | 63 | /* Abstract shape include file */ 64 | 65 | #include "R2Shapes/R2Shape.h" 66 | 67 | 68 | 69 | /* Solid shapes include files */ 70 | 71 | #include "R2Shapes/R2Solid.h" 72 | #include "R2Shapes/R2Box.h" 73 | #include "R2Shapes/R2Circle.h" 74 | #include "R2Shapes/R2Polygon.h" 75 | 76 | 77 | 78 | /* Curve shapes include files */ 79 | 80 | #include "R2Shapes/R2Curve.h" 81 | #include "R2Shapes/R2Arc.h" 82 | #include "R2Shapes/R2Polyline.h" 83 | 84 | 85 | 86 | /* Solid shapes include files */ 87 | 88 | #include "R2Shapes/R2Grid.h" 89 | 90 | 91 | 92 | /* Shape relationship include files */ 93 | 94 | #include "R2Shapes/R2Perp.h" 95 | #include "R2Shapes/R2Parall.h" 96 | #include "R2Shapes/R2Dist.h" 97 | #include "R2Shapes/R2Cont.h" 98 | #include "R2Shapes/R2Isect.h" 99 | #include "R2Shapes/R2Relate.h" 100 | #include "R2Shapes/R2Align.h" 101 | 102 | 103 | 104 | /* Closest point search include files */ 105 | 106 | #include "R2Shapes/R2Kdtree.h" 107 | 108 | 109 | 110 | /* Shape utility include files */ 111 | 112 | #include "R2Shapes/R2Draw.h" 113 | #include "R2Shapes/R2Io.h" 114 | 115 | 116 | 117 | /* Initialization functions */ 118 | 119 | int R2InitShapes(void); 120 | void R2StopShapes(void); 121 | 122 | 123 | 124 | #endif 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Solid.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for the R2 solid class */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "R2Shapes/R2Shapes.h" 8 | 9 | 10 | 11 | /* Public functions */ 12 | 13 | int 14 | R2InitSolid() 15 | { 16 | /* Return success */ 17 | return TRUE; 18 | } 19 | 20 | 21 | 22 | void 23 | R2StopSolid() 24 | { 25 | } 26 | 27 | 28 | 29 | R2Solid:: 30 | R2Solid(void) 31 | { 32 | } 33 | 34 | 35 | 36 | R2Solid:: 37 | ~R2Solid(void) 38 | { 39 | } 40 | 41 | 42 | 43 | const RNBoolean R2Solid:: 44 | IsSolid(void) const 45 | { 46 | // All solid shapes are solids 47 | return TRUE; 48 | } 49 | 50 | 51 | 52 | 53 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Solid.h: -------------------------------------------------------------------------------- 1 | /* Include file for the R2 solid class */ 2 | 3 | 4 | 5 | /* Initialization functions */ 6 | 7 | int R2InitSolid(); 8 | void R2StopSolid(); 9 | 10 | 11 | 12 | /* Class definition */ 13 | 14 | class R2Solid : public R2Shape { 15 | public: 16 | // Constructors/destructors ??? 17 | R2Solid(void); 18 | ~R2Solid(void); 19 | 20 | // Shape property functions/operators 21 | const RNBoolean IsSolid(void) const; 22 | }; 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Xform.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for the R2 transformation class */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "R2Shapes/R2Shapes.h" 8 | 9 | 10 | 11 | /* Public functions */ 12 | 13 | int 14 | R2InitTransformation() 15 | { 16 | /* Return success */ 17 | return TRUE; 18 | } 19 | 20 | 21 | 22 | void 23 | R2StopTransformation() 24 | { 25 | } 26 | 27 | 28 | 29 | R2Transformation:: 30 | ~R2Transformation(void) 31 | { 32 | } 33 | 34 | 35 | 36 | const RNBoolean R2Transformation:: 37 | IsMirrored(void) const 38 | { 39 | // Return whether transformation is mirrored (default is FALSE) 40 | return FALSE; 41 | } 42 | 43 | 44 | 45 | const RNBoolean R2Transformation:: 46 | IsLinear(void) const 47 | { 48 | // Return whether transformation is linear (default is FALSE) 49 | return FALSE; 50 | } 51 | 52 | 53 | 54 | const RNBoolean R2Transformation:: 55 | IsAffine(void) const 56 | { 57 | // Return whether transformation is affine (default is FALSE) 58 | return FALSE; 59 | } 60 | 61 | 62 | 63 | const RNBoolean R2Transformation:: 64 | IsIsotropic(void) const 65 | { 66 | // Return whether transformation is isotropic (default is FALSE) 67 | return FALSE; 68 | } 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /gaps/pkgs/R2Shapes/R2Xform.h: -------------------------------------------------------------------------------- 1 | /* Include file for the R2 transformation class */ 2 | 3 | 4 | 5 | /* Initialization functions */ 6 | 7 | int R2InitTransformation(); 8 | void R2StopTransformation(); 9 | 10 | 11 | 12 | /* Class definition */ 13 | 14 | class R2Transformation /* : public R2Base */ { 15 | public: 16 | // Destructor function 17 | virtual ~R2Transformation(void); 18 | 19 | // Property functions/operators 20 | virtual const RNBoolean IsMirrored(void) const; 21 | virtual const RNBoolean IsLinear(void) const; 22 | virtual const RNBoolean IsAffine(void) const; 23 | virtual const RNBoolean IsIsotropic(void) const; 24 | 25 | // Application functions/operators 26 | virtual void Apply(R2Vector& vector) const = 0; 27 | virtual void Apply(R2Point& point) const = 0; 28 | virtual void Apply(R2Transformation& transformation) const = 0; 29 | virtual void Apply(R2Affine& affine) const = 0; 30 | virtual void ApplyInverse(R2Vector& vector) const = 0; 31 | virtual void ApplyInverse(R2Point& point) const = 0; 32 | virtual void ApplyInverse(R2Transformation& transformation) const = 0; 33 | virtual void ApplyInverse(R2Affine& affine) const = 0; 34 | 35 | // Manipulation functions/operators 36 | virtual void Reset(const R2Transformation& transformation) = 0; 37 | virtual void Transform(const R2Transformation& transformation) = 0; 38 | virtual void InverseTransform(const R2Transformation& transformation) = 0; 39 | 40 | // Draw functions/operators 41 | virtual void Load(void) const = 0; 42 | virtual void Draw(void) const = 0; 43 | virtual void Push(void) const = 0; 44 | virtual void Pop(void) const = 0; 45 | }; 46 | 47 | 48 | 49 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Package name 3 | # 4 | 5 | NAME=RNBasics 6 | 7 | 8 | 9 | # 10 | # List of source files 11 | # 12 | 13 | CCSRCS=$(NAME).cpp \ 14 | RNTime.cpp \ 15 | RNGrfx.cpp RNRgb.cpp \ 16 | RNMap.cpp RNHeap.cpp RNQueue.cpp RNArray.cpp \ 17 | RNSvd.cpp RNIntval.cpp RNScalar.cpp \ 18 | RNType.cpp \ 19 | RNFlags.cpp \ 20 | RNFile.cpp RNMem.cpp \ 21 | RNError.cpp \ 22 | RNBase.cpp \ 23 | json.cpp 24 | 25 | 26 | 27 | # 28 | # PKG makefile 29 | # 30 | 31 | include ../../makefiles/Makefile.pkgs 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNBase.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for GAPS base class */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "RNBasics.h" 8 | 9 | 10 | 11 | /* Global variables */ 12 | 13 | RNMark RNmark = 1; 14 | 15 | 16 | 17 | int RNInitBase() 18 | { 19 | /* Return OK status */ 20 | return TRUE; 21 | } 22 | 23 | 24 | 25 | void RNStopBase() 26 | { 27 | } 28 | 29 | 30 | 31 | void RNBreakDebug(void) 32 | { 33 | } 34 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNBase.h: -------------------------------------------------------------------------------- 1 | /* Include file for GAPS basics */ 2 | 3 | 4 | 5 | /* Initialization functions */ 6 | 7 | int RNInitBase(); 8 | void RNStopBase(); 9 | 10 | 11 | 12 | /* Class definition */ 13 | 14 | class RNBase {}; 15 | 16 | 17 | 18 | /* TRUE/FALSE constant definitions */ 19 | 20 | typedef int RNBoolean; 21 | #ifndef TRUE 22 | #define TRUE 1 23 | #endif 24 | #ifndef FALSE 25 | #define FALSE 0 26 | #endif 27 | 28 | 29 | 30 | /* Programming convenience macros */ 31 | 32 | #define brcase break; case 33 | 34 | 35 | 36 | /* Standard types */ 37 | 38 | typedef int RNMark; 39 | 40 | 41 | 42 | /* Global variables */ 43 | 44 | extern RNMark RNmark; 45 | 46 | 47 | 48 | /* Useful functions */ 49 | 50 | extern void RNBreakDebug(void); 51 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNBasics.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for GAPS basics module */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "RNBasics.h" 8 | 9 | 10 | 11 | /* Private variables */ 12 | 13 | static int RNbasics_active_count = 0; 14 | 15 | 16 | 17 | int RNInitBasics(void) 18 | { 19 | // Check whether are already initialized 20 | if ((RNbasics_active_count++) > 0) return TRUE; 21 | 22 | // Initialize submodules 23 | RNSeedRandomScalar(); 24 | 25 | // Return OK status 26 | return TRUE; 27 | } 28 | 29 | 30 | 31 | void RNStopBasics(void) 32 | { 33 | // Check whether have been initialized 34 | if ((--RNbasics_active_count) > 0) return; 35 | 36 | // Stop submodules 37 | // ??? 38 | } 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNBasics.h: -------------------------------------------------------------------------------- 1 | /* Include file for GAPS basics module */ 2 | 3 | #ifndef __RN__BASICS__H__ 4 | #define __RN__BASICS__H__ 5 | 6 | 7 | 8 | /* Compatability switch include files */ 9 | 10 | #include "RNBasics/RNCompat.h" 11 | 12 | 13 | 14 | /* External include files */ 15 | 16 | #include "RNBasics/RNExtern.h" 17 | 18 | 19 | 20 | /* Base class for GAPS modules */ 21 | 22 | #include "RNBasics/RNBase.h" 23 | 24 | 25 | 26 | /* Error reporting include files */ 27 | 28 | #include "RNBasics/RNError.h" 29 | 30 | 31 | 32 | /* Memory management include files */ 33 | 34 | #include "RNBasics/RNMem.h" 35 | 36 | 37 | 38 | /* File management include files */ 39 | 40 | #include "RNBasics/RNFile.h" 41 | 42 | 43 | 44 | /* Basic bitflags include files */ 45 | 46 | #include "RNBasics/RNFlags.h" 47 | 48 | 49 | 50 | /* Class type include files */ 51 | 52 | #include "RNBasics/RNType.h" 53 | 54 | 55 | 56 | /* Math include files */ 57 | 58 | #include "RNBasics/RNScalar.h" 59 | #include "RNBasics/RNIntval.h" 60 | 61 | 62 | 63 | /* Dynamic array include files */ 64 | 65 | #include "RNBasics/RNArray.h" 66 | #include "RNBasics/RNQueue.h" 67 | #include "RNBasics/RNHeap.h" 68 | #include "RNBasics/RNMap.h" 69 | 70 | 71 | 72 | /* Graphics utility include files */ 73 | 74 | #include "RNBasics/RNGrfx.h" 75 | #include "RNBasics/RNRgb.h" 76 | 77 | 78 | 79 | /* OS utility include files */ 80 | 81 | #include "RNBasics/RNTime.h" 82 | 83 | 84 | 85 | /* SVD stuff */ 86 | 87 | #include "RNBasics/RNSvd.h" 88 | 89 | 90 | 91 | /* JSON stuff */ 92 | 93 | #include "RNBasics/json.h" 94 | 95 | 96 | 97 | /* Initialization functions */ 98 | 99 | int RNInitBasics(void); 100 | void RNStopBasics(void); 101 | 102 | 103 | 104 | #endif 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNError.h: -------------------------------------------------------------------------------- 1 | /* Include file for GAPS error utility */ 2 | 3 | 4 | 5 | /* Initialization functions */ 6 | 7 | int RNInitError(); 8 | void RNStopError(); 9 | 10 | 11 | 12 | /* Error file functions */ 13 | 14 | void RNSetErrorFile(FILE *fp); 15 | void RNSetErrorLevel(int level); 16 | 17 | 18 | 19 | /* Error reporting functions */ 20 | 21 | void RNAbort(const char *fmt, ...); 22 | void RNFail(const char *fmt, ...); 23 | void RNWarning(const char *fmt, ...); 24 | 25 | 26 | 27 | /* Define my own assert function */ 28 | 29 | #ifdef assert 30 | # undef assert 31 | #endif 32 | 33 | #ifdef NDEBUG 34 | #define assert(__x__) 35 | #else 36 | #define assert(__x__) \ 37 | if (!(__x__)) RNAbort("Assertion error %s at line %d in file %s", #__x__, __LINE__, __FILE__) 38 | #endif 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNExtern.h: -------------------------------------------------------------------------------- 1 | /* Include file for external stuff */ 2 | 3 | 4 | 5 | /* Usual C include files */ 6 | 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | 16 | 17 | 18 | /* Standard library include files */ 19 | 20 | #include 21 | #include 22 | 23 | 24 | 25 | /* Machine dependent include files */ 26 | 27 | #if (RN_OS == RN_WINDOWS) 28 | # include 29 | # include 30 | #else 31 | # include 32 | # include 33 | # include 34 | #endif 35 | 36 | 37 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNFile.cpp: -------------------------------------------------------------------------------- 1 | // Source file for file management utilities 2 | 3 | 4 | // Include files 5 | #include "RNBasics.h" 6 | 7 | 8 | 9 | //////////////////////////////////////////////////////////////////////// 10 | // FILE EXISTANCE FUNCTIONS 11 | //////////////////////////////////////////////////////////////////////// 12 | 13 | RNBoolean 14 | RNFileExists(const char *filename) 15 | { 16 | // Return whether or not file exists (and is readable) 17 | FILE *fp = fopen(filename, "rb"); 18 | if (!fp) return FALSE; 19 | fclose(fp); 20 | return TRUE; 21 | } 22 | 23 | 24 | 25 | //////////////////////////////////////////////////////////////////////// 26 | // FILE I/O UTILITY FUNCTIONS 27 | //////////////////////////////////////////////////////////////////////// 28 | 29 | int 30 | RNFileSeek(FILE *fp, unsigned long long offset, int whence) 31 | { 32 | #if (RN_OS == RN_WINDOWS) 33 | if (_fseek64(fp, offset, whence) == 0) return 1; 34 | else return 0; 35 | #else 36 | // Linux/unix/cygwin etc. 37 | if (fseeko(fp, offset, whence) == 0) return 1; 38 | else return 0; 39 | #endif 40 | } 41 | 42 | 43 | 44 | unsigned long long 45 | RNFileTell(FILE *fp) 46 | { 47 | #if (RN_OS == RN_WINDOWS) 48 | return _ftell64(fp); 49 | #else 50 | // Linux/unix/cygwin etc. 51 | return ftello(fp); 52 | #endif 53 | } 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNFile.h: -------------------------------------------------------------------------------- 1 | // Include file for file management utilities 2 | 3 | 4 | 5 | //////////////////////////////////////////////////////////////////////// 6 | // File existance funcitons 7 | //////////////////////////////////////////////////////////////////////// 8 | 9 | RNBoolean RNFileExists(const char *filename); 10 | 11 | 12 | 13 | //////////////////////////////////////////////////////////////////////// 14 | // File seek funcitons 15 | //////////////////////////////////////////////////////////////////////// 16 | 17 | int RNFileSeek(FILE *fp, unsigned long long offset, int whence); 18 | unsigned long long RNFileTell(FILE *fp); 19 | 20 | 21 | 22 | //////////////////////////////////////////////////////////////////////// 23 | // File seek constants 24 | //////////////////////////////////////////////////////////////////////// 25 | 26 | #define RN_FILE_SEEK_SET SEEK_SET 27 | #define RN_FILE_SEEK_CUR SEEK_CUR 28 | #define RN_FILE_SEEK_END SEEK_END 29 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNFlags.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for the GAPS flags class */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "RNBasics.h" 8 | 9 | 10 | 11 | /* Public functions */ 12 | 13 | int 14 | RNInitFlags() 15 | { 16 | /* Return success */ 17 | return TRUE; 18 | } 19 | 20 | 21 | 22 | void 23 | RNStopFlags() 24 | { 25 | } 26 | 27 | 28 | 29 | RNFlags:: 30 | RNFlags(void) 31 | : flags(0) 32 | { 33 | } 34 | 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNFlags.h: -------------------------------------------------------------------------------- 1 | /* Include file for the GAPS flags class */ 2 | 3 | 4 | 5 | /* Initialization functions */ 6 | 7 | int RNInitFlags(); 8 | void RNStopFlags(); 9 | 10 | 11 | 12 | /* Class definition */ 13 | 14 | class RNFlags /* : public RNBase */ { 15 | public: 16 | // Constructor functions 17 | RNFlags(void); 18 | RNFlags(unsigned long flags); 19 | 20 | // Type conversions 21 | operator unsigned long(void) const; 22 | 23 | // Relationship functions/operators 24 | int Intersects(const RNFlags flags) const; 25 | int Contains(const RNFlags flags) const; 26 | int operator[](const RNFlags flags) const; 27 | 28 | // Manipulation functions/operators 29 | void XOR(const RNFlags flags); 30 | void Add(const RNFlags flags); 31 | void Remove(const RNFlags flags); 32 | void Intersect(const RNFlags flags); 33 | void Reset(unsigned long flags); 34 | 35 | private: 36 | unsigned long flags; 37 | }; 38 | 39 | 40 | 41 | /* Flag mask definitions */ 42 | 43 | #define RN_NO_FLAGS 0x00000000 44 | #define RN_NULL_FLAGS 0x00000000 45 | #define RN_ALL_FLAGS 0xFFFFFFFF 46 | 47 | 48 | 49 | /* Inline functions */ 50 | 51 | inline RNFlags:: 52 | RNFlags(unsigned long flags) 53 | : flags(flags) 54 | { 55 | } 56 | 57 | 58 | 59 | inline RNFlags::operator 60 | unsigned long(void) const 61 | { 62 | // Convert RNFlags to unsigned long 63 | return flags; 64 | } 65 | 66 | 67 | 68 | inline int RNFlags:: 69 | Intersects(const RNFlags flags) const 70 | { 71 | // Return whether has a property 72 | return (this->flags & flags) ? 1 : 0; 73 | } 74 | 75 | 76 | 77 | inline int RNFlags:: 78 | Contains(const RNFlags flags) const 79 | { 80 | // Return whether contains all properties 81 | return ((this->flags & flags) == flags); 82 | } 83 | 84 | 85 | 86 | inline int RNFlags:: 87 | operator[] (const RNFlags flags) const 88 | { 89 | // Return whether flags intersect 90 | return this->Intersects(flags); 91 | } 92 | 93 | 94 | 95 | inline void RNFlags:: 96 | XOR(const RNFlags flags) 97 | { 98 | // Union this set of flags with ones passed in 99 | this->flags ^= flags; 100 | } 101 | 102 | 103 | 104 | inline void RNFlags:: 105 | Add(const RNFlags flags) 106 | { 107 | // Union this set of flags with ones passed in 108 | this->flags |= flags; 109 | } 110 | 111 | 112 | 113 | inline void RNFlags:: 114 | Remove(const RNFlags flags) 115 | { 116 | // Diff this set of flags with ones passed in 117 | this->flags &= ~flags; 118 | } 119 | 120 | 121 | 122 | inline void RNFlags:: 123 | Intersect(const RNFlags flags) 124 | { 125 | // Intersect this set of flags with ones passed in 126 | this->flags &= flags; 127 | } 128 | 129 | 130 | 131 | inline void RNFlags:: 132 | Reset(unsigned long flags) 133 | { 134 | // Set flags 135 | this->flags = flags; 136 | } 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNHeap.h: -------------------------------------------------------------------------------- 1 | // Include file for a heap 2 | 3 | #ifndef __RN__HEAP__H__ 4 | #define __RN__HEAP__H__ 5 | 6 | 7 | 8 | // Class definition 9 | 10 | template 11 | class RNHeap { 12 | public: 13 | // Constructor functions 14 | RNHeap(RNScalar (*value_callback)(PtrType, void *), 15 | PtrType **(*entry_callback)(PtrType, void *) = NULL, 16 | void *callback_data = NULL, int least_first = TRUE); 17 | RNHeap(PtrType base, RNScalar *value_ptr, PtrType **entry_ptr = NULL, int least_first = TRUE); 18 | RNHeap(int value_offset, int entry_offset = -1, int least_first = TRUE); 19 | ~RNHeap(void); 20 | 21 | // Data access functions 22 | int IsEmpty(void) const; 23 | int NEntries(void) const; 24 | PtrType Kth(int k) const; 25 | PtrType operator[](int k) const; 26 | PtrType Peek(void) const; 27 | 28 | // Manipulation functions 29 | void Empty(void); 30 | void Sort(int n = -1); 31 | void Truncate(int n, RNBoolean sort = TRUE); 32 | void Remove(PtrType data); 33 | void Update(PtrType data); 34 | void Push(PtrType data); 35 | PtrType Pop(void); 36 | 37 | // Debug functions 38 | int IsValid(void); 39 | 40 | protected: 41 | // Update functions 42 | RNScalar Value(int i) const; 43 | int Compare(int i, int j) const; 44 | void Swap(int i, int j); 45 | void Sort(int n, int left, int right); 46 | int BubbleUp(int i); 47 | int BubbleDown(int i); 48 | 49 | private: 50 | PtrType *entries; 51 | int nentries; 52 | int nallocated; 53 | int value_offset; 54 | int entry_offset; 55 | RNScalar (*value_callback)(PtrType, void *); 56 | PtrType **(*entry_callback)(PtrType, void *); 57 | void *callback_data; 58 | int least_first; 59 | }; 60 | 61 | 62 | 63 | // Include files 64 | 65 | #include "RNHeap.cpp" 66 | 67 | 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNMap.h: -------------------------------------------------------------------------------- 1 | /* Include file for the GAPS map class */ 2 | 3 | #ifndef __RN__MAP__H__ 4 | #define __RN__MAP__H__ 5 | 6 | 7 | 8 | /* Library initialization functions */ 9 | 10 | int RNInitMap(); 11 | void RNStopMap(); 12 | 13 | 14 | 15 | /* Support class */ 16 | 17 | template 18 | struct RNMapComparator { 19 | public: 20 | RNMapComparator(int (*compare_function)(KeyType, KeyType) = NULL) : compare_function(compare_function) {}; 21 | bool operator()(KeyType a, KeyType b) const { 22 | if (compare_function) { return ((*compare_function)(a, b) < 0) ? true: false; } 23 | else { return a < b; } 24 | }; 25 | private: 26 | int (*compare_function)(KeyType, KeyType); 27 | }; 28 | 29 | 30 | 31 | /* Class definition */ 32 | 33 | template 34 | class RNMap { 35 | public: 36 | // Constructor/destructor functions 37 | RNMap(void); 38 | RNMap(int (*compare)(KeyType, KeyType)); 39 | RNMap(const RNMap& map); 40 | ~RNMap(void); 41 | 42 | // Property functions/operations 43 | int NEntries(void) const; 44 | 45 | // Data access functions/operators 46 | RNBoolean Find(KeyType key, ValueType *value = NULL) const; 47 | 48 | // Manipulation functions 49 | void Empty(void); 50 | void Insert(KeyType key, ValueType value); 51 | void Replace(KeyType key, ValueType value); 52 | void Remove(KeyType key); 53 | 54 | // Manipulation operators 55 | RNMap& operator=(const RNMap& map); 56 | 57 | public: 58 | std::map > *m; 59 | }; 60 | 61 | 62 | 63 | 64 | /* Templated member functions */ 65 | 66 | #include "RNMap.cpp" 67 | 68 | 69 | 70 | /* A useful derived class definition */ 71 | 72 | template 73 | class RNSymbolTable : public RNMap { 74 | public: 75 | // Constructor/destructor functions 76 | RNSymbolTable(void) : RNMap() {}; 77 | }; 78 | 79 | 80 | 81 | #endif 82 | 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNMem.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for GAPS mem utility */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "RNBasics.h" 8 | 9 | 10 | 11 | int RNInitMem() 12 | { 13 | /* Return OK status */ 14 | return TRUE; 15 | } 16 | 17 | 18 | 19 | void RNStopMem() 20 | { 21 | } 22 | 23 | 24 | 25 | #if FALSE 26 | 27 | void *operator new(size_t size) 28 | { 29 | // Allocate size bytes 30 | void *data = (void *) malloc(size); 31 | if (!data) RNAbort("Unable to allocate %d bytes", size); 32 | return data; 33 | } 34 | 35 | 36 | 37 | void *operator new(size_t size, size_t extra) 38 | { 39 | // Allocate (size+extra) bytes 40 | void *data = (void *) malloc(size+extra); 41 | if (!data) RNAbort("Unable to allocate %d bytes", size+extra); 42 | return (void *) data; 43 | } 44 | 45 | 46 | 47 | void operator delete(void *data) 48 | { 49 | // Check arguments 50 | assert(data); 51 | 52 | // Free allocated bytes 53 | free(data); 54 | } 55 | 56 | #endif 57 | 58 | 59 | 60 | void RNSwap(void *node1, void *node2, void *buffer, int size) 61 | { 62 | // Check arguments 63 | assert(node1); 64 | assert(node2); 65 | assert(size > 0); 66 | 67 | // Find suitable swap buffer 68 | void *swap = buffer; 69 | char swap_buffer[RN_SWAP_BUFFER_SIZE]; 70 | if (buffer == NULL) { 71 | swap = (void *) swap_buffer; 72 | if (size > RN_SWAP_BUFFER_SIZE) { 73 | swap = (void *) malloc(size); 74 | if (!swap) { 75 | RNFail("Unable to allocate swap buffer"); 76 | return; 77 | } 78 | } 79 | } 80 | 81 | // Swap two buffers 82 | RNCopy(node1, swap, size); 83 | RNCopy(node2, node1, size); 84 | RNCopy(swap, node2, size); 85 | 86 | // Free swap buffer 87 | if (buffer == NULL) { 88 | if (size > RN_SWAP_BUFFER_SIZE) { 89 | free(swap); 90 | } 91 | } 92 | } 93 | 94 | 95 | 96 | void RNCopy(const void *src, void *dst, int size) 97 | { 98 | // Check arguments 99 | assert(src); 100 | assert(dst); 101 | assert(size > 0); 102 | 103 | // Copy buffer 104 | // bcopy(src, dst, size); 105 | memcpy(dst, src, size); 106 | } 107 | 108 | 109 | 110 | void RNZero(void *data, int size) 111 | { 112 | // Check arguments 113 | assert(data); 114 | assert(size > 0); 115 | 116 | // Zero buffer 117 | // bzero(data, size); 118 | memset(data, 0, size); 119 | } 120 | 121 | 122 | 123 | int RNCompare(const void *src1, const void *src2, int size) 124 | { 125 | // Check arguments 126 | assert(src1); 127 | assert(src2); 128 | assert(size > 0); 129 | 130 | // Compare buffers 131 | // return bcmp(src1, src2, size); 132 | return memcmp(src1, src2, size); 133 | } 134 | 135 | 136 | 137 | 138 | long RNMaxMemoryUsage(void) 139 | { 140 | # if (RN_OS == RN_WINDOWS) 141 | RNAbort("Not implemented"); 142 | return -1; 143 | #else 144 | struct rusage usage; 145 | if (getrusage(RUSAGE_SELF, &usage) == -1) return -1; 146 | return usage.ru_maxrss; 147 | # endif 148 | } 149 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNMem.h: -------------------------------------------------------------------------------- 1 | /* Include file for GAPS mem utility */ 2 | 3 | 4 | 5 | /* Initialization functions */ 6 | 7 | int RNInitMem(); 8 | void RNStopMem(); 9 | 10 | 11 | 12 | /* Memory allocation/deallocation functions */ 13 | 14 | #if FALSE 15 | 16 | void *operator new(size_t size); 17 | void *operator new(size_t size, size_t extra); 18 | void operator delete(void *data); 19 | 20 | #endif 21 | 22 | 23 | 24 | /* Standard memory manipulation functions */ 25 | 26 | #define RN_SWAP_BUFFER_SIZE 1024 27 | void RNSwap(void *node1, void *node2, void *buffer, int size); 28 | void RNCopy(const void *src, void *dst, int size); 29 | void RNZero(void *data, int size); 30 | int RNCompare(const void *src1, const void *src2, int size); 31 | 32 | 33 | 34 | /* Memory usage statistics */ 35 | 36 | long RNMaxMemoryUsage(void); 37 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNRgb.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for the RN RGB color class */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "RNBasics.h" 8 | 9 | 10 | 11 | /* Public variables */ 12 | 13 | RNRgb RNnull_rgb(0.0, 0.0, 0.0); 14 | RNRgb RNblack_rgb(0.0, 0.0, 0.0); 15 | RNRgb RNgray_rgb(0.5, 0.5, 0.5); 16 | RNRgb RNred_rgb(1.0, 0.0, 0.0); 17 | RNRgb RNgreen_rgb(0.0, 1.0, 0.0); 18 | RNRgb RNblue_rgb(0.0, 0.0, 1.0); 19 | RNRgb RNyellow_rgb(1.0, 1.0, 0.0); 20 | RNRgb RNcyan_rgb(0.0, 1.0, 1.0); 21 | RNRgb RNmagenta_rgb(1.0, 0.0, 1.0); 22 | RNRgb RNwhite_rgb(1.0, 1.0, 1.0); 23 | 24 | 25 | 26 | /* Public functions */ 27 | 28 | int 29 | RNInitRgb() 30 | { 31 | /* Return success */ 32 | return TRUE; 33 | } 34 | 35 | 36 | 37 | void 38 | RNStopRgb() 39 | { 40 | } 41 | 42 | 43 | 44 | RNRgb:: 45 | RNRgb(void) 46 | { 47 | } 48 | 49 | 50 | 51 | RNRgb:: 52 | RNRgb(const RNRgb& rgb) 53 | { 54 | c[0] = rgb.c[0]; 55 | c[1] = rgb.c[1]; 56 | c[2] = rgb.c[2]; 57 | } 58 | 59 | 60 | 61 | RNRgb:: 62 | RNRgb(RNScalar red, RNScalar green, RNScalar blue) 63 | { 64 | c[0] = red; 65 | c[1] = green; 66 | c[2] = blue; 67 | } 68 | 69 | 70 | 71 | RNRgb:: 72 | RNRgb(const RNScalar array[3]) 73 | { 74 | c[0] = array[0]; 75 | c[1] = array[1]; 76 | c[2] = array[2]; 77 | } 78 | 79 | 80 | 81 | const RNBoolean RNRgb:: 82 | operator==(const RNRgb& rgb) const 83 | { 84 | // Return whether rgb is equal 85 | return ((c[0] == rgb.c[0]) && (c[1] == rgb.c[1]) && (c[2] == rgb.c[2])); 86 | } 87 | 88 | 89 | 90 | const RNBoolean RNRgb:: 91 | operator!=(const RNRgb& rgb) const 92 | { 93 | // Return whether rgb is not equal 94 | return ((c[0] != rgb.c[0]) || (c[1] != rgb.c[1]) || (c[2] != rgb.c[2])); 95 | } 96 | 97 | 98 | 99 | RNRgb& RNRgb:: 100 | operator=(const RNRgb& rgb) 101 | { 102 | c[0] = rgb.c[0]; 103 | c[1] = rgb.c[1]; 104 | c[2] = rgb.c[2]; 105 | return *this; 106 | } 107 | 108 | 109 | 110 | RNRgb& RNRgb:: 111 | operator+=(const RNRgb& rgb) 112 | { 113 | c[0] += rgb.c[0]; 114 | c[1] += rgb.c[1]; 115 | c[2] += rgb.c[2]; 116 | return *this; 117 | } 118 | 119 | 120 | 121 | RNRgb& RNRgb:: 122 | operator-=(const RNRgb& rgb) 123 | { 124 | c[0] -= rgb.c[0]; 125 | c[1] -= rgb.c[1]; 126 | c[2] -= rgb.c[2]; 127 | return *this; 128 | } 129 | 130 | 131 | 132 | RNRgb& RNRgb:: 133 | operator*=(const RNRgb& rgb) 134 | { 135 | c[0] *= rgb.c[0]; 136 | c[1] *= rgb.c[1]; 137 | c[2] *= rgb.c[2]; 138 | return *this; 139 | } 140 | 141 | 142 | 143 | RNRgb& RNRgb:: 144 | operator*=(RNScalar a) 145 | { 146 | c[0] *= a; 147 | c[1] *= a; 148 | c[2] *= a; 149 | return *this; 150 | } 151 | 152 | 153 | 154 | RNRgb& RNRgb:: 155 | operator/=(RNScalar a) 156 | { 157 | // assert(!zero(a)); 158 | c[0] /= a; 159 | c[1] /= a; 160 | c[2] /= a; 161 | return *this; 162 | } 163 | 164 | 165 | 166 | 167 | 168 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNSvd.h: -------------------------------------------------------------------------------- 1 | // Include file for SVD functions 2 | 3 | 4 | 5 | // Function to perform singular value decomposition 6 | 7 | extern void RNSvdDecompose(int m, int n, 8 | const RNScalar *a, 9 | RNScalar *u, RNScalar *w, RNScalar *vt); 10 | 11 | 12 | 13 | // Function to perform back substitution 14 | 15 | extern void RNSvdBacksubstitute(int m, int n, 16 | const RNScalar *u, const RNScalar *w, const RNScalar *vt, const RNScalar *b, 17 | RNScalar *x, RNScalar eps = RN_EPSILON); 18 | 19 | 20 | 21 | // Function to solve system of equations by SVD and back substitution 22 | 23 | extern void RNSvdSolve(int m, int n, 24 | const RNScalar *a, const RNScalar *b, 25 | RNScalar *x, RNScalar eps = RN_EPSILON); 26 | 27 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNTime.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for GAPS real wallclock time class */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "RNBasics.h" 8 | 9 | 10 | 11 | int RNInitTime() 12 | { 13 | /* Return OK status */ 14 | return TRUE; 15 | } 16 | 17 | 18 | 19 | void RNStopTime() 20 | { 21 | } 22 | 23 | 24 | 25 | RNTime:: 26 | RNTime(void) 27 | { 28 | # if (RN_OS == RN_WINDOWS) 29 | QueryPerformanceFrequency(&timefreq); 30 | # endif 31 | } 32 | 33 | 34 | 35 | RNTime:: 36 | RNTime(const RNTime& tm) 37 | : timevalue(tm.timevalue) 38 | { 39 | # if (RN_OS == RN_WINDOWS) 40 | timefreq = timefreq; 41 | # endif 42 | } 43 | 44 | 45 | 46 | RNScalar RNTime:: 47 | operator- (const RNTime& tm) const 48 | { 49 | /* Return the difference between this and tm times (in seconds) */ 50 | # if (RN_OS == RN_WINDOWS) 51 | return ((RNScalar) this->timevalue.QuadPart - (RNScalar) tm.timevalue.QuadPart) / ((RNScalar) this->timefreq.QuadPart); 52 | # elif (RN_OS == OLD_RN_WINDOWS) 53 | return (RNScalar) (this->timevalue - tm.timevalue) / 1.0E3; 54 | # else 55 | return (RNScalar) (this->timevalue.tv_sec - tm.timevalue.tv_sec + 56 | 1.0E-6F * (this->timevalue.tv_usec - tm.timevalue.tv_usec)); 57 | # endif 58 | } 59 | 60 | 61 | 62 | RNScalar RNTime:: 63 | Elapsed (const RNTime& tm) const 64 | { 65 | // Return number of seconds elapsed between times 66 | RNScalar delta = *this - tm; 67 | assert(delta >= 0.0); 68 | return delta; 69 | } 70 | 71 | 72 | 73 | RNScalar RNTime:: 74 | Elapsed (void) const 75 | { 76 | // Return number of seconds elapsed since time 77 | RNTime tm; tm.Read(); 78 | return tm.Elapsed(*this); 79 | } 80 | 81 | 82 | 83 | RNTime 84 | RNCurrentTime(void) 85 | { 86 | RNTime tm; 87 | tm.Read(); 88 | return tm; 89 | } 90 | 91 | 92 | 93 | 94 | #if (RN_OS != RN_WINDOWS) 95 | # include 96 | #endif 97 | 98 | void 99 | RNSleep(RNScalar seconds) 100 | { 101 | #if (RN_OS == RN_IRIX) 102 | sginap((long) (seconds * CLK_TCK)); 103 | #elif (RN_OS == RN_WINDOWS) 104 | Sleep((unsigned long) (1000 * seconds)); 105 | #elif (RN_OS == RN_LINUX) 106 | usleep((unsigned long) (1000000 * seconds)); 107 | #else 108 | RNAbort("Not implemented"); 109 | #endif 110 | } 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNTime.h: -------------------------------------------------------------------------------- 1 | /* Include file for GAPS wallclock time class */ 2 | 3 | 4 | 5 | /* Initialization functions */ 6 | 7 | int RNInitTime(); 8 | void RNStopTime(); 9 | 10 | 11 | 12 | /* Class definition */ 13 | 14 | class RNTime /* : public RNBase */ { 15 | public: 16 | // Constructor functions 17 | RNTime(void); 18 | RNTime(const RNTime& tm); 19 | 20 | // Relationship functions/operators 21 | RNScalar Elapsed(const RNTime& tm) const; 22 | RNScalar Elapsed(void) const; 23 | 24 | // Arithmetic operators 25 | RNScalar operator-(const RNTime& tm) const; 26 | 27 | // Manipulation functions/operators 28 | void Read(void); 29 | 30 | private: 31 | # if (RN_OS == RN_WINDOWS) 32 | LARGE_INTEGER timefreq; 33 | LARGE_INTEGER timevalue; 34 | # elif (RN_OS == OLD_RN_WINDOWS) 35 | DWORD timevalue; 36 | # else 37 | struct timeval timevalue; 38 | # endif 39 | }; 40 | 41 | 42 | 43 | /* Public functions */ 44 | 45 | RNTime RNCurrentTime(void); 46 | void RNSleep(RNScalar seconds); 47 | 48 | 49 | 50 | /* Inline functions */ 51 | 52 | inline void RNTime:: 53 | Read (void) 54 | { 55 | /* Read the current time */ 56 | # if (RN_OS == RN_WINDOWS) 57 | QueryPerformanceCounter(&timevalue); 58 | # elif (RN_OS == OLD_RN_WINDOWS) 59 | timevalue = GetTickCount(); 60 | # else 61 | gettimeofday(&timevalue, NULL); 62 | # endif 63 | } 64 | 65 | 66 | 67 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNType.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for GAPS class types */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "RNBasics.h" 8 | 9 | 10 | 11 | /* Public variables */ 12 | 13 | const RNClassType RNnull_class_type(RN_NULL_CLASS_ID, ""); 14 | 15 | 16 | 17 | /* Private variables */ 18 | 19 | static RNClassID RNnclass_ids = 0; 20 | 21 | 22 | 23 | int RNInitClassType() 24 | { 25 | /* Return OK status */ 26 | return TRUE; 27 | } 28 | 29 | 30 | 31 | void RNStopClassType() 32 | { 33 | } 34 | 35 | 36 | 37 | RNClassType:: 38 | RNClassType(RNClassID id, const char *name) 39 | { 40 | // Initialize class type 41 | this->id = id; 42 | if (!name) this->name = NULL; 43 | else { 44 | this->name = new char[strlen(name) + 1]; 45 | assert(this->name); 46 | strcpy(this->name, name); 47 | } 48 | } 49 | 50 | 51 | 52 | RNClassType:: 53 | RNClassType(const char *name) 54 | { 55 | // Initialize class type 56 | id = ++RNnclass_ids; 57 | if (!name) this->name = NULL; 58 | else { 59 | this->name = new char[strlen(name) + 1]; 60 | assert(this->name); 61 | strcpy(this->name, name); 62 | } 63 | } 64 | 65 | 66 | 67 | RNClassType:: 68 | ~RNClassType(void) 69 | { 70 | // Free name 71 | if (name) delete [] name; 72 | } 73 | 74 | -------------------------------------------------------------------------------- /gaps/pkgs/RNBasics/RNType.h: -------------------------------------------------------------------------------- 1 | /* Include file GAPS class type identifier */ 2 | 3 | 4 | 5 | /* Initialization functions */ 6 | 7 | int RNInitClassType(); 8 | void RNStopClassType(); 9 | 10 | 11 | 12 | /* Type definitions */ 13 | 14 | typedef int RNClassID; 15 | 16 | 17 | 18 | /* Class definition */ 19 | 20 | class RNClassType { 21 | public: 22 | // Constructor functions 23 | RNClassType(RNClassID id, const char *name); 24 | RNClassType(const char *name); 25 | ~RNClassType(void); 26 | 27 | // Property functions 28 | const RNClassID ID(void) const; 29 | const char *Name(void) const; 30 | 31 | private: 32 | RNClassID id; 33 | char *name; 34 | }; 35 | 36 | 37 | 38 | /* Public constants */ 39 | 40 | #define RN_UNKNOWN_CLASS_ID (-1) 41 | #define RN_NULL_CLASS_ID (0) 42 | 43 | 44 | 45 | /* Public variables */ 46 | 47 | extern const RNClassType RNnull_class_type; 48 | 49 | 50 | 51 | /* Useful macros */ 52 | 53 | #define RN_CLASS_TYPE_DECLARATIONS(__class) \ 54 | virtual const RNClassID ClassID(void) const; \ 55 | virtual const char *ClassName(void) const; \ 56 | virtual const RNClassType& ClassType(void) const; \ 57 | static const RNClassID CLASS_ID(void); \ 58 | static const char * CLASS_NAME(void); \ 59 | static const RNClassType& CLASS_TYPE(void) 60 | 61 | #define RN_CLASS_TYPE_DEFINITIONS(__class) \ 62 | const RNClassType __class ## _class_type ( #__class ); \ 63 | const RNClassID __class::ClassID(void) const { return CLASS_ID(); } \ 64 | const char *__class::ClassName(void) const { return CLASS_NAME(); } \ 65 | const RNClassType& __class::ClassType(void) const { return CLASS_TYPE(); } \ 66 | const RNClassID __class::CLASS_ID(void) { return CLASS_TYPE().ID(); } \ 67 | const char * __class::CLASS_NAME(void) { return CLASS_TYPE().Name(); } \ 68 | const RNClassType& __class::CLASS_TYPE(void) { return __class ## _class_type; } 69 | 70 | 71 | 72 | 73 | /* Inline functions */ 74 | 75 | inline const RNClassID RNClassType:: 76 | ID(void) const 77 | { 78 | // Return class id 79 | return id; 80 | } 81 | 82 | 83 | 84 | inline const char *RNClassType:: 85 | Name(void) const 86 | { 87 | // Return class name 88 | return name; 89 | } 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /gaps/pkgs/RNMath/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Package name 3 | # 4 | 5 | NAME=RNMath 6 | 7 | 8 | 9 | # 10 | # List of source files 11 | # 12 | 13 | CCSRCS=$(NAME).cpp \ 14 | RNPolynomial.cpp RNAlgebraic.cpp RNEquation.cpp RNSystemOfEquations.cpp \ 15 | RNDenseLUMatrix.cpp RNDenseMatrix.cpp RNMatrix.cpp \ 16 | RNVector.cpp 17 | 18 | 19 | # 20 | # Dependencies 21 | # 22 | 23 | PKG_DEPENDENCIES = RNBasics 24 | 25 | 26 | 27 | # 28 | # PKG makefile 29 | # 30 | 31 | include ../../makefiles/Makefile.pkgs 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /gaps/pkgs/RNMath/RNDenseLUMatrix.h: -------------------------------------------------------------------------------- 1 | // Include file for abstract matrix class 2 | 3 | 4 | 5 | // Class definition 6 | 7 | class RNDenseLUMatrix : public RNDenseMatrix { 8 | public: 9 | // Constructor/destructor 10 | RNDenseLUMatrix(void); 11 | RNDenseLUMatrix(int nrows, int ncols, RNScalar *values = NULL); 12 | RNDenseLUMatrix(const RNDenseLUMatrix& matrix); 13 | RNDenseLUMatrix(const RNDenseMatrix& matrix); 14 | RNDenseLUMatrix(const RNMatrix& matrix); 15 | virtual ~RNDenseLUMatrix(void); 16 | 17 | // Property functions/operators 18 | virtual RNScalar Determinant(void) const; 19 | virtual RNDenseMatrix Inverse(void) const; 20 | 21 | // Factoring functions/operations 22 | int DecomposeLU(RNDenseMatrix& L, RNDenseMatrix& U) const; 23 | 24 | protected: 25 | // Utility functions 26 | void Decompose(void); 27 | void BackSubstitute(RNDenseMatrix &b, RNDenseMatrix &x) const; 28 | 29 | private: 30 | int *pivots; 31 | }; 32 | 33 | 34 | 35 | 36 | -------------------------------------------------------------------------------- /gaps/pkgs/RNMath/RNEquation.cpp: -------------------------------------------------------------------------------- 1 | // Source file for equation class 2 | 3 | 4 | 5 | //////////////////////////////////////////////////////////////////////// 6 | // Include files 7 | //////////////////////////////////////////////////////////////////////// 8 | 9 | #include "RNMath/RNMath.h" 10 | 11 | 12 | 13 | //////////////////////////////////////////////////////////////////////// 14 | // Functions 15 | //////////////////////////////////////////////////////////////////////// 16 | 17 | RNEquation:: 18 | RNEquation(void) 19 | : RNExpression(), 20 | system(NULL), 21 | system_index(-1), 22 | residual_threshold(0) 23 | { 24 | } 25 | 26 | 27 | 28 | RNEquation:: 29 | RNEquation(RNPolynomial *polynomial) 30 | : RNExpression(polynomial), 31 | system(NULL), 32 | system_index(-1), 33 | residual_threshold(0) 34 | { 35 | } 36 | 37 | 38 | 39 | RNEquation:: 40 | RNEquation(RNAlgebraic *algebraic) 41 | : RNExpression(algebraic), 42 | system(NULL), 43 | system_index(-1), 44 | residual_threshold(0) 45 | { 46 | } 47 | 48 | 49 | 50 | RNEquation:: 51 | RNEquation(RNScalar c, int nv, const int *v, const RNScalar *e, RNBoolean already_sorted) 52 | : RNExpression(c, nv, v, e, already_sorted), 53 | system(NULL), 54 | system_index(-1), 55 | residual_threshold(0) 56 | { 57 | } 58 | 59 | 60 | 61 | RNEquation:: 62 | RNEquation(int operation, RNExpression *operand1, RNExpression *operand2) 63 | : RNExpression(operation, operand1, operand2), 64 | system(NULL), 65 | system_index(-1), 66 | residual_threshold(0) 67 | { 68 | } 69 | 70 | 71 | 72 | RNEquation:: 73 | RNEquation(const RNPolynomial& polynomial, int dummy) 74 | : RNExpression(polynomial, dummy), 75 | system(NULL), 76 | system_index(-1), 77 | residual_threshold(0) 78 | { 79 | } 80 | 81 | 82 | 83 | RNEquation:: 84 | RNEquation(const RNExpression& expression, int dummy) 85 | : RNExpression(expression), 86 | system(NULL), 87 | system_index(-1), 88 | residual_threshold(0) 89 | { 90 | } 91 | 92 | 93 | 94 | RNEquation:: 95 | RNEquation(const RNEquation& equation) 96 | : RNExpression(equation), 97 | system(NULL), 98 | system_index(-1), 99 | residual_threshold(equation.residual_threshold) 100 | { 101 | } 102 | 103 | 104 | 105 | RNEquation:: 106 | ~RNEquation(void) 107 | { 108 | // Remove from system of equations 109 | if (system) system->RemoveEquation(this); 110 | } 111 | 112 | 113 | 114 | -------------------------------------------------------------------------------- /gaps/pkgs/RNMath/RNEquation.h: -------------------------------------------------------------------------------- 1 | // Include file for equation class 2 | 3 | 4 | 5 | //////////////////////////////////////////////////////////////////////// 6 | // Class definition 7 | //////////////////////////////////////////////////////////////////////// 8 | 9 | class RNEquation : public RNExpression { 10 | public: 11 | // Constructor/destructor 12 | RNEquation(void); 13 | RNEquation(RNPolynomial *polynomial); 14 | RNEquation(RNAlgebraic *algebraic); 15 | RNEquation(RNScalar c, int nv, const int *v = NULL, const RNScalar *e = NULL, RNBoolean already_sorted = FALSE); 16 | RNEquation(int operation, RNAlgebraic *operand1, RNAlgebraic *operand2); 17 | RNEquation(const RNPolynomial& polynomial, int dummy); 18 | RNEquation(const RNExpression& expression, int dummy); 19 | RNEquation(const RNEquation& equation); 20 | virtual ~RNEquation(void); 21 | 22 | // Access functions 23 | RNSystemOfEquations *SystemOfEquations(void) const; 24 | int SystemIndex(void) const; 25 | 26 | // Evaluation functions 27 | RNScalar EvaluateResidual(const RNScalar *x) const; 28 | 29 | private: 30 | friend class RNSystemOfEquations; 31 | RNSystemOfEquations *system; 32 | int system_index; 33 | 34 | public: 35 | // Temporary 36 | RNScalar ResidualThreshold(void) const { return residual_threshold; }; 37 | void SetResidualThreshold(RNScalar threshold) { this->residual_threshold = threshold; }; 38 | RNScalar residual_threshold; 39 | }; 40 | 41 | 42 | 43 | //////////////////////////////////////////////////////////////////////// 44 | // Inline functions 45 | //////////////////////////////////////////////////////////////////////// 46 | 47 | inline RNSystemOfEquations *RNEquation:: 48 | SystemOfEquations(void) const 49 | { 50 | // Return system of equations this equation belongs to 51 | return system; 52 | } 53 | 54 | 55 | 56 | inline int RNEquation:: 57 | SystemIndex(void) const 58 | { 59 | // Return index of this equation in its system of equations 60 | return system_index; 61 | } 62 | 63 | 64 | 65 | inline RNScalar RNEquation:: 66 | EvaluateResidual(const RNScalar *x) const 67 | { 68 | // Evaluate expression 69 | return Evaluate(x); 70 | } 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /gaps/pkgs/RNMath/RNMath.cpp: -------------------------------------------------------------------------------- 1 | /* Source file for GAPS math module */ 2 | 3 | 4 | 5 | /* Include files */ 6 | 7 | #include "RNMath.h" 8 | 9 | 10 | 11 | /* Private variables */ 12 | 13 | static int RNmath_active_count = 0; 14 | 15 | 16 | 17 | int RNInitMath(void) 18 | { 19 | // Check whether are already initialized 20 | if ((RNmath_active_count++) > 0) return TRUE; 21 | 22 | // Initialize submodules 23 | RNSeedRandomScalar(); 24 | 25 | // Return OK status 26 | return TRUE; 27 | } 28 | 29 | 30 | 31 | void RNStopMath(void) 32 | { 33 | // Check whether have been initialized 34 | if ((--RNmath_active_count) > 0) return; 35 | 36 | // Stop submodules 37 | // ??? 38 | } 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /gaps/pkgs/RNMath/RNMath.h: -------------------------------------------------------------------------------- 1 | // Include file for RNMath package 2 | 3 | #ifndef __RN__MATH__H__ 4 | #define __RN__MATH__H__ 5 | 6 | 7 | 8 | 9 | // Dependency include files 10 | 11 | #include "RNBasics/RNBasics.h" 12 | 13 | 14 | 15 | // Declarations 16 | 17 | class RNVector; 18 | class RNMatrix; 19 | class RNDenseMatrix; 20 | class RNPolynomial; 21 | class RNPolynomialTerm; 22 | class RNAlgebraic; 23 | typedef RNAlgebraic RNExpression; 24 | class RNEquation; 25 | class RNSystemOfEquations; 26 | 27 | 28 | 29 | // Matrix classes 30 | 31 | #include "RNMath/RNLapack.h" 32 | #include "RNMath/RNVector.h" 33 | #include "RNMath/RNMatrix.h" 34 | #include "RNMath/RNDenseMatrix.h" 35 | #include "RNMath/RNDenseLUMatrix.h" 36 | 37 | 38 | // Expression and equation classes 39 | 40 | #include "RNMath/RNPolynomial.h" 41 | #include "RNMath/RNAlgebraic.h" 42 | #include "RNMath/RNEquation.h" 43 | #include "RNMath/RNSystemOfEquations.h" 44 | 45 | 46 | 47 | #endif 48 | -------------------------------------------------------------------------------- /gaps/pkgs/RNMath/RNMatrix.cpp: -------------------------------------------------------------------------------- 1 | // Source file for abstract matrix class 2 | 3 | 4 | // Include files 5 | 6 | #include "RNMath.h" 7 | 8 | 9 | 10 | RNMatrix:: 11 | RNMatrix(void) 12 | { 13 | } 14 | 15 | 16 | 17 | RNMatrix:: 18 | RNMatrix(const RNMatrix& matrix) 19 | { 20 | } 21 | 22 | 23 | 24 | RNMatrix:: 25 | ~RNMatrix(void) 26 | { 27 | } 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /gaps/pkgs/RNMath/RNMatrix.h: -------------------------------------------------------------------------------- 1 | // Include file for abstract matrix class 2 | 3 | 4 | 5 | // Class definition 6 | 7 | class RNMatrix { 8 | public: 9 | // Constructor/destructor 10 | RNMatrix(void); 11 | RNMatrix(const RNMatrix& matrix); 12 | virtual ~RNMatrix(void); 13 | 14 | // Entry access 15 | virtual int NRows(void) const = 0; 16 | virtual int NColumns(void) const = 0; 17 | virtual RNScalar Value(int i, int j) const = 0; 18 | virtual void SetValue(int i, int j, RNScalar value) = 0; 19 | 20 | // Property functions/operators 21 | virtual RNBoolean IsDense(void) const = 0; 22 | virtual RNBoolean IsSparse(void) const = 0; 23 | }; 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /gaps/pkgs/RNMath/RNVector.h: -------------------------------------------------------------------------------- 1 | // Include file for vector class 2 | 3 | 4 | 5 | // Class definition 6 | 7 | class RNVector { 8 | public: 9 | // Constructor/destructor 10 | RNVector(void); 11 | RNVector(int n, RNScalar *values = NULL); 12 | RNVector(const RNVector& vector); 13 | ~RNVector(void); 14 | 15 | // Entry access 16 | int NRows(void) const; 17 | int NValues(void) const; 18 | RNScalar Value(int i) const; 19 | void SetValue(int i, RNScalar value); 20 | RNScalar operator[](int i) const; 21 | 22 | // Property functions/operators 23 | RNBoolean IsZero(void) const; 24 | RNLength Length(void) const; 25 | RNVector Subvector(int min_row, int max_row) const; 26 | RNScalar Dot(const RNVector& vector) const; 27 | RNBoolean operator==(const RNVector& vector) const; 28 | RNBoolean operator!=(const RNVector& vector) const; 29 | 30 | // Vector mainpulation 31 | void Negate(void); 32 | void Normalize(void); 33 | void Add(const RNVector& vector); 34 | void Subtract(const RNVector& vector); 35 | void Multiply(RNScalar a); 36 | void Reset(int nvalues, RNScalar *values = NULL); 37 | 38 | // Assignment operators 39 | RNVector& operator=(const RNVector& vector); 40 | RNVector& operator+=(const RNVector& vector); 41 | RNVector& operator-=(const RNVector& vector); 42 | RNVector& operator*=(RNScalar a); 43 | RNVector& operator/=(RNScalar a); 44 | 45 | // Arithmetic operators 46 | friend RNVector operator-(const RNVector& vector); 47 | friend RNVector operator+(const RNVector& vector1, const RNVector& vector2); 48 | friend RNVector operator-(const RNVector& vector1, const RNVector& vector2); 49 | friend RNVector operator*(RNScalar a, const RNVector& vector); 50 | friend RNVector operator*(const RNVector& vector, RNScalar a); 51 | friend RNVector operator/(const RNVector& vector, RNScalar a); 52 | 53 | // Friends 54 | friend class RNDenseMatrix; 55 | 56 | protected: 57 | RNScalar *values; 58 | int nvalues; 59 | }; 60 | 61 | 62 | 63 | // Inline functions 64 | 65 | inline int RNVector:: 66 | NRows(void) const 67 | { 68 | // Return number of values 69 | return nvalues; 70 | } 71 | 72 | 73 | 74 | inline int RNVector:: 75 | NValues(void) const 76 | { 77 | // Return number of values 78 | return NRows(); 79 | } 80 | 81 | 82 | 83 | 84 | inline RNScalar RNVector:: 85 | Value(int i) const 86 | { 87 | // Return ith value 88 | assert((i >= 0) && (i < nvalues)); 89 | return values[i]; 90 | } 91 | 92 | 93 | 94 | 95 | inline void RNVector:: 96 | SetValue(int i, RNScalar value) 97 | { 98 | // Return number of values 99 | assert((i >= 0) && (i < nvalues)); 100 | values[i] = value; 101 | } 102 | 103 | 104 | 105 | 106 | inline RNScalar RNVector:: 107 | operator[](int i) const 108 | { 109 | // Return number of values 110 | return Value(i); 111 | } 112 | 113 | 114 | 115 | 116 | -------------------------------------------------------------------------------- /gaps/pkgs/jpeg/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Package name 3 | # 4 | 5 | NAME=jpeg 6 | 7 | 8 | 9 | # 10 | # List of source files 11 | # 12 | 13 | # library object files common to compression and decompression 14 | COMSRCS= jcomapi.c jutils.c jerror.c jmemmgr.c jmemnobs.c 15 | 16 | # compression library object files 17 | CLIBSRCS= jcapimin.c jcapistd.c jctrans.c jcparam.c \ 18 | jdatadst.c jcinit.c jcmaster.c jcmarker.c jcmainct.c \ 19 | jcprepct.c jccoefct.c jccolor.c jcsample.c jchuff.c \ 20 | jcphuff.c jcdctmgr.c jfdctfst.c jfdctflt.c \ 21 | jfdctint.c 22 | 23 | # decompression library object files 24 | DLIBSRCS= jdapimin.c jdapistd.c jdtrans.c jdatasrc.c \ 25 | jdmaster.c jdinput.c jdmarker.c jdhuff.c jdphuff.c \ 26 | jdmainct.c jdcoefct.c jdpostct.c jddctmgr.c \ 27 | jidctfst.c jidctflt.c jidctint.c jidctred.c \ 28 | jdsample.c jdcolor.c jquant1.c jquant2.c jdmerge.c 29 | 30 | # JPEG library source files 31 | CSRCS=$(CLIBSRCS) $(DLIBSRCS) $(COMSRCS) 32 | 33 | 34 | 35 | # 36 | # GAPS library makefile 37 | # 38 | 39 | include ../../makefiles/Makefile.pkgs 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /gaps/pkgs/jpeg/jchuff.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jchuff.h 3 | * 4 | * Copyright (C) 1991-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains declarations for Huffman entropy encoding routines 9 | * that are shared between the sequential encoder (jchuff.c) and the 10 | * progressive encoder (jcphuff.c). No other modules need to see these. 11 | */ 12 | 13 | /* The legal range of a DCT coefficient is 14 | * -1024 .. +1023 for 8-bit data; 15 | * -16384 .. +16383 for 12-bit data. 16 | * Hence the magnitude should always fit in 10 or 14 bits respectively. 17 | */ 18 | 19 | #if BITS_IN_JSAMPLE == 8 20 | #define MAX_COEF_BITS 10 21 | #else 22 | #define MAX_COEF_BITS 14 23 | #endif 24 | 25 | /* Derived data constructed for each Huffman table */ 26 | 27 | typedef struct { 28 | unsigned int ehufco[256]; /* code for each symbol */ 29 | char ehufsi[256]; /* length of code for each symbol */ 30 | /* If no code has been allocated for a symbol S, ehufsi[S] contains 0 */ 31 | } c_derived_tbl; 32 | 33 | /* Short forms of external names for systems with brain-damaged linkers. */ 34 | 35 | #ifdef NEED_SHORT_EXTERNAL_NAMES 36 | #define jpeg_make_c_derived_tbl jMkCDerived 37 | #define jpeg_gen_optimal_table jGenOptTbl 38 | #endif /* NEED_SHORT_EXTERNAL_NAMES */ 39 | 40 | /* Expand a Huffman table definition into the derived format */ 41 | EXTERN(void) jpeg_make_c_derived_tbl 42 | JPP((j_compress_ptr cinfo, jboolean isDC, int tblno, 43 | c_derived_tbl ** pdtbl)); 44 | 45 | /* Generate an optimal table definition given the specified counts */ 46 | EXTERN(void) jpeg_gen_optimal_table 47 | JPP((j_compress_ptr cinfo, JHUFF_TBL * htbl, long freq[])); 48 | -------------------------------------------------------------------------------- /gaps/pkgs/jpeg/jcinit.c: -------------------------------------------------------------------------------- 1 | /* 2 | * jcinit.c 3 | * 4 | * Copyright (C) 1991-1997, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains initialization logic for the JPEG compressor. 9 | * This routine is in charge of selecting the modules to be executed and 10 | * making an initialization call to each one. 11 | * 12 | * Logically, this code belongs in jcmaster.c. It's split out because 13 | * linking this routine implies linking the entire compression library. 14 | * For a transcoding-only application, we want to be able to use jcmaster.c 15 | * without linking in the whole library. 16 | */ 17 | 18 | #define JPEG_INTERNALS 19 | #include "jinclude.h" 20 | #include "jpeglib.h" 21 | 22 | 23 | /* 24 | * Master selection of compression modules. 25 | * This is done once at the start of processing an image. We determine 26 | * which modules will be used and give them appropriate initialization calls. 27 | */ 28 | 29 | GLOBAL(void) 30 | jinit_compress_master (j_compress_ptr cinfo) 31 | { 32 | /* Initialize master control (includes parameter checking/processing) */ 33 | jinit_c_master_control(cinfo, FALSE /* full compression */); 34 | 35 | /* Preprocessing */ 36 | if (! cinfo->raw_data_in) { 37 | jinit_color_converter(cinfo); 38 | jinit_downsampler(cinfo); 39 | jinit_c_prep_controller(cinfo, FALSE /* never need full buffer here */); 40 | } 41 | /* Forward DCT */ 42 | jinit_forward_dct(cinfo); 43 | /* Entropy encoding: either Huffman or arithmetic coding. */ 44 | if (cinfo->arith_code) { 45 | ERREXIT(cinfo, JERR_ARITH_NOTIMPL); 46 | } else { 47 | if (cinfo->progressive_mode) { 48 | #ifdef C_PROGRESSIVE_SUPPORTED 49 | jinit_phuff_encoder(cinfo); 50 | #else 51 | ERREXIT(cinfo, JERR_NOT_COMPILED); 52 | #endif 53 | } else 54 | jinit_huff_encoder(cinfo); 55 | } 56 | 57 | /* Need a full-image coefficient buffer in any multi-pass mode. */ 58 | jinit_c_coef_controller(cinfo, 59 | (jboolean) (cinfo->num_scans > 1 || cinfo->optimize_coding)); 60 | jinit_c_main_controller(cinfo, FALSE /* never need full buffer here */); 61 | 62 | jinit_marker_writer(cinfo); 63 | 64 | /* We can now tell the memory manager to allocate virtual arrays. */ 65 | (*cinfo->mem->realize_virt_arrays) ((j_common_ptr) cinfo); 66 | 67 | /* Write the datastream header (SOI) immediately. 68 | * Frame and scan headers are postponed till later. 69 | * This lets application insert special markers after the SOI. 70 | */ 71 | (*cinfo->marker->write_file_header) (cinfo); 72 | } 73 | -------------------------------------------------------------------------------- /gaps/pkgs/jpeg/jconfig.h: -------------------------------------------------------------------------------- 1 | /* jconfig.h. Generated automatically by configure. */ 2 | /* jconfig.cfg --- source file edited by configure script */ 3 | /* see jconfig.doc for explanations */ 4 | 5 | #define HAVE_PROTOTYPES 6 | #define HAVE_UNSIGNED_CHAR 7 | #define HAVE_UNSIGNED_SHORT 8 | #undef void 9 | #undef const 10 | #undef CHAR_IS_UNSIGNED 11 | #define HAVE_STDDEF_H 12 | #define HAVE_STDLIB_H 13 | #undef NEED_BSD_STRINGS 14 | #undef NEED_SYS_TYPES_H 15 | #undef NEED_FAR_POINTERS 16 | #undef NEED_SHORT_EXTERNAL_NAMES 17 | #undef INCOMPLETE_TYPES_BROKEN 18 | 19 | -------------------------------------------------------------------------------- /gaps/pkgs/jpeg/jversion.h: -------------------------------------------------------------------------------- 1 | /* 2 | * jversion.h 3 | * 4 | * Copyright (C) 1991-1998, Thomas G. Lane. 5 | * This file is part of the Independent JPEG Group's software. 6 | * For conditions of distribution and use, see the accompanying README file. 7 | * 8 | * This file contains software version identification. 9 | */ 10 | 11 | 12 | #define JVERSION "6b 27-Mar-1998" 13 | 14 | #define JCOPYRIGHT "Copyright (C) 1998, Thomas G. Lane" 15 | -------------------------------------------------------------------------------- /gaps/pkgs/png/Makefile: -------------------------------------------------------------------------------- 1 | # 2 | # Package name 3 | # 4 | 5 | NAME=png 6 | 7 | 8 | 9 | # 10 | # List of source files 11 | # 12 | 13 | # JPEG library source files 14 | PNG_CSRCS = \ 15 | png.c \ 16 | pngset.c \ 17 | pngget.c \ 18 | pngrutil.c \ 19 | pngtrans.c \ 20 | pngwutil.c \ 21 | pngread.c \ 22 | pngrio.c \ 23 | pngwio.c \ 24 | pngwrite.c \ 25 | pngrtran.c \ 26 | pngwtran.c \ 27 | pngmem.c \ 28 | pngerror.c \ 29 | pngpread.c 30 | 31 | ZLIB_CSRCS = \ 32 | adler32.c \ 33 | compress.c \ 34 | crc32.c \ 35 | deflate.c \ 36 | gzclose.c \ 37 | gzlib.c \ 38 | gzread.c \ 39 | gzwrite.c \ 40 | infback.c \ 41 | inffast.c \ 42 | inflate.c \ 43 | inftrees.c \ 44 | trees.c \ 45 | uncompr.c \ 46 | zutil.c 47 | 48 | CSRCS = $(PNG_CSRCS) $(ZLIB_CSRCS) 49 | 50 | 51 | 52 | # 53 | # GAPS library makefile 54 | # 55 | 56 | include ../../makefiles/Makefile.pkgs 57 | 58 | 59 | 60 | -------------------------------------------------------------------------------- /gaps/pkgs/png/compress.c: -------------------------------------------------------------------------------- 1 | /* compress.c -- compress a memory buffer 2 | * Copyright (C) 1995-2005 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Compresses the source buffer into the destination buffer. The level 13 | parameter has the same meaning as in deflateInit. sourceLen is the byte 14 | length of the source buffer. Upon entry, destLen is the total size of the 15 | destination buffer, which must be at least 0.1% larger than sourceLen plus 16 | 12 bytes. Upon exit, destLen is the actual size of the compressed buffer. 17 | 18 | compress2 returns Z_OK if success, Z_MEM_ERROR if there was not enough 19 | memory, Z_BUF_ERROR if there was not enough room in the output buffer, 20 | Z_STREAM_ERROR if the level parameter is invalid. 21 | */ 22 | int ZEXPORT compress2 (dest, destLen, source, sourceLen, level) 23 | Bytef *dest; 24 | uLongf *destLen; 25 | const Bytef *source; 26 | uLong sourceLen; 27 | int level; 28 | { 29 | z_stream stream; 30 | int err; 31 | 32 | stream.next_in = (Bytef*)source; 33 | stream.avail_in = (uInt)sourceLen; 34 | #ifdef MAXSEG_64K 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | #endif 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | stream.opaque = (voidpf)0; 45 | 46 | err = deflateInit(&stream, level); 47 | if (err != Z_OK) return err; 48 | 49 | err = deflate(&stream, Z_FINISH); 50 | if (err != Z_STREAM_END) { 51 | deflateEnd(&stream); 52 | return err == Z_OK ? Z_BUF_ERROR : err; 53 | } 54 | *destLen = stream.total_out; 55 | 56 | err = deflateEnd(&stream); 57 | return err; 58 | } 59 | 60 | /* =========================================================================== 61 | */ 62 | int ZEXPORT compress (dest, destLen, source, sourceLen) 63 | Bytef *dest; 64 | uLongf *destLen; 65 | const Bytef *source; 66 | uLong sourceLen; 67 | { 68 | return compress2(dest, destLen, source, sourceLen, Z_DEFAULT_COMPRESSION); 69 | } 70 | 71 | /* =========================================================================== 72 | If the default memLevel or windowBits for deflateInit() is changed, then 73 | this function needs to be updated. 74 | */ 75 | uLong ZEXPORT compressBound (sourceLen) 76 | uLong sourceLen; 77 | { 78 | return sourceLen + (sourceLen >> 12) + (sourceLen >> 14) + 79 | (sourceLen >> 25) + 13; 80 | } 81 | -------------------------------------------------------------------------------- /gaps/pkgs/png/config.h: -------------------------------------------------------------------------------- 1 | /* config.h. Generated from config.h.in by configure. */ 2 | /* config.h.in. Generated from configure.ac by autoheader. */ 3 | 4 | /* Define to 1 if you have the header file. */ 5 | #define HAVE_DLFCN_H 1 6 | 7 | /* Define to 1 if you have the header file. */ 8 | #define HAVE_INTTYPES_H 1 9 | 10 | /* Define to 1 if you have the `m' library (-lm). */ 11 | /* #undef HAVE_LIBM */ 12 | 13 | /* Define to 1 if you have the `z' library (-lz). */ 14 | #define HAVE_LIBZ 1 15 | 16 | /* Define to 1 if you have the header file. */ 17 | #define HAVE_MALLOC_H 1 18 | 19 | /* Define to 1 if you have the header file. */ 20 | #define HAVE_MEMORY_H 1 21 | 22 | /* Define to 1 if you have the `memset' function. */ 23 | #define HAVE_MEMSET 1 24 | 25 | /* Define to 1 if you have the `pow' function. */ 26 | #define HAVE_POW 1 27 | 28 | /* Define to 1 if you have the header file. */ 29 | #define HAVE_STDINT_H 1 30 | 31 | /* Define to 1 if you have the header file. */ 32 | #define HAVE_STDLIB_H 1 33 | 34 | /* Define to 1 if you have the header file. */ 35 | #define HAVE_STRINGS_H 1 36 | 37 | /* Define to 1 if you have the header file. */ 38 | #define HAVE_STRING_H 1 39 | 40 | /* Define to 1 if you have the header file. */ 41 | #define HAVE_SYS_STAT_H 1 42 | 43 | /* Define to 1 if you have the header file. */ 44 | #define HAVE_SYS_TYPES_H 1 45 | 46 | /* Define to 1 if you have the header file. */ 47 | #define HAVE_UNISTD_H 1 48 | 49 | /* Define to the sub-directory in which libtool stores uninstalled libraries. 50 | */ 51 | #define LT_OBJDIR ".libs/" 52 | 53 | /* Name of package */ 54 | #define PACKAGE "libpng" 55 | 56 | /* Define to the address where bug reports for this package should be sent. */ 57 | #define PACKAGE_BUGREPORT "png-mng-implement@lists.sourceforge.net" 58 | 59 | /* Define to the full name of this package. */ 60 | #define PACKAGE_NAME "libpng" 61 | 62 | /* Define to the full name and version of this package. */ 63 | #define PACKAGE_STRING "libpng 1.4.4" 64 | 65 | /* Define to the one symbol short name of this package. */ 66 | #define PACKAGE_TARNAME "libpng" 67 | 68 | /* Define to the home page for this package. */ 69 | #define PACKAGE_URL "" 70 | 71 | /* Define to the version of this package. */ 72 | #define PACKAGE_VERSION "1.4.4" 73 | 74 | /* Define to 1 if you have the ANSI C header files. */ 75 | #define STDC_HEADERS 1 76 | 77 | /* Define to 1 if your declares `struct tm'. */ 78 | /* #undef TM_IN_SYS_TIME */ 79 | 80 | /* Version number of package */ 81 | #define VERSION "1.4.4" 82 | 83 | /* Define to empty if `const' does not conform to ANSI C. */ 84 | /* #undef const */ 85 | 86 | /* Define to `unsigned int' if does not define. */ 87 | /* #undef size_t */ 88 | -------------------------------------------------------------------------------- /gaps/pkgs/png/gzclose.c: -------------------------------------------------------------------------------- 1 | /* gzclose.c -- zlib gzclose() function 2 | * Copyright (C) 2004, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | #include "gzguts.h" 7 | 8 | /* gzclose() is in a separate file so that it is linked in only if it is used. 9 | That way the other gzclose functions can be used instead to avoid linking in 10 | unneeded compression or decompression routines. */ 11 | int ZEXPORT gzclose(file) 12 | gzFile file; 13 | { 14 | #ifndef NO_GZCOMPRESS 15 | gz_statep state; 16 | 17 | if (file == NULL) 18 | return Z_STREAM_ERROR; 19 | state = (gz_statep)file; 20 | 21 | return state->mode == GZ_READ ? gzclose_r(file) : gzclose_w(file); 22 | #else 23 | return gzclose_r(file); 24 | #endif 25 | } 26 | -------------------------------------------------------------------------------- /gaps/pkgs/png/inffast.h: -------------------------------------------------------------------------------- 1 | /* inffast.h -- header to use inffast.c 2 | * Copyright (C) 1995-2003, 2010 Mark Adler 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* WARNING: this file should *not* be used by applications. It is 7 | part of the implementation of the compression library and is 8 | subject to change. Applications should only use zlib.h. 9 | */ 10 | 11 | void ZLIB_INTERNAL inflate_fast OF((z_streamp strm, unsigned start)); 12 | -------------------------------------------------------------------------------- /gaps/pkgs/png/uncompr.c: -------------------------------------------------------------------------------- 1 | /* uncompr.c -- decompress a memory buffer 2 | * Copyright (C) 1995-2003, 2010 Jean-loup Gailly. 3 | * For conditions of distribution and use, see copyright notice in zlib.h 4 | */ 5 | 6 | /* @(#) $Id$ */ 7 | 8 | #define ZLIB_INTERNAL 9 | #include "zlib.h" 10 | 11 | /* =========================================================================== 12 | Decompresses the source buffer into the destination buffer. sourceLen is 13 | the byte length of the source buffer. Upon entry, destLen is the total 14 | size of the destination buffer, which must be large enough to hold the 15 | entire uncompressed data. (The size of the uncompressed data must have 16 | been saved previously by the compressor and transmitted to the decompressor 17 | by some mechanism outside the scope of this compression library.) 18 | Upon exit, destLen is the actual size of the compressed buffer. 19 | 20 | uncompress returns Z_OK if success, Z_MEM_ERROR if there was not 21 | enough memory, Z_BUF_ERROR if there was not enough room in the output 22 | buffer, or Z_DATA_ERROR if the input data was corrupted. 23 | */ 24 | int ZEXPORT uncompress (dest, destLen, source, sourceLen) 25 | Bytef *dest; 26 | uLongf *destLen; 27 | const Bytef *source; 28 | uLong sourceLen; 29 | { 30 | z_stream stream; 31 | int err; 32 | 33 | stream.next_in = (Bytef*)source; 34 | stream.avail_in = (uInt)sourceLen; 35 | /* Check for source > 64K on 16-bit machine: */ 36 | if ((uLong)stream.avail_in != sourceLen) return Z_BUF_ERROR; 37 | 38 | stream.next_out = dest; 39 | stream.avail_out = (uInt)*destLen; 40 | if ((uLong)stream.avail_out != *destLen) return Z_BUF_ERROR; 41 | 42 | stream.zalloc = (alloc_func)0; 43 | stream.zfree = (free_func)0; 44 | 45 | err = inflateInit(&stream); 46 | if (err != Z_OK) return err; 47 | 48 | err = inflate(&stream, Z_FINISH); 49 | if (err != Z_STREAM_END) { 50 | inflateEnd(&stream); 51 | if (err == Z_NEED_DICT || (err == Z_BUF_ERROR && stream.avail_in == 0)) 52 | return Z_DATA_ERROR; 53 | return err; 54 | } 55 | *destLen = stream.total_out; 56 | 57 | err = inflateEnd(&stream); 58 | return err; 59 | } 60 | -------------------------------------------------------------------------------- /matlab/GenerateOcclusionWeight.m: -------------------------------------------------------------------------------- 1 | function GenerateOcclusionWeight( input_dir, output_dir ) 2 | %GENERATEOCCLUSIONWEIGHT Convert the boundary estimation to occlusion 3 | %weight used by optimization 4 | if ~exist(output_dir, 'dir') 5 | mkdir(output_dir); 6 | end 7 | 8 | files = dir([input_dir '/*_bound_est.png']); 9 | for a = 1:length(files) 10 | fprintf('%d/%d\n',a, length(files)); 11 | bound = imread(fullfile(input_dir, files(a).name)); 12 | bound = im2double(bound); 13 | weight = (1-bound(:,:,2)).^3; 14 | imwrite(uint16(weight*1000), fullfile(output_dir, strrep(files(a).name, '_bound_est.png', '_weight.png'))); 15 | end 16 | 17 | end 18 | 19 | -------------------------------------------------------------------------------- /matlab/demo_realsense.m: -------------------------------------------------------------------------------- 1 | %% Demo for depth completion on RGBD images from Intel Realsense. 2 | % Torch must be installed. 3 | % If command lines cannot be called, please copy and run them in terminal. 4 | 5 | cd('../torch/'); 6 | 7 | % Boundary detection 8 | cmd = 'th main_test_bound_realsense.lua -test_model ../pre_train_model/bound.t7 -test_file ./data_list/realsense_list.txt -root_path ../data/realsense/'; 9 | system(cmd); % the result should be in ../torch/result/ 10 | 11 | % Surface normal estimation 12 | cmd = 'th main_test_realsense.lua -test_model ../pre_train_model/normal_scannet.t7 -test_file ./data_list/realsense_list.txt -root_path ../data/realsense/'; 13 | system(cmd); 14 | 15 | cd('../matlab/'); 16 | 17 | % Get occlusion boundary (the 2nd channel) and convert to weight 18 | GenerateOcclusionWeight('../torch/result/bound_realsense_test_bound/', '../torch/result/bound_realsense_weight/'); 19 | 20 | % Compose depth by global optimization 21 | composeDepth('../data/', '../torch/result/normal_scannet_realsense_test', '../torch/result/bound_realsense_weight', 'realsense', '../results/realsense/', [1000, 0.001, 1]); 22 | 23 | % Visualize results 24 | input = imread('../data/realsense/030_depth_open.png'); 25 | output = imread('../results/realsense/realsense_030_1.png'); 26 | colormap = jet(double(max([input(:);output(:)]))); 27 | figure; 28 | subplot(1,2,1); imshow(label2rgb(input, colormap)); title('Input'); 29 | subplot(1,2,2); imshow(label2rgb(output,colormap)); title('Output'); 30 | -------------------------------------------------------------------------------- /pre_calc_result/README.md: -------------------------------------------------------------------------------- 1 | # Pre-computed Result of Our Method 2 | 3 | For the sake of comparison, we provide our results on Matterport3D and ScanNet. Please check [`./torch/data_list/`] folder for the list of testing images. Since the testing data also comes from original dataset, you need to get access before downloading the pre-computed results. 4 | 5 | Files you will get upon dataset access: 6 | - matterport_normal.zip: result on Matterport3D (Require Matterport3D access) 7 | - scannet_normal.zip: result on ScanNet (Require ScanNet access) -------------------------------------------------------------------------------- /pre_train_model/README.md: -------------------------------------------------------------------------------- 1 | # Pretrained Models 2 | 3 | Find the urls below for pretrained network weights: 4 | - bound.t7: Occlusion detection model trained on SUNCG-RGBD. Download: http://deepcompletion.cs.princeton.edu/public/pre_train_model/bound.t7 5 | - normal_matterport.t7: Normal estimation model trained on rendered ground truth from Matterport3D. Download: http://deepcompletion.cs.princeton.edu/public/pre_train_model/normal_matterport.t7 6 | - normal_scannet.t7: Normal estiamtion model trained on rendered ground truth from ScanNet. Download: http://deepcompletion.cs.princeton.edu/public/pre_train_model/normal_scannet.t7 7 | - sync.t7: Normal estimation model trained on SUNCG-RGBD. Download: http://deepcompletion.cs.princeton.edu/public/pre_train_model/sync.t7 8 | - sync_mp.t7: Normal estimation model trained on raw Matterport3D data. Download: http://deepcompletion.cs.princeton.edu/public/pre_train_model/sync_mp.t7 9 | -------------------------------------------------------------------------------- /results/realsense/realsense_004_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/results/realsense/realsense_004_1.png -------------------------------------------------------------------------------- /results/realsense/realsense_012_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/results/realsense/realsense_012_1.png -------------------------------------------------------------------------------- /results/realsense/realsense_026_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/results/realsense/realsense_026_1.png -------------------------------------------------------------------------------- /results/realsense/realsense_030_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/results/realsense/realsense_030_1.png -------------------------------------------------------------------------------- /results/realsense/realsense_046_1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/results/realsense/realsense_046_1.png -------------------------------------------------------------------------------- /torch/README.md: -------------------------------------------------------------------------------- 1 | # Torch implementation of occlusion detection and surface normal estimation 2 | 3 | ## Data lists 4 | The training and testing data lists can be found in `./data_list/`. Specifically: 5 | - `sync_*` are for occlusion detection. 6 | - `mp_*` are for normal estimation on Matterport3D. 7 | - `scannet_*` are for normal estimation on ScanNet. 8 | 9 | ## Occlusion detection 10 | 11 | ### Testing 12 | Run 13 | ``` 14 | th main_test_bound_realsense.lua -test_model ../pre_train_model/bound.t7 -test_file ./data_list/realsense_list.txt -root_path ../data/realsense/ 15 | ``` 16 | 17 | The result will be generated in `./result/bound_realsense_test_bound/`. On ScanNet and Matterport3d, you may use `main_test_bound_[scannet/matterport].lus` to test on `./data_list/scannet_test_list_small.txt` and `./data_list/mp_test_list_horizontal.txt`. 18 | 19 | ### Training 20 | Run 21 | ``` 22 | th main_train_bound.lua -pretrain_file ../pre_train_model/sync.t7 -root_path ../data/pbrs_boundary/ -ps ./model/bound 23 | ``` 24 | 25 | The snapshots and models will be saved under `./model/`. 26 | 27 | ## Surface normal estimation 28 | 29 | ### Testing 30 | Run 31 | ``` 32 | th main_test_realsense.lua -test_model ../pre_train_model/normal_scannet.t7 -test_file ./data_list/realsense_list.txt -root_path ../data/realsense/ 33 | ``` 34 | 35 | The result will be generated in `./result/normal_scannet_realsense_test/`. On ScanNet and Matterport3d, you may use `main_test_[scannet/matterport].lus` to test on `./data_list/scannet_test_list_small.txt` and `./data_list/mp_test_list_horizontal.txt`. 36 | 37 | ### Training 38 | Run 39 | ``` 40 | th main_train_matterport.lua -ps ./model/normal_matterport -use_render_normal_gt -root_path ../data/to_matterport/ 41 | ``` 42 | 43 | The snapshots and models will be saved under `./model/`. Noted that you need to download color image from official Matterport3D dataset in order to train the model. Same as before, you can use `main_train_scannet.lua` to train on ScanNet. 44 | -------------------------------------------------------------------------------- /torch/config.lua: -------------------------------------------------------------------------------- 1 | require "utils" 2 | --- All parameters goes here 3 | local config = config or {} 4 | 5 | function config.parse(arg) 6 | local cmd = torch.CmdLine() 7 | cmd:text() 8 | cmd:text('Multi-Task Classification FCN') 9 | cmd:text() 10 | -- Parameters 11 | 12 | -- model configuration 13 | cmd:option('-model', 'model_deep.lua', 'model file') 14 | cmd:option('-input_channel', 3, '# of input channels') 15 | cmd:option('-output_channel', 3, '# of output channels') 16 | 17 | -- testing 18 | cmd:option('-test_model', '', 'model used for testing') 19 | cmd:option('-result_path', './result/', 'path to save result') 20 | cmd:option('-max_count', 1000000, 'max number of data to test') 21 | 22 | -- data loader 23 | cmd:option('-train_file', './data_list/sync_train_list.txt', 'train file, compulsory'); 24 | cmd:option('-test_file', './data_list/sync_test_list_small.txt', 'test file, compulsory'); 25 | cmd:option('-pretrain_file', '../pre_train_model/sync.t7', 'path to pretrained model'); 26 | cmd:option('-data_root', '********', 'path to suncg data'); 27 | 28 | -- training and testing 29 | cmd:option('-gpuid', 1, 'gpu id') 30 | cmd:option('-optim_state', {rho=0.95, eps=1e-6, learningRate=1e-3, learningRateMin=1e-7, momentum=0.9}, 'optim state') 31 | cmd:option('-lr_decay', 1000000, 'iterations between lr decreses') 32 | cmd:option('-lr_decay_t', 5, 'lr decay times') 33 | cmd:option('-nb_epoch', 20, 'number of epoches') 34 | cmd:option('-batch_size', 1, 'batch size') 35 | cmd:option('-pixel_means', {128, 128, 128}, 'Pixel mean values (RGB order)') 36 | 37 | -- resume 38 | cmd:option('-resume_training', false, 'whether resume training') 39 | cmd:option('-saved_model_weights', '', 'path to saved model weights') 40 | cmd:option('-saved_optim_state', '', 'path to saved model weights') 41 | 42 | -- finetune 43 | cmd:option('-finetune', false, '') 44 | cmd:option('-finetune_model', '', '') 45 | cmd:option('-finetune_init_lr', 1e-4, '') 46 | 47 | -- save/print/log 48 | cmd:option('-snapshot_iters', 50000, 'Iterations between snapshots (used for saving the network)') 49 | cmd:option('-print_iters', 20, 'Iterations between print') 50 | cmd:option('-log_iters', 20, 'Iterations between log') 51 | cmd:option('-log_path','./logs/','Path to be used for logging') 52 | cmd:option('-ps', '', 'prefix: path&name to model and snapshot') 53 | cmd:option('-verbose', false, 'show more message') 54 | 55 | -- Parsing the command line 56 | config = cmd:parse(arg or {}) 57 | config.colors = {{0, 0, 0}, -- black 58 | {1, 0, 0}, -- red 59 | {0, 1, 0}, -- green 60 | {0, 0, 1}, -- blue 61 | {1, 1, 0}, -- yellow 62 | {1, 0, 1}, -- magenta 63 | {0, 1, 1}, -- cyan 64 | {1, 1, 1} -- white 65 | } 66 | 67 | return config 68 | end 69 | 70 | return config 71 | -------------------------------------------------------------------------------- /torch/config_scannet.lua: -------------------------------------------------------------------------------- 1 | require "utils" 2 | --- All parameters goes here 3 | local config = config or {} 4 | 5 | function config.parse(arg) 6 | local cmd = torch.CmdLine() 7 | cmd:text() 8 | cmd:text('Multi-Task Classification FCN') 9 | cmd:text() 10 | -- Parameters 11 | 12 | -- model configuration 13 | cmd:option('-model', 'model_deep.lua', 'model file') 14 | cmd:option('-model_nobn', 'model_deep_new.lua', 'model file without the last bn layer') 15 | cmd:option('-input_channel', 3, '# of input channels') 16 | cmd:option('-output_channel', 3, '# of output channels') 17 | 18 | -- testing 19 | cmd:option('-test_model', '', 'model used for testing') 20 | cmd:option('-result_path', './result/', 'path to save result') 21 | cmd:option('-max_count', 1000000, 'max number of data to test') 22 | 23 | -- data loader 24 | cmd:option('-root_path', '/n/fs/rgbd/data/scannet/public/v1/scans/', 'path to the root of the dataset') 25 | cmd:option('-train_file', './data_list/scannet_train_list.txt', 'train file, compulsory'); 26 | cmd:option('-test_file', './data_list/scannet_test_list_small.txt', 'test file, compulsory'); 27 | 28 | -- training and testing 29 | cmd:option('-gpuid', 1, 'gpu id') 30 | cmd:option('-optim_state', {rho=0.95, eps=1e-6, learningRate=1e-3, learningRateMin=1e-7, momentum=0.9}, 'optim state') 31 | cmd:option('-lr_decay', 100000, 'iterations between lr decreses') 32 | cmd:option('-lr_decay_t', 5, 'lr decay times') 33 | cmd:option('-nb_epoch', 20, 'number of epoches') 34 | cmd:option('-batch_size', 1, 'batch size') 35 | cmd:option('-pixel_means', {128, 128, 128}, 'Pixel mean values (RGB order)') 36 | 37 | -- resume 38 | cmd:option('-resume_training', false, 'whether resume training') 39 | cmd:option('-saved_model_weights', '', 'path to saved model weights') 40 | cmd:option('-saved_optim_state', '', 'path to saved model weights') 41 | 42 | -- finetune 43 | -- cmd:option('-finetune', false, '') 44 | cmd:option('-finetune_model', '../pre_train_model/sync_mp.t7', '') 45 | cmd:option('-finetune_init_lr', 1e-4, '') 46 | 47 | -- save/print/log 48 | cmd:option('-snapshot_iters',50000, 'Iterations between snapshots (used for saving the network)') 49 | cmd:option('-print_iters', 20, 'Iterations between print') 50 | cmd:option('-log_iters', 20, 'Iterations between log') 51 | cmd:option('-log_path','./logs/','Path to be used for logging') 52 | cmd:option('-ps', '', 'prefix: path&name to model and snapshot') 53 | cmd:option('-verbose', false, 'show more message') 54 | 55 | -- Parsing the command line 56 | config = cmd:parse(arg or {}) 57 | config.colors = {{0, 0, 0}, -- black 58 | {1, 0, 0}, -- red 59 | {0, 1, 0}, -- green 60 | {0, 0, 1}, -- blue 61 | {1, 1, 0}, -- yellow 62 | {1, 0, 1}, -- magenta 63 | {0, 1, 1}, -- cyan 64 | {1, 1, 1} -- white 65 | } 66 | 67 | 68 | return config 69 | end 70 | 71 | return config 72 | -------------------------------------------------------------------------------- /torch/data_list/realsense_list.txt: -------------------------------------------------------------------------------- 1 | 004 2 | 012 3 | 026 4 | 030 5 | 046 -------------------------------------------------------------------------------- /torch/main_test_bound_matterport.lua: -------------------------------------------------------------------------------- 1 | require 'nn' 2 | require 'cutorch' 3 | require 'cunn' 4 | require 'cudnn' 5 | require 'nngraph' 6 | require 'optim' 7 | require 'image' 8 | 9 | require 'BatchIterator' 10 | require 'utils' 11 | require 'utils_matterport' 12 | require 'BatchIterator_matterport' 13 | -- require 'hdf5' 14 | 15 | local config = dofile('config.lua') 16 | config = config.parse(arg) 17 | print(config) 18 | cutorch.setDevice(config.gpuid) 19 | 20 | local tmp1 = split(config.test_model, "/") 21 | config.result_path = config.result_path .. "/" .. string.sub(tmp1[#tmp1],1,-4) 22 | 23 | 24 | config.result_path = config.result_path .. "_matterport_test_bound/" 25 | 26 | os.execute("mkdir " .. config.result_path) 27 | 28 | local model = dofile(config.model)(config) 29 | 30 | parameters, gradParameters = model:getParameters() 31 | model.forwardnodes[24].data.module.modules[1]:__init(128,64,3,3,1,1,1,1) 32 | model.forwardnodes[24].data.module.modules[2]:__init(64,nil,nil,nil) 33 | model.forwardnodes[24].data.module.modules[4]:__init(64,3,3,3,1,1,1,1) 34 | model.forwardnodes[24].data.module.modules[5]:__init(3,nil,nil,nil) 35 | 36 | model:cuda() 37 | parameters, gradParameters = model:getParameters() 38 | parameters:copy(torch.load(config.test_model)) 39 | 40 | -- dataset 41 | local train_data = {} 42 | local test_data = loadMatterport(config.test_file, config.root_path) 43 | local batch_iterator = BatchIterator(config, train_data, test_data) 44 | batch_iterator:setBatchSize(1) 45 | 46 | local test_count = 0 47 | local softmax_layer = nn.SoftMax():cuda() 48 | 49 | while batch_iterator.epoch==0 and test_count<#batch_iterator.test.data do 50 | local batch = batch_iterator:nextBatchMatterport('test', config) 51 | local currName = batch_iterator:currentName('test') 52 | print(currName) 53 | local k = split(currName, "/") 54 | saveName = k[#k-2] .. "_" .. k[#k] 55 | print(string.format("Testing %s", saveName)) 56 | 57 | 58 | local inputs = batch.pr_color 59 | inputs = inputs:contiguous():cuda() 60 | local outputs = model:forward(inputs) 61 | 62 | bound_est = outputs 63 | ch, h, w = bound_est:size(2), bound_est:size(3), bound_est:size(4) 64 | bound_est = bound_est:permute(1, 3, 4, 2):contiguous() 65 | bound_est = bound_est:view(-1, ch) 66 | 67 | bound_outputs = softmax_layer:forward(bound_est) 68 | bound_outputs = bound_outputs:view(1, h, w, ch) 69 | bound_outputs = bound_outputs:permute(1, 4, 2, 3):contiguous() 70 | bound_outputs = bound_outputs:view( ch, h, w) 71 | bound_outputs = bound_outputs:float() 72 | 73 | image.save(string.format("%s%s_bound_est.png", config.result_path, saveName), bound_outputs) 74 | 75 | test_count = test_count + 1 76 | end 77 | 78 | print("Finish!") 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /torch/main_test_bound_realsense.lua: -------------------------------------------------------------------------------- 1 | require 'nn' 2 | require 'cutorch' 3 | require 'cunn' 4 | require 'cudnn' 5 | require 'nngraph' 6 | require 'optim' 7 | require 'image' 8 | 9 | require 'BatchIterator' 10 | require 'utils' 11 | require 'utils_scannet' 12 | require 'BatchIterator_scannet' 13 | -- require 'hdf5' 14 | 15 | local config = dofile('config_scannet.lua') 16 | config = config.parse(arg) 17 | print(config) 18 | cutorch.setDevice(config.gpuid) 19 | 20 | local tmp1 = split(config.test_model, "/") 21 | config.result_path = config.result_path .. "/" .. string.sub(tmp1[#tmp1],1,-4) 22 | 23 | 24 | config.result_path = config.result_path .. "_realsense_test_bound/" 25 | 26 | os.execute("mkdir " .. config.result_path) 27 | 28 | local model = dofile(config.model)(config) 29 | 30 | parameters, gradParameters = model:getParameters() 31 | model.forwardnodes[24].data.module.modules[1]:__init(128,64,3,3,1,1,1,1) 32 | model.forwardnodes[24].data.module.modules[2]:__init(64,nil,nil,nil) 33 | model.forwardnodes[24].data.module.modules[4]:__init(64,3,3,3,1,1,1,1) 34 | model.forwardnodes[24].data.module.modules[5]:__init(3,nil,nil,nil) 35 | 36 | model:cuda() 37 | parameters, gradParameters = model:getParameters() 38 | parameters:copy(torch.load(config.test_model)) 39 | 40 | -- dataset 41 | local train_data = {} 42 | local test_data = loadRealsense(config.test_file, config.root_path) 43 | local batch_iterator = BatchIterator(config, train_data, test_data) 44 | batch_iterator:setBatchSize(1) 45 | 46 | local test_count = 0 47 | local softmax_layer = nn.SoftMax():cuda() 48 | 49 | while batch_iterator.epoch==0 and test_count<#batch_iterator.test.data do 50 | local batch = batch_iterator:nextBatchRealsense('test', config) 51 | local currName = batch_iterator:currentName('test') 52 | print(currName) 53 | local k = split(currName, "/") 54 | saveName = k[#k-1] .. "_" .. k[#k] 55 | print(string.format("Testing %s", saveName)) 56 | 57 | 58 | local inputs = batch.pr_color 59 | inputs = inputs:contiguous():cuda() 60 | local outputs = model:forward(inputs) 61 | 62 | bound_est = outputs 63 | ch, h, w = bound_est:size(2), bound_est:size(3), bound_est:size(4) 64 | bound_est = bound_est:permute(1, 3, 4, 2):contiguous() 65 | bound_est = bound_est:view(-1, ch) 66 | 67 | bound_outputs = softmax_layer:forward(bound_est) 68 | bound_outputs = bound_outputs:view(1, h, w, ch) 69 | bound_outputs = bound_outputs:permute(1, 4, 2, 3):contiguous() 70 | bound_outputs = bound_outputs:view( ch, h, w) 71 | bound_outputs = bound_outputs:float() 72 | 73 | image.save(string.format("%s%s_bound_est.png", config.result_path, saveName), bound_outputs) 74 | 75 | test_count = test_count + 1 76 | end 77 | 78 | print("Finish!") 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /torch/main_test_bound_scannet.lua: -------------------------------------------------------------------------------- 1 | require 'nn' 2 | require 'cutorch' 3 | require 'cunn' 4 | require 'cudnn' 5 | require 'nngraph' 6 | require 'optim' 7 | require 'image' 8 | 9 | require 'BatchIterator' 10 | require 'utils' 11 | require 'utils_scannet' 12 | require 'BatchIterator_scannet' 13 | -- require 'hdf5' 14 | 15 | local config = dofile('config_scannet.lua') 16 | config = config.parse(arg) 17 | print(config) 18 | cutorch.setDevice(config.gpuid) 19 | 20 | local tmp1 = split(config.test_model, "/") 21 | config.result_path = config.result_path .. "/" .. string.sub(tmp1[#tmp1],1,-4) 22 | 23 | 24 | config.result_path = config.result_path .. "_scannet_test_bound/" 25 | 26 | os.execute("mkdir " .. config.result_path) 27 | 28 | local model = dofile(config.model)(config) 29 | 30 | parameters, gradParameters = model:getParameters() 31 | model.forwardnodes[24].data.module.modules[1]:__init(128,64,3,3,1,1,1,1) 32 | model.forwardnodes[24].data.module.modules[2]:__init(64,nil,nil,nil) 33 | model.forwardnodes[24].data.module.modules[4]:__init(64,3,3,3,1,1,1,1) 34 | model.forwardnodes[24].data.module.modules[5]:__init(3,nil,nil,nil) 35 | 36 | model:cuda() 37 | parameters, gradParameters = model:getParameters() 38 | parameters:copy(torch.load(config.test_model)) 39 | 40 | -- dataset 41 | local train_data = {} 42 | local test_data = loadScanNetRender(config.test_file, config.root_path) 43 | local batch_iterator = BatchIterator(config, train_data, test_data) 44 | batch_iterator:setBatchSize(1) 45 | 46 | local test_count = 0 47 | local softmax_layer = nn.SoftMax():cuda() 48 | 49 | while batch_iterator.epoch==0 and test_count<#batch_iterator.test.data do 50 | local batch = batch_iterator:nextBatchScanNet('test', config) 51 | local currName = batch_iterator:currentName('test') 52 | print(currName) 53 | local k = split(currName, "/") 54 | saveName = k[#k-2] .. "_" .. k[#k] 55 | print(string.format("Testing %s", saveName)) 56 | 57 | 58 | local inputs = batch.pr_color 59 | inputs = inputs:contiguous():cuda() 60 | local outputs = model:forward(inputs) 61 | 62 | bound_est = outputs 63 | ch, h, w = bound_est:size(2), bound_est:size(3), bound_est:size(4) 64 | bound_est = bound_est:permute(1, 3, 4, 2):contiguous() 65 | bound_est = bound_est:view(-1, ch) 66 | 67 | bound_outputs = softmax_layer:forward(bound_est) 68 | bound_outputs = bound_outputs:view(1, h, w, ch) 69 | bound_outputs = bound_outputs:permute(1, 4, 2, 3):contiguous() 70 | bound_outputs = bound_outputs:view( ch, h, w) 71 | bound_outputs = bound_outputs:float() 72 | 73 | image.save(string.format("%s%s_bound_est.png", config.result_path, saveName), bound_outputs) 74 | 75 | test_count = test_count + 1 76 | end 77 | 78 | print("Finish!") 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | -------------------------------------------------------------------------------- /torch/main_test_matterport.lua: -------------------------------------------------------------------------------- 1 | require 'nn' 2 | require 'cutorch' 3 | require 'cunn' 4 | require 'cudnn' 5 | require 'nngraph' 6 | require 'optim' 7 | require 'image' 8 | 9 | require 'BatchIterator' 10 | require 'utils' 11 | require 'utils_matterport' 12 | require 'BatchIterator_matterport' 13 | require 'hdf5' 14 | 15 | local config = dofile('config_matterport.lua') 16 | config = config.parse(arg) 17 | print(config) 18 | cutorch.setDevice(config.gpuid) 19 | 20 | local tmp1 = split(config.test_model, "/") 21 | config.result_path = config.result_path .. "/" .. string.sub(tmp1[#tmp1],1,-4) 22 | 23 | 24 | config.result_path = config.result_path .. "_matterport_test/" 25 | 26 | os.execute("mkdir " .. config.result_path) 27 | 28 | local model = dofile(config.model_nobn)(config) 29 | model.forwardnodes[24].data.module.modules[1]:__init(128,64,3,3,1,1,1,1) 30 | model.forwardnodes[24].data.module.modules[3]:__init(64,3,3,3,1,1,1,1) 31 | model:cuda() 32 | parameters, gradParameters = model:getParameters() 33 | parameters:copy(torch.load(config.test_model)) 34 | 35 | 36 | -- dataset 37 | local train_data = {} 38 | local test_data = loadMatterportRender(config.test_file, config.root_path) 39 | local batch_iterator = BatchIterator(config, train_data, test_data) 40 | batch_iterator:setBatchSize(1) 41 | 42 | local test_count = 0 43 | 44 | while batch_iterator.epoch==0 and test_count<#batch_iterator.test.data do 45 | local batch = batch_iterator:nextBatchMatterport('test', config) 46 | local currName = batch_iterator:currentName('test') 47 | print(currName) 48 | local k = split(currName, "/") 49 | saveName = k[#k-2] .. "_" .. k[#k] 50 | print(string.format("Testing %s", saveName)) 51 | 52 | 53 | local inputs = batch.pr_color 54 | inputs = inputs:contiguous():cuda() 55 | local outputs = model:forward(inputs) 56 | 57 | local ch, h, w = 0, 0, 0 58 | local normal_est, normal_mask, normal_gnd, f_normal, df_do_normal, normal_outputs = nil,nil,nil,nil,nil,nil 59 | 60 | normal_est = outputs 61 | ch, h, w = normal_est:size(2), normal_est:size(3), normal_est:size(4) 62 | normal_est = normal_est:permute(1, 3, 4, 2):contiguous() 63 | normal_est = normal_est:view(-1, ch) 64 | local normalize_layer = nn.Normalize(2):cuda() 65 | normal_outputs = normalize_layer:forward(normal_est) 66 | normal_outputs = normal_outputs:view(1, h, w, ch) 67 | normal_outputs = normal_outputs:permute(1, 4, 2, 3):contiguous() 68 | normal_outputs = normal_outputs:view( ch, h, w) 69 | normal_outputs = normal_outputs:float() 70 | 71 | -- image.save(string.format("%s%s_normal_est.png", config.result_path, saveName), normal_outputs:add(1):mul(0.5)) 72 | myfile = hdf5.open(string.format("%s%s_normal_est.h5", config.result_path, saveName),'w') 73 | myfile:write('/result', normal_outputs:float()) 74 | myfile:close() 75 | 76 | 77 | test_count = test_count + 1 78 | end 79 | 80 | print("Finish!") 81 | 82 | 83 | -------------------------------------------------------------------------------- /torch/main_test_realsense.lua: -------------------------------------------------------------------------------- 1 | require 'nn' 2 | require 'cutorch' 3 | require 'cunn' 4 | require 'cudnn' 5 | require 'nngraph' 6 | require 'optim' 7 | require 'image' 8 | 9 | require 'BatchIterator' 10 | require 'utils' 11 | require 'utils_scannet' 12 | require 'BatchIterator_scannet' 13 | require 'hdf5' 14 | 15 | local config = dofile('config_scannet.lua') 16 | config = config.parse(arg) 17 | print(config) 18 | cutorch.setDevice(config.gpuid) 19 | 20 | local tmp1 = split(config.test_model, "/") 21 | config.result_path = config.result_path .. "/" .. string.sub(tmp1[#tmp1],1,-4) 22 | 23 | 24 | config.result_path = config.result_path .. "_realsense_test/" 25 | 26 | os.execute("mkdir " .. config.result_path) 27 | 28 | local model = dofile(config.model_nobn)(config) 29 | 30 | model.forwardnodes[24].data.module.modules[1]:__init(128,64,3,3,1,1,1,1) 31 | model.forwardnodes[24].data.module.modules[3]:__init(64,3,3,3,1,1,1,1) 32 | 33 | parameters, gradParameters = model:getParameters() 34 | model:cuda() 35 | parameters, gradParameters = model:getParameters() 36 | parameters:copy(torch.load(config.test_model)) 37 | print('Test model loaded') 38 | 39 | 40 | -- dataset 41 | local train_data = {} 42 | local test_data = loadRealsense(config.test_file, config.root_path) 43 | local batch_iterator = BatchIterator(config, train_data, test_data) 44 | batch_iterator:setBatchSize(1) 45 | 46 | local test_count = 0 47 | 48 | while batch_iterator.epoch==0 and test_count<#batch_iterator.test.data do 49 | local batch = batch_iterator:nextBatchRealsense('test', config) 50 | local currName = batch_iterator:currentName('test') 51 | print(currName) 52 | local k = split(currName, "/") 53 | saveName = k[#k-1] .. "_" .. k[#k] 54 | print(string.format("Testing %s", saveName)) 55 | 56 | 57 | local inputs = batch.pr_color 58 | inputs = inputs:contiguous():cuda() 59 | local outputs = model:forward(inputs) 60 | 61 | local ch, h, w = 0, 0, 0 62 | local normal_est, normal_mask, normal_gnd, f_normal, df_do_normal, normal_outputs = nil,nil,nil,nil,nil,nil 63 | 64 | normal_est = outputs 65 | ch, h, w = normal_est:size(2), normal_est:size(3), normal_est:size(4) 66 | normal_est = normal_est:permute(1, 3, 4, 2):contiguous() 67 | normal_est = normal_est:view(-1, ch) 68 | local normalize_layer = nn.Normalize(2):cuda() 69 | normal_outputs = normalize_layer:forward(normal_est) 70 | normal_outputs = normal_outputs:view(1, h, w, ch) 71 | normal_outputs = normal_outputs:permute(1, 4, 2, 3):contiguous() 72 | normal_outputs = normal_outputs:view( ch, h, w) 73 | normal_outputs = normal_outputs:float() 74 | 75 | -- image.save(string.format("%s%s_normal_est.png", config.result_path, saveName), normal_outputs:add(1):mul(0.5)) 76 | myfile = hdf5.open(string.format("%s%s_normal_est.h5", config.result_path, saveName),'w') 77 | myfile:write('/result', normal_outputs:float()) 78 | myfile:close() 79 | 80 | 81 | test_count = test_count + 1 82 | end 83 | 84 | print("Finish!") 85 | 86 | 87 | -------------------------------------------------------------------------------- /torch/main_test_scannet.lua: -------------------------------------------------------------------------------- 1 | require 'nn' 2 | require 'cutorch' 3 | require 'cunn' 4 | require 'cudnn' 5 | require 'nngraph' 6 | require 'optim' 7 | require 'image' 8 | 9 | require 'BatchIterator' 10 | require 'utils' 11 | require 'utils_scannet' 12 | require 'BatchIterator_scannet' 13 | require 'hdf5' 14 | 15 | local config = dofile('config_scannet.lua') 16 | config = config.parse(arg) 17 | print(config) 18 | cutorch.setDevice(config.gpuid) 19 | 20 | local tmp1 = split(config.test_model, "/") 21 | config.result_path = config.result_path .. "/" .. string.sub(tmp1[#tmp1],1,-4) 22 | 23 | 24 | config.result_path = config.result_path .. "_scannet_test/" 25 | 26 | os.execute("mkdir " .. config.result_path) 27 | 28 | local model = dofile(config.model_nobn)(config) 29 | 30 | model.forwardnodes[24].data.module.modules[1]:__init(128,64,3,3,1,1,1,1) 31 | model.forwardnodes[24].data.module.modules[3]:__init(64,3,3,3,1,1,1,1) 32 | 33 | parameters, gradParameters = model:getParameters() 34 | model:cuda() 35 | parameters, gradParameters = model:getParameters() 36 | parameters:copy(torch.load(config.test_model)) 37 | print('Test model loaded') 38 | 39 | 40 | -- dataset 41 | local train_data = {} 42 | local test_data = loadScanNetRender(config.test_file, config.root_path) 43 | local batch_iterator = BatchIterator(config, train_data, test_data) 44 | batch_iterator:setBatchSize(1) 45 | 46 | local test_count = 0 47 | 48 | while batch_iterator.epoch==0 and test_count<#batch_iterator.test.data do 49 | local batch = batch_iterator:nextBatchScanNet('test', config) 50 | local currName = batch_iterator:currentName('test') 51 | print(currName) 52 | local k = split(currName, "/") 53 | saveName = k[#k-2] .. "_" .. k[#k] 54 | print(string.format("Testing %s", saveName)) 55 | 56 | 57 | local inputs = batch.pr_color 58 | inputs = inputs:contiguous():cuda() 59 | local outputs = model:forward(inputs) 60 | 61 | local ch, h, w = 0, 0, 0 62 | local normal_est, normal_mask, normal_gnd, f_normal, df_do_normal, normal_outputs = nil,nil,nil,nil,nil,nil 63 | 64 | normal_est = outputs 65 | ch, h, w = normal_est:size(2), normal_est:size(3), normal_est:size(4) 66 | normal_est = normal_est:permute(1, 3, 4, 2):contiguous() 67 | normal_est = normal_est:view(-1, ch) 68 | local normalize_layer = nn.Normalize(2):cuda() 69 | normal_outputs = normalize_layer:forward(normal_est) 70 | normal_outputs = normal_outputs:view(1, h, w, ch) 71 | normal_outputs = normal_outputs:permute(1, 4, 2, 3):contiguous() 72 | normal_outputs = normal_outputs:view( ch, h, w) 73 | normal_outputs = normal_outputs:float() 74 | 75 | -- image.save(string.format("%s%s_normal_est.png", config.result_path, saveName), normal_outputs:add(1):mul(0.5)) 76 | myfile = hdf5.open(string.format("%s%s_normal_est.h5", config.result_path, saveName),'w') 77 | myfile:write('/result', normal_outputs:float()) 78 | myfile:close() 79 | 80 | 81 | test_count = test_count + 1 82 | end 83 | 84 | print("Finish!") 85 | 86 | 87 | -------------------------------------------------------------------------------- /torch/result/bound_realsense_test_bound/realsense_004_bound_est.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/torch/result/bound_realsense_test_bound/realsense_004_bound_est.png -------------------------------------------------------------------------------- /torch/result/bound_realsense_test_bound/realsense_012_bound_est.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/torch/result/bound_realsense_test_bound/realsense_012_bound_est.png -------------------------------------------------------------------------------- /torch/result/bound_realsense_test_bound/realsense_026_bound_est.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/torch/result/bound_realsense_test_bound/realsense_026_bound_est.png -------------------------------------------------------------------------------- /torch/result/bound_realsense_test_bound/realsense_030_bound_est.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/torch/result/bound_realsense_test_bound/realsense_030_bound_est.png -------------------------------------------------------------------------------- /torch/result/bound_realsense_test_bound/realsense_046_bound_est.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/torch/result/bound_realsense_test_bound/realsense_046_bound_est.png -------------------------------------------------------------------------------- /torch/result/bound_realsense_weight/realsense_004_weight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/torch/result/bound_realsense_weight/realsense_004_weight.png -------------------------------------------------------------------------------- /torch/result/bound_realsense_weight/realsense_012_weight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/torch/result/bound_realsense_weight/realsense_012_weight.png -------------------------------------------------------------------------------- /torch/result/bound_realsense_weight/realsense_026_weight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/torch/result/bound_realsense_weight/realsense_026_weight.png -------------------------------------------------------------------------------- /torch/result/bound_realsense_weight/realsense_030_weight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/torch/result/bound_realsense_weight/realsense_030_weight.png -------------------------------------------------------------------------------- /torch/result/bound_realsense_weight/realsense_046_weight.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/torch/result/bound_realsense_weight/realsense_046_weight.png -------------------------------------------------------------------------------- /torch/result/normal_scannet_realsense_test/realsense_004_normal_est.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/torch/result/normal_scannet_realsense_test/realsense_004_normal_est.h5 -------------------------------------------------------------------------------- /torch/result/normal_scannet_realsense_test/realsense_012_normal_est.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/torch/result/normal_scannet_realsense_test/realsense_012_normal_est.h5 -------------------------------------------------------------------------------- /torch/result/normal_scannet_realsense_test/realsense_026_normal_est.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/torch/result/normal_scannet_realsense_test/realsense_026_normal_est.h5 -------------------------------------------------------------------------------- /torch/result/normal_scannet_realsense_test/realsense_030_normal_est.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/torch/result/normal_scannet_realsense_test/realsense_030_normal_est.h5 -------------------------------------------------------------------------------- /torch/result/normal_scannet_realsense_test/realsense_046_normal_est.h5: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/yindaz/DeepCompletionRelease/109e4dd2104f8a31bbfab88e6bd62ef659fbf313/torch/result/normal_scannet_realsense_test/realsense_046_normal_est.h5 -------------------------------------------------------------------------------- /torch/utils.lua: -------------------------------------------------------------------------------- 1 | function loadData(file_name, config) 2 | print(string.format("Loading data from %s", file_name)) 3 | local output = {} 4 | local file = io.open(file_name, "r") 5 | for line in file:lines() do 6 | 7 | local data = {} 8 | 9 | -- define data here, will be used in BatchIterator 10 | data.input_file = config.data_root .. line .. '_mlt.png' 11 | data.input_valid = config.data_root .. line .. '_valid.png' 12 | data.boundary = config.data_root .. line .. '_3d_boundary.png' 13 | data.name = config.data_root .. line 14 | -- end 15 | 16 | table.insert(output, data) 17 | end 18 | print(string.format("%d data loaded.",#output)) 19 | return output 20 | end 21 | 22 | function round(num, idp) 23 | local mult = 10^(idp or 0) 24 | return math.floor(num * mult + 0.5) / mult 25 | end 26 | 27 | function split(str, pat) 28 | local t = {} -- NOTE: use {n = 0} in Lua-5.0 29 | local fpat = "(.-)" .. pat 30 | local last_end = 1 31 | local s, e, cap = str:find(fpat, 1) 32 | while s do 33 | if s ~= 1 or cap ~= "" then 34 | table.insert(t,cap) 35 | end 36 | last_end = e+1 37 | s, e, cap = str:find(fpat, last_end) 38 | end 39 | if last_end <= #str then 40 | cap = str:sub(last_end) 41 | table.insert(t, cap) 42 | end 43 | return t 44 | end 45 | 46 | function file_exists(name) 47 | local f=io.open(name,"r") 48 | if f~=nil then io.close(f) return true else return false end 49 | end 50 | 51 | function bool2num(var) 52 | return var and 1 or 0 53 | end 54 | 55 | function read_weight(file_name) 56 | print(string.format("Loading weight from %s", file_name)) 57 | local file = io.open(file_name, "r") 58 | a = file:read("*all") 59 | b = string.split(a, '\n') 60 | w = torch.Tensor(table.getn(b)) 61 | for i = 1,table.getn(b),1 do 62 | w[i] = b[i] 63 | end 64 | return w 65 | end -------------------------------------------------------------------------------- /torch/utils_matterport.lua: -------------------------------------------------------------------------------- 1 | function loadMatterport(file_name, root_path) 2 | print(string.format("Loading data from %s", file_name)) 3 | local output = {} 4 | local file = io.open(file_name, "r") 5 | for line in file:lines() do 6 | line = root_path .. line 7 | 8 | local data = {} 9 | data.color = line 10 | 11 | baseline = line 12 | baseline = baseline:gsub("_i", "_d") 13 | baseline = baseline:gsub("undistorted_color_dmages", "undistorted_normal_images") 14 | 15 | data.nx = string.gsub(baseline, '.jpg', '_nx.png') 16 | data.ny = string.gsub(baseline, '.jpg', '_ny.png') 17 | data.nz = string.gsub(baseline, '.jpg', '_nz.png') 18 | 19 | baseline = line 20 | baseline = baseline:gsub("_i", "_d") 21 | baseline = baseline:gsub("undistorted_color_dmages", "undistorted_depth_images") 22 | data.depth = string.gsub(baseline, '.jpg', '.png') 23 | 24 | data.name = string.gsub(baseline, '.jpg', '') 25 | 26 | table.insert(output, data) 27 | end 28 | print(string.format("%d data loaded.",#output)) 29 | return output 30 | end 31 | 32 | 33 | function loadMatterportRender(file_name, root_path) 34 | print(string.format("Loading data from %s", file_name)) 35 | local output = {} 36 | local file = io.open(file_name, "r") 37 | for line in file:lines() do 38 | line = root_path .. line 39 | 40 | local data = {} 41 | data.color = line 42 | baseline = line 43 | baseline = baseline:gsub("_i", "_d") 44 | baseline = baseline:gsub("undistorted_color_dmages", "mesh_images") 45 | 46 | data.nx = string.gsub(baseline, '.jpg', '_mesh_nx.png') 47 | data.ny = string.gsub(baseline, '.jpg', '_mesh_ny.png') 48 | data.nz = string.gsub(baseline, '.jpg', '_mesh_nz.png') 49 | 50 | baseline = line 51 | baseline = baseline:gsub("_i", "_d") 52 | baseline = baseline:gsub("undistorted_color_dmages", "mesh_images") 53 | data.depth = string.gsub(baseline, '.jpg', '_mesh_depth.png') 54 | 55 | data.name = string.gsub(baseline, '.jpg', '') 56 | 57 | baseline = line 58 | baseline = baseline:gsub("_i", "_d") 59 | baseline = baseline:gsub("undistorted_color_dmages", "undistorted_depth_images") 60 | data.depth_raw = string.gsub(baseline, '.jpg', '.png') 61 | 62 | table.insert(output, data) 63 | end 64 | print(string.format("%d data loaded.",#output)) 65 | return output 66 | end 67 | 68 | -------------------------------------------------------------------------------- /torch/utils_scannet.lua: -------------------------------------------------------------------------------- 1 | function loadRealsense(file_name, root_path) 2 | print(string.format("Loading data from %s", file_name)) 3 | local output = {} 4 | local file = io.open(file_name, "r") 5 | for line in file:lines() do 6 | 7 | local data = {} 8 | 9 | baseline = root_path .. line 10 | data.color = baseline .. '_color.png' 11 | data.depth = baseline .. '_depth.png' 12 | 13 | data.name = baseline 14 | 15 | table.insert(output, data) 16 | end 17 | print(string.format("%d data loaded.",#output)) 18 | return output 19 | end 20 | 21 | function loadScanNetRender(file_name, root_path) 22 | print(string.format("Loading data from %s", file_name)) 23 | local output = {} 24 | local file = io.open(file_name, "r") 25 | for line in file:lines() do 26 | line = root_path .. line 27 | 28 | local data = {} 29 | 30 | baseline = line 31 | data.color = baseline:gsub('data_dir', 'color'):gsub('_suffix', '.jpg'); 32 | 33 | baseline = line 34 | data.nx = baseline:gsub('data_dir', 'mesh_images'):gsub('_suffix', '_mesh_nx.png'); 35 | data.ny = baseline:gsub('data_dir', 'mesh_images'):gsub('_suffix', '_mesh_ny.png'); 36 | data.nz = baseline:gsub('data_dir', 'mesh_images'):gsub('_suffix', '_mesh_nz.png'); 37 | 38 | baseline = line 39 | data.depth = baseline:gsub('data_dir', 'mesh_images'):gsub('_suffix', '_mesh_depth.png'); 40 | 41 | baseline = line 42 | data.depth_raw = baseline:gsub('data_dir', 'depth'):gsub('_suffix', '.png'); 43 | 44 | data.name = line 45 | 46 | table.insert(output, data) 47 | end 48 | print(string.format("%d data loaded.",#output)) 49 | return output 50 | end 51 | 52 | 53 | --------------------------------------------------------------------------------