├── html
└── trimesh_logo.jpg
├── Makedefs.Darwin64
├── help
├── todo.txt
└── README
├── Makedefs.Linux64
├── gluit
├── freeglut_config.h
├── glui_bitmap_img_data.cc
├── COPYING.freeglut
├── glui_img_spinup_0.c
├── glui_img_spinup_1.c
├── glui_img_spindown_0.c
├── glui_img_spindown_1.c
├── glui_img_spindown_dis.c
├── glui_img_spinup_dis.c
├── glui_separator.cc
├── Makefile
├── freeglut_videoresize.c
├── freeglut_overlay.c
├── glui_column.cc
├── glui_img_checkbox_0.c
├── glui_img_checkbox_1.c
├── glui_img_checkbox_0_dis.c
├── glui_img_checkbox_1_dis.c
├── glui_arcball.h
├── glui_img_listbox_down.c
├── glui_img_listbox_up.c
├── glui_img_listbox_up_dis.c
├── glui_statictext.cc
├── glui_bitmaps.cc
├── glui_img_radiobutton_0.c
├── glui_img_radiobutton_1.c
├── glui_img_radiobutton_0_dis.c
├── glui_img_radiobutton_1_dis.c
├── glui_stdinc.h
├── freeglut_display.c
├── glui_img_downarrow.c
├── glui_img_leftarrow.c
├── glui_img_uparrow.c
├── glui_img_rightarrow.c
├── glui_quaternion.h
├── freeglut_glutfont_definitions.c
├── glui_panel.cc
├── glui_button.cc
├── glui_quaternion.cc
└── glui_arcball.cc
├── .github
└── workflows
│ └── c-cpp.yml
├── Makefile
├── utilsrc
├── wingetopt.h
├── Makefile
├── mesh_cat.cc
├── wingetopt.c
├── grid_subsamp.cc
├── shaders.inc
├── mesh_align.cc
├── mesh_crunch.cc
└── mesh_cc.cc
├── include
├── GL
│ ├── freeglut.h
│ └── glut.h
├── timestamp.h
├── GLCamera.h
├── ICP.h
├── noise3d.h
├── strutil.h
├── KDtree.h
└── endianutil.h
├── libsrc
├── faceflip.cc
├── Makefile
├── TriMesh_pointareas.cc
├── umbrella.cc
├── TriMesh_grid.cc
├── TriMesh_connectivity.cc
├── TriMesh_bounding.cc
├── remove.cc
└── overlap.cc
├── msvc
├── vs2019
│ └── trimesh_includes.props
└── vs2022
│ └── trimesh_includes.props
├── Makedefs.Linux
├── Makedefs.Darwin
├── Makedefs.Win32
├── Makerules
├── .gitattributes
├── .gitignore
└── README.md
/html/trimesh_logo.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/Forceflow/trimesh2/HEAD/html/trimesh_logo.jpg
--------------------------------------------------------------------------------
/Makedefs.Darwin64:
--------------------------------------------------------------------------------
1 | include $(MAKERULESDIR)/Makedefs.Darwin
2 |
3 | ARCHOPTS = -m64 -march=core2 -mfpmath=sse -mtune=native
4 |
5 |
--------------------------------------------------------------------------------
/help/todo.txt:
--------------------------------------------------------------------------------
1 | Add notice about OpenGL and mesh_view
2 | TravisCI implementation
3 | CPPCheck
4 | Build all utilities
5 | Interop with GLM vectors
--------------------------------------------------------------------------------
/Makedefs.Linux64:
--------------------------------------------------------------------------------
1 | include $(MAKERULESDIR)/Makedefs.Linux
2 |
3 | ARCHOPTS = -m64 -march=core2 -mfpmath=sse -mtune=native
4 | XLIBDIR = /usr/X11R6/lib64
5 |
6 |
--------------------------------------------------------------------------------
/gluit/freeglut_config.h:
--------------------------------------------------------------------------------
1 | #ifndef _WIN32
2 | #define HAVE_SYS_TYPES_H 1
3 | #define HAVE_UNISTD_H 1
4 | #define TIME_WITH_SYS_TIME
5 | #define HAVE_STDBOOL_H 1
6 | #define HAVE_GETTIMEOFDAY 1
7 | #define HAVE_ERRNO_H 1
8 | #endif
9 |
--------------------------------------------------------------------------------
/.github/workflows/c-cpp.yml:
--------------------------------------------------------------------------------
1 | name: C/C++ CI
2 |
3 | on:
4 | push:
5 | branches: [ main ]
6 | pull_request:
7 | branches: [ main ]
8 |
9 | jobs:
10 | build:
11 |
12 | runs-on: ubuntu-latest
13 |
14 | steps:
15 | - uses: actions/checkout@v2
16 | - name: install dependencies
17 | run: |
18 | sudo apt update
19 | sudo apt install -y mesa-common-dev libglu1-mesa-dev libxi-dev
20 | - name: make all
21 | run: make all
22 |
--------------------------------------------------------------------------------
/Makefile:
--------------------------------------------------------------------------------
1 | all win32 linux32 linux64 darwin32 darwin64 clean:
2 | $(MAKE) -C libsrc $@
3 | $(MAKE) -C gluit $@
4 | $(MAKE) -C utilsrc $@
5 |
6 | debug:
7 | $(MAKE) -C libsrc DEBUG=y
8 | $(MAKE) -C gluit DEBUG=y
9 | $(MAKE) -C utilsrc DEBUG=y
10 |
11 | FINDCMD = find trimesh2 -name 'OBJ*' -prune -o -name '.git*' -prune -o -type f -print
12 |
13 | tar:
14 | cd .. && tar zcvf trimesh2.tar.gz `$(FINDCMD) | sort`
15 |
16 | zip:
17 | cd .. && $(FINDCMD) | sort | zip -9 trimesh2 -@
18 |
19 | .PHONY : all win32 linux32 linux64 darwin32 darwin64 clean debug tar zip
20 |
21 |
--------------------------------------------------------------------------------
/utilsrc/wingetopt.h:
--------------------------------------------------------------------------------
1 | /*
2 | POSIX getopt for Windows
3 |
4 | AT&T Public License
5 |
6 | Code given out at the 1985 UNIFORUM conference in Dallas.
7 | */
8 |
9 | #ifdef __GNUC__
10 | #include
11 | #endif
12 | #ifndef __GNUC__
13 |
14 | #ifndef _WINGETOPT_H_
15 | #define _WINGETOPT_H_
16 |
17 | #ifdef __cplusplus
18 | extern "C" {
19 | #endif
20 |
21 | extern int opterr;
22 | extern int optind;
23 | extern int optopt;
24 | extern char *optarg;
25 | extern int getopt(int argc, char **argv, char *opts);
26 |
27 | #ifdef __cplusplus
28 | }
29 | #endif
30 |
31 | #endif /* _GETOPT_H_ */
32 | #endif /* __GNUC__ */
--------------------------------------------------------------------------------
/include/GL/freeglut.h:
--------------------------------------------------------------------------------
1 | #ifndef __FREEGLUT_H__
2 | #define __FREEGLUT_H__
3 |
4 | /*
5 | * freeglut.h
6 | *
7 | * The freeglut library include file
8 | *
9 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
10 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
11 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
12 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
13 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
14 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
15 | */
16 |
17 | #include "freeglut_std.h"
18 | #include "freeglut_ext.h"
19 |
20 | /*** END OF FILE ***/
21 |
22 | #endif /* __FREEGLUT_H__ */
23 |
--------------------------------------------------------------------------------
/libsrc/faceflip.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Szymon Rusinkiewicz
3 | Princeton University
4 |
5 | faceflip.cc
6 | Flip the order of vertices in each face. Turns the mesh inside out.
7 | */
8 |
9 | #include "TriMesh.h"
10 | #include "TriMesh_algo.h"
11 | #define dprintf TriMesh::dprintf
12 | using namespace std;
13 |
14 |
15 | namespace trimesh {
16 |
17 | void faceflip(TriMesh *mesh)
18 | {
19 | bool had_tstrips = !mesh->tstrips.empty();
20 | mesh->need_faces();
21 | mesh->tstrips.clear();
22 |
23 | dprintf("Flipping faces... ");
24 | int nf = mesh->faces.size();
25 | #pragma omp parallel for
26 | for (int i = 0; i < nf; i++)
27 | swap(mesh->faces[i][0], mesh->faces[i][2]);
28 | dprintf("Done.\n");
29 |
30 | if (had_tstrips)
31 | mesh->need_tstrips();
32 | }
33 |
34 | } // namespace trimesh
35 |
--------------------------------------------------------------------------------
/gluit/glui_bitmap_img_data.cc:
--------------------------------------------------------------------------------
1 |
2 | #include "glui_img_checkbox_0.c"
3 | #include "glui_img_checkbox_1.c"
4 | #include "glui_img_radiobutton_0.c"
5 | #include "glui_img_radiobutton_1.c"
6 | #include "glui_img_uparrow.c"
7 | #include "glui_img_downarrow.c"
8 | #include "glui_img_leftarrow.c"
9 | #include "glui_img_rightarrow.c"
10 | #include "glui_img_spinup_1.c"
11 | #include "glui_img_spinup_0.c"
12 | #include "glui_img_spindown_1.c"
13 | #include "glui_img_spindown_0.c"
14 | #include "glui_img_checkbox_0_dis.c"
15 | #include "glui_img_checkbox_1_dis.c"
16 | #include "glui_img_radiobutton_0_dis.c"
17 | #include "glui_img_radiobutton_1_dis.c"
18 | #include "glui_img_spinup_dis.c"
19 | #include "glui_img_spindown_dis.c"
20 | #include "glui_img_listbox_up.c"
21 | #include "glui_img_listbox_down.c"
22 | #include "glui_img_listbox_up_dis.c"
23 |
--------------------------------------------------------------------------------
/include/GL/glut.h:
--------------------------------------------------------------------------------
1 | #ifdef __APPLE__
2 |
3 | #include
4 |
5 | #else
6 |
7 | #ifndef __GLUT_H__
8 | #define __GLUT_H__
9 |
10 | /*
11 | * glut.h
12 | *
13 | * The freeglut library include file
14 | *
15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21 | */
22 |
23 | #include "freeglut_std.h"
24 |
25 | /*** END OF FILE ***/
26 |
27 | #endif /* __GLUT_H__ */
28 |
29 | #endif /* __APPLE__ */
30 |
--------------------------------------------------------------------------------
/libsrc/Makefile:
--------------------------------------------------------------------------------
1 | DESTDIR = ../lib.$(UNAME)
2 | INCLUDES = -I../include
3 |
4 | include ../Makerules
5 |
6 | CCFILES = TriMesh_bounding.cc \
7 | TriMesh_connectivity.cc \
8 | TriMesh_curvature.cc \
9 | TriMesh_io.cc \
10 | TriMesh_grid.cc \
11 | TriMesh_normals.cc \
12 | TriMesh_pointareas.cc \
13 | TriMesh_stats.cc \
14 | TriMesh_tstrips.cc \
15 | GLCamera.cc \
16 | GLManager.cc \
17 | ICP.cc \
18 | KDtree.cc \
19 | conn_comps.cc \
20 | diffuse.cc \
21 | edgeflip.cc \
22 | faceflip.cc \
23 | filter.cc \
24 | make.cc \
25 | merge.cc \
26 | overlap.cc \
27 | remove.cc \
28 | reorder_verts.cc \
29 | subdiv.cc \
30 | umbrella.cc
31 |
32 |
33 | OFILES = $(addprefix $(OBJDIR)/,$(CCFILES:.cc=.o))
34 | LIB = $(DESTDIR)/libtrimesh.a
35 | default: $(LIB)
36 |
37 | $(LIB): $(OFILES)
38 | $(STATICLIB)
39 |
40 | clean:
41 | -rm -f $(OBJDIR)/*.o $(OBJDIR)/*.d
42 | -rmdir $(OBJDIR)
43 |
44 | spotless: clean
45 | -rm -f $(LIB)
46 | -rmdir $(DESTDIR)
47 |
48 |
--------------------------------------------------------------------------------
/utilsrc/Makefile:
--------------------------------------------------------------------------------
1 | DESTDIR = ../bin.$(UNAME)
2 | INCLUDES = -I../include -I.
3 | LIBDIR = -L../lib.$(UNAME)
4 |
5 | include ../Makerules
6 |
7 | VIEWSOURCES = mesh_view.cc
8 |
9 | OTHERSOURCES = mesh_align.cc \
10 | mesh_cat.cc \
11 | mesh_cc.cc \
12 | mesh_check.cc \
13 | mesh_crunch.cc \
14 | mesh_filter.cc \
15 | mesh_hf.cc \
16 | mesh_info.cc \
17 | mesh_make.cc \
18 | mesh_shade.cc \
19 | grid_subsamp.cc \
20 | xf.cc
21 |
22 | VIEWOFILES = $(addprefix $(OBJDIR)/,$(VIEWSOURCES:.cc=.o))
23 | OTHEROFILES = $(addprefix $(OBJDIR)/,$(OTHERSOURCES:.cc=.o))
24 | OFILES = $(VIEWOFILES) $(OTHEROFILES)
25 |
26 | VIEWPROG = $(DESTDIR)/mesh_view$(EXE)
27 | OTHERPROGS = $(addsuffix $(EXE), $(addprefix $(DESTDIR)/, $(OTHERSOURCES:.cc=)))
28 | PROGS = $(OTHERPROGS) $(VIEWPROG)
29 |
30 | default: $(PROGS)
31 |
32 |
33 | LIBS += -ltrimesh
34 | $(PROGS) : -ltrimesh
35 |
36 | $(VIEWPROG) : $(VIEWOFILES)
37 | $(LINK) $(GLLIBS)
38 |
39 | $(OTHERPROGS) : $(DESTDIR)/%$(EXE) : $(OBJDIR)/%.o
40 | $(LINK)
41 |
42 | clean :
43 | -rm -f $(OBJDIR)/*.o $(OBJDIR)/*.d
44 | -rmdir $(OBJDIR)
45 |
46 | spotless : clean
47 | -rm -f $(PROGS)
48 | -rmdir $(DESTDIR)
49 |
50 |
--------------------------------------------------------------------------------
/msvc/vs2019/trimesh_includes.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ..\..\..
6 |
7 |
8 | $(TRIMESH_DIR)\include\;$(IncludePath)
9 | <_PropertySheetDisplayName>trimesh_includes
10 | $(TRIMESH_DIR)\lib.Win$(PlatformArchitecture).vs$(PlatformToolsetVersion);$(LibraryPath)
11 |
12 |
13 |
14 |
15 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
16 |
17 |
18 |
19 |
20 | $(TRIMESH_DIR)
21 | true
22 |
23 |
24 |
--------------------------------------------------------------------------------
/msvc/vs2022/trimesh_includes.props:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | ..\..\..
6 |
7 |
8 | $(TRIMESH_DIR)\include\;$(IncludePath)
9 | <_PropertySheetDisplayName>trimesh_includes
10 | $(TRIMESH_DIR)\lib.Win$(PlatformArchitecture).vs$(PlatformToolsetVersion);$(LibraryPath)
11 |
12 |
13 |
14 |
15 | kernel32.lib;user32.lib;gdi32.lib;winspool.lib;comdlg32.lib;advapi32.lib;shell32.lib;ole32.lib;oleaut32.lib;uuid.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)
16 |
17 |
18 |
19 |
20 | $(TRIMESH_DIR)
21 | true
22 |
23 |
24 |
--------------------------------------------------------------------------------
/utilsrc/mesh_cat.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Szymon Rusinkiewicz
3 | Princeton University
4 |
5 | mesh_cat.cc
6 | Concatenate meshes together
7 | */
8 |
9 | #include "TriMesh.h"
10 | #include "TriMesh_algo.h"
11 | #include
12 | #include
13 | #include
14 | using namespace std;
15 | using namespace trimesh;
16 |
17 |
18 | void usage(const char *myname)
19 | {
20 | fprintf(stderr, "Usage: %s infiles... [-share tol] -o outfile\n", myname);
21 | exit(1);
22 | }
23 |
24 | int main(int argc, char *argv[])
25 | {
26 | if (argc < 4)
27 | usage(argv[0]);
28 |
29 | vector meshes;
30 | const char *outfile = NULL;
31 | float tol = -1.0f;
32 | for (int i = 1; i < argc; i++) {
33 | if (strcmp(argv[i], "-o") == 0 && i < argc-1) {
34 | outfile = argv[i+1];
35 | i++;
36 | continue;
37 | }
38 | if (strncmp(argv[i], "-share", 6) == 0 && i < argc-1) {
39 | tol = atof(argv[i+1]);
40 | i++;
41 | continue;
42 | }
43 | TriMesh *m = TriMesh::read(argv[i]);
44 | if (!m) {
45 | fprintf(stderr, "Couldn't read file %s\n", argv[i]);
46 | continue;
47 | }
48 | meshes.push_back(m);
49 | }
50 |
51 |
52 | if (outfile)
53 | join(meshes, tol)->write(outfile);
54 | else
55 | fprintf(stderr, "No output file specified\n");
56 | }
57 |
--------------------------------------------------------------------------------
/gluit/COPYING.freeglut:
--------------------------------------------------------------------------------
1 |
2 | Freeglut Copyright
3 | ------------------
4 |
5 | Freeglut code without an explicit copyright is covered by the following
6 | copyright:
7 |
8 | Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
9 | Permission is hereby granted, free of charge, to any person obtaining a copy
10 | of this software and associated documentation files (the "Software"), to deal
11 | in the Software without restriction, including without limitation the rights
12 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
13 | copies or substantial portions of the Software.
14 |
15 | The above copyright notice and this permission notice shall be included in
16 | all copies or substantial portions of the Software.
17 |
18 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 | PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
22 | IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 | CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
24 |
25 | Except as contained in this notice, the name of Pawel W. Olszta shall not be
26 | used in advertising or otherwise to promote the sale, use or other dealings
27 | in this Software without prior written authorization from Pawel W. Olszta.
28 |
--------------------------------------------------------------------------------
/gluit/glui_img_spinup_0.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_spinup_0[] = { 12, 8, /* width, height */
4 | 255,255,255, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
5 | 127,127,127, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
6 | 127,127,127, 0, 0, 0, 255,255,255, 191,191,191, 191,191,191,
7 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
8 | 191,191,191, 191,191,191, 127,127,127, 0, 0, 0, 255,255,255,
9 | 191,191,191, 191,191,191, 0, 0, 0, 0, 0, 0, 0, 0, 0,
10 | 0, 0, 0, 0, 0, 0, 127,127,127, 191,191,191, 127,127,127,
11 | 0, 0, 0, 255,255,255, 191,191,191, 191,191,191, 191,191,191,
12 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 127,127,127, 191,191,191,
13 | 191,191,191, 127,127,127, 0, 0, 0, 255,255,255, 191,191,191,
14 | 191,191,191, 191,191,191, 191,191,191, 0, 0, 0, 127,127,127,
15 | 191,191,191, 191,191,191, 191,191,191, 127,127,127, 0, 0, 0,
16 | 255,255,255, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
17 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
18 | 127,127,127, 0, 0, 0, 255,255,255, 191,191,191, 191,191,191,
19 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
20 | 191,191,191, 191,191,191, 191,191,191, 0, 0, 0, 255,255,255,
21 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
22 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
23 | 255,255,255,
24 | };
25 |
--------------------------------------------------------------------------------
/gluit/glui_img_spinup_1.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_spinup_1[] = { 12, 8, /* width, height */
4 | 0, 0, 0, 127,127,127, 255,255,255, 255,255,255, 255,255,255,
5 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
6 | 255,255,255, 255,255,255, 0, 0, 0, 127,127,127, 191,191,191,
7 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
8 | 191,191,191, 191,191,191, 191,191,191, 255,255,255, 0, 0, 0,
9 | 127,127,127, 191,191,191, 127,127,127, 0, 0, 0, 0, 0, 0,
10 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 191,191,191, 191,191,191,
11 | 255,255,255, 0, 0, 0, 127,127,127, 191,191,191, 191,191,191,
12 | 127,127,127, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191,191,191,
13 | 191,191,191, 191,191,191, 255,255,255, 0, 0, 0, 127,127,127,
14 | 191,191,191, 191,191,191, 191,191,191, 127,127,127, 0, 0, 0,
15 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 255,255,255,
16 | 0, 0, 0, 127,127,127, 191,191,191, 191,191,191, 191,191,191,
17 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
18 | 191,191,191, 255,255,255, 0, 0, 0, 127,127,127, 127,127,127,
19 | 127,127,127, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
20 | 127,127,127, 127,127,127, 191,191,191, 255,255,255, 0, 0, 0,
21 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
22 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
23 | 255,255,255,
24 | };
25 |
--------------------------------------------------------------------------------
/gluit/glui_img_spindown_0.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_spindown_0[] = { 12, 8, /* width, height */
4 | 255,255,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6 | 0, 0, 0, 0, 0, 0, 255,255,255, 127,127,127, 127,127,127,
7 | 127,127,127, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
8 | 127,127,127, 127,127,127, 127,127,127, 0, 0, 0, 255,255,255,
9 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
10 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 127,127,127,
11 | 0, 0, 0, 255,255,255, 191,191,191, 191,191,191, 191,191,191,
12 | 191,191,191, 0, 0, 0, 127,127,127, 191,191,191, 191,191,191,
13 | 191,191,191, 127,127,127, 0, 0, 0, 255,255,255, 191,191,191,
14 | 191,191,191, 191,191,191, 0, 0, 0, 0, 0, 0, 0, 0, 0,
15 | 127,127,127, 191,191,191, 191,191,191, 127,127,127, 0, 0, 0,
16 | 255,255,255, 191,191,191, 191,191,191, 0, 0, 0, 0, 0, 0,
17 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 127,127,127, 191,191,191,
18 | 127,127,127, 0, 0, 0, 255,255,255, 191,191,191, 191,191,191,
19 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
20 | 191,191,191, 191,191,191, 127,127,127, 0, 0, 0, 255,255,255,
21 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
22 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
23 | 0, 0, 0,
24 | };
25 |
--------------------------------------------------------------------------------
/gluit/glui_img_spindown_1.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_spindown_1[] = { 12, 8, /* width, height */
4 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
5 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
6 | 255,255,255, 255,255,255, 0, 0, 0, 127,127,127, 191,191,191,
7 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
8 | 191,191,191, 191,191,191, 191,191,191, 255,255,255, 0, 0, 0,
9 | 127,127,127, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
10 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
11 | 255,255,255, 0, 0, 0, 127,127,127, 191,191,191, 191,191,191,
12 | 191,191,191, 127,127,127, 0, 0, 0, 191,191,191, 191,191,191,
13 | 191,191,191, 191,191,191, 255,255,255, 0, 0, 0, 127,127,127,
14 | 191,191,191, 191,191,191, 127,127,127, 0, 0, 0, 0, 0, 0,
15 | 0, 0, 0, 191,191,191, 191,191,191, 191,191,191, 255,255,255,
16 | 0, 0, 0, 127,127,127, 191,191,191, 127,127,127, 0, 0, 0,
17 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 191,191,191,
18 | 191,191,191, 255,255,255, 0, 0, 0, 127,127,127, 191,191,191,
19 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
20 | 191,191,191, 191,191,191, 191,191,191, 255,255,255, 0, 0, 0,
21 | 127,127,127, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
22 | 127,127,127, 127,127,127, 127,127,127, 127,127,127, 191,191,191,
23 | 255,255,255,
24 | };
25 |
--------------------------------------------------------------------------------
/gluit/glui_img_spindown_dis.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_spindown_dis[] = { 12, 8, /* width, height */
4 | 255,255,255, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
5 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
6 | 64, 64, 64, 64, 64, 64, 255,255,255, 127,127,127, 127,127,127,
7 | 127,127,127, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
8 | 127,127,127, 127,127,127, 127,127,127, 64, 64, 64, 255,255,255,
9 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
10 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 127,127,127,
11 | 64, 64, 64, 255,255,255, 191,191,191, 191,191,191, 191,191,191,
12 | 191,191,191, 127,127,127, 255,255,255, 191,191,191, 191,191,191,
13 | 191,191,191, 127,127,127, 64, 64, 64, 255,255,255, 191,191,191,
14 | 191,191,191, 191,191,191, 127,127,127, 127,127,127, 127,127,127,
15 | 255,255,255, 191,191,191, 191,191,191, 127,127,127, 64, 64, 64,
16 | 255,255,255, 191,191,191, 191,191,191, 127,127,127, 127,127,127,
17 | 127,127,127, 127,127,127, 127,127,127, 255,255,255, 191,191,191,
18 | 127,127,127, 64, 64, 64, 255,255,255, 191,191,191, 191,191,191,
19 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
20 | 191,191,191, 191,191,191, 127,127,127, 64, 64, 64, 255,255,255,
21 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
22 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
23 | 64, 64, 64,
24 | };
25 |
--------------------------------------------------------------------------------
/gluit/glui_img_spinup_dis.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_spinup_dis[] = { 12, 8, /* width, height */
4 | 255,255,255, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
5 | 127,127,127, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
6 | 127,127,127, 64, 64, 64, 255,255,255, 191,191,191, 191,191,191,
7 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
8 | 191,191,191, 191,191,191, 127,127,127, 64, 64, 64, 255,255,255,
9 | 191,191,191, 191,191,191, 127,127,127, 127,127,127, 127,127,127,
10 | 127,127,127, 127,127,127, 255,255,255, 191,191,191, 127,127,127,
11 | 64, 64, 64, 255,255,255, 191,191,191, 191,191,191, 191,191,191,
12 | 127,127,127, 127,127,127, 127,127,127, 255,255,255, 191,191,191,
13 | 191,191,191, 127,127,127, 64, 64, 64, 255,255,255, 191,191,191,
14 | 191,191,191, 191,191,191, 191,191,191, 127,127,127, 255,255,255,
15 | 191,191,191, 191,191,191, 191,191,191, 127,127,127, 64, 64, 64,
16 | 255,255,255, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
17 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
18 | 127,127,127, 64, 64, 64, 255,255,255, 191,191,191, 191,191,191,
19 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
20 | 191,191,191, 191,191,191, 191,191,191, 64, 64, 64, 255,255,255,
21 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
22 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
23 | 255,255,255,
24 | };
25 |
--------------------------------------------------------------------------------
/Makedefs.Linux:
--------------------------------------------------------------------------------
1 | CC = gcc
2 | CXX = g++
3 | #CC = clang
4 | #CXX = clang++
5 | #CXX = clang++ -stdlib=libc++
6 | AR = ar
7 |
8 | ARCHOPTS = -m32 -march=core2 -mfpmath=sse -mtune=native
9 | COPTS = -fno-strict-overflow -fno-math-errno -fno-trapping-math
10 | COPTS += -Wall -Wextra -Wshadow
11 | DEFINES = -U_FORTIFY_SOURCE
12 | XLIBDIR = /usr/X11R6/lib
13 |
14 | ifdef DEBUG
15 | COPTS += -O1 -ggdb3 -fno-omit-frame-pointer
16 | DEFINES += -DDEBUG
17 | else
18 | COPTS += -O3 -fomit-frame-pointer
19 | DEFINES += -DNDEBUG
20 | LDOPTS = -s
21 | endif
22 |
23 | ifeq (,$(shell $(CXX) --version | grep clang))
24 | # Real gcc, not clang
25 | COPTS += -fno-delete-null-pointer-checks
26 | OPENMPOPTS = -fopenmp
27 | endif
28 |
29 | CXXOPTS = $(COPTS)
30 | CFLAGS = $(ARCHOPTS) $(OPENMPOPTS) $(INCLUDES) $(DEFINES) $(COPTS)
31 | CXXFLAGS = $(ARCHOPTS) $(OPENMPOPTS) $(INCLUDES) $(DEFINES) $(CXXOPTS)
32 | LDFLAGS = $(LIBDIR) $(LDOPTS)
33 |
34 |
35 | LIBS = -lm
36 | GLLIBS = -L$(XLIBDIR) -lgluit -lGLU -lGL -lX11
37 |
38 |
39 | $(OBJDIR)/%.o: %.c
40 | @ echo "Compiling $<"
41 | @ rm -f $@
42 | @ $(CC) $(CFLAGS) -MMD -MP -c $< -o $@
43 |
44 | $(OBJDIR)/%.o: %.cc
45 | @ echo "Compiling $<"
46 | @ rm -f $@
47 | @ $(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@
48 |
49 | $(OBJDIR)/%.o: %.cpp
50 | @ echo "Compiling $<"
51 | @ rm -f $@
52 | @ $(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@
53 |
54 | ifneq (,$(findstring -L,$(LIBDIR)))
55 | VPATH = $(subst -L,,$(LIBDIR))
56 | endif
57 |
58 | define LINK
59 | @ echo "Linking $@"
60 | @ rm -f $@
61 | @ $(CXX) $(CXXFLAGS) $^ $(LDFLAGS) $(LIBS) -o $@
62 | endef
63 |
64 | define STATICLIB
65 | @ echo "Creating library $@"
66 | @ rm -f $@
67 | @ $(AR) -rcs $@ $^
68 | endef
69 |
70 | -include $(OBJDIR)/*.d
71 |
72 |
--------------------------------------------------------------------------------
/Makedefs.Darwin:
--------------------------------------------------------------------------------
1 | #CC = gcc
2 | #CXX = g++
3 | #CC = clang
4 | #CXX = clang++
5 | #CXX = clang++ -stdlib=libc++
6 | CC = clang-omp
7 | CXX = clang-omp++
8 | AR = ar
9 |
10 | ARCHOPTS = -m32 -march=core2 -mfpmath=sse -mtune=native
11 | COPTS = -fno-strict-overflow -fno-math-errno -fno-trapping-math
12 | COPTS += -Wall -Wextra -Wshadow
13 | DEFINES = -U_FORTIFY_SOURCE
14 |
15 | ifdef DEBUG
16 | COPTS += -O1 -ggdb3 -fno-omit-frame-pointer
17 | DEFINES += -DDEBUG
18 | else
19 | COPTS += -O3 -fomit-frame-pointer
20 | DEFINES += -DNDEBUG
21 | endif
22 |
23 | ifeq (,$(shell $(CXX) --version | grep clang))
24 | OPENMPOPTS = -fopenmp
25 | endif
26 | ifeq (clang-omp++, $(CXX))
27 | OPENMPOPTS = -fopenmp
28 | endif
29 |
30 | CXXOPTS = $(COPTS)
31 | CFLAGS = $(ARCHOPTS) $(OPENMPOPTS) $(INCLUDES) $(DEFINES) $(COPTS)
32 | CXXFLAGS = $(ARCHOPTS) $(OPENMPOPTS) $(INCLUDES) $(DEFINES) $(CXXOPTS)
33 | LDFLAGS = $(LIBDIR) $(LDOPTS)
34 |
35 |
36 | LIBS = -lm
37 | DONT_BUILD_FREEGLUT = y
38 | GLLIBS = -lgluit -framework GLUT -framework OpenGL
39 |
40 |
41 | $(OBJDIR)/%.o: %.c
42 | @ echo "Compiling $<"
43 | @ rm -f $@
44 | @ $(CC) $(CFLAGS) -MMD -MP -c $< -o $@
45 |
46 | $(OBJDIR)/%.o: %.cc
47 | @ echo "Compiling $<"
48 | @ rm -f $@
49 | @ $(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@
50 |
51 | $(OBJDIR)/%.o: %.cpp
52 | @ echo "Compiling $<"
53 | @ rm -f $@
54 | @ $(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@
55 |
56 | ifneq (,$(findstring -L,$(LIBDIR)))
57 | VPATH = $(subst -L,,$(LIBDIR))
58 | endif
59 |
60 | define LINK
61 | @ echo "Linking $@"
62 | @ rm -f $@
63 | @ $(CXX) $(CXXFLAGS) $^ $(LDFLAGS) $(LIBS) -o $@
64 | endef
65 |
66 | define STATICLIB
67 | @ echo "Creating library $@"
68 | @ rm -f $@
69 | @ $(AR) -rcs $@ $^
70 | endef
71 |
72 | -include $(OBJDIR)/*.d
73 |
74 |
--------------------------------------------------------------------------------
/gluit/glui_separator.cc:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 |
3 | GLUI User Interface Toolkit
4 | ---------------------------
5 |
6 | glui_separator.cpp - GLUI_Separator control class
7 |
8 |
9 | --------------------------------------------------
10 |
11 | Copyright (c) 1998 Paul Rademacher
12 |
13 | This program is freely distributable without licensing fees and is
14 | provided without guarantee or warrantee expressed or implied. This
15 | program is -not- in the public domain.
16 |
17 | *****************************************************************************/
18 |
19 | #include "glui.h"
20 | #include "glui_stdinc.h"
21 |
22 | /****************************** GLUI_Separator::draw() **********/
23 |
24 | void GLUI_Separator::draw( int x, int y )
25 | {
26 | int width, indent, orig;
27 | int cont_x, cont_y, cont_w, cont_h, cont_x_off, cont_y_off;
28 |
29 | if ( NOT can_draw() )
30 | return;
31 |
32 | orig = set_to_glut_window();
33 |
34 | if ( parent() != NULL ) {
35 | get_this_column_dims(&cont_x, &cont_y, &cont_w, &cont_h,
36 | &cont_x_off, &cont_y_off);
37 |
38 | width = cont_w - cont_x_off*2;
39 | }
40 | else {
41 | width = this->w;
42 | }
43 |
44 | indent = (int) floor(width * .05);
45 |
46 | glLineWidth( 1.0 );
47 | glBegin( GL_LINES );
48 | glColor3f( .5, .5, .5 );
49 | glVertex2i( indent, GLUI_SEPARATOR_HEIGHT/2-1 );
50 | glVertex2i( width-indent, GLUI_SEPARATOR_HEIGHT/2-1 );
51 |
52 | glColor3f( 1., 1., 1. );
53 | glVertex2i( indent, GLUI_SEPARATOR_HEIGHT/2 );
54 | glVertex2i( width-indent, GLUI_SEPARATOR_HEIGHT/2 );
55 | glEnd();
56 |
57 | restore_window(orig);
58 | }
59 |
60 |
61 |
--------------------------------------------------------------------------------
/utilsrc/wingetopt.c:
--------------------------------------------------------------------------------
1 | /*
2 | POSIX getopt for Windows
3 |
4 | AT&T Public License
5 |
6 | Code given out at the 1985 UNIFORUM conference in Dallas.
7 | */
8 |
9 | #ifndef __GNUC__
10 |
11 | #include "wingetopt.h"
12 | #include
13 |
14 | #define NULL 0
15 | #define EOF (-1)
16 | #define ERR(s, c) if(opterr){\
17 | char errbuf[2];\
18 | errbuf[0] = c; errbuf[1] = '\n';\
19 | fputs(argv[0], stderr);\
20 | fputs(s, stderr);\
21 | fputc(c, stderr);}
22 | //(void) write(2, argv[0], (unsigned)strlen(argv[0]));\
23 | //(void) write(2, s, (unsigned)strlen(s));\
24 | //(void) write(2, errbuf, 2);}
25 |
26 | int opterr = 1;
27 | int optind = 1;
28 | int optopt;
29 | char *optarg;
30 |
31 | int
32 | getopt(argc, argv, opts)
33 | int argc;
34 | char **argv, *opts;
35 | {
36 | static int sp = 1;
37 | register int c;
38 | register char *cp;
39 |
40 | if(sp == 1)
41 | if(optind >= argc ||
42 | argv[optind][0] != '-' || argv[optind][1] == '\0')
43 | return(EOF);
44 | else if(strcmp(argv[optind], "--") == NULL) {
45 | optind++;
46 | return(EOF);
47 | }
48 | optopt = c = argv[optind][sp];
49 | if(c == ':' || (cp=strchr(opts, c)) == NULL) {
50 | ERR(": illegal option -- ", c);
51 | if(argv[optind][++sp] == '\0') {
52 | optind++;
53 | sp = 1;
54 | }
55 | return('?');
56 | }
57 | if(*++cp == ':') {
58 | if(argv[optind][sp+1] != '\0')
59 | optarg = &argv[optind++][sp+1];
60 | else if(++optind >= argc) {
61 | ERR(": option requires an argument -- ", c);
62 | sp = 1;
63 | return('?');
64 | } else
65 | optarg = argv[optind++];
66 | sp = 1;
67 | } else {
68 | if(argv[optind][++sp] == '\0') {
69 | sp = 1;
70 | optind++;
71 | }
72 | optarg = NULL;
73 | }
74 | return(c);
75 | }
76 |
77 | #endif /* __GNUC__ */
--------------------------------------------------------------------------------
/utilsrc/grid_subsamp.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Szymon Rusinkiewicz
3 | Princeton University
4 |
5 | grid_subsamp.cc
6 | Subsample a mesh grid.
7 | */
8 |
9 | #include "TriMesh.h"
10 | #include
11 | #include
12 | using namespace std;
13 | using namespace trimesh;
14 |
15 |
16 | void usage(const char *myname)
17 | {
18 | fprintf(stderr, "Usage: %s in.ply subsamp out.ply\n", myname);
19 | exit(1);
20 | }
21 |
22 | int main(int argc, char *argv[])
23 | {
24 | if (argc < 4)
25 | usage(argv[0]);
26 |
27 | const char *infilename = argv[1], *outfilename = argv[3];
28 | int subsamp = atoi(argv[2]);
29 | if (subsamp < 2) {
30 | fprintf(stderr, "subsamp must be >= 2\n");
31 | usage(argv[0]);
32 | }
33 |
34 | TriMesh *mesh = TriMesh::read(infilename);
35 | if (!mesh)
36 | usage(argv[0]);
37 | if (mesh->grid.empty()) {
38 | fprintf(stderr, "No grid found in %s\n", infilename);
39 | usage(argv[0]);
40 | }
41 |
42 | TriMesh *outmesh = new TriMesh;
43 | outmesh->grid_width = mesh->grid_width / subsamp;
44 | outmesh->grid_height = mesh->grid_height / subsamp;
45 | if (outmesh->grid_width == 0 || outmesh->grid_height == 0) {
46 | fprintf(stderr, "Resized size is 0\n");
47 | usage(argv[0]);
48 | }
49 |
50 | int n = outmesh->grid_width * outmesh->grid_height;
51 | outmesh->grid.resize(n, TriMesh::GRID_INVALID);
52 | for (int i = 0; i < n; i++) {
53 | int x = i % outmesh->grid_width;
54 | int y = i / outmesh->grid_width;
55 | int ind = (subsamp * x) + (subsamp * y) * mesh->grid_width;
56 | int old_vert = mesh->grid[ind];
57 | if (old_vert < 0)
58 | continue;
59 | outmesh->grid[i] = int(outmesh->vertices.size());
60 | outmesh->vertices.push_back(mesh->vertices[old_vert]);
61 | if (!mesh->normals.empty())
62 | outmesh->normals.push_back(mesh->normals[old_vert]);
63 | if (!mesh->confidences.empty())
64 | outmesh->confidences.push_back(mesh->confidences[old_vert]);
65 | }
66 |
67 | outmesh->write(outfilename);
68 | }
69 |
--------------------------------------------------------------------------------
/gluit/Makefile:
--------------------------------------------------------------------------------
1 | DESTDIR = ../lib.$(UNAME)
2 | INCLUDES = -I../include -I../include/GL
3 |
4 | include ../Makerules
5 |
6 | COPTS += -Wno-unused-parameter -Wno-shadow -Wno-implicit-fallthrough -Wno-cast-function-type -Wno-restrict -Wno-stringop-truncation
7 |
8 | ifdef DONT_BUILD_FREEGLUT
9 | CFILES =
10 | else
11 | CFILES = freeglut_callbacks.c \
12 | freeglut_cursor.c \
13 | freeglut_display.c \
14 | freeglut_ext.c \
15 | freeglut_font.c \
16 | freeglut_font_data.c \
17 | freeglut_gamemode.c \
18 | freeglut_geometry.c \
19 | freeglut_glutfont_definitions.c \
20 | freeglut_init.c \
21 | freeglut_input_devices.c \
22 | freeglut_joystick.c \
23 | freeglut_main.c \
24 | freeglut_menu.c \
25 | freeglut_misc.c \
26 | freeglut_overlay.c \
27 | freeglut_spaceball.c \
28 | freeglut_state.c \
29 | freeglut_stroke_mono_roman.c \
30 | freeglut_stroke_roman.c \
31 | freeglut_structure.c \
32 | freeglut_teapot.c \
33 | freeglut_videoresize.c \
34 | freeglut_window.c \
35 | freeglut_xinput.c
36 | endif
37 |
38 | CCFILES = glui.cc \
39 | glui_add_controls.cc \
40 | glui_algebra3.cc \
41 | glui_arcball.cc \
42 | glui_bitmap_img_data.cc \
43 | glui_bitmaps.cc \
44 | glui_button.cc \
45 | glui_checkbox.cc \
46 | glui_column.cc \
47 | glui_control.cc \
48 | glui_edittext.cc \
49 | glui_listbox.cc \
50 | glui_mouse_iaction.cc \
51 | glui_node.cc \
52 | glui_panel.cc \
53 | glui_quaternion.cc \
54 | glui_radio.cc \
55 | glui_rollout.cc \
56 | glui_rotation.cc \
57 | glui_separator.cc \
58 | glui_slider.cc \
59 | glui_spinner.cc \
60 | glui_statictext.cc \
61 | glui_translation.cc
62 |
63 | OFILES = $(addprefix $(OBJDIR)/,$(CFILES:.c=.o) $(CCFILES:.cc=.o))
64 | LIB = $(DESTDIR)/libgluit.a
65 | default: $(LIB)
66 |
67 | $(LIB): $(OFILES)
68 | $(STATICLIB)
69 |
70 | clean:
71 | -rm -f $(OBJDIR)/*.o $(OBJDIR)/*.d
72 | -rmdir $(OBJDIR)
73 |
74 | spotless: clean
75 | -rm -f $(LIB)
76 | -rmdir $(DESTDIR)
77 |
78 |
--------------------------------------------------------------------------------
/include/timestamp.h:
--------------------------------------------------------------------------------
1 | #ifndef TIMESTAMP_H
2 | #define TIMESTAMP_H
3 | /*
4 | Szymon Rusinkiewicz
5 | Princeton University
6 |
7 | timestamp.h
8 | Wrapper around system-specific timestamps.
9 |
10 | Usage:
11 | timestamp t1 = now();
12 | // Do stuff
13 | timestamp t2 = now();
14 | float elapsed_sec = t2 - t1;
15 | */
16 |
17 | #include "mathutil.h"
18 |
19 | #ifdef _WIN32
20 | #ifndef WIN32_LEAN_AND_MEAN
21 | #define WIN32_LEAN_AND_MEAN
22 | #endif
23 | #include
24 | #include
25 | #else
26 | #include
27 | #include
28 | #endif
29 |
30 |
31 | namespace trimesh {
32 |
33 |
34 | #ifdef _WIN32
35 |
36 | struct timestamp { LARGE_INTEGER t; };
37 |
38 | static inline double LI2d(const LARGE_INTEGER &li)
39 | {
40 | // Work around random compiler bugs...
41 | double d = li.HighPart;
42 | d *= 65536.0 * 65536.0;
43 | d += *(unsigned long *)(&(li.LowPart));
44 | return d;
45 | }
46 |
47 | static inline float operator - (const timestamp &t1, const timestamp &t2)
48 | {
49 | static LARGE_INTEGER PerformanceFrequency;
50 | static int status = QueryPerformanceFrequency(&PerformanceFrequency);
51 | if (status == 0) return 1.0f;
52 |
53 | return float((LI2d(t1.t) - LI2d(t2.t)) / LI2d(PerformanceFrequency));
54 | }
55 |
56 | static inline timestamp now()
57 | {
58 | timestamp t;
59 | QueryPerformanceCounter(&t.t);
60 | return t;
61 | }
62 |
63 | static inline void sleep(unsigned x)
64 | {
65 | Sleep(x * 1000);
66 | }
67 |
68 | static inline void usleep(unsigned x)
69 | {
70 | Sleep(x / 1000);
71 | }
72 |
73 | #else
74 |
75 | typedef struct timeval timestamp;
76 |
77 | static inline float operator - (const timestamp &t1, const timestamp &t2)
78 | {
79 | return (float)(t1.tv_sec - t2.tv_sec) +
80 | 1.0e-6f * (t1.tv_usec - t2.tv_usec);
81 | }
82 |
83 | static inline timestamp now()
84 | {
85 | timestamp t;
86 | gettimeofday(&t, 0);
87 | return t;
88 | }
89 |
90 | #endif
91 |
92 |
93 | } // namespace trimesh
94 |
95 | #endif
96 |
--------------------------------------------------------------------------------
/Makedefs.Win32:
--------------------------------------------------------------------------------
1 | PATHS = /usr/bin/i686-pc-mingw32- /usr/bin/i686-w64-mingw32-
2 | CC := $(or $(firstword $(realpath $(foreach path,$(PATHS),$(path)gcc))), $(error Couldn't find gcc))
3 | CXX := $(or $(firstword $(realpath $(foreach path,$(PATHS),$(path)g++))), $(error Couldn't find g++))
4 | AR := $(or $(firstword $(realpath $(foreach path,$(PATHS),$(path)ar))), $(error Couldn't find ar))
5 | WINDRES := $(or $(firstword $(realpath $(foreach path,$(PATHS),$(path)windres))), $(error Couldn't find windres))
6 |
7 | EXE = .exe
8 |
9 | ARCHOPTS = -m32 -march=core2 -mfpmath=sse -mtune=native
10 | COPTS = -fno-strict-overflow -fno-math-errno -fno-trapping-math
11 | COPTS += -Wall -Wextra -Wshadow
12 | DEFINES = -U_FORTIFY_SOURCE
13 | LDOPTS = -static-libgcc -static-libstdc++
14 |
15 | ifdef DEBUG
16 | COPTS += -O1 -ggdb3 -fno-omit-frame-pointer
17 | DEFINES += -DDEBUG
18 | else
19 | COPTS += -O3 -fomit-frame-pointer
20 |
21 | # Workaround for g++ 4.5.2
22 | COPTS += -fno-caller-saves -fno-gcse
23 |
24 | # No commandline window
25 | #COPTS += -mwindows
26 |
27 | DEFINES += -DNDEBUG
28 |
29 | LDOPTS += -s
30 | endif
31 |
32 | OPENMPOPTS = -fopenmp
33 |
34 | CXXOPTS = $(COPTS)
35 | CFLAGS = $(ARCHOPTS) $(OPENMPOPTS) $(INCLUDES) $(DEFINES) $(COPTS)
36 | CXXFLAGS = $(ARCHOPTS) $(OPENMPOPTS) $(INCLUDES) $(DEFINES) $(CXXOPTS)
37 | LDFLAGS = $(LIBDIR) $(LDOPTS)
38 |
39 |
40 | LIBS = -lm
41 | GLLIBS = -lgluit -lwinmm -lglu32 -lopengl32 -lgdi32
42 |
43 |
44 | $(OBJDIR)/%.o: %.c
45 | @ echo "Compiling $<"
46 | @ rm -f $@
47 | @ $(CC) $(CFLAGS) -MMD -MP -c $< -o $@
48 |
49 | $(OBJDIR)/%.o: %.cc
50 | @ echo "Compiling $<"
51 | @ rm -f $@
52 | @ $(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@
53 |
54 | $(OBJDIR)/%.o: %.cpp
55 | @ echo "Compiling $<"
56 | @ rm -f $@
57 | @ $(CXX) $(CXXFLAGS) -MMD -MP -c $< -o $@
58 |
59 | ifneq (,$(findstring -L,$(LIBDIR)))
60 | VPATH = $(subst -L,,$(LIBDIR))
61 | endif
62 |
63 | define LINK
64 | @ echo "Linking $@"
65 | @ rm -f $@
66 | @ $(CXX) $(CXXFLAGS) $^ $(LDFLAGS) $(LIBS) -o $@
67 | endef
68 |
69 | define STATICLIB
70 | @ echo "Creating library $@"
71 | @ rm -f $@
72 | @ $(AR) -rcs $@ $^
73 | endef
74 |
75 | -include $(OBJDIR)/*.d
76 |
77 |
--------------------------------------------------------------------------------
/gluit/freeglut_videoresize.c:
--------------------------------------------------------------------------------
1 | /*
2 | * freeglut_videoresize.c
3 | *
4 | * Video resize functions (as defined by GLUT API)
5 | *
6 | * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 | * Written by Pawel W. Olszta,
8 | * Creation date: Thu Dec 16 1999
9 | *
10 | * Permission is hereby granted, free of charge, to any person obtaining a
11 | * copy of this software and associated documentation files (the "Software"),
12 | * to deal in the Software without restriction, including without limitation
13 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 | * and/or sell copies of the Software, and to permit persons to whom the
15 | * Software is furnished to do so, subject to the following conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be included
18 | * in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 | */
27 |
28 | #include
29 | #include "freeglut_internal.h"
30 |
31 | /*
32 | * NOTE: functions declared in this file probably will not be implemented.
33 | */
34 |
35 | /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
36 |
37 | int FGAPIENTRY glutVideoResizeGet( GLenum eWhat ) { return( 0x00 ); }
38 | void FGAPIENTRY glutSetupVideoResizing( void ) { /* Not implemented */ }
39 | void FGAPIENTRY glutStopVideoResizing( void ) { /* Not implemented */ }
40 | void FGAPIENTRY glutVideoResize( int x, int y, int w, int h ) { /* Not implemented */ }
41 | void FGAPIENTRY glutVideoPan( int x, int y, int w, int h ) { /* Not implemented */ }
42 |
43 | /*** END OF FILE ***/
44 |
45 |
46 |
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/gluit/freeglut_overlay.c:
--------------------------------------------------------------------------------
1 | /*
2 | * freeglut_overlay.c
3 | *
4 | * Overlay management functions (as defined by GLUT API)
5 | *
6 | * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 | * Written by Pawel W. Olszta,
8 | * Creation date: Thu Dec 16 1999
9 | *
10 | * Permission is hereby granted, free of charge, to any person obtaining a
11 | * copy of this software and associated documentation files (the "Software"),
12 | * to deal in the Software without restriction, including without limitation
13 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 | * and/or sell copies of the Software, and to permit persons to whom the
15 | * Software is furnished to do so, subject to the following conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be included
18 | * in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 | */
27 |
28 | #include
29 | #include "freeglut_internal.h"
30 |
31 | /*
32 | * NOTE: functions declared in this file probably will not be implemented.
33 | */
34 |
35 | /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
36 |
37 | void FGAPIENTRY glutEstablishOverlay( void ) { /* Not implemented */ }
38 | void FGAPIENTRY glutRemoveOverlay( void ) { /* Not implemented */ }
39 | void FGAPIENTRY glutUseLayer( GLenum layer ) { /* Not implemented */ }
40 | void FGAPIENTRY glutPostOverlayRedisplay( void ) { /* Not implemented */ }
41 | void FGAPIENTRY glutPostWindowOverlayRedisplay( int ID ) { /* Not implemented */ }
42 | void FGAPIENTRY glutShowOverlay( void ) { /* Not implemented */ }
43 | void FGAPIENTRY glutHideOverlay( void ) { /* Not implemented */ }
44 |
45 | /*** END OF FILE ***/
46 |
--------------------------------------------------------------------------------
/gluit/glui_column.cc:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 |
3 | GLUI User Interface Toolkit
4 | ---------------------------
5 |
6 | glui_column.cpp - GLUI_Column control class
7 |
8 |
9 | --------------------------------------------------
10 |
11 | Copyright (c) 1998 Paul Rademacher
12 |
13 | This program is freely distributable without licensing fees and is
14 | provided without guarantee or warrantee expressed or implied. This
15 | program is -not- in the public domain.
16 |
17 | *****************************************************************************/
18 |
19 | #include "glui.h"
20 | #include "glui_stdinc.h"
21 |
22 | /**************************************** GLUI_Column::draw() ************/
23 |
24 | void GLUI_Column::draw( int x, int y )
25 | {
26 | int orig;
27 | int panel_x, panel_y, panel_w, panel_h, panel_x_off, panel_y_off;
28 | int y_diff;
29 |
30 | if ( NOT can_draw() )
31 | return;
32 |
33 | if ( int_val == 1 ) { /* Draw a vertical bar */
34 | orig = set_to_glut_window();
35 |
36 | if ( parent() != NULL ) {
37 | get_this_column_dims(&panel_x, &panel_y, &panel_w, &panel_h,
38 | &panel_x_off, &panel_y_off);
39 |
40 | y_diff = y_abs - panel_y;
41 |
42 | if ( 0 ) {
43 | glLineWidth(1.0);
44 | glBegin( GL_LINES );
45 | glColor3f( .5, .5, .5 );
46 | glVertex2i( -GLUI_XOFF+1, -y_diff + GLUI_SEPARATOR_HEIGHT/2 );
47 | glVertex2i( -GLUI_XOFF+1, -y_diff + panel_h - GLUI_SEPARATOR_HEIGHT/2);
48 |
49 | glColor3f( 1.0, 1.0, 1.0 );
50 | glVertex2i( -GLUI_XOFF+2, -y_diff + GLUI_SEPARATOR_HEIGHT/2 );
51 | glVertex2i( -GLUI_XOFF+2, -y_diff + panel_h - GLUI_SEPARATOR_HEIGHT/2);
52 | glEnd();
53 | }
54 | else {
55 | glLineWidth(1.0);
56 | glBegin( GL_LINES );
57 | glColor3f( .5, .5, .5 );
58 | glVertex2i( -2, 0 );
59 | glVertex2i( -2, h );
60 | /*glVertex2i( 0, -y_diff + GLUI_SEPARATOR_HEIGHT/2 ); */
61 | /*glVertex2i( 0, -y_diff + panel_h - GLUI_SEPARATOR_HEIGHT/2); */
62 |
63 | glColor3f( 1.0, 1.0, 1.0 );
64 | glVertex2i( -1, 0 );
65 | glVertex2i( -1, h );
66 | /*glVertex2i( 1, -y_diff + GLUI_SEPARATOR_HEIGHT/2 ); */
67 | /*glVertex2i( 1, -y_diff + panel_h - GLUI_SEPARATOR_HEIGHT/2); */
68 | glEnd();
69 | }
70 |
71 | }
72 |
73 | restore_window(orig);
74 | }
75 | }
76 |
77 |
--------------------------------------------------------------------------------
/include/GLCamera.h:
--------------------------------------------------------------------------------
1 | #ifndef GLCAMERA_H
2 | #define GLCAMERA_H
3 | /*
4 | Szymon Rusinkiewicz
5 | Princeton University
6 |
7 | GLCamera.h
8 | Manages OpenGL camera and trackball/arcball interaction
9 | */
10 |
11 | #include "Vec.h"
12 | #include "XForm.h"
13 | #include "timestamp.h"
14 |
15 |
16 | namespace trimesh {
17 |
18 | namespace Mouse {
19 | enum button { NONE, ROTATE, MOVEXY, MOVEZ, WHEELUP, WHEELDOWN, LIGHT };
20 | }
21 |
22 | class GLCamera {
23 | public:
24 | enum Constraint { UNCONSTRAINED,
25 | XCONSTRAINED, YCONSTRAINED, ZCONSTRAINED };
26 |
27 | private:
28 | int lastmousex, lastmousey;
29 | Mouse::button lastb;
30 | timestamp last_time;
31 |
32 | vec lightdir;
33 |
34 | bool dospin;
35 | point spincenter;
36 | vec spinaxis;
37 | float spinspeed;
38 |
39 | Constraint constraint_;
40 | float field_of_view, pixscale;
41 | mutable float neardist, fardist;
42 | float click_depth;
43 | float tb_screen_x, tb_screen_y, tb_screen_size;
44 | bool read_depth(int x, int y, point &p) const;
45 |
46 | void startspin();
47 | vec mouse2tb(float x, float y);
48 | void rotate(int mousex, int mousey, xform &xf);
49 | void movexy(int mousex, int mousey, xform &xf);
50 | void movez(int mousex, int mousey, xform &xf);
51 | void wheel(Mouse::button updown, xform &xf);
52 | void relight(int mousex, int mousey);
53 | void mouse_click(int mousex, int mousey,
54 | const point &scene_center, float scene_size);
55 |
56 | public:
57 | GLCamera() : lastb(Mouse::NONE), lightdir(vec(0,0,1)),
58 | dospin(false), spinspeed(0),
59 | constraint_(UNCONSTRAINED), field_of_view(0.7f),
60 | neardist(0.0f), fardist(0.0f), click_depth(0.0f)
61 | {
62 | lightdir[0] = lightdir[1] = 0; lightdir[2] = 1;
63 | last_time = now();
64 | }
65 |
66 | void setupGL(const trimesh::point &scene_center, float scene_size) const;
67 |
68 | void mouse(int mousex, int mousey, Mouse::button b,
69 | const point &scene_center, float scene_size,
70 | xform &xf);
71 |
72 | bool autospin(xform &xf);
73 | void stopspin() { dospin = false; }
74 |
75 | vec light() const { return lightdir; }
76 | void set_light(const vec &lightdir_) { lightdir = lightdir_; }
77 |
78 | float fov() const { return field_of_view; }
79 | void set_fov(float fov_) { field_of_view = fov_; }
80 |
81 | Constraint constraint() { return constraint_; }
82 | void set_constraint(Constraint c) { constraint_ = c; }
83 | };
84 |
85 | } // namespace trimesh
86 |
87 | #endif
88 |
--------------------------------------------------------------------------------
/Makerules:
--------------------------------------------------------------------------------
1 | #
2 | # Makerules
3 | #
4 | # Pays attention to the following variables:
5 | # DEBUG = y - debugging compiler flags
6 | # UNAME = xxxxx - cross-compile for the given platform
7 | # (In particular, you can say UNAME = Win32 if mingw
8 | # is installed to cross-compile for Windows, or
9 | # UNAME = Linux to get 32-bit binaries on Linux x64)
10 | # If UNAME undefined on input, gets defined here.
11 | # DESTDIR = xxxx - Place to put output binaries.
12 | # MAKERULESDIR - Where to find Makerules and Makedefs
13 | #
14 | #
15 | # Defines the following variables:
16 | # UNAME - destination system type (if not set by user)
17 | # OBJDIR - directory for object files
18 | # CC - C compiler
19 | # CXX - C++ compiler
20 | # CFLAGS - C compiler flags
21 | # CXXFLAGS - C++ compiler flags
22 | # LDFLAGS - Linker flags
23 | # LIBS - Libraries
24 | # GLLIBS - OpenGL libraries
25 | # EXE - Extension of executables (.exe under Win32)
26 | # LINK - The entire linking process
27 | # STATICLIB - Create .a archive
28 | # SHAREDLIB - Create .so archive
29 | #
30 | #
31 | # Client Makefiles need to define a "default:" rule
32 | # - SMR
33 | #
34 |
35 | #
36 | # Define UNAME
37 | #
38 | ifdef windir
39 | UNAME := Win32
40 | else
41 | UNAME := $(shell uname)
42 | UNAME := $(patsubst CYGWIN%,Win32,$(UNAME))
43 | UNAME := $(patsubst MINGW%,Win32,$(UNAME))
44 |
45 | ifeq ($(UNAME),Linux)
46 | ARCH := $(shell uname -m)
47 | ifeq ($(ARCH),x86_64)
48 | UNAME := Linux64
49 | endif
50 | ifeq ($(ARCH),aarch64)
51 | UNAME := Linux64
52 | endif
53 | endif
54 | ifeq ($(UNAME),Darwin)
55 | IS64 := $(shell sysctl -n hw.cpu64bit_capable)
56 | ifeq ($(IS64),1)
57 | UNAME := Darwin64
58 | endif
59 | endif
60 | endif
61 |
62 | #
63 | # Other variable definitions
64 | #
65 | OBJDIR ?= OBJ.$(UNAME)
66 | DESTDIR ?= .
67 | ifndef MAKERULESDIR
68 | MAKERULESDIR := $(subst /,,$(dir $(lastword $(MAKEFILE_LIST))))
69 | endif
70 |
71 | #
72 | # Rules
73 | #
74 | all: $(OBJDIR) $(DESTDIR) default
75 |
76 | $(OBJDIR) $(DESTDIR):
77 | -mkdir $@
78 |
79 | debug:
80 | $(MAKE) DEBUG=y
81 |
82 | win32:
83 | $(MAKE) UNAME=Win32
84 |
85 | linux32:
86 | $(MAKE) UNAME=Linux
87 |
88 | linux64:
89 | $(MAKE) UNAME=Linux64
90 |
91 | darwin32:
92 | $(MAKE) UNAME=Darwin
93 |
94 | darwin64:
95 | $(MAKE) UNAME=Darwin64
96 |
97 | .PHONY: all default clean debug win32 linux32 linux64 darwin32 darwin64
98 |
99 | #
100 | # Makedefs
101 | #
102 | include $(MAKERULESDIR)/Makedefs.$(UNAME)
103 |
--------------------------------------------------------------------------------
/gluit/glui_img_checkbox_0.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_checkbox_0[] = { 13, 13, /* width, height */
4 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
5 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
6 | 255,255,255, 255,255,255, 255,255,255, 128,128,128, 192,192,192,
7 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
8 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
9 | 255,255,255, 128,128,128, 0, 0, 0, 255,255,255, 255,255,255,
10 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
11 | 255,255,255, 255,255,255, 192,192,192, 255,255,255, 128,128,128,
12 | 0, 0, 0, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
13 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
14 | 192,192,192, 255,255,255, 128,128,128, 0, 0, 0, 255,255,255,
15 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
16 | 255,255,255, 255,255,255, 255,255,255, 192,192,192, 255,255,255,
17 | 128,128,128, 0, 0, 0, 255,255,255, 255,255,255, 255,255,255,
18 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
19 | 255,255,255, 192,192,192, 255,255,255, 128,128,128, 0, 0, 0,
20 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
21 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 192,192,192,
22 | 255,255,255, 128,128,128, 0, 0, 0, 255,255,255, 255,255,255,
23 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
24 | 255,255,255, 255,255,255, 192,192,192, 255,255,255, 128,128,128,
25 | 0, 0, 0, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
26 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
27 | 192,192,192, 255,255,255, 128,128,128, 0, 0, 0, 255,255,255,
28 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
29 | 255,255,255, 255,255,255, 255,255,255, 192,192,192, 255,255,255,
30 | 128,128,128, 0, 0, 0, 255,255,255, 255,255,255, 255,255,255,
31 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
32 | 255,255,255, 192,192,192, 255,255,255, 128,128,128, 0, 0, 0,
33 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
34 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192,192,192,
35 | 255,255,255, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
36 | 128,128,128, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
37 | 128,128,128, 128,128,128, 128,128,128, 255,255,255,
38 | };
39 |
--------------------------------------------------------------------------------
/gluit/glui_img_checkbox_1.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_checkbox_1[] = { 13, 13, /* width, height */
4 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
5 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
6 | 255,255,255, 255,255,255, 255,255,255, 128,128,128, 192,192,192,
7 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
8 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
9 | 255,255,255, 128,128,128, 0, 0, 0, 255,255,255, 255,255,255,
10 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
11 | 255,255,255, 255,255,255, 192,192,192, 255,255,255, 128,128,128,
12 | 0, 0, 0, 255,255,255, 255,255,255, 255,255,255, 0, 0, 0,
13 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
14 | 192,192,192, 255,255,255, 128,128,128, 0, 0, 0, 255,255,255,
15 | 255,255,255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255,255,255,
16 | 255,255,255, 255,255,255, 255,255,255, 192,192,192, 255,255,255,
17 | 128,128,128, 0, 0, 0, 255,255,255, 0, 0, 0, 0, 0, 0,
18 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 255,255,255, 255,255,255,
19 | 255,255,255, 192,192,192, 255,255,255, 128,128,128, 0, 0, 0,
20 | 255,255,255, 0, 0, 0, 0, 0, 0, 255,255,255, 0, 0, 0,
21 | 0, 0, 0, 0, 0, 0, 255,255,255, 255,255,255, 192,192,192,
22 | 255,255,255, 128,128,128, 0, 0, 0, 255,255,255, 0, 0, 0,
23 | 255,255,255, 255,255,255, 255,255,255, 0, 0, 0, 0, 0, 0,
24 | 0, 0, 0, 255,255,255, 192,192,192, 255,255,255, 128,128,128,
25 | 0, 0, 0, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
26 | 255,255,255, 255,255,255, 0, 0, 0, 0, 0, 0, 255,255,255,
27 | 192,192,192, 255,255,255, 128,128,128, 0, 0, 0, 255,255,255,
28 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
29 | 255,255,255, 0, 0, 0, 255,255,255, 192,192,192, 255,255,255,
30 | 128,128,128, 0, 0, 0, 255,255,255, 255,255,255, 255,255,255,
31 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
32 | 255,255,255, 192,192,192, 255,255,255, 128,128,128, 0, 0, 0,
33 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
34 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 192,192,192,
35 | 255,255,255, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
36 | 128,128,128, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
37 | 128,128,128, 128,128,128, 128,128,128, 255,255,255,
38 | };
39 |
--------------------------------------------------------------------------------
/gluit/glui_img_checkbox_0_dis.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_checkbox_0_dis[] = { 13, 13, /* width, height */
4 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
5 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
6 | 255,255,255, 255,255,255, 255,255,255, 128,128,128, 192,192,192,
7 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
8 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
9 | 255,255,255, 128,128,128, 64, 64, 64, 192,192,192, 192,192,192,
10 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
11 | 192,192,192, 192,192,192, 192,192,192, 255,255,255, 128,128,128,
12 | 64, 64, 64, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
13 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
14 | 192,192,192, 255,255,255, 128,128,128, 64, 64, 64, 192,192,192,
15 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
16 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 255,255,255,
17 | 128,128,128, 64, 64, 64, 192,192,192, 192,192,192, 192,192,192,
18 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
19 | 192,192,192, 192,192,192, 255,255,255, 128,128,128, 64, 64, 64,
20 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
21 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
22 | 255,255,255, 128,128,128, 64, 64, 64, 192,192,192, 192,192,192,
23 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
24 | 192,192,192, 192,192,192, 192,192,192, 255,255,255, 128,128,128,
25 | 64, 64, 64, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
26 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
27 | 192,192,192, 255,255,255, 128,128,128, 64, 64, 64, 192,192,192,
28 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
29 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 255,255,255,
30 | 128,128,128, 64, 64, 64, 192,192,192, 192,192,192, 192,192,192,
31 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
32 | 192,192,192, 192,192,192, 255,255,255, 128,128,128, 64, 64, 64,
33 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
34 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 192,192,192,
35 | 255,255,255, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
36 | 128,128,128, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
37 | 128,128,128, 128,128,128, 128,128,128, 255,255,255,
38 | };
39 |
--------------------------------------------------------------------------------
/gluit/glui_img_checkbox_1_dis.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_checkbox_1_dis[] = { 13, 13, /* width, height */
4 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
5 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
6 | 255,255,255, 255,255,255, 255,255,255, 128,128,128, 192,192,192,
7 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
8 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
9 | 255,255,255, 128,128,128, 64, 64, 64, 192,192,192, 192,192,192,
10 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
11 | 192,192,192, 192,192,192, 192,192,192, 255,255,255, 128,128,128,
12 | 64, 64, 64, 192,192,192, 192,192,192, 192,192,192, 64, 64, 64,
13 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
14 | 192,192,192, 255,255,255, 128,128,128, 64, 64, 64, 192,192,192,
15 | 192,192,192, 64, 64, 64, 64, 64, 64, 64, 64, 64, 192,192,192,
16 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 255,255,255,
17 | 128,128,128, 64, 64, 64, 192,192,192, 64, 64, 64, 64, 64, 64,
18 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 192,192,192, 192,192,192,
19 | 192,192,192, 192,192,192, 255,255,255, 128,128,128, 64, 64, 64,
20 | 192,192,192, 64, 64, 64, 64, 64, 64, 192,192,192, 64, 64, 64,
21 | 64, 64, 64, 64, 64, 64, 192,192,192, 192,192,192, 192,192,192,
22 | 255,255,255, 128,128,128, 64, 64, 64, 192,192,192, 64, 64, 64,
23 | 192,192,192, 192,192,192, 192,192,192, 64, 64, 64, 64, 64, 64,
24 | 64, 64, 64, 192,192,192, 192,192,192, 255,255,255, 128,128,128,
25 | 64, 64, 64, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
26 | 192,192,192, 192,192,192, 64, 64, 64, 64, 64, 64, 192,192,192,
27 | 192,192,192, 255,255,255, 128,128,128, 64, 64, 64, 192,192,192,
28 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
29 | 192,192,192, 64, 64, 64, 192,192,192, 192,192,192, 255,255,255,
30 | 128,128,128, 64, 64, 64, 192,192,192, 192,192,192, 192,192,192,
31 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
32 | 192,192,192, 192,192,192, 255,255,255, 128,128,128, 64, 64, 64,
33 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64,
34 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 64, 192,192,192,
35 | 255,255,255, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
36 | 128,128,128, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
37 | 128,128,128, 128,128,128, 128,128,128, 255,255,255,
38 | };
39 |
--------------------------------------------------------------------------------
/.gitattributes:
--------------------------------------------------------------------------------
1 | ###############################################################################
2 | # Set default behavior to automatically normalize line endings.
3 | ###############################################################################
4 | * text=auto
5 |
6 | ###############################################################################
7 | # Set default behavior for command prompt diff.
8 | #
9 | # This is need for earlier builds of msysgit that does not have it on by
10 | # default for csharp files.
11 | # Note: This is only used by command line
12 | ###############################################################################
13 | #*.cs diff=csharp
14 |
15 | ###############################################################################
16 | # Set the merge driver for project and solution files
17 | #
18 | # Merging from the command prompt will add diff markers to the files if there
19 | # are conflicts (Merging from VS is not affected by the settings below, in VS
20 | # the diff markers are never inserted). Diff markers may cause the following
21 | # file extensions to fail to load in VS. An alternative would be to treat
22 | # these files as binary and thus will always conflict and require user
23 | # intervention with every merge. To do so, just uncomment the entries below
24 | ###############################################################################
25 | #*.sln merge=binary
26 | #*.csproj merge=binary
27 | #*.vbproj merge=binary
28 | #*.vcxproj merge=binary
29 | #*.vcproj merge=binary
30 | #*.dbproj merge=binary
31 | #*.fsproj merge=binary
32 | #*.lsproj merge=binary
33 | #*.wixproj merge=binary
34 | #*.modelproj merge=binary
35 | #*.sqlproj merge=binary
36 | #*.wwaproj merge=binary
37 |
38 | ###############################################################################
39 | # behavior for image files
40 | #
41 | # image files are treated as binary by default.
42 | ###############################################################################
43 | #*.jpg binary
44 | #*.png binary
45 | #*.gif binary
46 |
47 | ###############################################################################
48 | # diff behavior for common document formats
49 | #
50 | # Convert binary document formats to text before diffing them. This feature
51 | # is only available from the command line. Turn it on by uncommenting the
52 | # entries below.
53 | ###############################################################################
54 | #*.doc diff=astextplain
55 | #*.DOC diff=astextplain
56 | #*.docx diff=astextplain
57 | #*.DOCX diff=astextplain
58 | #*.dot diff=astextplain
59 | #*.DOT diff=astextplain
60 | #*.pdf diff=astextplain
61 | #*.PDF diff=astextplain
62 | #*.rtf diff=astextplain
63 | #*.RTF diff=astextplain
64 |
--------------------------------------------------------------------------------
/gluit/glui_arcball.h:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 |
3 | Arcball.h
4 |
5 | A C++ class that implements the Arcball, as described by Ken
6 | Shoemake in Graphics Gems IV.
7 | This class takes as input mouse events (mouse down, mouse drag,
8 | mouse up), and creates the appropriate quaternions and 4x4 matrices
9 | to represent the rotation given by the mouse.
10 |
11 | This class is used as follows:
12 | - initialize [either in the constructor or with set_params()], the
13 | center position (x,y) of the arcball on the screen, and the radius
14 | - on mouse down, call mouse_down(x,y) with the mouse position
15 | - as the mouse is dragged, repeatedly call mouse_motion() with the
16 | current x and y positions. One can optionally pass in the current
17 | state of the SHIFT, ALT, and CONTROL keys (passing zero if keys
18 | are not pressed, non-zero otherwise), which constrains
19 | the rotation to certain axes (X for CONTROL, Y for ALT).
20 | - when the mouse button is released, call mouse_up()
21 |
22 | Axis constraints can also be explicitly set with the
23 | set_constraints() function.
24 |
25 | The current rotation is stored in the 4x4 float matrix 'rot'.
26 | It is also stored in the quaternion 'q_now'.
27 |
28 | ------------------------------------------------------------------
29 |
30 | Feb 25, 1998 - Paul Rademacher (rademach@cs.unc.edu)
31 |
32 | **********************************************************************/
33 |
34 |
35 | #ifndef _ARCBALL_H_
36 | #define _ARCBALL_H_
37 |
38 |
39 | #include "glui_stdinc.h"
40 | #include "glui_algebra3.h"
41 | #include "glui_quaternion.h"
42 |
43 | class Arcball {
44 | public:
45 | Bool constraint_x, constraint_y;
46 | vec2 center;
47 | float radius, damp_factor;
48 | int zero_increment;
49 |
50 | vec3 constrain_vector( vec3 vector, vec3 axis );
51 | vec3 mouse_to_sphere( vec2 p );
52 |
53 | //public:
54 | int is_mouse_down; /* true for down, false for up */
55 | int is_spinning;
56 | quat q_now, q_down, q_drag, q_increment;
57 | vec2 down_pt;
58 | mat4 rot, rot_increment;
59 | mat4 *rot_ptr;
60 |
61 | void set_damping( float d );
62 | void idle( void );
63 | void mouse_down( int x, int y );
64 | void mouse_up( void );
65 | void mouse_motion( int x, int y, int shift, int ctrl, int alt );
66 | void mouse_motion( int x, int y );
67 | void set_constraints( Bool constrain_x, Bool constrain_y );
68 | void set_params( vec2 center, float radius );
69 | void reset_mouse( void );
70 | void init( void );
71 |
72 | Arcball( void );
73 | Arcball( mat4 *mtx );
74 | Arcball( vec2 center, float radius );
75 | };
76 |
77 |
78 | #endif
79 |
80 |
--------------------------------------------------------------------------------
/libsrc/TriMesh_pointareas.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Szymon Rusinkiewicz
3 | Princeton University
4 |
5 | TriMesh_pointareas.cc
6 | Compute the area "belonging" to each vertex or each corner
7 | of a triangle (defined as Voronoi area restricted to the 1-ring of
8 | a vertex, or to the triangle).
9 | */
10 |
11 | #include "TriMesh.h"
12 |
13 |
14 | namespace trimesh {
15 |
16 | // Compute per-vertex point areas
17 | void TriMesh::need_pointareas()
18 | {
19 | if (pointareas.size() == vertices.size())
20 | return;
21 | need_faces();
22 |
23 | dprintf("Computing point areas... ");
24 |
25 | int nf = faces.size(), nv = vertices.size();
26 | pointareas.clear();
27 | pointareas.resize(nv);
28 | cornerareas.clear();
29 | cornerareas.resize(nf);
30 |
31 | #pragma omp parallel for
32 | for (int i = 0; i < nf; i++) {
33 | // Edges
34 | vec e[3] = { vertices[faces[i][2]] - vertices[faces[i][1]],
35 | vertices[faces[i][0]] - vertices[faces[i][2]],
36 | vertices[faces[i][1]] - vertices[faces[i][0]] };
37 |
38 | // Compute corner weights
39 | float area = 0.5f * len(e[0] CROSS e[1]);
40 | float l2[3] = { len2(e[0]), len2(e[1]), len2(e[2]) };
41 |
42 | // Barycentric weights of circumcenter
43 | float bcw[3] = { l2[0] * (l2[1] + l2[2] - l2[0]),
44 | l2[1] * (l2[2] + l2[0] - l2[1]),
45 | l2[2] * (l2[0] + l2[1] - l2[2]) };
46 | if (bcw[0] <= 0.0f) {
47 | cornerareas[i][1] = -0.25f * l2[2] * area /
48 | (e[0] DOT e[2]);
49 | cornerareas[i][2] = -0.25f * l2[1] * area /
50 | (e[0] DOT e[1]);
51 | cornerareas[i][0] = area - cornerareas[i][1] -
52 | cornerareas[i][2];
53 | } else if (bcw[1] <= 0.0f) {
54 | cornerareas[i][2] = -0.25f * l2[0] * area /
55 | (e[1] DOT e[0]);
56 | cornerareas[i][0] = -0.25f * l2[2] * area /
57 | (e[1] DOT e[2]);
58 | cornerareas[i][1] = area - cornerareas[i][2] -
59 | cornerareas[i][0];
60 | } else if (bcw[2] <= 0.0f) {
61 | cornerareas[i][0] = -0.25f * l2[1] * area /
62 | (e[2] DOT e[1]);
63 | cornerareas[i][1] = -0.25f * l2[0] * area /
64 | (e[2] DOT e[0]);
65 | cornerareas[i][2] = area - cornerareas[i][0] -
66 | cornerareas[i][1];
67 | } else {
68 | float scale = 0.5f * area / (bcw[0] + bcw[1] + bcw[2]);
69 | for (int j = 0; j < 3; j++)
70 | cornerareas[i][j] = scale * (bcw[NEXT_MOD3(j)] +
71 | bcw[PREV_MOD3(j)]);
72 | }
73 | #pragma omp atomic
74 | pointareas[faces[i][0]] += cornerareas[i][0];
75 | #pragma omp atomic
76 | pointareas[faces[i][1]] += cornerareas[i][1];
77 | #pragma omp atomic
78 | pointareas[faces[i][2]] += cornerareas[i][2];
79 | }
80 |
81 | dprintf("Done.\n");
82 | }
83 |
84 | } // namespace trimesh
85 |
--------------------------------------------------------------------------------
/gluit/glui_img_listbox_down.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_listbox_down[] = { 11, 17, /* width, height */
4 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6 | 0, 0, 0, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
7 | 127,127,127, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
8 | 127,127,127, 0, 0, 0, 127,127,127, 191,191,191, 191,191,191,
9 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
10 | 191,191,191, 127,127,127, 0, 0, 0, 127,127,127, 191,191,191,
11 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
12 | 191,191,191, 191,191,191, 127,127,127, 0, 0, 0, 127,127,127,
13 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
14 | 191,191,191, 191,191,191, 191,191,191, 127,127,127, 0, 0, 0,
15 | 127,127,127, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
16 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 127,127,127,
17 | 0, 0, 0, 127,127,127, 191,191,191, 191,191,191, 191,191,191,
18 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
19 | 127,127,127, 0, 0, 0, 127,127,127, 191,191,191, 191,191,191,
20 | 191,191,191, 191,191,191, 127,127,127, 191,191,191, 191,191,191,
21 | 191,191,191, 127,127,127, 0, 0, 0, 127,127,127, 191,191,191,
22 | 191,191,191, 191,191,191, 127,127,127, 127,127,127, 127,127,127,
23 | 191,191,191, 191,191,191, 127,127,127, 0, 0, 0, 127,127,127,
24 | 191,191,191, 191,191,191, 127,127,127, 127,127,127, 127,127,127,
25 | 127,127,127, 127,127,127, 191,191,191, 127,127,127, 0, 0, 0,
26 | 127,127,127, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
27 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 127,127,127,
28 | 0, 0, 0, 127,127,127, 191,191,191, 191,191,191, 191,191,191,
29 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
30 | 127,127,127, 0, 0, 0, 127,127,127, 191,191,191, 191,191,191,
31 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
32 | 191,191,191, 127,127,127, 0, 0, 0, 127,127,127, 191,191,191,
33 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
34 | 191,191,191, 191,191,191, 127,127,127, 0, 0, 0, 127,127,127,
35 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
36 | 191,191,191, 191,191,191, 191,191,191, 127,127,127, 0, 0, 0,
37 | 127,127,127, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
38 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 127,127,127,
39 | 0, 0, 0, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
40 | 127,127,127, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
41 | 127,127,127, 0, 0, 0,
42 | };
43 |
--------------------------------------------------------------------------------
/gluit/glui_img_listbox_up.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_listbox_up[] = { 11, 17, /* width, height */
4 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6 | 0, 0, 0, 191,191,191, 127,127,127, 127,127,127, 127,127,127,
7 | 127,127,127, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
8 | 127,127,127, 0, 0, 0, 191,191,191, 255,255,255, 191,191,191,
9 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
10 | 191,191,191, 127,127,127, 0, 0, 0, 191,191,191, 255,255,255,
11 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
12 | 191,191,191, 191,191,191, 127,127,127, 0, 0, 0, 191,191,191,
13 | 255,255,255, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
14 | 191,191,191, 191,191,191, 191,191,191, 127,127,127, 0, 0, 0,
15 | 191,191,191, 255,255,255, 191,191,191, 191,191,191, 191,191,191,
16 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 127,127,127,
17 | 0, 0, 0, 191,191,191, 255,255,255, 191,191,191, 191,191,191,
18 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
19 | 127,127,127, 0, 0, 0, 191,191,191, 255,255,255, 191,191,191,
20 | 191,191,191, 191,191,191, 0, 0, 0, 191,191,191, 191,191,191,
21 | 191,191,191, 127,127,127, 0, 0, 0, 191,191,191, 255,255,255,
22 | 191,191,191, 191,191,191, 0, 0, 0, 0, 0, 0, 0, 0, 0,
23 | 191,191,191, 191,191,191, 127,127,127, 0, 0, 0, 191,191,191,
24 | 255,255,255, 191,191,191, 0, 0, 0, 0, 0, 0, 0, 0, 0,
25 | 0, 0, 0, 0, 0, 0, 191,191,191, 127,127,127, 0, 0, 0,
26 | 191,191,191, 255,255,255, 191,191,191, 191,191,191, 191,191,191,
27 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 127,127,127,
28 | 0, 0, 0, 191,191,191, 255,255,255, 191,191,191, 191,191,191,
29 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
30 | 127,127,127, 0, 0, 0, 191,191,191, 255,255,255, 191,191,191,
31 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
32 | 191,191,191, 127,127,127, 0, 0, 0, 191,191,191, 255,255,255,
33 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
34 | 191,191,191, 191,191,191, 127,127,127, 0, 0, 0, 191,191,191,
35 | 255,255,255, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
36 | 191,191,191, 191,191,191, 191,191,191, 127,127,127, 0, 0, 0,
37 | 191,191,191, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
38 | 255,255,255, 255,255,255, 255,255,252, 255,255,255, 127,127,127,
39 | 0, 0, 0, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
40 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
41 | 191,191,191, 0, 0, 0,
42 | };
43 |
--------------------------------------------------------------------------------
/gluit/glui_img_listbox_up_dis.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_listbox_up_dis[] = { 11, 17, /* width, height */
4 | 127,127,127, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
5 | 127,127,127, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
6 | 127,127,127, 191,191,191, 127,127,127, 127,127,127, 127,127,127,
7 | 127,127,127, 127,127,127, 127,127,127, 127,127,127, 127,127,127,
8 | 127,127,127, 127,127,127, 191,191,191, 255,255,255, 191,191,191,
9 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
10 | 191,191,191, 127,127,127, 127,127,127, 191,191,191, 255,255,255,
11 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
12 | 191,191,191, 191,191,191, 127,127,127, 127,127,127, 191,191,191,
13 | 255,255,255, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
14 | 191,191,191, 191,191,191, 191,191,191, 127,127,127, 127,127,127,
15 | 191,191,191, 255,255,255, 191,191,191, 191,191,191, 191,191,191,
16 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 127,127,127,
17 | 127,127,127, 191,191,191, 255,255,255, 191,191,191, 191,191,191,
18 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
19 | 127,127,127, 127,127,127, 191,191,191, 255,255,255, 191,191,191,
20 | 191,191,191, 191,191,191, 254,254,254, 191,191,191, 191,191,191,
21 | 191,191,191, 127,127,127, 127,127,127, 191,191,191, 255,255,255,
22 | 191,191,191, 191,191,191, 127,127,127, 127,127,127, 254,254,254,
23 | 191,191,191, 191,191,191, 127,127,127, 127,127,127, 191,191,191,
24 | 255,255,255, 191,191,191, 127,127,127, 127,127,127, 127,127,127,
25 | 127,127,127, 254,254,254, 191,191,191, 127,127,127, 127,127,127,
26 | 191,191,191, 255,255,255, 191,191,191, 191,191,191, 191,191,191,
27 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 127,127,127,
28 | 127,127,127, 191,191,191, 255,255,255, 191,191,191, 191,191,191,
29 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
30 | 127,127,127, 127,127,127, 191,191,191, 255,255,255, 191,191,191,
31 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
32 | 191,191,191, 127,127,127, 127,127,127, 191,191,191, 255,255,255,
33 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
34 | 191,191,191, 191,191,191, 127,127,127, 127,127,127, 191,191,191,
35 | 255,255,255, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
36 | 191,191,191, 191,191,191, 191,191,191, 127,127,127, 127,127,127,
37 | 191,191,191, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
38 | 255,255,255, 255,255,255, 255,255,252, 255,255,255, 127,127,127,
39 | 127,127,127, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
40 | 191,191,191, 191,191,191, 191,191,191, 191,191,191, 191,191,191,
41 | 191,191,191, 127,127,127,
42 | };
43 |
--------------------------------------------------------------------------------
/gluit/glui_statictext.cc:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 |
3 | GLUI User Interface Toolkit
4 | ---------------------------
5 |
6 | glui_statictext.cpp - GLUI_StaticText Control
7 |
8 |
9 | --------------------------------------------------
10 |
11 | Copyright (c) 1998 Paul Rademacher
12 |
13 | This program is freely distributable without licensing fees and is
14 | provided without guarantee or warrantee expressed or implied. This
15 | program is -not- in the public domain.
16 |
17 | *****************************************************************************/
18 |
19 | #include "glui.h"
20 | #include "glui_stdinc.h"
21 |
22 | /****************************** GLUI_StaticText::draw() **********/
23 |
24 | void GLUI_StaticText::draw( int x, int y )
25 | {
26 | int orig;
27 |
28 | if ( NOT can_draw() )
29 | return;
30 |
31 | orig = set_to_glut_window();
32 |
33 | draw_text();
34 |
35 | restore_window( orig );
36 | }
37 |
38 |
39 | /****************************** GLUI_StaticText::set_text() **********/
40 |
41 | void GLUI_StaticText::set_text( const char *text )
42 | {
43 | int orig = 0;
44 |
45 | if (strcmp(text,name) == 0) return;
46 |
47 | if ( can_draw() )
48 | {
49 | /**** Erase old text first *****/
50 | orig = set_to_glut_window();
51 |
52 | glMatrixMode( GL_MODELVIEW );
53 | glPushMatrix();
54 | translate_to_origin();
55 | erase_text();
56 | glPopMatrix();
57 | }
58 |
59 | /* Copy text */
60 | int old_w = w;
61 | strncpy((char*)name,text,sizeof(GLUI_String));
62 | update_size();
63 | if ((w != old_w)&&(glui)) glui->refresh();
64 |
65 | if ( can_draw() )
66 | {
67 |
68 | /**** Redraw the text in the window ****/
69 | glMatrixMode( GL_MODELVIEW );
70 | glPushMatrix();
71 | translate_to_origin();
72 | draw_text();
73 | glPopMatrix();
74 |
75 | restore_window( orig );
76 | }
77 | }
78 |
79 |
80 | /************************************ GLUI_StaticText::update_size() **********/
81 |
82 | void GLUI_StaticText::update_size( void )
83 | {
84 | int text_size;
85 |
86 | if ( NOT glui )
87 | return;
88 |
89 | text_size = string_width( name );
90 |
91 | if ( w < text_size )
92 | w = text_size;
93 | }
94 |
95 |
96 | /****************************** GLUI_StaticText::draw_text() **********/
97 |
98 | void GLUI_StaticText::draw_text( void )
99 | {
100 | if ( NOT can_draw() )
101 | return;
102 |
103 | erase_text();
104 | draw_name( 0, 9 );
105 | }
106 |
107 |
108 | /****************************** GLUI_StaticText::erase_text() **********/
109 |
110 | void GLUI_StaticText::erase_text( void )
111 | {
112 | if ( NOT can_draw() )
113 | return;
114 |
115 | set_to_bkgd_color();
116 | glDisable( GL_CULL_FACE );
117 | glBegin( GL_TRIANGLES );
118 | glVertex2i( 0,0 ); glVertex2i( w, 0 ); glVertex2i( w, h );
119 | glVertex2i( 0, 0 ); glVertex2i( w, h ); glVertex2i( 0, h );
120 | glEnd();
121 | }
122 |
123 |
124 |
125 |
--------------------------------------------------------------------------------
/include/ICP.h:
--------------------------------------------------------------------------------
1 | #ifndef ICP_H
2 | #define ICP_H
3 | /*
4 | Szymon Rusinkiewicz
5 | Princeton University
6 |
7 | ICP.h
8 | Iterative Closest Point alignment using symmetric point-to-plane minimization
9 | and adaptive outlier rejection.
10 | */
11 |
12 | #include "TriMesh.h"
13 | #include "XForm.h"
14 | #include "KDtree.h"
15 |
16 |
17 | namespace trimesh {
18 |
19 | class Grid;
20 |
21 | // Make a grid for accelerating overlap computation
22 | extern Grid *make_grid(TriMesh *mesh);
23 |
24 | // Determine which points on s1 and s2 overlap the other, filling in o1 and o2
25 | // Also fills in maxdist, if it is <= 0 on input
26 | extern void compute_overlaps(TriMesh *mesh1, TriMesh *mesh2,
27 | const xform &xf1, const xform &xf2,
28 | const KDtree *kd1, const KDtree *kd2,
29 | const Grid *g1, const Grid *g2,
30 | ::std::vector &o1, ::std::vector &o2,
31 | float &maxdist, int verbose);
32 |
33 | // Transformation for which ICP is solving
34 | enum ICP_xform_type {
35 | ICP_TRANSLATION, ICP_RIGID, ICP_SIMILARITY, ICP_AFFINE
36 | };
37 |
38 |
39 | // Do ICP. Aligns mesh2 to mesh1, updating xf2 with the new transform.
40 | // Returns alignment error, or -1 on failure.
41 | // Pass in 0 for maxdist to figure it out...
42 | // Pass in empty vector for weights to figure it out...
43 | extern float ICP(TriMesh *mesh1, TriMesh *mesh2,
44 | const xform &xf1, xform &xf2,
45 | const KDtree *kd1, const KDtree *kd2,
46 | ::std::vector &weights1, ::std::vector &weights2,
47 | float maxdist = 0.0f, int verbose = 0,
48 | ICP_xform_type xform_type = ICP_RIGID);
49 |
50 | // Easier-to-use interfaces to ICP
51 | extern float ICP(TriMesh *mesh1, TriMesh *mesh2,
52 | const xform &xf1, xform &xf2,
53 | const KDtree *kd1, const KDtree *kd2,
54 | int verbose = 0, ICP_xform_type xform_type = ICP_RIGID);
55 |
56 | extern float ICP(TriMesh *mesh1, TriMesh *mesh2,
57 | const xform &xf1, xform &xf2,
58 | int verbose = 0, ICP_xform_type xform_type = ICP_RIGID);
59 |
60 | // Compatibility interfaces to ICP from before we had ICP_xform_type
61 | extern float ICP(TriMesh *mesh1, TriMesh *mesh2,
62 | const xform &xf1, xform &xf2,
63 | const KDtree *kd1, const KDtree *kd2,
64 | ::std::vector &weights1, ::std::vector &weights2,
65 | float maxdist, int verbose,
66 | bool do_scale, bool do_affine = false);
67 |
68 | extern float ICP(TriMesh *mesh1, TriMesh *mesh2, const xform &xf1, xform &xf2,
69 | const KDtree *kd1, const KDtree *kd2,
70 | int verbose, bool do_scale, bool do_affine = false);
71 |
72 | extern float ICP(TriMesh *mesh1, TriMesh *mesh2, const xform &xf1, xform &xf2,
73 | int verbose, bool do_scale, bool do_affine = false);
74 |
75 | } // namespace trimesh
76 |
77 | #endif
78 |
--------------------------------------------------------------------------------
/gluit/glui_bitmaps.cc:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 |
3 | GLUI User Interface Toolkit
4 | ---------------------------
5 |
6 | glui_bitmaps.cpp
7 |
8 |
9 | --------------------------------------------------
10 |
11 | Copyright (c) 1998 Paul Rademacher
12 |
13 | This program is freely distributable without licensing fees and is
14 | provided without guarantee or warrantee expressed or implied. This
15 | program is -not- in the public domain.
16 |
17 | *****************************************************************************/
18 |
19 | #include "glui.h"
20 | #include "glui_stdinc.h"
21 |
22 | int *bitmap_arrays[] = {
23 | glui_img_checkbox_0,
24 | glui_img_checkbox_1,
25 | glui_img_radiobutton_0,
26 | glui_img_radiobutton_1,
27 | glui_img_uparrow,
28 | glui_img_downarrow,
29 | glui_img_leftarrow,
30 | glui_img_rightarrow,
31 | glui_img_spinup_0,
32 | glui_img_spinup_1,
33 | glui_img_spindown_0,
34 | glui_img_spindown_1,
35 | glui_img_checkbox_0_dis,
36 | glui_img_checkbox_1_dis,
37 | glui_img_radiobutton_0_dis,
38 | glui_img_radiobutton_1_dis,
39 | glui_img_spinup_dis,
40 | glui_img_spindown_dis,
41 | glui_img_listbox_up,
42 | glui_img_listbox_down,
43 | glui_img_listbox_up_dis,
44 | };
45 |
46 |
47 | /************************************ GLUI_Bitmap::load_from_array() ********/
48 |
49 | void GLUI_Bitmap::load_from_array( int *array )
50 | {
51 | int i;
52 |
53 | w = 0;
54 | h = 0;
55 |
56 | if ( array == NULL )
57 | return;
58 |
59 | w = array[0];
60 | h = array[1];
61 |
62 | pixels = (unsigned char*) malloc( sizeof(unsigned char) * w * h * 3);
63 |
64 | for( i = 0; i 128 )
95 | putchar( '#' );
96 | else
97 | putchar( ' ' );
98 | }
99 | putchar( '\n' );
100 | }
101 | fflush( stdout );
102 | */
103 | }
104 | }
105 |
--------------------------------------------------------------------------------
/gluit/glui_img_radiobutton_0.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_radiobutton_0[] = { 14, 14, /* width, height */
4 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
5 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
6 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
7 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 255,255,255,
8 | 255,255,255, 255,255,255, 255,255,255, 192,192,192, 192,192,192,
9 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
10 | 192,192,192, 255,255,255, 255,255,255, 192,192,192, 192,192,192,
11 | 192,192,192, 192,192,192, 255,255,255, 255,255,255, 192,192,192,
12 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 128,128,128,
13 | 192,192,192, 192,192,192, 255,255,255, 255,255,255, 255,255,255,
14 | 255,255,255, 192,192,192, 192,192,192, 255,255,255, 192,192,192,
15 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
16 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
17 | 255,255,255, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
18 | 192,192,192, 128,128,128, 0, 0, 0, 255,255,255, 255,255,255,
19 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
20 | 255,255,255, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
21 | 128,128,128, 0, 0, 0, 255,255,255, 255,255,255, 255,255,255,
22 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
23 | 192,192,192, 255,255,255, 192,192,192, 192,192,192, 128,128,128,
24 | 0, 0, 0, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
25 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 192,192,192,
26 | 255,255,255, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
27 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
28 | 255,255,255, 255,255,255, 255,255,255, 192,192,192, 255,255,255,
29 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
30 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
31 | 255,255,255, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
32 | 192,192,192, 192,192,192, 128,128,128, 0, 0, 0, 0, 0, 0,
33 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 0, 0, 0,
34 | 0, 0, 0, 255,255,255, 192,192,192, 192,192,192, 192,192,192,
35 | 192,192,192, 192,192,192, 128,128,128, 128,128,128, 0, 0, 0,
36 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 128,128,128, 128,128,128,
37 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
38 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 128,128,128,
39 | 128,128,128, 128,128,128, 192,192,192, 192,192,192, 192,192,192,
40 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
41 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
42 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
43 | 192,192,192,
44 | };
45 |
--------------------------------------------------------------------------------
/gluit/glui_img_radiobutton_1.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_radiobutton_1[] = { 14, 14, /* width, height */
4 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
5 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
6 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
7 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 255,255,255,
8 | 255,255,255, 255,255,255, 255,255,255, 192,192,192, 192,192,192,
9 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
10 | 192,192,192, 255,255,255, 255,255,255, 192,192,192, 192,192,192,
11 | 192,192,192, 192,192,192, 255,255,255, 255,255,255, 192,192,192,
12 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 128,128,128,
13 | 192,192,192, 192,192,192, 255,255,255, 255,255,255, 255,255,255,
14 | 255,255,255, 192,192,192, 192,192,192, 255,255,255, 192,192,192,
15 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
16 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
17 | 255,255,255, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
18 | 192,192,192, 128,128,128, 0, 0, 0, 255,255,255, 255,255,255,
19 | 255,255,255, 0, 0, 0, 0, 0, 0, 255,255,255, 255,255,255,
20 | 255,255,255, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
21 | 128,128,128, 0, 0, 0, 255,255,255, 255,255,255, 0, 0, 0,
22 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 255,255,255, 255,255,255,
23 | 192,192,192, 255,255,255, 192,192,192, 192,192,192, 128,128,128,
24 | 0, 0, 0, 255,255,255, 255,255,255, 0, 0, 0, 0, 0, 0,
25 | 0, 0, 0, 0, 0, 0, 255,255,255, 255,255,255, 192,192,192,
26 | 255,255,255, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
27 | 255,255,255, 255,255,255, 255,255,255, 0, 0, 0, 0, 0, 0,
28 | 255,255,255, 255,255,255, 255,255,255, 192,192,192, 255,255,255,
29 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
30 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
31 | 255,255,255, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
32 | 192,192,192, 192,192,192, 128,128,128, 0, 0, 0, 0, 0, 0,
33 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 0, 0, 0,
34 | 0, 0, 0, 255,255,255, 192,192,192, 192,192,192, 192,192,192,
35 | 192,192,192, 192,192,192, 128,128,128, 128,128,128, 0, 0, 0,
36 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 128,128,128, 128,128,128,
37 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
38 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 128,128,128,
39 | 128,128,128, 128,128,128, 192,192,192, 192,192,192, 192,192,192,
40 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
41 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
42 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
43 | 192,192,192,
44 | };
45 |
--------------------------------------------------------------------------------
/gluit/glui_img_radiobutton_0_dis.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_radiobutton_0_dis[] = { 14, 14, /* width, height */
4 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
5 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
6 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
7 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 255,255,255,
8 | 255,255,255, 255,255,255, 255,255,255, 192,192,192, 192,192,192,
9 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
10 | 192,192,192, 255,255,255, 255,255,255, 192,192,192, 192,192,192,
11 | 192,192,192, 192,192,192, 255,255,255, 255,255,255, 192,192,192,
12 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 128,128,128,
13 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
14 | 192,192,192, 192,192,192, 192,192,192, 255,255,255, 192,192,192,
15 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 64, 64, 64,
16 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
17 | 192,192,192, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
18 | 192,192,192, 128,128,128, 64, 64, 64, 192,192,192, 192,192,192,
19 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
20 | 192,192,192, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
21 | 128,128,128, 64, 64, 64, 192,192,192, 192,192,192, 192,192,192,
22 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
23 | 192,192,192, 255,255,255, 192,192,192, 192,192,192, 128,128,128,
24 | 64, 64, 64, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
25 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
26 | 255,255,255, 192,192,192, 192,192,192, 128,128,128, 64, 64, 64,
27 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
28 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 255,255,255,
29 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 64, 64, 64,
30 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
31 | 192,192,192, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
32 | 192,192,192, 192,192,192, 128,128,128, 64, 64, 64, 64, 64, 64,
33 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 64, 64, 64,
34 | 64, 64, 64, 255,255,255, 192,192,192, 192,192,192, 192,192,192,
35 | 192,192,192, 192,192,192, 128,128,128, 128,128,128, 64, 64, 64,
36 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 128,128,128, 128,128,128,
37 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
38 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 128,128,128,
39 | 128,128,128, 128,128,128, 192,192,192, 192,192,192, 192,192,192,
40 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
41 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
42 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
43 | 192,192,192,
44 | };
45 |
--------------------------------------------------------------------------------
/gluit/glui_img_radiobutton_1_dis.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_radiobutton_1_dis[] = { 14, 14, /* width, height */
4 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
5 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
6 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
7 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 255,255,255,
8 | 255,255,255, 255,255,255, 255,255,255, 192,192,192, 192,192,192,
9 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
10 | 192,192,192, 255,255,255, 255,255,255, 192,192,192, 192,192,192,
11 | 192,192,192, 192,192,192, 255,255,255, 255,255,255, 192,192,192,
12 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 128,128,128,
13 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
14 | 192,192,192, 192,192,192, 192,192,192, 255,255,255, 192,192,192,
15 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 64, 64, 64,
16 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
17 | 192,192,192, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
18 | 192,192,192, 128,128,128, 64, 64, 64, 192,192,192, 192,192,192,
19 | 192,192,192, 64, 64, 64, 64, 64, 64, 192,192,192, 192,192,192,
20 | 192,192,192, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
21 | 128,128,128, 64, 64, 64, 192,192,192, 192,192,192, 64, 64, 64,
22 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 192,192,192, 192,192,192,
23 | 192,192,192, 255,255,255, 192,192,192, 192,192,192, 128,128,128,
24 | 64, 64, 64, 192,192,192, 192,192,192, 64, 64, 64, 64, 64, 64,
25 | 64, 64, 64, 64, 64, 64, 192,192,192, 192,192,192, 192,192,192,
26 | 255,255,255, 192,192,192, 192,192,192, 128,128,128, 64, 64, 64,
27 | 192,192,192, 192,192,192, 192,192,192, 64, 64, 64, 64, 64, 64,
28 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 255,255,255,
29 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 64, 64, 64,
30 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
31 | 192,192,192, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
32 | 192,192,192, 192,192,192, 128,128,128, 64, 64, 64, 64, 64, 64,
33 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 64, 64, 64,
34 | 64, 64, 64, 255,255,255, 192,192,192, 192,192,192, 192,192,192,
35 | 192,192,192, 192,192,192, 128,128,128, 128,128,128, 64, 64, 64,
36 | 64, 64, 64, 64, 64, 64, 64, 64, 64, 128,128,128, 128,128,128,
37 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
38 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 128,128,128,
39 | 128,128,128, 128,128,128, 192,192,192, 192,192,192, 192,192,192,
40 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
41 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
42 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
43 | 192,192,192,
44 | };
45 |
--------------------------------------------------------------------------------
/libsrc/umbrella.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Szymon Rusinkiewicz
3 | Princeton University
4 |
5 | umbrella.cc
6 | Umbrella and Taubin lambda/mu mesh smoothing
7 | */
8 |
9 | #include "TriMesh.h"
10 | #include "TriMesh_algo.h"
11 | #define dprintf TriMesh::dprintf
12 |
13 |
14 | namespace trimesh {
15 |
16 | // One iteration of umbrella-operator smoothing
17 | void umbrella(TriMesh *mesh, float stepsize, bool tangent /* = false */)
18 | {
19 | mesh->need_neighbors();
20 | mesh->need_adjacentfaces();
21 | if (tangent)
22 | mesh->need_normals();
23 | int nv = mesh->vertices.size();
24 | std::vector disp(nv);
25 | #pragma omp parallel for
26 | for (int i = 0; i < nv; i++) {
27 | if (mesh->is_bdy(i)) {
28 | // Change to #if 1 to smooth boundaries.
29 | // This way, we leave boundaries alone.
30 | #if 0
31 | int nn = mesh->neighbors[i].size();
32 | int nnused = 0;
33 | if (!nn)
34 | continue;
35 | for (int j = 0; j < nn; j++) {
36 | if (!mesh->is_bdy(mesh->neighbors[i][j]))
37 | continue;
38 | disp[i] += mesh->vertices[mesh->neighbors[i][j]];
39 | nnused++;
40 | }
41 | disp[i] /= nnused;
42 | disp[i] -= mesh->vertices[i];
43 | #else
44 | disp[i].clear();
45 | #endif
46 | } else {
47 | int nn = mesh->neighbors[i].size();
48 | if (!nn)
49 | continue;
50 | for (int j = 0; j < nn; j++)
51 | disp[i] += mesh->vertices[mesh->neighbors[i][j]];
52 | disp[i] /= nn;
53 | disp[i] -= mesh->vertices[i];
54 | }
55 | }
56 | if (tangent) {
57 | #pragma omp parallel for
58 | for (int i = 0; i < nv; i++) {
59 | const vec &norm = mesh->normals[i];
60 | mesh->vertices[i] += stepsize * (disp[i] -
61 | norm * (disp[i] DOT norm));
62 | }
63 | } else {
64 | #pragma omp parallel for
65 | for (int i = 0; i < nv; i++)
66 | mesh->vertices[i] += stepsize * disp[i];
67 | }
68 |
69 | mesh->bbox.valid = false;
70 | mesh->bsphere.valid = false;
71 | }
72 |
73 |
74 | // Several iterations of Taubin lambda/mu
75 | void lmsmooth(TriMesh *mesh, int niters)
76 | {
77 | mesh->need_neighbors();
78 | mesh->need_adjacentfaces();
79 | dprintf("Smoothing mesh... ");
80 | for (int i = 0; i < niters; i++) {
81 | umbrella(mesh, 0.330f);
82 | umbrella(mesh, -0.331f);
83 | }
84 | dprintf("Done.\n");
85 |
86 | mesh->bbox.valid = false;
87 | mesh->bsphere.valid = false;
88 | }
89 |
90 |
91 | // One iteration of umbrella-operator smoothing on the normals
92 | void numbrella(TriMesh *mesh, float stepsize)
93 | {
94 | mesh->need_neighbors();
95 | mesh->need_normals();
96 | int nv = mesh->normals.size();
97 | std::vector disp(nv);
98 | #pragma omp parallel for
99 | for (int i = 0; i < nv; i++) {
100 | int nn = mesh->neighbors[i].size();
101 | if (!nn)
102 | continue;
103 | for (int j = 0; j < nn; j++)
104 | disp[i] += mesh->normals[mesh->neighbors[i][j]];
105 | disp[i] /= nn;
106 | disp[i] -= mesh->normals[i];
107 | }
108 |
109 | #pragma omp parallel for
110 | for (int i = 0; i < nv; i++) {
111 | mesh->normals[i] += stepsize * disp[i];
112 | normalize(mesh->normals[i]);
113 | }
114 | }
115 |
116 | } // namespace trimesh
117 |
--------------------------------------------------------------------------------
/libsrc/TriMesh_grid.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Szymon Rusinkiewicz
3 | Princeton University
4 |
5 | TriMesh_grid.cc
6 | Code for dealing with range grids
7 | */
8 |
9 | #include "TriMesh.h"
10 | #include "TriMesh_algo.h"
11 |
12 |
13 | namespace trimesh {
14 |
15 | // Helper function - make a face with the 3 given vertices from the grid
16 | static inline void mkface(TriMesh *mesh, int v1, int v2, int v3)
17 | {
18 | mesh->faces.push_back(TriMesh::Face(
19 | mesh->grid[v1], mesh->grid[v2], mesh->grid[v3]));
20 | }
21 |
22 |
23 | // Triangulate a range grid
24 | void TriMesh::triangulate_grid(bool remove_slivers /* = true */)
25 | {
26 | dprintf("Triangulating... ");
27 |
28 | int nv = vertices.size();
29 | int ngrid = grid_width * grid_height;
30 |
31 | // Work around broken files that have a vertex position of (0,0,0)
32 | // but mark the vertex as valid, or random broken grid indices
33 | for (int i = 0; i < ngrid; i++) {
34 | if (grid[i] >= 0) {
35 | if (grid[i] >= nv)
36 | grid[i] = GRID_INVALID;
37 | else if (!vertices[grid[i]])
38 | grid[i] = GRID_INVALID;
39 | } else { // Handle negative or NaN
40 | grid[i] = GRID_INVALID;
41 | }
42 | }
43 |
44 | // Count valid faces
45 | int ntris = 0;
46 | for (int j = 0; j < grid_height - 1; j++) {
47 | for (int i = 0; i < grid_width - 1; i++) {
48 | int ll = i + j * grid_width;
49 | int lr = ll + 1;
50 | int ul = ll + grid_width;
51 | int ur = ul + 1;
52 | int nvalid = (grid[ll] >= 0) + (grid[lr] >= 0) +
53 | (grid[ul] >= 0) + (grid[ur] >= 0);
54 | if (nvalid == 4)
55 | ntris += 2;
56 | else if (nvalid == 3)
57 | ntris += 1;
58 | }
59 | }
60 |
61 | // Actually make the faces
62 | int old_nfaces = faces.size();
63 | int new_nfaces = old_nfaces + ntris;
64 | faces.reserve(new_nfaces);
65 |
66 | for (int j = 0; j < grid_height - 1; j++) {
67 | for (int i = 0; i < grid_width - 1; i++) {
68 | int ll = i + j * grid_width;
69 | int lr = ll + 1;
70 | int ul = ll + grid_width;
71 | int ur = ul + 1;
72 | int nvalid = (grid[ll] >= 0) + (grid[lr] >= 0) +
73 | (grid[ul] >= 0) + (grid[ur] >= 0);
74 | if (nvalid < 3)
75 | continue;
76 | if (nvalid == 4) {
77 | // Triangulate in the direction that
78 | // gives the shorter diagonal
79 | float ll_ur = dist2(vertices[grid[ll]],
80 | vertices[grid[ur]]);
81 | float lr_ul = dist2(vertices[grid[lr]],
82 | vertices[grid[ul]]);
83 | if (ll_ur < lr_ul) {
84 | mkface(this, ll, lr, ur);
85 | mkface(this, ll, ur, ul);
86 | } else {
87 | mkface(this, ll, lr, ul);
88 | mkface(this, lr, ur, ul);
89 | }
90 | continue;
91 | }
92 | // nvalid == 3
93 | if (grid[ll] < 0)
94 | mkface(this, lr, ur, ul);
95 | else if (grid[lr] < 0)
96 | mkface(this, ll, ur, ul);
97 | else if (grid[ul] < 0)
98 | mkface(this, ll, lr, ur);
99 | else
100 | mkface(this, ll, lr, ul);
101 | }
102 | }
103 |
104 | dprintf("%lu faces.\n", ntris);
105 | if (!faces.empty() && remove_slivers)
106 | remove_sliver_faces(this);
107 | dprintf(" ");
108 | }
109 |
110 | } // namespace trimesh
111 |
--------------------------------------------------------------------------------
/include/noise3d.h:
--------------------------------------------------------------------------------
1 | #ifndef NOISE3D_H
2 | #define NOISE3D_H
3 | /*
4 | Szymon Rusinkiewicz
5 | Princeton University
6 |
7 | noise3d.h
8 | A class for 3-D noise functions, including white noise and 1/f noise
9 | */
10 |
11 | #include "mathutil.h"
12 | #include
13 |
14 |
15 | namespace trimesh {
16 |
17 | class Noise3D {
18 | public:
19 | int xsize, ysize, zsize;
20 | ::std::vector r;
21 | ::std::vector p;
22 |
23 | int coord2index(int x, int y, int z) const
24 | {
25 | return p[ p[x] + y ] + z;
26 | }
27 |
28 | Noise3D(int _xsize, int _ysize, int _zsize) :
29 | xsize(_xsize), ysize(_ysize), zsize(_zsize)
30 | {
31 | using namespace ::std;
32 |
33 | if (xsize < 2) xsize = 2;
34 | if (ysize < 2) ysize = 2;
35 | if (zsize < 2) ysize = 2;
36 |
37 | int pxy = max(xsize, ysize);
38 | for (int i = 0; i < pxy; i++)
39 | p.push_back(i);
40 | for (int i = 0; i < pxy; i++) {
41 | int j = uniform_rnd(pxy);
42 | swap(p[i], p[j]);
43 | }
44 | for (int i = pxy; i < pxy+ysize; i++)
45 | p.push_back(p[i-pxy]);
46 | for (int i = 0; i < pxy + zsize; i++)
47 | r.push_back(uniform_rnd());
48 | }
49 |
50 | virtual float lookup(float x, float y, float z) const
51 | {
52 | using namespace ::std;
53 | x -= floor(x);
54 | y -= floor(y);
55 | z -= floor(z);
56 |
57 | int X = int(x*xsize);
58 | int Y = int(y*ysize);
59 | int Z = int(z*zsize);
60 | int X1 = X + 1; if (X1 == xsize) X1 = 0;
61 | int Y1 = Y + 1; if (Y1 == ysize) Y1 = 0;
62 | int Z1 = Z + 1; if (Z1 == zsize) Z1 = 0;
63 |
64 | float xf = x*xsize - X, xf1 = 1.0f - xf;
65 | float yf = y*ysize - Y, yf1 = 1.0f - yf;
66 | float zf = z*zsize - Z, zf1 = 1.0f - zf;
67 |
68 | return xf1*(yf1*(zf1*r[coord2index(X , Y , Z )] +
69 | zf *r[coord2index(X , Y , Z1)]) +
70 | yf *(zf1*r[coord2index(X , Y1, Z )] +
71 | zf *r[coord2index(X , Y1, Z1)])) +
72 | xf *(yf1*(zf1*r[coord2index(X1, Y , Z )] +
73 | zf *r[coord2index(X1, Y , Z1)]) +
74 | yf *(zf1*r[coord2index(X1, Y1, Z )] +
75 | zf *r[coord2index(X1, Y1, Z1)]));
76 | }
77 |
78 | virtual ~Noise3D() {}
79 | };
80 |
81 |
82 | #define MAGIC_SCALE 1.5707963f
83 |
84 | class PerlinNoise3D : public Noise3D {
85 | int passes;
86 | float correction;
87 | public:
88 | PerlinNoise3D(int _xsize, int _ysize, int _zsize) :
89 | Noise3D(_xsize, _ysize, _zsize), correction(0)
90 | {
91 | using namespace ::std;
92 | passes = int(log((float)xsize)/log(MAGIC_SCALE) + 0.5f);
93 | passes = max(passes, int(log((float)ysize)/log(MAGIC_SCALE) + 0.5f));
94 | passes = max(passes, int(log((float)zsize)/log(MAGIC_SCALE) + 0.5f));
95 | float factor = 1.0f;
96 | for (int pass = 0 ; pass < passes; pass++, factor *= MAGIC_SCALE)
97 | correction += factor*factor;
98 | correction = 1.0f / sqrt(correction);
99 | }
100 |
101 | virtual float lookup(float x, float y, float z) const
102 | {
103 | float t = 0;
104 | float factor = 1.0;
105 | for (int pass = 0 ; pass < passes; pass++, factor *= MAGIC_SCALE) {
106 | float s = 1.0f / factor;
107 | t += Noise3D::lookup(s * x, s * y, s * z) * factor;
108 | }
109 |
110 | return t * correction;
111 | }
112 | };
113 |
114 | #undef MAGIC_SCALE
115 |
116 | } // namespace trimesh
117 |
118 | #endif
119 |
--------------------------------------------------------------------------------
/libsrc/TriMesh_connectivity.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Szymon Rusinkiewicz
3 | Princeton University
4 |
5 | TriMesh_connectivity.cc
6 | Manipulate data structures that describe connectivity between faces and verts.
7 | */
8 |
9 |
10 | #include "TriMesh.h"
11 | using namespace std;
12 |
13 |
14 | namespace trimesh {
15 |
16 | // Find the direct neighbors of each vertex
17 | void TriMesh::need_neighbors()
18 | {
19 | if (!neighbors.empty())
20 | return;
21 |
22 | need_faces();
23 | if (faces.empty())
24 | return;
25 |
26 | dprintf("Finding vertex neighbors... ");
27 | int nv = vertices.size(), nf = faces.size();
28 |
29 | vector numneighbors(nv);
30 | for (int i = 0; i < nf; i++) {
31 | numneighbors[faces[i][0]]++;
32 | numneighbors[faces[i][1]]++;
33 | numneighbors[faces[i][2]]++;
34 | }
35 |
36 | neighbors.resize(nv);
37 | for (int i = 0; i < nv; i++)
38 | neighbors[i].reserve(numneighbors[i]);
39 |
40 | for (int i = 0; i < nf; i++) {
41 | for (int j = 0; j < 3; j++) {
42 | vector &me = neighbors[faces[i][j]];
43 | int n1 = faces[i][NEXT_MOD3(j)];
44 | int n2 = faces[i][PREV_MOD3(j)];
45 | if (find(me.begin(), me.end(), n1) == me.end())
46 | me.push_back(n1);
47 | if (find(me.begin(), me.end(), n2) == me.end())
48 | me.push_back(n2);
49 | }
50 | }
51 |
52 | dprintf("Done.\n");
53 | }
54 |
55 |
56 | // Find the faces touching each vertex
57 | void TriMesh::need_adjacentfaces()
58 | {
59 | if (!adjacentfaces.empty())
60 | return;
61 |
62 | need_faces();
63 | if (faces.empty())
64 | return;
65 |
66 | dprintf("Finding vertex to triangle maps... ");
67 | int nv = vertices.size(), nf = faces.size();
68 |
69 | vector numadjacentfaces(nv);
70 | for (int i = 0; i < nf; i++) {
71 | numadjacentfaces[faces[i][0]]++;
72 | numadjacentfaces[faces[i][1]]++;
73 | numadjacentfaces[faces[i][2]]++;
74 | }
75 |
76 | adjacentfaces.resize(vertices.size());
77 | for (int i = 0; i < nv; i++)
78 | adjacentfaces[i].reserve(numadjacentfaces[i]);
79 |
80 | for (int i = 0; i < nf; i++) {
81 | for (int j = 0; j < 3; j++)
82 | adjacentfaces[faces[i][j]].push_back(i);
83 | }
84 |
85 | dprintf("Done.\n");
86 | }
87 |
88 |
89 | // Find the face across each edge from each other face (-1 on boundary)
90 | // If topology is bad, not necessarily what one would expect...
91 | void TriMesh::need_across_edge()
92 | {
93 | if (!across_edge.empty())
94 | return;
95 |
96 | need_adjacentfaces();
97 | if (adjacentfaces.empty())
98 | return;
99 |
100 | dprintf("Finding across-edge maps... ");
101 |
102 | int nf = faces.size();
103 | across_edge.resize(nf, Face(-1,-1,-1));
104 |
105 | #pragma omp parallel for
106 | for (int i = 0; i < nf; i++) {
107 | for (int j = 0; j < 3; j++) {
108 | int v1 = faces[i][NEXT_MOD3(j)];
109 | int v2 = faces[i][PREV_MOD3(j)];
110 | const vector &a1 = adjacentfaces[v1];
111 | for (size_t k1 = 0; k1 < a1.size(); k1++) {
112 | int other = a1[k1];
113 | if (other == i)
114 | continue;
115 | int v2_in_other = faces[other].indexof(v2);
116 | if (v2_in_other < 0)
117 | continue;
118 | if (faces[other][NEXT_MOD3(v2_in_other)] != v1)
119 | continue;
120 | across_edge[i][j] = other;
121 | break;
122 | }
123 | }
124 | }
125 |
126 | dprintf("Done.\n");
127 | }
128 |
129 | } // namespace trimesh
130 |
--------------------------------------------------------------------------------
/utilsrc/shaders.inc:
--------------------------------------------------------------------------------
1 | #ifndef SHADERS_INC
2 | #define SHADERS_INC
3 | /*
4 | Szymon Rusinkiewicz
5 | Princeton University
6 |
7 | shaders.inc
8 | GLSL shaders for mesh_view
9 | */
10 |
11 |
12 | #ifndef GL_VERTEX_PROGRAM_POINT_SIZE
13 | #define GL_VERTEX_PROGRAM_POINT_SIZE 0x8642
14 | #endif
15 |
16 |
17 | // Unlit - just pass through gl_Color
18 | const char unlit_vert[] = shader_text(
19 | varying vec4 color;
20 | void main()
21 | {
22 | gl_Position = ftransform();
23 | color = gl_Color;
24 | }
25 | );
26 |
27 | const char unlit_point_vert[] = shader_text(
28 | uniform float pointscale;
29 | varying vec4 color;
30 | void main()
31 | {
32 | gl_Position = ftransform();
33 | vec4 worldPos = gl_ModelViewMatrix * gl_Vertex;
34 | float z = -worldPos.z / worldPos.w;
35 | gl_PointSize = max(1.0, pointscale / z);
36 | color = gl_Color;
37 | }
38 | );
39 |
40 | const char unlit_frag[] = shader_text(
41 | varying vec4 color;
42 | void main()
43 | {
44 | gl_FragColor = color;
45 | }
46 | );
47 |
48 |
49 | // Lit with per-fragment Phong based on interpolated normals
50 | const char phong_vert[] = shader_text(
51 | varying vec3 norm;
52 | varying vec4 color;
53 | void main()
54 | {
55 | gl_Position = ftransform();
56 | norm = (gl_NormalMatrix * gl_Normal).xyz;
57 | color = gl_Color;
58 | }
59 | );
60 |
61 | const char phong_point_vert[] = shader_text(
62 | uniform float pointscale;
63 | varying vec3 norm;
64 | varying vec4 color;
65 | void main()
66 | {
67 | gl_Position = ftransform();
68 | vec4 worldPos = gl_ModelViewMatrix * gl_Vertex;
69 | float z = -worldPos.z / worldPos.w;
70 | gl_PointSize = max(1.0, pointscale / z);
71 | norm = (gl_NormalMatrix * gl_Normal).xyz;
72 | color = gl_Color;
73 | }
74 | );
75 |
76 | const char phong_frag[] = shader_text(
77 | varying vec3 norm;
78 | varying vec4 color;
79 | void main()
80 | {
81 | vec4 ambient = color * gl_LightSource[0].ambient;
82 | vec3 nnorm = normalize(norm);
83 | float ndotl = abs(dot(nnorm, gl_LightSource[0].position.xyz));
84 | vec4 diffuse = color * gl_LightSource[0].diffuse * ndotl;
85 | float ndoth = abs(dot(nnorm, gl_LightSource[0].halfVector.xyz));
86 | vec4 specular = gl_FrontMaterial.specular *
87 | pow(ndoth, gl_FrontMaterial.shininess);
88 | gl_FragColor = ambient + diffuse + specular;
89 | }
90 | );
91 |
92 |
93 | // Lit with per-fragment Phong based on (flat) face normals
94 | const char flat_vert[] = shader_text(
95 | varying vec3 pos;
96 | varying vec4 color;
97 | void main()
98 | {
99 | gl_Position = ftransform();
100 | pos = (gl_ModelViewMatrix * gl_Vertex).xyz;
101 | color = gl_Color;
102 | }
103 | );
104 |
105 | const char flat_frag[] = shader_text(
106 | varying vec3 pos;
107 | varying vec4 color;
108 | void main()
109 | {
110 | vec4 ambient = color * gl_LightSource[0].ambient;
111 | vec3 dposdx = vec3(dFdx(pos.x), dFdx(pos.y), dFdx(pos.z));
112 | vec3 dposdy = vec3(dFdy(pos.x), dFdy(pos.y), dFdy(pos.z));
113 | vec3 nnorm = normalize(cross(dposdx, dposdy));
114 | float ndotl = abs(dot(nnorm, gl_LightSource[0].position.xyz));
115 | vec4 diffuse = color * gl_LightSource[0].diffuse * ndotl;
116 | float ndoth = abs(dot(nnorm, gl_LightSource[0].halfVector.xyz));
117 | vec4 specular = gl_FrontMaterial.specular *
118 | pow(ndoth, gl_FrontMaterial.shininess);
119 | gl_FragColor = ambient + diffuse + specular;
120 | }
121 | );
122 |
123 | #endif
124 |
--------------------------------------------------------------------------------
/gluit/glui_stdinc.h:
--------------------------------------------------------------------------------
1 | #ifndef _STDINC_H_
2 | #define _STDINC_H_
3 |
4 | #include
5 | #include
6 | #include
7 | using namespace std;
8 |
9 | #ifndef AND
10 | #define AND &&
11 | #define OR ||
12 | #define NOT !
13 | #endif
14 |
15 | #ifndef true
16 | #define true 1
17 | #define false 0
18 | #endif
19 |
20 | #ifndef Bool
21 | typedef char Bool;
22 | #endif
23 |
24 | #ifndef MAX
25 | #define MAX(a,b) ((a)>(b) ? (a) : (b))
26 | #define MIN(a,b) ((a)<(b) ? (a) : (b))
27 | #endif
28 |
29 | #ifndef ABS
30 | #define ABS(a) ((a)>=0 ? (a) : (-(a)))
31 | #endif
32 |
33 | /********* TOGGLE_BOOL(boolean) : toggles values of 'boolean' ******/
34 | #ifndef TOGGLE_BOOL
35 | #define TOGGLE_BOOL(a) ((a)=1-(a))
36 | #endif
37 |
38 |
39 | /******************** bit comparisons and operations ***************/
40 | #ifndef TEST_BIT
41 | #define TEST_BIT( x, b ) (((x) & (1<<(b))) != 0 )
42 | #define SET_BIT( x, b ) ((x) |= (1 << (b)))
43 | #define CLEAR_BIT( x, b ) ((x) &= ~(1 << (b)))
44 | #define TOGGLE_BIT( x, b ) ((TEST_BIT(x,b)) ?(CLEAR_BIT(x,b)):(SET_BIT(x,b)))
45 | #endif
46 |
47 | #ifndef TEST_AND
48 | #define TEST_AND( a, b ) ((a&b)==b)
49 | #endif
50 |
51 |
52 | typedef char String[81];
53 |
54 |
55 | /*********** flush the stdout and stderr output streams *************/
56 | #ifndef flushout
57 | #define flushout fflush(stdout)
58 | #define flusherr fflush(stderr)
59 | #endif
60 |
61 |
62 | /********** Debugging functions *************************************/
63 | #ifndef error_return
64 | #define error_return( c ); {fprintf(stderr,c);return;}
65 | #endif
66 |
67 |
68 | /************************* floating-point random ********************/
69 | #ifndef randf
70 | #define randf() ((float) rand() / (float)RAND_MAX )
71 | #endif
72 |
73 | #ifndef SIGN
74 | #define SIGN(x) ((x)>=0 ? 1 : -1)
75 | #endif
76 |
77 |
78 | /****************** conversion between degrees and radians **********/
79 | #ifndef DEG2RAD
80 | # define DEG2RAD(x) ((x) * 3.1415927f / 180.0f)
81 | # define RAD2DEG(x) ((x) * 180.0f / 3.1415927f)
82 | #endif
83 |
84 |
85 | /***************** clamp a value to some fixed interval *************/
86 | #ifndef CLAMP
87 | #define CLAMP(x,lo,hi) {if ((x) < (lo)) {(x)=(lo);} else if((x) > (hi)) {(x)=(hi);}}
88 | #endif
89 |
90 |
91 |
92 | /************ check if a value lies within a closed interval *********/
93 | #ifndef IN_BOUNDS
94 | #define IN_BOUNDS( x, lo, hi ) ( (x) >= (lo) AND (x) <= (hi) )
95 | #endif
96 |
97 |
98 | /************ check if a 2D point lies within a 2D box ***************/
99 | #ifndef PT_IN_BOX
100 | #define PT_IN_BOX( x, y, lo_x, hi_x, lo_y, hi_y ) \
101 | ( IN_BOUNDS(x,lo_x,hi_x) AND IN_BOUNDS(y,lo_y,hi_y) )
102 | #endif
103 |
104 | /****** check if value lies on proper side of another value *****/
105 | /*** if side is positive => proper side is positive, else negative **/
106 | #ifndef CHECK_PROPER_SIDE
107 | #define CHECK_PROPER_SIDE(x,val,side) ((side) > 0 ? (x) > (val) : (x) < (val))
108 | #endif
109 |
110 |
111 | /***** Small value when we want to do a comparison to 'close to zero' *****/
112 | #ifndef FUDGE
113 | #define FUDGE .00001
114 | #endif
115 |
116 |
117 | /******************* swap two values, using a temp variable *********/
118 | #ifndef SWAP2
119 | #define SWAP2(a,b,t) {t=a;a=b;b=t;}
120 | #endif
121 |
122 | #define VEC3_TO_ARRAY(v,a) a[0]=v[0], a[1]=v[1], a[2]=v[2]
123 |
124 | #endif /* _STDINC_H_ */
125 |
126 |
127 |
128 |
129 |
130 |
--------------------------------------------------------------------------------
/include/strutil.h:
--------------------------------------------------------------------------------
1 | #ifndef STRUTIL_H
2 | #define STRUTIL_H
3 | /*
4 | Szymon Rusinkiewicz
5 | Princeton University
6 |
7 | strutil.h
8 | Miscellaneous string-manipulation utilities
9 |
10 | Usage:
11 | std::string s("foo.bar");
12 | std::string s2 = replace_ext(s, "baz"); // "foo.baz"
13 | std::string s2 = replace_ext(s, ""); // "foo"
14 | std::string s3 = string_printf("%d", 42);
15 |
16 | // All of the below are case-insensitive
17 | begins_with("Foobar", "foo") // true
18 | ends_with("foobar", "baz") // false
19 | contains("fooBar", "bar") // true
20 | */
21 |
22 |
23 | #include
24 | #include
25 | #include
26 | #include
27 | #include
28 |
29 | #ifdef _MSC_VER
30 | # ifndef strcasecmp
31 | # define strcasecmp _stricmp
32 | # endif
33 | # ifndef strncasecmp
34 | # define strncasecmp _strnicmp
35 | # endif
36 | # ifndef strdup
37 | # define strdup _strdup
38 | # endif
39 | #endif
40 |
41 |
42 | namespace trimesh {
43 |
44 | // Replace the extension of a filename, else add one if none present
45 | static inline ::std::string replace_ext(const ::std::string &filename,
46 | const ::std::string &ext)
47 | {
48 | using namespace ::std;
49 | string x = filename;
50 | string::size_type dot = x.rfind(".", x.length());
51 | if (dot != string::npos)
52 | x.erase(dot);
53 | if (ext.empty())
54 | return x;
55 | else
56 | return x + string(".") + ext;
57 | }
58 |
59 |
60 | // sprintf to a c++ string
61 | static inline ::std::string string_printf(const char *format, ...)
62 | {
63 | va_list ap;
64 | va_start(ap, format);
65 | size_t required = 1 + ::std::vsnprintf(NULL, 0, format, ap);
66 | va_end(ap);
67 | char *buf = new char[required];
68 | va_start(ap, format);
69 | ::std::vsnprintf(buf, required, format, ap);
70 | va_end(ap);
71 | ::std::string s(buf);
72 | delete [] buf;
73 | return s;
74 | }
75 |
76 |
77 | // Does string s1 begin with / end with / contain s2? (Case-insensitive)
78 | static inline bool begins_with(const char *s1, const char *s2)
79 | {
80 | using namespace ::std;
81 | return !strncasecmp(s1, s2, strlen(s2));
82 | }
83 |
84 | static inline bool begins_with(const ::std::string &s1, const ::std::string &s2)
85 | {
86 | return begins_with(s1.c_str(), s2.c_str());
87 | }
88 |
89 | static inline bool ends_with(const char *s1, const char *s2)
90 | {
91 | using namespace ::std;
92 | size_t l1 = strlen(s1), l2 = strlen(s2);
93 | return (l1 >= l2) && !strncasecmp(s1 + l1 - l2, s2, l2);
94 | }
95 |
96 | static inline bool ends_with(const ::std::string &s1, const ::std::string &s2)
97 | {
98 | return ends_with(s1.c_str(), s2.c_str());
99 | }
100 |
101 | static inline bool contains(const char *s1, const char *s2)
102 | {
103 | using namespace ::std;
104 | size_t len1 = strlen(s1), len2 = strlen(s2);
105 |
106 | // strcasestr is not portable, so simulate it
107 | char *lower1 = new char[len1 + 1];
108 | for (size_t i = 0; i < len1; i++)
109 | lower1[i] = tolower(s1[i]);
110 | lower1[len1] = '\0';
111 |
112 | char *lower2 = new char[len2 + 1];
113 | for (size_t i = 0; i < len2; i++)
114 | lower2[i] = tolower(s2[i]);
115 | lower2[len2] = '\0';
116 |
117 | bool found = (bool) strstr(lower1, lower2);
118 |
119 | delete [] lower2;
120 | delete [] lower1;
121 | return found;
122 | }
123 |
124 | static inline bool contains(const ::std::string &s1, const ::std::string &s2)
125 | {
126 | return contains(s1.c_str(), s2.c_str());
127 | }
128 |
129 | } // namespace trimesh
130 |
131 | #endif
132 |
--------------------------------------------------------------------------------
/libsrc/TriMesh_bounding.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Szymon Rusinkiewicz
3 | Princeton University
4 |
5 | TriMesh_bounding.cc
6 | Bounding box and bounding sphere.
7 | */
8 |
9 |
10 | #include "TriMesh.h"
11 | #include "bsphere.h"
12 | using namespace std;
13 |
14 |
15 | namespace trimesh {
16 |
17 | // Find axis-aligned bounding box of the vertices
18 | void TriMesh::need_bbox()
19 | {
20 | if (vertices.empty() || bbox.valid)
21 | return;
22 |
23 | dprintf("Computing bounding box... ");
24 |
25 | for (size_t i = 0; i < vertices.size(); i++)
26 | bbox += vertices[i];
27 |
28 | dprintf("Done.\n x = %g .. %g, y = %g .. %g, z = %g .. %g\n",
29 | bbox.min[0], bbox.max[0], bbox.min[1],
30 | bbox.max[1], bbox.min[2], bbox.max[2]);
31 | }
32 |
33 |
34 | // Change this to #if 0 to enable a simpler (approximate) bsphere computation
35 | // that does not use the Miniball code
36 | #if 1
37 |
38 | // Compute bounding sphere of the vertices.
39 | void TriMesh::need_bsphere()
40 | {
41 | if (vertices.empty() || bsphere.valid)
42 | return;
43 |
44 | dprintf("Computing bounding sphere... ");
45 |
46 | Miniball<3,float> mb;
47 | mb.check_in(vertices.begin(), vertices.end());
48 | mb.build();
49 | bsphere.center = mb.center();
50 | bsphere.r = sqrt(mb.squared_radius());
51 | bsphere.valid = true;
52 |
53 | dprintf("Done.\n center = (%g, %g, %g), radius = %g\n",
54 | bsphere.center[0], bsphere.center[1],
55 | bsphere.center[2], bsphere.r);
56 | }
57 |
58 | #else
59 |
60 | // Find extreme vertex in a given direction
61 | static int farthest_vertex_along(const TriMesh &t, const vec &dir)
62 | {
63 | const vector &v = t.vertices;
64 | int nv = v.size();
65 |
66 | int farthest = 0;
67 | float farthest_dot = v[0] DOT dir;
68 |
69 | for (int i = 1; i < nv; i++) {
70 | float my_dot = v[i] DOT dir;
71 | if (my_dot > farthest_dot)
72 | farthest = i, farthest_dot = my_dot;
73 | }
74 | return farthest;
75 | }
76 |
77 |
78 | // Approximate bounding sphere code based on an algorithm by Ritter
79 | void TriMesh::need_bsphere()
80 | {
81 | if (vertices.empty() || bsphere.valid)
82 | return;
83 |
84 | need_bbox();
85 | dprintf("Computing bounding sphere... ");
86 |
87 | point best_min, best_max;
88 | vector dirs;
89 | dirs.push_back(vec(1,0,0));
90 | dirs.push_back(vec(0,1,0));
91 | dirs.push_back(vec(0,0,1));
92 | dirs.push_back(vec(1,1,1));
93 | dirs.push_back(vec(1,-1,1));
94 | dirs.push_back(vec(1,-1,-1));
95 | dirs.push_back(vec(1,1,-1));
96 | for (int i = 0; i < dirs.size(); i++) {
97 | point p1 = vertices[farthest_vertex_along(*this, -dirs[i])];
98 | point p2 = vertices[farthest_vertex_along(*this, dirs[i])];
99 | if (dist2(p1, p2) > dist2(best_min, best_max)) {
100 | best_min = p1;
101 | best_max = p2;
102 | }
103 | }
104 | bsphere.center = 0.5f * (best_min + best_max);
105 | bsphere.r = 0.5f * dist(best_min, best_max);
106 | float r2 = sqr(bsphere.r);
107 |
108 | // Expand bsphere to contain all points
109 | for (int i = 0; i < vertices.size(); i++) {
110 | float d2 = dist2(vertices[i], bsphere.center);
111 | if (d2 <= r2)
112 | continue;
113 | float d = sqrt(d2);
114 | bsphere.r = 0.5f * (bsphere.r + d);
115 | r2 = sqr(bsphere.r);
116 | bsphere.center -= vertices[i];
117 | bsphere.center *= bsphere.r / d;
118 | bsphere.center += vertices[i];
119 | }
120 |
121 | bsphere.valid = true;
122 | dprintf("Done.\n center = (%g, %g, %g), radius = %g\n",
123 | bsphere.center[0], bsphere.center[1],
124 | bsphere.center[2], bsphere.r);
125 | }
126 |
127 | #endif
128 |
129 | } // namespace trimesh
130 |
--------------------------------------------------------------------------------
/utilsrc/mesh_align.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Szymon Rusinkiewicz
3 | Princeton University
4 |
5 | mesh_align.cc
6 | Minimal interface to ICP: register two meshes given an initial guess
7 | for their alignment.
8 | */
9 |
10 |
11 | #include "TriMesh.h"
12 | #include "TriMesh_algo.h"
13 | #include "ICP.h"
14 | #include "timestamp.h"
15 | #ifdef _WIN32
16 | # include "wingetopt.h"
17 | #else
18 | # include
19 | #endif
20 | #include
21 | using namespace std;
22 | using namespace trimesh;
23 |
24 |
25 | void usage(const char *myname)
26 | {
27 | fprintf(stderr, "Usage: %s [-options] mesh1.ply mesh2.ply\n", myname);
28 | fprintf(stderr, "Reads transforms in mesh1.xf and mesh2.xf, updates the latter\n");
29 | fprintf(stderr, "Options:\n");
30 | fprintf(stderr, " -a Align using affine xform\n");
31 | fprintf(stderr, " -b Bulk mode: overlap checking, write to mesh1--mesh2.xf\n");
32 | fprintf(stderr, " -r Align using rigid-body transform (default)\n");
33 | fprintf(stderr, " -s Align using rigid + isotropic scale\n");
34 | fprintf(stderr, " -t Align using translation only\n");
35 | fprintf(stderr, " -v Verbose\n");
36 | exit(1);
37 | }
38 |
39 | int main(int argc, char *argv[])
40 | {
41 | ICP_xform_type xform_type = ICP_RIGID;
42 | int verbose = 0;
43 | bool bulkmode = false;
44 |
45 | int c;
46 | while ((c = getopt(argc, argv, "harstvb")) != EOF) {
47 | switch (c) {
48 | case 'a': xform_type = ICP_AFFINE; break;
49 | case 'r': xform_type = ICP_RIGID; break;
50 | case 's': xform_type = ICP_SIMILARITY; break;
51 | case 't': xform_type = ICP_TRANSLATION; break;
52 | case 'v': verbose = 2; break;
53 | case 'b': bulkmode = true; break;
54 | default: usage(argv[0]);
55 | }
56 | }
57 |
58 | TriMesh::set_verbose(verbose);
59 |
60 | if (argc - optind < 2)
61 | usage(argv[0]);
62 | const char *filename1 = argv[optind], *filename2 = argv[optind+1];
63 |
64 | TriMesh *mesh1 = TriMesh::read(filename1);
65 | if (!mesh1)
66 | usage(argv[0]);
67 | TriMesh *mesh2 = TriMesh::read(filename2);
68 | if (!mesh2)
69 | usage(argv[0]);
70 |
71 | xform xf1;
72 | string xffilename1 = xfname(filename1);
73 | xf1.read(xffilename1);
74 |
75 | xform xf2;
76 | string xffilename2 = xfname(filename2);
77 | xf2.read(xffilename2);
78 |
79 | timestamp t = now();
80 | KDtree *kd1 = new KDtree(mesh1->vertices);
81 | KDtree *kd2 = new KDtree(mesh2->vertices);
82 | if (verbose > 1) {
83 | TriMesh::dprintf("Building KDtrees: %.3f msec.\n",
84 | (now() - t) * 1000.0f);
85 | }
86 | vector weights1, weights2;
87 |
88 | if (bulkmode) {
89 | float area1 = mesh1->stat(TriMesh::STAT_SUM, TriMesh::STAT_FACEAREA);
90 | float area2 = mesh2->stat(TriMesh::STAT_SUM, TriMesh::STAT_FACEAREA);
91 | float overlap_area, overlap_dist;
92 | find_overlap(mesh1, mesh2, xf1, xf2, kd1, kd2,
93 | overlap_area, overlap_dist);
94 | float frac_overlap = overlap_area / min(area1, area2);
95 | if (frac_overlap < 0.1f) {
96 | TriMesh::eprintf("Insufficient overlap\n");
97 | exit(1);
98 | } else {
99 | TriMesh::dprintf("%.1f%% overlap\n",
100 | frac_overlap * 100.0f);
101 | }
102 | }
103 |
104 | float err = ICP(mesh1, mesh2, xf1, xf2, kd1, kd2, weights1, weights2,
105 | 0.0f, verbose, xform_type);
106 |
107 | if (err < 0.0f) {
108 | TriMesh::eprintf("ICP failed\n");
109 | exit(1);
110 | }
111 |
112 | TriMesh::eprintf("ICP succeeded - distance = %f\n", err);
113 | if (bulkmode) {
114 | string xffilename12 = filename1;
115 | size_t dot = xffilename12.rfind(".", xffilename12.length());
116 | if (dot != string::npos)
117 | xffilename12.erase(dot);
118 | xffilename12 += string("--") + replace_ext(filename2, "xf");
119 | xform xf12 = inv(xf2) * xf1;
120 | xf12.write(xffilename12);
121 | } else {
122 | xf2.write(xffilename2);
123 | }
124 | }
125 |
--------------------------------------------------------------------------------
/include/KDtree.h:
--------------------------------------------------------------------------------
1 | #ifndef KDTREE_H
2 | #define KDTREE_H
3 | /*
4 | Szymon Rusinkiewicz
5 | Princeton University
6 |
7 | KDtree.h
8 | A K-D tree for points, with limited capabilities (find nearest point to
9 | a given point, or to a ray).
10 |
11 | Note that in order to be generic, this *doesn't* use Vecs and the like...
12 | */
13 |
14 | #include
15 | #include
16 |
17 | namespace trimesh {
18 |
19 | using ::std::size_t;
20 |
21 | class KDtree {
22 | private:
23 | struct Node;
24 | struct NodeStorageBlock;
25 |
26 | Node *root;
27 | NodeStorageBlock *storage;
28 |
29 | void build(const float *ptlist, size_t n);
30 | void build(const float **pts, size_t n);
31 |
32 | public:
33 | // Compatibility function for closest-compatible-point searches
34 | struct CompatFunc
35 | {
36 | virtual bool operator () (const float *p) const = 0;
37 | virtual ~CompatFunc() {} // To make the compiler shut up
38 | };
39 |
40 | // Constructors from an array or vector of points
41 | KDtree(const float *ptlist, size_t n) : root(NULL), storage(NULL)
42 | { build(ptlist, n); }
43 |
44 | template KDtree(const ::std::vector &v) : root(NULL), storage(NULL)
45 | { build((const float *) &v[0], v.size()); }
46 |
47 | // Constructors from an array or vector of pointers to points
48 | KDtree(const float **pts, size_t n) : root(NULL), storage(NULL)
49 | { build(pts, n); }
50 |
51 | template KDtree(::std::vector &pts) : root(NULL), storage(NULL)
52 | { build((const float **) &pts[0], pts.size()); }
53 |
54 | // Destructor - frees the whole tree
55 | ~KDtree();
56 |
57 | // Returns closest point to a given point p,
58 | // provided it's within sqrt(maxdist2) and is compatible.
59 | // If an approximation epsilon is provided, the queries will
60 | // return a point within a factor of (1+eps) of the closest.
61 | const float *closest_to_pt(const float *p,
62 | float maxdist2 = 0.0f,
63 | const CompatFunc *iscompat = NULL,
64 | float approx_eps = 0.0f) const;
65 |
66 | // Shorthand with approx_eps but no iscompat
67 | const float *closest_to_pt(const float *p,
68 | float maxdist2,
69 | float approx_eps) const
70 | { return closest_to_pt(p, maxdist2, NULL, approx_eps); }
71 |
72 |
73 | // Returns closest point to a ray through p in direction dir
74 | const float *closest_to_ray(const float *p, const float *dir,
75 | float maxdist2 = 0.0f,
76 | const CompatFunc *iscompat = NULL,
77 | float approx_eps = 0.0f) const;
78 |
79 | // Shorthand with approx_eps but no iscompat
80 | const float *closest_to_ray(const float *p, const float *dir,
81 | float maxdist2,
82 | float approx_eps) const
83 | { return closest_to_ray(p, dir, maxdist2, NULL, approx_eps); }
84 |
85 | // Find the k nearest neighbors to p, filling in knn array
86 | void find_k_closest_to_pt(::std::vector &knn,
87 | int k,
88 | const float *p,
89 | float maxdist2 = 0.0f,
90 | const CompatFunc *iscompat = NULL,
91 | float approx_eps = 0.0f) const;
92 |
93 | // Shorthand with approx_eps but no iscompat
94 | void find_k_closest_to_pt(::std::vector &knn,
95 | int k,
96 | const float *p,
97 | float maxdist2,
98 | float approx_eps) const
99 | { return find_k_closest_to_pt(knn, k, p, maxdist2, NULL, approx_eps); }
100 |
101 | // Is there a point within a given distance of a query?
102 | bool exists_pt_within(const float *p, float maxdist) const;
103 | };
104 |
105 | } // namespace trimesh
106 |
107 | #endif
108 |
--------------------------------------------------------------------------------
/libsrc/remove.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Szymon Rusinkiewicz
3 | Princeton University
4 |
5 | remove.cc
6 | Removing sets of vertices or faces from TriMeshes.
7 | */
8 |
9 | #include "TriMesh.h"
10 | #include "TriMesh_algo.h"
11 | using namespace std;
12 | #define dprintf TriMesh::dprintf
13 |
14 |
15 | namespace trimesh {
16 |
17 | // Remove the indicated vertices from the TriMesh.
18 | void remove_vertices(TriMesh *mesh, const vector &toremove)
19 | {
20 | int nv = mesh->vertices.size();
21 |
22 | // Build a table that tells how the vertices will be remapped
23 | if (!nv)
24 | return;
25 |
26 | vector remap_table(nv);
27 | int next = 0;
28 | for (int i = 0; i < nv; i++) {
29 | if (toremove[i])
30 | remap_table[i] = -1;
31 | else
32 | remap_table[i] = next++;
33 | }
34 |
35 | // Nothing to delete?
36 | if (next == nv)
37 | return;
38 |
39 | dprintf("Removing vertices... ");
40 | remap_verts(mesh, remap_table);
41 | dprintf("%d vertices removed... Done.\n", nv - next);
42 | }
43 |
44 |
45 | // Remove vertices that aren't referenced by any face
46 | void remove_unused_vertices(TriMesh *mesh)
47 | {
48 | int nv = mesh->vertices.size();
49 | if (!nv)
50 | return;
51 |
52 | bool had_faces = !mesh->faces.empty();
53 | mesh->need_faces();
54 | int nf = mesh->faces.size();
55 | vector unused(nv, true);
56 | for (int i = 0; i < nf; i++) {
57 | unused[mesh->faces[i][0]] = false;
58 | unused[mesh->faces[i][1]] = false;
59 | unused[mesh->faces[i][2]] = false;
60 | }
61 | remove_vertices(mesh, unused);
62 | if (!had_faces)
63 | mesh->clear_faces();
64 | }
65 |
66 |
67 | // Remove faces as indicated by toremove. Should probably be
68 | // followed by a call to remove_unused_vertices()
69 | void remove_faces(TriMesh *mesh, const vector &toremove)
70 | {
71 | bool had_tstrips = !mesh->tstrips.empty();
72 | bool had_faces = !mesh->faces.empty();
73 | mesh->need_faces();
74 | int numfaces = mesh->faces.size();
75 | if (!numfaces)
76 | return;
77 |
78 | mesh->clear_tstrips();
79 | mesh->clear_adjacentfaces();
80 | mesh->clear_neighbors();
81 | mesh->clear_across_edge();
82 | mesh->clear_pointareas();
83 |
84 | dprintf("Removing faces... ");
85 | int next = 0;
86 | for (int i = 0; i < numfaces; i++) {
87 | if (toremove[i])
88 | continue;
89 | mesh->faces[next++] = mesh->faces[i];
90 | }
91 | if (next == numfaces) {
92 | dprintf("None removed.\n");
93 | return;
94 | }
95 |
96 | mesh->faces.erase(mesh->faces.begin() + next, mesh->faces.end());
97 | dprintf("%d faces removed... Done.\n", numfaces - next);
98 |
99 | if (had_tstrips)
100 | mesh->need_tstrips();
101 | if (!had_faces)
102 | mesh->clear_faces();
103 |
104 | mesh->bbox.valid = false;
105 | mesh->bsphere.valid = false;
106 | }
107 |
108 |
109 | // Remove long, skinny faces. Should probably be followed by a
110 | // call to remove_unused_vertices()
111 | void remove_sliver_faces(TriMesh *mesh)
112 | {
113 | mesh->need_faces();
114 | int numfaces = mesh->faces.size();
115 |
116 | const float l2thresh = sqr(4.0f * mesh->feature_size());
117 | const float cos2thresh = 0.85f;
118 | vector toremove(numfaces, false);
119 | for (int i = 0; i < numfaces; i++) {
120 | const point &v0 = mesh->vertices[mesh->faces[i][0]];
121 | const point &v1 = mesh->vertices[mesh->faces[i][1]];
122 | const point &v2 = mesh->vertices[mesh->faces[i][2]];
123 | float d01 = dist2(v0, v1);
124 | float d12 = dist2(v1, v2);
125 | float d20 = dist2(v2, v0);
126 | if (d01 < l2thresh && d12 < l2thresh && d20 < l2thresh)
127 | continue;
128 | // c2 is square of cosine of smallest angle
129 | float m = min(min(d01,d12),d20);
130 | float c2 = sqr(d01+d12+d20-2.0f*m) * m/(4.0f*d01*d12*d20);
131 | if (c2 < cos2thresh)
132 | continue;
133 | toremove[i] = true;
134 | }
135 | remove_faces(mesh, toremove);
136 | }
137 |
138 | } // namespace trimesh
139 |
--------------------------------------------------------------------------------
/gluit/freeglut_display.c:
--------------------------------------------------------------------------------
1 | /*
2 | * freeglut_display.c
3 | *
4 | * Display message posting, context buffer swapping.
5 | *
6 | * Copyright (c) 1999-2000 Pawel W. Olszta. All Rights Reserved.
7 | * Written by Pawel W. Olszta,
8 | * Creation date: Fri Dec 3 1999
9 | *
10 | * Permission is hereby granted, free of charge, to any person obtaining a
11 | * copy of this software and associated documentation files (the "Software"),
12 | * to deal in the Software without restriction, including without limitation
13 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 | * and/or sell copies of the Software, and to permit persons to whom the
15 | * Software is furnished to do so, subject to the following conditions:
16 | *
17 | * The above copyright notice and this permission notice shall be included
18 | * in all copies or substantial portions of the Software.
19 | *
20 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
24 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
25 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 | */
27 |
28 | #include
29 | #include "freeglut_internal.h"
30 |
31 | /* -- INTERFACE FUNCTIONS -------------------------------------------------- */
32 |
33 | /*
34 | * Marks the current window to have the redisplay performed when possible...
35 | */
36 | void FGAPIENTRY glutPostRedisplay( void )
37 | {
38 | FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPostRedisplay" );
39 | if ( ! fgStructure.CurrentWindow )
40 | {
41 | fgError ( " ERROR: Function <%s> called"
42 | " with no current window defined.", "glutPostRedisplay" ) ;
43 | }
44 |
45 | fgStructure.CurrentWindow->State.Redisplay = GL_TRUE;
46 | }
47 |
48 | /*
49 | * Swaps the buffers for the current window (if any)
50 | */
51 | void FGAPIENTRY glutSwapBuffers( void )
52 | {
53 | FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutSwapBuffers" );
54 | FREEGLUT_EXIT_IF_NO_WINDOW ( "glutSwapBuffers" );
55 |
56 | /*
57 | * "glXSwapBuffers" already performs an implicit call to "glFlush". What
58 | * about "SwapBuffers"?
59 | */
60 | glFlush( );
61 | if( ! fgStructure.CurrentWindow->Window.DoubleBuffered )
62 | return;
63 |
64 | #if TARGET_HOST_POSIX_X11
65 | glXSwapBuffers( fgDisplay.Display, fgStructure.CurrentWindow->Window.Handle );
66 | #elif TARGET_HOST_MS_WINDOWS
67 | SwapBuffers( fgStructure.CurrentWindow->Window.Device );
68 | #endif
69 |
70 | /* GLUT_FPS env var support */
71 | if( fgState.FPSInterval )
72 | {
73 | GLint t = glutGet( GLUT_ELAPSED_TIME );
74 | fgState.SwapCount++;
75 | if( fgState.SwapTime == 0 )
76 | fgState.SwapTime = t;
77 | else if( t - fgState.SwapTime > fgState.FPSInterval )
78 | {
79 | float time = 0.001f * ( t - fgState.SwapTime );
80 | float fps = ( float )fgState.SwapCount / time;
81 | fprintf( stderr,
82 | "freeglut: %d frames in %.2f seconds = %.2f FPS\n",
83 | fgState.SwapCount, time, fps );
84 | fgState.SwapTime = t;
85 | fgState.SwapCount = 0;
86 | }
87 | }
88 | }
89 |
90 | /*
91 | * Mark appropriate window to be displayed
92 | */
93 | void FGAPIENTRY glutPostWindowRedisplay( int windowID )
94 | {
95 | SFG_Window* window;
96 |
97 | FREEGLUT_EXIT_IF_NOT_INITIALISED ( "glutPostWindowRedisplay" );
98 | window = fgWindowByID( windowID );
99 | freeglut_return_if_fail( window );
100 | window->State.Redisplay = GL_TRUE;
101 | }
102 |
103 | /*** END OF FILE ***/
104 |
--------------------------------------------------------------------------------
/gluit/glui_img_downarrow.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_downarrow[] = { 16, 16, /* width, height */
4 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7 | 0, 0, 0, 192,192,192, 128,128,128, 128,128,128, 128,128,128,
8 | 128,128,128, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
9 | 128,128,128, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
10 | 128,128,128, 0, 0, 0, 192,192,192, 255,255,255, 192,192,192,
11 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
12 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
13 | 192,192,192, 128,128,128, 0, 0, 0, 192,192,192, 255,255,255,
14 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
15 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
16 | 192,192,192, 192,192,192, 128,128,128, 0, 0, 0, 192,192,192,
17 | 255,255,255, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
18 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
19 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
20 | 192,192,192, 255,255,255, 192,192,192, 192,192,192, 192,192,192,
21 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
22 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 128,128,128,
23 | 0, 0, 0, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
24 | 192,192,192, 192,192,192, 192,192,192, 0, 0, 0, 192,192,192,
25 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
26 | 128,128,128, 0, 0, 0, 192,192,192, 255,255,255, 192,192,192,
27 | 192,192,192, 192,192,192, 192,192,192, 0, 0, 0, 0, 0, 0,
28 | 0, 0, 0, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
29 | 192,192,192, 128,128,128, 0, 0, 0, 192,192,192, 255,255,255,
30 | 192,192,192, 192,192,192, 192,192,192, 0, 0, 0, 0, 0, 0,
31 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 192,192,192, 192,192,192,
32 | 192,192,192, 192,192,192, 128,128,128, 0, 0, 0, 192,192,192,
33 | 255,255,255, 192,192,192, 192,192,192, 0, 0, 0, 0, 0, 0,
34 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
35 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
36 | 192,192,192, 255,255,255, 192,192,192, 192,192,192, 192,192,192,
37 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
38 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 128,128,128,
39 | 0, 0, 0, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
40 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
41 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
42 | 128,128,128, 0, 0, 0, 192,192,192, 255,255,255, 192,192,192,
43 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
44 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
45 | 192,192,192, 128,128,128, 0, 0, 0, 192,192,192, 255,255,255,
46 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
47 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
48 | 192,192,192, 192,192,192, 128,128,128, 0, 0, 0, 192,192,192,
49 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
50 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
51 | 255,255,255, 255,255,255, 255,255,255, 128,128,128, 0, 0, 0,
52 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
53 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
54 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
55 | 0, 0, 0,
56 | };
57 |
--------------------------------------------------------------------------------
/gluit/glui_img_leftarrow.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_leftarrow[] = { 16, 16, /* width, height */
4 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7 | 0, 0, 0, 192,192,192, 128,128,128, 128,128,128, 128,128,128,
8 | 128,128,128, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
9 | 128,128,128, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
10 | 128,128,128, 0, 0, 0, 192,192,192, 255,255,255, 192,192,192,
11 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
12 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
13 | 192,192,192, 128,128,128, 0, 0, 0, 192,192,192, 255,255,255,
14 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
15 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
16 | 192,192,192, 192,192,192, 128,128,128, 0, 0, 0, 192,192,192,
17 | 255,255,255, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
18 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
19 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
20 | 192,192,192, 255,255,255, 192,192,192, 192,192,192, 192,192,192,
21 | 192,192,192, 192,192,192, 192,192,192, 0, 0, 0, 192,192,192,
22 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 128,128,128,
23 | 0, 0, 0, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
24 | 192,192,192, 192,192,192, 192,192,192, 0, 0, 0, 0, 0, 0,
25 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
26 | 128,128,128, 0, 0, 0, 192,192,192, 255,255,255, 192,192,192,
27 | 192,192,192, 192,192,192, 192,192,192, 0, 0, 0, 0, 0, 0,
28 | 0, 0, 0, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
29 | 192,192,192, 128,128,128, 0, 0, 0, 192,192,192, 255,255,255,
30 | 192,192,192, 192,192,192, 192,192,192, 0, 0, 0, 0, 0, 0,
31 | 0, 0, 0, 0, 0, 0, 192,192,192, 192,192,192, 192,192,192,
32 | 192,192,192, 192,192,192, 128,128,128, 0, 0, 0, 192,192,192,
33 | 255,255,255, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
34 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 192,192,192, 192,192,192,
35 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
36 | 192,192,192, 255,255,255, 192,192,192, 192,192,192, 192,192,192,
37 | 192,192,192, 192,192,192, 0, 0, 0, 0, 0, 0, 192,192,192,
38 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 128,128,128,
39 | 0, 0, 0, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
40 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 0, 0, 0,
41 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
42 | 128,128,128, 0, 0, 0, 192,192,192, 255,255,255, 192,192,192,
43 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
44 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
45 | 192,192,192, 128,128,128, 0, 0, 0, 192,192,192, 255,255,255,
46 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
47 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
48 | 192,192,192, 192,192,192, 128,128,128, 0, 0, 0, 192,192,192,
49 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
50 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
51 | 255,255,255, 255,255,255, 255,255,255, 128,128,128, 0, 0, 0,
52 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
53 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
54 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
55 | 0, 0, 0,
56 | };
57 |
--------------------------------------------------------------------------------
/gluit/glui_img_uparrow.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_uparrow[] = { 16, 16, /* width, height */
4 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7 | 0, 0, 0, 192,192,192, 128,128,128, 128,128,128, 128,128,128,
8 | 128,128,128, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
9 | 128,128,128, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
10 | 128,128,128, 0, 0, 0, 192,192,192, 255,255,255, 192,192,192,
11 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
12 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
13 | 192,192,192, 128,128,128, 0, 0, 0, 192,192,192, 255,255,255,
14 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
15 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
16 | 192,192,192, 192,192,192, 128,128,128, 0, 0, 0, 192,192,192,
17 | 255,255,255, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
18 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
19 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
20 | 192,192,192, 255,255,255, 192,192,192, 192,192,192, 192,192,192,
21 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
22 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 128,128,128,
23 | 0, 0, 0, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
24 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
25 | 0, 0, 0, 0, 0, 0, 192,192,192, 192,192,192, 192,192,192,
26 | 128,128,128, 0, 0, 0, 192,192,192, 255,255,255, 192,192,192,
27 | 192,192,192, 192,192,192, 0, 0, 0, 0, 0, 0, 0, 0, 0,
28 | 0, 0, 0, 0, 0, 0, 192,192,192, 192,192,192, 192,192,192,
29 | 192,192,192, 128,128,128, 0, 0, 0, 192,192,192, 255,255,255,
30 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 0, 0, 0,
31 | 0, 0, 0, 0, 0, 0, 192,192,192, 192,192,192, 192,192,192,
32 | 192,192,192, 192,192,192, 128,128,128, 0, 0, 0, 192,192,192,
33 | 255,255,255, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
34 | 192,192,192, 0, 0, 0, 192,192,192, 192,192,192, 192,192,192,
35 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
36 | 192,192,192, 255,255,255, 192,192,192, 192,192,192, 192,192,192,
37 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
38 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 128,128,128,
39 | 0, 0, 0, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
40 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
41 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
42 | 128,128,128, 0, 0, 0, 192,192,192, 255,255,255, 192,192,192,
43 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
44 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
45 | 192,192,192, 128,128,128, 0, 0, 0, 192,192,192, 255,255,255,
46 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
47 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
48 | 192,192,192, 192,192,192, 128,128,128, 0, 0, 0, 192,192,192,
49 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
50 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
51 | 255,255,255, 255,255,255, 255,255,255, 128,128,128, 0, 0, 0,
52 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
53 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
54 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
55 | 0, 0, 0,
56 | };
57 |
--------------------------------------------------------------------------------
/gluit/glui_img_rightarrow.c:
--------------------------------------------------------------------------------
1 |
2 |
3 | int glui_img_rightarrow[] = { 16, 16, /* width, height */
4 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
5 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
6 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
7 | 0, 0, 0, 192,192,192, 128,128,128, 128,128,128, 128,128,128,
8 | 128,128,128, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
9 | 128,128,128, 128,128,128, 128,128,128, 128,128,128, 128,128,128,
10 | 128,128,128, 0, 0, 0, 192,192,192, 255,255,255, 192,192,192,
11 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
12 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
13 | 192,192,192, 128,128,128, 0, 0, 0, 192,192,192, 255,255,255,
14 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
15 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
16 | 192,192,192, 192,192,192, 128,128,128, 0, 0, 0, 192,192,192,
17 | 255,255,255, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
18 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
19 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
20 | 192,192,192, 255,255,255, 192,192,192, 192,192,192, 192,192,192,
21 | 192,192,192, 0, 0, 0, 192,192,192, 192,192,192, 192,192,192,
22 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 128,128,128,
23 | 0, 0, 0, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
24 | 192,192,192, 192,192,192, 0, 0, 0, 0, 0, 0, 192,192,192,
25 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
26 | 128,128,128, 0, 0, 0, 192,192,192, 255,255,255, 192,192,192,
27 | 192,192,192, 192,192,192, 192,192,192, 0, 0, 0, 0, 0, 0,
28 | 0, 0, 0, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
29 | 192,192,192, 128,128,128, 0, 0, 0, 192,192,192, 255,255,255,
30 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 0, 0, 0,
31 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 192,192,192, 192,192,192,
32 | 192,192,192, 192,192,192, 128,128,128, 0, 0, 0, 192,192,192,
33 | 255,255,255, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
34 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 192,192,192, 192,192,192,
35 | 192,192,192, 192,192,192, 192,192,192, 128,128,128, 0, 0, 0,
36 | 192,192,192, 255,255,255, 192,192,192, 192,192,192, 192,192,192,
37 | 192,192,192, 0, 0, 0, 0, 0, 0, 192,192,192, 192,192,192,
38 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 128,128,128,
39 | 0, 0, 0, 192,192,192, 255,255,255, 192,192,192, 192,192,192,
40 | 192,192,192, 192,192,192, 0, 0, 0, 192,192,192, 192,192,192,
41 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
42 | 128,128,128, 0, 0, 0, 192,192,192, 255,255,255, 192,192,192,
43 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
44 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
45 | 192,192,192, 128,128,128, 0, 0, 0, 192,192,192, 255,255,255,
46 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
47 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
48 | 192,192,192, 192,192,192, 128,128,128, 0, 0, 0, 192,192,192,
49 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
50 | 255,255,255, 255,255,255, 255,255,255, 255,255,255, 255,255,255,
51 | 255,255,255, 255,255,255, 255,255,255, 128,128,128, 0, 0, 0,
52 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
53 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
54 | 192,192,192, 192,192,192, 192,192,192, 192,192,192, 192,192,192,
55 | 0, 0, 0,
56 | };
57 |
--------------------------------------------------------------------------------
/gluit/glui_quaternion.h:
--------------------------------------------------------------------------------
1 | /**************************************************************************
2 |
3 | quaternion.h
4 |
5 | A quaternion class
6 |
7 | ---------------------------------------------------------------------
8 |
9 | Feb 1998, Paul Rademacher (rademach@cs.unc.edu)
10 |
11 | **************************************************************************/
12 |
13 | #ifndef _QUATERNION_H_
14 | #define _QUATERNION_H_
15 |
16 | #include "glui_algebra3.h"
17 |
18 |
19 | /* this line defines a new type: pointer to a function which returns a */
20 | /* float and takes as argument a float */
21 | typedef float (*V_FCT_PTR)(float);
22 |
23 |
24 | /****************************************************************
25 | * Quaternion *
26 | ****************************************************************/
27 |
28 | class quat
29 | {
30 | /*protected: */
31 | public:
32 |
33 | vec3 v; /* vector component */
34 | float s; /* scalar component */
35 |
36 | /*public: */
37 |
38 | /* Constructors */
39 |
40 | quat(void);
41 | quat(const float x, const float y, const float z, const float w);
42 | quat( vec3 v, float s );
43 | quat( float s, vec3 v );
44 | quat(const float *d ); /* copy from four-element float array */
45 | quat(const double *f ); /* copy from four-element double array */
46 | quat(const quat &q ); /* copy from other quat */
47 |
48 | /* Assignment operators */
49 |
50 | quat &operator = ( const quat &v ); /* assignment of a quat */
51 | quat &operator += ( const quat &v ); /* incrementation by a quat */
52 | quat &operator -= ( const quat &v ); /* decrementation by a quat */
53 | quat &operator *= ( const float d ); /* multiplication by a constant */
54 | quat &operator /= ( const float d ); /* division by a constant */
55 | float &operator [] ( int i); /* indexing */
56 |
57 | /* special functions */
58 |
59 | float length(void); /* length of a quat */
60 | float length2(void); /* squared length of a quat */
61 | quat &normalize(void); /* normalize a quat */
62 | quat &apply(V_FCT_PTR fct); /* apply a func. to each component */
63 | void set( float x, float y, float z ); /* set quat */
64 | void set( vec3 v, float s ); /* set quat */
65 | void print( FILE *file, const char *name ); /* print quat to a file */
66 | vec3 xform( const vec3 &v ); /* q*v*q-1 */
67 | mat4 to_mat4( void );
68 | void set_angle( float f ); /* set rot angle (degrees) */
69 | void scale_angle( float f ); /* scale rot angle (degrees) */
70 | float get_angle( void ); /* set rot angle (degrees) */
71 | vec3 get_axis( void ); /* get axis */
72 |
73 | /* friends */
74 |
75 | friend quat operator - (const quat &v); /* -q1 */
76 | friend quat operator + (const quat &a, const quat &b); /* q1 + q2 */
77 | friend quat operator - (const quat &a, const quat &b); /* q1 - q2 */
78 | friend quat operator * (const quat &a, const float d); /* q1 * 3.0 */
79 | friend quat operator * (const float d, const quat &a); /* 3.0 * q1 */
80 | friend quat operator * (const quat &a, const quat &b); /* q1 * q2 */
81 | friend quat operator / (const quat &a, const float d); /* q1 / 3.0 */
82 | friend int operator == (const quat &a, const quat &b); /* q1 == q2 ? */
83 | friend int operator != (const quat &a, const quat &b); /* q1 != q2 ? */
84 | friend void swap(quat &a, quat &b); /* swap q1 &q2 */
85 | /*friend quat min(const quat &a, const quat &b); -- min(q1, q2) */
86 | /*friend quat max(const quat &a, const quat &b); -- max(q1, q2) */
87 | friend quat prod(const quat &a, const quat &b); /* term by term mult */
88 | };
89 |
90 | /* Utility functions */
91 |
92 | quat quat_identity( void ); /* Returns quaternion identity element */
93 | quat quat_slerp( quat from, quat to, float t );
94 |
95 | #endif
96 |
--------------------------------------------------------------------------------
/utilsrc/mesh_crunch.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Szymon Rusinkiewicz
3 | Princeton University
4 |
5 | mesh_crunch.cc
6 | Replacement for plycrunch - decimate a mesh using the Rossignac-Borrel
7 | method of vertex collapse.
8 | */
9 |
10 | #include "TriMesh.h"
11 | #include
12 | #include
13 | using namespace std;
14 | using namespace trimesh;
15 |
16 |
17 | // A hash table for voxels -
18 | // stores an index (into the new vertex table) for each voxel.
19 | class VHashTable {
20 | public:
21 | typedef Vec<3,int> voxel_coord_t;
22 | typedef size_t key_t;
23 | typedef size_t data_t;
24 | static const size_t MAGIC1 = 100000007;
25 | static const size_t MAGIC2 = 161803409;
26 | static const size_t MAGIC3 = 423606823;
27 | static const size_t SIZE_FUDGE = 2;
28 | static const data_t NO_DATA = 0xffffffffu;
29 |
30 | private:
31 | float scale;
32 | vector voxel_coords;
33 | vector data;
34 |
35 | public:
36 | VHashTable(size_t maxpoints, float voxelsize_) :
37 | scale(1.0f / voxelsize_)
38 | {
39 | size_t n = SIZE_FUDGE * maxpoints;
40 | voxel_coords.resize(n);
41 | // Work around a bizarre compiler bug
42 | data_t tmp = NO_DATA;
43 | data.resize(n, tmp);
44 | }
45 | data_t &operator[] (const point &p)
46 | {
47 | voxel_coord_t c(int(floor(p[0] * scale)),
48 | int(floor(p[1] * scale)),
49 | int(floor(p[2] * scale)));
50 | key_t key = MAGIC1 * c[0] + MAGIC2 * c[1] + MAGIC3 * c[2];
51 | key %= data.size();
52 |
53 | // Open hashing
54 | while (1) {
55 | if (data[key] == NO_DATA) {
56 | voxel_coords[key] = c;
57 | break;
58 | } else if (voxel_coords[key] == c) {
59 | break;
60 | }
61 | key++;
62 | if (key == data.size())
63 | key = 0;
64 | }
65 |
66 | return data[key];
67 | }
68 | };
69 |
70 |
71 | // Perform the vertex collapse
72 | void crunch(TriMesh *in, TriMesh *out, float voxelsize)
73 | {
74 | size_t nv = in->vertices.size();
75 | // in->flags stores which output vertex we mapped to
76 | in->flags.clear();
77 | in->flags.resize(nv);
78 | out->vertices.reserve(nv);
79 | // out->flags stores number of vertices that mapped here
80 | out->flags.reserve(nv);
81 |
82 | // Go through input vertices. If we haven't encountered the
83 | // voxel yet, create a new vertex in the output. Else, merge with
84 | // other vertices in the same voxel.
85 | VHashTable hash(nv, voxelsize);
86 | for (size_t i = 0; i < nv; i++) {
87 | size_t &ind = hash[in->vertices[i]];
88 | if (ind >= nv) {
89 | // Failed lookup - add a new output vertex
90 | ind = out->vertices.size();
91 | out->vertices.push_back(in->vertices[i]);
92 | out->flags.push_back(1);
93 | } else {
94 | out->vertices[ind] += in->vertices[i];
95 | out->flags[ind]++;
96 | }
97 | in->flags[i] = ind;
98 | }
99 |
100 | // Divide by number of points per voxel, to get final vertex coords
101 | size_t onv = out->vertices.size();
102 | for (size_t i = 0; i < onv; i++)
103 | out->vertices[i] /= float(out->flags[i]);
104 |
105 | // Create new faces: only the non-degenerate ones
106 | in->need_faces();
107 | size_t nf = in->faces.size();
108 | out->faces.reserve(min(nf, onv*3));
109 | for (size_t i = 0; i < nf; i++) {
110 | size_t ind0 = in->flags[in->faces[i][0]];
111 | size_t ind1 = in->flags[in->faces[i][1]];
112 | size_t ind2 = in->flags[in->faces[i][2]];
113 | if (ind0 == ind1 || ind0 == ind2 || ind1 == ind2)
114 | continue;
115 | out->faces.push_back(TriMesh::Face(ind0,ind1,ind2));
116 | }
117 | }
118 |
119 |
120 | void usage(const char *myname)
121 | {
122 | fprintf(stderr, "Usage: %s in.ply out.ply\n", myname);
123 | exit(1);
124 | }
125 |
126 | int main(int argc, char *argv[])
127 | {
128 | if (argc < 3)
129 | usage(argv[0]);
130 | TriMesh *in = TriMesh::read(argv[1]);
131 | if (!in)
132 | usage(argv[0]);
133 |
134 | bool had_tstrips = !in->tstrips.empty();
135 |
136 | TriMesh *out = new TriMesh;
137 | float voxelsize = 2.0f * in->feature_size();
138 | crunch(in, out, voxelsize);
139 |
140 | if (had_tstrips)
141 | out->need_tstrips();
142 | out->write(argv[2]);
143 | }
144 |
--------------------------------------------------------------------------------
/gluit/freeglut_glutfont_definitions.c:
--------------------------------------------------------------------------------
1 | /*
2 | * freeglut_glutfont_definitions.c
3 | *
4 | * Bitmap and stroke fonts displaying.
5 | *
6 | * Copyright (c) 2003 Stephen J. Baker (whether he wants it or not).
7 | * All Rights Reserved.
8 | * Written by John F. Fay , who releases the
9 | * copyright over to the "freeglut" project lead.
10 | * Creation date: Mon July 21 2003
11 | *
12 | * Permission is hereby granted, free of charge, to any person obtaining a
13 | * copy of this software and associated documentation files (the "Software"),
14 | * to deal in the Software without restriction, including without limitation
15 | * the rights to use, copy, modify, merge, publish, distribute, sublicense,
16 | * and/or sell copies of the Software, and to permit persons to whom the
17 | * Software is furnished to do so, subject to the following conditions:
18 | *
19 | * The above copyright notice and this permission notice shall be included
20 | * in all copies or substantial portions of the Software.
21 | *
22 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
23 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
25 | * PAWEL W. OLSZTA BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
26 | * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
27 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 | */
29 |
30 | /*
31 | * This file is necessary for the *nix version of "freeglut" because the
32 | * original GLUT defined its font variables in rather an unusual way.
33 | * Publicly, in "glut.h", they were defined as "void *". Privately,
34 | * in one of the source code files, they were defined as pointers to a
35 | * structure. Most compilers and linkers are satisfied with the "void *"
36 | * and don't go any farther, but some of them balked. In particular,
37 | * when compiling with "freeglut" and then trying to run using the GLUT
38 | * ".so" library, some of them would give an error. So we are having to
39 | * create this file to define the variables as pointers to an unusual
40 | * structure to match GLUT.
41 | */
42 |
43 | /*
44 | * freeglut_internal.h uses some GL types, but including the GL header portably
45 | * is a bit tricky, so we include freeglut_std.h here, which contains the
46 | * necessary machinery. But this poses another problem, caused by the ugly
47 | * original defintion of the font constants in "classic" GLUT: They are defined
48 | * as void* externally, so we move them temporarily out of the way by AN EXTREME
49 | * CPP HACK.
50 | */
51 |
52 | #define glutStrokeRoman glutStrokeRomanIGNOREME
53 | #define glutStrokeMonoRoman glutStrokeMonoRomanIGNOREME
54 | #define glutBitmap9By15 glutBitmap9By15IGNOREME
55 | #define glutBitmap8By13 glutBitmap8By13IGNOREME
56 | #define glutBitmapTimesRoman10 glutBitmapTimesRoman10IGNOREME
57 | #define glutBitmapTimesRoman24 glutBitmapTimesRoman24IGNOREME
58 | #define glutBitmapHelvetica10 glutBitmapHelvetica10IGNOREME
59 | #define glutBitmapHelvetica12 glutBitmapHelvetica12IGNOREME
60 | #define glutBitmapHelvetica18 glutBitmapHelvetica18IGNOREME
61 |
62 | #include
63 |
64 | #undef glutStrokeRoman
65 | #undef glutStrokeMonoRoman
66 | #undef glutBitmap9By15
67 | #undef glutBitmap8By13
68 | #undef glutBitmapTimesRoman10
69 | #undef glutBitmapTimesRoman24
70 | #undef glutBitmapHelvetica10
71 | #undef glutBitmapHelvetica12
72 | #undef glutBitmapHelvetica18
73 |
74 | #include "freeglut_internal.h"
75 |
76 | #if TARGET_HOST_POSIX_X11
77 |
78 | struct freeglutStrokeFont
79 | {
80 | const char *name ;
81 | int num_chars ;
82 | void *ch ;
83 | float top ;
84 | float bottom ;
85 | };
86 |
87 | struct freeglutBitmapFont
88 | {
89 | const char *name ;
90 | const int num_chars ;
91 | const int first ;
92 | const void *ch ;
93 | };
94 |
95 |
96 | struct freeglutStrokeFont glutStrokeRoman ;
97 | struct freeglutStrokeFont glutStrokeMonoRoman ;
98 |
99 | struct freeglutBitmapFont glutBitmap9By15 ;
100 | struct freeglutBitmapFont glutBitmap8By13 ;
101 | struct freeglutBitmapFont glutBitmapTimesRoman10 ;
102 | struct freeglutBitmapFont glutBitmapTimesRoman24 ;
103 | struct freeglutBitmapFont glutBitmapHelvetica10 ;
104 | struct freeglutBitmapFont glutBitmapHelvetica12 ;
105 | struct freeglutBitmapFont glutBitmapHelvetica18 ;
106 |
107 | #endif
108 |
109 |
--------------------------------------------------------------------------------
/include/endianutil.h:
--------------------------------------------------------------------------------
1 | #ifndef ENDIANUTIL_H
2 | #define ENDIANUTIL_H
3 | /*
4 | Szymon Rusinkiewicz
5 | Princeton University
6 |
7 | endianutil.h
8 | Endian-ness and byte-swapping
9 | */
10 |
11 | #if defined(__linux__)
12 | # include
13 | # include
14 | #elif defined(__APPLE__)
15 | # include
16 | #elif defined(_MSC_VER)
17 | # include
18 | #endif
19 |
20 |
21 | namespace trimesh {
22 |
23 |
24 | // Figure out whether this machine is little- or big-endian
25 | static inline bool we_are_little_endian()
26 | {
27 | #if defined(__linux__)
28 | return (__BYTE_ORDER == __LITTLE_ENDIAN);
29 | #elif defined(__APPLE__)
30 | return (OSHostByteOrder() == OSLittleEndian);
31 | #elif defined(_MSC_VER)
32 | return true;
33 | #else
34 | // The following appears to be legal according to
35 | // C99 strict-aliasing rules
36 | static const int tmp = 1;
37 | static const bool little_endian = !!(* (const unsigned char *) &tmp);
38 | return little_endian;
39 | #endif
40 | }
41 |
42 | static inline bool we_are_big_endian()
43 | {
44 | return !we_are_little_endian();
45 | }
46 |
47 |
48 | // Byte-swap 16-, 32-, and 64-bit quantities
49 | static inline void swap_16(unsigned char *p)
50 | {
51 | #if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 408)
52 | * (unsigned short *) p = __builtin_bswap16(* (unsigned short *) p);
53 | #elif defined(__linux__)
54 | * (unsigned short *) p = bswap_16(* (unsigned short *) p);
55 | #elif defined(__APPLE__)
56 | * (unsigned short *) p = OSSwapInt16(* (unsigned short *) p);
57 | #elif defined(_MSC_VER) && _MSC_VER >= 1020
58 | * (unsigned short *) p = _byteswap_ushort(* (unsigned short *) p);
59 | #else
60 | * (unsigned short *) p =
61 | (((* (unsigned short *) p) & 0xff00u) >> 8) |
62 | (((* (unsigned short *) p) & 0x00ffu) << 8);
63 | #endif
64 | }
65 |
66 | static inline void swap_32(unsigned char *p)
67 | {
68 | #if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)
69 | * (unsigned *) p = __builtin_bswap32(* (unsigned *) p);
70 | #elif defined(__linux__)
71 | * (unsigned *) p = bswap_32(* (unsigned *) p);
72 | #elif defined(__APPLE__)
73 | * (unsigned *) p = OSSwapInt32(* (unsigned *) p);
74 | #elif defined(_MSC_VER) && _MSC_VER >= 1020
75 | * (unsigned *) p = _byteswap_ulong(* (unsigned *) p);
76 | #else
77 | * (unsigned *) p =
78 | (((* (unsigned *) p) & 0xff000000u) >> 24) |
79 | (((* (unsigned *) p) & 0x00ff0000u) >> 8) |
80 | (((* (unsigned *) p) & 0x0000ff00u) << 8) |
81 | (((* (unsigned *) p) & 0x000000ffu) << 24);
82 | #endif
83 | }
84 |
85 | static inline void swap_64(unsigned char *p)
86 | {
87 | #if defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 403)
88 | * (unsigned long long *) p =
89 | __builtin_bswap64(* (unsigned long long *) p);
90 | #elif defined(__linux__)
91 | * (unsigned long long *) p = bswap_64(* (unsigned long long *) p);
92 | #elif defined(__APPLE__)
93 | * (unsigned long long *) p = OSSwapInt64(* (unsigned long long *) p);
94 | #elif defined(_MSC_VER) && _MSC_VER >= 1020
95 | * (unsigned __int64 *) p = _byteswap_uint64(* (unsigned __int64 *) p);
96 | #else
97 | * (unsigned long long *) p =
98 | (((* (unsigned long long *) p) & 0xff00000000000000ull) >> 56) |
99 | (((* (unsigned long long *) p) & 0x00ff000000000000ull) >> 40) |
100 | (((* (unsigned long long *) p) & 0x0000ff0000000000ull) >> 24) |
101 | (((* (unsigned long long *) p) & 0x000000ff00000000ull) >> 8) |
102 | (((* (unsigned long long *) p) & 0x00000000ff000000ull) << 8) |
103 | (((* (unsigned long long *) p) & 0x0000000000ff0000ull) << 24) |
104 | (((* (unsigned long long *) p) & 0x000000000000ff00ull) << 40) |
105 | (((* (unsigned long long *) p) & 0x00000000000000ffull) << 56);
106 | #endif
107 | }
108 |
109 |
110 | // Byte swap ints, uints, and floats. Assumes int is 32bits.
111 | // Going through (unsigned char *) appears to be the legal
112 | // (C99 strict-aliasing compliant) way to do this.
113 | static inline void swap_short(short &x)
114 | {
115 | swap_16((unsigned char *) &x);
116 | }
117 |
118 | static inline void swap_ushort(unsigned short &x)
119 | {
120 | swap_16((unsigned char *) &x);
121 | }
122 |
123 | static inline void swap_int(int &x)
124 | {
125 | swap_32((unsigned char *) &x);
126 | }
127 |
128 | static inline void swap_unsigned(unsigned &x)
129 | {
130 | swap_32((unsigned char *) &x);
131 | }
132 |
133 | static inline void swap_float(float &x)
134 | {
135 | swap_32((unsigned char *) &x);
136 | }
137 |
138 | static inline void swap_double(double &x)
139 | {
140 | swap_64((unsigned char *) &x);
141 | }
142 |
143 |
144 | } // namespace trimesh
145 |
146 | #endif
147 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | ## Ignore Visual Studio temporary files, build results, and
2 | ## files generated by popular Visual Studio add-ons.
3 |
4 | # User-specific files
5 | *.suo
6 | *.user
7 | *.userosscache
8 | *.sln.docstates
9 |
10 | # User-specific files (MonoDevelop/Xamarin Studio)
11 | *.userprefs
12 |
13 | # Build results
14 | [Dd]ebug/
15 | [Dd]ebugPublic/
16 | [Rr]elease/
17 | [Rr]eleases/
18 | x64/
19 | x86/
20 | build/
21 | bld/
22 | [Bb]in/
23 | [Oo]bj/
24 | *.idb
25 |
26 | # Visual Studio 2015 cache/options directory
27 | .vs/
28 |
29 | # MSTest test Results
30 | [Tt]est[Rr]esult*/
31 | [Bb]uild[Ll]og.*
32 |
33 | # NUNIT
34 | *.VisualState.xml
35 | TestResult.xml
36 |
37 | # Build Results of an ATL Project
38 | [Dd]ebugPS/
39 | [Rr]eleasePS/
40 | dlldata.c
41 |
42 | # DNX
43 | project.lock.json
44 | artifacts/
45 |
46 | *_i.c
47 | *_p.c
48 | *_i.h
49 | *.ilk
50 | *.meta
51 | *.obj
52 | *.pch
53 | *.pdb
54 | *.pgc
55 | *.pgd
56 | *.rsp
57 | *.sbr
58 | *.tlb
59 | *.tli
60 | *.tlh
61 | *.tmp
62 | *.tmp_proj
63 | *.log
64 | *.vspscc
65 | *.vssscc
66 | .builds
67 | *.pidb
68 | *.svclog
69 | *.scc
70 |
71 | # Chutzpah Test files
72 | _Chutzpah*
73 |
74 | # Visual C++ cache files
75 | ipch/
76 | *.aps
77 | *.ncb
78 | *.opensdf
79 | *.sdf
80 | *.cachefile
81 |
82 | # Visual Studio profiler
83 | *.psess
84 | *.vsp
85 | *.vspx
86 |
87 | # TFS 2012 Local Workspace
88 | $tf/
89 |
90 | # Guidance Automation Toolkit
91 | *.gpState
92 |
93 | # ReSharper is a .NET coding add-in
94 | _ReSharper*/
95 | *.[Rr]e[Ss]harper
96 | *.DotSettings.user
97 |
98 | # JustCode is a .NET coding add-in
99 | .JustCode
100 |
101 | # TeamCity is a build add-in
102 | _TeamCity*
103 |
104 | # DotCover is a Code Coverage Tool
105 | *.dotCover
106 |
107 | # NCrunch
108 | _NCrunch_*
109 | .*crunch*.local.xml
110 |
111 | # MightyMoose
112 | *.mm.*
113 | AutoTest.Net/
114 |
115 | # Web workbench (sass)
116 | .sass-cache/
117 |
118 | # Installshield output folder
119 | [Ee]xpress/
120 |
121 | # DocProject is a documentation generator add-in
122 | DocProject/buildhelp/
123 | DocProject/Help/*.HxT
124 | DocProject/Help/*.HxC
125 | DocProject/Help/*.hhc
126 | DocProject/Help/*.hhk
127 | DocProject/Help/*.hhp
128 | DocProject/Help/Html2
129 | DocProject/Help/html
130 |
131 | # Click-Once directory
132 | publish/
133 |
134 | # Publish Web Output
135 | *.[Pp]ublish.xml
136 | *.azurePubxml
137 | ## TODO: Comment the next line if you want to checkin your
138 | ## web deploy settings but do note that will include unencrypted
139 | ## passwords
140 | #*.pubxml
141 |
142 | *.publishproj
143 |
144 | # NuGet Packages
145 | *.nupkg
146 | # The packages folder can be ignored because of Package Restore
147 | **/packages/*
148 | # except build/, which is used as an MSBuild target.
149 | !**/packages/build/
150 | # Uncomment if necessary however generally it will be regenerated when needed
151 | #!**/packages/repositories.config
152 |
153 | # Windows Azure Build Output
154 | csx/
155 | *.build.csdef
156 |
157 | # Windows Store app package directory
158 | AppPackages/
159 |
160 | # Visual Studio cache files
161 | # files ending in .cache can be ignored
162 | *.[Cc]ache
163 | # but keep track of directories ending in .cache
164 | !*.[Cc]ache/
165 |
166 | # Others
167 | ClientBin/
168 | [Ss]tyle[Cc]op.*
169 | ~$*
170 | *~
171 | *.dbmdl
172 | *.dbproj.schemaview
173 | *.pfx
174 | *.publishsettings
175 | node_modules/
176 | orleans.codegen.cs
177 |
178 | # RIA/Silverlight projects
179 | Generated_Code/
180 |
181 | # Backup & report files from converting an old project file
182 | # to a newer Visual Studio version. Backup files are not needed,
183 | # because we have git ;-)
184 | _UpgradeReport_Files/
185 | Backup*/
186 | UpgradeLog*.XML
187 | UpgradeLog*.htm
188 |
189 | # SQL Server files
190 | *.mdf
191 | *.ldf
192 |
193 | # Business Intelligence projects
194 | *.rdl.data
195 | *.bim.layout
196 | *.bim_*.settings
197 |
198 | # Microsoft Fakes
199 | FakesAssemblies/
200 |
201 | # Node.js Tools for Visual Studio
202 | .ntvs_analysis.dat
203 |
204 | # Visual Studio 6 build log
205 | *.plg
206 |
207 | # Visual Studio 6 workspace options file
208 | *.opt
209 |
210 | # LightSwitch generated files
211 | GeneratedArtifacts/
212 | _Pvt_Extensions/
213 | ModelManifest.xml
214 |
215 | # Compiled Object files
216 | *.slo
217 | *.lo
218 | *.o
219 | *.obj
220 |
221 | # Precompiled Headers
222 | *.gch
223 | *.pch
224 |
225 | # Compiled Dynamic libraries
226 | *.so
227 | *.dylib
228 | *.dll
229 |
230 | # Fortran module files
231 | *.mod
232 |
233 | # Compiled Static libraries
234 | *.lai
235 | *.la
236 | *.a
237 | *.lib
238 |
239 | # Executables
240 | *.exe
241 | *.out
242 | *.app
243 | *.opendb
244 | *.iobj
245 | *.ipdb
246 | *.db
247 | *.db
248 |
249 | #Filters
250 | ¨.filters
251 |
--------------------------------------------------------------------------------
/utilsrc/mesh_cc.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Szymon Rusinkiewicz
3 | Princeton University
4 |
5 | mesh_cc.cc
6 | Determine the connected components of a mesh, and possibly write
7 | out only selected components of the object.
8 |
9 | Does the same thing as "plycomps", part of the plytools package by Greg Turk.
10 | */
11 |
12 | #ifdef _MSC_VER
13 | #define _CRT_SECURE_NO_WARNINGS
14 | #endif
15 |
16 | #include "TriMesh.h"
17 | #include "TriMesh_algo.h"
18 | #ifdef _WIN32
19 | # include "wingetopt.h"
20 | #else
21 | # include
22 | #endif
23 | #include
24 | using namespace std;
25 | using namespace trimesh;
26 |
27 |
28 | #define BIGNUM numeric_limits::max()
29 |
30 |
31 | // Print out the connected components that are bigger than morethan and
32 | // smaller than lessthan. The largest min(nprint, total) components are
33 | // printed out, unless morethan == 0 and lessthan != BIGNUM, in which case
34 | // the smallest min(nprint, total) components are printed
35 | void print_comps(const vector &compsizes,
36 | int morethan, int lessthan, int total, int nprint)
37 | {
38 | printf("%lu connected components total.\n",
39 | (unsigned long) compsizes.size());
40 |
41 | if (compsizes.size() < 1 || total < 1)
42 | return;
43 | int numtoprint = min(min(nprint, total), (int)compsizes.size());
44 |
45 | if (morethan == 0 && lessthan != BIGNUM) {
46 | // Print numtoprint smallest components
47 | for (int i = 0; i < numtoprint; i++)
48 | printf(" Component #%d - %d faces\n", i+1, compsizes[compsizes.size()-1-i]);
49 | } else {
50 | // Print numtoprint largest components
51 | for (int i = 0; i < numtoprint; i++)
52 | printf(" Component #%d - %d faces\n", i+1, compsizes[i]);
53 | }
54 | if (numtoprint != (int)compsizes.size())
55 | printf(" ...\n");
56 | }
57 |
58 |
59 | void usage(const char *myname)
60 | {
61 | fprintf(stderr, "Usage: %s [options] in.ply [out.ply]\n", myname);
62 | fprintf(stderr, "Options:\n");
63 | fprintf(stderr, " -v Base connectivity on vertices, not edges\n");
64 | fprintf(stderr, " -a Print sizes of ALL the components\n");
65 | fprintf(stderr, " -s Split components into separate files\n");
66 | fprintf(stderr, " -m n Select components with >= n faces\n");
67 | fprintf(stderr, " -l n Select components with <= n faces\n");
68 | fprintf(stderr, " -t n Select the largest n components\n");
69 | exit(1);
70 | }
71 |
72 |
73 | int main(int argc, char *argv[])
74 | {
75 | // Parse command line
76 | int morethan = 0;
77 | int lessthan = BIGNUM;
78 | int total = BIGNUM;
79 | int nprint = 20;
80 | bool conn_vert = false;
81 | bool splitcc = false;
82 | const char *infilename=NULL, *outfilename=NULL;
83 |
84 | int c;
85 | while ((c = getopt(argc, argv, "hvasm:l:t:")) != EOF) {
86 | switch (c) {
87 | case 'v': conn_vert = true; break;
88 | case 'a': nprint = BIGNUM; break;
89 | case 's': splitcc = true; break;
90 | case 'm': morethan = atoi(optarg); break;
91 | case 'l': lessthan = atoi(optarg); break;
92 | case 't': total = atoi(optarg); break;
93 | default: usage(argv[0]);
94 | }
95 | }
96 | if (argc - optind < 1)
97 | usage(argv[0]);
98 | infilename = argv[optind];
99 | if (argc - optind >= 2)
100 | outfilename = argv[optind+1];
101 |
102 | // Read input file
103 | TriMesh *in = TriMesh::read(infilename);
104 | if (!in) {
105 | fprintf(stderr, "Couldn't read input %s\n", infilename);
106 | exit(1);
107 | }
108 | bool had_tstrips = !in->tstrips.empty();
109 | in->need_faces();
110 | in->tstrips.clear();
111 |
112 | // Find connected components
113 | vector comps;
114 | vector compsizes;
115 | find_comps(in, comps, compsizes, conn_vert);
116 |
117 | // Print out the top few components
118 | print_comps(compsizes, morethan, lessthan, total, nprint);
119 |
120 | // Exit here if just printing things out, and not saving anything
121 | if (!outfilename)
122 | exit(0);
123 |
124 | // Get rid of the junk we don't want...
125 | if (lessthan != BIGNUM) {
126 | select_small_comps(in, comps, compsizes, lessthan,
127 | morethan != 0 ? BIGNUM : total);
128 | find_comps(in, comps, compsizes, conn_vert);
129 | }
130 | if (morethan != 0 || (lessthan == BIGNUM && total != BIGNUM)) {
131 | select_big_comps(in, comps, compsizes, morethan, total);
132 | find_comps(in, comps, compsizes, conn_vert);
133 | }
134 |
135 | if (splitcc) {
136 | // Split into separate files, if requested
137 | int ncomps = compsizes.size();
138 | for (int i = 0; i < ncomps; i++) {
139 | TriMesh *tmp = new TriMesh(*in);
140 | select_comp(tmp, comps, i);
141 | if (had_tstrips)
142 | tmp->need_tstrips();
143 | char filename[1024];
144 | sprintf(filename, "cc%d-%s", i+1, outfilename);
145 | tmp->write(filename);
146 | delete tmp;
147 | }
148 | } else {
149 | // Write the requested components to a file
150 | if (had_tstrips)
151 | in->need_tstrips();
152 | in->write(outfilename);
153 | }
154 | }
155 |
--------------------------------------------------------------------------------
/gluit/glui_panel.cc:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 |
3 | GLUI User Interface Toolkit
4 | ---------------------------
5 |
6 | glui_panel.cpp - GLUI_Panel control class
7 |
8 |
9 | --------------------------------------------------
10 |
11 | Copyright (c) 1998 Paul Rademacher
12 |
13 | This program is freely distributable without licensing fees and is
14 | provided without guarantee or warrantee expressed or implied. This
15 | program is -not- in the public domain.
16 |
17 | *****************************************************************************/
18 |
19 | #include "glui.h"
20 | #include "glui_stdinc.h"
21 |
22 | /****************************** GLUI_Panel::draw() **********/
23 |
24 | void GLUI_Panel::draw( int x, int y )
25 | {
26 | int top, orig;
27 |
28 | if ( NOT can_draw() )
29 | return;
30 |
31 | orig = set_to_glut_window();
32 |
33 | if ( int_val == GLUI_PANEL_RAISED ) {
34 | top = 0;
35 | glLineWidth( 1.0 );
36 | glColor3f( 1.0, 1.0, 1.0 );
37 | glBegin( GL_LINE_LOOP );
38 | glVertex2i( 0, top ); glVertex2i( w, top );
39 | glVertex2i( 0, top ); glVertex2i( 0, h );
40 | glEnd();
41 |
42 | glColor3f( .5, .5, .5 );
43 | glBegin( GL_LINE_LOOP );
44 | glVertex2i( w, top );
45 | glVertex2i( w, h );
46 | glVertex2i( 0, h );
47 | glVertex2i( w, h );
48 | glEnd();
49 |
50 | /** ORIGINAL RAISED PANEL METHOD - A LITTLE TOO HIGH **
51 | glLineWidth(1.0);
52 | glBegin( GL_LINES );
53 | glColor3f( 1.0, 1.0, 1.0 );
54 | glVertex2i( 1, 1 ); glVertex2i( w-2, 1 );
55 | glVertex2i( 1, 1 ); glVertex2i( 1, h-2 );
56 |
57 | glColor3f( .5, .5, .5 );
58 | glVertex2i( w-1, 1 ); glVertex2i( w-1, h-1 );
59 | glVertex2i( 1, h-1 ); glVertex2i( w-1, h-1 );
60 |
61 | glColor3f( 0.0, 0.0, 0.0 );
62 | glVertex2i( 0, h ); glVertex2i( w, h );
63 | glVertex2i( w, 0 ); glVertex2i( w, h );
64 | glEnd();
65 |
66 | -- Touch up the lines a bit (needed in some opengl implementations
67 | glBegin( GL_POINTS );
68 | glColor3f( .5, .5, .5 );
69 | glVertex2i( w-1, h-1 );
70 | glColor3f( 0.0, 0.0, 0.0 );
71 | glVertex2i( w, h );
72 | glEnd();
73 | **/
74 | }
75 | else if ( int_val == GLUI_PANEL_EMBOSSED ) {
76 | if ( name[0] == '\0' ) {
77 | top = 0;
78 | }
79 | else {
80 | top = GLUI_PANEL_EMBOSS_TOP;
81 | }
82 |
83 | glLineWidth( 1.0 );
84 | glColor3f( 1.0, 1.0, 1.0 );
85 | glBegin( GL_LINE_LOOP );
86 | glVertex2i( 0, top ); glVertex2i( w, top );
87 | glVertex2i( w, h ); glVertex2i( 0, h );
88 |
89 | glVertex2i( 1, top+1 ); glVertex2i( w-1, top+1 );
90 | glVertex2i( w-1, h-1 ); glVertex2i( 1, h-1 );
91 | glEnd();
92 |
93 | glColor3f( .5, .5, .5 );
94 | glBegin( GL_LINE_LOOP );
95 | glVertex2i( 0, top );
96 | glVertex2i( w-1, top );
97 | glVertex2i( w-1, h-1 );
98 | glVertex2i( 0, h-1 );
99 | glEnd();
100 |
101 | /**** Only display text in embossed panel ****/
102 | if ( name[0] != '\0' ) { /* Only draw non-null strings */
103 | int left = 7, height=GLUI_PANEL_NAME_DROP+1;
104 | int str_width;
105 |
106 | str_width = string_width(name);
107 |
108 | if ( glui )
109 | glColor3ub(glui->bkgd_color.r,glui->bkgd_color.g,glui->bkgd_color.b);
110 | glDisable( GL_CULL_FACE );
111 | glBegin( GL_QUADS );
112 | glVertex2i( left-3, 0 ); glVertex2i( left+str_width+3, 0 );
113 | glVertex2i( left+str_width+3, height ); glVertex2i( left-3, height );
114 | glEnd();
115 |
116 | draw_name( left, GLUI_PANEL_NAME_DROP );
117 | }
118 | }
119 |
120 | glLineWidth( 1.0 );
121 |
122 | restore_window(orig);
123 | }
124 |
125 |
126 | /****************************** GLUI_Panel::set_name() **********/
127 |
128 | void GLUI_Panel::set_name( const char *new_name )
129 | {
130 | strncpy(name,new_name,sizeof(GLUI_String));
131 |
132 | update_size();
133 |
134 | if ( glui )
135 | glui->refresh();
136 | }
137 |
138 |
139 | /****************************** GLUI_Panel::set_type() **********/
140 |
141 | void GLUI_Panel::set_type( int new_type )
142 | {
143 | int old_window;
144 |
145 | if ( new_type != int_val ) {
146 | int_val = new_type;
147 |
148 | /* translate_and_draw_front(); */
149 | update_size();
150 |
151 | old_window = set_to_glut_window();
152 | glutPostRedisplay( );
153 | restore_window( old_window );
154 | }
155 | }
156 |
157 |
158 | /************************************** GLUI_Panel::update_size() **********/
159 |
160 | void GLUI_Panel::update_size( void )
161 | {
162 | int text_size;
163 |
164 | if ( NOT glui )
165 | return;
166 |
167 | text_size = string_width(name);
168 |
169 | if ( w < text_size + 16 )
170 | w = text_size + 16 ;
171 |
172 | if ( name[0] != '\0' AND int_val == GLUI_PANEL_EMBOSSED ) {
173 | this->y_off_top = GLUI_YOFF + 8;
174 | }
175 | else {
176 | this->y_off_top = GLUI_YOFF;
177 | }
178 | }
179 |
--------------------------------------------------------------------------------
/gluit/glui_button.cc:
--------------------------------------------------------------------------------
1 | /****************************************************************************
2 |
3 | GLUI User Interface Toolkit
4 | ---------------------------
5 |
6 | glui_button.cpp - GLUI_Button control class
7 |
8 |
9 | --------------------------------------------------
10 |
11 | Copyright (c) 1998 Paul Rademacher
12 |
13 | This program is freely distributable without licensing fees and is
14 | provided without guarantee or warrantee expressed or implied. This
15 | program is -not- in the public domain.
16 |
17 | *****************************************************************************/
18 |
19 | #include "glui.h"
20 | #include "glui_stdinc.h"
21 |
22 | /****************************** GLUI_Button::mouse_down_handler() **********/
23 |
24 | int GLUI_Button::mouse_down_handler( int local_x, int local_y )
25 | {
26 | int_val = 1; /** A button always in unpressed before here, so
27 | now we invariably set it to 'depressed' **/
28 |
29 | currently_inside = true;
30 |
31 | draw_pressed();
32 |
33 | return false;
34 | }
35 |
36 |
37 | /****************************** GLUI_Button::mouse_up_handler() **********/
38 |
39 | int GLUI_Button::mouse_up_handler( int local_x, int local_y, int inside )
40 | {
41 | set_int_val( 0 ); /** A button always turns off after you press it **/
42 |
43 | draw_unpressed();
44 |
45 | if ( NOT inside ) {
46 | }
47 | else {
48 | /*** Invoke the callback ***/
49 | execute_callback();
50 |
51 | /** Tell the main gfx window to update itself **/
52 | if( glui )
53 | glui->post_update_main_gfx();
54 | }
55 |
56 | return false;
57 | }
58 |
59 |
60 | /****************************** GLUI_Button::mouse_held_down_handler() ******/
61 |
62 | int GLUI_Button::mouse_held_down_handler( int local_x, int local_y,
63 | int new_inside)
64 | {
65 | if ( NOT new_inside AND currently_inside == true ) {
66 | draw_unpressed();
67 | }
68 | else if ( new_inside AND currently_inside == false ) {
69 | draw_pressed();
70 | }
71 |
72 | currently_inside = new_inside;
73 |
74 | return false;
75 | }
76 |
77 |
78 | /****************************** GLUI_Button::key_handler() **********/
79 |
80 | int GLUI_Button::key_handler( unsigned char key,int modifiers )
81 | {
82 | return false;
83 | }
84 |
85 |
86 | /************************************** GLUI_Button::draw_pressed() ******/
87 |
88 | void GLUI_Button::draw_pressed( void )
89 | {
90 | int state, orig;
91 |
92 | if ( NOT can_draw() )
93 | return;
94 |
95 | orig = set_to_glut_window();
96 | state = glui->set_front_draw_buffer();
97 |
98 | glColor3f( 0.0, 0.0, 0.0 );
99 | glPushMatrix();
100 | translate_to_origin();
101 |
102 | draw_text( 1 );
103 |
104 | glBegin( GL_LINE_LOOP );
105 | glVertex2i( 0, 0 ); glVertex2i( w, 0 );
106 | glVertex2i( w, h ); glVertex2i( 0, h );
107 | glEnd();
108 |
109 | glBegin( GL_LINE_LOOP );
110 | glVertex2i( 1, 1 ); glVertex2i( w-1, 1 );
111 | glVertex2i( w-1, h-1 ); glVertex2i( 1, h-1 );
112 | glEnd();
113 |
114 | glPopMatrix();
115 |
116 | glui->restore_draw_buffer(state);
117 | restore_window(orig);
118 | }
119 |
120 |
121 | /************************************** GLUI_Button::draw_unpressed() ******/
122 |
123 | void GLUI_Button::draw_unpressed( void )
124 | {
125 | if ( NOT can_draw() )
126 | return;
127 |
128 | translate_and_draw_front();
129 | }
130 |
131 |
132 |
133 |
134 | /********************************************** GLUI_Button::draw() **********/
135 |
136 | void GLUI_Button::draw( int x, int y )
137 | {
138 | if ( NOT can_draw() )
139 | return;
140 |
141 | if ( glui )
142 | glui->draw_raised_box( 0, 0, w, h );
143 |
144 | draw_text( 0 );
145 | }
146 |
147 |
148 | /**************************************** GLUI_Button::draw_text() **********/
149 |
150 | void GLUI_Button::draw_text( int sunken )
151 | {
152 | int string_width, orig;
153 |
154 | if ( NOT can_draw() )
155 | return;
156 |
157 | orig = set_to_glut_window();
158 |
159 | glColor3ub( glui->bkgd_color.r, glui->bkgd_color.g, glui->bkgd_color.b );
160 | glDisable( GL_CULL_FACE );
161 | glBegin( GL_QUADS );
162 | glVertex2i( 2, 2 ); glVertex2i( w-2, 2 );
163 | glVertex2i( w-2, h-2 ); glVertex2i( 2, h-2 );
164 | glEnd();
165 |
166 | glColor3ub( 0,0,0 );
167 |
168 | string_width = _glutBitmapWidthString( glui->font,
169 | this->name );
170 | if ( NOT sunken ) {
171 | draw_name( MAX((w-string_width),0)/2, 13);
172 | }
173 | else {
174 | draw_name( MAX((w-string_width),0)/2 + 1, 13 + 1);
175 | }
176 |
177 | if ( active ) {
178 | glEnable( GL_LINE_STIPPLE );
179 | glLineStipple( 1, 0x5555 );
180 |
181 | glColor3f( 0., 0., 0. );
182 |
183 | glBegin( GL_LINE_LOOP );
184 | glVertex2i( 3, 3 ); glVertex2i( w-3, 3 );
185 | glVertex2i( w-3, h-3 ); glVertex2i( 3, h-3 );
186 | glEnd();
187 |
188 | glDisable( GL_LINE_STIPPLE );
189 | }
190 |
191 | restore_window(orig);
192 | }
193 |
194 |
195 | /************************************** GLUI_Button::update_size() **********/
196 |
197 | void GLUI_Button::update_size( void )
198 | {
199 | int text_size;
200 |
201 | if ( NOT glui )
202 | return;
203 |
204 | text_size = string_width( name );
205 |
206 | if ( w < text_size + 16 )
207 | w = text_size + 16 ;
208 | }
209 |
--------------------------------------------------------------------------------
/libsrc/overlap.cc:
--------------------------------------------------------------------------------
1 | /*
2 | Szymon Rusinkiewicz
3 | Princeton University
4 |
5 | overlap.cc
6 | Compute overlap area and mesh-to-mesh distance for two meshes
7 | */
8 |
9 | #include "TriMesh.h"
10 | #include "TriMesh_algo.h"
11 | #include "KDtree.h"
12 | using namespace std;
13 |
14 |
15 | namespace trimesh {
16 |
17 | // Find the overlap area and RMS distance from mesh1 to mesh2. Used by
18 | // find_overlap in both directions, below
19 | static void find_overlap_onedir(TriMesh *mesh1, TriMesh *mesh2,
20 | const xform &xf1, const xform &xf2,
21 | const KDtree *kd2,
22 | float &overlap_area, float &nonoverlap_area,
23 | float &rmsdist)
24 | {
25 | overlap_area = 0.0f;
26 | rmsdist = 0.0f;
27 | float area_considered = 0.0f;
28 |
29 | xform xf12 = inv(xf2) * xf1;
30 | xform xf12r = norm_xf(xf12);
31 | int nv = mesh1->vertices.size();
32 | int nsamp = min(nv, 10000);
33 |
34 | for (int i = 0; i < nsamp; i++) {
35 | int ind = int((float) i / nsamp * nv);
36 | ind = clamp(ind, 0, nv-1);
37 | float this_area = mesh1->pointareas[ind];
38 | area_considered += this_area;
39 | point p = xf12 * mesh1->vertices[ind];
40 | const float *q = kd2->closest_to_pt(p);
41 | if (!q)
42 | continue;
43 | int ind2 = (q - (const float *) &(mesh2->vertices[0][0])) / 3;
44 | if (mesh2->is_bdy(ind2))
45 | continue;
46 | if (((xf12r * mesh1->normals[ind]) DOT mesh2->normals[ind2])
47 | <= 0.0f)
48 | continue;
49 | overlap_area += this_area;
50 | rmsdist += this_area *
51 | sqr((p - point(q)) DOT mesh2->normals[ind2]);
52 | }
53 |
54 | float total_area = mesh1->stat(TriMesh::STAT_SUM,
55 | TriMesh::STAT_FACEAREA);
56 |
57 | // Put the "m" and "s" in rms
58 | if (overlap_area) {
59 | rmsdist /= overlap_area;
60 | rmsdist = sqrt(rmsdist);
61 | }
62 |
63 | // Correct overlap_area for area_considered
64 | overlap_area *= total_area / area_considered;
65 | nonoverlap_area = total_area - overlap_area;
66 | }
67 |
68 |
69 | // Find overlap area and RMS distance between mesh1 and mesh2.
70 | // rmsdist is unchanged if area returned as zero
71 | void find_overlap(TriMesh *mesh1, TriMesh *mesh2,
72 | const xform &xf1, const xform &xf2,
73 | const KDtree *kd1, const KDtree *kd2,
74 | float &area, float &rmsdist)
75 | {
76 | mesh1->need_normals();
77 | mesh1->need_neighbors();
78 | mesh1->need_adjacentfaces();
79 | mesh1->need_pointareas();
80 | mesh2->need_normals();
81 | mesh2->need_neighbors();
82 | mesh2->need_adjacentfaces();
83 | mesh2->need_pointareas();
84 |
85 | float area1, area2, non1, non2, rmsdist1, rmsdist2;
86 |
87 | TriMesh::dprintf("Finding overlap 1->2... ");
88 | find_overlap_onedir(mesh1, mesh2, xf1, xf2, kd2, area1, non1, rmsdist1);
89 | TriMesh::dprintf("area = %g, RMS distance = %g\n", area1, rmsdist1);
90 | TriMesh::dprintf("Finding overlap 2->1... ");
91 | find_overlap_onedir(mesh2, mesh1, xf2, xf1, kd1, area2, non2, rmsdist2);
92 | TriMesh::dprintf("area = %g, RMS distance = %g\n", area2, rmsdist2);
93 | area = 0.5f * (area1 + area2);
94 | if (area)
95 | rmsdist = 0.5f * (rmsdist1 + rmsdist2);
96 | }
97 |
98 |
99 | // Return intersection-over-union between mesh1 and mesh2.
100 | float iou(TriMesh *mesh1, TriMesh *mesh2,
101 | const xform &xf1, const xform &xf2,
102 | const KDtree *kd1, const KDtree *kd2)
103 | {
104 | mesh1->need_normals();
105 | mesh1->need_neighbors();
106 | mesh1->need_adjacentfaces();
107 | mesh1->need_pointareas();
108 | mesh2->need_normals();
109 | mesh2->need_neighbors();
110 | mesh2->need_adjacentfaces();
111 | mesh2->need_pointareas();
112 |
113 | float area1, area2, non1, non2, rmsdist1, rmsdist2;
114 |
115 | TriMesh::dprintf("Finding overlap 1->2... ");
116 | find_overlap_onedir(mesh1, mesh2, xf1, xf2, kd2, area1, non1, rmsdist1);
117 | TriMesh::dprintf("area = %g, RMS distance = %g\n", area1, rmsdist1);
118 | TriMesh::dprintf("Finding overlap 2->1... ");
119 | find_overlap_onedir(mesh2, mesh1, xf2, xf1, kd1, area2, non2, rmsdist2);
120 | TriMesh::dprintf("area = %g, RMS distance = %g\n", area2, rmsdist2);
121 | float int_area = 0.5f * (area1 + area2);
122 | float union_area = area1 + non1 + area2 + non2 - int_area;
123 | return int_area / union_area;
124 | }
125 |
126 |
127 | // Easy-to-use interfaces
128 | void find_overlap(TriMesh *mesh1, TriMesh *mesh2, float &area, float &rmsdist)
129 | {
130 | KDtree *kd1 = new KDtree(mesh1->vertices);
131 | KDtree *kd2 = new KDtree(mesh2->vertices);
132 | find_overlap(mesh1, mesh2, xform(), xform(), kd1, kd2, area, rmsdist);
133 | delete kd2;
134 | delete kd1;
135 | }
136 |
137 | void find_overlap(TriMesh *mesh1, TriMesh *mesh2,
138 | const xform &xf1, const xform &xf2,
139 | float &area, float &rmsdist)
140 | {
141 | KDtree *kd1 = new KDtree(mesh1->vertices);
142 | KDtree *kd2 = new KDtree(mesh2->vertices);
143 | find_overlap(mesh1, mesh2, xf1, xf2, kd1, kd2, area, rmsdist);
144 | delete kd2;
145 | delete kd1;
146 | }
147 |
148 | float iou(TriMesh *mesh1, TriMesh *mesh2)
149 | {
150 | KDtree *kd1 = new KDtree(mesh1->vertices);
151 | KDtree *kd2 = new KDtree(mesh2->vertices);
152 | float ret = iou(mesh1, mesh2, xform(), xform(), kd1, kd2);
153 | delete kd2;
154 | delete kd1;
155 | return ret;
156 | }
157 |
158 | float iou(TriMesh *mesh1, TriMesh *mesh2, const xform &xf1, const xform &xf2)
159 | {
160 | KDtree *kd1 = new KDtree(mesh1->vertices);
161 | KDtree *kd2 = new KDtree(mesh2->vertices);
162 | float ret = iou(mesh1, mesh2, xf1, xf2, kd1, kd2);
163 | delete kd2;
164 | delete kd1;
165 | return ret;
166 | }
167 |
168 | } // namespace trimesh
169 |
--------------------------------------------------------------------------------
/gluit/glui_quaternion.cc:
--------------------------------------------------------------------------------
1 | /***********************************************************************
2 |
3 | quaternion.cpp
4 |
5 | A quaternion class
6 |
7 | -------------------------------------------------------------------
8 |
9 | Feb 1998, Paul Rademacher (rademach@cs.unc.edu)
10 |
11 | ************************************************************************/
12 |
13 | #include "glui_stdinc.h"
14 | #include "glui_quaternion.h"
15 |
16 | /******************************************* constructors **************/
17 |
18 | quat::quat( void )
19 | {
20 | *this = quat_identity();
21 | }
22 |
23 | quat::quat(const float x, const float y, const float z, const float w)
24 | {
25 | v.set( x, y, z );
26 | s = w;
27 | }
28 |
29 | quat::quat( vec3 _v, float _s )
30 | {
31 | set( _v, _s );
32 | }
33 |
34 | quat::quat( float _s, vec3 _v )
35 | {
36 | set( _v, _s );
37 | }
38 |
39 | quat::quat( const float *d )
40 | {
41 | v[0] = d[0];
42 | v[1] = d[1];
43 | v[2] = d[2];
44 | s = d[3];
45 | }
46 |
47 | quat::quat( const double *d )
48 | {
49 | v[0] = (float)d[0];
50 | v[1] = (float)d[1];
51 | v[2] = (float)d[2];
52 | s = (float)d[3];
53 | }
54 |
55 | quat::quat( const quat &q )
56 | {
57 | v = q.v;
58 | s = q.s;
59 | }
60 |
61 | void quat::set( vec3 _v, float _s )
62 | {
63 | v = _v;
64 | s = _s;
65 | }
66 |
67 | quat& quat::operator = (const quat& q)
68 | {
69 | v = q.v; s = q.s; return *this;
70 | }
71 |
72 |
73 | /* ... */
74 |
75 |
76 | /******** quat friends ************/
77 |
78 | quat operator + (const quat &a, const quat &b)
79 | {
80 | return quat( a.s+b.s, a.v+b.v );
81 | }
82 |
83 | quat operator - (const quat &a, const quat &b)
84 | {
85 | return quat( a.s-b.s, a.v-b.v );
86 | }
87 |
88 | quat operator - (const quat &a )
89 | {
90 | return quat( -a.s, -a.v );
91 | }
92 |
93 | quat operator * ( const quat &a, const quat &b)
94 | {
95 | return quat( a.s*b.s - a.v*b.v, a.s*b.v + b.s*a.v + (a.v^b.v) );
96 | }
97 |
98 | quat operator * ( const quat &a, const float t)
99 | {
100 | return quat( a.v * t, a.s * t );
101 | }
102 |
103 | quat operator * ( const float t, const quat &a )
104 | {
105 | return quat( a.v * t, a.s * t );
106 | }
107 |
108 |
109 | mat4 quat::to_mat4( void )
110 | {
111 | float t, xs, ys, zs, wx, wy, wz, xx, xy, xz, yy, yz, zz;
112 |
113 | t = 2.0f / (v*v + s*s);
114 |
115 | xs = v[VX]*t; ys = v[VY]*t; zs = v[VZ]*t;
116 | wx = s*xs; wy = s*ys; wz = s*zs;
117 | xx = v[VX]*xs; xy = v[VX]*ys; xz = v[VX]*zs;
118 | yy = v[VY]*ys; yz = v[VY]*zs; zz = v[VZ]*zs;
119 |
120 | mat4 matrix( 1.0f-(yy+zz), xy+wz, xz-wy, 0.0f,
121 | xy-wz, 1.0f-(xx+zz), yz+wx, 0.0f,
122 | xz+wy, yz-wx, 1.0f-(xx+yy), 0.0f,
123 | 0.0f, 0.0f, 0.0f, 1.0f );
124 |
125 | return matrix;
126 | }
127 |
128 |
129 | /************************************************* quat_identity() *****/
130 | /* Returns quaternion identity element */
131 |
132 | quat quat_identity( void )
133 | {
134 | return quat( vec3( 0.0, 0.0, 0.0 ), 1.0 );
135 | }
136 |
137 |
138 | /************************************************ quat_slerp() ********/
139 | /* Quaternion spherical interpolation */
140 |
141 | quat quat_slerp( quat from, quat to, float t )
142 | {
143 | quat to1;
144 | double omega, cosom, sinom, scale0, scale1;
145 |
146 | /* calculate cosine */
147 | cosom = from.v * to.v + from.s + to.s;
148 |
149 | /* Adjust signs (if necessary) */
150 | if ( cosom < 0.0 ) {
151 | cosom = -cosom;
152 | to1 = -to;
153 | }
154 | else
155 | {
156 | to1 = to;
157 | }
158 |
159 | /* Calculate coefficients */
160 | if ((1.0 - cosom) > FUDGE ) {
161 | /* standard case (slerp) */
162 | omega = acos( cosom );
163 | sinom = sin( omega );
164 | scale0 = sin((1.0 - (double)t) * omega) / sinom;
165 | scale1 = sin((double)t * omega) / sinom;
166 | }
167 | else {
168 | /* 'from' and 'to' are very close - just do linear interpolation */
169 | scale0 = 1.0 - (double)t;
170 | scale1 = t;
171 | }
172 |
173 | return (float) scale0 * from + (float) scale1 * to1;
174 | }
175 |
176 |
177 | /********************************************** set_angle() ************/
178 | /* set rot angle (degrees) */
179 |
180 | void quat::set_angle( float f )
181 | {
182 | vec3 axis = get_axis();
183 |
184 | s = cos( DEG2RAD( f ) / 2.0f );
185 |
186 | v = axis * sin(DEG2RAD(f) / 2.0f);
187 | }
188 |
189 |
190 | /********************************************** scale_angle() ************/
191 | /* scale rot angle (degrees) */
192 |
193 | void quat::scale_angle( float f )
194 | {
195 | set_angle( f * get_angle() );
196 | }
197 |
198 |
199 | /********************************************** get_angle() ************/
200 | /* get rot angle (degrees). Assumes s is between -1 and 1 */
201 |
202 | float quat::get_angle( void )
203 | {
204 | return RAD2DEG( 2.0f * acos( s ) );
205 | }
206 |
207 |
208 | /********************************************* get_axis() **************/
209 |
210 | vec3 quat::get_axis( void )
211 | {
212 | double scale = sin( acos( (double) s ) );
213 | if ( scale < FUDGE AND scale > -FUDGE )
214 | return vec3( 0.0, 0.0, 0.0 );
215 | else
216 | return v / (float) scale;
217 | }
218 |
219 |
220 | /******************************************* quat::print() ************/
221 |
222 | void quat::print( FILE *dest, const char *name )
223 | {
224 | fprintf( dest, "%s: v:<%3.2f %3.2f %3.2f> s:%3.2f\n", name,
225 | v[0], v[1], v[2], s );
226 | }
227 |
--------------------------------------------------------------------------------
/gluit/glui_arcball.cc:
--------------------------------------------------------------------------------
1 | /**********************************************************************
2 |
3 | arcball.cpp
4 |
5 |
6 | --------------------------------------------------
7 |
8 | Copyright (c) 1998 Paul Rademacher
9 |
10 | This program is freely distributable without licensing fees and is
11 | provided without guarantee or warrantee expressed or implied. This
12 | program is -not- in the public domain.
13 |
14 | **********************************************************************/
15 |
16 |
17 | #include "glui_arcball.h"
18 |
19 |
20 | /**************************************** Arcball::Arcball() ****/
21 | /* Default (void) constructor for Arcball */
22 |
23 | Arcball::Arcball( void )
24 | {
25 | rot_ptr = &rot;
26 |
27 | init();
28 | }
29 |
30 |
31 | /**************************************** Arcball::Arcball() ****/
32 | /* Takes as argument a mat4 to use instead of the internal rot */
33 |
34 | Arcball::Arcball( mat4 *mtx )
35 | {
36 | rot_ptr = mtx;
37 | }
38 |
39 |
40 | /**************************************** Arcball::Arcball() ****/
41 | /* A constructor that accepts the screen center and arcball radius*/
42 |
43 | Arcball::Arcball( vec2 _center, float _radius )
44 | {
45 | rot_ptr = &rot;
46 |
47 | init();
48 | set_params( _center, _radius );
49 | }
50 |
51 |
52 | /************************************** Arcball::set_params() ****/
53 |
54 | void Arcball::set_params( vec2 _center, float _radius )
55 | {
56 | center = _center;
57 | radius = _radius;
58 | }
59 |
60 |
61 | /*************************************** Arcball::init() **********/
62 |
63 | void Arcball::init( void )
64 | {
65 | center.set( 0.0, 0.0 );
66 | radius = 1.0;
67 | q_now = quat_identity();
68 | *rot_ptr = identity3D();
69 | q_increment = quat_identity();
70 | rot_increment = identity3D();
71 | is_mouse_down = false;
72 | is_spinning = false;
73 | damp_factor = 0.0;
74 | zero_increment = true;
75 | }
76 |
77 |
78 | /*********************************** Arcball::mouse_to_sphere() ****/
79 |
80 | vec3 Arcball::mouse_to_sphere( vec2 p )
81 | {
82 | float mag;
83 | vec2 v2 = (p - center) / radius;
84 | vec3 v3( v2[0], v2[1], 0.0 );
85 |
86 | mag = v2*v2;
87 |
88 | if ( mag > 1.0f ) {
89 | v3.normalize();
90 | }
91 | else {
92 | v3[VZ] = sqrt( 1.0f - mag );
93 | }
94 |
95 | /* Now we add constraints - X takes precedence over Y */
96 | if ( constraint_x ) {
97 | v3 = constrain_vector( v3, vec3( 1.0, 0.0, 0.0 ));
98 | } else if ( constraint_y ) {
99 | v3 = constrain_vector( v3, vec3( 0.0, 1.0, 0.0 ));
100 | }
101 |
102 | return v3;
103 | }
104 |
105 |
106 | /************************************ Arcball::constrain_vector() ****/
107 |
108 | vec3 Arcball::constrain_vector( vec3 vector, vec3 axis )
109 | {
110 | return (vector-(vector*axis)*axis).normalize();
111 | }
112 |
113 | /************************************ Arcball::mouse_down() **********/
114 |
115 | void Arcball::mouse_down( int x, int y )
116 | {
117 | down_pt.set( (float)x, (float) y );
118 | is_mouse_down = true;
119 |
120 | q_increment = quat_identity();
121 | rot_increment = identity3D();
122 | zero_increment = true;
123 | }
124 |
125 |
126 | /************************************ Arcball::mouse_up() **********/
127 |
128 | void Arcball::mouse_up( void )
129 | {
130 | q_now = q_drag * q_now;
131 | is_mouse_down = false;
132 | }
133 |
134 |
135 | /********************************** Arcball::mouse_motion() **********/
136 |
137 | void Arcball::mouse_motion( int x, int y, int shift, int ctrl, int alt )
138 | {
139 | /* Set the X constraint if CONTROL key is pressed, Y if ALT key */
140 | set_constraints( ctrl != 0, alt != 0 );
141 |
142 | vec2 new_pt( (float)x, (float) y );
143 | vec3 v0 = mouse_to_sphere( down_pt );
144 | vec3 v1 = mouse_to_sphere( new_pt );
145 |
146 | vec3 cross = v0^v1;
147 |
148 | q_drag.set( cross, v0 * v1 );
149 |
150 | // *rot_ptr = (q_drag * q_now).to_mat4();
151 | mat4 temp = q_drag.to_mat4();
152 | *rot_ptr = (*rot_ptr) * temp;
153 |
154 | down_pt = new_pt;
155 |
156 | /* We keep a copy of the current incremental rotation (= q_drag) */
157 | q_increment = q_drag;
158 | rot_increment = q_increment.to_mat4();
159 |
160 | set_constraints( false, false );
161 |
162 | if ( q_increment.s < .999999f ) {
163 | is_spinning = true;
164 |
165 | zero_increment = false;
166 | }
167 | else {
168 | is_spinning = false;
169 | zero_increment = true;
170 | }
171 | }
172 |
173 |
174 | /********************************** Arcball::mouse_motion() **********/
175 |
176 | void Arcball::mouse_motion( int x, int y )
177 | {
178 | mouse_motion( x, y, 0, 0, 0 );
179 | }
180 |
181 |
182 | /***************************** Arcball::set_constraints() **********/
183 |
184 | void Arcball::set_constraints( Bool _constraint_x, Bool _constraint_y )
185 | {
186 | constraint_x = _constraint_x;
187 | constraint_y = _constraint_y;
188 | }
189 |
190 | /***************************** Arcball::idle() *********************/
191 |
192 | void Arcball::idle( void )
193 | {
194 | if ( is_mouse_down ) {
195 | is_spinning = false;
196 | zero_increment = true;
197 | }
198 |
199 | if ( damp_factor < 1.0f ) {
200 | q_increment.scale_angle( 1.0f - damp_factor );
201 | }
202 |
203 | rot_increment = q_increment.to_mat4();
204 |
205 | if ( q_increment.s >= .999999f ) {
206 | is_spinning = false;
207 | zero_increment = true;
208 | }
209 | }
210 |
211 |
212 | /************************ Arcball::set_damping() *********************/
213 |
214 | void Arcball::set_damping( float d )
215 | {
216 | damp_factor = d;
217 | }
218 |
219 |
220 |
221 |
222 |
223 |
--------------------------------------------------------------------------------
/help/README:
--------------------------------------------------------------------------------
1 |
2 | This is trimesh2, a C++ library and set of utilities for input, output,
3 | and basic manipulation of 3D triangle meshes. The goals of the code are
4 | ease of use and efficiency, possibly at the expense of some generality.
5 |
6 |
7 | The library includes the following:
8 |
9 | - Support for reading PLY, OFF, 3DS, VVD, and Wavefront OBJ files,
10 | together with a few other formats of mostly local interest (SM, RAY).
11 |
12 | - Support for writing PLY, OFF, and OBJ files.
13 |
14 | - A templated C++ class for constant-length vectors, with support for the
15 | usual arithmetic operations (add, subtract, componentwise multiply and
16 | divide, dot product, cross product, etc.)
17 |
18 | - A class for rigid-body transformations.
19 |
20 | - An OpenGL trackball/arcball implementation, with automatic selection of
21 | rotation center.
22 |
23 | - Algorithms for subdivision, smoothing, curvature estimation, triangle
24 | stripping, and various other simple mesh manipulations.
25 |
26 |
27 | Bundled together with the library are:
28 |
29 | - Bernd Gartner's "miniball" code for efficient exact bounding sphere
30 | computation: http://www.inf.ethz.ch/personal/gaertner/minibal.html
31 |
32 | - An ever-so-slightly tweaked version of the freeglut library, an
33 | open source GLUT replacement: http://freeglut.sourceforge.net/
34 |
35 | - GLUI, a user interface library that sits on top of OpenGL, hence is
36 | portable to many different systems: http://www.nigels.com/glt/glui/
37 |
38 |
39 | In addition, the following utility programs are included:
40 |
41 | - mesh_view: a simple 3D mesh viewer
42 |
43 | - mesh_make: create arbitrarily-tessellated meshes of various simple shapes
44 |
45 | - mesh_filter: applies a variety of simple transformations to a mesh,
46 | such as converting formats, flipping faces, subdivision, smoothing,
47 | rigid-body transformations, etc.
48 |
49 | - mesh_cc: list and/or extract connected components from a mesh
50 |
51 | - mesh_cat: combine several meshes into a single file
52 |
53 | - mesh_align: align 2 meshes using ICP
54 |
55 |
56 | The author of trimesh2 is Szymon Rusinkiewicz, and the library is
57 | distributed under the GNU General Public License (GPL). The various
58 | libraries distributed with trimesh2 are open source, and are believed
59 | to be covered by GPL-compatible licenses. Please see the COPYING file.
60 |
61 |
62 | Running the utilities:
63 | ----------------------
64 |
65 | All of the programs must be run from the command line. Each displays
66 | a list of options when run without arguments.
67 |
68 | In the mesh_view program, the view is changed by dragging with particular
69 | mouse buttons as follows:
70 |
71 | Left: Rotate (release while moving to spin the object)
72 | Middle: Translate left, right, up, down
73 | Left+right: Translate left, right, up, down
74 | Right: Translate forward and back
75 | Mouse wheel: Translate forward and back
76 | Ctrl+Left: Move the light
77 |
78 | In addition, the following keys invoke various options:
79 |
80 | Space bar: Reset to initial view
81 | e: Toggle display of mesh edges
82 | l: Toggle lighting
83 | f: Toggle false-color rendering
84 | q: Exit
85 | s: Toggle specular component in reflection
86 | Shift-2: Toggle 2-sided lighting
87 | x: Write current viewpoint as a ".xf" file
88 | 1, 2, etc.: Toggle the n-th mesh off and on
89 |
90 |
91 | Using the library:
92 | ------------------
93 |
94 | There is no complete documentation for the library - poke around in
95 | include/*.h to see what is available, and look in utilsrc/*.cc to
96 | see how it's used. Here's a trivial program to help you get started:
97 |
98 |
99 | #include "TriMesh.h"
100 | #include
101 | #include
102 | using namespace trimesh;
103 | using namespace std;
104 |
105 | int main(int argc, char *argv[])
106 | {
107 | const char *filename = "foo.ply";
108 | TriMesh *m = TriMesh::read(filename);
109 | if (!m)
110 | exit(1);
111 |
112 | cout << "There are " << m->vertices.size() << " vertices" << endl;
113 | cout << "Vertex 0 is at " << m->vertices[0] << endl;
114 |
115 | // Convert triangle strips to faces, if necessary
116 | m->need_faces();
117 | cout << "Face 0 has vertices " << m->faces[0][0] << ", "
118 | << m->faces[0][1] << ", and " << m->faces[0][2] << endl;
119 |
120 | m->need_normals();
121 | cout << "Vertex 0 has normal " << m->normals[0] << endl;
122 | }
123 |
124 |
125 | Compiling:
126 | ----------
127 |
128 | The code is written in C++, and is known to compile using a recent version
129 | of g++ (4.0.1 or later, but avoid 4.1.2). Compiling under Windows is
130 | possible using Cygwin or MinGW32. Other compilers have not been tested -
131 | let me know of any successes or failures.
132 |
133 | After unpacking the code, edit the appropriate "Makedefs.*" file to
134 | specify the compiler and any necessary options. If there is no Makedefs
135 | for your OS, run "uname" to determine what it should be named and create
136 | one (probably starting with one of the existing files as a template).
137 | At this point, just running "make" in the top-level directory should make
138 | the library (placed in lib.`uname`) and utilities (placed in bin.`uname`).
139 |
140 | If you have any problems, please double check the following:
141 | - You are using a recent version of the compiler
142 | - You are using a recent version of GNU make
143 | - The correct -I option is included to find all the headers you need,
144 | including OpenGL headers
145 | If you still have problems, let me (smr@princeton.edu) know and I'll do
146 | my best to help resolve them.
147 |
148 |
149 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # TriMesh2 (v2.16)
2 | [](https://github.com/Forceflow/trimesh2/actions/workflows/c-cpp.yml) [](https://www.gnu.org/licenses/gpl-3.0)
3 |
4 | A C++ library and set of utilities for input, output, and basic manipulation of 3D triangle meshes.
5 |
6 | 
7 |
8 | This is a fork of the [TriMesh2 library](http://gfx.cs.princeton.edu/proj/trimesh2/) (originally by [Szymon Rusinkiewicz](https://www.cs.princeton.edu/~smr/)), which I use a lot in my [other](https://github.com/Forceflow/ooc_svo_builder) [graphics](https://github.com/Forceflow/cuda_voxelizer) [projects](https://github.com/Forceflow/gpu_suggestive_contours). I like TriMesh2 because of the low setup costs required to do model loading, as well as the robust and powerful implementation of various model manipulation techniques.
9 |
10 | The original TriMesh2 project is quite Linux/GCC-oriented, and only has limited Win32 support (through MinGW compilation targets). The primary aim of this fork is to add a stable Visual Studio solution, for both x86 and x64 targets, whilst staying as close as possible to the original codebase (and subsequent updates).
11 |
12 | ## Getting started
13 | * Download a [prebuilt release](https://github.com/Forceflow/trimesh2/releases) of trimesh2 or build the library yourself (see further below)
14 | * The static library will be called `trimesh.lib`, the debug version is `trimeshd.lib`.
15 | * Include the header `include/TriMesh.h`, and make sure the static library is in your build path. All Trimesh2 functions will be in the `TriMesh` namespace.
16 | * Typical ways to get started:
17 | * Loading a model : `TriMesh* themesh = TriMesh::read(filename);`.
18 | * This mesh class contains a data member `vertices` which will be filled with all the vertices of your model, and a data member `faces`, which will tell you which vertices make up a face.
19 | * If your model contains vertex normals, they will be in `normals`. You can (re)compute them by calling `need_normals` on the mesh. There's also `need_bbox` for a bounding box, `need_dcurv` for curvature, etc.
20 | * For inspiration on how to use the library and its various features, check out `include/TriMesh.h` and the utilities in the `utilsrc` folder.
21 | ## Building
22 | ### Dependencies
23 | * The library itself has no dependencies other than the standard C++ STL
24 | * The (optional) ``mesh_view`` utility has dependencies on OpenGL and Freeglut, because it needs to display a window with a textured model
25 |
26 | ### Build steps
27 | * For **Windows**, build solutions for VS2022 and VS2019 are provided in the `mscv`folder, verified working with the [free Community Editions](https://visualstudio.microsoft.com/vs/community/) of Visual Studio. The solutions contain both Debug and Release profiles for 32-bit and 64-bit builds.
28 | * The built libraries will be placed in a folder named `lib.(architecture).(visual studio version)` in the trimesh2 root folder. For example, for a 64-bit Visual Studio 2017 build, it will be `lib.win64.vs141`. The utilities will be placed in `util.(architecture).(visual studio version)`. This naming scheme is in place to avoid clashing trimesh2 versions.
29 | * For **Linux**, a makefile is provided. You might need additional packages before you can build the utilities on your system. On Ubuntu these are: `mesa-common-dev libglu1-mesa-dev libxi-dev`.
30 | * For **OSX**, I'm being told it builds using the makefile, but I have no way to check. If you encounter problems, please, file an issue report :)
31 |
32 | ## Info
33 | For the original TriMesh2 project, see [the Trimesh2 homepage](http://gfx.cs.princeton.edu/proj/trimesh2/).
34 |
35 | Features:
36 |
37 | * Support for reading/writing PLY, OFF, OBJ files. Read-only: 3DS, SM, RAY.
38 | * Vec: a templated C++ class for constant-length vectors, with support for the usual arithmetic operations and XForm: a class for rigid-body transformations.
39 | * An OpenGL trackball/arcball implementation, with automatic selection of rotation center.
40 | * Algorithms for subdivision, smoothing, curvature estimation, triangle stripping, and various other simple mesh manipulations.
41 |
42 | The following utility programs are included:
43 |
44 | * **mesh_view**: A simple 3D mesh viewer
45 | * **mesh_make**: Create arbitrarily-tessellated meshes of various simple shapes
46 | * **mesh_filter**: Applies a variety of simple transformations to a mesh, such as converting formats, flipping faces, subdivision, smoothing, rigid-body transformations, etc.
47 | * **mesh_cc**: List and/or extract connected components from a mesh
48 | * **mesh_cat**: Combine several meshes into a single file
49 | * **mesh_align**: Align 2 meshes using ICP
50 | * **mesh_shade**: A few procedural shaders for adding per-vertex color
51 | * **mesh_check**: Check for some kinds of topological oddities (e.g., more than 2 faces at an edge) in a mesh file.
52 | * **mesh_crunch**: Quick-n-dirty mesh decimation using the Rossignac-Borrel method of vertex collapse
53 | * **mesh_info**: Print out some information about a mesh
54 | * **xf**: Create or compose transformations in .xf files
55 |
56 | ## Fork Details
57 |
58 | This fork stays as close as possible to the original [trimesh2](http://gfx.cs.princeton.edu/proj/trimesh2/) code, only changing the actual source files when a solution for compilation errors cannot be reached through VS pre-build steps or preprocessor magic.
59 |
60 | Notable changes compared to vanilla trimesh2
61 | * MSVC project for Visual Studio Community Edition 2022, 2019 and 2017
62 | * Fixes for FreeGlut / Gluit compilation
63 | * Fixes for wingetopt replacement in MSVC
64 | * Added 64-bit MSVC compilation support
65 |
66 | ## See Also
67 |
68 | Other software for importing and manipulating 3D models:
69 | * [Tiny OBJ Loader](https://github.com/syoyo/tinyobjloader) (by @syoyo)
70 | * [Tiny PLY](https://github.com/ddiakopoulos/tinyply) (by @ddiakopoulos)
71 | * [Open Asset Import Library](http://www.assimp.org/) (ASSIMP)
72 |
--------------------------------------------------------------------------------