Compare commits

...

73 Commits

Author SHA1 Message Date
942f5b12df Chrome improvements: shortcuts, trim select/drag, Shift-D, per-trim tessellation resolution, etc. 2014-08-22 02:59:21 -06:00
63dd004afd Add circular trim 2014-08-21 21:51:54 -06:00
bc9d3591de Got RNA working and frontend for adding trims 2014-08-21 21:25:57 -06:00
686bb8aaf4 Sergey's patch, manually pruned so as to work with HEAD. 2014-08-20 20:34:04 -06:00
27d0bf77cb C89 support (I think). 2014-08-19 15:17:41 -04:00
d9992fbb53 UV editor editing functionality (drag pts / knots, add trim, etc) is finally stable\! Commence cleanup\! 2014-08-19 02:12:05 -04:00
eaeae5a568 Added select-linked, fixed leak, cleaned up operator poll functions 2014-08-14 16:43:55 -04:00
5abed28423 Got rid of unused function editnurb_draw_active_nurbs 2014-08-14 12:31:15 -04:00
f33bc29c34 Added support for transparent (see through surface) control mesh, fixed NURBS convert-to-mesh wasn't smooth, fixed spastic tessellation geometry bug, added support in UV editor for 1D curves. 2014-08-14 12:29:32 -04:00
ef4478c62b Selective selection based on what is selected in 3dview 2014-08-13 17:02:12 -04:00
047e44dbcc All types of selection work on knots 2014-08-13 14:27:22 -04:00
623dce3bb6 Continued work on UV Editor. Selections work, multiplicities are drawn, cursor is drawn. 2014-08-12 23:23:44 -04:00
44b5e6c0df UV Edit Selection Propagation 2014-08-08 23:24:54 -04:00
54e68e1b1e NURBS UV Editor 2014-08-07 23:29:04 -04:00
b4d795b9b7 Stopgap bugfix for trim tessellator failure when trim curve hits vert, read/write unstashed & bugfixed to not crash on undo push, changed UV axis orientation and coloring for consistency with RGB={+x,+y,+z} mnemonic. 2014-08-06 23:58:52 -04:00
e791aeb41b New mesher (proper ngon, orco, etc). 2014-08-05 13:23:43 -04:00
be8b5ecc84 Added support for loop-select and adjusted disply of NURBS control polygon to 1: use z-test, 2: appear 'thin'. 2014-08-01 07:39:25 -04:00
98e5beabb5 Fixed bug that turned all booleans into bool_SUB, added code to get trims from Blender into 3dm viz for debug. 2014-07-31 16:45:36 -04:00
053cd1f289 Interior trims are now preserved by re-knot-ing. For some reason exterior trims aren't... 2014-07-30 20:02:59 -04:00
a5a4360d32 Trim curve import works! They don't rescale to blender-style knots automatically yet, so they're fragile to edits. 2014-07-30 19:24:44 -04:00
f489cd54a1 Finally tracked down coordinate scrambling bug. 2014-07-30 15:37:23 -04:00
c38ca588e5 Fixed the DNA problem. 2014-07-29 22:19:41 -04:00
09636bf864 Added UV-mesh cache so editing is fast, implemented NurbTrim. DNA is still buggy. 2014-07-29 19:18:56 -04:00
ca5b2d3c5c An entire day spent chasing mem management bugs :( 2014-07-28 01:21:45 -04:00
85d8ff9f96 Removed platform-dependant timing code to fix build. 2014-07-27 18:08:43 -04:00
f630ed83d6 Progress commit: adding support for import+tessellate trim curves (mem mgt bugs). 2014-07-26 22:53:25 -04:00
7a75489f86 Putting it all together: {BSpline,NURBS} values+derivates calculate & verify with Mathematica, smooth normals display properly. 2014-07-23 23:50:32 -04:00
a0ed39729a NURBS surf eval + derivatives written (not verified), basis cache. 2014-07-22 23:27:48 -04:00
6103835784 BSpline basis (derivs 0,1,2), BSpline surface (derivs 0,1) fix + verification in Mathematica 2014-07-21 23:44:13 -04:00
14c73b305f Eval debug rig 2014-07-20 22:43:05 -04:00
b40acb2d98 Added new eval code (computes first and second surface partials). Still buggy near multi-knots. 2014-07-17 11:25:23 -04:00
db703dd4a2 Fixed the memory leak bug, the bug that caused trimmed vertices to linger, and the bug that separated connected triangle faces produced with alt+c. 2014-07-15 20:22:02 -04:00
b2ddd70949 Added dumber+faster grid propagator, fixed displist crash bug for >~10x10 tessellation grids. 2014-07-14 21:46:58 -04:00
dbf2f19b35 NURBS pushforward (U,V)->(x,y,z) works properly 2014-07-12 18:58:47 -04:00
e8e3bab45b Displist construction -- better commit it before I tear it up again 2014-07-10 13:24:07 -04:00
3091165472 Promoted curve.c to cpp (changed extension, added casts), moved gridmesh into blenkernel/intern, the location of the old tessellation code, and moved the GLUT debug tool into the tests folder which seems like the appropriate place for it. 2014-07-10 01:55:53 -04:00
c5644bc766 Timing code (TODO: REMOVE, it's platform-specific), reorganization of coords (now stored apart from verts) for compatibility with tess code. 2014-07-09 22:44:02 -04:00
8d6469adad BRep import base 2014-07-07 23:05:48 -04:00
7782970300 Bugfix: inadvertant bool_SUB->bool_UNION fix for trimming verts that start in a grid cell but not in any of its polygons. 2014-07-03 11:43:16 -04:00
91966c427e Boolean subtraction implemented and tested. 2014-07-03 00:05:03 -04:00
66056dc8c0 Bugfixes: now GridMesh can *actually* be ANDed with multiple successive polygons. 2014-07-02 23:05:20 -04:00
99c45cd6d8 GridMesh can now handle being ANDed with multiple *successive* polygons rather than all-at-once-so-long-as-they-dont-intersect. Also, slow PIP test is avoided when possible by a more general mechanism that can propagate interior/exterior info via any grid vertex. 2014-07-01 23:53:38 -04:00
61f83908fe Another order bug squashed! Can't order everything before cutting. Now cuts happen after every edge. 2014-06-30 12:36:53 -04:00
c2b928243f Buggy code pre-reorganization. 2014-06-27 16:07:45 -04:00
82ae614496 Added infrastructure to visualize inclusion-exclusion, moved trim code into GLUT demo. 2014-06-27 11:36:59 -04:00
469fae8820 Merge branch 'soc-2014-nurbs' of git.blender.org:blender into soc-2014-nurbs
Conflicts:
	source/blender/editors/io/io_rhino_import.cpp
2014-06-27 02:14:07 -04:00
df125e5f98 blender build fix 2014-06-27 02:09:52 -04:00
b7a9ccf60b Merge remote-tracking branch 'polytest/master' into soc-2014-nurbs 2014-06-27 02:04:41 -04:00
70ed4412d4 Moved files into position for merge with soc-2014-nurbs branch. 2014-06-27 01:58:09 -04:00
b15cb1ec01 Fixed dropped vertex in poly creation, finished multi-poly support, better default scene. 2014-06-27 01:16:53 -04:00
5872cd2cd2 Began to add back in multi-poly code, squashed left-horizontal bug. 2014-06-26 23:38:03 -04:00
9484bb2b88 Dammit, one more order bug and one raster bug. All 8+8 cases pass now. 2014-06-26 21:34:01 -04:00
c6f7b1b07b 3rd overlapping edge order bug fixed. Pretty sure this is the last one. 2014-06-26 21:10:44 -04:00
acef8bd268 Overlapping edge order fixed (exits old polygon before enters new polygon) 2014-06-26 15:49:53 -04:00
d74da659ed Interior label propagation 2014-06-26 13:33:54 -04:00
c5b1bb13ae Order bug fixed. 2014-06-26 10:29:18 -04:00
7de89d945f Finally nailed the edge-skipping bug (required minor architectural change). The out-of-order bug still lurks, but it should be relatively trivial. 2014-06-25 22:51:32 -04:00
2f5218fd8a Refactored code to fix bug on reallocation of large vertex table. 2014-06-25 12:30:43 -04:00
5fbf41a822 Whoops, I forgot to make git track the GridMesh GLUT code. Here it is. 2014-06-24 21:57:33 -04:00
dc9a5e71eb Updates to GridMesh (int indexes, now verts keep backpointers to first vert 2014-06-23 22:54:39 -04:00
e762cc1880 Added intelligent knot analysis code 2014-06-22 21:59:54 -04:00
be6cedce61 Added 3dm import code for curves and untrimmed surfaces. Debugged issue with homogeneous coordinate differences between Rhino, Blender. 2014-06-22 21:59:54 -04:00
3717e3a00b Adapted opennurbs to use the system zlib and removed its custom zlib library. 2014-06-22 21:59:54 -04:00
ff80781e8d Initial import of .3dm (Rhino) import/export stubs, OpenMP mac+CMake build fix, and opennurbs library (along with cmake changes to build it). 2014-06-22 21:59:53 -04:00
4d5081cc7c Added beginning of OO mesh-cut interface. 2014-06-22 05:35:34 -04:00
8c8a5a6dc4 Added 3dm import code for curves and untrimmed surfaces. Debugged issue with homogeneous coordinate differences between Rhino, Blender. 2014-06-22 05:33:45 -04:00
47212348cb Added raster algo, viz 2014-06-18 12:55:01 -04:00
8133d79264 Added multi subject-polygon capability, preliminary raster implementation. 2014-06-16 23:53:50 -04:00
a1fd3764fa Added support for drawing, moving, and inserting vertices in multiple subject polygons 2014-06-15 22:29:23 -04:00
a85ebd7720 Working: line intersection, point in polygon, chalk cart 2014-06-14 04:45:30 -04:00
49d78a3cc0 Initial Commit 2014-06-13 21:37:24 -04:00
db9b1f7d87 Adapted opennurbs to use the system zlib and removed its custom zlib library. 2014-06-02 10:16:43 -04:00
188de00d62 Initial import of .3dm (Rhino) import/export stubs, OpenMP mac+CMake build fix, and opennurbs library (along with cmake changes to build it). 2014-06-02 02:23:53 -04:00
296 changed files with 276484 additions and 737 deletions

View File

@@ -1888,6 +1888,7 @@ elseif(APPLE)
if(WITH_OPENMP AND CMAKE_C_COMPILER_ID MATCHES "Clang" AND NOT ${CMAKE_C_COMPILER_VERSION} VERSION_LESS '3.4')
set(OPENMP_FOUND ON)
set(OPENMP_LIBRARY iomp5)
set(OpenMP_C_FLAGS "-fopenmp" CACHE STRING "C compiler flags for OpenMP parallization" FORCE)
set(OpenMP_CXX_FLAGS "-fopenmp" CACHE STRING "C++ compiler flags for OpenMP parallization" FORCE)
include_directories(${LIBDIR}/openmp/include)

View File

@@ -313,6 +313,9 @@ macro(setup_liblinks
if(WITH_OPENAL)
target_link_libraries(${target} ${OPENAL_LIBRARY})
endif()
if(WITH_OPENMP)
target_link_libraries(${target} ${OPENMP_LIBRARY})
endif()
if(WITH_FFTW3)
target_link_libraries(${target} ${FFTW3_LIBRARIES})
endif()

View File

@@ -30,6 +30,7 @@ add_subdirectory(colamd)
add_subdirectory(rangetree)
add_subdirectory(wcwidth)
add_subdirectory(libmv)
add_subdirectory(opennurbs)
if(WITH_BULLET)
if(NOT WITH_SYSTEM_BULLET)

256
extern/opennurbs/CMakeLists.txt vendored Normal file
View File

@@ -0,0 +1,256 @@
# ***** BEGIN GPL LICENSE BLOCK *****
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software Foundation,
# Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# The Original Code is Copyright (C) 2011, Blender Foundation
# All rights reserved.
#
# Contributor(s): Blender Foundation,
# Sergey Sharybin
#
# ***** END GPL LICENSE BLOCK *****
# NOTE FOR THOSE UPDATING OPENNURBS:
# Change #include "./zlib/zlib.h" in opennurbs_zlib.h to #include "zlib.h"
set(INC
.
)
set(INC_SYS
${ZLIB_INCLUDE_DIR}
)
set(SRC
opennurbs_memory.c
opennurbs_memory_util.c
opennurbs_3dm_attributes.cpp
opennurbs_3dm_properties.cpp
opennurbs_3dm_settings.cpp
opennurbs_annotation.cpp
opennurbs_annotation2.cpp
opennurbs_arc.cpp
opennurbs_arccurve.cpp
opennurbs_archive.cpp
opennurbs_array.cpp
opennurbs_base32.cpp
opennurbs_base64.cpp
opennurbs_beam.cpp
opennurbs_bezier.cpp
opennurbs_beziervolume.cpp
opennurbs_bitmap.cpp
opennurbs_bounding_box.cpp
opennurbs_box.cpp
opennurbs_brep.cpp
opennurbs_brep_extrude.cpp
opennurbs_brep_io.cpp
opennurbs_brep_isvalid.cpp
opennurbs_brep_region.cpp
opennurbs_brep_tools.cpp
opennurbs_brep_v2valid.cpp
opennurbs_circle.cpp
opennurbs_color.cpp
opennurbs_compress.cpp
opennurbs_cone.cpp
opennurbs_crc.cpp
opennurbs_curve.cpp
opennurbs_curveonsurface.cpp
opennurbs_curveproxy.cpp
opennurbs_cylinder.cpp
opennurbs_defines.cpp
opennurbs_detail.cpp
opennurbs_dimstyle.cpp
opennurbs_dll.cpp
opennurbs_ellipse.cpp
opennurbs_embedded_file.cpp
opennurbs_error.cpp
opennurbs_error_message.cpp
opennurbs_evaluate_nurbs.cpp
opennurbs_extensions.cpp
opennurbs_font.cpp
opennurbs_fsp.cpp
opennurbs_geometry.cpp
opennurbs_gl.cpp
opennurbs_group.cpp
opennurbs_hatch.cpp
opennurbs_instance.cpp
opennurbs_intersect.cpp
opennurbs_knot.cpp
opennurbs_layer.cpp
opennurbs_light.cpp
opennurbs_line.cpp
opennurbs_linecurve.cpp
opennurbs_linetype.cpp
opennurbs_lookup.cpp
opennurbs_material.cpp
opennurbs_math.cpp
opennurbs_matrix.cpp
opennurbs_mesh.cpp
opennurbs_mesh_ngon.cpp
opennurbs_mesh_tools.cpp
opennurbs_morph.cpp
opennurbs_nurbscurve.cpp
opennurbs_nurbssurface.cpp
opennurbs_nurbsvolume.cpp
opennurbs_object.cpp
opennurbs_object_history.cpp
opennurbs_objref.cpp
opennurbs_offsetsurface.cpp
opennurbs_optimize.cpp
opennurbs_photogrammetry.cpp
opennurbs_plane.cpp
opennurbs_planesurface.cpp
opennurbs_pluginlist.cpp
opennurbs_point.cpp
opennurbs_pointcloud.cpp
opennurbs_pointgeometry.cpp
opennurbs_pointgrid.cpp
opennurbs_polycurve.cpp
opennurbs_polyedgecurve.cpp
opennurbs_polyline.cpp
opennurbs_polylinecurve.cpp
opennurbs_precompiledheader.cpp
opennurbs_quaternion.cpp
opennurbs_rand.cpp
opennurbs_revsurface.cpp
opennurbs_rtree.cpp
opennurbs_sort.cpp
opennurbs_sphere.cpp
opennurbs_string.cpp
opennurbs_sum.cpp
opennurbs_sumsurface.cpp
opennurbs_surface.cpp
opennurbs_surfaceproxy.cpp
opennurbs_textlog.cpp
opennurbs_torus.cpp
opennurbs_unicode.cpp
opennurbs_userdata.cpp
opennurbs_uuid.cpp
opennurbs_viewport.cpp
opennurbs_workspace.cpp
opennurbs_wstring.cpp
opennurbs_xform.cpp
opennurbs_zlib.cpp
opennurbs_zlib_memory.cpp
examples_linking_pragmas.h
opennurbs.h
opennurbs_3dm.h
opennurbs_3dm_attributes.h
opennurbs_3dm_properties.h
opennurbs_3dm_settings.h
opennurbs_annotation.h
opennurbs_annotation2.h
opennurbs_arc.h
opennurbs_arccurve.h
opennurbs_archive.h
opennurbs_array.h
opennurbs_array_defs.h
opennurbs_base32.h
opennurbs_base64.h
opennurbs_beam.h
opennurbs_bezier.h
opennurbs_bitmap.h
opennurbs_bounding_box.h
opennurbs_box.h
opennurbs_brep.h
opennurbs_circle.h
opennurbs_color.h
opennurbs_compress.h
opennurbs_cone.h
opennurbs_crc.h
opennurbs_curve.h
opennurbs_curveonsurface.h
opennurbs_curveproxy.h
opennurbs_cylinder.h
opennurbs_defines.h
opennurbs_detail.h
opennurbs_dimstyle.h
opennurbs_dll_resource.h
opennurbs_ellipse.h
opennurbs_error.h
opennurbs_evaluate_nurbs.h
opennurbs_extensions.h
opennurbs_font.h
opennurbs_fpoint.h
opennurbs_fsp.h
opennurbs_fsp_defs.h
opennurbs_geometry.h
opennurbs_gl.h
opennurbs_group.h
opennurbs_hatch.h
opennurbs_hsort_template.h
opennurbs_instance.h
opennurbs_intersect.h
opennurbs_knot.h
opennurbs_layer.h
opennurbs_light.h
opennurbs_line.h
opennurbs_linecurve.h
opennurbs_linestyle.h
opennurbs_linetype.h
opennurbs_lookup.h
opennurbs_mapchan.h
opennurbs_material.h
opennurbs_math.h
opennurbs_matrix.h
opennurbs_memory.h
opennurbs_mesh.h
opennurbs_nurbscurve.h
opennurbs_nurbssurface.h
opennurbs_object.h
opennurbs_object_history.h
opennurbs_objref.h
opennurbs_offsetsurface.h
opennurbs_optimize.h
opennurbs_photogrammetry.h
opennurbs_plane.h
opennurbs_planesurface.h
opennurbs_pluginlist.h
opennurbs_point.h
opennurbs_pointcloud.h
opennurbs_pointgeometry.h
opennurbs_pointgrid.h
opennurbs_polycurve.h
opennurbs_polyedgecurve.h
opennurbs_polyline.h
opennurbs_polylinecurve.h
opennurbs_qsort_template.h
opennurbs_quaternion.h
opennurbs_rand.h
opennurbs_rendering.h
opennurbs_revsurface.h
opennurbs_rtree.h
opennurbs_sphere.h
opennurbs_string.h
opennurbs_sumsurface.h
opennurbs_surface.h
opennurbs_surfaceproxy.h
opennurbs_system.h
opennurbs_textlog.h
opennurbs_texture.h
opennurbs_texture_mapping.h
opennurbs_torus.h
opennurbs_unicode.h
opennurbs_userdata.h
opennurbs_uuid.h
opennurbs_version.h
opennurbs_viewport.h
opennurbs_workspace.h
opennurbs_xform.h
opennurbs_zlib.h
)
blender_add_lib(extern_opennurbs "${SRC}" "${INC}" "${INC_SYS}")

67
extern/opennurbs/examples_linking_pragmas.h vendored Executable file
View File

@@ -0,0 +1,67 @@
#if defined(_MSC_VER)
// This file is specific to Micrsoft's compiler.
// It contains linking pragmas for building the opennurbs examples.
#pragma once
#if defined(ON_DLL_EXPORTS)
// If you get the following error, your compiler settings
// indicate you are building opennurbs as a DLL. This file
// is used for linking with opennurbs.
#error This file contains linking pragmas for using opennurbs.
#endif
#if !defined(ON_MSC_SOLUTION_DIR)
#define ON_MSC_SOLUTION_DIR ".."
#endif
#if !defined(ON_MSC_LIB_DIR)
#if defined(WIN64)
// x64 (64 bit) static libraries
#if defined(NDEBUG)
// Release x64 (64 bit) libs
#define ON_MSC_LIB_DIR "x64/Release"
#else // _DEBUG
// Debug x64 (64 bit) libs
#define ON_MSC_LIB_DIR "x64/Debug"
#endif // NDEBUG else _DEBUG
#else // WIN32
// x86 (32 bit) static libraries
#if defined(NDEBUG)
// Release x86 (32 bit) libs
#define ON_MSC_LIB_DIR "Release"
#else // _DEBUG
// Debug x86 (32 bit) libs
#define ON_MSC_LIB_DIR "Debug"
#endif // NDEBUG else _DEBUG
#endif // WIN64 else WIN32
#endif // !defined(ON_MSC_LIB_DIR)
#if defined(ON_DLL_IMPORTS)
#pragma message( " --- dynamically linking opennurbs (DLL)." )
#pragma comment(lib, "\"" ON_MSC_SOLUTION_DIR "/" ON_MSC_LIB_DIR "/" "opennurbs.lib" "\"")
#else
#pragma message( " --- statically linking opennurbs." )
#pragma comment(lib, "\"" ON_MSC_SOLUTION_DIR "/" ON_MSC_LIB_DIR "/" "zlib.lib" "\"")
#pragma comment(lib, "\"" ON_MSC_SOLUTION_DIR "/" ON_MSC_LIB_DIR "/" "opennurbs_staticlib.lib" "\"")
#endif
#endif

519
extern/opennurbs/makefile vendored Executable file
View File

@@ -0,0 +1,519 @@
###############################################################
# If your make doesn't use .cpp for C++ extensions,
# then uncomment the suffixes line.
.SUFFIXES : .c .cpp
RM = /bin/rm
# If you don't mind the risk of using the -f option and your rm
# asks too many questions, then uncomment the next line.
# RM = /bin/rm -f
AR = ar qvl
# If your system doesn't use ranlib, uncomment the "echo" define.
RANLIB = ranlib
# RANLIB = echo
###############################################################
# Gnu tools
#
# (Tested with gcc 4.2.1 on OSX 10.8.1)
#
# In order to get full wide character (UNICODE) support, you
# need to define _GNU_SOURCE
# Choose one of the following definitions for GCC_OPTIMIZER_FLAGS
# unoptimized debug build
ON_GNU_OPTIMIZER_FLAGS = -g
# optimized release build
#ON_GNU_OPTIMIZER_FLAGS = -O
# C compiler and flags
CC = gcc
CFLAGS = $(ON_GNU_OPTIMIZER_FLAGS) -Wall -D_GNU_SOURCE -DMY_ZCALLOC -DZ_PREFIX -I.
# C++ compiler and flags
CCC = g++
CCFLAGS = $(ON_GNU_OPTIMIZER_FLAGS) -Wall -D_GNU_SOURCE -I.
LINK = $(CCC)
LINKFLAGS =
###############################################################
# Irix 6.5 compiler (uncomment the lines in this block)
#
#
#OPTIMIZER = -g
#OPTIMIZER = -O3
#ABIISA = -n32 -mips3
#ABIISA = -64 -mips3
#IRIXDEF = -D_WCHAR_T_DEFINED -DON_COMPILER_IRIX -D_GNU_SOURCE
#IRIXFLAGS = -woff all -no_prelink -ptused
#CC = cc
#CFLAGS = $(OPTIMIZER) $(ABIISA) $(IRIXDEF) $(IRIXFLAGS) -DMY_ZCALLOC -DZ_PREFIX -I.
#CCC = CC
#CCFLAGS = $(OPTIMIZER) $(ABIISA) $(IRIXDEF) $(IRIXFLAGS) -I.
#LINK = $(CCC)
#LINKFLAGS =
# uncomment for 64 bit linking
#LINKFLAGS = $CCFLAGS
#
###############################################################
###############################################################
.cpp.o :
$(CCC) $(CCFLAGS) -c $*.cpp -o $*.o
# If your make doesn't have a rule for .c to .o, uncomment the
# next two lines.
#.c.o :
# $(CC) $(CFLAGS) -c $*.c -o $*.o
###############################################################
OPENNURBS_LIB_NAME = openNURBS
OPENNURBS_LIB_FILE = lib$(OPENNURBS_LIB_NAME).a
ON_INC= opennurbs.h \
opennurbs_3dm.h \
opennurbs_3dm_attributes.h \
opennurbs_3dm_properties.h \
opennurbs_3dm_settings.h \
opennurbs_annotation.h \
opennurbs_annotation2.h \
opennurbs_arc.h \
opennurbs_arccurve.h \
opennurbs_archive.h \
opennurbs_array.h \
opennurbs_array_defs.h \
opennurbs_base32.h \
opennurbs_base64.h \
opennurbs_beam.h \
opennurbs_bezier.h \
opennurbs_bitmap.h \
opennurbs_bounding_box.h \
opennurbs_box.h \
opennurbs_brep.h \
opennurbs_circle.h \
opennurbs_color.h \
opennurbs_compress.h \
opennurbs_cone.h \
opennurbs_crc.h \
opennurbs_curve.h \
opennurbs_curveonsurface.h \
opennurbs_curveproxy.h \
opennurbs_cylinder.h \
opennurbs_defines.h \
opennurbs_detail.h \
opennurbs_dimstyle.h \
opennurbs_ellipse.h \
opennurbs_error.h \
opennurbs_evaluate_nurbs.h \
opennurbs_extensions.h \
opennurbs_font.h \
opennurbs_fpoint.h \
opennurbs_fsp.h \
opennurbs_fsp_defs.h \
opennurbs_geometry.h \
opennurbs_gl.h \
opennurbs_group.h \
opennurbs_hatch.h \
opennurbs_hsort_template.h \
opennurbs_instance.h \
opennurbs_intersect.h \
opennurbs_knot.h \
opennurbs_layer.h \
opennurbs_light.h \
opennurbs_line.h \
opennurbs_linecurve.h \
opennurbs_linestyle.h \
opennurbs_linetype.h \
opennurbs_lookup.h \
opennurbs_mapchan.h \
opennurbs_material.h \
opennurbs_math.h \
opennurbs_matrix.h \
opennurbs_memory.h \
opennurbs_mesh.h \
opennurbs_nurbscurve.h \
opennurbs_nurbssurface.h \
opennurbs_object.h \
opennurbs_object_history.h \
opennurbs_objref.h \
opennurbs_offsetsurface.h \
opennurbs_optimize.h \
opennurbs_photogrammetry.h \
opennurbs_plane.h \
opennurbs_planesurface.h \
opennurbs_pluginlist.h \
opennurbs_point.h \
opennurbs_pointcloud.h \
opennurbs_pointgeometry.h \
opennurbs_pointgrid.h \
opennurbs_polycurve.h \
opennurbs_polyedgecurve.h \
opennurbs_polyline.h \
opennurbs_polylinecurve.h \
opennurbs_quaternion.h \
opennurbs_qsort_template.h \
opennurbs_rand.h \
opennurbs_rendering.h \
opennurbs_revsurface.h \
opennurbs_rtree.h \
opennurbs_sphere.h \
opennurbs_string.h \
opennurbs_sumsurface.h \
opennurbs_surface.h \
opennurbs_surfaceproxy.h \
opennurbs_system.h \
opennurbs_textlog.h \
opennurbs_texture.h \
opennurbs_texture_mapping.h \
opennurbs_torus.h \
opennurbs_unicode.h \
opennurbs_userdata.h \
opennurbs_uuid.h \
opennurbs_version.h \
opennurbs_viewport.h \
opennurbs_workspace.h \
opennurbs_xform.h \
opennurbs_zlib.h
ON_SRC= opennurbs_3dm_attributes.cpp \
opennurbs_3dm_properties.cpp \
opennurbs_3dm_settings.cpp \
opennurbs_annotation.cpp \
opennurbs_annotation2.cpp \
opennurbs_arc.cpp \
opennurbs_arccurve.cpp \
opennurbs_archive.cpp \
opennurbs_array.cpp \
opennurbs_base32.cpp \
opennurbs_base64.cpp \
opennurbs_beam.cpp \
opennurbs_bezier.cpp \
opennurbs_beziervolume.cpp \
opennurbs_bitmap.cpp \
opennurbs_bounding_box.cpp \
opennurbs_box.cpp \
opennurbs_brep.cpp \
opennurbs_brep_extrude.cpp \
opennurbs_brep_io.cpp \
opennurbs_brep_isvalid.cpp \
opennurbs_brep_region.cpp \
opennurbs_brep_tools.cpp \
opennurbs_brep_v2valid.cpp \
opennurbs_circle.cpp \
opennurbs_color.cpp \
opennurbs_compress.cpp \
opennurbs_cone.cpp \
opennurbs_crc.cpp \
opennurbs_curve.cpp \
opennurbs_curveonsurface.cpp \
opennurbs_curveproxy.cpp \
opennurbs_cylinder.cpp \
opennurbs_defines.cpp \
opennurbs_detail.cpp \
opennurbs_dimstyle.cpp \
opennurbs_ellipse.cpp \
opennurbs_embedded_file.cpp \
opennurbs_error.cpp \
opennurbs_error_message.cpp \
opennurbs_evaluate_nurbs.cpp \
opennurbs_extensions.cpp \
opennurbs_font.cpp \
opennurbs_fsp.cpp \
opennurbs_geometry.cpp \
opennurbs_group.cpp \
opennurbs_hatch.cpp \
opennurbs_instance.cpp \
opennurbs_intersect.cpp \
opennurbs_knot.cpp \
opennurbs_layer.cpp \
opennurbs_light.cpp \
opennurbs_line.cpp \
opennurbs_linecurve.cpp \
opennurbs_linetype.cpp \
opennurbs_lookup.cpp \
opennurbs_material.cpp \
opennurbs_math.cpp \
opennurbs_matrix.cpp \
opennurbs_memory.c \
opennurbs_memory_util.c \
opennurbs_mesh.cpp \
opennurbs_mesh_ngon.cpp \
opennurbs_mesh_tools.cpp \
opennurbs_morph.cpp \
opennurbs_nurbscurve.cpp \
opennurbs_nurbssurface.cpp \
opennurbs_nurbsvolume.cpp \
opennurbs_object.cpp \
opennurbs_object_history.cpp \
opennurbs_objref.cpp \
opennurbs_offsetsurface.cpp \
opennurbs_optimize.cpp \
opennurbs_photogrammetry.cpp \
opennurbs_plane.cpp \
opennurbs_planesurface.cpp \
opennurbs_pluginlist.cpp \
opennurbs_point.cpp \
opennurbs_pointcloud.cpp \
opennurbs_pointgeometry.cpp \
opennurbs_pointgrid.cpp \
opennurbs_polycurve.cpp \
opennurbs_polyedgecurve.cpp \
opennurbs_polyline.cpp \
opennurbs_polylinecurve.cpp \
opennurbs_quaternion.cpp \
opennurbs_rand.cpp \
opennurbs_revsurface.cpp \
opennurbs_rtree.cpp \
opennurbs_sort.cpp \
opennurbs_sphere.cpp \
opennurbs_string.cpp \
opennurbs_sum.cpp \
opennurbs_sumsurface.cpp \
opennurbs_surface.cpp \
opennurbs_surfaceproxy.cpp \
opennurbs_textlog.cpp \
opennurbs_torus.cpp \
opennurbs_unicode.cpp \
opennurbs_userdata.cpp \
opennurbs_uuid.cpp \
opennurbs_viewport.cpp \
opennurbs_workspace.cpp \
opennurbs_wstring.cpp \
opennurbs_xform.cpp \
opennurbs_zlib.cpp \
opennurbs_zlib_memory.cpp
ON_OBJ= opennurbs_3dm_attributes.o \
opennurbs_3dm_properties.o \
opennurbs_3dm_settings.o \
opennurbs_annotation.o \
opennurbs_annotation2.o \
opennurbs_arc.o \
opennurbs_arccurve.o \
opennurbs_archive.o \
opennurbs_array.o \
opennurbs_base32.o \
opennurbs_base64.o \
opennurbs_beam.o \
opennurbs_bezier.o \
opennurbs_beziervolume.o \
opennurbs_bitmap.o \
opennurbs_bounding_box.o \
opennurbs_box.o \
opennurbs_brep.o \
opennurbs_brep_extrude.o \
opennurbs_brep_io.o \
opennurbs_brep_isvalid.o \
opennurbs_brep_region.o \
opennurbs_brep_tools.o \
opennurbs_brep_v2valid.o \
opennurbs_circle.o \
opennurbs_color.o \
opennurbs_compress.o \
opennurbs_cone.o \
opennurbs_crc.o \
opennurbs_curve.o \
opennurbs_curveonsurface.o \
opennurbs_curveproxy.o \
opennurbs_cylinder.o \
opennurbs_defines.o \
opennurbs_detail.o \
opennurbs_dimstyle.o \
opennurbs_ellipse.o \
opennurbs_embedded_file.o \
opennurbs_error.o \
opennurbs_error_message.o \
opennurbs_evaluate_nurbs.o \
opennurbs_extensions.o \
opennurbs_font.o \
opennurbs_fsp.o \
opennurbs_geometry.o \
opennurbs_group.o \
opennurbs_hatch.o \
opennurbs_instance.o \
opennurbs_intersect.o \
opennurbs_knot.o \
opennurbs_layer.o \
opennurbs_light.o \
opennurbs_line.o \
opennurbs_linecurve.o \
opennurbs_linetype.o \
opennurbs_lookup.o \
opennurbs_material.o \
opennurbs_math.o \
opennurbs_matrix.o \
opennurbs_memory.o \
opennurbs_memory_util.o \
opennurbs_mesh.o \
opennurbs_mesh_ngon.o \
opennurbs_mesh_tools.o \
opennurbs_morph.o \
opennurbs_nurbscurve.o \
opennurbs_nurbssurface.o \
opennurbs_nurbsvolume.o \
opennurbs_object.o \
opennurbs_object_history.o \
opennurbs_objref.o \
opennurbs_offsetsurface.o \
opennurbs_optimize.o \
opennurbs_photogrammetry.o \
opennurbs_plane.o \
opennurbs_planesurface.o \
opennurbs_pluginlist.o \
opennurbs_point.o \
opennurbs_pointcloud.o \
opennurbs_pointgeometry.o \
opennurbs_pointgrid.o \
opennurbs_polycurve.o \
opennurbs_polyedgecurve.o \
opennurbs_polyline.o \
opennurbs_polylinecurve.o \
opennurbs_quaternion.o \
opennurbs_rand.o \
opennurbs_revsurface.o \
opennurbs_rtree.o \
opennurbs_sort.o \
opennurbs_sphere.o \
opennurbs_string.o \
opennurbs_sum.o \
opennurbs_sumsurface.o \
opennurbs_surface.o \
opennurbs_surfaceproxy.o \
opennurbs_textlog.o \
opennurbs_torus.o \
opennurbs_unicode.o \
opennurbs_userdata.o \
opennurbs_uuid.o \
opennurbs_viewport.o \
opennurbs_workspace.o \
opennurbs_wstring.o \
opennurbs_xform.o \
opennurbs_zlib.o \
opennurbs_zlib_memory.o
ZLIB_INC= zlib/crc32.h \
zlib/deflate.h \
zlib/inffast.h \
zlib/inffixed.h \
zlib/inflate.h \
zlib/inftrees.h \
zlib/trees.h \
zlib/zconf.h \
zlib/zlib.h \
zlib/zutil.h \
ZLIB_SRC= zlib/adler32.c \
zlib/compress.c \
zlib/crc32.c \
zlib/deflate.c \
zlib/infback.c \
zlib/inffast.c \
zlib/inflate.c \
zlib/inftrees.c \
zlib/trees.c \
zlib/uncompr.c \
zlib/zutil.c
ZLIB_OBJ= zlib/adler32.o \
zlib/compress.o \
zlib/crc32.o \
zlib/deflate.o \
zlib/infback.o \
zlib/inffast.o \
zlib/inflate.o \
zlib/inftrees.o \
zlib/trees.o \
zlib/uncompr.o \
zlib/zutil.o
EXAMPLE_OBJ = example_read/example_read.o \
example_write/example_write.o \
example_brep/example_brep.o \
example_userdata/example_ud.o \
example_userdata/example_userdata.o \
example_roundtrip/example_roundtrip.o
EXAMPLES = example_read/example_read \
example_write/example_write \
example_brep/example_brep \
example_roundtrip/example_roundtrip \
example_userdata/example_userdata
EXAMPLE_GL_OBJ = example_gl/example_gl.o \
opennurbs_gl.o
EXAMPLE_GL = example_gl/example_gl
all : $(OPENNURBS_LIB_FILE) $(EXAMPLES)
gl : $(OPENNURBS_LIB_FILE) $(EXAMPLE_GL)
opennurbs_gl.o : opennurbs_gl.h $(ON_INC)
example_userdata/example_ud.o : example_userdata/example_ud.h $(ON_INC)
$(ON_OBJ) : $(ON_INC)
$(ZLIB_OBJ) : $(ZLIB_INC)
$(OPENNURBS_LIB_FILE) : $(ON_OBJ) $(ZLIB_OBJ)
-$(RM) $@
$(AR) $@ $(ON_OBJ) $(ZLIB_OBJ)
$(RANLIB) $@
example_read/example_read : example_read/example_read.o example_userdata/example_ud.o $(OPENNURBS_LIB_FILE)
$(LINK) $(LINKFLAGS) example_read/example_read.o example_userdata/example_ud.o -L. -l$(OPENNURBS_LIB_NAME) -lm -o $@
example_write/example_write : example_write/example_write.o example_userdata/example_ud.o $(OPENNURBS_LIB_FILE)
$(LINK) $(LINKFLAGS) example_write/example_write.o example_userdata/example_ud.o -L. -l$(OPENNURBS_LIB_NAME) -lm -o $@
example_brep/example_brep : example_brep/example_brep.o $(OPENNURBS_LIB_FILE)
$(LINK) $(LINKFLAGS) example_brep/example_brep.o -L. -l$(OPENNURBS_LIB_NAME) -lm -o $@
example_userdata/example_userdata : example_userdata/example_userdata.o $(OPENNURBS_LIB_FILE)
$(LINK) $(LINKFLAGS) example_userdata/example_userdata.o -L. -l$(OPENNURBS_LIB_NAME) -lm -o $@
example_roundtrip/example_roundtrip : example_roundtrip/example_roundtrip.o $(OPENNURBS_LIB_FILE)
$(LINK) $(LINKFLAGS) example_roundtrip/example_roundtrip.o -L. -l$(OPENNURBS_LIB_NAME) -lm -o $@
LINK_GL = -lglaux -lglu -lgl
LINK_XWIN = -lXmu -lXi -lXext -lX11
$(EXAMPLE_GL) : example_gl/example_gl.o ./opennurbs_gl.o $(OPENNURBS_LIB_FILE)
$(LINK) $(LINKFLAGS) example_gl/example_gl.o ./opennurbs_gl.o -L. -l$(OPENNURBS_LIB_NAME) $(LINK_GL) $(LINK_XWIN) -lm -o $@
clean :
-$(RM) $(OPENNURBS_LIB_FILE)
-$(RM) $(ON_OBJ)
-$(RM) $(ZLIB_OBJ)
-$(RM) $(EXAMPLE_OBJ)
-$(RM) $(EXAMPLE_GL_OBJ)
-$(RM) $(EXAMPLES)
-$(RM) $(EXAMPLE_GL)

138
extern/opennurbs/opennurbs.h vendored Executable file
View File

@@ -0,0 +1,138 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
////////////////////////////////////////////////////////////////
//
// Includes all openNURBS toolkit headers required to use the
// openNURBS toolkit library. See readme.txt for details.
//
////////////////////////////////////////////////////////////////
#if !defined(OPENNURBS_INC_)
#define OPENNURBS_INC_
#define OPENNURBS_INC_IN_PROGRESS
#include "opennurbs_system.h" /* system headers used by openNURBS code */
#include "opennurbs_3dm.h" /* 3DM typecode (TCODE) definitions */
#include "opennurbs_defines.h" /* openNURBS defines and enums */
#include "opennurbs_error.h" /* error handling */
#include "opennurbs_memory.h" /* memory managment (onmalloc(), onrealloc(), onfree(), ...) */
#include "opennurbs_rand.h" /* random number generator */
#include "opennurbs_crc.h" /* cyclic redundancy check tool */
#include "opennurbs_uuid.h" /* universally unique identifiers (UUID, a.k.a, GUID) */
#include "opennurbs_unicode.h" /* unicode string conversion */
#if defined(ON_CPLUSPLUS)
#include "opennurbs_fsp.h" // fixed size memory pool
#include "opennurbs_string.h" // dynamic string classes (single and double byte)
#include "opennurbs_compress.h"
#include "opennurbs_base64.h" // base64 encodeing and decoding
#include "opennurbs_color.h" // R G B color
#include "opennurbs_linestyle.h" // line pattern, scale, and width
#include "opennurbs_point.h" // double precision 2d, 3d, 4d points and 2d, 3d vectors
#include "opennurbs_fpoint.h" // float precision 2d, 3d, 4d points and 2d, 3d vectors
#include "opennurbs_array.h" // dynamic array templates
#include "opennurbs_base32.h" // base32 encodeing and decoding
#include "opennurbs_pluginlist.h"
#include "opennurbs_bounding_box.h" // simple 3d axis aligned bounding box
#include "opennurbs_matrix.h" // general m X n matrix
#include "opennurbs_xform.h" // 4 X 4 transformation matrix
#include "opennurbs_quaternion.h" // quaternion
#include "opennurbs_workspace.h" // workspace memory allocation
#include "opennurbs_plane.h" // simple 3d plane
#include "opennurbs_circle.h" // simple 3d circle
#include "opennurbs_ellipse.h" // simple 3d ellipse
#include "opennurbs_line.h" // simple line
#include "opennurbs_polyline.h" // simple polyline
#include "opennurbs_cylinder.h" // simple 3d elliptical cylinder
#include "opennurbs_cone.h" // simple 3d right circular cone
#include "opennurbs_sphere.h" // simple 3d sphere
#include "opennurbs_box.h" // simple 3d box
#include "opennurbs_torus.h" // simple 3d torus
#include "opennurbs_bezier.h" // simple bezier and polynomial curves and surfaces
#include "opennurbs_math.h" // utilities for performing simple calculations
#include "opennurbs_intersect.h" // utilities for performing simple intersections
#include "opennurbs_optimize.h" // utilities for finding extrema and zeros
#include "opennurbs_knot.h" // utilities for working with NURBS knot vectors
#include "opennurbs_evaluate_nurbs.h" // utilities for evaluating Beziers and NURBS
#include "opennurbs_textlog.h" // text log for dumps, error logs, etc.
#include "opennurbs_zlib.h" // ON_BinaryArchive needs z_stream definition.
#include "opennurbs_rtree.h" // ON_RTree spatial search utility.
#include "opennurbs_mapchan.h"
#include "opennurbs_rendering.h"
#include "opennurbs_archive.h" // binary arcive objects for serialization to file, memory blocks, etc.
#include "opennurbs_arc.h" // simple 3d circular arc
#include "opennurbs_object.h" // virtual base class for all openNURBS objects
#include "opennurbs_userdata.h" // class for attaching persistent user information to openNURBS objects
#include "opennurbs_geometry.h" // virtual base class for geometric objects
#include "opennurbs_curve.h" // virtual parametric curve
#include "opennurbs_surface.h" // virtual parametric surface
#include "opennurbs_viewport.h" // simple renering projection
#include "opennurbs_texture_mapping.h" // texture coordinate evaluation
#include "opennurbs_texture.h" // texture definition
#include "opennurbs_material.h" // simple rendering material
#include "opennurbs_layer.h" // layer definition
#include "opennurbs_linetype.h" // linetype definition
#include "opennurbs_group.h" // group name and index
#include "opennurbs_font.h" // font name and index
#include "opennurbs_light.h" // light
#include "opennurbs_pointgeometry.h" // single point
#include "opennurbs_pointcloud.h" // point set
#include "opennurbs_curveproxy.h" // proxy curve provides a way to use an existing curve
#include "opennurbs_surfaceproxy.h" // proxy surface provides a way to use another surface
#include "opennurbs_mesh.h" // render mesh object
#include "opennurbs_pointgrid.h" // point grid object
#include "opennurbs_linecurve.h" // line as a paramtric curve object
#include "opennurbs_arccurve.h" // arc/circle as a paramtric curve object
#include "opennurbs_polylinecurve.h" // polyline as a paramtric curve object
#include "opennurbs_nurbscurve.h" // NURBS curve
#include "opennurbs_polycurve.h" // polycurve (composite curve)
#include "opennurbs_curveonsurface.h" // curve on surface (other kind of composite curve)
#include "opennurbs_nurbssurface.h" // NURBS surface
#include "opennurbs_planesurface.h" // plane surface
#include "opennurbs_revsurface.h" // surface of revolution
#include "opennurbs_sumsurface.h" // sum surface
#include "opennurbs_brep.h" // boundary rep
#include "opennurbs_beam.h" // lightweight extrusion object
#include "opennurbs_bitmap.h" // Windows and OpenGL bitmaps
#include "opennurbs_instance.h" // instance definitions and references
#include "opennurbs_3dm_properties.h"
#include "opennurbs_3dm_settings.h"
#include "opennurbs_3dm_attributes.h"
#include "opennurbs_annotation.h" // used to serialize annotation objects
#include "opennurbs_annotation2.h" // used to serialize annotation2 objects
#include "opennurbs_hatch.h" // hatch geometry definitions
#include "opennurbs_dimstyle.h" // dimstyle name and index
#include "opennurbs_hatch.h" // hatch geometry definitions
#include "opennurbs_linetype.h" // linetype pattern definitions
#include "opennurbs_objref.h" // ON_ObjRef definition
#include "opennurbs_offsetsurface.h" // ON_OffsetSurface definition
#include "opennurbs_detail.h" // ON_Detail definition
#include "opennurbs_lookup.h" // ON_SerialNumberTable
#include "opennurbs_object_history.h"
#include "opennurbs_photogrammetry.h"
#include "opennurbs_extensions.h"
#endif
#undef OPENNURBS_INC_IN_PROGRESS
#endif

528
extern/opennurbs/opennurbs_3dm.h vendored Executable file
View File

@@ -0,0 +1,528 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_THREEDM_INC_)
#define OPENNURBS_THREEDM_INC_
/* 3dm defines, structs and typedefs */
/* Typecode format 4 bytes long
x xxxxxxxxxxxxxxx,x xxx xxxx xxxx x x xx
| | | | | | |
| | | |
| | | | +--- "stuff" bit
| | | |
| | | +-- specific codes
| | |
| | +-- RESERVED - DO NOT USE (should be 0) (will be used to control CRC on/off)
| |
| +-- category:_000 0000 0000 0001 Legacy geometry TCODE_LEGACY_GEOMETRY
| _000 0000 0000 0010 openNURBS object TCODE_OPENNURBS_OBJECT
| _000 0000 0000 0100 -- RESERVED - DO NOT USE (should be 0 in any typecode) --
| _000 0000 0000 1000 -- RESERVED - DO NOT USE (should be 0 in any typecode) --
| _000 0000 0001 0000 Geometry TCODE_GEOMETRY
| _000 0000 0010 0000 Annotation
| _000 0000 0100 0000 Display Attributes TCODE_DISPLAY
| _000 0000 1000 0000 Rendering TCODE_RENDER
| _000 0001 0000 0000
| _000 0010 0000 0000 Interface TCODE_INTERFACE
| _000 0100 0000 0000 -- RESERVED - DO NOT USE (should be 0 in any typecode) --
| _000 1000 0000 0000 Tolerances TCODE_TOLERANCE
| _001 0000 0000 0000 Tables TCODE_TABLE
| _010 0000 0000 0000 Table record TCODE_TABLEREC
| _100 0000 0000 0000 User information TCODE_USER
|
+-- format: 0 - data size in header - data block follows TCODE_SHORT
1 - data in header - no data block follows
*/
/*
// The TCODE_COMMENTBLOCK is the first chunk in the file, starts 32 bytes into
// the file, and contains text information terminated with a ^Z. This ^Z and
// contents of this chunk were expanded in February 2000. Files written with
// code released earlier than this will not have the ^Z.
//
// The TCODE_ENDOFFILE is the last chunk in the file and the first 4 bytes
// of information in this chunk is an integer that contains the file length.
// This chunk was added in February 2000 and files written with code released
// earlier than this will not have this termination block.
*/
#define TCODE_COMMENTBLOCK 0x00000001
#define TCODE_ENDOFFILE 0x00007FFF
#define TCODE_ENDOFFILE_GOO 0x00007FFE /*
// this typecode is returned when
// a rogue eof marker is found
// Some v1 3dm file writers put
// these markers in a "goo".
// Simply skip these chunks and continue.
*/
#define TCODE_LEGACY_GEOMETRY 0x00010000
#define TCODE_OPENNURBS_OBJECT 0x00020000
#define TCODE_GEOMETRY 0x00100000
#define TCODE_ANNOTATION 0x00200000
#define TCODE_DISPLAY 0x00400000
#define TCODE_RENDER 0x00800000
#define TCODE_INTERFACE 0x02000000
#define TCODE_TOLERANCE 0x08000000
#define TCODE_TABLE 0x10000000
#define TCODE_TABLEREC 0x20000000
#define TCODE_USER 0x40000000
#define TCODE_SHORT 0x80000000
#define TCODE_CRC 0x8000
#define TCODE_ANONYMOUS_CHUNK (TCODE_USER | TCODE_CRC | 0x0000 )
/* The openNURBS toolkit allows users to write all openNURBS classed that are
// derived from ON_Object using using TCODE_OPENNURBS_CLASS chunks.
// In the .3dm file these TCODE_OPENNURBS_CLASS chunks are always have the
// following format.
*/
/* tables added 17 February 2000 */
#define TCODE_MATERIAL_TABLE (TCODE_TABLE | 0x0010) /* rendering materials */
#define TCODE_LAYER_TABLE (TCODE_TABLE | 0x0011) /* layers */
#define TCODE_LIGHT_TABLE (TCODE_TABLE | 0x0012) /* rendering lights */
#define TCODE_OBJECT_TABLE (TCODE_TABLE | 0x0013) /* geometry and annotation */
#define TCODE_PROPERTIES_TABLE (TCODE_TABLE | 0x0014) /* model properties:
// revision history
// notes
// preview image
*/
#define TCODE_SETTINGS_TABLE (TCODE_TABLE | 0x0015) /* file properties including,
// units, tolerancess,
// annotation defaults,
// render mesh defaults,
// current layer,
// current material,
// current color,
// named construction planes,
// named viewports,
// current viewports,
*/
#define TCODE_BITMAP_TABLE (TCODE_TABLE | 0x0016) /* embedded bitmaps */
#define TCODE_USER_TABLE (TCODE_TABLE | 0x0017) /* user table */
#define TCODE_GROUP_TABLE (TCODE_TABLE | 0x0018) /* group table */
#define TCODE_FONT_TABLE (TCODE_TABLE | 0x0019) /* annotation font table */
#define TCODE_DIMSTYLE_TABLE (TCODE_TABLE | 0x0020) /* annotation dimension style table */
#define TCODE_INSTANCE_DEFINITION_TABLE (TCODE_TABLE | 0x0021) /* instance definition table */
#define TCODE_HATCHPATTERN_TABLE (TCODE_TABLE | 0x0022) /* hatch pattern table */
#define TCODE_LINETYPE_TABLE (TCODE_TABLE | 0x0023) /* linetype table */
#define TCODE_OBSOLETE_LAYERSET_TABLE (TCODE_TABLE | 0x0024) /* obsolete layer set table */
#define TCODE_TEXTURE_MAPPING_TABLE (TCODE_TABLE | 0x0025) /* texture mappings */
#define TCODE_HISTORYRECORD_TABLE (TCODE_TABLE | 0x0026) /* history records */
#define TCODE_ENDOFTABLE 0xFFFFFFFF
/* records in properties table */
#define TCODE_PROPERTIES_REVISIONHISTORY (TCODE_TABLEREC | TCODE_CRC | 0x0021)
#define TCODE_PROPERTIES_NOTES (TCODE_TABLEREC | TCODE_CRC | 0x0022)
#define TCODE_PROPERTIES_PREVIEWIMAGE (TCODE_TABLEREC | TCODE_CRC | 0x0023)
#define TCODE_PROPERTIES_APPLICATION (TCODE_TABLEREC | TCODE_CRC | 0x0024)
#define TCODE_PROPERTIES_COMPRESSED_PREVIEWIMAGE (TCODE_TABLEREC | TCODE_CRC | 0x0025)
#define TCODE_PROPERTIES_OPENNURBS_VERSION (TCODE_TABLEREC | TCODE_SHORT | 0x0026)
/* records in settings table */
#define TCODE_SETTINGS_PLUGINLIST (TCODE_TABLEREC | TCODE_CRC | 0x0135)
#define TCODE_SETTINGS_UNITSANDTOLS (TCODE_TABLEREC | TCODE_CRC | 0x0031)
#define TCODE_SETTINGS_RENDERMESH (TCODE_TABLEREC | TCODE_CRC | 0x0032)
#define TCODE_SETTINGS_ANALYSISMESH (TCODE_TABLEREC | TCODE_CRC | 0x0033)
#define TCODE_SETTINGS_ANNOTATION (TCODE_TABLEREC | TCODE_CRC | 0x0034)
#define TCODE_SETTINGS_NAMED_CPLANE_LIST (TCODE_TABLEREC | TCODE_CRC | 0x0035)
#define TCODE_SETTINGS_NAMED_VIEW_LIST (TCODE_TABLEREC | TCODE_CRC | 0x0036)
#define TCODE_SETTINGS_VIEW_LIST (TCODE_TABLEREC | TCODE_CRC | 0x0037)
#define TCODE_SETTINGS_CURRENT_LAYER_INDEX (TCODE_TABLEREC | TCODE_SHORT | 0x0038)
#define TCODE_SETTINGS_CURRENT_MATERIAL_INDEX (TCODE_TABLEREC | TCODE_CRC | 0x0039)
#define TCODE_SETTINGS_CURRENT_COLOR (TCODE_TABLEREC | TCODE_CRC | 0x003A)
#define TCODE_SETTINGS__NEVER__USE__THIS (TCODE_TABLEREC | TCODE_CRC | 0x003E)
#define TCODE_SETTINGS_CURRENT_WIRE_DENSITY (TCODE_TABLEREC | TCODE_SHORT | 0x003C)
#define TCODE_SETTINGS_RENDER (TCODE_TABLEREC | TCODE_CRC | 0x003D)
#define TCODE_SETTINGS_GRID_DEFAULTS (TCODE_TABLEREC | TCODE_CRC | 0x003F)
#define TCODE_SETTINGS_MODEL_URL (TCODE_TABLEREC | TCODE_CRC | 0x0131)
#define TCODE_SETTINGS_CURRENT_FONT_INDEX (TCODE_TABLEREC | TCODE_SHORT | 0x0132)
#define TCODE_SETTINGS_CURRENT_DIMSTYLE_INDEX (TCODE_TABLEREC | TCODE_SHORT | 0x0133)
/* added 29 October 2002 as a chunk to hold new and future ON_3dmSettings information */
#define TCODE_SETTINGS_ATTRIBUTES (TCODE_TABLEREC | TCODE_CRC | 0x0134)
/* views are subrecords in the settings table */
#define TCODE_VIEW_RECORD (TCODE_TABLEREC | TCODE_CRC | 0x003B)
/* subrecords if view record */
#define TCODE_VIEW_CPLANE (TCODE_TABLEREC | TCODE_CRC | 0x013B)
#define TCODE_VIEW_VIEWPORT (TCODE_TABLEREC | TCODE_CRC | 0x023B)
#define TCODE_VIEW_SHOWCONGRID (TCODE_TABLEREC | TCODE_SHORT | 0x033B)
#define TCODE_VIEW_SHOWCONAXES (TCODE_TABLEREC | TCODE_SHORT | 0x043B)
#define TCODE_VIEW_SHOWWORLDAXES (TCODE_TABLEREC | TCODE_SHORT | 0x053B)
#define TCODE_VIEW_TRACEIMAGE (TCODE_TABLEREC | TCODE_CRC | 0x063B)
#define TCODE_VIEW_WALLPAPER (TCODE_TABLEREC | TCODE_CRC | 0x073B)
#define TCODE_VIEW_WALLPAPER_V3 (TCODE_TABLEREC | TCODE_CRC | 0x074B)
#define TCODE_VIEW_TARGET (TCODE_TABLEREC | TCODE_CRC | 0x083B)
#define TCODE_VIEW_DISPLAYMODE (TCODE_TABLEREC | TCODE_SHORT | 0x093B)
#define TCODE_VIEW_NAME (TCODE_TABLEREC | TCODE_CRC | 0x0A3B)
#define TCODE_VIEW_POSITION (TCODE_TABLEREC | TCODE_CRC | 0x0B3B)
/* added 29 October 2002 as a chunk to hold new and future ON_3dmView information */
#define TCODE_VIEW_ATTRIBUTES (TCODE_TABLEREC | TCODE_CRC | 0x0C3B)
/* added 27 June 2008 as a chunk to hold userdata on ON_Viewports saved in named view list */
#define TCODE_VIEW_VIEWPORT_USERDATA (TCODE_TABLEREC | TCODE_CRC | 0x0D3B)
/* records in bitmap table */
#define TCODE_BITMAP_RECORD (TCODE_TABLEREC | TCODE_CRC | 0x0090) /* bitmap table record derived from ON_Bitmap */
/* records in material table */
#define TCODE_MATERIAL_RECORD (TCODE_TABLEREC | TCODE_CRC | 0x0040) /* material table record derived from ON_Material */
/* records in layer table */
#define TCODE_LAYER_RECORD (TCODE_TABLEREC | TCODE_CRC | 0x0050) /* layer table record derived from ON_Layer */
/* records in light table */
#define TCODE_LIGHT_RECORD (TCODE_TABLEREC | TCODE_CRC | 0x0060) /* light table record derived from ON_Light */
#define TCODE_LIGHT_RECORD_ATTRIBUTES (TCODE_INTERFACE | TCODE_CRC | 0x0061) /* ON_3dmObjectAttributes chunk */
#define TCODE_LIGHT_RECORD_ATTRIBUTES_USERDATA (TCODE_INTERFACE | 0x0062) /* ON_3dmObjectAttributes userdata chunk */
#define TCODE_LIGHT_RECORD_END (TCODE_INTERFACE | TCODE_SHORT | 0x006F)
/* records in user table
Each user table entery has two top level chunks, a TCODE_USER_TABLE_UUID chunk
and a TCODE_USER_RECORD chunk.
*/
/* The TCODE_USER_TABLE_UUID chunk
contains the plug-in id and, if the archive is V5 or later
and was written by an opennurbs with version >= 200910190,
a TCODE_USER_TABLE_RECORD_HEADER chunk.
*/
#define TCODE_USER_TABLE_UUID (TCODE_TABLEREC | TCODE_CRC | 0x0080)
/* the user record header was added in 200910190 and is inside the TCODE_USER_TABLE_UUID chunk */
#define TCODE_USER_TABLE_RECORD_HEADER (TCODE_TABLEREC | TCODE_CRC | 0x0082)
/* information saved by the plug-in is in a TCODE_USER_RECORD chunk */
#define TCODE_USER_RECORD (TCODE_TABLEREC | 0x0081)
/* records in group table */
#define TCODE_GROUP_RECORD (TCODE_TABLEREC | TCODE_CRC | 0x0073)
/* records in font table */
#define TCODE_FONT_RECORD (TCODE_TABLEREC | TCODE_CRC | 0x0074)
/* records in dimension style table */
#define TCODE_DIMSTYLE_RECORD (TCODE_TABLEREC | TCODE_CRC | 0x0075)
/* records in instance definition table */
#define TCODE_INSTANCE_DEFINITION_RECORD (TCODE_TABLEREC | TCODE_CRC | 0x0076)
/* records in hatch pattern table */
#define TCODE_HATCHPATTERN_RECORD (TCODE_TABLEREC | TCODE_CRC | 0x0077)
/* records in linetye pattern table */
#define TCODE_LINETYPE_RECORD (TCODE_TABLEREC | TCODE_CRC | 0x0078)
/* OBSOLETE records in layer set table */
#define TCODE_OBSOLETE_LAYERSET_RECORD (TCODE_TABLEREC | TCODE_CRC | 0x0079)
/* records in linetye pattern table */
#define TCODE_TEXTURE_MAPPING_RECORD (TCODE_TABLEREC | TCODE_CRC | 0x007A)
/* records in history record pattern table */
#define TCODE_HISTORYRECORD_RECORD (TCODE_TABLEREC | TCODE_CRC | 0x007B)
/* records in object table */
#define TCODE_OBJECT_RECORD (TCODE_TABLEREC | TCODE_CRC | 0x0070)
#define TCODE_OBJECT_RECORD_TYPE (TCODE_INTERFACE | TCODE_SHORT | 0x0071) /* ON::object_type value */
#define TCODE_OBJECT_RECORD_ATTRIBUTES (TCODE_INTERFACE | TCODE_CRC | 0x0072) /* ON_3dmObjectAttributes chunk */
#define TCODE_OBJECT_RECORD_ATTRIBUTES_USERDATA (TCODE_INTERFACE | 0x0073) /* ON_3dmObjectAttributes userdata chunk */
#define TCODE_OBJECT_RECORD_HISTORY (TCODE_INTERFACE | TCODE_CRC | 0x0074) /* construction history */
#define TCODE_OBJECT_RECORD_HISTORY_HEADER (TCODE_INTERFACE | TCODE_CRC | 0x0075) /* construction history header*/
#define TCODE_OBJECT_RECORD_HISTORY_DATA (TCODE_INTERFACE | TCODE_CRC | 0x0076) /* construction history data */
#define TCODE_OBJECT_RECORD_END (TCODE_INTERFACE | TCODE_SHORT | 0x007F)
/*
/////////////////////////////////////////////////////////////////////////////////////
//
// TCODE_OBJECT_RECORD
// 4 byte length of entire object record
//
// TCODE_OBJECT_RECORD_TYPE required - used to quickly filter and skip unwanted objects
// 4 byte ON::object_type
//
// TCODE_OPENNURBS_CLASS
// 4 byte length
// TCODE_OPENNURBS_CLASS_UUID
// 4 byte length = 20
// value of ON_ClassId::m_uuid for this class
// 4 byte CRC
// TCODE_OPENNURBS_CLASS_DATA
// 4 byte length
// class specific data for geometry or annotation object
// 4 byte CRC
// TCODE_OPENNURBS_CLASS_USERDATA (1 chunk per piece of user data)
// 4 byte length
// 2 byte chunk version 2.1
// TCODE_OPENNURBS_CLASS_USERDATA_HEADER
// 4 byte length
// 16 byte value of ON_ClassId::m_uuid for this child class of ON_UserData
// 16 byte value of ON_UserData::m_userdata_uuid
// 4 byte value of ON_UserData::m_userdata_copycount
// 128 byte value of ON_UserData::m_userdata_xform
// 16 byte value of ON_UserData::m_application_uuid (in ver 2.1 chunks)
// TCODE_ANONYMOUS_CHUNK
// 4 byte length
// specific user data
// TCODE_OPENNURBS_CLASS_END
//
// TCODE_OBJECT_RECORD_ATTRIBUTES (optional)
// 4 byte length
// ON_3dmObjectAttributes information
// 4 byte crc
//
// TCODE_OBJECT_RECORD_ATTRIBUTES_USERDATA (optional)
// 4 byte length
// TCODE_OPENNURBS_CLASS_USERDATA (1 chunk per piece of user data)
// 4 byte length
// 2 byte chunk version 2.1
// TCODE_OPENNURBS_CLASS_USERDATA_HEADER
// 4 byte length
// 16 byte value of ON_ClassId::m_uuid for this child class of ON_UserData
// 16 byte value of ON_UserData::m_userdata_uuid
// 4 byte value of ON_UserData::m_userdata_copycount
// 128 byte value of ON_UserData::m_userdata_xform
// 16 byte value of ON_UserData::m_application_uuid (in ver 2.1 chunks)
// TCODE_ANONYMOUS_CHUNK
// 4 byte length
// specific user data
//
// TCODE_OBJECT_RECORD_HISTORY (optional) construction history
// 4 byte length
// 2 byte chunk version
// TCODE_OBJECT_RECORD_HISTORY_HEADER
// 4 byte length
// 2 byte chunk version
// ...
// 4 byte crc
// TCODE_OBJECT_RECORD_HISTORY_DATA
// 4 byte length
// 2 byte chunk version
// ...
// 4 byte crc
//
// TCODE_OBJECT_RECORD_END required - marks end of object record
//
/////////////////////////////////////////////////////////////////////////////////////
*/
#define TCODE_OPENNURBS_CLASS (TCODE_OPENNURBS_OBJECT | 0x7FFA)
#define TCODE_OPENNURBS_CLASS_UUID (TCODE_OPENNURBS_OBJECT | TCODE_CRC | 0x7FFB)
#define TCODE_OPENNURBS_CLASS_DATA (TCODE_OPENNURBS_OBJECT | TCODE_CRC | 0x7FFC)
#define TCODE_OPENNURBS_CLASS_USERDATA (TCODE_OPENNURBS_OBJECT | 0x7FFD)
#define TCODE_OPENNURBS_CLASS_USERDATA_HEADER (TCODE_OPENNURBS_OBJECT | TCODE_CRC | 0x7FF9)
#define TCODE_OPENNURBS_CLASS_END (TCODE_OPENNURBS_OBJECT | TCODE_SHORT | 0x7FFF)
/*
/////////////////////////////////////////////////////////////////////////////////////
//
// TCODE_OPENNURBS_CLASS
// length of entire openNURBS class object chunk
//
// TCODE_OPENNURBS_CLASS_UUID
// length of uuid (16 byte UUID + 4 byte CRC)
// 16 byte UUID ( a.k.a. GUID ) openNURBS class ID - determines specific openNURBS class
// 4 bytes (32 bit CRC of the UUID)
//
// TCODE_OPENNURBS_CLASS_DATA
// length of object data
// ... data that defines object
// use ON_classname::Read() to read this data and ON_classname::Write()
// to write this data
// 4 bytes (32 bit CRC of the object data)
//
// TCODE_OPENNURBS_CLASS_USERDATA ( 0 or more user data chunks)
//
// TCODE_OPENNURBS_CLASS_END
// 4 bytes = 0
//
/////////////////////////////////////////////////////////////////////////////////////
*/
/*
/////////////////////////////////////////////////////////////////////////////////////
//
//
// The TCODEs below were used in the version 1 file format and are needed so that
// the these files can be read and (optionally) written by the current OpenNURBS
// toolkit.
//
//
/////////////////////////////////////////////////////////////////////////////////////
*/
#define TCODE_ANNOTATION_SETTINGS (TCODE_ANNOTATION | 0x0001)
#define TCODE_TEXT_BLOCK (TCODE_ANNOTATION | 0x0004)
#define TCODE_ANNOTATION_LEADER (TCODE_ANNOTATION | 0x0005)
#define TCODE_LINEAR_DIMENSION (TCODE_ANNOTATION | 0x0006)
#define TCODE_ANGULAR_DIMENSION (TCODE_ANNOTATION | 0x0007)
#define TCODE_RADIAL_DIMENSION (TCODE_ANNOTATION | 0x0008)
/* old RhinoIO toolkit (pre February 2000) defines */
#define TCODE_RHINOIO_OBJECT_NURBS_CURVE (TCODE_OPENNURBS_OBJECT | 0x0008) /* old CRhinoNurbsCurve */
#define TCODE_RHINOIO_OBJECT_NURBS_SURFACE (TCODE_OPENNURBS_OBJECT | 0x0009) /* old CRhinoNurbsSurface */
#define TCODE_RHINOIO_OBJECT_BREP (TCODE_OPENNURBS_OBJECT | 0x000B) /* old CRhinoBrep */
#define TCODE_RHINOIO_OBJECT_DATA (TCODE_OPENNURBS_OBJECT | 0xFFFE) /* obsolete - don't confuse with TCODE_OPENNURBS_OBJECT_DATA */
#define TCODE_RHINOIO_OBJECT_END (TCODE_OPENNURBS_OBJECT | 0xFFFF) /* obsolete - don't confuse with TCODE_OPENNURBS_OBJECT_END */
/* OpenNURBS classes the require a unique tcode */
#define TCODE_OPENNURBS_BUFFER (TCODE_OPENNURBS_OBJECT | TCODE_CRC | 0x0100) /* chunk stores ON_Buffer classes */
/* legacy objects from Rhino 1.x */
#define TCODE_LEGACY_ASM (TCODE_LEGACY_GEOMETRY | 0x0001)
#define TCODE_LEGACY_PRT (TCODE_LEGACY_GEOMETRY | 0x0002)
#define TCODE_LEGACY_SHL (TCODE_LEGACY_GEOMETRY | 0x0003)
#define TCODE_LEGACY_FAC (TCODE_LEGACY_GEOMETRY | 0x0004)
#define TCODE_LEGACY_BND (TCODE_LEGACY_GEOMETRY | 0x0005)
#define TCODE_LEGACY_TRM (TCODE_LEGACY_GEOMETRY | 0x0006)
#define TCODE_LEGACY_SRF (TCODE_LEGACY_GEOMETRY | 0x0007)
#define TCODE_LEGACY_CRV (TCODE_LEGACY_GEOMETRY | 0x0008)
#define TCODE_LEGACY_SPL (TCODE_LEGACY_GEOMETRY | 0x0009)
#define TCODE_LEGACY_PNT (TCODE_LEGACY_GEOMETRY | 0x000A)
#define TCODE_STUFF 0x0100
#define TCODE_LEGACY_ASMSTUFF (TCODE_LEGACY_GEOMETRY | TCODE_STUFF | TCODE_LEGACY_ASM)
#define TCODE_LEGACY_PRTSTUFF (TCODE_LEGACY_GEOMETRY | TCODE_STUFF | TCODE_LEGACY_PRT)
#define TCODE_LEGACY_SHLSTUFF (TCODE_LEGACY_GEOMETRY | TCODE_STUFF | TCODE_LEGACY_SHL)
#define TCODE_LEGACY_FACSTUFF (TCODE_LEGACY_GEOMETRY | TCODE_STUFF | TCODE_LEGACY_FAC)
#define TCODE_LEGACY_BNDSTUFF (TCODE_LEGACY_GEOMETRY | TCODE_STUFF | TCODE_LEGACY_BND)
#define TCODE_LEGACY_TRMSTUFF (TCODE_LEGACY_GEOMETRY | TCODE_STUFF | TCODE_LEGACY_TRM)
#define TCODE_LEGACY_SRFSTUFF (TCODE_LEGACY_GEOMETRY | TCODE_STUFF | TCODE_LEGACY_SRF)
#define TCODE_LEGACY_CRVSTUFF (TCODE_LEGACY_GEOMETRY | TCODE_STUFF | TCODE_LEGACY_CRV)
#define TCODE_LEGACY_SPLSTUFF (TCODE_LEGACY_GEOMETRY | TCODE_STUFF | TCODE_LEGACY_SPL)
#define TCODE_LEGACY_PNTSTUFF (TCODE_LEGACY_GEOMETRY | TCODE_STUFF | TCODE_LEGACY_PNT)
/* legacy objects from Rhino 1.x */
#define TCODE_RH_POINT (TCODE_GEOMETRY | 0x0001)
#define TCODE_RH_SPOTLIGHT (TCODE_RENDER | 0x0001)
#define TCODE_OLD_RH_TRIMESH (TCODE_GEOMETRY | 0x0011)
#define TCODE_OLD_MESH_VERTEX_NORMALS (TCODE_GEOMETRY | 0x0012)
#define TCODE_OLD_MESH_UV (TCODE_GEOMETRY | 0x0013)
#define TCODE_OLD_FULLMESH (TCODE_GEOMETRY | 0x0014)
#define TCODE_MESH_OBJECT (TCODE_GEOMETRY | 0x0015)
#define TCODE_COMPRESSED_MESH_GEOMETRY (TCODE_GEOMETRY | 0x0017)
#define TCODE_ANALYSIS_MESH (TCODE_GEOMETRY | 0x0018)
#define TCODE_NAME (TCODE_INTERFACE | 0x0001)
#define TCODE_VIEW (TCODE_INTERFACE | 0x0002)
#define TCODE_CPLANE (TCODE_INTERFACE | 0x0003)
#define TCODE_NAMED_CPLANE (TCODE_INTERFACE | 0x0004)
#define TCODE_NAMED_VIEW (TCODE_INTERFACE | 0x0005)
#define TCODE_VIEWPORT (TCODE_INTERFACE | 0x0006)
#define TCODE_SHOWGRID (TCODE_SHORT | TCODE_INTERFACE | 0x0007)
#define TCODE_SHOWGRIDAXES (TCODE_SHORT | TCODE_INTERFACE | 0x0008)
#define TCODE_SHOWWORLDAXES (TCODE_SHORT | TCODE_INTERFACE | 0x0009)
#define TCODE_VIEWPORT_POSITION (TCODE_INTERFACE | 0x000A)
#define TCODE_VIEWPORT_TRACEINFO (TCODE_INTERFACE | 0x000B)
#define TCODE_SNAPSIZE (TCODE_INTERFACE | 0x000C)
#define TCODE_NEAR_CLIP_PLANE (TCODE_INTERFACE | 0x000D)
#define TCODE_HIDE_TRACE (TCODE_INTERFACE | 0x000E)
#define TCODE_NOTES (TCODE_INTERFACE | 0x000F)
#define TCODE_UNIT_AND_TOLERANCES (TCODE_INTERFACE | 0x0010)
#define TCODE_MAXIMIZED_VIEWPORT (TCODE_SHORT | TCODE_INTERFACE | 0x0011)
#define TCODE_VIEWPORT_WALLPAPER (TCODE_INTERFACE | 0x0012)
#define TCODE_SUMMARY (TCODE_INTERFACE | 0x0013)
#define TCODE_BITMAPPREVIEW (TCODE_INTERFACE | 0x0014)
#define TCODE_VIEWPORT_DISPLAY_MODE (TCODE_SHORT | TCODE_INTERFACE | 0x0015)
#define TCODE_LAYERTABLE (TCODE_SHORT | TCODE_TABLE | 0x0001) /* obsolete - do not use */
#define TCODE_LAYERREF (TCODE_SHORT | TCODE_TABLEREC | 0x0001)
#define TCODE_XDATA (TCODE_USER | 0x0001)
#define TCODE_RGB (TCODE_SHORT | TCODE_DISPLAY | 0x0001)
#define TCODE_TEXTUREMAP (TCODE_DISPLAY | 0x0002)
#define TCODE_BUMPMAP (TCODE_DISPLAY | 0x0003)
#define TCODE_TRANSPARENCY (TCODE_SHORT | TCODE_DISPLAY | 0x0004)
#define TCODE_DISP_AM_RESOLUTION (TCODE_SHORT | TCODE_DISPLAY | 0x0005)
#define TCODE_RGBDISPLAY (TCODE_SHORT | TCODE_DISPLAY | 0x0006) /* will be used for color by object */
#define TCODE_RENDER_MATERIAL_ID (TCODE_DISPLAY | 0x0007) /* id for render material */
#define TCODE_LAYER (TCODE_DISPLAY | 0x0010)
/* obsolete layer typecodes from earlier betas - not used anymore */
#define TCODE_LAYER_OBSELETE_1 (TCODE_SHORT | TCODE_DISPLAY | 0x0013)
#define TCODE_LAYER_OBSELETE_2 (TCODE_SHORT | TCODE_DISPLAY | 0x0014)
#define TCODE_LAYER_OBSELETE_3 (TCODE_SHORT | TCODE_DISPLAY | 0x0015)
/* these were only ever used by AccuModel and never by Rhino */
#define TCODE_LAYERON (TCODE_SHORT | TCODE_DISPLAY | 0x0016)
#define TCODE_LAYERTHAWED (TCODE_SHORT | TCODE_DISPLAY | 0x0017)
#define TCODE_LAYERLOCKED (TCODE_SHORT | TCODE_DISPLAY | 0x0018)
#define TCODE_LAYERVISIBLE (TCODE_SHORT | TCODE_DISPLAY | 0x0012)
#define TCODE_LAYERPICKABLE (TCODE_SHORT | TCODE_DISPLAY | 0x0030)
#define TCODE_LAYERSNAPABLE (TCODE_SHORT | TCODE_DISPLAY | 0x0031)
#define TCODE_LAYERRENDERABLE (TCODE_SHORT | TCODE_DISPLAY | 0x0032)
/* use LAYERSTATE ( 0 = LAYER_ON, 1 = LAYER_OFF, 2 = LAYER_LOCKED ) instead of above individual toggles */
#define TCODE_LAYERSTATE (TCODE_SHORT | TCODE_DISPLAY | 0x0033)
#define TCODE_LAYERINDEX (TCODE_SHORT | TCODE_DISPLAY | 0x0034)
#define TCODE_LAYERMATERIALINDEX (TCODE_SHORT | TCODE_DISPLAY | 0x0035)
#define TCODE_RENDERMESHPARAMS (TCODE_DISPLAY | 0x0020) /* block of parameters for render meshes */
#define TCODE_DISP_CPLINES (TCODE_SHORT | TCODE_DISPLAY | 0x0022)
#define TCODE_DISP_MAXLENGTH (TCODE_DISPLAY | 0x0023)
#define TCODE_CURRENTLAYER (TCODE_SHORT | TCODE_DISPLAY | 0x0025 )
#define TCODE_LAYERNAME (TCODE_DISPLAY | 0x0011)
#define TCODE_LEGACY_TOL_FIT (TCODE_TOLERANCE | 0x0001)
#define TCODE_LEGACY_TOL_ANGLE (TCODE_TOLERANCE | 0x0002)
#define TCODE_DICTIONARY (TCODE_USER | TCODE_CRC | 0x0010)
#define TCODE_DICTIONARY_ID (TCODE_USER | TCODE_CRC | 0x0011)
#define TCODE_DICTIONARY_ENTRY (TCODE_USER | TCODE_CRC | 0x0012)
#define TCODE_DICTIONARY_END (TCODE_USER | TCODE_SHORT | 0x0013)
#endif

1528
extern/opennurbs/opennurbs_3dm_attributes.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

573
extern/opennurbs/opennurbs_3dm_attributes.h vendored Executable file
View File

@@ -0,0 +1,573 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
////////////////////////////////////////////////////////////////
//
// defines ON_3dmObjectAttributes
//
////////////////////////////////////////////////////////////////
#if !defined(OPENNURBS_3DM_ATTRIBUTES_INC_)
#define OPENNURBS_3DM_ATTRIBUTES_INC_
/*
Description:
Top level OpenNURBS objects have geometry and attributes. The
geometry is stored in some class derived from ON_Geometry and
the attributes are stored in an ON_3dmObjectAttributes class.
Examples of attributes are object name, object id, display
attributes, group membership, layer membership, and so on.
Remarks:
7 January 2003 Dale Lear
Derived from ON_Object so ON_UserData can be attached
to ON_3dmObjectAttributes.
*/
class ON_CLASS ON_3dmObjectAttributes : public ON_Object
{
ON_OBJECT_DECLARE(ON_3dmObjectAttributes);
public:
// ON_Object virtual interface. See ON_Object
// for details.
// virtual
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
// virtual
void Dump( ON_TextLog& ) const;
// virtual
unsigned int SizeOf() const;
// virtual
ON_BOOL32 Write(ON_BinaryArchive&) const;
// virtual
ON_BOOL32 Read(ON_BinaryArchive&);
/*
Returns:
True if successful.
(xform is invertable or didn't need to be).
*/
bool Transform( const ON_Xform& xform );
// attributes of geometry and dimension table objects
public:
ON_3dmObjectAttributes();
~ON_3dmObjectAttributes();
// Default C++ copy constructor and operator= work fine
// Do not provide custom versions
// NO // ON_3dmObjectAttributes(const ON_3dmObjectAttributes&);
// NO // ON_3dmObjectAttributes& operator=(const ON_3dmObjectAttributes&);
bool operator==(const ON_3dmObjectAttributes&) const;
bool operator!=(const ON_3dmObjectAttributes&) const;
// Initializes all attributes to the default values.
void Default();
// Interface ////////////////////////////////////////////////////////
// An OpenNURBS object must be in one of three modes: normal, locked
// or hidden. If an object is in normal mode, then the object's layer
// controls visibility and selectability. If an object is locked, then
// the object's layer controls visibility by the object cannot be selected.
// If the object is hidden, it is not visible and it cannot be selected.
ON::object_mode Mode() const;
void SetMode( ON::object_mode ); // See Mode().
/*
Description:
Use this query to determine if an object is part of an
instance definition.
Returns:
True if the object is part of an instance definition.
*/
bool IsInstanceDefinitionObject() const;
/*
Returns:
Returns true if object is visible.
See Also:
ON_3dmObjectAttributes::SetVisible
*/
bool IsVisible() const;
/*
Description:
Controls object visibility
Parameters:
bVisible - [in] true to make object visible,
false to make object invisible
See Also:
ON_3dmObjectAttributes::IsVisible
*/
void SetVisible( bool bVisible );
// The Linetype used to display an OpenNURBS object is specified in one of two ways.
// If LinetypeSource() is ON::linetype_from_layer, then the object's layer
// ON_Layer::Linetype() is used.
// If LinetypeSource() is ON::linetype_from_object, then value of m_linetype is used.
ON::object_linetype_source LinetypeSource() const;
void SetLinetypeSource( ON::object_linetype_source ); // See LinetypeSource().
// The color used to display an OpenNURBS object is specified in one of three ways.
// If ColorSource() is ON::color_from_layer, then the object's layer
// ON_Layer::Color() is used.
// If ColorSource() is ON::color_from_object, then value of m_color is used.
// If ColorSource() is ON::color_from_material, then the diffuse color of the object's
// render material is used. See ON_3dmObjectAttributes::MaterialSource() to
// determine where to get the definition of the object's render material.
ON::object_color_source ColorSource() const;
void SetColorSource( ON::object_color_source ); // See ColorSource().
// The color used to plot an OpenNURBS object on paper is specified
// in one of three ways.
// If PlotColorSource() is ON::plot_color_from_layer, then the object's layer
// ON_Layer::PlotColor() is used.
// If PlotColorSource() is ON::plot_color_from_object, then value of PlotColor() is used.
ON::plot_color_source PlotColorSource() const;
void SetPlotColorSource( ON::plot_color_source ); // See PlotColorSource().
ON::plot_weight_source PlotWeightSource() const;
void SetPlotWeightSource( ON::plot_weight_source );
// OpenNURBS objects can be displayed in one of three ways: wireframe,
// shaded, or render preview. If the display mode is ON::default_display,
// then the display mode of the viewport detrmines how the object
// is displayed. If the display mode is ON::wireframe_display,
// ON::shaded_display, or ON::renderpreview_display, then the object is
// forced to display in that mode.
ON::display_mode DisplayMode() const;
void SetDisplayMode( ON::display_mode ); // See DisplayMode().
/*
Description:
If "this" has attributes (color, plot weight, ...) with
"by parent" sources, then the values of those attributes
on parent_attributes are copied.
Parameters:
parent_attributes - [in]
parent_layer - [in]
control_limits - [in]
The bits in control_limits determine which attributes may
may be copied.
1: visibility
2: color
4: render material
8: plot color
0x10: plot weight
0x20: linetype
0x40: display order
Returns:
The bits in the returned integer indicate which attributes were
actually modified.
1: visibility
2: color
4: render material
8: plot color
0x10: plot weight
0x20: linetype
0x40: display order
*/
ON_DEPRECATED unsigned int ApplyParentalControl(
const ON_3dmObjectAttributes& parent_attributes,
unsigned int control_limits = 0xFFFFFFFF
);
unsigned int ApplyParentalControl(
const ON_3dmObjectAttributes& parent_attributes,
const ON_Layer& parent_layer,
unsigned int control_limits = 0xFFFFFFFF
);
// Every OpenNURBS object has a UUID (universally unique identifier). The
// default value is NULL. When an OpenNURBS object is added to a model, the
// value is checked. If the value is NULL, a new UUID is created. If the
// value is not NULL but it is already used by another object in the model,
// a new UUID is created. If the value is not NULL and it is not used by
// another object in the model, then that value persists. When an object
// is updated, by a move for example, the value of m_uuid persists.
ON_UUID m_uuid;
// OpenNURBS object have optional text names. More than one object in
// a model can have the same name and some objects may have no name.
ON_wString m_name;
// OpenNURBS objects may have an URL. There are no restrictions on what
// value this URL may have. As an example, if the object came from a
// commercial part library, the URL might point to the definition of that
// part.
ON_wString m_url;
// Layer definitions in an OpenNURBS model are stored in a layer table.
// The layer table is conceptually an array of ON_Layer classes. Every
// OpenNURBS object in a model is on some layer. The object's layer
// is specified by zero based indicies into the ON_Layer array.
int m_layer_index;
// Linetype definitions in an OpenNURBS model are stored in a linetype table.
// The linetype table is conceptually an array of ON_Linetype classes. Every
// OpenNURBS object in a model references some linetype. The object's linetype
// is specified by zero based indicies into the ON_Linetype array.
// index 0 is reserved for continuous linetype (no pattern)
int m_linetype_index;
// Rendering material:
// If you want something simple and fast, set
// m_material_index to the index of the rendering material
// and ignore m_rendering_attributes.
// If you are developing a high quality plug-in renderer,
// and a user is assigning one of your fabulous rendering
// materials to this object, then add rendering material
// information to the m_rendering_attributes.m_materials[]
// array.
//
// Developers:
// As soon as m_rendering_attributes.m_materials[] is not empty,
// rendering material queries slow down. Do not populate
// m_rendering_attributes.m_materials[] when setting
// m_material_index will take care of your needs.
int m_material_index;
ON_ObjectRenderingAttributes m_rendering_attributes;
//////////////////////////////////////////////////////////////////
//
// BEGIN: Per object mesh parameter support
//
/*
Parameters:
mp - [in]
per object mesh parameters
Returns:
True if successful.
*/
bool SetCustomRenderMeshParameters(const class ON_MeshParameters& mp);
/*
Parameters:
bEnable - [in]
true to enable use of the per object mesh parameters.
false to disable use of the per object mesh parameters.
Returns:
False if the object doe not have per object mesh parameters
and bEnable was true. Use SetMeshParameters() to set
per object mesh parameters.
Remarks:
Sets the value of ON_MeshParameters::m_bCustomSettingsDisabled
to !bEnable
*/
bool EnableCustomRenderMeshParameters(bool bEnable);
/*
Returns:
Null or a pointer to fragile mesh parameters.
If a non-null pointer is returned, copy it and use the copy.
* DO NOT SAVE THIS POINTER FOR LATER USE. A call to
DeleteMeshParameters() will delete the class.
* DO NOT const_cast the returned pointer and change its
settings. You must use either SetMeshParameters()
or EnableMeshParameters() to change settings.
Remarks:
If the value of ON_MeshParameters::m_bCustomSettingsDisabled is
true, then do no use these parameters to make a render mesh.
*/
const ON_MeshParameters* CustomRenderMeshParameters() const;
/*
Description:
Deletes any per object mesh parameters.
*/
void DeleteCustomRenderMeshParameters();
//
// END: Per object mesh parameter support
//
//////////////////////////////////////////////////////////////////
/*
Description:
Determine if the simple material should come from
the object or from it's layer.
High quality rendering plug-ins should use m_rendering_attributes.
Returns:
Where to get material information if you do are too lazy
to look in m_rendering_attributes.m_materials[].
*/
ON::object_material_source MaterialSource() const;
/*
Description:
Specifies if the simple material should be the one
indicated by the material index or the one indicated
by the object's layer.
Parameters:
ms - [in]
*/
void SetMaterialSource( ON::object_material_source ms );
// If ON::color_from_object == ColorSource(), then m_color is the object's
// display color.
ON_Color m_color;
// If ON::plot_color_from_object == PlotColorSource(), then m_color is the object's
// display color.
ON_Color m_plot_color;
// Display order used to force objects to be drawn on top or behind each other
// 0 = draw object in standard depth buffered order
// <0 = draw object behind "normal" draw order objects
// >0 = draw object on top of "noraml" draw order objects
// Larger number draws on top of smaller number.
int m_display_order;
// Plot weight in millimeters.
// =0.0 means use the default width
// <0.0 means don't plot (visible for screen display, but does not show on plot)
double m_plot_weight_mm;
// Used to indicate an object has a decoration (like an arrowhead on a curve)
ON::object_decoration m_object_decoration;
// When a surface object is displayed in wireframe, m_wire_density controls
// how many isoparametric wires are used.
//
// @table
// value number of isoparametric wires
// -1 boundary wires
// 0 boundary and knot wires
// 1 boundary and knot wires and, if there are no
// interior knots, a single interior wire.
// N>=2 boundary and knot wires and (N-1) interior wires
int m_wire_density;
// If m_viewport_id is nil, the object is active in
// all viewports. If m_viewport_id is not nil, then
// this object is only active in a specific view.
// This field is primarily used to assign page space
// objects to a specific page, but it can also be used
// to restrict model space to a specific view.
ON_UUID m_viewport_id;
// Starting with V4, objects can be in either model space
// or page space. If an object is in page space, then
// m_viewport_id is not nil and identifies the page it
// is on.
ON::active_space m_space;
private:
bool m_bVisible;
unsigned char m_mode; // (m_mode % 16) = ON::object_mode values
// (m_mode / 16) = ON::display_mode values
unsigned char m_color_source; // ON::object_color_source values
unsigned char m_plot_color_source; // ON::plot_color_source values
unsigned char m_plot_weight_source; // ON::plot_weight_source values
unsigned char m_material_source; // ON::object_material_source values
unsigned char m_linetype_source; // ON::object_linetype_source values
unsigned char m_reserved_0;
ON_SimpleArray<int> m_group; // array of zero based group indices
public:
// group interface
// returns number of groups object belongs to
int GroupCount() const;
// Returns and array an array of GroupCount() zero based
// group indices. If GroupCount() is zero, then GroupList()
// returns NULL.
const int* GroupList() const;
// Returns GroupCount() and puts a list of zero based group indices
// into the array.
int GetGroupList(ON_SimpleArray<int>&) const;
// Returns the index of the last group in the group list
// or -1 if the object is not in any groups
int TopGroup() const;
// Returns true if object is in group with the specified index
ON_BOOL32 IsInGroup(
int // zero based group index
) const;
// Returns true if the object is in any of the groups in the list
ON_BOOL32 IsInGroups(
int, // group_list_count
const int* // group_list[] array
) const;
// Returns true if object is in any of the groups in the list
ON_BOOL32 IsInGroups(
const ON_SimpleArray<int>& // group_list[] array
) const;
// Adds object to the group with specified index by appending index to
// group list (If the object is already in group, nothing is changed.)
void AddToGroup(
int // zero based group index
);
// Removes object from the group with specified index. If the
// object is not in the group, nothing is changed.
void RemoveFromGroup(
int // zero based group index
);
// removes the object from the last group in the group list
void RemoveFromTopGroup();
// Removes object from all groups.
void RemoveFromAllGroups();
// display material references
/*
Description:
Searches for a matching display material. For a given
viewport id, there is at most one display material.
For a given display material id, there can be multiple
viewports. If there is a display reference in the
list with a nil viewport id, then the display material
will be used in all viewports that are not explictly
referenced in other ON_DisplayMaterialRefs.
Parameters:
search_material - [in]
found_material - [out]
If FindDisplayMaterialRef(), the input value of search_material
is never changed. If FindDisplayMaterialRef() returns true,
the chart shows the output value of display_material. When
there are multiple possibilities for a match, the matches
at the top of the chart have higher priority.
search_material found_material
input value output value
(nil,nil) (nil,did) if (nil,did) is in the list.
(nil,did) (vid,did) if (vid,did) is in the list.
(nil,did) (nil,did) if (nil,did) is in the list.
(vid,nil) (vid,did) if (vid,did) is in the list
(vid,nil) (vid,did) if (nil,did) is in the list
(vid,did) (vid,did) if (vid,did) is in the list.
Example:
ON_UUID display_material_id = ON_nil_uuid;
ON_Viewport vp = ...;
ON_DisplayMaterialRef search_dm;
search_dm.m_viewport_id = vp.ViewportId();
ON_DisplayMaterialRef found_dm;
if ( attributes.FindDisplayMaterial(search_dm, &found_dm) )
{
display_material_id = found_dm.m_display_material_id;
}
Returns:
True if a matching display material is found.
See Also:
ON_3dmObjectAttributes::AddDisplayMaterialRef
ON_3dmObjectAttributes::RemoveDisplayMaterialRef
*/
bool FindDisplayMaterialRef(
const ON_DisplayMaterialRef& search_material,
ON_DisplayMaterialRef* found_material = NULL
) const;
/*
Description:
Quick way to see if a viewport has a special material.
Parameters:
viewport_id - [in]
display_material_id - [out]
Returns:
True if a material_id is assigned.
*/
bool FindDisplayMaterialId(
const ON_UUID& viewport_id,
ON_UUID* display_material_id = NULL
) const;
/*
Description:
Add a display material reference to the attributes. If
there is an existing entry with a matching viewport id,
the existing entry is replaced.
Parameters:
display_material - [in]
Returns:
True if input is valid (material id != nil)
See Also:
ON_3dmObjectAttributes::FindDisplayMaterialRef
ON_3dmObjectAttributes::RemoveDisplayMaterialRef
*/
bool AddDisplayMaterialRef(
ON_DisplayMaterialRef display_material
);
/*
Description:
Remove a display material reference from the list.
Parameters:
viewport_id - [in] Any display material references
with this viewport id will be removed. If nil,
then viewport_id is ignored.
display_material_id - [in]
Any display material references that match the
viewport_id and have this display_material_id
will be removed. If nil, then display_material_id
is ignored.
Returns:
True if a display material reference was removed.
See Also:
ON_3dmObjectAttributes::FindDisplayMaterialRef
ON_3dmObjectAttributes::AddDisplayMaterialRef
*/
bool RemoveDisplayMaterialRef(
ON_UUID viewport_id,
ON_UUID display_material_id = ON_nil_uuid
);
/*
Description:
Remove a the entire display material reference list.
*/
void RemoveAllDisplayMaterialRefs();
/*
Returns:
Number of diplay material refences.
*/
int DisplayMaterialRefCount() const;
ON_SimpleArray<ON_DisplayMaterialRef> m_dmref;
private:
bool WriteV5Helper( ON_BinaryArchive& file ) const;
bool ReadV5Helper( ON_BinaryArchive& file );
};
#endif

598
extern/opennurbs/opennurbs_3dm_properties.cpp vendored Executable file
View File

@@ -0,0 +1,598 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_3dmRevisionHistory
//
ON_3dmRevisionHistory::ON_3dmRevisionHistory() : m_revision_count(0)
{
Default();
}
ON_3dmRevisionHistory::~ON_3dmRevisionHistory()
{
m_sCreatedBy.Destroy();
m_sLastEditedBy.Destroy();
}
void ON_3dmRevisionHistory::Default()
{
m_sCreatedBy.Destroy();
m_sLastEditedBy.Destroy();
memset( &m_create_time, 0, sizeof(m_create_time) );
memset( &m_last_edit_time, 0, sizeof(m_last_edit_time) );
m_revision_count = 0;
}
static int ON_CompareRevisionHistoryTime( const struct tm* time0, const struct tm* time1 )
{
if ( 0 == time0 || 0 == time1 )
{
if ( 0 != time0 )
return 1;
if ( 0 != time1 )
return -1;
return 0;
}
if (time0->tm_year < time1->tm_year)
return -1;
if (time0->tm_year > time1->tm_year)
return 1;
if (time0->tm_mon < time1->tm_mon)
return -1;
if (time0->tm_mon > time1->tm_mon)
return 1;
if (time0->tm_mday < time1->tm_mday)
return -1;
if (time0->tm_mday > time1->tm_mday)
return 1;
if (time0->tm_hour < time1->tm_hour)
return -1;
if (time0->tm_hour > time1->tm_hour)
return 1;
if (time0->tm_min < time1->tm_min)
return -1;
if (time0->tm_min > time1->tm_min)
return 1;
if (time0->tm_sec < time1->tm_sec)
return -1;
if (time0->tm_sec > time1->tm_sec)
return 1;
return 0;
}
bool ON_3dmRevisionHistory::CreateTimeIsSet() const
{
struct tm jan_1_1970;
memset(&jan_1_1970,0,sizeof(jan_1_1970));
jan_1_1970.tm_mday = 1; /* day of the month - [1,31] */
jan_1_1970.tm_year = 70; /* years since 1900 */
return ( ON_CompareRevisionHistoryTime(&jan_1_1970,&m_create_time) >= 0 );
}
/*
Returns:
true
if m_last_edit_time is >= January 1, 1970
*/
bool ON_3dmRevisionHistory::LastEditedTimeIsSet() const
{
struct tm jan_1_1970;
memset(&jan_1_1970,0,sizeof(jan_1_1970));
jan_1_1970.tm_mday = 1; /* day of the month - [1,31] */
jan_1_1970.tm_year = 70; /* years since 1900 */
return ( ON_CompareRevisionHistoryTime(&jan_1_1970,&m_last_edit_time) <= 0 );
}
ON_BOOL32 ON_3dmRevisionHistory::IsValid() const
{
return ( LastEditedTimeIsSet()
&& ON_CompareRevisionHistoryTime(&m_create_time, &m_last_edit_time) <= 0
);
}
int ON_3dmRevisionHistory::NewRevision()
{
struct tm current_time;
memset(&current_time,0,sizeof(current_time));
{
time_t gmt = time(0);
const struct tm* t = gmtime(&gmt);
if ( t )
current_time = *t;
}
m_last_edit_time = current_time;
#if defined(ON_OS_WINDOWS)
// use Windows ::GetUserNameW() to get current user name
wchar_t current_user[512];
memset( current_user, 0, sizeof(current_user) );
ULONG len = 510;
if( !::GetUserNameW(current_user,&len) )
current_user[0] = 0;
m_sLastEditedBy = current_user;
#endif
if ( m_revision_count <= 0 )
{
m_revision_count = 0;
m_sCreatedBy = m_sLastEditedBy;
m_create_time = current_time;
};
m_revision_count++;
return m_revision_count;
}
ON_BOOL32 ON_3dmRevisionHistory::Write( ON_BinaryArchive& file ) const
{
ON_BOOL32 rc = file.Write3dmChunkVersion( 1, 0 );
if (rc) rc = file.WriteString( m_sCreatedBy );
if (rc) rc = file.WriteTime( m_create_time );
if (rc) rc = file.WriteString( m_sLastEditedBy );
if (rc) rc = file.WriteTime(m_last_edit_time );
if (rc) rc = file.WriteInt( m_revision_count );
return rc;
}
ON_BOOL32 ON_3dmRevisionHistory::Read( ON_BinaryArchive& file )
{
Default();
int major_version = 0;
int minor_version = 0;
ON_BOOL32 rc = file.Read3dmChunkVersion( &major_version, &minor_version );
if ( rc && major_version == 1 ) {
rc = file.ReadString( m_sCreatedBy );
if (rc) rc = file.ReadTime( m_create_time );
if (rc) rc = file.ReadString( m_sLastEditedBy );
if (rc) rc = file.ReadTime(m_last_edit_time );
if (rc) rc = file.ReadInt( &m_revision_count );
}
return rc;
}
void ON_3dmRevisionHistory::Dump( ON_TextLog& dump ) const
{
const wchar_t* ws = m_sCreatedBy;
if ( !ws ) ws = L"";
dump.Print("Created by: %ls\n", ws );
dump.Print("Created on: "); dump.PrintTime(m_create_time); dump.Print("\n");
ws = m_sLastEditedBy;
if ( !ws ) ws = L"";
dump.Print("Last edited by: %ls\n", ws );
dump.Print("Last edited on: "); dump.PrintTime(m_last_edit_time); dump.Print("\n");
dump.Print("Revision count: %d\n",m_revision_count);
}
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_3dmNotes
//
ON_3dmNotes::ON_3dmNotes()
: m_bVisible(0),
m_bHTML(0),
m_window_left(0),
m_window_top(0),
m_window_right(0),
m_window_bottom(0)
{}
ON_3dmNotes::ON_3dmNotes( const ON_3dmNotes& src )
: m_bVisible(0),
m_bHTML(0),
m_window_left(0),
m_window_top(0),
m_window_right(0),
m_window_bottom(0)
{
*this = src;
}
ON_3dmNotes::~ON_3dmNotes()
{
m_notes.Destroy();
}
ON_3dmNotes& ON_3dmNotes::operator=(const ON_3dmNotes& src)
{
if ( this != &src ) {
m_notes = src.m_notes;
m_bVisible = src.m_bVisible;
m_bHTML = src.m_bHTML;
m_window_left = src.m_window_left;
m_window_top = src.m_window_top;
m_window_right = src.m_window_right;
m_window_bottom = src.m_window_bottom;
}
return *this;
}
void ON_3dmNotes::Default()
{
m_notes.Destroy();
m_bVisible = 0;
m_bHTML = 0;
m_window_left = 0;
m_window_top = 0;
m_window_right = 0;
m_window_bottom = 0;
}
ON_BOOL32 ON_3dmNotes::IsValid() const
{
return m_notes.IsEmpty() ? false : true;
}
ON_BOOL32 ON_3dmNotes::Read( ON_BinaryArchive& file )
{
Default();
int major_version = 0;
int minor_version = 0;
ON_BOOL32 rc = file.Read3dmChunkVersion( &major_version, &minor_version );
if ( rc && major_version == 1 ) {
m_notes.Destroy();
rc = file.ReadInt( &m_bHTML );
if ( rc ) rc = file.ReadString( m_notes );
if ( rc ) rc = file.ReadInt( &m_bVisible );
if ( rc ) rc = file.ReadInt( &m_window_left );
if ( rc ) rc = file.ReadInt( &m_window_top );
if ( rc ) rc = file.ReadInt( &m_window_right );
if ( rc ) rc = file.ReadInt( &m_window_bottom );
}
return rc;
}
ON_BOOL32 ON_3dmNotes::Write( ON_BinaryArchive& file ) const
{
ON_BOOL32 rc = file.Write3dmChunkVersion(1,0);
if ( rc ) rc = file.WriteInt( m_bHTML );
if ( rc ) rc = file.WriteString( m_notes );
if ( rc ) rc = file.WriteInt( m_bVisible );
if ( rc ) rc = file.WriteInt( m_window_left );
if ( rc ) rc = file.WriteInt( m_window_top );
if ( rc ) rc = file.WriteInt( m_window_right );
if ( rc ) rc = file.WriteInt( m_window_bottom );
return rc;
}
void ON_3dmNotes::Dump(ON_TextLog& dump) const
{
const wchar_t* s = m_notes;
if ( s )
dump.PrintWrappedText(s);
dump.Print("\n");
}
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_3dmApplication
//
ON_3dmApplication::ON_3dmApplication()
{
}
ON_3dmApplication::ON_3dmApplication( const ON_3dmApplication& src)
{
m_application_name = src.m_application_name;
m_application_URL = src.m_application_URL;
m_application_details = src.m_application_details;
}
ON_3dmApplication::~ON_3dmApplication()
{
m_application_name.Empty();
m_application_URL.Empty();
m_application_details.Empty();
}
ON_3dmApplication& ON_3dmApplication::operator=(const ON_3dmApplication& src)
{
if ( this != &src ) {
m_application_name = src.m_application_name;
m_application_URL = src.m_application_URL;
m_application_details = src.m_application_details;
}
return *this;
}
void ON_3dmApplication::Default()
{
m_application_name.Empty();
m_application_URL.Empty();
m_application_details.Empty();
}
void ON_3dmApplication::Dump( ON_TextLog& dump ) const
{
const wchar_t* s = m_application_name;
if ( s )
dump.Print("Name: %ls\n",s);
s = m_application_URL;
if ( s )
dump.Print("URL: %ls\n",s);
s = m_application_details;
if ( s )
dump.Print("Details: %ls\n",s);
}
ON_BOOL32 ON_3dmApplication::IsValid() const
{
return m_application_name.IsEmpty() ? false : true;
}
ON_BOOL32 ON_3dmApplication::Read( ON_BinaryArchive& file )
{
int major_version = 0;
int minor_version = 0;
ON_BOOL32 rc = file.Read3dmChunkVersion( &major_version, &minor_version );
if (rc) rc = file.ReadString( m_application_name );
if (rc) rc = file.ReadString( m_application_URL );
if (rc) rc = file.ReadString( m_application_details );
return rc;
}
ON_BOOL32 ON_3dmApplication::Write( ON_BinaryArchive& file ) const
{
ON_BOOL32 rc = file.Write3dmChunkVersion( 1, 0 );
if (rc) rc = file.WriteString( m_application_name );
if (rc) rc = file.WriteString( m_application_URL );
if (rc) rc = file.WriteString( m_application_details );
return rc;
}
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_3dmProperties
//
void ON_3dmProperties::Default()
{
// default properties
m_RevisionHistory.Default();
m_Notes.Default();
m_PreviewImage.Destroy();
m_Application.Default();
}
ON_3dmProperties::ON_3dmProperties()
{
Default();
};
ON_3dmProperties::~ON_3dmProperties()
{
Default();
}
ON_3dmProperties::ON_3dmProperties(const ON_3dmProperties& src)
{
Default();
*this = src;
}
ON_3dmProperties& ON_3dmProperties::operator=(const ON_3dmProperties& src)
{
if ( this != &src ) {
m_RevisionHistory = src.m_RevisionHistory;
m_Notes = src.m_Notes;
m_PreviewImage = src.m_PreviewImage;
m_Application = src.m_Application;
}
return *this;
}
void ON_SetBinaryArchiveOpenNURBSVersion(ON_BinaryArchive& file, int value)
{
if ( value >= 200012210 )
{
file.m_3dm_opennurbs_version = value;
}
else
{
ON_ERROR("ON_SetBinaryArchiveOpenNURBSVersion - invalid opennurbs version");
file.m_3dm_opennurbs_version = 0;
}
}
ON_BOOL32 ON_3dmProperties::Read(ON_BinaryArchive& file )
{
Default();
ON_BOOL32 rc = true;
unsigned int tcode;
ON__INT64 value;
for(;;) {
rc = file.BeginRead3dmBigChunk( &tcode, &value );
if ( !rc )
break;
switch(tcode) {
case TCODE_PROPERTIES_OPENNURBS_VERSION:
{
int on_version = 0;
if ( value > 299912319 || (value != 0 && value < 200101010) )
{
ON_ERROR("ON_3dmProperties::Read - TCODE_PROPERTIES_OPENNURBS_VERSION corrupt value");
rc = false;
}
else
{
on_version = (int)value;
}
ON_SetBinaryArchiveOpenNURBSVersion(file,on_version);
}
break;
case TCODE_PROPERTIES_REVISIONHISTORY: // file creation/revision information
m_RevisionHistory.Read(file);
break;
case TCODE_PROPERTIES_NOTES: // file notes
m_Notes.Read(file);
break;
case TCODE_PROPERTIES_PREVIEWIMAGE: // uncompressed preview image
m_PreviewImage.ReadUncompressed(file);
break;
case TCODE_PROPERTIES_COMPRESSED_PREVIEWIMAGE: // compressed preview image
m_PreviewImage.ReadCompressed(file);
break;
case TCODE_PROPERTIES_APPLICATION: // application that created 3dm file
m_Application.Read(file);
break;
default:
// information added in future will be skipped by file.EndRead3dmChunk()
break;
}
if ( !file.EndRead3dmChunk() ) {
rc = false;
break;
}
if ( TCODE_ENDOFTABLE == tcode )
break;
}
return rc;
}
ON_BOOL32 ON_3dmProperties::Write(ON_BinaryArchive& file) const
{
ON_BOOL32 rc = true;
// This short chunk identifies the version of OpenNURBS that was used to write this file.
rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_OPENNURBS_VERSION,ON::Version());
if ( rc) rc = file.EndWrite3dmChunk();
// optional TCODE_PROPERTIES_REVISIONHISTORY chunk - file creation/revision information
if ( rc && m_RevisionHistory.IsValid() ) {
rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_REVISIONHISTORY,0);
if ( rc ) {
rc = m_RevisionHistory.Write(file);
if ( !file.EndWrite3dmChunk() )
rc = false;
}
}
// optional TCODE_PROPERTIES_NOTES chunk - file notes
if ( rc && m_Notes.IsValid() ) {
rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_NOTES,0);
if ( rc ) {
rc = m_Notes.Write(file);
if ( !file.EndWrite3dmChunk() )
rc = false;
}
}
// optional TCODE_PROPERTIES_PREVIEWIMAGE chunk - bitmap preview
//if ( rc && m_PreviewImage.IsValid() ) {
// rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_PREVIEWIMAGE,0);
// if ( rc ) {
// rc = m_PreviewImage.WriteUncompressed(file);
// if ( !file.EndWrite3dmChunk() )
// rc = false;
// }
//}
// optional TCODE_PROPERTIES_COMPRESSED_PREVIEWIMAGE chunk - bitmap preview
if ( rc && m_PreviewImage.IsValid() ) {
rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_COMPRESSED_PREVIEWIMAGE,0);
if ( rc ) {
rc = m_PreviewImage.WriteCompressed(file);
if ( !file.EndWrite3dmChunk() )
rc = false;
}
}
// optional TCODE_PROPERTIES_APPLICATION chunk - application information
if ( rc && m_Application.IsValid() ) {
rc = file.BeginWrite3dmChunk(TCODE_PROPERTIES_APPLICATION,0);
if ( rc ) {
rc = m_Application.Write(file);
if ( !file.EndWrite3dmChunk() )
rc = false;
}
}
// required TCODE_ENDOFTABLE chunk - marks end of properties table
if ( rc ) {
rc = file.BeginWrite3dmChunk( TCODE_ENDOFTABLE, 0 );
if ( rc ) {
if ( !file.EndWrite3dmChunk() )
rc = false;
}
}
return rc;
}
void ON_3dmProperties::Dump( ON_TextLog& dump ) const
{
dump.Print("Revision history:\n");
dump.PushIndent();
m_RevisionHistory.Dump(dump);
dump.PopIndent();
dump.Print("\n");
dump.Print("Notes:\n");
if ( m_Notes.m_notes.Length() > 0 ) {
dump.PushIndent();
m_Notes.Dump(dump);
dump.PopIndent();
}
dump.Print("\n");
dump.Print("Application information:\n");
dump.PushIndent();
m_Application.Dump(dump);
dump.PopIndent();
if ( m_PreviewImage.IsValid() ) {
dump.Print("\n");
dump.Print("Preview image:\n");
dump.PushIndent();
m_PreviewImage.Dump(dump);
dump.PopIndent();
}
}

142
extern/opennurbs/opennurbs_3dm_properties.h vendored Executable file
View File

@@ -0,0 +1,142 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_3DM_PROPERTIES_INC_)
#define OPENNURBS_3DM_PROPERTIES_INC_
//////////////////////////////////////////////////////////////////////////////////////////
class ON_CLASS ON_3dmRevisionHistory
{
public:
ON_3dmRevisionHistory();
~ON_3dmRevisionHistory();
// C++ default operator= and copy constructor work fine.
void Default();
ON_BOOL32 IsValid() const;
int NewRevision(); // returns updated revision count
ON_BOOL32 Read( ON_BinaryArchive& );
ON_BOOL32 Write( ON_BinaryArchive& ) const;
void Dump( ON_TextLog& ) const;
/*
Returns:
true
if m_create_time is >= January 1, 1970
*/
bool CreateTimeIsSet() const;
/*
Returns:
true
if m_last_edit_time is >= January 1, 1970
*/
bool LastEditedTimeIsSet() const;
ON_wString m_sCreatedBy;
ON_wString m_sLastEditedBy;
struct tm m_create_time; // UCT create time
struct tm m_last_edit_time; // UCT las edited time
int m_revision_count;
};
//////////////////////////////////////////////////////////////////////////////////////////
class ON_CLASS ON_3dmNotes
{
public:
ON_3dmNotes();
ON_3dmNotes( const ON_3dmNotes& );
~ON_3dmNotes();
ON_3dmNotes& operator=(const ON_3dmNotes&);
void Default();
ON_BOOL32 IsValid() const;
ON_BOOL32 Read( ON_BinaryArchive& );
ON_BOOL32 Write( ON_BinaryArchive& ) const;
void Dump(ON_TextLog&) const;
////////////////////////////////////////////////////////////////
//
// Interface - this information is serialized. Applications
// may want to derive a runtime class that has additional
// window and font information.
ON_wString m_notes; // UNICODE
ON_BOOL32 m_bVisible; // true if notes window is showing
ON_BOOL32 m_bHTML; // true if notes are in HTML
// last window position
int m_window_left;
int m_window_top;
int m_window_right;
int m_window_bottom;
};
//////////////////////////////////////////////////////////////////////////////////////////
class ON_CLASS ON_3dmApplication
{
// application that created the 3dm file
public:
ON_3dmApplication();
ON_3dmApplication( const ON_3dmApplication& );
~ON_3dmApplication();
ON_3dmApplication& operator=(const ON_3dmApplication&);
void Default();
ON_BOOL32 IsValid() const;
ON_BOOL32 Read( ON_BinaryArchive& );
ON_BOOL32 Write( ON_BinaryArchive& ) const;
void Dump( ON_TextLog& ) const;
ON_wString m_application_name; // short name like "Rhino 2.0"
ON_wString m_application_URL; // URL
ON_wString m_application_details; // whatever you want
};
//////////////////////////////////////////////////////////////////////////////////////////
class ON_CLASS ON_3dmProperties
{
public:
ON_3dmProperties();
~ON_3dmProperties();
ON_3dmProperties(const ON_3dmProperties&);
ON_3dmProperties& operator=(const ON_3dmProperties&);
void Default();
ON_BOOL32 Read(ON_BinaryArchive&);
ON_BOOL32 Write(ON_BinaryArchive&) const;
void Dump( ON_TextLog& ) const;
ON_3dmRevisionHistory m_RevisionHistory;
ON_3dmNotes m_Notes;
ON_WindowsBitmap m_PreviewImage; // preview image of model
ON_3dmApplication m_Application; // application that created 3DM file
};
//////////////////////////////////////////////////////////////////////////////////////////
#endif

4094
extern/opennurbs/opennurbs_3dm_settings.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

926
extern/opennurbs/opennurbs_3dm_settings.h vendored Executable file
View File

@@ -0,0 +1,926 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_3DM_SETTINGS_INC_)
#define OPENNURBS_3DM_SETTINGS_INC_
///////////////////////////////////////////////////////////////////////
//
// units and tolerances
//
class ON_CLASS ON_3dmUnitsAndTolerances
{
public:
// The default constructor sets "this" to the values
// in ON_3dmUnitsAndTolerances::DefaultValues.
ON_3dmUnitsAndTolerances();
~ON_3dmUnitsAndTolerances();
ON_3dmUnitsAndTolerances(const ON_3dmUnitsAndTolerances&);
ON_3dmUnitsAndTolerances& operator=(const ON_3dmUnitsAndTolerances&);
// To get default values, use ... = ON_3dmUnitsAndTolerances::DefaultValue;
ON_DEPRECATED void Default();
bool Read( ON_BinaryArchive& );
bool Write( ON_BinaryArchive& ) const;
void Dump( ON_TextLog& ) const;
/*
Returns:
True if tolerances (m_absolute_tolerance, m_angle_tolerance, m_relative_tolerance)
are set to valid values.
*/
bool TolerancesAreValid() const;
/*
Description:
If m_absolute_tolerance is not set to a valid value, it is set
to ON_3dmUnitsAndTolerances::DefaultValue.m_absolute_tolerance.
If m_angle_tolerance is not set to a valid value, it is set
to ON_3dmUnitsAndTolerances::DefaultValue.m_angle_tolerance.
If m_relative_tolerance is not set to a valid value, it is set
to ON_3dmUnitsAndTolerances::DefaultValue.m_relative_tolerance.
Returns:
0: all tolerances were valid
0 != (rc & 1):
m_absolute_tolerance was invalid and set to the default value
0 != (rc & 2):
m_angle_tolerance was invalid and set to the default value
0 != (rc & 4):
m_relative_tolerance was invalid and set to the default value
*/
unsigned int SetInvalidTolerancesToDefaultValues();
//////////
// Returns scale factor that needs to be applied to change from
// the argument's unit system to m_unit_system.
// When m_unit_system is not ON::custom_unit_system,
// Scale(us) = ON::UnitScale(us,m_unit_system). When Scale(us)
// When m_unit_system is ON::custom_unit_system,
// Scale(us) = ON::UnitScale(us,ON::meters)*m_custom_unit_scale.
double Scale( ON::unit_system ) const;
ON_UnitSystem m_unit_system;
double m_absolute_tolerance; // in units > 0.0
double m_angle_tolerance; // in radians > 0.0 and <= ON_PI
double m_relative_tolerance; // fraction > 0.0 and < 1.0
ON::distance_display_mode m_distance_display_mode; // decimal or fractional
int m_distance_display_precision; // decimal mode: number of decimal places
// fractional modes:
// denominator = (1/2)^m_distance_display_precision
public:
/*
DefaultValue
m_unit_system ON::millimeters
m_absolute_tolerance 0.001
m_angle_tolerance pi/180 = 1 degree
m_relative_tolerance 0.01 = 1%
m_distance_display_mode ON::decimal
m_distance_display_precision 3
*/
static const ON_3dmUnitsAndTolerances DefaultValue;
};
///////////////////////////////////////////////////////////////////////
//
// Model settings
// render mesh defaults
// viewports
// construction planes
//
class ON_CLASS ON_3dmAnnotationSettings
{
public:
ON_3dmAnnotationSettings();
~ON_3dmAnnotationSettings();
ON_3dmAnnotationSettings(const ON_3dmAnnotationSettings&);
ON_3dmAnnotationSettings& operator=(const ON_3dmAnnotationSettings&);
void Default();
bool Read( ON_BinaryArchive& );
bool Write( ON_BinaryArchive& ) const;
void Dump( ON_TextLog& text_log ) const;
// these are the running defaults for making dimensions
// they are also the things written to the 3dm file as dimension settings
double m_dimscale; // model size / plotted size
double m_textheight;
double m_dimexe;
double m_dimexo;
double m_arrowlength;
double m_arrowwidth;
double m_centermark;
/*
Returns:
Value of m_world_view_text_scale;
*/
double WorldViewTextScale() const;
/*
Parameters:
world_view_text_scale - [in]
Sets value of m_world_view_text_scale.
*/
void SetWorldViewTextScale(double world_view_text_scale );
/*
Returns:
Value of m_world_view_hatch_scale;
*/
double WorldViewHatchScale() const;
/*
Parameters:
world_view_hatch_scale - [in]
Sets value of m_world_view_hatch_scale.
*/
void SetWorldViewHatchScale(double world_view_hatch_scale );
/*
Returns:
Value of m_bEnableAnnotationScaling;
*/
bool IsAnnotationScalingEnabled() const;
/*
Parameters:
bEnable - [in]
Sets value of m_bEnableAnnotationScaling.
*/
void EnableAnnotationScaling( bool bEnable );
/*
Returns:
Value of m_bEnableHatchScaling;
*/
bool IsHatchScalingEnabled() const;
/*
Parameters:
bEnable - [in]
Sets value of m_bEnableHatchScaling.
*/
void EnableHatchScaling( bool bEnable );
// Present but not used in V4 or V5 - removed 5 August 2010 to make room
// for m_world_view_text_scale and m_bEnableAnnotationScaling
//// added 12/28/05 LW
//double m_dimdle;
//double m_dimgap;
private:
// If m_bEnableAnnotationScaling is true,
// and ON_Annotation2::m_annotative_scale is true,
// and ON_Annotation2::m_type == ON::dtTextBlock,
// and the text object is being displayed in a world
// view (not a detail view and not a page view),
// then the text will be scaled by m_world_view_text_scale.
// The default is 1.0. Values <= 0.0 are not valid.
float m_world_view_text_scale;
float m_world_view_hatch_scale;
private:
// If m_bEnableAnnotationScaling is false:
// * m_world_view_text_scale is ignored.
// * text is not scaled.
// * ON_DimStyle::DimScale() determines the scale
// applied to all other annotation objects in all
// types of views.
// * The value of ON_DetailView::m_page_per_model_ratio
// is applied to all objects (annotation and geometry)
// in the detail view.
//
// If m_bEnableAnnotationScaling is true:
// * m_world_view_text_scale is used as described above.
// * ON_DimStyle::DimScale() determines the scale
// applied to all non text annotation objects in
// world views.
// * ON_DimStyle::DimScale() is ignored in page and
// detail views.
// * ON_DetailView::m_page_per_model_ratio is ingored
// for annotation objects in detail views, other
// geometry is scaled.
//
// Default is true.
unsigned char m_bEnableAnnotationScaling;
unsigned char m_bEnableHatchScaling;
private:
unsigned char m_reserved[6];
public:
ON::unit_system m_dimunits; // units used to measure the dimension
int m_arrowtype; // 0: filled narrow triangular arrow
int m_angularunits; // 0: degrees, 1: radians
int m_lengthformat; // 0: decimal, ...
int m_angleformat; // 0: decimal degrees, ...
int m_textalign; // 0: above line, 1: in line, 2: horizontal
int m_resolution; // depends on m_lengthformat
// for decimal, digits past the decimal point
ON_wString m_facename; // [LF_FACESIZE] // windows font name
};
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_3dmConstructionPlaneGridDefaults
//
// Default settings used for construction plane grids
class ON_CLASS ON_3dmConstructionPlaneGridDefaults
{
public:
ON_3dmConstructionPlaneGridDefaults();
~ON_3dmConstructionPlaneGridDefaults();
ON_3dmConstructionPlaneGridDefaults(const ON_3dmConstructionPlaneGridDefaults&);
ON_3dmConstructionPlaneGridDefaults& operator=(const ON_3dmConstructionPlaneGridDefaults&);
void Default();
bool Write( ON_BinaryArchive& ) const;
bool Read( ON_BinaryArchive& );
void Dump( ON_TextLog& text_log ) const;
double m_grid_spacing; // distance between grid lines
double m_snap_spacing; // when "grid snap" is enabled, the
// distance between snap points. Typically
// this is the same distance as grid spacing.
int m_grid_line_count; // number of grid lines in each direction
int m_grid_thick_frequency; // thick line frequency
// 0: none,
// 1: all lines are thick,
// 2: every other is thick, ...
ON_BOOL32 m_bShowGrid;
ON_BOOL32 m_bShowGridAxes;
ON_BOOL32 m_bShowWorldAxes;
};
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_3dmConstructionPlane
//
class ON_CLASS ON_3dmConstructionPlane
{
public:
ON_3dmConstructionPlane();
~ON_3dmConstructionPlane();
// default copy constructor and operator= work fine
//ON_3dmConstructionPlane(const ON_3dmConstructionPlane&);
//ON_3dmConstructionPlane& operator=(const ON_3dmConstructionPlane&);
void Default();
bool Write( ON_BinaryArchive& ) const;
bool Read( ON_BinaryArchive& );
void Dump( ON_TextLog& text_log ) const;
ON_Plane m_plane;
// construction grid appearance
double m_grid_spacing; // distance between grid lines
double m_snap_spacing; // when "grid snap" is enabled, the
// distance between snap points. Typically
// this is the same distance as grid spacing.
int m_grid_line_count; // number of grid lines in each direction
int m_grid_thick_frequency; // thick line frequency
// 0: none,
// 1: all lines are thick,
// 2: every other is thick, ...
bool m_bDepthBuffer; // false=grid is always drawn behind 3d geometry
// true=grid is drawn at its depth as a 3d plane
// and grid lines obscure things behind the grid.
ON_wString m_name;
};
#if defined(ON_DLL_TEMPLATE)
// This stuff is here because of a limitation in the way Microsoft
// handles templates and DLLs. See Microsoft's knowledge base
// article ID Q168958 for details.
#pragma warning( push )
#pragma warning( disable : 4231 )
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_3dmConstructionPlane>;
#pragma warning( pop )
#endif
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_3dmViewPosition
//
class ON_CLASS ON_3dmViewPosition
{
public:
// view window relative position and state in parent frame
ON_3dmViewPosition();
~ON_3dmViewPosition();
ON_3dmViewPosition(const ON_3dmViewPosition&);
ON_3dmViewPosition& operator=(const ON_3dmViewPosition&);
void Default();
bool Write( ON_BinaryArchive& ) const;
bool Read( ON_BinaryArchive& );
// relative position of view window in main frame
// if m_floating_viewport>0, this is relative position of the view window
// on the virtual screen (union of potentially multiple monitors)
double m_wnd_left; // 0.0 to 1.0
double m_wnd_right;
double m_wnd_top;
double m_wnd_bottom;
ON_BOOL32 m_bMaximized; // true if view window is maximized
// m_floating_viewport is used to track floating viewport information.
// 0 = the view is docked in the main application window.
// >0 = the view is floating. When floating, this corresponds to the
// number of monitors on on the user's computer when the file was saved
unsigned char m_floating_viewport;
private:
// reserved for future use
unsigned char m_reserved_1;
unsigned char m_reserved_2;
unsigned char m_reserved_3;
};
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_3dmViewTraceImage
//
class ON_CLASS ON_3dmViewTraceImage
{
public:
ON_3dmViewTraceImage();
~ON_3dmViewTraceImage();
bool operator==( const ON_3dmViewTraceImage& ) const;
bool operator!=( const ON_3dmViewTraceImage& ) const;
void Default();
bool Write( ON_BinaryArchive& ) const;
bool Read( ON_BinaryArchive& );
// view window relative position and state in parent frame
ON_Plane m_plane;
double m_width;
double m_height;
ON_wString m_bitmap_filename;
bool m_bGrayScale; // true if image should be black and white
bool m_bHidden; // true if image is currently hidden from view
bool m_bFiltered; // true if image should be filtered (bilinear) before displayed.
};
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_3dmViewTraceImage
//
class ON_CLASS ON_3dmWallpaperImage
{
public:
ON_3dmWallpaperImage();
~ON_3dmWallpaperImage();
bool operator==( const ON_3dmWallpaperImage& ) const;
bool operator!=( const ON_3dmWallpaperImage& ) const;
void Default();
bool Write( ON_BinaryArchive& ) const;
bool Read( ON_BinaryArchive& );
ON_wString m_bitmap_filename;
bool m_bGrayScale; // true if image should be black and white
bool m_bHidden; // true if image is currently hidden from view
};
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_3dmView
//
class ON_CLASS ON_3dmPageSettings
{
public:
ON_3dmPageSettings();
~ON_3dmPageSettings();
bool IsValid( ON_TextLog* text_log = 0 ) const;
void Default();
int m_page_number;
// Overall size of the page in millimeters
double m_width_mm;
double m_height_mm;
// Page margins in millimeters
double m_left_margin_mm;
double m_right_margin_mm;
double m_top_margin_mm;
double m_bottom_margin_mm;
ON_wString m_printer_name;
bool Write(ON_BinaryArchive& archive) const;
bool Read(ON_BinaryArchive& archive);
};
class ON_CLASS ON_3dmView
{
public:
ON_3dmView();
~ON_3dmView();
// The C++ default copy constructor and operator= work fine.
// Do not provide customized versions.
// NO // ON_3dmView(const ON_3dmView&);
// NO // ON_3dmView& operator=(const ON_3dmView&);
void Default();
bool Write( ON_BinaryArchive& ) const;
bool Read( ON_BinaryArchive& );
void Dump( ON_TextLog& text_log ) const;
bool IsValid( ON_TextLog* text_log = 0 ) const;
// view projection information
ON_Viewport m_vp;
// clipping planes
// Prior to Dec 14, 2010 m_clipping_planes was not saved with the view.
// After Dec 14, 2010 m_clipping_planes is saved.
ON_SimpleArray<ON_ClippingPlaneInfo> m_clipping_planes;
// If true, the the camera location, camera direction,
// and lens angle should not be changed.
// It is ok to adjust clipping planes.
bool m_bLockedProjection;
///////////////////////////////////////////////////////////////////////
//
// target point
//
/*
Returns:
Target point. This point is saved on m_vp.m_target_point.
The default constructor sets the target point to
ON_3dPoint::UnsetPoint. You must explicitly set the target
point if you want to use it.
Remarks:
The target point is stored on m_vp.m_target_point. The
value ON_3dmView.m_target is obsolete. This function always
returns the value of m_vp.m_target_point.
*/
ON_3dPoint TargetPoint() const;
/*
Description:
Sets the target point.
Parameters:
target_point - [in]
When in double, the point m_vp.FrustumCenterPoint(ON_UNSET_VALUE)
is a good choice.
Remarks:
This point is saved on m_vp.m_target_point. Using this function
keeps the obsolete ON_3dmView.m_target value equal to
m_vp.m_target_point.
*/
bool SetTargetPoint(ON_3dPoint target_point);
///////////////////////////////////////////////////////////////////////
// OBSOLETE //
// Use ON_3dmView::SetTargetPoint() and ON_3dmView::TargetPoint() //
// functions to set and get the target point. The m_target member //
// will be removed in V6. The only reason m_target is still here //
// is to avoid breaking the public SDK. //
/* OBSOLETE */ ON_3dPoint m_target; // OBSOLETE //
// Hmm, did you notice that m_target is obsolete? Try using the //
// SetTargetPoint() and TargetPoint() functions instead. //
// OBSOLETE //
///////////////////////////////////////////////////////////////////////
//
///////////////////////////////////////////////////////////////////////
ON_wString m_name; // name on window
// If m_display_mode_id is nil, then use m_display_mode
// to show one of the "standard" (wireframe, shaded, rendered)
// display modes. If m_display_mode_id is not nil, then
// ignore m_display_mode.
ON_UUID m_display_mode_id;
ON::display_mode m_display_mode;
// position of view in parent window
// (relative display device coordinates)
ON_3dmViewPosition m_position;
ON::view_type m_view_type; // model, page, or nested
// If m_view_type == ON::page_view_type, then the m_page_settings
// records the page size. Otherwise, m_page_settings should
// be ignored.
ON_3dmPageSettings m_page_settings;
// construction plane
ON_3dmConstructionPlane m_cplane;
bool m_bShowConstructionGrid;
bool m_bShowConstructionAxes;
// world axes icon
bool m_bShowWorldAxes;
// tracing image
ON_3dmViewTraceImage m_trace_image;
// wallpaper image
ON_3dmWallpaperImage m_wallpaper_image;
};
#if defined(ON_DLL_TEMPLATE)
// This stuff is here because of a limitation in the way Microsoft
// handles templates and DLLs. See Microsoft's knowledge base
// article ID Q168958 for details.
#pragma warning( push )
#pragma warning( disable : 4231 )
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_3dmView>;
#pragma warning( pop )
#endif
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_3dmRenderSettings
//
class ON_CLASS ON_3dmRenderSettings
{
public:
ON_3dmRenderSettings();
~ON_3dmRenderSettings();
ON_3dmRenderSettings(const ON_3dmRenderSettings&);
ON_3dmRenderSettings& operator=(const ON_3dmRenderSettings&);
void Default();
bool Write( ON_BinaryArchive& ) const;
bool Read( ON_BinaryArchive& );
void Dump( ON_TextLog& text_log ) const;
bool ScaleBackgroundToFit() const;
void SetScaleBackgroundToFit( bool bScaleBackgroundToFit );
//////////
// false: image pixel size = current viewport size
// true: image pixel size = m_image_width X m_image_height pixels
ON_BOOL32 m_bCustomImageSize;
int m_image_width; // image width in pixels
int m_image_height; // image height in pixels
private:
bool m_bScaleBackgroundToFit;
unsigned char m_reserved1[3];
public:
////////
// Number of dots/inch (dots=pixels) to use when printing and
// saving bitmaps. The default is 72.0 dots/inch.
double m_image_dpi;
//////////
// unit system to use when converting image pixel size and dpi
// information into a print size. Default = inches
ON::unit_system m_image_us;
ON_Color m_ambient_light;
int m_background_style; // 0 = solid color, 1 = "wallpaper" image, 2 = Gradient, 3 = Environment
ON_Color m_background_color; // also Top color of gradient...
ON_wString m_background_bitmap_filename;
ON_BOOL32 m_bUseHiddenLights;
ON_BOOL32 m_bDepthCue;
ON_BOOL32 m_bFlatShade;
ON_BOOL32 m_bRenderBackfaces;
ON_BOOL32 m_bRenderPoints;
ON_BOOL32 m_bRenderCurves;
ON_BOOL32 m_bRenderIsoparams;
ON_BOOL32 m_bRenderMeshEdges;
ON_BOOL32 m_bRenderAnnotation;
int m_antialias_style; // 0 = none, 1 = normal, 2 = best
int m_shadowmap_style; // 0 = none, 1 = normal, 2 = best
int m_shadowmap_width;
int m_shadowmap_height;
double m_shadowmap_offset;
ON_Color m_background_bottom_color;
// Flags that are used to determine which render settings a render
// plugin uses, and which ones the display pipeline should use.
// Note: Render plugins set these, and they don't need to persist
// in the document...Also, when set, they turn OFF their
// corresponding setting in the Display Attributes Manager's
// UI pages for "Rendered" mode.
bool m_bUsesAmbientAttr;
bool m_bUsesBackgroundAttr;
bool m_bUsesBackfaceAttr;
bool m_bUsesPointsAttr;
bool m_bUsesCurvesAttr;
bool m_bUsesIsoparmsAttr;
bool m_bUsesMeshEdgesAttr;
bool m_bUsesAnnotationAttr;
bool m_bUsesHiddenLightsAttr;
private:
unsigned char m_reserved2[3];
};
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_EarthAnchorPoint
//
class ON_CLASS ON_EarthAnchorPoint
{
public:
ON_EarthAnchorPoint();
~ON_EarthAnchorPoint();
static
int Compare(
const ON_EarthAnchorPoint*,
const ON_EarthAnchorPoint*
);
static
int CompareEarthLocation(
const ON_EarthAnchorPoint*,
const ON_EarthAnchorPoint*
);
static
int CompareModelDirection(
const ON_EarthAnchorPoint*,
const ON_EarthAnchorPoint*
);
static
int CompareIdentification(
const ON_EarthAnchorPoint*,
const ON_EarthAnchorPoint*
);
void Default();
bool Read( ON_BinaryArchive& );
bool Write( ON_BinaryArchive& ) const;
// Point on the Earth
// Latitude (degrees): +90 = north pole, 0 = equator, -90 = south pole
// Longitude (degrees): 0 = prime meridian (Greenwich meridian)
// Elevation (meters):
double m_earth_basepoint_latitude; // in decimal degrees
double m_earth_basepoint_longitude; // in decimal degrees
double m_earth_basepoint_elevation; // in meters
int m_earth_basepoint_elevation_zero; // 0 = ground level
// 1 = mean sea level
// 2 = center of earth
// Corresponding model point in model coordinates.
ON_3dPoint m_model_basepoint; // in model coordinates
// Earth directions in model coordinates
ON_3dVector m_model_north; // in model coordinates
ON_3dVector m_model_east; // in model coordinates
// Identification information about this location
ON_UUID m_id; // unique id for this anchor point
ON_wString m_name;
ON_wString m_description;
ON_wString m_url;
ON_wString m_url_tag; // UI link text for m_url
/*
Parameters:
model_compass - [out]
A plane in model coordinates whose xaxis points East,
yaxis points North and zaxis points up. The origin
is set to m_model_basepoint.
*/
bool GetModelCompass(
ON_Plane& model_compass
) const;
/*
Description:
Get a transformation from model coordinates to earth coordinates.
This transformation assumes the model is small enough that
the curvature of the earth can be ignored.
Parameters:
model_unit_system - [in]
model_to_earth - [out]
Transformation from model coordinates to earth locations
(degrees latitude,degrees longitude,elevation in meters)
Remarks:
If M is a point in model coordinates and E = model_to_earth*M,
then
E.x = latitude in decimal degrees
E.y = longitude in decimal degrees
E.z = elevation in meters above mean sea level
Because the earth is not flat, there is a small amount of error
when using a linear transformation to calculate oblate spherical
coordinates. This error is small. If the distance from P to M
is d meters, then the approximation error is
latitude error <=
longitude error <=
elevation error <= 6379000*((1 + (d/6356000)^2)-1) meters
In particular, if every point in the model is within 1000 meters of
the m_model_basepoint, then the maximum approximation errors are
latitude error <=
longitude error <=
elevation error <= 8 centimeters
*/
bool GetModelToEarthXform(
const ON_UnitSystem& model_unit_system,
ON_Xform& model_to_earth
) const;
};
class ON_CLASS ON_3dmIOSettings
{
public:
ON_3dmIOSettings();
void Default();
bool Read(ON_BinaryArchive&);
bool Write(ON_BinaryArchive&) const;
// bitmaps associated with rendering materials
bool m_bSaveTextureBitmapsInFile;
// As of 7 February 2012, the m_idef_link_update setting
// controls if, when and how linked and linked_and_embedded
// instance defintions are updated when the source archive
// that was used to create the idef has changed.
int m_idef_link_update;
// 1 = prompt - ask the user if the idef should be updated.
// 2 = always update - no prompting
// 3 = never update - no prompting
// Any value not equal to 1,2 or 3 shall be treated as 1.
};
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_3dmSettings
//
class ON_CLASS ON_3dmSettings
{
public:
ON_3dmSettings();
~ON_3dmSettings();
// C++ copy constructor and operator= work fine.
// Do not provide custom versions.
// NO // ON_3dmSettings(const ON_3dmSettings&);
// NO // ON_3dmSettings& operator=(const ON_3dmSettings&);
void Default();
bool Read(ON_BinaryArchive&);
bool Write(ON_BinaryArchive&) const;
void Dump( ON_TextLog& ) const;
// model URL (can be empty)
ON_wString m_model_URL;
// Model basepoint is used when the file is read as
// an instance definition and is the point that is
// mapped to the origin in the instance definition.
ON_3dPoint m_model_basepoint;
// If set, this is the model's location on the earth.
// This information is used when the model is used
// with GIS information.
ON_EarthAnchorPoint m_earth_anchor_point;
// Model space tolerances and unit system
ON_3dmUnitsAndTolerances m_ModelUnitsAndTolerances;
// Page space (printing/paper) tolerances and unit system
ON_3dmUnitsAndTolerances m_PageUnitsAndTolerances;
// settings used for automatically created rendering meshes
ON_MeshParameters m_RenderMeshSettings;
// saved custom settings
ON_MeshParameters m_CustomRenderMeshSettings;
// settings used for automatically created analysis meshes
ON_MeshParameters m_AnalysisMeshSettings;
// settings used when annotation objects are created
ON_3dmAnnotationSettings m_AnnotationSettings;
ON_ClassArray<ON_3dmConstructionPlane> m_named_cplanes;
ON_ClassArray<ON_3dmView> m_named_views;
ON_ClassArray<ON_3dmView> m_views; // current viewports
ON_UUID m_active_view_id; // id of "active" viewport
// These fields determine what layer, material, color, line style, and
// wire density are used for new objects.
int m_current_layer_index;
int m_current_material_index;
ON::object_material_source m_current_material_source;
ON_Color m_current_color;
ON::object_color_source m_current_color_source;
ON_Color m_current_plot_color;
ON::plot_color_source m_current_plot_color_source;
int m_current_linetype_index;
ON::object_linetype_source m_current_linetype_source;
int m_current_font_index;
int m_current_dimstyle_index;
// Surface wireframe density
//
// @untitled table
// 0 boundary + "knot" wires
// 1 boundary + "knot" wires + 1 interior wire if no interior "knots"
// N>=2 boundry + "knot" wires + (N-1) interior wires
int m_current_wire_density;
ON_3dmRenderSettings m_RenderSettings;
// default settings for construction plane grids
ON_3dmConstructionPlaneGridDefaults m_GridDefaults;
// World scale factor to apply to non-solid linetypes
// for model display. For plotting, the linetype settings
// are used without scaling.
double m_linetype_display_scale;
// Plugins that were loaded when the file was saved.
ON_ClassArray<ON_PlugInRef> m_plugin_list;
ON_3dmIOSettings m_IO_settings;
private:
bool Read_v1(ON_BinaryArchive&);
bool Read_v2(ON_BinaryArchive&);
bool Write_v1(ON_BinaryArchive&) const;
bool Write_v2(ON_BinaryArchive&) const;
};
#endif

732
extern/opennurbs/opennurbs_annotation.cpp vendored Executable file
View File

@@ -0,0 +1,732 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
ON_VIRTUAL_OBJECT_IMPLEMENT( ON_Annotation, ON_Geometry, "ABAF5873-4145-11d4-800F-0010830122F0" );
ON_OBJECT_IMPLEMENT( ON_LinearDimension, ON_Annotation, "5DE6B20D-486B-11d4-8014-0010830122F0" );
ON_OBJECT_IMPLEMENT( ON_RadialDimension, ON_Annotation, "5DE6B20E-486B-11d4-8014-0010830122F0" );
ON_OBJECT_IMPLEMENT( ON_AngularDimension, ON_Annotation, "5DE6B20F-486B-11d4-8014-0010830122F0" );
ON_OBJECT_IMPLEMENT( ON_TextEntity, ON_Annotation, "5DE6B210-486B-11d4-8014-0010830122F0" );
ON_OBJECT_IMPLEMENT( ON_Leader, ON_Annotation, "5DE6B211-486B-11d4-8014-0010830122F0" );
ON_BOOL32 ON_LinearDimension::IsRealObject() const {return true;}
ON_BOOL32 ON_RadialDimension::IsRealObject() const {return true;}
ON_BOOL32 ON_AngularDimension::IsRealObject() const {return true;}
ON_BOOL32 ON_TextEntity::IsRealObject() const {return true;}
ON_BOOL32 ON_Leader::IsRealObject() const {return true;}
#define REALLY_BIG_NUMBER 1e150
static const ON_3dmAnnotationSettings* sglb_asets = 0;
void ON_Annotation::SetAnnotationSettings( const ON_3dmAnnotationSettings* p )
{
sglb_asets = p;
}
const ON_3dmAnnotationSettings& ON_Annotation::AnnotationSettings()
{
static ON_3dmAnnotationSettings defaults;
return sglb_asets ? *sglb_asets : defaults;
}
void ON_Annotation::Create()
{
// TODO: initialize class members assuming any member that is not a class
// is not initialized.
m_type = ON::dtNothing;
m_plane = ON_xy_plane;
m_points.EmergencyDestroy();
m_usertext.EmergencyDestroy();
m_defaulttext.EmergencyDestroy();
m_userpositionedtext = false;
}
void ON_Annotation::Destroy()
{
m_points.Destroy();
m_usertext.Destroy();
m_defaulttext.Destroy();
m_type = ON::dtNothing;
m_plane = ON_xy_plane;
m_userpositionedtext = false;
}
void ON_Annotation::EmergencyDestroy()
{
m_points.EmergencyDestroy();
m_usertext.EmergencyDestroy();
m_defaulttext.EmergencyDestroy();
m_type = ON::dtNothing;
m_plane = ON_xy_plane;
m_userpositionedtext = false;
}
ON_Annotation::ON_Annotation()
{
Create();
}
ON_Annotation::ON_Annotation(const ON_Annotation& src)
{
Create();
*this = src;
}
ON_Annotation::~ON_Annotation()
{
Destroy();
}
bool ON_Annotation::IsText() const { return Type() == ON::dtTextBlock; }
bool ON_Annotation::IsLeader() const { return Type() == ON::dtLeader; }
bool ON_Annotation::IsDimension() const { if( IsText() || IsLeader()) return false; return true; }
//virtual
double ON_Annotation::NumericValue() const { return 0.0; }
//virtual
void ON_Annotation::SetTextToDefault() { SetDefaultText( L""); }
void ON_Annotation::SetType( ON::eAnnotationType type ) { m_type = type; }
ON::eAnnotationType ON_Annotation::Type() const { return m_type; }
void ON_Annotation::SetTextDisplayMode( ON::eTextDisplayMode mode) { m_textdisplaymode = mode; }
ON::eTextDisplayMode ON_Annotation::TextDisplayMode() const { return m_textdisplaymode; }
void ON_Annotation::SetPlane( const ON_Plane& plane ) { m_plane = plane; }
ON_Plane ON_Annotation::Plane() const { return m_plane; }
int ON_Annotation::PointCount() const { return m_points.Count(); }
void ON_Annotation::SetPoints( const ON_SimpleArray<ON_2dPoint>& points ) { m_points = points; }
const ON_SimpleArray<ON_2dPoint>& ON_Annotation::Points() const { return m_points; }
void ON_Annotation::SetUserText( const wchar_t* string ) {m_usertext = string; }
const ON_wString& ON_Annotation::UserText() const { return m_usertext; }
void ON_Annotation::SetDefaultText( const wchar_t* string ) { m_defaulttext = string; }
const ON_wString& ON_Annotation::DefaultText() const { return m_defaulttext; }
void ON_Annotation::SetUserPositionedText( int bUserPositionedText ) { m_userpositionedtext = (bUserPositionedText?true:false); }
bool ON_Annotation::UserPositionedText() const { return m_userpositionedtext; }
ON_Annotation& ON_Annotation::operator=(const ON_Annotation& src)
{
if ( this != &src ) {
// get a clean and empty "this"
Destroy();
Create();
ON_Geometry::operator=(src);
// TODO: copy fields
m_type = src.m_type;
m_plane = src.m_plane;
m_points = src.m_points;
m_usertext = src.m_usertext;
m_userpositionedtext = src.m_userpositionedtext;
}
return *this;
}
ON_BOOL32 ON_Annotation::IsValid( ON_TextLog* text_log ) const
{
// TODO: quickly inspect object and return true/false
bool rc = true;
if ( ON::dtNothing == m_type )
{
if ( 0 != text_log )
text_log->Print("ON_Annotation has m_type = ON::dtNothing.\n");
rc = false;
}
return rc;
}
void ON_Annotation::Dump( ON_TextLog& dump ) const
{
// for debugging
dump.Print("ON_Annotation: ....\n");
}
ON_BOOL32 ON_Annotation::Write( ON_BinaryArchive& file ) const
{
int i;
ON_BOOL32 rc = file.Write3dmChunkVersion( 1, 0 );
// TODO: use
// if (rc) rc = file.WritePoint(....);
// if (rc) rc = file.WriteString(....);
// if (rc) rc = file.WriteDouble(....);
// to write object.
i = m_type;
if (rc)
rc = file.WriteInt( i );
if (rc)
rc = file.WritePlane( m_plane );
if (rc)
rc = file.WriteArray( m_points );
if (rc)
rc = file.WriteString( m_usertext );
if (rc)
rc = file.WriteString( m_defaulttext );
if( rc )
rc = file.WriteInt( m_userpositionedtext );
return rc;
}
ON_BOOL32 ON_Annotation::Read( ON_BinaryArchive& file )
{
Destroy();
int major_version = 0;
int minor_version = 0;
ON_BOOL32 rc = file.Read3dmChunkVersion(&major_version,&minor_version);
if ( rc && major_version == 1 )
{
int i;
if (rc)
{
rc = file.ReadInt( &i );
if (rc)
m_type = ON::AnnotationType(i);
}
if (rc)
rc = file.ReadPlane( m_plane );
if (rc)
rc = file.ReadArray( m_points );
if (rc)
rc = file.ReadString( m_usertext );
if (rc)
rc = file.ReadString( m_defaulttext );
if( rc )
{
rc = file.ReadInt( &i );
if (rc) m_userpositionedtext = i ? true : false;
}
}
if( fabs( m_plane.origin.x) > REALLY_BIG_NUMBER || fabs( m_plane.origin.y) > REALLY_BIG_NUMBER || fabs( m_plane.origin.z) > REALLY_BIG_NUMBER)
return false;
for( int i = 0; i < m_points.Count(); i++)
{
if( fabs( m_points[i].x) > REALLY_BIG_NUMBER || fabs( m_points[i].y) > REALLY_BIG_NUMBER)
return false;
}
return rc;
}
ON::object_type ON_Annotation::ObjectType() const
{
return ON::annotation_object;
}
int ON_Annotation::Dimension() const
{
return 3;
}
ON_BOOL32 ON_Annotation::GetBBox( // returns true if successful
double* boxmin,
double* boxmax,
ON_BOOL32 bGrowBox // default = false
) const
{
// TODO:
// If the class is not valid, return false.
//
// If the class is valid and bGrowBox is false,
// return the 3d bounding box of the annotation.
//
// If the class is valid and bGrowBox is true,
// return the union of the input box and the 3d bounding
// box of the annotation.
if( !bGrowBox )
{
boxmin[0] = boxmin[1] = boxmin[2] = 1e300;
boxmax[0] = boxmax[1] = boxmax[2] = -1e300;
}
ON_3dPoint wpt;
ON_Xform xform;
GetECStoWCSXform( xform );
for( int i = 0; i < m_points.Count(); i++ )
{
wpt = m_points[i];
if( wpt.y < boxmin[1] )
boxmin[1] = wpt.y;
if( wpt.z < boxmin[2] )
boxmin[2] = wpt.z;
if( wpt.x > boxmax[0] )
boxmax[0] = wpt.x;
if( wpt.y > boxmax[1] )
boxmax[1] = wpt.y;
if( wpt.z > boxmax[2] )
boxmax[2] = wpt.z;
}
return true;
}
ON_BOOL32 ON_Annotation::Transform( const ON_Xform& xform )
{
// TODO: Return false if class is invalid or xform cannot be applied.
// Otherwise, apply xform to geometry and return true.
TransformUserData(xform);
return m_plane.Transform( xform );
}
// Converts 2d points in annotation to 3d WCS points
bool ON_Annotation::GetECStoWCSXform( ON_Xform& xform ) const
{
ON_3dVector z = ON_CrossProduct( m_plane.xaxis, m_plane.yaxis );
return xform.ChangeBasis( m_plane.origin, m_plane.xaxis, m_plane.yaxis, z,
ON_origin, ON_xaxis, ON_yaxis, ON_zaxis );
}
// Converts from WCS 3d points to 2d points in annotation
bool ON_Annotation::GeWCStoECSXform( ON_Xform& xform ) const
{
ON_3dVector z = ON_CrossProduct( m_plane.xaxis, m_plane.yaxis );
return xform.ChangeBasis( ON_origin, ON_xaxis, ON_yaxis, ON_zaxis,
m_plane.origin, m_plane.xaxis, m_plane.yaxis, z );
}
void ON_Annotation::SetPoint( int idx, ON_3dPoint point )
{
if( idx >= 0 && idx < m_points.Count() )
m_points[idx] = point;
}
ON_2dPoint ON_Annotation::Point( int idx ) const
{
if( idx >= 0 && idx < m_points.Count() )
return m_points[idx];
return ON_2dPoint( 0.0, 0.0 );
}
//----- ON_LinearDimension ------------------------------------------
ON_LinearDimension::ON_LinearDimension()
{
}
ON_LinearDimension::ON_LinearDimension(const ON_LinearDimension& src) : ON_Annotation(src)
{
}
ON_LinearDimension::~ON_LinearDimension()
{
}
ON_LinearDimension& ON_LinearDimension::operator=(const ON_LinearDimension& src)
{
if ( this != &src ) {
ON_Annotation::operator=(src);
}
return *this;
}
void ON_LinearDimension::EmergencyDestroy()
{
ON_Annotation::EmergencyDestroy();
}
double ON_LinearDimension::NumericValue()
{
return (Point( 1) - Point( 3)).Length();
}
void ON_LinearDimension::SetTextToDefault()
{
SetUserText( L"<>");
}
//----- ON_RadialDimension ------------------------------------------
ON_RadialDimension::ON_RadialDimension()
{
}
ON_RadialDimension::ON_RadialDimension(const ON_RadialDimension& src) : ON_Annotation(src)
{
}
ON_RadialDimension::~ON_RadialDimension()
{
}
ON_RadialDimension& ON_RadialDimension::operator=(const ON_RadialDimension& src)
{
if ( this != &src ) {
ON_Annotation::operator=(src);
}
return *this;
}
void ON_RadialDimension::EmergencyDestroy()
{
ON_Annotation::EmergencyDestroy();
}
double ON_RadialDimension::NumericValue()
{
double d = (Point( 0) - Point( 1)).Length();
if( Type() == ON::dtDimDiameter)
d *= 2.0;
return d;
}
void ON_RadialDimension::SetTextToDefault()
{
ON_wString s;
if( Type() == ON::dtDimDiameter)
s.Format( L"%c<>", ON_Annotation::diametersym);
else
s.Format( L"%c<>", ON_Annotation::radiussym);
SetUserText( s);
}
//----- ON_AngularDimension -----------------------------------------
ON_AngularDimension::ON_AngularDimension() : m_angle(0.0), m_radius(0.0)
{
}
ON_AngularDimension::ON_AngularDimension(const ON_AngularDimension& src) : ON_Annotation(src)
{
m_angle = src.m_angle;
m_radius = src.m_radius;
}
ON_AngularDimension::~ON_AngularDimension()
{
}
ON_AngularDimension& ON_AngularDimension::operator=(const ON_AngularDimension& src)
{
if ( this != &src ) {
ON_Annotation::operator=(src);
m_angle = src.m_angle;
m_radius = src.m_radius;
}
return *this;
}
void ON_AngularDimension::EmergencyDestroy()
{
ON_Annotation::EmergencyDestroy();
}
ON_BOOL32 ON_AngularDimension::Write( ON_BinaryArchive& file ) const
{
ON_BOOL32 rc = ON_Annotation::Write( file );
if( rc )
rc = file.WriteDouble( m_angle );
if( rc )
rc = file.WriteDouble( m_radius );
return rc;
}
ON_BOOL32 ON_AngularDimension::Read( ON_BinaryArchive& file )
{
ON_BOOL32 rc = ON_Annotation::Read( file );
if( rc )
rc = file.ReadDouble( &m_angle );
if( rc )
rc = file.ReadDouble( &m_radius );
if( m_angle <= 0.0 || m_angle > REALLY_BIG_NUMBER)
return false;
if( m_radius <= 0.0 || m_radius > REALLY_BIG_NUMBER)
return false;
return rc;
}
double ON_AngularDimension::NumericValue()
{
return Angle() * 180.0 / ON_PI;
}
void ON_AngularDimension::SetTextToDefault()
{
ON_wString s;
s.Format( L"<>%c", ON_Annotation::degreesym);
SetUserText( s);
}
//----- ON_TextEntity -----------------------------------------------
ON_TextEntity::ON_TextEntity() : m_fontweight(400), m_height(20.0)
{
}
ON_TextEntity::ON_TextEntity(const ON_TextEntity& src) : ON_Annotation(src)
{
m_facename = src.m_facename;
m_fontweight = src.m_fontweight;
m_height = src.m_height;
}
ON_TextEntity::~ON_TextEntity()
{
m_facename.Destroy();
}
ON_TextEntity& ON_TextEntity::operator=(const ON_TextEntity& src)
{
if ( this != &src ) {
m_facename = src.m_facename;
m_fontweight = src.m_fontweight;
m_height = src.m_height;
ON_Annotation::operator=(src);
}
return *this;
}
void ON_TextEntity::EmergencyDestroy()
{
ON_Annotation::EmergencyDestroy();
m_facename.EmergencyDestroy();
}
ON_BOOL32 ON_TextEntity::Write( ON_BinaryArchive& file ) const
{
ON_BOOL32 rc = ON_Annotation::Write( file );
if( rc )
rc = file.WriteString( m_facename );
if( rc )
rc = file.WriteInt( m_fontweight );
if( rc )
rc = file.WriteDouble( m_height );
return rc;
}
ON_BOOL32 ON_TextEntity::Read( ON_BinaryArchive& file )
{
ON_BOOL32 rc = ON_Annotation::Read( file );
if( rc )
rc = file.ReadString( m_facename );
if( rc )
rc = file.ReadInt( &m_fontweight );
if( rc )
rc = file.ReadDouble( &m_height );
if( fabs( m_height) > REALLY_BIG_NUMBER)
return false;
return rc;
}
//----- ON_Leader ------------------------------------------
ON_Leader::ON_Leader()
{
}
ON_Leader::ON_Leader(const ON_Leader& src) : ON_Annotation(src)
{
}
ON_Leader::~ON_Leader()
{
}
ON_Leader& ON_Leader::operator=(const ON_Leader& src)
{
if ( this != &src ) {
ON_Annotation::operator=(src);
}
return *this;
}
void ON_Leader::EmergencyDestroy()
{
ON_Annotation::EmergencyDestroy();
}
ON_OBJECT_IMPLEMENT(ON_AnnotationTextDot,ON_Point,"8BD94E19-59E1-11d4-8018-0010830122F0");
ON_AnnotationTextDot::ON_AnnotationTextDot()
{}
ON_AnnotationTextDot::~ON_AnnotationTextDot()
{
m_text.Destroy();
}
ON_AnnotationTextDot::ON_AnnotationTextDot(const ON_AnnotationTextDot& src) : ON_Point(src), m_text(src.m_text)
{}
ON_AnnotationTextDot& ON_AnnotationTextDot::operator=(const ON_AnnotationTextDot& src)
{
if ( this != &src ) {
ON_Point::operator=(src);
m_text = src.m_text;
}
return *this;
}
ON_BOOL32 ON_AnnotationTextDot::IsValid( ON_TextLog* text_log ) const
{
bool rc = true;
if ( m_text.IsEmpty() )
{
if ( 0 != text_log )
text_log->Print("ON_AnnotationTextDot.m_text is empty\n");
rc = false;
}
return rc;
}
void ON_AnnotationTextDot::Dump( ON_TextLog& log ) const
{
log.Print("ON_AnnotationTextDot \"%ls\" at ",m_text.Array());
log.Print(point);
log.Print("\n");
}
ON_BOOL32 ON_AnnotationTextDot::Write( ON_BinaryArchive& file ) const
{
ON_BOOL32 rc = file.Write3dmChunkVersion(1,0);
if (rc) rc = file.WritePoint( point );
if (rc) rc = file.WriteString( m_text );
return rc;
}
ON_BOOL32 ON_AnnotationTextDot::Read( ON_BinaryArchive& file )
{
m_text.Destroy();
int major_version = 0;
int minor_version = 0;
ON_BOOL32 rc = file.Read3dmChunkVersion(&major_version,&minor_version);
if ( major_version == 1 ) {
if (rc) rc = file.ReadPoint( point );
if (rc) rc = file.ReadString( m_text );
}
else {
rc = false;
}
return rc;
}
ON_OBJECT_IMPLEMENT(ON_AnnotationArrow,ON_Geometry,"8BD94E1A-59E1-11d4-8018-0010830122F0");
ON_AnnotationArrow::ON_AnnotationArrow() : m_tail(0.0,0.0,0.0), m_head(0.0,0.0,0.0)
{}
ON_AnnotationArrow::~ON_AnnotationArrow()
{}
ON_AnnotationArrow::ON_AnnotationArrow(const ON_AnnotationArrow& src) : ON_Geometry(src), m_tail(src.m_tail), m_head(src.m_head)
{}
ON_AnnotationArrow& ON_AnnotationArrow::operator=(const ON_AnnotationArrow& src)
{
if ( this != &src ) {
ON_Geometry::operator=(src);
m_tail = src.m_tail;
m_head = src.m_head;
}
return *this;
}
ON_BOOL32 ON_AnnotationArrow::IsValid( ON_TextLog* text_log ) const
{
bool rc = true;
if (m_tail == m_head)
{
if ( 0 != text_log )
text_log->Print("ON_AnnotationArrow has m_head=m_tail.\n");
rc = false;
}
return rc;
}
void ON_AnnotationArrow::Dump( ON_TextLog& log ) const
{
log.Print("ON_AnnotationArrow: ");
log.Print(m_tail);
log.Print(" to ");
log.Print(m_head);
log.Print("\n");
}
ON_BOOL32 ON_AnnotationArrow::Write( ON_BinaryArchive& file ) const
{
ON_BOOL32 rc = file.Write3dmChunkVersion(1,0);
if (rc) rc = file.WritePoint( m_tail );
if (rc) rc = file.WritePoint( m_head );
return rc;
}
ON_BOOL32 ON_AnnotationArrow::Read(ON_BinaryArchive& file)
{
int major_version = 0;
int minor_version = 0;
ON_BOOL32 rc = file.Read3dmChunkVersion(&major_version,&minor_version);
if ( major_version == 1 ) {
if (rc) rc = file.ReadPoint( m_tail );
if (rc) rc = file.ReadPoint( m_head );
}
else {
rc = false;
}
return rc;
}
ON::object_type ON_AnnotationArrow::ObjectType() const
{
return ON::annotation_object;
}
int ON_AnnotationArrow::Dimension() const
{
return 3;
}
ON_BOOL32 ON_AnnotationArrow::GetBBox( double* boxmin, double* boxmax, ON_BOOL32 bGrowBox ) const
{
ON_BOOL32 rc = ON_GetPointListBoundingBox( 3, false, 1, 3, m_tail, boxmin, boxmax, bGrowBox?true:false );
if (rc)
rc = ON_GetPointListBoundingBox( 3, false, 1, 3, m_head, boxmin, boxmax, true );
return rc;
}
ON_BOOL32 ON_AnnotationArrow::Transform( const ON_Xform& xform )
{
TransformUserData(xform);
m_tail = xform*m_tail;
m_head = xform*m_head;
return true;
}
ON_3dVector ON_AnnotationArrow::Vector() const
{
return (m_head-m_tail);
}
ON_3dPoint ON_AnnotationArrow::Head() const
{
return m_head;
}
ON_3dPoint ON_AnnotationArrow::Tail() const
{
return m_tail;
}

404
extern/opennurbs/opennurbs_annotation.h vendored Executable file
View File

@@ -0,0 +1,404 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_ANNOTATION_INC_)
#define OPENNURBS_ANNOTATION_INC_
class ON_CLASS ON_AnnotationTextDot : public ON_Point
{
// 3d annotation dot with text
ON_OBJECT_DECLARE(ON_AnnotationTextDot);
public:
ON_AnnotationTextDot();
~ON_AnnotationTextDot();
ON_AnnotationTextDot(const ON_AnnotationTextDot&);
ON_AnnotationTextDot& operator=(const ON_AnnotationTextDot&);
/////////////////////////////////////////////////////////////////
//
// ON_Object overrides
//
/*
Description:
Tests an object to see if its data members are correctly
initialized.
Parameters:
text_log - [in] if the object is not valid and text_log
is not NULL, then a brief englis description of the
reason the object is not valid is appened to the log.
The information appended to text_log is suitable for
low-level debugging purposes by programmers and is
not intended to be useful as a high level user
interface tool.
Returns:
@untitled table
true object is valid
false object is invalid, uninitialized, etc.
Remarks:
Overrides virtual ON_Object::IsValid
*/
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
void Dump( ON_TextLog& ) const; // for debugging
ON_BOOL32 Write(
ON_BinaryArchive& // serialize definition to binary archive
) const;
ON_BOOL32 Read(
ON_BinaryArchive& // restore definition from binary archive
);
ON_wString m_text;
};
class ON_CLASS ON_AnnotationArrow : public ON_Geometry
{
// 3d annotation arrow
ON_OBJECT_DECLARE(ON_AnnotationArrow);
public:
ON_AnnotationArrow();
~ON_AnnotationArrow();
ON_AnnotationArrow(const ON_AnnotationArrow&);
ON_AnnotationArrow& operator=(const ON_AnnotationArrow&);
/////////////////////////////////////////////////////////////////
//
// ON_Object overrides
//
/*
Description:
Tests an object to see if its data members are correctly
initialized.
Parameters:
text_log - [in] if the object is not valid and text_log
is not NULL, then a brief englis description of the
reason the object is not valid is appened to the log.
The information appended to text_log is suitable for
low-level debugging purposes by programmers and is
not intended to be useful as a high level user
interface tool.
Returns:
@untitled table
true object is valid
false object is invalid, uninitialized, etc.
Remarks:
Overrides virtual ON_Object::IsValid
*/
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
void Dump( ON_TextLog& ) const; // for debugging
ON_BOOL32 Write(
ON_BinaryArchive& // serialize definition to binary archive
) const;
ON_BOOL32 Read(
ON_BinaryArchive& // restore definition from binary archive
);
ON::object_type ObjectType() const;
/////////////////////////////////////////////////////////////////
//
// ON_Geometry overrides
//
int Dimension() const;
// work horse bounding box getter
ON_BOOL32 GetBBox( // returns true if successful
double*, // boxmin[dim]
double*, // boxmax[dim]
ON_BOOL32 = false // true means grow box
) const;
ON_BOOL32 Transform(
const ON_Xform&
);
/////////////////////////////////////////////////////////////////
//
// Interface
//
ON_3dVector Vector() const;
ON_3dPoint Head() const;
ON_3dPoint Tail() const;
ON_3dPoint m_tail;
ON_3dPoint m_head;
};
////////////////////////////////////////////////////////////////
//
// ON_Annotation - used to serialize definitions of annotation
// objects (dimensions, text blocks, etc.).
//
class ON_CLASS ON_Annotation : public ON_Geometry
{
ON_OBJECT_DECLARE(ON_Annotation);
enum SYMBOLS
{
degreesym = 176,
radiussym = 'R',
diametersym = 216,
plusminussym = 177,
};
public:
virtual ON_BOOL32 IsRealObject() const = 0;
ON_Annotation();
ON_Annotation(const ON_Annotation&);
~ON_Annotation();
ON_Annotation& operator=(const ON_Annotation&);
void Create(); // initialize class's fields assuming
// memory is uninitialized
void Destroy();
void EmergencyDestroy();
/////////////////////////////////////////////////////////////////
//
// ON_Object overrides
//
/*
Description:
Tests an object to see if its data members are correctly
initialized.
Parameters:
text_log - [in] if the object is not valid and text_log
is not NULL, then a brief englis description of the
reason the object is not valid is appened to the log.
The information appended to text_log is suitable for
low-level debugging purposes by programmers and is
not intended to be useful as a high level user
interface tool.
Returns:
@untitled table
true object is valid
false object is invalid, uninitialized, etc.
Remarks:
Overrides virtual ON_Object::IsValid
*/
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
void Dump( ON_TextLog& ) const; // for debugging
ON_BOOL32 Write(
ON_BinaryArchive& // serialize definition to binary archive
) const;
ON_BOOL32 Read(
ON_BinaryArchive& // restore definition from binary archive
);
ON::object_type ObjectType() const;
/////////////////////////////////////////////////////////////////
//
// ON_Geometry overrides
//
int Dimension() const;
ON_BOOL32 GetBBox( // returns true if successful
double*, // boxmin[dim]
double*, // boxmax[dim]
ON_BOOL32 = false // true means grow box
) const;
ON_BOOL32 Transform(
const ON_Xform&
);
/////////////////////////////////////////////////////////////////
//
// ON_Annotation interface
//
// use these to get/set the current annotation settings
static const ON_3dmAnnotationSettings& AnnotationSettings();
static void SetAnnotationSettings( const ON_3dmAnnotationSettings* );
bool IsText() const;
bool IsLeader() const;
bool IsDimension() const;
virtual double NumericValue() const;
virtual void SetTextToDefault();
void SetType( ON::eAnnotationType type );
ON::eAnnotationType Type() const;
void SetTextDisplayMode( ON::eTextDisplayMode mode);
ON::eTextDisplayMode TextDisplayMode() const;
void SetPlane( const ON_Plane& plane );
ON_Plane Plane() const;
int PointCount() const;
void SetPoints( const ON_SimpleArray<ON_2dPoint>& points );
const ON_SimpleArray<ON_2dPoint>& Points() const;
void SetPoint( int idx, ON_3dPoint point );
ON_2dPoint Point( int idx ) const;
void SetUserText( const wchar_t* string );
const ON_wString& UserText() const;
void SetDefaultText( const wchar_t* string );
const ON_wString& DefaultText() const;
void SetUserPositionedText( int bUserPositionedText );
bool UserPositionedText() const;
// to convert world 3d points to and from annotation 2d points
bool GetECStoWCSXform( ON_Xform& xform ) const;
bool GeWCStoECSXform( ON_Xform& xform ) const;
ON::eAnnotationType m_type; // enum for type of annotation
// DimLinear, DimRadius, etc.
ON::eTextDisplayMode m_textdisplaymode; // how the text is displayed
// Horizontal, InLine, AboveLine
ON_Plane m_plane; // ECS reference plane in WCS coordinates
ON_SimpleArray<ON_2dPoint> m_points; // Definition points for the dimension
ON_wString m_usertext; // "<>", or user override
ON_wString m_defaulttext; // The displayed text string
bool m_userpositionedtext; // true: User has positioned text
// false: use default location
};
class ON_CLASS ON_LinearDimension : public ON_Annotation
{
ON_OBJECT_DECLARE(ON_LinearDimension);
public:
ON_BOOL32 IsRealObject() const;
ON_LinearDimension();
ON_LinearDimension(const ON_LinearDimension&);
~ON_LinearDimension();
ON_LinearDimension& operator=(const ON_LinearDimension&);
double NumericValue();
void SetTextToDefault();
void EmergencyDestroy();
};
class ON_CLASS ON_RadialDimension : public ON_Annotation
{
ON_OBJECT_DECLARE(ON_RadialDimension);
public:
ON_BOOL32 IsRealObject() const;
ON_RadialDimension();
ON_RadialDimension(const ON_RadialDimension&);
~ON_RadialDimension();
ON_RadialDimension& operator=(const ON_RadialDimension&);
double NumericValue();
void SetTextToDefault();
void EmergencyDestroy();
};
class ON_CLASS ON_AngularDimension : public ON_Annotation
{
ON_OBJECT_DECLARE(ON_AngularDimension);
public:
ON_BOOL32 IsRealObject() const;
ON_AngularDimension();
ON_AngularDimension(const ON_AngularDimension&);
~ON_AngularDimension();
ON_AngularDimension& operator=(const ON_AngularDimension&);
void EmergencyDestroy();
ON_BOOL32 Write( ON_BinaryArchive& file ) const;
ON_BOOL32 Read( ON_BinaryArchive& file );
void SetAngle( double angle ) { m_angle = angle; }
double Angle() const { return m_angle; }
void SetRadius( double radius ) { m_radius = radius; }
double Radius() const { return m_radius; }
double NumericValue();
void SetTextToDefault();
private:
double m_angle; // angle being dimensioned
double m_radius; // radius for dimension arc
};
class ON_CLASS ON_TextEntity : public ON_Annotation
{
ON_OBJECT_DECLARE(ON_TextEntity);
public:
ON_BOOL32 IsRealObject() const;
ON_TextEntity();
ON_TextEntity(const ON_TextEntity&);
~ON_TextEntity();
ON_TextEntity& operator=(const ON_TextEntity&);
void EmergencyDestroy();
ON_BOOL32 Write( ON_BinaryArchive& file ) const;
ON_BOOL32 Read( ON_BinaryArchive& file );
void SetFaceName( ON_wString string ) { m_facename = string; }
ON_wString FaceName() const { return m_facename; }
void SetFontWeight( int weight ) { m_fontweight = weight; }
int FontWeight() const { return m_fontweight; }
void SetHeight( double height ) { m_height = height; }
double Height() const { return m_height; }
private:
ON_wString m_facename;
int m_fontweight; // windows - 400 = NORMAL )
double m_height; // gets multiplied by dimscale
};
class ON_CLASS ON_Leader : public ON_Annotation
{
ON_OBJECT_DECLARE(ON_Leader);
public:
ON_BOOL32 IsRealObject() const;
ON_Leader();
ON_Leader(const ON_Leader&);
~ON_Leader();
ON_Leader& operator=(const ON_Leader&);
void EmergencyDestroy();
};
#endif

6870
extern/opennurbs/opennurbs_annotation2.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

2346
extern/opennurbs/opennurbs_annotation2.h vendored Executable file

File diff suppressed because it is too large Load Diff

623
extern/opennurbs/opennurbs_arc.cpp vendored Executable file
View File

@@ -0,0 +1,623 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
ON_Arc::ON_Arc() : m_angle(0.0,2.0*ON_PI)
{
radius=1.0;
}
ON_Arc::ON_Arc( const ON_Circle& c, double angle_in_radians )
: m_angle(0.0,2.0*ON_PI)
{
Create( c, angle_in_radians );
}
ON_Arc::ON_Arc( const ON_Circle& c, ON_Interval angle_interval_in_radians )
: m_angle(0.0,2.0*ON_PI)
{
Create( c, angle_interval_in_radians );
}
ON_Arc::ON_Arc( const ON_Plane& p, double r, double angle_in_radians )
: m_angle(0.0,2.0*ON_PI)
{
Create( p, r, angle_in_radians );
}
ON_Arc::ON_Arc( const ON_3dPoint& C, double r, double angle_in_radians )
: m_angle(0.0,2.0*ON_PI)
{
Create( C, r, angle_in_radians );
}
ON_Arc::ON_Arc( const ON_Plane& pln, const ON_3dPoint& C, double r, double angle_in_radians )
: m_angle(0.0,2.0*ON_PI)
{
Create( pln, C, r, angle_in_radians );
}
ON_Arc::ON_Arc( const ON_2dPoint& P, const ON_2dPoint& Q, const ON_2dPoint& R )
: m_angle(0.0,2.0*ON_PI)
{
Create( P, Q, R );
}
ON_Arc::ON_Arc( const ON_3dPoint& P, const ON_3dPoint& Q, const ON_3dPoint& R )
: m_angle(0.0,2.0*ON_PI)
{
Create( P, Q, R );
}
ON_Arc& ON_Arc::operator=( const ON_Circle& c )
{
#if defined(ON_COMPILER_IRIX)
plane = c.plane;
radius = c.radius;
#else
ON_Circle::operator=(c);
#endif
m_angle.Set(0.0,2.0*ON_PI);
return *this;
}
bool ON_Arc::Create(
const ON_Circle& circle,
double angle_radians // angle in radians
)
{
return Create( circle, ON_Interval( 0.0, angle_radians ) );
}
bool ON_Arc::Create(
const ON_Circle& circle,
ON_Interval angle_interval_in_radians
)
{
bool rc = true;
plane = circle.plane;
plane.UpdateEquation();
radius = circle.radius;
m_angle = angle_interval_in_radians;
if ( m_angle.IsDecreasing() )
{
rc = false; // bogus input
// m_angle must never be decreasing
m_angle.Swap();
Reverse();
}
if ( m_angle.Length() > 2.0*ON_PI )
{
rc = false; // bogus input
m_angle.m_t[1] = m_angle.m_t[0] + 2.0*ON_PI;
}
if ( rc )
rc = IsValid();
return rc;
}
bool ON_Arc::Create(
const ON_Plane& pl, // circle is in this plane with center at m_origin
double r, // radius
double angle_radians // angle in radians
)
{
return Create( ON_Circle(pl,r), ON_Interval( 0.0, angle_radians ) );
}
bool ON_Arc::Create( // arc is parallel to XY plane
const ON_3dPoint& center, // center
double r, // radius
double angle_radians // angle in radians
)
{
ON_Plane p;
p.CreateFromNormal( center, ON_zaxis );
return Create( ON_Circle(p,r), ON_Interval( 0.0, angle_radians ) );
}
bool ON_Arc::Create( // arc parallel to a plane
const ON_Plane& pl, // circle will be parallel to this plane
const ON_3dPoint& center, // center
double r, // radius
double angle_radians // angle in radians
)
{
ON_Plane p = pl;
p.origin = center;
p.UpdateEquation();
return Create( ON_Circle( p, r), ON_Interval( 0.0, angle_radians ) );
}
bool ON_Arc::Create( // arc through 3 2d points
const ON_2dPoint& P, // point P
const ON_2dPoint& Q, // point Q
const ON_2dPoint& R // point R
)
{
ON_Circle c(P,Q,R);
double a = 0.0;
c.ClosestPointTo( R, &a );
return Create( c, ON_Interval(0.0,a) );
}
bool ON_Arc::Create( // arc through 3 3d points
const ON_3dPoint& P, // point P
const ON_3dPoint& Q, // point Q
const ON_3dPoint& R // point R
)
{
ON_Circle c;
double a = 0.0;
for (;;)
{
if ( !c.Create(P,Q,R) )
break;
if ( !c.ClosestPointTo( R, &a ) )
break;
if ( !(a > 0.0) )
break;
if ( !Create( c, ON_Interval(0.0,a) ) )
break;
return true;
}
plane = ON_Plane::World_xy;
radius = 0.0;
m_angle.Set(0.0,0.0);
return false;
}
//////////
// Create an arc from a 2d start point, 2d start direction, and 2d end point.
bool ON_Arc::Create(
const ON_2dPoint& P, // [IN] start point
const ON_2dVector& Pdir, // [IN] arc direction at start
const ON_2dPoint& Q // [IN] end point
)
{
return Create( ON_3dPoint(P), ON_3dVector(Pdir), ON_3dPoint(Q) );
}
//////////
// Create an arc from a 3d start point, 3d start direction, and 3d end point.
bool ON_Arc::Create(
const ON_3dPoint& P, // [IN] start point
const ON_3dVector& Pdir, // [IN] arc direction at start
const ON_3dPoint& Q // [IN] end point
)
{
double a=0.0;
bool rc = ON_Circle::Create(P,Pdir,Q);
if ( rc ) {
m_angle.m_t[0] = 0.0;
rc = ON_Circle::ClosestPointTo(Q,&a);
m_angle.m_t[1] = a;
if (a <= ON_ZERO_TOLERANCE || a >= 2.0*ON_PI-ON_ZERO_TOLERANCE )
rc = false;
}
return rc;
}
ON_Arc::~ON_Arc()
{}
void ON_Arc::Dump( ON_TextLog& dump ) const
{
dump.Print("Arc: normal = ");
dump.Print(plane.zaxis);
dump.Print(" center = ");
dump.Print(plane.origin);
dump.Print(" start = ");
dump.Print( StartPoint() );
dump.Print(" end = ");
dump.Print( EndPoint() );
dump.Print(" radius = ");
dump.Print(Radius());
dump.Print(" angle = [");
dump.Print(m_angle[0]);
dump.Print(",");
dump.Print(m_angle[1]);
dump.Print("]\n");
}
ON_3dPoint ON_Arc::StartPoint() const
{
return PointAt(m_angle[0]);
}
ON_3dPoint ON_Arc::MidPoint() const
{
return PointAt(m_angle.Mid());
}
ON_3dPoint ON_Arc::EndPoint() const
{
return PointAt(m_angle[1]);
}
bool ON_Arc::IsValid() const
{
return ( ON_Circle::IsValid()
&& m_angle.IsValid()
&& AngleRadians() > ON_ZERO_TOLERANCE
&& AngleRadians() <= 2.0*ON_PI+ON_ZERO_TOLERANCE)
? true : false;
}
ON_BoundingBox ON_Arc::BoundingBox() const
{
// TODO - compute tight arc bounding box
// Using these knot[] and cv[] arrays makes this function
// not use any heap memory.
double knot[10];
ON_4dPoint cv[9];
ON_NurbsCurve c;
c.m_knot = knot;
c.m_cv = &cv[0].x;
if ( GetNurbForm(c) )
return c.BoundingBox();
return ON_Circle::BoundingBox();
}
bool ON_Arc::GetBoundingBox(
ON_BoundingBox& bbox,
int bGrowBox
) const
{
if (bGrowBox)
{
ON_BoundingBox arc_bbox = BoundingBox();
bbox.Union(arc_bbox);
}
else
bbox = BoundingBox();
return bbox.IsValid();
}
bool ON_Arc::IsCircle() const
{
return (fabs(fabs(AngleRadians()) - 2.0*ON_PI) <= ON_ZERO_TOLERANCE)
? true : false;
}
double ON_Arc::AngleRadians() const
{
return m_angle[1]-m_angle[0];
}
double ON_Arc::AngleDegrees() const
{
return (AngleRadians()/ON_PI)*180.0;
}
ON_Interval ON_Arc::Domain() const
{
return m_angle;
}
ON_Interval ON_Arc::DomainRadians() const
{
return m_angle;
}
ON_Interval ON_Arc::DomainDegrees() const
{
const double rtd = 180.0/ON_PI;
ON_Interval ad = m_angle;
ad.m_t[0] *= rtd;
ad.m_t[1] *= rtd;
return ad;
}
bool ON_Arc::SetAngleRadians( double a )
{
if ( a < 0.0 )
{
double a0 = m_angle.m_t[0];
m_angle.Set(a0+a,a0);
Reverse();
}
else
{
m_angle.m_t[1] = m_angle.m_t[0] + a;
}
return ( fabs(m_angle.Length()) <= 2.0*ON_PI ) ? true : false;
}
bool ON_Arc::SetAngleIntervalRadians( ON_Interval angle_in_radians )
{
bool rc = angle_in_radians.IsIncreasing()
&& angle_in_radians.Length() < (1.0+ON_SQRT_EPSILON)*2.0*ON_PI;
if (rc)
{
m_angle = angle_in_radians;
}
return rc;
}
bool ON_Arc::SetAngleDegrees( double a )
{
return SetAngleRadians( (a/180.0)*ON_PI );
}
bool ON_Arc::Trim( ON_Interval domain)
{
bool ok = false;
if(domain[0]<domain[1] && domain[1]-domain[0]<=2.0 * ON_PI+ON_ZERO_TOLERANCE){
m_angle = domain;
if (m_angle.Length() > 2.0*ON_PI) m_angle[1] = m_angle[0] + 2.0*ON_PI;
ok = true;
}
return ok;
}
bool ON_ArcCurve::IsContinuous(
ON::continuity c,
double t,
int*, // hint - formal parameter intentionally ignored in this virtual function
double, // point_tolerance - formal parameter intentionally ignored in this virtual function
double, // d1_tolerance - formal parameter intentionally ignored in this virtual function
double, // d2_tolerance - formal parameter intentionally ignored in this virtual function
double, // cos_angle_tolerance - formal parameter intentionally ignored in this virtual function
double // curvature_tolerance - formal parameter intentionally ignored in this virtual function
) const
{
// 20 March 2003 Dale Lear
// Added this override of IsContinuous() to
// speed queries and support the
// locus favors of ON::continuity.
bool rc = true;
if ( !IsClosed() )
{
switch(c)
{
case ON::unknown_continuity:
case ON::C0_continuous:
case ON::C1_continuous:
case ON::C2_continuous:
case ON::G1_continuous:
case ON::G2_continuous:
case ON::Cinfinity_continuous:
case ON::Gsmooth_continuous:
// rc = true;
break;
case ON::C0_locus_continuous:
case ON::C1_locus_continuous:
case ON::C2_locus_continuous:
case ON::G1_locus_continuous:
case ON::G2_locus_continuous:
// open arc is locus discontinuous at end parameter.
// By convention (see ON::continuity comments) it
// is locus continuous at start parameter.
if ( t >= Domain()[1] )
rc = false;
break;
}
}
return rc;
}
bool ON_Arc::Reverse()
{
m_angle.Reverse();
plane.yaxis = -plane.yaxis;
plane.zaxis = -plane.zaxis;
plane.UpdateEquation();
return true;
}
double ON_Arc::Length() const
{
return fabs(AngleRadians()*radius);
}
double ON_Arc::SectorArea() const
{
return fabs(0.5*AngleRadians()*radius*radius);
}
ON_3dPoint ON_Arc::SectorAreaCentroid() const
{
double a = 0.5*fabs(AngleRadians());
double d = (a > 0.0) ? sin(a)/a : 0.0;
d *= 2.0*radius/3.0;
a = 0.5*(m_angle[1]+m_angle[0]);
return plane.PointAt(d*cos(a),d*sin(a));
}
double ON_Arc::SegmentArea() const
{
double a = fabs(AngleRadians());
return (0.5*(a - sin(a))*radius*radius);
}
ON_3dPoint ON_Arc::SegmentAreaCentroid() const
{
double a = fabs(AngleRadians());
double sin_halfa = sin(0.5*a);
double d = 3.0*(a - sin(a));
if ( d > 0.0 )
d = (sin_halfa*sin_halfa*sin_halfa)/d;
d *= 4.0*radius;
a = 0.5*(m_angle[1]+m_angle[0]);
return plane.PointAt(d*cos(a),d*sin(a));
}
/* moved to opennurbs_arccurve.cpp
int ON_Arc::GetNurbForm( ON_NurbsCurve& nurbscurve ) const
{
int rc = 0;
if ( IsValid() ) {
if ( IsCircle() )
rc = ON_Circle::GetNurbForm( nurbscurve );
else {
double a, b, c, t, dt, angle;
int span_count, i;
angle = m_angle.Length();
if (angle <= 0.5*ON_PI + ON_ZERO_TOLERANCE) {
span_count = 1;
dt = 0.5;
}
else if (angle <= ON_PI + ON_ZERO_TOLERANCE) {
span_count = 2;
angle *= 0.5;
dt = 0.25;
}
else if (angle <= 1.5*ON_PI + ON_ZERO_TOLERANCE) {
span_count = 3;
angle /= 3.0;
dt = 1.0/6.0;
}
else {
span_count = 4;
angle *= 0.25;
dt = 0.125;
}
nurbscurve.Create( 3, true, 3, 2*span_count+1 );
ON_4dPoint* CV = (ON_4dPoint*)nurbscurve.m_cv;
t = m_angle[0];
for ( i = 0; i < span_count; i++ ) {
nurbscurve.m_knot[2*i] = t;
nurbscurve.m_knot[2*i+1] = t;
CV[2*i] = PointAt(m_angle.ParameterAt(t));
t += dt;
CV[2*i+1] = PointAt(m_angle.ParameterAt(t));
t += dt;
}
span_count *= 2;
t = m_angle[1];
CV[span_count] = PointAt(t);
nurbscurve.m_knot[span_count] = t;
nurbscurve.m_knot[span_count+1] = t;
a = cos(0.5*angle);
b = a - 1.0;
c = radius*angle;
for (i = 1; i < span_count; i += 2) {
CV[i].x += b * plane.origin.x;
CV[i].y += b * plane.origin.y;
CV[i].z += b * plane.origin.z;
CV[i].w = a;
}
//for ( i = 1; i < span_count; i += 2 ) {
// t = CV[i].w;
// c = 1.0/t;
// a = CV[i].x*c; b = ArcDeFuzz(a); if ( a != b ) CV[i].x = b*t;
// a = CV[i].y*c; b = ArcDeFuzz(a); if ( a != b ) CV[i].y = b*t;
// a = CV[i].z*c; b = ArcDeFuzz(a); if ( a != b ) CV[i].z = b*t;
//}
}
rc = 2;
}
return rc;
}
*/
// returns parameters of point on arc that is closest to given point
bool ON_Arc::ClosestPointTo(
const ON_3dPoint& pt,
double* t
) const
{
/*
double tt, a;
if ( !t )
t =&tt;
ON_BOOL32 rc = ON_Circle::ClosestPointTo(pt,t);
if (rc) {
if ( *t < m_angle[0] ) {
a = 0.5*(m_angle[0] + m_angle[1] - 2.0*ON_PI);
if ( *t < a )
*t = m_angle[1];
else
*t = m_angle[0];
}
else if ( *t > m_angle[1] ) {
a = 0.5*(m_angle[0] + m_angle[1] + 2.0*ON_PI);
if ( *t > a )
*t = m_angle[0];
else
*t = m_angle[1];
}
}
*/
double s;
double twopi = 2.0*ON_PI;
bool rc = ON_Circle::ClosestPointTo(pt,&s);
if (rc){
s -= m_angle[0];
while (s < 0.0) s += twopi;
// Greg Arden April 14 2003. Changed test from ">" to ">=" this ensures that
// closest point to a circle at the seam will return the least parameter value.
while (s >= twopi) s -= twopi;
double s1 = m_angle.Length();
if (s < 0.0) s = 0.0;//shouldn't happen
if (s > s1){
if (s > 0.5*s1 + ON_PI)
s = 0.0;
else
s = s1;
}
if (t)
*t = m_angle[0] + s;
}
return rc;
}
// returns point on circle that is arc to given point
ON_3dPoint ON_Arc::ClosestPointTo(
const ON_3dPoint& pt
) const
{
double t = m_angle[0];
ClosestPointTo( pt, &t );
return PointAt(t);
}

600
extern/opennurbs/opennurbs_arc.h vendored Executable file
View File

@@ -0,0 +1,600 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(ON_ARC_INC_)
#define ON_ARC_INC_
/*
Description:
An ON_Arc is a subcurve of 3d circle.
Details:
The curve is parameterized by an angle expressed in radians. For an IsValid() arc
the total subtended angle AngleRadians() = Domain()(1) - Domain()(0) must satisfy
0< AngleRadians() <2*Pi .
The parameterization of the ON_Arc is inherited from the ON_Circle it is derived from.
In particular
t -> center + cos(t)*radius*xaxis + sin(t)*radius*yaxis
where xaxis and yaxis, (part of ON_Circle::m_plane) form an othonormal frame of the plane
containing the circle.
*/
class ON_CLASS ON_Arc : public ON_Circle
{
public:
// Create a radius one arc with angle = 2*pi
ON_Arc();
/*
Description:
Construct an arc from a circle and an angle in radians
Parameters:
circle - [in]
angle_in_radians - [in]
*/
ON_Arc(
const ON_Circle& circle,
double angle_in_radians
);
/*
Parameters:
circle - [in]
angle_interval_in_radians - [in] increasing angle interval
in radians with angle_interval_in_radians.Length() <= 2.0*ON_PI.
*/
ON_Arc(
const ON_Circle& circle,
ON_Interval angle_interval_in_radians
);
/*
Description:
Construct an arc from a plane, radius and an angle in radians.
The center of the arc is at the plane's origin.
Parameters:
plane - [in]
circle is in this plane with center at m_origin
center - [in]
circle's center point
radius - [in]
angle_in_radians - [in]
*/
ON_Arc(
const ON_Plane& plane,
double radius,
double angle_in_radians
);
/*
Description:
Construct an arc parallel to the world XY plane from a
center point, radius, and angle in radians.
The arc starts at center+(radius,0,0).
Parameters:
center - [in]
radius - [in]
angle_in_radians - [in]
*/
ON_Arc(
const ON_3dPoint& center,
double radius,
double angle_in_radians
);
/*
Description:
Construct an arc parallel to plane from a center point,
radius, and angle in radians.
The arc starts at center+radius*plane.xaxis.
Parameters:
plane - [in]
The plane x, y and z axis are used to defines the circle
plane's x, y and z axis. The plane origin is ignorned.
center - [in]
circle's center point
radius - [in]
angle_in_radians - [in]
*/
ON_Arc(
const ON_Plane& plane,
const ON_3dPoint& center,
double radius,
double angle_in_radians
);
/*
Description:
Construct an arc that passes through three 2d points.
Parameters:
start_point - [in]
interior_point - [in]
end_point - [in]
*/
ON_Arc(
const ON_2dPoint& start_point,
const ON_2dPoint& interior_point,
const ON_2dPoint& end_point
);
/*
Description:
Construct an arc that passes through three 3d points.
Parameters:
start_point - [in]
interior_point - [in]
end_point - [in]
*/
ON_Arc(
const ON_3dPoint& start_point,
const ON_3dPoint& interior_point,
const ON_3dPoint& end_point
);
/*
Description:
Create an arc from a circle and an angle in radians
Parameters:
circle - [in]
angle_in_radians - [in]
Returns:
true if input is valid and a valid arc is created.
*/
bool Create(
const ON_Circle& circle,
double angle_in_radians
);
/*
Description:
Create an arc from a circle and an increasing angle interval
Parameters:
circle - [in]
angle_interval_in_radians - [in] increasing angle interval in radians
with angle_interval_in_radians.Length() <= 2.0*ON_PI
Returns:
true if input is valid and a valid arc is created.
*/
bool Create(
const ON_Circle& circle,
ON_Interval angle_interval_in_radians
);
/*
Description:
Create an arc from a plane, radius and an angle in radians.
The center of the arc is at the plane's origin.
Parameters:
plane - [in]
circle is in this plane with center at m_origin
center - [in]
circle's center point
radius - [in]
angle_in_radians - [in]
*/
bool Create(
const ON_Plane& plane,
double radius,
double angle_in_radians
);
/*
Description:
Create an arc parallel to the world XY plane from a
center point, radius, and angle in radians.
The arc starts at center+(radius,0,0).
Parameters:
center - [in]
radius - [in]
angle_in_radians - [in]
*/
bool Create(
const ON_3dPoint& center,
double radius,
double angle_in_radians
);
/*
Description:
Create an arc parallel to plane from a center point,
radius, and angle in radians.
The arc starts at center+radius*plane.xaxis.
Parameters:
plane - [in]
The plane x, y and z axis are used to defines the circle
plane's x, y and z axis. The plane origin is ignorned.
center - [in]
circle's center point
radius - [in]
angle_in_radians - [in]
*/
bool Create(
const ON_Plane& plane,
const ON_3dPoint& center,
double radius,
double angle_in_radians
);
/*
Description:
Create an arc that passes through three 2d points.
Parameters:
start_point - [in]
interior_point - [in]
end_point - [in]
*/
bool Create(
const ON_2dPoint& start_point,
const ON_2dPoint& interior_point,
const ON_2dPoint& end_point
);
/*
Description:
Create an arc that passes through three 3d points.
Parameters:
start_point - [in]
interior_point - [in]
end_point - [in]
*/
bool Create(
const ON_3dPoint& start_point,
const ON_3dPoint& interior_point,
const ON_3dPoint& end_point
);
/*
Description:
Create an arc from a 2d start point, 2d start direction
and a 2d end point.
Parameters:
start_point - [in]
dir_at_start - [in]
end_point - [in]
*/
bool Create(
const ON_2dPoint& start_point,
const ON_2dVector& dir_at_start,
const ON_2dPoint& end_point
);
/*
Description:
Create an arc from a 3d start point, 3d start direction
and a 3d end point.
Parameters:
start_point - [in]
dir_at_start - [in]
end_point - [in]
*/
bool Create(
const ON_3dPoint& start_point,
const ON_3dVector& dir_at_start,
const ON_3dPoint& end_point
);
ON_Arc& operator=( const ON_Circle& );
~ON_Arc();
// Description:
// Creates a text dump of the arc listing the normal, center
// radius, start point, end point, and angle.
// Remarks:
// Dump() is intended for debugging and is not suitable
// for creating high quality text descriptions of an
// arc.
void Dump( ON_TextLog& dump ) const;
// Description:
// Checks an arc to make sure it is valid.
// Detail:
// Radius>0 and 0<AngleRadians()<=2 ON_PI
// Returns:
// true if the arc is valid.
bool IsValid() const;
// Description:
// Get arc's 3d axis aligned bounding box.
// Returns:
// 3d bounding box.
ON_BoundingBox BoundingBox() const;
// Description:
// Get arc's 3d axis aligned bounding box or the
// union of the input box with the arc's bounding box.
// Parameters:
// bbox - [in/out] 3d axis aligned bounding box
// bGrowBox - [in] (default=false)
// If true, then the union of the input bbox and the
// arc's bounding box is returned in bbox.
// If false, the arc's bounding box is returned in bbox.
// Returns:
// true if arc has bounding box and calculation was successful.
bool GetBoundingBox(
ON_BoundingBox& bbox,
int bGrowBox = false
) const;
/*
Description:
Get tight bounding box.
Parameters:
tight_bbox - [in/out] tight bounding box
bGrowBox -[in] (default=false)
If true and the input tight_bbox is valid, then returned
tight_bbox is the union of the input tight_bbox and the
arc's tight bounding box.
xform -[in] (default=NULL)
If not NULL, the tight bounding box of the transformed
arc is calculated. The arc is not modified.
Returns:
True if a valid tight_bbox is returned.
*/
bool GetTightBoundingBox(
ON_BoundingBox& tight_bbox,
int bGrowBox = false,
const ON_Xform* xform = 0
) const;
// Returns:
// true if the arc is a complete circle; i.e., the arc's
// angle is 360 degrees.
bool IsCircle() const;
// Returns:
// The arc's subtended angle in radians.
double AngleRadians() const;
// Returns:
// The arc's subtended angle in degrees.
double AngleDegrees() const;
/*
Description:
Get evaluation domain.
Returns:
Evaluation domain (same as DomainRadians()).
*/
ON_Interval Domain() const;
// Returns:
// The arc's domain in radians.
ON_Interval DomainRadians() const;
// Returns:
// The arc's domain in degrees.
ON_Interval DomainDegrees() const;
// Description:
// Set arc's subtended angle in radians.
// Parameters:
// angle_in_radians - [in] 0 <= angle_in_radians <= 2.0*ON_PI
//
bool SetAngleRadians(
double angle_in_radians
);
/*
Description:
Set arc's angle interval in radians.
Parameters:
angle_in_radians - [in] increasing interval with
start and end angle in radians.
Length of the interval <= 2.0*ON_PI.
Returns:
true if successful.
*/
bool SetAngleIntervalRadians(
ON_Interval angle_in_radians
);
// Description:
// Set arc's domain as a subdomain of the circle.
// Parameters:
// domain_radian - [in] 0 < domain_radian[1] - domain_radian[0] <= 2.0 * ON*PI
//
bool Trim(
ON_Interval domain_radian
);
// Description:
// Set arc's subtended angle in degrees.
// Parameters:
// angle_in_degrees - [in] 0 < angle_in_degrees <= 360
bool SetAngleDegrees(
double angle_in_degrees
);
// Returns:
// Point at start of the arc.
ON_3dPoint StartPoint() const;
// Returns:
// Point at middle of the arc.
ON_3dPoint MidPoint() const;
// Returns:
// Point at end of the arc.
ON_3dPoint EndPoint() const;
// Description:
// Get the point on the arc that is closest to test_point.
// Parameters:
// test_point - [in]
// t - [out] parameter (in radians) of the point on the arc that
// is closest to test_point. If test_point is the center
// of the arc, then the starting point of the arc is
// (arc.Domain()[0]) returned.
bool ClosestPointTo(
const ON_3dPoint& test_point,
double* t
) const;
// Description:
// Get the point on the arc that is closest to test_point.
// Parameters:
// test_point - [in]
// Returns:
// The point on the arc that is closest to test_point.
// If test_point is the center of the arc, then the
// starting point of the arc is returned.
ON_3dPoint ClosestPointTo(
const ON_3dPoint& test_point
) const;
// Returns:
// Length of the arc = radius*(subtended angle in radians).
double Length() const;
/*
Returns:
Area of the arc's sector.
Remarks:
The arc's sector is the region bounded by the arc,
the line segment from the arc's end to the center,
and the line segment from the center to the arc's
start.
*/
double SectorArea() const;
/*
Returns:
Area centroid of the arc's sector.
Remarks:
The arc's sector is the region bounded by the arc,
the line segment from the arc's end to the center,
and the line segment from the center to the arc's
start.
*/
ON_3dPoint SectorAreaCentroid() const;
/*
Returns:
Area of the arc's segment.
Remarks:
The arc's segment is the region bounded by the arc and
the line segment from the arc's end to the arc's start.
*/
double SegmentArea() const;
/*
Returns:
Area centroid of the arc's segment.
Remarks:
The arc's segment is the region bounded by the arc and
the line segment from the arc's end to the arc's start.
*/
ON_3dPoint SegmentAreaCentroid() const;
// Description:
// Reverse the orientation of the arc. Changes the domain
// from [a,b] to [-b.-a].
bool Reverse();
// Description:
// Get a rational degree 2 NURBS curve representation
// of the arc. Note that the parameterization of NURBS curve
// does not match arc's transcendental paramaterization.
// Use GetRadianFromNurbFormParameter() and
// GetParameterFromRadian() to convert between the NURBS curve
// parameter and the transcendental parameter
// Parameters:
// nurbs_curve - [out] nurbs_curve returned here.
// Returns:
// 0 for failure and 2 for success.
int GetNurbForm(
ON_NurbsCurve& nurbs_curve
) const;
/*
Description:
Convert a NURBS curve arc parameter to a arc radians parameter.
Parameters:
nurbs_parameter - [in]
arc_radians_parameter - [out]
Example:
ON_Arc arc = ...;
double nurbs_t = 1.2345; // some number in interval (0,2.0*ON_PI).
double arc_t;
arc.GetRadianFromNurbFormParameter( nurbs_t, &arc_t );
ON_NurbsCurve nurbs_curve;
arc.GetNurbsForm( nurbs_curve );
arc_pt = arc.PointAt(arc_t);
nurbs_pt = nurbs_curve.PointAt(nurbs_t);
// arc_pt and nurbs_pt will be the same
Remarks:
The NURBS curve parameter is with respect to the NURBS curve
created by ON_Arc::GetNurbForm. At nurbs parameter values of
0.0, 0.5*ON_PI, ON_PI, 1.5*ON_PI, and 2.0*ON_PI, the nurbs
parameter and radian parameter are the same. At all other
values the nurbs and radian parameter values are different.
See Also:
ON_Arc::GetNurbFormParameterFromRadian
*/
bool GetRadianFromNurbFormParameter(
double nurbs_parameter,
double* arc_radians_parameter
) const;
/*
Description:
Convert a arc radians parameter to a NURBS curve arc parameter.
Parameters:
arc_radians_parameter - [in] 0.0 to 2.0*ON_PI
nurbs_parameter - [out]
Example:
ON_Arc arc = ...;
double arc_t = 1.2345; // some number in interval (0,2.0*ON_PI).
double nurbs_t;
arc.GetNurbFormParameterFromRadian( arc_t, &nurbs_t );
ON_NurbsCurve nurbs_curve;
arc.GetNurbsForm( nurbs_curve );
arc_pt = arc.PointAt(arc_t);
nurbs_pt = nurbs_curve.PointAt(nurbs_t);
// arc_pt and nurbs_pt will be the same
Remarks:
The NURBS curve parameter is with respect to the NURBS curve
created by ON_Arc::GetNurbForm. At radian values of
0.0, 0.5*ON_PI, ON_PI, 1.5*ON_PI, and 2.0*ON_PI, the nurbs
parameter and radian parameter are the same. At all other
values the nurbs and radian parameter values are different.
See Also:
ON_Arc::GetNurbFormParameterFromRadian
*/
bool GetNurbFormParameterFromRadian(
double arc_radians_parameter,
double* nurbs_parameter
) const;
private:
friend bool ON_BinaryArchive::ReadArc( ON_Arc& );
friend bool ON_BinaryArchive::WriteArc( const ON_Arc& );
// increasing interval with start and end angle in radians
ON_Interval m_angle;
};
#endif

1181
extern/opennurbs/opennurbs_arccurve.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

425
extern/opennurbs/opennurbs_arccurve.h vendored Executable file
View File

@@ -0,0 +1,425 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(ON_GEOMETRY_CURVE_ARC_INC_)
#define ON_GEOMETRY_CURVE_ARC_INC_
/*
Description:
ON_ArcCurve is used to represent arcs and circles.
ON_ArcCurve.IsCircle() returns true if the curve
is a complete circle.
Details:
an ON_ArcCurve is a subcurve of a circle, with a
constant speed parameterization. The parameterization is
an affine linear reparameterzation of the underlying arc
m_arc onto the domain m_t.
A valid ON_ArcCurve has Radius()>0 and 0<AngleRadians()<=2*PI
and a strictly increasing Domain().
*/
class ON_CLASS ON_ArcCurve : public ON_Curve
{
ON_OBJECT_DECLARE(ON_ArcCurve);
public:
ON_ArcCurve();
ON_ArcCurve(const ON_ArcCurve&);
virtual ~ON_ArcCurve();
// virtual ON_Object::SizeOf override
unsigned int SizeOf() const;
// virtual ON_Object::DataCRC override
ON__UINT32 DataCRC(ON__UINT32 current_remainder) const;
/*
Description:
Create an arc curve with domain (0,arc.Length()).
*/
ON_ArcCurve(
const ON_Arc& arc
);
/*
Description:
Create an arc curve with domain (t0,t1)
*/
ON_ArcCurve(
const ON_Arc& arc,
double t0,
double t1
);
/*
Description:
Creates a curve that is a complete circle with
domain (0,circle.Length()).
*/
ON_ArcCurve(
const ON_Circle& circle
);
/*
Description:
Creates a curve that is a complete circle with domain (t0,t1).
*/
ON_ArcCurve(
const ON_Circle& circle,
double t0,
double t1
);
ON_ArcCurve& operator=(const ON_ArcCurve&);
/*
Description:
Create an arc curve with domain (0,arc.Length()).
*/
ON_ArcCurve& operator=(const ON_Arc& arc);
/*
Description:
Creates a curve that is a complete circle with
domain (0,circle.Length()).
*/
ON_ArcCurve& operator=(const ON_Circle& circle);
/////////////////////////////////////////////////////////////////
// ON_Object overrides
/*
Description:
A valid ON_ArcCurve has Radius()>0 and 0<AngleRadians()<=2*PI
and a strictly increasing Domain().
Parameters:
text_log - [in] if the object is not valid and text_log
is not NULL, then a brief englis description of the
reason the object is not valid is appened to the log.
The information appended to text_log is suitable for
low-level debugging purposes by programmers and is
not intended to be useful as a high level user
interface tool.
Returns:
@untitled table
true object is valid
false object is invalid, uninitialized, etc.
Remarks:
Overrides virtual ON_Object::IsValid
*/
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
void Dump( ON_TextLog& ) const;
ON_BOOL32 Write(
ON_BinaryArchive& // open binary file
) const;
ON_BOOL32 Read(
ON_BinaryArchive& // open binary file
);
/////////////////////////////////////////////////////////////////
// ON_Geometry overrides
int Dimension() const;
ON_BOOL32 GetBBox( // returns true if successful
double*, // minimum
double*, // maximum
ON_BOOL32 = false // true means grow box
) const;
/*
Description:
Get tight bounding box of the arc.
Parameters:
tight_bbox - [in/out] tight bounding box
bGrowBox -[in] (default=false)
If true and the input tight_bbox is valid, then returned
tight_bbox is the union of the input tight_bbox and the
arc's tight bounding box.
xform -[in] (default=NULL)
If not NULL, the tight bounding box of the transformed
arc is calculated. The arc is not modified.
Returns:
True if the returned tight_bbox is set to a valid
bounding box.
*/
bool GetTightBoundingBox(
ON_BoundingBox& tight_bbox,
int bGrowBox = false,
const ON_Xform* xform = 0
) const;
ON_BOOL32 Transform(
const ON_Xform&
);
/////////////////////////////////////////////////////////////////
// ON_Curve overrides
// Description:
// virtual ON_Curve::SetDomain override.
// Set the domain of the curve
// Parameters:
// t0 - [in]
// t1 - [in] new domain will be [t0,t1]
// Returns:
// true if successful.
ON_BOOL32 SetDomain(
double t0,
double t1
);
ON_Interval Domain() const;
bool ChangeDimension(
int desired_dimension
);
ON_BOOL32 ChangeClosedCurveSeam(
double t
);
int SpanCount() const; // number of smooth spans in curve
ON_BOOL32 GetSpanVector( // span "knots"
double* // array of length SpanCount() + 1
) const; //
int Degree( // returns maximum algebraic degree of any span
// ( or a good estimate if curve spans are not algebraic )
) const;
ON_BOOL32 IsLinear( // true if curve locus is a line segment between
// between specified points
double = ON_ZERO_TOLERANCE // tolerance to use when checking linearity
) const;
ON_BOOL32 IsArc( // ON_Arc.m_angle > 0 if curve locus is an arc between
// specified points
const ON_Plane* = NULL, // if not NULL, test is performed in this plane
ON_Arc* = NULL, // if not NULL and true is returned, then arc parameters
// are filled in
double = 0.0 // tolerance to use when checking
) const;
ON_BOOL32 IsPlanar(
ON_Plane* = NULL, // if not NULL and true is returned, then plane parameters
// are filled in
double = 0.0 // tolerance to use when checking
) const;
ON_BOOL32 IsInPlane(
const ON_Plane&, // plane to test
double = 0.0 // tolerance to use when checking
) const;
ON_BOOL32 IsClosed( // true if curve is closed (either curve has
void // clamped end knots and euclidean location of start
) const; // CV = euclidean location of end CV, or curve is
// periodic.)
ON_BOOL32 IsPeriodic( // true if curve is a single periodic segment
void
) const;
bool IsContinuous(
ON::continuity c,
double t,
int* hint = NULL,
double point_tolerance=ON_ZERO_TOLERANCE,
double d1_tolerance=ON_ZERO_TOLERANCE,
double d2_tolerance=ON_ZERO_TOLERANCE,
double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
double curvature_tolerance=ON_SQRT_EPSILON
) const;
ON_BOOL32 Reverse(); // reverse parameterizatrion
// Domain changes from [a,b] to [-b,-a]
/*
Description:
Force the curve to start at a specified point.
Parameters:
start_point - [in]
Returns:
true if successful.
Remarks:
Some end points cannot be moved. Be sure to check return
code.
See Also:
ON_Curve::SetEndPoint
ON_Curve::PointAtStart
ON_Curve::PointAtEnd
*/
ON_BOOL32 SetStartPoint(
ON_3dPoint start_point
);
/*
Description:
Force the curve to end at a specified point.
Parameters:
end_point - [in]
Returns:
true if successful.
Remarks:
Some end points cannot be moved. Be sure to check return
code.
See Also:
ON_Curve::SetStartPoint
ON_Curve::PointAtStart
ON_Curve::PointAtEnd
*/
ON_BOOL32 SetEndPoint(
ON_3dPoint end_point
);
ON_BOOL32 Evaluate( // returns false if unable to evaluate
double, // evaluation parameter
int, // number of derivatives (>=0)
int, // array stride (>=Dimension())
double*, // array of length stride*(ndir+1)
int = 0, // optional - determines which side to evaluate from
// 0 = default
// < 0 to evaluate from below,
// > 0 to evaluate from above
int* = 0 // optional - evaluation hint (int) used to speed
// repeated evaluations
) const;
ON_BOOL32 Trim( const ON_Interval& );
// Description:
// Where possible, analytically extends curve to include domain.
// Parameters:
// domain - [in] if domain is not included in curve domain,
// curve will be extended so that its domain includes domain.
// Will not work if curve is closed. Original curve is identical
// to the restriction of the resulting curve to the original curve domain,
// Returns:
// true if successful.
bool Extend(
const ON_Interval& domain
);
/*
Description:
Splits (divides) the arc at the specified parameter.
The parameter must be in the interior of the arc's domain.
The ON_Curve pointers passed to ON_ArcCurve::Split must
either be NULL or point to ON_ArcCurve objects.
If a pointer is NULL, then an ON_ArcCurve will be created
in Split(). You may pass "this" as left_side or right_side.
Parameters:
t - [in] parameter to split the curve at in the
interval returned by Domain().
left_side - [out] left portion of curve returned here.
If not NULL, left_side must point to an ON_ArcCuve.
right_side - [out] right portion of curve returned here
If not NULL, right_side must point to an ON_ArcCuve.
Remarks:
Overrides virtual ON_Curve::Split.
*/
virtual
ON_BOOL32 Split(
double t,
ON_Curve*& left_side,
ON_Curve*& right_side
) const;
// virtual ON_Curve::GetNurbForm override
int GetNurbForm( // returns 0: unable to create NURBS representation
// with desired accuracy.
// 1: success - returned NURBS parameterization
// matches the curve's to wthe desired accuracy
// 2: success - returned NURBS point locus matches
// the curve's to the desired accuracy but, on
// the interior of the curve's domain, the
// curve's parameterization and the NURBS
// parameterization may not match to the
// desired accuracy.
ON_NurbsCurve&,
double = 0.0,
const ON_Interval* = NULL // OPTIONAL subdomain of arc curve
) const;
// virtual ON_Curve::HasNurbForm override
int HasNurbForm( // returns 0: unable to create NURBS representation
// with desired accuracy.
// 1: success - NURBS parameterization
// matches the curve's
// 2: success - returned NURBS point locus matches
// the curve'sbut, on
// the interior of the curve's domain, the
// curve's parameterization and the NURBS
// parameterization may not match to the
// desired accuracy.
) const;
// virtual ON_Curve::GetCurveParameterFromNurbFormParameter override
ON_BOOL32 GetCurveParameterFromNurbFormParameter(
double, // nurbs_t
double* // curve_t
) const;
// virtual ON_Curve::GetNurbFormParameterFromCurveParameter override
ON_BOOL32 GetNurbFormParameterFromCurveParameter(
double, // curve_t
double* // nurbs_t
) const;
/*
Description:
Returns true if this arc curve is a complete circle.
*/
bool IsCircle() const;
// Returns:
// The arc's radius.
double Radius() const;
// Returns:
// The arc's subtended angle in radians.
double AngleRadians() const;
// Returns:
// The arc's subtended angle in degrees.
double AngleDegrees() const;
/////////////////////////////////////////////////////////////////
ON_Arc m_arc;
// evaluation domain (always increasing)
// ( m_t[i] corresponds to m_arc.m_angle[i] )
ON_Interval m_t;
// The dimension of a arc curve can be 2 or 3.
// (2 so ON_ArcCurve can be used as a trimming curve)
int m_dim;
};
#endif

15617
extern/opennurbs/opennurbs_archive.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

3084
extern/opennurbs/opennurbs_archive.h vendored Executable file

File diff suppressed because it is too large Load Diff

1532
extern/opennurbs/opennurbs_array.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

1832
extern/opennurbs/opennurbs_array.h vendored Executable file

File diff suppressed because it is too large Load Diff

1752
extern/opennurbs/opennurbs_array_defs.h vendored Executable file

File diff suppressed because it is too large Load Diff

247
extern/opennurbs/opennurbs_base32.cpp vendored Executable file
View File

@@ -0,0 +1,247 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
bool ON_Base32ToString( const ON_SimpleArray<unsigned char>& base32_digits, ON_String& sBase32 )
{
int digit_count = base32_digits.Count();
sBase32.ReserveArray(digit_count);
sBase32.SetLength(digit_count);
bool rc = ON_Base32ToString( base32_digits, digit_count, sBase32.Array() );
if (!rc)
sBase32.SetLength(0);
return rc;
}
bool ON_Base32ToString( const ON_SimpleArray<unsigned char>& base32_digits, ON_wString& sBase32 )
{
ON_String s;
bool rc = ON_Base32ToString( base32_digits, s );
if (rc)
sBase32 = s;
return rc;
}
bool ON_Base32ToString( const unsigned char* base32_digits, int base32_digit_count, char* sBase32 )
{
const char* base32_digit_symbol = "0123456789ABCDEFGHJKMNPQRTUVWXYZ";
const char error_symbol = '#';
unsigned char d;
bool rc = false;
if ( 0 == sBase32 )
return false;
if ( 0 == base32_digits || base32_digit_count <= 0 )
{
*sBase32++ = error_symbol;
}
else
{
rc = true;
while(base32_digit_count--)
{
d = *base32_digits++;
if ( d < 32 )
{
*sBase32++ = base32_digit_symbol[d];
}
else
{
rc = false;
*sBase32++ = error_symbol;
}
}
}
*sBase32 = 0; // NULL terminate string
return rc;
}
int ON_CorrectBase32StringTypos( const char* sBase32, ON_String& sBase32clean )
{
char* sClean = 0;
if ( sBase32 == sBase32clean.Array() )
sClean = sBase32clean.Array();
else
{
sBase32clean.SetLength(0);
sBase32clean.ReserveArray(strlen(sBase32));
sClean = sBase32clean.Array();
}
int length = ON_CorrectBase32StringTypos( sBase32, sClean );
sBase32clean.SetLength(length);
return length;
}
int ON_CorrectBase32StringTypos( const wchar_t* sBase32, ON_wString& sBase32clean )
{
if ( 0 == sBase32 || 0 == sBase32[0] )
return 0;
ON_String s = sBase32;
int length = ON_CorrectBase32StringTypos(s.Array(),s.Array());
if ( length > 0 )
sBase32clean = s;
else
sBase32clean.SetLength(0);
return length;
}
int ON_CorrectBase32StringTypos( const char* sBase32, char* sBase32clean )
{
char c;
int length = 0;
if ( 0 == sBase32clean )
return 0;
if (0 != sBase32 )
{
while ( 0 != (c = *sBase32++) )
{
if ( c >= '0' && c <= '9' )
{
sBase32clean[length++] = c;
}
else
{
if ( c >= 'a' && c < 'z' )
c -= 'a'-'A';
if ( 'I' == c || 'L' == c )
c = '1';
else if ('O' == c )
c = '0';
else if ( 'S' == c )
c = '5';
else if ( c < 'A' || c > 'Z' )
{
length = 0;
break;
}
sBase32clean[length++] = c;
}
}
}
sBase32clean[length] = 0;
return length;
}
int ON_StringToBase32(const ON_wString& sBase32, ON_SimpleArray<unsigned char>& base32_digits )
{
ON_String s(sBase32);
return ON_StringToBase32(s,base32_digits);
}
int ON_StringToBase32(const ON_String& sBase32, ON_SimpleArray<unsigned char>& base32_digits )
{
const char* s = sBase32;
if ( 0 == s || 0 == s[0] )
return 0;
base32_digits.Reserve(sBase32.Length());
int digit_count = ON_StringToBase32(sBase32,base32_digits.Array());
base32_digits.SetCount(digit_count);
return digit_count;
}
int ON_StringToBase32(const char* sBase32, unsigned char* base32_digits )
{
char c;
int digit_count = 0;
if ( 0 == base32_digits )
return 0;
if ( 0 != sBase32 )
{
while ( 0 != (c = *sBase32++) )
{
if (c >= '0' && c <= '9' )
base32_digits[digit_count++] = c - '0';
else if ( c >= 'A' && c <= 'H' )
base32_digits[digit_count++] = 10 + c - 'A';
else if ( c >= 'J' && c <= 'K' )
base32_digits[digit_count++] = 9 + c - 'A';
else if ( c >= 'M' && c <= 'N' )
base32_digits[digit_count++] = 8 + c - 'A';
else if ( c >= 'P' && c <= 'R' )
base32_digits[digit_count++] = 7 + c - 'A';
else if ( c >= 'T' && c <= 'Z' )
base32_digits[digit_count++] = 6 + c - 'A';
else
{
digit_count = 0;
break;
}
}
}
return digit_count;
}
int ON_GetBase32Digits( const ON_SimpleArray<unsigned char>& x, ON_SimpleArray<unsigned char>& base32_digits )
{
int x_count = x.Count();
int bit_count = 8*x_count;
int base32_digit_count = (bit_count/5) + ((bit_count%5)?1:0);
base32_digits.Reserve(base32_digit_count);
base32_digit_count = ON_GetBase32Digits( x.Array(), x_count, base32_digits.Array() );
base32_digits.SetCount(base32_digit_count);
return base32_digit_count;
}
int ON_GetBase32Digits( const unsigned char* x, int x_count, unsigned char* base32_digits )
{
int x_bit_count = 8*x_count;
unsigned char mask, c;
unsigned char bits[5] = {0,0,0,0,0};
unsigned int bits_count = 0;
unsigned int base32_digit_count = 0;
int i;
if ( 0 == base32_digits || 0 == x || x_count <= 0 )
return 0;
if ( x == base32_digits )
{
unsigned char* tmp = (unsigned char*)onmalloc(x_count*sizeof(x[0]));
if ( 0 == tmp )
return 0;
memcpy(tmp,x,x_count*sizeof(x[0]));
i = ON_GetBase32Digits(tmp,x_count,base32_digits);
onfree(tmp);
return i;
}
i = x_bit_count % 5;
if ( i )
bits_count = 5-i;
for ( i = 0; i < x_count; i++)
{
c = x[i];
for (mask = 128; 0 != mask; mask /= 2 )
{
bits[bits_count++] = (0 != (c & mask)) ? 1 : 0;
if ( 5 == bits_count )
{
base32_digits[base32_digit_count++] = 16*bits[0] + 8*bits[1] + 4*bits[2] + 2*bits[3] + bits[4];
bits_count = 0;
}
}
}
return base32_digit_count;
}

126
extern/opennurbs/opennurbs_base32.h vendored Executable file
View File

@@ -0,0 +1,126 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(ON_BASE32_INC_)
#define ON_BASE32_INC_
/*
Description:
Convert a number into base32 digits.
Parameters:
x - [in]
x_count - [in]
x[] is an array of length x_count and represents the value
x[0]*2^(8*(x_count-1)) + ... + x[x_count-2]*256 + x[x_count-1].
base32_digits - [out]
When base32_digits is not a dynamic array, base32_digits[]
must a be an array of length at least
((8*x_count)/5) + (((8*x_count)%5)?1:0) or 1,
whichever is greater.
The base32_digits[] array will be filled in with base32 digit
values (0 to 31) so that the value
b[0]*32^(b_count-1) + ... + b[b_count-2]*32 + b[b_count-1]
is the same as that defined by the x[] array.
Returns
The number of base 32 digits in the base32_digits[] array.
If 0 is returned, the input is not valid.
*/
ON_DECL
int ON_GetBase32Digits( const ON_SimpleArray<unsigned char>& x, ON_SimpleArray<unsigned char>& base32_digits );
ON_DECL
int ON_GetBase32Digits( const unsigned char* x, int x_count, unsigned char* base32_digits );
/*
Description:
Convert a list of base32 digits into a string form.
Parameters:
base32_digits - [in]
base32_digit_count - [in]
base32_digits[] is an array of length base32_digit_count.
Each element is in the range 0 to 31.
sBase32 - [out]
sBase32[] must be an array of length base32_digit_count+1 or 2,
whichever is greater. The string representation of the base 32
number will be put in this string. A hash mark symbol (#) is
used to indicate an error in the input value. The returned
string is null terminated.
Returns
True if the input is valid. False if the input is not valid,
in which case hash marks indicate the invalid entries.
*/
ON_DECL
bool ON_Base32ToString( const ON_SimpleArray<unsigned char>& base32_digits, ON_String& sBase32 );
ON_DECL
bool ON_Base32ToString( const ON_SimpleArray<unsigned char>& base32_digits, ON_wString& sBase32 );
ON_DECL
bool ON_Base32ToString( const unsigned char* base32_digits, int base32_digit_count, char* sBase32 );
/*
Description:
Fixt a common typos in sBase32 string. Lower case letters are
converted to upper case. The letters 'I', 'L', 'O' and 'S' are
converted to '1' (one), '1' (one) '0' zero and '5' (five).
Parameters:
sBase32 - [in]
sBase32clean - [out]
(can be the same string as sBase32)
Returns:
If the input is valid, the length of the converted string is returned.
If the input is not valid, 0 is returned.
*/
ON_DECL
int ON_CorrectBase32StringTypos( const wchar_t* sBase32, ON_wString& sBase32clean );
ON_DECL
int ON_CorrectBase32StringTypos( const char* sBase32, ON_String& sBase32clean );
ON_DECL
int ON_CorrectBase32StringTypos( const char* sBase32, char* sBase32clean );
/*
Description:
Convert a null terminate string containing the 32 symbols
0 1 2 3 4 5 6 7 8 9 A B C D E F G H J K M N P Q R T U V W X Y Z
(I,L,O and S are missing) into a list of base 32 digits.
Parameters:
sBase32 - [in]
String with base 32 digits
base32_digits - [out]
base32_digits[] is an array of length strlen(sBase32).
The returned array, element will be in the range 0 to 31.
sBase32[] must be an array of length base32_digit_count+1 or 2,
whichever is greater. The string representation of the base 32
number will be put in this string. A hash mark symbol (#) is
used to indicate an error in the input value. The returned
string is null terminated.
Returns
True if the input is valid. False if the input is not valid,
in which case hash marks indicate the invalid entries.
*/
ON_DECL
int ON_StringToBase32(const ON_wString& sBase32, ON_SimpleArray<unsigned char>& base32_digits );
ON_DECL
int ON_StringToBase32(const ON_String& sBase32, ON_SimpleArray<unsigned char>& base32_digits );
ON_DECL
int ON_StringToBase32(const char* sBase32, unsigned char* base32_digits );
#endif

1088
extern/opennurbs/opennurbs_base64.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

345
extern/opennurbs/opennurbs_base64.h vendored Executable file
View File

@@ -0,0 +1,345 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_BASE64_INC_)
#define OPENNURBS_BASE64_INC_
//////////////////////////////////////////////////////////////////////////////////////////
class ON_CLASS ON_Base64EncodeStream
{
public:
ON_Base64EncodeStream();
virtual ~ON_Base64EncodeStream();
/*
Description:
ON_Base64EncodeStream delivers the base64 encoded stream by
calling a base64 encoded stream output handler function.
There are two options for specifying the base64 encoded stream
output handler function.
1. Overriding the virtual Out() function.
2. Providing a callback function.
SetCallback() is used to specify a callback function to handle
the base64 encoded stream and to specify a context pointer to be
passed to either option of the handler.
Parameters:
callback_function - [in]
Function to handle sections of the base64 encoded stream.
If callback_function is null, then the virtual Out()
function will be called. When callback_function
is specified, it must return true if the base64 encoding
calculation should continue and false to cancel the
base64 encoding calculation.
callback_context - [in]
This value is passed as the first argument when calling
callback_function or the virutal Out() function.
Returns:
True if successful.
Remarks:
Once base64 encoding has started, it would be unusual to
intentionally change the base64 encoded stream output handler,
but you can do this if you need to.
*/
bool SetCallback(
ON_StreamCallbackFunction callback_function,
void* callback_context
);
/*
Returns:
Current value of the callback function for handling
the base64 encoded stream. If the callback function is
null, the the virtual Out() function is used to
handle the output stream.
*/
ON_StreamCallbackFunction CallbackFunction() const;
/*
Returns:
Current value of the context pointer passed as the first
argument to the base64 encoded stream output handler function.
*/
void* CallbackContext() const;
/*
Description:
Call Begin() one time to initialize the base64 encoding
calculation. Then call In() one or more times
to submit the unencoded stream to the base64 encoding
calculation. When you reach the end of the unencoded
stream, call End().
Returns:
true if successful, false if an error occured.
*/
bool Begin();
/*
Description:
Call In() one or more times to base64 encode a stream of bytes.
After the last call to In(), call End(). Calling In() will
result in at least in_buffer_size/57 and at most
(in_buffer_size+56)/57 calls to to the output stream handler.
Parameters:
in_buffer_size - [in]
number of bytes in in_buffer
in_buffer - [in]
Returns:
true if successful, false if an error occured.
*/
bool In(
ON__UINT64 in_buffer_size,
const void* in_buffer
);
/*
Description:
If an explicit base 64 encoded stream output handler is not
specified ( CallbackFunction() returns null ), then the
virtual Out() function is called to handle the base 64 encoded
output stream. As the input stream is encoded, one or more
calls to Out() will occur.
With a possible exception of the last call to Out(), when Out()
is called, 57 input bytes have been encoded into 76 output
characters with ASCII codes A-Z, a-z, 0-9, +, /.
Parameters:
callback_context - [in]
context pointer set by calling SetCallback(). Typically
the context pointer is not used by a virtual override
because the context can be added as member variables
of the derived class, but it is available if needed.
out_buffer_size - [in]
number of non-null characters in out_buffer.
out_buffer - [in]
A null terminated ASCII string that is a base 64 encoding.
out_buffer[0...(out_buffer_size-1)] are ASCII characters with
values characters with ASCII codes A-Z, a-z, 0-9, +, /
and out_buffer[out_buffer_size] = 0.
Returns:
True to continue base 64 encodeing and false to cancel the
encoding calculation.
*/
virtual bool Out(
void* callback_context,
ON__UINT32 out_buffer_size,
const char* out_buffer
);
/*
Description:
After the last call to In(), call End(). Calling End() may
generate one call to the output stream handler with the value
of out_buffer_size = 4 to 76.
Returns:
true if successful, false if an error occured.
*/
bool End();
/*
Returns:
Then the returned value is the total number bytes in the input
stream. The size is updated every time In() is called before
any calls are made to the output stream handler. If the
calculation is finished ( End() has been called ), then the
returned value is the total number of bytes in the entire
input stream.
*/
ON__UINT64 InSize() const;
/*
Returns:
Then the returned value is the total number characters in the
output stream. The size is incremented immediately after each
call to the output stream handler. If the base64 encoding
calculation is finished ( End() has been called ), then the
returned value is the total number of bytes in the entire
output stream.
*/
ON__UINT64 OutSize() const;
/*
Returns:
Then the returned value is the 32-bit crc of the input stream.
The crc is updated every time In() is called before any calls
are made to the output stream handler. If the base64 encoding
calculation is finished ( End() has been called ), then the
returned value is the 32-bit crc of the entire input stream.
*/
ON__UINT32 InCRC() const;
/*
Returns:
Then the returned value is the 32bit crc of the output stream.
The crc is updated immediately after each call to the output
stream handler. If the calculation is finished ( End() has
been called ), then the returned value is the 32-bit crc of
the entire output stream.
*/
ON__UINT32 OutCRC() const;
private:
ON_StreamCallbackFunction m_out_callback_function;
void* m_out_callback_context;
ON__UINT64 m_in_size;
ON__UINT64 m_out_size;
ON__UINT32 m_in_crc;
ON__UINT32 m_out_crc;
void* m_implementation;
void* m_reserved;
void ErrorHandler();
private:
// prohibit use - no implementation
ON_Base64EncodeStream(const ON_Base64EncodeStream&);
ON_Base64EncodeStream& operator=(const ON_Base64EncodeStream&);
};
//////////////////////////////////////////////////////////////////////////////////////////
class ON_CLASS ON_DecodeBase64
{
public:
ON_DecodeBase64();
virtual ~ON_DecodeBase64();
void Begin();
// Decode will generate zero or more callbacks to the
// virtual Output() function. If the base 64 encoded information
// is in pieces, you can call Decode() for each piece. For example,
// if your encoded information is in a text file, you might call
// Decode() for every line in the file. Decode() returns 0 if
// there is nothing in base64str to decode or if it detects an
// error that prevents any further decoding. The function Error()
// can be used to determine if an error occured. Otherwise,
// Decode() returns a pointer to the location in the string where
// it stopped decoding because it detected a character, like a null
// terminator, an end of line character, or any other character
// that could not be part of the base 64 encoded information.
const char* Decode(const char* base64str);
const char* Decode(const char* base64str, size_t base64str_count);
const wchar_t* Decode(const wchar_t* base64str);
const wchar_t* Decode(const wchar_t* base64str, size_t base64str_count);
// You must call End() when Decode() returns 0 or when you have
// reached the end of your encoded information. End() may
// callback to Output() zero or one time. If all the information
// passed to Decode() was successfully decoded, then End()
// returns true. If something was not decoded, then End()
// returns false.
bool End();
// Override the virtual Output() callback function to process the
// decoded output. Each time Output() is called there are m_output_count
// bytes in the m_output[] array.
// Every call to Decode() can result in zero, one, or many callbacks
// to Output(). Calling End() may result in zero or one callbacks
// to Output().
virtual void Output();
// m_decode_count = total number of input base64 characters
// that Decode() has decoded.
unsigned int m_decode_count;
int m_output_count; // 0 to 512
unsigned char m_output[512];
// Call if your Output() function detects an error and
// wants to stop further decoding.
void SetError();
// Returns true if an error occured during decoding because
// invalid input was passed to Decode().
const bool Error() const;
private:
int m_status; // 1: error - decoding stopped
// 2: '=' encountered as 3rd char in Decode()
// 3: successfully parsed "**=="
// 4: successfully parsed "***="
// 5: End() successfully called.
// cached encoded input from previous call to Decode()
int m_cache_count;
int m_cache[4];
void DecodeHelper1(); // decodes "**==" quartet into 1 byte
void DecodeHelper2(); // decodes "***=" quartet into 2 bytes
};
/////////////////////////////////////////////////////////////////////
/*
class ON_CLASS ON_EncodeBase64
{
public:
ON_EncodeBase64();
virtual ~ON_EncodeBase64();
void Begin();
// Calling Encode will generate at least
// sizeof_buffer/57 and at most (sizeof_buffer+56)/57
// calls to Output(). Every callback to Output() will
// have m_output_count = 76.
void Encode(const void* buffer, size_t sizeof_buffer);
// Calling End may generate a single call to Output()
// If it does generate a single call to Output(),
// then m_output_count will be between 1 and 76.
void End(); // may generate a single call to Output().
// With a single exception, when Output() is called,
// 57 input bytes have been encoded into 76 output
// characters with ASCII codes A-Z, a-z, 0-9, +, /.
// m_output_count will be 76
// m_output[0...(m_output_count-1)] will be the base 64
// encoding.
// m_output[m_output_count] = 0.
// The Output() function can modify the values of m_output[]
// and m_output_count anyway it wants.
virtual void Output();
// Total number of bytes passed to Encode().
int m_encode_count;
// When the virtual Output() is called, there are m_output_count (1 to 76)
// characters of base64 encoded output in m_output[]. The remainder of
// the m_output[] array is zero. The Output function may modify the
// contents of m_output[] any way it sees fit.
int m_output_count;
char m_output[80];
private:
// input waiting to be encoded
// At most 56 bytes can be waiting to be processed in m_input[].
unsigned int m_unused2; // Here for alignment purposes. Never used by opennurbs.
unsigned int m_input_count;
unsigned char m_input[64];
void EncodeHelper1(const unsigned char*, char*);
void EncodeHelper2(const unsigned char*, char*);
void EncodeHelper3(const unsigned char*, char*);
void EncodeHelper57(const unsigned char*);
};
*/
#endif

5147
extern/opennurbs/opennurbs_beam.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

997
extern/opennurbs/opennurbs_beam.h vendored Executable file
View File

@@ -0,0 +1,997 @@
#if !defined(OPENNURBS_EXTRUSION_INC_)
#define OPENNURBS_EXTRUSION_INC_
/*
Description:
Get the transformation that maps the ON_Extrusion
2d xy profile to 3d world space.
Parameters:
P - [in] start or end of path
T - [in] unit tanget to path
U - [in] unit up vector perpendicular to T
Normal - [in] optional unit vector with Normal->z > 0 that
defines the unit normal to the miter plane.
xform - [out]
transformation that maps the profile curve to 3d world space
scale2d - [out]
If not NULL, this is the scale part of the transformation.
If there is no mitering, then this is the identity.
rot2d - [out]
If not null, this is the part of the transformation
that rotates the xy plane into its 3d world location.
Returns:
true if successful.
*/
ON_DECL
bool ON_GetEndCapTransformation(
ON_3dPoint P,
ON_3dVector T,
ON_3dVector U,
const ON_3dVector* Normal,
ON_Xform& xform, // = rot3d*scale2d
ON_Xform* scale2d,
ON_Xform* rot2d
);
class ON_CLASS ON_Extrusion : public ON_Surface
{
ON_OBJECT_DECLARE(ON_Extrusion);
public:
ON_Extrusion();
ON_Extrusion(const ON_Extrusion& src);
~ON_Extrusion();
ON_Extrusion& operator=(const ON_Extrusion&);
////////////////////////////////////////////////////////////
//
// overrides of virtual ON_Object functions
//
void DestroyRuntimeCache( bool bDelete = true );
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
void Dump( ON_TextLog& ) const;
unsigned int SizeOf() const;
ON__UINT32 DataCRC( ON__UINT32 current_remainder ) const;
ON_BOOL32 Write( ON_BinaryArchive& binary_archive) const;
ON_BOOL32 Read( ON_BinaryArchive& binary_archive );
ON::object_type ObjectType() const;
////////////////////////////////////////////////////////////
//
// overrides of virtual ON_Geometry functions
//
int Dimension() const;
ON_BOOL32 GetBBox(
double* boxmin,
double* boxmax,
int bGrowBox = false
) const;
bool GetTightBoundingBox(
ON_BoundingBox& tight_bbox,
int bGrowBox = false,
const ON_Xform* xform = 0
) const;
ON_BOOL32 Transform(
const ON_Xform& xform
);
/*
Description:
Build a brep form of the extrusion. The outer profile is always
the first face in the brep. If there are inner profiles,
additional brep faces are created for each profile. If the
outer profile is closed, then end caps are added as the last
two faces in the brep.
Parameters:
brep - [in]
If the brep pointer is not null, then the brep form is constructed
in brep. If the brep pointer is null, then an ON_Brep is allocated
on the heap.
Returns:
If successful, a pointer to the brep form. If unsuccessful, null.
*/
ON_Brep* BrepForm(
ON_Brep* brep = NULL
) const;
/*
Description:
Build a brep form of the extrusion. The outer profile is always
the first face in the brep. If there are inner profiles,
additional brep faces are created for each profile. If the
outer profile is closed, then end caps are added as the last
two faces in the brep.
Parameters:
brep - [in]
If the brep pointer is not null, then the brep form is constructed
in brep. If the brep pointer is null, then an ON_Brep is allocated
on the heap.
bSmoothFaces - [in]
If true and the profiles have kinks, then the faces corresponding
to those profiles are split so they will be G1.
Returns:
If successful, a pointer to the brep form. If unsuccessful, null.
*/
ON_Brep* BrepForm(
ON_Brep* brep,
bool bSmoothFaces
) const;
/*
Description:
Build a sum surface form of the extrusion.
Parameters:
sum_surface - [in]
If the sum_surface pointer is not null, then the sum surface
form is constructed in sum_surface. If the sum_surface pointer
is null, then an ON_SumSurface is allocated on the heap.
Returns:
If successful, a pointer to the sum surface form.
If unsuccessful, null. In particular, extrusions with
mitered ends do not have sum surface forms.
*/
ON_SumSurface* SumSurfaceForm(
ON_SumSurface* sum_surface
) const;
/*
Description:
Convert a component index that identifies a part of this extrusion
to a component index that identifies a part of the brep created
by BrepForm(...,false).
Parameters:
extrusion_ci - [in]
extrusion_profile_parameter - [in]
brep_form - [in]
brep created by ON_Extrusion::BrepForm()
brep_ci - [out]
Returns:
True if successful. False if input is not valid, in which case brep_ci
is set by calling ON_COMPONENT_INDEX::UnSet().
Remarks:
If the wall surfaces have creases, then this function cannot
be used to identify brep components created by BrepForm(...,true).
*/
bool GetBrepFormComponentIndex(
ON_COMPONENT_INDEX extrusion_ci,
ON_COMPONENT_INDEX& brep_ci
) const;
bool GetBrepFormComponentIndex(
ON_COMPONENT_INDEX extrusion_ci,
double extrusion_profile_parameter,
const ON_Brep& brep_form,
ON_COMPONENT_INDEX& brep_ci
) const;
////////////////////////////////////////////////////////////
//
// overrides of virtual ON_Surface functions
//
ON_BOOL32 SetDomain(
int dir,
double t0,
double t1
);
ON_Interval Domain(
int dir
) const;
ON_BOOL32 GetSurfaceSize(
double* width,
double* height
) const;
int SpanCount(
int dir
) const;
ON_BOOL32 GetSpanVector(
int dir,
double* span_vector
) const;
ON_BOOL32 GetSpanVectorIndex(
int dir,
double t,
int side,
int* span_vector_index,
ON_Interval* span_interval
) const;
int Degree(
int dir
) const;
ON_BOOL32 GetParameterTolerance(
int dir,
double t,
double* tminus,
double* tplus
) const;
ISO IsIsoparametric(
const ON_Curve& curve,
const ON_Interval* curve_domain = NULL
) const;
ON_BOOL32 IsPlanar(
ON_Plane* plane = NULL,
double tolerance = ON_ZERO_TOLERANCE
) const;
ON_BOOL32 IsClosed(
int
) const;
ON_BOOL32 IsPeriodic(
int
) const;
bool GetNextDiscontinuity(
int dir,
ON::continuity c,
double t0,
double t1,
double* t,
int* hint=NULL,
int* dtype=NULL,
double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
double curvature_tolerance=ON_SQRT_EPSILON
) const;
bool IsContinuous(
ON::continuity c,
double s,
double t,
int* hint = NULL,
double point_tolerance=ON_ZERO_TOLERANCE,
double d1_tolerance=ON_ZERO_TOLERANCE,
double d2_tolerance=ON_ZERO_TOLERANCE,
double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
double curvature_tolerance=ON_SQRT_EPSILON
) const;
ISO IsIsoparametric(
const ON_BoundingBox& bbox
) const;
ON_BOOL32 Reverse( int dir );
ON_BOOL32 Transpose();
ON_BOOL32 Evaluate(
double u, double v,
int num_der,
int array_stride,
double* der_array,
int quadrant = 0,
int* hint = 0
) const;
ON_Curve* IsoCurve(
int dir,
double c
) const;
ON_BOOL32 Trim(
int dir,
const ON_Interval& domain
);
bool Extend(
int dir,
const ON_Interval& domain
);
ON_BOOL32 Split(
int dir,
double c,
ON_Surface*& west_or_south_side,
ON_Surface*& east_or_north_side
) const;
bool GetClosestPoint(
const ON_3dPoint& P,
double* s,
double* t,
double maximum_distance = 0.0,
const ON_Interval* sdomain = 0,
const ON_Interval* tdomain = 0
) const;
ON_BOOL32 GetLocalClosestPoint( const ON_3dPoint&, // test_point
double,double, // seed_parameters
double*,double*, // parameters of local closest point returned here
const ON_Interval* = NULL, // first parameter sub_domain
const ON_Interval* = NULL // second parameter sub_domain
) const;
//ON_Surface* Offset(
// double offset_distance,
// double tolerance,
// double* max_deviation = NULL
// ) const;
int GetNurbForm(
ON_NurbsSurface& nurbs_surface,
double tolerance = 0.0
) const;
int HasNurbForm() const;
bool GetSurfaceParameterFromNurbFormParameter(
double nurbs_s, double nurbs_t,
double* surface_s, double* surface_t
) const;
bool GetNurbFormParameterFromSurfaceParameter(
double surface_s, double surface_t,
double* nurbs_s, double* nurbs_t
) const;
////////////////////////////////////////////////////////////
//
// ON_Extrusion mesh interface
//
/*
Description:
Attach a mesh to the ON_Extrusion.
Parameters:
mt - [in]
type of mesh that is being attached.
If mt is ON::render_mesh, ON::analysis_mesh or ON::preview_mesh,
the mesh is attached as that type of mesh.
If mt is ON::default_mesh or ON::any_mesh, then
nothing is done and false is returned.
mesh - [in]
* mesh to attach.
* mesh must be on the heap because ~ON_Extrusion()
will delete it.
* if there is already of mesh of the prescribed type,
it will be deleted.
* if mesh is null, any existing mesh is deleted and
nothing is attached.
*/
bool SetMesh( ON::mesh_type mt, ON_Mesh* mesh );
/*
Description:
Get a mesh attached to the ON_Extrusion.
Parameters:
mt - [in]
type of mesh to get.
ON::render_mesh, ON::analysis_mesh and ON::preview_mesh
remove the meshes of those types.
If mt is ON::default_mesh or ON::any_mesh, then
the first non null mesh is returned.
Returns:
A pointer to a mesh on the ON_Extusion object.
This mesh will be deleted by ~ON_Extrusion().
If a mesh of the requested type is not available,
then null is returned.
*/
const ON_Mesh* Mesh( ON::mesh_type mt ) const;
/*
Description:
Remove a mesh attached to the ON_Extrusion.
Parameters:
mt - [in]
type of mesh to get.
ON::render_mesh, ON::analysis_mesh and ON::preview_mesh
remove the meshes of those types.
If mt is ON::default_mesh or ON::any_mesh, then
null is returned.
Returns:
A pointer to a mesh on the ON_Extusion object.
If a mesh of the requested type is not available,
then null is returned.
The caller is responsible for deleteing the returned mesh.
*/
ON_Mesh* RemoveMesh( ON::mesh_type mt );
/*
Description:
Destroy a mesh attached to the ON_Extrusion.
Parameters:
mt - [in] type of mesh to destroy
If mt is ON::default_mesh or ON::any_mesh, then
all attached meshes of all types are destroyed.
bDeleteMesh - [in] if true, cached mesh is deleted.
If false, pointer to cached mesh is just set to null.
*/
void DestroyMesh( ON::mesh_type mt, bool bDeleteMesh = true );
////////////////////////////////////////////////////////////
//
// ON_Extrusion interface
//
void Destroy();
/*
Description:
Sets m_path to (A,B), m_path_domain to [0,Length(AB)],
and m_t to [0,1].
Parameters:
A - [in] path start
B - [in] path end
Returns:
true A and B are valid, the distance from A to B is larger
than ON_ZERO_TOLERANCE, and the path was set.
false A or B is not valid or the distance from A to B is
at most ON_ZERO_TOLERANCE. In this case nothing is set.
Remark:
You must also set the up direction to be perpendicular to the path.
*/
bool SetPath(ON_3dPoint A, ON_3dPoint B);
/*
Description:
Sets m_path to (A,B), m_path_domain to [0,Length(AB)],
m_t to [0,1], and m_up.
Parameters:
A - [in] path start
B - [in] path end
up - [in] up direction
If up is a unit vector and perpendicular to the line
segment from A to B, then m_up is set to up.
Otherwise up will be adjusted so it is perpendicular
to the line segment from A to B and unitized.
Returns:
true A and B are valid, the distance from A to B is larger
than ON_ZERO_TOLERANCE, and the path was set.
false A or B is not valid, or the distance from A to B is
at most ON_ZERO_TOLERANCE, or up is invalid, or up
is zero, or up is parallel to the line segment.
In this case nothing is set.
*/
bool SetPathAndUp(ON_3dPoint A, ON_3dPoint B, ON_3dVector up );
/*
Description:
Get the surface parameter for the path.
Returns:
0: The first surface parameter corresponds to the path direction.
(m_bTransposed = true)
1: The second surface parameter corresponds to the path direction.
(m_bTransposed = false)
Remarks:
The default ON_Extrusion constructor sets
m_bTransposed = false which corresponds to the 1 = PathParameter().
*/
int PathParameter() const;
ON_3dPoint PathStart() const;
ON_3dPoint PathEnd() const;
ON_3dVector PathTangent() const;
/*
Description:
Set miter plane normal.
Parameters:
N - [in] If ON_UNSET_VECTOR or N is parallel to the z-axis,
then the miter plane is the default plane
perpendicular to the path.
If N is valid and the z coordinate of a unitized
N is greater than m_Nz_tol, then the miter plane
normal is set.
end - [in] 0 = set miter plane at the start of the path.
1 = set miter plane at the end of the path.
*/
bool SetMiterPlaneNormal(ON_3dVector N, int end);
void GetMiterPlaneNormal(int end, ON_3dVector& N) const;
/*
Returns:
0: not mitered.
1: start of path is mitered.
2: end of path is mitered.
3: start and end are mitered.
*/
int IsMitered() const;
/*
Returns:
True if extrusion object is a capped solid.
*/
bool IsSolid() const;
/*
Returns:
0: no or profile is open
1: bottom cap
2: top cap
3: both ends capped.
*/
int IsCapped() const;
/*
Returns:
0: no caps
1: exrusion has either a top cap or a bottom cap
2: both ends are capped.
See Also:
ON_Extrusion::ProfileCount()
ON_Extrusion::ProfileSmoothSegmentCount()
*/
int CapCount() const;
/*
Description:
Deprecated function.
Use CapCount() to determine how many end caps there are.
Use ProfileCount() to determine how many profiles there are.
Use ProfileSmoothSegmentCount() to determine how many
smooth subsegments are in a profile. Each smooth subsegment
becomes a wall face in the brep form.
Returns:
Number of "faces" the extrusion has.
0: extrusion is not valid
1: extrusion is not capped
2: extrusion has a closed outer profile and one cap
3: extrusion has a closed outer profile and two caps
Remarks:
This function was written before extrusions supported "holes"
and before the brep form was divided at profile creases.
At this point it simply leads to confusion. See the Description
function replacements.
*/
ON_DEPRECATED int FaceCount() const;
/*
Description:
Get the transformation that maps the xy profile curve
to its 3d location.
Parameters:
s - [in] 0.0 = starting profile
1.0 = ending profile
*/
bool GetProfileTransformation( double s, ON_Xform& xform ) const;
/*
Description:
Get the the 3d plane containing the profile curve at a
normalized path parameter.
Parameters:
s - [in] 0.0 = starting plane
1.0 = ending plane
plane - [out]
Plane containing profile is returned in plane. If
false is returned, then the input value of plane
is not changed.
Returns:
true if plane was set. False if this is invalid and plane
could not be set.
Remarks:
When no mitering is happening, GetPathPlane() and
GetProfilePlane() return the same plane.
*/
bool GetProfilePlane( double s, ON_Plane& plane ) const;
/*
Description:
Get the the 3d plane perpendicular to the path at a
normalized path parameter.
Parameters:
s - [in] 0.0 = starting plane
1.0 = ending plane
plane - [out]
Plane is returned here. If
false is returned, then the input value of plane
is not changed.
Returns:
true if plane was set. False if this is invalid and plane
could not be set.
Remarks:
When no mitering is happening, GetPathPlane() and
GetProfilePlane() return the same plane.
*/
bool GetPathPlane( double s, ON_Plane& plane ) const;
/*
Description:
Set the outer profile of the extrusion.
Paramters:
outer_profile - [in]
curve in the xy plane or a 2d curve.
bCap - [in]
If outer_profile is a closed curve, then bCap
determines if the extrusion has end caps.
If outer_profile is an open curve, bCap is ignored.
Returns:
True if the profile was set. In this case the ON_Extrusion class
manages the curve and ~ON_Extrusion will delete it. If the outer
profile is closed, then the extrusion may also have inner profiles.
If the outer profile is open, the extrusion may not have inner
profiles. If the extrusion already has a profile, the set will
fail.
Remarks:
If needed, outer_profile will be converted to a 2d
curve. If outer_curve is closed but not correctly oriented,
it will reversed so it has a counter-clockwise orientation.
*/
bool SetOuterProfile( ON_Curve* outer_profile, bool bCap );
/*
Description:
Add an inner profile.
Paramters:
inner_profile - [in]
closed curve in the xy plane or a 2d curve.
Returns:
True if the profile was set. In this case the
ON_Extrusion class manages the curve and ~ON_Extrusion will
delete it. The extrusion must already have an outer profile.
If the extrusion already has a profile, the set will
fail.
Remarks:
If needed, innter_profile will be converted to a 2d
curve. If inner_profile is not correctly oriented, it
will be reversed so it has a clockwise orientation.
*/
bool AddInnerProfile( ON_Curve* inner_profile );
/*
Returns:
Number of profile curves.
See Also:
ON_Extrusion::CapCount()
ON_Extrusion::ProfileSmoothSegmentCount()
*/
int ProfileCount() const;
/*
Parameter:
profile_index - [in]
0 <= profile_index < ProfileCount().
The outer profile has index 0.
Returns:
Number of smooth segments in the profile curve.
See Also:
ON_Extrusion::CapCount()
ON_Extrusion::GetProfileKinkParameters()
ON_Extrusion::ProfileCount()
*/
int ProfileSmoothSegmentCount( int profile_index ) const;
/*
Description:
Get the surface parameter for the profile.
Returns:
0: The first surface parameter corresponds to the profile direction.
(m_bTransposed = false)
1: The second surface parameter corresponds to the profile direction.
(m_bTransposed = true)
Remarks:
The default ON_Extrusion constructor sets
m_bTransposed = false which corresponds to the 0 = ProfileParameter().
*/
int ProfileParameter() const;
/*
Paramters:
profile_index - [in]
0 <= profile_index < ProfileCount().
The outer profile has index 0.
Returns:
Pointer to the i-th 2d profile. The ON_Extrusion
class manages this curve. Do not delete it
and do not use the pointer if the ON_Extrusion
class changes.
*/
const ON_Curve* Profile(int profile_index) const;
/*
Paramters:
profile_index - [in]
0 <= profile_index < ProfileCount().
The outer profile has index 0.
s - [in] ( 0.0 <= s <= 1.0 )
A relative parameter controling which priofile
is returned. s = 0.0 returns the bottom profile
and s = 1.0 returns the top profile.
Returns:
NULL if the input parameters or the ON_Extrusion class is
not valid. Otherwise a pointer to a 3d curve for
the requested profile. This curve is on the heap and
the caller is responsible for deleting this curve.
*/
ON_Curve* Profile3d(int profile_index, double s ) const;
/*
Paramters:
ci - [in]
component index identifying a 3d extrusion profile curve.
Returns:
NULL if the component index or the ON_Extrusion class is
not valid. Otherwise a pointer to a 3d curve for
the requested profile. This curve is on the heap and
the caller is responsible for deleting this curve.
*/
ON_Curve* Profile3d( ON_COMPONENT_INDEX ci ) const;
/*
Paramters:
ci - [in]
component index identifying a wall edge curve.
Returns:
NULL if the component index or the ON_Extrusion class is
not valid. Otherwise a pointer to a 3d curve for
the requested wall edge. This curve is on the heap and
the caller is responsible for deleting this curve.
*/
ON_Curve* WallEdge( ON_COMPONENT_INDEX ci ) const;
/*
Paramters:
ci - [in]
component index identifying a wall surface.
Returns:
NULL if the component index or the ON_Extrusion class is
not valid. Otherwise a pointer to a surface for
the requested wall surface. This curve is on the heap and
the caller is responsible for deleting this curve.
*/
ON_Surface* WallSurface( ON_COMPONENT_INDEX ci ) const;
/*
Paramters:
line_curve - [in]
If null, a line curve will be allocated using new.
Returns:
Null if the extrusion path is not valid. Otherwise
a pointer to an ON_LineCurve that is set to the
extrusion's path. The caller must delete this curve.
*/
ON_LineCurve* PathLineCurve(ON_LineCurve* line_curve) const;
/*
Paramters:
profile_parameter - [in]
parameter on profile curve
Returns:
-1: if the profile_parameter does not correspond
to a point on the profile curve.
>= 0: index of the profile curve with domain containing
this paramter. When the profile_parameter corresponds
to the end of one profile and the beginning of the next
profile, the index of the next profile is returned.
*/
int ProfileIndex( double profile_parameter ) const;
/*
Returns:
If m_profile_count >= 2 and m_profile is an ON_PolyCurve
with m_profile_count segments defining outer and inner
profiles, a pointer to the polycurve is returned.
Otherwise null is returned.
*/
const ON_PolyCurve* PolyProfile() const;
/*
Description:
Get a list of the 2d profile curves.
Returns:
Number of curves appended to the list.
*/
int GetProfileCurves( ON_SimpleArray<const ON_Curve*>& profile_curves ) const;
/*
Description:
Get the parameters where a profile curve has kinks.
Parameters:
profile_index - [in]
profile_kink_parameters - [out]
parameters at internal kinks are appended to this array.
Returns:
Number of parameters appended to profile_kink_parameters[]
Remarks:
This function is used when making the brep form that has
smooth faces.
*/
int GetProfileKinkParameters( int profile_index, ON_SimpleArray<double>& profile_kink_parameters ) const;
/*
Parameters:
profile_index - [in]
Returns:
True if the profile has at least one kink.
*/
bool ProfileIsKinked( int profile_index ) const;
/*
Description:
Test a polycurve to determine if it meets the necessary
conditions to be used as a multi-segment profile in a extrusion.
Returns:
True if the returned polycurve can be used a a multi-segment
profile in a extrusion.
*/
static bool IsValidPolyCurveProfile( const ON_PolyCurve& polycurve, ON_TextLog* text_log = 0 );
/*
Description:
If possible, modify a polycurve so it meets the necessary conditions
to be used as a multi-segment profile in a extrusion.
Returns:
True if the returned polycurve can be used a a multi-segment
profile in a extrusion.
*/
static bool CleanupPolyCurveProfile( ON_PolyCurve& polycurve );
// path definition:
// The line m_path must have length > m_path_length_min.
// The interval m_t must statisfy 0 <= m_t[0] < m_t[1] <= 1.
// The extrusion starts at m_path.PointAt(m_t[0]) and ends
// at m_path.PointAt(m_t[1]).
// The "up" direction m_up is a unit vector that must
// be perpendicular to m_path.Tangent().
ON_Line m_path;
ON_Interval m_t;
ON_3dVector m_up;
// profile information:
// In general, use SetOuterProfile() and AddInnerProfile()
// to set m_profile_count and m_profile. If you are
// a glutton for punishment, then you might be interested
// in the following.
// The profile curves must be in the x-y plane.
// The profile's "y" axis corresponds to m_up.
// The point (0,0) is extruded along the m_path line.
// If m_profile_count = 1, then m_profile can be any
// type of continous curve. If m_profile_count > 1,
// then m_profile must be an ON_PolyCurve with
// m_profile_count segments, the domain of each segment
// must exactly match the polycurve's segment domain,
// every segment must be continuous and closed,
// the first segement curve must have counter-clockwise
// orientation, and the rest must have clockwise
// orientations.
int m_profile_count;
ON_Curve* m_profile;
// capped end information:
// If the profile is closed, then m_bCap[] determines
// if the ends are capped.
bool m_bCap[2];
// mitered end information:
// The normals m_N[] are with respect to the xy plane.
// A normal parallel to the z axis has no mitering.
// If m_bHaveN[i] is true, then m_N[i] must be a 3d unit
// vector with m_N[i].z > m_Nz_tol; If m_bHaveN[i]
// is false, then m_N[i] is ignored. The normal m_N[0]
// defines the start miter plane and m_N[1] defines the
// end miter plane.
bool m_bHaveN[2];
ON_3dVector m_N[2];
// Surface parameterization information
ON_Interval m_path_domain;
bool m_bTransposed; // false: (s,t) = (profile,path)
// The z coordinates of miter plane normals must be
// greater than m_Nz_tol
static const double m_Nz_min; // 1/64;
// The length of the m_path line must be greater than
// m_path_length_min
static const double m_path_length_min; // ON_ZERO_TOLERANCE;
/*
Description:
Get an ON_Exrusion form of a cylinder.
Parameters:
cylinder - [in] cylinder.IsFinite() must be true
bCapBottom - [in] if true, the end at cylinder.m_height[0] will be capped
bCapTop - [in] if true, the end at cylinder.m_height[1] will be capped
extrusion - [in]
If the input extrusion pointer is null, one will be allocated on the heap
and it is the caller's responsibility to delte it at an appropriate time.
If the input pointer is not null, this extrusion will be used and the same
pointer will be returned, provided the input is valid.
Returns:
If the input is valid, a pointer to an ON_Exrusion form of the cylinder.
If the input is not valid, then null, even when the input extrusion
object is not null.
Example:
ON_Cylinder cylinder = ...;
bool bCapBottom = true;
bool bCapTop = true;
ON_Extrusion extrusion;
if ( 0 == ON_Extrusion::Cylinder(cylinder,bCapBottom,bCapTop,&extrusion) )
{
// input is not valid - nothing set
...
}
else
{
// extrusion = cylinder
...
}
*/
static ON_Extrusion* Cylinder(
const ON_Cylinder& cylinder,
bool bCapBottom,
bool bCapTop,
ON_Extrusion* extrusion = 0
);
/*
Description:
Get an ON_Exrusion form of a pipe.
Parameters:
cylinder - [in] cylinder.IsFinite() must be true
The cylinder can be either the inner or outer wall of the pipe.
other_radius - [in] ( != cylinder.Radius() )
If cylinder.Radius() < other_radius, then the cylinder will be
the inside of the pipe. If cylinder.Radius() > other_radius, then
the cylinder will be the outside of the pipe.
bCapBottom - [in] if true, the end at cylinder.m_height[0] will be capped
bCapTop - [in] if true, the end at cylinder.m_height[1] will be capped
extrusion - [in]
If the input extrusion pointer is null, one will be allocated on the heap
and it is the caller's responsibility to delte it at an appropriate time.
If the input pointer is not null, this extrusion will be used and the same
pointer will be returned, provided the input is valid.
Returns:
If the input is valid, a pointer to an ON_Exrusion form of the pipe.
If the input is not valid, then null, even when the input extrusion
object is not null.
Example:
ON_Cylinder cylinder = ...;
double other_radius = cylinder.Radius()+1.0;
bool bCapBottom = true;
bool bCapTop = true;
ON_Extrusion extrusion;
if ( 0 == ON_Extrusion::Pipe(cylinder,other_radius,bCapBottom,bCapTop,&extrusion) )
{
// input is not valid - nothing set
...
}
else
{
// extrusion = pipe
...
}
*/
static ON_Extrusion* Pipe(
const ON_Cylinder& cylinder,
double other_radius,
bool bCapBottom,
bool bCapTop,
ON_Extrusion* extrusion = 0
);
/*
Description:
Create an ON_Exrusion from a 3d curve, a plane and a height.
Parameters:
curve - [in]
A continuous 3d curve.
plane - [in]
If plane is null, then the plane returned by curve.IsPlanar() is used.
The 3d curve is projected to this plane and the result is passed to
ON_Extrusion::SetOuterProfile().
height - [in]
If the height > 0, the bottom of the extrusion will be in plane and
the top will be height units above the plane.
If the height < 0, the top of the extrusion will be in plane and
the bottom will be height units below the plane.
bCap - [in]
If the curve is closed and bCap is true, then the resulting extrusion
is capped.
extrusion - [in]
If the input extrusion pointer is null, one will be allocated on the heap
and it is the caller's responsibility to delte it at an appropriate time.
If the input pointer is not null, this extrusion will be used and the same
pointer will be returned, provided the input is valid.
Returns:
If the input is valid, a pointer to an ON_Exrusion form of the pipe.
If the input is not valid, then null, even when the input extrusion
object is not null.
*/
static ON_Extrusion* CreateFrom3dCurve(
const ON_Curve& curve,
const ON_Plane* plane,
double height,
bool bCap,
ON_Extrusion* extrusion = 0
);
};
#endif

3415
extern/opennurbs/opennurbs_bezier.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

1938
extern/opennurbs/opennurbs_bezier.h vendored Executable file

File diff suppressed because it is too large Load Diff

1264
extern/opennurbs/opennurbs_beziervolume.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

1060
extern/opennurbs/opennurbs_bitmap.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

600
extern/opennurbs/opennurbs_bitmap.h vendored Executable file
View File

@@ -0,0 +1,600 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
////////////////////////////////////////////////////////////////
//
// Defines ON_WindowsBITMAPINFO class that is used to provide OS independent
// serialization of Windows device independent bitmaps (BITMAPINFO) used
// to store preview images.
//
////////////////////////////////////////////////////////////////
#if !defined(OPENNURBS_BITMAP_INC_)
#define OPENNURBS_BITMAP_INC_
class ON_CLASS ON_Bitmap : public ON_Object
{
// virtual base class for bitmap objects
ON_OBJECT_DECLARE(ON_Bitmap);
public:
ON_Bitmap();
~ON_Bitmap();
// C++ defaults work fine
//ON_Bitmap(const ON_Bitmap&);
//ON_Bitmap& operator=(const ON_Bitmap&);
// virtual
ON_UUID ModelObjectId() const;
void Dump( ON_TextLog& ) const; // for debugging
void EmergencyDestroy();
void Destroy();
void Defaults();
virtual
int Width() const = 0;
virtual
int Height() const = 0; // >0 means it's a bottom-up bitmap with origin at lower right
// <0 means it's a top-down bitmap with origin at upper left
virtual
int BitsPerPixel() const = 0; // bits per pixel
virtual
int SizeofScan() const = 0; // number of bytes per scan line
virtual
int SizeofImage() const = 0; // size of current map in bytes
virtual
unsigned char* Bits(
int // index of scan line
) = 0;
virtual
const unsigned char* Bits(
int // index of scan line
) const = 0;
ON_UUID m_bitmap_id;
int m_bitmap_index;
ON_wString m_bitmap_name; // descriptive name
ON_wString m_bitmap_filename; // full path to file
};
/*
ON_EmbeddedFile is derived from ON_Bitmap so it can be stored
in the Rhino document's CRhinoDoc::m_bitmap_table[] array.
The ON_EmbeddedFile class is used to embed any type of file
in a Rhino document.
*/
class ON_CLASS ON_EmbeddedFile : public ON_Object
{
ON_OBJECT_DECLARE(ON_EmbeddedFile);
public:
ON_EmbeddedFile();
ON_EmbeddedFile(const ON_EmbeddedFile& src);
ON_EmbeddedFile& operator=(const ON_EmbeddedFile& src);
virtual ~ON_EmbeddedFile();
void EmergencyDestroy();
void Destroy();
void DestroyBuffer();
/*
Description:
Store the specified file in an ON_EmbeddedFile class.
Parameters:
filename - [in]
full path to the file.
bCompress - [in]
true if the image of the file should be compressed.
(Pass false if the file is already in a compressed
format, like jpg, png, zip files.)
Returns:
true if successful. When true is returned m_id is set to
a new unique id, m_full_file_name is set to filename,
and m_relative_file_name is empty.
*/
bool Create(
const wchar_t* filename,
bool bCompress
);
/*
Description:
Store the specified file in an ON_EmbeddedFile class.
Parameters:
fp - [in]
Result of calling ON::OpenFile( ..., "rb" )
bCompress - [in]
true if the image of the file should be compressed.
(Pass false if the file is already in a compressed
format, like jpg, png, zip files.)
*/
bool Create(
FILE* fp,
bool bCompress
);
/*
Description:
Store the specified buffer in an ON_EmbeddedFile class.
Parameters:
source_buffer - [in]
source_buffer_size - [in]
number of bytes in source_buffer.
bCompress - [in]
true if the source_buffer should be compressed.
(Pass false if source_buffer is already in a compressed format.)
*/
bool Create(
const void* source_buffer,
ON__UINT64 sizeof_source_buffer,
bool bCompress
);
bool Extract(
const wchar_t* destination_filename
) const;
bool Extract(
FILE* fp
) const;
/*
Description:
Extracts the file into a buffer.
Parameters:
buffer - [out]
buffer must point to FileSize() bytes of memory.
The extracted file will be copied to this buffer.
Returns:
True if successful.
False if not successful.
*/
bool Extract(
void* buffer
) const;
/*
Returns
full path file name
*/
const wchar_t* FullFileName() const;
/*
Returns
Relative file name. Usually relative to the directory
where the archive containing this embedded file was last
saved.
*/
const wchar_t* RelativeFileName() const;
ON_UUID Id() const;
void SetId( ON_UUID id );
void SetFullFileName( const wchar_t* full_file_name );
void SetRelativeFileName( const wchar_t* relative_file_name );
ON__UINT64 FileSize() const;
ON__UINT64 FileLastModifiedTime() const;
ON__UINT32 FileCRC() const;
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
ON_BOOL32 Write( ON_BinaryArchive& ) const;
ON_BOOL32 Read( ON_BinaryArchive& );
// The relative path is typically set when the .3dm file is
// saved and is the path to the file relative to the location
// of the saved file.
// (The full path to the file is in ON_Bitmap::m_bitmap_filename.)
ON_UUID m_id;
ON_wString m_full_file_name; // full path file name
ON_wString m_relative_file_name; // relative path when the archive was last saved.
private:
void* m_reserved;
public:
ON__UINT64 m_file_size;
ON__UINT64 m_file_time; // last modified time returned by ON::GetFileStats()
ON__UINT32 m_file_crc; // 32 bit crc of the file from ON_CRC32
public:
ON__UINT32 m_buffer_crc; // will be different from m_file_crc if the buffer is compressed.
ON_Buffer m_buffer;
unsigned char m_bCompressedBuffer; // true if m_buffer is compressed.
private:
unsigned char m_reserved3[7];
};
#if !defined(ON_OS_WINDOWS_GDI)
// These are the values of the Windows defines mentioned
// in the comment below. If you're running on Windows,
// they get defined by Windows system header files.
// If you aren't running on Windows, then you don't
// need them.
//#define BI_RGB 0L
//#define BI_RLE8 1L
//#define BI_RLE4 2L
//#define BI_BITFIELDS 3L
// Mimics Windows BITMAPINFOHEADER structure.
// For details searh for "BITMAPINFOHEADER" at http://msdn.microsoft.com/default.asp
struct ON_WindowsBITMAPINFOHEADER
{
unsigned int biSize; // DWORD = sizeof(BITMAPINFOHEADER)
int biWidth; // LONG = width (in pixels) of (decompressed) bitmap
int biHeight; // LONG = height (in pixels) of (decompressed) bitmap
// >0 means it's a bottom-up bitmap with origin
// in the lower left corner.
// <0 means it's a top-down bitmap with origin
// in the upper left corner.
unsigned short biPlanes; // WORD = number of planes
// (always 1 in current Windows versions)
unsigned short biBitCount; // WORD = bits per pixel (0,1,4,8,16,24,32 are valid)
// 1 See http://msdn.microsoft.com/default.asp
// 4 See http://msdn.microsoft.com/default.asp
// 8 The bitmap has a maximum of 256 colors,
// and the bmiColors member contains up
// to 256 entries. In this case, each byte
// in the array represents a single pixel.
// 16 See http://msdn.microsoft.com/default.asp
// 24 If biClrUsed=0 and biCompression=BI_RGB(0),
// then each 3-byte triplet in the bitmap
// array represents the relative intensities
// of blue, green, and red, respectively, for
// a pixel. For other possibilities, see
// http://msdn.microsoft.com/default.asp
// 32 If biClrUsed=0 and biCompression=BI_RGB(0),
// then each 4-byte DWORD in the bitmap
// array represents the relative intensities
// of blue, green, and red, respectively, for
// a pixel. The high byte in each DWORD is not
// used.
// If biClrUsed=3, biCompression=BITFIELDS(3),
// biColors[0] = red mask (0x00FF0000),
// biColors[1] = green mask (0x0000FF00), and
// biColors[2] = blue mask (0x000000FF),
// then tese masks are used with each 4-byte
// DWORD in the bitmap array to determine
// the pixel's relative intensities. //
// For other possibilities, see
// http://msdn.microsoft.com/default.asp
unsigned int biCompression; // DWORD Currently, Windows defines the following
// types of compression.
// =0 BI_RGB (no compression)
// =1 BI_RLE8 (run length encoded used for 8 bpp)
// =2 BI_RLE4 (run length encoded used for 4 bpp)
// =3 BI_BITFIELDS Specifies that the bitmap is
// not compressed and that the color table
// consists of three DWORD color masks that
// specify the red, green, and blue components,
// respectively, of each pixel. This is valid
// when used with 16- and 32-bit-per-pixel
// bitmaps.
// =4 BI_JPEG (not supported in Win 95/NT4)
//
unsigned int biSizeImage; // DWORD = bytes in image
int biXPelsPerMeter; // LONG
int biYPelsPerMeter; // LONG
unsigned int biClrUsed; // DWORD = 0 or true length of bmiColors[] array. If 0,
// then the value of biBitCount determines the
// length of the bmiColors[] array.
unsigned int biClrImportant; // DWORD
};
struct ON_WindowsRGBQUAD {
// Mimics Windows RGBQUAD structure.
// For details searh for "RGBQUAD" at http://msdn.microsoft.com/default.asp
unsigned char rgbBlue; // BYTE
unsigned char rgbGreen; // BYTE
unsigned char rgbRed; // BYTE
unsigned char rgbReserved; // BYTE
};
struct ON_WindowsBITMAPINFO
{
// Mimics Windows BITMAPINFO structure.
// For details searh for "BITMAPINFO" at http://msdn.microsoft.com/default.asp
ON_WindowsBITMAPINFOHEADER bmiHeader;
ON_WindowsRGBQUAD bmiColors[1]; // The "[1]" is for the compiler. In
// practice this array commonly has
// length 0, 3, or 256 and a BITMAPINFO*
// points to a contiguous piece of memory
// that contains
//
// BITMAPINFOHEADER
// RGBQUAD[length determined by flags]
// unsigned char[biSizeImage]
//
// See the ON_WindowsBITMAPINFOHEADER comments
// and http://msdn.microsoft.com/default.asp
// for more details.
};
#endif
// OBSOLETE // class ON_OpenGLBitmap;
class ON_CLASS ON_WindowsBitmap : public ON_Bitmap
{
ON_OBJECT_DECLARE(ON_WindowsBitmap);
// Uncompressed 8 bpp, 24 bpp, or 32 bpp Windows device
// independent bitmaps (DIB)
public:
ON_WindowsBitmap();
ON_WindowsBitmap( const ON_WindowsBitmap& );
~ON_WindowsBitmap();
ON_WindowsBitmap& operator=( const ON_WindowsBitmap& );
void EmergencyDestroy();
void Destroy();
bool Create(
int, // width
int, // height
int // bits per pixel ( 1, 2, 4, 8, 16, 24, or 32 )
);
/*
Description:
Tests an object to see if its data members are correctly
initialized.
Parameters:
text_log - [in] if the object is not valid and text_log
is not NULL, then a brief englis description of the
reason the object is not valid is appened to the log.
The information appended to text_log is suitable for
low-level debugging purposes by programmers and is
not intended to be useful as a high level user
interface tool.
Returns:
@untitled table
true object is valid
false object is invalid, uninitialized, etc.
Remarks:
Overrides virtual ON_Object::IsValid
*/
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
ON_BOOL32 Write( ON_BinaryArchive& ) const; // writes compressed image
ON_BOOL32 Read( ON_BinaryArchive& ); // reads compressed image
bool WriteCompressed( ON_BinaryArchive& ) const;
bool ReadCompressed( ON_BinaryArchive& );
bool WriteUncompressed( ON_BinaryArchive& ) const;
bool ReadUncompressed( ON_BinaryArchive& );
int Width() const;
int Height() const; // >0 means it's a bottom-up bitmap with origin at lower right
// <0 means it's a top-down bitmap with origin at upper left
int PaletteColorCount() const; // number of colors in palette
int SizeofPalette() const; // number of bytes in palette
int BitsPerPixel() const;
//int SizeofPixel() const; // number of bytes per pixel
int SizeofScan() const; // number of bytes per scan line
int SizeofImage() const; // number of bytes in image
unsigned char* Bits(
int // index of scan line
);
const unsigned char* Bits(
int // index of scan line
) const;
//int PaletteIndex( ON_Color ) const; // for 8bpp bitmaps
ON_Color Pixel(
int, // 0 <= i < width
int // 0 <= j < height
) const;
ON_Color Pixel(
int, // 0 <= i < width
const unsigned char* // value of Bits( j )
) const;
//ON_BOOL32 SetColor( // sets entire map to specified color
// ON_Color
// );
#if defined(ON_OS_WINDOWS_GDI)
/*
Description:
Create an ON_WindowsBitmap from a contiguous bitmap.
Copies src.
Parameters:
src - [in] contiguous Windows device independent bitmap.
Remarks:
If the current Windows BITMAPINFO is identical to ON_WindowsBITMAPINFO,
then the result of this call is identical to
int color_count = number of colors in bitmap's palette;
ON_WindowsBitmap::Create( &src, &src.bmiColors[color_count], true ).
See Also:
ON_WindowsBitmap::Create
*/
ON_WindowsBitmap( const BITMAPINFO& src );
/*
Description:
Create an ON_WindowsBitmap from a contiguous bitmap.
Shares bitmap memory with src.
Parameters:
src - [in] contiguous Windows device independent bitmap.
See Also:
ON_WindowsBitmap::Create
Remarks:
~ON_WindowsBitmap will not delete src.
*/
ON_WindowsBitmap( const BITMAPINFO* src );
/*
Description:
Create an ON_WindowsBitmap from a contiguous bitmap.
Copies src.
Parameters:
src - [in] contiguous Windows device independent bitmap.
See Also:
ON_WindowsBitmap::Create
*/
ON_WindowsBitmap& operator=( const BITMAPINFO& src );
/*
Description:
Create and ON_WindowsBitmap from a Windows BITMAPINFO pointer
and a pointer to the bits.
This is intended to make it easy to write compressed bimaps.
For ON_WindowsBitmap classes created with ON_WindowsBitmap::Share,
ON_WindowsBitmap::Destroy and ~ON_WindowsBitmap will
not free the bmi and bits memory.
Parameters:
bmi - [in] valid BITMAPINFO
bits - [in] bits for BITMAPINFO
bCopy - [in] If true, the bmi and bits are copied into a contiguous
bitmap that will be deleted by ~ON_WindowsBitmap.
If false, the m_bmi and m_bits pointers on this class
are simply set to bmi and bits. In this case,
~ON_WindowsBitmap will not free the bmi or bits
memory.
Example:
ON_BinaryArchive archive = ...;
BITMAPINFO* bmi = 0;
unsigned char* bits = 0;
int color_count = ...; // number of colors in palette
int sizeof_palette = sizeof(bmi->bmiColors[0]) * color_count;
BITMAPINFO* bmi = (LPBITMAPINFO)calloc( 1, sizeof(*bmi) + sizeof_palette );
bmi->bmiHeader.biSize = sizeof(bmi->bmiHeader);
bmi->bmiHeader.biWidth = width;
bmi->bmiHeader.biHeight = height;
bmi->bmiHeader.biPlanes = 1;
bmi->bmiHeader.biBitCount = (USHORT)color_depth;
bmi->bmiHeader.biCompression = BI_RGB;
bmi->bmiHeader.biXPelsPerMeter = 0;
bmi->bmiHeader.biYPelsPerMeter = 0;
bmi->bmiHeader.biClrUsed = 0;
bmi->bmiHeader.biClrImportant = 0;
bmi->bmiHeader.biSizeImage = GetStorageSize();
// initialize palette
...
HBITMAP hbm = ::CreateDIBSection( NULL, bmi, ..., (LPVOID*)&bits, NULL, 0);
{
// Use ON_WindowsBitmap to write a compressed bitmap to
// archive. Does not modify bmi or bits.
ON_WindowsBitmap onbm;
onbm.Create(bmi,bit,false);
onbm.Write( arcive );
}
*/
bool Create( const BITMAPINFO* bmi,
const unsigned char* bits,
bool bCopy
);
#endif
/*
Returns:
True if m_bmi and m_bits are in a single contiguous
block of memory.
False if m_bmi and m_bits are in two blocks of memory.
*/
bool IsContiguous() const;
#if defined(ON_OS_WINDOWS_GDI)
BITMAPINFO* m_bmi;
#else
struct ON_WindowsBITMAPINFO* m_bmi;
#endif
unsigned char* m_bits;
private:
int m_bFreeBMI; // 0 m_bmi and m_bits are not freed by ON_WindowsBitmap::Destroy
// 1 m_bmi memory is freed by ON_WindowsBitmap::Destroy
// 2 m_bits memory is freed by ON_WindowsBitmap::Destroy
// 3 m_bmi and m_bits memory is freed by ON_WindowsBitmap::Destroy
};
/*
Description:
ON_WindowsBitmapEx is identical to ON_WindowsBitmap except that
it's Read/Write functions save bitmap names.
*/
class ON_CLASS ON_WindowsBitmapEx : public ON_WindowsBitmap
{
ON_OBJECT_DECLARE(ON_WindowsBitmapEx);
public:
ON_WindowsBitmapEx();
~ON_WindowsBitmapEx();
ON_BOOL32 Write( ON_BinaryArchive& ) const; // writes compressed image
ON_BOOL32 Read( ON_BinaryArchive& ); // reads compressed image
};
class ON_CLASS ON_EmbeddedBitmap : public ON_Bitmap
{
ON_OBJECT_DECLARE(ON_EmbeddedBitmap);
public:
ON_EmbeddedBitmap();
~ON_EmbeddedBitmap();
void EmergencyDestroy();
void Destroy();
void Create( int sizeof_buffer );
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
ON_BOOL32 Write( ON_BinaryArchive& ) const;
ON_BOOL32 Read( ON_BinaryArchive& );
int Width() const;
int Height() const;
int BitsPerPixel() const;
int SizeofScan() const;
int SizeofImage() const;
unsigned char* Bits(int);
const unsigned char* Bits(int) const;
void* m_buffer;
size_t m_sizeof_buffer;
int m_free_buffer; // 1 = ~ON_EmbeddedBitmap will onfree m_buffer.
ON__UINT32 m_biffer_crc32; // 32 bit crc from ON_CRC32
};
#endif

3310
extern/opennurbs/opennurbs_bounding_box.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

713
extern/opennurbs/opennurbs_bounding_box.h vendored Executable file
View File

@@ -0,0 +1,713 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(ON_BOUNDING_BOX_INC_)
#define ON_BOUNDING_BOX_INC_
////////////////////////////////////////////////////////////////
//
// ON_BoundingBox - axis aligned bounding box
//
class ON_CLASS ON_BoundingBox
{
public:
static const ON_BoundingBox EmptyBoundingBox; // ((1.0,0,0,0,0),(-1.0,0.0,0.0))
ON_BoundingBox(); // creates EmptyBox
ON_BoundingBox(
const ON_3dPoint&, // min corner of axis aligned bounding box
const ON_3dPoint& // max corner of axis aligned bounding box
);
~ON_BoundingBox();
// temporary - use ON_ClippingRegion - this function will be removed soon.
int IsVisible(
const ON_Xform& bbox2c
) const;
void Destroy(); // invalidates bounding box
// operator[] returns min if index <= 0 and max if indes >= 1
ON_3dPoint& operator[](int);
const ON_3dPoint& operator[](int) const;
ON_3dPoint Min() const;
ON_3dPoint Max() const;
ON_3dVector Diagonal() const; // max corner - min corner
ON_3dPoint Center() const;
ON_3dPoint Corner( // 8 corners of box
int, // x_index 0 = Min().x, 1 = Max().x
int, // y_index 0 = Min().y, 1 = Max().y
int // z_index 0 = Min().z, 1 = Max().z
) const;
bool GetCorners(
ON_3dPointArray& box_corners // returns list of 8 corner points
) const;
bool GetCorners(
ON_3dPoint box_corners[8] // returns list of 8 corner points
) const;
/*
Parameters:
edges[] - out
12 edge lines. If the bounding box has no height, width or depth,
then the corresponding edges will have the same "from" and "to"
points.
Returns:
If the bounding box is valid, then true is returned and
12 line segments, some possibly a single point, are returned.
Otherwise false is returned and 12 line segments with "from"
and "to" points set to ON_3dPoint::UnsetPoint are returned.
*/
bool GetEdges(
ON_Line edges[12] // returns list of 12 edge segments
) const;
bool IsValid() const; // empty boxes are not valid
void Dump(class ON_TextLog&) const;
/*
Description:
Test a bounding box to see if it is degenerate (flat)
in one or more directions.
Parameters:
tolerance - [in] Distances <= tolerance will be considered
to be zero. If tolerance is negative (default), then
a scale invarient tolerance is used.
Returns:
@untitled table
0 box is not degenerate
1 box is a rectangle (degenerate in one direction)
2 box is a line (degenerate in two directions)
3 box is a point (degenerate in three directions)
4 box is not valid
*/
int IsDegenerate(
double tolerance = ON_UNSET_VALUE
) const;
//////////
// ON_BoundingBox::Transform() updates the bounding box
// to be the smallest axis aligned bounding box that contains
// the transform of the eight corner points of the input
// bounding box.
bool Transform( const ON_Xform& );
double Tolerance() const; // rough guess at a tolerance to use for comparing
// objects in this bounding box
// All of these Set() functions set or expand a box to enclose the points in the arguments
// If bGrowBox is true, the existing box is expanded, otherwise it is only set to the current point list
bool Set(
int dim,
int is_rat,
int count,
int stride,
const double* point_array,
int bGrowBox = false
);
bool Set(
const ON_3dPoint& point,
int bGrowBox = false
);
bool Set(
const ON_2dPoint& point,
int bGrowBox = false
);
bool Set(
const ON_SimpleArray<ON_4dPoint>& point_array,
int bGrowBox = false
);
bool Set(
const ON_SimpleArray<ON_3dPoint>& point_array,
int bGrowBox = false
);
bool Set(
const ON_SimpleArray<ON_2dPoint>& point_array,
int bGrowBox = false
);
bool Set(
int dim,
int is_rat,
int count,
int stride,
const float* point_array,
int bGrowBox = false
);
bool Set(
const ON_3fPoint& point,
int bGrowBox = false
);
bool Set(
const ON_2fPoint& point,
int bGrowBox = false
);
bool Set(
const ON_SimpleArray<ON_4fPoint>& point_array,
int bGrowBox = false
);
bool Set(
const ON_SimpleArray<ON_3fPoint>& point_array,
int bGrowBox = false
);
bool Set(
const ON_SimpleArray<ON_2fPoint>& point_array,
int bGrowBox = false
);
bool IsPointIn(
const ON_3dPoint& test_point, // point to test
int bStrictlyIn = false
// true to test for strict ( min < point < max )
// false to test for (min <= point <= max)
//
) const;
//////////
// Point on or in the box that is closest to test_point.
// If test_point is in or on the box, the test_point is returned.
ON_3dPoint ClosestPoint(
const ON_3dPoint& test_point
) const;
/*
Description:
Quickly find a lower bound on the distance
between the point and this bounding box.
Parameters:
P - [in]
Returns:
A distance that is less than or equal to the shortest
distance from the line to this bounding box.
Put another way, if Q is any point in this bounding box,
then P.DistanceTo(Q) >= MinimumDistanceTo(bbox).
*/
double MinimumDistanceTo( const ON_3dPoint& P ) const;
/*
Description:
Quickly find an upper bound on the distance
between the point and this bounding box.
Parameters:
P - [in]
Returns:
A distance that is greater than or equal to the
longest distance from the point P to this bounding box.
Put another way, if Q is any point in this bounding box,
then P.DistanceTo(Q) <= MaximumDistanceTo(bbox).
*/
double MaximumDistanceTo( const ON_3dPoint& P ) const;
/*
Description:
Quickly find a lower bound on the distance
between this and the other bounding box.
Parameters:
other - [in]
Returns:
A distance that is less than or equal to the shortest
distance between the bounding boxes.
Put another way, if Q is any point in this bounding box
and P is any point in the other bounding box,
then P.DistanceTo(Q) >= MinimumDistanceTo(bbox).
*/
double MinimumDistanceTo( const ON_BoundingBox& other ) const;
/*
Description:
Quickly find an upper bound on the distance
between this and the other bounding box.
Parameters:
other - [in]
Returns:
A distance that is greater than or equal to the longest
distance between the bounding boxes.
Put another way, if Q is any point in this bounding box
and P is any point in the other bounding box,
then P.DistanceTo(Q) <= MaximumDistanceTo(bbox).
*/
double MaximumDistanceTo( const ON_BoundingBox& other ) const;
/*
Description:
Quickly find a lower bound on the distance
between the line segment and this bounding box.
Parameters:
line - [in]
Returns:
A distance that is less than or equal to the shortest
distance from the line to this bounding box.
Put another way, if Q is any point on line
and P is any point in this bounding box, then
P.DistanceTo(Q) >= MinimumDistanceTo(bbox).
*/
double MinimumDistanceTo( const ON_Line& line ) const;
/*
Description:
Quickly find a tight lower bound on the distance
between the plane and this bounding box.
Parameters:
plane - [in]
Returns:
The minimum distance between a point on the plane
and a point on the bounding box.
See Also:
ON_PlaneEquation::MimimumValueAt
ON_PlaneEquation::MaximumValueAt
*/
double MinimumDistanceTo( const ON_Plane& plane ) const;
double MinimumDistanceTo( const ON_PlaneEquation& plane_equation ) const;
/*
Description:
Quickly find an upper bound on the distance
between the line segment and this bounding box.
Parameters:
line - [in]
Returns:
A distance that is greater than or equal to the
longest distance from the line to this bounding box.
Put another way, if Q is any point on the line
and P is any point in this bounding box, then
P.DistanceTo(Q) <= MaximumDistanceTo(bbox).
*/
double MaximumDistanceTo( const ON_Line& line ) const;
/*
Description:
Quickly find a tight upper bound on the distance
between the plane and this bounding box.
Parameters:
plane - [in]
Returns:
A distance that is equal to the longest distance from
the plane to this bounding box. Put another way,
if Q is any point on the plane and P is any point
in this bounding box, then
P.DistanceTo(Q) <= MaximumDistanceTo(bbox) and there
is at least one point on the bounding box where the
distance is equal to the returned value.
See Also:
ON_PlaneEquation::MaximumValueAt
*/
double MaximumDistanceTo( const ON_Plane& plane ) const;
double MaximumDistanceTo( const ON_PlaneEquation& plane_equation ) const;
/*
Description:
Quickly determine if the shortest distance from
the point P to the bounding box is greater than d.
Parameters:
d - [in] distance (> 0.0)
P - [in]
Returns:
True if if the shortest distance from the point P
to the bounding box is greater than d.
*/
bool IsFartherThan( double d, const ON_3dPoint& P ) const;
/*
Description:
Quickly determine if the shortest distance from the line
to the bounding box is greater than d.
Parameters:
d - [in] distance (> 0.0)
line - [in]
Returns:
True if the shortest distance from the line
to the bounding box is greater than d. It is not the
case that false means that the shortest distance
is less than or equal to d.
*/
bool IsFartherThan( double d, const ON_Line& line ) const;
/*
Description:
Quickly determine if the shortest distance from the plane
to the bounding box is greater than d.
Parameters:
d - [in] distance (> 0.0)
plane - [in]
Returns:
True if the shortest distance from the plane
to the bounding box is greater than d, and false
if the shortest distance is less than or equal to d.
*/
bool IsFartherThan( double d, const ON_Plane& plane ) const;
/*
Description:
Quickly determine if the shortest distance from the plane
to the bounding box is greater than d.
Parameters:
d - [in] distance (> 0.0)
plane_equation - [in] (the first three coefficients
are assumed to be a unit vector.
If not, adjust your d accordingly.)
Returns:
True if the shortest distance from the plane
to the bounding box is greater than d, and false
if the shortest distance is less than or equal to d.
*/
bool IsFartherThan( double d, const ON_PlaneEquation& plane_equation ) const;
/*
Description:
Quickly determine if the shortest distance this bounding
box to another bounding box is greater than d.
Parameters:
d - [in] distance (> 0.0)
other - [in] other bounding box
Returns:
True if if the shortest distance from this bounding
box to the other bounding box is greater than d.
*/
bool IsFartherThan( double d, const ON_BoundingBox& other ) const;
// Description:
// Get point in a bounding box that is closest to a line
// segment.
// Parameters:
// line - [in] line segment
// box_point - [out] point in box that is closest to line
// segment point at t0.
// t0 - [out] parameter of point on line that is closest to
// the box.
// t1 - [out] parameter of point on line that is closest to
// the box.
// Returns:
// 3 success - line segments intersects box in a segment
// from line(t0) to line(t1) (t0 < t1)
// 2 success - line segments intersects box in a single point
// at line(t0) (t0==t1)
// 1 success - line segment does not intersect box. Closest
// point on the line is at line(t0) (t0==t1)
// 0 failure - box is invalid.
// Remarks:
// The box is treated as a solid box. If the intersection
// of the line segment, then 3 is returned.
int GetClosestPoint(
const ON_Line&, // line
ON_3dPoint&, // box_point
double*, // t0
double* // t1
) const;
//////////
// Get points on bounding boxes that are closest to each other.
// If the boxes intersect, then the point at the centroid of the
// intersection is returned for both points.
bool GetClosestPoint(
const ON_BoundingBox&, // "other" bounding box
ON_3dPoint&, // point on "this" box that is closest to "other" box
ON_3dPoint& // point on "other" box that is closest to "this" box
) const;
//////////
// Point on the box that is farthest from the test_point.
ON_3dPoint FarPoint(
const ON_3dPoint& // test_point
) const;
//////////
// Get points on bounding boxes that are farthest from each other.
bool GetFarPoint(
const ON_BoundingBox&, // "other" bounding box
ON_3dPoint&, // point on "this" box that is farthest from "other" box
ON_3dPoint& // point on "other" box that is farthest from "this" box
) const;
/*
Description:
Intersect this with other_bbox and save intersection in this.
Parameters:
other_bbox - [in]
Returns:
True if this-intesect-other_bbox is a non-empty valid bounding box
and this is set. False if the intersection is empty, in which case
"this" is set to an invalid bounding box.
Remarks:
If "this" or other_bbox is invalid, they are treated as
the empty set, and false is returned.
*/
bool Intersection(
const ON_BoundingBox& other_bbox
);
/*
Description:
Set "this" to the intersection of bbox_A and bbox_B.
Parameters:
bbox_A - [in]
bbox_B - [in]
Returns:
True if the "this" is a non-empty valid bounding box.
False if the intersection is empty, in which case
"this" is set to an invalid bounding box.
Remarks:
If bbox_A or bbox_B is invalid, they are treated as
the empty set, and false is returned.
*/
bool Intersection( // this = intersection of two args
const ON_BoundingBox& bbox_A,
const ON_BoundingBox& bbox_B
);
bool Intersection( //Returns true when intersect is non-empty.
const ON_Line&, //Infinite Line segment to intersect with
double* =NULL , // t0 parameter of first intersection point
double* =NULL // t1 parameter of last intersection point (t0<=t1)
) const;
/*
Description:
Test a box to see if it is contained in this box.
Parameters:
other - [in] box to test
bProperSubSet - [in] if true, then the test is for a proper inclusion.
Returns:
If bProperSubSet is false, then the result is true when
this->m_min[i] <= other.m_min[i] and other.m_max[i] <= this->m_max[i].
for i=0,1 and 2.
If bProperSubSet is true, then the result is true when
the above condition is true and at least one of the inequalities is strict.
*/
bool Includes(
const ON_BoundingBox& other,
bool bProperSubSet = false
) const;
double Volume() const;
double Area() const;
// Union() returns true if union is not empty.
// Invalid boxes are treated as the empty set.
bool Union( // this = this union arg
const ON_BoundingBox&
);
bool Union( // this = union of two args
const ON_BoundingBox&,
const ON_BoundingBox&
);
/*
Description:
Test to see if "this" and other_bbox are disjoint (do not intersect).
Parameters:
other_bbox - [in]
Returns:
True if "this" and other_bbox are disjoint.
Remarks:
If "this" or other_bbox is invalid, then true is returned.
*/
bool IsDisjoint(
const ON_BoundingBox& other_bbox
) const;
bool SwapCoordinates( int, int );
ON_3dPoint m_min;
ON_3dPoint m_max;
};
#if defined(ON_DLL_TEMPLATE)
// This stuff is here because of a limitation in the way Microsoft
// handles templates and DLLs. See Microsoft's knowledge base
// article ID Q168958 for details.
#pragma warning( push )
#pragma warning( disable : 4231 )
ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_BoundingBox>;
#pragma warning( pop )
#endif
/*
Description:
Get a tight bounding box that contains the points.
Parameters:
dim - [in] (>=1)
is_rat - [in] true if points are rational
count - [in] number of points
stride - [in] stride between points
point_list - [in]
bbox - [in/out]
bGrowBox - [in] (default = false)
If the input bbox is valid and bGrowBox is true,
then the output bbox is the union of the input
bbox and the bounding box of the point list.
xform - [in] (default = NULL)
If not null, the bounding box of the transformed
points is calculated. The points are not modified.
Returns:
True if the output bbox is valid.
*/
ON_DECL
bool ON_GetPointListBoundingBox(
int dim,
int is_rat,
int count,
int stride,
const double* point_list,
ON_BoundingBox& bbox,
int bGrowBox = false,
const ON_Xform* xform = 0
);
ON_DECL
bool ON_GetPointListBoundingBox(
int dim,
int is_rat,
int count,
int stride,
const float* point_list,
ON_BoundingBox& bbox,
int bGrowBox = false,
const ON_Xform* xform = 0
);
ON_DECL
bool ON_GetPointListBoundingBox(
int dim,
int is_rat,
int count,
int stride,
const double* point_list,
double* boxmin, // min[dim]
double* boxmax, // max[dim]
int bGrowBox
);
ON_DECL
ON_BoundingBox ON_PointListBoundingBox(
int dim,
int is_rat,
int count,
int stride,
const double* point_list
);
ON_DECL
bool ON_GetPointListBoundingBox(
int dim,
int is_rat,
int count,
int stride,
const float* point_list,
float* boxmin, // min[dim]
float* boxmax, // max[dim]
int bGrowBox
);
ON_DECL
ON_BoundingBox ON_PointListBoundingBox( // low level workhorse function
int dim,
int is_rat,
int count,
int stride,
const float* point_list
);
ON_DECL
bool ON_GetPointGridBoundingBox(
int dim,
int is_rat,
int point_count0, int point_count1,
int point_stride0, int point_stride1,
const double* point_grid,
double* boxmin, // min[dim]
double* boxmax, // max[dim]
int bGrowBox
);
ON_DECL
ON_BoundingBox ON_PointGridBoundingBox(
int dim,
int is_rat,
int point_count0, int point_count1,
int point_stride0, int point_stride1,
const double* point_grid
);
ON_DECL
double ON_BoundingBoxTolerance(
int dim,
const double* bboxmin,
const double* bboxmax
);
/*
Description:
Determine if an object is too large or too far
from the origin for single precision coordinates
to be useful.
Parameters:
bbox - [in]
Bounding box of an object with single precision
coordinates. An ON_Mesh is an example of an
object with single precision coordinates.
xform - [out]
If this function returns false and xform is not
null, then the identity transform is returned.
If this function returns true and xform is not
null, then the transform moves the region
contained in bbox to a location where single
precision coordinates will have enough
information for the object to be useful.
Returns:
true:
The region contained in bbox is too large
or too far from the origin for single
precision coordinates to be useful.
false:
A single precision object contained in bbox
will be satisfactory for common calculations.
*/
ON_DECL
bool ON_BeyondSinglePrecision( const ON_BoundingBox& bbox, ON_Xform* xform );
ON_DECL
bool ON_WorldBBoxIsInTightBBox(
const ON_BoundingBox& tight_bbox,
const ON_BoundingBox& world_bbox,
const ON_Xform* xform
);
#endif

258
extern/opennurbs/opennurbs_box.cpp vendored Executable file
View File

@@ -0,0 +1,258 @@
#include "opennurbs.h"
ON_Box::ON_Box()
{}
ON_Box::ON_Box( const ON_BoundingBox& bbox )
{
Create(bbox);
}
ON_Box::~ON_Box()
{}
void ON_Box::Destroy()
{
plane = ON_xy_plane;
dx.Destroy();
dy.Destroy();
dz.Destroy();
}
bool ON_Box::IsValid() const
{
return ( dx.IsIncreasing()
&& dy.IsIncreasing()
&& dz.IsIncreasing()
&& plane.IsValid()
);
}
bool ON_Box::Create( const ON_BoundingBox& bbox )
{
plane = ON_xy_plane;
dx.Set(bbox.m_min.x,bbox.m_max.x);
dy.Set(bbox.m_min.y,bbox.m_max.y);
dz.Set(bbox.m_min.z,bbox.m_max.z);
return (dx.IsValid() && dy.IsValid() && dz.IsValid());
}
int ON_Box::IsDegenerate( double tolerance ) const
{
int rc = 0;
// 0 box is not degenerate
// 1 box is a rectangle (degenerate in one direction)
// 2 box is a line (degenerate in two directions)
// 3 box is a point (degenerate in three directions)
// 4 box is not valid
if ( !dx.IsIncreasing() || !dy.IsIncreasing() || !dz.IsIncreasing() )
{
rc = 4;
}
else
{
const ON_3dVector diag(dx.Length(),dy.Length(),dz.Length());
if ( !ON_IsValid(tolerance) || tolerance < 0.0 )
{
// compute scale invarient tolerance
tolerance = diag.MaximumCoordinate()*ON_SQRT_EPSILON;
}
if ( diag.x <= tolerance )
rc++;
if ( diag.y <= tolerance )
rc++;
if ( diag.z <= tolerance )
rc++;
}
return rc;
}
ON_3dPoint ON_Box::Center() const
{
return plane.PointAt(dx.Mid(),dy.Mid(),dz.Mid());
}
bool ON_Box::GetCorners( ON_3dPoint* corners ) const
{
int i,j,k,n=0;
double r,s,t;
for( i= 0; i < 2; i++ )
{
r = dx.m_t[i];
for ( j = 0; j < 2; j++ )
{
s = dy.m_t[j];
for ( k = 0; k < 2; k++ )
{
t = dz.m_t[k];
corners[n++] = plane.PointAt(r,s,t);
}
}
}
return true;
}
bool ON_Box::GetCorners( ON_SimpleArray<ON_3dPoint>& corners ) const
{
corners.Empty();
corners.Reserve(8);
bool rc = GetCorners(corners.Array());
if (rc)
corners.SetCount(8);
return rc;
}
ON_BoundingBox ON_Box::BoundingBox() const
{
ON_BoundingBox bbox;
ON_3dPoint corners[8];
if ( GetCorners(corners) )
bbox.Set(3,0,8,3,&corners[0].x,false);
return bbox;
}
ON_3dPoint ON_Box::PointAt(
double r,
double s,
double t
) const
{
// Do not validate - it is too slow.
return plane.PointAt(r,s,t);
}
// returns point on cylinder that is closest to given point
bool ON_Box::ClosestPointTo( ON_3dPoint point, double* r, double* s, double* t ) const
{
// Do not validate box - it is too slow.
const ON_3dVector v = point - plane.origin;
*r = v*plane.xaxis;
if ( *r < dx.m_t[0] )
*r = dx.m_t[0];
else if ( *r > dx.m_t[1] )
*r = dx.m_t[1];
*s = v*plane.yaxis;
if ( *s < dy.m_t[0] )
*s = dy.m_t[0];
else if ( *s > dy.m_t[1] )
*s = dy.m_t[1];
*t = v*plane.zaxis;
if ( *t < dz.m_t[0] )
*t = dz.m_t[0];
else if ( *t > dz.m_t[1] )
*t = dz.m_t[1];
return true;
}
ON_3dPoint ON_Box::ClosestPointTo( ON_3dPoint point ) const
{
// Do not validate - it is too slow.
double r,s,t;
ClosestPointTo(point,&r,&s,&t);
return PointAt(r,s,t);
}
// rotate box about its center
bool ON_Box::Rotate(
double sin_angle,
double cos_angle,
const ON_3dVector& axis // axis of rotation
)
{
return Rotate(sin_angle, cos_angle, axis, Center() );
}
bool ON_Box::Rotate(
double angle, // angle in radians
const ON_3dVector& axis // axis of rotation
)
{
return Rotate(sin(angle), cos(angle), axis, plane.origin );
}
// rotate box about a point and axis
bool ON_Box::Rotate(
double sin_angle,
double cos_angle,
const ON_3dVector& axis, // axis of rotation
const ON_3dPoint& point // center of rotation
)
{
return plane.Rotate( sin_angle, cos_angle, axis, point );
}
bool ON_Box::Rotate(
double angle, // angle in radians
const ON_3dVector& axis, // axis of rotation
const ON_3dPoint& point // center of rotation
)
{
return Rotate(sin(angle),cos(angle),axis,point);
}
bool ON_Box::Translate(
const ON_3dVector& delta
)
{
return plane.Translate(delta);
}
bool ON_Box::Transform( const ON_Xform& xform )
{
ON_3dPoint corners[8];
bool rc = GetCorners(corners);
if ( rc )
{
ON_Plane xplane(plane);
rc = xplane.Transform(xform);
if ( rc )
{
int i;
for ( i = 0; i < 8; i++ )
{
corners[i] = xform*corners[i];
}
double x0,x1,x,y0,y1,y,z0,z1,z;
ON_3dVector v = corners[7] - plane.origin;
x0 = x1 = v*plane.xaxis;
y0 = y1 = v*plane.yaxis;
z0 = z1 = v*plane.zaxis;
for ( i = 0; i < 7; i++ )
{
v = corners[i] - plane.origin;
x = v*plane.xaxis;
if ( x < x0 ) x0 = x; else if (x > x1 ) x1 = x;
y = v*plane.yaxis;
if ( y < y0 ) y0 = y; else if (y > y1 ) y1 = y;
z = v*plane.zaxis;
if ( z < z0 ) z0 = z; else if (z > z1 ) z1 = z;
}
double tol = ON_SQRT_EPSILON;
if ( fabs(dx.ParameterAt(x0)) > tol || fabs(dx.ParameterAt(x1)-1.0) > tol )
dx.Set(x0,x1);
if ( fabs(dy.ParameterAt(y0)) > tol || fabs(dy.ParameterAt(y1)-1.0) > tol )
dy.Set(y0,y1);
if ( fabs(dz.ParameterAt(z0)) > tol || fabs(dz.ParameterAt(z1)-1.0) > tol )
dz.Set(z0,z1);
}
}
return rc;
}
double ON_Box::Volume() const
{
return dx.Length()*dy.Length()*dz.Length();
}
double ON_Box::Area() const
{
double a = dx.Length();
double b = dy.Length();
double c = dz.Length();
return 2.0*(a*b + b*c + c*a);
}

120
extern/opennurbs/opennurbs_box.h vendored Executable file
View File

@@ -0,0 +1,120 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(ON_BOX_INC_)
#define ON_BOX_INC_
class ON_CLASS ON_Box
{
public:
ON_Plane plane;
// intervals are finite and increasing when the box is valid
ON_Interval dx;
ON_Interval dy;
ON_Interval dz;
ON_Box();
ON_Box( const ON_BoundingBox& bbox );
~ON_Box();
bool IsValid() const;
bool Create( const ON_BoundingBox& bbox );
void Destroy();
ON_3dPoint Center() const;
bool GetCorners( ON_3dPoint* corners ) const;
bool GetCorners( ON_SimpleArray<ON_3dPoint>& corners ) const;
ON_BoundingBox BoundingBox() const;
ON_3dPoint PointAt(
double r,
double s,
double t
) const;
bool ClosestPointTo(
ON_3dPoint point,
double* r,
double* s,
double* t
) const;
// returns point on box that is closest to given point
ON_3dPoint ClosestPointTo(
ON_3dPoint test_point
) const;
// rotate sphere about its origin
bool Rotate(
double sin_angle, // sin(angle)
double cos_angle, // cos(angle)
const ON_3dVector& axis_of_rotation // axis of rotation
);
bool Rotate(
double angle_radians, // angle in radians
const ON_3dVector& axis_of_rotation // axis of rotation
);
// rotate sphere about a point and axis
bool Rotate(
double sin_angle, // sin(angle)
double cos_angle, // cos(angle)
const ON_3dVector& axis_of_rotation, // axis of rotation
const ON_3dPoint& center_of_rotation // center of rotation
);
bool Rotate(
double angle_radians, // angle in radians
const ON_3dVector& axis_of_rotation, // axis of rotation
const ON_3dPoint& center_of_rotation // center of rotation
);
bool Translate(
const ON_3dVector&
);
bool Transform( const ON_Xform& );
/*
Description:
Test the box to see if it is degenerate (flat)
in one or more directions.
Parameters:
tolerance - [in] Distances <= tolerance will be considered
to be zero. If tolerance is negative (default), then
a scale invarient tolerance is used.
Returns:
@untitled table
0 box is not degenerate
1 box is a rectangle (degenerate in one direction)
2 box is a line (degenerate in two directions)
3 box is a point (degenerate in three directions)
4 box is not valid
*/
int IsDegenerate(
double tolerance = ON_UNSET_VALUE
) const;
double Volume() const;
double Area() const;
};
#endif

12156
extern/opennurbs/opennurbs_brep.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

4411
extern/opennurbs/opennurbs_brep.h vendored Executable file

File diff suppressed because it is too large Load Diff

1278
extern/opennurbs/opennurbs_brep_extrude.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

1474
extern/opennurbs/opennurbs_brep_io.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

1853
extern/opennurbs/opennurbs_brep_isvalid.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

1216
extern/opennurbs/opennurbs_brep_region.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

2870
extern/opennurbs/opennurbs_brep_tools.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

210
extern/opennurbs/opennurbs_brep_v2valid.cpp vendored Executable file
View File

@@ -0,0 +1,210 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
bool ON_Brep::IsValidForV2( const ON_BrepTrim& trim ) const
{
int ti = trim.m_trim_index;
if ( ti < 0 || ti >= m_T.Count() )
return false;
if ( &trim != &m_T[ti] )
return false;
if ( trim.ProxyCurveIsReversed() )
return false;
if ( trim.Domain() != trim.ProxyCurveDomain() )
return false;
const ON_Curve * curve = trim.TrimCurveOf();
if ( curve != trim.ProxyCurve() )
return false;
const ON_NurbsCurve* nurbs_curve = ON_NurbsCurve::Cast(curve);
if ( 0 == nurbs_curve )
return false;
if ( !nurbs_curve->IsClamped(2) )
return false;
if ( nurbs_curve->m_dim != 2 )
return false;
if ( nurbs_curve->m_is_rat )
{
// 2 June 2003 Dale Lear - RR 8809 fix
// V2 likes end weights to be 1.0
if ( nurbs_curve->m_cv[2] != 1.0 || nurbs_curve->CV(nurbs_curve->m_cv_count-1)[2] != 1.0 )
{
return false;
}
}
if ( nurbs_curve->m_cv_count >= 4
&& 0 == ON_ComparePoint( nurbs_curve->m_dim, nurbs_curve->m_is_rat, nurbs_curve->m_cv, nurbs_curve->CV(nurbs_curve->m_cv_count-1) )
)
{
// 14 April 2003 Dale Lear
// RR 8843 - V2 wants ends of this trim farther apart
if ( trim.m_vi[0] != trim.m_vi[1] )
{
const ON_BrepLoop* loop = Loop(trim.m_li);
if ( 0 != loop && loop->m_ti.Count() > 1 )
return false;
}
}
if ( curve->Domain() != trim.Domain() )
return false;
return true;
}
bool ON_Brep::IsValidForV2( const ON_BrepEdge& edge ) const
{
int ei = edge.m_edge_index;
if ( ei < 0 || ei >= m_E.Count() )
return false;
if ( &edge != &m_E[ei] )
return false;
if ( edge.ProxyCurveIsReversed() )
return false;
if ( edge.Domain() != edge.ProxyCurveDomain() )
return false;
const ON_Curve * curve = edge.EdgeCurveOf();
if ( curve != edge.ProxyCurve() )
return false;
const ON_NurbsCurve* nurbs_curve = ON_NurbsCurve::Cast(curve);
if ( 0 == nurbs_curve )
return false;
if ( !nurbs_curve->IsClamped(2) )
return false;
if ( nurbs_curve->m_dim != 3 )
return false;
if ( nurbs_curve->m_is_rat )
{
// 2 June 2003 Dale Lear - RR 8809 fix
// V2 likes end weights to be 1.0
if ( nurbs_curve->m_cv[3] != 1.0 || nurbs_curve->CV(nurbs_curve->m_cv_count-1)[3] != 1.0 )
{
return false;
}
}
if ( curve->Domain() != edge.Domain() )
return false;
// 14 April 2003 Dale Lear
// RR 8808 - V2 requires edges to be strictly closed/open
if ( nurbs_curve->m_cv_count >= 4
&& 0 == ON_ComparePoint( nurbs_curve->m_dim, nurbs_curve->m_is_rat, nurbs_curve->m_cv, nurbs_curve->CV(nurbs_curve->m_cv_count-1) )
)
{
if ( edge.m_vi[0] != edge.m_vi[1] )
return false;
}
else if (edge.m_vi[0] == edge.m_vi[1] )
{
return false;
}
return true;
}
bool ON_Brep::IsValidForV2() const
{
bool rc = IsValidTopology()?true:false;
if ( rc )
{
int c2i, c3i, si, ti, li, ei, vi, fi, next_ti, lti, next_lti, loop_trim_count;
ON_3dPoint P0, P1;
const int c2_count = m_C2.Count();
const int c3_count = m_C3.Count();
const int s_count = m_S.Count();
const int vertex_count = m_V.Count();
const int edge_count = m_E.Count();
const int face_count = m_F.Count();
const int loop_count = m_L.Count();
const int trim_count = m_T.Count();
for ( c2i = 0; c2i < c2_count; c2i++ )
{
// v2 3dm files expect NURBS curves
if ( !ON_NurbsCurve::Cast(m_C2[c2i]) )
return false;
}
for ( c3i = 0; c3i < c3_count; c3i++ )
{
// v2 3dm files expect NURBS curves
if ( !ON_NurbsCurve::Cast(m_C3[c3i]) )
return false;
}
for ( si = 0; si < s_count; si++ )
{
// v2 3dm files expect NURBS surfaces
if ( !ON_NurbsSurface::Cast(m_S[si]) )
return false;
}
for ( vi = 0; vi < vertex_count; vi++ )
{
const ON_BrepVertex& vertex = m_V[vi];
if ( vertex.m_vertex_index != vi )
return false;
}
for ( fi = 0; fi < face_count; fi++ )
{
const ON_BrepFace& face = m_F[fi];
if ( face.m_face_index != fi )
return false;
}
for ( ti = 0; ti < trim_count; ti++ )
{
if ( !IsValidForV2( m_T[ti] ) )
return false;
}
for ( ei = 0; ei < edge_count; ei++ )
{
if ( !IsValidForV2(m_E[ei]) )
return false;
}
for ( li = 0; li < loop_count; li++ )
{
const ON_BrepLoop& loop = m_L[li];
if ( loop.m_loop_index == -1 )
return false;
loop_trim_count = loop.m_ti.Count();
for ( lti = 0; lti < loop_trim_count; lti++ )
{
next_lti = (lti+1)%loop_trim_count;
ti = loop.m_ti[lti];
next_ti = loop.m_ti[next_lti];
if ( ti < 0 || ti >= trim_count )
return false;
if ( next_ti < 0 || next_ti >= trim_count )
return false;
P0 = m_T[ti].PointAtEnd();
P1 = m_T[next_ti].PointAtStart();
if ( P0.DistanceTo(P1) > ON_ZERO_TOLERANCE )
return false;
}
}
}
return rc;
}

613
extern/opennurbs/opennurbs_circle.cpp vendored Executable file
View File

@@ -0,0 +1,613 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
ON_Circle::ON_Circle()
: radius(1.0)
{
//m_point[0].Zero();
//m_point[1].Zero();
//m_point[2].Zero();
}
ON_Circle::~ON_Circle()
{}
ON_Circle::ON_Circle( const ON_Plane& p, double r )
{
Create( p, r );
}
ON_Circle::ON_Circle( const ON_3dPoint& C, double r )
{
Create( C, r );
}
ON_Circle::ON_Circle( const ON_Plane& pln, const ON_3dPoint& C, double r )
{
Create( pln, C, r );
}
ON_Circle::ON_Circle( const ON_2dPoint& P, const ON_2dPoint& Q, const ON_2dPoint& R )
{
Create(P,Q,R);
}
ON_Circle::ON_Circle( const ON_3dPoint& P, const ON_3dPoint& Q, const ON_3dPoint& R )
{
Create(P,Q,R);
}
double ON_Circle::Radius() const
{
return radius;
}
double ON_Circle::Diameter() const
{
return 2.0*radius;
}
const ON_3dPoint& ON_Circle::Center() const
{
return plane.origin;
}
const ON_3dVector& ON_Circle::Normal() const
{
return plane.zaxis;
}
const ON_Plane& ON_Circle::Plane() const
{
return plane;
}
ON_BoundingBox ON_Circle::BoundingBox() const
{
ON_BoundingBox bbox;
ON_3dPoint corners[4]; // = corners of square that contains circle
corners[0] = plane.PointAt( radius, radius );
corners[1] = plane.PointAt( radius,-radius );
corners[2] = plane.PointAt(-radius, radius );
corners[3] = plane.PointAt(-radius,-radius );
bbox.Set(3,0,4,3,&corners[0].x,false);
return bbox;
}
bool ON_Circle::Transform( const ON_Xform& xform )
{
const ON_Plane plane0(plane);
const bool rc = plane.Transform(xform);
if (!rc)
{
// restore original
plane = plane0;
}
else
{
const double ztol = 1.0e-12;
double a,b,c,d,r1,r2,s;
// determine scale factor in circle's plane
// In practice, transformation are either rotations,
// the scale factor is clearly distinct from 1,
// or the transformation does not map a circle
// to a circle. The code below has tolerance checks
// so that anything that is close to a rotation gets
// treated does not change the radius. If it is
// clearly a uniform scale in the plane of the circle
// the scale factor is calculated without using a
// determinant. Sine "2d scales" are common, it doesn't
// work well use the cubed root of the xform'd determinant.
ON_3dVector V = xform*plane0.xaxis;
a = V*plane.xaxis;
b = V*plane.yaxis;
if (fabs(a) >= fabs(b))
{
r1 = fabs(a);
if ( r1 > 0.0)
{
a = (a>0.0) ? 1.0 : -1.0;
b /= r1;
if ( fabs(b) <= ztol )
{
b = 0.0;
if ( fabs(1.0-r1) <= ztol )
r1 = 1.0;
}
}
}
else
{
r1 = fabs(b);
b = (b>0.0) ? 1.0 : -1.0;
a /= r1;
if ( fabs(a) <= ztol )
{
a = 0.0;
if ( fabs(1.0-r1) <= ztol )
r1 = 1.0;
}
}
V = xform*plane0.yaxis;
c = V*plane.xaxis;
d = V*plane.yaxis;
if (fabs(d) >= fabs(c))
{
r2 = fabs(d);
if (r2 > 0.0)
{
d = (d>0.0) ? 1.0 : -1.0;
c /= r2;
if ( fabs(c) <= ztol )
{
c = 0.0;
if ( fabs(1.0-r2) <= ztol )
r2 = 1.0;
}
}
}
else
{
r2 = fabs(c);
c = (c>0.0) ? 1.0 : -1.0;
d /= r2;
if ( fabs(d) <= ztol )
{
d = 0.0;
if ( fabs(1.0-r2) <= ztol )
r2 = 1.0;
}
}
if ( 0.0 == b
&& 0.0 == c
&& fabs(r1-r2) <= ON_SQRT_EPSILON*(r1+r2)
)
{
// transform is a similarity
s = (r1 == r2) ? r1 : (0.5*(r1+r2)); // = sqrt(r1*r2) but more accurate
}
else
{
// non-uniform scaling or skew in circle's plane
// do something reasonable
s = sqrt(fabs(r1*r2*(a*d-b*c)));
}
if ( s > 0.0 )
{
//#if defined(ON_DEBUG) && !defined(ON_COMPILER_GNU)
//double det = fabs(xform.Determinant());
//double s0 = pow(det,1.0/3.0);
//if ( fabs(s-s0) > ON_SQRT_EPSILON*s0 )
//{
// // non-uniform scale or a bug
// // In the non-uniform scal case, b and c should be
// // "zero".
// int breakpointhere = 0; // (generates gcc warning)
//}
//#endif
if ( fabs(s-1.0) > ON_SQRT_EPSILON )
radius *= s;
}
}
return rc;
}
double ON_Circle::Circumference() const
{
return fabs(2.0*ON_PI*radius);
}
bool ON_Circle::Create( const ON_Plane& p, double r )
{
plane = p;
if ( !plane.IsValid() )
plane.UpdateEquation(); // people often forget to set equation
radius = r;
//m_point[0] = plane.PointAt( radius, 0.0 );
//m_point[1] = plane.PointAt( 0.0, radius );
//m_point[2] = plane.PointAt( -radius, 0.0 );
return ( radius > 0.0 );
}
bool ON_Circle::Create( const ON_3dPoint& C, double r )
{
ON_Plane p = ON_xy_plane;
p.origin = C;
p.UpdateEquation();
return Create( p, r );
}
bool ON_Circle::Create( const ON_Plane& pln,
const ON_3dPoint& C,
double r
)
{
ON_Plane p = pln;
p.origin = C;
p.UpdateEquation();
return Create( p, r );
}
bool ON_Circle::Create( // circle through three 3d points
const ON_2dPoint& P,
const ON_2dPoint& Q,
const ON_2dPoint& R
)
{
return Create(ON_3dPoint(P),ON_3dPoint(Q),ON_3dPoint(R));
}
bool ON_Circle::Create( // circle through three 3d points
const ON_3dPoint& P,
const ON_3dPoint& Q,
const ON_3dPoint& R
)
{
ON_3dPoint C;
ON_3dVector X, Y, Z;
// return ( radius > 0.0 && plane.IsValid() );
//m_point[0] = P;
//m_point[1] = Q;
//m_point[2] = R;
// get normal
for(;;)
{
if ( !Z.PerpendicularTo( P, Q, R ) )
break;
// get center as the intersection of 3 planes
ON_Plane plane0( P, Z );
ON_Plane plane1( 0.5*(P+Q), P-Q );
ON_Plane plane2( 0.5*(R+Q), R-Q );
if ( !ON_Intersect( plane0, plane1, plane2, C ) )
break;
X = P - C;
radius = X.Length();
if ( !(radius > 0.0) )
break;
if ( !X.Unitize() )
break;
Y = ON_CrossProduct( Z, X );
if ( !Y.Unitize() )
break;
plane.origin = C;
plane.xaxis = X;
plane.yaxis = Y;
plane.zaxis = Z;
plane.UpdateEquation();
return true;
}
plane = ON_Plane::World_xy;
radius = 0.0;
return false;
}
//////////
// Create an circle from two 2d points and a tangent at the first point.
bool ON_Circle::Create(
const ON_2dPoint& P, // [IN] point P
const ON_2dVector& Pdir, // [IN] tangent at P
const ON_2dPoint& Q // [IN] point Q
)
{
return Create( ON_3dPoint(P), ON_3dVector(Pdir), ON_3dPoint(Q) );
}
//////////
// Create an circle from two 3d points and a tangent at the first point.
bool ON_Circle::Create(
const ON_3dPoint& P, // [IN] point P
const ON_3dVector& Pdir, // [IN] tangent at P
const ON_3dPoint& Q // [IN] point Q
)
{
bool rc = false;
double a, b;
ON_3dVector QP, RM, RP, X, Y, Z;
ON_3dPoint M, C;
ON_Line A, B;
// n = normal to circle
QP = Q-P;
Z = ON_CrossProduct( QP, Pdir );
if ( Z.Unitize() ) {
M = 0.5*(P+Q);
RM = ON_CrossProduct( QP, Z ); // vector parallel to center-M
A.Create(M,M+RM);
RP = ON_CrossProduct( Pdir, Z ); // vector parallel to center-P
B.Create(P,P+RP);
if ( ON_Intersect( A, B, &a, &b ) ) {
C = A.PointAt( a ); // center = intersection of lines A and B
X = P-C;
radius = C.DistanceTo(P);
if ( X.Unitize() ) {
Y = ON_CrossProduct( Z, X );
if ( Y*Pdir < 0.0 ) {
Z.Reverse();
Y.Reverse();
RM.Reverse();
}
plane.origin = C;
plane.xaxis = X;
plane.yaxis = Y;
plane.zaxis = Z;
plane.UpdateEquation();
//m_point[0] = P;
//m_point[1] = C + radius*RM/RM.Length();
//m_point[2] = Q;
rc = IsValid();
}
}
}
return rc;
}
bool ON_Circle::IsValid() const
{
bool rc = ( ON_IsValid(radius)
&& radius > 0.0
&& plane.IsValid()
);
return rc;
}
bool ON_Circle::IsInPlane( const ON_Plane& plane, double tolerance ) const
{
double d;
int i;
for ( i = 0; i < 8; i++ ) {
d = plane.plane_equation.ValueAt( PointAt(0.25*i*ON_PI) );
if ( fabs(d) > tolerance )
return false;
}
return true;
}
ON_3dPoint ON_Circle::PointAt( double t ) const
{
return plane.PointAt( cos(t)*radius, sin(t)*radius );
}
ON_3dVector ON_Circle::DerivativeAt(
int d, // desired derivative ( >= 0 )
double t // parameter
) const
{
double r0 = radius;
double r1 = radius;
switch (abs(d)%4) {
case 0:
r0 *= cos(t);
r1 *= sin(t);
break;
case 1:
r0 *= -sin(t);
r1 *= cos(t);
break;
case 2:
r0 *= -cos(t);
r1 *= -sin(t);
break;
case 3:
r0 *= sin(t);
r1 *= -cos(t);
break;
}
return ( r0*plane.xaxis + r1*plane.yaxis );
}
ON_3dVector ON_Circle::TangentAt( double t ) const
{
ON_3dVector T = DerivativeAt(1,t);
T.Unitize();
return T;
}
bool ON_Circle::ClosestPointTo( const ON_3dPoint& point, double* t ) const
{
bool rc = true;
if ( t ) {
double u, v;
rc = plane.ClosestPointTo( point, &u, &v );
if ( u == 0.0 && v == 0.0 ) {
*t = 0.0;
}
else {
*t = atan2( v, u );
if ( *t < 0.0 )
*t += 2.0*ON_PI;
}
}
return rc;
}
ON_3dPoint ON_Circle::ClosestPointTo( const ON_3dPoint& point ) const
{
ON_3dPoint P;
ON_3dVector V = plane.ClosestPointTo( point ) - Center();
if ( V.Unitize() ) {
V.Unitize();
P = Center() + Radius()*V;
}
else {
P = PointAt(0.0);
}
return P;
}
double ON_Circle::EquationAt(
const ON_2dPoint& p // coordinates in plane
) const
{
double e, x, y;
if ( radius != 0.0 ) {
x = p.x/radius;
y = p.y/radius;
e = x*x + y*y - 1.0;
}
else {
e = 0.0;
}
return e;
}
ON_2dVector ON_Circle::GradientAt(
const ON_2dPoint& p // coordinates in plane
) const
{
ON_2dVector g;
if ( radius != 0.0 ) {
const double rr = 2.0/(radius*radius);
g.x = rr*p.x;
g.y = rr*p.y;
}
else {
g.Zero();
}
return g;
}
bool ON_Circle::Rotate(
double sin_angle, double cos_angle,
const ON_3dVector& axis
)
{
return plane.Rotate( sin_angle, cos_angle, axis );
}
bool ON_Circle::Rotate(
double angle,
const ON_3dVector& axis
)
{
return plane.Rotate( angle, axis );
}
bool ON_Circle::Rotate(
double sin_angle, double cos_angle,
const ON_3dVector& axis,
const ON_3dPoint& point
)
{
return plane.Rotate( sin_angle, cos_angle, axis, point );
}
bool ON_Circle::Rotate(
double angle,
const ON_3dVector& axis,
const ON_3dPoint& point
)
{
return plane.Rotate( angle, axis, point );
}
bool ON_Circle::Translate(
const ON_3dVector& delta
)
{
//m_point[0] += delta;
//m_point[1] += delta;
//m_point[2] += delta;
return plane.Translate( delta );
}
bool ON_Circle::Reverse()
{
//ON_3dPoint P = m_point[0];
//m_point[0] = m_point[2];
//m_point[2] = P;
plane.yaxis = -plane.yaxis;
plane.zaxis = -plane.zaxis;
plane.UpdateEquation();
return true;
}
int ON_Circle::GetNurbForm( ON_NurbsCurve& nurbscurve ) const
{
int rc = 0;
if ( IsValid() ) {
nurbscurve.Create( 3, true, 3, 9 );
nurbscurve.m_knot[0] = nurbscurve.m_knot[1] = 0.0;
nurbscurve.m_knot[2] = nurbscurve.m_knot[3] = 0.5*ON_PI;
nurbscurve.m_knot[4] = nurbscurve.m_knot[5] = ON_PI;
nurbscurve.m_knot[6] = nurbscurve.m_knot[7] = 1.5*ON_PI;
nurbscurve.m_knot[8] = nurbscurve.m_knot[9] = 2.0*ON_PI;
ON_4dPoint* CV = (ON_4dPoint*)nurbscurve.m_cv;
CV[0] = plane.PointAt( radius, 0.0);
CV[1] = plane.PointAt( radius, radius);
CV[2] = plane.PointAt( 0.0, radius);
CV[3] = plane.PointAt(-radius, radius);
CV[4] = plane.PointAt(-radius, 0.0);
CV[5] = plane.PointAt(-radius, -radius);
CV[6] = plane.PointAt( 0.0, -radius);
CV[7] = plane.PointAt( radius, -radius);
CV[8] = CV[0];
const double w = 1.0/sqrt(2.0);
int i;
for ( i = 1; i < 8; i += 2 ) {
CV[i].x *= w;
CV[i].y *= w;
CV[i].z *= w;
CV[i].w = w;
}
rc = 2;
}
return rc;
}
bool ON_Circle::GetRadianFromNurbFormParameter( double NurbParameter, double* RadianParameter ) const
//returns false unless 0<= NurbParameter, <= 2*PI*Radius
{
if(!IsValid())
return false;
ON_Arc arc(*this, 2*ON_PI);
return arc.GetRadianFromNurbFormParameter( NurbParameter, RadianParameter);
}
bool ON_Circle::GetNurbFormParameterFromRadian( double RadianParameter, double* NurbParameter) const
{
if(!IsValid())
return false;
ON_Arc arc(*this, 2*ON_PI);
return arc.GetNurbFormParameterFromRadian( RadianParameter, NurbParameter);
}

325
extern/opennurbs/opennurbs_circle.h vendored Executable file
View File

@@ -0,0 +1,325 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(ON_CIRCLE_INC_)
#define ON_CIRCLE_INC_
class ON_NurbsCurve;
/*
Description:
ON_Circle is a circle in 3d. The cirle is represented by a radius and an
orthonormal frame of the plane containing the circle, with origin at the center.
An Is_Valid() circle has positive radius and an Is_ Valid() plane defining the frame.
The circle is parameterized by radians from 0 to 2 Pi given by
t -> center + cos(t)*radius*xaxis + sin(t)*radius*yaxis
where center, xaxis and yaxis define the orthonormal frame of the circle's plane.
*/
class ON_CLASS ON_Circle
{
public:
// Creates a radius one circle with center (0,0,0)
// in the world XY plane
ON_Circle();
// Creates a circle in the plane with center at
// plane.origin.
ON_Circle(
const ON_Plane& plane,
double radius
);
// Creates a circle parallel to the world XY plane
// with given center and radius
ON_Circle(
const ON_3dPoint& center,
double radius
);
// Creates a circle parallel to the plane
// with given center and radius.
ON_Circle(
const ON_Plane& plane,
const ON_3dPoint& center,
double radius
);
// Create a circle through three 2d points.
// The start/end of the circle is at point P.
ON_Circle( // circle through 3 2d points
const ON_2dPoint& P,
const ON_2dPoint& Q,
const ON_2dPoint& R
);
// Create a circle through three 3d points.
// The start/end of the circle is at point P.
ON_Circle(
const ON_3dPoint& P,
const ON_3dPoint& Q,
const ON_3dPoint& R
);
~ON_Circle();
// Creates a circle in the plane with center at
// plane.origin.
bool Create(
const ON_Plane& plane,
double radius
);
// Creates a circle parallel to the world XY plane
// with given center and radius
bool Create(
const ON_3dPoint& center,
double radius
);
// Creates a circle parallel to the plane
// with given centr and radius.
bool Create(
const ON_Plane& plane,
const ON_3dPoint& center,
double radius
);
// Create a circle through three 2d points.
// The start/end of the circle is at point P.
bool Create( // circle through 3 2d points
const ON_2dPoint& P,
const ON_2dPoint& Q,
const ON_2dPoint& R
);
// Create a circle through three 3d points.
// The start/end of the circle is at point P.
bool Create(
const ON_3dPoint& P,
const ON_3dPoint& Q,
const ON_3dPoint& R
);
// Create a circle from two 2d points and a
// tangent at the first point.
// The start/end of the circle is at point P.
bool Create(
const ON_2dPoint& P,
const ON_2dVector& tangent_at_P,
const ON_2dPoint& Q
);
// Create a circle from two 3d points and a
// tangent at the first point.
// The start/end of the circle is at point P.
bool Create(
const ON_3dPoint& P,
const ON_3dVector& tangent_at_P,
const ON_3dPoint& Q
);
// A Valid circle has m_radius>0 and m_plane.IsValid().
bool IsValid() const;
//bool UpdatePoints(); // sets m_point[] to have valid points
bool IsInPlane( const ON_Plane&, double = ON_ZERO_TOLERANCE ) const;
double Radius() const;
double Diameter() const;
double Circumference() const;
const ON_3dPoint& Center() const;
const ON_3dVector& Normal() const;
const ON_Plane& Plane() const; // plane containing circle
ON_BoundingBox BoundingBox() const;
/*
Description:
Get tight bounding box.
Parameters:
tight_bbox - [in/out] tight bounding box
bGrowBox -[in] (default=false)
If true and the input tight_bbox is valid, then returned
tight_bbox is the union of the input tight_bbox and the
arc's tight bounding box.
xform -[in] (default=NULL)
If not NULL, the tight bounding box of the transformed
arc is calculated. The arc is not modified.
Returns:
True if a valid tight_bbox is returned.
*/
bool GetTightBoundingBox(
ON_BoundingBox& tight_bbox,
int bGrowBox = false,
const ON_Xform* xform = 0
) const;
bool Transform( const ON_Xform& );
// Circles use trigonometric parameterization
// t -> center + cos(t)*radius*xaxis + sin(t)*radius*yaxis
ON_3dPoint PointAt(
double // evaluation parameter
) const;
ON_3dVector DerivativeAt(
int, // derivative (>=0)
double // evaluation parameter
) const;
ON_3dVector TangentAt(double) const;
// returns parameters of point on circle that is closest to given point
bool ClosestPointTo(
const ON_3dPoint& point,
double* t
) const;
// returns point on circle that is closest to given point
ON_3dPoint ClosestPointTo(
const ON_3dPoint& point
) const;
// evaluate circle's implicit equation in plane
double EquationAt( const ON_2dPoint& plane_point ) const;
ON_2dVector GradientAt( const ON_2dPoint& plane_point ) const;
// rotate circle about its center
bool Rotate(
double sin_angle,
double cos_angle,
const ON_3dVector& axis_of_rotation
);
bool Rotate(
double angle_in_radians,
const ON_3dVector& axis_of_rotation
);
// rotate circle about a point and axis
bool Rotate(
double sin_angle,
double cos_angle,
const ON_3dVector& axis_of_rotation,
const ON_3dPoint& center_of_rotation
);
bool Rotate(
double angle_in_radians,
const ON_3dVector& axis_of_rotation,
const ON_3dPoint& center_of_rotation
);
bool Translate(
const ON_3dVector& delta
);
bool Reverse();
// Description:
// Get a four span rational degree 2 NURBS circle representation
// of the circle.
// Returns:
// 2 for success, 0 for failure
// Remarks:
// Note that the parameterization of NURBS curve
// does not match circle's transcendental paramaterization.
// Use ON_Circle::GetRadianFromNurbFormParameter() and
// ON_Circle::GetParameterFromRadian() to convert between
// the NURBS curve parameter and the transcendental parameter.
int GetNurbForm(
ON_NurbsCurve& nurbs_curve
) const;
/*
Description:
Convert a NURBS curve circle parameter to a circle radians parameter.
Parameters:
nurbs_parameter - [in]
circle_radians_parameter - [out]
Example:
ON_Circle circle = ...;
double nurbs_t = 1.2345; // some number in interval (0,2.0*ON_PI).
double circle_t;
circle.GetRadianFromNurbFormParameter( nurbs_t, &circle_t );
ON_NurbsCurve nurbs_curve;
circle.GetNurbsForm( nurbs_curve );
circle_pt = circle.PointAt(circle_t);
nurbs_pt = nurbs_curve.PointAt(nurbs_t);
// circle_pt and nurbs_pt will be the same
Remarks:
The NURBS curve parameter is with respect to the NURBS curve
created by ON_Circle::GetNurbForm. At nurbs parameter values of
0.0, 0.5*ON_PI, ON_PI, 1.5*ON_PI, and 2.0*ON_PI, the nurbs
parameter and radian parameter are the same. At all other
values the nurbs and radian parameter values are different.
See Also:
ON_Circle::GetNurbFormParameterFromRadian
*/
bool GetRadianFromNurbFormParameter(
double nurbs_parameter,
double* circle_radians_parameter
) const;
/*
Description:
Convert a circle radians parameter to a NURBS curve circle parameter.
Parameters:
circle_radians_parameter - [in] 0.0 to 2.0*ON_PI
nurbs_parameter - [out]
Example:
ON_Circle circle = ...;
double circle_t = 1.2345; // some number in interval (0,2.0*ON_PI).
double nurbs_t;
circle.GetNurbFormParameterFromRadian( circle_t, &nurbs_t );
ON_NurbsCurve nurbs_curve;
circle.GetNurbsForm( nurbs_curve );
circle_pt = circle.PointAt(circle_t);
nurbs_pt = nurbs_curve.PointAt(nurbs_t);
// circle_pt and nurbs_pt will be the same
Remarks:
The NURBS curve parameter is with respect to the NURBS curve
created by ON_Circle::GetNurbForm. At radian values of
0.0, 0.5*ON_PI, ON_PI, 1.5*ON_PI, and 2.0*ON_PI, the nurbs
parameter and radian parameter are the same. At all other
values the nurbs and radian parameter values are different.
See Also:
ON_Circle::GetNurbFormParameterFromRadian
*/
bool GetNurbFormParameterFromRadian(
double circle_radians_parameter,
double* nurbs_parameter
) const;
public:
// circle is in the plane with center at plane.m_origin.
ON_Plane plane;
double radius; // radius
//ON_3dPoint m_point[3]; // 3 points on the circle
};
#endif

255
extern/opennurbs/opennurbs_color.cpp vendored Executable file
View File

@@ -0,0 +1,255 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
const ON_Color ON_Color::UnsetColor(ON_UNSET_COLOR);
ON_Color::ON_Color() : m_color(0)
{}
ON_Color::ON_Color(unsigned int colorref) : m_color(colorref)
{}
ON_Color::ON_Color(int r, int g, int b) : m_color(0)
{
SetRGB(r,g,b);
}
ON_Color::ON_Color(int r, int g, int b, int a) : m_color(0)
{
SetRGBA(r,g,b,a);
}
unsigned int ON_Color::WindowsRGB() const
{
unsigned int RGB = ON_Color(Red(),Green(),Blue());
return RGB;
}
ON_Color::operator unsigned int() const
{
return m_color;
}
int ON_Color::Compare( const ON_Color& b ) const
{
unsigned int bc = b;
return (((int)m_color) - ((int)bc));
}
int ON_Color::Red() const
{ return m_color & 0xFF;}
int ON_Color::Green() const
{ return (m_color>>8) & 0xFF;}
int ON_Color::Blue() const
{ return (m_color>>16) & 0xFF;}
int ON_Color::Alpha() const
{ return (m_color>>24) & 0xFF;}
double ON_Color::FractionRed() const
{
//return Red()/255.0;
return (m_color & 0xFF)*0.003921568627450980392156862745; // better fodder for optimizer
}
double ON_Color::FractionGreen() const
{
//return Green()/255.0;
return ((m_color>>8) & 0xFF)*0.003921568627450980392156862745; // better fodder for optimizer
}
double ON_Color::FractionBlue() const
{
//return Blue()/255.0;
return ((m_color>>16) & 0xFF)*0.003921568627450980392156862745; // better fodder for optimizer
}
double ON_Color::FractionAlpha() const
{
//return Alpha()/255.0;
return ((m_color>>24) & 0xFF)*0.003921568627450980392156862745; // better fodder for optimizer
}
void ON_Color::SetRGB(int r,int g,int b) // 0 to 255
{
SetRGBA(r,g,b,0);
}
void ON_Color::SetFractionalRGB(double r,double g,double b)
{
SetFractionalRGBA(r,g,b,0.0);
}
void ON_Color::SetAlpha(int alpha)
{
if (alpha < 0 ) alpha = 0; else if ( alpha > 255 ) alpha = 255;
m_color = (m_color & 0x00FFFFFF) | (alpha << 24 );
}
void ON_Color::SetFractionalAlpha(double alpha)
{
if (alpha < 0.0 ) alpha = 0.0; else if ( alpha > 1.0 ) alpha = 1.0;
SetAlpha((int)(alpha*255.0));
}
void
ON_Color::SetRGBA( int red, int green, int blue, int alpha )
{
if (red < 0 ) red = 0; else if ( red > 255 ) red = 255;
if (green < 0 ) green = 0; else if ( green > 255 ) green = 255;
if (blue < 0 ) blue = 0; else if ( blue > 255 ) blue = 255;
if (alpha < 0 ) alpha = 0; else if ( alpha > 255 ) alpha = 255;
m_color = (alpha << 24 ) | (blue << 16) | (green << 8) | red;
}
void
ON_Color::SetFractionalRGBA( double red, double green, double blue, double alpha )
{
int r,g,b,a;
if (red < 0.0 ) red = 0.0; else if ( red > 1.0 ) red = 1.0;
if (green < 0.0 ) green = 0.0; else if ( green > 1.0 ) green = 1.0;
if (blue < 0.0 ) blue = 0.0; else if ( blue > 1.0 ) blue = 1.0;
if (alpha < 0.0 ) alpha = 0.0; else if ( alpha > 1.0 ) alpha = 1.0;
red *= 255.0;
green *= 255.0;
blue *= 255.0;
alpha *= 255.0;
r = (int)red;
g = (int)green;
b = (int)blue;
a = (int)alpha;
// round to closest int
if( (red-r)>=0.5 ) r++;
if( (green-g)>=0.5 ) g++;
if( (blue-b)>=0.5 ) b++;
if( (alpha-a)>=0.5 ) a++;
SetRGBA( r, g, b, a );
}
double ON_Color::Hue() const
{
// returns 0 to 2*pi
// 0 = red, pi/3 = yellow, 2*pi/3 = green,
// pi = cyan, 4*pi/3 = blue, 5*pi/3 = magenta,
// 2*pi = red
double h;
int r = Red();
int g = Green();
int b = Blue();
int minrgb, maxrgb;
if ( r <= g ) {minrgb = r; maxrgb = g;} else {minrgb = g; maxrgb = r;}
if (minrgb > b) minrgb = b; else if (maxrgb < b ) maxrgb = b;
if ( maxrgb != minrgb ) {
double d = 1.0/(maxrgb - minrgb);
if ( r == maxrgb) {
h = (g - b)*d;
if ( h < 0.0 )
h += 6.0;
}
else if ( g == maxrgb)
h = 2.0 + (b - r)*d;
else
h = 4.0 + (r - g)*d;
h *= ON_PI/3.0;
}
else
h = 0.0;
return h;
}
double ON_Color::Saturation() const
{
// 0.0 to 1.0 0.0 = gray, 1.0 = saturated
double s;
int r = Red();
int g = Green();
int b = Blue();
int minrgb, maxrgb;
if ( r <= g ) {minrgb = r; maxrgb = g;} else {minrgb = g; maxrgb = r;}
if (minrgb > b) minrgb = b; else if (maxrgb < b ) maxrgb = b;
if ( maxrgb > 0 ) {
s = ((double)(maxrgb - minrgb))/((double)maxrgb);
}
else
s = 0.0;
return s;
}
double ON_Color::Value() const
{
// 0.0 to 1.0 0.0 = black, 1.0 = white
int r = Red();
int g = Green();
int b = Blue();
int maxrgb = ( r <= g ) ? g : r; if ( maxrgb < b ) maxrgb = b;
return (maxrgb/255.0);
}
void ON_Color::SetHSV(
double hue, // hue in radians
double saturation, // satuation 0.0 = gray, 1.0 = saturated
double value // value
)
{
int i;
double f, p, q, t, r, g, b;
if ( saturation <= 1.0/256.0 ) {
r = value;
g = value;
b = value;
}
else {
hue *= 3.0 / ON_PI; // (6.0 / 2.0 * ON_PI);
i = (int)floor(hue);
if ( i < 0 || i > 5 ) {
hue = fmod(hue,6.0);
if ( hue < 0.0 )
hue += 6.0;
i = (int)floor(hue);
}
f = hue - i;
p = value * ( 1.0 - saturation);
q = value * ( 1.0 - ( saturation * f) );
t = value * ( 1.0 - ( saturation * ( 1.0 - f) ) );
switch( i)
{
case 0:
r = value; g = t; b = p; break;
case 1:
r = q; g = value; b = p; break;
case 2:
r = p; g = value; b = t; break;
case 3:
r = p; g = q; b = value; break;
case 4:
r = t; g = p; b = value; break;
case 5:
r = value; g = p; b = q; break;
default:
r = 0; g = 0; b = 0; break; // to keep lint quiet
}
}
SetFractionalRGB(r,g,b);
}

138
extern/opennurbs/opennurbs_color.h vendored Executable file
View File

@@ -0,0 +1,138 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_COLOR_INC_)
#define OPENNURBS_COLOR_INC_
///////////////////////////////////////////////////////////////////////////////
//
// Class ON_Color
//
class ON_CLASS ON_Color
{
public:
// Constructors & Conversions - also default copy and assignment
static const ON_Color UnsetColor; // 0xFFFFFFFF
// Default is R = 0, G = 0, B = 0, A = 0
ON_Color();
// Sets A = 0
ON_Color(
int red, // ( 0 to 255 )
int green, // ( 0 to 255 )
int blue // ( 0 to 255 )
);
ON_Color(
int red, // ( 0 to 255 )
int green, // ( 0 to 255 )
int blue, // ( 0 to 255 )
int alpha // ( 0 to 255 ) (0 = opaque, 255 = transparent)
);
// Construct from Windows COLORREF
ON_Color(unsigned int);
// Conversion to Windows COLORREF
operator unsigned int() const;
/*
Description:
Call this function when the color is needed in a
Windows COLORREF format with alpha = 0;
Returns
A Windows COLOREF with alpha = 0.
*/
unsigned int WindowsRGB() const;
// < 0 if this < arg, 0 ir this==arg, > 0 if this > arg
int Compare( const ON_Color& ) const;
int Red() const; // ( 0 to 255 )
int Green() const; // ( 0 to 255 )
int Blue() const; // ( 0 to 255 )
int Alpha() const; // ( 0 to 255 ) (0 = opaque, 255 = transparent)
double FractionRed() const; // ( 0.0 to 1.0 )
double FractionGreen() const; // ( 0.0 to 1.0 )
double FractionBlue() const; // ( 0.0 to 1.0 )
double FractionAlpha() const; // ( 0.0 to 1.0 ) (0.0 = opaque, 1.0 = transparent)
void SetRGB(
int red, // red in range 0 to 255
int green, // green in range 0 to 255
int blue // blue in range 0 to 255
);
void SetFractionalRGB(
double red, // red in range 0.0 to 1.0
double green, // green in range 0.0 to 1.0
double blue // blue in range 0.0 to 1.0
);
void SetAlpha(
int alpha // alpha in range 0 to 255 (0 = opaque, 255 = transparent)
);
void SetFractionalAlpha(
double alpha // alpha in range 0.0 to 1.0 (0.0 = opaque, 1.0 = transparent)
);
void SetRGBA(
int red, // red in range 0 to 255
int green, // green in range 0 to 255
int blue, // blue in range 0 to 255
int alpha // alpha in range 0 to 255 (0 = opaque, 255 = transparent)
);
// input args
void SetFractionalRGBA(
double red, // red in range 0.0 to 1.0
double green, // green in range 0.0 to 1.0
double blue, // blue in range 0.0 to 1.0
double alpha // alpha in range 0.0 to 1.0 (0.0 = opaque, 1.0 = transparent)
);
// Hue() returns an angle in the range 0 to 2*pi
//
// 0 = red, pi/3 = yellow, 2*pi/3 = green,
// pi = cyan, 4*pi/3 = blue,5*pi/3 = magenta,
// 2*pi = red
double Hue() const;
// Returns 0.0 (gray) to 1.0 (saturated)
double Saturation() const;
// Returns 0.0 (black) to 1.0 (white)
double Value() const;
void SetHSV(
double h, // hue in radians 0 to 2*pi
double s, // satuation 0.0 = gray, 1.0 = saturated
double v // value
);
private:
// m_color is in Windows COLORREF format.
//
// 0xaabbggrr, rr= red component 0-255, etc. (little endian order)
// aa=0 means opaque, aa=255 means transparent.
unsigned int m_color;
};
#endif

654
extern/opennurbs/opennurbs_compress.cpp vendored Executable file
View File

@@ -0,0 +1,654 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
struct ON_ZlibImplementation
{
z_stream m_strm;
unsigned char m_zlib_out_buffer[16384];
};
ON_CompressStream::ON_CompressStream()
: m_out_callback_function(0)
, m_out_callback_context(0)
, m_in_size(0)
, m_out_size(0)
, m_in_crc(0)
, m_out_crc(0)
, m_implementation(0)
, m_reserved(0)
{}
ON_CompressStream::~ON_CompressStream()
{
if ( 0 != m_implementation )
{
onfree(m_implementation);
m_implementation = 0;
}
}
void ON_CompressStream::ErrorHandler()
{
// place holder for error handing
ON_ERROR("ON_CompressStream error");
}
bool ON_CompressStream::Begin()
{
if ( 0 != m_implementation )
{
onfree(m_implementation);
m_implementation = 0;
}
// zero these because the same instance of an
// ON_CompressStream class may be used multiple times.
m_in_size = 0;
m_out_size = 0;
m_in_crc = 0;
m_out_crc = 0;
struct ON_ZlibImplementation* imp = (struct ON_ZlibImplementation*)onmalloc(sizeof(*imp));
memset(&imp->m_strm,0,sizeof(imp->m_strm));
if ( Z_OK != deflateInit( &imp->m_strm, Z_BEST_COMPRESSION ) )
{
onfree(imp);
return false;
}
m_implementation = imp;
return true;
}
bool ON_CompressStream::In( ON__UINT64 size, const void* uncompressed_buffer )
{
if ( size <= 0 )
return true;
if ( 0 == m_implementation )
{
ErrorHandler();
return false;
}
if ( 0 == uncompressed_buffer )
{
ErrorHandler();
return false;
}
struct ON_ZlibImplementation* imp = (struct ON_ZlibImplementation*)m_implementation;
z_stream& strm = imp->m_strm;
if ( 0 != strm.avail_in || 0 != strm.next_in )
{
// strm.avail_in is always zero when we leave an ON_CompressStream function.
ErrorHandler();
return false;
}
const ON__UINT32 sizeof_out_buffer = (ON__UINT32)(sizeof(imp->m_zlib_out_buffer));
void* out_buffer = imp->m_zlib_out_buffer;
int zrc = Z_OK;
const ON__UINT64 max_sz = 0x7FFFFFF0;
bool rc = false;
ON__UINT32 deflate_output_count;
// counter prevents infinte loops if there is a bug in zlib return codes.
for( int counter = 512; counter > 0; counter-- )
{
// Call zlib's deflate function. It can either process
// more input from m_zlib.strm.next_in[], create more
// compressed output in m_zlib.strm.next_out[], or do both.
// provide storage for compressed stream output
strm.next_out = (Bytef*)out_buffer;
strm.avail_out = sizeof_out_buffer;
if ( strm.avail_in <= 0 )
{
if ( size <= 0 )
{
// finshed with uncompressed input
break;
}
// submit a portion of uncompressed_buffer to zlib
ON__UINT64 sz = (size > max_sz) ? max_sz : size;
m_in_size += sz;
m_in_crc = ON_CRC32(m_in_crc,(size_t)sz,uncompressed_buffer); // (size_t) cast is safe because sz <= max_sz = 0x7FFFFFF0
strm.next_in = (Bytef*)uncompressed_buffer;
strm.avail_in = (ON__UINT32)sz;
uncompressed_buffer = ((const unsigned char*)uncompressed_buffer) + sz;
size -= sz;
counter = 512; // added input - reset the counter that detects stalls
}
// calculate compression
ON__UINT32 avail_in0 = strm.avail_in;
ON__UINT32 avail_out0 = strm.avail_out;
zrc = deflate( &strm, Z_NO_FLUSH );
if ( zrc < 0 )
{
// Something went haywire - bail out.
ErrorHandler();
rc = false;
break;
}
if ( strm.avail_in < avail_in0 || strm.avail_out > avail_out0 )
{
// zlib did something
rc = true;
}
deflate_output_count = sizeof_out_buffer - strm.avail_out;
if ( deflate_output_count > 0 )
{
// The last call to deflate created compressed output.
// Send the output to compressed stream handler.
// Calculate the updated crc and size before we call
// the output handler because someday sombody will
// decide it's a good idea to modify the values
// in the buffer argument.
ON__UINT32 out_crc1 = ON_CRC32( m_out_crc, deflate_output_count, out_buffer);
ON__UINT64 out_size1 = m_out_size + deflate_output_count;
rc = (0 != m_out_callback_function)
? m_out_callback_function( m_out_callback_context, deflate_output_count, out_buffer )
: Out( m_out_callback_context, deflate_output_count, out_buffer );
if ( !rc )
break;
// Update compressed stream crc and size
m_out_crc = out_crc1;
m_out_size = out_size1;
counter = 512; // created output - reset counter that detects stalls
}
if ( size <= 0 && strm.avail_in <= 0 )
{
// no input left
break;
}
}
strm.avail_in = 0;
strm.next_in = 0;
strm.next_out = 0;
strm.avail_out = 0;
return rc;
}
bool ON_CompressStream::End()
{
if ( 0 == m_implementation )
{
ErrorHandler();
return false;
}
struct ON_ZlibImplementation* imp = (struct ON_ZlibImplementation*)m_implementation;
z_stream& strm = imp->m_strm;
if ( 0 != strm.avail_in || 0 != strm.next_in )
{
// strm.avail_in is always zero when we leave an ON_CompressStream function.
ErrorHandler();
return false;
}
const ON__UINT32 sizeof_out_buffer = (ON__UINT32)(sizeof(imp->m_zlib_out_buffer));
void* out_buffer = imp->m_zlib_out_buffer;
int zrc = Z_OK;
bool rc = false;
ON__UINT32 deflate_output_count;
// counter prevents infinte loops if there is a bug in zlib return codes.
for( int counter = 512; counter > 0; counter-- )
{
// provide storage for compressed stream output
strm.avail_in = 0;
strm.next_in = 0;
strm.next_out = (Bytef*)out_buffer;
strm.avail_out = sizeof_out_buffer;
// finish compression calculation
zrc = deflate( &strm, Z_FINISH );
if ( zrc < 0 )
{
// Something went haywire - bail out.
ErrorHandler();
rc = false;
break;
}
deflate_output_count = sizeof_out_buffer - strm.avail_out;
if ( deflate_output_count > 0 )
{
// The last call to deflate created compressed output.
// Send the output to compressed stream handler.
// Calculate the updated crc and size before we call
// the output handler because someday sombody will
// decide it's a good idea to modify the values
// in the buffer argument.
ON__UINT32 compressed_crc1 = ON_CRC32( m_out_crc, deflate_output_count, out_buffer);
ON__UINT64 compressed_size1 = m_out_size + ((ON__UINT64)deflate_output_count);
rc = (0 != m_out_callback_function)
? m_out_callback_function( m_out_callback_context, deflate_output_count, out_buffer )
: Out( m_out_callback_context, deflate_output_count, out_buffer );
if ( !rc )
break;
// Update compressed stream crc and size
m_out_crc = compressed_crc1;
m_out_size = compressed_size1;
counter = 512; // created output - reset counter that detects stalls
}
if ( Z_STREAM_END == zrc )
{
// no input left, all pending compressing is finished,
// and all compressed output has been returned.
rc = true;
break;
}
}
strm.avail_in = 0;
strm.next_in = 0;
strm.next_out = 0;
strm.avail_out = 0;
deflateEnd(&strm);
onfree(m_implementation);
m_implementation = 0;
return rc;
}
bool ON_CompressStream::Out( void*, ON__UINT32, const void* )
{
// default compressed stream handler does nothing.
return true;
}
bool ON_CompressStream::SetCallback(
ON_StreamCallbackFunction out_callback_function,
void* out_callback_context
)
{
m_out_callback_function = out_callback_function;
m_out_callback_context = out_callback_context;
return true;
}
ON_StreamCallbackFunction ON_CompressStream::CallbackFunction() const
{
return m_out_callback_function;
}
void* ON_CompressStream::CallbackContext() const
{
return m_out_callback_context;
}
ON__UINT64 ON_CompressStream::InSize() const
{
return m_in_size;
}
ON__UINT64 ON_CompressStream::OutSize() const
{
return m_out_size;
}
ON__UINT32 ON_CompressStream::InCRC() const
{
return m_in_crc;
}
ON__UINT32 ON_CompressStream::OutCRC() const
{
return m_out_crc;
}
///////////////////////////////////////////////////////////////////////////////////////////
ON_UncompressStream::ON_UncompressStream()
: m_out_callback_function(0)
, m_out_callback_context(0)
, m_in_size(0)
, m_out_size(0)
, m_in_crc(0)
, m_out_crc(0)
, m_implementation(0)
, m_reserved(0)
{}
ON_UncompressStream::~ON_UncompressStream()
{
if ( 0 != m_implementation )
{
onfree(m_implementation);
m_implementation = 0;
}
}
void ON_UncompressStream::ErrorHandler()
{
// place holder for error handing
ON_ERROR("ON_UncompressStream error");
}
bool ON_UncompressStream::Begin()
{
if ( 0 != m_implementation )
{
onfree(m_implementation);
m_implementation = 0;
}
// zero these because the same instance of an
// ON_UncompressStream class may be used multiple times.
m_in_size = 0;
m_out_size = 0;
m_in_crc = 0;
m_out_crc = 0;
struct ON_ZlibImplementation* imp = (struct ON_ZlibImplementation*)onmalloc(sizeof(*imp));
memset(&imp->m_strm,0,sizeof(imp->m_strm));
if ( Z_OK != inflateInit( &imp->m_strm ) )
{
onfree(imp);
return false;
}
m_implementation = imp;
return true;
}
bool ON_UncompressStream::In( ON__UINT64 size, const void* compressed_buffer )
{
if ( size <= 0 )
return true;
if ( 0 == m_implementation )
{
ErrorHandler();
return false;
}
if ( 0 == compressed_buffer )
{
ErrorHandler();
return false;
}
struct ON_ZlibImplementation* imp = (struct ON_ZlibImplementation*)m_implementation;
z_stream& strm = imp->m_strm;
if ( 0 != strm.avail_in || 0 != strm.next_in )
{
// strm.avail_in is always zero when we leave an ON_UncompressStream function.
ErrorHandler();
return false;
}
const ON__UINT32 sizeof_out_buffer = (ON__UINT32)(sizeof(imp->m_zlib_out_buffer));
void* out_buffer = imp->m_zlib_out_buffer;
int zrc = Z_OK;
const ON__UINT64 max_sz = 0x7FFFFFF0;
bool rc = false;
ON__UINT32 inflate_output_count;
// counter prevents infinte loops if there is a bug in zlib return codes.
for( int counter = 512; counter > 0; counter-- )
{
// Call zlib's inflate function. It can process
// more compressed input from strm.next_in[], create more
// uncompressed output in strm.next_out[], or do both.
// provide storage for uncompressed stream output
strm.next_out = (Bytef*)out_buffer;
strm.avail_out = sizeof_out_buffer;
if ( strm.avail_in <= 0 )
{
if ( size <= 0 )
{
// finshed with compressed input
break;
}
// submit a portion of compressed_buffer to zlib
ON__UINT64 sz = (size > max_sz) ? max_sz : size;
m_in_size += sz;
m_in_crc = ON_CRC32(m_in_crc,(size_t)sz,compressed_buffer); // (size_t) cast is safe because sz <= max_sz = 0x7FFFFFF0
strm.next_in = (Bytef*)compressed_buffer;
strm.avail_in = (ON__UINT32)sz;
compressed_buffer = ((const unsigned char*)compressed_buffer) + sz;
size -= sz;
counter = 512; // added input - reset the counter that detects stalls
}
// calculate compression
ON__UINT32 avail_in0 = strm.avail_in;
ON__UINT32 avail_out0 = strm.avail_out;
zrc = inflate( &strm, Z_NO_FLUSH );
if ( zrc < 0 )
{
// Something went haywire - bail out.
ErrorHandler();
rc = false;
break;
}
if ( strm.avail_in < avail_in0 || strm.avail_out > avail_out0 )
{
// zlib did something
rc = true;
}
inflate_output_count = sizeof_out_buffer - strm.avail_out;
if ( inflate_output_count > 0 )
{
// The last call to inflate created uncompressed output.
// Send the output to the uncompressed stream handler.
// Calculate the updated crc and size before we call
// the output handler because someday sombody will
// decide it's a good idea to modify the values
// in the buffer argument.
ON__UINT32 out_crc1 = ON_CRC32( m_out_crc, inflate_output_count, out_buffer);
ON__UINT64 out_size1 = m_out_size + inflate_output_count;
rc = (0 != m_out_callback_function)
? m_out_callback_function( m_out_callback_context, inflate_output_count, out_buffer )
: Out( m_out_callback_context, inflate_output_count, out_buffer );
if ( !rc )
break;
// Update compressed stream crc and size
m_out_crc = out_crc1;
m_out_size = out_size1;
counter = 512; // created output - reset counter that detects stalls
}
if ( size <= 0 && strm.avail_in <= 0 )
{
// no input left
break;
}
}
strm.avail_in = 0;
strm.next_in = 0;
strm.next_out = 0;
strm.avail_out = 0;
return rc;
}
bool ON_UncompressStream::End()
{
if ( 0 == m_implementation )
{
ErrorHandler();
return false;
}
struct ON_ZlibImplementation* imp = (struct ON_ZlibImplementation*)m_implementation;
z_stream& strm = imp->m_strm;
if ( 0 != strm.avail_in || 0 != strm.next_in )
{
// strm.avail_in is always zero when we leave an ON_UncompressStream function.
ErrorHandler();
return false;
}
const ON__UINT32 sizeof_out_buffer = (ON__UINT32)(sizeof(imp->m_zlib_out_buffer));
void* out_buffer = imp->m_zlib_out_buffer;
int zrc = Z_OK;
bool rc = false;
ON__UINT32 inflate_output_count;
// counter prevents infinte loops if there is a bug in zlib return codes.
for( int counter = 512; counter > 0; counter-- )
{
// provide storage for compressed stream output
strm.avail_in = 0;
strm.next_in = 0;
strm.next_out = (Bytef*)out_buffer;
strm.avail_out = sizeof_out_buffer;
// finish compression calculation
zrc = inflate( &strm, Z_FINISH );
if ( zrc < 0 )
{
// Something went haywire - bail out.
ErrorHandler();
rc = false;
break;
}
inflate_output_count = sizeof_out_buffer - strm.avail_out;
if ( inflate_output_count > 0 )
{
// The last call to inflate created uncompressed output.
// Send the output to the uncompressed stream handler.
// Calculate the updated crc and size before we call
// the output handler because someday sombody will
// decide it's a good idea to modify the values
// in the buffer argument.
ON__UINT32 out_crc1 = ON_CRC32( m_out_crc, inflate_output_count, out_buffer);
ON__UINT64 out_size1 = m_out_size + inflate_output_count;
rc = (0 != m_out_callback_function)
? m_out_callback_function( m_out_callback_context, inflate_output_count, out_buffer )
: Out( m_out_callback_context, inflate_output_count, out_buffer );
if ( !rc )
break;
// Update compressed stream crc and size
m_out_crc = out_crc1;
m_out_size = out_size1;
counter = 512; // created output - reset counter that detects stalls
}
if ( Z_STREAM_END == zrc )
{
// no input left, all pending compressing is finished,
// and all compressed output has been returned.
rc = true;
break;
}
}
strm.avail_in = 0;
strm.next_in = 0;
strm.next_out = 0;
strm.avail_out = 0;
inflateEnd(&strm);
onfree(m_implementation);
m_implementation = 0;
return rc;
}
bool ON_UncompressStream::Out( void*, ON__UINT32, const void* )
{
// default uncompressed stream handler does nothing.
return true;
}
bool ON_UncompressStream::SetCallback(
ON_StreamCallbackFunction out_callback_function,
void* out_callback_context
)
{
m_out_callback_function = out_callback_function;
m_out_callback_context = out_callback_context;
return true;
}
ON_StreamCallbackFunction ON_UncompressStream::CallbackFunction() const
{
return m_out_callback_function;
}
void* ON_UncompressStream::CallbackContext() const
{
return m_out_callback_context;
}
ON__UINT64 ON_UncompressStream::InSize() const
{
return m_in_size;
}
ON__UINT64 ON_UncompressStream::OutSize() const
{
return m_out_size;
}
ON__UINT32 ON_UncompressStream::InCRC() const
{
return m_in_crc;
}
ON__UINT32 ON_UncompressStream::OutCRC() const
{
return m_out_crc;
}

375
extern/opennurbs/opennurbs_compress.h vendored Executable file
View File

@@ -0,0 +1,375 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_COMPRESS_INC_)
#define OPENNURBS_COMPRESS_INC_
typedef bool (*ON_StreamCallbackFunction)( void* context, ON__UINT32 size, const void* buffer );
class ON_CLASS ON_CompressStream
{
public:
ON_CompressStream();
virtual ~ON_CompressStream();
/*
Description:
ON_CompressStream delivers the compressed stream by calling
a compressed stream output handler function. There are two
options for specifying the compressed stream output handler
function.
1. Overriding the virtual Out() function.
2. Providing a callback function.
SetCallback() is used to specify a callback function to handle
the compressed stream and to specify a context pointer to be
passed to either option of the handler.
Parameters:
callback_function - [in]
Function to call with sections of the compressed stream.
If callback_function is null, then the virtual Out()
function will be called. When callback_function
is specified, it must return true if the compression
calculation should continue and false to cancel the
compression calculation.
callback_context - [in]
This value is passed as the first argument when calling
callback_function or the virutal Out() function.
Returns:
True if successful.
Remarks:
Once compression has started, it would be unusual to
intentionally change the compressed stream output handler,
but you can do this if you need to.
*/
bool SetCallback(
ON_StreamCallbackFunction callback_function,
void* callback_context
);
/*
Returns:
Current value of the callback function for handling
the compressed stream. If the callback function is
null, the the virtual Out() function is used to
handle
*/
ON_StreamCallbackFunction CallbackFunction() const;
/*
Returns:
Current value of the context pointer passed as the first
argument to the compressed stream output handler function.
*/
void* CallbackContext() const;
/*
Description:
Call Begin() one time to initialize the compression
calculation. Then call In() one or more times
to submit the uncompressed stream to the compression calculation.
When you reach the end of the uncompressed stream, call
End().
Returns:
true if successful, false if an error occured.
*/
bool Begin();
/*
Description:
Call In() one or more times to compress a stream of uncompressed
bytes. After the last call to In(), call End(). Calling In()
may generate zero or more calls to the output stream handler.
Parameters:
in_buffer_size - [in]
number of bytes in in_buffer
in_buffer - [in]
Returns:
true if successful, false if an error occured.
*/
bool In(
ON__UINT64 in_buffer_size,
const void* in_buffer
);
/*
Description:
If an explicit compressed stream output handler is not specified
( CallbackFunction() returns null ), then the virtual Out()
function is called to handle the compressed output stream.
As the input stream is compressed, one or more calls to Out()
will occur.
Returns:
True to continue compressing and false to cancel the compression
calculation.
Remarks:
In general, it is probably going to be easier to test and debug
your code if you ignore the callback_context parameter and add
a member variable to your derived class to make additional
information accessable to your Out function.
*/
virtual bool Out(
void* callback_context,
ON__UINT32 out_buffer_size,
const void* out_buffer
);
/*
Description:
After the last call to In(), call End().
Calling End() may generate zero or more
calls to the output stream handler.
Returns:
true if successful, false if an error occured.
*/
bool End();
/*
Returns:
Then the returned value is the total number bytes in the input
stream. The size is updated every time In() is called before
any calls are made to the output stream handler. If the
calculation is finished ( End() has been called ), then the
returned value is the total number of bytes in the entire
input stream.
*/
ON__UINT64 InSize() const;
/*
Returns:
Then the returned value is the total number bytes in the output
stream. The size is incremented immediately after each call to
the output stream handler. If the compression calculation is
finished ( End() has been called ), then the returned value is
the total number of bytes in the entire output stream.
*/
ON__UINT64 OutSize() const;
/*
Returns:
Then the returned value is the 32-bit crc of the input stream.
The crc is updated every time In() is called before any calls
are made to the output stream handler. If the compression
calculation is finished ( End() has been called ), then the
returned value is the 32-bit crc of the entire input stream.
*/
ON__UINT32 InCRC() const;
/*
Returns:
Then the returned value is the 32bit crc of the output stream.
The crc is updated immediately after each call to the output
stream handler. If the calculation is finished ( End() has
been called ), then the returned value is the 32-bit crc of
the entire output stream.
*/
ON__UINT32 OutCRC() const;
private:
ON_StreamCallbackFunction m_out_callback_function;
void* m_out_callback_context;
ON__UINT64 m_in_size;
ON__UINT64 m_out_size;
ON__UINT32 m_in_crc;
ON__UINT32 m_out_crc;
void* m_implementation;
void* m_reserved;
void ErrorHandler();
private:
// prohibit use - no implementation
ON_CompressStream(const ON_CompressStream&);
ON_CompressStream& operator=(const ON_CompressStream&);
};
class ON_CLASS ON_UncompressStream
{
public:
ON_UncompressStream();
virtual ~ON_UncompressStream();
/*
Description:
ON_UncompressStream delivers the uncompressed stream by calling
an uncompressed stream output handler function. There are two
options for specifying the uncompressed stream output handler
function.
1. Overriding the virtual Out() function.
2. Providing a callback function.
SetCallback() is used to specify a callback function to handle
the uncompressed stream and to specify a context pointer to be
passed to either option of the handler.
Parameters:
callback_function - [in]
Function to call with sections of the uncompressed stream.
If callback_function is null, then the virtual Out()
function will be called. When callback_function
is specified, it must return true if the uncompression
calculation should continue and false to cancel the
uncompression calculation.
callback_context - [in]
This value is passed as the first argument when calling
callback_function or the virutal Out() function.
Returns:
True if successful.
Remarks:
Once uncompression has started, it would be unusual to
intentionally change the uncompressed stream output handler,
but you can do this if you need to.
*/
bool SetCallback(
ON_StreamCallbackFunction callback_function,
void* callback_context
);
/*
Returns:
Current value of the callback function for handling
the uncompressed stream. If the callback function is
null, the the virtual UncompressedStreamOut() function
is used.
*/
ON_StreamCallbackFunction CallbackFunction() const;
/*
Returns:
Current value of the context pointer passed as the first
argument to the uncompressed stream output handler function.
*/
void* CallbackContext() const;
/*
Description:
Call BeginUnompressStream() one time to initialize the compression
calculation. Then call In() one or more times
to submit the compressed stream to the uncompression calculation.
When you reach the end of the compressed stream, call
End().
Returns:
true if successful, false if an error occured.
*/
bool Begin();
/*
Description:
Call In() one or more times to uncompress a stream of compressed
bytes. After the last call to In(), call End(). Calling End()
may generate zero or more calls to the output stream handler.
Parameters:
in_buffer_size - [in]
number of bytes in in_buffer
in_buffer - [in]
Returns:
true if successful, false if an error occured.
*/
bool In(
ON__UINT64 in_buffer_size,
const void* in_buffer
);
/*
Description:
If an explicit uncompressed stream handler is not specified
( CallbackFunction() returns null ), then the virtual Out()
function is called to handle the uncompressed output stream.
As the input stream is uncompressed, one or more calls to Out()
will occur.
Returns:
True to continue uncompressing and false to cancel the
uncompression calculation.
Remarks:
In general, it is probably going to be easier to test and debug
your code if you ignore the callback_context parameter and add
a member variable to your derived class to make additional
information accessable to your Out function.
*/
virtual bool Out(
void* callback_context,
ON__UINT32 out_buffer_size,
const void* out_buffer
);
/*
Description:
After the last call to In(), call End().
Calling End() may generate zero or more
calls to the output stream handler.
Returns:
true if successful, false if an error occured.
*/
bool End();
/*
Returns:
Then the returned value is the total number bytes in the input
stream. The size is updated every time In() is called before
any calls are made to the output stream handler. If the
calculation is finished ( End() has been called ), then the
returned value is the total number of bytes in the entire
input stream.
*/
ON__UINT64 InSize() const;
/*
Returns:
Then the returned value is the total number bytes in the output
stream. The size is incremented immediately after each call to
the output stream handler. If the compression calculation is
finished ( End() has been called ), then the returned value is
the total number of bytes in the entire output stream.
*/
ON__UINT64 OutSize() const;
/*
Returns:
Then the returned value is the 32-bit crc of the input stream.
The crc is updated every time In() is called before any calls
are made to the output stream handler. If the compression
calculation is finished ( End() has been called ), then the
returned value is the 32-bit crc of the entire input stream.
*/
ON__UINT32 InCRC() const;
/*
Returns:
Then the returned value is the 32bit crc of the output stream.
The crc is updated immediately after each call to the output
stream handler. If the calculation is finished ( End() has
been called ), then the returned value is the 32-bit crc of
the entire output stream.
*/
ON__UINT32 OutCRC() const;
private:
ON_StreamCallbackFunction m_out_callback_function;
void* m_out_callback_context;
ON__UINT64 m_in_size;
ON__UINT64 m_out_size;
ON__UINT32 m_in_crc;
ON__UINT32 m_out_crc;
void* m_implementation;
void* m_reserved;
void ErrorHandler();
private:
// prohibit use - no implementation
ON_UncompressStream(const ON_UncompressStream&);
ON_UncompressStream& operator=(const ON_UncompressStream&);
};
#endif

413
extern/opennurbs/opennurbs_cone.cpp vendored Executable file
View File

@@ -0,0 +1,413 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
ON_Cone::ON_Cone()
{
height = 0.0;
}
ON_Cone::ON_Cone(
const ON_Plane& p,
double h,
double r
)
{
Create(p,h,r);
}
ON_Cone::~ON_Cone()
{}
ON_BOOL32 ON_Cone::Create(
const ON_Plane& p,
double h,
double r
)
{
plane = p;
height = h;
radius = r;
return IsValid();
}
ON_BOOL32 ON_Cone::IsValid() const
{
return (plane.IsValid() && height != 0.0 && radius != 0.0);
}
const ON_3dVector& ON_Cone::Axis() const
{
return plane.zaxis;
}
const ON_3dPoint& ON_Cone::ApexPoint() const
{
return plane.origin;
}
ON_3dPoint ON_Cone::BasePoint() const
{
return plane.origin + height*plane.zaxis;
}
double ON_Cone::AngleInRadians() const
{
return height == 0.0 ? (radius!=0.0?ON_PI:0.0) : atan(radius/height);
}
double ON_Cone::AngleInDegrees() const
{
return 180.0*AngleInRadians()/ON_PI;
}
ON_Circle ON_Cone::CircleAt(
double height_parameter
) const
{
ON_Circle c(plane,radius);
c.Translate(height_parameter*plane.zaxis);
if ( height != 0.0 )
c.radius *= height_parameter/height;
else if (height_parameter==0.0)
c.radius = 0.0;
return c;
}
ON_Line ON_Cone::LineAt(
double radial_parameter
) const
{
return ON_Line(PointAt(radial_parameter,height),ApexPoint());
}
ON_3dPoint ON_Cone::PointAt( double radial_parameter, double height_parameter ) const
{
double r;
if ( height != 0.0 )
r = (radius/height)*height_parameter;
else
r = (height_parameter == 0.0)?0.0:radius;
return plane.PointAt(r*cos(radial_parameter),r*sin(radial_parameter)) + height_parameter*plane.zaxis;
}
ON_3dVector ON_Cone::NormalAt( double radial_parameter, double height_parameter ) const
{
double s = sin(radial_parameter);
double c = cos(radial_parameter);
if ( radius<0.) {
c = -c;
s = -s;
}
ON_3dVector ds = c*plane.yaxis - s*plane.xaxis;
ON_3dVector N = ON_CrossProduct( ((radius<0.0)?-ds:ds),
plane.PointAt(radius*c,radius*s,height) - plane.origin
);
N.Unitize();
return N;
}
ON_BOOL32 ON_Cone::Transform( const ON_Xform& xform )
{
ON_Circle xc(plane,radius);
ON_BOOL32 rc = xc.Transform(xform);
if (rc)
{
ON_3dPoint xH = xform*(plane.origin + height*plane.zaxis);
double xh = (xH-xc.plane.origin)*xc.plane.zaxis;
plane = xc.plane;
radius = xc.radius;
height = xh;
}
return rc;
}
bool ON_Cone::ClosestPointTo(
ON_3dPoint point,
double* radial_parameter,
double* height_parameter
) const
{
// untested code
bool rc = false;
ON_3dVector v = (point-plane.origin);
double x = v*plane.xaxis;
double y = v*plane.yaxis;
double z = v*plane.zaxis;
if ( radial_parameter )
{
double a = ( 0.0 == y && 0.0 == x ) ? 0.0 : atan2(y,x);
if (a > 2.0*ON_PI )
{
a -= 2.0*ON_PI;
}
if (a < 0.0 )
{
a += 2.0*ON_PI;
}
*radial_parameter = a;
}
if (height_parameter)
{
point.x -= plane.origin.x;
point.y -= plane.origin.y;
point.z -= plane.origin.z;
v.x = x;
v.y = y;
v.z = 0.0;
v.Unitize();
v.x *= radius;
v.y *= radius;
ON_Line line(ON_origin, v.x*plane.xaxis + v.y*plane.yaxis + height*plane.zaxis );
rc = line.ClosestPointTo(point,&z);
if (rc)
{
*height_parameter = z*height;
}
}
return rc;
}
// returns point on cylinder that is closest to given point
ON_3dPoint ON_Cone::ClosestPointTo(
ON_3dPoint point
) const
{
// untested code
ON_3dVector v = (point-plane.origin);
double x = v*plane.xaxis;
double y = v*plane.yaxis;
//double z = v*plane.zaxis;
point.x -= plane.origin.x;
point.y -= plane.origin.y;
point.z -= plane.origin.z;
v.x = x;
v.y = y;
v.z = 0.0;
v.Unitize();
v.x *= radius;
v.y *= radius;
ON_Line line(ON_origin, v.x*plane.xaxis + v.y*plane.yaxis + height*plane.zaxis );
return line.ClosestPointTo(point);
}
ON_BOOL32 ON_Cone::Rotate(
double sin_angle,
double cos_angle,
const ON_3dVector& axis_of_rotation
)
{
return Rotate( sin_angle, cos_angle, axis_of_rotation, plane.origin );
}
ON_BOOL32 ON_Cone::Rotate(
double angle,
const ON_3dVector& axis_of_rotation
)
{
return Rotate( sin(angle), cos(angle), axis_of_rotation, plane.origin );
}
// rotate plane about a point and axis
ON_BOOL32 ON_Cone::Rotate(
double sin_angle,
double cos_angle,
const ON_3dVector& axis_of_rotation,
const ON_3dPoint& center_of_rotation
)
{
return plane.Rotate( sin_angle, cos_angle, axis_of_rotation, center_of_rotation );
}
ON_BOOL32 ON_Cone::Rotate(
double angle, // angle in radians
const ON_3dVector& axis, // axis of rotation
const ON_3dPoint& point // center of rotation
)
{
return Rotate( sin(angle), cos(angle), axis, point );
}
ON_BOOL32 ON_Cone::Translate(
const ON_3dVector& delta
)
{
return plane.Translate( delta );
}
int ON_Cone::GetNurbForm( ON_NurbsSurface& s ) const
{
int rc = 0;
if ( IsValid() ) {
ON_Circle c = CircleAt(height);
ON_NurbsCurve n;
c.GetNurbForm(n);
ON_3dPoint apex = ApexPoint();
ON_4dPoint cv;
int i, j0, j1;
s.Create(3,true,3,2,9,2);
for ( i = 0; i < 10; i++ )
s.m_knot[0][i] = n.m_knot[i];
if ( height >= 0.0 ) {
s.m_knot[1][0] = 0.0;
s.m_knot[1][1] = height;
j0 = 0;
j1 = 1;
}
else {
s.m_knot[1][0] = height;
s.m_knot[1][1] = 0.0;
j0 = 1;
j1 = 0;
}
for ( i = 0; i < 9; i++ ) {
cv = n.CV(i);
s.SetCV(i, j1, ON::homogeneous_rational, &cv.x );
cv.x = apex.x*cv.w;
cv.y = apex.y*cv.w;
cv.z = apex.z*cv.w;
s.SetCV(i, j0, cv);
}
rc = 2;
}
return rc;
}
ON_RevSurface* ON_Cone::RevSurfaceForm( ON_RevSurface* srf ) const
{
if ( srf )
srf->Destroy();
ON_RevSurface* pRevSurface = NULL;
if ( IsValid() )
{
ON_Line line;
ON_Interval line_domain;
if ( height >= 0.0 )
line_domain.Set(0.0,height);
else
line_domain.Set(height,0.0);
line.from = PointAt(0.0,line_domain[0]);
line.to = PointAt(0.0,line_domain[1]);
ON_LineCurve* line_curve = new ON_LineCurve( line, line_domain[0], line_domain[1] );
if ( srf )
pRevSurface = srf;
else
pRevSurface = new ON_RevSurface();
pRevSurface->m_angle.Set(0.0,2.0*ON_PI);
pRevSurface->m_t = pRevSurface->m_angle;
pRevSurface->m_curve = line_curve;
pRevSurface->m_axis.from = plane.origin;
pRevSurface->m_axis.to = plane.origin + plane.zaxis;
pRevSurface->m_bTransposed = false;
pRevSurface->m_bbox.m_min = plane.origin;
pRevSurface->m_bbox.m_max = plane.origin;
pRevSurface->m_bbox.Union(CircleAt(height).BoundingBox());
}
return pRevSurface;
}
/*
// obsolete use ON_BrepCone
ON_Brep* ON_Cone::BrepForm( ON_Brep* brep ) const
{
ON_Brep* pBrep = 0;
if ( brep )
brep->Destroy();
ON_RevSurface* pRevSurface = RevSurfaceForm();
if ( pRevSurface )
{
if ( brep )
pBrep = brep;
else
pBrep = new ON_Brep();
if ( !pBrep->Create(pRevSurface) )
{
if ( !brep )
delete pBrep;
pBrep = 0;
if ( !pRevSurface )
{
delete pRevSurface;
pRevSurface = 0;
}
}
else
{
// add cap
ON_Circle circle = CircleAt(height);
ON_NurbsSurface* pCapSurface = ON_NurbsSurfaceQuadrilateral(
circle.plane.PointAt(-radius,-radius),
circle.plane.PointAt(+radius,-radius),
circle.plane.PointAt(+radius,+radius),
circle.plane.PointAt(-radius,+radius)
);
pCapSurface->m_knot[0][0] = -fabs(radius);
pCapSurface->m_knot[0][1] = fabs(radius);
pCapSurface->m_knot[1][0] = pCapSurface->m_knot[0][0];
pCapSurface->m_knot[1][1] = pCapSurface->m_knot[0][1];
circle.Create( ON_xy_plane, ON_origin, radius );
ON_NurbsCurve* c2 = new ON_NurbsCurve();
circle.GetNurbForm(*c2);
c2->ChangeDimension(2);
pBrep->m_S.Append(pCapSurface);
pBrep->m_C2.Append(c2);
ON_BrepFace& cap = pBrep->NewFace( pBrep->m_S.Count()-1 );
ON_BrepLoop& loop = pBrep->NewLoop( ON_BrepLoop::outer, cap );
ON_BrepEdge& edge = pBrep->m_E[1];
ON_BrepTrim& trim = pBrep->NewTrim( edge, true, loop, pBrep->m_C2.Count()-1 );
trim.m_tolerance[0] = 0.0;
trim.m_tolerance[1] = 0.0;
trim.m_pbox.m_min.x = -radius;
trim.m_pbox.m_min.y = -radius;
trim.m_pbox.m_min.z = 0.0;
trim.m_pbox.m_max.x = radius;
trim.m_pbox.m_max.y = radius;
trim.m_pbox.m_max.z = 0.0;
loop.m_pbox = trim.m_pbox;
pBrep->SetTrimIsoFlags(trim);
for ( int eti = 0; eti < edge.m_ti.Count(); eti++ )
pBrep->m_T[ edge.m_ti[eti] ].m_type = ON_BrepTrim::mated;
if ( !pBrep->IsValid() )
{
if (brep)
brep->Destroy();
else
delete pBrep;
pBrep = 0;
}
}
}
return pBrep;
}
*/

185
extern/opennurbs/opennurbs_cone.h vendored Executable file
View File

@@ -0,0 +1,185 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(ON_CONE_INC_)
#define ON_CONE_INC_
class ON_NurbsSurface;
class ON_Brep;
// Description:
// Lightweight right circular cone. Use ON_ConeSurface if
// you need ON_Cone geometry as a virtual ON_Surface.
class ON_CLASS ON_Cone
{
public:
// Creates a cone with world XY plane as the base plane,
// center = (0,0,0), radius = 0.0, height = 0.0.
ON_Cone();
// See ON_Cone::Create.
ON_Cone(
const ON_Plane& plane,
double height,
double radius
);
~ON_Cone();
// Description:
// Creates a right circular cone from a plane, height,
// and radius.
// plane - [in] The apex of cone is at plane.origin and
// the axis of the cone is plane.zaxis.
// height - [in] The center of the base is height*plane.zaxis.
// radius - [in] tan(cone angle) = radius/height
ON_BOOL32 Create(
const ON_Plane& plane,
double height,
double radius
);
// Returns true if plane is valid, height is not zero, and
// radius is not zero.
ON_BOOL32 IsValid() const;
// Returns:
// Center of base circle.
// Remarks:
// The base point is plane.origin + height*plane.zaxis.
ON_3dPoint BasePoint() const;
// Returns:
// Point at the tip of the cone.
// Remarks:
// The apex point is plane.origin.
const ON_3dPoint& ApexPoint() const;
// Returns:
// Unit vector axis of cone.
const ON_3dVector& Axis() const;
// Returns:
// The angle (in radians) between the axis and the
// side of the cone.
// The angle and the height have the same sign.
double AngleInRadians() const;
// Returns:
// The angle Iin degrees) between the axis and the side.
// The angle and the height have the same sign.
double AngleInDegrees() const;
// evaluate parameters and return point
// Parameters:
// radial_parameter - [in] 0.0 to 2.0*ON_PI
// height_parameter - [in] 0 = apex, height = base
ON_3dPoint PointAt(
double radial_parameter,
double height_parameter
) const;
// Parameters:
// radial_parameter - [in] (in radians) 0.0 to 2.0*ON_PI
// height_parameter - [in] 0 = apex, height = base
// Remarks:
// If radius>0 and height>0, then the normal points "out"
// when height_parameter >= 0.
ON_3dVector NormalAt(
double radial_parameter,
double height_parameter
) const;
// Description:
// Get iso curve circle at a specified height.
// Parameters:
// height_parameter - [in] 0 = apex, height = base
ON_Circle CircleAt(
double height_parameter
) const;
// Description:
// Get iso curve line segment at a specified angle.
// Parameters:
// radial_parameter - [in] (in radians) 0.0 to 2.0*ON_PI
ON_Line LineAt(
double radial_parameter
) const;
// returns parameters of point on cone that is closest to given point
bool ClosestPointTo(
ON_3dPoint point,
double* radial_parameter,
double* height_parameter
) const;
// returns point on cone that is closest to given point
ON_3dPoint ClosestPointTo(
ON_3dPoint
) const;
ON_BOOL32 Transform( const ON_Xform& );
// rotate cone about its origin
ON_BOOL32 Rotate(
double sin_angle,
double cos_angle,
const ON_3dVector& axis_of_rotation
);
ON_BOOL32 Rotate(
double angle_in_radians,
const ON_3dVector& axis_of_rotation
);
// rotate cone about a point and axis
ON_BOOL32 Rotate(
double sin_angle,
double cos_angle,
const ON_3dVector& axis_of_rotation,
const ON_3dPoint& center_of_rotation
);
ON_BOOL32 Rotate(
double angle_in_radians,
const ON_3dVector& axis_of_rotation,
const ON_3dPoint& center_of_rotation
);
ON_BOOL32 Translate(
const ON_3dVector& delta
);
ON_BOOL32 GetNurbForm( ON_NurbsSurface& ) const;
/*
Description:
Creates a surface of revolution definition of the cylinder.
Parameters:
srf - [in] if not NULL, then this srf is used.
Result:
A surface of revolution or NULL if the cylinder is not
valid or is infinite.
*/
ON_RevSurface* RevSurfaceForm( ON_RevSurface* srf = NULL ) const;
public:
ON_Plane plane; // apex = plane.origin, axis = plane.zaxis
double height; // not zero
double radius; // not zero
};
#endif

254
extern/opennurbs/opennurbs_crc.cpp vendored Executable file
View File

@@ -0,0 +1,254 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
ON__UINT16 ON_CRC16( ON__UINT16 current_remainder, size_t count, const void* p )
{
// 16 bit cyclic redundancy check using CCITT generator polynomial
// CRC calculations are typically done something like this:
//
// const short crc_seed = 0; // or 1, or your favorite starting value
//
// // Compute CRC on "good" data
// short first_crc = crc_seed;
// first_crc = ON_CRC16( first_crc, size1, buffer1 );
// ...
// first_crc = ON_CRC16( first_crc, sizeN, bufferN );
//
// Do something that may potentially change the values in
// the buffers (like storing them on a faulty disk).
//
// // Compute CRC on "suspect" data
// short second_crc = crc_seed;
// second_crc = ON_CRC16( second_crc, size1, buffer1 );
// ...
// second_crc = ON_CRC16( second_crc, sizeN, bufferN );
// if ( ON_CRC16( second_crc, 2, &first_crc ) ) {
// printf( "The value of at least one byte has changed.\n" );
// }
static ON__UINT16 ON_CRC16_CCITT_TABLE[256] =
{0x0000,0x1021,0x2042,0x3063,0x4084,0x50A5,0x60C6,0x70E7,0x8108,0x9129,0xA14A,0xB16B,0xC18C,0xD1AD,0xE1CE,0xF1EF,
0x1231,0x0210,0x3273,0x2252,0x52B5,0x4294,0x72F7,0x62D6,0x9339,0x8318,0xB37B,0xA35A,0xD3BD,0xC39C,0xF3FF,0xE3DE,
0x2462,0x3443,0x0420,0x1401,0x64E6,0x74C7,0x44A4,0x5485,0xA56A,0xB54B,0x8528,0x9509,0xE5EE,0xF5CF,0xC5AC,0xD58D,
0x3653,0x2672,0x1611,0x0630,0x76D7,0x66F6,0x5695,0x46B4,0xB75B,0xA77A,0x9719,0x8738,0xF7DF,0xE7FE,0xD79D,0xC7BC,
0x48C4,0x58E5,0x6886,0x78A7,0x0840,0x1861,0x2802,0x3823,0xC9CC,0xD9ED,0xE98E,0xF9AF,0x8948,0x9969,0xA90A,0xB92B,
0x5AF5,0x4AD4,0x7AB7,0x6A96,0x1A71,0x0A50,0x3A33,0x2A12,0xDBFD,0xCBDC,0xFBBF,0xEB9E,0x9B79,0x8B58,0xBB3B,0xAB1A,
0x6CA6,0x7C87,0x4CE4,0x5CC5,0x2C22,0x3C03,0x0C60,0x1C41,0xEDAE,0xFD8F,0xCDEC,0xDDCD,0xAD2A,0xBD0B,0x8D68,0x9D49,
0x7E97,0x6EB6,0x5ED5,0x4EF4,0x3E13,0x2E32,0x1E51,0x0E70,0xFF9F,0xEFBE,0xDFDD,0xCFFC,0xBF1B,0xAF3A,0x9F59,0x8F78,
0x9188,0x81A9,0xB1CA,0xA1EB,0xD10C,0xC12D,0xF14E,0xE16F,0x1080,0x00A1,0x30C2,0x20E3,0x5004,0x4025,0x7046,0x6067,
0x83B9,0x9398,0xA3FB,0xB3DA,0xC33D,0xD31C,0xE37F,0xF35E,0x02B1,0x1290,0x22F3,0x32D2,0x4235,0x5214,0x6277,0x7256,
0xB5EA,0xA5CB,0x95A8,0x8589,0xF56E,0xE54F,0xD52C,0xC50D,0x34E2,0x24C3,0x14A0,0x0481,0x7466,0x6447,0x5424,0x4405,
0xA7DB,0xB7FA,0x8799,0x97B8,0xE75F,0xF77E,0xC71D,0xD73C,0x26D3,0x36F2,0x0691,0x16B0,0x6657,0x7676,0x4615,0x5634,
0xD94C,0xC96D,0xF90E,0xE92F,0x99C8,0x89E9,0xB98A,0xA9AB,0x5844,0x4865,0x7806,0x6827,0x18C0,0x08E1,0x3882,0x28A3,
0xCB7D,0xDB5C,0xEB3F,0xFB1E,0x8BF9,0x9BD8,0xABBB,0xBB9A,0x4A75,0x5A54,0x6A37,0x7A16,0x0AF1,0x1AD0,0x2AB3,0x3A92,
0xFD2E,0xED0F,0xDD6C,0xCD4D,0xBDAA,0xAD8B,0x9DE8,0x8DC9,0x7C26,0x6C07,0x5C64,0x4C45,0x3CA2,0x2C83,0x1CE0,0x0CC1,
0xEF1F,0xFF3E,0xCF5D,0xDF7C,0xAF9B,0xBFBA,0x8FD9,0x9FF8,0x6E17,0x7E36,0x4E55,0x5E74,0x2E93,0x3EB2,0x0ED1,0x1EF0};
const unsigned char* b = (const unsigned char*)p;
if ( count > 0 && b )
{
ON__UINT16 r1;
// update crc remainder
while (count >= 8)
{
// while() loop unrolled for speed
r1 = ON_CRC16_CCITT_TABLE[(current_remainder & ((ON__UINT16)0xff00))>>8];
current_remainder = (current_remainder << 8) ^ (*b++);
current_remainder ^= r1;
r1 = ON_CRC16_CCITT_TABLE[(current_remainder & ((ON__UINT16)0xff00))>>8];
current_remainder = (current_remainder << 8) ^ (*b++);
current_remainder ^= r1;
r1 = ON_CRC16_CCITT_TABLE[(current_remainder & ((ON__UINT16)0xff00))>>8];
current_remainder = (current_remainder << 8) ^ (*b++);
current_remainder ^= r1;
r1 = ON_CRC16_CCITT_TABLE[(current_remainder & ((ON__UINT16)0xff00))>>8];
current_remainder = (current_remainder << 8) ^ (*b++);
current_remainder ^= r1;
r1 = ON_CRC16_CCITT_TABLE[(current_remainder & ((ON__UINT16)0xff00))>>8];
current_remainder = (current_remainder << 8) ^ (*b++);
current_remainder ^= r1;
r1 = ON_CRC16_CCITT_TABLE[(current_remainder & ((ON__UINT16)0xff00))>>8];
current_remainder = (current_remainder << 8) ^ (*b++);
current_remainder ^= r1;
r1 = ON_CRC16_CCITT_TABLE[(current_remainder & ((ON__UINT16)0xff00))>>8];
current_remainder = (current_remainder << 8) ^ (*b++);
current_remainder ^= r1;
r1 = ON_CRC16_CCITT_TABLE[(current_remainder & ((ON__UINT16)0xff00))>>8];
current_remainder = (current_remainder << 8) ^ (*b++);
current_remainder ^= r1;
count -= 8;
}
while (count--)
{
r1 = ON_CRC16_CCITT_TABLE[(current_remainder & ((ON__UINT16)0xff00))>>8];
current_remainder = (current_remainder << 8) ^ (*b++);
current_remainder ^= r1;
}
}
return current_remainder;
}
ON__UINT32 ON_CRC32( ON__UINT32 current_remainder, size_t count, const void* p )
{
/*
//////////////////////////////////////////////////////////////////////////////////////////
//
// ON_CRC32() is a slightly altered version of zlib 1.3.3's crc32()
// and the zlib "legal stuff" is reproduced below.
//
// ON_CRC32() and crc32() compute the same values. ON_CRC32() was renamed
// so it wouldn't clash with the other crc32()'s that are out there and the
// argument order was switched to match that used by the legacy ON_CRC16().
//
//////////////////////////////////////////////////////////////////////////////////////////
zlib.h -- interface of the 'zlib' general purpose compression library
version 1.1.3, July 9th, 1998
Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jean-loup Gailly Mark Adler
jloup@gzip.org madler@alumni.caltech.edu
The data format used by the zlib library is described by RFCs (Request for
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
*/
/*
ON_CRC32_ZLIB_TABLE[] is a table for a byte-wise 32-bit CRC calculation
using the generator polynomial:
x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1.
*/
static ON__UINT32 ON_CRC32_ZLIB_TABLE[256] = {
0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419,
0x706af48f, 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4,
0xe0d5e91e, 0x97d2d988, 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07,
0x90bf1d91, 0x1db71064, 0x6ab020f2, 0xf3b97148, 0x84be41de,
0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7, 0x136c9856,
0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4,
0xa2677172, 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b,
0x35b5a8fa, 0x42b2986c, 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3,
0x45df5c75, 0xdcd60dcf, 0xabd13d59, 0x26d930ac, 0x51de003a,
0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423, 0xcfba9599,
0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190,
0x01db7106, 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f,
0x9fbfe4a5, 0xe8b8d433, 0x7807c9a2, 0x0f00f934, 0x9609a88e,
0xe10e9818, 0x7f6a0dbb, 0x086d3d2d, 0x91646c97, 0xe6635c01,
0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e, 0x6c0695ed,
0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3,
0xfbd44c65, 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2,
0x4adfa541, 0x3dd895d7, 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a,
0x346ed9fc, 0xad678846, 0xda60b8d0, 0x44042d73, 0x33031de5,
0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa, 0xbe0b1010,
0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17,
0x2eb40d81, 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6,
0x03b6e20c, 0x74b1d29a, 0xead54739, 0x9dd277af, 0x04db2615,
0x73dc1683, 0xe3630b12, 0x94643b84, 0x0d6d6a3e, 0x7a6a5aa8,
0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1, 0xf00f9344,
0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a,
0x67dd4acc, 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5,
0xd6d6a3e8, 0xa1d1937e, 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1,
0xa6bc5767, 0x3fb506dd, 0x48b2364b, 0xd80d2bda, 0xaf0a1b4c,
0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55, 0x316e8eef,
0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe,
0xb2bd0b28, 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31,
0x2cd99e8b, 0x5bdeae1d, 0x9b64c2b0, 0xec63f226, 0x756aa39c,
0x026d930a, 0x9c0906a9, 0xeb0e363f, 0x72076785, 0x05005713,
0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38, 0x92d28e9b,
0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1,
0x18b74777, 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c,
0x8f659eff, 0xf862ae69, 0x616bffd3, 0x166ccf45, 0xa00ae278,
0xd70dd2ee, 0x4e048354, 0x3903b3c2, 0xa7672661, 0xd06016f7,
0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc, 0x40df0b66,
0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605,
0xcdd70693, 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8,
0x5d681b02, 0x2a6f2b94, 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b,
0x2d02ef8d
};
if ( count > 0 && p )
{
const unsigned char* b = (const unsigned char*)p;
// The trailing L was needed long ago when "int" was often a 16 bit integers.
// Today it is more common for "int" to be a 32 bit integer and
// L to be a 32 or 64 bit integer. So, the L is causing more
// problems that it is fixing.
// current_remainder ^= 0xffffffffL;
current_remainder ^= 0xffffffff;
while (count >= 8)
{
// while() loop unrolled for speed
current_remainder = ON_CRC32_ZLIB_TABLE[((int)current_remainder ^ (*b++)) & 0xff] ^ (current_remainder >> 8);
current_remainder = ON_CRC32_ZLIB_TABLE[((int)current_remainder ^ (*b++)) & 0xff] ^ (current_remainder >> 8);
current_remainder = ON_CRC32_ZLIB_TABLE[((int)current_remainder ^ (*b++)) & 0xff] ^ (current_remainder >> 8);
current_remainder = ON_CRC32_ZLIB_TABLE[((int)current_remainder ^ (*b++)) & 0xff] ^ (current_remainder >> 8);
current_remainder = ON_CRC32_ZLIB_TABLE[((int)current_remainder ^ (*b++)) & 0xff] ^ (current_remainder >> 8);
current_remainder = ON_CRC32_ZLIB_TABLE[((int)current_remainder ^ (*b++)) & 0xff] ^ (current_remainder >> 8);
current_remainder = ON_CRC32_ZLIB_TABLE[((int)current_remainder ^ (*b++)) & 0xff] ^ (current_remainder >> 8);
current_remainder = ON_CRC32_ZLIB_TABLE[((int)current_remainder ^ (*b++)) & 0xff] ^ (current_remainder >> 8);
count -= 8;
}
while(count--)
{
current_remainder = ON_CRC32_ZLIB_TABLE[((int)current_remainder ^ (*b++)) & 0xff] ^ (current_remainder >> 8);
}
// The trailing L was needed long ago when "int" was often a 16 bit integers.
// Today it is more common for "int" to be a 32 bit integer and
// L to be a 32 or 64 bit integer. So, the L is causing more
// problems than it is fixing.
//current_remainder ^= 0xffffffffL;
current_remainder ^= 0xffffffff;
}
return current_remainder;
}

152
extern/opennurbs/opennurbs_crc.h vendored Executable file
View File

@@ -0,0 +1,152 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_CRC_INC_)
#define OPENNURBS_CRC_INC_
ON_BEGIN_EXTERNC
/*
Description:
Continues 16 bit CRC calulation to include the buffer.
Parameters:
current_remainder - [in]
sizeof_buffer - [in] number of bytes in buffer
buffer - [in]
Example:
16 bit CRC calculations are typically done something like this:
const ON__UINT16 crc_seed = 0; // or 1, or your favorite starting value
// Compute CRC on "good" data
unsigned ON__UINT16 first_crc = crc_seed;
first_crc = ON_CRC16( first_crc, size1, buffer1 );
...
first_crc = ON_CRC16( first_crc, sizeN, bufferN );
unsigned char two_zero_bytes[2] = (0,0);
first_crc = ON_CRC16( first_crc, 2, two_zero_bytes );
// make sure 16 bit CRC calculation is valid
ON__UINT16 check_crc_calculation = ON_CRC16( first_crc, 2, &first_crc );
if ( check_crc_calculation != 0 )
{
printf("ON_CRC16() calculated a bogus 16 bit CRC\n");
}
// Do something that may potentially change the values in
// the buffers (like storing them on a faulty disk).
// Compute CRC on "suspect" data
ON__UINT16 second_crc = crc_seed;
second_crc = ON_CRC16( second_crc, size1, buffer1 );
...
second_crc = ON_CRC16( second_crc, sizeN, bufferN );
if ( 0 != ON_CRC16( second_crc, 2, &first_crc ) )
{
printf( "The value of at least one byte has changed.\n" );
}
*/
ON_DECL
ON__UINT16 ON_CRC16(
ON__UINT16 current_remainder,
size_t sizeof_buffer,
const void* buffer
);
/*
Description:
Continues 32 bit CRC calulation to include the buffer
ON_CRC32() is a slightly altered version of zlib 1.3.3's crc32()
and the zlib "legal stuff" is reproduced below.
ON_CRC32() and zlib's crc32() compute the same values. ON_CRC32()
was renamed so it wouldn't clash with the other crc32()'s that are
out there and the argument order was switched to match that used by
the legacy ON_CRC16().
Parameters:
current_remainder - [in]
sizeof_buffer - [in] number of bytes in buffer
buffer - [in]
Example:
32 bit CRC calculations are typically done something like this:
const ON__UINT32 crc_seed = 0; // or 1, or your favorite starting value
//Compute CRC on "good" data
ON__UINT32 first_crc = crc_seed;
first_crc = ON_CRC32( first_crc, size1, buffer1 );
...
first_crc = ON_CRC32( first_crc, sizeN, bufferN );
// Do something that may potentially change the values in
// the buffers (like storing them on a faulty disk).
// Compute CRC on "suspect" data
ON__UINT32 second_crc = crc_seed;
second_crc = ON_CRC32( second_crc, size1, buffer1 );
...
second_crc = ON_CRC32( second_crc, sizeN, bufferN );
if ( second_crc != first_crc )
{
printf( "The value of at least one byte has changed.\n" );
}
*/
ON_DECL
ON__UINT32 ON_CRC32(
ON__UINT32 current_remainder,
size_t sizeof_buffer,
const void* buffer
);
/*
zlib.h -- interface of the 'zlib' general purpose compression library
version 1.1.3, July 9th, 1998
Copyright (C) 1995-1998 Jean-loup Gailly and Mark Adler
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
Jean-loup Gailly Mark Adler
jloup@gzip.org madler@alumni.caltech.edu
The data format used by the zlib library is described by RFCs (Request for
Comments) 1950 to 1952 in the files ftp://ds.internic.net/rfc/rfc1950.txt
(zlib format), rfc1951.txt (deflate format) and rfc1952.txt (gzip format).
*/
ON_END_EXTERNC
#endif

3037
extern/opennurbs/opennurbs_curve.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

1403
extern/opennurbs/opennurbs_curve.h vendored Executable file

File diff suppressed because it is too large Load Diff

439
extern/opennurbs/opennurbs_curveonsurface.cpp vendored Executable file
View File

@@ -0,0 +1,439 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
ON_OBJECT_IMPLEMENT(ON_CurveOnSurface,ON_Curve,"4ED7D4D8-E947-11d3-BFE5-0010830122F0");
ON_CurveOnSurface::ON_CurveOnSurface() : m_c2(0), m_c3(0), m_s(0)
{}
ON_CurveOnSurface::ON_CurveOnSurface( ON_Curve* c2, ON_Curve* c3, ON_Surface* s )
: m_c2(c2), m_c3(c3), m_s(s)
{}
ON_CurveOnSurface::ON_CurveOnSurface( const ON_CurveOnSurface& src ) : m_c2(0), m_c3(0), m_s(0)
{
*this = src;
}
unsigned int ON_CurveOnSurface::SizeOf() const
{
unsigned int sz = ON_Curve::SizeOf();
sz += sizeof(*this) - sizeof(ON_Curve);
if ( m_c2 )
sz += m_c2->SizeOf();
if ( m_c3 )
sz += m_c3->SizeOf();
if ( m_s )
sz += m_s->SizeOf();
return sz;
}
ON_CurveOnSurface& ON_CurveOnSurface::operator=( const ON_CurveOnSurface& src )
{
if ( this != &src ) {
ON_Curve::operator=(src);
if ( m_c2 ) {
delete m_c2;
m_c2 = 0;
}
if ( m_c3 ) {
delete m_c3;
m_c3 = 0;
}
if ( m_s ) {
delete m_s;
m_s = 0;
}
if ( ON_Curve::Cast(src.m_c2) ) {
m_c2 = ON_Curve::Cast(src.m_c2->Duplicate());
}
if ( ON_Curve::Cast(src.m_c3) ) {
m_c3 = ON_Curve::Cast(src.m_c3->Duplicate());
}
if ( ON_Surface::Cast(src.m_s) ) {
m_s = ON_Surface::Cast(src.m_s->Duplicate());
}
}
return *this;
}
ON_CurveOnSurface::~ON_CurveOnSurface()
{
if ( m_c2 ) {
delete m_c2;
m_c2 = 0;
}
if ( m_c3 ) {
delete m_c3;
m_c3 = 0;
}
if ( m_s ) {
delete m_s;
m_s = 0;
}
}
ON_BOOL32
ON_CurveOnSurface::IsValid( ON_TextLog* text_log ) const
{
if ( !m_c2 )
return false;
if ( !m_s )
return false;
if ( !m_c2->IsValid() )
return false;
if ( m_c2->Dimension() != 2 ) {
ON_ERROR("ON_CurveOnSurface::IsValid() m_c2 is not 2d.");
return false;
}
if ( !m_s->IsValid() )
return false;
if ( m_c3 ) {
if ( !m_c3->IsValid() )
return false;
if ( m_c3->Dimension() != m_s->Dimension() ) {
ON_ERROR("ON_CurveOnSurface::IsValid() m_c3 and m_s have different dimensions.");
return false;
}
}
return true;
}
void
ON_CurveOnSurface::Dump( ON_TextLog& dump ) const
{
dump.Print("ON_CurveOnSurface \n");
}
ON_BOOL32
ON_CurveOnSurface::Write(
ON_BinaryArchive& file // open binary file
) const
{
ON_BOOL32 rc = IsValid();
if (rc)
rc = file.WriteObject(*m_c2);
if (rc)
rc = file.WriteInt( m_c3?1:0 );
if ( rc && m_c3 )
rc = file.WriteObject(*m_c3);
if (rc)
rc = file.WriteObject(*m_s);
return rc;
}
ON_BOOL32
ON_CurveOnSurface::Read(
ON_BinaryArchive& file // open binary file
)
{
delete m_c2;
delete m_c3;
m_c2 = 0;
m_c3 = 0;
delete m_s;
m_s = 0;
ON_Object *o=0;
ON_BOOL32 rc = file.ReadObject(&o);
if (rc && o) {
m_c2 = ON_Curve::Cast(o);
if ( !m_c2 ) {
delete o;
} rc = false;
}
o = 0;
ON_BOOL32 bHasC3 = 0;
rc = file.ReadInt( &bHasC3 );
if ( rc && bHasC3 ) {
if (rc)
rc = file.ReadObject(&o);
if ( rc && o ) {
m_c2 = ON_Curve::Cast(o);
if ( !m_c2 ) {
delete o;
} rc = false;
}
}
o = 0;
if (rc)
rc = file.ReadObject(&o);
if (rc&&o) {
m_s = ON_Surface::Cast(o);
if ( !m_s ) {
delete o;
rc = false;
}
}
return rc;
}
int
ON_CurveOnSurface::Dimension() const
{
return ( m_s ) ? m_s->Dimension() : false;
}
ON_BOOL32
ON_CurveOnSurface::GetBBox( // returns true if successful
double* boxmin, // minimum
double* boxmax, // maximum
ON_BOOL32 bGrowBox
) const
{
return ( m_s ) ? m_s->GetBBox(boxmin,boxmax,bGrowBox) : false;
}
ON_BOOL32
ON_CurveOnSurface::Transform( const ON_Xform& xform )
{
TransformUserData(xform);
DestroyCurveTree();
return ( m_s ) ? m_s->Transform(xform) : false;
}
ON_BOOL32
ON_CurveOnSurface::SwapCoordinates( int i, int j )
{
return ( m_s ) ? m_s->SwapCoordinates(i,j) : false;
}
ON_Interval ON_CurveOnSurface::Domain() const
{
ON_Interval d;
if ( m_c2 )
d = m_c2->Domain();
return d;
}
int ON_CurveOnSurface::SpanCount() const
{
return m_c2 ? m_c2->SpanCount() : 0;
}
ON_BOOL32 ON_CurveOnSurface::GetSpanVector( // span "knots"
double* s // array of length SpanCount() + 1
) const
{
return m_c2 ? m_c2->GetSpanVector(s) : false;
}
int ON_CurveOnSurface::Degree() const
{
return m_c2 ? m_c2->Degree() : 0;
}
ON_BOOL32
ON_CurveOnSurface::GetParameterTolerance(
double t, // t = parameter in domain
double* tminus, // tminus
double* tplus // tplus
) const
{
return (m_c2) ? m_c2->GetParameterTolerance(t,tminus,tplus) : false;
}
ON_BOOL32
ON_CurveOnSurface::IsLinear( // true if curve locus is a line segment
double tolerance // tolerance to use when checking linearity
) const
{
ON_BOOL32 rc = (m_c2&&ON_PlaneSurface::Cast(m_s)) ? (ON_PlaneSurface::Cast(m_s) && m_c2->IsLinear(tolerance)) : false;
if ( rc ) {
// TODO: rc = m_s->IsPlanar(tolerance)
}
return rc;
}
ON_BOOL32
ON_CurveOnSurface::IsArc( // true if curve locus in an arc or circle
const ON_Plane* plane, // if not NULL, test is performed in this plane
ON_Arc* arc, // if not NULL and true is returned, then arc
// arc parameters are filled in
double tolerance // tolerance to use when checking linearity
) const
{
return (m_c2&&ON_PlaneSurface::Cast(m_s)) ? m_c2->IsArc(plane,arc,tolerance) : false;
}
ON_BOOL32
ON_CurveOnSurface::IsPlanar(
ON_Plane* plane, // if not NULL and true is returned, then plane parameters
// are filled in
double tolerance // tolerance to use when checking linearity
) const
{
return ( ON_PlaneSurface::Cast(m_s) ) ? true : false;
}
ON_BOOL32
ON_CurveOnSurface::IsInPlane(
const ON_Plane& plane, // plane to test
double tolerance // tolerance to use when checking linearity
) const
{
return false;
}
ON_BOOL32
ON_CurveOnSurface::IsClosed() const
{
ON_BOOL32 rc = ( m_c2 && m_s ) ? m_c2->IsClosed() : false;
if ( !rc )
rc = ON_Curve::IsClosed();
return rc;
}
ON_BOOL32
ON_CurveOnSurface::IsPeriodic() const
{
return ( m_c2 && m_s ) ? m_c2->IsPeriodic() : false;
}
ON_BOOL32
ON_CurveOnSurface::Reverse()
{
ON_BOOL32 rc = ( m_c2 ) ? m_c2->Reverse() : false;
if ( rc && m_c3 ) rc = m_c3->Reverse();
DestroyCurveTree();
return rc;
}
ON_BOOL32
ON_CurveOnSurface::Evaluate( // returns false if unable to evaluate
double t, // evaluation parameter
int der_count, // number of derivatives (>=0)
int v_stride, // v[] array stride (>=Dimension())
double* v, // v[] array of length stride*(ndir+1)
int side, // optional - determines which side to evaluate from
// 0 = default
// < 0 to evaluate from below,
// > 0 to evaluate from above
int* hint // optional - evaluation hint (int) used to speed
// repeated evaluations
) const
{
ON_3dVector c[5];
ON_3dVector s[15], d;
const int dim = Dimension();
ON_BOOL32 rc = (dim > 0 && dim <= 3 ) ? true : false;
if ( rc ) {
int chint=0, shint[2]={0,0};
if(hint) {
chint = (*hint)&0xFFF;
shint[0] = (*hint)>>16;
shint[1] = shint[0]>>8;
shint[0] &= 0xFF;
}
rc = ( m_c2&&m_s ) ? m_c2->Evaluate(t,der_count,3,c[0],side,&chint) : false;
if (rc) {
side = 0;
if ( der_count>0 ) {
if ( c[1].x >= 0.0 ) {
side = ( c[1].y >= 0.0 ) ? 1 : 4;
}
else {
side = ( c[1].y >= 0.0 ) ? 2 : 3;
}
}
rc = m_s->Evaluate( c[0].x, c[0].y, der_count, 3, s[0], side, shint );
if ( rc ) {
if ( hint ) {
*hint = (chint&0xFFFF) | ((shint[0]&0xFF)<<16) | ((shint[1]&0xFF)<<24);
}
v[0] = s[0].x;
if ( dim > 1 ) v[1] = s[0].y;
if ( dim > 2 ) v[2] = s[0].z;
v += v_stride;
if (der_count >= 1 ) {
const double du = c[1].x;
const double dv = c[1].y;
d = du*s[1] + dv*s[2];
v[0] = d.x;
if ( dim > 1 ) v[1] = d.y;
if ( dim > 2 ) v[2] = d.z;
v += v_stride;
if ( der_count >= 2 ) {
const double ddu = c[2].x;
const double ddv = c[2].y;
d = ddu*s[1] + ddv*s[2] + du*du*s[3] + 2.0*du*dv*s[4] + dv*dv*s[5];
v[0] = d.x;
if ( dim > 1 ) v[1] = d.y;
if ( dim > 2 ) v[2] = d.z;
v += v_stride;
if ( der_count >= 3 ) {
const double dddu = c[3].x;
const double dddv = c[3].y;
d = dddu*s[1] + dddv*s[2]
+ 3.0*du*ddu*s[3] + 3.0*(ddu*dv + du*ddv)*s[4] + 3.0*dv*ddv*s[5]
+ du*du*du*s[6] + 3.0*du*du*dv*s[7] + 3.0*du*dv*dv*s[8] + dv*dv*dv*s[9];
v[0] = d.x;
if ( dim > 1 ) v[1] = d.y;
if ( dim > 2 ) v[2] = d.z;
v += v_stride;
if ( der_count >= 4 ) {
int n;
for ( n = 4; n <= der_count; n++ ) {
v[0] = 0.0;
if ( dim > 1 ) v[1] = 0.0;
if ( dim > 2 ) v[2] = 0.0;
v += v_stride;
rc = false; // TODO - generic chain rule
}
}
}
}
}
}
}
}
return rc;
}
int
ON_CurveOnSurface::GetNurbForm( // returns 0: unable to create NURBS representation
// with desired accuracy.
// 1: success - returned NURBS parameterization
// matches the curve's to wthe desired accuracy
// 2: success - returned NURBS point locus matches
// the curve's to the desired accuracy but, on
// the interior of the curve's domain, the
// curve's parameterization and the NURBS
// parameterization may not match to the
// desired accuracy.
ON_NurbsCurve& nurbs,
double tolerance, // (>=0)
const ON_Interval* subdomain // OPTIONAL subdomain of 2d curve
) const
{
ON_ERROR("TODO - finish ON_CurveOnSurface::GetNurbForm().");
return false;
}

208
extern/opennurbs/opennurbs_curveonsurface.h vendored Executable file
View File

@@ -0,0 +1,208 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_CURVE_ON_SURFACE_INC_)
#define OPENNURBS_CURVE_ON_SURFACE_INC_
class ON_CurveOnSurface;
class ON_CLASS ON_CurveOnSurface : public ON_Curve
{
ON_OBJECT_DECLARE(ON_CurveOnSurface);
public:
ON_CurveOnSurface();
/*
Parameters:
p2dCurve - [in] ~ON_CurveOnSurface() will delete this curve.
Use an ON_CurveProxy if you don't want the original deleted.
p3dCurve - [in] ~ON_CurveOnSurface() will delete this curve.
Use an ON_CurveProxy if you don't want the original deleted.
pSurface - [in] ~ON_CurveOnSurface() will delete this surface.
Use an ON_SurfaceProxy if you don't want the original deleted.
*/
ON_CurveOnSurface( ON_Curve* p2dCurve, // required 2d curve
ON_Curve* p3dCurve, // optional 3d curve
ON_Surface* pSurface // required surface
);
ON_CurveOnSurface(const ON_CurveOnSurface&); // no implementation
ON_CurveOnSurface& operator=(const ON_CurveOnSurface&); // no implementation
/*
Remarks:
Deletes m_c2, m_c3, and m_s. Use ON_CurveProxy or ON_SurfaceProxy
if you need to use curves or a surface that you do not want deleted.
*/
virtual ~ON_CurveOnSurface();
// virtual ON_Object::SizeOf override
unsigned int SizeOf() const;
/////////////////////////////////////////////////////////////////
// ON_Object overrides
/*
Description:
Tests an object to see if its data members are correctly
initialized.
Parameters:
text_log - [in] if the object is not valid and text_log
is not NULL, then a brief englis description of the
reason the object is not valid is appened to the log.
The information appended to text_log is suitable for
low-level debugging purposes by programmers and is
not intended to be useful as a high level user
interface tool.
Returns:
@untitled table
true object is valid
false object is invalid, uninitialized, etc.
Remarks:
Overrides virtual ON_Object::IsValid
*/
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
void Dump( ON_TextLog& ) const; // for debugging
ON_BOOL32 Write(
ON_BinaryArchive& // open binary file
) const;
ON_BOOL32 Read(
ON_BinaryArchive& // open binary file
);
/////////////////////////////////////////////////////////////////
// ON_Geometry overrides
int Dimension() const;
ON_BOOL32 GetBBox( // returns true if successful
double*, // minimum
double*, // maximum
ON_BOOL32 = false // true means grow box
) const;
ON_BOOL32 Transform(
const ON_Xform&
);
// (optional - default uses Transform for 2d and 3d objects)
ON_BOOL32 SwapCoordinates(
int, int // indices of coords to swap
);
/////////////////////////////////////////////////////////////////
// ON_Curve overrides
ON_Interval Domain() const;
int SpanCount() const; // number of smooth spans in curve
ON_BOOL32 GetSpanVector( // span "knots"
double* // array of length SpanCount() + 1
) const; //
int Degree( // returns maximum algebraic degree of any span
// ( or a good estimate if curve spans are not algebraic )
) const;
// (optional - override if curve is piecewise smooth)
ON_BOOL32 GetParameterTolerance( // returns tminus < tplus: parameters tminus <= s <= tplus
double, // t = parameter in domain
double*, // tminus
double* // tplus
) const;
ON_BOOL32 IsLinear( // true if curve locus is a line segment between
// between specified points
double = ON_ZERO_TOLERANCE // tolerance to use when checking linearity
) const;
ON_BOOL32 IsArc( // ON_Arc.m_angle > 0 if curve locus is an arc between
// specified points
const ON_Plane* = NULL, // if not NULL, test is performed in this plane
ON_Arc* = NULL, // if not NULL and true is returned, then arc parameters
// are filled in
double = ON_ZERO_TOLERANCE // tolerance to use when checking
) const;
ON_BOOL32 IsPlanar(
ON_Plane* = NULL, // if not NULL and true is returned, then plane parameters
// are filled in
double = ON_ZERO_TOLERANCE // tolerance to use when checking
) const;
ON_BOOL32 IsInPlane(
const ON_Plane&, // plane to test
double = ON_ZERO_TOLERANCE // tolerance to use when checking
) const;
ON_BOOL32 IsClosed( // true if curve is closed (either curve has
void // clamped end knots and euclidean location of start
) const; // CV = euclidean location of end CV, or curve is
// periodic.)
ON_BOOL32 IsPeriodic( // true if curve is a single periodic segment
void
) const;
ON_BOOL32 Reverse(); // reverse parameterizatrion
// Domain changes from [a,b] to [-b,-a]
ON_BOOL32 Evaluate( // returns false if unable to evaluate
double, // evaluation parameter
int, // number of derivatives (>=0)
int, // array stride (>=Dimension())
double*, // array of length stride*(ndir+1)
int = 0, // optional - determines which side to evaluate from
// 0 = default
// < 0 to evaluate from below,
// > 0 to evaluate from above
int* = 0 // optional - evaluation hint (int) used to speed
// repeated evaluations
) const;
int GetNurbForm( // returns 0: unable to create NURBS representation
// with desired accuracy.
// 1: success - returned NURBS parameterization
// matches the curve's to wthe desired accuracy
// 2: success - returned NURBS point locus matches
// the curve's to the desired accuracy but, on
// the interior of the curve's domain, the
// curve's parameterization and the NURBS
// parameterization may not match to the
// desired accuracy.
ON_NurbsCurve&,
double = 0.0,
const ON_Interval* = NULL // OPTIONAL subdomain of 2d curve
) const;
/////////////////////////////////////////////////////////////////
// Interface
// ~ON_CurveOnSurface() deletes these classes. Use a
// ON_CurveProxy and/or ON_SurfaceProxy wrapper if you don't want
// the destructor to destroy the curves
ON_Curve* m_c2; // REQUIRED parameter space (2d) curve
ON_Curve* m_c3; // OPTIONAL 3d curve (approximation) to srf(crv2(t))
ON_Surface* m_s;
};
#endif

1219
extern/opennurbs/opennurbs_curveproxy.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

472
extern/opennurbs/opennurbs_curveproxy.h vendored Executable file
View File

@@ -0,0 +1,472 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
////////////////////////////////////////////////////////////////
//
// Definition of curve proxy object
//
////////////////////////////////////////////////////////////////
#if !defined(OPENNURBS_CURVEPROXY_INC_)
#define OPENNURBS_CURVEPROXY_INC_
/*
Description:
An ON_CurveProxy is a reference to an ON_Curve.
One may specify a subdomain of the referenced curve
and apply a affine reparameterization, possibly reversing
the orientation. The underlying curve cannot be modified through
the curve proxy.
Details:
The reference to the "real_curve" is const, so most functions
which modify an ON_Curve will fail when passed an ON_CurveProxy.
*/
class ON_CurveProxy;
class ON_CLASS ON_CurveProxy : public ON_Curve
{
ON_OBJECT_DECLARE(ON_CurveProxy);
public:
// virtual ON_Object::DestroyRuntimeCache override
void DestroyRuntimeCache( bool bDelete = true );
public:
ON_CurveProxy();
ON_CurveProxy( const ON_CurveProxy& );
ON_CurveProxy( const ON_Curve* );
ON_CurveProxy( const ON_Curve*, ON_Interval );
ON_CurveProxy& operator=(const ON_CurveProxy&);
virtual ~ON_CurveProxy();
// virtual ON_Object::SizeOf override
unsigned int SizeOf() const;
// virtual ON_Object::DataCRC override
ON__UINT32 DataCRC(ON__UINT32 current_remainder) const;
/*
Description:
Sets the curve geometry that "this" is a proxy for.
Sets proxy domain to proxy_curve->Domain().
Parameters:
real_curve - [in]
*/
void SetProxyCurve( const ON_Curve* real_curve );
/*
Description:
Sets the curve geometry that "this" is a proxy for.
Sets proxy domain to proxy_curve->Domain().
Parameters:
real_curve - [in]
real_curve_subdomain - [in] increasing sub interval of
real_curve->Domain(). This interval defines the
portion the "real" curve geometry that "this" proxy
uses.
bReversed - [in] true if the parameterization of "this" proxy
as a curve is reversed from the underlying "real" curve
geometry.
*/
void SetProxyCurve( const ON_Curve* real_curve,
ON_Interval real_curve_subdomain
);
/*
Returns:
"Real" curve geometry that "this" is a proxy for.
*/
const ON_Curve* ProxyCurve() const;
/*
Description:
Sets portion of the "real" curve that this proxy represents.
Does NOT change the domain of "this" curve.
Parameters:
proxy_curve_subdomain - [in] increasing sub interval of
ProxyCurve()->Domain(). This interval defines the
portion the curve geometry that "this" proxy uses.
Remarks:
This function is poorly named. It does NOT set the proxy
curve's domain. It does set the interval of the "real"
curve for which "this" is a proxy.
*/
bool SetProxyCurveDomain( ON_Interval proxy_curve_subdomain );
/*
Returns:
Sub interval of the "real" curve's domain that "this" uses.
This interval is not necessarily the same as "this" curve's
domain.
Remarks:
This function is poorly named. It does NOT get the proxy
curve's domain. It does get the evaluation interval
of the "real" curve for which "this" is a proxy.
*/
ON_Interval ProxyCurveDomain() const;
/*
Returns:
True if "this" as a curve is reversed from the "real" curve
geometry.
*/
bool ProxyCurveIsReversed() const;
/*
Parameters:
t - [in] parameter for "this" curve
Returns:
Corresponding parameter in m_real_curve's domain.
*/
double RealCurveParameter( double t ) const;
/*
Parameters:
real_curve_parameter - [in] m_real_curve parameter
Returns:
Corresponding parameter for "this" curve
*/
double ThisCurveParameter( double real_curve_parameter ) const;
private:
// "real" curve geometry that "this" is a proxy for.
const ON_Curve* m_real_curve;
// If true, the parameterization of "this" proxy is
// the reverse of the m_curve parameterization.
bool m_bReversed;
// The m_domain interval is always increasing and included in
// m_curve->Domain(). The m_domain interval defines the portion
// of m_curve that "this" proxy uses and it can be a proper
// sub-interval of m_curve->Domain().
ON_Interval m_real_curve_domain;
// The evaluation domain of this curve. If "t" is a parameter for
// "this" and "r" is a parameter for m_curve, then when m_bReversed==false
// we have
// t = m_this_domain.ParameterAt(m_real_curve_domain.NormalizedParameterAt(r))
// r = m_real_curve_domain.ParameterAt(m_this_domain.NormalizedParameterAt(t))
// and when m_bReversed==true we have
// t = m_this_domain.ParameterAt(1 - m_real_curve_domain.NormalizedParameterAt(r))
// r = m_real_curve_domain.ParameterAt(1 - m_this_domain.NormalizedParameterAt(t))
ON_Interval m_this_domain;
ON_Interval RealCurveInterval( const ON_Interval* sub_domain ) const;
public:
/*
Description:
Get a duplicate of the curve.
Returns:
A duplicate of the curve.
Remarks:
The caller must delete the returned curve.
For non-ON_CurveProxy objects, this simply duplicates the curve using
ON_Object::Duplicate.
For ON_CurveProxy objects, this duplicates the actual proxy curve
geometry and, if necessary, trims and reverse the result to that
the returned curve's parameterization and locus match the proxy curve's.
*/
ON_Curve* DuplicateCurve() const;
/////////////////////////////////////////////////////////////////
// ON_Object overrides
/*
Description:
Tests an object to see if its data members are correctly
initialized.
Parameters:
text_log - [in] if the object is not valid and text_log
is not NULL, then a brief englis description of the
reason the object is not valid is appened to the log.
The information appended to text_log is suitable for
low-level debugging purposes by programmers and is
not intended to be useful as a high level user
interface tool.
Returns:
@untitled table
true object is valid
false object is invalid, uninitialized, etc.
Remarks:
Overrides virtual ON_Object::IsValid
*/
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
void Dump( ON_TextLog& ) const; // for debugging
ON_BOOL32 Write( // returns false - nothing serialized
ON_BinaryArchive& // open binary file
) const;
ON_BOOL32 Read( // returns false - nothing serialized
ON_BinaryArchive& // open binary file
);
/////////////////////////////////////////////////////////////////
// ON_Geometry overrides
int Dimension() const;
ON_BOOL32 GetBBox( // returns true if successful
double*, // minimum
double*, // maximum
ON_BOOL32 = false // true means grow box
) const;
ON_BOOL32 Transform(
const ON_Xform&
);
/////////////////////////////////////////////////////////////////
// ON_Curve overrides
// Returns:
// domain of the curve.
// Remarks:
// If m_bReverse is true, this returns the reverse
// of m_domain.
ON_Interval Domain() const;
/* virtual ON_Curve::SetDomain() override */
ON_BOOL32 SetDomain(
double t0,
double t1
);
bool SetDomain( ON_Interval domain );
int SpanCount() const; // number of smooth spans in curve
ON_BOOL32 GetSpanVector(
double*
) const;
int Degree( // returns maximum algebraic degree of any span
// ( or a good estimate if curve spans are not algebraic )
) const;
// (optional - override if curve is piecewise smooth)
ON_BOOL32 GetParameterTolerance( // returns tminus < tplus: parameters tminus <= s <= tplus
double, // t = parameter in domain
double*, // tminus
double* // tplus
) const;
ON_BOOL32 IsLinear( // true if curve locus is a line segment between
// between specified points
double = ON_ZERO_TOLERANCE // tolerance to use when checking linearity
) const;
// virtual override of ON_Curve::IsPolyline
int IsPolyline(
ON_SimpleArray<ON_3dPoint>* pline_points = NULL,
ON_SimpleArray<double>* pline_t = NULL
) const;
ON_BOOL32 IsArc( // ON_Arc.m_angle > 0 if curve locus is an arc between
// specified points
const ON_Plane* = NULL, // if not NULL, test is performed in this plane
ON_Arc* = NULL, // if not NULL and true is returned, then arc parameters
// are filled in
double = ON_ZERO_TOLERANCE // tolerance to use when checking
) const;
ON_BOOL32 IsPlanar(
ON_Plane* = NULL, // if not NULL and true is returned, then plane parameters
// are filled in
double = ON_ZERO_TOLERANCE // tolerance to use when checking
) const;
ON_BOOL32 IsInPlane(
const ON_Plane&, // plane to test
double = ON_ZERO_TOLERANCE // tolerance to use when checking
) const;
ON_BOOL32 IsClosed( // true if curve is closed (either curve has
void // clamped end knots and euclidean location of start
) const; // CV = euclidean location of end CV, or curve is
// periodic.)
ON_BOOL32 IsPeriodic( // true if curve is a single periodic segment
void
) const;
/*
Description:
Search for a derivatitive, tangent, or curvature discontinuity.
Parameters:
c - [in] type of continity to test for. If ON::C1_continuous
t0 - [in] search begins at t0
t1 - [in] (t0 < t1) search ends at t1
t - [out] if a discontinuity is found, the *t reports the
parameter at the discontinuity.
hint - [in/out] if GetNextDiscontinuity will be called repeatedly,
passing a "hint" with initial value *hint=0 will increase the speed
of the search.
dtype - [out] if not NULL, *dtype reports the kind of discontinuity
found at *t. A value of 1 means the first derivative or unit tangent
was discontinuous. A value of 2 means the second derivative or
curvature was discontinuous.
cos_angle_tolerance - [in] default = cos(1 degree) Used only when
c is ON::G1_continuous or ON::G2_continuous. If the cosine
of the angle between two tangent vectors
is <= cos_angle_tolerance, then a G1 discontinuity is reported.
curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used only when
c is ON::G2_continuous or ON::Gsmooth_continuous.
ON::G2_continuous:
If K0 and K1 are curvatures evaluated
from above and below and |K0 - K1| > curvature_tolerance,
then a curvature discontinuity is reported.
ON::Gsmooth_continuous:
If K0 and K1 are curvatures evaluated from above and below
and the angle between K0 and K1 is at least twice angle tolerance
or ||K0| - |K1|| > (max(|K0|,|K1|) > curvature_tolerance,
then a curvature discontinuity is reported.
Returns:
true if a discontinuity was found on the interior of the interval (t0,t1).
Remarks:
Overrides ON_Curve::GetNextDiscontinuity.
*/
bool GetNextDiscontinuity(
ON::continuity c,
double t0,
double t1,
double* t,
int* hint=NULL,
int* dtype=NULL,
double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
double curvature_tolerance=ON_SQRT_EPSILON
) const;
/*
Description:
Test continuity at a curve parameter value.
Parameters:
c - [in] continuity to test for
t - [in] parameter to test
hint - [in] evaluation hint
point_tolerance - [in] if the distance between two points is
greater than point_tolerance, then the curve is not C0.
d1_tolerance - [in] if the difference between two first derivatives is
greater than d1_tolerance, then the curve is not C1.
d2_tolerance - [in] if the difference between two second derivatives is
greater than d2_tolerance, then the curve is not C2.
cos_angle_tolerance - [in] default = cos(1 degree) Used only when
c is ON::G1_continuous or ON::G2_continuous. If the cosine
of the angle between two tangent vectors
is <= cos_angle_tolerance, then a G1 discontinuity is reported.
curvature_tolerance - [in] (default = ON_SQRT_EPSILON) Used only when
c is ON::G2_continuous or ON::Gsmooth_continuous.
ON::G2_continuous:
If K0 and K1 are curvatures evaluated
from above and below and |K0 - K1| > curvature_tolerance,
then a curvature discontinuity is reported.
ON::Gsmooth_continuous:
If K0 and K1 are curvatures evaluated from above and below
and the angle between K0 and K1 is at least twice angle tolerance
or ||K0| - |K1|| > (max(|K0|,|K1|) > curvature_tolerance,
then a curvature discontinuity is reported.
Returns:
true if the curve has at least the c type continuity at the parameter t.
Remarks:
Overrides ON_Curve::IsContinuous.
*/
bool IsContinuous(
ON::continuity c,
double t,
int* hint = NULL,
double point_tolerance=ON_ZERO_TOLERANCE,
double d1_tolerance=ON_ZERO_TOLERANCE,
double d2_tolerance=ON_ZERO_TOLERANCE,
double cos_angle_tolerance=ON_DEFAULT_ANGLE_TOLERANCE_COSINE,
double curvature_tolerance=ON_SQRT_EPSILON
) const;
ON_BOOL32 Reverse(); // reverse parameterizatrion
// Domain changes from [a,b] to [-b,-a]
ON_BOOL32 Evaluate( // returns false if unable to evaluate
double, // evaluation parameter
int, // number of derivatives (>=0)
int, // array stride (>=Dimension())
double*, // array of length stride*(ndir+1)
int = 0, // optional - determines which side to evaluate from
// 0 = default
// < 0 to evaluate from below,
// > 0 to evaluate from above
int* = 0 // optional - evaluation hint (int) used to speed
// repeated evaluations
) const;
// override of virtual ON_Curve::Trim
ON_BOOL32 Trim(
const ON_Interval& domain
);
// override of virtual ON_Curve::Split
ON_BOOL32 Split(
double t,
ON_Curve*& left_side,
ON_Curve*& right_side
) const;
int GetNurbForm( // returns 0: unable to create NURBS representation
// with desired accuracy.
// 1: success - returned NURBS parameterization
// matches the curve's to wthe desired accuracy
// 2: success - returned NURBS point locus matches
// the curve's to the desired accuracy but, on
// the interior of the curve's domain, the
// curve's parameterization and the NURBS
// parameterization may not match to the
// desired accuracy.
ON_NurbsCurve&,
double = 0.0,
const ON_Interval* = NULL // OPTIONAL subdomain of ON_CurveProxy::Domain()
) const;
int HasNurbForm( // returns 0: unable to create NURBS representation
// with desired accuracy.
// 1: success - returned NURBS parameterization
// matches the curve's to wthe desired accuracy
// 2: success - returned NURBS point locus matches
// the curve's to the desired accuracy but, on
// the interior of the curve's domain, the
// curve's parameterization and the NURBS
// parameterization may not match to the
// desired accuracy.
) const;
// virtual ON_Curve::GetCurveParameterFromNurbFormParameter override
ON_BOOL32 GetCurveParameterFromNurbFormParameter(
double, // nurbs_t
double* // curve_t
) const;
// virtual ON_Curve::GetNurbFormParameterFromCurveParameter override
ON_BOOL32 GetNurbFormParameterFromCurveParameter(
double, // curve_t
double* // nurbs_t
) const;
};
#endif

369
extern/opennurbs/opennurbs_cylinder.cpp vendored Executable file
View File

@@ -0,0 +1,369 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
ON_Cylinder::ON_Cylinder()
{
height[0] = 0.0;
height[1] = 0.0;
}
ON_Cylinder::ON_Cylinder(
const ON_Circle& c
)
{
Create(c);
}
ON_Cylinder::ON_Cylinder(
const ON_Circle& c,
double h
)
{
Create(c,h);
}
ON_Cylinder::~ON_Cylinder()
{}
bool ON_Cylinder::Create(
const ON_Circle& c
)
{
return Create( c, 0.0 );
}
bool ON_Cylinder::Create(
const ON_Circle& c,
double h
)
{
circle = c;
if ( h > 0.0 ) {
height[0] = 0.0;
height[1] = h;
}
else {
height[0] = h;
height[1] = 0.0;
}
return IsValid();
}
bool ON_Cylinder::IsValid() const
{
return circle.IsValid();
}
bool ON_Cylinder::IsFinite() const
{
return height[0] != height[1];
}
const ON_3dVector& ON_Cylinder::Axis() const
{
return circle.plane.zaxis;
}
const ON_3dPoint& ON_Cylinder::Center() const
{
return circle.plane.origin;
}
double ON_Cylinder::Height() const
{
return height[1] - height[0];
}
ON_Circle ON_Cylinder::CircleAt(
double t // linear parameter
) const
{
ON_Circle c = circle;
if ( t != 0.0 )
c.Translate(t*circle.plane.zaxis);
return c;
}
ON_Line ON_Cylinder::LineAt(
double s // angular parameter
) const
{
ON_3dPoint p = circle.PointAt(s);
ON_Line line;
line.from = p + height[0]*circle.plane.zaxis;
line.to = p + height[1]*circle.plane.zaxis;
return line;
}
ON_3dPoint ON_Cylinder::PointAt( double s, double t ) const
{
return ( circle.PointAt(s) + t*circle.plane.zaxis );
}
ON_3dPoint ON_Cylinder::NormalAt( double s, double t ) const
{
ON_3dVector N = ON_CrossProduct( circle.TangentAt(s), circle.plane.zaxis );
N.Unitize();
return N;
}
// returns parameters of point on cylinder that is closest to given point
bool ON_Cylinder::ClosestPointTo(
ON_3dPoint point,
double* s, // angular parameter
double* t // linear parameter
) const
{
bool rc = true;
//const ON_3dVector v = point - circle.plane.origin;
double h = (point - circle.plane.origin)*circle.plane.zaxis;
if ( s )
rc = circle.ClosestPointTo( point - h*circle.plane.zaxis, s );
if ( t ) {
if ( height[0] < height[1] ) {
if ( h < height[0] ) h = height[0]; else if ( h > height[1] ) h = height[1];
}
else if ( height[0] > height[1] ) {
if ( h > height[0] ) h = height[0]; else if ( h < height[1] ) h = height[1];
}
*t = h;
}
return rc;
}
// returns point on cylinder that is closest to given point
ON_3dPoint ON_Cylinder::ClosestPointTo(
ON_3dPoint point
) const
{
double s, t;
ClosestPointTo( point, &s, &t );
return PointAt( s, t );
}
// rotate plane about its origin
bool ON_Cylinder::Rotate(
double sin_angle,
double cos_angle,
const ON_3dVector& axis // axis of rotation
)
{
return Rotate( sin_angle, cos_angle, axis, circle.plane.origin );
}
bool ON_Cylinder::Rotate(
double angle, // angle in radians
const ON_3dVector& axis // axis of rotation
)
{
return Rotate( sin(angle), cos(angle), axis, circle.plane.origin );
}
// rotate plane about a point and axis
bool ON_Cylinder::Rotate(
double sin_angle, // sin(angle)
double cos_angle, // cos(angle)
const ON_3dVector& axis, // axis of rotation
const ON_3dPoint& point // center of rotation
)
{
return circle.Rotate( sin_angle, cos_angle, axis, point );
}
bool ON_Cylinder::Rotate(
double angle, // angle in radians
const ON_3dVector& axis, // axis of rotation
const ON_3dPoint& point // center of rotation
)
{
return Rotate( sin(angle), cos(angle), axis, point );
}
bool ON_Cylinder::Translate(
const ON_3dVector& delta
)
{
return circle.Translate( delta );
}
int ON_Cylinder::GetNurbForm( ON_NurbsSurface& s ) const
{
int rc = 0;
if ( IsValid() && height[0] != height[1] ) {
ON_NurbsCurve n0, n1;
int i;
ON_Circle c0 = CircleAt(height[0]);
ON_Circle c1 = CircleAt(height[1]);
if ( height[0] <= height[1] ) {
c0.GetNurbForm(n0);
c1.GetNurbForm(n1);
}
else {
c0.GetNurbForm(n1);
c1.GetNurbForm(n0);
}
if ( n0.m_dim != n1.m_dim
|| n0.m_is_rat != n1.m_is_rat
|| n0.m_order != n1.m_order
|| n0.m_cv_count != n1.m_cv_count )
return 0;
s.Create(3,true, n0.m_order, 2, n0.m_cv_count, 2 );
if ( height[0] <= height[1] ) {
s.m_knot[1][0] = height[0];
s.m_knot[1][1] = height[1];
}
else {
s.m_knot[1][0] = height[1];
s.m_knot[1][1] = height[0];
}
for ( i = 0; i < n0.KnotCount(); i++ )
s.m_knot[0][i] = n0.m_knot[i];
for ( i = 0; i < n0.m_cv_count; i++ ) {
s.SetCV(i,0,ON::homogeneous_rational,n0.CV(i));
s.SetCV(i,1,ON::homogeneous_rational,n1.CV(i));
}
rc = 2;
}
return rc;
}
ON_RevSurface* ON_Cylinder::RevSurfaceForm( ON_RevSurface* srf ) const
{
if ( srf )
srf->Destroy();
ON_RevSurface* pRevSurface = NULL;
if ( IsFinite() && IsValid() )
{
ON_Line line;
line.from = PointAt(0.0,height[0]);
line.to = PointAt(0.0,height[1]);
ON_Interval h(height[0],height[1]); // h = evaluation domain for line (must be increasing)
if ( h.IsDecreasing() )
h.Swap();
ON_LineCurve* line_curve = new ON_LineCurve( line, h[0], h[1] );
if ( srf )
pRevSurface = srf;
else
pRevSurface = new ON_RevSurface();
pRevSurface->m_angle.Set(0.0,2.0*ON_PI);
pRevSurface->m_t = pRevSurface->m_angle;
pRevSurface->m_curve = line_curve;
pRevSurface->m_axis.from = circle.plane.origin;
pRevSurface->m_axis.to = circle.plane.origin + circle.plane.zaxis;
pRevSurface->m_bTransposed = false;
ON_Circle c0(circle);
c0.Translate(height[0]*circle.plane.zaxis);
ON_Circle c1(circle);
c1.Translate(height[1]*circle.plane.zaxis);
pRevSurface->m_bbox = c0.BoundingBox();
pRevSurface->m_bbox.Union(c1.BoundingBox());
}
return pRevSurface;
}
/*
// obsolete use ON_BrepCylinder
ON_Brep* ON_Cylinder::BrepForm( ON_Brep* brep ) const
{
if ( brep )
brep->Destroy();
ON_Brep* pBrep = 0;
ON_RevSurface* pRevSurface = RevSurfaceForm();
if ( pRevSurface )
{
if ( brep )
pBrep = brep;
else
pBrep = new ON_Brep();
if ( !pBrep->Create(pRevSurface) )
{
if ( !brep )
delete pBrep;
pBrep = 0;
if (pRevSurface)
{
delete pRevSurface;
pRevSurface = 0;
}
}
else
{
// add caps
for ( int capcount = 0; capcount < 2; capcount++ )
{
// capcount = 0 for bottom cap and 1 for top cap
ON_Circle circle = CircleAt(height[capcount]);
if ( capcount == 0 )
circle.Reverse();
double radius = circle.radius;
ON_NurbsSurface* pCapSurface = ON_NurbsSurfaceQuadrilateral(
circle.plane.PointAt(-radius,-radius),
circle.plane.PointAt(+radius,-radius),
circle.plane.PointAt(+radius,+radius),
circle.plane.PointAt(-radius,+radius)
);
pCapSurface->m_knot[0][0] = -fabs(radius);
pCapSurface->m_knot[0][1] = fabs(radius);
pCapSurface->m_knot[1][0] = pCapSurface->m_knot[0][0];
pCapSurface->m_knot[1][1] = pCapSurface->m_knot[0][1];
circle.Create( ON_xy_plane, ON_origin, radius );
ON_NurbsCurve* c2 = new ON_NurbsCurve();
circle.GetNurbForm(*c2);
c2->ChangeDimension(2);
pBrep->m_S.Append(pCapSurface);
pBrep->m_C2.Append(c2);
ON_BrepFace& cap = pBrep->NewFace( pBrep->m_S.Count()-1 );
ON_BrepLoop& loop = pBrep->NewLoop( ON_BrepLoop::outer, cap );
ON_BrepEdge& edge = pBrep->m_E[capcount?0:2];
ON_BrepTrim& trim = pBrep->NewTrim( edge, true, loop, pBrep->m_C2.Count()-1 );
for ( int eti = 0; eti < edge.m_ti.Count(); eti++ )
pBrep->m_T[ edge.m_ti[eti] ].m_type = ON_BrepTrim::mated;
trim.m_tolerance[0] = 0.0;
trim.m_tolerance[1] = 0.0;
trim.m_pbox.m_min.x = -radius;
trim.m_pbox.m_min.y = -radius;
trim.m_pbox.m_min.z = 0.0;
trim.m_pbox.m_max.x = radius;
trim.m_pbox.m_max.y = radius;
trim.m_pbox.m_max.z = 0.0;
loop.m_pbox = trim.m_pbox;
pBrep->SetTrimTypeFlags(trim);
pBrep->SetTrimIsoFlags(trim);
}
if ( !pBrep->IsValid() )
{
if (brep)
brep->Destroy();
else
delete pBrep;
pBrep = 0;
}
}
}
return pBrep;
}
*/

152
extern/opennurbs/opennurbs_cylinder.h vendored Executable file
View File

@@ -0,0 +1,152 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_CYLINDER_INC_)
#define OPENNURBS_CYLINDER_INC_
class ON_NurbsSurface;
class ON_RevSurface;
class ON_Brep;
/*
Description:
ON_Cylinder is a right circular cylinder.
*/
class ON_CLASS ON_Cylinder
{
public:
ON_Cylinder(); // zeros all fields - cylinder is invalid
ON_Cylinder( // infinte cylinder
const ON_Circle& // point on the bottom plane
);
ON_Cylinder( // infinte cylinder
const ON_Circle&, // point on the bottom plane
double // height
);
~ON_Cylinder();
bool Create(
const ON_Circle& // point on the bottom plane
);
bool Create(
const ON_Circle&, // point on the bottom plane
double // height
);
bool IsValid() const; // returns true if all fields contain reasonable
// information and equation jibes with point and Z.
bool IsFinite() const; // returns true if the cylinder is finite
// (height[0] != height[1]) and false if the
// cylinder is infinite.
const ON_3dVector& Axis() const;
const ON_3dPoint& Center() const;
double Height() const; // returns 0 for infinite cylinder
ON_Circle CircleAt(
double // linear parameter
) const;
ON_Line LineAt(
double // angular parameter
) const;
// evaluate parameters and return point
ON_3dPoint PointAt(
double, // angular parameter [0,2pi]
double // linear parameter (height from base circle's plane)
) const;
ON_3dPoint NormalAt(
double, // angular parameter [0,2pi]
double // linear parameter (height from base circle's plane)
) const;
// returns parameters of point on cylinder that is closest to given point
bool ClosestPointTo(
ON_3dPoint,
double*, // angular parameter [0,2pi]
double* // linear parameter (height from base circle's plane)
) const;
// returns point on cylinder that is closest to given point
ON_3dPoint ClosestPointTo(
ON_3dPoint
) const;
// For intersections see ON_Intersect();
// rotate cylinder about its origin
bool Rotate(
double, // sin(angle)
double, // cos(angle)
const ON_3dVector& // axis of rotation
);
bool Rotate(
double, // angle in radians
const ON_3dVector& // axis of rotation
);
// rotate cylinder about a point and axis
bool Rotate(
double, // sin(angle)
double, // cos(angle)
const ON_3dVector&, // axis of rotation
const ON_3dPoint& // center of rotation
);
bool Rotate(
double, // angle in radians
const ON_3dVector&, // axis of rotation
const ON_3dPoint& // center of rotation
);
bool Translate(
const ON_3dVector&
);
// parameterization of NURBS surface does not match cylinder's transcendental paramaterization
int GetNurbForm( ON_NurbsSurface& ) const; // returns 0=failure, 2=success
/*
Description:
Creates a surface of revolution definition of the cylinder.
Parameters:
srf - [in] if not NULL, then this srf is used.
Result:
A surface of revolution or NULL if the cylinder is not
valid or is infinite.
*/
ON_RevSurface* RevSurfaceForm( ON_RevSurface* srf = NULL ) const;
public: // members left public
// base circle
ON_Circle circle;
// If height[0] = height[1], the cylinder is infinite,
// Otherwise, height[0] < height[1] and the center of
// the "bottom" cap is
//
// circle.plane.origin + height[0]*circle.plane.zaxis,
//
// and the center of the top cap is
//
// circle.plane.origin + height[1]*circle.plane.zaxis.
double height[2];
};
#endif

2266
extern/opennurbs/opennurbs_defines.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

1710
extern/opennurbs/opennurbs_defines.h vendored Executable file

File diff suppressed because it is too large Load Diff

190
extern/opennurbs/opennurbs_detail.cpp vendored Executable file
View File

@@ -0,0 +1,190 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
ON_OBJECT_IMPLEMENT(ON_DetailView,ON_Geometry,"C8C66EFA-B3CB-4e00-9440-2AD66203379E");
ON_DetailView::ON_DetailView()
{
m_page_per_model_ratio = 0.0;
}
ON_DetailView::~ON_DetailView()
{
}
void ON_DetailView::MemoryRelocate()
{
m_boundary.MemoryRelocate();
}
ON_BOOL32 ON_DetailView::IsValid( ON_TextLog* text_log ) const
{
// Don't bother checking m_view - during runtime it's
// not filled in. It is only used for IO. See
// CRhDetailViewObject::PrepareToWrite() for details.
return m_boundary.IsValid(text_log);
}
void ON_DetailView::Dump( ON_TextLog& text_log ) const
{
m_view.Dump(text_log);
m_boundary.Dump(text_log);
}
unsigned int ON_DetailView::SizeOf() const
{
unsigned int sz = ON_Geometry::SizeOf();
sz += sizeof(*this) - sizeof(ON_Geometry);
sz += m_boundary.SizeOf();
return sz;
}
ON_BOOL32 ON_DetailView::Write( ON_BinaryArchive& archive ) const
{
bool rc = archive.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 1, 1 );
if (!rc)
return false;
for(;;)
{
// m_view is wrapped in a subchunk so ON_3dmView can be expanded
// without breaking the file format.
rc = archive.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 1, 0 );
if (rc)
{
rc = m_view.Write(archive);
if (!archive.EndWrite3dmChunk())
rc = false;
}
if(!rc)
break;
// m_boundary is wrapped in a subchunk so ON_NurbsCurve can be expanded
// without breaking the file format.
rc = archive.BeginWrite3dmChunk( TCODE_ANONYMOUS_CHUNK, 1, 0 );
if (rc)
{
rc = m_boundary.Write(archive)?true:false;
if (!archive.EndWrite3dmChunk())
rc = false;
}
if(!rc)
break;
// 28 Feb 2006 1.1 fields added
rc = archive.WriteDouble(m_page_per_model_ratio);
if ( !rc )
break;
break;
}
if ( !archive.EndWrite3dmChunk() )
rc = false;
return rc;
}
ON_BOOL32 ON_DetailView::Read(ON_BinaryArchive& archive)
{
m_page_per_model_ratio = 0.0;
m_view.Default();
m_boundary.Destroy();
int major_version = 0;
int minor_version = 0;
bool rc = archive.BeginRead3dmChunk( TCODE_ANONYMOUS_CHUNK, &major_version, &minor_version );
if (!rc)
return false;
for(;;)
{
rc = (1 == major_version );
if (!rc) break;
// m_view is wrapped in a subchunk so ON_3dmView can be expanded
// without breaking the file format.
int mj = 0, mn = 0;
rc = archive.BeginRead3dmChunk( TCODE_ANONYMOUS_CHUNK, &mj, &mn );
if (rc)
{
rc = m_view.Read(archive);
if (!archive.EndRead3dmChunk())
rc = false;
}
if (!rc) break;
// m_boundary is wrapped in a subchunk so ON_NurbsCurve can be expanded
// without breaking the file format.
mj = mn = 0;
rc = archive.BeginRead3dmChunk( TCODE_ANONYMOUS_CHUNK, &mj, &mn );
if (rc)
{
rc = m_boundary.Read(archive)?true:false;
if (!archive.EndRead3dmChunk())
rc = false;
}
if (!rc) break;
if ( minor_version >= 1 )
{
rc = archive.ReadDouble(&m_page_per_model_ratio);
}
break;
}
if ( !archive.EndRead3dmChunk() )
rc = false;
return rc;
}
ON::object_type ON_DetailView::ObjectType() const
{
return ON::detail_object;
}
int ON_DetailView::Dimension() const
{
return m_boundary.Dimension();
}
ON_BOOL32 ON_DetailView::GetBBox(
double* boxmin,
double* boxmax,
int bGrowBox
) const
{
return m_boundary.GetBBox(boxmin,boxmax,bGrowBox);
}
bool ON_DetailView::GetTightBoundingBox(
ON_BoundingBox& tight_bbox, int bGrowBox, const ON_Xform* xform
) const
{
return m_boundary.GetTightBoundingBox(tight_bbox,bGrowBox,xform);
}
ON_BOOL32 ON_DetailView::Transform( const ON_Xform& xform )
{
return m_boundary.Transform(xform);
}

95
extern/opennurbs/opennurbs_detail.h vendored Executable file
View File

@@ -0,0 +1,95 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(ON_DETAIL_OBJECTY_INC_)
#define ON_DETAIL_OBJECTY_INC_
class ON_CLASS ON_DetailView : public ON_Geometry
{
ON_OBJECT_DECLARE(ON_DetailView);
public:
ON_DetailView();
~ON_DetailView();
// C++ defaults for copy constructor and
// operator= work fine.
//////////////////////////////////////////////////////
//
// virtual ON_Object overrides
//
void MemoryRelocate();
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
void Dump( ON_TextLog& ) const;
unsigned int SizeOf() const;
ON_BOOL32 Write(
ON_BinaryArchive& binary_archive
) const;
ON_BOOL32 Read(
ON_BinaryArchive& binary_archive
);
ON::object_type ObjectType() const; // returns ON::detail_object
//////////////////////////////////////////////////////
//
// virtual ON_Geometry overrides
// The m_boundary determines all bounding boxes
//
int Dimension() const;
ON_BOOL32 GetBBox(
double* boxmin,
double* boxmax,
int bGrowBox = false
) const;
bool GetTightBoundingBox(
ON_BoundingBox& tight_bbox,
int bGrowBox = false,
const ON_Xform* xform = 0
) const;
ON_BOOL32 Transform( const ON_Xform& xform );
// m_page_per_model_ratio is the ratio of page length / model length
// where both lengths are in the same unit system
// (ex. 1/4" on page = 1' in model = 0.25/12 = 0.02083)
// ( 1mm on page = 1m in model = 1/1000 = 0.001)
// If m_page_per_model_ratio > 0.0, then the detail
// is drawn using the specified scale.
double m_page_per_model_ratio;
// A view with ON_3dmView::m_view_type = ON::nested_view_type
// This field is used for IO purposes only. Runtime detail
// view projection information is on CRhDetailViewObject.
ON_3dmView m_view;
// 2d curve in page layout coordinates in mm
// (0,0) = lower left corner of page
ON_NurbsCurve m_boundary;
};
#endif

2342
extern/opennurbs/opennurbs_dimstyle.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

469
extern/opennurbs/opennurbs_dimstyle.h vendored Executable file
View File

@@ -0,0 +1,469 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_DIMSTYLE_INC_)
#define OPENNURBS_DIMSTYLE_INC_
class ON_CLASS ON_DimStyle : public ON_Object
{
ON_OBJECT_DECLARE(ON_DimStyle);
public:
enum eArrowType
{
solidtriangle = 0, // 2:1
dot = 1,
tick = 2,
shorttriangle = 3, // 1:1
arrow = 4,
rectangle = 5,
longtriangle = 6, // 4:1
longertriangle = 7, // 6:1
};
ON_DimStyle();
~ON_DimStyle();
// C++ default copy construction and operator= work fine.-
ON_DimStyle& operator=( const ON_3dmAnnotationSettings& src);
//////////////////////////////////////////////////////////////////////
//
// ON_Object overrides
/*
Description:
Tests an object to see if its data members are correctly
initialized.
Parameters:
text_log - [in] if the object is not valid and text_log
is not NULL, then a brief englis description of the
reason the object is not valid is appened to the log.
The information appended to text_log is suitable for
low-level debugging purposes by programmers and is
not intended to be useful as a high level user
interface tool.
Returns:
@untitled table
true object is valid
false object is invalid, uninitialized, etc.
Remarks:
Overrides virtual ON_Object::IsValid
*/
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
// virtual
void Dump( ON_TextLog& ) const; // for debugging
// virtual
ON_BOOL32 Write(
ON_BinaryArchive& // serialize definition to binary archive
) const;
// virtual
ON_BOOL32 Read(
ON_BinaryArchive& // restore definition from binary archive
);
void EmergencyDestroy();
// virtual
ON_UUID ModelObjectId() const;
//////////////////////////////////////////////////////////////////////
//
// Interface
void SetName( const wchar_t* );
void SetName( const char* );
void GetName( ON_wString& ) const;
const wchar_t* Name() const;
void SetIndex(int);
int Index() const;
void SetDefaults();
void SetDefaultsNoExtension();
double ExtExtension() const;
void SetExtExtension( const double);
double ExtOffset() const;
void SetExtOffset( const double);
double ArrowSize() const;
void SetArrowSize( const double);
double LeaderArrowSize() const;
void SetLeaderArrowSize( const double);
double CenterMark() const;
void SetCenterMark( const double);
int TextAlignment() const;
void SetTextAlignment( ON::eTextDisplayMode);
int ArrowType() const;
void SetArrowType( eArrowType);
int LeaderArrowType() const;
void SetLeaderArrowType( eArrowType);
int AngularUnits() const;
void SetAngularUnits( int);
int LengthFormat() const;
void SetLengthFormat( int);
int AngleFormat() const;
void SetAngleFormat( int);
int LengthResolution() const;
void SetLengthResolution( int);
int AngleResolution() const;
void SetAngleResolution( int);
int FontIndex() const;
virtual void SetFontIndex( int index);
double TextGap() const;
void SetTextGap( double gap);
double TextHeight() const;
void SetTextHeight( double height);
// added at ver 1.3
double LengthFactor() const;
ON_DEPRECATED void SetLengthactor( double);
void SetLengthFactor( double); // added 6/24/07 because of typo
bool Alternate() const;
void SetAlternate( bool);
double AlternateLengthFactor() const;
ON_DEPRECATED void SetAlternateLengthactor( double);
void SetAlternateLengthFactor( double); // added 6/24/07 because of typo
int AlternateLengthFormat() const;
void SetAlternateLengthFormat( int);
int AlternateLengthResolution() const;
void SetAlternateLengthResolution( int);
int AlternateAngleFormat() const;
void SetAlternateAngleFormat( int);
int AlternateAngleResolution() const;
void SetAlternateAngleResolution( int);
void GetPrefix( ON_wString& ) const;
const wchar_t* Prefix() const;
void SetPrefix( const wchar_t*);
void SetPrefix( wchar_t*);
void GetSuffix( ON_wString& ) const;
const wchar_t* Suffix() const;
void SetSuffix( const wchar_t*);
void SetSuffix( wchar_t*);
void GetAlternatePrefix( ON_wString& ) const;
const wchar_t* AlternatePrefix() const;
void SetAlternatePrefix( const wchar_t*);
void SetAlternatePrefix( wchar_t*);
void GetAlternateSuffix( ON_wString& ) const;
const wchar_t* AlternateSuffix() const;
void SetAlternateSuffix( const wchar_t*);
void SetAlternateSuffix( wchar_t*);
bool SuppressExtension1() const;
void SetSuppressExtension1( bool);
bool SuppressExtension2() const;
void SetSuppressExtension2( bool);
// obsolete
ON_DEPRECATED void Composite( const ON_DimStyle& override);
// Don't change these enum values
// They are used in file reading & writing
enum eField
{
fn_name = 0,
fn_index = 1,
fn_extextension = 2,
fn_extoffset = 3,
fn_arrowsize = 4,
fn_centermark = 5,
fn_textgap = 6,
fn_textheight = 7,
fn_textalign = 8,
fn_arrowtype = 9,
fn_angularunits = 10,
fn_lengthformat = 11,
fn_angleformat = 12,
fn_angleresolution = 13,
fn_lengthresolution = 14,
fn_fontindex = 15,
fn_lengthfactor = 16,
fn_bAlternate = 17,
fn_alternate_lengthfactor = 18,
fn_alternate_lengthformat = 19,
fn_alternate_lengthresolution = 20,
fn_alternate_angleformat = 21,
fn_alternate_angleresolution = 22,
fn_prefix = 23,
fn_suffix = 24,
fn_alternate_prefix = 25,
fn_alternate_suffix = 26,
fn_dimextension = 27,
fn_leaderarrowsize = 28,
fn_leaderarrowtype = 29,
fn_suppressextension1 = 30,
fn_suppressextension2 = 31,
fn_last = 32, // not used - left here for sdk
// Added for v5 - 5/01/07 LW
// version 1.6
fn_overall_scale = 33,
fn_ext_line_color_source = 34,
fn_dim_line_color_source = 35,
fn_arrow_color_source = 36,
fn_text_color_source = 37,
fn_ext_line_color = 38,
fn_dim_line_color = 39,
fn_arrow_color = 40,
fn_text_color = 41,
fn_ext_line_plot_color_source = 42,
fn_dim_line_plot_color_source = 43,
fn_arrow_plot_color_source = 44,
fn_text_plot_color_source = 45,
fn_ext_line_plot_color = 46,
fn_dim_line_plot_color = 47,
fn_arrow_plot_color = 48,
fn_text_plot_color = 49,
fn_ext_line_plot_weight_source = 50,
fn_dim_line_plot_weight_source = 51,
fn_ext_line_plot_weight_mm = 52,
fn_dim_line_plot_weight_mm = 53,
fn_tolerance_style = 54,
fn_tolerance_resolution = 55,
fn_tolerance_upper_value = 56,
fn_tolerance_lower_value = 57,
fn_tolerance_height_scale = 58,
fn_baseline_spacing = 59,
// Added for v5 - 12/15/09 LW
// version 1.7
fn_draw_mask = 60,
fn_mask_color_source = 61,
fn_mask_color = 62,
fn_mask_border = 63,
// Added for v5 - 12/17/09 LW
// version 1.8
fn_dimscale = 64,
fn_dimscale_source = 65,
//When fields are added to ON_DimStyleExtra,
// enum { eFieldCount = 64 }; in opennurbs_dimstyle.cpp
// needs to be changed.
fn_really_last = 0xFFFF
};
// These are obsolete - don't use
// 5/01/07 - LW
ON_DEPRECATED void InvalidateField( eField field);
ON_DEPRECATED void InvalidateAllFields();
ON_DEPRECATED void ValidateField( eField field);
ON_DEPRECATED bool IsFieldValid( eField) const;
// added version 1.3
double DimExtension() const;
void SetDimExtension( const double);
// This section Added for v5 - 4-24-07 LW
// version 1.6
// Test if a specific field has been set in this dimstyle
// and not inherited from its parent.
bool IsFieldOverride( eField field_id) const;
// Set a field to be overridden or not
// Fields that aren't overrides inherit from their parent dimstyle
void SetFieldOverride( ON_DimStyle::eField field_id, bool bOverride);
// Test if the dimstyle has any field override flags set
bool HasOverrides() const;
// Change the fields in this dimstyle to match the fields of the
// source dimstyle for all of the fields that are marked overridden in the source
// and to match the parent for all of the fields not marked overriden.
// Returns true if any overrides were set.
bool OverrideFields( const ON_DimStyle& source, const ON_DimStyle& parent);
//
// Change the fields in this dimstyle to match the fields of the
// parent dimstyle for all of the fields that are not marked overridden in the
// target dimstyle.
// This is the complement of OverrideFields()
bool InheritFields( const ON_DimStyle& parent);
// Test if this dimstyle is the child of any other dimstyle
bool IsChildDimstyle() const;
// Test if this dimstyle is the child of a given dimstyle
// A dimstyle may have several child dimstyles, but only one parent
bool IsChildOf( const ON_UUID& parent_uuid) const;
bool IsChildOf( ON_UUID& parent_uuid) const; // decl error - const forgotten
ON_UUID ParentId() const;
// Set the parent of this dimstyle
void SetParentId( ON_UUID parent_uuid);
ON_DEPRECATED void SetParent( ON_UUID& parent_uuid); // use set parent id
// Tolerances
// Tolerance style
// 0: None
// 1: Symmetrical
// 2: Deviation
// 3: Limits
// 4: Basic
int ToleranceStyle() const;
int ToleranceResolution() const;
double ToleranceUpperValue() const;
double ToleranceLowerValue() const;
double ToleranceHeightScale() const;
double BaselineSpacing() const;
void SetToleranceStyle( int style);
void SetToleranceResolution( int resolution);
void SetToleranceUpperValue( double upper_value);
void SetToleranceLowerValue( double lower_value);
void SetToleranceHeightScale( double scale);
void SetBaselineSpacing( double spacing = false);
// Determines whether or not to draw a Text Mask
bool DrawTextMask() const;
void SetDrawTextMask(bool bDraw);
// Determines where to get the color to draw a Text Mask
// 0: Use background color of the viewport. Initially, gradient backgrounds will not be supported
// 1: Use the ON_Color returned by MaskColor()
int MaskColorSource() const;
void SetMaskColorSource(int source);
ON_Color MaskColor() const; // Only works right if MaskColorSource returns 1.
// Does not return viewport background color
void SetMaskColor(ON_Color color);
// Per DimStyle DimScale
void SetDimScaleSource(int source);
int DimScaleSource() const; // 0: Global DimScale, 1: DimStyle DimScale
void SetDimScale(double scale);
double DimScale() const;
// Offset for the border around text to the rectangle used to draw the mask
// This number * CRhinoAnnotation::TextHeight() for the text is the offset
// on each side of the tight rectangle around the text characters to the mask rectangle.
double MaskOffsetFactor() const;
void Scale( double scale);
// UUID of the dimstyle this was originally copied from
// so Restore Defaults has some place to look
void SetSourceDimstyle(ON_UUID source_uuid);
ON_UUID SourceDimstyle() const;
// Defaults for values stored in Userdata extension
static int DefaultToleranceStyle();
static int DefaultToleranceResolution();
static double DefaultToleranceUpperValue();
static double DefaultToleranceLowerValue();
static double DefaultToleranceHeightScale();
static double DefaultBaselineSpacing();
static bool DefaultDrawTextMask(); // false
static int DefaultMaskColorSource(); // 0;
static ON_Color DefaultMaskColor(); // .SetRGB(255,255,255);
static double DefaultDimScale(); // 1.0;
static int DefaultDimScaleSource(); // 0;
bool CompareFields(const ON_DimStyle& other) const;
public:
ON_wString m_dimstyle_name; // String name of the style
int m_dimstyle_index; // Index in the dimstyle table
ON_UUID m_dimstyle_id;
double m_extextension; // extension line extension
double m_extoffset; // extension line offset
double m_arrowsize; // length of an arrow - may mean different things to different arrows
double m_centermark; // size of the + at circle centers
double m_textgap; // gap around the text for clipping dim line
double m_textheight; // model unit height of dimension text before applying dimscale
int m_textalign; // text alignment relative to the dimension line
int m_arrowtype; // 0: filled narrow triangular arrow
int m_angularunits; // 0: degrees, 1: radians
int m_lengthformat; // 0: decimal, 1: feet, 2: feet & inches
int m_angleformat; // 0: decimal degrees, ...
int m_angleresolution; // for decimal degrees, digits past decimal
int m_lengthresolution; // depends on m_lengthformat
// for decimal, digits past the decimal point
int m_fontindex; // index of the ON_Font used by this dimstyle
// added fields version 1.2, Jan 13, 05
double m_lengthfactor; // (dimlfac) model units multiplier for length display
bool m_bAlternate; // (dimalt) display alternate dimension string (or not)
// using m_alternate_xxx values
double m_alternate_lengthfactor; // (dimaltf) model units multiplier for alternate length display
int m_alternate_lengthformat; // 0: decimal, 1: feet, 2: feet & inches
int m_alternate_lengthresolution; // depends on m_lengthformat
// for decimal, digits past the decimal point
int m_alternate_angleformat; // 0: decimal degrees, ...
int m_alternate_angleresolution; // for decimal degrees, digits past decimal
ON_wString m_prefix; // string preceding dimension value string
ON_wString m_suffix; // string following dimension value string
ON_wString m_alternate_prefix; // string preceding alternate value string
ON_wString m_alternate_suffix; // string following alternate value string
private:
unsigned int m_valid; // Obsolete deprecated field to be removed - Do not use
public:
// field added version 1.4, Dec 28, 05
double m_dimextension; // (dimdle) dimension line extension past the "tip" location
// fields added version 1.5 Mar 23 06
double m_leaderarrowsize; // Like dimension arrow size but applies to leaders
int m_leaderarrowtype; // Like dimension arrow type but applies to leaders
bool m_bSuppressExtension1; // flag to not draw extension lines
bool m_bSuppressExtension2; // flag to not draw extension lines
// Added March 23, 2008 -LW
// This function is temporary and will be removed next time the SDK can be modified.
class ON_DimStyleExtra* DimStyleExtension(); // can return null
const class ON_DimStyleExtra* DimStyleExtension() const; // can return null
};
#endif

65
extern/opennurbs/opennurbs_dll.cpp vendored Executable file
View File

@@ -0,0 +1,65 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
// opennurbs_dll.cpp : Defines the entry point for the Windows DLL application.
//
#if defined(ON_OS_WINDOWS) && defined(ON_DLL_EXPORTS)
BOOL APIENTRY DllMain( HANDLE hModule,
DWORD ul_reason_for_call,
LPVOID lpReserved
)
{
static int bRunning = 0;
if ( !bRunning )
{
bRunning = true;
}
switch( ul_reason_for_call ) {
case DLL_PROCESS_ATTACH:
ON_ClassId::IncrementMark(); // make sure each DLL that each process that
// uses OpenNURBS has a unique mark.
break;
// 16 August 2010 Dale Lear:
// These generate too much noise in the output window
//
//case DLL_THREAD_ATTACH:
// ::OutputDebugStringA("OpenNURBS DllMain() ul_reason_for_call = DLL_THREAD_ATTACH\n");
// break;
//case DLL_THREAD_DETACH:
// ::OutputDebugStringA("OpenNURBS DllMain() ul_reason_for_call = DLL_THREAD_DETACH\n");
// break;
//case DLL_PROCESS_DETACH:
// ::OutputDebugStringA("OpenNURBS DllMain() ul_reason_for_call = DLL_PROCESS_DETACH\n");
// break;
//default:
// ::OutputDebugStringA("OpenNURBS DllMain() ul_reason_for_call = ?\n");
// break;
}
return true;
}
#endif

14
extern/opennurbs/opennurbs_dll_resource.h vendored Executable file
View File

@@ -0,0 +1,14 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by opennurbs.rc
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1001
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

465
extern/opennurbs/opennurbs_ellipse.cpp vendored Executable file
View File

@@ -0,0 +1,465 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
ON_Ellipse::ON_Ellipse()
{
radius[0] = radius[1] = 0.0;
}
ON_Ellipse::ON_Ellipse(
const ON_Plane& p,
double rx, double ry
)
{
Create(p,rx,ry);
}
ON_Ellipse::ON_Ellipse(
const ON_Circle& c
)
{
Create(c);
}
ON_Ellipse::~ON_Ellipse()
{}
ON_Ellipse& ON_Ellipse::operator=(const ON_Circle& c)
{
Create( c );
return *this;
}
ON_BOOL32 ON_Ellipse::Create( const ON_Plane& p, double rx, double ry )
{
plane = p;
radius[0] = rx;
radius[1] = ry;
return IsValid();
}
ON_BOOL32 ON_Ellipse::Create( const ON_Circle& c )
{
return Create( c.Plane(), c.Radius(), c.Radius() );
}
ON_BOOL32 ON_Ellipse::IsValid() const
{
return (plane.IsValid() && radius[0] > ON_ZERO_TOLERANCE && radius[1] > ON_ZERO_TOLERANCE) ? true : false;
}
ON_BOOL32 ON_Ellipse::IsCircle() const
{
double r0 = radius[0];
return ( ON_IsValid(r0) && fabs(r0-radius[1]) <= fabs(r0)*ON_ZERO_TOLERANCE && IsValid() ) ? true : false;
}
double ON_Ellipse::Radius( int i ) const
{
return radius[(i)?1:0];
}
const ON_3dPoint& ON_Ellipse::Center() const
{
return plane.origin;
}
double ON_Ellipse::FocalDistance() const
{
int i = (fabs(radius[0]) >= fabs(radius[1])) ? 0 : 1;
const double a = fabs(radius[i]);
const double b = a > 0.0 ? fabs(radius[1-i])/a : 0.0;
return a*sqrt(1.0 - b*b);
}
bool ON_Ellipse::GetFoci( ON_3dPoint& F1, ON_3dPoint& F2 ) const
{
const double f = FocalDistance();
const ON_3dVector& majorAxis = (radius[0] >= radius[1]) ? plane.xaxis : plane.yaxis;
F1 = plane.origin + f*majorAxis;
F2 = plane.origin - f*majorAxis;
return true;
}
const ON_3dVector& ON_Ellipse::Normal() const
{
return plane.zaxis;
}
const ON_Plane& ON_Ellipse::Plane() const
{
return plane;
}
ON_3dPoint ON_Ellipse::PointAt( double t ) const
{
return plane.PointAt( cos(t)*radius[0], sin(t)*radius[1] );
}
ON_3dVector ON_Ellipse::DerivativeAt(
int d, // desired derivative ( >= 0 )
double t // parameter
) const
{
double r0 = radius[0];
double r1 = radius[1];
switch (abs(d)%4) {
case 0:
r0 *= cos(t);
r1 *= sin(t);
break;
case 1:
r0 *= -sin(t);
r1 *= cos(t);
break;
case 2:
r0 *= -cos(t);
r1 *= -sin(t);
break;
case 3:
r0 *= sin(t);
r1 *= -cos(t);
break;
}
return ( r0*plane.xaxis + r1*plane.yaxis );
}
ON_3dVector ON_Ellipse::TangentAt(
double t // parameter
) const
{
ON_3dVector T = DerivativeAt( 1, t );
T.Unitize();
return T;
}
ON_3dVector ON_Ellipse::CurvatureAt(
double t // parameter
) const
{
ON_3dVector T, K;
ON_EvCurvature(DerivativeAt( 1, t ),DerivativeAt( 2, t ),T,K);
return K;
}
static int distSqToEllipse(void* p, double t, double* f, double* df )
{
// used in call to TL_NRdbrent().
double dx, dy, st, ct;
const double* a = (const double*)p;
// a[0], a[1] = x/y radii of 2d ellipse
// (a[2],a[3]) = 2d point
// f(t) = distance squared from ellipse(t) to 2d point
ct = cos(t);
st = sin(t);
dx = ct*a[0] - a[2];
dy = st*a[1] - a[3];
if ( f ) {
*f = dx*dx + dy*dy;
}
if ( df ) {
*df = 2.0*(dy*a[1]*ct - dx*a[0]*st);
}
return 0;
}
#if defined(ON_COMPILER_MSC)
// Disable the MSC /W4 warning
// C4127: conditional expression is constant
// on the line
// for(...; true; ... )
//
// This source code is used on many compilers and
// I do not trust all of them to get for(..;;...)
// right.
#pragma warning( push )
#pragma warning( disable : 4127 )
#endif
ON_BOOL32 ON_Ellipse::ClosestPointTo( const ON_3dPoint& point, double* t ) const
{
ON_BOOL32 rc = true;
if ( t ) {
ON_2dPoint uv;
rc = plane.ClosestPointTo( point, &uv.x, &uv.y );
if ( uv.x == 0.0 ) {
if ( uv.y == 0.0 ) {
*t = (radius[0] <= radius[1]) ? 0.0 : 0.5*ON_PI;
return true;
}
if ( uv.y >= radius[1] ) {
*t = 0.5*ON_PI;
return true;
}
if ( uv.y <= -radius[1] ) {
*t = 1.5*ON_PI;
return true;
}
}
else if ( uv.y == 0.0 ) {
if ( uv.x >= radius[0] ) {
*t = 0.0;
return true;
}
if ( uv.x <= -radius[0] ) {
*t = ON_PI;
return true;
}
}
{
// use circluar approximation to get a seed value
double t0, t1;
*t = atan2( uv.y, uv.x );
if ( *t < 0.0 )
{
*t += 2.0*ON_PI;
if ( 2.0*ON_PI <= *t)
{
// == happens when atan2() <= 0.5*ON_EPSILON*2.0*PI
*t = 0.0;
}
}
if ( radius[0] != radius[1] ) {
// set limits for search
if ( uv.x >= 0.0 ) {
if ( uv.y >= 0.0 ) {
// search quadrant I
t0 = 0.0;
t1 = 0.5*ON_PI;
}
else {
// search quadrant IV
t0 = 1.5*ON_PI;
t1 = 2.0*ON_PI;
}
}
else {
if ( uv.y >= 0.0 ) {
// search quadrant II
t0 = 0.5*ON_PI;
t1 = ON_PI;
}
else {
// search quadrant III
t0 = ON_PI;
t1 = 1.5*ON_PI;
}
}
// solve for closest point using Brent's algorithm
{
// 6 October 2003 Dale Lear:
// Fixed several serious bugs here.
// get seed value appropriate for Brent
double p[4], et, d0, d1, dt;
int i;
p[0] = radius[0];
p[1] = radius[1];
p[2] = uv.x;
p[3] = uv.y;
et = *t;
if ( et <= t0 )
et = 0.9*t0 + 0.1*t1;
else if ( et >= t1 )
et = 0.9*t1 + 0.1*t0;
distSqToEllipse( p, t0, &d0, NULL );
distSqToEllipse( p, t1, &d1, NULL );
if ( d0 == 0.0 ) {
*t = (t0 == 2.0*ON_PI) ? 0.0 : t0;
return true;
}
if ( d1 == 0.0 ) {
*t = (t1 == 2.0*ON_PI) ? 0.0 : t1;
return true;
}
if ( d0 > d1 ) {
dt = t0; t0 = t1; t1 = dt;
dt = d0; d0 = d1; d1 = dt;
}
*t = (t0 == 2.0*ON_PI) ? 0.0 : t0;
for ( i = 0; true; i++ ) {
distSqToEllipse( p, et, &dt, NULL );
if ( dt < d0 )
{
*t = (et >= 2.0*ON_PI) ? 0.0 : et;
break;
}
if ( i >= 100 )
{
ON_3dPoint E0 = PointAt(t0);
if ( sqrt(d0) <= ON_ZERO_TOLERANCE
|| sqrt(d0) <= ON_SQRT_EPSILON*E0.DistanceTo(Center())
)
{
// Could not find a seed value for dbrent,
// but t0 is pretty close.
return true;
}
ON_3dVector T = TangentAt(t0);
ON_3dVector V = E0 - point;
if ( V.Unitize() )
{
// Could not find a seed value for dbrent,
// but V and T are orthoganal, so t0 is
// pretty close.
if ( fabs(V*T) <= 0.087155742747658173558064270837474 )
return true;
}
return false; // can't get valid seed - bail out
}
et = (i) ? (0.5*(t0+et)) : 0.5*(t0+t1);
if ( et == t0 )
{
return true;
}
}
rc = ON_FindLocalMinimum( distSqToEllipse, p,
t0, et, t1,
ON_EPSILON, ON_SQRT_EPSILON, 100,
&et );
rc = (rc > 0) ? true : false;
if ( rc )
*t = (et >= 2.0*ON_PI) ? 0.0 : et;
}
}
}
}
return rc;
}
#if defined(ON_COMPILER_MSC)
#pragma warning( pop )
#endif
ON_3dPoint ON_Ellipse::ClosestPointTo( const ON_3dPoint& point ) const
{
double t;
ClosestPointTo( point, &t );
return PointAt( t );
}
double ON_Ellipse::EquationAt(
const ON_2dPoint& p // coordinates in plane
) const
{
double e, x, y;
if ( radius[0] != 0.0 && radius[1] != 0.0 ) {
x = p.x/radius[0];
y = p.y/radius[1];
e = x*x + y*y - 1.0;
}
else {
e = 0.0;
}
return e;
}
ON_2dVector ON_Ellipse::GradientAt(
const ON_2dPoint& p // coordinates in plane
) const
{
ON_2dVector g;
if ( radius[0] != 0.0 && radius[1] != 0.0 ) {
g.x = 2.0*p.x/(radius[0]*radius[0]);
g.y = 2.0*p.y/(radius[1]*radius[1]);
}
else {
g.Zero();
}
return g;
}
ON_BOOL32 ON_Ellipse::Rotate(
double sin_angle, double cos_angle,
const ON_3dVector& axis
)
{
return plane.Rotate( sin_angle, cos_angle, axis );
}
ON_BOOL32 ON_Ellipse::Rotate(
double angle,
const ON_3dVector& axis
)
{
return plane.Rotate( angle, axis );
}
ON_BOOL32 ON_Ellipse::Rotate(
double sin_angle, double cos_angle,
const ON_3dVector& axis,
const ON_3dPoint& point
)
{
return plane.Rotate( sin_angle, cos_angle, axis, point );
}
ON_BOOL32 ON_Ellipse::Rotate(
double angle,
const ON_3dVector& axis,
const ON_3dPoint& point
)
{
return plane.Rotate( angle, axis, point );
}
ON_BOOL32 ON_Ellipse::Translate(
const ON_3dVector& delta
)
{
return plane.Translate( delta );
}
ON_BOOL32 ON_Ellipse::GetNurbForm( ON_NurbsCurve& nurbscurve ) const
{
int rc = 0;
if ( IsValid() ) {
nurbscurve.Create( 3, true, 3, 9 );
nurbscurve.m_knot[0] = nurbscurve.m_knot[1] = 0.0;
nurbscurve.m_knot[2] = nurbscurve.m_knot[3] = 0.5*ON_PI;
nurbscurve.m_knot[4] = nurbscurve.m_knot[5] = ON_PI;
nurbscurve.m_knot[6] = nurbscurve.m_knot[7] = 1.5*ON_PI;
nurbscurve.m_knot[8] = nurbscurve.m_knot[9] = 2.0*ON_PI;
ON_4dPoint* CV = (ON_4dPoint*)nurbscurve.m_cv;
CV[0] = plane.PointAt( radius[0], 0.0);
CV[1] = plane.PointAt( radius[0], radius[1]);
CV[2] = plane.PointAt( 0.0, radius[1]);
CV[3] = plane.PointAt(-radius[0], radius[1]);
CV[4] = plane.PointAt(-radius[0], 0.0);
CV[5] = plane.PointAt(-radius[0], -radius[1]);
CV[6] = plane.PointAt( 0.0, -radius[1]);
CV[7] = plane.PointAt( radius[0], -radius[1]);
CV[8] = CV[0];
const double w = 1.0/sqrt(2.0);
int i;
for ( i = 1; i < 8; i += 2 ) {
CV[i].x *= w;
CV[i].y *= w;
CV[i].z *= w;
CV[i].w = w;
}
rc = 2;
}
return rc;
}

135
extern/opennurbs/opennurbs_ellipse.h vendored Executable file
View File

@@ -0,0 +1,135 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_ELLIPSE_INC_)
#define OPENNURBS_ELLIPSE_INC_
class ON_Ellipse;
class ON_Plane;
class ON_CLASS ON_Ellipse
{
public:
ON_Ellipse(); // zeros all fields - plane is invalid
ON_Ellipse(
const ON_Plane&,
double, double // radii for x and y vectors
);
ON_Ellipse(
const ON_Circle&
);
~ON_Ellipse();
ON_Ellipse& operator=(const ON_Circle&);
ON_BOOL32 Create(
const ON_Plane&, // point on the plane
double, double // radii for x and y vectors
);
ON_BOOL32 Create(
const ON_Circle&
);
ON_BOOL32 IsValid() const; // returns true if all fields contain reasonable
// information and equation jibes with point and Z.
ON_BOOL32 IsCircle() const; // returns true is ellipse is a circle
double Radius(
int // 0 = x axis radius, 1 = y axis radius
) const;
const ON_3dPoint& Center() const;
const ON_3dVector& Normal() const;
const ON_Plane& Plane() const; // plane containing ellipse
/*
Returns:
Distance from the center to a focus, commonly called "c".
*/
double FocalDistance() const;
bool GetFoci( ON_3dPoint& F1, ON_3dPoint& F2 ) const;
// Evaluation uses the trigonometrix parameterization
// t -> plane.origin + cos(t)*radius[0]*plane.xaxis + sin(t)*radius[1]*plane.yaxis
// evaluate parameters and return point
ON_3dPoint PointAt( double ) const;
ON_3dVector DerivativeAt(
int, // desired derivative ( >= 0 )
double // parameter
) const;
ON_3dVector TangentAt( double ) const; // returns unit tangent
ON_3dVector CurvatureAt( double ) const; // returns curvature vector
// returns parameters of point on ellipse that is closest to given point
ON_BOOL32 ClosestPointTo(
const ON_3dPoint&,
double*
) const;
// returns point on ellipse that is closest to given point
ON_3dPoint ClosestPointTo(
const ON_3dPoint&
) const;
// evaluate ellipse's implicit equation in plane
double EquationAt( const ON_2dPoint& ) const;
ON_2dVector GradientAt( const ON_2dPoint& ) const;
// rotate ellipse about its center
ON_BOOL32 Rotate(
double, // sin(angle)
double, // cos(angle)
const ON_3dVector& // axis of rotation
);
ON_BOOL32 Rotate(
double, // angle in radians
const ON_3dVector& // axis of rotation
);
// rotate ellipse about a point and axis
ON_BOOL32 Rotate(
double, // sin(angle)
double, // cos(angle)
const ON_3dVector&, // axis of rotation
const ON_3dPoint& // center of rotation
);
ON_BOOL32 Rotate(
double, // angle in radians
const ON_3dVector&, // axis of rotation
const ON_3dPoint& // center of rotation
);
ON_BOOL32 Translate(
const ON_3dVector&
);
// parameterization of NURBS curve does not match ellipse's transcendental paramaterization
int GetNurbForm( ON_NurbsCurve& ) const; // returns 0=failure, 2=success
public: // members left public
// The center of the ellipse is at the plane's origin. The axes of the
// ellipse are the plane's x and y axes. The equation of the ellipse
// with respect to the plane is (x/m_r[0])^2 + (y/m_r[1])^2 = 1;
ON_Plane plane;
double radius[2]; // radii for x and y axes (both must be > 0)
};
#endif

1859
extern/opennurbs/opennurbs_embedded_file.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

335
extern/opennurbs/opennurbs_error.cpp vendored Executable file
View File

@@ -0,0 +1,335 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
// openNURBS Geometry Library Errors and Warnings
//
// If an error condition occurs during a openNURBS Geometry Library
// computation, the ON_Error() function is called, the computation is
// stopped, and an error code (negative integer ) is returned. If a
// warning condition occurs during a Trout Lake Geometry Library
// computation, the ON_Warning() function is called and the computation
// continues.
//
// ON_GetErrorCount()
// ON_GetWarningCount()
// ON_Error()
// ON_Warning()
//
static int ON_ERROR_COUNT = 0;
static int ON_WARNING_COUNT = 0;
static int ON_MATH_ERROR_COUNT = 0;
static int ON_DEBUG_ERROR_MESSAGE_OPTION = 0;
int ON_GetErrorCount(void)
{
return ON_ERROR_COUNT;
}
int ON_GetWarningCount(void)
{
return ON_WARNING_COUNT;
}
int ON_GetMathErrorCount(void)
{
return ON_MATH_ERROR_COUNT;
}
int ON_GetDebugErrorMessage(void)
{
return ON_DEBUG_ERROR_MESSAGE_OPTION?true:false;
}
void ON_EnableDebugErrorMessage( int bEnableDebugErrorMessage )
{
ON_DEBUG_ERROR_MESSAGE_OPTION = bEnableDebugErrorMessage ? 1 : 0;
}
// The sMessage[] string is used by ON_Error() and ON_Warning()
// to hold the message. The static function ON_FormatMessage()
// is used to do most of the actual formatting.
#define MAX_MSG_LENGTH 2048
static char sMessage[MAX_MSG_LENGTH];
static bool ON_FormatMessage(const char*, va_list );
void ON_MathError(
const char* sModuleName,
const char* sErrorType,
const char* sFunctionName
)
{
ON_MATH_ERROR_COUNT++; // <- Good location for a debugger breakpoint.
if ( !sModuleName)
sModuleName = "";
if ( !sErrorType )
sErrorType = "";
if ( !sFunctionName )
sFunctionName = "";
ON_Error(__FILE__,__LINE__,
"Math library or floating point ERROR # %d module=%s type=%s function=%s",
ON_MATH_ERROR_COUNT,
sModuleName, // rhino.exe, opennurbs.dll, etc.
sErrorType,
sFunctionName
);
}
static void ON_IncrementErrorCount()
{
ON_ERROR_COUNT++;
}
static void ON_IncrementWarningCount()
{
ON_WARNING_COUNT++;
}
bool ON_IsNotValid()
{
return false;
}
static bool ON_PrintErrorHeader(
int type, // 0 = warning, 1 = error, 2 = assert
const char* sFileName,
int line_number,
const char* sFunctionName
)
{
bool bPrintMessage = false;
sMessage[0] = 0;
#if defined(ON_COMPILER_MSC)
// use sprintf_s() ...
size_t sz = (sizeof(sMessage)/sizeof(sMessage[0])) - 1;
#define ON_SPRINTF4(s,count,fname,ln,func) sprintf_s(sMessage,sz,s,count,fname,ln,func)
#define ON_SPRINTF3(s,count,fname,ln) sprintf_s(sMessage,sz,s,count,fname,ln)
#define ON_SPRINTF1(s,count) sprintf_s(sMessage,sz,s,count)
#else
// use sprintf() ...
#define ON_SPRINTF4(s,count,fname,ln,func) sprintf(sMessage,s,count,fname,ln,func)
#define ON_SPRINTF3(s,count,fname,ln) sprintf(sMessage,s,count,fname,ln)
#define ON_SPRINTF1(s,count) sprintf(sMessage,s,count)
#endif
if ( ON_DEBUG_ERROR_MESSAGE_OPTION )
{
if ( 0 == type )
{
if ( ON_WARNING_COUNT < 50 )
{
if (0 == sFileName )
sFileName = "";
if ( sFunctionName && sFunctionName[0] )
ON_SPRINTF4("openNURBS WARNING # %d %s.%d %s(): ",ON_WARNING_COUNT,sFileName,line_number,sFunctionName);
else
ON_SPRINTF3("openNURBS WARNING # %d %s.%d ",ON_WARNING_COUNT,sFileName,line_number);
bPrintMessage = true;
}
else if ( 50 == ON_ERROR_COUNT )
{
ON_SPRINTF1("openNURBS WARNING # %d - Too many warnings. No more printed messages.",ON_WARNING_COUNT);
bPrintMessage = true;
}
}
else if ( 1 == type || 2 == type )
{
if ( ON_ERROR_COUNT < 50 )
{
if (0 == sFileName )
sFileName = "";
if ( sFunctionName && sFunctionName[0] )
ON_SPRINTF4("openNURBS ERROR # %d %s.%d %s(): ",ON_ERROR_COUNT,sFileName,line_number,sFunctionName);
else
ON_SPRINTF3("openNURBS ERROR # %d %s.%d ",ON_ERROR_COUNT,sFileName,line_number);
bPrintMessage = true;
}
else if ( 50 == ON_ERROR_COUNT )
{
ON_SPRINTF1("openNURBS ERROR # %d - Too many errors. No more printed messages.",ON_ERROR_COUNT);
bPrintMessage = true;
}
}
}
#undef ON_SPRINTF4
#undef ON_SPRINTF3
#undef ON_SPRINTF1
return bPrintMessage;
}
void ON_Error(const char* sFileName, int line_number,
const char* sFormat, ...)
{
ON_IncrementErrorCount();
bool bPrintMessage = ON_PrintErrorHeader(1,sFileName,line_number,0);
if ( bPrintMessage )
{
if (sFormat && sFormat[0])
{
// append formatted error message to sMessage[]
va_list args;
va_start(args, sFormat);
bPrintMessage = ON_FormatMessage(sFormat,args);
va_end(args);
}
if ( bPrintMessage )
ON_ErrorMessage(1,sMessage);
}
}
void ON_ErrorEx(const char* sFileName, int line_number, const char* sFunctionName,
const char* sFormat, ...)
{
ON_IncrementErrorCount();
bool bPrintMessage = ON_PrintErrorHeader(1,sFileName,line_number,sFunctionName);
if ( bPrintMessage )
{
if (sFormat && sFormat[0])
{
// append formatted error message to sMessage[]
va_list args;
va_start(args, sFormat);
bPrintMessage = ON_FormatMessage(sFormat,args);
va_end(args);
}
if ( bPrintMessage )
ON_ErrorMessage(1,sMessage);
}
}
void ON_Warning(const char* sFileName, int line_number,
const char* sFormat, ...)
{
ON_IncrementWarningCount();
bool bPrintMessage = ON_PrintErrorHeader(0,sFileName,line_number,0);
if ( bPrintMessage )
{
if (sFormat && sFormat[0])
{
// append formatted error message to sMessage[]
va_list args;
va_start(args, sFormat);
bPrintMessage = ON_FormatMessage(sFormat,args);
va_end(args);
}
if ( bPrintMessage )
ON_ErrorMessage(0,sMessage);
}
}
void ON_WarningEx(const char* sFileName, int line_number, const char* sFunctionName,
const char* sFormat, ...)
{
ON_IncrementWarningCount();
bool bPrintMessage = ON_PrintErrorHeader(0,sFileName,line_number,sFunctionName);
if ( bPrintMessage )
{
if (sFormat && sFormat[0])
{
// append formatted error message to sMessage[]
va_list args;
va_start(args, sFormat);
bPrintMessage = ON_FormatMessage(sFormat,args);
va_end(args);
}
if ( bPrintMessage )
ON_ErrorMessage(0,sMessage);
}
}
void ON_Assert(int bCondition,
const char* sFileName, int line_number,
const char* sFormat, ...)
{
if ( !bCondition )
{
ON_IncrementErrorCount();
bool bPrintMessage = ON_PrintErrorHeader(2,sFileName,line_number,0);
if ( bPrintMessage )
{
if (sFormat && sFormat[0])
{
// append formatted error message to sMessage[]
va_list args;
va_start(args, sFormat);
bPrintMessage = ON_FormatMessage(sFormat,args);
va_end(args);
}
if ( bPrintMessage )
ON_ErrorMessage(2,sMessage);
}
}
}
void ON_AssertEx(int bCondition,
const char* sFileName, int line_number, const char* sFunctionName,
const char* sFormat, ...)
{
if ( !bCondition )
{
ON_IncrementErrorCount();
bool bPrintMessage = ON_PrintErrorHeader(2,sFileName,line_number,sFunctionName);
if ( bPrintMessage )
{
if (sFormat && sFormat[0])
{
// append formatted error message to sMessage[]
va_list args;
va_start(args, sFormat);
bPrintMessage = ON_FormatMessage(sFormat,args);
va_end(args);
}
if ( bPrintMessage )
ON_ErrorMessage(2,sMessage);
}
}
}
static bool ON_FormatMessage(const char* format, va_list args)
{
// appends formatted message to sMessage[]
int len = ((int)strlen(sMessage));
if (len < 0 )
return false;
if (MAX_MSG_LENGTH-1-len < 2)
return false;
sMessage[MAX_MSG_LENGTH-1] = 0;
on_vsnprintf(sMessage+len, MAX_MSG_LENGTH-1-len, format, args);
return true;
}

137
extern/opennurbs/opennurbs_error.h vendored Executable file
View File

@@ -0,0 +1,137 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_ERROR_INC_)
#define OPENNURBS_ERROR_INC_
/*
// Macros used to log errors and warnings. The ON_Warning() and ON_Error()
// functions are defined in opennurbs_error.cpp.
*/
#if defined(__FUNCTION__)
// __FUNCTION__ macro exists
#define ON_ERROR(msg) ON_ErrorEx(__FILE__,__LINE__,__FUNCTION__,msg)
#define ON_WARNING(msg) ON_WarningEx(__FILE__,__LINE__,__FUNCTION__,msg)
#define ON_ASSERT(cond) ON_AssertEx(cond,__FILE__,__LINE__,__FUNCTION__, #cond " is false")
#define ON_ASSERT_OR_RETURN(cond,returncode) do{if (!(cond)) {ON_AssertEx(false,__FILE__,__LINE__,__FUNCTION__, #cond " is false");return(returncode);}}while(0)
#else
// __FUNCTION__ macro does not exist
#define ON_ERROR(msg) ON_Error(__FILE__,__LINE__,msg)
#define ON_WARNING(msg) ON_Warning(__FILE__,__LINE__,msg)
#define ON_ASSERT(cond) ON_Assert(cond,__FILE__,__LINE__, #cond " is false")
#define ON_ASSERT_OR_RETURN(cond,returncode) do{if (!(cond)) {ON_Assert(false,__FILE__,__LINE__, #cond " is false");return(returncode);}}while(0)
#endif
ON_BEGIN_EXTERNC
/*
// All error/warning messages are sent to ON_ErrorMessage(). Replace the
// default handler (defined in opennurbs_error_message.cpp) with something
// that is appropriate for debugging your application.
*/
ON_DECL
void ON_ErrorMessage(
int, /* 0 = warning message, 1 = serious error message, 2 = assert failure */
const char*
);
/*
Returns:
Number of opennurbs errors since program started.
*/
ON_DECL
int ON_GetErrorCount(void);
/*
Returns:
Number of opennurbs warnings since program started.
*/
ON_DECL
int ON_GetWarningCount(void);
/*
Returns:
Number of math library or floating point errors that have
been handled since program started.
*/
ON_DECL
int ON_GetMathErrorCount(void);
ON_DECL
int ON_GetDebugErrorMessage(void);
ON_DECL
void ON_EnableDebugErrorMessage( int bEnableDebugErrorMessage );
ON_DECL
void ON_Error( const char*, /* sFileName: __FILE__ will do fine */
int, /* line number: __LINE__ will do fine */
const char*, /* printf() style format string */
... /* printf() style ags */
);
ON_DECL
void ON_ErrorEx( const char*, // sFileName: __FILE__ will do fine
int, // line number: __LINE__ will do fine
const char*, // sFunctionName: __FUNCTION__ will do fine
const char*, // printf() style format string
... // printf() style ags
);
ON_DECL
void ON_Warning( const char*, /* sFileName: __FILE__ will do fine */
int, /* line number: __LINE__ will do fine */
const char*, /* printf() style format string */
... /* printf() style ags */
);
ON_DECL
void ON_WarningEx( const char*, // sFileName: __FILE__ will do fine
int, // line number: __LINE__ will do fine
const char*, // sFunctionName: __FUNCTION__ will do fine
const char*, // printf() style format string
... // printf() style ags
);
// Ideally - these "assert" functions will be deleted when the SDK can be changed.
ON_DECL
void ON_Assert( int, /* if false, error is flagged */
const char*, /* sFileName: __FILE__ will do fine */
int, /* line number: __LINE__ will do fine */
const char*, /* printf() style format string */
... /* printf() style ags */
);
ON_DECL
void ON_AssertEx( int, // if false, error is flagged
const char*, // sFileName: __FILE__ will do fine
int, // line number: __LINE__ will do fine
const char*, // sFunctionName: __FUNCTION__ will do fine
const char*, // printf() style format string
... // printf() style ags
);
ON_DECL
void ON_MathError(
const char*, /* sModuleName */
const char*, /* sErrorType */
const char* /* sFunctionName */
);
ON_END_EXTERNC
#endif

51
extern/opennurbs/opennurbs_error_message.cpp vendored Executable file
View File

@@ -0,0 +1,51 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
void ON_ErrorMessage(
int message_type, // 0=warning - serious problem that code is designed to handle
// 1=error - serious problem code will attempt to handle
// The thing causing the error is a bug that must
// be fixed.
// 2=assert failed - crash is nearly certain
const char* sErrorMessage
)
{
// error/warning/assert message is in sMessage[] buffer. Modify this function
// to do whatever you want to with the message.
if ( sErrorMessage && sErrorMessage[0] )
{
#if defined(ON_PURIFY_BUILD) && defined(ON_32BIT_POINTER)
// 10 December 2003 Dale Lear
// Make ON_ERROR/ON_WARNING messages show up in Purify
PurifyPrintf("%s",sErrorMessage);
#endif
#if defined(ON_OS_WINDOWS)
::OutputDebugStringA( "\n" );
::OutputDebugStringA( sErrorMessage );
::OutputDebugStringA( "\n" );
#else
#if defined(ON__DEBUG)
// not using OutputDebugStringA
printf("\n%s\n",sErrorMessage);
#endif
#endif
}
}

1695
extern/opennurbs/opennurbs_evaluate_nurbs.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

381
extern/opennurbs/opennurbs_evaluate_nurbs.h vendored Executable file
View File

@@ -0,0 +1,381 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(ON_EVALUATE_NURBS_INC_)
#define ON_EVALUATE_NURBS_INC_
ON_DECL
bool ON_IncreaseBezierDegree(
int, // dimension
ON_BOOL32, // true if Bezier is rational
int, // order (>=2)
int, // cv_stride (>=dim+1)
double* // cv[(order+1)*cv_stride] array
);
ON_DECL
bool ON_RemoveBezierSingAt0( // input bezier is rational with 0/0 at start
int, // dimension
int, // order (>=2)
int, // cv_stride (>=dim+1)
double* // cv[order*cv_stride] array
);
ON_DECL
bool ON_RemoveBezierSingAt1( // input bezier is rational with 0/0 at end
int, // dimension
int, // order (>=2)
int, // cv_stride (>=dim+1)
double* // cv[order*cv_stride] array
);
ON_DECL
double ON_EvaluateBernsteinBasis( // returns (i choose d)*(1-t)^(d-i)*t^i
int, // degree,
int, // 0 <= i <= degree
double // t
);
ON_DECL
void ON_EvaluatedeCasteljau(
int, // dim
int, // order
int, // side <= 0 return left side of bezier in cv array
// > 0 return right side of bezier in cv array
int, // cv_stride
double*, // cv
double // t 0 <= t <= 1
);
ON_DECL
bool ON_EvaluateBezier(
int, // dimension
ON_BOOL32, // true if Bezier is rational
int, // order (>=2)
int, // cv_stride >= (is_rat)?dim+1:dim
const double*, // cv[order*cv_stride] array
double, double, // t0,t1 = domain of bezier
int, // number of derivatives to compute (>=0)
double, // evaluation parameter
int, // v_stride (>=dimension)
double* // v[(der_count+1)*v_stride] array
);
ON_DECL
bool ON_EvaluateNurbsBasis(
int, // order (>=1)
const double*, // knot[] array of 2*(order-1) knots
double, // evaluation parameter
double* // basis_values[] array of length order*order
);
ON_DECL
bool ON_EvaluateNurbsBasisDerivatives(
int, // order (>=1)
const double*, // knot[] array of 2*(order-1) knots
int, // number of derivatives
double* // basis_values[] array of length order*order
);
/*
int dim, // dimension
ON_BOOL32 is_rat, // true if NURBS is rational
int order, // order
const double* knot, // knot[] array of (2*order-2) doubles
int cv_stride, // cv_stride >= (is_rat)?dim+1:dim
const double* cv, // cv[order*cv_stride] array
int der_count, // number of derivatives to compute
double t, // evaluation parameter
int v_stride, // v_stride (>=dimension)
double* v // v[(der_count+1)*v_stride] array
)
int, // dimension
ON_BOOL32, // true if NURBS is rational
int, // order
const double*, // knot[] array of (2*order-2) doubles
int, // cv_stride
const double*, // cv[] array of order*cv_stride doubles
int, // number of derivatives to compute (>=0)
double, // evaluation parameter
int, // answer_stride (>=dimension)
double* // answer[] array of length (ndir+1)*answer_stride
*/
ON_DECL
/*
Description:
Evaluate a NURBS curve span.
Parameters:
dim - [in]
dimension (> 0).
is_rat - [in]
true or false.
order - [in]
order=degree+1 (order>=2)
knot - [in] NURBS knot vector.
NURBS knot vector with 2*(order-1) knots, knot[order-2] != knot[order-1]
cv_stride - [in]
cv - [in]
For 0 <= i < order the i-th control vertex is
cv[n],...,cv[n+(is_rat?dim:dim+1)],
where n = i*cv_stride. If is_rat is true the cv is
in homogeneous form.
der_count - [in]
number of derivatives to evaluate (>=0)
t - [in]
evaluation parameter
v_stride - [in]
v - [out]
An array of length v_stride*(der_count+1). The evaluation
results are returned in this array.
P = v[0],...,v[m_dim-1]
Dt = v[v_stride],...
Dtt = v[2*v_stride],...
...
In general, Dt^i returned in v[n],...,v[n+m_dim-1], where
n = v_stride*i.
Returns:
True if successful.
See Also:
ON_NurbsCurve::Evaluate
ON_EvaluateNurbsSurfaceSpan
ON_EvaluateNurbsCageSpan
*/
bool ON_EvaluateNurbsSpan(
int dim,
int is_rat,
int order,
const double* knot,
int cv_stride,
const double* cv,
int der_count,
double t,
int v_stride,
double* v
);
/*
Description:
Evaluate a NURBS surface bispan.
Parameters:
dim - [in] >0
is_rat - [in] true of false
order0 - [in] >= 2
order1 - [in] >= 2
knot0 - [in]
NURBS knot vector with 2*(order0-1) knots, knot0[order0-2] != knot0[order0-1]
knot1 - [in]
NURBS knot vector with 2*(order1-1) knots, knot1[order1-2] != knot1[order1-1]
cv_stride0 - [in]
cv_stride1 - [in]
cv - [in]
For 0 <= i < order0 and 0 <= j < order1, the (i,j) control vertex is
cv[n],...,cv[n+(is_rat?dim:dim+1)],
where n = i*cv_stride0 + j*cv_stride1. If is_rat is true the cv is
in homogeneous form.
der_count - [in] (>=0)
s - [in]
t - [in] (s,t) is the evaluation parameter
v_stride - [in] (>=dim)
v - [out] An array of length v_stride*(der_count+1)*(der_count+2)/2.
The evaluation results are stored in this array.
P = v[0],...,v[m_dim-1]
Ds = v[v_stride],...
Dt = v[2*v_stride],...
Dss = v[3*v_stride],...
Dst = v[4*v_stride],...
Dtt = v[5*v_stride],...
In general, Ds^i Dt^j is returned in v[n],...,v[n+m_dim-1], where
n = v_stride*( (i+j)*(i+j+1)/2 + j).
Returns:
True if succcessful.
See Also:
ON_NurbsSurface::Evaluate
ON_EvaluateNurbsSpan
ON_EvaluateNurbsCageSpan
*/
ON_DECL
bool ON_EvaluateNurbsSurfaceSpan(
int dim,
int is_rat,
int order0,
int order1,
const double* knot0,
const double* knot1,
int cv_stride0,
int cv_stride1,
const double* cv,
int der_count,
double s,
double t,
int v_stride,
double* v
);
/*
Description:
Evaluate a NURBS cage trispan.
Parameters:
dim - [in] >0
is_rat - [in] true of false
order0 - [in] >= 2
order1 - [in] >= 2
order2 - [in] >= 2
knot0 - [in]
NURBS knot vector with 2*(order0-1) knots, knot0[order0-2] != knot0[order0-1]
knot1 - [in]
NURBS knot vector with 2*(order1-1) knots, knot1[order1-2] != knot1[order1-1]
knot2 - [in]
NURBS knot vector with 2*(order1-1) knots, knot2[order2-2] != knot2[order2-1]
cv_stride0 - [in]
cv_stride1 - [in]
cv_stride2 - [in]
cv - [in]
For 0 <= i < order0, 0 <= j < order1, and 0 <= k < order2,
the (i,j,k)-th control vertex is
cv[n],...,cv[n+(is_rat?dim:dim+1)],
where n = i*cv_stride0 + j*cv_stride1 *k*cv_stride2.
If is_rat is true the cv is in homogeneous form.
der_count - [in] (>=0)
r - [in]
s - [in]
t - [in] (r,s,t) is the evaluation parameter
v_stride - [in] (>=dim)
v - [out] An array of length v_stride*(der_count+1)*(der_count+2)*(der_count+3)/6.
The evaluation results are stored in this array.
P = v[0],...,v[m_dim-1]
Dr = v[v_stride],...
Ds = v[2*v_stride],...
Dt = v[3*v_stride],...
Drr = v[4*v_stride],...
Drs = v[5*v_stride],...
Drt = v[6*v_stride],...
Dss = v[7*v_stride],...
Dst = v[8*v_stride],...
Dtt = v[9*v_stride],...
In general, Dr^i Ds^j Dt^k is returned in v[n],...,v[n+dim-1], where
d = (i+j+k)
n = v_stride*( d*(d+1)*(d+2)/6 + (j+k)*(j+k+1)/2 + k)
Returns:
True if succcessful.
See Also:
ON_NurbsCage::Evaluate
ON_EvaluateNurbsSpan
ON_EvaluateNurbsSurfaceSpan
*/
ON_DECL
bool ON_EvaluateNurbsCageSpan(
int dim,
int is_rat,
int order0, int order1, int order2,
const double* knot0,
const double* knot1,
const double* knot2,
int cv_stride0, int cv_stride1, int cv_stride2,
const double* cv,
int der_count,
double t0, double t1, double t2,
int v_stride,
double* v
);
ON_DECL
bool ON_EvaluateNurbsDeBoor( // for expert users only - no support available
int, // cv_dim ( dim+1 for rational cvs )
int, // order (>=2)
int, // cv_stride (>=cv_dim)
double*, // cv array - values changed to result of applying De Boor's algorithm
const double*, // knot array
int, // side,
// -1 return left side of B-spline span in cv array
// +1 return right side of B-spline span in cv array
// -2 return left side of B-spline span in cv array
// Ignore values of knots[0,...,order-3] and assume
// left end of span has a fully multiple knot with
// value "mult_k".
// +2 return right side of B-spline span in cv array
// Ignore values of knots[order,...,2*order-2] and
// assume right end of span has a fully multiple
// knot with value "mult_k".
double, // mult_k - used when side is +2 or -2. See above for usage.
double // t
// If side < 0, then the cv's for the portion of the NURB span to
// the LEFT of t are computed. If side > 0, then the cv's for the
// portion the span to the RIGHT of t are computed. The following
// table summarizes the restrictions on t:
//
// value of side condition t must satisfy
// -2 mult_k < t and mult_k < knots[order-1]
// -1 knots[order-2] < t
// +1 t < knots[order-1]
// +2 t < mult_k and knots[order-2] < mult_k
);
ON_DECL
bool ON_EvaluateNurbsBlossom(int, // cvdim,
int, // order,
int, // cv_stride,
const double*, //CV, size cv_stride*order
const double*, //knot, nondecreasing, size 2*(order-1)
// knot[order-2] != knot[order-1]
const double*, //t, input parameters size order-1
double* // P
// DeBoor algorithm with different input at each step.
// returns false for bad input.
);
ON_DECL
void ON_ConvertNurbSpanToBezier(
int, // cvdim (dim+1 for rational curves)
int, // order,
int, // cvstride (>=cvdim)
double*, // cv array - input has NURBS cvs, output has Bezier cvs
const double*, // (2*order-2) knots for the NURBS span
double, // t0, NURBS span parameter of start point
double // t1, NURBS span parameter of end point
);
#endif

5454
extern/opennurbs/opennurbs_extensions.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

826
extern/opennurbs/opennurbs_extensions.h vendored Executable file
View File

@@ -0,0 +1,826 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_EXTENSIONS_INC_)
#define OPENNURBS_EXTENSIONS_INC_
/*
Description:
Used to store user data information in an ONX_Model.
*/
class ON_CLASS ONX_Model_UserData
{
public:
#if defined(ON_DLL_EXPORTS) || defined(ON_DLL_IMPORTS)
// See comments at the top of opennurbs_extensions.cpp for details.
// new/delete
void* operator new(size_t);
void operator delete(void*);
// array new/delete
void* operator new[] (size_t);
void operator delete[] (void*);
// in place new/delete
void* operator new(size_t,void*);
void operator delete(void*,void*);
#endif
ONX_Model_UserData();
~ONX_Model_UserData();
ONX_Model_UserData(const ONX_Model_UserData&);
ONX_Model_UserData& operator=(const ONX_Model_UserData&);
void Dump( ON_TextLog& ) const;
ON_UUID m_uuid;
ON_3dmGoo m_goo;
private:
void Destroy();
unsigned int* m_ref_count; // reference counts used to avoid expensive object copying
public:
int m_usertable_3dm_version ;
int m_usertable_opennurbs_version;
};
/*
Description:
Used to store geometry table object definition and attributes in an ONX_Model.
*/
class ON_CLASS ONX_Model_Object
{
public:
#if defined(ON_DLL_EXPORTS) || defined(ON_DLL_IMPORTS)
// See comments at the top of opennurbs_extensions.cpp for details.
// new/delete
void* operator new(size_t);
void operator delete(void*);
// array new/delete
void* operator new[] (size_t);
void operator delete[] (void*);
// in place new/delete
void* operator new(size_t,void*);
void operator delete(void*,void*);
#endif
ONX_Model_Object();
~ONX_Model_Object();
ONX_Model_Object(const ONX_Model_Object&);
ONX_Model_Object& operator=(const ONX_Model_Object&);
void Dump( ON_TextLog& ) const;
// If m_bDeleteObject is true, then m_object will be deleted when
// the last ONX_Model_Object that refers to it is destroyed. The
// default value of m_bDeleteObject is false.
bool m_bDeleteObject;
const ON_Object* m_object;
ON_3dmObjectAttributes m_attributes;
private:
void Destroy();
unsigned int* m_ref_count; // reference counts used to avoid expensive object copying
};
/*
Description:
Used to store render light table light definition and attributes in an ONX_Model.
*/
class ON_CLASS ONX_Model_RenderLight
{
public:
#if defined(ON_DLL_EXPORTS) || defined(ON_DLL_IMPORTS)
// See comments at the top of opennurbs_extensions.cpp for details.
// new/delete
void* operator new(size_t);
void operator delete(void*);
// array new/delete
void* operator new[] (size_t);
void operator delete[] (void*);
// in place new/delete
void* operator new(size_t,void*);
void operator delete(void*,void*);
#endif
ONX_Model_RenderLight();
~ONX_Model_RenderLight();
ONX_Model_RenderLight(const ONX_Model_RenderLight&);
ONX_Model_RenderLight& operator=(const ONX_Model_RenderLight&);
ON_Light m_light;
ON_3dmObjectAttributes m_attributes;
};
#if defined(ON_DLL_TEMPLATE)
// This stuff is here because of a limitation in the way Microsoft
// handles templates and DLLs. See Microsoft's knowledge base
// article ID Q168958 for details.
#pragma warning( push )
#pragma warning( disable : 4231 )
ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_Bitmap*>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_Linetype>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_Linetype>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_Layer>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_Layer>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_Group>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_Group>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_Font>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_Font>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_DimStyle>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_DimStyle>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ONX_Model_RenderLight>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_HatchPattern>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_HatchPattern>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_InstanceDefinition>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ObjectArray<ON_InstanceDefinition>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ONX_Model_Object>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ONX_Model_UserData>;
ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_HistoryRecord*>;
#pragma warning( pop )
#endif
/*
Description:
Pedegodgical example of all the things in an OpenNURBS 3dm archive.
The openNURBS examples use ONX_Model to store the information
read from 3dm archives. Please study example_read.cpp for
details.
*/
class ON_CLASS ONX_Model
{
public:
#if defined(ON_DLL_EXPORTS) || defined(ON_DLL_IMPORTS)
// See comments at the top of opennurbs_extensions.cpp for details.
// new/delete
void* operator new(size_t);
void operator delete(void*);
// array new/delete
void* operator new[] (size_t);
void operator delete[] (void*);
// in place new/delete
void* operator new(size_t,void*);
void operator delete(void*,void*);
#endif
ONX_Model();
virtual ~ONX_Model();
/*
Description:
Destroys contents of this model and leaves it ready to be reused.
*/
void Destroy();
/*
Description:
Reads an openNURBS archive and saves the information in this model
Parameters:
archive - [in] archive to read from
error_log - [out] any archive reading errors are logged here.
Returns:
true if archive is read with no error. False if errors occur.
Error details are logged in error_log. If crc errors are in
the archive, then m_crc_error_count is set to the number of
errors.
Example:
// for ASCII file names
const char* sFileName = ....;
FILE* fp = ON::OpenFile( sFileName, "rb");
// for UNICODE file names
const wchar_t* wsFileName = ....;
FILE* fp = ON::OpenFile( wsFileName, L"rb");
bool bModelRead = false;
bool bModelIsValid = false;
ON_TextLog error_log;
ONX_Model model;
if ( 0 != fp )
{
ON_BinaryFile archive( ON::read3dm, fp );
bModelRead = model.read( archive, error_log );
ON::CloseFile( fp );
}
if ( bModelRead )
{
bModelIsValid = model.Validate(error_log);
}
See Also:
ONX_Model::IsValid
ONX_Model::Write
ONX_Model::m_crc_error_count
*/
bool Read(
ON_BinaryArchive& archive,
ON_TextLog* error_log = NULL
);
bool Read(
const char* filename,
ON_TextLog* error_log = NULL
);
bool Read(
const wchar_t* filename,
ON_TextLog* error_log = NULL
);
/*
Description:
Writes contents of this model to an openNURBS archive.
It is a good practice to call Polish() before calling
Write so that your file has all the "fluff" that makes it
complete. If the model is not valid, then Write will refuse
to write it.
Parameters:
archive - [in]
archive to write to
version - [in]
Version of the openNURBS archive to write.
0 default value and suggested.
When 0 is passed in, the value of ON_BinaryArchive::CurrentArchiveVersion()
is used.
2, 3, 4
If you pass in one of these values, some information
in current data structures will not be saved in the
file.
Rhino 2.x can read version 2 files.
Rhino 3.x can read version 2 and 3 files.
Rhino 4.x can read version 2, 3 and 4 files.
Rhino 5.x can read version 2, 3, 4, 5 and 50 files.
Rhino 5.x writes version 50 files.
sStartSectionComment - [in]
Brief desciption of your app, today's date, etc.
error_log - [out]
any archive writing errors are logged here.
Returns:
True if archive is written with no error.
False if errors occur.
Error details are logged in error_log.
Example:
model = ...;
model.Polish(); // fill in defaults as needed.
ON_TextLog error_log;
if ( !model.IsValid( error_log ) )
{
// try to repair the model
model.Audit(true);
}
if ( model.IsValid( error_log ) )
{
// for ASCII file names
const char* sFileName = ....;
FILE* fp = ON::OpenFile( sFileName, "wb");
// for UNICODE file names
const wchar_t* wsFileName = ....;
FILE* fp = ON::OpenFile( wsFileName, L"wb");
bool ok = false;
if ( 0 != fp )
{
const char* sStartSectionComment = "...";
int version = 5; // 2, 3, 4 or 5 are valid
ON_BinaryFile archive( ON::write3dm, fp );
ok = model.write( archive,
version,
sStartSectionComment,
error_log );
ON::CloseFile( fp );
}
}
See Also:
ONX_Model::Polish
ONX_Model::IsValid
ONX_Model::Read
*/
bool Write(
ON_BinaryArchive& archive,
int version = 0,
const char* sStartSectionComment = NULL,
ON_TextLog* error_log = NULL
);
bool Write(
const char* filename,
int version = 0,
const char* sStartSectionComment = NULL,
ON_TextLog* error_log = NULL
);
bool Write(
const wchar_t* filename,
int version = 0,
const char* sStartSectionComment = NULL,
ON_TextLog* error_log = NULL
);
/*
Description:
Check a model to make sure it is valid.
Parameters:
text_log - [in] if not NULL and errors are found,
a description of the problem is put in
this text_log.
Returns:
True if the model is valid.
*/
bool IsValid( ON_TextLog* text_log = NULL ) const;
/*
Description:
Quickly fills in the little details, like making sure there is
at least one layer and table indices make sense.
For a full blown check and repair, call Audit(true).
See Also:
ONX_Model::Audit
*/
virtual
void Polish();
/*
Description:
Check a model to make sure it is valid and, if possible
and requrested, attempt to repair.
Parameters:
bAttemptRepair - [in] if true and a problem is found,
the problem is repaired.
repair_count - [out] number of successful repairs.
text_log - [in] if not NULL and errors are found,
a description of the problem is put in
this text_log.
warnings - [out]
If problems were found, warning ids are appended to this list.
@untitled table
1 m_material_table[] flaws
2 layer table is not perfect.
3 some m_object_table[].m_attributes.m_uuid was nil or not unique.
4 some m_object_table[].IsValid() is false
5 some m_idef_table[] has an invalid or duplicate name
6 warning some m_idef_table[].m_object_uuid[] is not valid
7 warning some m_object_table[].m_object is null
8 warning some m_object_table[].m_object->IsValid() is false
9 warning some m_object_table[].m_attributes is not valid
10 linetype table is not perfect.
11 lineset table is not perfect.
12 some m_idef_table[].m_uuid was nil or not unique.
13 some m_texture_mapping_table[i].m_mapping_id was nil or not unique.
14 some m_material_table[i].m_material_id was nil or not unique.
15 some m_light_table[i].m_light_id was nil or not unique.
Returns:
True if model is valid and false if the model has serious
@untitled table
<0 model has serious errors
=0 model is ok
>0 number of problems that were found.
*/
virtual
int Audit(
bool bAttemptRepair,
int* repair_count,
ON_TextLog* text_log,
ON_SimpleArray<int>* warnings
);
/////////////////////////////////////////////////////////////////////
//
// BEGIN model definitions
//
// start section information
int m_3dm_file_version;
int m_3dm_opennurbs_version;
ON_String m_sStartSectionComments;
// Properties include revision history, notes, information about
// the applicaton that created the file, and an option preview image.
ON_3dmProperties m_properties;
// Settings include tolerance, and unit system, and defaults used
// for creating views and objects.
ON_3dmSettings m_settings;
// Tables in an openNURBS archive
ON_SimpleArray<ON_Bitmap*> m_bitmap_table;
ON_ObjectArray<ON_TextureMapping> m_mapping_table;
ON_ObjectArray<ON_Material> m_material_table;
ON_ObjectArray<ON_Linetype> m_linetype_table;
ON_ObjectArray<ON_Layer> m_layer_table;
ON_ObjectArray<ON_Group> m_group_table;
ON_ObjectArray<ON_Font> m_font_table;
ON_ObjectArray<ON_DimStyle> m_dimstyle_table;
ON_ClassArray<ONX_Model_RenderLight> m_light_table;
ON_ObjectArray<ON_HatchPattern> m_hatch_pattern_table;
ON_ObjectArray<ON_InstanceDefinition> m_idef_table;
ON_ClassArray<ONX_Model_Object> m_object_table;
ON_SimpleArray<ON_HistoryRecord*> m_history_record_table;
ON_ClassArray<ONX_Model_UserData> m_userdata_table;
// The id index fields are used to lookup objects by id
ON_UuidIndexList m_mapping_id_index;
ON_UuidIndexList m_material_id_index;
ON_UuidIndexList m_object_id_index;
ON_UuidIndexList m_idef_id_index;
// length of archive returned by ON_BinaryArchive::Read3dmEndMark()
size_t m_file_length;
// Number of crc errors found during archive reading.
// If > 0, then the archive is corrupt.
int m_crc_error_count;
//
// END model definitions
//
/////////////////////////////////////////////////////////////////////
/*
Returns:
Bounding box of every object in m_object_table[].
*/
ON_BoundingBox BoundingBox() const;
/*
Description:
Get render material from object attributes.
Parameters:
attributes - [in] object attributes.
material - [out] render material
*/
void GetRenderMaterial(
const ON_3dmObjectAttributes& attributes,
ON_Material& material
) const;
/*
Description:
Get render material from object_index.
Parameters:
object_index - [in] m_object_table[] index
material - [out] render material
*/
void GetRenderMaterial(
int object_index,
ON_Material& material
) const;
/*
Description:
Get linetype from object attributes.
Parameters:
attributes - [in] object attributes.
linetype - [out] linetype
*/
void GetLinetype(
const ON_3dmObjectAttributes& attributes,
ON_Linetype& linetype
) const;
/*
Description:
Get linetype from object_index.
Parameters:
object_index - [in] m_object_table[] index
linetype - [out] linetype
*/
void GetLinetype(
int object_index,
ON_Linetype& linetype
) const;
/*
Description:
Get wireframe drawing color from object attributes.
Parameters:
attributes - [in] object attributes.
Returns:
Wireframe drawing color.
*/
ON_Color WireframeColor(const ON_3dmObjectAttributes& attributes) const;
/*
Description:
Get wireframe drawing color from object attributes.
Parameters:
object_index - [in] m_object_table[] index
Returns:
Wireframe drawing color.
*/
ON_Color WireframeColor(int object_index) const;
/*
Description:
Get index of object in m_object_table from object_uuid.
Parameters:
object_uuid - [in] object uuid.
Returns:
Index of the object or -1 if it is not found.
*/
virtual
int ObjectIndex(
ON_UUID object_uuid
) const;
/*
Description:
Get instance definition from instance definition table.
Parameters:
idef_uuid - [in] instance definition uuid.
Example:
ON_XModel model = ...;
..
ON_InstanceRef* pIRef = ..;
ON_UUID idef_uuid = pIRef->m_instance_definition_uuid;
int idef_index = model.IDefIndex( idef_uuid );
if ( idef_index >= 0 )
{
const ON_InstanceDefinition& idef = model.m_idef_table[idef_index];
...
}
Returns:
Index of the instance definition or -1 if it is not found.
*/
virtual
int IDefIndex(
ON_UUID idef_uuid
) const;
/*
Description:
Get instance definition index from instance definition name.
Parameters:
idef_name - [in] name to search for
Returns:
Index of the instance definition or -1 if it is not found.
*/
virtual
int IDefIndex(
const wchar_t* idef_name
) const;
/*
Description:
Get instance definition name that is not currently in use.
*/
virtual
void GetUnusedIDefName( ON_wString& idef_name ) const;
/*
Description:
See if the instance reference iref refers to an instance
definition.
Parameters:
iref - [in]
idef_uuid - [in] id of idef we are looking for
Returns:
@untitled table
0 iref does not use idef
1 iref directly references idef
>1 iref has a nested reference to idef (nesting depth returned)
-1 iref.m_instance_definition_uuid is not valid
-2 invalid idef found
*/
virtual
int UsesIDef(
const ON_InstanceRef& iref,
ON_UUID idef_uuid
) const;
/*
Description:
Get layer definition from layer table.
Parameters:
layer_name - [in] name to search for
Example:
ON_XModel model = ...;
..
ON_InstanceRef* pIRef = ..;
ON_UUID idef_uuid = pIRef->m_instance_definition_uuid;
int layer_index = model.IDefIndex( idef_uuid );
if ( idef_index >= 0 )
{
const ON_InstanceDefinition& idef = model.m_idef_table[idef_index];
...
}
Returns:
Index of the layer or -1 if it is not found.
*/
virtual
int LayerIndex(
const wchar_t* layer_name
) const;
/*
Description:
Get layer name that is not currently in use.
*/
virtual
void GetUnusedLayerName( ON_wString& layer_name ) const;
/////////////////////////////////////////////////////////////////////
//
// BEGIN model document level user string tools
//
/*
Description:
Attach a user string to the document.
Parameters:
key - [in] id used to retrieve this string.
string_value - [in]
If NULL, the string with this id will be removed.
Returns:
True if successful.
*/
bool SetDocumentUserString(
const wchar_t* key,
const wchar_t* string_value
);
/*
Description:
Get user string from the document.
Parameters:
key - [in] id used to retrieve the string.
string_value - [out]
Returns:
True if a string with id was found.
*/
bool GetDocumentUserString(
const wchar_t* key,
ON_wString& string_value
) const;
/*
Description:
Get a list of all user strings in the document.
Parameters:
user_strings - [out]
user strings are appended to this list.
Returns:
Number of elements appended to the user_strings list.
*/
int GetDocumentUserStrings( ON_ClassArray<ON_UserString>& user_strings ) const;
//
// END model document level user string tools
//
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
//
// BEGIN model text dump tools
//
// text dump of entire model
void Dump( ON_TextLog& ) const;
// text dump of model properties and settings
void DumpSummary( ON_TextLog& ) const;
// text dump of bitmap table
void DumpBitmapTable( ON_TextLog& ) const;
// text dump of texture mapping table
void DumpTextureMappingTable( ON_TextLog& ) const;
// text dump of render material table
void DumpMaterialTable( ON_TextLog& ) const;
// text dump of line type table
void DumpLinetypeTable( ON_TextLog& ) const;
// text dump of layer table
void DumpLayerTable( ON_TextLog& ) const;
// text dump of light table
void DumpLightTable( ON_TextLog& ) const;
// text dump of group table
void DumpGroupTable( ON_TextLog& ) const;
// text dump of font table
void DumpFontTable( ON_TextLog& ) const;
// text dump of dimstyle table
void DumpDimStyleTable( ON_TextLog& ) const;
// text dump of hatch pattern table
void DumpHatchPatternTable( ON_TextLog& ) const;
// text dump of instance definition table
void DumpIDefTable( ON_TextLog& ) const;
// text dump of object table
void DumpObjectTable( ON_TextLog& ) const;
// text dump of object table
void DumpHistoryRecordTable( ON_TextLog& ) const;
// text dump of user data table
void DumpUserDataTable( ON_TextLog& ) const;
//
// END model text dump tools
//
/////////////////////////////////////////////////////////////////////
/*
Description:
Destroys cached searching and bounding box information. Call
if you modify the m_object_table or m_idef_table.
*/
void DestroyCache();
/////////////////////////////////////////////////////////////////////
//
// BEGIN Render Development Toolkit (RDK) information
//
static bool IsRDKDocumentInformation(const ONX_Model_UserData& docud);
static bool GetRDKDocumentInformation(const ONX_Model_UserData& docud,ON_wString& rdk_xml_document_data);
static bool IsRDKObjectInformation(const ON_UserData& objectud);
static bool GetRDKObjectInformation(const ON_Object& object,ON_wString& rdk_xml_object_data);
//
// END Render Development Toolkit (RDK) information
//
/////////////////////////////////////////////////////////////////////
private:
// prohibit use of copy construction and operator=
ONX_Model(const ONX_Model&);
ONX_Model& operator=(const ONX_Model&);
private:
// This bounding box contains all objects in the object table.
ON_BoundingBox m__object_table_bbox;
};
/*
Description:
Tests a string to see if it is valid as a name for a layer,
object, material, linetype, instance definition, etc.
Parameters:
name - [in] string to test
Returns:
True if the string is a valid name.
*/
ON_DECL
bool ONX_IsValidName(
const wchar_t* name
);
#endif

658
extern/opennurbs/opennurbs_font.cpp vendored Executable file
View File

@@ -0,0 +1,658 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
ON_OBJECT_IMPLEMENT( ON_Font, ON_Object, "4F0F51FB-35D0-4865-9998-6D2C6A99721D" );
ON_Font::ON_Font()
{
Defaults();
}
ON_Font::~ON_Font()
{
}
bool ON_Font::CreateFontFromFaceName(
const wchar_t* facename,
bool bBold,
bool bItalic
)
{
PurgeUserData();
Defaults();
if ( 0 == facename || 0 == facename[0] )
facename = L"Arial";
bool rc = SetFontFaceName(facename);
HeightOfI();
m_font_name = facename;
if ( bBold )
{
SetBold(true);
m_font_name += "L Bold";
}
if ( bItalic )
{
SetItalic(true);
m_font_name += "L Italic";
}
return rc;
}
void ON_Font::Defaults()
{
m_font_name.Empty();
m_font_weight = ON_Font::normal_weight;
m_font_italic = false;
m_font_underlined = false;
m_linefeed_ratio = m_default_linefeed_ratio;
m_font_index = -1;
memset(&m_font_id,0,sizeof(m_font_id));
memset( &m_facename, 0, sizeof( m_facename));
m_I_height = 0;
#if defined(ON_OS_WINDOWS_GDI)
memset(&m_logfont,0,sizeof(m_logfont));
m_logfont.lfHeight = normal_font_height;
m_logfont.lfCharSet = default_charset;
#endif
SetFontFaceName(L"Arial");
}
//////////////////////////////////////////////////////////////////////
//
// ON_Object overrides
ON_BOOL32 ON_Font::IsValid( ON_TextLog* text_log ) const
{
return ( m_font_name.Length() > 0
&& m_font_index >= 0
&& m_facename[0] > 32
&& m_facename[64] == 0
);
}
void ON_Font::Dump( ON_TextLog& dump ) const
{
const wchar_t* name = FontName();
if ( !name )
name = L"";
dump.Print("font index = %d\n",m_font_index);
dump.Print("font name = \"%ls\"\n",name);
dump.Print("font face name = \"%ls\"\n",m_facename);
dump.Print("font weight = \"%d\"\n",m_font_weight);
dump.Print("font is italic = \"%d\"\n",m_font_italic);
dump.Print("font is underlined = \"%d\"\n",m_font_underlined);
dump.Print("font linefeed ratio = \"%g\"\n", m_linefeed_ratio);
}
ON_BOOL32 ON_Font::Write(
ON_BinaryArchive& file // serialize definition to binary archive
) const
{
bool rc = file.Write3dmChunkVersion(1,2);
while(rc)
{
rc = file.WriteInt(m_font_index);
if (!rc) break;
rc = file.WriteString(m_font_name);
if (!rc) break;
{
// 18 October 2002 Dale Lear:
// Lowell, wchar_t has different sizes on different OSs.
// When writing a wchar_t string, you should use one
// of the WriteString functions. This function must continue
// to use WriteShort(64,...) so old files will remain valid.
unsigned short sh[64];
memset(sh,0,sizeof(sh));
int i;
for ( i = 0; i < 64 && i < face_name_size-1; i++ )
sh[i] = m_facename[i];
rc = file.WriteShort(64, sh);
if (!rc) break;
}
// 1.1 additions
rc = file.WriteInt( m_font_weight);
if (!rc) break;
rc = file.WriteInt( m_font_italic);
if (!rc) break;
rc = file.WriteDouble( m_linefeed_ratio);
if (!rc) break;
// 1.2 addition
rc = file.WriteUuid( m_font_id);
if (!rc) break;
// 1.3 addition
// rc = file.WriteInt( m_font_underlined);
// if (!rc) break;
break;
}
return rc;
}
ON_BOOL32 ON_Font::Read(
ON_BinaryArchive& file // restore definition from binary archive
)
{
Defaults();
m_font_index = -1;
int major_version = 0;
int minor_version = 0;
bool rc = file.Read3dmChunkVersion(&major_version,&minor_version);
if ( rc && major_version == 1 )
{
int i;
for(;;)
{
rc = file.ReadInt( &m_font_index );
if (!rc) break;
rc = file.ReadString( m_font_name );
if (!rc) break;
{
// 18 October 2002 Dale Lear:
// Lowell, wchar_t has different sizes on different OSs.
// When writing a wchar_t string, you should use one
// of the WriteString functions. This function must continue
// to use ReadShort(64,...) so old files will remain valid.
unsigned short sh[64];
rc = file.ReadShort(64, sh);
if (!rc) break;
wchar_t facename[65];
for ( i = 0; i < 64; i++ )
{
facename[i] = sh[i];
}
facename[64] = 0;
SetFontFaceName(facename);
}
if( minor_version >= 1 )
{
rc = file.ReadInt( &i );
if (!rc) break;
SetFontWeight(i);
rc = file.ReadInt( &i);
if (!rc) break;
SetIsItalic(i?true:false);
rc = file.ReadDouble( &m_linefeed_ratio );
if (!rc) break;
if ( minor_version >= 2 )
{
rc = file.ReadUuid( m_font_id );
if (!rc) break;
}
//if ( minor_version >= 3 )
//{
// rc = file.ReadInt( &i);
// if (!rc) break;
// SetUnderlined(i?true:false);
//}
}
break;
}
}
else
{
ON_ERROR("ON_Font::Read - get newer version of opennurbs");
rc = false;
}
return rc;
}
// Ratio of linefeed to character height
const double ON_Font::m_default_linefeed_ratio = 1.6;
// This must be an 'I' or 'H', but we have not tested 'H'.
// There are problems with any other upper case character.
// In particular, the standard 'M' does not work.
const int ON_Font::m_metrics_char = 'I';
//////////////////////////////////////////////////////////////////////
//
// Interface
void ON_Font::SetFontName( const wchar_t* s )
{
m_font_name = s;
}
void ON_Font::SetFontName( const char* s )
{
m_font_name = s;
}
void ON_Font::GetFontName( ON_wString& s ) const
{
s = m_font_name;
}
const wchar_t* ON_Font::FontName() const
{
const wchar_t* s = m_font_name;
return s;
}
#if defined(ON_OS_WINDOWS_GDI)
static
int CALLBACK ON__IsSymbolFontFaceNameHelper( ENUMLOGFONTEX*, NEWTEXTMETRICEX*, DWORD, LPARAM)
{
// If the fontname in the logfont structure has
// a corresponding symbol font on the system,
// set the lfCharSet member to SYMBOL_CHARSET,
// otherwise DEFAULT_CHARSET
// The input logfont structure may be modified.
return 7;
}
#endif
bool ON_Font::IsSymbolFontFaceName( const wchar_t* s)
{
bool rc = false;
#if defined(ON_OS_WINDOWS_GDI)
if( s && s[0])
{
HDC hdc = ::GetDC( NULL);
if( hdc)
{
LOGFONT logfont;
memset( &logfont, 0, sizeof( logfont));
int i;
for ( i = 0; i < LF_FACESIZE && s[i]; i++ )
{
logfont.lfFaceName[i] = s[i];
}
logfont.lfCharSet = ON_Font::symbol_charset;
if( 7 == ::EnumFontFamiliesEx( hdc, &logfont, (FONTENUMPROC)ON__IsSymbolFontFaceNameHelper, 0, 0))
{
rc = true;
}
::ReleaseDC( NULL, hdc);
}
}
#endif
return rc;
}
bool ON_Font::SetFontFaceName( const wchar_t* s )
{
int i;
memset( &m_facename, 0, sizeof(m_facename) );
if ( s)
{
for ( i = 0; i < face_name_size-1 && s[i]; i++ )
{
m_facename[i] = s[i];
}
}
#if defined(ON_OS_WINDOWS_GDI)
memset( &m_logfont.lfFaceName, 0, sizeof(m_logfont.lfFaceName) );
#endif
m_I_height = 0;
UpdateImplementationSettings();
return( m_facename[0] ? true : false);
}
bool ON_Font::SetFontFaceName( const char* s )
{
ON_wString wstr(s);
const wchar_t* w = wstr;
return SetFontFaceName(w);
}
double ON_Font::AscentRatio() const
{
return ((double)normal_font_height) / ((double)HeightOfI());
}
void ON_Font::GetFontFaceName( ON_wString& s ) const
{
s = m_facename;
}
const wchar_t* ON_Font::FontFaceName() const
{
const wchar_t* s = m_facename;
return s;
}
void ON_Font::SetFontIndex(int i)
{
m_font_index = i;
}
int ON_Font::FontIndex() const
{
return m_font_index;
}
double ON_Font::LinefeedRatio() const
{
return m_linefeed_ratio;
}
void ON_Font::SetLinefeedRatio( double d)
{
m_linefeed_ratio = d;
}
int ON_Font::FontWeight() const
{
return m_font_weight;
}
void ON_Font::SetFontWeight( int w)
{
if ( w != m_font_weight )
{
if ( w < 0 )
w = 0;
m_font_weight = w;
m_I_height = 0;
UpdateImplementationSettings();
}
}
bool ON_Font::IsItalic() const
{
return m_font_italic;
}
void ON_Font::SetIsItalic( bool b)
{
SetItalic( b);
}
void ON_Font::SetItalic( bool b)
{
if ( m_font_italic != b )
{
m_font_italic = b?true:false;
m_I_height = 0;
UpdateImplementationSettings();
}
}
bool ON_Font::IsBold() const
{
return (FontWeight() >= bold_weight);
}
void ON_Font::SetBold( bool bBold )
{
SetFontWeight( bBold ? bold_weight : normal_weight);
}
bool ON_Font::IsUnderlined() const
{
return m_font_underlined;
}
void ON_Font::SetUnderlined( bool b)
{
if ( m_font_underlined != b )
{
m_font_underlined = b?true:false;
UpdateImplementationSettings();
}
}
void ON_Font::UpdateImplementationSettings()
{
#if defined(ON_OS_WINDOWS_GDI)
BYTE b;
LONG w;
size_t cap0, cap1, cap, i;
w = m_font_weight;
if ( w < 0 )
w = 0;
if ( w != m_logfont.lfWeight )
{
m_logfont.lfWeight = w;
m_I_height = 0;
}
b = m_font_italic ? 1 : 0;
if ( b != m_logfont.lfItalic )
{
m_logfont.lfItalic = b;
m_I_height = 0;
}
b = m_font_underlined ? 1 : 0;
if ( b != m_logfont.lfUnderline )
{
m_logfont.lfUnderline = b;
m_I_height = 0;
}
b = 0;
cap0 = sizeof(m_facename)/sizeof(m_facename[0]);
cap1 = sizeof(m_logfont.lfFaceName)/sizeof(m_logfont.lfFaceName[0]);
cap = cap0 < cap1 ? cap0 : cap1;
for ( i = 0; i < cap; i++ )
{
if ( m_logfont.lfFaceName[i] != m_facename[i] )
{
m_logfont.lfFaceName[i] = m_facename[i];
b = 1;
}
}
if ( b )
{
for ( i = cap; i < cap1; i++ )
m_logfont.lfFaceName[i] = 0;
m_logfont.lfCharSet = ON_Font::IsSymbolFontFaceName( m_logfont.lfFaceName )
? ((unsigned char)ON_Font::symbol_charset)
: ((unsigned char)ON_Font::default_charset);
m_I_height = 0;
}
#endif
}
/*
Returns:
Height of the 'I' character when the font is drawn
with m_logfont.lfHeight = 256.
*/
int ON_Font::HeightOfI() const
{
if ( m_I_height <= 0 )
{
// Default is height of Arial 'I'. If we are running
// on Windows, then we calculate the actual height of
// an 'I' in the font.
// The ..ON_Font::normal_font_height/256 is here
// so this code will continue to work correctly
// if somebody changes ON_Font::normal_font_height.
int I_height = (166*ON_Font::normal_font_height)/256;
#if defined(ON_OS_WINDOWS_GDI)
if ( m_logfont.lfFaceName[0] )
{
// Get the height of an 'I'
HDC hdc = ::GetDC( NULL);
if (hdc)
{
LOGFONT logfont = m_logfont;
logfont.lfHeight = normal_font_height;
HFONT font = ::CreateFontIndirect( &logfont);
if ( font )
{
wchar_t str[2];
str[0] = ON_Font::m_metrics_char;
str[1] = 0;
HFONT oldfont = (HFONT)::SelectObject( hdc, font);
::SetBkMode( hdc, TRANSPARENT);
::BeginPath(hdc);
::ExtTextOut( hdc, 0, 0, 0, NULL, str, 1, NULL);
::EndPath( hdc);
int numPoints = ::GetPath( hdc, NULL, NULL, 0);
if( numPoints > 2)
{
// Allocate room for the points & point types
LPPOINT pPoints = (LPPOINT)onmalloc( numPoints * sizeof(*pPoints) );
LPBYTE pTypes = (LPBYTE)onmalloc( numPoints * sizeof(*pTypes) );
if ( pTypes && pPoints)
{
// Get the points and types from the current path
numPoints = ::GetPath( hdc, pPoints, pTypes, numPoints);
if( numPoints > 2)
{
int ymin = pPoints[0].y;
int ymax = ymin;
int k;
for( k = 1; k < numPoints; k++)
{
if( pPoints[k].y < ymin)
ymin = pPoints[k].y;
else if( pPoints[k].y > ymax)
ymax = pPoints[k].y;
}
I_height = ymax - ymin + 1;
}
}
onfree( pPoints);
onfree( pTypes);
}
::SelectObject( hdc, oldfont);
::DeleteObject( font);
}
}
::ReleaseDC( NULL, hdc);
}
#endif
const_cast<ON_Font*>(this)->m_I_height = I_height;
}
return m_I_height;
}
int ON_Font::HeightOfLinefeed() const
{
return ( (int)( ceil(m_linefeed_ratio*HeightOfI()) ) );
}
#if defined(ON_OS_WINDOWS_GDI)
#pragma message( " --- OpenNURBS including Windows LOGFONT support in ON_Font" )
bool ON_Font::SetLogFont( const LOGFONT& logfont )
{
if ( &m_logfont != &logfont )
{
memcpy(&m_logfont,&logfont,sizeof(m_logfont));
}
// synch persistent fields
m_font_weight = m_logfont.lfWeight;
m_font_italic = (m_logfont.lfItalic?true:false);
m_font_underlined = (m_logfont.lfUnderline?true:false);
memset(&m_facename[0],0,sizeof(m_facename));
int i;
for ( i = 0; i < face_name_size && i < LF_FACESIZE; i++ )
{
m_facename[i] = (wchar_t)m_logfont.lfFaceName[i];
}
m_facename[face_name_size-1] = 0;
m_I_height = 0;
return true;
}
const LOGFONT& ON_Font::LogFont() const
{
return m_logfont;
}
ON_Font::ON_Font( const LOGFONT& logfont )
{
Defaults();
SetLogFont(logfont);
}
ON_Font& ON_Font::operator=( const LOGFONT& logfont )
{
if ( &m_logfont == &logfont )
{
LOGFONT lf = logfont;
SetLogFont(lf);
}
else
{
SetLogFont(logfont);
}
return *this;
}
bool ON_Font::CompareFontCharacteristics( ON_Font& other_font, bool bCompareName) const
{
if( bCompareName && m_font_name.CompareNoCase( other_font.m_font_name))
return false;
if( m_font_weight != other_font.m_font_weight)
return false;
if( m_font_italic != other_font.m_font_italic)
return false;
if( m_font_underlined != other_font.m_font_underlined)
return false;
if( m_linefeed_ratio != other_font.m_linefeed_ratio)
return false;
if( _wcsicmp( m_facename, other_font.m_facename))
return false;
return true;
}
#endif

284
extern/opennurbs/opennurbs_font.h vendored Executable file
View File

@@ -0,0 +1,284 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_FONT_INC_)
#define OPENNURBS_FONT_INC_
class ON_CLASS ON_Font : public ON_Object
{
ON_OBJECT_DECLARE(ON_Font);
public:
ON_Font();
~ON_Font();
// C++ default copy construction and operator= work fine.
/*
Description:
Create a font with a specified facename and properties.
Parameters:
face_name - [in]
If face_name is null or empty, then "Arial" is used.
bBold - [in]
True for a bold version of the font.
bItalic - [in]
True for an italic version of the font.
Returns:
True if the font was created. The name of this font is
the face name with " Bold", " Italic" or " Bold Italic"
appended as
*/
bool CreateFontFromFaceName(
const wchar_t* face_name,
bool bBold,
bool bItalic
);
#if defined(ON_OS_WINDOWS_GDI)
ON_Font( const LOGFONT& logfont );
ON_Font& operator=( const LOGFONT& logfont );
#endif
//////////////////////////////////////////////////////////////////////
//
// ON_Object overrides
/*
Description:
Tests an object to see if its data members are correctly
initialized.
Parameters:
text_log - [in] if the object is not valid and text_log
is not NULL, then a brief englis description of the
reason the object is not valid is appened to the log.
The information appended to text_log is suitable for
low-level debugging purposes by programmers and is
not intended to be useful as a high level user
interface tool.
Returns:
@untitled table
true object is valid
false object is invalid, uninitialized, etc.
Remarks:
Overrides virtual ON_Object::IsValid
*/
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
// virtual
void Dump( ON_TextLog& ) const; // for debugging
// virtual
ON_BOOL32 Write(
ON_BinaryArchive& // serialize definition to binary archive
) const;
// virtual
ON_BOOL32 Read(
ON_BinaryArchive& // restore definition from binary archive
);
// virtual
ON_UUID ModelObjectId() const;
//////////////////////////////////////////////////////////////////////
//
// Interface
enum
{
#if defined(ON_OS_WINDOWS_GDI)
// Windows GDI facename length
// 13 November 2008 - Dale Lear
// Because:
// * Prior to this date the above "ON_OS_WINDOWS_GDI"
// was misspelled and this code did not get compiled.
// * The Windows headers defines LF_FACESIZE = 32
// * ON_Font has a member wchar_t m_facename[face_name_size] array
// * We cannot break the SDK by changing the size of ON_Font
//
// we cannot define face_name_size = LF_FACESIZE+1. So, I'm
// using the same "65" we use below. It is critical that
// face_name_size >= LF_FACESIZE+1
//
//face_name_size = LF_FACESIZE+1, // <- prior to 13 Nov but never used
face_name_size = 65,
// Windows GDI font weights
bold_weight = FW_BOLD,
medium_weight = FW_MEDIUM,
normal_weight = FW_NORMAL,
light_weight = FW_LIGHT,
// Windows GDI character sets
default_charset = DEFAULT_CHARSET,
symbol_charset = SYMBOL_CHARSET,
#else
face_name_size = 65, // must be >= 33
bold_weight = 700,
medium_weight = 500,
normal_weight = 400,
light_weight = 300,
default_charset = 1,
symbol_charset = 2,
#endif
normal_font_height = 256
};
// Ratio of linefeed to character height (1.6)
static
const double m_default_linefeed_ratio;
static
const int m_metrics_char; // ASCII code of character to used
// to get runtime "default" glyph
// metrics. (Currently an "I").
/*
Returns:
True if the font's character set should be SYMBOL_CHARSET;
*/
static
bool IsSymbolFontFaceName(
const wchar_t* facename
);
void SetFontName( const wchar_t* );
void SetFontName( const char* );
void GetFontName( ON_wString& ) const;
const wchar_t* FontName() const;
void SetFontIndex(int);
int FontIndex() const;
/*
Returns:
The ratio (height of linefeed)/(height of I).
*/
double LinefeedRatio() const;
void SetLinefeedRatio( double linefeed_ratio );
bool SetFontFaceName( const wchar_t* );
bool SetFontFaceName( const char* );
void GetFontFaceName( ON_wString& ) const;
const wchar_t* FontFaceName() const;
int FontWeight() const;
void SetFontWeight( int);
bool IsItalic() const;
void SetIsItalic( bool );
void SetItalic( bool );
bool IsBold() const;
void SetBold( bool );
// Added 7/12/07 LW
bool IsUnderlined() const;
void SetUnderlined( bool );
void Defaults();
/*
Returns:
Height of the 'I' character when the font is drawn
with m_logfont.lfHeight = ON_Font::normal_font_height.
*/
int HeightOfI() const;
/*
Returns:
Height of a linefeed when the font is drawn
with m_logfont.lfHeight = ON_Font::normal_font_height.
*/
int HeightOfLinefeed() const;
/*
Description:
Returns the ratio of the height of a typical upper case letter
to the height of a whole character cell.
Parameters:
none
Returns:
double - ratio of Windows Font Height / m_HeightOfH
*/
double AscentRatio() const;
/*
Description:
Compare the visible characteristics to another font
Parameters:
font_to_compare - [in] The cont to compare this one to
bCompareName - [in] if this is set, test if the names match
otherwise don't compare the names
Returns:
true if font_to_compare matches this one
false if font_to_match doesn't match this one
Added for v5 - 5/20/07
*/
bool CompareFontCharacteristics( ON_Font& font_to_compare, bool bCompareName) const;
#if defined(ON_OS_WINDOWS_GDI)
bool SetLogFont( const LOGFONT& logfont );
const LOGFONT& LogFont() const;
#endif
public:
ON_wString m_font_name; // Name of this font in the Rhino UI
int m_font_weight; // Same as m_logfont.lfWeight
bool m_font_italic; // Same as m_logfont.lfItalic
bool m_font_underlined;// Same as m_logfont.lfUnderlined (Added 7/12/07 LW)
double m_linefeed_ratio; // defaults to static s_linefeed_ratio.
int m_font_index; // font index in Rhino font table
ON_UUID m_font_id;
wchar_t m_facename[face_name_size]; // same as m_logfont.lfFaceName (
public:
/*
Description:
Insures the settings in the OS specific information, like
the Windows m_logfont field, match the persistent m_font_* values
above that are used for all OSs and used in UI code.
*/
void UpdateImplementationSettings();
#if defined(ON_OS_WINDOWS_GDI)
// Windows specific settins
LOGFONT m_logfont;
#endif
private:
// volitile - can be changed by ON_Font::HeightOfI() const.
int m_I_height; // height of the 'I' character when the font is drawn
// with m_logfont.lfHeight = 256.
};
#endif

900
extern/opennurbs/opennurbs_fpoint.h vendored Executable file
View File

@@ -0,0 +1,900 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
////////////////////////////////////////////////////////////////
//
// defines float precision point, vector, and array classes
//
////////////////////////////////////////////////////////////////
#if !defined(ON_FPOINT_INC_)
#define ON_FPOINT_INC_
class ON_Xform;
class ON_2fPoint;
class ON_3fPoint;
class ON_4fPoint;
class ON_2fVector;
class ON_3fVector;
////////////////////////////////////////////////////////////////
//
// ON_2fPoint
//
class ON_CLASS ON_2fPoint
{
public:
float x, y;
static const ON_2fPoint Origin; // (0.0f,0.0f)
// use implicit destructor, copy constructor
ON_2fPoint(); // x,y not initialized
ON_2fPoint(float x,float y);
ON_2fPoint(const ON_3fPoint& ); // from 3f point
ON_2fPoint(const ON_4fPoint& ); // from 4f point
ON_2fPoint(const ON_2fVector& ); // from 2f vector
ON_2fPoint(const ON_3fVector& ); // from 3f vector
ON_2fPoint(const float*); // from float[2] array
ON_2fPoint(const ON_2dPoint& ); // from 2d point
ON_2fPoint(const ON_3dPoint& ); // from 3d point
ON_2fPoint(const ON_4dPoint& ); // from 4d point
ON_2fPoint(const ON_2dVector& ); // from 2d vector
ON_2fPoint(const ON_3dVector& ); // from 3d vector
ON_2fPoint(const double*); // from double[2] array
// (float*) conversion operators
operator float*();
operator const float*() const;
// use implicit operator=(const ON_2fPoint&)
ON_2fPoint& operator=(const ON_3fPoint&);
ON_2fPoint& operator=(const ON_4fPoint&);
ON_2fPoint& operator=(const ON_2fVector&);
ON_2fPoint& operator=(const ON_3fVector&);
ON_2fPoint& operator=(const float*); // point = float[2] support
ON_2fPoint& operator=(const ON_2dPoint&);
ON_2fPoint& operator=(const ON_3dPoint&);
ON_2fPoint& operator=(const ON_4dPoint&);
ON_2fPoint& operator=(const ON_2dVector&);
ON_2fPoint& operator=(const ON_3dVector&);
ON_2fPoint& operator=(const double*); // point = double[2] support
ON_2fPoint& operator*=(float);
ON_2fPoint& operator/=(float);
ON_2fPoint& operator+=(const ON_2fPoint&);
ON_2fPoint& operator+=(const ON_2fVector&);
ON_2fPoint& operator+=(const ON_3fVector&);
ON_2fPoint& operator-=(const ON_2fPoint&);
ON_2fPoint& operator-=(const ON_2fVector&);
ON_2fPoint& operator-=(const ON_3fVector&);
ON_2fPoint operator*(int) const;
ON_2fPoint operator/(int) const;
ON_2fPoint operator*(float) const;
ON_2fPoint operator/(float) const;
ON_2dPoint operator*(double) const;
ON_2dPoint operator/(double) const;
ON_2fPoint operator+(const ON_2fPoint&) const;
ON_2fPoint operator+(const ON_2fVector&) const;
ON_2fVector operator-(const ON_2fPoint&) const;
ON_2fPoint operator-(const ON_2fVector&) const;
ON_3fPoint operator+(const ON_3fPoint&) const;
ON_3fPoint operator+(const ON_3fVector&) const;
ON_3fVector operator-(const ON_3fPoint&) const;
ON_3fPoint operator-(const ON_3fVector&) const;
ON_2dPoint operator+(const ON_2dPoint&) const;
ON_2dPoint operator+(const ON_2dVector&) const;
ON_2dVector operator-(const ON_2dPoint&) const;
ON_2dPoint operator-(const ON_2dVector&) const;
ON_3dPoint operator+(const ON_3dPoint&) const;
ON_3dPoint operator+(const ON_3dVector&) const;
ON_3dVector operator-(const ON_3dPoint&) const;
ON_3dPoint operator-(const ON_3dVector&) const;
float operator*(const ON_2fPoint&) const; // for points acting as vectors
float operator*(const ON_2fVector&) const; // for points acting as vectors
float operator*(const ON_4fPoint&) const;
bool operator==(const ON_2fPoint&) const;
bool operator!=(const ON_2fPoint&) const;
// dictionary order comparisons
bool operator<=(const ON_2fPoint&) const;
bool operator>=(const ON_2fPoint&) const;
bool operator<(const ON_2fPoint&) const;
bool operator>(const ON_2fPoint&) const;
// index operators mimic float[2] behavior
float& operator[](int);
float operator[](int) const;
float& operator[](unsigned int);
float operator[](unsigned int) const;
// set 2d point value
void Set(float,float);
double DistanceTo( const ON_2fPoint& ) const;
int MaximumCoordinateIndex() const;
double MaximumCoordinate() const; // absolute value of maximum coordinate
void Zero(); // set all coordinates to zero;
// These transform the point in place. The transformation matrix acts on
// the left of the point; i.e., result = transformation*point
void Transform(
const ON_Xform&
);
void Rotate( // rotatation in XY plane
double, // angle in radians
const ON_2fPoint& // center of rotation
);
void Rotate( // rotatation in XY plane
double, // sin(angle)
double, // cos(angle)
const ON_2fPoint& // center of rotation
);
};
ON_DECL
ON_2fPoint operator*(int, const ON_2fPoint&);
ON_DECL
ON_2fPoint operator*(float, const ON_2fPoint&);
ON_DECL
ON_2dPoint operator*(double, const ON_2fPoint&);
////////////////////////////////////////////////////////////////
//
// ON_3fPoint
//
class ON_CLASS ON_3fPoint
{
public:
float x, y, z;
static const ON_3fPoint Origin; // (0.0f,0.0f,0.0f)
// use implicit destructor, copy constructor
ON_3fPoint(); // x,y,z not initialized
ON_3fPoint(float x,float y,float z);
ON_3fPoint(const ON_2fPoint& ); // from 2f point
ON_3fPoint(const ON_4fPoint& ); // from 4f point
ON_3fPoint(const ON_2fVector& ); // from 2f vector
ON_3fPoint(const ON_3fVector& ); // from 3f vector
ON_3fPoint(const float*); // from float[3] array
ON_3fPoint(const ON_2dPoint& ); // from 2d point
ON_3fPoint(const ON_3dPoint& ); // from 3d point
ON_3fPoint(const ON_4dPoint& ); // from 4d point
ON_3fPoint(const ON_2dVector& ); // from 2d vector
ON_3fPoint(const ON_3dVector& ); // from 3d vector
ON_3fPoint(const double*); // from double[3] array
// (float*) conversion operators
operator float*();
operator const float*() const;
// use implicit operator=(const ON_3fPoint&)
ON_3fPoint& operator=(const ON_2fPoint&);
ON_3fPoint& operator=(const ON_4fPoint&);
ON_3fPoint& operator=(const ON_2fVector&);
ON_3fPoint& operator=(const ON_3fVector&);
ON_3fPoint& operator=(const float*); // point = float[3] support
ON_3fPoint& operator=(const ON_2dPoint&);
ON_3fPoint& operator=(const ON_3dPoint&);
ON_3fPoint& operator=(const ON_4dPoint&);
ON_3fPoint& operator=(const ON_2dVector&);
ON_3fPoint& operator=(const ON_3dVector&);
ON_3fPoint& operator=(const double*); // point = double[3] support
ON_3fPoint& operator*=(float);
ON_3fPoint& operator/=(float);
ON_3fPoint& operator+=(const ON_3fPoint&);
ON_3fPoint& operator+=(const ON_3fVector&);
ON_3fPoint& operator-=(const ON_3fPoint&);
ON_3fPoint& operator-=(const ON_3fVector&);
ON_3fPoint operator*(int) const;
ON_3fPoint operator/(int) const;
ON_3fPoint operator*(float) const;
ON_3fPoint operator/(float) const;
ON_3dPoint operator*(double) const;
ON_3dPoint operator/(double) const;
ON_3fPoint operator+(const ON_3fPoint&) const;
ON_3fPoint operator+(const ON_3fVector&) const;
ON_3fVector operator-(const ON_3fPoint&) const;
ON_3fPoint operator-(const ON_3fVector&) const;
ON_3fPoint operator+(const ON_2fPoint&) const;
ON_3fPoint operator+(const ON_2fVector&) const;
ON_3fVector operator-(const ON_2fPoint&) const;
ON_3fPoint operator-(const ON_2fVector&) const;
ON_3dPoint operator+(const ON_3dPoint&) const;
ON_3dPoint operator+(const ON_3dVector&) const;
ON_3dVector operator-(const ON_3dPoint&) const;
ON_3dPoint operator-(const ON_3dVector&) const;
ON_3dPoint operator+(const ON_2dPoint&) const;
ON_3dPoint operator+(const ON_2dVector&) const;
ON_3dVector operator-(const ON_2dPoint&) const;
ON_3dPoint operator-(const ON_2dVector&) const;
float operator*(const ON_3fPoint&) const; // for points acting as vectors
float operator*(const ON_3fVector&) const; // for points acting as vectors
float operator*(const ON_4fPoint&) const;
bool operator==(const ON_3fPoint&) const;
bool operator!=(const ON_3fPoint&) const;
// dictionary order comparisons
bool operator<=(const ON_3fPoint&) const;
bool operator>=(const ON_3fPoint&) const;
bool operator<(const ON_3fPoint&) const;
bool operator>(const ON_3fPoint&) const;
// index operators mimic float[3] behavior
float& operator[](int);
float operator[](int) const;
float& operator[](unsigned int);
float operator[](unsigned int) const;
// set 3d point value
void Set(float,float,float);
double DistanceTo( const ON_3fPoint& ) const;
int MaximumCoordinateIndex() const;
double MaximumCoordinate() const; // absolute value of maximum coordinate
double Fuzz( double = ON_ZERO_TOLERANCE ) const; // tolerance to use when comparing 3d points
void Zero(); // set all coordinates to zero;
// These transform the point in place. The transformation matrix acts on
// the left of the point; i.e., result = transformation*point
void Transform(
const ON_Xform&
);
void Rotate(
double, // angle in radians
const ON_3fVector&, // axis of rotation
const ON_3fPoint& // center of rotation
);
void Rotate(
double, // sin(angle)
double, // cos(angle)
const ON_3fVector&, // axis of rotation
const ON_3fPoint& // center of rotation
);
};
ON_DECL
ON_3fPoint operator*(int, const ON_3fPoint&);
ON_DECL
ON_3fPoint operator*(float, const ON_3fPoint&);
ON_DECL
ON_3dPoint operator*(double, const ON_3fPoint&);
////////////////////////////////////////////////////////////////
//
// ON_4fPoint (homogeneous coordinates)
//
class ON_CLASS ON_4fPoint
{
public:
float x, y, z, w;
// use implicit destructor, copy constructor
ON_4fPoint(); // x,y,z,w not initialized
ON_4fPoint(float x,float y,float z,float w);
ON_4fPoint(const ON_2fPoint& ); // from 2f point
ON_4fPoint(const ON_3fPoint& ); // from 3f point
ON_4fPoint(const ON_2fVector& ); // from 2f vector
ON_4fPoint(const ON_3fVector& ); // from 3f vector
ON_4fPoint(const float*); // from float[4] array
ON_4fPoint(const ON_2dPoint& ); // from 2d point
ON_4fPoint(const ON_3dPoint& ); // from 3d point
ON_4fPoint(const ON_4dPoint& ); // from 4d point
ON_4fPoint(const ON_2dVector& ); // from 2d vector
ON_4fPoint(const ON_3dVector& ); // from 3d vector
ON_4fPoint(const double*); // from double[4] array
// (float*) conversion operators
operator float*();
operator const float*() const;
// use implicit operator=(const ON_4fPoint&)
ON_4fPoint& operator=(const ON_2fPoint&);
ON_4fPoint& operator=(const ON_3fPoint&);
ON_4fPoint& operator=(const ON_2fVector&);
ON_4fPoint& operator=(const ON_3fVector&);
ON_4fPoint& operator=(const float*); // point = float[4] support
ON_4fPoint& operator=(const ON_2dPoint&);
ON_4fPoint& operator=(const ON_3dPoint&);
ON_4fPoint& operator=(const ON_4dPoint&);
ON_4fPoint& operator=(const ON_2dVector&);
ON_4fPoint& operator=(const ON_3dVector&);
ON_4fPoint& operator=(const double*); // point = double[4] support
ON_4fPoint& operator*=(float);
ON_4fPoint& operator/=(float);
ON_4fPoint& operator+=(const ON_4fPoint&);
ON_4fPoint& operator-=(const ON_4fPoint&);
ON_4fPoint operator*(float) const;
ON_4fPoint operator/(float) const;
ON_4fPoint operator+(const ON_4fPoint&) const; // sum w = sqrt(w1*w2)
ON_4fPoint operator-(const ON_4fPoint&) const; // difference w = sqrt(w1*w2)
float operator*(const ON_4fPoint&) const;
// projective comparison
// (i.e., [x,y,z,w] == [c*x,c*y,c*z,c*w] is true for nonzero c)
bool operator==(ON_4fPoint) const;
bool operator!=(const ON_4fPoint&) const;
// index operators mimic float[4] behavior
float& operator[](int);
float operator[](int) const;
float& operator[](unsigned int);
float operator[](unsigned int) const;
// set 4d point value
void Set(float,float,float,float);
int MaximumCoordinateIndex() const;
double MaximumCoordinate() const; // absolute value of maximum coordinate
void Zero(); // set all 4 coordinates to zero;
bool Normalize(); // set so x^2 + y^2 + z^2 + w^2 = 1
// These transform the point in place. The transformation matrix acts on
// the left of the point; i.e., result = transformation*point
void Transform(
const ON_Xform&
);
};
ON_DECL
ON_4fPoint operator*(float, const ON_4fPoint&);
ON_DECL
ON_4dPoint operator*(double, const ON_4fPoint&);
////////////////////////////////////////////////////////////////
//
// ON_2fVector
//
class ON_CLASS ON_2fVector
{
public:
float x, y;
static const ON_2fVector ZeroVector; // (0.0f,0.0f)
static const ON_2fVector XAxis; // (1.0f,0.0f)
static const ON_2fVector YAxis; // (0.0f,1.0f)
// Description:
// A index driven function to get unit axis vectors.
// Parameters:
// index - [in] 0 returns (1,0), 1 returns (0,1)
// Returns:
// Unit 3d vector with vector[i] = (i==index)?1:0;
static const ON_2fVector& UnitVector(
int // index
);
// use implicit destructor, copy constructor
ON_2fVector(); // x,y not initialized
ON_2fVector(float x,float y);
ON_2fVector(const ON_2fPoint& ); // from 2f point
ON_2fVector(const ON_3fPoint& ); // from 3f point
ON_2fVector(const ON_4fPoint& ); // from 4f point
ON_2fVector(const ON_3fVector& ); // from 3f vector
ON_2fVector(const float*); // from float[2] array
ON_2fVector(const ON_2dPoint& ); // from 2d point
ON_2fVector(const ON_3dPoint& ); // from 3d point
ON_2fVector(const ON_4dPoint& ); // from 4d point
ON_2fVector(const ON_2dVector& ); // from 2d vector
ON_2fVector(const ON_3dVector& ); // from 3d vector
ON_2fVector(const double*); // from double[2] array
// (float*) conversion operators
operator float*();
operator const float*() const;
// use implicit operator=(const ON_2fVector&)
ON_2fVector& operator=(const ON_2fPoint&);
ON_2fVector& operator=(const ON_3fPoint&);
ON_2fVector& operator=(const ON_3fVector&);
ON_2fVector& operator=(const float*); // point = float[2] support
ON_2fVector& operator=(const ON_2dPoint&);
ON_2fVector& operator=(const ON_3dPoint&);
ON_2fVector& operator=(const ON_2dVector&);
ON_2fVector& operator=(const ON_3dVector&);
ON_2fVector& operator=(const double*); // point = double[2] support
ON_2fVector operator-() const;
ON_2fVector& operator*=(float);
ON_2fVector& operator/=(float);
ON_2fVector& operator+=(const ON_2fVector&);
ON_2fVector& operator-=(const ON_2fVector&);
float operator*(const ON_2fVector&) const; // inner (dot) product
float operator*(const ON_2fPoint&) const; // inner (dot) product point acting as a vector
double operator*(const ON_2dVector&) const; // inner (dot) product
ON_2fVector operator*(int) const;
ON_2fVector operator/(int) const;
ON_2fVector operator*(float) const;
ON_2fVector operator/(float) const;
ON_2dVector operator*(double) const;
ON_2dVector operator/(double) const;
ON_2fVector operator+(const ON_2fVector&) const;
ON_2fPoint operator+(const ON_2fPoint&) const;
ON_2fVector operator-(const ON_2fVector&) const;
ON_2fPoint operator-(const ON_2fPoint&) const;
ON_3fVector operator+(const ON_3fVector&) const;
ON_3fPoint operator+(const ON_3fPoint&) const;
ON_3fVector operator-(const ON_3fVector&) const;
ON_3fPoint operator-(const ON_3fPoint&) const;
ON_2dVector operator+(const ON_2dVector&) const;
ON_2dPoint operator+(const ON_2dPoint&) const;
ON_2dVector operator-(const ON_2dVector&) const;
ON_2dPoint operator-(const ON_2dPoint&) const;
ON_3dVector operator+(const ON_3dVector&) const;
ON_3dPoint operator+(const ON_3dPoint&) const;
ON_3dVector operator-(const ON_3dVector&) const;
ON_3dPoint operator-(const ON_3dPoint&) const;
float operator*(const ON_4fPoint&) const;
bool operator==(const ON_2fVector&) const;
bool operator!=(const ON_2fVector&) const;
// dictionary order comparisons
bool operator<=(const ON_2fVector&) const;
bool operator>=(const ON_2fVector&) const;
bool operator<(const ON_2fVector&) const;
bool operator>(const ON_2fVector&) const;
// index operators mimic float[2] behavior
float& operator[](int);
float operator[](int) const;
float& operator[](unsigned int);
float operator[](unsigned int) const;
// set 2d vector value
void Set(float,float);
int MaximumCoordinateIndex() const;
double MaximumCoordinate() const; // absolute value of maximum coordinate
double LengthSquared() const;
double Length() const;
bool Decompose( // Computes a, b such that this vector = a*X + b*Y
// Returns false if unable to solve for a,b. This happens
// when X,Y is not really a basis.
//
// If X,Y is known to be an orthonormal frame,
// then a = V*X, b = V*Y will compute
// the same result more quickly.
const ON_2fVector&, // X
const ON_2fVector&, // Y
double*, // a
double* // b
) const;
int IsParallelTo(
// returns 1: this and other vectors are parallel
// -1: this and other vectors are anti-parallel
// 0: this and other vectors are not parallel
// or at least one of the vectors is zero
const ON_2fVector&, // other vector
double = ON_DEFAULT_ANGLE_TOLERANCE // optional angle tolerance (radians)
) const;
bool IsPerpendicularTo(
// returns true: this and other vectors are perpendicular
// false: this and other vectors are not perpendicular
// or at least one of the vectors is zero
const ON_2fVector&, // other vector
double = ON_DEFAULT_ANGLE_TOLERANCE // optional angle tolerance (radians)
) const;
void Zero(); // set all coordinates to zero;
void Reverse(); // negate all coordinates
bool Unitize(); // returns false if vector has zero length
bool IsUnitVector() const;
// Description:
// Test a vector to see if it is very short
//
// Parameters:
// tiny_tol - [in] (default = ON_ZERO_TOLERANCE) a nonzero
// value used as the coordinate zero tolerance.
//
// Returns:
// ( fabs(x) <= tiny_tol && fabs(y) <= tiny_tol )
//
bool IsTiny(
double = ON_ZERO_TOLERANCE // tiny_tol
) const;
// Returns:
// true if vector is the zero vector.
bool IsZero() const;
// set this vector to be perpendicular to another vector
bool PerpendicularTo( // Result is not unitized.
// returns false if input vector is zero
const ON_2fVector&
);
// set this vector to be perpendicular to a line defined by 2 points
bool PerpendicularTo(
const ON_2fPoint&,
const ON_2fPoint&
);
};
ON_DECL
ON_2fVector operator*(int, const ON_2fVector&);
ON_DECL
ON_2fVector operator*(float, const ON_2fVector&);
ON_DECL
ON_2dVector operator*(double, const ON_2fVector&);
///////////////////////////////////////////////////////////////
//
// ON_2fVector utilities
//
ON_DECL
float
ON_DotProduct(
const ON_2fVector&,
const ON_2fVector&
);
ON_DECL
ON_3fVector
ON_CrossProduct(
const ON_2fVector&,
const ON_2fVector&
);
ON_DECL
bool
ON_IsOrthogonalFrame( // true if X, Y are nonzero and mutually perpendicular
const ON_2fVector&, // X
const ON_2fVector& // Y
);
ON_DECL
bool
ON_IsOrthonormalFrame( // true if X, Y are orthogonal and unit length
const ON_2fVector&, // X
const ON_2fVector& // Y
);
ON_DECL
bool
ON_IsRightHandFrame( // true if X, Y are orthonormal and right handed
const ON_2fVector&, // X
const ON_2fVector& // Y
);
////////////////////////////////////////////////////////////////
//
// ON_3fVector
//
class ON_CLASS ON_3fVector
{
public:
float x, y, z;
static const ON_3fVector ZeroVector; // (0.0f,0.0f,0.0f)
static const ON_3fVector XAxis; // (1.0f,0.0f,0.0f)
static const ON_3fVector YAxis; // (0.0f,1.0f,0.0f)
static const ON_3fVector ZAxis; // (0.0f,0.0f,1.0f)
// Description:
// A index driven function to get unit axis vectors.
// Parameters:
// index - [in] 0 returns (1,0,0), 1 returns (0,1,0)
// 2 returns (0,0,1)
// Returns:
// Unit 3d vector with vector[i] = (i==index)?1:0;
static const ON_3fVector& UnitVector(
int // index
);
// use implicit destructor, copy constructor
ON_3fVector(); // x,y,z not initialized
ON_3fVector(float x,float y,float z);
ON_3fVector(const ON_2fPoint& ); // from 2f point
ON_3fVector(const ON_3fPoint& ); // from 3f point
ON_3fVector(const ON_4fPoint& ); // from 4f point
ON_3fVector(const ON_2fVector& ); // from 2f vector
ON_3fVector(const float*); // from float[3] array
ON_3fVector(const ON_2dPoint& ); // from 2d point
ON_3fVector(const ON_3dPoint& ); // from 3d point
ON_3fVector(const ON_4dPoint& ); // from 4d point
ON_3fVector(const ON_2dVector& ); // from 2d vector
ON_3fVector(const ON_3dVector& ); // from 3d vector
ON_3fVector(const double*); // from double[3] array
// (float*) conversion operators
operator float*();
operator const float*() const;
// use implicit operator=(const ON_3fVector&)
ON_3fVector& operator=(const ON_2fPoint&);
ON_3fVector& operator=(const ON_3fPoint&);
ON_3fVector& operator=(const ON_4fPoint&);
ON_3fVector& operator=(const ON_2fVector&);
ON_3fVector& operator=(const float*); // point = float[3] support
ON_3fVector& operator=(const ON_2dPoint&);
ON_3fVector& operator=(const ON_3dPoint&);
ON_3fVector& operator=(const ON_4dPoint&);
ON_3fVector& operator=(const ON_2dVector&);
ON_3fVector& operator=(const ON_3dVector&);
ON_3fVector& operator=(const double*); // point = double[3] support
ON_3fVector operator-() const;
ON_3fVector& operator*=(float);
ON_3fVector& operator/=(float);
ON_3fVector& operator+=(const ON_3fVector&);
ON_3fVector& operator-=(const ON_3fVector&);
float operator*(const ON_3fVector&) const; // inner (dot) product
float operator*(const ON_3fPoint&) const; // inner (dot) product (point acting as a vector)
double operator*(const ON_3dVector&) const; // inner (dot) product
ON_3fVector operator*(int) const;
ON_3fVector operator/(int) const;
ON_3fVector operator*(float) const;
ON_3fVector operator/(float) const;
ON_3dVector operator*(double) const;
ON_3dVector operator/(double) const;
ON_3fVector operator+(const ON_3fVector&) const;
ON_3fPoint operator+(const ON_3fPoint&) const;
ON_3fVector operator-(const ON_3fVector&) const;
ON_3fPoint operator-(const ON_3fPoint&) const;
ON_3fVector operator+(const ON_2fVector&) const;
ON_3fPoint operator+(const ON_2fPoint&) const;
ON_3fVector operator-(const ON_2fVector&) const;
ON_3fPoint operator-(const ON_2fPoint&) const;
ON_3dVector operator+(const ON_3dVector&) const;
ON_3dPoint operator+(const ON_3dPoint&) const;
ON_3dVector operator-(const ON_3dVector&) const;
ON_3dPoint operator-(const ON_3dPoint&) const;
ON_3dVector operator+(const ON_2dVector&) const;
ON_3dPoint operator+(const ON_2dPoint&) const;
ON_3dVector operator-(const ON_2dVector&) const;
ON_3dPoint operator-(const ON_2dPoint&) const;
float operator*(const ON_4fPoint&) const;
bool operator==(const ON_3fVector&) const;
bool operator!=(const ON_3fVector&) const;
// dictionary order comparisons
bool operator<=(const ON_3fVector&) const;
bool operator>=(const ON_3fVector&) const;
bool operator<(const ON_3fVector&) const;
bool operator>(const ON_3fVector&) const;
// index operators mimic float[3] behavior
float& operator[](int);
float operator[](int) const;
float& operator[](unsigned int);
float operator[](unsigned int) const;
// set 3d vector value
void Set(float,float,float);
int MaximumCoordinateIndex() const;
double MaximumCoordinate() const; // absolute value of maximum coordinate
double LengthSquared() const;
double Length() const;
bool IsPerpendicularTo(
// returns true: this and other vectors are perpendicular
// false: this and other vectors are not perpendicular
// or at least one of the vectors is zero
const ON_3fVector&, // other vector
double = ON_DEFAULT_ANGLE_TOLERANCE // optional angle tolerance (radians)
) const;
double Fuzz( double = ON_ZERO_TOLERANCE ) const; // tolerance to use when comparing 3d vectors
void Zero(); // set all coordinates to zero
void Reverse(); // negate all coordinates
bool Unitize(); // returns false if vector has zero length
bool IsUnitVector() const;
// Description:
// Test a vector to see if it is very short
//
// Parameters:
// tiny_tol - [in] (default = ON_ZERO_TOLERANCE) a nonzero
// value used as the coordinate zero tolerance.
//
// Returns:
// ( fabs(x) <= tiny_tol && fabs(y) <= tiny_tol && fabs(z) <= tiny_tol )
//
bool IsTiny(
double = ON_ZERO_TOLERANCE // tiny_tol
) const;
// Returns:
// true if vector is the zero vector.
bool IsZero() const;
// set this vector to be perpendicular to another vector
bool PerpendicularTo( // Result is not unitized.
// returns false if input vector is zero
const ON_3fVector&
);
// These transform the vector in place. The transformation matrix acts on
// the left of the vector; i.e., result = transformation*vector
void Transform(
const ON_Xform& // can use ON_Xform here
);
void Rotate(
double, // angle in radians
const ON_3fVector& // axis of rotation
);
void Rotate(
double, // sin(angle)
double, // cos(angle)
const ON_3fVector& // axis of rotation
);
};
ON_DECL
ON_3fVector operator*(int, const ON_3fVector&);
ON_DECL
ON_3fVector operator*(float, const ON_3fVector&);
ON_DECL
ON_3dVector operator*(double, const ON_3fVector&);
///////////////////////////////////////////////////////////////
//
// ON_3fVector utilities
//
ON_DECL
float
ON_DotProduct(
const ON_3fVector&,
const ON_3fVector&
);
ON_DECL
ON_3fVector
ON_CrossProduct(
const ON_3fVector&,
const ON_3fVector&
);
ON_DECL
ON_3fVector
ON_CrossProduct( // 3d cross product for old fashioned arrays
const float*, // array of 3d floats
const float* // array of 3d floats
);
ON_DECL
float
ON_TripleProduct(
const ON_3fVector&,
const ON_3fVector&,
const ON_3fVector&
);
ON_DECL
float
ON_TripleProduct( // 3d triple product for old fashioned arrays
const float*, // array of 3d floats
const float*, // array of 3d floats
const float* // array of 3d floats
);
ON_DECL
bool
ON_IsOrthogonalFrame( // true if X, Y, Z are nonzero and mutually perpendicular
const ON_3fVector&, // X
const ON_3fVector&, // Y
const ON_3fVector& // Z
);
ON_DECL
bool
ON_IsOrthonormalFrame( // true if X, Y, Z are orthogonal and unit length
const ON_3fVector&, // X
const ON_3fVector&, // Y
const ON_3fVector& // Z
);
ON_DECL
bool
ON_IsRightHandFrame( // true if X, Y, Z are orthonormal and right handed
const ON_3fVector&, // X
const ON_3fVector&, // Y
const ON_3fVector& // Z
);
///////////////////////////////////////////////////////////////
//
// common points and vectors
//
// ON_forigin is OBSOLETE - use ON_3fPoint::Origin
extern ON_EXTERN_DECL const ON_3fPoint ON_forigin; // (0.0, 0.0, 0.0)
// ON_fxaxis is OBSOLETE - use ON_3fPoint::XAxis
extern ON_EXTERN_DECL const ON_3fVector ON_fxaxis; // (1.0, 0.0, 0.0)
// ON_fyaxis is OBSOLETE - use ON_3fVector::YAxis
extern ON_EXTERN_DECL const ON_3fVector ON_fyaxis; // (0.0, 1.0, 0.0)
// ON_fzaxis is OBSOLETE - use ON_3fVector::ZAxis
extern ON_EXTERN_DECL const ON_3fVector ON_fzaxis; // (0.0, 0.0, 1.0)
#endif

553
extern/opennurbs/opennurbs_fsp.cpp vendored Executable file
View File

@@ -0,0 +1,553 @@
#include "opennurbs.h"
ON_FixedSizePool::ON_FixedSizePool()
{
memset(this,0,sizeof(*this));
}
ON_FixedSizePool::~ON_FixedSizePool()
{
Destroy();
}
size_t ON_FixedSizePool::SizeofElement() const
{
return m_sizeof_element;
}
bool ON_FixedSizePool::Create(
size_t sizeof_element,
size_t element_count_estimate,
size_t block_element_capacity
)
{
if ( sizeof_element <= 0 )
{
ON_ERROR( "ON_FixedSizePool::Create - sizeof_element <= 0" );
return false;
}
if ( m_sizeof_element != 0 || 0 != m_first_block )
{
ON_ERROR( "ON_FixedSizePool::Create - called on a pool that is in use." );
return false;
}
memset(this,0,sizeof(*this));
m_sizeof_element = sizeof_element;
if ( block_element_capacity <= 0 )
{
size_t page_size = ON_MemoryPageSize();
if ( page_size < 512 )
page_size = 512;
// The "overhead" is for the 2*sizeof(void*) ON_FixedSizePool uses at
// the start of each block + 32 bytes extra for the heap manager
// to keep the total allocation not exceeding multiple of page_size.
const size_t overhead = 2*sizeof(void*) + 32;
size_t page_count = 1;
block_element_capacity = (page_count*page_size - overhead)/m_sizeof_element;
while ( block_element_capacity < 1000 )
{
page_count *= 2;
block_element_capacity = (page_count*page_size - overhead)/m_sizeof_element;
if (page_count > 8 && block_element_capacity > 64)
{
// for pools with large elements
break;
}
}
}
// capacity for the the 2nd and subsequent blocks
m_block_element_count = block_element_capacity;
// Set m_al_count = capacity of the first block.
// If the estimated number of elements is not too big,
// then make the first block that size.
if ( element_count_estimate > 0 )
{
// this is the first block and it has a custom size
if ( 8*m_block_element_count >= element_count_estimate )
m_al_count = element_count_estimate;
else
m_al_count = 8*m_block_element_count; // first block will be large
}
else
{
m_al_count = m_block_element_count;
}
return true;
}
void ON_FixedSizePool::ReturnAll()
{
if ( 0 != m_first_block )
{
// initialize
m_al_element_stack = 0;
m_qwerty_it_block = 0;
m_qwerty_it_element = 0;
m_al_block = m_first_block;
m_al_element_array = (void*)(((char*)m_al_block) + 2*sizeof(void*));
m_al_count = BlockElementCapacity(m_first_block);
m_active_element_count = 0;
m_total_element_count = 0;
}
}
void ON_FixedSizePool::Destroy()
{
void* p;
void* next;
next = m_first_block;
memset(this,0,sizeof(*this));
for ( p = next; 0 != p; p = next )
{
next = *((void**)p);
onfree(p);
}
}
void ON_FixedSizePool::EmergencyDestroy()
{
memset(this,0,sizeof(*this));
}
void ON_FixedSizePool::SetHeap( ON_MEMORY_POOL* heap )
{
m_heap = heap;
}
ON_MEMORY_POOL* ON_FixedSizePool::Heap()
{
return m_heap;
}
size_t ON_FixedSizePool::ActiveElementCount() const
{
return m_active_element_count;
}
size_t ON_FixedSizePool::TotalElementCount() const
{
return m_total_element_count;
}
void* ON_FixedSizePool::AllocateElement()
{
void* p;
if ( 0 != m_al_element_stack )
{
// use item on the returned stack first.
p = m_al_element_stack;
m_al_element_stack = *((void**)m_al_element_stack);
}
else
{
if ( 0 == m_al_block || 0 == m_al_count )
{
// No more memory left in m_al_block.
void* next_block = (0 != m_al_block)
? *((void**)m_al_block)
: 0;
if ( 0 == next_block )
{
// This if clause is used when we need to allocate a new block from the heap
if ( 0 == m_sizeof_element )
{
ON_ERROR("ON_FixedSizePool::AllocateElement - you must call ON_FixedSizePool::Create with a valid element size before using ON_FixedSizePool");
return 0;
}
// allocate a new block
if ( 0 == m_al_count )
m_al_count = m_block_element_count;
if ( m_al_count <= 0 )
{
ON_ERROR("ON_FixedSizePool::AllocateElement - you must call ON_FixedSizePool::Create with a valid element size before using ON_FixedSizePool");
return 0;
}
p = onmalloc_from_pool( m_heap, 2*sizeof(void*) + m_al_count*m_sizeof_element ); // get some heap
// set "next" pointer to zero
*((void**)p) = 0;
// set "end" pointer to address after last byte in the block
*((void**)(((char*)p) + sizeof(void*))) = ((char*)p) + (2*sizeof(void*) + m_al_count*m_sizeof_element);
if ( 0 == m_first_block )
{
m_first_block = p;
// If the call to Create() specified a positive element_count_estimate,
// then m_sizeof_block needs to be reset for any future block allocations.
}
else
{
// If m_first_block != 0, then m_al_block is nonzero (or memory for this class has been trashed)
*((void**)m_al_block) = p;
}
m_al_block = p;
}
else
{
// If we get here, ReturnAll() was used at some point in
// the past, m_al_block != 0, m_al_count = zero, and we are
// reusing blocks that were allocated early.
m_al_block = next_block;
m_al_count = BlockElementCapacity(m_al_block);
}
m_al_element_array = (void*)(((char*)m_al_block)+2*sizeof(void*));
}
m_al_count--;
p = m_al_element_array;
m_al_element_array = (void*)(((char*)m_al_element_array) + m_sizeof_element);
m_total_element_count++;
}
memset(p,0,m_sizeof_element);
m_active_element_count++;
return p;
}
void ON_FixedSizePool::ReturnElement(void* p)
{
if ( p )
{
if ( m_active_element_count <= 0 )
{
// If you get this error, something is seriously wrong.
// You may be returning the same element multiple times or
// you may be returning pointers that are not from this pool.
// In any case, you're probably going to be crashing sometime soon.
ON_ERROR("ON_FixedSizePool::ReturnElement - no active elements exist.");
}
else
{
m_active_element_count--;
*((void**)p) = m_al_element_stack;
m_al_element_stack = p;
}
}
}
ON_FixedSizePoolIterator::ON_FixedSizePoolIterator( const ON_FixedSizePool& fsp )
: m_fsp(fsp)
, m_it_block(0)
, m_it_element(0)
{}
void* ON_FixedSizePool::FirstElement()
{
if ( m_first_block && m_total_element_count > 0 )
{
m_qwerty_it_block = m_first_block;
m_qwerty_it_element = (void*)(((char*)m_qwerty_it_block)+2*sizeof(void*)); // m_qwerty_it_element points to first element in m_first_block
}
else
{
m_qwerty_it_block = 0;
m_qwerty_it_element = 0;
}
return m_qwerty_it_element;
}
void* ON_FixedSizePoolIterator::FirstElement()
{
if ( m_fsp.m_first_block && m_fsp.m_total_element_count > 0 )
{
m_it_block = m_fsp.m_first_block;
m_it_element = (void*)(((char*)m_it_block)+2*sizeof(void*)); // m_it_element points to first element in m_first_block
}
else
{
m_it_block = 0;
m_it_element = 0;
}
return m_it_element;
}
void* ON_FixedSizePool::NextElement()
{
if ( m_qwerty_it_element )
{
m_qwerty_it_element = (void*)(((char*)m_qwerty_it_element) + m_sizeof_element);
if ( m_qwerty_it_element == m_al_element_array )
{
m_qwerty_it_block = 0;
m_qwerty_it_element = 0;
}
else if ( m_qwerty_it_element == *((void**)(((char*)m_qwerty_it_block) + sizeof(void*))) )
{
// m_qwerty_it_element = "end" pointer which means we are at the end of m_qwerty_it_block
m_qwerty_it_block = *((void**)m_qwerty_it_block); // m_qwerty_it_block = "next" block
m_qwerty_it_element = (0 != m_qwerty_it_block) // m_qwerty_it_element points to first element in m_qwerty_it_block
? (void*)(((char*)m_qwerty_it_block)+2*sizeof(void*))
: 0;
if ( m_qwerty_it_element == m_al_element_array )
{
m_qwerty_it_block = 0;
m_qwerty_it_element = 0;
}
}
}
return m_qwerty_it_element;
}
void* ON_FixedSizePoolIterator::NextElement()
{
if ( m_it_element )
{
m_it_element = (void*)(((char*)m_it_element) + m_fsp.m_sizeof_element);
if ( m_it_element == m_fsp.m_al_element_array )
{
m_it_block = 0;
m_it_element = 0;
}
else if ( m_it_element == *((void**)(((char*)m_it_block) + sizeof(void*))) )
{
// m_it_element = "end" pointer which means we are at the end of m_it_block
m_it_block = *((void**)m_it_block); // m_it_block = "next" block
m_it_element = (0 != m_it_block) // m_it_element points to first element in m_it_block
? (void*)(((char*)m_it_block)+2*sizeof(void*))
: 0;
if ( m_it_element == m_fsp.m_al_element_array )
{
m_it_block = 0;
m_it_element = 0;
}
}
}
return m_it_element;
}
void* ON_FixedSizePool::FirstElement(size_t element_index)
{
const char* block;
const char* block_end;
const char* next_block;
size_t block_count;
m_qwerty_it_block = 0;
m_qwerty_it_element = 0;
if ( element_index < m_total_element_count )
{
for ( block = (const char*)m_first_block; 0 != block; block = next_block )
{
if ( block == m_al_block )
{
next_block = 0;
block_end = (const char*)m_al_element_array;
}
else
{
next_block = *((const char**)block);
block_end = *((const char**)(block + sizeof(void*)));
}
block_count = (block_end - block)/m_sizeof_element;
if ( element_index < block_count )
{
m_qwerty_it_block = (void*)block;
m_qwerty_it_element = ((void*)(block + (2*sizeof(void*) + element_index*m_sizeof_element)));
break;
}
element_index -= block_count;
}
}
return m_qwerty_it_element;
}
void* ON_FixedSizePoolIterator::FirstElement(size_t element_index)
{
const char* block;
const char* block_end;
const char* next_block;
size_t block_count;
m_it_block = 0;
m_it_element = 0;
if ( element_index < m_fsp.m_total_element_count )
{
for ( block = (const char*)m_fsp.m_first_block; 0 != block; block = next_block )
{
if ( block == m_fsp.m_al_block )
{
next_block = 0;
block_end = (const char*)m_fsp.m_al_element_array;
}
else
{
next_block = *((const char**)block);
block_end = *((const char**)(block + sizeof(void*)));
}
block_count = (block_end - block)/m_fsp.m_sizeof_element;
if ( element_index < block_count )
{
m_it_block = (void*)block;
m_it_element = ((void*)(block + (2*sizeof(void*) + element_index*m_fsp.m_sizeof_element)));
break;
}
element_index -= block_count;
}
}
return m_it_element;
}
size_t ON_FixedSizePool::BlockElementCapacity( const void* block ) const
{
// returns number of items that can be allocated from block
if ( 0 == block || m_sizeof_element <= 0 )
return 0;
char* block_end = *((char**)(((char*)block)+sizeof(void*)));
return (block_end - ((char*)block))/m_sizeof_element;
}
size_t ON_FixedSizePool::BlockElementCount( const void* block ) const
{
// returns number of items allocated from block
if ( 0 == block || m_sizeof_element <= 0 )
return 0;
char* block_end = (block == m_al_block && m_al_count > 0)
? ((char*)m_al_element_array)
: *((char**)(((char*)block)+sizeof(void*)));
return (block_end - ((char*)block))/m_sizeof_element;
}
void* ON_FixedSizePool::FirstBlock( size_t* block_element_count )
{
if ( m_first_block && m_total_element_count > 0 )
{
m_qwerty_it_block = m_first_block;
m_qwerty_it_element = (void*)(((char*)m_qwerty_it_block)+2*sizeof(void*)); // m_qwerty_it_element points to first element in m_first_block
if ( 0 != block_element_count )
*block_element_count = BlockElementCount(m_qwerty_it_block);
}
else
{
m_qwerty_it_block = 0;
m_qwerty_it_element = 0;
if ( 0 != block_element_count )
*block_element_count = 0;
}
return m_qwerty_it_element;
}
void* ON_FixedSizePoolIterator::FirstBlock( size_t* block_element_count )
{
if ( m_fsp.m_first_block && m_fsp.m_total_element_count > 0 )
{
m_it_block = m_fsp.m_first_block;
m_it_element = (void*)(((char*)m_it_block)+2*sizeof(void*)); // m_it_element points to first element in m_first_block
if ( 0 != block_element_count )
*block_element_count = m_fsp.BlockElementCount(m_it_block);
}
else
{
m_it_block = 0;
m_it_element = 0;
if ( 0 != block_element_count )
*block_element_count = 0;
}
return m_it_element;
}
void* ON_FixedSizePool::NextBlock( size_t* block_element_count )
{
if ( 0 != m_qwerty_it_block
&& m_qwerty_it_block != m_al_block
&& m_qwerty_it_element == (void*)(((char*)m_qwerty_it_block)+2*sizeof(void*)) )
{
m_qwerty_it_block = *((void**)m_qwerty_it_block);
if ( m_qwerty_it_block == m_al_element_array )
{
m_qwerty_it_block = 0;
m_qwerty_it_element = 0;
if ( 0 != block_element_count )
*block_element_count = 0;
}
else
{
m_qwerty_it_element = (void*)(((char*)m_qwerty_it_block)+2*sizeof(void*)); // m_qwerty_it_element points to first element in m_first_block
if ( 0 != block_element_count )
*block_element_count = BlockElementCount(m_qwerty_it_block);
}
}
else
{
m_qwerty_it_block = 0;
m_qwerty_it_element = 0;
if ( 0 != block_element_count )
*block_element_count = 0;
}
return m_qwerty_it_element;
}
void* ON_FixedSizePoolIterator::NextBlock( size_t* block_element_count )
{
if ( 0 != m_it_block
&& m_it_block != m_fsp.m_al_block
&& m_it_element == (void*)(((char*)m_it_block)+2*sizeof(void*)) )
{
m_it_block = *((void**)m_it_block);
if ( m_it_block == m_fsp.m_al_element_array )
{
m_it_block = 0;
m_it_element = 0;
if ( 0 != block_element_count )
*block_element_count = 0;
}
else
{
m_it_element = (void*)(((char*)m_it_block)+2*sizeof(void*)); // m_it_element points to first element in m_first_block
if ( 0 != block_element_count )
*block_element_count = m_fsp.BlockElementCount(m_it_block);
}
}
else
{
m_it_block = 0;
m_it_element = 0;
if ( 0 != block_element_count )
*block_element_count = 0;
}
return m_it_element;
}
void* ON_FixedSizePool::Element(size_t element_index) const
{
const char* block;
const char* block_end;
const char* next_block;
size_t block_count;
for ( block = (const char*)m_first_block; 0 != block; block = next_block )
{
if ( block == m_al_block )
{
next_block = 0;
block_end = (const char*)m_al_element_array;
}
else
{
next_block = *((const char**)block);
block_end = *((const char**)(block + sizeof(void*)));
}
block_count = (block_end - block)/m_sizeof_element;
if ( element_index < block_count )
return ((void*)(block + (2*sizeof(void*) + element_index*m_sizeof_element)));
element_index -= block_count;
}
return 0;
}

754
extern/opennurbs/opennurbs_fsp.h vendored Executable file
View File

@@ -0,0 +1,754 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_FSP_INC_)
#define OPENNURBS_FSP_INC_
class ON_CLASS ON_FixedSizePool
{
public:
ON_FixedSizePool();
~ON_FixedSizePool();
/*
Description:
Create a fixed size memory pool.
Parameters:
sizeof_element - [in]
number of bytes in each element. This parameter must be greater than zero.
In general, use sizeof(element type). If you pass a "raw" number as
sizeof_element, then be certain that it is the right size to insure the
fields in your elements will be properly aligned.
element_count_estimate - [in] (0 = good default)
If you know how many elements you will need, pass that number here.
It is better to slightly overestimate than to slightly underestimate.
If you do not have a good estimate, then use zero.
block_element_capacity - [in] (0 = good default)
If block_element_capacity is zero, Create() will calculate a block
size that is efficent for most applications. If you are an expert
user and want to specify the number of elements per block,
then pass the number of elements per block here. When
block_element_capacity > 0 and element_count_estimate > 0, the first
block will have a capacity of at least element_count_estimate; in this
case do not ask for extraordinarly large amounts of contiguous heap.
Remarks:
You must call Create() on an unused ON_FixedSizePool or call Destroy()
before calling create.
Returns:
True if successful and the pool can be used.
*/
bool Create(
size_t sizeof_element,
size_t element_count_estimate,
size_t block_element_capacity
);
/*
Returns:
Size of the elements in this pool.
*/
size_t SizeofElement() const;
/*
Returns:
A pointer to sizeof_element bytes. The memory is zeroed.
*/
void* AllocateElement();
/*
Description:
Return an element to the pool.
Parameters:
p - [in]
A pointer returned by AllocateElement().
It is critical that p be from this pool and that
you return a pointer no more than one time.
Remarks:
If you find the following remarks confusing, but you really want to use
ReturnElement(), then here are some simple guidelines.
1) SizeofElement() must be >= 16
2) SizeofElement() must be a multiple of 8.
3) Do not use FirstElement() and NextElement() to iterate through
the pool.
If 1 to 3 don't work for you, then you need to understand the following
information before using ReturnElement().
ON_FixedMemoryPool uses the first sizeof(void*) bytes of the
returned element for bookkeeping purposes. Therefore, if you
are going to use ReturnElement(), then SizeofElement() must be
at least sizeof(void*). If you are using a platform that requires
pointers to be aligned on sizeof(void*) boundaries, then
SizeofElement() must be a multiple of sizeof(void*).
If you are going to use ReturnElement() and then use FirstElement()
and NextElement() to iterate through the list of elements, then you
need to set a value in the returned element to indicate that it
needs to be skipped during the iteration. This value cannot be
located in the fist sizeof(void*) bytes of the element. If the
element is a class with a vtable, you cannot call a virtual
function on a returned element because the vtable pointer is
trashed when ReturnElement() modifies the fist sizeof(void*) bytes.
*/
void ReturnElement(void* p);
/*
Description:
Return all allocated elements to the pool. No heap is freed and
the pool remains initialized and ready for AllocateElement()
to be called.
*/
void ReturnAll();
/*
Description:
Destroy the pool and free all the heap. The pool cannot be used again
until Create() is called.
*/
void Destroy();
/*
Returns:
Number of active elements. (Elements that have been returned are not active.)
*/
size_t ActiveElementCount() const;
/*
Returns:
Total number of elements = number of active elements + number of returned elements.
*/
size_t TotalElementCount() const;
/*
Description:
Get the first element when iterating through the list of elements.
Parameters:
element_index - [in]
If you use the version of FirstElement() that has an
element_index parameter, then the iteration begins at
that element.
Example:
The loop will iteratate through all the elements returned from
AllocateElement(), including any that have be returned to the pool
using ReturnElement().
// iterate through all elements in the pool
// This iteration will go through TotalElements() items.
for ( void* p = FirstElement(); 0 != p; p = NextElement() )
{
// If you are not using ReturnElement(), then you may process
// "p" immediately. If you have used ReturnElement(), then you
// must check some value in p located after the first sizeof(void*)
// bytes to see if p is active.
if ( p is not active )
continue;
... process p
}
Returns:
The first element when iterating through the list of elements.
Remarks:
FirstElement() and NextElement() will return elements that have
been returned to the pool using ReturnElement(). If you use
ReturnElement(), then be sure to mark the element so it can be
identified and skipped.
Do not make any calls to FirstBlock() or NextBlock() when using
FirstElement() and NextElement() to iteratate through elements.
If you need iterate through a fixed size pool and another
function may also be in the middle of iterating the pool
as well, then use ON_FixedSizePoolIterator. In particular,
if you have multiple concurrent threads iterating the same
fixed size pool, then use ON_FixedSizePoolIterator.
*/
void* FirstElement();
void* FirstElement( size_t element_index );
/*
Description:
Get the next element when iterating through the list of elements.
Example:
See the FirstElement() documentation.
Returns:
The next element when iterating through the list of elements.
Remarks:
FirstElement() and NextElement() will return elements that have
been returned to the pool using ReturnElement(). If you use
ReturnElement(), then be sure to mark the element so it can be
identified and skipped.
Do not make any calls to FirstBlock() or NextBlock() when using
FirstElement() and NextElement() to iteratate through elements.
If you need iterate through a fixed size pool and another
function may also be in the middle of iterating the pool
as well, then use ON_FixedSizePoolIterator. In particular,
if you have multiple concurrent threads iterating the same
fixed size pool, then use ON_FixedSizePoolIterator.
*/
void* NextElement();
/*
Description:
Get a pointer to the first element in the first block.
Parameters:
block_element_count - [out] (can be null)
If not null, the number of elements allocated from the
first block is returned in block_element_count.
Note that if you have used ReturnElement(), some
of these elemements may have been returned.
Example:
The loop will iteratate through all the blocks.
// iterate through all blocks in the pool
size_t block_element_count = 0;
for ( void* p = FirstBlock(&block_element_count);
0 != p;
p = NextBlock(&block_element_count)
)
{
ElementType* e = (ElementType*)p;
for ( size_t i = 0;
i < block_element_count;
i++, e = ((const char*)e) + SizeofElement()
)
{
...
}
}
Returns:
The first block when iterating the list of blocks.
Remarks:
The heap for a fixed size memory pool is simply a linked
list of blocks. FirstBlock() and NextBlock() can be used
to iterate through the list of blocks.
Do not make any calls to FirstElement() or NextElement() when using
FirstBlock() and NextBlock() to iteratate through blocks.
If you need iterate through a fixed size pool and another
function may also be in the middle of iterating the pool
as well, then use ON_FixedSizePoolIterator. In particular,
if you have multiple concurrent threads iterating the same
fixed size pool, then use ON_FixedSizePoolIterator.
*/
void* FirstBlock( size_t* block_element_count );
/*
Description:
Get the next block when iterating through the blocks.
Parameters:
block_element_count - [out] (can be null)
If not null, the number of elements allocated from the
block is returned in block_element_count. Note that if
you have used ReturnElement(), some of these elemements
may have been returned.
Example:
See the FirstBlock() documentation.
Returns:
The next block when iterating through the blocks.
Remarks:
Do not make any calls to FirstElement() or NextElement() when using
FirstBlock() and NextBlock() to iteratate through blocks.
If you need iterate through a fixed size pool and another
function may also be in the middle of iterating the pool
as well, then use ON_FixedSizePoolIterator. In particular,
if you have multiple concurrent threads iterating the same
fixed size pool, then use ON_FixedSizePoolIterator.
*/
void* NextBlock( size_t* block_element_count );
/*
Description:
Get the i-th elment in the pool.
Parameters:
element_index - [in]
Returns:
A pointer to the i-th element. The first element has index = 0
and is the element returned by the first call to AllocateElement().
The last element has index = ElementCount()-1.
If i is out of range, null is returned.
Remarks:
It is faster to use FirstElement() and NextElement() to iterate
through the entire list of elements. This function is relatively
efficient when there are a few large blocks in the pool
or element_index is small compared to the number of elements
in the first few blocks.
If ReturnElement() is not used or AllocateElement() calls to
are made after any use of ReturnElement(), then the i-th
element is the one returned by the (i+1)-th call to
AllocateElement().
*/
void* Element(size_t element_index) const;
public:
// Expert user functions below for situations where you
// need to specify the heap used for this pool.
/*
Description:
Expert user function to specify which heap is used.
*/
void SetHeap( ON_MEMORY_POOL* heap );
/*
Description:
Expert user function.
Returns:
Heap used by this pool. A null pointer means the default
heap is being used.
*/
ON_MEMORY_POOL* Heap();
/*
Description:
Expert user function to call when the heap used by this pool
is no longer valid. This call zeros all fields and does not
call any heap functions. After calling EmergencyDestroy(),
the destructor will not attempt to free any heap.
*/
void EmergencyDestroy();
private:
friend class ON_FixedSizePoolIterator;
void* m_first_block;
// ReturnElement() adds to the m_al_element stack.
// AllocateElement() will use the stack before using m_al_element_array[]
void* m_al_element_stack;
// used by the iterators
void* m_qwerty_it_block;
void* m_qwerty_it_element;
void* m_al_block; // current element allocation block.
// m_al_element_array[] is in m_al_block and has length m_al_count.
void* m_al_element_array;
size_t m_al_count;
size_t m_sizeof_element;
size_t m_block_element_count; // block element count
size_t m_active_element_count; // number of active elements
size_t m_total_element_count; // total number of elements (active + returned)
ON_MEMORY_POOL* m_heap;
private:
// returns capacity of elements in existing block
size_t BlockElementCapacity( const void* block ) const;
// returns number of allocated of elements in existing block
size_t BlockElementCount( const void* block ) const;
private:
// prohibit copy construction and operator=.
ON_FixedSizePool(const ON_FixedSizePool&);
ON_FixedSizePool& operator=(const ON_FixedSizePool&);
};
class ON_CLASS ON_FixedSizePoolIterator
{
public:
ON_FixedSizePoolIterator( const class ON_FixedSizePool& fsp );
const class ON_FixedSizePool& m_fsp;
/*
Description:
Get the first element when iterating through the list of elements.
Parameters:
element_index - [in]
If you use the version of FirstElement() that has an
element_index parameter, then the iteration begins at
that element.
Example:
The loop will iteratate through all the elements returned from
AllocateElement(), including any that have be returned to the pool
using ReturnElement().
// iterate through all elements in the pool
// This iteration will go through TotalElements() items.
for ( void* p = FirstElement(); 0 != p; p = NextElement() )
{
// If you are not using ReturnElement(), then you may process
// "p" immediately. If you have used ReturnElement(), then you
// must check some value in p located after the first sizeof(void*)
// bytes to see if p is active.
if ( p is not active )
continue;
... process p
}
Returns:
The first element when iterating through the list of elements.
Remarks:
FirstElement() and NextElement() will return elements that have
been returned to the pool using ReturnElement(). If you use
ReturnElement(), then be sure to mark the element so it can be
identified and skipped.
Do not make any calls to FirstBlock() or NextBlock() when using
FirstElement() and NextElement() to iteratate through elements.
*/
void* FirstElement();
void* FirstElement( size_t element_index );
/*
Description:
Get the next element when iterating through the list of elements.
Example:
See the FirstElement() documentation.
Returns:
The next element when iterating through the list of elements.
Remarks:
FirstElement() and NextElement() will return elements that have
been returned to the pool using ReturnElement(). If you use
ReturnElement(), then be sure to mark the element so it can be
identified and skipped.
Do not make any calls to FirstBlock() or NextBlock() when using
FirstElement() and NextElement() to iteratate through elements.
*/
void* NextElement();
/*
Description:
Get a pointer to the first element in the first block.
Parameters:
block_element_count - [out] (can be null)
If not null, the number of elements allocated from the
first block is returned in block_element_count.
Note that if you have used ReturnElement(), some
of these elemements may have been returned.
Example:
The loop will iteratate through all the blocks.
// iterate through all blocks in the pool
size_t block_element_count = 0;
for ( void* p = FirstBlock(&block_element_count);
0 != p;
p = NextBlock(&block_element_count)
)
{
ElementType* e = (ElementType*)p;
for ( size_t i = 0;
i < block_element_count;
i++, e = ((const char*)e) + SizeofElement()
)
{
...
}
}
Returns:
The first block when iterating the list of blocks.
Remarks:
The heap for a fixed size memory pool is simply a linked
list of blocks. FirstBlock() and NextBlock() can be used
to iterate through the list of blocks.
Do not make any calls to FirstElement() or NextElement() when using
FirstBlock() and NextBlock() to iteratate through blocks.
*/
void* FirstBlock( size_t* block_element_count );
/*
Description:
Get the next block when iterating through the blocks.
Parameters:
block_element_count - [out] (can be null)
If not null, the number of elements allocated from the
block is returned in block_element_count. Note that if
you have used ReturnElement(), some of these elemements
may have been returned.
Example:
See the FirstBlock() documentation.
Returns:
The next block when iterating through the blocks.
Remarks:
Do not make any calls to FirstElement() or NextElement() when using
FirstBlock() and NextBlock() to iteratate through blocks.
*/
void* NextBlock( size_t* block_element_count );
private:
void* m_it_block;
void* m_it_element;
// no implementation (you can use a copy construtor)
ON_FixedSizePoolIterator& operator=(const ON_FixedSizePoolIterator&);
};
template <class T> class ON_SimpleFixedSizePool : private ON_FixedSizePool
{
public:
// construction ////////////////////////////////////////////////////////
ON_SimpleFixedSizePool();
~ON_SimpleFixedSizePool();
/*
Description:
Create a fixed size memory pool.
Parameters:
element_count_estimate - [in] (0 = good default)
If you know how many elements you will need, pass that number here.
It is better to slightly overestimate than to slightly underestimate.
If you do not have a good estimate, then use zero.
block_element_count - [in] (0 = good default)
If block_element_count is zero, Create() will calculate a block
size that is efficent for most applications. If you are an expert
user and want to specify the number of blocks, then pass the number
of elements per block here. When block_element_count > 0 and
element_count_estimate > 0, the first block will be large enough
element_count_estimate*sizeof(T) bytes; in this case do not
ask for extraordinarly large amounts of contiguous heap.
Remarks:
You must call Create() on an unused ON_FixedSizePool or call Destroy()
before calling create.
Returns:
True if successful and the pool can be used.
*/
bool Create(
size_t element_count_estimate,
size_t block_element_count
);
/*
Returns:
Size of the elements in this pool.
*/
size_t SizeofElement() const;
/*
Returns:
A pointer to sizeof_element bytes. The memory is zeroed.
*/
T* AllocateElement();
/*
Description:
Return an element to the pool.
Parameters:
p - [in]
A pointer returned by AllocateElement().
It is critical that p be from this pool and that
you return a pointer no more than one time.
Remarks:
If you find the following remarks confusing, but you really want to use
ReturnElement(), then here are some simple guidelines.
1) SizeofElement() must be >= 16
2) SizeofElement() must be a multiple of 8.
3) Do not use FirstElement() and NextElement() to iterate through
the pool.
If 1 to 3 don't work for you, then you need to understand the following
information before using ReturnElement().
ON_FixedMemoryPool uses the first sizeof(void*) bytes of the
returned element for bookkeeping purposes. Therefore, if you
are going to use ReturnElement(), then SizeofElement() must be
at least sizeof(void*). If you are using a platform that requires
pointers to be aligned on sizeof(void*) boundaries, then
SizeofElement() must be a multiple of sizeof(void*).
If you are going to use ReturnElement() and then use FirstElement()
and NextElement() to iterate through the list of elements, then you
need to set a value in the returned element to indicate that it
needs to be skipped during the iteration. This value cannot be
located in the fist sizeof(void*) bytes of the element. If the
element is a class with a vtable, you cannot call a virtual
function on a returned element because the vtable pointer is
trashed when ReturnElement() modifies the fist sizeof(void*) bytes.
*/
void ReturnElement(T* p);
/*
Description:
Return all allocated elements to the pool. No heap is freed and
the pool remains initialized and ready for AllocateElement()
to be called.
*/
void ReturnAll();
/*
Description:
Destroy the pool and free all the heap. The pool cannot be used again
until Create() is called.
*/
void Destroy();
/*
Returns:
Number of active elements. (Elements that have been returned are not active.)
*/
size_t ActiveElementCount() const;
/*
Returns:
Total number of elements = number of active elements + number of returned elements.
*/
size_t TotalElementCount() const;
/*
Description:
Get the next element when iterating through the active elements.
Example:
The loop will iteratate through all the elements returned from
AllocateElement(), including any that have be returned to the pool
using ReturnElement().
// iterate through all elements in the pool
for ( T* p = FirstElement(); 0 != p; p = NextElement() )
{
// If you are not using ReturnElement(), then you may process
// "p" immediately. If you have used ReturnElement(), then you
// must check some value in p located after the first sizeof(void*)
// bytes to see if p is active.
if ( p is not active )
continue;
... process p
}
Returns:
The next element when iterating through the active elements.
Remarks:
NextElement() will return elements that have been returned to
the pool using ReturnElement(). If you use ReturnElement(),
be sure to mark the element so it can be identified and skipped.
*/
T* FirstElement();
/*
Description:
Get the next element when iterating through the active elements.
Example:
See the FirstElement() documentation.
Returns:
The next element when iterating through the active elements.
Remarks:
NextElement() will return elements that have been returned to
the pool using ReturnElement(). If you use ReturnElement(),
be sure to mark the element so it can be identified and skipped.
*/
T* NextElement();
/*
Description:
Get a pointer to the first element in the first block.
Example:
The loop will iteratate through all the blocks.
// iterate through all blocks in the pool
size_t block_element_count = 0;
for ( T* p = FirstBlock(&block_element_count);
0 != p;
p = NextBlock(&block_element_count)
)
{
// a[] is an array of length block_element_count
}
Returns:
The next block when iterating the list of blocks.
Remarks:
Do not make any calls to FirstElement() or NextElement() when using
FirstBlock() and NextBlock() to iteratate through blocks.
*/
T* FirstBlock( size_t* block_element_count );
/*
Description:
Get the next block when iterating through the blocks.
Example:
See the FirstBlock() documentation.
Returns:
The next block when iterating through the blocks.
Remarks:
Do not make any calls to FirstElement() or NextElement() when using
FirstBlock() and NextBlock() to iteratate through blocks.
*/
T* NextBlock( size_t* block_element_count );
/*
Description:
Get the i-th elment in the pool.
Parameters:
element_index - [in]
Returns:
A pointer to the i-th element. The first element has index = 0
and is the element returned by the first call to AllocateElement().
The last element has index = ElementCount()-1.
If i is out of range, null is returned.
Remarks:
It is faster to use FirstElement() and NextElement() to iterate
through the entire list of elements. This function is relatively
efficient when there are a few large blocks in the pool
or element_index is small compared to the number of elements
in the first few blocks.
If ReturnElement() is not used or AllocateElement() calls to
are made after any use of ReturnElement(), then the i-th
element is the one returned by the (i+1)-th call to
AllocateElement().
*/
T* Element(size_t element_index) const;
public:
// Expert user functions below for situations where you
// need to specify the heap used for this pool.
/*
Description:
Expert user function to specify which heap is used.
*/
void SetHeap( ON_MEMORY_POOL* heap );
/*
Description:
Expert user function.
Returns:
Heap used by this pool. A null pointer means the default
heap is being used.
*/
ON_MEMORY_POOL* Heap();
/*
Description:
Expert user function to call when the heap used by this pool
is no longer valid. This call zeros all fields and does not
call any heap functions. After calling EmergencyDestroy(),
the destructor will not attempt to free any heap.
*/
void EmergencyDestroy();
private:
// prohibit copy construction and operator=.
ON_SimpleFixedSizePool(const ON_SimpleFixedSizePool<T>&);
ON_SimpleFixedSizePool<T>& operator=(const ON_SimpleFixedSizePool<T>&);
};
// definitions of the template functions are in a different file
// so that Microsoft's developer studio's autocomplete utility
// will work on the template functions.
#include "opennurbs_fsp_defs.h"
#endif

130
extern/opennurbs/opennurbs_fsp_defs.h vendored Executable file
View File

@@ -0,0 +1,130 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(ON_FSP_DEFS_INC_)
#define ON_FSP_DEFS_INC_
template <class T>
ON_SimpleFixedSizePool<T>::ON_SimpleFixedSizePool()
: ON_FixedSizePool()
{}
template <class T>
ON_SimpleFixedSizePool<T>::~ON_SimpleFixedSizePool()
{
ON_FixedSizePool::Destroy();
}
template <class T>
bool ON_SimpleFixedSizePool<T>::Create(
size_t element_count_estimate,
size_t block_element_count
)
{
return ON_FixedSizePool::Create(sizeof(T),element_count_estimate,block_element_count);
}
template <class T>
size_t ON_SimpleFixedSizePool<T>::SizeofElement() const
{
return ON_FixedSizePool::SizeofElement();
}
template <class T>
T* ON_SimpleFixedSizePool<T>::AllocateElement()
{
return (T *)ON_FixedSizePool::AllocateElement();
}
template <class T>
void ON_SimpleFixedSizePool<T>::ReturnElement(T* p)
{
ON_FixedSizePool::ReturnElement(p);
}
template <class T>
void ON_SimpleFixedSizePool<T>::ReturnAll()
{
ON_FixedSizePool::ReturnAll();
}
template <class T>
void ON_SimpleFixedSizePool<T>::Destroy()
{
ON_FixedSizePool::Destroy();
}
template <class T>
size_t ON_SimpleFixedSizePool<T>::ActiveElementCount() const
{
return ON_FixedSizePool::ActiveElementCount();
}
template <class T>
size_t ON_SimpleFixedSizePool<T>::TotalElementCount() const
{
return ON_FixedSizePool::TotalElementCount();
}
template <class T>
T* ON_SimpleFixedSizePool<T>::FirstElement()
{
return (T *)ON_FixedSizePool::FirstElement();
}
template <class T>
T* ON_SimpleFixedSizePool<T>::NextElement()
{
return (T *)ON_FixedSizePool::NextElement();
}
template <class T>
T* ON_SimpleFixedSizePool<T>::FirstBlock( size_t* block_element_count )
{
return (T *)ON_FixedSizePool::FirstBlock(block_element_count);
}
template <class T>
T* ON_SimpleFixedSizePool<T>::NextBlock( size_t* block_element_count )
{
return (T *)ON_FixedSizePool::NextBlock(block_element_count);
}
template <class T>
T* ON_SimpleFixedSizePool<T>::Element(size_t element_index) const
{
return (T *)ON_FixedSizePool::Element(element_index);
}
template <class T>
void ON_SimpleFixedSizePool<T>::SetHeap( ON_MEMORY_POOL* heap )
{
ON_FixedSizePool::SetHeap(heap);
}
template <class T>
ON_MEMORY_POOL* ON_SimpleFixedSizePool<T>::Heap()
{
return ON_FixedSizePool::Heap();
}
template <class T>
void ON_SimpleFixedSizePool<T>::EmergencyDestroy()
{
ON_FixedSizePool::EmergencyDestroy();
}
#endif

254
extern/opennurbs/opennurbs_geometry.cpp vendored Executable file
View File

@@ -0,0 +1,254 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
ON_VIRTUAL_OBJECT_IMPLEMENT(ON_Geometry,ON_Object,"4ED7D4DA-E947-11d3-BFE5-0010830122F0");
ON_Geometry::ON_Geometry()
{}
ON_Geometry::ON_Geometry(const ON_Geometry& src) : ON_Object(src)
{}
ON_Geometry& ON_Geometry::operator=(const ON_Geometry& src)
{
ON_Object::operator=(src);
return *this;
}
ON_Geometry::~ON_Geometry()
{}
ON_BoundingBox ON_Geometry::BoundingBox() const
{
ON_BoundingBox bbox;
if ( !GetBoundingBox( bbox.m_min, bbox.m_max, false ) )
bbox.Destroy();
return bbox;
}
ON_BOOL32
ON_Geometry::GetBoundingBox( // returns true if successful
ON_BoundingBox& bbox,
ON_BOOL32 bGrowBox
) const
{
return GetBoundingBox( bbox.m_min, bbox.m_max, bGrowBox );
}
ON_BOOL32
ON_Geometry::GetBoundingBox( // returns true if successful
ON_3dPoint& boxmin,
ON_3dPoint& boxmax,
ON_BOOL32 bGrowBox
) const
{
ON_Workspace ws;
const int dim = Dimension();
double *bmin, *bmax;
if ( dim <= 3 ) {
bmin = &boxmin.x;
bmax = &boxmax.x;
}
else {
bmin = ws.GetDoubleMemory(dim*2);
bmax = bmin+dim;
memset( bmin, 0, 2*dim*sizeof(*bmin) );
if ( bGrowBox ) {
bmin[0] = boxmin.x; bmin[1] = boxmin.y; bmin[1] = boxmin.z;
bmax[0] = boxmax.x; bmax[1] = boxmax.y; bmax[1] = boxmax.z;
}
}
// Treat invalid box on input as empty
bool invalid=false; //input box invalid=empty
if(bGrowBox)
invalid = boxmin.x>boxmax.x || boxmin.y>boxmax.y|| boxmin.z>boxmax.z;
if(bGrowBox && invalid)
bGrowBox=false;
const ON_BOOL32 rc = GetBBox( bmin, bmax, bGrowBox );
if ( dim > 3 ) {
boxmin.x = bmin[0]; boxmin.y = bmin[1]; boxmin.z = bmin[2];
boxmax.x = bmax[0]; boxmax.y = bmax[1]; boxmax.z = bmax[2];
}
else if ( dim <= 2 ) {
boxmin.z = 0.0;
boxmax.z = 0.0;
if ( dim <= 1 ) {
boxmin.y = 0.0;
boxmax.y = 0.0;
}
}
return rc;
}
bool ON_Geometry::GetTightBoundingBox(
ON_BoundingBox& tight_bbox,
int bGrowBox,
const ON_Xform* xform
) const
{
// This implementation should be overridden by classes devived
// from ON_Geometry
if ( bGrowBox && !tight_bbox.IsValid() )
{
bGrowBox = false;
}
if ( !bGrowBox )
{
tight_bbox.Destroy();
}
if ( xform && !xform->IsIdentity() )
{
ON_3dPointArray corners(8);
ON_BoundingBox world_bbox;
if ( GetBoundingBox(world_bbox,false) )
{
world_bbox.GetCorners(corners);
if ( corners.GetTightBoundingBox(tight_bbox,bGrowBox,xform) )
bGrowBox = true;
}
}
else
{
if ( GetBoundingBox(tight_bbox,bGrowBox) )
bGrowBox = true;
}
return bGrowBox?true:false;
}
ON_BOOL32 ON_Geometry::SwapCoordinates(
int i, int j // indices of coords to swap
)
{
ON_BOOL32 rc = false;
const int dim = Dimension();
if ( dim > 0 && dim <= 3 && i >= 0 && i < 3 && j >= 0 && j < 3 ) {
if ( i == j ) {
rc = true;
}
else {
int k;
ON_Xform swapij(0.0);
for ( k = 0; k < 4; k++ ) {
if ( i == k )
swapij[k][j] = 1.0;
else if ( j == k )
swapij[k][i] = 1.0;
else
swapij[k][k] = 1.0;
}
rc = Transform( swapij );
}
}
return rc;
}
ON_BOOL32 ON_Geometry::Rotate(
double sin_angle, // sin(angle)
double cos_angle, // cos(angle)
const ON_3dVector& axis, // axis of rotation
const ON_3dPoint& center // center of rotation
)
{
if ( sin_angle == 0.0 && cos_angle == 1.0 )
return true;
ON_Xform rot;
rot.Rotation( sin_angle, cos_angle, axis, center );
return Transform( rot );
}
ON_BOOL32 ON_Geometry::Rotate(
double angle, // angle in radians
const ON_3dVector& axis, // axis of rotation
const ON_3dPoint& center // center of rotation
)
{
if ( angle == 0.0 )
return true;
return Rotate( sin(angle), cos(angle), axis, center );
}
ON_BOOL32 ON_Geometry::Translate( const ON_3dVector& delta )
{
if ( delta.IsZero() )
return true;
ON_Xform tr;
tr.Translation( delta );
return Transform( tr );
}
ON_BOOL32 ON_Geometry::Scale( double x )
{
if ( x == 1.0 )
return true;
ON_Xform s;
s.Scale( x, x, x );
return Transform( s );
}
bool ON_Geometry::IsDeformable() const
{
return false;
}
bool ON_Geometry::MakeDeformable()
{
return false;
}
void ON_Geometry::ClearBoundingBox()
{
// default implementation does nothing
}
ON_BOOL32 ON_Geometry::Transform( const ON_Xform& xform )
{
TransformUserData(xform);
return true;
}
ON_BOOL32 ON_Geometry::HasBrepForm() const
{
// override if specific geoemtry has brep form
return false;
}
ON_Brep* ON_Geometry::BrepForm( ON_Brep* brep ) const
{
// override if specific geoemtry has brep form
return NULL;
}
ON_COMPONENT_INDEX ON_Geometry::ComponentIndex() const
{
// default constructor sets
// m_type = ON_COMPONENT_INDEX::invalid_type and m_index = -1.
ON_COMPONENT_INDEX ci;
return ci;
}
bool ON_Geometry::EvaluatePoint( const class ON_ObjRef& objref, ON_3dPoint& P ) const
{
// virtual function default
P = ON_UNSET_POINT;
return false;
}

380
extern/opennurbs/opennurbs_geometry.h vendored Executable file
View File

@@ -0,0 +1,380 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
////////////////////////////////////////////////////////////////
//
// virtual base class for all geomtric objects
//
////////////////////////////////////////////////////////////////
#if !defined(OPENNURBS_GEOMETRY_INC_)
#define OPENNURBS_GEOMETRY_INC_
class ON_Brep;
////////////////////////////////////////////////////////////////
// Description:
// Base class for all geometry classes that must
// provide runtime class id. Provides interface
// for common geometric operations like finding bounding
// boxes and transforming.
//
class ON_CLASS ON_Geometry : public ON_Object
{
// Any object derived from ON_Geometry should have a
// ON_OBJECT_DECLARE(ON_...);
// as the last line of its class definition and a
// ON_OBJECT_IMPLEMENT( ON_..., ON_baseclass );
// in a .cpp file.
//
// See the definition of ON_Object for details.
ON_OBJECT_DECLARE(ON_Geometry);
public:
ON_Geometry();
ON_Geometry(const ON_Geometry&);
ON_Geometry& operator=(const ON_Geometry&);
virtual ~ON_Geometry();
// Description:
// Get object's 3d axis aligned bounding box.
// Returns:
// 3d bounding box.
// Remarks:
// Uses virtual GetBBox() function to calculate the result.
ON_BoundingBox BoundingBox() const;
// Description:
// Get object's 3d axis aligned bounding box or the
// union of the input box with the object's bounding box.
// Parameters:
// bbox - [in/out] 3d axis aligned bounding box
// bGrowBox - [in] (default=false)
// If true, then the union of the input bbox and the
// object's bounding box is returned in bbox.
// If false, the object's bounding box is returned in bbox.
// Returns:
// true if object has bounding box and calculation was successful.
// Remarks:
// Uses virtual GetBBox() function to calculate the result.
ON_BOOL32 GetBoundingBox(
ON_BoundingBox& bbox,
int bGrowBox = false
) const;
// Description:
// Get corners of object's 3d axis aligned bounding box
// or the union of the input box with the object's bounding
// box.
// Parameters:
// bbox_min - [in/out] minimum corner of the 3d bounding box
// bbox_max - [in/out] maximum corner of the 3d bounding box
// bGrowBox - [in] (default=false)
// If true, then the union of the input bbox and the
// object's bounding box is returned.
// If false, the object's bounding box is returned.
// Returns:
// true if successful.
ON_BOOL32 GetBoundingBox(
ON_3dPoint& bbox_min,
ON_3dPoint& bbox_max,
int bGrowBox = false
) const;
// Description:
// Rotates the object about the specified axis. A positive
// rotation angle results in a counter-clockwise rotation
// about the axis (right hand rule).
// Parameters:
// sin_angle - [in] sine of rotation angle
// cos_angle - [in] sine of rotation angle
// rotation_axis - [in] direction of the axis of rotation
// rotation_center - [in] point on the axis of rotation
// Returns:
// true if object successfully rotated
// Remarks:
// Uses virtual Transform() function to calculate the result.
ON_BOOL32 Rotate(
double sin_angle,
double cos_angle,
const ON_3dVector& rotation_axis,
const ON_3dPoint& rotation_center
);
// Description:
// Rotates the object about the specified axis. A positive
// rotation angle results in a counter-clockwise rotation
// about the axis (right hand rule).
// Parameters:
// rotation_angle - [in] angle of rotation in radians
// rotation_axis - [in] direction of the axis of rotation
// rotation_center - [in] point on the axis of rotation
// Returns:
// true if object successfully rotated
// Remarks:
// Uses virtual Transform() function to calculate the result.
ON_BOOL32 Rotate(
double rotation_angle,
const ON_3dVector& rotation_axis,
const ON_3dPoint& rotation_center
);
// Description:
// Translates the object along the specified vector.
// Parameters:
// translation_vector - [in] translation vector
// Returns:
// true if object successfully translated
// Remarks:
// Uses virtual Transform() function to calculate the result.
ON_BOOL32 Translate(
const ON_3dVector& translation_vector
);
// Description:
// Scales the object by the specified facotor. The scale is
// centered at the origin.
// Parameters:
// scale_factor - [in] scale factor
// Returns:
// true if object successfully scaled
// Remarks:
// Uses virtual Transform() function to calculate the result.
ON_BOOL32 Scale(
double scale_factor
);
// Description:
// Dimension of the object.
// Returns:
// Dimension of the object.
// Remarks:
// The dimension is typically three. For parameter space trimming
// curves the dimension is two. In rare cases the dimension can
// be one or greater than three.
virtual
int Dimension() const = 0;
// Description:
// This is the virtual function that actually calculates axis
// aligned bounding boxes.
// Parameters:
// boxmin - [in/out] array of Dimension() doubles
// boxmax - [in/out] array of Dimension() doubles
// bGrowBox - [in] (default=false)
// If true, then the union of the input bbox and the
// object's bounding box is returned in bbox.
// If false, the object's bounding box is returned in bbox.
// Returns:
// true if object has bounding box and calculation was successful
virtual
ON_BOOL32 GetBBox(
double* boxmin,
double* boxmax,
int bGrowBox = false
) const = 0;
/*
Description:
Get tight bounding box.
Parameters:
tight_bbox - [in/out] tight bounding box
bGrowBox -[in] (default=false)
If true and the input tight_bbox is valid, then returned
tight_bbox is the union of the input tight_bbox and the
curve's tight bounding box.
xform -[in] (default=NULL)
If not NULL, the tight bounding box of the transformed
geometry is calculated. The geometry is not modified.
Returns:
True if a valid tight_bbox is returned.
Remarks:
In general, GetTightBoundingBox is slower that BoundingBox,
especially when xform is not null.
*/
virtual
bool GetTightBoundingBox(
ON_BoundingBox& tight_bbox,
int bGrowBox = false,
const ON_Xform* xform = 0
) const;
// Description:
// Some objects cache bounding box information.
// If you modify an object, then call ClearBoundingBox()
// to inform the object that any cached bounding boxes
// are invalid.
//
// Remarks:
// Generally, ClearBoundingBox() overrides
// simply invalidate a cached bounding box and then wait
// for a call to GetBBox() before recomputing the bounding box.
//
// The default implementation does nothing.
virtual
void ClearBoundingBox();
/*
Description:
Transforms the object.
Parameters:
xform - [in] transformation to apply to object.
If xform.IsSimilarity() is zero, then you may
want to call MakeSquishy() before calling
Transform.
Remarks:
When overriding this function, be sure to include a call
to ON_Object::TransformUserData() which takes care of
transforming any ON_UserData that may be attached to
the object.
See Also:
ON_Geometry::IsDeformable();
Remarks:
Classes derived from ON_Geometry should call
ON_Geometry::Transform() to handle user data
transformations and then transform their
definition.
*/
virtual
ON_BOOL32 Transform(
const ON_Xform& xform
);
/*
Returns:
True if object can be accuratly modified with
"squishy" transformations like projections,
shears, an non-uniform scaling.
See Also:
ON_Geometry::MakeDeformable();
*/
virtual
bool IsDeformable() const;
/*
Description:
If possible, converts the object into a form that can
be accuratly modified with "squishy" transformations
like projections, shears, an non-uniform scaling.
Returns:
False if object cannot be converted to a deformable
object. True if object was already deformable or
was converted into a deformable object.
See Also:
ON_Geometry::IsDeformable();
*/
virtual
bool MakeDeformable();
// Description:
// Swaps object coordinate values with indices i and j.
//
// Parameters:
// i - [in] coordinate index
// j - [in] coordinate index
//
// Remarks:
// The default implementation uses the virtual Transform()
// function to calculate the result. If you are creating
// an object where Transform() is slow, coordinate swapping
// will be frequently used, and coordinate swapping can
// be quickly accomplished, then override this function.
//
// Example:
//
// ON_Point point(7,8,9);
// point.SwapCoordinates(0,2);
// // point = (9,8,7)
virtual
ON_BOOL32 SwapCoordinates(
int i,
int j
);
/*
Description:
Query an object to see if it has an ON_Brep form.
Result:
Returns true if the virtual ON_Geometry::BrepForm can compute
an ON_Brep representation of this object.
Remarks:
The default implementation of ON_Geometry::BrepForm returns
false.
See Also
ON_Geometry::BrepForm
*/
virtual
ON_BOOL32 HasBrepForm() const;
/*
Description:
If possible, BrepForm() creates a brep form of the
ON_Geometry.
Parameters:
brep - [in] if not NULL, brep is used to store the brep
form of the geometry.
Result:
Returns a pointer to on ON_Brep or NULL. If the brep
parameter is not NULL, then brep is returned if the
geometry has a brep form and NULL is returned if the
geometry does not have a brep form.
Remarks:
The caller is responsible for managing the brep memory.
See Also
ON_Geometry::HasBrepForm
*/
virtual
ON_Brep* BrepForm( ON_Brep* brep = NULL ) const;
/*
Description:
If this piece of geometry is a component in something
larger, like an ON_BrepEdge in an ON_Brep, then this
function returns the component index.
Returns:
This object's component index. If this object is
not a sub-piece of a larger geometric entity, then
the returned index has
m_type = ON_COMPONENT_INDEX::invalid_type
and
m_index = -1.
*/
virtual
ON_COMPONENT_INDEX ComponentIndex() const;
/*
Description:
Evaluate the location of a point from the object
reference.
Parameters:
objref - [in]
point - [out]
If the evaluation cannot be performed, ON_UNSET_POINT
is returned.
Returns:
True if successful.
*/
virtual
bool EvaluatePoint( const class ON_ObjRef& objref, ON_3dPoint& P ) const;
};
#endif

754
extern/opennurbs/opennurbs_gl.cpp vendored Executable file
View File

@@ -0,0 +1,754 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2011 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Assoicates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
#include "opennurbs_gl.h" // ON_GL() function declarations
void ON_GL( const int order, // ON_NurbsCurve order
const int cv_count, // ON_NurbsCurve cv count
const double* knot, // ON_NurbsCurve knot vector
GLfloat* glknot, // GL knot vector
int bPermitScaling, // true if knot scaling is allowed
double* scale // If not NULL and knot scaling is
// allowed, then the scaling
// parameters are returned here.
// glknot = (knot - scale[0])*scale[1]
)
{
// Because GL uses floats instead of doubles for knot vectors and
// because some GLs are intolerant of closely spaced knots,
// the returned glknots[] may be re-scaled when bPermitScaling
// is true. When the knots belong to a trimmed surface, any rescaling
// done to the surface's knots must be applied to the trimming geometry.
const int knot_count = order + cv_count - 2;
const int nknots = knot_count+2;
// GL knot vectors have old-fashioned extra knot at start and end
const double k0 = ON_SuperfluousKnot( order, cv_count, knot,0);
const double k1 = ON_SuperfluousKnot( order, cv_count, knot,1);
if ( scale ) {
scale[0] = 0.0;
scale[1] = 1.0;
}
int i, j;
if ( bPermitScaling ) {
double d0 = knot[order-2];
double dk = 1.0;
if ( bPermitScaling ) {
double dmin = 1.0;
double dmax = 1.0;
double d;
for ( i = 1; i < knot_count; i++ ) {
d = knot[i] - knot[i-1];
if ( d <= 0.0 )
continue; // multiple knot
if ( d < dmin )
dmin = d;
else if ( d > dmax )
dmax = d;
}
if ( dmin > 0.0 && dmax >= dmin ) {
if ( dmin < 1.0e-2 )
dk = 1.0e-2/dmin;
else if ( dmax > 1.0e4 ) {
if ( 1.0e4*dmin >= 1.0e-2*dmax )
dk = 1.0e4/dmax;
}
}
}
if ( scale ) {
scale[0] = d0;
scale[1] = dk;
}
glknot[0] = (GLfloat)((k0-d0)*dk);
for( i = 1, j = 0; j < knot_count; i++, j++ )
glknot[i] = (GLfloat)((knot[j]-d0)*dk);
glknot[nknots-1] = (GLfloat)((k1-d0)*dk);
}
else {
glknot[0] = (GLfloat)k0;
for( i = 1, j = 0; j < knot_count; i++, j++ )
glknot[i] = (GLfloat)knot[j];
glknot[nknots-1] = (GLfloat)k1;
}
}
static void GetGLCV( const int dim, const int is_rat, const double* cv,
double xform[4][4],
GLfloat* glcv )
{
if ( xform ) {
const double x = cv[0];
const double y = cv[1];
const double z = (dim == 3) ? cv[2] : 0.0;
const double w = (is_rat) ? cv[dim] : 1.0;
glcv[0] = (GLfloat)(xform[0][0]*x + xform[0][1]*y + xform[0][2]*z + xform[0][3]*w);
glcv[1] = (GLfloat)(xform[1][0]*x + xform[1][1]*y + xform[1][2]*z + xform[1][3]*w);
if ( dim == 3 )
glcv[2] = (GLfloat)(xform[2][0]*x + xform[2][1]*y + xform[2][2]*z + xform[2][3]*w);
if ( is_rat )
glcv[dim] = (GLfloat)(xform[3][0]*x + xform[3][1]*y + xform[3][2]*z + xform[3][3]*w);
}
else {
glcv[0] = (GLfloat)cv[0];
glcv[1] = (GLfloat)cv[1];
if ( dim == 3)
glcv[2] = (GLfloat)cv[2];
if ( is_rat )
glcv[dim] = (GLfloat)cv[dim];
}
}
void ON_GL( const ON_NurbsCurve& nurbs_curve,
GLUnurbsObj* nobj, // created with gluNewNurbsRenderer )
GLenum type, // = 0 (and type is automatically set)
int bPermitKnotScaling,
double* knot_scale,
double xform[][4]
)
{
ON_GL( nurbs_curve.Dimension(),
nurbs_curve.IsRational(),
nurbs_curve.Order(),
nurbs_curve.CVCount(),
nurbs_curve.Knot(),
nurbs_curve.m_cv_stride,
nurbs_curve.m_cv,
nobj,
type,
bPermitKnotScaling,
knot_scale,
xform
);
}
void ON_GL( const ON_Curve& curve,
GLUnurbsObj* nobj, // created with gluNewNurbsRenderer )
GLenum type, // = 0 (and type is automatically set)
double xform[][4]
)
{
const ON_PolyCurve* poly_curve = ON_PolyCurve::Cast(&curve);
if ( poly_curve )
{
ON_Curve* pSegmentCurve = 0;
int segment_count = poly_curve->Count();
int i;
for ( i = 0; i < segment_count; i++ ) {
pSegmentCurve = poly_curve->SegmentCurve(i);
if ( pSegmentCurve )
ON_GL( *pSegmentCurve, nobj, type, xform );
}
return;
}
const ON_CurveProxy* curve_proxy = ON_CurveProxy::Cast(&curve);
if ( curve_proxy && !curve_proxy->ProxyCurveIsReversed() )
{
const ON_Curve* real_curve = curve_proxy->ProxyCurve();
if ( 0 == real_curve )
return;
if ( curve_proxy == real_curve )
return;
if ( curve_proxy->ProxyCurveDomain() == real_curve->Domain() )
{
ON_GL( *real_curve, nobj, type, xform );
return;
}
}
{
ON_NurbsCurve tmp;
const ON_NurbsCurve* nurbs_curve = ON_NurbsCurve::Cast(&curve);
if ( !nurbs_curve )
{
if ( curve.GetNurbForm(tmp) )
nurbs_curve = &tmp;
}
ON_GL( *nurbs_curve, nobj, type, true, NULL, xform );
}
}
void ON_GL( int dim, int is_rat, int nurb_order, int cv_count,
const double* knot_vector,
int cv_stride, const double* cv,
GLUnurbsObj* nobj,
GLenum type,
int bPermitKnotScaling,
double* knot_scale,
double xform[][4]
)
{
ON_BOOL32 bCallgluBeginEndCurve = false;
int i;
GLint nknots = nurb_order + cv_count; // GL knot count = TL knot count + 2
GLfloat* knot = (GLfloat*)onmalloc( nknots*sizeof(*knot) );
ON_GL( nurb_order, cv_count, knot_vector, knot, bPermitKnotScaling, knot_scale );
// control vertices
//const int cv_size = (is_rat) ? dim+1: dim;
GLint stride = cv_stride;
GLfloat* ctlarray = (GLfloat*)onmalloc( stride*cv_count*sizeof(*ctlarray) );
for ( i = 0; i < cv_count; i++ ) {
GetGLCV( dim, is_rat, cv + i*cv_stride, xform, ctlarray + stride*i );
}
GLint order = nurb_order;
switch(type)
{
case 0:
{
switch ( dim ) {
case 2: // must be a GLU_MAP1_TRIM_2/3
type = ( is_rat )
? GLU_MAP1_TRIM_3 // rational 2d trim uses homogeneous coords
: GLU_MAP1_TRIM_2; // non-rational 2d trim uses euclidean coords
break;
case 3: // must be a GLU_MAP1_VERTEX_3/4
type = ( is_rat )
? GL_MAP1_VERTEX_4 // rational 3d curve uses homogeneous coords
: GL_MAP1_VERTEX_3; // non-rational 3d curve used euclidean coords
bCallgluBeginEndCurve = true;
break;
}
}
break;
case GLU_MAP1_TRIM_2:
case GLU_MAP1_TRIM_3:
// make sure type matches rational flag
type = ( is_rat )
? GLU_MAP1_TRIM_3 // rational 2d trim uses homogeneous coords
: GLU_MAP1_TRIM_2; // non-rational 2d trim uses euclidean coords
break;
case GL_MAP1_VERTEX_3:
case GL_MAP1_VERTEX_4:
// make sure type matches rational flag
type = ( is_rat )
? GL_MAP1_VERTEX_4 // rational 3d curve uses homogeneous coords
: GL_MAP1_VERTEX_3; // non-rational 3d curve used euclidean coords
bCallgluBeginEndCurve = true;
break;
}
if ( bCallgluBeginEndCurve )
gluBeginCurve(nobj);
gluNurbsCurve(
nobj,
nknots,
knot,
stride,
ctlarray,
order,
type
);
if ( bCallgluBeginEndCurve )
gluEndCurve(nobj);
onfree( ctlarray );
onfree( knot );
}
// See comments in opennurbs_gl.h for calling instructions.
void ON_GL( const ON_NurbsSurface& s,
GLUnurbsObj* nobj, // created with gluNewNurbsRenderer )
GLenum type, // = 0 (and type is automatically set)
int bPermitKnotScaling,
double* knot_scale0,
double* knot_scale1
)
{
int i, j, k;
// The "bPermitScaling" parameters to the ON_GL() call that
// fills in the knot vectors is set to false because any
// rescaling that is applied to a surface domain must also
// be applied to parameter space trimming curve geometry.
// GL "s" knots
GLint sknot_count = s.KnotCount(0) + 2;
GLfloat* sknot = (GLfloat*)onmalloc( sknot_count*sizeof(*sknot) );
ON_GL( s.Order(0), s.CVCount(0), s.Knot(0), sknot,
bPermitKnotScaling, knot_scale0 );
// GL "t" knots
GLint tknot_count = s.KnotCount(1) + 2;
GLfloat* tknot = (GLfloat*)onmalloc( tknot_count*sizeof(*tknot) );
ON_GL( s.Order(1), s.CVCount(1), s.Knot(1), tknot,
bPermitKnotScaling, knot_scale1 );
// control vertices
const int cv_size= s.CVSize();
const int cv_count[2] = {s.CVCount(0), s.CVCount(1)};
GLint s_stride = cv_size*cv_count[1];
GLint t_stride = cv_size;
GLfloat* ctlarray = (GLfloat*)onmalloc( s_stride*cv_count[0]*sizeof(*ctlarray) );
for ( i = 0; i < cv_count[0]; i++ ) {
for ( j = 0; j < cv_count[1]; j++ ) {
const double* cv = s.CV(i,j);
GLfloat* gl_cv = ctlarray + s_stride*i + t_stride*j;
for ( k = 0; k < cv_size; k++ ) {
gl_cv[k] = (GLfloat)cv[k];
}
}
}
GLint sorder = s.Order(0);
GLint torder = s.Order(1);
if ( type == 0 ) {
// set GL surface type for 3d CVs in homogeneous/euclidean form.
type = ( s.IsRational() ) ? GL_MAP2_VERTEX_4 : GL_MAP2_VERTEX_3;
}
gluNurbsSurface (
nobj,
sknot_count,
sknot,
tknot_count,
tknot,
s_stride,
t_stride,
ctlarray,
sorder,
torder,
type
);
onfree( ctlarray );
onfree( tknot );
onfree( sknot );
}
void ON_GL( const ON_Brep& brep,
GLUnurbsObj* nobj // created with gluNewNurbsRenderer )
)
{
const int face_count = brep.m_F.Count();
int face_index;
for ( face_index = 0; face_index < face_count; face_index++ ) {
const ON_BrepFace& face = brep.m_F[face_index];
ON_GL( face, nobj );
}
}
// See comments in opennurbs_gl.h for calling instructions.
void ON_GL( const ON_BrepFace& face,
GLUnurbsObj* nobj // created with gluNewNurbsRenderer )
)
{
bool bSkipTrims = false;
const ON_Mesh* mesh;
mesh = face.Mesh(ON::render_mesh);
if ( mesh )
{
// use saved render mesh
ON_GL(*mesh);
}
else
{
// use (slow and buggy) glu trimmed NURBS rendering
double knot_scale[2][2] = {{0.0,1.0},{0.0,1.0}};
const ON_Brep* brep = face.Brep();
if ( !brep )
return;
// untrimmed surface
{
ON_NurbsSurface tmp_nurbssrf;
const ON_Surface* srf = brep->m_S[face.m_si];
const ON_NurbsSurface* nurbs_srf = ON_NurbsSurface::Cast(srf);
if ( !nurbs_srf )
{
// attempt to get NURBS form of this surface
if ( srf->GetNurbForm( tmp_nurbssrf ) )
nurbs_srf = &tmp_nurbssrf;
}
if ( !nurbs_srf )
return;
gluBeginSurface( nobj );
ON_GL( *nurbs_srf,
nobj,
(nurbs_srf->IsRational()) ? GL_MAP2_VERTEX_4 : GL_MAP2_VERTEX_3,
true, knot_scale[0], knot_scale[1]
);
}
if ( bSkipTrims || brep->FaceIsSurface( face.m_face_index ) ) {
gluEndSurface( nobj );
return; // face is trivially trimmed
}
int fli, li, lti, ti;
// any knot scaling applied to the surface must also be applied to
// the parameter space trimming geometry
double xform[4][4]
= {{knot_scale[0][1], 0.0, 0.0, -knot_scale[0][0]*knot_scale[0][1] },
{0.0, knot_scale[1][1], 0.0, -knot_scale[1][0]*knot_scale[1][1] },
{0.0, 0.0, 1.0, 0.0},
{0.0, 0.0, 0.0, 1.0}};
// Add face's 2d trimming loop(s)
const int face_loop_count = face.m_li.Count();
for ( fli = 0; fli < face_loop_count; fli++ )
{
gluBeginTrim( nobj );
li = face.m_li[fli];
const ON_BrepLoop& loop = brep->m_L[li];
const int loop_trim_count = loop.m_ti.Count();
for ( lti = 0; lti < loop_trim_count; lti++ )
{
ti = loop.m_ti[lti];
const ON_BrepTrim& trim = brep->m_T[ti];
ON_GL( trim,
nobj,
GLU_MAP1_TRIM_2,
xform
);
}
gluEndTrim( nobj );
}
gluEndSurface( nobj );
}
}
void ON_GL( const ON_Mesh& mesh )
{
int i0, i1, i2, j0, j1, j2;
int fi;
ON_3fPoint v[4];
ON_3fVector n[4];
ON_2fPoint t[4];
const int face_count = mesh.FaceCount();
const ON_BOOL32 bHasNormals = mesh.HasVertexNormals();
const ON_BOOL32 bHasTCoords = mesh.HasTextureCoordinates();
glBegin(GL_TRIANGLES);
for ( fi = 0; fi < face_count; fi++ ) {
const ON_MeshFace& f = mesh.m_F[fi];
v[0] = mesh.m_V[f.vi[0]];
v[1] = mesh.m_V[f.vi[1]];
v[2] = mesh.m_V[f.vi[2]];
if ( bHasNormals ) {
n[0] = mesh.m_N[f.vi[0]];
n[1] = mesh.m_N[f.vi[1]];
n[2] = mesh.m_N[f.vi[2]];
}
if ( bHasTCoords ) {
t[0] = mesh.m_T[f.vi[0]];
t[1] = mesh.m_T[f.vi[1]];
t[2] = mesh.m_T[f.vi[2]];
}
if ( f.IsQuad() ) {
// quadrangle - render as two triangles
v[3] = mesh.m_V[f.vi[3]];
if ( bHasNormals )
n[3] = mesh.m_N[f.vi[3]];
if ( bHasTCoords )
t[3] = mesh.m_T[f.vi[3]];
if ( v[0].DistanceTo(v[2]) <= v[1].DistanceTo(v[3]) ) {
i0 = 0; i1 = 1; i2 = 2;
j0 = 0; j1 = 2; j2 = 3;
}
else {
i0 = 1; i1 = 2; i2 = 3;
j0 = 1; j1 = 3; j2 = 0;
}
}
else {
// single triangle
i0 = 0; i1 = 1; i2 = 2;
j0 = j1 = j2 = 0;
}
// first triangle
if ( bHasNormals )
glNormal3f( n[i0].x, n[i0].y, n[i0].z );
if ( bHasTCoords )
glTexCoord2f( t[i0].x, t[i0].y );
glVertex3f( v[i0].x, v[i0].y, v[i0].z );
if ( bHasNormals )
glNormal3f( n[i1].x, n[i1].y, n[i1].z );
if ( bHasTCoords )
glTexCoord2f( t[i1].x, t[i1].y );
glVertex3f( v[i1].x, v[i1].y, v[i1].z );
if ( bHasNormals )
glNormal3f( n[i2].x, n[i2].y, n[i2].z );
if ( bHasTCoords )
glTexCoord2f( t[i2].x, t[i2].y );
glVertex3f( v[i2].x, v[i2].y, v[i2].z );
if ( j0 != j1 ) {
// if we have a quad, second triangle
if ( bHasNormals )
glNormal3f( n[j0].x, n[j0].y, n[j0].z );
if ( bHasTCoords )
glTexCoord2f( t[j0].x, t[j0].y );
glVertex3f( v[j0].x, v[j0].y, v[j0].z );
if ( bHasNormals )
glNormal3f( n[j1].x, n[j1].y, n[j1].z );
if ( bHasTCoords )
glTexCoord2f( t[j1].x, t[j1].y );
glVertex3f( v[j1].x, v[j1].y, v[j1].z );
if ( bHasNormals )
glNormal3f( n[j2].x, n[j2].y, n[j2].z );
if ( bHasTCoords )
glTexCoord2f( t[j2].x, t[j2].y );
glVertex3f( v[j2].x, v[j2].y, v[j2].z );
}
}
glEnd();
}
void ON_GL(
const ON_3dPoint& point
)
{
glVertex3d( point.x, point.y, point.z );
}
void ON_GL(
const ON_Point& point
)
{
glBegin(GL_POINTS);
ON_GL(point.point);
glEnd();
}
void ON_GL( const ON_PointCloud& cloud )
{
int i;
ON_3dPoint P;
glBegin(GL_POINTS);
for ( i = 0; i < cloud.PointCount(); i++ ) {
ON_GL( cloud.m_P[i] );
}
glEnd();
}
void ON_GL( const ON_Material& m )
{
ON_GL( &m );
}
void ON_GL( const ON_Color& rc, double alpha, GLfloat c[4] )
{
c[0] = (GLfloat)rc.FractionRed();
c[1] = (GLfloat)rc.FractionGreen();
c[2] = (GLfloat)rc.FractionBlue();
c[3] = (GLfloat)alpha;
}
void ON_GL( const ON_Color& rc, GLfloat c[4] )
{
c[0] = (GLfloat)rc.FractionRed();
c[1] = (GLfloat)rc.FractionGreen();
c[2] = (GLfloat)rc.FractionBlue();
c[3] = (GLfloat)1.0;
}
void ON_GL( const ON_Material* pMat )
{
// set GL material to match Rhino material
if ( !pMat ) {
ON_Material default_mat;
ON_GL( &default_mat );
}
else {
GLfloat ambient[4], diffuse[4], specular[4], emission[4];
GLfloat alpha = (GLfloat)(1.0 - pMat->Transparency());
ON_GL( pMat->Ambient(), alpha, ambient );
ON_GL( pMat->Diffuse(), alpha, diffuse );
ON_GL( pMat->Specular(), alpha, specular );
ON_GL( pMat->Emission(), alpha, emission );
GLint shine = (GLint)(128.0*(pMat->Shine() / ON_Material::MaxShine()));
if ( shine == 0 ) {
specular[0]=specular[1]=specular[2]=(GLfloat)0.0;
}
glMaterialfv( GL_FRONT_AND_BACK, GL_AMBIENT, ambient );
glMaterialfv( GL_FRONT_AND_BACK, GL_DIFFUSE, diffuse );
glMaterialfv( GL_FRONT_AND_BACK, GL_SPECULAR, specular );
glMaterialfv( GL_FRONT_AND_BACK, GL_EMISSION, emission );
glMateriali( GL_FRONT_AND_BACK, GL_SHININESS, shine );
}
}
void ON_GL( const ON_Light* light, GLenum light_index )
{
ON_Light default_light;
if ( !light ) {
default_light.Default();
light = &default_light;
}
ON_GL( *light, light_index );
}
void ON_GL( const ON_Light& light, GLenum light_index )
{
ON_BOOL32 bPopModelViewMatrix = false;
ON_BOOL32 bPopProjectionMatrix = false;
switch ( light.CoordinateSystem() )
{
case ON::world_cs:
break;
case ON::clip_cs:
bPopProjectionMatrix = true;
glMatrixMode(GL_PROJECTION);
glPushMatrix();
glLoadIdentity();
// no break here
case ON::camera_cs:
bPopModelViewMatrix = true;
glMatrixMode(GL_MODELVIEW);
glPushMatrix();
glLoadIdentity();
break;
case ON::screen_cs:
break;
}
GLfloat ambient[4], diffuse[4], specular[4];
ON_GL( light.Ambient(), ambient );
ON_GL( light.Diffuse(), diffuse );
ON_GL( light.Specular(), specular );
glLightfv( light_index, GL_AMBIENT, ambient );
glLightfv( light_index, GL_DIFFUSE, diffuse );
glLightfv( light_index, GL_SPECULAR, specular );
ON_3dPoint loc = light.Location();
GLfloat f[4] = {(GLfloat)loc.x,(GLfloat)loc.y,(GLfloat)loc.z,(GLfloat)1.0};
glLightfv( light_index, GL_POSITION, f );
ON_3dVector dir = light.Direction();
f[0] = (GLfloat)dir.x;
f[1] = (GLfloat)dir.y;
f[2] = (GLfloat)dir.z;
glLightfv( light_index, GL_SPOT_DIRECTION, f );
glLightf( light_index, GL_SPOT_EXPONENT, (GLfloat)(light.SpotExponent()*128.0) );
glLightf( light_index, GL_SPOT_CUTOFF, (GLfloat)light.SpotAngleRadians() );
ON_3dVector attenuation = light.Attenuation();
glLightf( light_index, GL_CONSTANT_ATTENUATION, (GLfloat)attenuation.x );
glLightf( light_index, GL_LINEAR_ATTENUATION, (GLfloat)attenuation.y );
glLightf( light_index, GL_QUADRATIC_ATTENUATION, (GLfloat)attenuation.z );
if ( light.IsEnabled() )
glEnable( light_index );
else
glDisable( light_index );
if ( bPopProjectionMatrix ) {
glMatrixMode(GL_PROJECTION);
glPopMatrix();
}
if ( bPopModelViewMatrix ) {
glMatrixMode(GL_MODELVIEW);
glPopMatrix();
}
}
void ON_GL( ON_Viewport& viewport,
int port_left, int port_right,
int port_bottom, int port_top
)
{
// Sets viewport's port to port_* values and adjusts frustum
// so it's aspect matches the port's.
ON_Xform projectionMatrix; // camera to clip transformation
const int port_width = abs(port_right - port_left);
const int port_height = abs(port_top - port_bottom);
if ( port_width == 0 || port_height == 0 )
return;
const double port_aspect = ((double)port_width)/((double)port_height);
viewport.SetFrustumAspect( port_aspect );
viewport.SetScreenPort( port_left, port_right, port_bottom, port_top,
0, 0xff );
ON_BOOL32 bHaveCameraToClip = viewport.GetXform(
ON::camera_cs,
ON::clip_cs,
projectionMatrix
);
if ( bHaveCameraToClip ) {
projectionMatrix.Transpose();
glMatrixMode(GL_PROJECTION);
glLoadMatrixd( &projectionMatrix.m_xform[0][0] );
}
}
void ON_GL( const ON_Viewport& viewport )
{
// sets model view matrix (world to camera transformation)
ON_Xform modelviewMatrix; // world to camera transformation
ON_BOOL32 bHaveWorldToCamera = viewport.GetXform(
ON::world_cs,
ON::camera_cs,
modelviewMatrix
);
if ( bHaveWorldToCamera ) {
modelviewMatrix.Transpose();
glMatrixMode(GL_MODELVIEW);
glLoadMatrixd( &modelviewMatrix.m_xform[0][0] );
}
}
void ON_GL(
const ON_Surface& surface, //
GLUnurbsObj* nobj // created with gluNewNurbsRenderer
)
{
ON_NurbsSurface tmp;
const ON_NurbsSurface* nurbs_surface;
nurbs_surface = ON_NurbsSurface::Cast(&surface);
if ( !nurbs_surface ) {
if ( surface.GetNurbForm(tmp) ) {
nurbs_surface = &tmp;
}
}
if ( nurbs_surface )
ON_GL( *nurbs_surface, nobj, 0, true );
}

244
extern/opennurbs/opennurbs_gl.h vendored Executable file
View File

@@ -0,0 +1,244 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2011 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Assoicates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
////////////////////////////////////////////////////////////////
//
// Definitions of ON_GL() functions that demonstrate how to
// use GL to display OpenNURBS objects.
//
////////////////////////////////////////////////////////////////
#include "opennurbs.h"
#if defined(ON_COMPILER_MSC)
// Tested compilers:
// Microsoft Developer Studio 6.0
// Microsoft Visual Studio 2005
// Support for other Windows compilers is not available.
// Windows Open GL files require windows.h to be included before the
// Open GL header files.
#include <windows.h>
#include <GL/gl.h> // Open GL basic definitions
#include <GL/glu.h> // Open GL utilities (for GL NURBS stuff)
#elif defined(ON_COMPILER_XCODE)
// Tested compilers:
// Apple Xcode 2.4.1
// Support for other Apple compilers is not available.
#include <GLUT/glut.h> // Open GL auxillary functions
#else
// Unsupported compiler:
// Support for other compilers is not available
#include <GL/gl.h> // Open GL basic definitions
#include <GL/glu.h> // Open GL utilities (for GL NURBS stuff)
#endif
#if !defined(OPENNURBS_GL_INC_)
#define OPENNURBS_GL_INC_
// Use ON_GL( const ON_Point, ...) to render single points.
void ON_GL(
const ON_Point&
);
// Use ON_GL( const ON_PointCloud, ...) to render Rhino point sets.
void ON_GL(
const ON_PointCloud&
);
// Use ON_GL( const ON_Mesh&, ...) to render OpenNURBS meshes.
void ON_GL(
const ON_Mesh&
);
// Use ON_GL( const ON_Brep&, ...) to render OpenNURBS b-reps.
void ON_GL(
const ON_Brep&,
GLUnurbsObj*
);
// must be bracketed by calls to glBegin(GL_POINTS) / glEnd()
void ON_GL(
const ON_3dPoint&
);
void ON_GL(
const ON_Curve&, //
GLUnurbsObj*, // created with gluNewNurbsRenderer
GLenum = 0, // type of curve (if 0, type is automatically set)
double[][4] = NULL // optional transformation applied to curve
);
// must be bracketed by calls to gluBeginSurface( nobj )/gluEndSurface( nobj )
void ON_GL(
const ON_Surface&, //
GLUnurbsObj* // created with gluNewNurbsRenderer
);
// Use ON_GL( const ON_NurbsCurve&,...) in place of
// gluNurbsCurve(). See your system's gluNurbsCurve() documentation
// for details. In particular, for 3d curves the call to
// ON_GL( const ON_NurbsCurve&, nobj,...) should appear inside
// of a gluBeginCurve( nobj )/gluEndCurve( nobj ) pair.
// Generally, the GL "type" should be set using the formula
// ON_NurbsCurve:IsRational()
// ? GL_MAP1_VERTEX_4
// : GL_MAP1_VERTEX_3;
void ON_GL(
const ON_NurbsCurve&, //
GLUnurbsObj*, // created with gluNewNurbsRenderer
GLenum = 0, // type of curve (if 0, type is automatically set)
int = 1, // bPermitKnotScaling - If true, curve knots may
// be rescaled to avoid knot vectors GL cannot handle.
double* = NULL, // knot_scale[2] - If not NULL and bPermitKnotScaling,
// the scaling applied to the knot vector is
// returned here.
double[][4] = NULL // optional transformation applied to curve
);
void ON_GL( // low level NURBS curve renderer
int, int, int, int, // dim, is_rat, cv_count, order
const double*, // knot_vector[]
int, // cv_stride
const double*, // cv
GLUnurbsObj*, // created with gluNewNurbsRenderer
GLenum = 0, // type of curve (if 0, type is automatically set)
int = 1, // bPermitKnotScaling - If true, curve knots may
// be rescaled to avoid knot vectors GL cannot handle.
double* = NULL, // knot_scale[2] - If not NULL and bPermitKnotScaling,
// the scaling applied to the knot vector is
// returned here.
double[][4] = NULL // optional transformation applied to curve
);
// Use ON_GL( const ON_NurbsSurface&,...) in place of
// gluNurbsSurface(). See your system's gluNurbsSurface() documentation
// for details. In particular, the call to
// ON_GL( const ON_NurbsSurface&, nobj, ...) should appear inside
// of a gluBeginSurface( nobj )/gluEndSurface( nobj ) pair.
// Generally, the GL "type" should be set using the formula
// ON_NurbsSurface:IsRational()
// ? GL_MAP2_VERTEX_4
// : GL_MAP2_VERTEX_3;
void ON_GL(
const ON_NurbsSurface&, //
GLUnurbsObj*, // created with gluNewNurbsRenderer
GLenum = 0, // type of surface
// (if 0, type is automatically set)
int = 1, // bPermitKnotScaling - If true, surface knots may
// be rescaled to avoid knot vectors GL cannot handle.
double* = NULL, // knot_scale0[2] - If not NULL and bPermitKnotScaling,
// the scaleing applied to the first parameter is
// returned here.
double* = NULL // knot_scale0[2] - If not NULL and bPermitKnotScaling,
// the scaleing applied to the second parameter is
// returned here.
);
// Use ON_GL( const ON_BrepFace&, nobj ) to render
// the trimmed NURBS surface that defines a ON_Brep face's geometry.
// The call to ON_GL( const ON_BrepFace&, nobj ) should
// appear inside of a gluBeginSurface( nobj )/gluEndSurface( nobj )
// pair.
void ON_GL(
const ON_BrepFace&, //
GLUnurbsObj* // created with gluNewNurbsRenderer
);
// Use ON_GL( const ON_Color ...) to set GL color to OpenNURBS color
void ON_GL( const ON_Color&,
GLfloat[4]
);
void ON_GL( const ON_Color&,
double, // alpha
GLfloat[4]
);
// Use ON_GL( const ON_Material ...) to set GL material to OpenNURBS material
void ON_GL(
const ON_Material&
);
void ON_GL(
const ON_Material* // pass NULL to get OpenNURBS's default material
);
// Use ON_GL( const ON_Light, ...) to add OpenNURBS spotlights to
// GL lighting model
void ON_GL(
const ON_Light*, // pass NULL to disable the light
GLenum // GL_LIGHTi where 0 <= i <= GL_MAX_LIGHTS
// See glLight*() documentation for details
);
void ON_GL(
const ON_Light&,
GLenum // GL_LIGHTi where 0 <= i <= GL_MAX_LIGHTS
// See glLight*() documentation for details
);
//////////////////////////////////////////////////////////////////////////
// Use ON_GL( ON_Viewport& ... ) to set the GL projections to match
// those used in the OpenNURBS viewport.
////////////
//
// Use ON_GL( ON_Viewport&, in, int, int, int ) to specify the size of the
// GL window and loads the GL projection matrix (camera to clip
// transformation). If the aspect ratio of the GL window and
// ON_Viewport's frustum do not match, the viewport's frustum is
// adjusted to get things back to 1:1.
//
// For systems where the upper left corner of a window has
// coordinates (0,0) use:
// port_left = 0
// port_right = width-1
// port_bottom = height-1
// port_top = 0
void ON_GL( ON_Viewport&,
int, int, // port_left, port_right (port_left != port_right)
int, int // port_bottom, port_top (port_bottom != port_top)
);
////////////
//
// Use ON_GL( ON_Viewport& ) to load the GL model view matrix (world to
// camera transformation).
void ON_GL( const ON_Viewport& );
// Use ON_GL( order, cv_count, knot, bPermitScaling, glknot )
// to create knot vectors suitable for GL NURBS rendering.
void ON_GL(
const int, // order, ON_NurbsCurve... order
const int, // cv_count, ON_NurbsCurve... cv count
const double*, // knot, ON_NurbsCurve... knot vector
GLfloat*, // glknot[] - GL knot vector
int = 0, // bPermitScaling - true if re-scaling is allowed
double* = NULL // scale[2] - If not NULL and bPermitScaling is true,
// then the scaling parameters are returned here.
// ( glknot = (knot = scale[0])*scale[1] )
);
#endif

118
extern/opennurbs/opennurbs_group.cpp vendored Executable file
View File

@@ -0,0 +1,118 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#include "opennurbs.h"
ON_OBJECT_IMPLEMENT( ON_Group, ON_Object, "721D9F97-3645-44c4-8BE6-B2CF697D25CE" );
ON_Group::ON_Group() : m_group_index(-1)
{
memset(&m_group_id,0,sizeof(m_group_id));
}
ON_Group::~ON_Group()
{
}
//////////////////////////////////////////////////////////////////////
//
// ON_Object overrides
ON_BOOL32 ON_Group::IsValid( ON_TextLog* text_log ) const
{
return ( m_group_name.Length() > 0 && m_group_index >= 0 );
}
void ON_Group::Dump( ON_TextLog& dump ) const
{
const wchar_t* name = GroupName();
if ( !name )
name = L"";
dump.Print("group index = %d\n",m_group_index);
dump.Print("group name = \"%ls\"\n",name);
}
ON_BOOL32 ON_Group::Write(
ON_BinaryArchive& file // serialize definition to binary archive
) const
{
ON_BOOL32 rc = file.Write3dmChunkVersion(1,1);
// version 1.0 fields
if (rc) rc = file.WriteInt(m_group_index);
if (rc) rc = file.WriteString(m_group_name);
// version 1.1 fields
if (rc) rc = file.WriteUuid(m_group_id);
return rc;
}
ON_BOOL32 ON_Group::Read(
ON_BinaryArchive& file // restore definition from binary archive
)
{
m_group_index = -1;
m_group_name.Empty();
memset(&m_group_id,0,sizeof(m_group_id));
int major_version = 0;
int minor_version = 0;
ON_BOOL32 rc = file.Read3dmChunkVersion(&major_version,&minor_version);
if ( major_version == 1 )
{
if (rc) rc = file.ReadInt( &m_group_index );
if (rc) rc = file.ReadString( m_group_name );
if ( minor_version >= 1 )
{
if (rc) rc = file.ReadUuid( m_group_id );
}
}
else
rc = false;
return rc;
}
//////////////////////////////////////////////////////////////////////
//
// Interface
void ON_Group::SetGroupName( const wchar_t* s )
{
m_group_name = s;
}
void ON_Group::SetGroupName( const char* s )
{
m_group_name = s;
}
void ON_Group::GetGroupName( ON_wString& s ) const
{
s = m_group_name;
}
const wchar_t* ON_Group::GroupName() const
{
const wchar_t* s = m_group_name;
return s;
}
void ON_Group::SetGroupIndex(int i )
{
m_group_index = i;
}
int ON_Group::GroupIndex() const
{
return m_group_index;
}

82
extern/opennurbs/opennurbs_group.h vendored Executable file
View File

@@ -0,0 +1,82 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#if !defined(OPENNURBS_GROUP_INC_)
#define OPENNURBS_GROUP_INC_
class ON_CLASS ON_Group : public ON_Object
{
ON_OBJECT_DECLARE(ON_Group);
public:
ON_Group();
~ON_Group();
// C++ default copy construction and operator= work fine.
// Do not add custom versions.
//////////////////////////////////////////////////////////////////////
//
// ON_Object overrides
/*
Description:
Tests an object to see if its data members are correctly
initialized.
Parameters:
text_log - [in] if the object is not valid and text_log
is not NULL, then a brief englis description of the
reason the object is not valid is appened to the log.
The information appended to text_log is suitable for
low-level debugging purposes by programmers and is
not intended to be useful as a high level user
interface tool.
Returns:
@untitled table
true object is valid
false object is invalid, uninitialized, etc.
Remarks:
Overrides virtual ON_Object::IsValid
*/
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
void Dump( ON_TextLog& ) const; // for debugging
ON_BOOL32 Write(
ON_BinaryArchive& // serialize definition to binary archive
) const;
ON_BOOL32 Read(
ON_BinaryArchive& // restore definition from binary archive
);
//////////////////////////////////////////////////////////////////////
//
// Obsolete interface - just work on the public members
void SetGroupName( const wchar_t* );
void SetGroupName( const char* );
void GetGroupName( ON_wString& ) const;
const wchar_t* GroupName() const;
void SetGroupIndex(int);
int GroupIndex() const;
public:
ON_wString m_group_name;
int m_group_index;
ON_UUID m_group_id;
};
#endif

1475
extern/opennurbs/opennurbs_hatch.cpp vendored Executable file

File diff suppressed because it is too large Load Diff

833
extern/opennurbs/opennurbs_hatch.h vendored Executable file
View File

@@ -0,0 +1,833 @@
/* $NoKeywords: $ */
/*
//
// Copyright (c) 1993-2012 Robert McNeel & Associates. All rights reserved.
// OpenNURBS, Rhinoceros, and Rhino3D are registered trademarks of Robert
// McNeel & Associates.
//
// THIS SOFTWARE IS PROVIDED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY.
// ALL IMPLIED WARRANTIES OF FITNESS FOR ANY PARTICULAR PURPOSE AND OF
// MERCHANTABILITY ARE HEREBY DISCLAIMED.
//
// For complete openNURBS copyright information see <http://www.opennurbs.org>.
//
////////////////////////////////////////////////////////////////
*/
#ifndef OPENNURBS_HATCH_H_INCLUDED
#define OPENNURBS_HATCH_H_INCLUDED
/*
class ON_HatchLoop
/////////////////////////////////////////////////////////////////
Represents a 3d boundary loop curve
*/
class ON_CLASS ON_HatchLoop
{
public:
#if defined(ON_DLL_EXPORTS) || defined(ON_DLL_IMPORTS)
// When the Microsoft CRT(s) is/are used, this is the best
// way to prevent crashes that happen when a hatch loop is
// allocated with new in one DLL and deallocated with
// delete in another DLL.
// new/delete
void* operator new(size_t);
void operator delete(void*);
// array new/delete
void* operator new[] (size_t);
void operator delete[] (void*);
// in place new/delete
void* operator new(size_t,void*);
void operator delete(void*,void*);
#endif
enum eLoopType
{
ltOuter = 0,
ltInner = 1,
};
ON_HatchLoop();
ON_HatchLoop( ON_Curve* pCurve2d, eLoopType type = ltOuter);
ON_HatchLoop( const ON_HatchLoop& src);
~ON_HatchLoop();
ON_HatchLoop& operator=( const ON_HatchLoop& src);
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
void Dump( ON_TextLog& ) const; // for debugging
ON_BOOL32 Write( ON_BinaryArchive&) const;
ON_BOOL32 Read( ON_BinaryArchive&);
// Interface
/////////////////////////////////////////////////////////////////
/*
Description:
Get a closed 2d curve boundary loop
Parameters:
Return:
Pointer to loop's 2d curve
*/
const ON_Curve* Curve() const;
/*
Description:
Specify the 2d loop curve in the hatch's plane coordinates
Parameters:
curve - [in] 2d input curve
Return:
true: success, false, curve couldn't be duplicated
Remarks:
The curve is copied
*/
bool SetCurve( const ON_Curve& curve);
/*
Description:
Get the type flag of the loop
Returns:
eLoopType::ltInner or eLoopType::ltOuter
*/
eLoopType Type() const;
/*
Description:
Specify the type flag of the loop
Parameters:
type - [in] ltInner or ltOuter
*/
void SetType( eLoopType type);
protected:
friend class ON_Hatch;
eLoopType m_type; // loop type flag - inner or outer
ON_Curve* m_p2dCurve; // 2d closed curve bounding the hatch
// This is really a 3d curve with z coordinates = 0
};
/*
class ON_HatchLine
/////////////////////////////////////////////////////////////////
Represents one line of a hatch pattern
Similar to AutoCAD's .pat file definition
ON_HatchLine's are used by ON_HatchPattern
to specify the dashes and offset patterns of the lines.
Each line has the following information:
Angle is the direction of the line CCW from the x axis
The first line origin is at base
Each line repetition is offset by offset from the previous line
offset.x is parallel to the line and
offset.y is perpendicular to the line
The base and offset values are rotated by the line's angle to
produce a location in the hatch pattern's coordinate system
There can be gaps and dashes specified for drawing the line
If there are no dashes, the line is solid
Negative length dashes are gaps
Positive length dashes are drawn as line segments
*/
class ON_CLASS ON_HatchLine
{
public:
ON_HatchLine();
// C++ default copy construction and operator= work fine.
ON_HatchLine(
double angle,
const ON_2dPoint& base,
const ON_2dVector& offset,
const ON_SimpleArray<double> dashes);
bool operator==( const ON_HatchLine&) const;
bool operator!=( const ON_HatchLine&) const;
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
void Dump( ON_TextLog& ) const; // for debugging
ON_BOOL32 Write( ON_BinaryArchive&) const; // serialize definition to binary archive
ON_BOOL32 Read( ON_BinaryArchive&); // restore definition from binary archive
// Interface
/////////////////////////////////////////////////////////////////
/*
Description:
Get angle of the hatch line.
CCW from x-axis
Parameters:
Return:
The angle in radians
*/
double Angle() const;
/*
Description:
Set angle of the hatch line.
CCW from x-axis
Parameters:
angle - [in] angle in radians
Return:
*/
void SetAngle( double angle);
/*
Description:
Get this line's 2d basepoint
Parameters:
Return:
the base point
*/
ON_2dPoint Base() const;
/*
Description:
Set this line's 2d basepoint
Parameters:
base - [in] the basepoint
Return:
*/
void SetBase( const ON_2dPoint& base);
/*
Description:
Get this line's 2d offset for line repetitions
Offset().x is shift parallel to line
Offset().y is spacing perpendicular to line
Parameters:
Return:
the offset
*/
ON_2dVector Offset() const;
/*
Description:
Get this line's 2d offset for line repetitions
Offset().x is shift parallel to line
Offset().y is spacing perpendicular to line
Parameters:
offset - [in] the shift,spacing for repeated lines
Return:
*/
void SetOffset( const ON_2dVector& offset);
/*
Description:
Get the number of gaps + dashes in the line
Parameters:
Return:
nummber of dashes in the line
*/
int DashCount() const;
/*
Description:
Get the dash length at index
Parameters:
index - [in] the dash to get
Return:
the length of the dash ( gap if negative)
*/
double Dash( int) const;
/*
Description:
Add a dash to the pattern
Parameters:
dash - [in] length to append - < 0 for a gap
*/
void AppendDash( double dash);
/*
Description:
Specify a new dash array
Parameters:
dashes - [in] array of dash lengths
*/
void SetPattern( const ON_SimpleArray<double>& dashes);
/*
Description:
Get the line's angle, base, offset and dashes
in one function call
Parameters:
angle - [out] angle in radians CCW from x-axis
base - [out] origin of the master line
offset - [out] offset for line replications
dashes - [out] the dash array for the line
Return:
*/
void GetLineData(
double& angle,
ON_2dPoint& base,
ON_2dVector& offset,
ON_SimpleArray<double>& dashes) const;
/*
Description:
Get the total length of a pattern repeat
Parameters:
Return:
Pattern length
*/
double GetPatternLength() const;
public:
double m_angle;
ON_2dPoint m_base;
ON_2dVector m_offset;
ON_SimpleArray< double> m_dashes;
};
#if defined(ON_DLL_TEMPLATE)
// This stuff is here because of a limitation in the way Microsoft
// handles templates and DLLs. See Microsoft's knowledge base
// article ID Q168958 for details.
#pragma warning( push )
#pragma warning( disable : 4231 )
ON_DLL_TEMPLATE template class ON_CLASS ON_SimpleArray<ON_HatchLoop*>;
ON_DLL_TEMPLATE template class ON_CLASS ON_ClassArray<ON_HatchLine>;
#pragma warning( pop )
#endif
/*
class ON_HatchPattern
/////////////////////////////////////////////////////////////////
Fill definition for a hatch
The hatch will be one of
ON_Hatch::ftLines - pat file style definition
ON_Hatch::ftGradient - uses a color function
ON_Hatch::ftSolid - uses entity color
*/
class ON_CLASS ON_HatchPattern : public ON_Object
{
ON_OBJECT_DECLARE( ON_HatchPattern);
public:
enum eFillType
{
ftSolid = 0, // uses entity color
ftLines = 1, // pat file definition
ftGradient = 2, // uses a fill color function
ftLast = 3
};
ON_HatchPattern();
~ON_HatchPattern();
// C++ default copy construction and operator= work fine.
// ON_Object overrides
/////////////////////////////////////////////////////////////////
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
void Dump( ON_TextLog& ) const; // for debugging
ON_BOOL32 Write( ON_BinaryArchive&) const;
ON_BOOL32 Read( ON_BinaryArchive&);
// virtual
ON_UUID ModelObjectId() const;
//////////////////////////////////////////////////////////////////////
// Interface
/*
Description:
Return the pattern's fill type
Parameters:
*/
eFillType FillType() const;
/*
Description:
Set the pattern's fill type
Parameters:
type - [in] the new filltype
*/
void SetFillType( eFillType type);
/*
Description:
Set the name of the pattern
Parameters:
pName - [in] the new name
Returns:
*/
void SetName( const wchar_t* pName);
void SetName( const char* pName);
/*
Description:
Get the name of the pattern
Parameters:
string - [out] The name is returned here
*/
void GetName( ON_wString& string) const;
/*
Description:
Get the name of the pattern
Returns:
The name string
*/
const wchar_t* Name() const;
/*
Description:
Set the name of the pattern
Parameters:
pDescription - [in] the new description
Returns:
*/
void SetDescription( const wchar_t* pDescription);
void SetDescription( const char* pDescription);
/*
Description:
Get a short description of the pattern
Parameters:
string - [out] The string is returned here
*/
void GetDescription( ON_wString& string) const;
/*
Description:
Return a short text description of the pattern type
Parameters:
Returns:
The description string
*/
const wchar_t* Description() const;
/*
Description:
Set the table index of the pattern
Parameters:
index - [in] the new index
Returns:
*/
void SetIndex( int index);
/*
Description:
Return the table index of the pattern
Parameters:
Returns:
The table index
*/
int Index() const;
// Interface functions for line hatches
/////////////////////////////////////////////////////////////////
/*
Description:
Get the number of ON_HatchLines in the pattern
Parameters:
Return:
number of lines
*/
int HatchLineCount() const;
/*
Description:
Add an ON_HatchLine to the pattern
Parameters:
line - [in] the line to add
Return:
>= 0 index of the new line
-1 on failure
*/
int AddHatchLine( const ON_HatchLine& line);
/*
Description:
Get the ON_HatchLine at index
Parameters:
index - [in] Index of the line to get
Return:
the hatch line
NULL if index is out of range
*/
const ON_HatchLine* HatchLine( int index) const;
/*
Description:
Remove a hatch line from the pattern
Parameters:
index - [in] Index of the line to remove
Return:
true - success
false - index out of range
*/
bool RemoveHatchLine( int index);
/*
Description:
Remove all of the hatch line from the pattern
Parameters:
Return:
true - success
false - index out of range
*/
void RemoveAllHatchLines();
/*
Description:
Set all of the hatch lines at once.
Existing hatchlines are deleted.
Parameters:
lines - [in] Array of lines to add. Lines are copied
Return:
number of lines added
*/
int SetHatchLines( const ON_ClassArray<ON_HatchLine> lines);
public:
int m_hatchpattern_index; // Index in the hatch pattern table
ON_wString m_hatchpattern_name; // String name of the pattern
ON_UUID m_hatchpattern_id;
eFillType m_type;
ON_wString m_description; // String description of the pattern
// Represents a collection of ON_HatchLine's to make a complete pattern
// This is the definition of a hatch pattern.
// Simple solid line hatches with fixed angle and spacing are also
// represented with this type of hatch
ON_ClassArray<ON_HatchLine> m_lines; // used by line hatches
};
/*
class ON_Hatch
/////////////////////////////////////////////////////////////////
Represents a hatch in planar boundary loop or loops
This is a 2d entity with a plane defining a local coordinate system
The loops, patterns, angles, etc are all in this local coordinate system
The ON_Hatch object manages the plane and loop array
Fill definitions are in the ON_HatchPattern or class derived from ON_HatchPattern
ON_Hatch has an index to get the pattern definition from the pattern table
*/
class ON_CLASS ON_Hatch : public ON_Geometry
{
ON_OBJECT_DECLARE( ON_Hatch);
public:
// Default constructor
ON_Hatch();
ON_Hatch( const ON_Hatch&);
ON_Hatch& operator=(const ON_Hatch&);
~ON_Hatch();
virtual ON_Hatch* DuplicateHatch() const;
// ON_Object overrides
/////////////////////////////////////////////////////////////////
ON_BOOL32 IsValid( ON_TextLog* text_log = NULL ) const;
void Dump( ON_TextLog& ) const; // for debugging
ON_BOOL32 Write( ON_BinaryArchive&) const;
ON_BOOL32 Read( ON_BinaryArchive&);
ON::object_type ObjectType() const;
// ON_Geometry overrides
/////////////////////////////////////////////////////////////////
/*
Returns the geometric dimension of the object ( usually 3)
*/
int Dimension() const;
/*
Description:
Get a bounding 3d WCS box of the object
This is a bounding box of the boundary loops
Parameters:
[in/out] double* boxmin - pointer to dim doubles for min box corner
[in/out] double* boxmax - pointer to dim doubles for max box corner
[in] ON_BOOL32 growbox - true to grow the existing box,
false ( the default) to reset the box
Returns:
true = Success
false = Failure
Remarks:
*/
ON_BOOL32 GetBBox( double*, double*, ON_BOOL32 = false) const;
/*
Description:
Get tight bounding box of the hatch.
Parameters:
tight_bbox - [in/out] tight bounding box
bGrowBox -[in] (default=false)
If true and the input tight_bbox is valid, then returned
tight_bbox is the union of the input tight_bbox and the
tight bounding box of the hatch.
xform -[in] (default=NULL)
If not NULL, the tight bounding box of the transformed
hatch is calculated. The hatch is not modified.
Returns:
True if the returned tight_bbox is set to a valid
bounding box.
*/
bool GetTightBoundingBox(
ON_BoundingBox& tight_bbox,
int bGrowBox = false,
const ON_Xform* xform = 0
) const;
/*
Description:
Transform the object by a 4x4 xform matrix
Parameters:
[in] xform - An ON_Xform with the transformation information
Returns:
true = Success
false = Failure
Remarks:
The object has been transformed when the function returns.
*/
ON_BOOL32 Transform( const ON_Xform&);
// Interface
/////////////////////////////////////////////////////////////////
/*
Description:
Create a hatch from input geometry and parameters
Parameters:
plane [I] - ON_Plane to make the hatch on
loops [I] - Array of boundary loops with the outer one first
pattern_index [I] - Index into the hatch table
pattern_rotation [I] - ccw in radians about plane origin
pattern_scale [I] - Scale factor for pattern definition
Returns:
true = success, false = failure
*/
bool Create( const ON_Plane& plane,
const ON_SimpleArray<const ON_Curve*> loops,
int pattern_index,
double pattern_rotation,
double pattern_scale);
/*
Description:
Get the plane defining the hatch's coordinate system
Parameters:
Returns:
the plane
*/
const ON_Plane& Plane() const;
/*
Description:
Set the plane defining the hatch's coordinate system
Parameters:
plane - [in] the plane to set
Returns:
*/
void SetPlane( const ON_Plane& plane);
/*
Description:
Gets the rotation applied to the hatch pattern
when it is mapped to the hatch's plane
Returns:
The rotation in radians
Remarks:
The pattern is rotated counter-clockwise around
the hatch's plane origin by this value
*/
double PatternRotation() const;
/*
Description:
Sets the rotation applied to the hatch pattern
when it is mapped to the hatch's plane
Parameters:
rotation - [in] The rotation in radians
Remarks:
The pattern is rotated counter-clockwise around
the hatch's plane origin by this value
*/
void SetPatternRotation( double rotation);
/*
Description:
Gets the scale applied to the hatch pattern
when it is mapped to the hatch's plane
Returns:
The scale
Remarks:
The pattern is scaled around
the hatch's plane origin by this value
*/
double PatternScale() const;
/*
Description:
Sets the scale applied to the hatch pattern
when it is mapped to the hatch's plane
Parameters:
scale - [in] The scale
Remarks:
The pattern is scaled around
the hatch's plane origin by this value
*/
void SetPatternScale( double scale);
/*
Description:
Get the number of loops used by this hatch
Parameters:
Returns:
the number of loops
*/
int LoopCount() const;
/*
Description:
Add a loop to the hatch
Parameters:
loop - [in] the loop to add. Memory management for the loop is managed
by this class.
Returns:
*/
void AddLoop( ON_HatchLoop* loop);
/*
Description:
Insert a loop to the hatch at the specified index
Parameters:
index - [in] zero based index of the position where insert the loop to.
loop - [in] the loop to insert. Memory management for the loop is managed
by this class on success.
Returns:
true if success
false if index is lower than 0 or greater than current loop count.
*/
bool InsertLoop( int index,
ON_HatchLoop* loop);
/*
Description:
Remove a loop in the hatch
Parameters:
loop - [in] zero based index of the loop to remove.
Returns:
true if success
*/
bool RemoveLoop( int index);
/*
Description:
Get the loop at index
Parameters:
index - [in] which loop to get
Returns:
pointer to loop at index
NULL if index is out of range
*/
const ON_HatchLoop* Loop( int index) const;
/*
Description:
Get the 3d curve corresponding to loop[index]
Parameters:
index - [in] which loop to get
Returns:
pointer to 3d curve of loop at index
NULL if index is out of range or curve can't be made
Caller deletes the returned curve
*/
ON_Curve* LoopCurve3d( int index) const;
/*
Description:
Get the index of the hatch's pattern
Parameters:
Returns:
index of the pattern
*/
int PatternIndex() const;
/*
Description:
Set the index of the hatch's pattern
Parameters:
index - [in] pattern index to set
Returns:
*/
void SetPatternIndex( int index);
// Basepoint functions added March 23, 2008 -LW
/*
Description:
Set 2d Base point for hatch pattern alignment.
Parameters:
basepoint - 2d point in hatch's ECS
*/
void SetBasePoint(ON_2dPoint basepoint);
/*
Description:
Set 3d Base point for hatch pattern alignment.
Parameters:
point - 3d WCS point
Remarks:
Projects point to hatch's plane and sets 2d point
*/
void SetBasePoint(ON_3dPoint point);
/*
Description:
Return 3d WCS point that lies on hatch's plane used for pattern origin.
*/
ON_3dPoint BasePoint() const;
/*
Description:
Return 2d ECS point used for pattern origin.
*/
ON_2dPoint BasePoint2d() const;
/*
Function added June 12 2008 LW
Description:
Remove all of the loops on the hatch and add the curves in 'loops' as new loops
Parameters:
loops - [in] An array of pointers to 2d or 3d curves
If the curves are 2d, add them to the hatch directly
If they are 3d, project them to the hatch's plane first
Returns:
true - success
false - no loops in input array or an error adding them
*/
bool ReplaceLoops(ON_SimpleArray<const ON_Curve*> loops);
protected:
ON_Plane m_plane;
double m_pattern_scale;
double m_pattern_rotation;
ON_SimpleArray<ON_HatchLoop*> m_loops;
int m_pattern_index;
// This function is temporary and will be removed next time the SDK can be modified.
class ON_HatchExtra* HatchExtension();
};
#endif

Some files were not shown because too many files have changed in this diff Show More