Salome HOME
spns #32926: backport KERNEL & CONFIGURATION fixes on more recent platforms to ensure...
[tools/sat_salome.git] / products / patches / netgen-5.3.1_OCCT-7.3_Windows-10_Visual-2017.patch
1 --- /dev/null
2 +++ netgen/CMakeLists.txt
3 @@ -0,0 +1,75 @@
4 +# Copyright (C) 2016 OPEN CASCADE
5 +#
6 +# This library is free software; you can redistribute it and/or
7 +# modify it under the terms of the GNU Lesser General Public
8 +# License as published by the Free Software Foundation; either
9 +# version 2.1 of the License, or (at your option) any later version.
10 +#
11 +# This library is distributed in the hope that it will be useful,
12 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
13 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 +# Lesser General Public License for more details.
15 +#
16 +# You should have received a copy of the GNU Lesser General Public
17 +# License along with this library; if not, write to the Free Software
18 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
19 +#
20 +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
21 +#
22 +CMAKE_MINIMUM_REQUIRED(VERSION 2.8.8 FATAL_ERROR)
23 +INCLUDE(CMakeDependentOption)
24 +
25 +PROJECT(netgen C CXX)
26 +
27 +# Ensure a proper linker behavior:
28 +CMAKE_POLICY(SET CMP0003 NEW)
29 +
30 +# Versioning
31 +# ===========
32 +# Project name, upper case
33 +STRING(TOUPPER ${PROJECT_NAME} PROJECT_NAME_UC)
34 +
35 +SET(${PROJECT_NAME_UC}_MAJOR_VERSION 5)
36 +SET(${PROJECT_NAME_UC}_MINOR_VERSION 3)
37 +SET(${PROJECT_NAME_UC}_PATCH_VERSION 1)
38 +SET(${PROJECT_NAME_UC}_VERSION
39 +  ${${PROJECT_NAME_UC}_MAJOR_VERSION}.${${PROJECT_NAME_UC}_MINOR_VERSION}.${${PROJECT_NAME_UC}_PATCH_VERSION})
40 +
41 +# Common CMake macros
42 +# ===================
43 +LIST(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake")
44 +# Detect platform
45 +INCLUDE(FindPLATFORM) 
46 +# Detect OCCT
47 +INCLUDE(FindCAS)
48 +
49 +# Detect ZLIB on Windows
50 +IF(WIN32)
51 +  SET(ZLIB_ROOT_DIR $ENV{ZLIB_ROOT_DIR})
52 +  IF(EXISTS ${ZLIB_ROOT_DIR})
53 +    SET(ZLIB_ROOT ${ZLIB_ROOT_DIR})
54 +    INCLUDE(FindZLIB)
55 +    IF (NOT ${ZLIB_FOUND})
56 +      MESSAGE(FATAL_ERROR "We absolutely need the zlib library, please check zlib installation !")
57 +    ENDIF()
58 +  ELSE()
59 +    MESSAGE(FATAL_ERROR "We absolutely need the zlib library, please define ZLIB_ROOT_DIR !")
60 +  ENDIF()
61 +ENDIF()
62 +
63 +
64 +# Common definitions
65 +# ==================
66 +ADD_DEFINITIONS(-DNO_PARALLEL_THREADS)
67 +ADD_DEFINITIONS(-DOCCGEOMETRY)
68 +
69 +# Target directories
70 +SET(NETGEN_INSTALL_BINS "${CMAKE_INSTALL_PREFIX}/bin" CACHE PATH "Install path: netgen binaries")
71 +SET(NETGEN_INSTALL_LIBS "${CMAKE_INSTALL_PREFIX}/lib" CACHE PATH "Install path: netgen libs")
72 +SET(NETGEN_INSTALL_HEADERS "${CMAKE_INSTALL_PREFIX}/include" CACHE PATH "Install path: netgen headers")
73 +SET(NETGEN_INSTALL_CMAKE "${CMAKE_INSTALL_PREFIX}/cmake" CACHE PATH "Install path: netgen cmake files")
74 +
75 +# Sub-directories
76 +ADD_SUBDIRECTORY(nglib)
77 +ADD_SUBDIRECTORY(cmake)
78 +
79 --- netgen_ref/Makefile.am
80 +++ netgen/Makefile.am
81 @@ -2,7 +2,7 @@
82  
83  METASOURCES = AUTO
84  
85 -SUBDIRS = libsrc ng tutorials doc windows nglib
86 +SUBDIRS = libsrc nglib #tutorials doc windows nglib
87  
88  # TESTS = ng/netgen -batchmode
89  
90 --- netgen_ref/Makefile.in
91 +++ netgen/Makefile.in
92 @@ -280,7 +280,7 @@
93  top_srcdir = @top_srcdir@
94  ACLOCAL_AMFLAGS = -I m4
95  METASOURCES = AUTO
96 -SUBDIRS = libsrc ng tutorials doc windows nglib
97 +SUBDIRS = libsrc nglib #tutorials doc windows nglib
98  all: config.h
99         $(MAKE) $(AM_MAKEFLAGS) all-recursive
100  
101 --- /dev/null
102 +++ netgen/cmake/CMakeLists.txt
103 @@ -0,0 +1,22 @@
104 +# Copyright (C) 2016 OPEN CASCADE
105 +#
106 +# This library is free software; you can redistribute it and/or
107 +# modify it under the terms of the GNU Lesser General Public
108 +# License as published by the Free Software Foundation; either
109 +# version 2.1 of the License, or (at your option) any later version.
110 +#
111 +# This library is distributed in the hope that it will be useful,
112 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
113 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
114 +# Lesser General Public License for more details.
115 +#
116 +# You should have received a copy of the GNU Lesser General Public
117 +# License along with this library; if not, write to the Free Software
118 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
119 +#
120 +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
121 +#
122 +
123 +IF(WIN32)
124 + INSTALL(FILES FindZLIB.cmake DESTINATION ${NETGEN_INSTALL_CMAKE})
125 +ENDIF()
126 \ No newline at end of file
127 --- /dev/null
128 +++ netgen/cmake/FindCAS.cmake
129 @@ -0,0 +1,152 @@
130 +#  Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
131 +#
132 +#  This library is free software; you can redistribute it and/or
133 +#  modify it under the terms of the GNU Lesser General Public
134 +#  License as published by the Free Software Foundation; either
135 +#  version 2.1 of the License.
136 +#
137 +#  This library is distributed in the hope that it will be useful,
138 +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
139 +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
140 +#  Lesser General Public License for more details.
141 +#
142 +#  You should have received a copy of the GNU Lesser General Public
143 +#  License along with this library; if not, write to the Free Software
144 +#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
145 +#
146 +#  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
147 +#
148 +
149 +SET(CASROOT $ENV{CASROOT})
150 +ADD_DEFINITIONS(-DLIN -DLINTEL -DCSFDB)
151 +ADD_DEFINITIONS(-DNo_exception)
152 +ADD_DEFINITIONS(-DHAVE_LIMITS_H)
153 +
154 +IF(CMAKE_SIZEOF_VOID_P STREQUAL 8)
155 +  ADD_DEFINITIONS(-D_OCC64)
156 +ENDIF(CMAKE_SIZEOF_VOID_P STREQUAL 8)
157 +
158 +IF(NOT WINDOWS)
159 +  FIND_LIBRARY(Xmu Xmu)
160 +  IF(Xmu)
161 +    SET(CAS_LDPATH ${Xmu})
162 +  ENDIF(Xmu)
163 +ENDIF(NOT WINDOWS)
164 +
165 +IF(WINDOWS)
166 +  IF(CMAKE_BUILD_TYPE STREQUAL Debug)
167 +    SET(CASROOT_LIBDIR ${CASROOT}/win32/libd ${CASROOT}/win64/vc14/lib)
168 +  ELSE(CMAKE_BUILD_TYPE STREQUAL Release)
169 +    SET(CASROOT_LIBDIR ${CASROOT}/win32/lib ${CASROOT}/win64/vc14/lib)
170 +  ENDIF(CMAKE_BUILD_TYPE STREQUAL Debug)
171 +ELSE(WINDOWS)
172 +  SET(CASROOT_LIBDIR ${CASROOT}/lib)
173 +ENDIF(WINDOWS)
174 +
175 +SET(_CAS_VERSION_FILE_NAME Standard_Version.hxx)
176 +
177 +# Include directories:
178 +FIND_PATH(CAS_INCLUDE_DIRS ${_CAS_VERSION_FILE_NAME} PATHS ${CASROOT} PATH_SUFFIXES include/opencascade)
179 +IF(CAS_INCLUDE_DIRS)
180 +ELSE()
181 +  FIND_PATH(CAS_INCLUDE_DIRS ${_CAS_VERSION_FILE_NAME} PATHS ${CASROOT} PATH_SUFFIXES include inc)
182 +ENDIF()
183 +
184 +
185 +FIND_LIBRARY(BinLPlugin BinLPlugin PATHS ${CASROOT_LIBDIR})
186 +FIND_LIBRARY(BinPlugin BinPlugin PATHS ${CASROOT_LIBDIR})
187 +FIND_LIBRARY(BinTObjPlugin BinTObjPlugin PATHS ${CASROOT_LIBDIR})
188 +FIND_LIBRARY(BinXCAFPlugin BinXCAFPlugin PATHS ${CASROOT_LIBDIR})
189 +FIND_LIBRARY(FWOSPlugin FWOSPlugin PATHS ${CASROOT_LIBDIR})
190 +
191 +FIND_LIBRARY(PTKernel PTKernel PATHS ${CASROOT_LIBDIR})
192 +FIND_LIBRARY(StdLPlugin StdLPlugin PATHS ${CASROOT_LIBDIR})
193 +FIND_LIBRARY(StdPlugin StdPlugin PATHS ${CASROOT_LIBDIR})
194 +FIND_LIBRARY(TKAdvTools TKAdvTools PATHS ${CASROOT_LIBDIR})
195 +FIND_LIBRARY(TKBin TKBin PATHS ${CASROOT_LIBDIR})
196 +FIND_LIBRARY(TKBinL TKBinL PATHS ${CASROOT_LIBDIR})
197 +FIND_LIBRARY(TKBinTObj TKBinTObj PATHS ${CASROOT_LIBDIR})
198 +FIND_LIBRARY(TKBinXCAF TKBinXCAF PATHS ${CASROOT_LIBDIR})
199 +FIND_LIBRARY(TKBO TKBO PATHS ${CASROOT_LIBDIR})
200 +FIND_LIBRARY(TKBool TKBool PATHS ${CASROOT_LIBDIR})
201 +FIND_LIBRARY(TKBRep TKBRep PATHS ${CASROOT_LIBDIR})
202 +FIND_LIBRARY(TKCAF TKCAF PATHS ${CASROOT_LIBDIR})
203 +FIND_LIBRARY(TKCDF TKCDF PATHS ${CASROOT_LIBDIR})
204 +FIND_LIBRARY(TKernel TKernel PATHS ${CASROOT_LIBDIR})
205 +FIND_LIBRARY(TKFeat TKFeat PATHS ${CASROOT_LIBDIR})
206 +FIND_LIBRARY(TKFillet TKFillet PATHS ${CASROOT_LIBDIR})
207 +FIND_LIBRARY(TKG2d TKG2d PATHS ${CASROOT_LIBDIR})
208 +FIND_LIBRARY(TKG3d TKG3d PATHS ${CASROOT_LIBDIR})
209 +FIND_LIBRARY(TKGeomAlgo TKGeomAlgo PATHS ${CASROOT_LIBDIR})
210 +FIND_LIBRARY(TKGeomBase TKGeomBase PATHS ${CASROOT_LIBDIR})
211 +FIND_LIBRARY(TKHLR TKHLR PATHS ${CASROOT_LIBDIR})
212 +FIND_LIBRARY(TKIGES TKIGES PATHS ${CASROOT_LIBDIR})
213 +FIND_LIBRARY(TKLCAF TKLCAF PATHS ${CASROOT_LIBDIR})
214 +FIND_LIBRARY(TKMath TKMath PATHS ${CASROOT_LIBDIR})
215 +FIND_LIBRARY(TKMesh TKMesh PATHS ${CASROOT_LIBDIR})
216 +FIND_LIBRARY(TKMeshVS TKMeshVS PATHS ${CASROOT_LIBDIR})
217 +FIND_LIBRARY(TKNIS TKNIS PATHS ${CASROOT_LIBDIR})
218 +FIND_LIBRARY(TKOffset TKOffset PATHS ${CASROOT_LIBDIR})
219 +FIND_LIBRARY(TKOpenGl TKOpenGl PATHS ${CASROOT_LIBDIR})
220 +FIND_LIBRARY(TKPCAF TKPCAF PATHS ${CASROOT_LIBDIR})
221 +FIND_LIBRARY(TKPLCAF TKPLCAF PATHS ${CASROOT_LIBDIR})
222 +FIND_LIBRARY(TKPrim TKPrim PATHS ${CASROOT_LIBDIR})
223 +FIND_LIBRARY(TKPShape TKPShape PATHS ${CASROOT_LIBDIR})
224 +FIND_LIBRARY(TKService TKService PATHS ${CASROOT_LIBDIR})
225 +FIND_LIBRARY(TKShapeSchema TKShapeSchema PATHS ${CASROOT_LIBDIR})
226 +FIND_LIBRARY(TKShHealing TKShHealing PATHS ${CASROOT_LIBDIR})
227 +FIND_LIBRARY(TKStdLSchema TKStdLSchema PATHS ${CASROOT_LIBDIR})
228 +FIND_LIBRARY(TKStdSchema TKStdSchema PATHS ${CASROOT_LIBDIR})
229 +FIND_LIBRARY(TKSTEP TKSTEP PATHS ${CASROOT_LIBDIR})
230 +FIND_LIBRARY(TKSTEP209 TKSTEP209 PATHS ${CASROOT_LIBDIR})
231 +FIND_LIBRARY(TKSTEPAttr TKSTEPAttr PATHS ${CASROOT_LIBDIR})
232 +FIND_LIBRARY(TKSTEPBase TKSTEPBase PATHS ${CASROOT_LIBDIR})
233 +FIND_LIBRARY(TKSTL TKSTL PATHS ${CASROOT_LIBDIR})
234 +FIND_LIBRARY(TKTObj TKTObj PATHS ${CASROOT_LIBDIR})
235 +FIND_LIBRARY(TKTopAlgo TKTopAlgo PATHS ${CASROOT_LIBDIR})
236 +FIND_LIBRARY(TKV2d TKV2d PATHS ${CASROOT_LIBDIR})
237 +FIND_LIBRARY(TKV3d TKV3d PATHS ${CASROOT_LIBDIR})
238 +FIND_LIBRARY(TKVRML TKVRML PATHS ${CASROOT_LIBDIR})
239 +FIND_LIBRARY(TKXCAF TKXCAF PATHS ${CASROOT_LIBDIR})
240 +FIND_LIBRARY(TKXCAFSchema TKXCAFSchema PATHS ${CASROOT_LIBDIR})
241 +FIND_LIBRARY(TKXDEIGES TKXDEIGES PATHS ${CASROOT_LIBDIR})
242 +FIND_LIBRARY(TKXDESTEP TKXDESTEP PATHS ${CASROOT_LIBDIR})
243 +FIND_LIBRARY(TKXMesh TKXMesh PATHS ${CASROOT_LIBDIR})
244 +FIND_LIBRARY(TKXml TKXml PATHS ${CASROOT_LIBDIR})
245 +FIND_LIBRARY(TKXmlL TKXmlL PATHS ${CASROOT_LIBDIR})
246 +FIND_LIBRARY(TKXmlTObj TKXmlTObj PATHS ${CASROOT_LIBDIR})
247 +FIND_LIBRARY(TKXmlXCAF TKXmlXCAF PATHS ${CASROOT_LIBDIR})
248 +FIND_LIBRARY(TKXSBase TKXSBase PATHS ${CASROOT_LIBDIR})
249 +FIND_LIBRARY(XCAFPlugin XCAFPlugin PATHS ${CASROOT_LIBDIR})
250 +FIND_LIBRARY(XmlLPlugin XmlLPlugin PATHS ${CASROOT_LIBDIR})
251 +FIND_LIBRARY(XmlPlugin XmlPlugin PATHS ${CASROOT_LIBDIR})
252 +FIND_LIBRARY(XmlTObjPlugin XmlTObjPlugin PATHS ${CASROOT_LIBDIR})
253 +FIND_LIBRARY(XmlXCAFPlugin XmlXCAFPlugin PATHS ${CASROOT_LIBDIR})
254 +
255 +SET(CAS_KERNEL ${TKernel} ${TKMath})
256 +SET(CAS_OCAF ${TKernel} ${TKMath} ${TKCDF} ${TKLCAF})
257 +SET(CAS_VIEWER ${TKService} ${TKV3d} ${TKG3d} ${TKGeomBase} ${TKBRep})
258 +SET(CAS_OCAFVIS ${TKCAF} ${TKBRep} ${TKG2d})
259 +SET(CAS_MODELER ${TKG3d} ${TKGeomBase} ${TKGeomAlgo} ${TKBRep} ${TKTopAlgo} ${TKG2d})
260 +
261 +SET(TKV3d_EA ${TKernel} ${TKMath} ${TKV3d})
262 +SET(TKBool_EA ${TKernel} ${TKMath} ${TKBRep} ${TKG2d} ${TKG3d} ${TKGeomBase} ${TKGeomAlgo} ${TKTopAlgo} ${TKBool})
263 +SET(TKBRep_EA ${TKernel} ${TKMath} ${TKBRep})
264 +SET(TKIGES_EA ${TKernel} ${TKMath} ${TKXSBase} ${TKBRep} ${TKIGES})
265 +SET(TKSTEP_EA ${TKernel} ${TKMath} ${TKXSBase} ${TKBRep} ${TKSTEP})
266 +SET(TKSTL_EA ${TKernel} ${TKMath} ${TKSTL})
267 +SET(TKCAF_EA ${TKPrim} ${TKCAF})
268 +
269 +SET(TKV3d ${TKV3d_EA})
270 +SET(TKBool ${TKBool_EA})
271 +SET(TKBRep ${TKBRep_EA})
272 +SET(TKIGES ${TKIGES_EA})
273 +SET(TKSTEP ${TKSTEP_EA})
274 +SET(TKSTL ${TKSTL_EA})
275 +SET(TKCAF ${TKCAF_EA})
276 +
277 +#LIBRARIES
278 +SET(OCCLIBS ${CAS_LDPATH})
279 +SET(OCCLIBS ${OCCLIBS} ${TKernel} ${TKGeomBase} ${TKMath} ${TKG2d} ${TKG3d} ${TKXSBase} ${TKOffset} ${TKFillet} ${TKShHealing})
280 +SET(OCCLIBS ${OCCLIBS} ${TKMesh} ${TKMeshVS} ${TKTopAlgo} ${TKGeomAlgo} ${TKBool} ${TKPrim} ${TKBO} ${TKIGES} ${TKBRep})
281 +SET(OCCLIBS ${OCCLIBS} ${TKSTEPBase} ${TKSTEP} ${TKSTL} ${TKSTEPAttr} ${TKSTEP209} ${TKXDESTEP} ${TKXDEIGES} ${TKXCAF} ${TKLCAF})
282 \ No newline at end of file
283 --- /dev/null
284 +++ netgen/cmake/FindPLATFORM.cmake
285 @@ -0,0 +1,96 @@
286 +#  Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
287 +#
288 +#  This library is free software; you can redistribute it and/or
289 +#  modify it under the terms of the GNU Lesser General Public
290 +#  License as published by the Free Software Foundation; either
291 +#  version 2.1 of the License.
292 +#
293 +#  This library is distributed in the hope that it will be useful,
294 +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
295 +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
296 +#  Lesser General Public License for more details.
297 +#
298 +#  You should have received a copy of the GNU Lesser General Public
299 +#  License along with this library; if not, write to the Free Software
300 +#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
301 +#
302 +#  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
303 +#
304 +
305 +MARK_AS_ADVANCED(ISSUE)
306 +FIND_FILE(ISSUE issue /etc)
307 +IF(ISSUE)
308 +  SET(WINDOWS 0)
309 +ELSE()
310 +  SET(WINDOWS 1)
311 +ENDIF(ISSUE)
312 +
313 +IF(WINDOWS)
314 +  SET(MACHINE WINDOWS)
315 +ELSE(WINDOWS)
316 +  SET(MACHINE PCLINUX)
317 +ENDIF(WINDOWS)
318 +
319 +SET(CMAKE_INSTALL_PREFIX_ENV $ENV{CMAKE_INSTALL_PREFIX})
320 +IF(CMAKE_INSTALL_PREFIX_ENV)
321 +  SET(CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX_ENV} CACHE PATH "installation prefix" FORCE)
322 +ENDIF(CMAKE_INSTALL_PREFIX_ENV)
323 +
324 +IF(NOT CMAKE_BUILD_TYPE)
325 +  SET(CMAKE_BUILD_TYPE $ENV{CMAKE_BUILD_TYPE})
326 +ENDIF(NOT CMAKE_BUILD_TYPE)
327 +
328 +IF(NOT CMAKE_BUILD_TYPE)
329 +  SET(CMAKE_BUILD_TYPE Release)
330 +ENDIF(NOT CMAKE_BUILD_TYPE)
331 +
332 +IF(WINDOWS)
333 +ELSE(WINDOWS)
334 +  SET(ADD_WERROR ON)
335 +  SET(NAMES ACCEPT_SALOME_WARNINGS ACCEPT_${MODULE}_WARNINGS I_AM_A_TROLL_I_DO_NOT_FIX_${MODULE}_WARNINGS)
336 +  FOREACH(name ${NAMES})
337 +    SET(VAL $ENV{${name}})
338 +    IF(X${VAL} STREQUAL X0)
339 +      SET(ADD_WERROR ON)
340 +    ENDIF(X${VAL} STREQUAL X0)
341 +    IF(X${VAL} STREQUAL X1)
342 +      SET(ADD_WERROR OFF)
343 +    ENDIF(X${VAL} STREQUAL X1)
344 +  ENDFOREACH(name ${NAMES})
345 +  IF(ADD_WERROR)
346 +    SET(CMAKE_C_FLAGS "-Werror")
347 +    SET(CMAKE_CXX_FLAGS "-Werror")
348 +  ENDIF(ADD_WERROR)
349 +ENDIF(WINDOWS)
350 +
351 +IF(CMAKE_BUILD_TYPE)
352 +  IF(WINDOWS)
353 +    MARK_AS_ADVANCED(CLEAR CMAKE_CONFIGURATION_TYPES)
354 +    SET(CMAKE_CONFIGURATION_TYPES ${CMAKE_BUILD_TYPE} CACHE STRING "compilation types" FORCE)
355 +  ELSE(WINDOWS)
356 +    IF(CMAKE_BUILD_TYPE STREQUAL Debug)
357 +      SET(CMAKE_C_FLAGS_DEBUG "-g")
358 +      SET(CMAKE_CXX_FLAGS_DEBUG "-g")
359 +    ENDIF(CMAKE_BUILD_TYPE STREQUAL Debug)
360 +    IF(CMAKE_BUILD_TYPE STREQUAL Release)
361 +      SET(CMAKE_C_FLAGS_RELEASE "-O1 -DNDEBUG")
362 +      SET(CMAKE_CXX_FLAGS_RELEASE "-O1 -DNDEBUG")
363 +    ENDIF(CMAKE_BUILD_TYPE STREQUAL Release)
364 +  ENDIF(WINDOWS)
365 +ENDIF(CMAKE_BUILD_TYPE)
366 +
367 +SET(PLATFORM_CPPFLAGS)
368 +SET(PLATFORM_LDFLAGS)
369 +SET(PLATFORM_LIBADD)
370 +IF(WINDOWS)
371 +  ADD_DEFINITIONS(-D_CRT_SECURE_NO_WARNINGS)  # To disable windows warnings for strcpy, fopen, ...
372 +  ADD_DEFINITIONS(-D_SCL_SECURE_NO_WARNINGS)  # To disable windows warnings std::copy, std::transform, ...
373 +  ADD_DEFINITIONS(-DWNT)
374 +  ADD_DEFINITIONS(-DPPRO_NT) # For medfile
375 +  ADD_DEFINITIONS(-D_USE_MATH_DEFINES) # At least for MEDMEM
376 +  ADD_DEFINITIONS(-D_WIN32_WINNT=0x0500) # Windows 2000 or later API is required
377 +  SET(PLATFORM_LIBADD ${PLATFORM_LIBADD} Ws2_32.lib)
378 +  SET(PLATFORM_LIBADD ${PLATFORM_LIBADD} Userenv.lib) # At least for GEOM suit
379 +ELSE(WINDOWS)
380 +  SET(PLATFORM_LIBADD ${PLATFORM_LIBADD} -ldl)
381 +ENDIF(WINDOWS) 
382 \ No newline at end of file
383 --- /dev/null
384 +++ netgen/cmake/FindZLIB.cmake
385 @@ -0,0 +1,45 @@
386 +#  Copyright (C) 2007-2016  CEA/DEN, EDF R&D, OPEN CASCADE
387 +#
388 +#  This library is free software; you can redistribute it and/or
389 +#  modify it under the terms of the GNU Lesser General Public
390 +#  License as published by the Free Software Foundation; either
391 +#  version 2.1 of the License.
392 +#
393 +#  This library is distributed in the hope that it will be useful,
394 +#  but WITHOUT ANY WARRANTY; without even the implied warranty of
395 +#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
396 +#  Lesser General Public License for more details.
397 +#
398 +#  You should have received a copy of the GNU Lesser General Public
399 +#  License along with this library; if not, write to the Free Software
400 +#  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
401 +#
402 +#  See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
403 +#
404 +
405 +SET(_ZLIB_SDIRS)
406 +
407 +# Search in ZLIB_ROOT_DIR first
408 +IF(ZLIB_ROOT_DIR)
409 +  SET(_ZLIB_SEARCH_ROOT PATHS ${ZLIB_ROOT_DIR} NO_DEFAULT_PATH)
410 +  list(APPEND _ZLIB_SDIRS _ZLIB_SEARCH_ROOT)
411 +ENDIF()
412 +
413 +SET(ZLIB_NAMES z zlib zdll zlib1 zlibd zlibd1 zlib1d)
414 +
415 +# Try each search configuration.
416 +FOREACH(search ${_ZLIB_SDIRS})
417 +  FIND_PATH(ZLIB_INCLUDE_DIR NAMES zlib.h        ${${search}} PATH_SUFFIXES include)
418 +  FIND_LIBRARY(ZLIB_LIBRARY  NAMES ${ZLIB_NAMES} ${search} PATH_SUFFIXES lib)
419 +ENDFOREACH()
420 +
421 +MARK_AS_ADVANCED(ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
422 +
423 +
424 +INCLUDE(FindPackageHandleStandardArgs)
425 +FIND_PACKAGE_HANDLE_STANDARD_ARGS(ZLIB REQUIRED_VARS ZLIB_LIBRARY ZLIB_INCLUDE_DIR)
426 +
427 +IF(ZLIB_FOUND)
428 +    SET(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})
429 +    SET(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
430 +ENDIF()
431 --- netgen_ref/configure.ac
432 +++ netgen/configure.ac
433 @@ -20,7 +20,7 @@
434  CXXFLAGS="$CXXFLAGS $OPENMP_CXXFLAGS"
435  # LDFLAGS="$LDFLAGS $OPENMP_CXXFLAGS"
436  
437 -AM_PROG_AR
438 +m4_ifdef([AM_PROG_AR], [AM_PROG_AR])
439  AC_PROG_LIBTOOL
440  LT_INIT
441  
442 @@ -42,8 +42,8 @@
443  
444  if test a$occon = atrue ; then
445  
446 -       AC_SUBST([OCCFLAGS], ["-DOCCGEOMETRY -I$occdir/inc -I/usr/include/opencascade"])
447 -       AC_SUBST([OCCLIBS], ["-L$occdir/lib -lTKernel -lTKGeomBase -lTKMath -lTKG2d -lTKG3d -lTKXSBase -lTKOffset -lTKFillet -lTKShHealing -lTKMesh -lTKMeshVS -lTKTopAlgo -lTKGeomAlgo -lTKBool -lTKPrim -lTKBO -lTKIGES -lTKBRep -lTKSTEPBase -lTKSTEP -lTKSTL -lTKSTEPAttr -lTKSTEP209 -lTKXDESTEP -lTKXDEIGES -lTKXCAF -lTKLCAF -lFWOSPlugin"])
448 +       AC_SUBST([OCCFLAGS], ["-DOCCGEOMETRY -I$occdir/include/opencascade"])
449 +       AC_SUBST([OCCLIBS], ["-L$occdir/lib -lTKernel -lTKGeomBase -lTKMath -lTKG2d -lTKG3d -lTKXSBase -lTKOffset -lTKFillet -lTKShHealing -lTKMesh -lTKMeshVS -lTKTopAlgo -lTKGeomAlgo -lTKBool -lTKPrim -lTKBO -lTKIGES -lTKBRep -lTKSTEPBase -lTKSTEP -lTKSTL -lTKSTEPAttr -lTKSTEP209 -lTKXDESTEP -lTKXDEIGES -lTKXCAF -lTKLCAF"])
450  
451  #  -lTKDCAF
452  
453 --- netgen_ref/libsrc/csg/Makefile.am
454 +++ netgen/libsrc/csg/Makefile.am
455 @@ -8,7 +8,7 @@
456  AM_CPPFLAGS = -I$(top_srcdir)/libsrc/include  $(TCL_INCLUDES)
457  METASOURCES = AUTO
458  
459 -lib_LTLIBRARIES = libcsg.la
460 +noinst_LTLIBRARIES = libcsg.la
461  
462  
463  libcsg_la_SOURCES = algprim.cpp brick.cpp   \
464 @@ -17,12 +17,9 @@
465  manifold.cpp meshsurf.cpp polyhedra.cpp revolution.cpp singularref.cpp \
466  solid.cpp specpoin.cpp spline3d.cpp surface.cpp triapprox.cpp
467  
468 -libcsg_la_LIBADD =  $(top_builddir)/libsrc/meshing/libmesh.la
469  
470 -
471 -
472  if NGGUI
473 -lib_LTLIBRARIES += libcsgvis.la 
474 +lib_LTLIBRARIES = libcsgvis.la 
475  
476  libcsgvis_la_SOURCES = vscsg.cpp csgpkg.cpp
477  libcsgvis_la_LIBADD = libcsg.la
478 --- netgen_ref/libsrc/csg/specpoin.hpp
479 +++ netgen/libsrc/csg/specpoin.hpp
480 @@ -8,10 +8,12 @@
481  /* Date:   01. Okt. 95                                                    */
482  /**************************************************************************/
483  
484 +#include <myadt.hpp>
485 +
486  namespace netgen
487  {
488  
489 -  extern DLL_HEADER MeshingParameters mparam;
490 +  DLL_HEADER extern MeshingParameters mparam;
491  
492    /*
493  
494 --- netgen_ref/libsrc/general/array.hpp
495 +++ netgen/libsrc/general/array.hpp
496 @@ -50,7 +50,7 @@
497      {
498  #ifdef DEBUG
499        if (i-BASE < 0 || i-BASE >= size)
500 -       cout << "array<" << typeid(T).name() << "> out of range, i = " << i << ", s = " << size << endl;
501 +       std::cout << "array<" << typeid(T).name() << "> out of range, i = " << i << ", s = " << size << std::endl;
502  #endif
503  
504        return data[i-BASE]; 
505 @@ -69,9 +69,9 @@
506      {
507  #ifdef DEBUG
508        if (i < 1 || i > size)
509 -       cout << "Array<" << typeid(T).name() 
510 +       std::cout << "Array<" << typeid(T).name() 
511              << ">::Elem out of range, i = " << i
512 -            << ", s = " << size << endl;
513 +            << ", s = " << size << std::endl;
514  #endif
515  
516        return ((T*)data)[i-1]; 
517 @@ -82,8 +82,8 @@
518      {
519  #ifdef DEBUG
520        if (i < 1 || i > size)
521 -       cout << "Array<" << typeid(T).name() << ">::Get out of range, i = " << i
522 -            << ", s = " << size << endl;
523 +       std::cout << "Array<" << typeid(T).name() << ">::Get out of range, i = " << i
524 +            << ", s = " << size << std::endl;
525  #endif
526  
527        return ((const T*)data)[i-1]; 
528 @@ -94,8 +94,8 @@
529      { 
530  #ifdef DEBUG
531        if (i < 1 || i > size)
532 -       cout << "Array<" << typeid(T).name() << ">::Set out of range, i = " << i
533 -            << ", s = " << size << endl;
534 +       std::cout << "Array<" << typeid(T).name() << ">::Set out of range, i = " << i
535 +            << ", s = " << size << std::endl;
536  #endif
537  
538        ((T*)data)[i-1] = el; 
539 @@ -151,7 +151,7 @@
540    inline ostream & operator<< (ostream & s, const FlatArray<T,BASE,TIND> & a)
541    {
542      for (TIND i = a.Begin(); i < a.End(); i++)
543 -      s << i << ": " << a[i] << endl;
544 +      s << i << ": " << a[i] << std::endl;
545      return s;
546    }
547  
548 @@ -435,7 +435,7 @@
549    inline ostream & operator<< (ostream & s, const IndirectArray<T1,T2> & ia)
550    {
551      for (int i = ia.Begin(); i < ia.End(); i++)
552 -      s << i << ": " << ia[i] << endl;
553 +      s << i << ": " << ia[i] << std::endl;
554      return s;
555    }
556    
557 @@ -551,7 +551,7 @@
558      void PrintMemInfo (ostream & ost) const
559      {
560        ost << Size() << " elements of size " << sizeof(T) << " = " 
561 -         << Size() * sizeof(T) << endl;
562 +         << Size() * sizeof(T) << std::endl;
563      }
564  
565      MoveableArray & operator= (const T & el)
566 @@ -593,7 +593,7 @@
567    inline ostream & operator<< (ostream & ost, MoveableArray<T> & a)
568    {
569      for (int i = 0; i < a.Size(); i++)
570 -      ost << i << ": " << a[i] << endl;
571 +      ost << i << ": " << a[i] << std::endl;
572      return ost;
573    }
574    */
575 --- netgen_ref/libsrc/general/hashtabl.hpp
576 +++ netgen/libsrc/general/hashtabl.hpp
577 @@ -182,9 +182,9 @@
578    ///
579    void PrintMemInfo (ostream & ost) const
580    {
581 -    ost << "Hash: " << endl;
582 +    ost << "Hash: " << std::endl;
583      hash.PrintMemInfo (ost);
584 -    ost << "Cont: " << endl;
585 +    ost << "Cont: " << std::endl;
586      cont.PrintMemInfo (ost);
587    }
588  
589 @@ -212,7 +212,7 @@
590  
591      void operator++ (int)
592      {
593 -      // cout << "begin Operator ++: bagnr = " << bagnr << " -  pos = " << pos << endl;
594 +      // std::cout << "begin Operator ++: bagnr = " << bagnr << " -  pos = " << pos << std::endl;
595        pos++;
596        while (bagnr < ht.GetNBags() && 
597              pos == ht.GetBagSize(bagnr+1))
598 @@ -220,7 +220,7 @@
599           pos = 0;
600           bagnr++;
601         }
602 -      // cout << "end Operator ++: bagnr = " << bagnr << " - pos = " << pos << endl;
603 +      // std::cout << "end Operator ++: bagnr = " << bagnr << " - pos = " << pos << std::endl;
604      }
605  
606      bool operator != (int i) const
607 @@ -264,7 +264,7 @@
608    for (typename INDEX_2_HASHTABLE<T>::Iterator it = ht.Begin();
609         it != ht.End(); it++)
610      {
611 -      ost << ht.GetHash(it) << ": " << ht.GetData(it) << endl;
612 +      ost << ht.GetHash(it) << ": " << ht.GetData(it) << std::endl;
613      }
614  
615    return ost;
616 @@ -375,7 +375,7 @@
617  
618      void operator++ (int)
619      {
620 -      // cout << "begin Operator ++: bagnr = " << bagnr << " -  pos = " << pos << endl;
621 +      // std::cout << "begin Operator ++: bagnr = " << bagnr << " -  pos = " << pos << std::endl;
622        pos++;
623        while (bagnr < ht.GetNBags() && 
624              pos == ht.GetBagSize(bagnr+1))
625 @@ -383,7 +383,7 @@
626           pos = 0;
627           bagnr++;
628         }
629 -      // cout << "end Operator ++: bagnr = " << bagnr << " - pos = " << pos << endl;
630 +      // std::cout << "end Operator ++: bagnr = " << bagnr << " - pos = " << pos << std::endl;
631      }
632  
633      bool operator != (int i) const
634 @@ -433,7 +433,7 @@
635    for (typename INDEX_3_HASHTABLE<T>::Iterator it = ht.Begin();
636         it != ht.End(); it++)
637      {
638 -      ost << ht.GetHash(it) << ": " << ht.GetData(it) << endl;
639 +      ost << ht.GetHash(it) << ": " << ht.GetData(it) << std::endl;
640      }
641  
642    return ost;
643 @@ -747,7 +747,7 @@
644         INDEX_2 hash;
645         T data;
646         ht.GetData (i, hash, data);
647 -       ost << "hash = " << hash << ", data = " << data << endl;
648 +       ost << "hash = " << hash << ", data = " << data << std::endl;
649        }
650    return ost;
651  }
652 @@ -917,9 +917,9 @@
653  
654    void PrintMemInfo (ostream & ost) const
655    {
656 -    cout << "Hashtable: " << Size() 
657 +    std::cout << "Hashtable: " << Size() 
658           << " entries of size " << sizeof(INDEX_3) << " + " << sizeof(T) 
659 -         << " = " << Size() * (sizeof(INDEX_3) + sizeof(T)) << " bytes" << endl;
660 +         << " = " << Size() * (sizeof(INDEX_3) + sizeof(T)) << " bytes" << std::endl;
661      
662    }
663  
664 @@ -947,7 +947,7 @@
665         INDEX_3 hash;
666         T data;
667         ht.GetData (i, hash, data);
668 -       ost << "hash = " << hash << ", data = " << data << endl;
669 +       ost << "hash = " << hash << ", data = " << data << std::endl;
670        }
671    return ost;
672  }
673 @@ -1079,9 +1079,9 @@
674  template<class T>
675  inline void INDEX_3_HASHTABLE<T> :: PrintMemInfo (ostream & ost) const
676    {
677 -    ost << "Hash: " << endl;
678 +    ost << "Hash: " << std::endl;
679      hash.PrintMemInfo (ost);
680 -    ost << "Cont: " << endl;
681 +    ost << "Cont: " << std::endl;
682      cont.PrintMemInfo (ost);
683    }
684  
685 @@ -1146,9 +1146,9 @@
686  template<class T>
687  inline void INDEX_HASHTABLE<T> :: PrintMemInfo (ostream & ost) const
688    {
689 -    ost << "Hash: " << endl;
690 +    ost << "Hash: " << std::endl;
691      hash.PrintMemInfo (ost);
692 -    ost << "Cont: " << endl;
693 +    ost << "Cont: " << std::endl;
694      cont.PrintMemInfo (ost);
695    }
696  
697 @@ -1249,11 +1249,11 @@
698  inline void INDEX_2_CLOSED_HASHTABLE<T> :: 
699  PrintMemInfo (ostream & ost) const
700  {
701 -  cout << "Hashtable: " << Size() 
702 +  std::cout << "Hashtable: " << Size() 
703         << " entries of size " << sizeof(INDEX_2) << " + " << sizeof(T) 
704         << " = " << Size() * (sizeof(INDEX_2) + sizeof(T)) << " bytes." 
705         << " Used els: " << UsedElements() 
706 -       << endl;
707 +       << std::endl;
708  }
709  
710  
711 @@ -1356,9 +1356,9 @@
712  inline void INDEX_3_CLOSED_HASHTABLE<T> :: 
713  PrintMemInfo (ostream & ost) const
714  {
715 -  cout << "Hashtable: " << Size() 
716 +  std::cout << "Hashtable: " << Size() 
717         << " entries of size " << sizeof(INDEX_3) << " + " << sizeof(T) 
718 -       << " = " << Size() * (sizeof(INDEX_3) + sizeof(T)) << " bytes" << endl;
719 +       << " = " << Size() * (sizeof(INDEX_3) + sizeof(T)) << " bytes" << std::endl;
720  }
721  */
722  
723 --- netgen_ref/libsrc/general/table.hpp
724 +++ netgen/libsrc/general/table.hpp
725 @@ -210,7 +210,7 @@
726    { 
727  #ifdef DEBUG
728      if (i-BASE < 0 || i-BASE >= data.Size())
729 -      cout << "table out of range, i = " << i << ", s = " << data.Size() << endl;
730 +      std::cout << "table out of range, i = " << i << ", s = " << data.Size() << std::endl;
731  #endif
732  
733      return FlatArray<T> (data[i-BASE].size, (T*)data[i-BASE].col);
734 --- netgen_ref/libsrc/general/template.hpp
735 +++ netgen/libsrc/general/template.hpp
736 @@ -26,10 +26,10 @@
737  DLL_HEADER extern ostream * testout;
738  
739  /** use instead of cout */
740 -extern ostream * mycout;
741 +DLL_HEADER extern ostream * mycout;
742  
743  /** error output stream */
744 -extern ostream * myerr;
745 +DLL_HEADER extern ostream * myerr;
746  
747  /** Error messages display.
748    Error messages are displayed by this function */
749 --- netgen_ref/libsrc/geom2d/Makefile.am
750 +++ netgen/libsrc/geom2d/Makefile.am
751 @@ -4,16 +4,15 @@
752  
753  METASOURCES = AUTO
754  
755 -lib_LTLIBRARIES = libgeom2d.la 
756 +noinst_LTLIBRARIES = libgeom2d.la 
757  
758  if NGGUI
759 -lib_LTLIBRARIES += libgeom2dvis.la 
760 +lib_LTLIBRARIES = libgeom2dvis.la 
761  endif
762  
763  
764  
765  libgeom2d_la_SOURCES = genmesh2d.cpp geom2dmesh.cpp geometry2d.cpp
766 -libgeom2d_la_LIBADD =  $(top_builddir)/libsrc/meshing/libmesh.la
767  
768  libgeom2dvis_la_SOURCES = geom2dpkg.cpp vsgeom2d.cpp
769  libgeom2dvis_la_LIBADD = libgeom2d.la
770 --- netgen_ref/libsrc/gprim/spline.hpp
771 +++ netgen/libsrc/gprim/spline.hpp
772 @@ -55,7 +55,7 @@
773      /// returns a (not necessarily unit-length) tangent vector for 0 <= t <= 1
774      virtual Vec<D> GetTangent (const double t) const
775      { 
776 -      cerr << "GetTangent not implemented for spline base-class"  << endl; 
777 +      std::cerr << "GetTangent not implemented for spline base-class"  << std::endl; 
778        Vec<D> dummy; return dummy;
779      }
780  
781 @@ -100,10 +100,10 @@
782      virtual string GetType(void) const {return "splinebase";}
783  
784      virtual void Project (const Point<D> point, Point<D> & point_on_curve, double & t) const
785 -    { cerr << "Project not implemented for spline base-class" << endl;}
786 +    { std::cerr << "Project not implemented for spline base-class" << std::endl;}
787  
788      virtual void GetRawData (Array<double> & data) const
789 -    { cerr << "GetRawData not implemented for spline base-class" << endl;}
790 +    { std::cerr << "GetRawData not implemented for spline base-class" << std::endl;}
791  
792    };
793  
794 @@ -300,7 +300,7 @@
795  
796  
797    template<int D>
798 -  void SplineSeg<D> :: PrintCoeff (ostream & ost) const
799 +  void SplineSeg<D> :: PrintCoeff (std::ostream & ost) const
800    {
801      Vector u(6);
802  
803 @@ -308,7 +308,7 @@
804  
805      for ( int i=0; i<6; i++)
806        ost << u[i] << "  ";
807 -    ost << endl;
808 +    ost << std::endl;
809    }
810  
811  
812 --- netgen_ref/libsrc/include/mystdlib.h
813 +++ netgen/libsrc/include/mystdlib.h
814 @@ -66,6 +66,7 @@
815  #  ifdef MSVC_EXPRESS
816  #   include <pthread.h>
817  #  else
818 +    #define _AFXDLL
819  #   include <afxwin.h>
820  #   include <afxmt.h>
821  #  endif // MSVC_EXPRESS
822 --- netgen_ref/libsrc/interface/Makefile.am
823 +++ netgen/libsrc/interface/Makefile.am
824 @@ -2,14 +2,11 @@
825  
826  AM_CPPFLAGS = -I$(top_srcdir)/libsrc/include -I$(top_srcdir)/libsrc/interface  $(MPI_INCLUDES) $(TCL_INCLUDES) -DOPENGL
827  METASOURCES = AUTO
828 -lib_LTLIBRARIES = libinterface.la
829 +noinst_LTLIBRARIES = libinterface.la
830  libinterface_la_SOURCES = nginterface.cpp nginterface_v2.cpp \
831         read_fnf_mesh.cpp readtetmesh.cpp readuser.cpp writeabaqus.cpp writediffpack.cpp \
832         writedolfin.cpp writeelmer.cpp writefeap.cpp writefluent.cpp writegmsh.cpp writejcm.cpp \
833         writepermas.cpp writetecplot.cpp writetet.cpp writetochnog.cpp writeuser.cpp \
834         wuchemnitz.cpp writegmsh2.cpp writeOpenFOAM15x.cpp 
835 -
836 -
837 -libinterface_la_LIBADD = $(top_builddir)/libsrc/meshing/libmesh.la
838  
839  # libinterface_la_LDFLAGS = -rdynamic
840 --- netgen_ref/libsrc/interface/nginterface.cpp
841 +++ netgen/libsrc/interface/nginterface.cpp
842 @@ -1,3 +1,18 @@
843 +#ifdef _MSC_VER
844 +#ifndef MSVC_EXPRESS
845 +
846 +#define _AFXDLL
847 +#define WINVER 0x0A00
848 +#define _WIN32_WINNT 0x0A00
849 +
850 +#include <Afxwin.h>
851 +#include <winsock2.h>
852 +#include <winsock.h>
853 +#include <windows.h>
854 +
855 +#endif
856 +#endif
857 +
858  #include <mystdlib.h>
859  
860  #include <meshing.hpp>
861 @@ -10,7 +25,6 @@
862  
863  #include "nginterface.h"
864  #include "../visualization/soldata.hpp"
865 -
866  
867  #ifdef _MSC_VER
868  // Philippose - 30/01/2009
869 --- netgen_ref/libsrc/linalg/densemat.hpp
870 +++ netgen/libsrc/linalg/densemat.hpp
871 @@ -62,24 +62,24 @@
872  #ifdef DEBUG
873      if (prod.Size() != height)
874        {
875 -       (*myerr) << "Mult: wrong vector size " << endl;
876 +       (*myerr) << "Mult: wrong vector size " << std::endl;
877        }
878      if (!height) 
879        {
880 -       cout << "DenseMatrix::Mult height = 0" << endl;
881 +       std::cout << "DenseMatrix::Mult height = 0" << std::endl;
882        }
883      if (!width) 
884        {
885 -       cout << "DenseMatrix::Mult width = 0" << endl;
886 +       std::cout << "DenseMatrix::Mult width = 0" << std::endl;
887        }
888      
889      if (width != v.Size())
890        {
891 -       (*myerr) << "\nMatrix and Vector don't fit" << endl;
892 +       (*myerr) << "\nMatrix and Vector don't fit" << std::endl;
893        }
894      else if (Height() != prod.Size())
895        {
896 -       (*myerr) << "Base_Matrix::operator*(Vector): prod vector not ok" << endl;
897 +       (*myerr) << "Base_Matrix::operator*(Vector): prod vector not ok" << std::endl;
898        }
899      else
900  #endif
901 @@ -208,7 +208,7 @@
902      /*    
903      if (prod.Size() != height)
904        {
905 -       cerr << "MatrixFixWidth::Mult: wrong vector size " << endl;
906 +       cerr << "MatrixFixWidth::Mult: wrong vector size " << std::endl;
907         assert (1);
908        }
909      */    
910 @@ -268,7 +268,7 @@
911      {
912        for (int j = 0; j < m.Width(); j++)
913         ost << m.Get(i+1,j+1) << " ";
914 -      ost << endl;
915 +      ost << std::endl;
916      }
917    return ost;
918  };
919 --- netgen_ref/libsrc/meshing/Makefile.am
920 +++ netgen/libsrc/meshing/Makefile.am
921 @@ -15,7 +15,7 @@
922  
923  METASOURCES = AUTO
924  
925 -lib_LTLIBRARIES = libmesh.la
926 +noinst_LTLIBRARIES = libmesh.la
927  
928  libmesh_la_SOURCES = adfront2.cpp adfront3.cpp bisect.cpp boundarylayer.cpp \
929         clusters.cpp curvedelems.cpp delaunay.cpp delaunay2d.cpp            \
930 @@ -30,8 +30,5 @@
931         topology.cpp triarls.cpp validate.cpp zrefine.cpp bcfunctions.cpp   \
932         parallelmesh.cpp  paralleltop.cpp  paralleltop.hpp basegeom.cpp 
933  
934 -libmesh_la_LIBADD =  $(top_builddir)/libsrc/linalg/libla.la \
935 -       $(top_builddir)/libsrc/gprim/libgprim.la \
936 -       $(top_builddir)/libsrc/general/libgen.la \
937 -       -lz
938 +libmesh_la_LIBADD = -lz
939  
940 --- netgen_ref/libsrc/meshing/classifyhpel.hpp
941 +++ netgen/libsrc/meshing/classifyhpel.hpp
942 @@ -64,11 +64,11 @@
943         
944         if (debug)
945           {
946 -           cout << "debug" << endl;
947 -           *testout  << "debug" << endl;
948 -           *testout << "ep = " << ep1 << ep2 << ep3 << ep4 << endl;
949 -           *testout << "cp = " << cp1 << cp2 << cp3 << cp4 << endl;
950 -           *testout << "edge = " << isedge1 << isedge2 << isedge3 << isedge4 << isedge5 << isedge6 << endl;
951 +           std::cout << "debug" << std::endl;
952 +           *testout  << "debug" << std::endl;
953 +           *testout << "ep = " << ep1 << ep2 << ep3 << ep4 << std::endl;
954 +           *testout << "cp = " << cp1 << cp2 << cp3 << cp4 << std::endl;
955 +           *testout << "edge = " << isedge1 << isedge2 << isedge3 << isedge4 << isedge5 << isedge6 << std::endl;
956           }
957  
958  
959 @@ -402,18 +402,18 @@
960        }
961    
962    
963 -  if (debug) cout << "type = " << type << endl;
964 +  if (debug) std::cout << "type = " << type << std::endl;
965  
966    if (type == HP_NONE)
967      {
968        //     cnt_undef++;
969 -      (*testout) << "undefined element" << endl
970 -                << "cp = " << cp1 << cp2 << cp3 << cp4 << endl
971 -                << "ep = " << ep1 << ep2 << ep3 << ep4 << endl
972 +      (*testout) << "undefined element" << std::endl
973 +                << "cp = " << cp1 << cp2 << cp3 << cp4 << std::endl
974 +                << "ep = " << ep1 << ep2 << ep3 << ep4 << std::endl
975                  << "isedge = " << isedge1 << isedge2 << isedge3 
976 -                << isedge4 << isedge5 << isedge6 << endl
977 -                << "isface = " << isface1 << isface2 << isface3 << isface4 << endl;
978 -      cout << "undefined element !!! " << endl;
979 +                << isedge4 << isedge5 << isedge6 << std::endl
980 +                << "isface = " << isface1 << isface2 << isface3 << isface4 << std::endl;
981 +      std::cout << "undefined element !!! " << std::endl;
982  
983        
984      }
985 @@ -597,7 +597,7 @@
986           
987         case 2:
988           if(sve[0] <= 1) 
989 -           cout << " **** WARNING: Edge between to different singular faces should be marked singular " << endl; 
990 +           std::cout << " **** WARNING: Edge between to different singular faces should be marked singular " << std::endl; 
991                       
992           if(sve[1] <= 1)   
993             if(sve[2] <=1) 
994 @@ -638,9 +638,9 @@
995      }
996          
997    /*
998 -   *testout << " Prism with pnums " << endl; 
999 +   *testout << " Prism with pnums " << std::endl; 
1000     for(int j=0;j<6;j++) *testout << el.pnums[j] << "\t"; 
1001 -   *testout << endl; 
1002 +   *testout << std::endl; 
1003     */
1004    
1005    if(type != HP_NONE) 
1006 @@ -650,9 +650,9 @@
1007        for(int k=0;k<6;k++) el.pnums[k] = pnums[k]; 
1008      }
1009  
1010 -  /* *testout << " Classified Prism with pnums " << endl; 
1011 +  /* *testout << " Classified Prism with pnums " << std::endl; 
1012       for(int j=0;j<6;j++) *testout << el.pnums[j] << "\t"; 
1013 -     *testout << endl; 
1014 +     *testout << std::endl; 
1015       */ 
1016    return(type); 
1017  }
1018 @@ -673,7 +673,7 @@
1019    i3.Sort();
1020    bool sing_face = faces.Used (i3);
1021    
1022 -  // *testout << " facepoint " << facepoint << endl;  
1023 +  // *testout << " facepoint " << facepoint << std::endl;  
1024        
1025  
1026    // Try all rotations of the trig 
1027 @@ -688,7 +688,7 @@
1028           pnums[m] = el.PNum(p[m]); // global vertex number 
1029           // *testout << pnums[m] << " \t "; 
1030         }
1031 -      // *testout << endl ; 
1032 +      // *testout << std::endl ; 
1033        
1034        if(dim == 3) 
1035         {
1036 @@ -696,9 +696,9 @@
1037           for(int k=0;k<3;k++)
1038             if(!sing_face)
1039               { 
1040 -               //      *testout << " fp [" << k << "] = " << facepoint[pnums[k]] << endl;   
1041 -               //      *testout << " fd.DomainIn()" <<  fd.DomainIn() << endl; 
1042 -               //      *testout  << " fd.DomainOut()" <<  fd.DomainOut() << endl; 
1043 +               //      *testout << " fp [" << k << "] = " << facepoint[pnums[k]] << std::endl;   
1044 +               //      *testout << " fd.DomainIn()" <<  fd.DomainIn() << std::endl; 
1045 +               //      *testout  << " fd.DomainOut()" <<  fd.DomainOut() << std::endl; 
1046                 if( facepoint[pnums[k]]  && (facepoint[pnums[k]] ==-1 || 
1047                                              facepoint[pnums[k]] == fd.DomainIn() ||   facepoint[pnums[k]] == fd.DomainOut()))
1048                   point_sing[p[k]-1] = 1; 
1049 @@ -707,7 +707,7 @@
1050  
1051           /*      *testout << " pointsing NACH FACEPOints ... FALLS EDGEPOINT UMSETZEN" ; 
1052              for (int k=0;k<3;k++) *testout << "\t" << point_sing[p[k]-1] ;
1053 -            *testout << endl; */
1054 +            *testout << std::endl; */
1055         }
1056        
1057        const ELEMENT_EDGE * eledges = MeshTopology::GetEdges1(TRIG); 
1058 @@ -746,13 +746,13 @@
1059               
1060               /*  *testout << " pointsing NACH edges UND FACEEDGES UMSETZEN ... " ; 
1061                    for (int k=0;k<3;k++) *testout << "\t" << point_sing[p[k]-1] ; 
1062 -                  *testout << endl;          
1063 +                  *testout << std::endl;          
1064                    */
1065             }
1066         }
1067        /*
1068 -       *testout << " dim " << dim << endl; 
1069 -       *testout << " edgepoint_dom " << edgepoint_dom << endl; 
1070 +       *testout << " dim " << dim << std::endl; 
1071 +       *testout << " edgepoint_dom " << edgepoint_dom << std::endl; 
1072         */
1073        if(dim==2)
1074         {
1075 @@ -796,7 +796,7 @@
1076         if(cornerpoint.Test(el.PNum(p[k]))) 
1077           point_sing[p[k]-1] = 3; 
1078        
1079 -      *testout << "point_sing = " << point_sing[0] << point_sing[1] << point_sing[2] << endl;
1080 +      *testout << "point_sing = " << point_sing[0] << point_sing[1] << point_sing[2] << std::endl;
1081  
1082        if(edge_sing[0] + edge_sing[1] + edge_sing[2] == 0) 
1083          { 
1084 @@ -854,21 +854,21 @@
1085            else if (edge_sing[2] && edge_sing[1] && edge_sing[0])
1086              type = HP_TRIG_3SINGEDGES; 
1087       
1088 -      //  cout << " run for " <<  j << " gives type " << type << endl; 
1089 -      //*testout << " run for " <<  j << " gives type " << type << endl; 
1090 +      //  std::cout << " run for " <<  j << " gives type " << type << std::endl; 
1091 +      //*testout << " run for " <<  j << " gives type " << type << std::endl; 
1092  
1093        if(type!=HP_NONE) break;
1094      }
1095  
1096 -  *testout << "type = " << type << endl;
1097 +  *testout << "type = " << type << std::endl;
1098      
1099    for(int k=0;k<3;k++) el[k] = pnums[k]; 
1100    /*if(type != HP_NONE) 
1101      {
1102       
1103 -    cout << " TRIG with pnums " << pnums[0] << "\t"  << 
1104 -    pnums[1] << "\t"  << pnums[2] << endl; 
1105 -    cout << " type "  << type << endl; 
1106 +    std::cout << " TRIG with pnums " << pnums[0] << "\t"  << 
1107 +    pnums[1] << "\t"  << pnums[2] << std::endl; 
1108 +    std::cout << " type "  << type << std::endl; 
1109      }
1110    */
1111        return(type);
1112 @@ -921,7 +921,7 @@
1113        ep3 |= cp3;
1114        
1115        
1116 -      // (*testout) << "cp = " << cp1 << cp2 << cp3 << ", ep = " << ep1 << ep2 << ep3 << endl;
1117 +      // (*testout) << "cp = " << cp1 << cp2 << cp3 << ", ep = " << ep1 << ep2 << ep3 << std::endl;
1118  
1119        int p[3] = { el.PNumMod (j), el.PNumMod (j+1), el.PNumMod (j+2)};
1120        if(ep1)
1121 @@ -980,7 +980,7 @@
1122               ep1 = 1; ep3=1;
1123             }
1124           
1125 -         // cout << " isedge " << isedge1 << " \t " << isedge2 << " \t " << isedge3 << endl;  
1126 +         // std::cout << " isedge " << isedge1 << " \t " << isedge2 << " \t " << isedge3 << std::endl;  
1127         
1128           if (!sing_face)
1129              {
1130 @@ -1031,11 +1031,11 @@
1131        
1132                   
1133        /*
1134 -        cout << " used " << face_edges.Used (INDEX_2::Sort (el.PNumMod(j), el.PNumMod(j+1))) << endl; 
1135 +        std::cout << " used " << face_edges.Used (INDEX_2::Sort (el.PNumMod(j), el.PNumMod(j+1))) << std::endl; 
1136  
1137 -        cout << " isedge " << isedge1 << " \t " << isedge2 << " \t " << isedge3 << endl; 
1138 -        cout << " ep " << ep1 << "\t" << ep2 << " \t " << ep3 << endl; 
1139 -        cout << " cp " << cp1 << "\t" << cp2 << " \t " << cp3 << endl; 
1140 +        std::cout << " isedge " << isedge1 << " \t " << isedge2 << " \t " << isedge3 << std::endl; 
1141 +        std::cout << " ep " << ep1 << "\t" << ep2 << " \t " << ep3 << std::endl; 
1142 +        std::cout << " cp " << cp1 << "\t" << cp2 << " \t " << cp3 << std::endl; 
1143        */
1144                   
1145  
1146 @@ -1127,9 +1127,9 @@
1147    /*if(type != HP_NONE) 
1148      {
1149       
1150 -    cout << " TRIG with pnums " << pnums[0] << "\t"  << 
1151 -    pnums[1] << "\t"  << pnums[2] << endl; 
1152 -    cout << " type "  << type << endl; 
1153 +    std::cout << " TRIG with pnums " << pnums[0] << "\t"  << 
1154 +    pnums[1] << "\t"  << pnums[2] << std::endl; 
1155 +    std::cout << " type "  << type << std::endl; 
1156      }
1157    */
1158    return(type);
1159 @@ -1144,7 +1144,7 @@
1160    int ep1(-1), ep2(-1), ep3(-1), ep4(-1), cp1(-1), cp2(-1), cp3(-1), cp4(-1);
1161    int isedge1, isedge2, isedge3, isedge4;
1162  
1163 -  *testout << "edges = " << edges << endl;
1164 +  *testout << "edges = " << edges << std::endl;
1165    
1166    for (int j = 1; j <= 4; j++)
1167      {
1168 @@ -1301,9 +1301,9 @@
1169        int sumep = ep1 + ep2 + ep3 + ep4;
1170        int sumedge = isedge1 + isedge2 + isedge3 + isedge4;
1171  
1172 -      *testout << "isedge = " << isedge1 << isedge2 << isedge3 << isedge4 << endl;
1173 -      *testout << "iscp = " << cp1 << cp2 << cp3 << cp4 << endl;
1174 -      *testout << "isep = " << ep1 << ep2 << ep3 << ep4 << endl;
1175 +      *testout << "isedge = " << isedge1 << isedge2 << isedge3 << isedge4 << std::endl;
1176 +      *testout << "iscp = " << cp1 << cp2 << cp3 << cp4 << std::endl;
1177 +      *testout << "isep = " << ep1 << ep2 << ep3 << ep4 << std::endl;
1178  
1179        switch (sumedge)
1180          {
1181 @@ -1463,23 +1463,23 @@
1182            pnums[3] = el.PNumMod (j+3);
1183            for (int k=0;k<4;k++) el[k] = pnums[k]; 
1184         
1185 -          /*  cout << " QUAD with pnums " << pnums[0] << "\t"  << 
1186 +          /*  std::cout << " QUAD with pnums " << pnums[0] << "\t"  << 
1187                pnums[1] << "\t"  << pnums[2] << "\t"  << pnums[3] 
1188 -              << endl << " of type " << type << endl; */
1189 +              << std::endl << " of type " << type << std::endl; */
1190                                       
1191            break;
1192          }
1193      }
1194    if (type == HP_NONE)
1195      {
1196 -      (*testout) << "undefined element" << endl
1197 -                 << "cp = " << cp1 << cp2 << cp3 << cp4 << endl
1198 -                 << "ep = " << ep1 << ep2 << ep3 << ep4 << endl
1199 +      (*testout) << "undefined element" << std::endl
1200 +                 << "cp = " << cp1 << cp2 << cp3 << cp4 << std::endl
1201 +                 << "ep = " << ep1 << ep2 << ep3 << ep4 << std::endl
1202                   << "isedge = " << isedge1 << isedge2 << isedge3 
1203 -                 << isedge4 << endl;
1204 +                 << isedge4 << std::endl;
1205      }
1206             
1207 -  *testout << "quad type = " << type << endl;
1208 +  *testout << "quad type = " << type << std::endl;
1209  
1210    return type;  
1211  }          
1212 @@ -1574,9 +1574,9 @@
1213             int pnums[8]; 
1214             for(int l=0;l<8;l++) pnums[l] = el[p[l]-1];
1215             for(int l=0;l<8;l++) el[l] = pnums[l];
1216 -           /* cout << " HEX with pnums " << pnums[0] << "\t"  << 
1217 +           /* std::cout << " HEX with pnums " << pnums[0] << "\t"  << 
1218                 pnums[1] << "\t"  << pnums[2] << "\t"  << pnums[3] << "\t"  << 
1219 -               pnums[4] << "\t"  <<  pnums[5] << endl << " of type " << type << endl; */
1220 +               pnums[4] << "\t"  <<  pnums[5] << std::endl << " of type " << type << std::endl; */
1221             break; 
1222           }
1223        }
1224 @@ -1623,7 +1623,7 @@
1225    else
1226      hpel.type = HP_SEGM_SINGCORNERS;
1227    
1228 -  // cout << " SEGM found with " << hpel[0] << " \t" << hpel[1] << endl << " of type " << hpel.type << endl; 
1229 +  // std::cout << " SEGM found with " << hpel[0] << " \t" << hpel[1] << std::endl << " of type " << hpel.type << std::endl; 
1230    return(hpel.type) ; 
1231  } 
1232  
1233 --- netgen_ref/libsrc/meshing/findip.hpp
1234 +++ netgen/libsrc/meshing/findip.hpp
1235 @@ -75,6 +75,9 @@
1236    static int timer = NgProfiler::CreateTimer ("FindInnerPoint");
1237    NgProfiler::RegionTimer reg (timer);
1238  
1239 +  if ( points.Size() < 3 )
1240 +    return 0;
1241 +
1242    Array<Vec3d> a;
1243    Array<double> c;
1244    Mat<3> m, inv;
1245 --- netgen_ref/libsrc/meshing/global.hpp
1246 +++ netgen/libsrc/meshing/global.hpp
1247 @@ -8,6 +8,8 @@
1248  /* Date:   01. Okt. 95                                                    */
1249  /**************************************************************************/
1250  
1251 +#include <myadt.hpp>
1252 +
1253  /*
1254    global functions and variables
1255  */
1256 @@ -29,7 +31,7 @@
1257  
1258    extern Array<int> tets_in_qualclass;
1259  
1260 -  class multithreadt
1261 +  class DLL_HEADER multithreadt
1262    {
1263    public:
1264      int pause;
1265 @@ -44,7 +46,7 @@
1266      multithreadt();
1267    };
1268  
1269 -  extern volatile multithreadt multithread;
1270 +  DLL_HEADER extern volatile multithreadt multithread;
1271  
1272    DLL_HEADER extern string ngdir;
1273    extern DebugParameters debugparam;
1274 --- netgen_ref/libsrc/meshing/improve3.cpp
1275 +++ netgen/libsrc/meshing/improve3.cpp
1276 @@ -1219,6 +1219,7 @@
1277  
1278               tetused = 0;
1279               tetused[0] = 1;
1280 +              int nbtetused = 0;
1281  
1282               for (int l = 2; l < nsuround; l++)
1283                 {
1284 @@ -1239,10 +1240,12 @@
1285                               
1286                               tetused[k] = 1; 
1287                               suroundpts[l] = newpi;
1288 +                              ++nbtetused;
1289                             }                   
1290                       }
1291                 }
1292 -
1293 +              if ( nbtetused < nsuround )
1294 +                continue;
1295               
1296               bad1 = 0;
1297               for (int k = 0; k < nsuround; k++)
1298 --- netgen_ref/libsrc/meshing/meshclass.hpp
1299 +++ netgen/libsrc/meshing/meshclass.hpp
1300 @@ -311,7 +311,7 @@
1301      { return lockedpoints; }
1302  
1303      /// Returns number of domains
1304 -    int GetNDomains() const;
1305 +    DLL_HEADER int GetNDomains() const;
1306  
1307      ///
1308      int GetDimension() const 
1309 @@ -320,7 +320,7 @@
1310      { dimension = dim; }
1311  
1312      /// sets internal tables
1313 -    void CalcSurfacesOfNode ();
1314 +    void DLL_HEADER CalcSurfacesOfNode ();
1315  
1316      /// additional (temporarily) fix points 
1317      void FixPoints (const BitArray & fixpoints);
1318 @@ -390,13 +390,13 @@
1319      ///
1320      DLL_HEADER void SetGlobalH (double h);
1321      ///
1322 -    void SetMinimalH (double h);
1323 +    void DLL_HEADER SetMinimalH (double h);
1324      ///
1325      double MaxHDomain (int dom) const;
1326      ///
1327      void SetMaxHDomain (const Array<double> & mhd);
1328      ///
1329 -    double GetH (const Point3d & p) const;
1330 +    double DLL_HEADER GetH (const Point3d & p) const;
1331      ///
1332      double GetMinH (const Point3d & pmin, const Point3d & pmax);
1333      ///
1334 --- netgen_ref/libsrc/meshing/meshtype.cpp
1335 +++ netgen/libsrc/meshing/meshtype.cpp
1336 @@ -1,4 +1,5 @@
1337  #include <mystdlib.h>
1338 +#include <float.h> // to get DBL_MIN defined
1339  
1340  #include "meshing.hpp"  
1341  
1342 @@ -666,7 +667,8 @@
1343  
1344          double det = trans.Det();
1345  
1346 -        if (det <= 0)
1347 +        // if (det <= 0)
1348 +        if (det <= DBL_MIN) // avoid FPE
1349            err += 1e12;
1350          else
1351            err += frob * frob / det;
1352 @@ -722,7 +724,8 @@
1353  
1354              double det = trans(0,0)*trans(1,1)-trans(1,0)*trans(0,1);
1355  
1356 -            if (det <= 0)
1357 +            // if (det <= 0)
1358 +            if (det <= DBL_MIN)  // avoid FPE
1359                {
1360                  dd = 0;
1361                  return 1e12;
1362 @@ -806,7 +809,8 @@
1363            = dtrans(0,0) * trans(1,1) - trans(0,1) * dtrans(1,0)
1364            + trans(0,0) * dtrans(1,1) - dtrans(0,1) * trans(1,0);
1365  
1366 -        if (det <= 0)
1367 +        // if (det <= 0)
1368 +        if (det <= DBL_MIN) // avoid FPE
1369            err += 1e12;
1370          else
1371            {
1372 @@ -856,7 +860,8 @@
1373          frob /= 2;
1374  
1375          double det = trans.Det();
1376 -        if (det <= 0)
1377 +        //if (det <= 0)
1378 +        if (det <= DBL_MIN) // avoid FPE
1379            err += 1e12;
1380          else
1381            err += frob * frob / det;
1382 @@ -1864,7 +1869,8 @@
1383        case PYRAMID:
1384          {
1385            double noz = 1-p(2);
1386 -          if (noz == 0.0) noz = 1e-10;
1387 +          //if (noz == 0.0) noz = 1e-10;
1388 +          if (noz <= DBL_MIN) noz = 1e-10; // avoid FPE
1389  
1390            double xi  = p(0) / noz;
1391            double eta = p(1) / noz;
1392 @@ -2030,7 +2036,8 @@
1393  
1394          double det = -trans.Det();
1395        
1396 -        if (det <= 0)
1397 +        //if (det <= 0)
1398 +        if (det <= DBL_MIN) // avoid FPE
1399            err += 1e12;
1400          else
1401            err += frob * frob * frob / det;
1402 @@ -2102,7 +2109,8 @@
1403          ddet *= -1;
1404  
1405        
1406 -        if (det <= 0)
1407 +        //if (det <= 0)
1408 +        if (det <= DBL_MIN) // avoid FPE
1409            err += 1e12;
1410          else
1411            {
1412 @@ -2184,7 +2192,7 @@
1413        
1414          det *= -1;
1415        
1416 -        if (det <= 0)
1417 +        if (det <= DBL_MIN)
1418            err += 1e12;
1419          else
1420            {
1421 --- netgen_ref/libsrc/meshing/meshtype.hpp
1422 +++ netgen/libsrc/meshing/meshtype.hpp
1423 @@ -15,6 +15,7 @@
1424      Classes for NETGEN
1425    */
1426  
1427 +class Mesh; // added due to compilation errors on some platforms
1428  
1429  
1430    enum ELEMENT_TYPE { 
1431 @@ -323,19 +324,19 @@
1432  
1433    public:
1434      ///
1435 -    Element2d ();
1436 +    DLL_HEADER Element2d ();
1437      ///
1438 -    Element2d (int anp);
1439 +    DLL_HEADER Element2d (int anp);
1440      ///
1441      DLL_HEADER Element2d (ELEMENT_TYPE type);
1442      ///
1443 -    Element2d (int pi1, int pi2, int pi3);
1444 +    DLL_HEADER Element2d (int pi1, int pi2, int pi3);
1445      ///
1446 -    Element2d (int pi1, int pi2, int pi3, int pi4);
1447 +    DLL_HEADER Element2d (int pi1, int pi2, int pi3, int pi4);
1448      ///
1449 -    ELEMENT_TYPE GetType () const { return typ; }
1450 +    DLL_HEADER ELEMENT_TYPE GetType () const { return typ; }
1451      /// 
1452 -    void SetType (ELEMENT_TYPE atyp)
1453 +    DLL_HEADER  void SetType (ELEMENT_TYPE atyp)
1454      {
1455        typ = atyp;
1456        switch (typ)
1457 @@ -350,9 +351,9 @@
1458         }
1459      }
1460      ///
1461 -    int GetNP() const { return np; }
1462 +    DLL_HEADER int GetNP() const { return np; }
1463      ///
1464 -    int GetNV() const
1465 +    DLL_HEADER int GetNV() const
1466      {
1467        if (typ == TRIG || typ == TRIG6)
1468          return 3;
1469 @@ -360,7 +361,7 @@
1470          {
1471  #ifdef DEBUG
1472            if (typ != QUAD && typ != QUAD6 && typ != QUAD8)
1473 -            PrintSysError ("element2d::GetNV not implemented for typ", typ)
1474 +            PrintSysError ("element2d::GetNV not implemented for typ", typ);
1475  #endif
1476            return 4;
1477          }
1478 @@ -384,95 +385,95 @@
1479      }
1480  
1481      ///
1482 -    PointIndex & operator[] (int i) { return pnum[i]; }
1483 +    DLL_HEADER  PointIndex & operator[] (int i) { return pnum[i]; }
1484      ///
1485 -    const PointIndex & operator[] (int i) const { return pnum[i]; }
1486 +    DLL_HEADER const PointIndex & operator[] (int i) const { return pnum[i]; }
1487  
1488 -    FlatArray<const PointIndex> PNums () const 
1489 +    DLL_HEADER  FlatArray<const PointIndex> PNums () const 
1490      { return FlatArray<const PointIndex> (np, &pnum[0]); }
1491      
1492      ///
1493 -    PointIndex & PNum (int i) { return pnum[i-1]; }
1494 +    DLL_HEADER PointIndex & PNum (int i) { return pnum[i-1]; }
1495      ///
1496 -    const PointIndex & PNum (int i) const { return pnum[i-1]; }
1497 +    DLL_HEADER const PointIndex & PNum (int i) const { return pnum[i-1]; }
1498      ///
1499 -    PointIndex & PNumMod (int i) { return pnum[(i-1) % np]; }
1500 +    DLL_HEADER PointIndex & PNumMod (int i) { return pnum[(i-1) % np]; }
1501      ///
1502 -    const PointIndex & PNumMod (int i) const { return pnum[(i-1) % np]; }
1503 +    DLL_HEADER const PointIndex & PNumMod (int i) const { return pnum[(i-1) % np]; }
1504      ///
1505  
1506      ///
1507 -    PointGeomInfo & GeomInfoPi (int i) { return geominfo[i-1]; }
1508 +    DLL_HEADER PointGeomInfo & GeomInfoPi (int i) { return geominfo[i-1]; }
1509      ///
1510 -    const PointGeomInfo & GeomInfoPi (int i) const { return geominfo[i-1]; }
1511 +    DLL_HEADER const PointGeomInfo & GeomInfoPi (int i) const { return geominfo[i-1]; }
1512      ///
1513 -    PointGeomInfo & GeomInfoPiMod (int i) { return geominfo[(i-1) % np]; }
1514 +    DLL_HEADER PointGeomInfo & GeomInfoPiMod (int i) { return geominfo[(i-1) % np]; }
1515      ///
1516 -    const PointGeomInfo & GeomInfoPiMod (int i) const { return geominfo[(i-1) % np]; }
1517 +    DLL_HEADER const PointGeomInfo & GeomInfoPiMod (int i) const { return geominfo[(i-1) % np]; }
1518  
1519  
1520 -    void SetIndex (int si) { index = si; }
1521 +    DLL_HEADER void SetIndex (int si) { index = si; }
1522      ///
1523 -    int GetIndex () const { return index; }
1524 +    DLL_HEADER int GetIndex () const { return index; }
1525  
1526 -    int GetOrder () const { return orderx; }
1527 -    void SetOrder (int aorder) { orderx = ordery = aorder; }
1528 +    DLL_HEADER int GetOrder () const { return orderx; }
1529 +    DLL_HEADER void SetOrder (int aorder) { orderx = ordery = aorder; }
1530  
1531  
1532 -    void GetOrder (int & ox, int & oy) const { ox = orderx, oy =ordery;};
1533 -    void GetOrder (int & ox, int & oy, int & oz) const { ox = orderx; oy = ordery; oz=0; }
1534 -    void SetOrder (int ox, int oy, int  /* oz */) { orderx = ox; ordery = oy;}
1535 -    void SetOrder (int ox, int oy) { orderx = ox; ordery = oy;}
1536 +    DLL_HEADER void GetOrder (int & ox, int & oy) const { ox = orderx, oy =ordery;};
1537 +    DLL_HEADER void GetOrder (int & ox, int & oy, int & oz) const { ox = orderx; oy = ordery; oz=0; }
1538 +    DLL_HEADER void SetOrder (int ox, int oy, int  /* oz */) { orderx = ox; ordery = oy;}
1539 +    DLL_HEADER void SetOrder (int ox, int oy) { orderx = ox; ordery = oy;}
1540  
1541  
1542      ///
1543 -    void GetBox (const T_POINTS & points, Box3d & box) const;
1544 +    DLL_HEADER void GetBox (const T_POINTS & points, Box3d & box) const;
1545      /// invert orientation
1546 -    inline void Invert ();
1547 +    DLL_HEADER inline void Invert ();
1548      ///
1549 -    void Invert2 ();
1550 +    DLL_HEADER void Invert2 ();
1551      /// first point number is smallest
1552 -    inline void NormalizeNumbering ();
1553 +    DLL_HEADER inline void NormalizeNumbering ();
1554      ///
1555 -    void NormalizeNumbering2 ();
1556 +    DLL_HEADER void NormalizeNumbering2 ();
1557  
1558 -    bool BadElement() const { return badel; }
1559 +    DLL_HEADER bool BadElement() const { return badel; }
1560  
1561      // friend ostream & operator<<(ostream  & s, const Element2d & el);
1562      friend class Mesh;
1563  
1564  
1565      /// get number of 'integration points'
1566 -    int GetNIP () const;
1567 -    void GetIntegrationPoint (int ip, Point2d & p, double & weight) const;
1568 +    DLL_HEADER int GetNIP () const;
1569 +    DLL_HEADER void GetIntegrationPoint (int ip, Point2d & p, double & weight) const;
1570  
1571 -    void GetTransformation (int ip, const Array<Point2d> & points,
1572 +    DLL_HEADER void GetTransformation (int ip, const Array<Point2d> & points,
1573                             class DenseMatrix & trans) const;
1574 -    void GetTransformation (int ip, class DenseMatrix & pmat,
1575 +    DLL_HEADER void GetTransformation (int ip, class DenseMatrix & pmat,
1576                             class DenseMatrix & trans) const;
1577  
1578 -    void GetShape (const Point2d & p, class Vector & shape) const;
1579 -    void GetShapeNew (const Point<2> & p, class FlatVector & shape) const;
1580 +    DLL_HEADER void GetShape (const Point2d & p, class Vector & shape) const;
1581 +    DLL_HEADER void GetShapeNew (const Point<2> & p, class FlatVector & shape) const;
1582      /// matrix 2 * np
1583 -    void GetDShape (const Point2d & p, class DenseMatrix & dshape) const;
1584 -    void GetDShapeNew (const Point<2> & p, class MatrixFixWidth<2> & dshape) const;
1585 +    DLL_HEADER void GetDShape (const Point2d & p, class DenseMatrix & dshape) const;
1586 +    DLL_HEADER void GetDShapeNew (const Point<2> & p, class MatrixFixWidth<2> & dshape) const;
1587      /// matrix 2 * np
1588 -    void GetPointMatrix (const Array<Point2d> & points,
1589 +    DLL_HEADER void GetPointMatrix (const Array<Point2d> & points,
1590                          class DenseMatrix & pmat) const; 
1591  
1592 -    void ComputeIntegrationPointData () const;
1593 +    DLL_HEADER void ComputeIntegrationPointData () const;
1594    
1595  
1596 -    double CalcJacobianBadness (const Array<Point2d> & points) const;
1597 -    double CalcJacobianBadness (const T_POINTS & points, 
1598 +    DLL_HEADER double CalcJacobianBadness (const Array<Point2d> & points) const;
1599 +    DLL_HEADER double CalcJacobianBadness (const T_POINTS & points, 
1600                                 const Vec<3> & n) const;
1601 -    double CalcJacobianBadnessDirDeriv (const Array<Point2d> & points,
1602 +    DLL_HEADER double CalcJacobianBadnessDirDeriv (const Array<Point2d> & points,
1603                                         int pi, Vec2d & dir, double & dd) const;
1604  
1605  
1606  
1607 -    void Delete () { deleted = 1; pnum[0] = pnum[1] = pnum[2] = pnum[3] = PointIndex::BASE-1; }
1608 -    bool IsDeleted () const 
1609 +    DLL_HEADER void Delete () { deleted = 1; pnum[0] = pnum[1] = pnum[2] = pnum[3] = PointIndex::BASE-1; }
1610 +    DLL_HEADER bool IsDeleted () const 
1611      {
1612  #ifdef DEBUG
1613        if (pnum[0] < PointIndex::BASE && !deleted)
1614 @@ -483,27 +484,27 @@
1615  
1616      // Philippose - 08 August 2010
1617      // Access functions for the new property: visible
1618 -    void Visible(bool vis = 1) 
1619 +    DLL_HEADER void Visible(bool vis = 1) 
1620      { visible = vis; }
1621 -    bool IsVisible () const 
1622 +    DLL_HEADER bool IsVisible () const 
1623      { return visible; }
1624     
1625 -    void SetRefinementFlag (bool rflag = 1) 
1626 +    DLL_HEADER void SetRefinementFlag (bool rflag = 1) 
1627      { refflag = rflag; }
1628 -    bool TestRefinementFlag () const
1629 +    DLL_HEADER bool TestRefinementFlag () const
1630      { return refflag; }
1631  
1632 -    void SetStrongRefinementFlag (bool rflag = 1) 
1633 +    DLL_HEADER void SetStrongRefinementFlag (bool rflag = 1) 
1634      { strongrefflag = rflag; }
1635 -    bool TestStrongRefinementFlag () const
1636 +    DLL_HEADER bool TestStrongRefinementFlag () const
1637      { return strongrefflag; }
1638  
1639    
1640 -    SurfaceElementIndex NextElement() { return next; }
1641 +    DLL_HEADER SurfaceElementIndex NextElement() { return next; }
1642  
1643 -    bool operator==(const Element2d & el2) const;
1644 +    DLL_HEADER bool operator==(const Element2d & el2) const;
1645  
1646 -    int HasFace(const Element2d& el) const;
1647 +    DLL_HEADER int HasFace(const Element2d& el) const;
1648      ///
1649      int meshdocval;
1650      ///
1651 @@ -516,7 +517,7 @@
1652    };
1653  
1654  
1655 -  ostream & operator<<(ostream  & s, const Element2d & el);
1656 +  DLL_HEADER ostream & operator<<(ostream  & s, const Element2d & el);
1657  
1658  
1659  
1660 @@ -618,7 +619,7 @@
1661           return 8;
1662         default:
1663  #ifdef DEBUG
1664 -         PrintSysError ("Element3d::GetNV not implemented for typ ", typ)
1665 +         PrintSysError ("Element3d::GetNV not implemented for typ ", typ);
1666  #endif
1667             ;
1668         }
1669 @@ -682,7 +683,7 @@
1670         case PRISM12: return 5;
1671         default:
1672  #ifdef DEBUG
1673 -         PrintSysError ("element3d::GetNFaces not implemented for typ", typ)
1674 +         PrintSysError ("element3d::GetNFaces not implemented for typ", typ);
1675  #endif
1676             ;
1677         }
1678 --- netgen_ref/libsrc/occ/Makefile.am
1679 +++ netgen/libsrc/occ/Makefile.am
1680 @@ -14,10 +14,10 @@
1681  
1682  METASOURCES = AUTO
1683  
1684 -lib_LTLIBRARIES = libocc.la
1685 +noinst_LTLIBRARIES = libocc.la
1686  
1687  if NGGUI
1688 -lib_LTLIBRARIES += liboccvis.la 
1689 +lib_LTLIBRARIES = liboccvis.la 
1690  endif
1691  
1692  
1693 --- netgen_ref/libsrc/occ/Partition_Inter2d.cxx
1694 +++ netgen/libsrc/occ/Partition_Inter2d.cxx
1695 @@ -47,9 +47,7 @@
1696  #include <TopOpeBRep_EdgesIntersector.hxx>
1697  #include <TopOpeBRep_Point2d.hxx>
1698  #include <TopTools_ListIteratorOfListOfShape.hxx>
1699 -#include <TopTools_ListOfShape.hxx>
1700  #include <TopTools_MapIteratorOfMapOfShape.hxx>
1701 -#include <TopTools_MapOfShape.hxx>
1702  #include <TopoDS.hxx>
1703  #include <TopoDS_Edge.hxx>
1704  #include <TopoDS_Vertex.hxx>
1705 --- netgen_ref/libsrc/occ/Partition_Inter2d.hxx
1706 +++ netgen/libsrc/occ/Partition_Inter2d.hxx
1707 @@ -27,7 +27,9 @@
1708  #ifndef _Partition_Inter2d_HeaderFile
1709  #define _Partition_Inter2d_HeaderFile
1710  
1711 -#ifndef _Handle_BRepAlgo_AsDes_HeaderFile
1712 +#include <Standard_Version.hxx>
1713 +
1714 +#if OCC_VERSION_MAJOR < 7
1715  #include <Handle_BRepAlgo_AsDes.hxx>
1716  #endif
1717  #ifndef _Standard_Real_HeaderFile
1718 @@ -36,11 +38,13 @@
1719  #ifndef _Standard_Boolean_HeaderFile
1720  #include <Standard_Boolean.hxx>
1721  #endif
1722 +
1723 +#include <TopTools_MapOfShape.hxx>
1724 +#include <TopTools_ListOfShape.hxx>
1725 +
1726  class BRepAlgo_AsDes;
1727  class TopoDS_Face;
1728 -class TopTools_MapOfShape;
1729  class TopoDS_Vertex;
1730 -class TopTools_ListOfShape;
1731  class TopoDS_Edge;
1732  
1733  
1734 --- netgen_ref/libsrc/occ/Partition_Inter3d.cxx
1735 +++ netgen/libsrc/occ/Partition_Inter3d.cxx
1736 @@ -48,7 +48,6 @@
1737  #include <TopOpeBRepTool_BoxSort.hxx>
1738  #include <TopTools_DataMapIteratorOfDataMapOfShapeListOfShape.hxx>
1739  #include <TopTools_ListIteratorOfListOfShape.hxx>
1740 -#include <TopTools_ListOfShape.hxx>
1741  #include <TopoDS.hxx>
1742  #include <TopoDS_Compound.hxx>
1743  #include <TopoDS_Edge.hxx>
1744 @@ -206,7 +205,7 @@
1745    Handle (Geom_Surface) S   = BRep_Tool::Surface(F,L);
1746  
1747    if (S->IsKind(STANDARD_TYPE(Geom_RectangularTrimmedSurface))) {
1748 -    S = (*(Handle_Geom_RectangularTrimmedSurface*)&S)->BasisSurface();
1749 +    S = Handle(Geom_RectangularTrimmedSurface)::DownCast (S)->BasisSurface();
1750    }
1751    if (!S->IsUPeriodic() && !S->IsVPeriodic())
1752      return;
1753 --- netgen_ref/libsrc/occ/Partition_Inter3d.hxx
1754 +++ netgen/libsrc/occ/Partition_Inter3d.hxx
1755 @@ -27,7 +27,9 @@
1756  #ifndef _Partition_Inter3d_HeaderFile
1757  #define _Partition_Inter3d_HeaderFile
1758  
1759 -#ifndef _Handle_BRepAlgo_AsDes_HeaderFile
1760 +#include <Standard_Version.hxx>
1761 +
1762 +#if OCC_VERSION_MAJOR < 7
1763  #include <Handle_BRepAlgo_AsDes.hxx>
1764  #endif
1765  #ifndef _TopTools_DataMapOfShapeListOfShape_HeaderFile
1766 @@ -36,6 +38,9 @@
1767  #ifndef _TopTools_MapOfShape_HeaderFile
1768  #include <TopTools_MapOfShape.hxx>
1769  #endif
1770 +#ifndef _TopTools_ListOfShape_HeaderFile
1771 +#include <TopTools_ListOfShape.hxx>
1772 +#endif
1773  #ifndef _TopTools_DataMapOfShapeShape_HeaderFile
1774  #include <TopTools_DataMapOfShapeShape.hxx>
1775  #endif
1776 @@ -43,10 +48,7 @@
1777  #include <Standard_Boolean.hxx>
1778  #endif
1779  class BRepAlgo_AsDes;
1780 -class TopTools_ListOfShape;
1781 -class TopTools_DataMapOfShapeShape;
1782  class TopoDS_Face;
1783 -class TopTools_MapOfShape;
1784  class TopoDS_Shape;
1785  class TopoDS_Vertex;
1786  class TopoDS_Edge;
1787 @@ -83,13 +85,13 @@
1788     void FacesPartition(const TopoDS_Face& F1,const TopoDS_Face& F2) ;
1789     Standard_Boolean IsDone(const TopoDS_Face& F1,const TopoDS_Face& F2) const;
1790     TopTools_MapOfShape& TouchedFaces() ;
1791 -   Handle_BRepAlgo_AsDes AsDes() const;
1792 +   Handle(BRepAlgo_AsDes) AsDes() const;
1793     TopTools_MapOfShape& NewEdges() ;
1794     Standard_Boolean HasSameDomainF(const TopoDS_Shape& F) const;
1795     Standard_Boolean IsSameDomainF(const TopoDS_Shape& F1,const TopoDS_Shape& F2) const;
1796     const TopTools_ListOfShape& SameDomain(const TopoDS_Face& F) const;
1797     TopoDS_Vertex ReplaceSameDomainV(const TopoDS_Vertex& V,const TopoDS_Edge& E) const;
1798 -   Handle_BRepAlgo_AsDes SectionEdgesAD() const;
1799 +   Handle(BRepAlgo_AsDes) SectionEdgesAD() const;
1800     Standard_Boolean IsSectionEdge(const TopoDS_Edge& E) const;
1801     Standard_Boolean HasSectionEdge(const TopoDS_Face& F) const;
1802     Standard_Boolean IsSplitOn(const TopoDS_Edge& NewE,const TopoDS_Edge& OldE,const TopoDS_Face& F) const;
1803 @@ -121,11 +123,11 @@
1804  
1805     // Fields PRIVATE
1806     //
1807 -   Handle_BRepAlgo_AsDes myAsDes;
1808 +   Handle(BRepAlgo_AsDes) myAsDes;
1809     TopTools_DataMapOfShapeListOfShape myDone;
1810     TopTools_MapOfShape myTouched;
1811     TopTools_MapOfShape myNewEdges;
1812 -   Handle_BRepAlgo_AsDes mySectionEdgesAD;
1813 +   Handle(BRepAlgo_AsDes) mySectionEdgesAD;
1814     TopTools_DataMapOfShapeListOfShape mySameDomainFM;
1815     TopTools_DataMapOfShapeShape mySameDomainVM;
1816  
1817 --- netgen_ref/libsrc/occ/Partition_Loop.hxx
1818 +++ netgen/libsrc/occ/Partition_Loop.hxx
1819 @@ -38,8 +38,6 @@
1820  #endif
1821  class TopoDS_Face;
1822  class TopoDS_Edge;
1823 -class TopTools_ListOfShape;
1824 -
1825  
1826  #ifndef _Standard_HeaderFile
1827  #include <Standard.hxx>
1828 --- netgen_ref/libsrc/occ/Partition_Loop2d.cxx
1829 +++ netgen/libsrc/occ/Partition_Loop2d.cxx
1830 @@ -210,7 +210,7 @@
1831      Cc->D1(uc, PC, CTg1);
1832      if (!isForward) CTg1.Reverse();
1833  
1834 -    Standard_Real anglemin = 3 * PI, tolAng = 1.e-8;
1835 +    Standard_Real anglemin = 3 * M_PI, tolAng = 1.e-8;
1836  
1837      // select an edge whose first derivative is most left of CTg1
1838      // ie an angle between Tg1 and CTg1 is least
1839 @@ -234,7 +234,7 @@
1840        // -PI < angle < PI
1841        Standard_Real angle = Tg1.Angle(CTg1);
1842  
1843 -      if (PI - Abs(angle) <= tolAng)
1844 +      if (M_PI - Abs(angle) <= tolAng)
1845        {
1846          // an angle is too close to PI; assure that an angle sign really
1847          // reflects an edge position: +PI - an edge is worst,
1848 --- netgen_ref/libsrc/occ/Partition_Loop2d.hxx
1849 +++ netgen/libsrc/occ/Partition_Loop2d.hxx
1850 @@ -24,7 +24,6 @@
1851  #endif
1852  class TopoDS_Face;
1853  class TopoDS_Edge;
1854 -class TopTools_ListOfShape;
1855  class BRepAlgo_Image;
1856  
1857  
1858 --- netgen_ref/libsrc/occ/Partition_Loop3d.hxx
1859 +++ netgen/libsrc/occ/Partition_Loop3d.hxx
1860 @@ -13,6 +13,9 @@
1861  #ifndef _TopTools_ListOfShape_HeaderFile
1862  #include <TopTools_ListOfShape.hxx>
1863  #endif
1864 +#ifndef _TopTools_MapOfOrientedShape_HeaderFile
1865 +#include <TopTools_MapOfOrientedShape.hxx>
1866 +#endif
1867  #ifndef _TopTools_IndexedDataMapOfShapeListOfShape_HeaderFile
1868  #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
1869  #endif
1870 @@ -23,8 +26,6 @@
1871  #include <Standard_Real.hxx>
1872  #endif
1873  class TopoDS_Shape;
1874 -class TopTools_ListOfShape;
1875 -class TopTools_MapOfOrientedShape;
1876  class TopoDS_Edge;
1877  class TopoDS_Face;
1878  class gp_Vec;
1879 --- netgen_ref/libsrc/occ/Partition_Spliter.cxx
1880 +++ netgen/libsrc/occ/Partition_Spliter.cxx
1881 @@ -48,7 +48,6 @@
1882  #include <TopTools_IndexedDataMapOfShapeListOfShape.hxx>
1883  #include <TopTools_IndexedMapOfShape.hxx>
1884  #include <TopTools_ListIteratorOfListOfShape.hxx>
1885 -#include <TopTools_ListOfShape.hxx>
1886  #include <TopTools_MapIteratorOfMapOfShape.hxx>
1887  #include <TopTools_SequenceOfShape.hxx>
1888  
1889 --- netgen_ref/libsrc/occ/Partition_Spliter.hxx
1890 +++ netgen/libsrc/occ/Partition_Spliter.hxx
1891 @@ -28,9 +28,6 @@
1892  #ifndef _TopTools_DataMapOfShapeShape_HeaderFile
1893  #include <TopTools_DataMapOfShapeShape.hxx>
1894  #endif
1895 -#ifndef _Handle_BRepAlgo_AsDes_HeaderFile
1896 -#include <Handle_BRepAlgo_AsDes.hxx>
1897 -#endif
1898  #ifndef _BRepAlgo_Image_HeaderFile
1899  #include <BRepAlgo_Image.hxx>
1900  #endif
1901 @@ -45,7 +42,6 @@
1902  #endif
1903  class BRepAlgo_AsDes;
1904  class TopoDS_Shape;
1905 -class TopTools_ListOfShape;
1906  class TopoDS_Edge;
1907  
1908  
1909 @@ -129,7 +125,7 @@
1910     TopTools_DataMapOfShapeShape myFaceShapeMap;
1911     TopTools_DataMapOfShapeShape myInternalFaces;
1912     TopTools_DataMapOfShapeShape myIntNotClFaces;
1913 -   Handle_BRepAlgo_AsDes myAsDes;
1914 +   Handle(BRepAlgo_AsDes) myAsDes;
1915     BRepAlgo_Image myImagesFaces;
1916     BRepAlgo_Image myImagesEdges;
1917     BRepAlgo_Image myImageShape;
1918 --- netgen_ref/libsrc/occ/occconstruction.cpp
1919 +++ netgen/libsrc/occ/occconstruction.cpp
1920 @@ -28,7 +28,7 @@
1921  #include <BRepAlgoAPI_Common.hxx>
1922  #include <BRepAlgoAPI_Fuse.hxx>
1923  #include <BRepAlgoAPI_Section.hxx>
1924 -#include <BRepOffsetAPI_Sewing.hxx>
1925 +//#include <BRepOffsetAPI_Sewing.hxx>
1926  //#include <BRepAlgo_Sewing.hxx>
1927  #include <BRepOffsetAPI_MakeOffsetShape.hxx>
1928  #include <ShapeFix_Shape.hxx>
1929 --- netgen_ref/libsrc/occ/occgenmesh.cpp
1930 +++ netgen/libsrc/occ/occgenmesh.cpp
1931 @@ -1,1467 +1,1570 @@
1932 -#ifdef OCCGEOMETRY
1933 -
1934 -#include <mystdlib.h>
1935 -#include <occgeom.hpp>
1936 -#include <meshing.hpp>
1937 -
1938 -
1939 -namespace netgen
1940 -{
1941 -
1942 -#include "occmeshsurf.hpp"
1943 -
1944 -#define TCL_OK 0
1945 -#define TCL_ERROR 1
1946 -
1947 -#define DIVIDEEDGESECTIONS 1000
1948 -#define IGNORECURVELENGTH 1e-4
1949 -#define VSMALL 1e-10
1950 -
1951 -
1952 -   bool merge_solids = 1;
1953 -
1954 -
1955 -  // can you please explain what you intend to compute here (JS) !!!
1956 -   double Line :: Dist (Line l)
1957 -   {
1958 -      Vec<3> n = p1-p0;
1959 -      Vec<3> q = l.p1-l.p0;
1960 -      double nq = n*q;
1961 -
1962 -      Point<3> p = p0 + 0.5*n;
1963 -      double lambda = (p-l.p0)*n / (nq + VSMALL);
1964 -
1965 -      if (lambda >= 0 && lambda <= 1)
1966 -      {
1967 -         double d = (p-l.p0-lambda*q).Length();
1968 -         //        if (d < 1e-3) d = 1e99;
1969 -         return d;
1970 -      }
1971 -      else
1972 -         return 1e99;
1973 -   }
1974 -
1975 -
1976 -
1977 -   double Line :: Length ()
1978 -   {
1979 -      return (p1-p0).Length();
1980 -   }
1981 -
1982 -
1983 -
1984 -   inline Point<3> occ2ng (const gp_Pnt & p)
1985 -   {
1986 -      return  Point<3> (p.X(), p.Y(), p.Z());
1987 -   }
1988 -
1989 -
1990 -
1991 -   double ComputeH (double kappa)
1992 -   {
1993 -      double hret;
1994 -      kappa *= mparam.curvaturesafety;
1995 -
1996 -      if (mparam.maxh * kappa < 1)
1997 -         hret = mparam.maxh;
1998 -      else
1999 -         hret = 1 / (kappa + VSMALL);
2000 -
2001 -      if (mparam.maxh < hret)
2002 -         hret = mparam.maxh;
2003 -
2004 -      return (hret);
2005 -   }
2006 -
2007 -
2008 -
2009 -
2010 -   void RestrictHTriangle (gp_Pnt2d & par0, gp_Pnt2d & par1, gp_Pnt2d & par2,
2011 -                           BRepLProp_SLProps * prop, Mesh & mesh, int depth, double h = 0)
2012 -   {
2013 -      int ls = -1;
2014 -
2015 -      gp_Pnt pnt0,pnt1,pnt2;
2016 -
2017 -      prop->SetParameters (par0.X(), par0.Y());
2018 -      pnt0 = prop->Value();
2019 -
2020 -      prop->SetParameters (par1.X(), par1.Y());
2021 -      pnt1 = prop->Value();
2022 -
2023 -      prop->SetParameters (par2.X(), par2.Y());
2024 -      pnt2 = prop->Value();
2025 -
2026 -      double aux;
2027 -      double maxside = pnt0.Distance(pnt1);
2028 -      ls = 2;
2029 -      aux = pnt1.Distance(pnt2);
2030 -      if(aux > maxside)
2031 -      {
2032 -         maxside = aux;
2033 -         ls = 0;
2034 -      }
2035 -      aux = pnt2.Distance(pnt0);
2036 -      if(aux > maxside)
2037 -      {
2038 -         maxside = aux;
2039 -         ls = 1;
2040 -      }
2041 -
2042 -
2043 -
2044 -      gp_Pnt2d parmid;
2045 -
2046 -      parmid.SetX( (par0.X()+par1.X()+par2.X()) / 3 );
2047 -      parmid.SetY( (par0.Y()+par1.Y()+par2.Y()) / 3 );
2048 -
2049 -      if (depth%3 == 0)
2050 -      {
2051 -         double curvature = 0;
2052 -
2053 -         prop->SetParameters (parmid.X(), parmid.Y());
2054 -         if (!prop->IsCurvatureDefined())
2055 -         {
2056 -            (*testout) << "curvature not defined!" << endl;
2057 -            return;
2058 -         }
2059 -         curvature = max(fabs(prop->MinCurvature()),
2060 -            fabs(prop->MaxCurvature()));
2061 -
2062 -         prop->SetParameters (par0.X(), par0.Y());
2063 -         if (!prop->IsCurvatureDefined())
2064 -         {
2065 -            (*testout) << "curvature not defined!" << endl;
2066 -            return;
2067 -         }
2068 -         curvature = max(curvature,max(fabs(prop->MinCurvature()),
2069 -            fabs(prop->MaxCurvature())));
2070 -
2071 -         prop->SetParameters (par1.X(), par1.Y());
2072 -         if (!prop->IsCurvatureDefined())
2073 -         {
2074 -            (*testout) << "curvature not defined!" << endl;
2075 -            return;
2076 -         }
2077 -         curvature = max(curvature,max(fabs(prop->MinCurvature()),
2078 -            fabs(prop->MaxCurvature())));
2079 -
2080 -         prop->SetParameters (par2.X(), par2.Y());
2081 -         if (!prop->IsCurvatureDefined())
2082 -         {
2083 -            (*testout) << "curvature not defined!" << endl;
2084 -            return;
2085 -         }
2086 -         curvature = max(curvature,max(fabs(prop->MinCurvature()),
2087 -            fabs(prop->MaxCurvature())));
2088 -
2089 -         //(*testout) << "curvature " << curvature << endl;
2090 -
2091 -         if (curvature < 1e-3)
2092 -         {
2093 -            //(*testout) << "curvature too small (" << curvature << ")!" << endl;
2094 -            return;
2095 -            // return war bis 10.2.05 auskommentiert
2096 -         }
2097 -
2098 -
2099 -
2100 -         h = ComputeH (curvature+1e-10);
2101 -
2102 -         if(h < 1e-4*maxside)
2103 -            return;
2104 -
2105 -
2106 -         if (h > 30) return;
2107 -      }
2108 -
2109 -      if (h < maxside && depth < 10)
2110 -      {
2111 -         //cout << "\r h " << h << flush;
2112 -         gp_Pnt2d pm;
2113 -
2114 -         //cout << "h " << h << " maxside " << maxside << " depth " << depth << endl;
2115 -         //cout << "par0 " << par0.X() << " " << par0.Y()
2116 -         //<< " par1 " << par1.X() << " " << par1.Y()
2117 -         //   << " par2 " << par2.X() << " " << par2.Y()<< endl;
2118 -
2119 -         if(ls == 0)
2120 -         {
2121 -            pm.SetX(0.5*(par1.X()+par2.X())); pm.SetY(0.5*(par1.Y()+par2.Y()));
2122 -            RestrictHTriangle(pm, par2, par0, prop, mesh, depth+1, h);
2123 -            RestrictHTriangle(pm, par0, par1, prop, mesh, depth+1, h);
2124 -         }
2125 -         else if(ls == 1)
2126 -         {
2127 -            pm.SetX(0.5*(par0.X()+par2.X())); pm.SetY(0.5*(par0.Y()+par2.Y()));
2128 -            RestrictHTriangle(pm, par1, par2, prop, mesh, depth+1, h);
2129 -            RestrictHTriangle(pm, par0, par1, prop, mesh, depth+1, h);
2130 -         }
2131 -         else if(ls == 2)
2132 -         {
2133 -            pm.SetX(0.5*(par0.X()+par1.X())); pm.SetY(0.5*(par0.Y()+par1.Y()));
2134 -            RestrictHTriangle(pm, par1, par2, prop, mesh, depth+1, h);
2135 -            RestrictHTriangle(pm, par2, par0, prop, mesh, depth+1, h);
2136 -         }
2137 -
2138 -      }
2139 -      else
2140 -      {
2141 -         gp_Pnt pnt;
2142 -         Point3d p3d;
2143 -
2144 -         prop->SetParameters (parmid.X(), parmid.Y());
2145 -         pnt = prop->Value();
2146 -         p3d = Point3d(pnt.X(), pnt.Y(), pnt.Z());
2147 -         mesh.RestrictLocalH (p3d, h);
2148 -
2149 -         p3d = Point3d(pnt0.X(), pnt0.Y(), pnt0.Z());
2150 -         mesh.RestrictLocalH (p3d, h);
2151 -
2152 -         p3d = Point3d(pnt1.X(), pnt1.Y(), pnt1.Z());
2153 -         mesh.RestrictLocalH (p3d, h);
2154 -
2155 -         p3d = Point3d(pnt2.X(), pnt2.Y(), pnt2.Z());
2156 -         mesh.RestrictLocalH (p3d, h);
2157 -
2158 -         //(*testout) << "p = " << p3d << ", h = " << h << ", maxside = " << maxside << endl;
2159 -
2160 -      }
2161 -   }
2162 -
2163 -
2164 -
2165 -   void DivideEdge (TopoDS_Edge & edge, Array<MeshPoint> & ps,
2166 -                    Array<double> & params, Mesh & mesh)
2167 -   {
2168 -      double s0, s1;
2169 -      double maxh = mparam.maxh;
2170 -      int nsubedges = 1;
2171 -      gp_Pnt pnt, oldpnt;
2172 -      double svalue[DIVIDEEDGESECTIONS];
2173 -
2174 -      GProp_GProps system;
2175 -      BRepGProp::LinearProperties(edge, system);
2176 -      double L = system.Mass();
2177 -
2178 -      Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1);
2179 -
2180 -      double hvalue[DIVIDEEDGESECTIONS+1];
2181 -      hvalue[0] = 0;
2182 -      pnt = c->Value(s0);
2183 -
2184 -      double olddist = 0;
2185 -      double dist = 0;
2186 -
2187 -      int tmpVal = (int)(DIVIDEEDGESECTIONS);
2188 -
2189 -      for (int i = 1; i <= tmpVal; i++)
2190 -      {
2191 -         oldpnt = pnt;
2192 -         pnt = c->Value(s0+(i/double(DIVIDEEDGESECTIONS))*(s1-s0));
2193 -         hvalue[i] = hvalue[i-1] +
2194 -            1.0/mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))*
2195 -            pnt.Distance(oldpnt);
2196 -
2197 -         //(*testout) << "mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z())) " << mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))
2198 -         //       <<  " pnt.Distance(oldpnt) " << pnt.Distance(oldpnt) << endl;
2199 -
2200 -         olddist = dist;
2201 -         dist = pnt.Distance(oldpnt);
2202 -      }
2203 -
2204 -      //  nsubedges = int(ceil(hvalue[DIVIDEEDGESECTIONS]));
2205 -      nsubedges = max (1, int(floor(hvalue[DIVIDEEDGESECTIONS]+0.5)));
2206 -
2207 -      ps.SetSize(nsubedges-1);
2208 -      params.SetSize(nsubedges+1);
2209 -
2210 -      int i = 1;
2211 -      int i1 = 0;
2212 -      do
2213 -      {
2214 -         if (hvalue[i1]/hvalue[DIVIDEEDGESECTIONS]*nsubedges >= i)
2215 -         {
2216 -            params[i] = s0+(i1/double(DIVIDEEDGESECTIONS))*(s1-s0);
2217 -            pnt = c->Value(params[i]);
2218 -            ps[i-1] = MeshPoint (Point3d(pnt.X(), pnt.Y(), pnt.Z()));
2219 -            i++;
2220 -         }
2221 -         i1++;
2222 -         if (i1 > DIVIDEEDGESECTIONS)
2223 -         {
2224 -            nsubedges = i;
2225 -            ps.SetSize(nsubedges-1);
2226 -            params.SetSize(nsubedges+1);
2227 -            cout << "divide edge: local h too small" << endl;
2228 -         }
2229 -      } while (i < nsubedges);
2230 -
2231 -      params[0] = s0;
2232 -      params[nsubedges] = s1;
2233 -
2234 -      if (params[nsubedges] <= params[nsubedges-1])
2235 -      {
2236 -         cout << "CORRECTED" << endl;
2237 -         ps.SetSize (nsubedges-2);
2238 -         params.SetSize (nsubedges);
2239 -         params[nsubedges] = s1;
2240 -      }
2241 -   }
2242 -
2243 -
2244 -
2245 -
2246 -   void OCCFindEdges (OCCGeometry & geom, Mesh & mesh)
2247 -   {
2248 -      const char * savetask = multithread.task;
2249 -      multithread.task = "Edge meshing";
2250 -
2251 -      (*testout) << "edge meshing" << endl;
2252 -
2253 -      int nvertices = geom.vmap.Extent();
2254 -      int nedges = geom.emap.Extent();
2255 -
2256 -      (*testout) << "nvertices = " << nvertices << endl;
2257 -      (*testout) << "nedges = " << nedges << endl;
2258 -
2259 -      double eps = 1e-6 * geom.GetBoundingBox().Diam();
2260 -
2261 -      for (int i = 1; i <= nvertices; i++)
2262 -      {
2263 -         gp_Pnt pnt = BRep_Tool::Pnt (TopoDS::Vertex(geom.vmap(i)));
2264 -         MeshPoint mp( Point<3>(pnt.X(), pnt.Y(), pnt.Z()) );
2265 -
2266 -         bool exists = 0;
2267 -         if (merge_solids)
2268 -            for (PointIndex pi = 1; pi <= mesh.GetNP(); pi++)
2269 -               if ( Dist2 (mesh[pi], Point<3>(mp)) < eps*eps)
2270 -               {
2271 -                  exists = 1;
2272 -                  break;
2273 -               }
2274 -
2275 -               if (!exists)
2276 -                  mesh.AddPoint (mp);
2277 -      }
2278 -
2279 -      (*testout) << "different vertices = " << mesh.GetNP() << endl;
2280 -
2281 -
2282 -      int first_ep = mesh.GetNP()+1;
2283 -
2284 -      Array<int> face2solid[2];
2285 -      for (int i = 0; i<2; i++)
2286 -      {
2287 -         face2solid[i].SetSize (geom.fmap.Extent());
2288 -         face2solid[i] = 0;
2289 -      }
2290 -
2291 -      int solidnr = 0;
2292 -      for (TopExp_Explorer exp0(geom.shape, TopAbs_SOLID); exp0.More(); exp0.Next())
2293 -      {
2294 -         solidnr++;
2295 -         for (TopExp_Explorer exp1(exp0.Current(), TopAbs_FACE); exp1.More(); exp1.Next())
2296 -         {
2297 -            TopoDS_Face face = TopoDS::Face(exp1.Current());
2298 -            int facenr = geom.fmap.FindIndex(face);
2299 -
2300 -            if (face2solid[0][facenr-1] == 0)
2301 -               face2solid[0][facenr-1] = solidnr;
2302 -            else
2303 -               face2solid[1][facenr-1] = solidnr;
2304 -         }
2305 -      }
2306 -
2307 -
2308 -      int total = 0;
2309 -      for (int i3 = 1; i3 <= geom.fmap.Extent(); i3++)
2310 -         for (TopExp_Explorer exp2(geom.fmap(i3), TopAbs_WIRE); exp2.More(); exp2.Next())
2311 -            for (TopExp_Explorer exp3(exp2.Current(), TopAbs_EDGE); exp3.More(); exp3.Next())
2312 -               total++;
2313 -
2314 -
2315 -      int facenr = 0;
2316 -      int edgenr = 0;
2317 -
2318 -
2319 -      (*testout) << "faces = " << geom.fmap.Extent() << endl;
2320 -      int curr = 0;
2321 -
2322 -      for (int i3 = 1; i3 <= geom.fmap.Extent(); i3++)
2323 -      {
2324 -         TopoDS_Face face = TopoDS::Face(geom.fmap(i3));
2325 -         facenr = geom.fmap.FindIndex (face);       // sollte doch immer == i3 sein ??? JS
2326 -
2327 -         int solidnr0 = face2solid[0][i3-1];
2328 -         int solidnr1 = face2solid[1][i3-1];
2329 -
2330 -         /* auskommentiert am 3.3.05 von robert
2331 -         for (exp2.Init (geom.somap(solidnr0), TopAbs_FACE); exp2.More(); exp2.Next())
2332 -         {
2333 -         TopoDS_Face face2 = TopoDS::Face(exp2.Current());
2334 -         if (geom.fmap.FindIndex(face2) == facenr)
2335 -         {
2336 -         //                  if (face.Orientation() != face2.Orientation()) swap (solidnr0, solidnr1);
2337 -         }
2338 -         }
2339 -         */
2340 -
2341 -         mesh.AddFaceDescriptor (FaceDescriptor(facenr, solidnr0, solidnr1, 0));
2342 -
2343 -         // Philippose - 06/07/2009
2344 -         // Add the face colour to the mesh data
2345 -         Quantity_Color face_colour;
2346 -
2347 -         if(!(geom.face_colours.IsNull())
2348 -            && (geom.face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour)))
2349 -         {
2350 -            mesh.GetFaceDescriptor(facenr).SetSurfColour(Vec3d(face_colour.Red(),face_colour.Green(),face_colour.Blue()));
2351 -         }
2352 -         else
2353 -         {
2354 -            mesh.GetFaceDescriptor(facenr).SetSurfColour(Vec3d(0.0,1.0,0.0));
2355 -         }
2356 -         // ACHTUNG! STIMMT NICHT ALLGEMEIN (RG)
2357 -
2358 -
2359 -         Handle(Geom_Surface) occface = BRep_Tool::Surface(face);
2360 -
2361 -         for (TopExp_Explorer exp2 (face, TopAbs_WIRE); exp2.More(); exp2.Next())
2362 -         {
2363 -            TopoDS_Shape wire = exp2.Current();
2364 -
2365 -            for (TopExp_Explorer exp3 (wire, TopAbs_EDGE); exp3.More(); exp3.Next())
2366 -            {
2367 -               curr++;
2368 -               (*testout) << "edge nr " << curr << endl;
2369 -
2370 -               multithread.percent = 100 * curr / double (total);
2371 -               if (multithread.terminate) return;
2372 -
2373 -               TopoDS_Edge edge = TopoDS::Edge (exp3.Current());
2374 -               if (BRep_Tool::Degenerated(edge))
2375 -               {
2376 -                  //(*testout) << "ignoring degenerated edge" << endl;
2377 -                  continue;
2378 -               }
2379 -
2380 -               if (geom.vmap.FindIndex(TopExp::FirstVertex (edge)) ==
2381 -                  geom.vmap.FindIndex(TopExp::LastVertex (edge)))
2382 -               {
2383 -                  GProp_GProps system;
2384 -                  BRepGProp::LinearProperties(edge, system);
2385 -
2386 -                  if (system.Mass() < eps)
2387 -                  {
2388 -                     cout << "ignoring edge " << geom.emap.FindIndex (edge)
2389 -                        << ". closed edge with length < " << eps << endl;
2390 -                     continue;
2391 -                  }
2392 -               }
2393 -
2394 -
2395 -               Handle(Geom2d_Curve) cof;
2396 -               double s0, s1;
2397 -               cof = BRep_Tool::CurveOnSurface (edge, face, s0, s1);
2398 -
2399 -               int geomedgenr = geom.emap.FindIndex(edge);
2400 -
2401 -               Array <MeshPoint> mp;
2402 -               Array <double> params;
2403 -
2404 -               DivideEdge (edge, mp, params, mesh);
2405
2406 -               Array <int> pnums;
2407 -               pnums.SetSize (mp.Size()+2);
2408 -
2409 -               if (!merge_solids)
2410 -               {
2411 -                  pnums[0] = geom.vmap.FindIndex (TopExp::FirstVertex (edge));
2412 -                  pnums[pnums.Size()-1] = geom.vmap.FindIndex (TopExp::LastVertex (edge));
2413 -               }
2414 -               else
2415 -               {
2416 -                  Point<3> fp = occ2ng (BRep_Tool::Pnt (TopExp::FirstVertex (edge)));
2417 -                  Point<3> lp = occ2ng (BRep_Tool::Pnt (TopExp::LastVertex (edge)));
2418 -
2419 -                  pnums[0] = -1;
2420 -                  pnums.Last() = -1;
2421 -                  for (PointIndex pi = 1; pi < first_ep; pi++)
2422 -                  {
2423 -                     if (Dist2 (mesh[pi], fp) < eps*eps) pnums[0] = pi;
2424 -                     if (Dist2 (mesh[pi], lp) < eps*eps) pnums.Last() = pi;
2425 -                  }
2426 -               }
2427 -
2428 -
2429 -               for (int i = 1; i <= mp.Size(); i++)
2430 -               {
2431 -                  bool exists = 0;
2432 -                  int j;
2433 -                  for (j = first_ep; j <= mesh.GetNP(); j++)
2434 -                     if ((mesh.Point(j)-Point<3>(mp[i-1])).Length() < eps)
2435 -                     {
2436 -                        exists = 1;
2437 -                        break;
2438 -                     }
2439 -
2440 -                     if (exists)
2441 -                        pnums[i] = j;
2442 -                     else
2443 -                     {
2444 -                        mesh.AddPoint (mp[i-1]);
2445 -                        (*testout) << "add meshpoint " << mp[i-1] << endl;
2446 -                        pnums[i] = mesh.GetNP();
2447 -                     }
2448 -               }
2449 -               (*testout) << "NP = " << mesh.GetNP() << endl;
2450 -
2451 -               //(*testout) << pnums[pnums.Size()-1] << endl;
2452 -
2453 -               for (int i = 1; i <= mp.Size()+1; i++)
2454 -               {
2455 -                  edgenr++;
2456 -                  Segment seg;
2457 -
2458 -                  seg[0] = pnums[i-1];
2459 -                  seg[1] = pnums[i];
2460 -                  seg.edgenr = edgenr;
2461 -                  seg.si = facenr;
2462 -                  seg.epgeominfo[0].dist = params[i-1];
2463 -                  seg.epgeominfo[1].dist = params[i];
2464 -                  seg.epgeominfo[0].edgenr = geomedgenr;
2465 -                  seg.epgeominfo[1].edgenr = geomedgenr;
2466 -
2467 -                  gp_Pnt2d p2d;
2468 -                  p2d = cof->Value(params[i-1]);
2469 -                  //                   if (i == 1) p2d = cof->Value(s0);
2470 -                  seg.epgeominfo[0].u = p2d.X();
2471 -                  seg.epgeominfo[0].v = p2d.Y();
2472 -                  p2d = cof->Value(params[i]);
2473 -                  //                   if (i == mp.Size()+1) p2d = cof -> Value(s1);
2474 -                  seg.epgeominfo[1].u = p2d.X();
2475 -                  seg.epgeominfo[1].v = p2d.Y();
2476 -
2477 -                  /*
2478 -                  if (occface->IsUPeriodic())
2479 -                  {
2480 -                  cout << "U Periodic" << endl;
2481 -                  if (fabs(seg.epgeominfo[1].u-seg.epgeominfo[0].u) >
2482 -                  fabs(seg.epgeominfo[1].u-
2483 -                  (seg.epgeominfo[0].u-occface->UPeriod())))
2484 -                  seg.epgeominfo[0].u = p2d.X()+occface->UPeriod();
2485 -
2486 -                  if (fabs(seg.epgeominfo[1].u-seg.epgeominfo[0].u) >
2487 -                  fabs(seg.epgeominfo[1].u-
2488 -                  (seg.epgeominfo[0].u+occface->UPeriod())))
2489 -                  seg.epgeominfo[0].u = p2d.X()-occface->UPeriod();
2490 -                  }
2491 -
2492 -                  if (occface->IsVPeriodic())
2493 -                  {
2494 -                  cout << "V Periodic" << endl;
2495 -                  if (fabs(seg.epgeominfo[1].v-seg.epgeominfo[0].v) >
2496 -                  fabs(seg.epgeominfo[1].v-
2497 -                  (seg.epgeominfo[0].v-occface->VPeriod())))
2498 -                  seg.epgeominfo[0].v = p2d.Y()+occface->VPeriod();
2499 -
2500 -                  if (fabs(seg.epgeominfo[1].v-seg.epgeominfo[0].v) >
2501 -                  fabs(seg.epgeominfo[1].v-
2502 -                  (seg.epgeominfo[0].v+occface->VPeriod())))
2503 -                  seg.epgeominfo[0].v = p2d.Y()-occface->VPeriod();
2504 -                  }
2505 -                  */
2506 -
2507 -                  if (edge.Orientation() == TopAbs_REVERSED)
2508 -                  {
2509 -                     swap (seg[0], seg[1]);
2510 -                     swap (seg.epgeominfo[0].dist, seg.epgeominfo[1].dist);
2511 -                     swap (seg.epgeominfo[0].u, seg.epgeominfo[1].u);
2512 -                     swap (seg.epgeominfo[0].v, seg.epgeominfo[1].v);
2513 -                  }
2514 -
2515 -                  mesh.AddSegment (seg);
2516 -
2517 -                  //edgesegments[geomedgenr-1]->Append(mesh.GetNSeg());
2518 -
2519 -               }
2520 -            }
2521 -         }
2522 -      }
2523 -
2524 -      //       for(i=1; i<=mesh.GetNSeg(); i++)
2525 -      //               (*testout) << "edge " << mesh.LineSegment(i).edgenr << " face " << mesh.LineSegment(i).si
2526 -      //                               << " p1 " << mesh.LineSegment(i)[0] << " p2 " << mesh.LineSegment(i)[1] << endl;
2527 -      //       exit(10);
2528 -
2529 -      mesh.CalcSurfacesOfNode();
2530 -      multithread.task = savetask;
2531 -   }
2532 -
2533 -
2534 -
2535 -
2536 -   void OCCMeshSurface (OCCGeometry & geom, Mesh & mesh, int perfstepsend)
2537 -   {
2538 -      int i, j, k;
2539 -      int changed;
2540 -
2541 -      const char * savetask = multithread.task;
2542 -      multithread.task = "Surface meshing";
2543 -
2544 -      geom.facemeshstatus = 0;
2545 -
2546 -      int noldp = mesh.GetNP();
2547 -
2548 -      double starttime = GetTime();
2549 -
2550 -      Array<int> glob2loc(noldp);
2551 -
2552 -      //int projecttype = PARAMETERSPACE;
2553 -
2554 -      int projecttype = PARAMETERSPACE;
2555 -
2556 -      int notrys = 1;
2557 -
2558 -      int surfmesherror = 0;
2559 -
2560 -      for (k = 1; k <= mesh.GetNFD(); k++)
2561 -      {
2562 -         if(1==0 && !geom.fvispar[k-1].IsDrawable())
2563 -         {
2564 -            (*testout) << "ignoring face " << k << endl;
2565 -            cout << "ignoring face " << k << endl;
2566 -            continue;
2567 -         }
2568 -
2569 -         (*testout) << "mesh face " << k << endl;
2570 -         multithread.percent = 100 * k / (mesh.GetNFD() + VSMALL);
2571 -         geom.facemeshstatus[k-1] = -1;
2572 -
2573 -
2574 -         /*
2575 -         if (k != 42)
2576 -         {
2577 -         cout << "skipped" << endl;
2578 -         continue;
2579 -         }
2580 -         */
2581 -
2582 -
2583 -         FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
2584 -
2585 -         int oldnf = mesh.GetNSE();
2586 -
2587 -         Box<3> bb = geom.GetBoundingBox();
2588 -
2589 -         //      int projecttype = PLANESPACE;
2590 -
2591 -         Meshing2OCCSurfaces meshing(TopoDS::Face(geom.fmap(k)), bb, projecttype);
2592 -
2593 -         if (meshing.GetProjectionType() == PLANESPACE)
2594 -            PrintMessage (2, "Face ", k, " / ", mesh.GetNFD(), " (plane space projection)");
2595 -         else
2596 -            PrintMessage (2, "Face ", k, " / ", mesh.GetNFD(), " (parameter space projection)");
2597 -
2598 -         if (surfmesherror)
2599 -            cout << "Surface meshing error occured before (in " << surfmesherror << " faces)" << endl;
2600 -
2601 -         //      Meshing2OCCSurfaces meshing(f2, bb);
2602 -         meshing.SetStartTime (starttime);
2603 -
2604 -         //(*testout) << "Face " << k << endl << endl;
2605 -
2606 -
2607 -         if (meshing.GetProjectionType() == PLANESPACE)
2608 -         {
2609 -            int cntp = 0;
2610 -            glob2loc = 0;
2611 -            for (i = 1; i <= mesh.GetNSeg(); i++)
2612 -            {
2613 -               Segment & seg = mesh.LineSegment(i);
2614 -               if (seg.si == k)
2615 -               {
2616 -                  for (j = 1; j <= 2; j++)
2617 -                  {
2618 -                     int pi = (j == 1) ? seg[0] : seg[1];
2619 -                     if (!glob2loc.Get(pi))
2620 -                     {
2621 -                        meshing.AddPoint (mesh.Point(pi), pi);
2622 -                        cntp++;
2623 -                        glob2loc.Elem(pi) = cntp;
2624 -                     }
2625 -                  }
2626 -               }
2627 -            }
2628 -
2629 -            for (i = 1; i <= mesh.GetNSeg(); i++)
2630 -            {
2631 -               Segment & seg = mesh.LineSegment(i);
2632 -               if (seg.si == k)
2633 -               {
2634 -                  PointGeomInfo gi0, gi1;
2635 -                  gi0.trignum = gi1.trignum = k;
2636 -                  gi0.u = seg.epgeominfo[0].u;
2637 -                  gi0.v = seg.epgeominfo[0].v;
2638 -                  gi1.u = seg.epgeominfo[1].u;
2639 -                  gi1.v = seg.epgeominfo[1].v;
2640 -
2641 -                  meshing.AddBoundaryElement (glob2loc.Get(seg[0]), glob2loc.Get(seg[1]), gi0, gi1);
2642 -                  //(*testout) << gi0.u << " " << gi0.v << endl;
2643 -                  //(*testout) << gi1.u << " " << gi1.v << endl;
2644 -               }
2645 -            }
2646 -         }
2647 -         else
2648 -         {
2649 -            int cntp = 0;
2650 -
2651 -            for (i = 1; i <= mesh.GetNSeg(); i++)
2652 -               if (mesh.LineSegment(i).si == k)
2653 -                  cntp+=2;
2654 -
2655 -
2656 -            Array< PointGeomInfo > gis;
2657 -
2658 -            gis.SetAllocSize (cntp);
2659 -            gis.SetSize (0);
2660 -
2661 -            for (i = 1; i <= mesh.GetNSeg(); i++)
2662 -            {
2663 -               Segment & seg = mesh.LineSegment(i);
2664 -               if (seg.si == k)
2665 -               {
2666 -                  PointGeomInfo gi0, gi1;
2667 -                  gi0.trignum = gi1.trignum = k;
2668 -                  gi0.u = seg.epgeominfo[0].u;
2669 -                  gi0.v = seg.epgeominfo[0].v;
2670 -                  gi1.u = seg.epgeominfo[1].u;
2671 -                  gi1.v = seg.epgeominfo[1].v;
2672 -
2673 -                  int locpnum[2] = {0, 0};
2674 -
2675 -                  for (j = 0; j < 2; j++)
2676 -                  {
2677 -                     PointGeomInfo gi = (j == 0) ? gi0 : gi1;
2678 -
2679 -                     int l;
2680 -                     for (l = 0; l < gis.Size() && locpnum[j] == 0; l++)
2681 -                     {
2682 -                        double dist = sqr (gis[l].u-gi.u)+sqr(gis[l].v-gi.v);
2683 -
2684 -                        if (dist < 1e-10)
2685 -                           locpnum[j] = l+1;
2686 -                     }
2687 -
2688 -                     if (locpnum[j] == 0)
2689 -                     {
2690 -                        int pi = (j == 0) ? seg[0] : seg[1];
2691 -                        meshing.AddPoint (mesh.Point(pi), pi);
2692 -
2693 -                        gis.SetSize (gis.Size()+1);
2694 -                        gis[l] = gi;
2695 -                        locpnum[j] = l+1;
2696 -                     }
2697 -                  }
2698 -
2699 -                  meshing.AddBoundaryElement (locpnum[0], locpnum[1], gi0, gi1);
2700 -                  //(*testout) << gi0.u << " " << gi0.v << endl;
2701 -                  //(*testout) << gi1.u << " " << gi1.v << endl;
2702 -
2703 -               }
2704 -            }
2705 -         }
2706 -
2707 -
2708 -
2709 -
2710 -
2711 -         // Philippose - 15/01/2009
2712 -         double maxh = geom.face_maxh[k-1];
2713 -         //double maxh = mparam.maxh;
2714 -         mparam.checkoverlap = 0;
2715 -         //      int noldpoints = mesh->GetNP();
2716 -         int noldsurfel = mesh.GetNSE();
2717 -
2718 -         GProp_GProps sprops;
2719 -         BRepGProp::SurfaceProperties(TopoDS::Face(geom.fmap(k)),sprops);
2720 -         meshing.SetMaxArea(2.*sprops.Mass());
2721 -
2722 -         MESHING2_RESULT res;
2723 -
2724 -         try {
2725 -          res = meshing.GenerateMesh (mesh, mparam, maxh, k);
2726 -         }
2727 -
2728 -         catch (SingularMatrixException)
2729 -         {
2730 -            (*myerr) << "Singular Matrix" << endl;
2731 -            res = MESHING2_GIVEUP;
2732 -         }
2733 -
2734 -         catch (UVBoundsException)
2735 -         {
2736 -            (*myerr) << "UV bounds exceeded" << endl;
2737 -            res = MESHING2_GIVEUP;
2738 -         }
2739 -
2740 -         projecttype = PARAMETERSPACE;
2741 -
2742 -         if (res != MESHING2_OK)
2743 -         {
2744 -            if (notrys == 1)
2745 -            {
2746 -               for (int i = noldsurfel+1; i <= mesh.GetNSE(); i++)
2747 -                  mesh.DeleteSurfaceElement (i);
2748 -
2749 -               mesh.Compress();
2750 -
2751 -               cout << "retry Surface " << k << endl;
2752 -
2753 -               k--;
2754 -               projecttype*=-1;
2755 -               notrys++;
2756 -               continue;
2757 -            }
2758 -            else
2759 -            {
2760 -               geom.facemeshstatus[k-1] = -1;
2761 -               PrintError ("Problem in Surface mesh generation");
2762 -               surfmesherror++;
2763 -               //            throw NgException ("Problem in Surface mesh generation");
2764 -            }
2765 -         }
2766 -         else
2767 -         {
2768 -            geom.facemeshstatus[k-1] = 1;
2769 -         }
2770 -
2771 -         notrys = 1;
2772 -
2773 -         for (i = oldnf+1; i <= mesh.GetNSE(); i++)
2774 -            mesh.SurfaceElement(i).SetIndex (k);
2775 -
2776 -      }
2777 -
2778 -//      ofstream problemfile("occmesh.rep");
2779 -
2780 -//      problemfile << "SURFACEMESHING" << endl << endl;
2781 -
2782 -      if (surfmesherror)
2783 -      {
2784 -         cout << "WARNING! NOT ALL FACES HAVE BEEN MESHED" << endl;
2785 -         cout << "SURFACE MESHING ERROR OCCURED IN " << surfmesherror << " FACES:" << endl;
2786 -         for (int i = 1; i <= geom.fmap.Extent(); i++)
2787 -            if (geom.facemeshstatus[i-1] == -1)
2788 -            {
2789 -               cout << "Face " << i << endl;
2790 -//               problemfile << "problem with face " << i << endl;
2791 -//               problemfile << "vertices: " << endl;
2792 -               TopExp_Explorer exp0,exp1,exp2;
2793 -               for ( exp0.Init(TopoDS::Face (geom.fmap(i)), TopAbs_WIRE); exp0.More(); exp0.Next() )
2794 -               {
2795 -                  TopoDS_Wire wire = TopoDS::Wire(exp0.Current());
2796 -                  for ( exp1.Init(wire,TopAbs_EDGE); exp1.More(); exp1.Next() )
2797 -                  {
2798 -                     TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
2799 -                     for ( exp2.Init(edge,TopAbs_VERTEX); exp2.More(); exp2.Next() )
2800 -                     {
2801 -                        TopoDS_Vertex vertex = TopoDS::Vertex(exp2.Current());
2802 -                        gp_Pnt point = BRep_Tool::Pnt(vertex);
2803 -//                        problemfile << point.X() << " " << point.Y() << " " << point.Z() << endl;
2804 -                     }
2805 -                  }
2806 -               }
2807 -//               problemfile << endl;
2808 -
2809 -            }
2810 -            cout << endl << endl;
2811 -            cout << "for more information open IGES/STEP Topology Explorer" << endl;
2812 -//            problemfile.close();
2813 -            throw NgException ("Problem in Surface mesh generation");
2814 -      }
2815 -      else
2816 -      {
2817 -//         problemfile << "OK" << endl << endl;
2818 -//         problemfile.close();
2819 -      }
2820 -
2821 -
2822 -
2823 -
2824 -      if (multithread.terminate || perfstepsend < MESHCONST_OPTSURFACE)
2825 -         return;
2826 -
2827 -      multithread.task = "Optimizing surface";
2828 -
2829 -      static int timer_opt2d = NgProfiler::CreateTimer ("Optimization 2D");
2830 -      NgProfiler::StartTimer (timer_opt2d);
2831 -
2832 -      for (k = 1; k <= mesh.GetNFD(); k++)
2833 -      {
2834 -         //      if (k != 42) continue;
2835 -         //      if (k != 36) continue;
2836 -
2837 -         //      (*testout) << "optimize face " << k << endl;
2838 -         multithread.percent = 100 * k / (mesh.GetNFD() + VSMALL);
2839 -
2840 -         FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
2841 -
2842 -         PrintMessage (1, "Optimize Surface ", k);
2843 -         for (i = 1; i <= mparam.optsteps2d; i++)
2844 -         {
2845 -            //   (*testout) << "optstep " << i << endl;
2846 -            if (multithread.terminate) return;
2847 -
2848 -            {
2849 -               MeshOptimize2dOCCSurfaces meshopt(geom);
2850 -               meshopt.SetFaceIndex (k);
2851 -               meshopt.SetImproveEdges (0);
2852 -               meshopt.SetMetricWeight (mparam.elsizeweight);
2853 -               //meshopt.SetMetricWeight (0.2);
2854 -               meshopt.SetWriteStatus (0);
2855 -
2856 -               //          (*testout) << "EdgeSwapping (mesh, (i > mparam.optsteps2d/2))" << endl;
2857 -               meshopt.EdgeSwapping (mesh, (i > mparam.optsteps2d/2));
2858 -            }
2859 -
2860 -            if (multithread.terminate) return;
2861 -            {
2862 -               MeshOptimize2dOCCSurfaces meshopt(geom);
2863 -               meshopt.SetFaceIndex (k);
2864 -               meshopt.SetImproveEdges (0);
2865 -               //meshopt.SetMetricWeight (0.2);
2866 -               meshopt.SetMetricWeight (mparam.elsizeweight);
2867 -               meshopt.SetWriteStatus (0);
2868 -
2869 -               //          (*testout) << "ImproveMesh (mesh)" << endl;
2870 -               meshopt.ImproveMesh (mesh, mparam);
2871 -            }
2872 -
2873 -            {
2874 -               MeshOptimize2dOCCSurfaces meshopt(geom);
2875 -               meshopt.SetFaceIndex (k);
2876 -               meshopt.SetImproveEdges (0);
2877 -               //meshopt.SetMetricWeight (0.2);
2878 -               meshopt.SetMetricWeight (mparam.elsizeweight);
2879 -               meshopt.SetWriteStatus (0);
2880 -
2881 -               //          (*testout) << "CombineImprove (mesh)" << endl;
2882 -               meshopt.CombineImprove (mesh);
2883 -            }
2884 -
2885 -            if (multithread.terminate) return;
2886 -            {
2887 -               MeshOptimize2dOCCSurfaces meshopt(geom);
2888 -               meshopt.SetFaceIndex (k);
2889 -               meshopt.SetImproveEdges (0);
2890 -               //meshopt.SetMetricWeight (0.2);
2891 -               meshopt.SetMetricWeight (mparam.elsizeweight);
2892 -               meshopt.SetWriteStatus (0);
2893 -
2894 -               //          (*testout) << "ImproveMesh (mesh)" << endl;
2895 -               meshopt.ImproveMesh (mesh, mparam);
2896 -            }
2897 -         }
2898 -
2899 -      }
2900 -
2901 -
2902 -      mesh.CalcSurfacesOfNode();
2903 -      mesh.Compress();
2904 -
2905 -      NgProfiler::StopTimer (timer_opt2d);
2906 -
2907 -      multithread.task = savetask;
2908 -   }
2909 -
2910 -
2911 -
2912 -   void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh)
2913 -   {
2914 -      mesh.SetGlobalH (mparam.maxh);
2915 -      mesh.SetMinimalH (mparam.minh);
2916 -
2917 -      Array<double> maxhdom;
2918 -      maxhdom.SetSize (geom.NrSolids());
2919 -      maxhdom = mparam.maxh;
2920 -
2921 -      mesh.SetMaxHDomain (maxhdom);
2922 -
2923 -      Box<3> bb = geom.GetBoundingBox();
2924 -      bb.Increase (bb.Diam()/10);
2925 -
2926 -      mesh.SetLocalH (bb.PMin(), bb.PMax(), 0.5);
2927 -
2928 -      if (mparam.uselocalh)
2929 -      {
2930 -         const char * savetask = multithread.task;
2931 -         multithread.percent = 0;
2932 -
2933 -         mesh.SetLocalH (bb.PMin(), bb.PMax(), mparam.grading);
2934 -
2935 -         int nedges = geom.emap.Extent();
2936 -
2937 -                double mincurvelength = IGNORECURVELENGTH;
2938 -         double maxedgelen = 0;
2939 -         double minedgelen = 1e99;
2940 -
2941 -                if(occparam.resthminedgelenenable) 
2942 -                {
2943 -                       mincurvelength = occparam.resthminedgelen;
2944 -                       if(mincurvelength < IGNORECURVELENGTH) mincurvelength = IGNORECURVELENGTH;
2945 -                }
2946 -
2947 -         multithread.task = "Setting local mesh size (elements per edge)";
2948 -
2949 -         // setting elements per edge
2950 -
2951 -         for (int i = 1; i <= nedges && !multithread.terminate; i++)
2952 -         {
2953 -            TopoDS_Edge e = TopoDS::Edge (geom.emap(i));
2954 -            multithread.percent = 100 * (i-1)/double(nedges);
2955 -            if (BRep_Tool::Degenerated(e)) continue;
2956 -
2957 -            GProp_GProps system;
2958 -            BRepGProp::LinearProperties(e, system);
2959 -            double len = system.Mass();
2960 -
2961 -            if (len < mincurvelength)
2962 -            {
2963 -               (*testout) << "ignored" << endl;
2964 -               continue;
2965 -            }
2966 -
2967 -            double localh = len/mparam.segmentsperedge;
2968 -            double s0, s1;
2969 -
2970 -            // Philippose - 23/01/2009
2971 -            // Find all the parent faces of a given edge
2972 -            // and limit the mesh size of the edge based on the
2973 -            // mesh size limit of the face
2974 -            TopTools_IndexedDataMapOfShapeListOfShape edge_face_map;
2975 -            edge_face_map.Clear();
2976 -
2977 -            TopExp::MapShapesAndAncestors(geom.shape, TopAbs_EDGE, TopAbs_FACE, edge_face_map);
2978 -            const TopTools_ListOfShape& parent_faces = edge_face_map.FindFromKey(e);
2979 -
2980 -            TopTools_ListIteratorOfListOfShape parent_face_list;
2981 -
2982 -            for(parent_face_list.Initialize(parent_faces); parent_face_list.More(); parent_face_list.Next())
2983 -            {
2984 -               TopoDS_Face parent_face = TopoDS::Face(parent_face_list.Value());
2985 -
2986 -               int face_index = geom.fmap.FindIndex(parent_face);
2987 -
2988 -               if(face_index >= 1) localh = min(localh,geom.face_maxh[face_index - 1]);
2989 -            }
2990 -
2991 -            Handle(Geom_Curve) c = BRep_Tool::Curve(e, s0, s1);
2992 -
2993 -            maxedgelen = max (maxedgelen, len);
2994 -            minedgelen = min (minedgelen, len);
2995 -
2996 -            // Philippose - 23/01/2009
2997 -            // Modified the calculation of maxj, because the
2998 -            // method used so far always results in maxj = 2,
2999 -            // which causes the localh to be set only at the
3000 -            // starting, mid and end of the edge.
3001 -            // Old Algorithm:
3002 -            // int maxj = 2 * (int) ceil (localh/len);
3003 -            int maxj = max((int) ceil(len/localh), 2);
3004 -
3005 -            for (int j = 0; j <= maxj; j++)
3006 -            {
3007 -               gp_Pnt pnt = c->Value (s0+double(j)/maxj*(s1-s0));
3008 -               mesh.RestrictLocalH (Point3d(pnt.X(), pnt.Y(), pnt.Z()), localh);
3009 -            }
3010 -         }
3011 -
3012 -         multithread.task = "Setting local mesh size (edge curvature)";
3013 -
3014 -         // setting edge curvature
3015 -
3016 -         int nsections = 20;
3017 -
3018 -         for (int i = 1; i <= nedges && !multithread.terminate; i++)
3019 -         {
3020 -            double maxcur = 0;
3021 -            multithread.percent = 100 * (i-1)/double(nedges);
3022 -            TopoDS_Edge edge = TopoDS::Edge (geom.emap(i));
3023 -            if (BRep_Tool::Degenerated(edge)) continue;
3024 -            double s0, s1;
3025 -            Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1);
3026 -            BRepAdaptor_Curve brepc(edge);
3027 -            BRepLProp_CLProps prop(brepc, 2, 1e-5);
3028 -
3029 -            for (int j = 1; j <= nsections; j++)
3030 -            {
3031 -               double s = s0 + j/(double) nsections * (s1-s0);
3032 -               prop.SetParameter (s);
3033 -               double curvature = prop.Curvature();
3034 -               if(curvature> maxcur) maxcur = curvature;
3035 -
3036 -               if (curvature >= 1e99)
3037 -                  continue;
3038 -
3039 -               gp_Pnt pnt = c->Value (s);
3040 -
3041 -               mesh.RestrictLocalH (Point3d(pnt.X(), pnt.Y(), pnt.Z()), ComputeH (fabs(curvature)));
3042 -            }
3043 -            // (*testout) << "edge " << i << " max. curvature: " << maxcur << endl;
3044 -         }
3045 -
3046 -         multithread.task = "Setting local mesh size (face curvature)";
3047 -
3048 -         // setting face curvature
3049 -
3050 -         int nfaces = geom.fmap.Extent();
3051 -
3052 -         for (int i = 1; i <= nfaces && !multithread.terminate; i++)
3053 -         {
3054 -            multithread.percent = 100 * (i-1)/double(nfaces);
3055 -            TopoDS_Face face = TopoDS::Face(geom.fmap(i));
3056 -            TopLoc_Location loc;
3057 -            Handle(Geom_Surface) surf = BRep_Tool::Surface (face);
3058 -            Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation (face, loc);
3059 -
3060 -            if (triangulation.IsNull()) continue;
3061 -
3062 -            BRepAdaptor_Surface sf(face, Standard_True);
3063 -            BRepLProp_SLProps prop(sf, 2, 1e-5);
3064 -
3065 -            int ntriangles = triangulation -> NbTriangles();
3066 -            for (int j = 1; j <= ntriangles; j++)
3067 -            {
3068 -               gp_Pnt p[3];
3069 -               gp_Pnt2d par[3];
3070 -
3071 -               for (int k = 1; k <=3; k++)
3072 -               {
3073 -                  int n = triangulation->Triangles()(j)(k);
3074 -                  p[k-1] = triangulation->Nodes()(n).Transformed(loc);
3075 -                  par[k-1] = triangulation->UVNodes()(n);
3076 -               }
3077 -
3078 -               //double maxside = 0;
3079 -               //maxside = max (maxside, p[0].Distance(p[1]));
3080 -               //maxside = max (maxside, p[0].Distance(p[2]));
3081 -               //maxside = max (maxside, p[1].Distance(p[2]));
3082 -               //cout << "\rFace " << i << " pos11 ntriangles " << ntriangles << " maxside " << maxside << flush;
3083 -
3084 -               RestrictHTriangle (par[0], par[1], par[2], &prop, mesh, 0);
3085 -               //cout << "\rFace " << i << " pos12 ntriangles " << ntriangles << flush;
3086 -            }
3087 -         }
3088 -
3089 -         // setting close edges
3090 -
3091 -         if (occparam.resthcloseedgeenable)
3092 -         {
3093 -            multithread.task = "Setting local mesh size (close edges)";
3094 -
3095 -            int sections = 100;
3096 -
3097 -            Array<Line> lines(sections*nedges);
3098 -
3099 -            Box3dTree* searchtree =
3100 -               new Box3dTree (bb.PMin(), bb.PMax());
3101 -
3102 -            int nlines = 0;
3103 -            for (int i = 1; i <= nedges && !multithread.terminate; i++)
3104 -            {
3105 -               TopoDS_Edge edge = TopoDS::Edge (geom.emap(i));
3106 -               if (BRep_Tool::Degenerated(edge)) continue;
3107 -
3108 -               double s0, s1;
3109 -               Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1);
3110 -               BRepAdaptor_Curve brepc(edge);
3111 -               BRepLProp_CLProps prop(brepc, 1, 1e-5);
3112 -               prop.SetParameter (s0);
3113 -
3114 -               gp_Vec d0 = prop.D1().Normalized();
3115 -               double s_start = s0;
3116 -               int count = 0;
3117 -               for (int j = 1; j <= sections; j++)
3118 -               {
3119 -                  double s = s0 + (s1-s0)*(double)j/(double)sections;
3120 -                  prop.SetParameter (s);
3121 -                  gp_Vec d1 = prop.D1().Normalized();
3122 -                  double cosalpha = fabs(d0*d1);
3123 -                  if ((j == sections) || (cosalpha < cos(10.0/180.0*M_PI)))
3124 -                  {
3125 -                     count++;
3126 -                     gp_Pnt p0 = c->Value (s_start);
3127 -                     gp_Pnt p1 = c->Value (s);
3128 -                     lines[nlines].p0 = Point<3> (p0.X(), p0.Y(), p0.Z());
3129 -                     lines[nlines].p1 = Point<3> (p1.X(), p1.Y(), p1.Z());
3130 -
3131 -                     Box3d box;
3132 -                     box.SetPoint (Point3d(lines[nlines].p0));
3133 -                     box.AddPoint (Point3d(lines[nlines].p1));
3134 -
3135 -                     searchtree->Insert (box.PMin(), box.PMax(), nlines+1);
3136 -                     nlines++;
3137 -
3138 -                     s_start = s;
3139 -                     d0 = d1;
3140 -                  }
3141 -               }
3142 -            }
3143 -
3144 -            Array<int> linenums;
3145 -
3146 -            for (int i = 0; i < nlines; i++)
3147 -            {
3148 -               multithread.percent = (100*i)/double(nlines);
3149 -               Line & line = lines[i];
3150 -
3151 -               Box3d box;
3152 -               box.SetPoint (Point3d(line.p0));
3153 -               box.AddPoint (Point3d(line.p1));
3154 -               double maxhline = max (mesh.GetH(box.PMin()),
3155 -                  mesh.GetH(box.PMax()));
3156 -               box.Increase(maxhline);
3157 -
3158 -               double mindist = 1e99;
3159 -               linenums.SetSize(0);
3160 -               searchtree->GetIntersecting(box.PMin(),box.PMax(),linenums);
3161 -
3162 -               for (int j = 0; j < linenums.Size(); j++)
3163 -               {
3164 -                  int num = linenums[j]-1;
3165 -                  if (i == num) continue;
3166 -                  if ((line.p0-lines[num].p0).Length2() < 1e-15) continue;
3167 -                  if ((line.p0-lines[num].p1).Length2() < 1e-15) continue;
3168 -                  if ((line.p1-lines[num].p0).Length2() < 1e-15) continue;
3169 -                  if ((line.p1-lines[num].p1).Length2() < 1e-15) continue;
3170 -                  mindist = min (mindist, line.Dist(lines[num]));
3171 -               }
3172 -
3173 -               mindist /= (occparam.resthcloseedgefac + VSMALL);
3174 -
3175 -               if (mindist < 1e-3)
3176 -               {
3177 -                  (*testout) << "extremely small local h: " << mindist
3178 -                     << " --> setting to 1e-3" << endl;
3179 -                  (*testout) << "somewhere near " << line.p0 << " - " << line.p1 << endl;
3180 -                  mindist = 1e-3;
3181 -               }
3182 -
3183 -               mesh.RestrictLocalHLine(line.p0, line.p1, mindist);
3184 -            }
3185 -         }
3186 -
3187 -         multithread.task = savetask;
3188 -
3189 -      }
3190 -
3191 -      // Philippose - 09/03/2009
3192 -      // Added the capability to load the mesh size from a 
3193 -      // file also for OpenCascade Geometry
3194 -      // Note: 
3195 -      // ** If the "uselocalh" option is ticked in 
3196 -      // the "mesh options...insider" menu, the mesh 
3197 -      // size will be further modified by the topology 
3198 -      // analysis routines.
3199 -      // ** To use the mesh size file as the sole source 
3200 -      // for defining the mesh size, uncheck the "uselocalh"
3201 -      // option.
3202 -      mesh.LoadLocalMeshSize (mparam.meshsizefilename);
3203 -   }
3204 -
3205 -
3206 -
3207 -  int OCCGenerateMesh (OCCGeometry & geom, Mesh *& mesh, MeshingParameters & mparam,
3208 -                      int perfstepsstart, int perfstepsend)
3209 -   {
3210 -      multithread.percent = 0;
3211 -
3212 -      if (perfstepsstart <= MESHCONST_ANALYSE)
3213 -      {
3214 -         delete mesh;
3215 -         mesh = new Mesh();
3216 -         mesh->geomtype = Mesh::GEOM_OCC;
3217 -
3218 -         OCCSetLocalMeshSize(geom,*mesh);
3219 -      }
3220 -
3221 -      if (multithread.terminate || perfstepsend <= MESHCONST_ANALYSE)
3222 -         return TCL_OK;
3223 -
3224 -      if (perfstepsstart <= MESHCONST_MESHEDGES)
3225 -      {
3226 -         OCCFindEdges (geom, *mesh);
3227 -
3228 -         /*
3229 -         cout << "Removing redundant points" << endl;
3230 -
3231 -         int i, j;
3232 -         int np = mesh->GetNP();
3233 -         Array<int> equalto;
3234 -
3235 -         equalto.SetSize (np);
3236 -         equalto = 0;
3237 -
3238 -         for (i = 1; i <= np; i++)
3239 -         {
3240 -         for (j = i+1; j <= np; j++)
3241 -         {
3242 -         if (!equalto[j-1] && (Dist2 (mesh->Point(i), mesh->Point(j)) < 1e-12))
3243 -         equalto[j-1] = i;
3244 -         }
3245 -         }
3246 -
3247 -         for (i = 1; i <= np; i++)
3248 -         if (equalto[i-1])
3249 -         {
3250 -         cout << "Point " << i << " is equal to Point " << equalto[i-1] << endl;
3251 -         for (j = 1; j <= mesh->GetNSeg(); j++)
3252 -         {
3253 -         Segment & seg = mesh->LineSegment(j);
3254 -         if (seg[0] == i) seg[0] = equalto[i-1];
3255 -         if (seg[1] == i) seg[1] = equalto[i-1];
3256 -         }
3257 -         }
3258 -
3259 -         cout << "Removing degenerated segments" << endl;
3260 -         for (j = 1; j <= mesh->GetNSeg(); j++)
3261 -         {
3262 -         Segment & seg = mesh->LineSegment(j);
3263 -         if (seg[0] == seg[1])
3264 -         {
3265 -         mesh->DeleteSegment(j);
3266 -         cout << "Deleting Segment " << j << endl;
3267 -         }
3268 -         }
3269 -
3270 -         mesh->Compress();
3271 -         */
3272 -
3273 -         /*
3274 -         for (int i = 1; i <= geom.fmap.Extent(); i++)
3275 -         {
3276 -         Handle(Geom_Surface) hf1 =
3277 -         BRep_Tool::Surface(TopoDS::Face(geom.fmap(i)));
3278 -         for (int j = i+1; j <= geom.fmap.Extent(); j++)
3279 -         {
3280 -         Handle(Geom_Surface) hf2 =
3281 -         BRep_Tool::Surface(TopoDS::Face(geom.fmap(j)));
3282 -         if (hf1 == hf2) cout << "face " << i << " and face " << j << " lie on same surface" << endl;
3283 -         }
3284 -         }
3285 -         */
3286 -
3287 -#ifdef LOG_STREAM
3288 -         (*logout) << "Edges meshed" << endl
3289 -            << "time = " << GetTime() << " sec" << endl
3290 -            << "points: " << mesh->GetNP() << endl;
3291 -#endif
3292 -      }
3293 -
3294 -      if (multithread.terminate || perfstepsend <= MESHCONST_MESHEDGES)
3295 -         return TCL_OK;
3296 -
3297 -      if (perfstepsstart <= MESHCONST_MESHSURFACE)
3298 -      {
3299 -         OCCMeshSurface (geom, *mesh, perfstepsend);
3300 -         if (multithread.terminate) return TCL_OK;
3301 -
3302 -#ifdef LOG_STREAM
3303 -         (*logout) << "Surfaces meshed" << endl
3304 -            << "time = " << GetTime() << " sec" << endl
3305 -            << "points: " << mesh->GetNP() << endl;
3306 -#endif
3307 -
3308 -#ifdef STAT_STREAM
3309 -         (*statout) << mesh->GetNSeg() << " & "
3310 -            << mesh->GetNSE() << " & - &"
3311 -            << GetTime() << " & " << endl;
3312 -#endif
3313 -
3314 -         //      MeshQuality2d (*mesh);
3315 -         mesh->CalcSurfacesOfNode();
3316 -      }
3317 -
3318 -      if (multithread.terminate || perfstepsend <= MESHCONST_OPTSURFACE)
3319 -         return TCL_OK;
3320 -
3321 -      if (perfstepsstart <= MESHCONST_MESHVOLUME)
3322 -      {
3323 -         multithread.task = "Volume meshing";
3324 -
3325 -         MESHING3_RESULT res = MeshVolume (mparam, *mesh);
3326 -
3327 -/*
3328 -         ofstream problemfile("occmesh.rep",ios_base::app);
3329 -
3330 -         problemfile << "VOLUMEMESHING" << endl << endl;
3331 -         if(res != MESHING3_OK)
3332 -            problemfile << "ERROR" << endl << endl;
3333 -         else
3334 -            problemfile << "OK" << endl
3335 -            << mesh->GetNE() << " elements" << endl << endl;
3336 -
3337 -         problemfile.close();
3338 -*/
3339 -
3340 -         if (res != MESHING3_OK) return TCL_ERROR;
3341 -
3342 -         if (multithread.terminate) return TCL_OK;
3343 -
3344 -         RemoveIllegalElements (*mesh);
3345 -         if (multithread.terminate) return TCL_OK;
3346 -
3347 -         MeshQuality3d (*mesh);
3348 -
3349 -#ifdef STAT_STREAM
3350 -         (*statout) << GetTime() << " & ";
3351 -#endif
3352 -
3353 -#ifdef LOG_STREAM
3354 -         (*logout) << "Volume meshed" << endl
3355 -            << "time = " << GetTime() << " sec" << endl
3356 -            << "points: " << mesh->GetNP() << endl;
3357 -#endif
3358 -      }
3359 -
3360 -      if (multithread.terminate || perfstepsend <= MESHCONST_MESHVOLUME)
3361 -         return TCL_OK;
3362 -
3363 -      if (perfstepsstart <= MESHCONST_OPTVOLUME)
3364 -      {
3365 -         multithread.task = "Volume optimization";
3366 -
3367 -         OptimizeVolume (mparam, *mesh);
3368 -         if (multithread.terminate) return TCL_OK;
3369 -
3370 -#ifdef STAT_STREAM
3371 -         (*statout) << GetTime() << " & "
3372 -            << mesh->GetNE() << " & "
3373 -            << mesh->GetNP() << " " << '\\' << '\\' << " \\" << "hline" << endl;
3374 -#endif
3375 -
3376 -#ifdef LOG_STREAM
3377 -         (*logout) << "Volume optimized" << endl
3378 -            << "time = " << GetTime() << " sec" << endl
3379 -            << "points: " << mesh->GetNP() << endl;
3380 -#endif
3381 -
3382 -         // cout << "Optimization complete" << endl;
3383 -
3384 -      }
3385 -
3386 -      (*testout) << "NP: " << mesh->GetNP() << endl;
3387 -      for (int i = 1; i <= mesh->GetNP(); i++)
3388 -         (*testout) << mesh->Point(i) << endl;
3389 -
3390 -      (*testout) << endl << "NSegments: " << mesh->GetNSeg() << endl;
3391 -      for (int i = 1; i <= mesh->GetNSeg(); i++)
3392 -         (*testout) << mesh->LineSegment(i) << endl;
3393 -
3394 -      return TCL_OK;
3395 -   }
3396 -}
3397 -
3398 -#endif
3399 +#ifdef OCCGEOMETRY
3400 +
3401 +#include <mystdlib.h>
3402 +#include <occgeom.hpp>
3403 +#include <meshing.hpp>
3404 +
3405 +
3406 +namespace netgen
3407 +{
3408 +
3409 +#include "occmeshsurf.hpp"
3410 +
3411 +#define TCL_OK 0
3412 +#define TCL_ERROR 1
3413 +
3414 +#define DIVIDEEDGESECTIONS 1000
3415 +#define IGNORECURVELENGTH 1e-4
3416 +#define VSMALL 1e-10
3417 +
3418 +
3419 +   DLL_HEADER bool merge_solids = 1;
3420 +
3421 +
3422 +  // can you please explain what you intend to compute here (JS) !!!
3423 +   double Line :: Dist (Line l)
3424 +   {
3425 +      Vec<3> n = p1-p0;
3426 +      Vec<3> q = l.p1-l.p0;
3427 +      double nq = n*q;
3428 +
3429 +      Point<3> p = p0 + 0.5*n;
3430 +      double lambda = (p-l.p0)*n / (nq + VSMALL);
3431 +
3432 +      if (lambda >= 0 && lambda <= 1)
3433 +      {
3434 +         double d = (p-l.p0-lambda*q).Length();
3435 +         //        if (d < 1e-3) d = 1e99;
3436 +         return d;
3437 +      }
3438 +      else
3439 +         return 1e99;
3440 +   }
3441 +
3442 +
3443 +
3444 +   double Line :: Length ()
3445 +   {
3446 +      return (p1-p0).Length();
3447 +   }
3448 +
3449 +
3450 +
3451 +   inline Point<3> occ2ng (const gp_Pnt & p)
3452 +   {
3453 +      return  Point<3> (p.X(), p.Y(), p.Z());
3454 +   }
3455 +
3456 +
3457 +
3458 +   double ComputeH (double kappa)
3459 +   {
3460 +      double hret;
3461 +      kappa *= mparam.curvaturesafety;
3462 +
3463 +      if (mparam.maxh * kappa < 1)
3464 +         hret = mparam.maxh;
3465 +      else
3466 +         hret = 1 / (kappa + VSMALL);
3467 +
3468 +      if (mparam.maxh < hret)
3469 +         hret = mparam.maxh;
3470 +
3471 +      return (hret);
3472 +   }
3473 +
3474 +
3475 +
3476 +
3477 +   void RestrictHTriangle (gp_Pnt2d & par0, gp_Pnt2d & par1, gp_Pnt2d & par2,
3478 +                           BRepLProp_SLProps * prop, Mesh & mesh, int depth, double h = 0)
3479 +   {
3480 +      int ls = -1;
3481 +
3482 +      gp_Pnt pnt0,pnt1,pnt2;
3483 +
3484 +      prop->SetParameters (par0.X(), par0.Y());
3485 +      pnt0 = prop->Value();
3486 +
3487 +      prop->SetParameters (par1.X(), par1.Y());
3488 +      pnt1 = prop->Value();
3489 +
3490 +      prop->SetParameters (par2.X(), par2.Y());
3491 +      pnt2 = prop->Value();
3492 +
3493 +      double aux;
3494 +      double maxside = pnt0.Distance(pnt1);
3495 +      ls = 2;
3496 +      aux = pnt1.Distance(pnt2);
3497 +      if(aux > maxside)
3498 +      {
3499 +         maxside = aux;
3500 +         ls = 0;
3501 +      }
3502 +      aux = pnt2.Distance(pnt0);
3503 +      if(aux > maxside)
3504 +      {
3505 +         maxside = aux;
3506 +         ls = 1;
3507 +      }
3508 +
3509 +
3510 +
3511 +      gp_Pnt2d parmid;
3512 +
3513 +      parmid.SetX( (par0.X()+par1.X()+par2.X()) / 3 );
3514 +      parmid.SetY( (par0.Y()+par1.Y()+par2.Y()) / 3 );
3515 +
3516 +      if (depth%3 == 0)
3517 +      {
3518 +         double curvature = 0;
3519 +
3520 +         prop->SetParameters (parmid.X(), parmid.Y());
3521 +         if (!prop->IsCurvatureDefined())
3522 +         {
3523 +            (*testout) << "curvature not defined!" << std::endl;
3524 +            return;
3525 +         }
3526 +         curvature = max(fabs(prop->MinCurvature()),
3527 +            fabs(prop->MaxCurvature()));
3528 +
3529 +         prop->SetParameters (par0.X(), par0.Y());
3530 +         if (!prop->IsCurvatureDefined())
3531 +         {
3532 +            (*testout) << "curvature not defined!" << std::endl;
3533 +            return;
3534 +         }
3535 +         curvature = max(curvature,max(fabs(prop->MinCurvature()),
3536 +            fabs(prop->MaxCurvature())));
3537 +
3538 +         prop->SetParameters (par1.X(), par1.Y());
3539 +         if (!prop->IsCurvatureDefined())
3540 +         {
3541 +            (*testout) << "curvature not defined!" << std::endl;
3542 +            return;
3543 +         }
3544 +         curvature = max(curvature,max(fabs(prop->MinCurvature()),
3545 +            fabs(prop->MaxCurvature())));
3546 +
3547 +         prop->SetParameters (par2.X(), par2.Y());
3548 +         if (!prop->IsCurvatureDefined())
3549 +         {
3550 +            (*testout) << "curvature not defined!" << std::endl;
3551 +            return;
3552 +         }
3553 +         curvature = max(curvature,max(fabs(prop->MinCurvature()),
3554 +            fabs(prop->MaxCurvature())));
3555 +
3556 +         //(*testout) << "curvature " << curvature << std::endl;
3557 +
3558 +         if (curvature < 1e-3)
3559 +         {
3560 +            //(*testout) << "curvature too small (" << curvature << ")!" << std::endl;
3561 +            return;
3562 +            // return war bis 10.2.05 auskommentiert
3563 +         }
3564 +
3565 +
3566 +
3567 +         h = ComputeH (curvature+1e-10);
3568 +
3569 +         if(h < 1e-4*maxside)
3570 +            return;
3571 +
3572 +         // commented to restrict H on a large sphere for example
3573 +         //if (h > 30) return;
3574 +      }
3575 +
3576 +      if (h < maxside && depth < 10)
3577 +      {
3578 +         //std::cout << "\r h " << h << flush;
3579 +         gp_Pnt2d pm;
3580 +
3581 +         //std::cout << "h " << h << " maxside " << maxside << " depth " << depth << std::endl;
3582 +         //std::cout << "par0 " << par0.X() << " " << par0.Y()
3583 +         //<< " par1 " << par1.X() << " " << par1.Y()
3584 +         //   << " par2 " << par2.X() << " " << par2.Y()<< std::endl;
3585 +
3586 +         if(ls == 0)
3587 +         {
3588 +            pm.SetX(0.5*(par1.X()+par2.X())); pm.SetY(0.5*(par1.Y()+par2.Y()));
3589 +            RestrictHTriangle(pm, par2, par0, prop, mesh, depth+1, h);
3590 +            RestrictHTriangle(pm, par0, par1, prop, mesh, depth+1, h);
3591 +         }
3592 +         else if(ls == 1)
3593 +         {
3594 +            pm.SetX(0.5*(par0.X()+par2.X())); pm.SetY(0.5*(par0.Y()+par2.Y()));
3595 +            RestrictHTriangle(pm, par1, par2, prop, mesh, depth+1, h);
3596 +            RestrictHTriangle(pm, par0, par1, prop, mesh, depth+1, h);
3597 +         }
3598 +         else if(ls == 2)
3599 +         {
3600 +            pm.SetX(0.5*(par0.X()+par1.X())); pm.SetY(0.5*(par0.Y()+par1.Y()));
3601 +            RestrictHTriangle(pm, par1, par2, prop, mesh, depth+1, h);
3602 +            RestrictHTriangle(pm, par2, par0, prop, mesh, depth+1, h);
3603 +         }
3604 +
3605 +      }
3606 +      else
3607 +      {
3608 +         gp_Pnt pnt;
3609 +         Point3d p3d;
3610 +
3611 +         prop->SetParameters (parmid.X(), parmid.Y());
3612 +         pnt = prop->Value();
3613 +         p3d = Point3d(pnt.X(), pnt.Y(), pnt.Z());
3614 +         mesh.RestrictLocalH (p3d, h);
3615 +
3616 +         p3d = Point3d(pnt0.X(), pnt0.Y(), pnt0.Z());
3617 +         mesh.RestrictLocalH (p3d, h);
3618 +
3619 +         p3d = Point3d(pnt1.X(), pnt1.Y(), pnt1.Z());
3620 +         mesh.RestrictLocalH (p3d, h);
3621 +
3622 +         p3d = Point3d(pnt2.X(), pnt2.Y(), pnt2.Z());
3623 +         mesh.RestrictLocalH (p3d, h);
3624 +
3625 +         //(*testout) << "p = " << p3d << ", h = " << h << ", maxside = " << maxside << std::endl;
3626 +
3627 +      }
3628 +   }
3629 +
3630 +
3631 +
3632 +   void DivideEdge (TopoDS_Edge & edge, Array<MeshPoint> & ps,
3633 +                    Array<double> & params, Mesh & mesh)
3634 +   {
3635 +      double s0, s1;
3636 +      double maxh = mparam.maxh;
3637 +      int nsubedges = 1;
3638 +      gp_Pnt pnt, oldpnt;
3639 +      double svalue[DIVIDEEDGESECTIONS];
3640 +
3641 +      GProp_GProps system;
3642 +      BRepGProp::LinearProperties(edge, system);
3643 +      double L = system.Mass();
3644 +
3645 +      Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1);
3646 +
3647 +      double hvalue[DIVIDEEDGESECTIONS+1];
3648 +      hvalue[0] = 0;
3649 +      pnt = c->Value(s0);
3650 +
3651 +      //double olddist = 0; -- useless variables
3652 +      //double dist = 0;
3653 +
3654 +      int tmpVal = (int)(DIVIDEEDGESECTIONS);
3655 +
3656 +      for (int i = 1; i <= tmpVal; i++)
3657 +      {
3658 +         oldpnt = pnt;
3659 +         pnt = c->Value(s0+(i/double(DIVIDEEDGESECTIONS))*(s1-s0));
3660 +         // -- no more than 1 segment per <edge length>/DIVIDEEDGESECTIONS
3661 +         hvalue[i] = hvalue[i-1] +
3662 +         //   1.0/mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))*
3663 +         //   pnt.Distance(oldpnt);
3664 +           min( 1.0,
3665 +            1.0/mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))*
3666 +                pnt.Distance(oldpnt));
3667 +
3668 +         //(*testout) << "mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z())) " << mesh.GetH(Point3d(pnt.X(), pnt.Y(), pnt.Z()))
3669 +         //       <<  " pnt.Distance(oldpnt) " << pnt.Distance(oldpnt) << std::endl;
3670 +
3671 +         //olddist = dist; -- useless variables
3672 +         //dist = pnt.Distance(oldpnt);
3673 +      }
3674 +
3675 +      //  nsubedges = int(ceil(hvalue[DIVIDEEDGESECTIONS]));
3676 +      nsubedges = max (1, int(floor(hvalue[DIVIDEEDGESECTIONS]+0.5)));
3677 +
3678 +      ps.SetSize(nsubedges-1);
3679 +      params.SetSize(nsubedges+1);
3680 +
3681 +      int i = 1;
3682 +      int i1 = 0;
3683 +      do
3684 +      {
3685 +         if (hvalue[i1]/hvalue[DIVIDEEDGESECTIONS]*nsubedges >= i)
3686 +         {
3687 +            // -- for nsubedges comparable to DIVIDEEDGESECTIONS
3688 +            //params[i] = s0+(i1/double(DIVIDEEDGESECTIONS))*(s1-s0);
3689 +            double d1 = i1 - (hvalue[i1] - i*hvalue[DIVIDEEDGESECTIONS]/nsubedges)/(hvalue[i1]-hvalue[i1-1]);
3690 +            params[i] = s0+(d1/double(DIVIDEEDGESECTIONS))*(s1-s0);
3691 +            pnt = c->Value(params[i]);
3692 +            ps[i-1] = MeshPoint (Point3d(pnt.X(), pnt.Y(), pnt.Z()));
3693 +            i++;
3694 +         }
3695 +         i1++;
3696 +         if (i1 > DIVIDEEDGESECTIONS)
3697 +         {
3698 +            nsubedges = i;
3699 +            ps.SetSize(nsubedges-1);
3700 +            params.SetSize(nsubedges+1);
3701 +            std::cout << "divide edge: local h too small" << std::endl;
3702 +         }
3703 +      } while (i < nsubedges);
3704 +
3705 +      params[0] = s0;
3706 +      params[nsubedges] = s1;
3707 +
3708 +      if (params[nsubedges] <= params[nsubedges-1])
3709 +      {
3710 +         std::cout << "CORRECTED" << std::endl;
3711 +         ps.SetSize (nsubedges-2);
3712 +         params.SetSize (nsubedges);
3713 +         params[nsubedges] = s1;
3714 +      }
3715 +   }
3716 +
3717 +
3718 +
3719 +
3720 +   void OCCFindEdges (OCCGeometry & geom, Mesh & mesh)
3721 +   {
3722 +      const char * savetask = multithread.task;
3723 +      multithread.task = "Edge meshing";
3724 +
3725 +      (*testout) << "edge meshing" << std::endl;
3726 +
3727 +      int nvertices = geom.vmap.Extent();
3728 +      int nedges = geom.emap.Extent();
3729 +
3730 +      (*testout) << "nvertices = " << nvertices << std::endl;
3731 +      (*testout) << "nedges = " << nedges << std::endl;
3732 +
3733 +      double eps = 1e-6 * geom.GetBoundingBox().Diam();
3734 +      const double eps2 = eps * eps; // -- small optimization
3735 +
3736 +      int first_vp = mesh.GetNP()+1; // -- to support SALOME sub-meshes
3737 +
3738 +      for (int i = 1; i <= nvertices; i++)
3739 +      {
3740 +         gp_Pnt pnt = BRep_Tool::Pnt (TopoDS::Vertex(geom.vmap(i)));
3741 +         MeshPoint mp( Point<3>(pnt.X(), pnt.Y(), pnt.Z()) );
3742 +
3743 +         bool exists = 0;
3744 +         if (merge_solids)
3745 +            for (PointIndex pi = 1; pi <= mesh.GetNP(); pi++)
3746 +               //if ( Dist2 (mesh[pi], Point<3>(mp)) < eps*eps)              
3747 +               if ( Dist2 (mesh[pi], Point<3>(mp)) < eps2 ) // -- small optimization
3748 +               {
3749 +                  exists = 1;
3750 +                  break;
3751 +               }
3752 +
3753 +               if (!exists)
3754 +                  mesh.AddPoint (mp);
3755 +      }
3756 +
3757 +      (*testout) << "different vertices = " << mesh.GetNP() << std::endl;
3758 +
3759 +
3760 +      int first_ep = mesh.GetNP()+1;
3761 +
3762 +      Array<int> face2solid[2];
3763 +      for (int i = 0; i<2; i++)
3764 +      {
3765 +         face2solid[i].SetSize (geom.fmap.Extent());
3766 +         face2solid[i] = 0;
3767 +      }
3768 +
3769 +      int solidnr = 0;
3770 +      for (TopExp_Explorer exp0(geom.shape, TopAbs_SOLID); exp0.More(); exp0.Next())
3771 +      {
3772 +         solidnr++;
3773 +         for (TopExp_Explorer exp1(exp0.Current(), TopAbs_FACE); exp1.More(); exp1.Next())
3774 +         {
3775 +            TopoDS_Face face = TopoDS::Face(exp1.Current());
3776 +            int facenr = geom.fmap.FindIndex(face);
3777 +            if ( facenr < 1 ) continue; // -- to support SALOME sub-meshes
3778 +
3779 +            if (face2solid[0][facenr-1] == 0)
3780 +               face2solid[0][facenr-1] = solidnr;
3781 +            else
3782 +               face2solid[1][facenr-1] = solidnr;
3783 +         }
3784 +      }
3785 +
3786 +
3787 +      int total = 0;
3788 +      for (int i3 = 1; i3 <= geom.fmap.Extent(); i3++)
3789 +         for (TopExp_Explorer exp2(geom.fmap(i3), TopAbs_WIRE); exp2.More(); exp2.Next())
3790 +            for (TopExp_Explorer exp3(exp2.Current(), TopAbs_EDGE); exp3.More(); exp3.Next())
3791 +               total++;
3792 +
3793 +
3794 +      int facenr = 0;
3795 +      int edgenr = 0;
3796 +
3797 +      edgenr = mesh.GetNSeg(); // to support SALOME sub-meshes
3798 +
3799 +      (*testout) << "faces = " << geom.fmap.Extent() << std::endl;
3800 +      int curr = 0;
3801 +
3802 +      for (int i3 = 1; i3 <= geom.fmap.Extent(); i3++)
3803 +      {
3804 +         TopoDS_Face face = TopoDS::Face(geom.fmap(i3));
3805 +         facenr = geom.fmap.FindIndex (face);       // sollte doch immer == i3 sein ??? JS
3806 +
3807 +         int solidnr0 = face2solid[0][i3-1];
3808 +         int solidnr1 = face2solid[1][i3-1];
3809 +
3810 +         /* auskommentiert am 3.3.05 von robert
3811 +         for (exp2.Init (geom.somap(solidnr0), TopAbs_FACE); exp2.More(); exp2.Next())
3812 +         {
3813 +         TopoDS_Face face2 = TopoDS::Face(exp2.Current());
3814 +         if (geom.fmap.FindIndex(face2) == facenr)
3815 +         {
3816 +         //                  if (face.Orientation() != face2.Orientation()) swap (solidnr0, solidnr1);
3817 +         }
3818 +         }
3819 +         */
3820 +
3821 +         mesh.AddFaceDescriptor (FaceDescriptor(facenr, solidnr0, solidnr1, 0));
3822 +
3823 +         // Philippose - 06/07/2009
3824 +         // Add the face colour to the mesh data
3825 +         Quantity_Color face_colour;
3826 +
3827 +         if(!(geom.face_colours.IsNull())
3828 +            && (geom.face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour)))
3829 +         {
3830 +            mesh.GetFaceDescriptor(facenr).SetSurfColour(Vec3d(face_colour.Red(),face_colour.Green(),face_colour.Blue()));
3831 +         }
3832 +         else
3833 +         {
3834 +            mesh.GetFaceDescriptor(facenr).SetSurfColour(Vec3d(0.0,1.0,0.0));
3835 +         }
3836 +         // ACHTUNG! STIMMT NICHT ALLGEMEIN (RG)
3837 +
3838 +
3839 +         Handle(Geom_Surface) occface = BRep_Tool::Surface(face);
3840 +
3841 +         for (TopExp_Explorer exp2 (face, TopAbs_WIRE); exp2.More(); exp2.Next())
3842 +         {
3843 +            TopoDS_Shape wire = exp2.Current();
3844 +
3845 +            for (TopExp_Explorer exp3 (wire, TopAbs_EDGE); exp3.More(); exp3.Next())
3846 +            {
3847 +               curr++;
3848 +               (*testout) << "edge nr " << curr << std::endl;
3849 +
3850 +               multithread.percent = 100 * curr / double (total);
3851 +               if (multithread.terminate) return;
3852 +
3853 +               TopoDS_Edge edge = TopoDS::Edge (exp3.Current());
3854 +               if (BRep_Tool::Degenerated(edge))
3855 +               {
3856 +                  //(*testout) << "ignoring degenerated edge" << std::endl;
3857 +                  continue;
3858 +               }
3859 +               if ( geom.emap.FindIndex(edge) < 1 ) continue; // to support SALOME sub-meshes
3860 +
3861 +               if (geom.vmap.FindIndex(TopExp::FirstVertex (edge)) ==
3862 +                  geom.vmap.FindIndex(TopExp::LastVertex (edge)))
3863 +               {
3864 +                  GProp_GProps system;
3865 +                  BRepGProp::LinearProperties(edge, system);
3866 +
3867 +                  if (system.Mass() < eps)
3868 +                  {
3869 +                     std::cout << "ignoring edge " << geom.emap.FindIndex (edge)
3870 +                        << ". closed edge with length < " << eps << std::endl;
3871 +                     continue;
3872 +                  }
3873 +               }
3874 +
3875 +
3876 +               Handle(Geom2d_Curve) cof;
3877 +               double s0, s1;
3878 +               cof = BRep_Tool::CurveOnSurface (edge, face, s0, s1);
3879 +
3880 +               int geomedgenr = geom.emap.FindIndex(edge);
3881 +
3882 +               Array <MeshPoint> mp;
3883 +               Array <double> params;
3884 +
3885 +               DivideEdge (edge, mp, params, mesh);
3886
3887 +               Array <int> pnums;
3888 +               pnums.SetSize (mp.Size()+2);
3889 +
3890 +               if (!merge_solids)
3891 +               {
3892 +                 //pnums[0] = geom.vmap.FindIndex (TopExp::FirstVertex (edge));
3893 +                 //pnums[pnums.Size()-1] = geom.vmap.FindIndex (TopExp::LastVertex (edge));
3894 +                 MeshPoint dfltP ( Point<3> ( 0, 0, 0 ) );
3895 +                 int *ipp[] = { &pnums[0], &pnums[pnums.Size()-1] };
3896 +                 TopoDS_Iterator vIt( edge, false );
3897 +                 TopoDS_Vertex v[2];
3898 +                 v[0] = TopoDS::Vertex( vIt.Value() ); vIt.Next();
3899 +                 v[1] = TopoDS::Vertex( vIt.Value() );
3900 +                 if ( v[0].Orientation() == TopAbs_REVERSED )
3901 +                   std::swap( v[0], v[1] );
3902 +                 for ( int i = 0; i < 2; ++i)
3903 +                 {
3904 +                   int &ip = *ipp[i];
3905 +                   ip = geom.vmap.FindIndex ( v[i] );
3906 +                   if ( ip == 0 || ip > nvertices )
3907 +                   {
3908 +                     int iv = ip;
3909 +                     if ( ip == 0 )
3910 +                       ip = iv = geom.vmap.Add( v[i] );
3911 +                     gp_Pnt pnt = BRep_Tool::Pnt( v[i] );
3912 +                     MeshPoint mp( Point<3>(pnt.X(), pnt.Y(), pnt.Z()) );
3913 +                     for (PointIndex pi = 1; pi < first_vp; pi++)
3914 +                       if ( Dist2 (mesh.Point(pi), Point<3>(mp)) < 1e-100 )
3915 +                       {
3916 +                         ip = pi;
3917 +                         if ( mesh.Point(ip).GetLayer() != dfltP.GetLayer() && mesh.Point(ip).GetLayer() != iv )
3918 +                           continue;
3919 +                         if ( mesh.Point(ip).GetLayer() == dfltP.GetLayer())
3920 +                           mesh.Point(ip) = MeshPoint( mesh.Point(ip), iv );
3921 +                         break;
3922 +                       }
3923 +               }
3924 +               else
3925 +               {
3926 +                     ip += first_vp - 1;
3927 +                   }
3928 +                 }
3929 +               }
3930 +               else
3931 +               {
3932 +                 TopoDS_Iterator vIt( edge, false );
3933 +                 TopoDS_Vertex v1 = TopoDS::Vertex( vIt.Value() ); vIt.Next();
3934 +                 TopoDS_Vertex v2 = TopoDS::Vertex( vIt.Value() );
3935 +                 if ( v1.Orientation() == TopAbs_REVERSED )
3936 +                   std::swap( v1, v2 );
3937 +                 const bool isClosedEdge = v1.IsSame( v2 );
3938 +                 
3939 +                  Point<3> fp = occ2ng (BRep_Tool::Pnt (v1));
3940 +                  Point<3> lp = occ2ng (BRep_Tool::Pnt (v2));
3941 +                  double tol2 = min( eps*eps, 1e-6 * Dist2( fp, lp ));
3942 +                  if ( isClosedEdge )
3943 +                    tol2 = BRep_Tool::Tolerance( v1 ) * BRep_Tool::Tolerance( v1 );
3944 +
3945 +                  pnums[0] = -1;
3946 +                  pnums.Last() = -1;
3947 +                  for (PointIndex pi = 1; pi < first_ep; pi++)
3948 +                  {
3949 +                    if (Dist2 (mesh[pi], fp) < tol2) pnums[0] = pi;
3950 +                    if (Dist2 (mesh[pi], lp) < tol2) pnums.Last() = pi;
3951 +                  }
3952 +                  if (( isClosedEdge && pnums[0] != pnums.Last() ) ||
3953 +                      ( !isClosedEdge && pnums[0] == pnums.Last() ))
3954 +                    pnums[0] = pnums.Last() = -1;
3955 +                  if ( pnums[0] == -1 || pnums.Last() == -1 )
3956 +                  {
3957 +                    // take into account a possible large gap between a vertex and an edge curve
3958 +                    // end and a large vertex tolerance covering the whole edge
3959 +                    if ( pnums[0] == -1 )
3960 +                    {
3961 +                      double tol = BRep_Tool::Tolerance( v1 );
3962 +                      for (PointIndex pi = 1; pi < first_ep; pi++)
3963 +                        if (pi != pnums.Last() && Dist2 (mesh[pi], fp) < 2*tol*tol)
3964 +                          pnums[0] = pi;
3965 +
3966 +                      if ( pnums[0] == -1 )
3967 +                        pnums[0] = first_ep-1- nvertices + geom.vmap.FindIndex ( v1 );
3968 +                    }
3969 +                    if ( isClosedEdge )
3970 +                    {
3971 +                      pnums.Last() = pnums[0];
3972 +                    }
3973 +                    else
3974 +                    {
3975 +                      if ( pnums.Last() == -1 )
3976 +                      {
3977 +                        double tol = BRep_Tool::Tolerance( v2 );
3978 +                        for (PointIndex pi = 1; pi < first_ep; pi++)
3979 +                          if (pi != pnums[0] && Dist2 (mesh[pi], lp) < 2*tol*tol)
3980 +                            pnums.Last() = pi;
3981 +
3982 +                        if ( pnums.Last() == -1 )
3983 +                          pnums.Last() = first_ep-1-nvertices + geom.vmap.FindIndex ( v2 );
3984 +                      }
3985 +
3986 +                      if ( Dist2( fp, mesh[PointIndex(pnums[0])]) >
3987 +                           Dist2( lp, mesh[PointIndex(pnums.Last())]))
3988 +                      std::swap( pnums[0], pnums.Last() );
3989 +                    }
3990 +                  }
3991 +               }
3992 +
3993 +
3994 +               for (int i = 1; i <= mp.Size(); i++)
3995 +               {
3996 +                  bool exists = 0;
3997 +                  int j;
3998 +                  for (j = first_ep; j <= mesh.GetNP(); j++)
3999 +                  {
4000 +                     if (!merge_solids && mesh.Point(j).GetLayer() != geomedgenr ) continue; // to support SALOME fuse edges
4001 +                     if ((mesh.Point(j)-Point<3>(mp[i-1])).Length() < eps)
4002 +                     {
4003 +                        exists = 1;
4004 +                        break;
4005 +                     }
4006 +                  }
4007 +
4008 +                     if (exists)
4009 +                        pnums[i] = j;
4010 +                     else
4011 +                     {
4012 +                        mesh.AddPoint (mp[i-1], geomedgenr); // to support SALOME fuse edges
4013 +                        (*testout) << "add meshpoint " << mp[i-1] << std::endl;
4014 +                        pnums[i] = mesh.GetNP();
4015 +                     }
4016 +               }
4017 +               (*testout) << "NP = " << mesh.GetNP() << std::endl;
4018 +
4019 +               //(*testout) << pnums[pnums.Size()-1] << std::endl;
4020 +
4021 +               for (int i = 1; i <= mp.Size()+1; i++)
4022 +               {
4023 +                  edgenr++;
4024 +                  Segment seg;
4025 +
4026 +                  seg[0] = pnums[i-1];
4027 +                  seg[1] = pnums[i];
4028 +                  seg.edgenr = edgenr;
4029 +                  seg.si = facenr;
4030 +                  seg.epgeominfo[0].dist = params[i-1];
4031 +                  seg.epgeominfo[1].dist = params[i];
4032 +                  seg.epgeominfo[0].edgenr = geomedgenr;
4033 +                  seg.epgeominfo[1].edgenr = geomedgenr;
4034 +
4035 +                  gp_Pnt2d p2d;
4036 +                  p2d = cof->Value(params[i-1]);
4037 +                  //                   if (i == 1) p2d = cof->Value(s0);
4038 +                  seg.epgeominfo[0].u = p2d.X();
4039 +                  seg.epgeominfo[0].v = p2d.Y();
4040 +                  p2d = cof->Value(params[i]);
4041 +                  //                   if (i == mp.Size()+1) p2d = cof -> Value(s1);
4042 +                  seg.epgeominfo[1].u = p2d.X();
4043 +                  seg.epgeominfo[1].v = p2d.Y();
4044 +
4045 +                  /*
4046 +                  if (occface->IsUPeriodic())
4047 +                  {
4048 +                  std::cout << "U Periodic" << std::endl;
4049 +                  if (fabs(seg.epgeominfo[1].u-seg.epgeominfo[0].u) >
4050 +                  fabs(seg.epgeominfo[1].u-
4051 +                  (seg.epgeominfo[0].u-occface->UPeriod())))
4052 +                  seg.epgeominfo[0].u = p2d.X()+occface->UPeriod();
4053 +
4054 +                  if (fabs(seg.epgeominfo[1].u-seg.epgeominfo[0].u) >
4055 +                  fabs(seg.epgeominfo[1].u-
4056 +                  (seg.epgeominfo[0].u+occface->UPeriod())))
4057 +                  seg.epgeominfo[0].u = p2d.X()-occface->UPeriod();
4058 +                  }
4059 +
4060 +                  if (occface->IsVPeriodic())
4061 +                  {
4062 +                  std::cout << "V Periodic" << std::endl;
4063 +                  if (fabs(seg.epgeominfo[1].v-seg.epgeominfo[0].v) >
4064 +                  fabs(seg.epgeominfo[1].v-
4065 +                  (seg.epgeominfo[0].v-occface->VPeriod())))
4066 +                  seg.epgeominfo[0].v = p2d.Y()+occface->VPeriod();
4067 +
4068 +                  if (fabs(seg.epgeominfo[1].v-seg.epgeominfo[0].v) >
4069 +                  fabs(seg.epgeominfo[1].v-
4070 +                  (seg.epgeominfo[0].v+occface->VPeriod())))
4071 +                  seg.epgeominfo[0].v = p2d.Y()-occface->VPeriod();
4072 +                  }
4073 +                  */
4074 +
4075 +                  if (edge.Orientation() == TopAbs_REVERSED)
4076 +                  {
4077 +                     swap (seg[0], seg[1]);
4078 +                     swap (seg.epgeominfo[0].dist, seg.epgeominfo[1].dist);
4079 +                     swap (seg.epgeominfo[0].u, seg.epgeominfo[1].u);
4080 +                     swap (seg.epgeominfo[0].v, seg.epgeominfo[1].v);
4081 +                  }
4082 +
4083 +                  mesh.AddSegment (seg);
4084 +
4085 +                  //edgesegments[geomedgenr-1]->Append(mesh.GetNSeg());
4086 +
4087 +               }
4088 +            }
4089 +         }
4090 +      }
4091 +
4092 +      //       for(i=1; i<=mesh.GetNSeg(); i++)
4093 +      //               (*testout) << "edge " << mesh.LineSegment(i).edgenr << " face " << mesh.LineSegment(i).si
4094 +      //                               << " p1 " << mesh.LineSegment(i)[0] << " p2 " << mesh.LineSegment(i)[1] << std::endl;
4095 +      //       exit(10);
4096 +      for (int j = 1; j <= mesh.GetNP(); j++) // to support SALOME fuse edges: set level to zero
4097 +        mesh.Point(j) = MeshPoint( (Point<3>&) mesh.Point(j) );
4098 +
4099 +      mesh.CalcSurfacesOfNode();
4100 +      multithread.task = savetask;
4101 +   }
4102 +
4103 +
4104 +
4105 +
4106 +   void OCCMeshSurface (OCCGeometry & geom, Mesh & mesh, int perfstepsend)
4107 +   {
4108 +      int i, j, k;
4109 +      int changed;
4110 +
4111 +      const char * savetask = multithread.task;
4112 +      multithread.task = "Surface meshing";
4113 +
4114 +      geom.facemeshstatus = 0;
4115 +
4116 +      int noldp = mesh.GetNP();
4117 +
4118 +      double starttime = GetTime();
4119 +
4120 +      Array<int> glob2loc(noldp);
4121 +
4122 +      //int projecttype = PARAMETERSPACE;
4123 +
4124 +      int projecttype = PARAMETERSPACE;
4125 +
4126 +      int notrys = 1;
4127 +
4128 +      int surfmesherror = 0;
4129 +
4130 +      for (k = 1; k <= mesh.GetNFD(); k++)
4131 +      {
4132 +         if(1==0 && !geom.fvispar[k-1].IsDrawable())
4133 +         {
4134 +            (*testout) << "ignoring face " << k << std::endl;
4135 +            std::cout << "ignoring face " << k << std::endl;
4136 +            continue;
4137 +         }
4138 +
4139 +         (*testout) << "mesh face " << k << std::endl;
4140 +         multithread.percent = 100 * k / (mesh.GetNFD() + VSMALL);
4141 +         geom.facemeshstatus[k-1] = -1;
4142 +
4143 +
4144 +         /*
4145 +         if (k != 42)
4146 +         {
4147 +         std::cout << "skipped" << std::endl;
4148 +         continue;
4149 +         }
4150 +         */
4151 +
4152 +
4153 +         FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
4154 +
4155 +         int oldnf = mesh.GetNSE();
4156 +
4157 +         Box<3> bb = geom.GetBoundingBox();
4158 +
4159 +         //      int projecttype = PLANESPACE;
4160 +
4161 +         Meshing2OCCSurfaces meshing(TopoDS::Face(geom.fmap(k)), bb, projecttype);
4162 +
4163 +         if (meshing.GetProjectionType() == PLANESPACE)
4164 +            PrintMessage (2, "Face ", k, " / ", mesh.GetNFD(), " (plane space projection)");
4165 +         else
4166 +            PrintMessage (2, "Face ", k, " / ", mesh.GetNFD(), " (parameter space projection)");
4167 +
4168 +         if (surfmesherror)
4169 +            std::cout << "Surface meshing error occured before (in " << surfmesherror << " faces)" << std::endl;
4170 +
4171 +         //      Meshing2OCCSurfaces meshing(f2, bb);
4172 +         meshing.SetStartTime (starttime);
4173 +
4174 +         //(*testout) << "Face " << k << std::endl << std::endl;
4175 +
4176 +
4177 +         if (meshing.GetProjectionType() == PLANESPACE)
4178 +         {
4179 +            int cntp = 0;
4180 +            glob2loc = 0;
4181 +            for (i = 1; i <= mesh.GetNSeg(); i++)
4182 +            {
4183 +               Segment & seg = mesh.LineSegment(i);
4184 +               if (seg.si == k)
4185 +               {
4186 +                  for (j = 1; j <= 2; j++)
4187 +                  {
4188 +                     int pi = (j == 1) ? seg[0] : seg[1];
4189 +                     if (!glob2loc.Get(pi))
4190 +                     {
4191 +                        meshing.AddPoint (mesh.Point(pi), pi);
4192 +                        cntp++;
4193 +                        glob2loc.Elem(pi) = cntp;
4194 +                     }
4195 +                  }
4196 +               }
4197 +            }
4198 +
4199 +            for (i = 1; i <= mesh.GetNSeg(); i++)
4200 +            {
4201 +               Segment & seg = mesh.LineSegment(i);
4202 +               if (seg.si == k)
4203 +               {
4204 +                  PointGeomInfo gi0, gi1;
4205 +                  gi0.trignum = gi1.trignum = k;
4206 +                  gi0.u = seg.epgeominfo[0].u;
4207 +                  gi0.v = seg.epgeominfo[0].v;
4208 +                  gi1.u = seg.epgeominfo[1].u;
4209 +                  gi1.v = seg.epgeominfo[1].v;
4210 +
4211 +                  meshing.AddBoundaryElement (glob2loc.Get(seg[0]), glob2loc.Get(seg[1]), gi0, gi1);
4212 +                  //(*testout) << gi0.u << " " << gi0.v << std::endl;
4213 +                  //(*testout) << gi1.u << " " << gi1.v << std::endl;
4214 +               }
4215 +            }
4216 +         }
4217 +         else
4218 +         {
4219 +            int cntp = 0;
4220 +
4221 +            for (i = 1; i <= mesh.GetNSeg(); i++)
4222 +               if (mesh.LineSegment(i).si == k)
4223 +                  cntp+=2;
4224 +
4225 +
4226 +            Array< PointGeomInfo > gis;
4227 +
4228 +            gis.SetAllocSize (cntp);
4229 +            gis.SetSize (0);
4230 +
4231 +            for (i = 1; i <= mesh.GetNSeg(); i++)
4232 +            {
4233 +               Segment & seg = mesh.LineSegment(i);
4234 +               if (seg.si == k)
4235 +               {
4236 +                  PointGeomInfo gi0, gi1;
4237 +                  gi0.trignum = gi1.trignum = k;
4238 +                  gi0.u = seg.epgeominfo[0].u;
4239 +                  gi0.v = seg.epgeominfo[0].v;
4240 +                  gi1.u = seg.epgeominfo[1].u;
4241 +                  gi1.v = seg.epgeominfo[1].v;
4242 +
4243 +                  int locpnum[2] = {0, 0};
4244 +
4245 +                  for (j = 0; j < 2; j++)
4246 +                  {
4247 +                     PointGeomInfo gi = (j == 0) ? gi0 : gi1;
4248 +
4249 +                     int l;
4250 +                     for (l = 0; l < gis.Size() && locpnum[j] == 0; l++)
4251 +                     {
4252 +                        double dist = sqr (gis[l].u-gi.u)+sqr(gis[l].v-gi.v);
4253 +
4254 +                        if (dist < 1e-10)
4255 +                           locpnum[j] = l+1;
4256 +                     }
4257 +
4258 +                     if (locpnum[j] == 0)
4259 +                     {
4260 +                        int pi = (j == 0) ? seg[0] : seg[1];
4261 +                        meshing.AddPoint (mesh.Point(pi), pi);
4262 +
4263 +                        gis.SetSize (gis.Size()+1);
4264 +                        gis[l] = gi;
4265 +                        locpnum[j] = l+1;
4266 +                     }
4267 +                  }
4268 +
4269 +                  meshing.AddBoundaryElement (locpnum[0], locpnum[1], gi0, gi1);
4270 +                  //(*testout) << gi0.u << " " << gi0.v << std::endl;
4271 +                  //(*testout) << gi1.u << " " << gi1.v << std::endl;
4272 +
4273 +               }
4274 +            }
4275 +         }
4276 +
4277 +
4278 +
4279 +
4280 +
4281 +         // Philippose - 15/01/2009
4282 +         double maxh = geom.face_maxh[k-1];
4283 +         //double maxh = mparam.maxh;
4284 +         mparam.checkoverlap = 0;
4285 +         //      int noldpoints = mesh->GetNP();
4286 +         int noldsurfel = mesh.GetNSE();
4287 +
4288 +         GProp_GProps sprops;
4289 +         BRepGProp::SurfaceProperties(TopoDS::Face(geom.fmap(k)),sprops);
4290 +         meshing.SetMaxArea(2.*sprops.Mass());
4291 +
4292 +         MESHING2_RESULT res;
4293 +
4294 +         try {
4295 +          res = meshing.GenerateMesh (mesh, mparam, maxh, k);
4296 +         }
4297 +
4298 +         catch (SingularMatrixException)
4299 +         {
4300 +            (*myerr) << "Singular Matrix" << std::endl;
4301 +            res = MESHING2_GIVEUP;
4302 +         }
4303 +
4304 +         catch (UVBoundsException)
4305 +         {
4306 +            (*myerr) << "UV bounds exceeded" << std::endl;
4307 +            res = MESHING2_GIVEUP;
4308 +         }
4309 +
4310 +         projecttype = PARAMETERSPACE;
4311 +
4312 +         if (res != MESHING2_OK)
4313 +         {
4314 +            if (notrys == 1)
4315 +            {
4316 +               for (int i = noldsurfel+1; i <= mesh.GetNSE(); i++)
4317 +                  mesh.DeleteSurfaceElement (i);
4318 +
4319 +               mesh.Compress();
4320 +
4321 +               std::cout << "retry Surface " << k << std::endl;
4322 +
4323 +               k--;
4324 +               projecttype*=-1;
4325 +               notrys++;
4326 +               continue;
4327 +            }
4328 +            else
4329 +            {
4330 +               geom.facemeshstatus[k-1] = -1;
4331 +               PrintError ("Problem in Surface mesh generation");
4332 +               surfmesherror++;
4333 +               //            throw NgException ("Problem in Surface mesh generation");
4334 +            }
4335 +         }
4336 +         else
4337 +         {
4338 +            geom.facemeshstatus[k-1] = 1;
4339 +         }
4340 +
4341 +         notrys = 1;
4342 +
4343 +         for (i = oldnf+1; i <= mesh.GetNSE(); i++)
4344 +            mesh.SurfaceElement(i).SetIndex (k);
4345 +
4346 +      }
4347 +
4348 +//      ofstream problemfile("occmesh.rep");
4349 +
4350 +//      problemfile << "SURFACEMESHING" << std::endl << std::endl;
4351 +
4352 +      if (surfmesherror)
4353 +      {
4354 +         std::cout << "WARNING! NOT ALL FACES HAVE BEEN MESHED" << std::endl;
4355 +         std::cout << "SURFACE MESHING ERROR OCCURED IN " << surfmesherror << " FACES:" << std::endl;
4356 +         for (int i = 1; i <= geom.fmap.Extent(); i++)
4357 +            if (geom.facemeshstatus[i-1] == -1)
4358 +            {
4359 +               std::cout << "Face " << i << std::endl;
4360 +//               problemfile << "problem with face " << i << std::endl;
4361 +//               problemfile << "vertices: " << std::endl;
4362 +               TopExp_Explorer exp0,exp1,exp2;
4363 +               for ( exp0.Init(TopoDS::Face (geom.fmap(i)), TopAbs_WIRE); exp0.More(); exp0.Next() )
4364 +               {
4365 +                  TopoDS_Wire wire = TopoDS::Wire(exp0.Current());
4366 +                  for ( exp1.Init(wire,TopAbs_EDGE); exp1.More(); exp1.Next() )
4367 +                  {
4368 +                     TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
4369 +                     for ( exp2.Init(edge,TopAbs_VERTEX); exp2.More(); exp2.Next() )
4370 +                     {
4371 +                        TopoDS_Vertex vertex = TopoDS::Vertex(exp2.Current());
4372 +                        gp_Pnt point = BRep_Tool::Pnt(vertex);
4373 +//                        problemfile << point.X() << " " << point.Y() << " " << point.Z() << std::endl;
4374 +                     }
4375 +                  }
4376 +               }
4377 +//               problemfile << std::endl;
4378 +
4379 +            }
4380 +            std::cout << std::endl << std::endl;
4381 +            std::cout << "for more information open IGES/STEP Topology Explorer" << std::endl;
4382 +//            problemfile.close();
4383 +            throw NgException ("Problem in Surface mesh generation");
4384 +      }
4385 +      else
4386 +      {
4387 +//         problemfile << "OK" << std::endl << std::endl;
4388 +//         problemfile.close();
4389 +      }
4390 +
4391 +
4392 +
4393 +
4394 +      if (multithread.terminate || perfstepsend < MESHCONST_OPTSURFACE)
4395 +         return;
4396 +
4397 +      multithread.task = "Optimizing surface";
4398 +
4399 +      static int timer_opt2d = NgProfiler::CreateTimer ("Optimization 2D");
4400 +      NgProfiler::StartTimer (timer_opt2d);
4401 +
4402 +      for (k = 1; k <= mesh.GetNFD(); k++)
4403 +      {
4404 +         //      if (k != 42) continue;
4405 +         //      if (k != 36) continue;
4406 +
4407 +         //      (*testout) << "optimize face " << k << std::endl;
4408 +         multithread.percent = 100 * k / (mesh.GetNFD() + VSMALL);
4409 +
4410 +         FaceDescriptor & fd = mesh.GetFaceDescriptor(k);
4411 +
4412 +         PrintMessage (1, "Optimize Surface ", k);
4413 +         for (i = 1; i <= mparam.optsteps2d; i++)
4414 +         {
4415 +            //   (*testout) << "optstep " << i << std::endl;
4416 +            if (multithread.terminate) return;
4417 +
4418 +            {
4419 +               MeshOptimize2dOCCSurfaces meshopt(geom);
4420 +               meshopt.SetFaceIndex (k);
4421 +               meshopt.SetImproveEdges (0);
4422 +               meshopt.SetMetricWeight (mparam.elsizeweight);
4423 +               //meshopt.SetMetricWeight (0.2);
4424 +               meshopt.SetWriteStatus (0);
4425 +
4426 +               //          (*testout) << "EdgeSwapping (mesh, (i > mparam.optsteps2d/2))" << std::endl;
4427 +               meshopt.EdgeSwapping (mesh, (i > mparam.optsteps2d/2));
4428 +            }
4429 +
4430 +            if (multithread.terminate) return;
4431 +            {
4432 +               MeshOptimize2dOCCSurfaces meshopt(geom);
4433 +               meshopt.SetFaceIndex (k);
4434 +               meshopt.SetImproveEdges (0);
4435 +               //meshopt.SetMetricWeight (0.2);
4436 +               meshopt.SetMetricWeight (mparam.elsizeweight);
4437 +               meshopt.SetWriteStatus (0);
4438 +
4439 +               //          (*testout) << "ImproveMesh (mesh)" << std::endl;
4440 +               meshopt.ImproveMesh (mesh, mparam);
4441 +            }
4442 +
4443 +            {
4444 +               MeshOptimize2dOCCSurfaces meshopt(geom);
4445 +               meshopt.SetFaceIndex (k);
4446 +               meshopt.SetImproveEdges (0);
4447 +               //meshopt.SetMetricWeight (0.2);
4448 +               meshopt.SetMetricWeight (mparam.elsizeweight);
4449 +               meshopt.SetWriteStatus (0);
4450 +
4451 +               //          (*testout) << "CombineImprove (mesh)" << std::endl;
4452 +               meshopt.CombineImprove (mesh);
4453 +            }
4454 +
4455 +            if (multithread.terminate) return;
4456 +            {
4457 +               MeshOptimize2dOCCSurfaces meshopt(geom);
4458 +               meshopt.SetFaceIndex (k);
4459 +               meshopt.SetImproveEdges (0);
4460 +               //meshopt.SetMetricWeight (0.2);
4461 +               meshopt.SetMetricWeight (mparam.elsizeweight);
4462 +               meshopt.SetWriteStatus (0);
4463 +
4464 +               //          (*testout) << "ImproveMesh (mesh)" << std::endl;
4465 +               meshopt.ImproveMesh (mesh, mparam);
4466 +            }
4467 +         }
4468 +
4469 +      }
4470 +
4471 +
4472 +      mesh.CalcSurfacesOfNode();
4473 +      mesh.Compress();
4474 +
4475 +      NgProfiler::StopTimer (timer_opt2d);
4476 +
4477 +      multithread.task = savetask;
4478 +   }
4479 +
4480 +
4481 +
4482 +   void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh)
4483 +   {
4484 +      mesh.SetGlobalH (mparam.maxh);
4485 +      mesh.SetMinimalH (mparam.minh);
4486 +
4487 +      Array<double> maxhdom;
4488 +      maxhdom.SetSize (geom.NrSolids());
4489 +      maxhdom = mparam.maxh;
4490 +
4491 +      mesh.SetMaxHDomain (maxhdom);
4492 +
4493 +      Box<3> bb = geom.GetBoundingBox();
4494 +      bb.Increase (bb.Diam()/10);
4495 +
4496 +      mesh.SetLocalH (bb.PMin(), bb.PMax(), 0.5);
4497 +
4498 +      if (mparam.uselocalh)
4499 +      {
4500 +         const char * savetask = multithread.task;
4501 +         multithread.percent = 0;
4502 +
4503 +         mesh.SetLocalH (bb.PMin(), bb.PMax(), mparam.grading);
4504 +
4505 +         int nedges = geom.emap.Extent();
4506 +
4507 +                double mincurvelength = IGNORECURVELENGTH;
4508 +         double maxedgelen = 0;
4509 +         double minedgelen = 1e99;
4510 +
4511 +                if(occparam.resthminedgelenenable) 
4512 +                {
4513 +                       mincurvelength = occparam.resthminedgelen;
4514 +                       if(mincurvelength < IGNORECURVELENGTH) mincurvelength = IGNORECURVELENGTH;
4515 +                }
4516 +
4517 +         multithread.task = "Setting local mesh size (elements per edge)";
4518 +
4519 +         // setting elements per edge
4520 +
4521 +         for (int i = 1; i <= nedges && !multithread.terminate; i++)
4522 +         {
4523 +            TopoDS_Edge e = TopoDS::Edge (geom.emap(i));
4524 +            multithread.percent = 100 * (i-1)/double(nedges);
4525 +            if (BRep_Tool::Degenerated(e)) continue;
4526 +
4527 +            GProp_GProps system;
4528 +            BRepGProp::LinearProperties(e, system);
4529 +            double len = system.Mass();
4530 +
4531 +            if (len < mincurvelength)
4532 +            {
4533 +               (*testout) << "ignored" << std::endl;
4534 +               continue;
4535 +            }
4536 +
4537 +            double localh = len/mparam.segmentsperedge;
4538 +            double s0, s1;
4539 +
4540 +            // Philippose - 23/01/2009
4541 +            // Find all the parent faces of a given edge
4542 +            // and limit the mesh size of the edge based on the
4543 +            // mesh size limit of the face
4544 +            TopTools_IndexedDataMapOfShapeListOfShape edge_face_map;
4545 +            edge_face_map.Clear();
4546 +
4547 +            TopExp::MapShapesAndAncestors(geom.shape, TopAbs_EDGE, TopAbs_FACE, edge_face_map);
4548 +            const TopTools_ListOfShape& parent_faces = edge_face_map.FindFromKey(e);
4549 +
4550 +            TopTools_ListIteratorOfListOfShape parent_face_list;
4551 +
4552 +            for(parent_face_list.Initialize(parent_faces); parent_face_list.More(); parent_face_list.Next())
4553 +            {
4554 +               TopoDS_Face parent_face = TopoDS::Face(parent_face_list.Value());
4555 +
4556 +               int face_index = geom.fmap.FindIndex(parent_face);
4557 +
4558 +               if(face_index >= 1) localh = min(localh,geom.face_maxh[face_index - 1]);
4559 +            }
4560 +
4561 +            Handle(Geom_Curve) c = BRep_Tool::Curve(e, s0, s1);
4562 +
4563 +            maxedgelen = max (maxedgelen, len);
4564 +            minedgelen = min (minedgelen, len);
4565 +
4566 +            // Philippose - 23/01/2009
4567 +            // Modified the calculation of maxj, because the
4568 +            // method used so far always results in maxj = 2,
4569 +            // which causes the localh to be set only at the
4570 +            // starting, mid and end of the edge.
4571 +            // Old Algorithm:
4572 +            // int maxj = 2 * (int) ceil (localh/len);
4573 +            int maxj = max((int) ceil(len/localh), 2);
4574 +
4575 +            for (int j = 0; j <= maxj; j++)
4576 +            {
4577 +               gp_Pnt pnt = c->Value (s0+double(j)/maxj*(s1-s0));
4578 +               mesh.RestrictLocalH (Point3d(pnt.X(), pnt.Y(), pnt.Z()), localh);
4579 +            }
4580 +         }
4581 +
4582 +         multithread.task = "Setting local mesh size (edge curvature)";
4583 +
4584 +         // setting edge curvature
4585 +
4586 +         int nsections = 20;
4587 +
4588 +         for (int i = 1; i <= nedges && !multithread.terminate; i++)
4589 +         {
4590 +            double maxcur = 0;
4591 +            multithread.percent = 100 * (i-1)/double(nedges);
4592 +            TopoDS_Edge edge = TopoDS::Edge (geom.emap(i));
4593 +            if (BRep_Tool::Degenerated(edge)) continue;
4594 +            double s0, s1;
4595 +            Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1);
4596 +            BRepAdaptor_Curve brepc(edge);
4597 +            BRepLProp_CLProps prop(brepc, 2, 1e-5);
4598 +
4599 +            for (int j = 1; j <= nsections; j++)
4600 +            {
4601 +               double s = s0 + j/(double) nsections * (s1-s0);
4602 +               prop.SetParameter (s);
4603 +               double curvature = prop.Curvature();
4604 +               if(curvature> maxcur) maxcur = curvature;
4605 +
4606 +               if (curvature >= 1e99)
4607 +                  continue;
4608 +
4609 +               gp_Pnt pnt = c->Value (s);
4610 +
4611 +               mesh.RestrictLocalH (Point3d(pnt.X(), pnt.Y(), pnt.Z()), ComputeH (fabs(curvature)));
4612 +            }
4613 +            // (*testout) << "edge " << i << " max. curvature: " << maxcur << std::endl;
4614 +         }
4615 +
4616 +         multithread.task = "Setting local mesh size (face curvature)";
4617 +
4618 +         // setting face curvature
4619 +
4620 +         int nfaces = geom.fmap.Extent();
4621 +
4622 +         for (int i = 1; i <= nfaces && !multithread.terminate; i++)
4623 +         {
4624 +            multithread.percent = 100 * (i-1)/double(nfaces);
4625 +            TopoDS_Face face = TopoDS::Face(geom.fmap(i));
4626 +            TopLoc_Location loc;
4627 +            Handle(Geom_Surface) surf = BRep_Tool::Surface (face);
4628 +            Handle(Poly_Triangulation) triangulation = BRep_Tool::Triangulation (face, loc);
4629 +
4630 +            if (triangulation.IsNull()) continue;
4631 +
4632 +            BRepAdaptor_Surface sf(face, Standard_True);
4633 +            BRepLProp_SLProps prop(sf, 2, 1e-5);
4634 +
4635 +            int ntriangles = triangulation -> NbTriangles();
4636 +            for (int j = 1; j <= ntriangles; j++)
4637 +            {
4638 +               gp_Pnt p[3];
4639 +               gp_Pnt2d par[3];
4640 +
4641 +               for (int k = 1; k <=3; k++)
4642 +               {
4643 +                  int n = triangulation->Triangles()(j)(k);
4644 +                  p[k-1] = triangulation->Nodes()(n).Transformed(loc);
4645 +                  par[k-1] = triangulation->UVNodes()(n);
4646 +               }
4647 +
4648 +               //double maxside = 0;
4649 +               //maxside = max (maxside, p[0].Distance(p[1]));
4650 +               //maxside = max (maxside, p[0].Distance(p[2]));
4651 +               //maxside = max (maxside, p[1].Distance(p[2]));
4652 +               //std::cout << "\rFace " << i << " pos11 ntriangles " << ntriangles << " maxside " << maxside << flush;
4653 +
4654 +               RestrictHTriangle (par[0], par[1], par[2], &prop, mesh, 0);
4655 +               //std::cout << "\rFace " << i << " pos12 ntriangles " << ntriangles << flush;
4656 +            }
4657 +         }
4658 +
4659 +         // setting close edges
4660 +
4661 +         if (occparam.resthcloseedgeenable)
4662 +         {
4663 +            multithread.task = "Setting local mesh size (close edges)";
4664 +
4665 +            int sections = 100;
4666 +
4667 +            Array<Line> lines(sections*nedges);
4668 +
4669 +            Box3dTree* searchtree =
4670 +               new Box3dTree (bb.PMin(), bb.PMax());
4671 +
4672 +            int nlines = 0;
4673 +            for (int i = 1; i <= nedges && !multithread.terminate; i++)
4674 +            {
4675 +               TopoDS_Edge edge = TopoDS::Edge (geom.emap(i));
4676 +               if (BRep_Tool::Degenerated(edge)) continue;
4677 +
4678 +               double s0, s1;
4679 +               Handle(Geom_Curve) c = BRep_Tool::Curve(edge, s0, s1);
4680 +               BRepAdaptor_Curve brepc(edge);
4681 +               BRepLProp_CLProps prop(brepc, 1, 1e-5);
4682 +               prop.SetParameter (s0);
4683 +
4684 +               gp_Vec d0 = prop.D1().Normalized();
4685 +               double s_start = s0;
4686 +               int count = 0;
4687 +               for (int j = 1; j <= sections; j++)
4688 +               {
4689 +                  double s = s0 + (s1-s0)*(double)j/(double)sections;
4690 +                  prop.SetParameter (s);
4691 +                  gp_Vec d1 = prop.D1().Normalized();
4692 +                  double cosalpha = fabs(d0*d1);
4693 +                  if ((j == sections) || (cosalpha < cos(10.0/180.0*M_PI)))
4694 +                  {
4695 +                     count++;
4696 +                     gp_Pnt p0 = c->Value (s_start);
4697 +                     gp_Pnt p1 = c->Value (s);
4698 +                     lines[nlines].p0 = Point<3> (p0.X(), p0.Y(), p0.Z());
4699 +                     lines[nlines].p1 = Point<3> (p1.X(), p1.Y(), p1.Z());
4700 +
4701 +                     Box3d box;
4702 +                     box.SetPoint (Point3d(lines[nlines].p0));
4703 +                     box.AddPoint (Point3d(lines[nlines].p1));
4704 +
4705 +                     searchtree->Insert (box.PMin(), box.PMax(), nlines+1);
4706 +                     nlines++;
4707 +
4708 +                     s_start = s;
4709 +                     d0 = d1;
4710 +                  }
4711 +               }
4712 +            }
4713 +
4714 +            Array<int> linenums;
4715 +
4716 +            for (int i = 0; i < nlines; i++)
4717 +            {
4718 +               multithread.percent = (100*i)/double(nlines);
4719 +               Line & line = lines[i];
4720 +
4721 +               Box3d box;
4722 +               box.SetPoint (Point3d(line.p0));
4723 +               box.AddPoint (Point3d(line.p1));
4724 +               double maxhline = max (mesh.GetH(box.PMin()),
4725 +                  mesh.GetH(box.PMax()));
4726 +               box.Increase(maxhline);
4727 +
4728 +               double mindist = 1e99;
4729 +               linenums.SetSize(0);
4730 +               searchtree->GetIntersecting(box.PMin(),box.PMax(),linenums);
4731 +
4732 +               for (int j = 0; j < linenums.Size(); j++)
4733 +               {
4734 +                  int num = linenums[j]-1;
4735 +                  if (i == num) continue;
4736 +                  if ((line.p0-lines[num].p0).Length2() < 1e-15) continue;
4737 +                  if ((line.p0-lines[num].p1).Length2() < 1e-15) continue;
4738 +                  if ((line.p1-lines[num].p0).Length2() < 1e-15) continue;
4739 +                  if ((line.p1-lines[num].p1).Length2() < 1e-15) continue;
4740 +                  mindist = min (mindist, line.Dist(lines[num]));
4741 +               }
4742 +
4743 +               mindist /= (occparam.resthcloseedgefac + VSMALL);
4744 +
4745 +               if (mindist < 1e-3)
4746 +               {
4747 +                  (*testout) << "extremely small local h: " << mindist
4748 +                     << " --> setting to 1e-3" << std::endl;
4749 +                  (*testout) << "somewhere near " << line.p0 << " - " << line.p1 << std::endl;
4750 +                  mindist = 1e-3;
4751 +               }
4752 +
4753 +               mesh.RestrictLocalHLine(line.p0, line.p1, mindist);
4754 +            }
4755 +         }
4756 +
4757 +         multithread.task = savetask;
4758 +
4759 +      }
4760 +
4761 +      // Philippose - 09/03/2009
4762 +      // Added the capability to load the mesh size from a 
4763 +      // file also for OpenCascade Geometry
4764 +      // Note: 
4765 +      // ** If the "uselocalh" option is ticked in 
4766 +      // the "mesh options...insider" menu, the mesh 
4767 +      // size will be further modified by the topology 
4768 +      // analysis routines.
4769 +      // ** To use the mesh size file as the sole source 
4770 +      // for defining the mesh size, uncheck the "uselocalh"
4771 +      // option.
4772 +      mesh.LoadLocalMeshSize (mparam.meshsizefilename);
4773 +   }
4774 +
4775 +
4776 +
4777 +  int OCCGenerateMesh (OCCGeometry & geom, Mesh *& mesh, MeshingParameters & mparam,
4778 +                      int perfstepsstart, int perfstepsend)
4779 +   {
4780 +      multithread.percent = 0;
4781 +
4782 +      if (perfstepsstart <= MESHCONST_ANALYSE)
4783 +      {
4784 +         delete mesh;
4785 +         mesh = new Mesh();
4786 +         mesh->geomtype = Mesh::GEOM_OCC;
4787 +
4788 +         OCCSetLocalMeshSize(geom,*mesh);
4789 +      }
4790 +
4791 +      if (multithread.terminate || perfstepsend <= MESHCONST_ANALYSE)
4792 +         return TCL_OK;
4793 +
4794 +      if (perfstepsstart <= MESHCONST_MESHEDGES)
4795 +      {
4796 +         OCCFindEdges (geom, *mesh);
4797 +
4798 +         /*
4799 +         std::cout << "Removing redundant points" << std::endl;
4800 +
4801 +         int i, j;
4802 +         int np = mesh->GetNP();
4803 +         Array<int> equalto;
4804 +
4805 +         equalto.SetSize (np);
4806 +         equalto = 0;
4807 +
4808 +         for (i = 1; i <= np; i++)
4809 +         {
4810 +         for (j = i+1; j <= np; j++)
4811 +         {
4812 +         if (!equalto[j-1] && (Dist2 (mesh->Point(i), mesh->Point(j)) < 1e-12))
4813 +         equalto[j-1] = i;
4814 +         }
4815 +         }
4816 +
4817 +         for (i = 1; i <= np; i++)
4818 +         if (equalto[i-1])
4819 +         {
4820 +         std::cout << "Point " << i << " is equal to Point " << equalto[i-1] << std::endl;
4821 +         for (j = 1; j <= mesh->GetNSeg(); j++)
4822 +         {
4823 +         Segment & seg = mesh->LineSegment(j);
4824 +         if (seg[0] == i) seg[0] = equalto[i-1];
4825 +         if (seg[1] == i) seg[1] = equalto[i-1];
4826 +         }
4827 +         }
4828 +
4829 +         std::cout << "Removing degenerated segments" << std::endl;
4830 +         for (j = 1; j <= mesh->GetNSeg(); j++)
4831 +         {
4832 +         Segment & seg = mesh->LineSegment(j);
4833 +         if (seg[0] == seg[1])
4834 +         {
4835 +         mesh->DeleteSegment(j);
4836 +         std::cout << "Deleting Segment " << j << std::endl;
4837 +         }
4838 +         }
4839 +
4840 +         mesh->Compress();
4841 +         */
4842 +
4843 +         /*
4844 +         for (int i = 1; i <= geom.fmap.Extent(); i++)
4845 +         {
4846 +         Handle(Geom_Surface) hf1 =
4847 +         BRep_Tool::Surface(TopoDS::Face(geom.fmap(i)));
4848 +         for (int j = i+1; j <= geom.fmap.Extent(); j++)
4849 +         {
4850 +         Handle(Geom_Surface) hf2 =
4851 +         BRep_Tool::Surface(TopoDS::Face(geom.fmap(j)));
4852 +         if (hf1 == hf2) std::cout << "face " << i << " and face " << j << " lie on same surface" << std::endl;
4853 +         }
4854 +         }
4855 +         */
4856 +
4857 +#ifdef LOG_STREAM
4858 +         (*logout) << "Edges meshed" << std::endl
4859 +            << "time = " << GetTime() << " sec" << std::endl
4860 +            << "points: " << mesh->GetNP() << std::endl;
4861 +#endif
4862 +      }
4863 +
4864 +      if (multithread.terminate || perfstepsend <= MESHCONST_MESHEDGES)
4865 +         return TCL_OK;
4866 +
4867 +      if (perfstepsstart <= MESHCONST_MESHSURFACE)
4868 +      {
4869 +         OCCMeshSurface (geom, *mesh, perfstepsend);
4870 +         if (multithread.terminate) return TCL_OK;
4871 +
4872 +#ifdef LOG_STREAM
4873 +         (*logout) << "Surfaces meshed" << std::endl
4874 +            << "time = " << GetTime() << " sec" << std::endl
4875 +            << "points: " << mesh->GetNP() << std::endl;
4876 +#endif
4877 +
4878 +#ifdef STAT_STREAM
4879 +         (*statout) << mesh->GetNSeg() << " & "
4880 +            << mesh->GetNSE() << " & - &"
4881 +            << GetTime() << " & " << std::endl;
4882 +#endif
4883 +
4884 +         //      MeshQuality2d (*mesh);
4885 +         mesh->CalcSurfacesOfNode();
4886 +      }
4887 +
4888 +      if (multithread.terminate || perfstepsend <= MESHCONST_OPTSURFACE)
4889 +         return TCL_OK;
4890 +
4891 +      if (perfstepsstart <= MESHCONST_MESHVOLUME)
4892 +      {
4893 +         multithread.task = "Volume meshing";
4894 +
4895 +         MESHING3_RESULT res = MeshVolume (mparam, *mesh);
4896 +
4897 +/*
4898 +         ofstream problemfile("occmesh.rep",ios_base::app);
4899 +
4900 +         problemfile << "VOLUMEMESHING" << std::endl << std::endl;
4901 +         if(res != MESHING3_OK)
4902 +            problemfile << "ERROR" << std::endl << std::endl;
4903 +         else
4904 +            problemfile << "OK" << std::endl
4905 +            << mesh->GetNE() << " elements" << std::endl << std::endl;
4906 +
4907 +         problemfile.close();
4908 +*/
4909 +
4910 +         if (res != MESHING3_OK) return TCL_ERROR;
4911 +
4912 +         if (multithread.terminate) return TCL_OK;
4913 +
4914 +         RemoveIllegalElements (*mesh);
4915 +         if (multithread.terminate) return TCL_OK;
4916 +
4917 +         MeshQuality3d (*mesh);
4918 +
4919 +#ifdef STAT_STREAM
4920 +         (*statout) << GetTime() << " & ";
4921 +#endif
4922 +
4923 +#ifdef LOG_STREAM
4924 +         (*logout) << "Volume meshed" << std::endl
4925 +            << "time = " << GetTime() << " sec" << std::endl
4926 +            << "points: " << mesh->GetNP() << std::endl;
4927 +#endif
4928 +      }
4929 +
4930 +      if (multithread.terminate || perfstepsend <= MESHCONST_MESHVOLUME)
4931 +         return TCL_OK;
4932 +
4933 +      if (perfstepsstart <= MESHCONST_OPTVOLUME)
4934 +      {
4935 +         multithread.task = "Volume optimization";
4936 +
4937 +         OptimizeVolume (mparam, *mesh);
4938 +         if (multithread.terminate) return TCL_OK;
4939 +
4940 +#ifdef STAT_STREAM
4941 +         (*statout) << GetTime() << " & "
4942 +            << mesh->GetNE() << " & "
4943 +            << mesh->GetNP() << " " << '\\' << '\\' << " \\" << "hline" << std::endl;
4944 +#endif
4945 +
4946 +#ifdef LOG_STREAM
4947 +         (*logout) << "Volume optimized" << std::endl
4948 +            << "time = " << GetTime() << " sec" << std::endl
4949 +            << "points: " << mesh->GetNP() << std::endl;
4950 +#endif
4951 +
4952 +         // std::cout << "Optimization complete" << std::endl;
4953 +
4954 +      }
4955 +
4956 +      (*testout) << "NP: " << mesh->GetNP() << std::endl;
4957 +      for (int i = 1; i <= mesh->GetNP(); i++)
4958 +         (*testout) << mesh->Point(i) << std::endl;
4959 +
4960 +      (*testout) << std::endl << "NSegments: " << mesh->GetNSeg() << std::endl;
4961 +      for (int i = 1; i <= mesh->GetNSeg(); i++)
4962 +         (*testout) << mesh->LineSegment(i) << std::endl;
4963 +
4964 +      return TCL_OK;
4965 +   }
4966 +}
4967 +
4968 +#endif
4969 --- netgen_ref/libsrc/occ/occgeom.cpp
4970 +++ netgen/libsrc/occ/occgeom.cpp
4971 @@ -1,1612 +1,1669 @@
4972 -
4973 -#ifdef OCCGEOMETRY
4974 -
4975 -#include <mystdlib.h>
4976 -#include <occgeom.hpp>
4977 -#include "ShapeAnalysis_ShapeTolerance.hxx"
4978 -#include "ShapeAnalysis_ShapeContents.hxx"
4979 -#include "ShapeAnalysis_CheckSmallFace.hxx"
4980 -#include "ShapeAnalysis_DataMapOfShapeListOfReal.hxx"
4981 -#include "ShapeAnalysis_Surface.hxx"
4982 -#include "BRepAlgoAPI_Fuse.hxx"
4983 -#include "BRepCheck_Analyzer.hxx"
4984 -#include "BRepLib.hxx"
4985 -#include "ShapeBuild_ReShape.hxx"
4986 -#include "ShapeFix.hxx"
4987 -#include "ShapeFix_FixSmallFace.hxx"
4988 -#include "Partition_Spliter.hxx"
4989 -
4990 -
4991 -namespace netgen
4992 -{
4993 -   void OCCGeometry :: PrintNrShapes ()
4994 -   {
4995 -      TopExp_Explorer e;
4996 -      int count = 0;
4997 -      for (e.Init(shape, TopAbs_COMPSOLID); e.More(); e.Next()) count++;
4998 -      cout << "CompSolids: " << count << endl;
4999 -
5000 -      cout << "Solids    : " << somap.Extent() << endl;
5001 -      cout << "Shells    : " << shmap.Extent() << endl;
5002 -      cout << "Faces     : " << fmap.Extent() << endl;
5003 -      cout << "Edges     : " << emap.Extent() << endl;
5004 -      cout << "Vertices  : " << vmap.Extent() << endl;
5005 -   }
5006 -
5007 -
5008 -
5009 -
5010 -   void PrintContents (OCCGeometry * geom)
5011 -   {
5012 -      ShapeAnalysis_ShapeContents cont;
5013 -      cont.Clear();
5014 -      cont.Perform(geom->shape);
5015 -
5016 -      (*testout) << "OCC CONTENTS" << endl;
5017 -      (*testout) << "============" << endl;
5018 -      (*testout) << "SOLIDS   : " << cont.NbSolids() << endl;
5019 -      (*testout) << "SHELLS   : " << cont.NbShells() << endl;
5020 -      (*testout) << "FACES    : " << cont.NbFaces() << endl;
5021 -      (*testout) << "WIRES    : " << cont.NbWires() << endl;
5022 -      (*testout) << "EDGES    : " << cont.NbEdges() << endl;
5023 -      (*testout) << "VERTICES : " << cont.NbVertices() << endl;
5024 -
5025 -      TopExp_Explorer e;
5026 -      int count = 0;
5027 -      for (e.Init(geom->shape, TopAbs_COMPOUND); e.More(); e.Next())
5028 -         count++;
5029 -      (*testout) << "Compounds: " << count << endl;
5030 -
5031 -      count = 0;
5032 -      for (e.Init(geom->shape, TopAbs_COMPSOLID); e.More(); e.Next())
5033 -         count++;
5034 -      (*testout) << "CompSolids: " << count << endl;
5035 -
5036 -      (*testout) << endl;
5037 -
5038 -      cout << "Highest entry in topology hierarchy: " << endl;
5039 -      if (count)
5040 -         cout << count << " composite solid(s)" << endl;
5041 -      else
5042 -         if (geom->somap.Extent())
5043 -            cout << geom->somap.Extent() << " solid(s)" << endl;
5044 -         else
5045 -            if (geom->shmap.Extent())
5046 -               cout << geom->shmap.Extent() << " shells(s)" << endl;
5047 -            else
5048 -               if (geom->fmap.Extent())
5049 -                  cout << geom->fmap.Extent() << " face(s)" << endl;
5050 -               else
5051 -                  if (geom->wmap.Extent())
5052 -                     cout << geom->wmap.Extent() << " wire(s)" << endl;
5053 -                  else
5054 -                     if (geom->emap.Extent())
5055 -                        cout << geom->emap.Extent() << " edge(s)" << endl;
5056 -                     else
5057 -                        if (geom->vmap.Extent())
5058 -                           cout << geom->vmap.Extent() << " vertices(s)" << endl;
5059 -                        else
5060 -                           cout << "no entities" << endl;
5061 -
5062 -   }
5063 -
5064 -
5065 -
5066 -   void OCCGeometry :: HealGeometry ()
5067 -   {
5068 -      int nrc = 0, nrcs = 0,
5069 -         nrso = somap.Extent(),
5070 -         nrsh = shmap.Extent(),
5071 -         nrf = fmap.Extent(),
5072 -         nrw = wmap.Extent(),
5073 -         nre = emap.Extent(),
5074 -         nrv = vmap.Extent();
5075 -
5076 -      TopExp_Explorer exp0;
5077 -      TopExp_Explorer exp1;
5078 -
5079 -
5080 -      for (exp0.Init(shape, TopAbs_COMPOUND); exp0.More(); exp0.Next()) nrc++;
5081 -      for (exp0.Init(shape, TopAbs_COMPSOLID); exp0.More(); exp0.Next()) nrcs++;
5082 -
5083 -      double surfacecont = 0;
5084 -
5085 -      {
5086 -         Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;
5087 -         rebuild->Apply(shape);
5088 -         for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
5089 -         {
5090 -            TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
5091 -            if ( BRep_Tool::Degenerated(edge) )
5092 -               rebuild->Remove(edge, false);
5093 -         }
5094 -         shape = rebuild->Apply(shape);
5095 -      }
5096 -
5097 -      BuildFMap();
5098 -
5099 -
5100 -      for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next())
5101 -      {
5102 -         TopoDS_Face face = TopoDS::Face(exp0.Current());
5103 -
5104 -         GProp_GProps system;
5105 -         BRepGProp::SurfaceProperties(face, system);
5106 -         surfacecont += system.Mass();
5107 -      }
5108 -
5109 -
5110 -      cout << "Starting geometry healing procedure (tolerance: " << tolerance << ")" << endl
5111 -         << "-----------------------------------" << endl;
5112 -
5113 -      {
5114 -         cout << endl << "- repairing faces" << endl;
5115 -
5116 -         Handle(ShapeFix_Face) sff;
5117 -         Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;
5118 -         rebuild->Apply(shape);
5119 -
5120 -
5121 -         for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next())
5122 -         {
5123 -            // Variable to hold the colour (if there exists one) of 
5124 -            // the current face being processed
5125 -            Quantity_Color face_colour;
5126 -
5127 -            TopoDS_Face face = TopoDS::Face (exp0.Current());
5128 -
5129 -            if(face_colours.IsNull()
5130 -               || (!(face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour))))
5131 -            {
5132 -               // Set the default face colour to green (Netgen Standard)
5133 -               // if no colour has been defined for the face
5134 -               face_colour = Quantity_Color(0.0,1.0,0.0,Quantity_TOC_RGB);
5135 -            }
5136 -
5137 -            sff = new ShapeFix_Face (face);
5138 -            sff->FixAddNaturalBoundMode() = Standard_True;
5139 -            sff->FixSmallAreaWireMode() = Standard_True;
5140 -            sff->Perform();
5141 -
5142 -            if(sff->Status(ShapeExtend_DONE1) ||
5143 -               sff->Status(ShapeExtend_DONE2) ||
5144 -               sff->Status(ShapeExtend_DONE3) ||
5145 -               sff->Status(ShapeExtend_DONE4) ||
5146 -               sff->Status(ShapeExtend_DONE5))
5147 -            {
5148 -               cout << "repaired face " << fmap.FindIndex(face) << " ";
5149 -               if(sff->Status(ShapeExtend_DONE1))
5150 -                  cout << "(some wires are fixed)" <<endl;
5151 -               else if(sff->Status(ShapeExtend_DONE2))
5152 -                  cout << "(orientation of wires fixed)" <<endl;
5153 -               else if(sff->Status(ShapeExtend_DONE3))
5154 -                  cout << "(missing seam added)" <<endl;
5155 -               else if(sff->Status(ShapeExtend_DONE4))
5156 -                  cout << "(small area wire removed)" <<endl;
5157 -               else if(sff->Status(ShapeExtend_DONE5))
5158 -                  cout << "(natural bounds added)" <<endl;
5159 -               TopoDS_Face newface = sff->Face();
5160 -
5161 -               rebuild->Replace(face, newface, Standard_False);
5162 -            }
5163 -
5164 -            // Set the original colour of the face to the newly created 
5165 -            // face (after the healing process)
5166 -            face = TopoDS::Face (exp0.Current());
5167 -            face_colours->SetColor(face,face_colour,XCAFDoc_ColorSurf);
5168 -         }
5169 -         shape = rebuild->Apply(shape);
5170 -      }
5171 -
5172 -
5173 -      {
5174 -         Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;
5175 -         rebuild->Apply(shape);
5176 -         for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
5177 -         {
5178 -            TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
5179 -            if ( BRep_Tool::Degenerated(edge) )
5180 -               rebuild->Remove(edge, false);
5181 -         }
5182 -         shape = rebuild->Apply(shape);
5183 -      }
5184 -
5185 -
5186 -      if (fixsmalledges)
5187 -      {
5188 -         cout << endl << "- fixing small edges" << endl;
5189 -
5190 -         Handle(ShapeFix_Wire) sfw;
5191 -         Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;
5192 -         rebuild->Apply(shape);
5193 -
5194 -
5195 -         for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next())
5196 -         {
5197 -            TopoDS_Face face = TopoDS::Face(exp0.Current());
5198 -
5199 -            for (exp1.Init (face, TopAbs_WIRE); exp1.More(); exp1.Next())
5200 -            {
5201 -               TopoDS_Wire oldwire = TopoDS::Wire(exp1.Current());
5202 -               sfw = new ShapeFix_Wire (oldwire, face ,tolerance);
5203 -               sfw->ModifyTopologyMode() = Standard_True;
5204 -
5205 -               sfw->ClosedWireMode() = Standard_True;
5206 -
5207 -               bool replace = false;
5208 -
5209 -               replace = sfw->FixReorder() || replace;
5210 -
5211 -               replace = sfw->FixConnected() || replace;
5212 -
5213 -
5214 -
5215 -               if (sfw->FixSmall (Standard_False, tolerance) && ! (sfw->StatusSmall(ShapeExtend_FAIL1) ||
5216 -                  sfw->StatusSmall(ShapeExtend_FAIL2) ||
5217 -                  sfw->StatusSmall(ShapeExtend_FAIL3)))
5218 -               {
5219 -                  cout << "Fixed small edge in wire " << wmap.FindIndex (oldwire) << endl;
5220 -                  replace = true;
5221 -
5222 -               }
5223 -               else if (sfw->StatusSmall(ShapeExtend_FAIL1))
5224 -                  cerr << "Failed to fix small edge in wire " << wmap.FindIndex (oldwire)
5225 -                  << ", edge cannot be checked (no 3d curve and no pcurve)" << endl;
5226 -               else if (sfw->StatusSmall(ShapeExtend_FAIL2))
5227 -                  cerr << "Failed to fix small edge in wire " << wmap.FindIndex (oldwire)
5228 -                  << ", edge is null-length and has different vertives at begin and end, and lockvtx is True or ModifiyTopologyMode is False" << endl;
5229 -               else if (sfw->StatusSmall(ShapeExtend_FAIL3))
5230 -                  cerr << "Failed to fix small edge in wire " << wmap.FindIndex (oldwire)
5231 -                  << ", CheckConnected has failed" << endl;
5232 -
5233 -               replace = sfw->FixEdgeCurves() || replace;
5234 -
5235 -               replace = sfw->FixDegenerated() || replace;
5236 -
5237 -               replace = sfw->FixSelfIntersection() || replace;
5238 -
5239 -               replace = sfw->FixLacking(Standard_True) || replace;
5240 -
5241 -               if(replace)
5242 -               {
5243 -                  TopoDS_Wire newwire = sfw->Wire();
5244 -                  rebuild->Replace(oldwire, newwire, Standard_False);
5245 -               }
5246 -
5247 -               //delete sfw; sfw = NULL;
5248 -
5249 -            }
5250 -         }
5251 -
5252 -         shape = rebuild->Apply(shape);
5253 -
5254 -
5255 -
5256 -         {
5257 -            BuildFMap();
5258 -            Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;
5259 -            rebuild->Apply(shape);
5260 -
5261 -            for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
5262 -            {
5263 -               TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
5264 -               if (vmap.FindIndex(TopExp::FirstVertex (edge)) ==
5265 -                  vmap.FindIndex(TopExp::LastVertex (edge)))
5266 -               {
5267 -                  GProp_GProps system;
5268 -                  BRepGProp::LinearProperties(edge, system);
5269 -                  if (system.Mass() < tolerance)
5270 -                  {
5271 -                     cout << "removing degenerated edge " << emap.FindIndex(edge)
5272 -                        << " from vertex " << vmap.FindIndex(TopExp::FirstVertex (edge))
5273 -                        << " to vertex " << vmap.FindIndex(TopExp::LastVertex (edge)) << endl;
5274 -                     rebuild->Remove(edge, false);
5275 -                  }
5276 -               }
5277 -            }
5278 -            shape = rebuild->Apply(shape);
5279 -
5280 -            //delete rebuild; rebuild = NULL;
5281 -         }
5282 -
5283 -
5284 -
5285 -         {
5286 -            Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;
5287 -            rebuild->Apply(shape);
5288 -            for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
5289 -            {
5290 -               TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
5291 -               if ( BRep_Tool::Degenerated(edge) )
5292 -                  rebuild->Remove(edge, false);
5293 -            }
5294 -            shape = rebuild->Apply(shape);
5295 -         }
5296 -
5297 -
5298 -
5299 -
5300 -         Handle(ShapeFix_Wireframe) sfwf = new ShapeFix_Wireframe;
5301 -         sfwf->SetPrecision(tolerance);
5302 -         sfwf->Load (shape);
5303 -         sfwf->ModeDropSmallEdges() = Standard_True;
5304 -
5305 -         sfwf->SetPrecision(boundingbox.Diam());
5306 -
5307 -         if (sfwf->FixWireGaps())
5308 -         {
5309 -            cout << endl << "- fixing wire gaps" << endl;
5310 -            if (sfwf->StatusWireGaps(ShapeExtend_OK)) cout << "no gaps found" << endl;
5311 -            if (sfwf->StatusWireGaps(ShapeExtend_DONE1)) cout << "some 2D gaps fixed" << endl;
5312 -            if (sfwf->StatusWireGaps(ShapeExtend_DONE2)) cout << "some 3D gaps fixed" << endl;
5313 -            if (sfwf->StatusWireGaps(ShapeExtend_FAIL1)) cout << "failed to fix some 2D gaps" << endl;
5314 -            if (sfwf->StatusWireGaps(ShapeExtend_FAIL2)) cout << "failed to fix some 3D gaps" << endl;
5315 -         }
5316 -
5317 -         sfwf->SetPrecision(tolerance);
5318 -
5319 -
5320 -         {
5321 -            for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
5322 -            {
5323 -               TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
5324 -               if ( BRep_Tool::Degenerated(edge) )
5325 -                  cout << "degenerated edge at position 4" << endl;
5326 -            }
5327 -         }
5328 -
5329 -
5330 -
5331 -         if (sfwf->FixSmallEdges())
5332 -         {
5333 -            cout << endl << "- fixing wire frames" << endl;
5334 -            if (sfwf->StatusSmallEdges(ShapeExtend_OK)) cout << "no small edges found" << endl;
5335 -            if (sfwf->StatusSmallEdges(ShapeExtend_DONE1)) cout << "some small edges fixed" << endl;
5336 -            if (sfwf->StatusSmallEdges(ShapeExtend_FAIL1)) cout << "failed to fix some small edges" << endl;
5337 -         }
5338 -
5339 -
5340 -
5341 -         shape = sfwf->Shape();
5342 -
5343 -         //delete sfwf; sfwf = NULL;
5344 -         //delete rebuild; rebuild = NULL;
5345 -
5346 -      }
5347 -
5348 -
5349 -
5350 -
5351 -
5352 -      {
5353 -         for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
5354 -         {
5355 -            TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
5356 -            if ( BRep_Tool::Degenerated(edge) )
5357 -               cout << "degenerated edge at position 5" << endl;
5358 -         }
5359 -      }
5360 -
5361 -
5362 -
5363 -
5364 -      if (fixspotstripfaces)
5365 -      {
5366 -
5367 -         cout << endl << "- fixing spot and strip faces" << endl;
5368 -         Handle(ShapeFix_FixSmallFace) sffsm = new ShapeFix_FixSmallFace();
5369 -         sffsm -> Init (shape);
5370 -         sffsm -> SetPrecision (tolerance);
5371 -         sffsm -> Perform();
5372 -
5373 -         shape = sffsm -> FixShape();
5374 -         //delete sffsm; sffsm = NULL;
5375 -      }
5376 -
5377 -
5378 -      {
5379 -         for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
5380 -         {
5381 -            TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
5382 -            if ( BRep_Tool::Degenerated(edge) )
5383 -               cout << "degenerated edge at position 6" << endl;
5384 -         }
5385 -      }
5386 -
5387 -
5388 -
5389 -      if (sewfaces)
5390 -      {
5391 -         cout << endl << "- sewing faces" << endl;
5392 -
5393 -         BRepOffsetAPI_Sewing sewedObj(tolerance);
5394 -
5395 -         for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next())
5396 -         {
5397 -            TopoDS_Face face = TopoDS::Face (exp0.Current());
5398 -            sewedObj.Add (face);
5399 -         }
5400 -
5401 -         sewedObj.Perform();
5402 -
5403 -         if (!sewedObj.SewedShape().IsNull())
5404 -            shape = sewedObj.SewedShape();
5405 -         else
5406 -            cout << " not possible";
5407 -      }
5408 -
5409 -
5410 -
5411 -      {
5412 -         Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;
5413 -         rebuild->Apply(shape);
5414 -         for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
5415 -         {
5416 -            TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
5417 -            if ( BRep_Tool::Degenerated(edge) )
5418 -               rebuild->Remove(edge, false);
5419 -         }
5420 -         shape = rebuild->Apply(shape);
5421 -      }
5422 -
5423 -
5424 -      if (makesolids)
5425 -      {
5426 -         cout << endl << "- making solids" << endl;
5427 -
5428 -         BRepBuilderAPI_MakeSolid ms;
5429 -         int count = 0;
5430 -         for (exp0.Init(shape, TopAbs_SHELL); exp0.More(); exp0.Next())
5431 -         {
5432 -            count++;
5433 -            ms.Add (TopoDS::Shell(exp0.Current()));
5434 -         }
5435 -
5436 -         if (!count)
5437 -         {
5438 -            cout << " not possible (no shells)" << endl;
5439 -         }
5440 -         else
5441 -         {
5442 -            BRepCheck_Analyzer ba(ms);
5443 -            if (ba.IsValid ())
5444 -            {
5445 -               Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
5446 -               sfs->Init (ms);
5447 -               sfs->SetPrecision(tolerance);
5448 -               sfs->SetMaxTolerance(tolerance);
5449 -               sfs->Perform();
5450 -               shape = sfs->Shape();
5451 -
5452 -               for (exp0.Init(shape, TopAbs_SOLID); exp0.More(); exp0.Next())
5453 -               {
5454 -                  TopoDS_Solid solid = TopoDS::Solid(exp0.Current());
5455 -                  TopoDS_Solid newsolid = solid;
5456 -                  BRepLib::OrientClosedSolid (newsolid);
5457 -                  Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;
5458 -                  //             rebuild->Apply(shape);
5459 -                  rebuild->Replace(solid, newsolid, Standard_False);
5460 -                  TopoDS_Shape newshape = rebuild->Apply(shape, TopAbs_COMPSOLID);//, 1);
5461 -                  //             TopoDS_Shape newshape = rebuild->Apply(shape);
5462 -                  shape = newshape;
5463 -               }
5464 -
5465 -               //delete sfs; sfs = NULL;
5466 -            }
5467 -            else
5468 -               cout << " not possible" << endl;
5469 -         }
5470 -      }
5471 -
5472 -
5473 -
5474 -      if (splitpartitions)
5475 -      {
5476 -         cout << "- running SALOME partition splitter" << endl;
5477 -
5478 -         TopExp_Explorer e2;
5479 -         Partition_Spliter ps;
5480 -         int count = 0;
5481 -
5482 -         for (e2.Init (shape, TopAbs_SOLID);
5483 -            e2.More(); e2.Next())
5484 -         {
5485 -            count++;
5486 -            ps.AddShape (e2.Current());
5487 -         }
5488 -
5489 -         ps.Compute();
5490 -         shape = ps.Shape();
5491 -
5492 -         cout << " before: " << count << " solids" << endl;
5493 -
5494 -         count = 0;
5495 -         for (e2.Init (shape, TopAbs_SOLID);
5496 -            e2.More(); e2.Next()) count++;
5497 -
5498 -            cout << " after : " << count << " solids" << endl;
5499 -      }
5500 -
5501 -      BuildFMap();
5502 -
5503 -
5504 -
5505 -      {
5506 -         for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
5507 -         {
5508 -            TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
5509 -            if ( BRep_Tool::Degenerated(edge) )
5510 -               cout << "degenerated edge at position 8" << endl;
5511 -         }
5512 -      }
5513 -
5514 -
5515 -      double newsurfacecont = 0;
5516 -
5517 -
5518 -      for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next())
5519 -      {
5520 -         TopoDS_Face face = TopoDS::Face(exp0.Current());
5521 -         GProp_GProps system;
5522 -         BRepGProp::SurfaceProperties(face, system);
5523 -         newsurfacecont += system.Mass();
5524 -      }
5525 -
5526 -
5527 -      int nnrc = 0, nnrcs = 0,
5528 -         nnrso = somap.Extent(),
5529 -         nnrsh = shmap.Extent(),
5530 -         nnrf = fmap.Extent(),
5531 -         nnrw = wmap.Extent(),
5532 -         nnre = emap.Extent(),
5533 -         nnrv = vmap.Extent();
5534 -
5535 -      for (exp0.Init(shape, TopAbs_COMPOUND); exp0.More(); exp0.Next()) nnrc++;
5536 -      for (exp0.Init(shape, TopAbs_COMPSOLID); exp0.More(); exp0.Next()) nnrcs++;
5537 -
5538 -      cout << "-----------------------------------" << endl;
5539 -      cout << "Compounds       : " << nnrc << " (" << nrc << ")" << endl;
5540 -      cout << "Composite solids: " << nnrcs << " (" << nrcs << ")" << endl;
5541 -      cout << "Solids          : " << nnrso << " (" << nrso << ")" << endl;
5542 -      cout << "Shells          : " << nnrsh << " (" << nrsh << ")" << endl;
5543 -      cout << "Wires           : " << nnrw << " (" << nrw << ")" << endl;
5544 -      cout << "Faces           : " << nnrf << " (" << nrf << ")" << endl;
5545 -      cout << "Edges           : " << nnre << " (" << nre << ")" << endl;
5546 -      cout << "Vertices        : " << nnrv << " (" << nrv << ")" << endl;
5547 -      cout << endl;
5548 -      cout << "Totol surface area : " << newsurfacecont << " (" << surfacecont << ")" << endl;
5549 -      cout << endl;
5550 -   }
5551 -
5552 -
5553 -
5554 -
5555 -   void OCCGeometry :: BuildFMap()
5556 -   {
5557 -      somap.Clear();
5558 -      shmap.Clear();
5559 -      fmap.Clear();
5560 -      wmap.Clear();
5561 -      emap.Clear();
5562 -      vmap.Clear();
5563 -
5564 -      TopExp_Explorer exp0, exp1, exp2, exp3, exp4, exp5;
5565 -
5566 -      for (exp0.Init(shape, TopAbs_COMPOUND);
5567 -         exp0.More(); exp0.Next())
5568 -      {
5569 -         TopoDS_Compound compound = TopoDS::Compound (exp0.Current());
5570 -         (*testout) << "compound" << endl;
5571 -         int i = 0;
5572 -         for (exp1.Init(compound, TopAbs_SHELL);
5573 -            exp1.More(); exp1.Next())
5574 -         {
5575 -            (*testout) << "shell " << ++i << endl;
5576 -         }
5577 -      }
5578 -
5579 -      for (exp0.Init(shape, TopAbs_SOLID);
5580 -         exp0.More(); exp0.Next())
5581 -      {
5582 -         TopoDS_Solid solid = TopoDS::Solid (exp0.Current());
5583 -
5584 -         if (somap.FindIndex(solid) < 1)
5585 -         {
5586 -            somap.Add (solid);
5587 -
5588 -            for (exp1.Init(solid, TopAbs_SHELL);
5589 -               exp1.More(); exp1.Next())
5590 -            {
5591 -               TopoDS_Shell shell = TopoDS::Shell (exp1.Current());
5592 -               if (shmap.FindIndex(shell) < 1)
5593 -               {
5594 -                  shmap.Add (shell);
5595 -
5596 -                  for (exp2.Init(shell, TopAbs_FACE);
5597 -                     exp2.More(); exp2.Next())
5598 -                  {
5599 -                     TopoDS_Face face = TopoDS::Face(exp2.Current());
5600 -                     if (fmap.FindIndex(face) < 1)
5601 -                     {
5602 -                        fmap.Add (face);
5603 -                        (*testout) << "face " << fmap.FindIndex(face) << " ";
5604 -                        (*testout) << ((face.Orientation() == TopAbs_REVERSED) ? "-" : "+") << ", ";
5605 -                        (*testout) << ((exp2.Current().Orientation() == TopAbs_REVERSED) ? "-" : "+") << endl;
5606 -                        for (exp3.Init(exp2.Current(), TopAbs_WIRE);
5607 -                           exp3.More(); exp3.Next())
5608 -                        {
5609 -                           TopoDS_Wire wire = TopoDS::Wire (exp3.Current());
5610 -                           if (wmap.FindIndex(wire) < 1)
5611 -                           {
5612 -                              wmap.Add (wire);
5613 -
5614 -                              for (exp4.Init(exp3.Current(), TopAbs_EDGE);
5615 -                                 exp4.More(); exp4.Next())
5616 -                              {
5617 -                                 TopoDS_Edge edge = TopoDS::Edge(exp4.Current());
5618 -                                 if (emap.FindIndex(edge) < 1)
5619 -                                 {
5620 -                                    emap.Add (edge);
5621 -                                    for (exp5.Init(exp4.Current(), TopAbs_VERTEX);
5622 -                                       exp5.More(); exp5.Next())
5623 -                                    {
5624 -                                       TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
5625 -                                       if (vmap.FindIndex(vertex) < 1)
5626 -                                          vmap.Add (vertex);
5627 -                                    }
5628 -                                 }
5629 -                              }
5630 -                           }
5631 -                        }
5632 -                     }
5633 -                  }
5634 -               }
5635 -            }
5636 -         }
5637 -      }
5638 -
5639 -      // Free Shells
5640 -      for (exp1.Init(shape, TopAbs_SHELL, TopAbs_SOLID); exp1.More(); exp1.Next())
5641 -      {
5642 -         TopoDS_Shell shell = TopoDS::Shell(exp1.Current());
5643 -         if (shmap.FindIndex(shell) < 1)
5644 -         {
5645 -            shmap.Add (shell);
5646 -
5647 -            (*testout) << "shell " << shmap.FindIndex(shell) << " ";
5648 -            (*testout) << ((shell.Orientation() == TopAbs_REVERSED) ? "-" : "+") << ", ";
5649 -            (*testout) << ((exp1.Current().Orientation() == TopAbs_REVERSED) ? "-" : "+") << endl;
5650 -
5651 -            for (exp2.Init(shell, TopAbs_FACE); exp2.More(); exp2.Next())
5652 -            {
5653 -               TopoDS_Face face = TopoDS::Face(exp2.Current());
5654 -               if (fmap.FindIndex(face) < 1)
5655 -               {
5656 -                  fmap.Add (face);
5657 -
5658 -                  for (exp3.Init(face, TopAbs_WIRE); exp3.More(); exp3.Next())
5659 -                  {
5660 -                     TopoDS_Wire wire = TopoDS::Wire (exp3.Current());
5661 -                     if (wmap.FindIndex(wire) < 1)
5662 -                     {
5663 -                        wmap.Add (wire);
5664 -
5665 -                        for (exp4.Init(wire, TopAbs_EDGE); exp4.More(); exp4.Next())
5666 -                        {
5667 -                           TopoDS_Edge edge = TopoDS::Edge(exp4.Current());
5668 -                           if (emap.FindIndex(edge) < 1)
5669 -                           {
5670 -                              emap.Add (edge);
5671 -                              for (exp5.Init(edge, TopAbs_VERTEX); exp5.More(); exp5.Next())
5672 -                              {
5673 -                                 TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
5674 -                                 if (vmap.FindIndex(vertex) < 1)
5675 -                                    vmap.Add (vertex);
5676 -                              }
5677 -                           }
5678 -                        }
5679 -                     }
5680 -                  }
5681 -               }
5682 -            }
5683 -         }
5684 -      }
5685 -
5686 -
5687 -      // Free Faces
5688 -
5689 -      for (exp2.Init(shape, TopAbs_FACE, TopAbs_SHELL); exp2.More(); exp2.Next())
5690 -      {
5691 -         TopoDS_Face face = TopoDS::Face(exp2.Current());
5692 -         if (fmap.FindIndex(face) < 1)
5693 -         {
5694 -            fmap.Add (face);
5695 -
5696 -            for (exp3.Init(exp2.Current(), TopAbs_WIRE); exp3.More(); exp3.Next())
5697 -            {
5698 -               TopoDS_Wire wire = TopoDS::Wire (exp3.Current());
5699 -               if (wmap.FindIndex(wire) < 1)
5700 -               {
5701 -                  wmap.Add (wire);
5702 -
5703 -                  for (exp4.Init(exp3.Current(), TopAbs_EDGE); exp4.More(); exp4.Next())
5704 -                  {
5705 -                     TopoDS_Edge edge = TopoDS::Edge(exp4.Current());
5706 -                     if (emap.FindIndex(edge) < 1)
5707 -                     {
5708 -                        emap.Add (edge);
5709 -                        for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next())
5710 -                        {
5711 -                           TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
5712 -                           if (vmap.FindIndex(vertex) < 1)
5713 -                              vmap.Add (vertex);
5714 -                        }
5715 -                     }
5716 -                  }
5717 -               }
5718 -            }
5719 -         }
5720 -      }
5721 -
5722 -
5723 -      // Free Wires
5724 -
5725 -      for (exp3.Init(shape, TopAbs_WIRE, TopAbs_FACE); exp3.More(); exp3.Next())
5726 -      {
5727 -         TopoDS_Wire wire = TopoDS::Wire (exp3.Current());
5728 -         if (wmap.FindIndex(wire) < 1)
5729 -         {
5730 -            wmap.Add (wire);
5731 -
5732 -            for (exp4.Init(exp3.Current(), TopAbs_EDGE); exp4.More(); exp4.Next())
5733 -            {
5734 -               TopoDS_Edge edge = TopoDS::Edge(exp4.Current());
5735 -               if (emap.FindIndex(edge) < 1)
5736 -               {
5737 -                  emap.Add (edge);
5738 -                  for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next())
5739 -                  {
5740 -                     TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
5741 -                     if (vmap.FindIndex(vertex) < 1)
5742 -                        vmap.Add (vertex);
5743 -                  }
5744 -               }
5745 -            }
5746 -         }
5747 -      }
5748 -
5749 -
5750 -      // Free Edges
5751 -
5752 -      for (exp4.Init(shape, TopAbs_EDGE, TopAbs_WIRE); exp4.More(); exp4.Next())
5753 -      {
5754 -         TopoDS_Edge edge = TopoDS::Edge(exp4.Current());
5755 -         if (emap.FindIndex(edge) < 1)
5756 -         {
5757 -            emap.Add (edge);
5758 -            for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next())
5759 -            {
5760 -               TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
5761 -               if (vmap.FindIndex(vertex) < 1)
5762 -                  vmap.Add (vertex);
5763 -            }
5764 -         }
5765 -      }
5766 -
5767 -
5768 -      // Free Vertices
5769 -
5770 -      for (exp5.Init(shape, TopAbs_VERTEX, TopAbs_EDGE); exp5.More(); exp5.Next())
5771 -      {
5772 -         TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
5773 -         if (vmap.FindIndex(vertex) < 1)
5774 -            vmap.Add (vertex);
5775 -      }
5776 -
5777 -
5778 -
5779 -
5780 -      facemeshstatus.DeleteAll();
5781 -      facemeshstatus.SetSize (fmap.Extent());
5782 -      facemeshstatus = 0;
5783 -
5784 -      // Philippose - 15/01/2009
5785 -      face_maxh.DeleteAll();
5786 -      face_maxh.SetSize (fmap.Extent());
5787 -      face_maxh = mparam.maxh;
5788 -
5789 -      // Philippose - 15/01/2010      
5790 -      face_maxh_modified.DeleteAll();      
5791 -      face_maxh_modified.SetSize(fmap.Extent());      
5792 -      face_maxh_modified = 0;
5793 -      
5794 -
5795 -      // Philippose - 17/01/2009
5796 -      face_sel_status.DeleteAll();
5797 -      face_sel_status.SetSize (fmap.Extent());
5798 -      face_sel_status = 0;
5799 -
5800 -      fvispar.SetSize (fmap.Extent());
5801 -      evispar.SetSize (emap.Extent());
5802 -      vvispar.SetSize (vmap.Extent());
5803 -
5804 -      fsingular.SetSize (fmap.Extent());
5805 -      esingular.SetSize (emap.Extent());
5806 -      vsingular.SetSize (vmap.Extent());
5807 -
5808 -      fsingular = esingular = vsingular = false;
5809 -   }
5810 -
5811 -
5812 -
5813 -   void OCCGeometry :: SewFaces ()
5814 -   {
5815 -      (*testout) << "Trying to sew faces ..." << endl;
5816 -      cout << "Trying to sew faces ..." << flush;
5817 -
5818 -      BRepOffsetAPI_Sewing sewedObj(1);
5819
5820 -      for (int i = 1; i <= fmap.Extent(); i++)
5821 -      {
5822 -         TopoDS_Face face = TopoDS::Face (fmap(i));
5823 -         sewedObj.Add (face);
5824 -      }
5825 -
5826 -      sewedObj.Perform();
5827 -
5828 -      if (!sewedObj.SewedShape().IsNull())
5829 -      {
5830 -         shape = sewedObj.SewedShape();
5831 -         cout << " done" << endl;
5832 -      }
5833 -      else
5834 -         cout << " not possible";
5835 -   }
5836 -
5837 -
5838 -
5839 -
5840 -
5841 -   void OCCGeometry :: MakeSolid ()
5842 -   {
5843 -      TopExp_Explorer exp0;
5844 -
5845 -      (*testout) << "Trying to build solids ..." << endl;
5846 -      cout << "Trying to build solids ..." << flush;
5847 -
5848 -      BRepBuilderAPI_MakeSolid ms;
5849 -      int count = 0;
5850 -      for (exp0.Init(shape, TopAbs_SHELL); exp0.More(); exp0.Next())
5851 -      {
5852 -         count++;
5853 -         ms.Add (TopoDS::Shell(exp0.Current()));
5854 -      }
5855 -
5856 -      if (!count)
5857 -      {
5858 -         cout << " not possible (no shells)" << endl;
5859 -         return;
5860 -      }
5861 -
5862 -      BRepCheck_Analyzer ba(ms);
5863 -      if (ba.IsValid ())
5864 -      {
5865 -         Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
5866 -         sfs->Init (ms);
5867 -
5868 -         sfs->SetPrecision(1e-5);
5869 -         sfs->SetMaxTolerance(1e-5);
5870 -
5871 -         sfs->Perform();
5872 -
5873 -         shape = sfs->Shape();
5874 -
5875 -         for (exp0.Init(shape, TopAbs_SOLID); exp0.More(); exp0.Next())
5876 -         {
5877 -            TopoDS_Solid solid = TopoDS::Solid(exp0.Current());
5878 -            TopoDS_Solid newsolid = solid;
5879 -            BRepLib::OrientClosedSolid (newsolid);
5880 -            Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;
5881 -            rebuild->Replace(solid, newsolid, Standard_False);
5882 -
5883 -            TopoDS_Shape newshape = rebuild->Apply(shape, TopAbs_SHAPE, 1);
5884 -            shape = newshape;
5885 -         }
5886 -
5887 -         cout << " done" << endl;
5888 -      }
5889 -      else
5890 -         cout << " not possible" << endl;
5891 -   }
5892 -
5893 -
5894 -
5895 -
5896 -   void OCCGeometry :: BuildVisualizationMesh (double deflection)
5897 -   {
5898 -      cout << "Preparing visualization (deflection = " << deflection << ") ... " << flush;
5899 -
5900 -      BRepTools::Clean (shape);
5901 -      // BRepMesh_IncrementalMesh::
5902 -      BRepMesh_IncrementalMesh (shape, deflection, true);
5903 -      cout << "done" << endl;
5904 -   }
5905 -
5906 -
5907 -
5908 -
5909 -   void OCCGeometry :: CalcBoundingBox ()
5910 -   {
5911 -      Bnd_Box bb;
5912 -      BRepBndLib::Add (shape, bb);
5913 -
5914 -      double x1,y1,z1,x2,y2,z2;
5915 -      bb.Get (x1,y1,z1,x2,y2,z2);
5916 -      Point<3> p1 = Point<3> (x1,y1,z1);
5917 -      Point<3> p2 = Point<3> (x2,y2,z2);
5918 -
5919 -      (*testout) << "Bounding Box = [" << p1 << " - " << p2 << "]" << endl;
5920 -      boundingbox = Box<3> (p1,p2);
5921 -      SetCenter();
5922 -   }
5923 -
5924 -
5925 -
5926 -
5927 -   void OCCGeometry :: Project (int surfi, Point<3> & p) const
5928 -   {
5929 -      static int cnt = 0;
5930 -      if (++cnt % 1000 == 0) cout << "Project cnt = " << cnt << endl;
5931 -
5932 -      gp_Pnt pnt(p(0), p(1), p(2));
5933 -
5934 -      double u,v;
5935 -      Handle( Geom_Surface ) thesurf = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));
5936 -      Handle( ShapeAnalysis_Surface ) su = new ShapeAnalysis_Surface( thesurf );
5937 -      gp_Pnt2d suval = su->ValueOfUV ( pnt, BRep_Tool::Tolerance( TopoDS::Face(fmap(surfi)) ) );
5938 -      suval.Coord( u, v);
5939 -      pnt = thesurf->Value( u, v );
5940 -
5941 -
5942 -      p = Point<3> (pnt.X(), pnt.Y(), pnt.Z());
5943 -
5944 -   }
5945 -
5946 -
5947 -
5948 -
5949 -   bool OCCGeometry :: FastProject (int surfi, Point<3> & ap, double& u, double& v) const
5950 -   {
5951 -      gp_Pnt p(ap(0), ap(1), ap(2));
5952 -
5953 -      Handle(Geom_Surface) surface = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));
5954 -
5955 -      gp_Pnt x = surface->Value (u,v);
5956 -
5957 -      if (p.SquareDistance(x) <= sqr(PROJECTION_TOLERANCE)) return true;
5958 -
5959 -      gp_Vec du, dv;
5960 -
5961 -      surface->D1(u,v,x,du,dv);
5962 -
5963 -      int count = 0;
5964 -
5965 -      gp_Pnt xold;
5966 -      gp_Vec n;
5967 -      double det, lambda, mu;
5968 -
5969 -      do {
5970 -         count++;
5971 -
5972 -         n = du^dv;
5973 -
5974 -         det = Det3 (n.X(), du.X(), dv.X(),
5975 -            n.Y(), du.Y(), dv.Y(),
5976 -            n.Z(), du.Z(), dv.Z());
5977 -
5978 -         if (det < 1e-15) return false;
5979 -
5980 -         lambda = Det3 (n.X(), p.X()-x.X(), dv.X(),
5981 -            n.Y(), p.Y()-x.Y(), dv.Y(),
5982 -            n.Z(), p.Z()-x.Z(), dv.Z())/det;
5983 -
5984 -         mu     = Det3 (n.X(), du.X(), p.X()-x.X(),
5985 -            n.Y(), du.Y(), p.Y()-x.Y(),
5986 -            n.Z(), du.Z(), p.Z()-x.Z())/det;
5987 -
5988 -         u += lambda;
5989 -         v += mu;
5990 -
5991 -         xold = x;
5992 -         surface->D1(u,v,x,du,dv);
5993 -
5994 -      } while (xold.SquareDistance(x) > sqr(PROJECTION_TOLERANCE) && count < 50);
5995 -
5996 -      //    (*testout) << "FastProject count: " << count << endl;
5997 -
5998 -      if (count == 50) return false;
5999 -
6000 -      ap = Point<3> (x.X(), x.Y(), x.Z());
6001 -
6002 -      return true;
6003 -   }
6004 -
6005 -
6006 -
6007 -
6008 -   void OCCGeometry :: WriteOCC_STL(char * filename)
6009 -   {
6010 -      cout << "writing stl..."; cout.flush();
6011 -      StlAPI_Writer writer;
6012 -      writer.RelativeMode() = Standard_False;
6013 -
6014 -      writer.SetDeflection(0.02);
6015 -      writer.Write(shape,filename);
6016 -
6017 -      cout << "done" << endl;
6018 -   }
6019 -
6020 -
6021 -
6022 -   // Philippose - 23/02/2009
6023 -   /* Special IGES File load function including the ability
6024 -   to extract individual surface colours via the extended
6025 -   OpenCascade XDE and XCAF Feature set.
6026 -   */
6027 -   OCCGeometry *LoadOCC_IGES(const char *filename)
6028 -   {
6029 -      OCCGeometry *occgeo;
6030 -      occgeo = new OCCGeometry;
6031 -
6032 -      // Initiate a dummy XCAF Application to handle the IGES XCAF Document
6033 -      static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication();
6034 -
6035 -      // Create an XCAF Document to contain the IGES file itself
6036 -      Handle_TDocStd_Document iges_doc;
6037 -
6038 -      // Check if a IGES File is already open under this handle, if so, close it to prevent
6039 -      // Segmentation Faults when trying to create a new document
6040 -      if(dummy_app->NbDocuments() > 0)
6041 -      {
6042 -         dummy_app->GetDocument(1,iges_doc);
6043 -         dummy_app->Close(iges_doc);
6044 -      }
6045 -      dummy_app->NewDocument ("IGES-XCAF",iges_doc);
6046 -
6047 -      IGESCAFControl_Reader reader;
6048 -
6049 -      Standard_Integer stat = reader.ReadFile((char*)filename);
6050 -
6051 -      if(stat != IFSelect_RetDone)
6052 -      {
6053 -         delete occgeo;
6054 -         return NULL;
6055 -      }
6056 -
6057 -      // Enable transfer of colours
6058 -      reader.SetColorMode(Standard_True);
6059 -
6060 -      reader.Transfer(iges_doc);
6061 -
6062 -      // Read in the shape(s) and the colours present in the IGES File
6063 -      Handle_XCAFDoc_ShapeTool iges_shape_contents = XCAFDoc_DocumentTool::ShapeTool(iges_doc->Main());
6064 -      Handle_XCAFDoc_ColorTool iges_colour_contents = XCAFDoc_DocumentTool::ColorTool(iges_doc->Main());
6065 -
6066 -      TDF_LabelSequence iges_shapes;
6067 -      iges_shape_contents->GetShapes(iges_shapes);
6068 -
6069 -      // List out the available colours in the IGES File as Colour Names
6070 -      TDF_LabelSequence all_colours;
6071 -      iges_colour_contents->GetColors(all_colours);
6072 -      PrintMessage(1,"Number of colours in IGES File: ",all_colours.Length());
6073 -      for(int i = 1; i <= all_colours.Length(); i++)
6074 -      {
6075 -         Quantity_Color col;
6076 -         stringstream col_rgb;
6077 -         iges_colour_contents->GetColor(all_colours.Value(i),col);
6078 -         col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")";
6079 -         PrintMessage(1, "Colour [", i, "] = ",col.StringName(col.Name()),col_rgb.str());
6080 -      }
6081 -
6082 -
6083 -      // For the IGES Reader, all the shapes can be exported as one compund shape 
6084 -      // using the "OneShape" member
6085 -      occgeo->shape = reader.OneShape();
6086 -      occgeo->face_colours = iges_colour_contents;
6087 -      occgeo->changed = 1;
6088 -      occgeo->BuildFMap();
6089 -
6090 -      occgeo->CalcBoundingBox();
6091 -      PrintContents (occgeo);
6092 -
6093 -      return occgeo;
6094 -   }
6095 -
6096 -
6097 -
6098 -
6099 -
6100 -   // Philippose - 29/01/2009
6101 -   /* Special STEP File load function including the ability
6102 -   to extract individual surface colours via the extended
6103 -   OpenCascade XDE and XCAF Feature set.
6104 -   */
6105 -   OCCGeometry * LoadOCC_STEP (const char * filename)
6106 -   {
6107 -      OCCGeometry * occgeo;
6108 -      occgeo = new OCCGeometry;
6109 -
6110 -      // Initiate a dummy XCAF Application to handle the STEP XCAF Document
6111 -      static Handle_XCAFApp_Application dummy_app = XCAFApp_Application::GetApplication();
6112 -
6113 -      // Create an XCAF Document to contain the STEP file itself
6114 -      Handle_TDocStd_Document step_doc;
6115 -
6116 -      // Check if a STEP File is already open under this handle, if so, close it to prevent
6117 -      // Segmentation Faults when trying to create a new document
6118 -      if(dummy_app->NbDocuments() > 0)
6119 -      {
6120 -         dummy_app->GetDocument(1,step_doc);
6121 -         dummy_app->Close(step_doc);
6122 -      }
6123 -      dummy_app->NewDocument ("STEP-XCAF",step_doc);
6124 -
6125 -      STEPCAFControl_Reader reader;
6126 -
6127 -      // Enable transfer of colours
6128 -      reader.SetColorMode(Standard_True);
6129 -
6130 -      Standard_Integer stat = reader.ReadFile((char*)filename);
6131 -
6132 -      if(stat != IFSelect_RetDone)
6133 -      {
6134 -         delete occgeo;
6135 -         return NULL;
6136 -      }
6137 -
6138 -      reader.Transfer(step_doc);
6139 -
6140 -      // Read in the shape(s) and the colours present in the STEP File
6141 -      Handle_XCAFDoc_ShapeTool step_shape_contents = XCAFDoc_DocumentTool::ShapeTool(step_doc->Main());
6142 -      Handle_XCAFDoc_ColorTool step_colour_contents = XCAFDoc_DocumentTool::ColorTool(step_doc->Main());
6143 -
6144 -      TDF_LabelSequence step_shapes;
6145 -      step_shape_contents->GetShapes(step_shapes);
6146 -
6147 -      // List out the available colours in the STEP File as Colour Names
6148 -      TDF_LabelSequence all_colours;
6149 -      step_colour_contents->GetColors(all_colours);
6150 -      PrintMessage(1,"Number of colours in STEP File: ",all_colours.Length());
6151 -      for(int i = 1; i <= all_colours.Length(); i++)
6152 -      {
6153 -         Quantity_Color col;
6154 -         stringstream col_rgb;
6155 -         step_colour_contents->GetColor(all_colours.Value(i),col);
6156 -         col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")";
6157 -         PrintMessage(1, "Colour [", i, "] = ",col.StringName(col.Name()),col_rgb.str());
6158 -      }
6159 -
6160 -
6161 -      // For the STEP File Reader in OCC, the 1st Shape contains the entire 
6162 -      // compound geometry as one shape
6163 -      occgeo->shape = step_shape_contents->GetShape(step_shapes.Value(1));
6164 -      occgeo->face_colours = step_colour_contents;
6165 -      occgeo->changed = 1;
6166 -      occgeo->BuildFMap();
6167 -
6168 -      occgeo->CalcBoundingBox();
6169 -      PrintContents (occgeo);
6170 -
6171 -      return occgeo;
6172 -   }
6173 -
6174 -
6175 -
6176 -
6177 -   OCCGeometry *LoadOCC_BREP (const char *filename)
6178 -   {
6179 -      OCCGeometry * occgeo;
6180 -      occgeo = new OCCGeometry;
6181 -
6182 -      BRep_Builder aBuilder;
6183 -      Standard_Boolean result = BRepTools::Read(occgeo->shape, const_cast<char*> (filename),aBuilder);
6184 -
6185 -      if(!result)
6186 -      {
6187 -         delete occgeo;
6188 -         return NULL;
6189 -      }
6190 -
6191 -      // Philippose - 23/02/2009
6192 -      // Fixed a bug in the OpenCascade XDE Colour handling when 
6193 -      // opening BREP Files, since BREP Files have no colour data.
6194 -      // Hence, the face_colours Handle needs to be created as a NULL handle.
6195 -      occgeo->face_colours = Handle_XCAFDoc_ColorTool();
6196 -      occgeo->face_colours.Nullify();
6197 -      occgeo->changed = 1;
6198 -      occgeo->BuildFMap();
6199 -
6200 -      occgeo->CalcBoundingBox();
6201 -      PrintContents (occgeo);
6202 -
6203 -      return occgeo;
6204 -   }
6205 -
6206 -
6207 -  void OCCGeometry :: Save (string sfilename) const
6208 -  {
6209 -    const char * filename = sfilename.c_str();
6210 -    if (strlen(filename) < 4) 
6211 -      throw NgException ("illegal filename");
6212 -    
6213 -    if (strcmp (&filename[strlen(filename)-3], "igs") == 0)
6214 -      {
6215 -       IGESControl_Writer writer("millimeters", 1);
6216 -       writer.AddShape (shape);
6217 -       writer.Write (filename);
6218 -      }
6219 -    else if (strcmp (&filename[strlen(filename)-3], "stp") == 0)
6220 -      {
6221 -       STEPControl_Writer writer;
6222 -       writer.Transfer (shape, STEPControl_AsIs);
6223 -       writer.Write (filename);
6224 -      }
6225 -    else if (strcmp (&filename[strlen(filename)-3], "stl") == 0)
6226 -      {
6227 -       StlAPI_Writer writer;
6228 -       writer.ASCIIMode() = Standard_True;
6229 -       writer.Write (shape, filename);
6230 -      }
6231 -    else if (strcmp (&filename[strlen(filename)-4], "stlb") == 0)
6232 -      {
6233 -       StlAPI_Writer writer;
6234 -       writer.ASCIIMode() = Standard_False;
6235 -       writer.Write (shape, filename);
6236 -      }
6237 -  }
6238 -
6239 -
6240 -
6241 -  const char * shapesname[] =
6242 -   {" ", "CompSolids", "Solids", "Shells",
6243 -
6244 -   "Faces", "Wires", "Edges", "Vertices"};
6245 -
6246 -  const char * shapename[] =
6247 -   {" ", "CompSolid", "Solid", "Shell",
6248 -   "Face", "Wire", "Edge", "Vertex"};
6249 -
6250 -  const char * orientationstring[] =
6251 -     {"+", "-"};
6252 -
6253 -
6254 -
6255 -
6256 -   void OCCGeometry :: RecursiveTopologyTree (const TopoDS_Shape & sh,
6257 -      stringstream & str,
6258 -      TopAbs_ShapeEnum l,
6259 -      bool isfree,
6260 -      const char * lname)
6261 -   {
6262 -      if (l > TopAbs_VERTEX) return;
6263 -
6264 -      TopExp_Explorer e;
6265 -      int count = 0;
6266 -      int count2 = 0;
6267 -
6268 -      if (isfree)
6269 -         e.Init(sh, l, TopAbs_ShapeEnum(l-1));
6270 -      else
6271 -         e.Init(sh, l);
6272 -
6273 -      for (; e.More(); e.Next())
6274 -      {
6275 -         count++;
6276 -
6277 -         stringstream lname2;
6278 -         lname2 << lname << "/" << shapename[l] << count;
6279 -         str << lname2.str() << " ";
6280 -
6281 -         switch (e.Current().ShapeType())
6282 -          {
6283 -          case TopAbs_SOLID:
6284 -            count2 = somap.FindIndex(TopoDS::Solid(e.Current())); break;
6285 -          case TopAbs_SHELL:
6286 -            count2 = shmap.FindIndex(TopoDS::Shell(e.Current())); break;
6287 -          case TopAbs_FACE:
6288 -            count2 = fmap.FindIndex(TopoDS::Face(e.Current())); break;
6289 -          case TopAbs_WIRE:
6290 -            count2 = wmap.FindIndex(TopoDS::Wire(e.Current())); break;
6291 -          case TopAbs_EDGE:
6292 -            count2 = emap.FindIndex(TopoDS::Edge(e.Current())); break;
6293 -          case TopAbs_VERTEX:
6294 -            count2 = vmap.FindIndex(TopoDS::Vertex(e.Current())); break;
6295 -          default:
6296 -            cout << "RecursiveTopologyTree: Case " << e.Current().ShapeType() << " not handeled" << endl;
6297 -         }
6298 -
6299 -         int nrsubshapes = 0;
6300 -
6301 -         if (l <= TopAbs_WIRE)
6302 -         {
6303 -            TopExp_Explorer e2;
6304 -            for (e2.Init (e.Current(), TopAbs_ShapeEnum (l+1));
6305 -               e2.More(); e2.Next())
6306 -               nrsubshapes++;
6307 -         }
6308 -
6309 -         str << "{" << shapename[l] << " " << count2;
6310 -
6311 -         if (l <= TopAbs_EDGE)
6312 -         {
6313 -            str << " (" << orientationstring[e.Current().Orientation()];
6314 -            if (nrsubshapes != 0) str << ", " << nrsubshapes;
6315 -            str << ") } ";
6316 -         }
6317 -         else
6318 -            str << " } ";
6319 -
6320 -         RecursiveTopologyTree (e.Current(), str, TopAbs_ShapeEnum (l+1),
6321 -            false, (char*)lname2.str().c_str());
6322 -
6323 -      }
6324 -   }
6325 -
6326 -
6327 -
6328 -
6329 -   void OCCGeometry :: GetTopologyTree (stringstream & str)
6330 -   {
6331 -      cout << "Building topology tree ... " << flush;
6332 -      RecursiveTopologyTree (shape, str, TopAbs_COMPSOLID, false, "CompSolids");
6333 -      RecursiveTopologyTree (shape, str, TopAbs_SOLID, true, "FreeSolids");
6334 -      RecursiveTopologyTree (shape, str, TopAbs_SHELL, true, "FreeShells");
6335 -      RecursiveTopologyTree (shape, str, TopAbs_FACE, true, "FreeFaces");
6336 -      RecursiveTopologyTree (shape, str, TopAbs_WIRE, true, "FreeWires");
6337 -      RecursiveTopologyTree (shape, str, TopAbs_EDGE, true, "FreeEdges");
6338 -      RecursiveTopologyTree (shape, str, TopAbs_VERTEX, true, "FreeVertices");
6339 -      str << flush;
6340 -      //  cout << "done" << endl;
6341 -   }
6342 -
6343 -
6344 -
6345 -
6346 -   void OCCGeometry :: CheckIrregularEntities(stringstream & str)
6347 -   {
6348 -      ShapeAnalysis_CheckSmallFace csm;
6349 -
6350 -      csm.SetTolerance (1e-6);
6351 -
6352 -      TopTools_DataMapOfShapeListOfShape mapEdges;
6353 -      ShapeAnalysis_DataMapOfShapeListOfReal mapParam;
6354 -      TopoDS_Compound theAllVert;
6355 -
6356 -      int spotfaces = 0;
6357 -      int stripsupportfaces = 0;
6358 -      int singlestripfaces = 0;
6359 -      int stripfaces = 0;
6360 -      int facessplitbyvertices = 0;
6361 -      int stretchedpinfaces = 0;
6362 -      int smoothpinfaces = 0;
6363 -      int twistedfaces = 0;
6364 -      // int edgessamebutnotidentified = 0;
6365 -
6366 -      cout << "checking faces ... " << flush;
6367 -
6368 -      int i;
6369 -      for (i = 1; i <= fmap.Extent(); i++)
6370 -      {
6371 -         TopoDS_Face face = TopoDS::Face (fmap(i));
6372 -         TopoDS_Edge e1, e2;
6373 -
6374 -         if (csm.CheckSpotFace (face))
6375 -         {
6376 -            if (!spotfaces++)
6377 -               str << "SpotFace {Spot face} ";
6378 -
6379 -            (*testout) << "Face " << i << " is a spot face" << endl;
6380 -            str << "SpotFace/Face" << i << " ";
6381 -            str << "{Face " << i << " } ";
6382 -         }
6383 -
6384 -         if (csm.IsStripSupport (face))
6385 -         {
6386 -            if (!stripsupportfaces++)
6387 -               str << "StripSupportFace {Strip support face} ";
6388 -
6389 -            (*testout) << "Face " << i << " has strip support" << endl;
6390 -            str << "StripSupportFace/Face" << i << " ";
6391 -            str << "{Face " << i << " } ";
6392 -         }
6393 -
6394 -         if (csm.CheckSingleStrip(face, e1, e2))
6395 -         {
6396 -            if (!singlestripfaces++)
6397 -               str << "SingleStripFace {Single strip face} ";
6398 -
6399 -            (*testout) << "Face " << i << " is a single strip (edge " << emap.FindIndex(e1)
6400 -               << " and edge " << emap.FindIndex(e2) << " are identical)" << endl;
6401 -            str << "SingleStripFace/Face" << i << " ";
6402 -            str << "{Face " << i << " (edge " << emap.FindIndex(e1)
6403 -               << " and edge " << emap.FindIndex(e2) << " are identical)} ";
6404 -         }
6405 -
6406 -         if (csm.CheckStripFace(face, e1, e2))
6407 -         {
6408 -            if (!stripfaces++)
6409 -               str << "StripFace {Strip face} ";
6410 -
6411 -            (*testout) << "Face " << i << " is a strip (edge " << emap.FindIndex(e1)
6412 -               << " and edge " << emap.FindIndex(e2)
6413 -               << " are identical)" << endl;
6414 -            str << "StripFace/Face" << i << " ";
6415 -            str << "{Face " << i << " (edge " << emap.FindIndex(e1)
6416 -               << " and edge " << emap.FindIndex(e2) << " are identical)} ";
6417 -         }
6418 -
6419 -         if (int count = csm.CheckSplittingVertices(face, mapEdges, mapParam, theAllVert))
6420 -         {
6421 -            if (!facessplitbyvertices++)
6422 -               str << "FaceSplitByVertices {Face split by vertices} ";
6423 -
6424 -            (*testout) << "Face " << i << " is split by " << count
6425 -               << " vertex/vertices " << endl;
6426 -            str << "FaceSplitByVertices/Face" << i << " ";
6427 -            str << "{Face " << i << " (split by " << count << "vertex/vertices)} ";
6428 -         }
6429 -
6430 -         int whatrow, sens;
6431 -         if (int type = csm.CheckPin (face, whatrow, sens))
6432 -         {
6433 -            if (type == 1)
6434 -            {
6435 -               if (!smoothpinfaces++)
6436 -                  str << "SmoothPinFace {Smooth pin face} ";
6437 -
6438 -               (*testout) << "Face " << i << " is a smooth pin" << endl;
6439 -               str << "SmoothPinFace/Face" << i << " ";
6440 -               str << "{Face " << i << " } ";
6441 -            }
6442 -            else
6443 -            {
6444 -               if (!stretchedpinfaces++)
6445 -                  str << "StretchedPinFace {Stretched pin face} ";
6446 -
6447 -               (*testout) << "Face " << i << " is a streched pin" << endl;
6448 -               str << "StretchedPinFace/Face" << i << " ";
6449 -               str << "{Face " << i << " } ";
6450 -            }
6451 -         }
6452 -
6453 -         double paramu, paramv;
6454 -         if (csm.CheckTwisted (face, paramu, paramv))
6455 -         {
6456 -            if (!twistedfaces++)
6457 -               str << "TwistedFace {Twisted face} ";
6458 -
6459 -            (*testout) << "Face " << i << " is twisted" << endl;
6460 -            str << "TwistedFace/Face" << i << " ";
6461 -            str << "{Face " << i << " } ";
6462 -         }
6463 -      }
6464 -
6465 -      cout << "done" << endl;
6466 -      cout << "checking edges ... " << flush;
6467 -
6468 -      // double dmax;
6469 -      // int cnt = 0;
6470 -      Array <double> edgeLengths;
6471 -      Array <int> order;
6472 -      edgeLengths.SetSize (emap.Extent());
6473 -      order.SetSize (emap.Extent());
6474 -
6475 -      for (i = 1; i <= emap.Extent(); i++)
6476 -      {
6477 -         TopoDS_Edge edge1 = TopoDS::Edge (emap(i));
6478 -         GProp_GProps system;
6479 -         BRepGProp::LinearProperties(edge1, system);
6480 -         edgeLengths[i-1] = system.Mass();
6481 -      }
6482 -
6483 -      Sort (edgeLengths, order);
6484 -
6485 -      str << "ShortestEdges {Shortest edges} ";
6486 -      for (i = 1; i <= min(20, emap.Extent()); i++)
6487 -      {
6488 -         str << "ShortestEdges/Edge" << i;
6489 -         str << " {Edge " << order[i-1] << " (L=" << edgeLengths[order[i-1]-1] << ")} ";
6490 -      }
6491 -
6492 -      str << flush;
6493 -
6494 -      cout << "done" << endl;
6495 -   }
6496 -
6497 -
6498 -
6499 -
6500 -   void OCCGeometry :: GetUnmeshedFaceInfo (stringstream & str)
6501 -   {
6502 -      for (int i = 1; i <= fmap.Extent(); i++)
6503 -      {
6504 -         if (facemeshstatus[i-1] == -1)
6505 -            str << "Face" << i << " {Face " << i << " } ";
6506 -      }
6507 -      str << flush;
6508 -   }
6509 -
6510 -
6511 -
6512 -
6513 -   void OCCGeometry :: GetNotDrawableFaces (stringstream & str)
6514 -   {
6515 -      for (int i = 1; i <= fmap.Extent(); i++)
6516 -      {
6517 -         if (!fvispar[i-1].IsDrawable())
6518 -            str << "Face" << i << " {Face " << i << " } ";
6519 -      }
6520 -      str << flush;
6521 -   }
6522 -
6523 -
6524 -
6525 -
6526 -   bool OCCGeometry :: ErrorInSurfaceMeshing ()
6527 -   {
6528 -      for (int i = 1; i <= fmap.Extent(); i++)
6529 -         if (facemeshstatus[i-1] == -1)
6530 -            return true;
6531 -
6532 -      return false;
6533 -   }
6534 -
6535 -
6536 -
6537 -
6538 -  int OCCGeometry :: GenerateMesh (Mesh*& mesh, MeshingParameters & mparam,
6539 -      int perfstepsstart, int perfstepsend)
6540 -   {
6541 -     return OCCGenerateMesh (*this, mesh, mparam, perfstepsstart, perfstepsend);
6542 -   }
6543 -
6544 -
6545 -
6546 -
6547 -   const Refinement & OCCGeometry :: GetRefinement () const
6548 -   {
6549 -      return * new OCCRefinementSurfaces (*this);
6550 -   }
6551 -
6552 -
6553 -
6554 -
6555 -   OCCParameters :: OCCParameters()
6556 -   {
6557 -      resthcloseedgefac = 1;
6558 -      resthcloseedgeenable = 1;
6559 -         resthminedgelen = 0.001;
6560 -         resthminedgelenenable = 1;
6561 -   }
6562 -
6563 -
6564 -
6565 -
6566 -   void OCCParameters :: Print(ostream & ost) const
6567 -   {
6568 -      ost << "OCC Parameters:" << endl
6569 -         << "close edges: " << resthcloseedgeenable
6570 -         << ", fac = " << resthcloseedgefac << endl
6571 -                << "minimum edge length: " << resthminedgelenenable
6572 -                << ", min len = " << resthminedgelen << endl;
6573 -   }
6574 -
6575 -
6576 -
6577 -
6578 -   OCCParameters occparam;
6579 -
6580 -}
6581 -
6582 -
6583 -#endif
6584 +
6585 +#ifdef OCCGEOMETRY
6586 +
6587 +#include <mystdlib.h>
6588 +#include <occgeom.hpp>
6589 +#include "ShapeAnalysis_ShapeTolerance.hxx"
6590 +#include "ShapeAnalysis_ShapeContents.hxx"
6591 +#include "ShapeAnalysis_CheckSmallFace.hxx"
6592 +#include "ShapeAnalysis_DataMapOfShapeListOfReal.hxx"
6593 +#include "ShapeAnalysis_Surface.hxx"
6594 +#include <BRepTopAdaptor_FClass2d.hxx> // -- to optimize Project() and FastProject()
6595 +#include <TopAbs_State.hxx>
6596 +#include "BRepAlgoAPI_Fuse.hxx"
6597 +#include "BRepCheck_Analyzer.hxx"
6598 +#include "BRepLib.hxx"
6599 +#include "ShapeBuild_ReShape.hxx"
6600 +#include "ShapeFix.hxx"
6601 +#include "ShapeFix_FixSmallFace.hxx"
6602 +#include "Partition_Spliter.hxx"
6603 +
6604 +namespace netgen
6605 +{
6606 +  // free data used to optimize Project() and FastProject()
6607 +  OCCGeometry::~OCCGeometry()
6608 +  {
6609 +    NCollection_DataMap<int,BRepTopAdaptor_FClass2d*>::Iterator it(fclsmap);
6610 +    for (; it.More(); it.Next())
6611 +      delete it.Value();
6612 +  }
6613 +
6614 +   void OCCGeometry :: PrintNrShapes ()
6615 +   {
6616 +      TopExp_Explorer e;
6617 +      int count = 0;
6618 +      for (e.Init(shape, TopAbs_COMPSOLID); e.More(); e.Next()) count++;
6619 +      std::cout << "CompSolids: " << count << std::endl;
6620 +
6621 +      std::cout << "Solids    : " << somap.Extent() << std::endl;
6622 +      std::cout << "Shells    : " << shmap.Extent() << std::endl;
6623 +      std::cout << "Faces     : " << fmap.Extent() << std::endl;
6624 +      std::cout << "Edges     : " << emap.Extent() << std::endl;
6625 +      std::cout << "Vertices  : " << vmap.Extent() << std::endl;
6626 +   }
6627 +
6628 +
6629 +
6630 +
6631 +   void PrintContents (OCCGeometry * geom)
6632 +   {
6633 +      ShapeAnalysis_ShapeContents cont;
6634 +      cont.Clear();
6635 +      cont.Perform(geom->shape);
6636 +
6637 +      (*testout) << "OCC CONTENTS" << std::endl;
6638 +      (*testout) << "============" << std::endl;
6639 +      (*testout) << "SOLIDS   : " << cont.NbSolids() << std::endl;
6640 +      (*testout) << "SHELLS   : " << cont.NbShells() << std::endl;
6641 +      (*testout) << "FACES    : " << cont.NbFaces() << std::endl;
6642 +      (*testout) << "WIRES    : " << cont.NbWires() << std::endl;
6643 +      (*testout) << "EDGES    : " << cont.NbEdges() << std::endl;
6644 +      (*testout) << "VERTICES : " << cont.NbVertices() << std::endl;
6645 +
6646 +      TopExp_Explorer e;
6647 +      int count = 0;
6648 +      for (e.Init(geom->shape, TopAbs_COMPOUND); e.More(); e.Next())
6649 +         count++;
6650 +      (*testout) << "Compounds: " << count << std::endl;
6651 +
6652 +      count = 0;
6653 +      for (e.Init(geom->shape, TopAbs_COMPSOLID); e.More(); e.Next())
6654 +         count++;
6655 +      (*testout) << "CompSolids: " << count << std::endl;
6656 +
6657 +      (*testout) << std::endl;
6658 +
6659 +      std::cout << "Highest entry in topology hierarchy: " << std::endl;
6660 +      if (count)
6661 +         std::cout << count << " composite solid(s)" << std::endl;
6662 +      else
6663 +         if (geom->somap.Extent())
6664 +            std::cout << geom->somap.Extent() << " solid(s)" << std::endl;
6665 +         else
6666 +            if (geom->shmap.Extent())
6667 +               std::cout << geom->shmap.Extent() << " shells(s)" << std::endl;
6668 +            else
6669 +               if (geom->fmap.Extent())
6670 +                  std::cout << geom->fmap.Extent() << " face(s)" << std::endl;
6671 +               else
6672 +                  if (geom->wmap.Extent())
6673 +                     std::cout << geom->wmap.Extent() << " wire(s)" << std::endl;
6674 +                  else
6675 +                     if (geom->emap.Extent())
6676 +                        std::cout << geom->emap.Extent() << " edge(s)" << std::endl;
6677 +                     else
6678 +                        if (geom->vmap.Extent())
6679 +                           std::cout << geom->vmap.Extent() << " vertices(s)" << std::endl;
6680 +                        else
6681 +                           std::cout << "no entities" << std::endl;
6682 +
6683 +   }
6684 +
6685 +
6686 +
6687 +   void OCCGeometry :: HealGeometry ()
6688 +   {
6689 +      int nrc = 0, nrcs = 0,
6690 +         nrso = somap.Extent(),
6691 +         nrsh = shmap.Extent(),
6692 +         nrf = fmap.Extent(),
6693 +         nrw = wmap.Extent(),
6694 +         nre = emap.Extent(),
6695 +         nrv = vmap.Extent();
6696 +
6697 +      TopExp_Explorer exp0;
6698 +      TopExp_Explorer exp1;
6699 +
6700 +
6701 +      for (exp0.Init(shape, TopAbs_COMPOUND); exp0.More(); exp0.Next()) nrc++;
6702 +      for (exp0.Init(shape, TopAbs_COMPSOLID); exp0.More(); exp0.Next()) nrcs++;
6703 +
6704 +      double surfacecont = 0;
6705 +
6706 +      {
6707 +         Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
6708 +         rebuild->Apply(shape);
6709 +         for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
6710 +         {
6711 +            TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
6712 +            if ( BRep_Tool::Degenerated(edge) )
6713 +               rebuild->Remove(edge);
6714 +         }
6715 +         shape = rebuild->Apply(shape);
6716 +      }
6717 +
6718 +      BuildFMap();
6719 +
6720 +
6721 +      for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next())
6722 +      {
6723 +         TopoDS_Face face = TopoDS::Face(exp0.Current());
6724 +
6725 +         GProp_GProps system;
6726 +         BRepGProp::SurfaceProperties(face, system);
6727 +         surfacecont += system.Mass();
6728 +      }
6729 +
6730 +
6731 +      std::cout << "Starting geometry healing procedure (tolerance: " << tolerance << ")" << std::endl
6732 +         << "-----------------------------------" << std::endl;
6733 +
6734 +      {
6735 +         std::cout << std::endl << "- repairing faces" << std::endl;
6736 +
6737 +         Handle(ShapeFix_Face) sff;
6738 +         Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
6739 +         rebuild->Apply(shape);
6740 +
6741 +
6742 +         for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next())
6743 +         {
6744 +            // Variable to hold the colour (if there exists one) of 
6745 +            // the current face being processed
6746 +            Quantity_Color face_colour;
6747 +
6748 +            TopoDS_Face face = TopoDS::Face (exp0.Current());
6749 +
6750 +            if(face_colours.IsNull()
6751 +               || (!(face_colours->GetColor(face,XCAFDoc_ColorSurf,face_colour))))
6752 +            {
6753 +               // Set the default face colour to green (Netgen Standard)
6754 +               // if no colour has been defined for the face
6755 +               face_colour = Quantity_Color(0.0,1.0,0.0,Quantity_TOC_RGB);
6756 +            }
6757 +
6758 +            sff = new ShapeFix_Face (face);
6759 +            sff->FixAddNaturalBoundMode() = Standard_True;
6760 +            sff->FixSmallAreaWireMode() = Standard_True;
6761 +            sff->Perform();
6762 +
6763 +            if(sff->Status(ShapeExtend_DONE1) ||
6764 +               sff->Status(ShapeExtend_DONE2) ||
6765 +               sff->Status(ShapeExtend_DONE3) ||
6766 +               sff->Status(ShapeExtend_DONE4) ||
6767 +               sff->Status(ShapeExtend_DONE5))
6768 +            {
6769 +               std::cout << "repaired face " << fmap.FindIndex(face) << " ";
6770 +               if(sff->Status(ShapeExtend_DONE1))
6771 +                  std::cout << "(some wires are fixed)" <<std::endl;
6772 +               else if(sff->Status(ShapeExtend_DONE2))
6773 +                  std::cout << "(orientation of wires fixed)" <<std::endl;
6774 +               else if(sff->Status(ShapeExtend_DONE3))
6775 +                  std::cout << "(missing seam added)" <<std::endl;
6776 +               else if(sff->Status(ShapeExtend_DONE4))
6777 +                  std::cout << "(small area wire removed)" <<std::endl;
6778 +               else if(sff->Status(ShapeExtend_DONE5))
6779 +                  std::cout << "(natural bounds added)" <<std::endl;
6780 +               TopoDS_Face newface = sff->Face();
6781 +
6782 +               rebuild->Replace(face, newface);
6783 +            }
6784 +
6785 +            // Set the original colour of the face to the newly created 
6786 +            // face (after the healing process)
6787 +            face = TopoDS::Face (exp0.Current());
6788 +            face_colours->SetColor(face,face_colour,XCAFDoc_ColorSurf);
6789 +         }
6790 +         shape = rebuild->Apply(shape);
6791 +      }
6792 +
6793 +
6794 +      {
6795 +         Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
6796 +         rebuild->Apply(shape);
6797 +         for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
6798 +         {
6799 +            TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
6800 +            if ( BRep_Tool::Degenerated(edge) )
6801 +               rebuild->Remove(edge);
6802 +         }
6803 +         shape = rebuild->Apply(shape);
6804 +      }
6805 +
6806 +
6807 +      if (fixsmalledges)
6808 +      {
6809 +         std::cout << std::endl << "- fixing small edges" << std::endl;
6810 +
6811 +         Handle(ShapeFix_Wire) sfw;
6812 +         Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
6813 +         rebuild->Apply(shape);
6814 +
6815 +
6816 +         for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next())
6817 +         {
6818 +            TopoDS_Face face = TopoDS::Face(exp0.Current());
6819 +
6820 +            for (exp1.Init (face, TopAbs_WIRE); exp1.More(); exp1.Next())
6821 +            {
6822 +               TopoDS_Wire oldwire = TopoDS::Wire(exp1.Current());
6823 +               sfw = new ShapeFix_Wire (oldwire, face ,tolerance);
6824 +               sfw->ModifyTopologyMode() = Standard_True;
6825 +
6826 +               sfw->ClosedWireMode() = Standard_True;
6827 +
6828 +               bool replace = false;
6829 +
6830 +               replace = sfw->FixReorder() || replace;
6831 +
6832 +               replace = sfw->FixConnected() || replace;
6833 +
6834 +
6835 +
6836 +               if (sfw->FixSmall (Standard_False, tolerance) && ! (sfw->StatusSmall(ShapeExtend_FAIL1) ||
6837 +                  sfw->StatusSmall(ShapeExtend_FAIL2) ||
6838 +                  sfw->StatusSmall(ShapeExtend_FAIL3)))
6839 +               {
6840 +                  std::cout << "Fixed small edge in wire " << wmap.FindIndex (oldwire) << std::endl;
6841 +                  replace = true;
6842 +
6843 +               }
6844 +               else if (sfw->StatusSmall(ShapeExtend_FAIL1))
6845 +                  cerr << "Failed to fix small edge in wire " << wmap.FindIndex (oldwire)
6846 +                  << ", edge cannot be checked (no 3d curve and no pcurve)" << std::endl;
6847 +               else if (sfw->StatusSmall(ShapeExtend_FAIL2))
6848 +                  cerr << "Failed to fix small edge in wire " << wmap.FindIndex (oldwire)
6849 +                  << ", edge is null-length and has different vertives at begin and end, and lockvtx is True or ModifiyTopologyMode is False" << std::endl;
6850 +               else if (sfw->StatusSmall(ShapeExtend_FAIL3))
6851 +                  cerr << "Failed to fix small edge in wire " << wmap.FindIndex (oldwire)
6852 +                  << ", CdheckConnected has failed" << std::endl;
6853 +
6854 +               replace = sfw->FixEdgeCurves() || replace;
6855 +
6856 +               replace = sfw->FixDegenerated() || replace;
6857 +
6858 +               replace = sfw->FixSelfIntersection() || replace;
6859 +
6860 +               replace = sfw->FixLacking(Standard_True) || replace;
6861 +
6862 +               if(replace)
6863 +               {
6864 +                  TopoDS_Wire newwire = sfw->Wire();
6865 +                  rebuild->Replace(oldwire, newwire);
6866 +               }
6867 +
6868 +               //delete sfw; sfw = NULL;
6869 +
6870 +            }
6871 +         }
6872 +
6873 +         shape = rebuild->Apply(shape);
6874 +
6875 +
6876 +
6877 +         {
6878 +            BuildFMap();
6879 +            Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
6880 +            rebuild->Apply(shape);
6881 +
6882 +            for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
6883 +            {
6884 +               TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
6885 +               if (vmap.FindIndex(TopExp::FirstVertex (edge)) ==
6886 +                  vmap.FindIndex(TopExp::LastVertex (edge)))
6887 +               {
6888 +                  GProp_GProps system;
6889 +                  BRepGProp::LinearProperties(edge, system);
6890 +                  if (system.Mass() < tolerance)
6891 +                  {
6892 +                     std::cout << "removing degenerated edge " << emap.FindIndex(edge)
6893 +                        << " from vertex " << vmap.FindIndex(TopExp::FirstVertex (edge))
6894 +                        << " to vertex " << vmap.FindIndex(TopExp::LastVertex (edge)) << std::endl;
6895 +                     rebuild->Remove(edge);
6896 +                  }
6897 +               }
6898 +            }
6899 +            shape = rebuild->Apply(shape);
6900 +
6901 +            //delete rebuild; rebuild = NULL;
6902 +         }
6903 +
6904 +
6905 +
6906 +         {
6907 +            Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
6908 +            rebuild->Apply(shape);
6909 +            for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
6910 +            {
6911 +               TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
6912 +               if ( BRep_Tool::Degenerated(edge) )
6913 +                  rebuild->Remove(edge);
6914 +            }
6915 +            shape = rebuild->Apply(shape);
6916 +         }
6917 +
6918 +
6919 +
6920 +
6921 +         Handle(ShapeFix_Wireframe) sfwf = new ShapeFix_Wireframe;
6922 +         sfwf->SetPrecision(tolerance);
6923 +         sfwf->Load (shape);
6924 +         sfwf->ModeDropSmallEdges() = Standard_True;
6925 +
6926 +         sfwf->SetPrecision(boundingbox.Diam());
6927 +
6928 +         if (sfwf->FixWireGaps())
6929 +         {
6930 +            std::cout << std::endl << "- fixing wire gaps" << std::endl;
6931 +            if (sfwf->StatusWireGaps(ShapeExtend_OK)) std::cout << "no gaps found" << std::endl;
6932 +            if (sfwf->StatusWireGaps(ShapeExtend_DONE1)) std::cout << "some 2D gaps fixed" << std::endl;
6933 +            if (sfwf->StatusWireGaps(ShapeExtend_DONE2)) std::cout << "some 3D gaps fixed" << std::endl;
6934 +            if (sfwf->StatusWireGaps(ShapeExtend_FAIL1)) std::cout << "failed to fix some 2D gaps" << std::endl;
6935 +            if (sfwf->StatusWireGaps(ShapeExtend_FAIL2)) std::cout << "failed to fix some 3D gaps" << std::endl;
6936 +         }
6937 +
6938 +         sfwf->SetPrecision(tolerance);
6939 +
6940 +
6941 +         {
6942 +            for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
6943 +            {
6944 +               TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
6945 +               if ( BRep_Tool::Degenerated(edge) )
6946 +                  std::cout << "degenerated edge at position 4" << std::endl;
6947 +            }
6948 +         }
6949 +
6950 +
6951 +
6952 +         if (sfwf->FixSmallEdges())
6953 +         {
6954 +            std::cout << std::endl << "- fixing wire frames" << std::endl;
6955 +            if (sfwf->StatusSmallEdges(ShapeExtend_OK)) std::cout << "no small edges found" << std::endl;
6956 +            if (sfwf->StatusSmallEdges(ShapeExtend_DONE1)) std::cout << "some small edges fixed" << std::endl;
6957 +            if (sfwf->StatusSmallEdges(ShapeExtend_FAIL1)) std::cout << "failed to fix some small edges" << std::endl;
6958 +         }
6959 +
6960 +
6961 +
6962 +         shape = sfwf->Shape();
6963 +
6964 +         //delete sfwf; sfwf = NULL;
6965 +         //delete rebuild; rebuild = NULL;
6966 +
6967 +      }
6968 +
6969 +
6970 +
6971 +
6972 +
6973 +      {
6974 +         for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
6975 +         {
6976 +            TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
6977 +            if ( BRep_Tool::Degenerated(edge) )
6978 +               std::cout << "degenerated edge at position 5" << std::endl;
6979 +         }
6980 +      }
6981 +
6982 +
6983 +
6984 +
6985 +      if (fixspotstripfaces)
6986 +      {
6987 +
6988 +         std::cout << std::endl << "- fixing spot and strip faces" << std::endl;
6989 +         Handle(ShapeFix_FixSmallFace) sffsm = new ShapeFix_FixSmallFace();
6990 +         sffsm -> Init (shape);
6991 +         sffsm -> SetPrecision (tolerance);
6992 +         sffsm -> Perform();
6993 +
6994 +         shape = sffsm -> FixShape();
6995 +         //delete sffsm; sffsm = NULL;
6996 +      }
6997 +
6998 +
6999 +      {
7000 +         for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
7001 +         {
7002 +            TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
7003 +            if ( BRep_Tool::Degenerated(edge) )
7004 +               std::cout << "degenerated edge at position 6" << std::endl;
7005 +         }
7006 +      }
7007 +
7008 +
7009 +
7010 +      if (sewfaces)
7011 +      {
7012 +         std::cout << std::endl << "- sewing faces" << std::endl;
7013 +
7014 +         BRepOffsetAPI_Sewing sewedObj(tolerance);
7015 +
7016 +         for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next())
7017 +         {
7018 +            TopoDS_Face face = TopoDS::Face (exp0.Current());
7019 +            sewedObj.Add (face);
7020 +         }
7021 +
7022 +         sewedObj.Perform();
7023 +
7024 +         if (!sewedObj.SewedShape().IsNull())
7025 +            shape = sewedObj.SewedShape();
7026 +         else
7027 +            std::cout << " not possible";
7028 +      }
7029 +
7030 +
7031 +
7032 +      {
7033 +         Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
7034 +         rebuild->Apply(shape);
7035 +         for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
7036 +         {
7037 +            TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
7038 +            if ( BRep_Tool::Degenerated(edge) )
7039 +               rebuild->Remove(edge);
7040 +         }
7041 +         shape = rebuild->Apply(shape);
7042 +      }
7043 +
7044 +
7045 +      if (makesolids)
7046 +      {
7047 +         std::cout << std::endl << "- making solids" << std::endl;
7048 +
7049 +         BRepBuilderAPI_MakeSolid ms;
7050 +         int count = 0;
7051 +         for (exp0.Init(shape, TopAbs_SHELL); exp0.More(); exp0.Next())
7052 +         {
7053 +            count++;
7054 +            ms.Add (TopoDS::Shell(exp0.Current()));
7055 +         }
7056 +
7057 +         if (!count)
7058 +         {
7059 +            std::cout << " not possible (no shells)" << std::endl;
7060 +         }
7061 +         else
7062 +         {
7063 +            BRepCheck_Analyzer ba(ms);
7064 +            if (ba.IsValid ())
7065 +            {
7066 +               Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
7067 +               sfs->Init (ms);
7068 +               sfs->SetPrecision(tolerance);
7069 +               sfs->SetMaxTolerance(tolerance);
7070 +               sfs->Perform();
7071 +               shape = sfs->Shape();
7072 +
7073 +               for (exp0.Init(shape, TopAbs_SOLID); exp0.More(); exp0.Next())
7074 +               {
7075 +                  TopoDS_Solid solid = TopoDS::Solid(exp0.Current());
7076 +                  TopoDS_Solid newsolid = solid;
7077 +                  BRepLib::OrientClosedSolid (newsolid);
7078 +                  Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
7079 +                  //             rebuild->Apply(shape);
7080 +                  rebuild->Replace(solid, newsolid);
7081 +                  TopoDS_Shape newshape = rebuild->Apply(shape, TopAbs_COMPSOLID);//, 1);
7082 +                  //             TopoDS_Shape newshape = rebuild->Apply(shape);
7083 +                  shape = newshape;
7084 +               }
7085 +
7086 +               //delete sfs; sfs = NULL;
7087 +            }
7088 +            else
7089 +               std::cout << " not possible" << std::endl;
7090 +         }
7091 +      }
7092 +
7093 +
7094 +
7095 +      if (splitpartitions)
7096 +      {
7097 +         std::cout << "- running SALOME partition splitter" << std::endl;
7098 +
7099 +         TopExp_Explorer e2;
7100 +         Partition_Spliter ps;
7101 +         int count = 0;
7102 +
7103 +         for (e2.Init (shape, TopAbs_SOLID);
7104 +            e2.More(); e2.Next())
7105 +         {
7106 +            count++;
7107 +            ps.AddShape (e2.Current());
7108 +         }
7109 +
7110 +         ps.Compute();
7111 +         shape = ps.Shape();
7112 +
7113 +         std::cout << " before: " << count << " solids" << std::endl;
7114 +
7115 +         count = 0;
7116 +         for (e2.Init (shape, TopAbs_SOLID);
7117 +            e2.More(); e2.Next()) count++;
7118 +
7119 +            std::cout << " after : " << count << " solids" << std::endl;
7120 +      }
7121 +
7122 +      BuildFMap();
7123 +
7124 +
7125 +
7126 +      {
7127 +         for (exp1.Init (shape, TopAbs_EDGE); exp1.More(); exp1.Next())
7128 +         {
7129 +            TopoDS_Edge edge = TopoDS::Edge(exp1.Current());
7130 +            if ( BRep_Tool::Degenerated(edge) )
7131 +               std::cout << "degenerated edge at position 8" << std::endl;
7132 +         }
7133 +      }
7134 +
7135 +
7136 +      double newsurfacecont = 0;
7137 +
7138 +
7139 +      for (exp0.Init (shape, TopAbs_FACE); exp0.More(); exp0.Next())
7140 +      {
7141 +         TopoDS_Face face = TopoDS::Face(exp0.Current());
7142 +         GProp_GProps system;
7143 +         BRepGProp::SurfaceProperties(face, system);
7144 +         newsurfacecont += system.Mass();
7145 +      }
7146 +
7147 +
7148 +      int nnrc = 0, nnrcs = 0,
7149 +         nnrso = somap.Extent(),
7150 +         nnrsh = shmap.Extent(),
7151 +         nnrf = fmap.Extent(),
7152 +         nnrw = wmap.Extent(),
7153 +         nnre = emap.Extent(),
7154 +         nnrv = vmap.Extent();
7155 +
7156 +      for (exp0.Init(shape, TopAbs_COMPOUND); exp0.More(); exp0.Next()) nnrc++;
7157 +      for (exp0.Init(shape, TopAbs_COMPSOLID); exp0.More(); exp0.Next()) nnrcs++;
7158 +
7159 +      std::cout << "-----------------------------------" << std::endl;
7160 +      std::cout << "Compounds       : " << nnrc << " (" << nrc << ")" << std::endl;
7161 +      std::cout << "Composite solids: " << nnrcs << " (" << nrcs << ")" << std::endl;
7162 +      std::cout << "Solids          : " << nnrso << " (" << nrso << ")" << std::endl;
7163 +      std::cout << "Shells          : " << nnrsh << " (" << nrsh << ")" << std::endl;
7164 +      std::cout << "Wires           : " << nnrw << " (" << nrw << ")" << std::endl;
7165 +      std::cout << "Faces           : " << nnrf << " (" << nrf << ")" << std::endl;
7166 +      std::cout << "Edges           : " << nnre << " (" << nre << ")" << std::endl;
7167 +      std::cout << "Vertices        : " << nnrv << " (" << nrv << ")" << std::endl;
7168 +      std::cout << std::endl;
7169 +      std::cout << "Totol surface area : " << newsurfacecont << " (" << surfacecont << ")" << std::endl;
7170 +      std::cout << std::endl;
7171 +   }
7172 +
7173 +
7174 +
7175 +
7176 +   void OCCGeometry :: BuildFMap()
7177 +   {
7178 +      somap.Clear();
7179 +      shmap.Clear();
7180 +      fmap.Clear();
7181 +      wmap.Clear();
7182 +      emap.Clear();
7183 +      vmap.Clear();
7184 +
7185 +      TopExp_Explorer exp0, exp1, exp2, exp3, exp4, exp5;
7186 +
7187 +      for (exp0.Init(shape, TopAbs_COMPOUND);
7188 +         exp0.More(); exp0.Next())
7189 +      {
7190 +         TopoDS_Compound compound = TopoDS::Compound (exp0.Current());
7191 +         (*testout) << "compound" << std::endl;
7192 +         int i = 0;
7193 +         for (exp1.Init(compound, TopAbs_SHELL);
7194 +            exp1.More(); exp1.Next())
7195 +         {
7196 +            (*testout) << "shell " << ++i << std::endl;
7197 +         }
7198 +      }
7199 +
7200 +      for (exp0.Init(shape, TopAbs_SOLID);
7201 +         exp0.More(); exp0.Next())
7202 +      {
7203 +         TopoDS_Solid solid = TopoDS::Solid (exp0.Current());
7204 +
7205 +         if (somap.FindIndex(solid) < 1)
7206 +         {
7207 +            somap.Add (solid);
7208 +
7209 +            for (exp1.Init(solid, TopAbs_SHELL);
7210 +               exp1.More(); exp1.Next())
7211 +            {
7212 +               TopoDS_Shell shell = TopoDS::Shell (exp1.Current());
7213 +               if (shmap.FindIndex(shell) < 1)
7214 +               {
7215 +                  shmap.Add (shell);
7216 +
7217 +                  for (exp2.Init(shell, TopAbs_FACE);
7218 +                     exp2.More(); exp2.Next())
7219 +                  {
7220 +                     TopoDS_Face face = TopoDS::Face(exp2.Current());
7221 +                     if (fmap.FindIndex(face) < 1)
7222 +                     {
7223 +                        fmap.Add (face);
7224 +                        (*testout) << "face " << fmap.FindIndex(face) << " ";
7225 +                        (*testout) << ((face.Orientation() == TopAbs_REVERSED) ? "-" : "+") << ", ";
7226 +                        (*testout) << ((exp2.Current().Orientation() == TopAbs_REVERSED) ? "-" : "+") << std::endl;
7227 +                        for (exp3.Init(exp2.Current(), TopAbs_WIRE);
7228 +                           exp3.More(); exp3.Next())
7229 +                        {
7230 +                           TopoDS_Wire wire = TopoDS::Wire (exp3.Current());
7231 +                           if (wmap.FindIndex(wire) < 1)
7232 +                           {
7233 +                              wmap.Add (wire);
7234 +
7235 +                              for (exp4.Init(exp3.Current(), TopAbs_EDGE);
7236 +                                 exp4.More(); exp4.Next())
7237 +                              {
7238 +                                 TopoDS_Edge edge = TopoDS::Edge(exp4.Current());
7239 +                                 if (emap.FindIndex(edge) < 1)
7240 +                                 {
7241 +                                    emap.Add (edge);
7242 +                                    for (exp5.Init(exp4.Current(), TopAbs_VERTEX);
7243 +                                       exp5.More(); exp5.Next())
7244 +                                    {
7245 +                                       TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
7246 +                                       if (vmap.FindIndex(vertex) < 1)
7247 +                                          vmap.Add (vertex);
7248 +                                    }
7249 +                                 }
7250 +                              }
7251 +                           }
7252 +                        }
7253 +                     }
7254 +                  }
7255 +               }
7256 +            }
7257 +         }
7258 +      }
7259 +
7260 +      // Free Shells
7261 +      for (exp1.Init(shape, TopAbs_SHELL, TopAbs_SOLID); exp1.More(); exp1.Next())
7262 +      {
7263 +         TopoDS_Shell shell = TopoDS::Shell(exp1.Current());
7264 +         if (shmap.FindIndex(shell) < 1)
7265 +         {
7266 +            shmap.Add (shell);
7267 +
7268 +            (*testout) << "shell " << shmap.FindIndex(shell) << " ";
7269 +            (*testout) << ((shell.Orientation() == TopAbs_REVERSED) ? "-" : "+") << ", ";
7270 +            (*testout) << ((exp1.Current().Orientation() == TopAbs_REVERSED) ? "-" : "+") << std::endl;
7271 +
7272 +            for (exp2.Init(shell, TopAbs_FACE); exp2.More(); exp2.Next())
7273 +            {
7274 +               TopoDS_Face face = TopoDS::Face(exp2.Current());
7275 +               if (fmap.FindIndex(face) < 1)
7276 +               {
7277 +                  fmap.Add (face);
7278 +
7279 +                  for (exp3.Init(face, TopAbs_WIRE); exp3.More(); exp3.Next())
7280 +                  {
7281 +                     TopoDS_Wire wire = TopoDS::Wire (exp3.Current());
7282 +                     if (wmap.FindIndex(wire) < 1)
7283 +                     {
7284 +                        wmap.Add (wire);
7285 +
7286 +                        for (exp4.Init(wire, TopAbs_EDGE); exp4.More(); exp4.Next())
7287 +                        {
7288 +                           TopoDS_Edge edge = TopoDS::Edge(exp4.Current());
7289 +                           if (emap.FindIndex(edge) < 1)
7290 +                           {
7291 +                              emap.Add (edge);
7292 +                              for (exp5.Init(edge, TopAbs_VERTEX); exp5.More(); exp5.Next())
7293 +                              {
7294 +                                 TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
7295 +                                 if (vmap.FindIndex(vertex) < 1)
7296 +                                    vmap.Add (vertex);
7297 +                              }
7298 +                           }
7299 +                        }
7300 +                     }
7301 +                  }
7302 +               }
7303 +            }
7304 +         }
7305 +      }
7306 +
7307 +
7308 +      // Free Faces
7309 +
7310 +      for (exp2.Init(shape, TopAbs_FACE, TopAbs_SHELL); exp2.More(); exp2.Next())
7311 +      {
7312 +         TopoDS_Face face = TopoDS::Face(exp2.Current());
7313 +         if (fmap.FindIndex(face) < 1)
7314 +         {
7315 +            fmap.Add (face);
7316 +
7317 +            for (exp3.Init(exp2.Current(), TopAbs_WIRE); exp3.More(); exp3.Next())
7318 +            {
7319 +               TopoDS_Wire wire = TopoDS::Wire (exp3.Current());
7320 +               if (wmap.FindIndex(wire) < 1)
7321 +               {
7322 +                  wmap.Add (wire);
7323 +
7324 +                  for (exp4.Init(exp3.Current(), TopAbs_EDGE); exp4.More(); exp4.Next())
7325 +                  {
7326 +                     TopoDS_Edge edge = TopoDS::Edge(exp4.Current());
7327 +                     if (emap.FindIndex(edge) < 1)
7328 +                     {
7329 +                        emap.Add (edge);
7330 +                        for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next())
7331 +                        {
7332 +                           TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
7333 +                           if (vmap.FindIndex(vertex) < 1)
7334 +                              vmap.Add (vertex);
7335 +                        }
7336 +                     }
7337 +                  }
7338 +               }
7339 +            }
7340 +         }
7341 +      }
7342 +
7343 +
7344 +      // Free Wires
7345 +
7346 +      for (exp3.Init(shape, TopAbs_WIRE, TopAbs_FACE); exp3.More(); exp3.Next())
7347 +      {
7348 +         TopoDS_Wire wire = TopoDS::Wire (exp3.Current());
7349 +         if (wmap.FindIndex(wire) < 1)
7350 +         {
7351 +            wmap.Add (wire);
7352 +
7353 +            for (exp4.Init(exp3.Current(), TopAbs_EDGE); exp4.More(); exp4.Next())
7354 +            {
7355 +               TopoDS_Edge edge = TopoDS::Edge(exp4.Current());
7356 +               if (emap.FindIndex(edge) < 1)
7357 +               {
7358 +                  emap.Add (edge);
7359 +                  for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next())
7360 +                  {
7361 +                     TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
7362 +                     if (vmap.FindIndex(vertex) < 1)
7363 +                        vmap.Add (vertex);
7364 +                  }
7365 +               }
7366 +            }
7367 +         }
7368 +      }
7369 +
7370 +
7371 +      // Free Edges
7372 +
7373 +      for (exp4.Init(shape, TopAbs_EDGE, TopAbs_WIRE); exp4.More(); exp4.Next())
7374 +      {
7375 +         TopoDS_Edge edge = TopoDS::Edge(exp4.Current());
7376 +         if (emap.FindIndex(edge) < 1)
7377 +         {
7378 +            emap.Add (edge);
7379 +            for (exp5.Init(exp4.Current(), TopAbs_VERTEX); exp5.More(); exp5.Next())
7380 +            {
7381 +               TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
7382 +               if (vmap.FindIndex(vertex) < 1)
7383 +                  vmap.Add (vertex);
7384 +            }
7385 +         }
7386 +      }
7387 +
7388 +
7389 +      // Free Vertices
7390 +
7391 +      for (exp5.Init(shape, TopAbs_VERTEX, TopAbs_EDGE); exp5.More(); exp5.Next())
7392 +      {
7393 +         TopoDS_Vertex vertex = TopoDS::Vertex(exp5.Current());
7394 +         if (vmap.FindIndex(vertex) < 1)
7395 +            vmap.Add (vertex);
7396 +      }
7397 +
7398 +
7399 +
7400 +
7401 +      facemeshstatus.DeleteAll();
7402 +      facemeshstatus.SetSize (fmap.Extent());
7403 +      facemeshstatus = 0;
7404 +
7405 +      // Philippose - 15/01/2009
7406 +      face_maxh.DeleteAll();
7407 +      face_maxh.SetSize (fmap.Extent());
7408 +      face_maxh = mparam.maxh;
7409 +
7410 +      // Philippose - 15/01/2010      
7411 +      face_maxh_modified.DeleteAll();      
7412 +      face_maxh_modified.SetSize(fmap.Extent());      
7413 +      face_maxh_modified = 0;
7414 +      
7415 +
7416 +      // Philippose - 17/01/2009
7417 +      face_sel_status.DeleteAll();
7418 +      face_sel_status.SetSize (fmap.Extent());
7419 +      face_sel_status = 0;
7420 +
7421 +      fvispar.SetSize (fmap.Extent());
7422 +      evispar.SetSize (emap.Extent());
7423 +      vvispar.SetSize (vmap.Extent());
7424 +
7425 +      fsingular.SetSize (fmap.Extent());
7426 +      esingular.SetSize (emap.Extent());
7427 +      vsingular.SetSize (vmap.Extent());
7428 +
7429 +      fsingular = esingular = vsingular = false;
7430 +   }
7431 +
7432 +
7433 +
7434 +   void OCCGeometry :: SewFaces ()
7435 +   {
7436 +      (*testout) << "Trying to sew faces ..." << std::endl;
7437 +      std::cout << "Trying to sew faces ..." << flush;
7438 +
7439 +      BRepOffsetAPI_Sewing sewedObj(1);
7440
7441 +      for (int i = 1; i <= fmap.Extent(); i++)
7442 +      {
7443 +         TopoDS_Face face = TopoDS::Face (fmap(i));
7444 +         sewedObj.Add (face);
7445 +      }
7446 +
7447 +      sewedObj.Perform();
7448 +
7449 +      if (!sewedObj.SewedShape().IsNull())
7450 +      {
7451 +         shape = sewedObj.SewedShape();
7452 +         std::cout << " done" << std::endl;
7453 +      }
7454 +      else
7455 +         std::cout << " not possible";
7456 +   }
7457 +
7458 +
7459 +
7460 +
7461 +
7462 +   void OCCGeometry :: MakeSolid ()
7463 +   {
7464 +      TopExp_Explorer exp0;
7465 +
7466 +      (*testout) << "Trying to build solids ..." << std::endl;
7467 +      std::cout << "Trying to build solids ..." << flush;
7468 +
7469 +      BRepBuilderAPI_MakeSolid ms;
7470 +      int count = 0;
7471 +      for (exp0.Init(shape, TopAbs_SHELL); exp0.More(); exp0.Next())
7472 +      {
7473 +         count++;
7474 +         ms.Add (TopoDS::Shell(exp0.Current()));
7475 +      }
7476 +
7477 +      if (!count)
7478 +      {
7479 +         std::cout << " not possible (no shells)" << std::endl;
7480 +         return;
7481 +      }
7482 +
7483 +      BRepCheck_Analyzer ba(ms);
7484 +      if (ba.IsValid ())
7485 +      {
7486 +         Handle(ShapeFix_Shape) sfs = new ShapeFix_Shape;
7487 +         sfs->Init (ms);
7488 +
7489 +         sfs->SetPrecision(1e-5);
7490 +         sfs->SetMaxTolerance(1e-5);
7491 +
7492 +         sfs->Perform();
7493 +
7494 +         shape = sfs->Shape();
7495 +
7496 +         for (exp0.Init(shape, TopAbs_SOLID); exp0.More(); exp0.Next())
7497 +         {
7498 +            TopoDS_Solid solid = TopoDS::Solid(exp0.Current());
7499 +            TopoDS_Solid newsolid = solid;
7500 +            BRepLib::OrientClosedSolid (newsolid);
7501 +            Handle(ShapeBuild_ReShape) rebuild = new ShapeBuild_ReShape;
7502 +            rebuild->Replace(solid, newsolid);
7503 +
7504 +            TopoDS_Shape newshape = rebuild->Apply(shape, TopAbs_SHAPE, 1);
7505 +            shape = newshape;
7506 +         }
7507 +
7508 +         std::cout << " done" << std::endl;
7509 +      }
7510 +      else
7511 +         std::cout << " not possible" << std::endl;
7512 +   }
7513 +
7514 +
7515 +
7516 +
7517 +   void OCCGeometry :: BuildVisualizationMesh (double deflection)
7518 +   {
7519 +      std::cout << "Preparing visualization (deflection = " << deflection << ") ... " << flush;
7520 +
7521 +      BRepTools::Clean (shape);
7522 +      // BRepMesh_IncrementalMesh::
7523 +      BRepMesh_IncrementalMesh (shape, deflection, true);
7524 +      std::cout << "done" << std::endl;
7525 +   }
7526 +
7527 +
7528 +
7529 +
7530 +   void OCCGeometry :: CalcBoundingBox ()
7531 +   {
7532 +      Bnd_Box bb;
7533 +      BRepBndLib::Add (shape, bb);
7534 +
7535 +      double x1,y1,z1,x2,y2,z2;
7536 +      bb.Get (x1,y1,z1,x2,y2,z2);
7537 +      Point<3> p1 = Point<3> (x1,y1,z1);
7538 +      Point<3> p2 = Point<3> (x2,y2,z2);
7539 +
7540 +      (*testout) << "Bounding Box = [" << p1 << " - " << p2 << "]" << std::endl;
7541 +      boundingbox = Box<3> (p1,p2);
7542 +      SetCenter();
7543 +   }
7544 +
7545 +
7546 +   // returns a projector and a classifier for the given surface
7547 +   void OCCGeometry::GetFaceTools(int surfi, Handle(ShapeAnalysis_Surface)& proj,
7548 +                                  BRepTopAdaptor_FClass2d*& cls) const
7549 +   {
7550 +     //MSV: organize caching projector in the map
7551 +     if (fprjmap.IsBound(surfi))
7552 +     {
7553 +       proj = fprjmap.Find(surfi);
7554 +       cls = fclsmap.Find(surfi);
7555 +     }
7556 +     else
7557 +     {
7558 +       const TopoDS_Face& aFace = TopoDS::Face(fmap(surfi));
7559 +       Handle(Geom_Surface) aSurf = BRep_Tool::Surface(aFace);
7560 +       proj = new ShapeAnalysis_Surface(aSurf);
7561 +       fprjmap.Bind(surfi, proj);
7562 +       cls = new BRepTopAdaptor_FClass2d(aFace,Precision::Confusion());
7563 +       fclsmap.Bind(surfi, cls);
7564 +     }
7565 +   }
7566 +
7567 +   // void OCCGeometry :: Project (int surfi, Point<3> & p) const
7568 +   bool OCCGeometry :: Project (int surfi, Point<3> & p, double& u, double& v) const
7569 +   {
7570 +      static int cnt = 0;
7571 +      if (++cnt % 1000 == 0) std::cout << "Project cnt = " << cnt << std::endl;
7572 +
7573 +      gp_Pnt pnt(p(0), p(1), p(2));
7574 +
7575 +      // -- Optimization: use cached projector and classifier
7576 +      // double u,v;
7577 +      // Handle( Geom_Surface ) thesurf = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));
7578 +      // Handle( ShapeAnalysis_Surface ) su = new ShapeAnalysis_Surface( thesurf );
7579 +      // gp_Pnt2d suval = su->ValueOfUV ( pnt, BRep_Tool::Tolerance( TopoDS::Face(fmap(surfi)) ) );
7580 +      // suval.Coord( u, v);
7581 +      // pnt = thesurf->Value( u, v );  
7582 +
7583 +      Handle(ShapeAnalysis_Surface) proj;
7584 +      BRepTopAdaptor_FClass2d *cls;
7585 +      GetFaceTools(surfi, proj, cls);
7586 +
7587 +      gp_Pnt2d p2d = proj->ValueOfUV(pnt, Precision::Confusion());
7588 +      if (cls->Perform(p2d) == TopAbs_OUT)
7589 +      {
7590 +        return false;
7591 +      }
7592 +      pnt = proj->Value(p2d);
7593 +      p2d.Coord(u, v);
7594 +
7595 +      p = Point<3> (pnt.X(), pnt.Y(), pnt.Z());
7596 +
7597 +      return true;
7598 +   }
7599 +
7600 +
7601 +
7602 +
7603 +   bool OCCGeometry :: FastProject (int surfi, Point<3> & ap, double& u, double& v) const
7604 +   {
7605 +      gp_Pnt p(ap(0), ap(1), ap(2));
7606 +
7607 +      // -- Optimization: use cached projector and classifier
7608 +      // Handle(Geom_Surface) surface = BRep_Tool::Surface(TopoDS::Face(fmap(surfi)));
7609 +      // 
7610 +      // gp_Pnt x = surface->Value (u,v);
7611 +      // 
7612 +      // if (p.SquareDistance(x) <= sqr(PROJECTION_TOLERANCE)) return true;
7613 +      // 
7614 +      // gp_Vec du, dv;
7615 +      // 
7616 +      // surface->D1(u,v,x,du,dv);
7617 +      // 
7618 +      // int count = 0;
7619 +      // 
7620 +      // gp_Pnt xold;
7621 +      // gp_Vec n;
7622 +      // double det, lambda, mu;
7623 +      // 
7624 +      // do {
7625 +      //    count++;
7626 +      // 
7627 +      //    n = du^dv;
7628 +      // 
7629 +      //    det = Det3 (n.X(), du.X(), dv.X(),
7630 +      //       n.Y(), du.Y(), dv.Y(),
7631 +      //       n.Z(), du.Z(), dv.Z());
7632 +      // 
7633 +      //    if (det < 1e-15) return false;
7634 +      // 
7635 +      //    lambda = Det3 (n.X(), p.X()-x.X(), dv.X(),
7636 +      //       n.Y(), p.Y()-x.Y(), dv.Y(),
7637 +      //       n.Z(), p.Z()-x.Z(), dv.Z())/det;
7638 +      // 
7639 +      //    mu     = Det3 (n.X(), du.X(), p.X()-x.X(),
7640 +      //       n.Y(), du.Y(), p.Y()-x.Y(),
7641 +      //       n.Z(), du.Z(), p.Z()-x.Z())/det;
7642 +      // 
7643 +      //    u += lambda;
7644 +      //    v += mu;
7645 +      // 
7646 +      //    xold = x;
7647 +      //    surface->D1(u,v,x,du,dv);
7648 +      // 
7649 +      // } while (xold.SquareDistance(x) > sqr(PROJECTION_TOLERANCE) && count < 50);
7650 +      // 
7651 +      // //    (*testout) << "FastProject count: " << count << std::endl;
7652 +      // 
7653 +      // if (count == 50) return false;
7654 +      // 
7655 +      // ap = Point<3> (x.X(), x.Y(), x.Z());
7656 +      Handle(ShapeAnalysis_Surface) proj;
7657 +      BRepTopAdaptor_FClass2d *cls;
7658 +      GetFaceTools(surfi, proj, cls);
7659 +
7660 +      gp_Pnt2d p2d = proj->NextValueOfUV(gp_Pnt2d(u,v), p, Precision::Confusion());
7661 +      if (cls->Perform(p2d) == TopAbs_OUT)
7662 +      {
7663 +        //std::cout << "Projection fails" << std::endl;
7664 +        return false;
7665 +      }
7666 +
7667 +      p = proj->Value(p2d);
7668 +      p2d.Coord(u, v);
7669 +      ap = Point<3> (p.X(), p.Y(), p.Z());
7670 +
7671 +      return true;
7672 +   }
7673 +
7674 +
7675 +
7676 +
7677 +   void OCCGeometry :: WriteOCC_STL(char * filename)
7678 +   {
7679 +      std::cout << "writing stl..."; std::cout.flush();
7680 +      StlAPI_Writer writer;
7681 +      //writer.RelativeMode() = Standard_False;
7682 +
7683 +      //writer.SetDeflection(0.02);
7684 +      writer.Write(shape,filename);
7685 +
7686 +      std::cout << "done" << std::endl;
7687 +   }
7688 +
7689 +
7690 +
7691 +   // Philippose - 23/02/2009
7692 +   /* Special IGES File load function including the ability
7693 +   to extract individual surface colours via the extended
7694 +   OpenCascade XDE and XCAF Feature set.
7695 +   */
7696 +   OCCGeometry *LoadOCC_IGES(const char *filename)
7697 +   {
7698 +      OCCGeometry *occgeo;
7699 +      occgeo = new OCCGeometry;
7700 +
7701 +      // Initiate a dummy XCAF Application to handle the IGES XCAF Document
7702 +      static Handle(XCAFApp_Application) dummy_app = XCAFApp_Application::GetApplication();
7703 +
7704 +      // Create an XCAF Document to contain the IGES file itself
7705 +      Handle(TDocStd_Document) iges_doc;
7706 +
7707 +      // Check if a IGES File is already open under this handle, if so, close it to prevent
7708 +      // Segmentation Faults when trying to create a new document
7709 +      if(dummy_app->NbDocuments() > 0)
7710 +      {
7711 +         dummy_app->GetDocument(1,iges_doc);
7712 +         dummy_app->Close(iges_doc);
7713 +      }
7714 +      dummy_app->NewDocument ("IGES-XCAF",iges_doc);
7715 +
7716 +      IGESCAFControl_Reader reader;
7717 +
7718 +      Standard_Integer stat = reader.ReadFile((char*)filename);
7719 +
7720 +      if(stat != IFSelect_RetDone)
7721 +      {
7722 +         delete occgeo;
7723 +         return NULL;
7724 +      }
7725 +
7726 +      // Enable transfer of colours
7727 +      reader.SetColorMode(Standard_True);
7728 +
7729 +      reader.Transfer(iges_doc);
7730 +
7731 +      // Read in the shape(s) and the colours present in the IGES File
7732 +      Handle(XCAFDoc_ShapeTool) iges_shape_contents = XCAFDoc_DocumentTool::ShapeTool(iges_doc->Main());
7733 +      Handle(XCAFDoc_ColorTool) iges_colour_contents = XCAFDoc_DocumentTool::ColorTool(iges_doc->Main());
7734 +
7735 +      TDF_LabelSequence iges_shapes;
7736 +      iges_shape_contents->GetShapes(iges_shapes);
7737 +
7738 +      // List out the available colours in the IGES File as Colour Names
7739 +      TDF_LabelSequence all_colours;
7740 +      iges_colour_contents->GetColors(all_colours);
7741 +      PrintMessage(1,"Number of colours in IGES File: ",all_colours.Length());
7742 +      for(int i = 1; i <= all_colours.Length(); i++)
7743 +      {
7744 +         Quantity_Color col;
7745 +         stringstream col_rgb;
7746 +         iges_colour_contents->GetColor(all_colours.Value(i),col);
7747 +         col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")";
7748 +         PrintMessage(1, "Colour [", i, "] = ",col.StringName(col.Name()),col_rgb.str());
7749 +      }
7750 +
7751 +
7752 +      // For the IGES Reader, all the shapes can be exported as one compund shape 
7753 +      // using the "OneShape" member
7754 +      occgeo->shape = reader.OneShape();
7755 +      occgeo->face_colours = iges_colour_contents;
7756 +      occgeo->changed = 1;
7757 +      occgeo->BuildFMap();
7758 +
7759 +      occgeo->CalcBoundingBox();
7760 +      PrintContents (occgeo);
7761 +
7762 +      return occgeo;
7763 +   }
7764 +
7765 +
7766 +
7767 +
7768 +
7769 +   // Philippose - 29/01/2009
7770 +   /* Special STEP File load function including the ability
7771 +   to extract individual surface colours via the extended
7772 +   OpenCascade XDE and XCAF Feature set.
7773 +   */
7774 +   OCCGeometry * LoadOCC_STEP (const char * filename)
7775 +   {
7776 +      OCCGeometry * occgeo;
7777 +      occgeo = new OCCGeometry;
7778 +
7779 +      // Initiate a dummy XCAF Application to handle the STEP XCAF Document
7780 +      static Handle(XCAFApp_Application) dummy_app = XCAFApp_Application::GetApplication();
7781 +
7782 +      // Create an XCAF Document to contain the STEP file itself
7783 +      Handle(TDocStd_Document) step_doc;
7784 +
7785 +      // Check if a STEP File is already open under this handle, if so, close it to prevent
7786 +      // Segmentation Faults when trying to create a new document
7787 +      if(dummy_app->NbDocuments() > 0)
7788 +      {
7789 +         dummy_app->GetDocument(1,step_doc);
7790 +         dummy_app->Close(step_doc);
7791 +      }
7792 +      dummy_app->NewDocument ("STEP-XCAF",step_doc);
7793 +
7794 +      STEPCAFControl_Reader reader;
7795 +
7796 +      // Enable transfer of colours
7797 +      reader.SetColorMode(Standard_True);
7798 +
7799 +      Standard_Integer stat = reader.ReadFile((char*)filename);
7800 +
7801 +      if(stat != IFSelect_RetDone)
7802 +      {
7803 +         delete occgeo;
7804 +         return NULL;
7805 +      }
7806 +
7807 +      reader.Transfer(step_doc);
7808 +
7809 +      // Read in the shape(s) and the colours present in the STEP File
7810 +      Handle(XCAFDoc_ShapeTool) step_shape_contents = XCAFDoc_DocumentTool::ShapeTool(step_doc->Main());
7811 +      Handle(XCAFDoc_ColorTool) step_colour_contents = XCAFDoc_DocumentTool::ColorTool(step_doc->Main());
7812 +
7813 +      TDF_LabelSequence step_shapes;
7814 +      step_shape_contents->GetShapes(step_shapes);
7815 +
7816 +      // List out the available colours in the STEP File as Colour Names
7817 +      TDF_LabelSequence all_colours;
7818 +      step_colour_contents->GetColors(all_colours);
7819 +      PrintMessage(1,"Number of colours in STEP File: ",all_colours.Length());
7820 +      for(int i = 1; i <= all_colours.Length(); i++)
7821 +      {
7822 +         Quantity_Color col;
7823 +         stringstream col_rgb;
7824 +         step_colour_contents->GetColor(all_colours.Value(i),col);
7825 +         col_rgb << " : (" << col.Red() << "," << col.Green() << "," << col.Blue() << ")";
7826 +         PrintMessage(1, "Colour [", i, "] = ",col.StringName(col.Name()),col_rgb.str());
7827 +      }
7828 +
7829 +
7830 +      // For the STEP File Reader in OCC, the 1st Shape contains the entire 
7831 +      // compound geometry as one shape
7832 +      occgeo->shape = step_shape_contents->GetShape(step_shapes.Value(1));
7833 +      occgeo->face_colours = step_colour_contents;
7834 +      occgeo->changed = 1;
7835 +      occgeo->BuildFMap();
7836 +
7837 +      occgeo->CalcBoundingBox();
7838 +      PrintContents (occgeo);
7839 +
7840 +      return occgeo;
7841 +   }
7842 +
7843 +
7844 +
7845 +
7846 +   OCCGeometry *LoadOCC_BREP (const char *filename)
7847 +   {
7848 +      OCCGeometry * occgeo;
7849 +      occgeo = new OCCGeometry;
7850 +
7851 +      BRep_Builder aBuilder;
7852 +      Standard_Boolean result = BRepTools::Read(occgeo->shape, const_cast<char*> (filename),aBuilder);
7853 +
7854 +      if(!result)
7855 +      {
7856 +         delete occgeo;
7857 +         return NULL;
7858 +      }
7859 +
7860 +      // Philippose - 23/02/2009
7861 +      // Fixed a bug in the OpenCascade XDE Colour handling when 
7862 +      // opening BREP Files, since BREP Files have no colour data.
7863 +      // Hence, the face_colours Handle needs to be created as a NULL handle.
7864 +      occgeo->face_colours = Handle(XCAFDoc_ColorTool)();
7865 +      occgeo->face_colours.Nullify();
7866 +      occgeo->changed = 1;
7867 +      occgeo->BuildFMap();
7868 +
7869 +      occgeo->CalcBoundingBox();
7870 +      PrintContents (occgeo);
7871 +
7872 +      return occgeo;
7873 +   }
7874 +
7875 +
7876 +  void OCCGeometry :: Save (string sfilename) const
7877 +  {
7878 +    const char * filename = sfilename.c_str();
7879 +    if (strlen(filename) < 4) 
7880 +      throw NgException ("illegal filename");
7881 +    
7882 +    if (strcmp (&filename[strlen(filename)-3], "igs") == 0)
7883 +      {
7884 +       IGESControl_Writer writer("millimeters", 1);
7885 +       writer.AddShape (shape);
7886 +       writer.Write (filename);
7887 +      }
7888 +    else if (strcmp (&filename[strlen(filename)-3], "stp") == 0)
7889 +      {
7890 +       STEPControl_Writer writer;
7891 +       writer.Transfer (shape, STEPControl_AsIs);
7892 +       writer.Write (filename);
7893 +      }
7894 +    else if (strcmp (&filename[strlen(filename)-3], "stl") == 0)
7895 +      {
7896 +       StlAPI_Writer writer;
7897 +       writer.ASCIIMode() = Standard_True;
7898 +       writer.Write (shape, filename);
7899 +      }
7900 +    else if (strcmp (&filename[strlen(filename)-4], "stlb") == 0)
7901 +      {
7902 +       StlAPI_Writer writer;
7903 +       writer.ASCIIMode() = Standard_False;
7904 +       writer.Write (shape, filename);
7905 +      }
7906 +  }
7907 +
7908 +
7909 +
7910 +  const char * shapesname[] =
7911 +   {" ", "CompSolids", "Solids", "Shells",
7912 +
7913 +   "Faces", "Wires", "Edges", "Vertices"};
7914 +
7915 +  const char * shapename[] =
7916 +   {" ", "CompSolid", "Solid", "Shell",
7917 +   "Face", "Wire", "Edge", "Vertex"};
7918 +
7919 +  const char * orientationstring[] =
7920 +     {"+", "-"};
7921 +
7922 +
7923 +
7924 +
7925 +   void OCCGeometry :: RecursiveTopologyTree (const TopoDS_Shape & sh,
7926 +      stringstream & str,
7927 +      TopAbs_ShapeEnum l,
7928 +      bool isfree,
7929 +      const char * lname)
7930 +   {
7931 +      if (l > TopAbs_VERTEX) return;
7932 +
7933 +      TopExp_Explorer e;
7934 +      int count = 0;
7935 +      int count2 = 0;
7936 +
7937 +      if (isfree)
7938 +         e.Init(sh, l, TopAbs_ShapeEnum(l-1));
7939 +      else
7940 +         e.Init(sh, l);
7941 +
7942 +      for (; e.More(); e.Next())
7943 +      {
7944 +         count++;
7945 +
7946 +         stringstream lname2;
7947 +         lname2 << lname << "/" << shapename[l] << count;
7948 +         str << lname2.str() << " ";
7949 +
7950 +         switch (e.Current().ShapeType())
7951 +          {
7952 +          case TopAbs_SOLID:
7953 +            count2 = somap.FindIndex(TopoDS::Solid(e.Current())); break;
7954 +          case TopAbs_SHELL:
7955 +            count2 = shmap.FindIndex(TopoDS::Shell(e.Current())); break;
7956 +          case TopAbs_FACE:
7957 +            count2 = fmap.FindIndex(TopoDS::Face(e.Current())); break;
7958 +          case TopAbs_WIRE:
7959 +            count2 = wmap.FindIndex(TopoDS::Wire(e.Current())); break;
7960 +          case TopAbs_EDGE:
7961 +            count2 = emap.FindIndex(TopoDS::Edge(e.Current())); break;
7962 +          case TopAbs_VERTEX:
7963 +            count2 = vmap.FindIndex(TopoDS::Vertex(e.Current())); break;
7964 +          default:
7965 +            std::cout << "RecursiveTopologyTree: Case " << e.Current().ShapeType() << " not handeled" << std::endl;
7966 +         }
7967 +
7968 +         int nrsubshapes = 0;
7969 +
7970 +         if (l <= TopAbs_WIRE)
7971 +         {
7972 +            TopExp_Explorer e2;
7973 +            for (e2.Init (e.Current(), TopAbs_ShapeEnum (l+1));
7974 +               e2.More(); e2.Next())
7975 +               nrsubshapes++;
7976 +         }
7977 +
7978 +         str << "{" << shapename[l] << " " << count2;
7979 +
7980 +         if (l <= TopAbs_EDGE)
7981 +         {
7982 +            str << " (" << orientationstring[e.Current().Orientation()];
7983 +            if (nrsubshapes != 0) str << ", " << nrsubshapes;
7984 +            str << ") } ";
7985 +         }
7986 +         else
7987 +            str << " } ";
7988 +
7989 +         RecursiveTopologyTree (e.Current(), str, TopAbs_ShapeEnum (l+1),
7990 +            false, (char*)lname2.str().c_str());
7991 +
7992 +      }
7993 +   }
7994 +
7995 +
7996 +
7997 +
7998 +   void OCCGeometry :: GetTopologyTree (stringstream & str)
7999 +   {
8000 +      std::cout << "Building topology tree ... " << flush;
8001 +      RecursiveTopologyTree (shape, str, TopAbs_COMPSOLID, false, "CompSolids");
8002 +      RecursiveTopologyTree (shape, str, TopAbs_SOLID, true, "FreeSolids");
8003 +      RecursiveTopologyTree (shape, str, TopAbs_SHELL, true, "FreeShells");
8004 +      RecursiveTopologyTree (shape, str, TopAbs_FACE, true, "FreeFaces");
8005 +      RecursiveTopologyTree (shape, str, TopAbs_WIRE, true, "FreeWires");
8006 +      RecursiveTopologyTree (shape, str, TopAbs_EDGE, true, "FreeEdges");
8007 +      RecursiveTopologyTree (shape, str, TopAbs_VERTEX, true, "FreeVertices");
8008 +      str << flush;
8009 +      //  std::cout << "done" << std::endl;
8010 +   }
8011 +
8012 +
8013 +
8014 +
8015 +   void OCCGeometry :: CheckIrregularEntities(stringstream & str)
8016 +   {
8017 +      ShapeAnalysis_CheckSmallFace csm;
8018 +
8019 +      csm.SetTolerance (1e-6);
8020 +
8021 +      TopTools_DataMapOfShapeListOfShape mapEdges;
8022 +      ShapeAnalysis_DataMapOfShapeListOfReal mapParam;
8023 +      TopoDS_Compound theAllVert;
8024 +
8025 +      int spotfaces = 0;
8026 +      int stripsupportfaces = 0;
8027 +      int singlestripfaces = 0;
8028 +      int stripfaces = 0;
8029 +      int facessplitbyvertices = 0;
8030 +      int stretchedpinfaces = 0;
8031 +      int smoothpinfaces = 0;
8032 +      int twistedfaces = 0;
8033 +      // int edgessamebutnotidentified = 0;
8034 +
8035 +      std::cout << "checking faces ... " << flush;
8036 +
8037 +      int i;
8038 +      for (i = 1; i <= fmap.Extent(); i++)
8039 +      {
8040 +         TopoDS_Face face = TopoDS::Face (fmap(i));
8041 +         TopoDS_Edge e1, e2;
8042 +
8043 +         if (csm.CheckSpotFace (face))
8044 +         {
8045 +            if (!spotfaces++)
8046 +               str << "SpotFace {Spot face} ";
8047 +
8048 +            (*testout) << "Face " << i << " is a spot face" << std::endl;
8049 +            str << "SpotFace/Face" << i << " ";
8050 +            str << "{Face " << i << " } ";
8051 +         }
8052 +
8053 +         if (csm.IsStripSupport (face))
8054 +         {
8055 +            if (!stripsupportfaces++)
8056 +               str << "StripSupportFace {Strip support face} ";
8057 +
8058 +            (*testout) << "Face " << i << " has strip support" << std::endl;
8059 +            str << "StripSupportFace/Face" << i << " ";
8060 +            str << "{Face " << i << " } ";
8061 +         }
8062 +
8063 +         if (csm.CheckSingleStrip(face, e1, e2))
8064 +         {
8065 +            if (!singlestripfaces++)
8066 +               str << "SingleStripFace {Single strip face} ";
8067 +
8068 +            (*testout) << "Face " << i << " is a single strip (edge " << emap.FindIndex(e1)
8069 +               << " and edge " << emap.FindIndex(e2) << " are identical)" << std::endl;
8070 +            str << "SingleStripFace/Face" << i << " ";
8071 +            str << "{Face " << i << " (edge " << emap.FindIndex(e1)
8072 +               << " and edge " << emap.FindIndex(e2) << " are identical)} ";
8073 +         }
8074 +
8075 +         if (csm.CheckStripFace(face, e1, e2))
8076 +         {
8077 +            if (!stripfaces++)
8078 +               str << "StripFace {Strip face} ";
8079 +
8080 +            (*testout) << "Face " << i << " is a strip (edge " << emap.FindIndex(e1)
8081 +               << " and edge " << emap.FindIndex(e2)
8082 +               << " are identical)" << std::endl;
8083 +            str << "StripFace/Face" << i << " ";
8084 +            str << "{Face " << i << " (edge " << emap.FindIndex(e1)
8085 +               << " and edge " << emap.FindIndex(e2) << " are identical)} ";
8086 +         }
8087 +
8088 +         if (int count = csm.CheckSplittingVertices(face, mapEdges, mapParam, theAllVert))
8089 +         {
8090 +            if (!facessplitbyvertices++)
8091 +               str << "FaceSplitByVertices {Face split by vertices} ";
8092 +
8093 +            (*testout) << "Face " << i << " is split by " << count
8094 +               << " vertex/vertices " << std::endl;
8095 +            str << "FaceSplitByVertices/Face" << i << " ";
8096 +            str << "{Face " << i << " (split by " << count << "vertex/vertices)} ";
8097 +         }
8098 +
8099 +         int whatrow, sens;
8100 +         if (int type = csm.CheckPin (face, whatrow, sens))
8101 +         {
8102 +            if (type == 1)
8103 +            {
8104 +               if (!smoothpinfaces++)
8105 +                  str << "SmoothPinFace {Smooth pin face} ";
8106 +
8107 +               (*testout) << "Face " << i << " is a smooth pin" << std::endl;
8108 +               str << "SmoothPinFace/Face" << i << " ";
8109 +               str << "{Face " << i << " } ";
8110 +            }
8111 +            else
8112 +            {
8113 +               if (!stretchedpinfaces++)
8114 +                  str << "StretchedPinFace {Stretched pin face} ";
8115 +
8116 +               (*testout) << "Face " << i << " is a streched pin" << std::endl;
8117 +               str << "StretchedPinFace/Face" << i << " ";
8118 +               str << "{Face " << i << " } ";
8119 +            }
8120 +         }
8121 +
8122 +         double paramu, paramv;
8123 +         if (csm.CheckTwisted (face, paramu, paramv))
8124 +         {
8125 +            if (!twistedfaces++)
8126 +               str << "TwistedFace {Twisted face} ";
8127 +
8128 +            (*testout) << "Face " << i << " is twisted" << std::endl;
8129 +            str << "TwistedFace/Face" << i << " ";
8130 +            str << "{Face " << i << " } ";
8131 +         }
8132 +      }
8133 +
8134 +      std::cout << "done" << std::endl;
8135 +      std::cout << "checking edges ... " << flush;
8136 +
8137 +      // double dmax;
8138 +      // int cnt = 0;
8139 +      Array <double> edgeLengths;
8140 +      Array <int> order;
8141 +      edgeLengths.SetSize (emap.Extent());
8142 +      order.SetSize (emap.Extent());
8143 +
8144 +      for (i = 1; i <= emap.Extent(); i++)
8145 +      {
8146 +         TopoDS_Edge edge1 = TopoDS::Edge (emap(i));
8147 +         GProp_GProps system;
8148 +         BRepGProp::LinearProperties(edge1, system);
8149 +         edgeLengths[i-1] = system.Mass();
8150 +      }
8151 +
8152 +      Sort (edgeLengths, order);
8153 +
8154 +      str << "ShortestEdges {Shortest edges} ";
8155 +      for (i = 1; i <= min(20, emap.Extent()); i++)
8156 +      {
8157 +         str << "ShortestEdges/Edge" << i;
8158 +         str << " {Edge " << order[i-1] << " (L=" << edgeLengths[order[i-1]-1] << ")} ";
8159 +      }
8160 +
8161 +      str << flush;
8162 +
8163 +      std::cout << "done" << std::endl;
8164 +   }
8165 +
8166 +
8167 +
8168 +
8169 +   void OCCGeometry :: GetUnmeshedFaceInfo (stringstream & str)
8170 +   {
8171 +      for (int i = 1; i <= fmap.Extent(); i++)
8172 +      {
8173 +         if (facemeshstatus[i-1] == -1)
8174 +            str << "Face" << i << " {Face " << i << " } ";
8175 +      }
8176 +      str << flush;
8177 +   }
8178 +
8179 +
8180 +
8181 +
8182 +   void OCCGeometry :: GetNotDrawableFaces (stringstream & str)
8183 +   {
8184 +      for (int i = 1; i <= fmap.Extent(); i++)
8185 +      {
8186 +         if (!fvispar[i-1].IsDrawable())
8187 +            str << "Face" << i << " {Face " << i << " } ";
8188 +      }
8189 +      str << flush;
8190 +   }
8191 +
8192 +
8193 +
8194 +
8195 +   bool OCCGeometry :: ErrorInSurfaceMeshing ()
8196 +   {
8197 +      for (int i = 1; i <= fmap.Extent(); i++)
8198 +         if (facemeshstatus[i-1] == -1)
8199 +            return true;
8200 +
8201 +      return false;
8202 +   }
8203 +
8204 +
8205 +
8206 +
8207 +  int OCCGeometry :: GenerateMesh (Mesh*& mesh, MeshingParameters & mparam,
8208 +      int perfstepsstart, int perfstepsend)
8209 +   {
8210 +     return OCCGenerateMesh (*this, mesh, mparam, perfstepsstart, perfstepsend);
8211 +   }
8212 +
8213 +
8214 +
8215 +
8216 +   const Refinement & OCCGeometry :: GetRefinement () const
8217 +   {
8218 +      return * new OCCRefinementSurfaces (*this);
8219 +   }
8220 +
8221 +
8222 +
8223 +
8224 +   OCCParameters :: OCCParameters()
8225 +   {
8226 +      resthcloseedgefac = 1;
8227 +      resthcloseedgeenable = 1;
8228 +         resthminedgelen = 0.001;
8229 +         resthminedgelenenable = 1;
8230 +   }
8231 +
8232 +
8233 +
8234 +
8235 +   void OCCParameters :: Print(ostream & ost) const
8236 +   {
8237 +      ost << "OCC Parameters:" << std::endl
8238 +         << "close edges: " << resthcloseedgeenable
8239 +         << ", fac = " << resthcloseedgefac << std::endl
8240 +                << "minimum edge length: " << resthminedgelenenable
8241 +                << ", min len = " << resthminedgelen << std::endl;
8242 +   }
8243 +
8244 +
8245 +
8246 +
8247 +   OCCParameters occparam;
8248 +
8249 +}
8250 +
8251 +
8252 +#endif
8253 --- netgen_ref/libsrc/occ/occgeom.hpp
8254 +++ netgen/libsrc/occ/occgeom.hpp
8255 @@ -1,457 +1,478 @@
8256 -#ifndef FILE_OCCGEOM
8257 -#define FILE_OCCGEOM
8258 -
8259 -/* *************************************************************************/
8260 -/* File:   occgeom.hpp                                                     */
8261 -/* Author: Robert Gaisbauer                                                */
8262 -/* Date:   26. May  03                                                     */
8263 -/* *************************************************************************/
8264 -
8265 -#ifdef OCCGEOMETRY
8266 -
8267 -#include <meshing.hpp>
8268 -
8269 -#include "BRep_Tool.hxx"
8270 -#include "Geom_Curve.hxx"
8271 -#include "Geom2d_Curve.hxx"
8272 -#include "Geom_Surface.hxx"
8273 -#include "GeomAPI_ProjectPointOnSurf.hxx"
8274 -#include "GeomAPI_ProjectPointOnCurve.hxx"
8275 -#include "BRepTools.hxx"
8276 -#include "TopExp.hxx"
8277 -#include "BRepBuilderAPI_MakeVertex.hxx"
8278 -#include "BRepBuilderAPI_MakeShell.hxx"
8279 -#include "BRepBuilderAPI_MakeSolid.hxx"
8280 -#include "BRepOffsetAPI_Sewing.hxx"
8281 -#include "BRepLProp_SLProps.hxx"
8282 -#include "BRepAdaptor_Surface.hxx"
8283 -#include "Poly_Triangulation.hxx"
8284 -#include "Poly_Array1OfTriangle.hxx"
8285 -#include "TColgp_Array1OfPnt2d.hxx"
8286 -#include "Poly_Triangle.hxx"
8287 -#include "GProp_GProps.hxx"
8288 -#include "BRepGProp.hxx"
8289 -#include "Geom_Surface.hxx"
8290 -#include "TopExp.hxx"
8291 -#include "gp_Pnt.hxx"
8292 -#include "TopoDS.hxx"
8293 -#include "TopoDS_Solid.hxx"
8294 -#include "TopExp_Explorer.hxx"
8295 -#include "TopTools_ListIteratorOfListOfShape.hxx"
8296 -#include "BRep_Tool.hxx"
8297 -#include "Geom_Curve.hxx"
8298 -#include "Geom2d_Curve.hxx"
8299 -#include "Geom_Surface.hxx"
8300 -#include "GeomAPI_ProjectPointOnSurf.hxx"
8301 -#include "GeomAPI_ProjectPointOnCurve.hxx"
8302 -#include "TopoDS_Wire.hxx"
8303 -#include "BRepTools_WireExplorer.hxx"
8304 -#include "BRepTools.hxx"
8305 -#include "TopTools_IndexedMapOfShape.hxx"
8306 -#include "TopExp.hxx"
8307 -#include "BRepBuilderAPI_MakeVertex.hxx"
8308 -#include "BRepBuilderAPI_MakeShell.hxx"
8309 -#include "BRepBuilderAPI_MakeSolid.hxx"
8310 -#include "BRepOffsetAPI_Sewing.hxx"
8311 -#include "BRepLProp_CLProps.hxx"
8312 -#include "BRepLProp_SLProps.hxx"
8313 -#include "BRepAdaptor_Surface.hxx"
8314 -#include "BRepAdaptor_Curve.hxx"
8315 -#include "Poly_Triangulation.hxx"
8316 -#include "Poly_Array1OfTriangle.hxx"
8317 -#include "TColgp_Array1OfPnt2d.hxx"
8318 -#include "Poly_Triangle.hxx"
8319 -#include "GProp_GProps.hxx"
8320 -#include "BRepGProp.hxx"
8321 -#include "TopoDS_Shape.hxx"
8322 -#include "TopoDS_Face.hxx"
8323 -#include "IGESToBRep_Reader.hxx"
8324 -#include "Interface_Static.hxx"
8325 -#include "GeomAPI_ExtremaCurveCurve.hxx"
8326 -#include "Standard_ErrorHandler.hxx"
8327 -#include "Standard_Failure.hxx"
8328 -#include "ShapeUpgrade_ShellSewing.hxx"
8329 -#include "ShapeFix_Shape.hxx"
8330 -#include "ShapeFix_Wireframe.hxx"
8331 -#include "BRepMesh.hxx"
8332 -#include "BRepMesh_IncrementalMesh.hxx"
8333 -#include "BRepBndLib.hxx"
8334 -#include "Bnd_Box.hxx"
8335 -#include "ShapeAnalysis.hxx"
8336 -#include "ShapeBuild_ReShape.hxx"
8337 -
8338 -
8339 -// Philippose - 29/01/2009
8340 -// OpenCascade XDE Support
8341 -// Include support for OpenCascade XDE Features
8342 -#include "TDocStd_Document.hxx"
8343 -#include "Quantity_Color.hxx"
8344 -#include "XCAFApp_Application.hxx"
8345 -#include "XCAFDoc_ShapeTool.hxx"
8346 -#include "XCAFDoc_Color.hxx"
8347 -#include "XCAFDoc_ColorTool.hxx"
8348 -#include "XCAFDoc_ColorType.hxx"
8349 -#include "XCAFDoc_LayerTool.hxx"
8350 -#include "XCAFDoc_DimTolTool.hxx"
8351 -#include "XCAFDoc_MaterialTool.hxx"
8352 -#include "XCAFDoc_DocumentTool.hxx"
8353 -#include "TDF_Label.hxx"
8354 -#include "TDF_LabelSequence.hxx"
8355 -#include "STEPCAFControl_Reader.hxx"
8356 -#include "STEPCAFControl_Writer.hxx"
8357 -#include "IGESCAFControl_Reader.hxx"
8358 -#include "IGESCAFControl_Writer.hxx"
8359 -
8360 -#include "IGESControl_Reader.hxx"
8361 -#include "STEPControl_Reader.hxx"
8362 -#include "IGESControl_Writer.hxx"
8363 -#include "STEPControl_Writer.hxx"
8364 -
8365 -#include "StlAPI_Writer.hxx"
8366 -#include "STEPControl_StepModelType.hxx"
8367 -
8368 -namespace netgen
8369 -{
8370 -#include "occmeshsurf.hpp"
8371 -
8372 -  extern DLL_HEADER MeshingParameters mparam;
8373 -
8374 -#define PROJECTION_TOLERANCE 1e-10
8375 -
8376 -#define ENTITYISVISIBLE 1
8377 -#define ENTITYISHIGHLIGHTED 2
8378 -#define ENTITYISDRAWABLE 4
8379 -
8380 -#define OCCGEOMETRYVISUALIZATIONNOCHANGE   0
8381 -#define OCCGEOMETRYVISUALIZATIONFULLCHANGE 1  // Compute transformation matrices and redraw
8382 -#define OCCGEOMETRYVISUALIZATIONHALFCHANGE 2  // Redraw
8383 -
8384 -
8385 -
8386 -   class EntityVisualizationCode
8387 -   {
8388 -      int code;
8389 -
8390 -   public:
8391 -
8392 -      EntityVisualizationCode()
8393 -      {  code = ENTITYISVISIBLE + !ENTITYISHIGHLIGHTED + ENTITYISDRAWABLE;}
8394 -
8395 -      int IsVisible ()
8396 -      {  return code & ENTITYISVISIBLE;}
8397 -
8398 -      int IsHighlighted ()
8399 -      {  return code & ENTITYISHIGHLIGHTED;}
8400 -
8401 -      int IsDrawable ()
8402 -      {  return code & ENTITYISDRAWABLE;}
8403 -
8404 -      void Show ()
8405 -      {  code |= ENTITYISVISIBLE;}
8406 -
8407 -      void Hide ()
8408 -      {  code &= ~ENTITYISVISIBLE;}
8409 -
8410 -      void Highlight ()
8411 -      {  code |= ENTITYISHIGHLIGHTED;}
8412 -
8413 -      void Lowlight ()
8414 -      {  code &= ~ENTITYISHIGHLIGHTED;}
8415 -
8416 -      void SetDrawable ()
8417 -      {  code |= ENTITYISDRAWABLE;}
8418 -
8419 -      void SetNotDrawable ()
8420 -      {  code &= ~ENTITYISDRAWABLE;}
8421 -   };
8422 -
8423 -
8424 -
8425 -   class Line
8426 -   {
8427 -   public:
8428 -      Point<3> p0, p1;
8429 -
8430 -      double Dist (Line l);
8431 -
8432 -      double Length ();
8433 -   };
8434 -
8435 -
8436 -
8437 -   inline double Det3 (double a00, double a01, double a02,
8438 -      double a10, double a11, double a12,
8439 -      double a20, double a21, double a22)
8440 -   {
8441 -      return a00*a11*a22 + a01*a12*a20 + a10*a21*a02 - a20*a11*a02 - a10*a01*a22 - a21*a12*a00;
8442 -   }
8443 -
8444 -
8445 -
8446 -
8447 -   class OCCGeometry : public NetgenGeometry
8448 -   {
8449 -      Point<3> center;
8450 -
8451 -   public:
8452 -      TopoDS_Shape shape;
8453 -      TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap;
8454 -      Array<bool> fsingular, esingular, vsingular;
8455 -      Box<3> boundingbox;
8456 -
8457 -      // Philippose - 29/01/2009
8458 -      // OpenCascade XDE Support
8459 -      // XCAF Handle to make the face colours available to the rest of
8460 -      // the system
8461 -      Handle_XCAFDoc_ColorTool face_colours;
8462 -
8463 -     mutable int changed;
8464 -      Array<int> facemeshstatus;
8465 -
8466 -      // Philippose - 15/01/2009
8467 -      // Maximum mesh size for a given face
8468 -      // (Used to explicitly define mesh size limits on individual faces)
8469 -      Array<double> face_maxh;
8470 -      
8471 -      // Philippose - 14/01/2010
8472 -      // Boolean array to detect whether a face has been explicitly modified 
8473 -      // by the user or not
8474 -      Array<bool> face_maxh_modified;
8475 -
8476 -      // Philippose - 15/01/2009
8477 -      // Indicates which faces have been selected by the user in geometry mode
8478 -      // (Currently handles only selection of one face at a time, but an array would
8479 -      //  help to extend this to multiple faces)
8480 -      Array<bool> face_sel_status;
8481 -
8482 -      Array<EntityVisualizationCode> fvispar, evispar, vvispar;
8483 -
8484 -      double tolerance;
8485 -      bool fixsmalledges;
8486 -      bool fixspotstripfaces;
8487 -      bool sewfaces;
8488 -      bool makesolids;
8489 -      bool splitpartitions;
8490 -
8491 -      OCCGeometry()
8492 -      {
8493 -         somap.Clear();
8494 -         shmap.Clear();
8495 -         fmap.Clear();
8496 -         wmap.Clear();
8497 -         emap.Clear();
8498 -         vmap.Clear();
8499 -      }
8500 -
8501 -
8502 -     virtual void Save (string filename) const;
8503 -
8504 -
8505 -      void BuildFMap();
8506 -
8507 -      Box<3> GetBoundingBox()
8508 -      {  return boundingbox;}
8509 -
8510 -      int NrSolids()
8511 -      {  return somap.Extent();}
8512 -
8513 -      // Philippose - 17/01/2009
8514 -      // Total number of faces in the geometry
8515 -      int NrFaces()
8516 -      {  return fmap.Extent();}
8517 -
8518 -      void SetCenter()
8519 -      {  center = boundingbox.Center();}
8520 -
8521 -      Point<3> Center()
8522 -      {  return center;}
8523 -
8524 -      void Project (int surfi, Point<3> & p) const;
8525 -      bool FastProject (int surfi, Point<3> & ap, double& u, double& v) const;
8526 -
8527 -      OCCSurface GetSurface (int surfi)
8528 -      {
8529 -         cout << "OCCGeometry::GetSurface using PLANESPACE" << endl;
8530 -         return OCCSurface (TopoDS::Face(fmap(surfi)), PLANESPACE);
8531 -      }
8532 -
8533 -      void CalcBoundingBox ();
8534 -      void BuildVisualizationMesh (double deflection);
8535 -
8536 -      void RecursiveTopologyTree (const TopoDS_Shape & sh,
8537 -         stringstream & str,
8538 -         TopAbs_ShapeEnum l,
8539 -         bool free,
8540 -         const char * lname);
8541 -
8542 -      void GetTopologyTree (stringstream & str);
8543 -
8544 -      void PrintNrShapes ();
8545 -
8546 -      void CheckIrregularEntities (stringstream & str);
8547 -
8548 -      void SewFaces();
8549 -
8550 -      void MakeSolid();
8551 -
8552 -      void HealGeometry();
8553 -
8554 -      // Philippose - 15/01/2009
8555 -      // Sets the maximum mesh size for a given face
8556 -      // (Note: Local mesh size limited by the global max mesh size)
8557 -      void SetFaceMaxH(int facenr, double faceh)
8558 -      {
8559 -         if((facenr> 0) && (facenr <= fmap.Extent()))
8560 -         {
8561 -          face_maxh[facenr-1] = min(mparam.maxh,faceh);
8562 -            
8563 -            // Philippose - 14/01/2010
8564 -            // If the face maxh is greater than or equal to the 
8565 -            // current global maximum, then identify the face as 
8566 -            // not explicitly controlled by the user any more
8567 -            if(faceh >= mparam.maxh)
8568 -            {
8569 -               face_maxh_modified[facenr-1] = 0;
8570 -            }
8571 -            else
8572 -            {
8573 -               face_maxh_modified[facenr-1] = 1;
8574 -            }
8575 -         }
8576 -      }
8577 -
8578 -      // Philippose - 15/01/2009
8579 -      // Returns the local mesh size of a given face
8580 -      double GetFaceMaxH(int facenr)
8581 -      {
8582 -         if((facenr> 0) && (facenr <= fmap.Extent()))
8583 -         {
8584 -            return face_maxh[facenr-1];
8585 -         }
8586 -         else
8587 -         {
8588 -            return 0.0;
8589 -         }
8590 -      }
8591 -      
8592 -      // Philippose - 14/01/2010
8593 -      // Returns the flag whether the given face 
8594 -      // has a mesh size controlled by the user or not
8595 -      bool GetFaceMaxhModified(int facenr)
8596 -      {
8597 -         return face_maxh_modified[facenr-1];
8598 -      }
8599 -      
8600 -      // Philippose - 17/01/2009
8601 -      // Returns the index of the currently selected face
8602 -      int SelectedFace()
8603 -      {
8604 -         int i;
8605 -
8606 -         for(i = 1; i <= fmap.Extent(); i++)
8607 -         {
8608 -            if(face_sel_status[i-1])
8609 -            {
8610 -               return i;
8611 -            }
8612 -         }
8613 -
8614 -         return 0;
8615 -      }
8616 -
8617 -      // Philippose - 17/01/2009
8618 -      // Sets the currently selected face
8619 -      void SetSelectedFace(int facenr)
8620 -      {
8621 -         face_sel_status = 0;
8622 -
8623 -         if((facenr >= 1) && (facenr <= fmap.Extent()))
8624 -         {
8625 -            face_sel_status[facenr-1] = 1;
8626 -         }
8627 -      }
8628 -
8629 -      void LowLightAll()
8630 -      {
8631 -         for (int i = 1; i <= fmap.Extent(); i++)
8632 -            fvispar[i-1].Lowlight();
8633 -         for (int i = 1; i <= emap.Extent(); i++)
8634 -            evispar[i-1].Lowlight();
8635 -         for (int i = 1; i <= vmap.Extent(); i++)
8636 -            vvispar[i-1].Lowlight();
8637 -      }
8638 -
8639 -      void GetUnmeshedFaceInfo (stringstream & str);
8640 -      void GetNotDrawableFaces (stringstream & str);
8641 -      bool ErrorInSurfaceMeshing ();
8642 -
8643 -     void WriteOCC_STL(char * filename);
8644 -
8645 -     virtual int GenerateMesh (Mesh*& mesh, MeshingParameters & mparam, 
8646 -         int perfstepsstart, int perfstepsend);
8647 -
8648 -      virtual const Refinement & GetRefinement () const;
8649 -   };
8650 -
8651 -
8652 -
8653 -   class OCCParameters
8654 -   {
8655 -   public:
8656 -
8657 -      /// Factor for meshing close edges 
8658 -      double resthcloseedgefac;
8659 -
8660 -
8661 -      /// Enable / Disable detection of close edges
8662 -      int resthcloseedgeenable;
8663 -
8664 -
8665 -         /// Minimum edge length to be used for dividing edges to mesh points
8666 -         double resthminedgelen;
8667 -
8668 -
8669 -         /// Enable / Disable use of the minimum edge length (by default use 1e-4)
8670 -         int resthminedgelenenable;
8671 -
8672 -      /*!
8673 -         Default Constructor for the OpenCascade
8674 -         Mesh generation parameter set
8675 -      */
8676 -      OCCParameters();
8677 -
8678 -
8679 -      /*!
8680 -         Dump all the OpenCascade specific meshing parameters 
8681 -         to console
8682 -      */
8683 -      void Print (ostream & ost) const;
8684 -   };
8685 -   
8686 -
8687 -   void PrintContents (OCCGeometry * geom);
8688 -
8689 -   OCCGeometry * LoadOCC_IGES (const char * filename);
8690 -   OCCGeometry * LoadOCC_STEP (const char * filename);
8691 -   OCCGeometry * LoadOCC_BREP (const char * filename);
8692 -
8693 -   extern OCCParameters occparam;
8694 -
8695 -
8696 -   // Philippose - 31.09.2009
8697 -   // External access to the mesh generation functions within the OCC
8698 -   // subsystem (Not sure if this is the best way to implement this....!!)
8699 -   extern int OCCGenerateMesh (OCCGeometry & occgeometry, Mesh*& mesh,
8700 -                              MeshingParameters & mparam,
8701 -                              int perfstepsstart, int perfstepsend);
8702 -
8703 -  extern void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh);
8704 -
8705 -   extern void OCCMeshSurface (OCCGeometry & geom, Mesh & mesh, int perfstepsend);
8706 -
8707 -   extern void OCCFindEdges (OCCGeometry & geom, Mesh & mesh);
8708 -}
8709 -
8710 -#endif
8711 -
8712 -#endif
8713 +#ifndef FILE_OCCGEOM
8714 +#define FILE_OCCGEOM
8715 +
8716 +/* *************************************************************************/
8717 +/* File:   occgeom.hpp                                                     */
8718 +/* Author: Robert Gaisbauer                                                */
8719 +/* Date:   26. May  03                                                     */
8720 +/* *************************************************************************/
8721 +
8722 +#ifdef OCCGEOMETRY
8723 +
8724 +#include <myadt.hpp>
8725 +#include <iostream>
8726 +
8727 +#include <meshing.hpp>
8728 +
8729 +#include "BRep_Tool.hxx"
8730 +#include "Geom_Curve.hxx"
8731 +#include "Geom2d_Curve.hxx"
8732 +#include "Geom_Surface.hxx"
8733 +// #include "GeomAPI_ProjectPointOnSurf.hxx"
8734 +// #include "GeomAPI_ProjectPointOnCurve.hxx"
8735 +#include "BRepTools.hxx"
8736 +#include "TopExp.hxx"
8737 +#include "BRepBuilderAPI_MakeVertex.hxx"
8738 +#include "BRepBuilderAPI_MakeShell.hxx"
8739 +#include "BRepBuilderAPI_MakeSolid.hxx"
8740 +#include "BRepOffsetAPI_Sewing.hxx"
8741 +#include "BRepLProp_SLProps.hxx"
8742 +#include "BRepAdaptor_Surface.hxx"
8743 +#include "Poly_Triangulation.hxx"
8744 +#include "Poly_Array1OfTriangle.hxx"
8745 +#include "TColgp_Array1OfPnt2d.hxx"
8746 +#include "Poly_Triangle.hxx"
8747 +#include "GProp_GProps.hxx"
8748 +#include "BRepGProp.hxx"
8749 +#include "Geom_Surface.hxx"
8750 +#include "TopExp.hxx"
8751 +#include "gp_Pnt.hxx"
8752 +#include "TopoDS.hxx"
8753 +#include "TopoDS_Solid.hxx"
8754 +#include "TopExp_Explorer.hxx"
8755 +#include "TopTools_ListIteratorOfListOfShape.hxx"
8756 +#include "BRep_Tool.hxx"
8757 +#include "Geom_Curve.hxx"
8758 +#include "Geom2d_Curve.hxx"
8759 +#include "Geom_Surface.hxx"
8760 +// #include "GeomAPI_ProjectPointOnSurf.hxx"
8761 +// #include "GeomAPI_ProjectPointOnCurve.hxx"
8762 +#include "TopoDS_Wire.hxx"
8763 +#include "BRepTools_WireExplorer.hxx"
8764 +#include "BRepTools.hxx"
8765 +#include "TopTools_IndexedMapOfShape.hxx"
8766 +#include "TopExp.hxx"
8767 +#include "BRepBuilderAPI_MakeVertex.hxx"
8768 +#include "BRepBuilderAPI_MakeShell.hxx"
8769 +#include "BRepBuilderAPI_MakeSolid.hxx"
8770 +#include "BRepOffsetAPI_Sewing.hxx"
8771 +#include "BRepLProp_CLProps.hxx"
8772 +#include "BRepLProp_SLProps.hxx"
8773 +#include "BRepAdaptor_Surface.hxx"
8774 +#include "BRepAdaptor_Curve.hxx"
8775 +#include "Poly_Triangulation.hxx"
8776 +#include "Poly_Array1OfTriangle.hxx"
8777 +#include "TColgp_Array1OfPnt2d.hxx"
8778 +#include "Poly_Triangle.hxx"
8779 +#include "GProp_GProps.hxx"
8780 +#include "BRepGProp.hxx"
8781 +#include "TopoDS_Shape.hxx"
8782 +#include "TopoDS_Face.hxx"
8783 +#include "IGESToBRep_Reader.hxx"
8784 +#include "Interface_Static.hxx"
8785 +#include "GeomAPI_ExtremaCurveCurve.hxx"
8786 +//#include "Standard_ErrorHandler.hxx"
8787 +#include "Standard_Failure.hxx"
8788 +#include "ShapeUpgrade_ShellSewing.hxx"
8789 +#include "ShapeFix_Shape.hxx"
8790 +#include "ShapeFix_Wireframe.hxx"
8791 +#include <Standard_Version.hxx>
8792 +#if (OCC_VERSION_MAJOR << 16 | OCC_VERSION_MINOR << 8 | OCC_VERSION_MAINTENANCE) <= 0x060702
8793 +// porting to OCCT6.7.3
8794 +#include "BRepMesh.hxx"
8795 +#endif
8796 +#include "BRepMesh_IncrementalMesh.hxx"
8797 +#include "BRepBndLib.hxx"
8798 +#include "Bnd_Box.hxx"
8799 +#include "ShapeAnalysis.hxx"
8800 +#include "ShapeBuild_ReShape.hxx"
8801 +
8802 +// -- Optimization: to use cached projector and classifier
8803 +#include <NCollection_DataMap.hxx>
8804 +class ShapeAnalysis_Surface;
8805 +class BRepTopAdaptor_FClass2d;
8806 +
8807 +// Philippose - 29/01/2009
8808 +// OpenCascade XDE Support
8809 +// Include support for OpenCascade XDE Features
8810 +#include "TDocStd_Document.hxx"
8811 +#include "Quantity_Color.hxx"
8812 +#include "XCAFApp_Application.hxx"
8813 +#include "XCAFDoc_ShapeTool.hxx"
8814 +#include "XCAFDoc_Color.hxx"
8815 +#include "XCAFDoc_ColorTool.hxx"
8816 +#include "XCAFDoc_ColorType.hxx"
8817 +#include "XCAFDoc_LayerTool.hxx"
8818 +#include "XCAFDoc_DimTolTool.hxx"
8819 +#include "XCAFDoc_MaterialTool.hxx"
8820 +#include "XCAFDoc_DocumentTool.hxx"
8821 +#include "TDF_Label.hxx"
8822 +#include "TDF_LabelSequence.hxx"
8823 +#include "STEPCAFControl_Reader.hxx"
8824 +#include "STEPCAFControl_Writer.hxx"
8825 +#include "IGESCAFControl_Reader.hxx"
8826 +#include "IGESCAFControl_Writer.hxx"
8827 +
8828 +#include "IGESControl_Reader.hxx"
8829 +#include "STEPControl_Reader.hxx"
8830 +#include "IGESControl_Writer.hxx"
8831 +#include "STEPControl_Writer.hxx"
8832 +
8833 +#include "StlAPI_Writer.hxx"
8834 +#include "STEPControl_StepModelType.hxx"
8835 +
8836 +namespace netgen
8837 +{
8838 +#include "occmeshsurf.hpp"
8839 +
8840 +  DLL_HEADER extern MeshingParameters mparam;
8841 +
8842 +#define PROJECTION_TOLERANCE 1e-10
8843 +
8844 +#define ENTITYISVISIBLE 1
8845 +#define ENTITYISHIGHLIGHTED 2
8846 +#define ENTITYISDRAWABLE 4
8847 +
8848 +#define OCCGEOMETRYVISUALIZATIONNOCHANGE   0
8849 +#define OCCGEOMETRYVISUALIZATIONFULLCHANGE 1  // Compute transformation matrices and redraw
8850 +#define OCCGEOMETRYVISUALIZATIONHALFCHANGE 2  // Redraw
8851 +
8852 +
8853 +
8854 +   class EntityVisualizationCode
8855 +   {
8856 +      int code;
8857 +
8858 +   public:
8859 +
8860 +      EntityVisualizationCode()
8861 +      {  code = ENTITYISVISIBLE + !ENTITYISHIGHLIGHTED + ENTITYISDRAWABLE;}
8862 +
8863 +      int IsVisible ()
8864 +      {  return code & ENTITYISVISIBLE;}
8865 +
8866 +      int IsHighlighted ()
8867 +      {  return code & ENTITYISHIGHLIGHTED;}
8868 +
8869 +      int IsDrawable ()
8870 +      {  return code & ENTITYISDRAWABLE;}
8871 +
8872 +      void Show ()
8873 +      {  code |= ENTITYISVISIBLE;}
8874 +
8875 +      void Hide ()
8876 +      {  code &= ~ENTITYISVISIBLE;}
8877 +
8878 +      void Highlight ()
8879 +      {  code |= ENTITYISHIGHLIGHTED;}
8880 +
8881 +      void Lowlight ()
8882 +      {  code &= ~ENTITYISHIGHLIGHTED;}
8883 +
8884 +      void SetDrawable ()
8885 +      {  code |= ENTITYISDRAWABLE;}
8886 +
8887 +      void SetNotDrawable ()
8888 +      {  code &= ~ENTITYISDRAWABLE;}
8889 +   };
8890 +
8891 +
8892 +
8893 +   class Line
8894 +   {
8895 +   public:
8896 +      Point<3> p0, p1;
8897 +
8898 +      double Dist (Line l);
8899 +
8900 +      double Length ();
8901 +   };
8902 +
8903 +
8904 +
8905 +   inline double Det3 (double a00, double a01, double a02,
8906 +      double a10, double a11, double a12,
8907 +      double a20, double a21, double a22)
8908 +   {
8909 +      return a00*a11*a22 + a01*a12*a20 + a10*a21*a02 - a20*a11*a02 - a10*a01*a22 - a21*a12*a00;
8910 +   }
8911 +
8912 +
8913 +
8914 +
8915 +   class DLL_HEADER OCCGeometry : public NetgenGeometry
8916 +   {
8917 +      Point<3> center;
8918 +      // -- Optimization: to use cached projector and classifier
8919 +      mutable NCollection_DataMap<int,Handle(ShapeAnalysis_Surface)> fprjmap;
8920 +      mutable NCollection_DataMap<int,BRepTopAdaptor_FClass2d*> fclsmap;
8921 +
8922 +   public:
8923 +      TopoDS_Shape shape;
8924 +      TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap;
8925 +      Array<bool> fsingular, esingular, vsingular;
8926 +      Box<3> boundingbox;
8927 +
8928 +      // Philippose - 29/01/2009
8929 +      // OpenCascade XDE Support
8930 +      // XCAF Handle to make the face colours available to the rest of
8931 +      // the system
8932 +      Handle(XCAFDoc_ColorTool) face_colours;
8933 +
8934 +     mutable int changed;
8935 +      Array<int> facemeshstatus;
8936 +
8937 +      // Philippose - 15/01/2009
8938 +      // Maximum mesh size for a given face
8939 +      // (Used to explicitly define mesh size limits on individual faces)
8940 +      Array<double> face_maxh;
8941 +      
8942 +      // Philippose - 14/01/2010
8943 +      // Boolean array to detect whether a face has been explicitly modified 
8944 +      // by the user or not
8945 +      Array<bool> face_maxh_modified;
8946 +
8947 +      // Philippose - 15/01/2009
8948 +      // Indicates which faces have been selected by the user in geometry mode
8949 +      // (Currently handles only selection of one face at a time, but an array would
8950 +      //  help to extend this to multiple faces)
8951 +      Array<bool> face_sel_status;
8952 +
8953 +      Array<EntityVisualizationCode> fvispar, evispar, vvispar;
8954 +
8955 +      double tolerance;
8956 +      bool fixsmalledges;
8957 +      bool fixspotstripfaces;
8958 +      bool sewfaces;
8959 +      bool makesolids;
8960 +      bool splitpartitions;
8961 +
8962 +      OCCGeometry()
8963 +      {
8964 +         somap.Clear();
8965 +         shmap.Clear();
8966 +         fmap.Clear();
8967 +         wmap.Clear();
8968 +         emap.Clear();
8969 +         vmap.Clear();
8970 +      }
8971 +
8972 +
8973 +     virtual void Save (string filename) const;
8974 +
8975 +
8976 +      ~OCCGeometry();      // -- to free cached projector and classifier
8977 +
8978 +      void BuildFMap();
8979 +
8980 +      Box<3> GetBoundingBox()
8981 +      {  return boundingbox;}
8982 +
8983 +      int NrSolids()
8984 +      {  return somap.Extent();}
8985 +
8986 +      // Philippose - 17/01/2009
8987 +      // Total number of faces in the geometry
8988 +      int NrFaces()
8989 +      {  return fmap.Extent();}
8990 +
8991 +      void SetCenter()
8992 +      {  center = boundingbox.Center();}
8993 +
8994 +      Point<3> Center()
8995 +      {  return center;}
8996 +
8997 +      // void Project (int surfi, Point<3> & p) const; -- optimization
8998 +      bool Project (int surfi, Point<3> & p, double& u, double& v) const;
8999 +      bool FastProject (int surfi, Point<3> & ap, double& u, double& v) const;
9000 +
9001 +      // -- Optimization: to use cached projector and classifier
9002 +      void GetFaceTools(int surfi, Handle(ShapeAnalysis_Surface)& proj,
9003 +                        BRepTopAdaptor_FClass2d*& cls) const;
9004 +
9005 +      OCCSurface GetSurface (int surfi)
9006 +      {
9007 +         std::cout << "OCCGeometry::GetSurface using PLANESPACE" << std::endl;
9008 +         return OCCSurface (TopoDS::Face(fmap(surfi)), PLANESPACE);
9009 +      }
9010 +
9011 +      void CalcBoundingBox ();
9012 +      void BuildVisualizationMesh (double deflection);
9013 +
9014 +      void RecursiveTopologyTree (const TopoDS_Shape & sh,
9015 +         stringstream & str,
9016 +         TopAbs_ShapeEnum l,
9017 +         bool free,
9018 +         const char * lname);
9019 +
9020 +      void GetTopologyTree (stringstream & str);
9021 +
9022 +      void PrintNrShapes ();
9023 +
9024 +      void CheckIrregularEntities (stringstream & str);
9025 +
9026 +      void SewFaces();
9027 +
9028 +      void MakeSolid();
9029 +
9030 +      void HealGeometry();
9031 +
9032 +      // Philippose - 15/01/2009
9033 +      // Sets the maximum mesh size for a given face
9034 +      // (Note: Local mesh size limited by the global max mesh size)
9035 +      void SetFaceMaxH(int facenr, double faceh)
9036 +      {
9037 +         if((facenr> 0) && (facenr <= fmap.Extent()))
9038 +         {
9039 +          face_maxh[facenr-1] = min(mparam.maxh,faceh);
9040 +            
9041 +            // Philippose - 14/01/2010
9042 +            // If the face maxh is greater than or equal to the 
9043 +            // current global maximum, then identify the face as 
9044 +            // not explicitly controlled by the user any more
9045 +            if(faceh >= mparam.maxh)
9046 +            {
9047 +               face_maxh_modified[facenr-1] = 0;
9048 +            }
9049 +            else
9050 +            {
9051 +               face_maxh_modified[facenr-1] = 1;
9052 +            }
9053 +         }
9054 +      }
9055 +
9056 +      // Philippose - 15/01/2009
9057 +      // Returns the local mesh size of a given face
9058 +      double GetFaceMaxH(int facenr)
9059 +      {
9060 +         if((facenr> 0) && (facenr <= fmap.Extent()))
9061 +         {
9062 +            return face_maxh[facenr-1];
9063 +         }
9064 +         else
9065 +         {
9066 +            return 0.0;
9067 +         }
9068 +      }
9069 +      
9070 +      // Philippose - 14/01/2010
9071 +      // Returns the flag whether the given face 
9072 +      // has a mesh size controlled by the user or not
9073 +      bool GetFaceMaxhModified(int facenr)
9074 +      {
9075 +         return face_maxh_modified[facenr-1];
9076 +      }
9077 +      
9078 +      // Philippose - 17/01/2009
9079 +      // Returns the index of the currently selected face
9080 +      int SelectedFace()
9081 +      {
9082 +         int i;
9083 +
9084 +         for(i = 1; i <= fmap.Extent(); i++)
9085 +         {
9086 +            if(face_sel_status[i-1])
9087 +            {
9088 +               return i;
9089 +            }
9090 +         }
9091 +
9092 +         return 0;
9093 +      }
9094 +
9095 +      // Philippose - 17/01/2009
9096 +      // Sets the currently selected face
9097 +      void SetSelectedFace(int facenr)
9098 +      {
9099 +         face_sel_status = 0;
9100 +
9101 +         if((facenr >= 1) && (facenr <= fmap.Extent()))
9102 +         {
9103 +            face_sel_status[facenr-1] = 1;
9104 +         }
9105 +      }
9106 +
9107 +      void LowLightAll()
9108 +      {
9109 +         for (int i = 1; i <= fmap.Extent(); i++)
9110 +            fvispar[i-1].Lowlight();
9111 +         for (int i = 1; i <= emap.Extent(); i++)
9112 +            evispar[i-1].Lowlight();
9113 +         for (int i = 1; i <= vmap.Extent(); i++)
9114 +            vvispar[i-1].Lowlight();
9115 +      }
9116 +
9117 +      void GetUnmeshedFaceInfo (stringstream & str);
9118 +      void GetNotDrawableFaces (stringstream & str);
9119 +      bool ErrorInSurfaceMeshing ();
9120 +
9121 +     void WriteOCC_STL(char * filename);
9122 +
9123 +     virtual int GenerateMesh (Mesh*& mesh, MeshingParameters & mparam, 
9124 +         int perfstepsstart, int perfstepsend);
9125 +
9126 +      virtual const Refinement & GetRefinement () const;
9127 +   };
9128 +
9129 +
9130 +
9131 +   class DLL_HEADER OCCParameters
9132 +   {
9133 +   public:
9134 +
9135 +      /// Factor for meshing close edges 
9136 +      double resthcloseedgefac;
9137 +
9138 +
9139 +      /// Enable / Disable detection of close edges
9140 +      int resthcloseedgeenable;
9141 +
9142 +
9143 +         /// Minimum edge length to be used for dividing edges to mesh points
9144 +         double resthminedgelen;
9145 +
9146 +
9147 +         /// Enable / Disable use of the minimum edge length (by default use 1e-4)
9148 +         int resthminedgelenenable;
9149 +
9150 +      /*!
9151 +         Default Constructor for the OpenCascade
9152 +         Mesh generation parameter set
9153 +      */
9154 +      OCCParameters();
9155 +
9156 +
9157 +      /*!
9158 +         Dump all the OpenCascade specific meshing parameters 
9159 +         to console
9160 +      */
9161 +      void Print (ostream & ost) const;
9162 +   };
9163 +   
9164 +
9165 +   void PrintContents (OCCGeometry * geom);
9166 +
9167 +   OCCGeometry * LoadOCC_IGES (const char * filename);
9168 +   OCCGeometry * LoadOCC_STEP (const char * filename);
9169 +   OCCGeometry * LoadOCC_BREP (const char * filename);
9170 +
9171 +   extern DLL_HEADER OCCParameters occparam;
9172 +
9173 +
9174 +   // Philippose - 31.09.2009
9175 +   // External access to the mesh generation functions within the OCC
9176 +   // subsystem (Not sure if this is the best way to implement this....!!)
9177 +   extern DLL_HEADER int OCCGenerateMesh (OCCGeometry & occgeometry, Mesh*& mesh,
9178 +                              MeshingParameters & mparam,
9179 +                              int perfstepsstart, int perfstepsend);
9180 +
9181 +  extern DLL_HEADER void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh);
9182 +
9183 +   extern DLL_HEADER void OCCMeshSurface (OCCGeometry & geom, Mesh & mesh, int perfstepsend);
9184 +
9185 +   extern DLL_HEADER void OCCFindEdges (OCCGeometry & geom, Mesh & mesh);
9186 +}
9187 +
9188 +#endif
9189 +
9190 +#endif
9191 --- /dev/null
9192 +++ netgen/libsrc/occ/occgeom.hpp.orig
9193 @@ -0,0 +1,457 @@
9194 +#ifndef FILE_OCCGEOM
9195 +#define FILE_OCCGEOM
9196 +
9197 +/* *************************************************************************/
9198 +/* File:   occgeom.hpp                                                     */
9199 +/* Author: Robert Gaisbauer                                                */
9200 +/* Date:   26. May  03                                                     */
9201 +/* *************************************************************************/
9202 +
9203 +#ifdef OCCGEOMETRY
9204 +
9205 +#include <meshing.hpp>
9206 +
9207 +#include "BRep_Tool.hxx"
9208 +#include "Geom_Curve.hxx"
9209 +#include "Geom2d_Curve.hxx"
9210 +#include "Geom_Surface.hxx"
9211 +#include "GeomAPI_ProjectPointOnSurf.hxx"
9212 +#include "GeomAPI_ProjectPointOnCurve.hxx"
9213 +#include "BRepTools.hxx"
9214 +#include "TopExp.hxx"
9215 +#include "BRepBuilderAPI_MakeVertex.hxx"
9216 +#include "BRepBuilderAPI_MakeShell.hxx"
9217 +#include "BRepBuilderAPI_MakeSolid.hxx"
9218 +#include "BRepOffsetAPI_Sewing.hxx"
9219 +#include "BRepLProp_SLProps.hxx"
9220 +#include "BRepAdaptor_Surface.hxx"
9221 +#include "Poly_Triangulation.hxx"
9222 +#include "Poly_Array1OfTriangle.hxx"
9223 +#include "TColgp_Array1OfPnt2d.hxx"
9224 +#include "Poly_Triangle.hxx"
9225 +#include "GProp_GProps.hxx"
9226 +#include "BRepGProp.hxx"
9227 +#include "Geom_Surface.hxx"
9228 +#include "TopExp.hxx"
9229 +#include "gp_Pnt.hxx"
9230 +#include "TopoDS.hxx"
9231 +#include "TopoDS_Solid.hxx"
9232 +#include "TopExp_Explorer.hxx"
9233 +#include "TopTools_ListIteratorOfListOfShape.hxx"
9234 +#include "BRep_Tool.hxx"
9235 +#include "Geom_Curve.hxx"
9236 +#include "Geom2d_Curve.hxx"
9237 +#include "Geom_Surface.hxx"
9238 +#include "GeomAPI_ProjectPointOnSurf.hxx"
9239 +#include "GeomAPI_ProjectPointOnCurve.hxx"
9240 +#include "TopoDS_Wire.hxx"
9241 +#include "BRepTools_WireExplorer.hxx"
9242 +#include "BRepTools.hxx"
9243 +#include "TopTools_IndexedMapOfShape.hxx"
9244 +#include "TopExp.hxx"
9245 +#include "BRepBuilderAPI_MakeVertex.hxx"
9246 +#include "BRepBuilderAPI_MakeShell.hxx"
9247 +#include "BRepBuilderAPI_MakeSolid.hxx"
9248 +#include "BRepOffsetAPI_Sewing.hxx"
9249 +#include "BRepLProp_CLProps.hxx"
9250 +#include "BRepLProp_SLProps.hxx"
9251 +#include "BRepAdaptor_Surface.hxx"
9252 +#include "BRepAdaptor_Curve.hxx"
9253 +#include "Poly_Triangulation.hxx"
9254 +#include "Poly_Array1OfTriangle.hxx"
9255 +#include "TColgp_Array1OfPnt2d.hxx"
9256 +#include "Poly_Triangle.hxx"
9257 +#include "GProp_GProps.hxx"
9258 +#include "BRepGProp.hxx"
9259 +#include "TopoDS_Shape.hxx"
9260 +#include "TopoDS_Face.hxx"
9261 +#include "IGESToBRep_Reader.hxx"
9262 +#include "Interface_Static.hxx"
9263 +#include "GeomAPI_ExtremaCurveCurve.hxx"
9264 +#include "Standard_ErrorHandler.hxx"
9265 +#include "Standard_Failure.hxx"
9266 +#include "ShapeUpgrade_ShellSewing.hxx"
9267 +#include "ShapeFix_Shape.hxx"
9268 +#include "ShapeFix_Wireframe.hxx"
9269 +#include "BRepMesh.hxx"
9270 +#include "BRepMesh_IncrementalMesh.hxx"
9271 +#include "BRepBndLib.hxx"
9272 +#include "Bnd_Box.hxx"
9273 +#include "ShapeAnalysis.hxx"
9274 +#include "ShapeBuild_ReShape.hxx"
9275 +
9276 +
9277 +// Philippose - 29/01/2009
9278 +// OpenCascade XDE Support
9279 +// Include support for OpenCascade XDE Features
9280 +#include "TDocStd_Document.hxx"
9281 +#include "Quantity_Color.hxx"
9282 +#include "XCAFApp_Application.hxx"
9283 +#include "XCAFDoc_ShapeTool.hxx"
9284 +#include "XCAFDoc_Color.hxx"
9285 +#include "XCAFDoc_ColorTool.hxx"
9286 +#include "XCAFDoc_ColorType.hxx"
9287 +#include "XCAFDoc_LayerTool.hxx"
9288 +#include "XCAFDoc_DimTolTool.hxx"
9289 +#include "XCAFDoc_MaterialTool.hxx"
9290 +#include "XCAFDoc_DocumentTool.hxx"
9291 +#include "TDF_Label.hxx"
9292 +#include "TDF_LabelSequence.hxx"
9293 +#include "STEPCAFControl_Reader.hxx"
9294 +#include "STEPCAFControl_Writer.hxx"
9295 +#include "IGESCAFControl_Reader.hxx"
9296 +#include "IGESCAFControl_Writer.hxx"
9297 +
9298 +#include "IGESControl_Reader.hxx"
9299 +#include "STEPControl_Reader.hxx"
9300 +#include "IGESControl_Writer.hxx"
9301 +#include "STEPControl_Writer.hxx"
9302 +
9303 +#include "StlAPI_Writer.hxx"
9304 +#include "STEPControl_StepModelType.hxx"
9305 +
9306 +namespace netgen
9307 +{
9308 +#include "occmeshsurf.hpp"
9309 +
9310 +  extern DLL_HEADER MeshingParameters mparam;
9311 +
9312 +#define PROJECTION_TOLERANCE 1e-10
9313 +
9314 +#define ENTITYISVISIBLE 1
9315 +#define ENTITYISHIGHLIGHTED 2
9316 +#define ENTITYISDRAWABLE 4
9317 +
9318 +#define OCCGEOMETRYVISUALIZATIONNOCHANGE   0
9319 +#define OCCGEOMETRYVISUALIZATIONFULLCHANGE 1  // Compute transformation matrices and redraw
9320 +#define OCCGEOMETRYVISUALIZATIONHALFCHANGE 2  // Redraw
9321 +
9322 +
9323 +
9324 +   class EntityVisualizationCode
9325 +   {
9326 +      int code;
9327 +
9328 +   public:
9329 +
9330 +      EntityVisualizationCode()
9331 +      {  code = ENTITYISVISIBLE + !ENTITYISHIGHLIGHTED + ENTITYISDRAWABLE;}
9332 +
9333 +      int IsVisible ()
9334 +      {  return code & ENTITYISVISIBLE;}
9335 +
9336 +      int IsHighlighted ()
9337 +      {  return code & ENTITYISHIGHLIGHTED;}
9338 +
9339 +      int IsDrawable ()
9340 +      {  return code & ENTITYISDRAWABLE;}
9341 +
9342 +      void Show ()
9343 +      {  code |= ENTITYISVISIBLE;}
9344 +
9345 +      void Hide ()
9346 +      {  code &= ~ENTITYISVISIBLE;}
9347 +
9348 +      void Highlight ()
9349 +      {  code |= ENTITYISHIGHLIGHTED;}
9350 +
9351 +      void Lowlight ()
9352 +      {  code &= ~ENTITYISHIGHLIGHTED;}
9353 +
9354 +      void SetDrawable ()
9355 +      {  code |= ENTITYISDRAWABLE;}
9356 +
9357 +      void SetNotDrawable ()
9358 +      {  code &= ~ENTITYISDRAWABLE;}
9359 +   };
9360 +
9361 +
9362 +
9363 +   class Line
9364 +   {
9365 +   public:
9366 +      Point<3> p0, p1;
9367 +
9368 +      double Dist (Line l);
9369 +
9370 +      double Length ();
9371 +   };
9372 +
9373 +
9374 +
9375 +   inline double Det3 (double a00, double a01, double a02,
9376 +      double a10, double a11, double a12,
9377 +      double a20, double a21, double a22)
9378 +   {
9379 +      return a00*a11*a22 + a01*a12*a20 + a10*a21*a02 - a20*a11*a02 - a10*a01*a22 - a21*a12*a00;
9380 +   }
9381 +
9382 +
9383 +
9384 +
9385 +   class OCCGeometry : public NetgenGeometry
9386 +   {
9387 +      Point<3> center;
9388 +
9389 +   public:
9390 +      TopoDS_Shape shape;
9391 +      TopTools_IndexedMapOfShape fmap, emap, vmap, somap, shmap, wmap;
9392 +      Array<bool> fsingular, esingular, vsingular;
9393 +      Box<3> boundingbox;
9394 +
9395 +      // Philippose - 29/01/2009
9396 +      // OpenCascade XDE Support
9397 +      // XCAF Handle to make the face colours available to the rest of
9398 +      // the system
9399 +      Handle_XCAFDoc_ColorTool face_colours;
9400 +
9401 +     mutable int changed;
9402 +      Array<int> facemeshstatus;
9403 +
9404 +      // Philippose - 15/01/2009
9405 +      // Maximum mesh size for a given face
9406 +      // (Used to explicitly define mesh size limits on individual faces)
9407 +      Array<double> face_maxh;
9408 +      
9409 +      // Philippose - 14/01/2010
9410 +      // Boolean array to detect whether a face has been explicitly modified 
9411 +      // by the user or not
9412 +      Array<bool> face_maxh_modified;
9413 +
9414 +      // Philippose - 15/01/2009
9415 +      // Indicates which faces have been selected by the user in geometry mode
9416 +      // (Currently handles only selection of one face at a time, but an array would
9417 +      //  help to extend this to multiple faces)
9418 +      Array<bool> face_sel_status;
9419 +
9420 +      Array<EntityVisualizationCode> fvispar, evispar, vvispar;
9421 +
9422 +      double tolerance;
9423 +      bool fixsmalledges;
9424 +      bool fixspotstripfaces;
9425 +      bool sewfaces;
9426 +      bool makesolids;
9427 +      bool splitpartitions;
9428 +
9429 +      OCCGeometry()
9430 +      {
9431 +         somap.Clear();
9432 +         shmap.Clear();
9433 +         fmap.Clear();
9434 +         wmap.Clear();
9435 +         emap.Clear();
9436 +         vmap.Clear();
9437 +      }
9438 +
9439 +
9440 +     virtual void Save (string filename) const;
9441 +
9442 +
9443 +      void BuildFMap();
9444 +
9445 +      Box<3> GetBoundingBox()
9446 +      {  return boundingbox;}
9447 +
9448 +      int NrSolids()
9449 +      {  return somap.Extent();}
9450 +
9451 +      // Philippose - 17/01/2009
9452 +      // Total number of faces in the geometry
9453 +      int NrFaces()
9454 +      {  return fmap.Extent();}
9455 +
9456 +      void SetCenter()
9457 +      {  center = boundingbox.Center();}
9458 +
9459 +      Point<3> Center()
9460 +      {  return center;}
9461 +
9462 +      void Project (int surfi, Point<3> & p) const;
9463 +      bool FastProject (int surfi, Point<3> & ap, double& u, double& v) const;
9464 +
9465 +      OCCSurface GetSurface (int surfi)
9466 +      {
9467 +         cout << "OCCGeometry::GetSurface using PLANESPACE" << endl;
9468 +         return OCCSurface (TopoDS::Face(fmap(surfi)), PLANESPACE);
9469 +      }
9470 +
9471 +      void CalcBoundingBox ();
9472 +      void BuildVisualizationMesh (double deflection);
9473 +
9474 +      void RecursiveTopologyTree (const TopoDS_Shape & sh,
9475 +         stringstream & str,
9476 +         TopAbs_ShapeEnum l,
9477 +         bool free,
9478 +         const char * lname);
9479 +
9480 +      void GetTopologyTree (stringstream & str);
9481 +
9482 +      void PrintNrShapes ();
9483 +
9484 +      void CheckIrregularEntities (stringstream & str);
9485 +
9486 +      void SewFaces();
9487 +
9488 +      void MakeSolid();
9489 +
9490 +      void HealGeometry();
9491 +
9492 +      // Philippose - 15/01/2009
9493 +      // Sets the maximum mesh size for a given face
9494 +      // (Note: Local mesh size limited by the global max mesh size)
9495 +      void SetFaceMaxH(int facenr, double faceh)
9496 +      {
9497 +         if((facenr> 0) && (facenr <= fmap.Extent()))
9498 +         {
9499 +          face_maxh[facenr-1] = min(mparam.maxh,faceh);
9500 +            
9501 +            // Philippose - 14/01/2010
9502 +            // If the face maxh is greater than or equal to the 
9503 +            // current global maximum, then identify the face as 
9504 +            // not explicitly controlled by the user any more
9505 +            if(faceh >= mparam.maxh)
9506 +            {
9507 +               face_maxh_modified[facenr-1] = 0;
9508 +            }
9509 +            else
9510 +            {
9511 +               face_maxh_modified[facenr-1] = 1;
9512 +            }
9513 +         }
9514 +      }
9515 +
9516 +      // Philippose - 15/01/2009
9517 +      // Returns the local mesh size of a given face
9518 +      double GetFaceMaxH(int facenr)
9519 +      {
9520 +         if((facenr> 0) && (facenr <= fmap.Extent()))
9521 +         {
9522 +            return face_maxh[facenr-1];
9523 +         }
9524 +         else
9525 +         {
9526 +            return 0.0;
9527 +         }
9528 +      }
9529 +      
9530 +      // Philippose - 14/01/2010
9531 +      // Returns the flag whether the given face 
9532 +      // has a mesh size controlled by the user or not
9533 +      bool GetFaceMaxhModified(int facenr)
9534 +      {
9535 +         return face_maxh_modified[facenr-1];
9536 +      }
9537 +      
9538 +      // Philippose - 17/01/2009
9539 +      // Returns the index of the currently selected face
9540 +      int SelectedFace()
9541 +      {
9542 +         int i;
9543 +
9544 +         for(i = 1; i <= fmap.Extent(); i++)
9545 +         {
9546 +            if(face_sel_status[i-1])
9547 +            {
9548 +               return i;
9549 +            }
9550 +         }
9551 +
9552 +         return 0;
9553 +      }
9554 +
9555 +      // Philippose - 17/01/2009
9556 +      // Sets the currently selected face
9557 +      void SetSelectedFace(int facenr)
9558 +      {
9559 +         face_sel_status = 0;
9560 +
9561 +         if((facenr >= 1) && (facenr <= fmap.Extent()))
9562 +         {
9563 +            face_sel_status[facenr-1] = 1;
9564 +         }
9565 +      }
9566 +
9567 +      void LowLightAll()
9568 +      {
9569 +         for (int i = 1; i <= fmap.Extent(); i++)
9570 +            fvispar[i-1].Lowlight();
9571 +         for (int i = 1; i <= emap.Extent(); i++)
9572 +            evispar[i-1].Lowlight();
9573 +         for (int i = 1; i <= vmap.Extent(); i++)
9574 +            vvispar[i-1].Lowlight();
9575 +      }
9576 +
9577 +      void GetUnmeshedFaceInfo (stringstream & str);
9578 +      void GetNotDrawableFaces (stringstream & str);
9579 +      bool ErrorInSurfaceMeshing ();
9580 +
9581 +     void WriteOCC_STL(char * filename);
9582 +
9583 +     virtual int GenerateMesh (Mesh*& mesh, MeshingParameters & mparam, 
9584 +         int perfstepsstart, int perfstepsend);
9585 +
9586 +      virtual const Refinement & GetRefinement () const;
9587 +   };
9588 +
9589 +
9590 +
9591 +   class OCCParameters
9592 +   {
9593 +   public:
9594 +
9595 +      /// Factor for meshing close edges 
9596 +      double resthcloseedgefac;
9597 +
9598 +
9599 +      /// Enable / Disable detection of close edges
9600 +      int resthcloseedgeenable;
9601 +
9602 +
9603 +         /// Minimum edge length to be used for dividing edges to mesh points
9604 +         double resthminedgelen;
9605 +
9606 +
9607 +         /// Enable / Disable use of the minimum edge length (by default use 1e-4)
9608 +         int resthminedgelenenable;
9609 +
9610 +      /*!
9611 +         Default Constructor for the OpenCascade
9612 +         Mesh generation parameter set
9613 +      */
9614 +      OCCParameters();
9615 +
9616 +
9617 +      /*!
9618 +         Dump all the OpenCascade specific meshing parameters 
9619 +         to console
9620 +      */
9621 +      void Print (ostream & ost) const;
9622 +   };
9623 +   
9624 +
9625 +   void PrintContents (OCCGeometry * geom);
9626 +
9627 +   OCCGeometry * LoadOCC_IGES (const char * filename);
9628 +   OCCGeometry * LoadOCC_STEP (const char * filename);
9629 +   OCCGeometry * LoadOCC_BREP (const char * filename);
9630 +
9631 +   extern OCCParameters occparam;
9632 +
9633 +
9634 +   // Philippose - 31.09.2009
9635 +   // External access to the mesh generation functions within the OCC
9636 +   // subsystem (Not sure if this is the best way to implement this....!!)
9637 +   extern int OCCGenerateMesh (OCCGeometry & occgeometry, Mesh*& mesh,
9638 +                              MeshingParameters & mparam,
9639 +                              int perfstepsstart, int perfstepsend);
9640 +
9641 +  extern void OCCSetLocalMeshSize(OCCGeometry & geom, Mesh & mesh);
9642 +
9643 +   extern void OCCMeshSurface (OCCGeometry & geom, Mesh & mesh, int perfstepsend);
9644 +
9645 +   extern void OCCFindEdges (OCCGeometry & geom, Mesh & mesh);
9646 +}
9647 +
9648 +#endif
9649 +
9650 +#endif
9651 --- netgen_ref/libsrc/occ/occmeshsurf.cpp
9652 +++ netgen/libsrc/occ/occmeshsurf.cpp
9653 @@ -6,6 +6,7 @@
9654  #include <meshing.hpp>
9655  #include <GeomLProp_SLProps.hxx>
9656  #include <ShapeAnalysis_Surface.hxx>
9657 +#include <GeomAPI_ProjectPointOnCurve.hxx> // -- moved here from occgeom.hpp
9658  
9659  
9660  namespace netgen
9661 @@ -96,24 +97,27 @@
9662  
9663         n.Normalize();
9664        }
9665 -    else
9666 +    else if ( lprop.IsNormalDefined() )
9667        {
9668         n(0)=lprop.Normal().X();
9669         n(1)=lprop.Normal().Y();
9670         n(2)=lprop.Normal().Z();
9671        }
9672 -
9673 +    else
9674 +      {
9675 +        n = 0;
9676 +      }
9677      if(glob_testout)
9678        {
9679         (*testout) << "u " << geominfo.u << " v " << geominfo.v 
9680                    << " du " << lprop.D1U().X() << " "<< lprop.D1U().Y() << " "<< lprop.D1U().Z()
9681 -                  << " dv " << lprop.D1V().X() << " "<< lprop.D1V().Y() << " "<< lprop.D1V().Z() << endl;
9682 +                  << " dv " << lprop.D1V().X() << " "<< lprop.D1V().Y() << " "<< lprop.D1V().Z() << std::endl;
9683        }
9684  
9685  
9686  
9687      if (orient == TopAbs_REVERSED) n = -1*n;
9688 -    //  (*testout) << "GetNormalVector" << endl;
9689 +    //  (*testout) << "GetNormalVector" << std::endl;
9690    }
9691  
9692  
9693 @@ -126,8 +130,8 @@
9694        {
9695         p1 = ap1; p2 = ap2;
9696  
9697 -       //cout << "p1 = " << p1 << endl;
9698 -       //cout << "p2 = " << p2 << endl;
9699 +       //std::cout << "p1 = " << p1 << std::endl;
9700 +       //std::cout << "p2 = " << p2 << std::endl;
9701        
9702         GetNormalVector (p1, geominfo1, ez);
9703        
9704 @@ -148,7 +152,7 @@
9705         ez.Normalize();
9706         ey = Cross (ez, ex);
9707         nmid = ez;
9708 -       //cout << "ex " << ex << " ey " << ey << " ez " << ez << endl;
9709 +       //std::cout << "ex " << ex << " ey " << ey << " ez " << ez << std::endl;
9710        }
9711      else
9712        {
9713 @@ -178,9 +182,9 @@
9714         D1(0,1) = dv.X(); D1(1,1) = dv.Y(); D1(2,1) = dv.Z();
9715  
9716         /*
9717 -         (*testout) << "DefineTangentialPlane" << endl
9718 -         << "---------------------" << endl;
9719 -         (*testout) << "D1 = " << endl << D1 << endl;
9720 +         (*testout) << "DefineTangentialPlane" << std::endl
9721 +         << "---------------------" << std::endl;
9722 +         (*testout) << "D1 = " << std::endl << D1 << std::endl;
9723         */
9724  
9725         Transpose (D1, D1T);
9726 @@ -270,7 +274,7 @@
9727         /*
9728           if(zone == -1)
9729           {
9730 -         (*testout) << "zone = -1 for " << p3d << " 2D: " << pplane << " n " << n << " nmid " << nmid << endl;
9731 +         (*testout) << "zone = -1 for " << p3d << " 2D: " << pplane << " n " << n << " nmid " << nmid << std::endl;
9732           glob_testout = true;
9733           GetNormalVector (p3d, geominfo, n);
9734           glob_testout = false;
9735 @@ -280,7 +284,7 @@
9736      else
9737        {
9738         pplane = Point<2>(geominfo.u, geominfo.v);
9739 -       //      (*testout) << "(u,v) = " << geominfo.u << ", " << geominfo.v << endl;
9740 +       //      (*testout) << "(u,v) = " << geominfo.u << ", " << geominfo.v << std::endl;
9741         pplane = Point<2> (1/h * (Amatinv * (pplane-psp1)));
9742         //      pplane = Point<2> (h * (Amatinv * (pplane-psp1)));
9743         //      pplane = Point<2> (1/h * ((pplane-psp1)));
9744 @@ -297,11 +301,11 @@
9745    { 
9746      if (projecttype == PLANESPACE)
9747        {
9748 -       //      cout << "2d   : " << pplane << endl;
9749 +       //      std::cout << "2d   : " << pplane << std::endl;
9750         p3d = p1 + (h * pplane(0)) * ex + (h * pplane(1)) * ey;
9751 -       //      cout << "3d   : " << p3d << endl;
9752 +       //      std::cout << "3d   : " << p3d << std::endl;
9753         Project (p3d, gi);  
9754 -       //      cout << "proj : " << p3d << endl;
9755 +       //      std::cout << "proj : " << p3d << std::endl;
9756        }
9757      else
9758        {
9759 @@ -321,11 +325,11 @@
9760    void OCCSurface :: Project (Point<3> & p, PointGeomInfo & gi)
9761    {
9762      //   static int cnt = 0;
9763 -    //  if (cnt++ % 1000 == 0) cout << "********************************************** OCCSurfce :: Project, cnt = " << cnt << endl;
9764 +    //  if (cnt++ % 1000 == 0) std::cout << "********************************************** OCCSurfce :: Project, cnt = " << cnt << std::endl;
9765    
9766      gp_Pnt pnt(p(0), p(1), p(2));
9767  
9768 -    //(*testout) << "pnt = " << pnt.X() << ", " << pnt.Y() << ", " << pnt.Z() << endl;
9769 +    //(*testout) << "pnt = " << pnt.X() << ", " << pnt.Y() << ", " << pnt.Z() << std::endl;
9770  
9771  
9772      /*
9773 @@ -333,7 +337,7 @@
9774  
9775      if (!proj.NbPoints())
9776        {
9777 -       cout << "Project Point on Surface FAIL" << endl;
9778 +       std::cout << "Project Point on Surface FAIL" << std::endl;
9779         throw UVBoundsException();
9780        }
9781      */
9782 @@ -343,13 +347,13 @@
9783  
9784  
9785      /*
9786 -      cout << "NP = " << proj.NbPoints() << endl;
9787 +      std::cout << "NP = " << proj.NbPoints() << std::endl;
9788  
9789        for (int i = 1; i <= proj.NbPoints(); i++)
9790        {
9791        gp_Pnt pnt2 = proj.Point(i);
9792        Point<3> p2 = Point<3> (pnt2.X(), pnt2.Y(), pnt2.Z());
9793 -      cout << i << ". p = " << p2 << ", dist = " << (p2-p).Length() << endl;
9794 +      std::cout << i << ". p = " << p2 << ", dist = " << (p2-p).Length() << std::endl;
9795        }
9796      */
9797  
9798 @@ -364,7 +368,7 @@
9799      suval.Coord( u, v);
9800      pnt = occface->Value( u, v );
9801      
9802 -    //(*testout) << "pnt(proj) = " << pnt.X() << ", " << pnt.Y() << ", " << pnt.Z() << endl;
9803 +    //(*testout) << "pnt(proj) = " << pnt.X() << ", " << pnt.Y() << ", " << pnt.Z() << std::endl;
9804      gi.u = u;
9805      gi.v = v;
9806      
9807 @@ -434,23 +438,33 @@
9808  
9809    void MeshOptimize2dOCCSurfaces :: ProjectPoint (INDEX surfind, Point<3> & p) const
9810    {
9811 -    geometry.Project (surfind, p);
9812 +    // geometry.Project (surfind, p); -- signature of Project() changed for optimization
9813 +    double u, v;
9814 +    geometry.Project (surfind, p, u, v);
9815    }
9816  
9817  
9818    int MeshOptimize2dOCCSurfaces :: ProjectPointGI (INDEX surfind, Point<3> & p, PointGeomInfo & gi) const
9819    {
9820 -    double u = gi.u;
9821 -    double v = gi.v;
9822 +    //double u = gi.u;
9823 +    //double v = gi.v;
9824  
9825      Point<3> hp = p;
9826 -    if (geometry.FastProject (surfind, hp, u, v))
9827 -      {
9828 +    // -- u and v are computed by FastProject() and Project(), no need to call CalcPointGeomInfo()
9829 +    // if (geometry.FastProject (surfind, hp, u, v))
9830 +    //   {
9831 +    //    p = hp;
9832 +    //    return 1;
9833 +    //   }
9834 +    // ProjectPoint (surfind, p); 
9835 +    // return CalcPointGeomInfo (surfind, gi, p); 
9836 +    bool ok;
9837 +    if (gi.trignum > 0)
9838 +      ok = geometry.FastProject (surfind, hp, gi.u, gi.v);
9839 +    else
9840 +      ok = geometry.Project (surfind, hp, gi.u, gi.v);
9841         p = hp;
9842 -       return 1;
9843 -      }
9844 -    ProjectPoint (surfind, p); 
9845 -    return CalcPointGeomInfo (surfind, gi, p); 
9846 +    return ok;
9847    }
9848  
9849  
9850 @@ -506,7 +520,7 @@
9851    GetNormalVector(INDEX surfind, const Point<3> & p, Vec<3> & n) const
9852    {
9853      //  static int cnt = 0;
9854 -    //  if (cnt++ % 1000 == 0) cout << "GetNV cnt = " << cnt << endl;
9855 +    //  if (cnt++ % 1000 == 0) std::cout << "GetNV cnt = " << cnt << std::endl;
9856      Standard_Real u,v;
9857  
9858      gp_Pnt pnt(p(0), p(1), p(2));
9859 @@ -519,9 +533,9 @@
9860  
9861      if (proj.NbPoints() < 1)
9862        {
9863 -       cout << "ERROR: OCCSurface :: GetNormalVector: GeomAPI_ProjectPointOnSurf failed!"
9864 -            << endl;
9865 -       cout << p << endl;
9866 +       std::cout << "ERROR: OCCSurface :: GetNormalVector: GeomAPI_ProjectPointOnSurf failed!"
9867 +            << std::endl;
9868 +       std::cout << p << std::endl;
9869         return;
9870        }
9871   
9872 @@ -540,7 +554,7 @@
9873  
9874      /*
9875        if (!occface->IsCNu (1) || !occface->IsCNv (1))
9876 -      (*testout) << "SurfOpt: Differentiation FAIL" << endl;
9877 +      (*testout) << "SurfOpt: Differentiation FAIL" << std::endl;
9878      */
9879  
9880      n = Cross (Vec3d(du.X(), du.Y(), du.Z()),
9881 @@ -566,9 +580,9 @@
9882  
9883      if (proj.NbPoints() < 1)
9884        {
9885 -       cout << "ERROR: OCCSurface :: GetNormalVector: GeomAPI_ProjectPointOnSurf failed!"
9886 -            << endl;
9887 -       cout << p << endl;
9888 +       std::cout << "ERROR: OCCSurface :: GetNormalVector: GeomAPI_ProjectPointOnSurf failed!"
9889 +            << std::endl;
9890 +       std::cout << p << std::endl;
9891         return 0;
9892        }
9893   
9894 @@ -679,8 +693,9 @@
9895   
9896         if (!geometry.FastProject (surfi, hnewp, u, v))
9897           {
9898 -         //  cout << "Fast projection to surface fails! Using OCC projection" << endl;
9899 -           geometry.Project (surfi, hnewp);
9900 +         //  std::cout << "Fast projection to surface fails! Using OCC projection" << std::endl;
9901 +           // geometry.Project (surfi, hnewp); -- Project() changed for optimization
9902 +           geometry.Project (surfi, hnewp, u, v);
9903           }
9904  
9905         newgi.trignum = 1;
9906 @@ -689,7 +704,7 @@
9907        }
9908    
9909      newp = hnewp;
9910 -  }
9911 +  }//; -- to compile with -Wall -pedantic
9912  
9913  
9914    void OCCRefinementSurfaces :: 
9915 @@ -708,24 +723,29 @@
9916      hnewp = Point<3> (pnt.X(), pnt.Y(), pnt.Z());
9917      newp = hnewp;
9918      newgi = ap1;
9919 -  };
9920 +  }//; -- to compile with -Wall -pedantic
9921  
9922  
9923    void OCCRefinementSurfaces :: ProjectToSurface (Point<3> & p, int surfi) const
9924    {
9925      if (surfi > 0)
9926 -      geometry.Project (surfi, p);
9927 -  };
9928 +      //geometry.Project (surfi, p);
9929 +    {
9930 +      double u, v;
9931 +      geometry.Project (surfi, p, u, v);
9932 +    }
9933 +  }//; -- to compile with -Wall -pedantic
9934  
9935    void OCCRefinementSurfaces :: ProjectToSurface (Point<3> & p, int surfi, PointGeomInfo & gi) const
9936    {
9937      if (surfi > 0)
9938        if (!geometry.FastProject (surfi, p, gi.u, gi.v))
9939         {
9940 -         cout << "Fast projection to surface fails! Using OCC projection" << endl;
9941 -         geometry.Project (surfi, p);
9942 +         std::cout << "Fast projection to surface fails! Using OCC projection" << std::endl;
9943 +          double u, v;
9944 +         geometry.Project (surfi, p, u, v);
9945         }
9946 -  };
9947 +       }
9948  
9949  
9950  
9951 --- netgen_ref/libsrc/occ/occmeshsurf.hpp
9952 +++ netgen/libsrc/occ/occmeshsurf.hpp
9953 @@ -169,7 +169,7 @@
9954  class OCCGeometry;
9955  
9956  
9957 -class OCCRefinementSurfaces : public Refinement
9958 +class DLL_HEADER OCCRefinementSurfaces : public Refinement
9959  {
9960    const OCCGeometry & geometry;
9961  
9962 --- netgen_ref/libsrc/occ/occpkg.cpp
9963 +++ netgen/libsrc/occ/occpkg.cpp
9964 @@ -1,1024 +1,1024 @@
9965 -#ifdef OCCGEOMETRY
9966 -
9967 -#include <mystdlib.h>
9968 -#include <myadt.hpp>
9969 -#include <linalg.hpp>
9970 -#include <csg.hpp>
9971 -#include <occgeom.hpp>
9972 -
9973 -
9974 -#include <incvis.hpp>
9975 -#include <visual.hpp>
9976 -
9977 -#include "../meshing/bcfunctions.hpp"
9978 -
9979 -#include "vsocc.hpp"
9980 -
9981 -
9982 -extern "C" int Ng_occ_Init (Tcl_Interp * interp);
9983 -
9984 -
9985 -
9986 -namespace netgen
9987 -{
9988 -  extern AutoPtr<NetgenGeometry> ng_geometry;
9989 -  extern AutoPtr<Mesh> mesh;
9990
9991 -  char * err_needsoccgeometry = (char*) "This operation needs an OCC geometry";
9992 -  extern char * err_needsmesh;
9993 -  extern char * err_jobrunning;
9994 -
9995 -
9996 -
9997 -                          
9998 -  class OCCGeometryRegister : public GeometryRegister
9999 -  {
10000 -  public:
10001 -    virtual NetgenGeometry * Load (string filename) const;
10002 -    virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const;
10003 -
10004 -    virtual void SetParameters (Tcl_Interp * interp) 
10005 -    {
10006 -      occparam.resthcloseedgefac =
10007 -       atof (Tcl_GetVar (interp, "::stloptions.resthcloseedgefac", 0));
10008 -      occparam.resthcloseedgeenable =
10009 -       atoi (Tcl_GetVar (interp, "::stloptions.resthcloseedgeenable", 0));
10010 -         occparam.resthminedgelen = 
10011 -       atof (Tcl_GetVar (interp, "::stloptions.resthminedgelen", 0));
10012 -         occparam.resthminedgelenenable = 
10013 -       atoi (Tcl_GetVar (interp, "::stloptions.resthminedgelenenable", 0));
10014 -    }
10015 -  };
10016 -
10017 -
10018 -
10019 -
10020 -  int Ng_SetOCCVisParameters  (ClientData clientData,
10021 -                              Tcl_Interp * interp,
10022 -                              int argc, tcl_const char *argv[])
10023 -  {
10024 -#ifdef OCCGEOMETRY
10025 -    int showvolume;
10026 -       OCCGeometry * occgeometry = dynamic_cast<OCCGeometry*> (ng_geometry.Ptr());
10027 -
10028 -    showvolume = atoi (Tcl_GetVar (interp, "::occoptions.showvolumenr", 0));
10029 -
10030 -    if (occgeometry)
10031 -      if (showvolume != vispar.occshowvolumenr)
10032 -       {
10033 -         if (showvolume < 0 || showvolume > occgeometry->NrSolids())
10034 -           {
10035 -             char buf[20];
10036 -             sprintf (buf, "%5i", vispar.occshowvolumenr);
10037 -             Tcl_SetVar (interp, "::occoptions.showvolumenr", buf, 0);
10038 -           }
10039 -         else
10040 -           {
10041 -             vispar.occshowvolumenr = showvolume;
10042 -             if (occgeometry)
10043 -               occgeometry -> changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10044 -           }
10045 -       }
10046 -    
10047 -    int temp;
10048 -
10049 -    temp = atoi (Tcl_GetVar (interp, "::occoptions.visproblemfaces", 0));
10050 -
10051 -    if ((bool) temp != vispar.occvisproblemfaces)
10052 -      {
10053 -       vispar.occvisproblemfaces = temp;
10054 -       if (occgeometry)
10055 -         occgeometry -> changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10056 -      }
10057 -
10058 -    vispar.occshowsurfaces = atoi (Tcl_GetVar (interp, "::occoptions.showsurfaces", 0));
10059 -    vispar.occshowedges = atoi (Tcl_GetVar (interp, "::occoptions.showedges", 0));
10060 -    vispar.occzoomtohighlightedentity = atoi (Tcl_GetVar (interp, "::occoptions.zoomtohighlightedentity", 0));
10061 -    vispar.occdeflection = pow(10.0,-1-atof (Tcl_GetVar (interp, "::occoptions.deflection", 0)));
10062 -
10063 -#endif
10064 -
10065 -
10066 -
10067 -
10068 -
10069 -#ifdef ACIS
10070 -    vispar.ACISshowfaces = atoi (Tcl_GetVar (interp, "::occoptions.showsurfaces", 0));
10071 -    vispar.ACISshowedges = atoi (Tcl_GetVar (interp, "::occoptions.showedges", 0));
10072 -    vispar.ACISshowsolidnr = atoi (Tcl_GetVar (interp, "::occoptions.showsolidnr", 0));
10073 -    vispar.ACISshowsolidnr2 = atoi (Tcl_GetVar (interp, "::occoptions.showsolidnr2", 0));
10074 -
10075 -#endif
10076 -
10077 -
10078 -
10079 -    return TCL_OK;
10080 -  }  
10081 -
10082 -
10083 -
10084 -
10085 -  int Ng_GetOCCData (ClientData clientData,
10086 -                    Tcl_Interp * interp,
10087 -                    int argc, tcl_const char *argv[])
10088 -  {
10089 -#ifdef OCCGEOMETRY
10090 -    OCCGeometry * occgeometry = dynamic_cast<OCCGeometry*> (ng_geometry.Ptr());
10091 -
10092 -    static char buf[1000];
10093 -    buf[0] = 0;
10094 -    stringstream str;
10095 -
10096 -    if (argc >= 2)
10097 -      {
10098 -       if (strcmp (argv[1], "getentities") == 0)
10099 -         {
10100 -           if (occgeometry)
10101 -             {
10102 -               occgeometry->GetTopologyTree(str);
10103 -             }
10104 -         }
10105 -      }
10106 -
10107 -    Tcl_SetResult (interp, (char*)str.str().c_str(), TCL_VOLATILE);
10108 -
10109 -#endif
10110 -    return TCL_OK;
10111 -  }
10112 -
10113 -  
10114 -
10115 -  int Ng_OCCCommand (ClientData clientData,
10116 -                    Tcl_Interp * interp,
10117 -                    int argc, tcl_const char *argv[])
10118 -  {
10119 -#ifdef OCCGEOMETRY
10120 -    OCCGeometry * occgeometry = dynamic_cast<OCCGeometry*> (ng_geometry.Ptr());
10121 -
10122 -    stringstream str;
10123 -    if (argc >= 2)
10124 -      {
10125 -       if (strcmp (argv[1], "isoccgeometryloaded") == 0)
10126 -         {
10127 -           if (occgeometry)
10128 -             str << "1 " << flush;
10129 -           else str << "0 " << flush;
10130 -
10131 -           Tcl_SetResult (interp, (char*)str.str().c_str(), TCL_VOLATILE);
10132 -         }
10133 -       if (occgeometry)
10134 -         {
10135 -           if (strcmp (argv[1], "buildvisualizationmesh") == 0)
10136 -             {
10137 -               occgeometry->BuildVisualizationMesh(vispar.occdeflection);
10138 -               occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10139 -             }
10140 -           if (strcmp (argv[1], "mesherror") == 0)
10141 -             {
10142 -               if (occgeometry->ErrorInSurfaceMeshing())
10143 -                 str << 1;
10144 -               else
10145 -                 str << 0;
10146 -             }
10147 -           if (strcmp (argv[1], "sewfaces") == 0)
10148 -             {
10149 -               cout << "Before operation:" << endl;
10150 -               occgeometry->PrintNrShapes();
10151 -               occgeometry->SewFaces();
10152 -               occgeometry->BuildFMap();
10153 -               cout << endl << "After operation:" << endl;
10154 -               occgeometry->PrintNrShapes();
10155 -               occgeometry->BuildVisualizationMesh(vispar.occdeflection);
10156 -               occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10157 -             }
10158 -           if (strcmp (argv[1], "makesolid") == 0)
10159 -             {
10160 -               cout << "Before operation:" << endl;
10161 -               occgeometry->PrintNrShapes();
10162 -               occgeometry->MakeSolid();
10163 -               occgeometry->BuildFMap();
10164 -               cout << endl << "After operation:" << endl;
10165 -               occgeometry->PrintNrShapes();
10166 -               occgeometry->BuildVisualizationMesh(vispar.occdeflection);
10167 -               occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10168 -             }
10169 -           if (strcmp (argv[1], "upgradetopology") == 0)
10170 -             {
10171 -               cout << "Before operation:" << endl;
10172 -               occgeometry->PrintNrShapes();
10173 -               occgeometry->SewFaces();
10174 -               occgeometry->MakeSolid();
10175 -               occgeometry->BuildFMap();
10176 -               cout << endl << "After operation:" << endl;
10177 -               occgeometry->PrintNrShapes();
10178 -               occgeometry->BuildVisualizationMesh(vispar.occdeflection);
10179 -               occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10180 -             }
10181 -           if (strcmp (argv[1], "shapehealing") == 0)
10182 -             {
10183 -               occgeometry->tolerance =
10184 -                 atof (Tcl_GetVar (interp, "::occoptions.tolerance", 0));
10185 -               occgeometry->fixsmalledges =
10186 -                 atoi (Tcl_GetVar (interp, "::occoptions.fixsmalledges", 0));
10187 -               occgeometry->fixspotstripfaces =
10188 -                 atoi (Tcl_GetVar (interp, "::occoptions.fixspotstripfaces", 0));
10189 -               occgeometry->sewfaces =
10190 -                 atoi (Tcl_GetVar (interp, "::occoptions.sewfaces", 0));
10191 -               occgeometry->makesolids =
10192 -                 atoi (Tcl_GetVar (interp, "::occoptions.makesolids", 0));
10193 -               occgeometry->splitpartitions =
10194 -                 atoi (Tcl_GetVar (interp, "::occoptions.splitpartitions", 0));
10195 -
10196 -               //            cout << "Before operation:" << endl;
10197 -               //            occgeometry->PrintNrShapes();
10198 -               occgeometry->HealGeometry();
10199 -               occgeometry->BuildFMap();
10200 -               //            cout << endl << "After operation:" << endl;
10201 -               //            occgeometry->PrintNrShapes();
10202 -               occgeometry->BuildVisualizationMesh(vispar.occdeflection);
10203 -               occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10204 -             }
10205 -
10206 -
10207 -           if (strcmp (argv[1], "highlightentity") == 0)
10208 -             {
10209 -               if (strcmp (argv[2], "Face") == 0)
10210 -                 {
10211 -                   int nr = atoi (argv[3]);
10212 -                   occgeometry->LowLightAll();
10213 -
10214 -                   occgeometry->fvispar[nr-1].Highlight();
10215 -                   if (vispar.occzoomtohighlightedentity)
10216 -                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
10217 -                   else
10218 -                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10219 -                 }
10220 -               if (strcmp (argv[2], "Shell") == 0)
10221 -                 {
10222 -                   int nr = atoi (argv[3]);
10223 -                   occgeometry->LowLightAll();
10224 -
10225 -                   TopExp_Explorer exp;
10226 -                   for (exp.Init (occgeometry->shmap(nr), TopAbs_FACE);
10227 -                        exp.More(); exp.Next())
10228 -                     {
10229 -                       int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
10230 -                       occgeometry->fvispar[i-1].Highlight();
10231 -                     }
10232 -                   if (vispar.occzoomtohighlightedentity)
10233 -                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
10234 -                   else
10235 -                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10236 -                 }
10237 -               if (strcmp (argv[2], "Solid") == 0)
10238 -                 {
10239 -                   int nr = atoi (argv[3]);
10240 -                   occgeometry->LowLightAll();
10241 -
10242 -                   TopExp_Explorer exp;
10243 -                   for (exp.Init (occgeometry->somap(nr), TopAbs_FACE);
10244 -                        exp.More(); exp.Next())
10245 -                     {
10246 -                       int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
10247 -                       occgeometry->fvispar[i-1].Highlight();
10248 -                     }
10249 -                   if (vispar.occzoomtohighlightedentity)
10250 -                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
10251 -                   else
10252 -                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10253 -                 }
10254 -               /*
10255 -                 if (strcmp (argv[2], "CompSolid") == 0)
10256 -                 {
10257 -                 int nr = atoi (argv[3]);
10258 -                 occgeometry->LowLightAll();
10259 -
10260 -                 TopExp_Explorer exp;
10261 -                 for (exp.Init (occgeometry->cmap(nr), TopAbs_FACE);
10262 -                 exp.More(); exp.Next())
10263 -                 {
10264 -                 int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
10265 -                 occgeometry->fvispar[i-1].Highlight();
10266 -                 }
10267 -                 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10268 -                 }
10269 -               */
10270 -
10271 -               if (strcmp (argv[2], "Edge") == 0)
10272 -                 {
10273 -                   int nr = atoi (argv[3]);
10274 -                   occgeometry->LowLightAll();
10275 -
10276 -                   occgeometry->evispar[nr-1].Highlight();
10277 -                   if (vispar.occzoomtohighlightedentity)
10278 -                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
10279 -                   else
10280 -                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10281 -                 }
10282 -               if (strcmp (argv[2], "Wire") == 0)
10283 -                 {
10284 -                   int nr = atoi (argv[3]);
10285 -                   occgeometry->LowLightAll();
10286 -
10287 -                   TopExp_Explorer exp;
10288 -                   for (exp.Init (occgeometry->wmap(nr), TopAbs_EDGE);
10289 -                        exp.More(); exp.Next())
10290 -                     {
10291 -                       int i = occgeometry->emap.FindIndex (TopoDS::Edge(exp.Current()));
10292 -                       occgeometry->evispar[i-1].Highlight();
10293 -                     }
10294 -                   if (vispar.occzoomtohighlightedentity)
10295 -                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
10296 -                   else
10297 -                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10298 -                 }
10299 -
10300 -               if (strcmp (argv[2], "Vertex") == 0)
10301 -                 {
10302 -                   int nr = atoi (argv[3]);
10303 -                   occgeometry->LowLightAll();
10304 -
10305 -                   occgeometry->vvispar[nr-1].Highlight();
10306 -                   if (vispar.occzoomtohighlightedentity)
10307 -                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
10308 -                   else
10309 -                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10310 -                 }
10311 -
10312 -             }
10313 -
10314 -
10315 -
10316 -           if (strcmp (argv[1], "show") == 0)
10317 -             {
10318 -               int nr = atoi (argv[3]);
10319 -               occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10320 -
10321 -               if (strcmp (argv[2], "Face") == 0)
10322 -                 {
10323 -                   occgeometry->fvispar[nr-1].Show();
10324 -                 }
10325 -               if (strcmp (argv[2], "Shell") == 0)
10326 -                 {
10327 -                   TopExp_Explorer exp;
10328 -                   for (exp.Init (occgeometry->shmap(nr), TopAbs_FACE);
10329 -                        exp.More(); exp.Next())
10330 -                     {
10331 -                       int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
10332 -                       occgeometry->fvispar[i-1].Show();
10333 -                     }
10334 -                 }
10335 -               if (strcmp (argv[2], "Solid") == 0)
10336 -                 {
10337 -                   TopExp_Explorer exp;
10338 -                   for (exp.Init (occgeometry->somap(nr), TopAbs_FACE);
10339 -                        exp.More(); exp.Next())
10340 -                     {
10341 -                       int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
10342 -                       occgeometry->fvispar[i-1].Show();
10343 -                     }
10344 -                 }
10345 -               if (strcmp (argv[2], "Edge") == 0)
10346 -                 {
10347 -                   occgeometry->evispar[nr-1].Show();
10348 -                 }
10349 -               if (strcmp (argv[2], "Wire") == 0)
10350 -                 {
10351 -                   TopExp_Explorer exp;
10352 -                   for (exp.Init (occgeometry->wmap(nr), TopAbs_EDGE);
10353 -                        exp.More(); exp.Next())
10354 -                     {
10355 -                       int i = occgeometry->emap.FindIndex (TopoDS::Edge(exp.Current()));
10356 -                       occgeometry->evispar[i-1].Show();
10357 -                     }
10358 -                 }
10359 -             }
10360 -
10361 -
10362 -           if (strcmp (argv[1], "hide") == 0)
10363 -             {
10364 -               int nr = atoi (argv[3]);
10365 -               occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10366 -
10367 -               if (strcmp (argv[2], "Face") == 0)
10368 -                 {
10369 -                   occgeometry->fvispar[nr-1].Hide();
10370 -                 }
10371 -               if (strcmp (argv[2], "Shell") == 0)
10372 -                 {
10373 -                   TopExp_Explorer exp;
10374 -                   for (exp.Init (occgeometry->shmap(nr), TopAbs_FACE);
10375 -                        exp.More(); exp.Next())
10376 -                     {
10377 -                       int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
10378 -                       occgeometry->fvispar[i-1].Hide();
10379 -                     }
10380 -                 }
10381 -               if (strcmp (argv[2], "Solid") == 0)
10382 -                 {
10383 -                   TopExp_Explorer exp;
10384 -                   for (exp.Init (occgeometry->somap(nr), TopAbs_FACE);
10385 -                        exp.More(); exp.Next())
10386 -                     {
10387 -                       int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
10388 -                       occgeometry->fvispar[i-1].Hide();
10389 -                     }
10390 -                 }
10391 -               if (strcmp (argv[2], "Edge") == 0)
10392 -                 {
10393 -                   occgeometry->evispar[nr-1].Hide();
10394 -                 }
10395 -               if (strcmp (argv[2], "Wire") == 0)
10396 -                 {
10397 -                   TopExp_Explorer exp;
10398 -                   for (exp.Init (occgeometry->wmap(nr), TopAbs_EDGE);
10399 -                        exp.More(); exp.Next())
10400 -                     {
10401 -                       int i = occgeometry->emap.FindIndex (TopoDS::Edge(exp.Current()));
10402 -                       occgeometry->evispar[i-1].Hide();
10403 -                     }
10404 -                 }
10405 -             }
10406 -
10407 -
10408 -
10409 -           if (strcmp (argv[1], "findsmallentities") == 0)
10410 -             {
10411 -               stringstream str("");
10412 -               occgeometry->CheckIrregularEntities(str);
10413 -               Tcl_SetResult (interp, (char*)str.str().c_str(), TCL_VOLATILE);
10414 -             }
10415 -           if (strcmp (argv[1], "getunmeshedfaceinfo") == 0)
10416 -             {
10417 -               occgeometry->GetUnmeshedFaceInfo(str);
10418 -               Tcl_SetResult (interp, (char*)str.str().c_str(), TCL_VOLATILE);
10419 -             }
10420 -           if (strcmp (argv[1], "getnotdrawablefaces") == 0)
10421 -             {
10422 -               occgeometry->GetNotDrawableFaces(str);
10423 -               Tcl_SetResult (interp, (char*)str.str().c_str(), TCL_VOLATILE);
10424 -             }
10425 -           if (strcmp (argv[1], "redrawstatus") == 0)
10426 -             {
10427 -               int i = atoi (argv[2]);
10428 -               occgeometry->changed = i;
10429 -             }
10430 -           if (strcmp (argv[1], "swaporientation") == 0)
10431 -             {
10432 -               IGESControl_Writer writer("millimeters", 1);
10433 -               writer.AddShape (occgeometry->shape);
10434 -               writer.Write ("1.igs");
10435 -               /*
10436 -                 int nr = atoi (argv[3]);
10437 -
10438 -                 //          const_cast<TopoDS_Shape&> (occgeometry->fmap(nr)).Reverse();
10439 -
10440 -                 Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;
10441 -                 rebuild->Apply(occgeometry->shape);
10442 -
10443 -                 TopoDS_Shape sh;
10444 -
10445 -                 //          if (strcmp (argv[2], "CompSolid") == 0) sh = occgeometry->cmap(nr);
10446 -                 if (strcmp (argv[2], "Solid") == 0) sh = occgeometry->somap(nr);
10447 -                 if (strcmp (argv[2], "Shell") == 0) sh = occgeometry->shmap(nr);
10448 -                 if (strcmp (argv[2], "Face") == 0) sh = occgeometry->fmap(nr);
10449 -                 if (strcmp (argv[2], "Wire") == 0) sh = occgeometry->wmap(nr);
10450 -                 if (strcmp (argv[2], "Edge") == 0) sh = occgeometry->emap(nr);
10451 -
10452 -                 rebuild->Replace(sh, sh.Reversed(), Standard_False);
10453 -
10454 -                 TopoDS_Shape newshape = rebuild->Apply(occgeometry->shape, TopAbs_SHELL, 1);
10455 -                 occgeometry->shape = newshape;
10456 -
10457 -                 occgeometry->BuildFMap();
10458 -                 occgeometry->BuildVisualizationMesh();
10459 -                 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10460 -               */
10461 -             }
10462 -           if (strcmp (argv[1], "marksingular") == 0)
10463 -             {
10464 -               int nr = atoi (argv[3]);
10465 -               cout << "marking " << argv[2] << " " << nr << endl;
10466 -               char buf[2]; buf[0] = '0'; buf[1] = 0;
10467 -               bool sing = false;
10468 -               if (strcmp (argv[2], "Face") == 0)
10469 -                 sing = occgeometry->fsingular[nr-1] = !occgeometry->fsingular[nr-1];
10470 -               if (strcmp (argv[2], "Edge") == 0)
10471 -                 sing = occgeometry->esingular[nr-1] = !occgeometry->esingular[nr-1];
10472 -               if (strcmp (argv[2], "Vertex") == 0)
10473 -                 sing = occgeometry->vsingular[nr-1] = !occgeometry->vsingular[nr-1];
10474 -
10475 -               if (sing) buf[0] = '1';
10476 -
10477 -                Tcl_SetVar (interp, "::ismarkedsingular", buf, 0);
10478 -
10479 -               stringstream str;
10480 -               occgeometry->GetTopologyTree (str);
10481 -
10482 -               char* cstr = (char*)str.str().c_str();
10483 -
10484 -               (*testout) << cstr << endl;
10485 -
10486 -               char helpstr[1000];
10487 -
10488 -               while (strchr (cstr, '}'))
10489 -                 {
10490 -                   strncpy (helpstr, cstr+2, strlen(strchr(cstr+2, '}')));
10491 -                   (*testout) << "***" << cstr << "***" << endl;
10492 -                   cstr = strchr (cstr, '}');
10493 -                 } 
10494 -             }
10495 -         }
10496 -      }
10497 -
10498 -#endif
10499 -    return TCL_OK;
10500 -  }
10501 -
10502 -
10503 -
10504 -#ifdef OCCGEOMETRY
10505 -  /*
10506 -  void OCCConstructGeometry (OCCGeometry & geom);
10507 -
10508 -  int Ng_OCCConstruction (ClientData clientData,
10509 -                         Tcl_Interp * interp,
10510 -                         int argc, tcl_const char *argv[])
10511 -  {
10512 -    if (occgeometry)
10513 -      OCCConstructGeometry (*occgeometry);
10514 -    return TCL_OK;
10515 -  }
10516 -  */
10517 -#endif
10518 -
10519 -
10520 -
10521 -
10522 -  // Philippose - 30/01/2009
10523 -  // TCL interface function for the Local Face Mesh size
10524 -  // definition functionality
10525 -  int Ng_SurfaceMeshSize (ClientData clientData,
10526 -                                   Tcl_Interp * interp,
10527 -                                   int argc, tcl_const char *argv[])
10528 -  {
10529 -#ifdef OCCGEOMETRY
10530 -
10531 -    static char buf[100];
10532 -
10533 -    if (argc < 2)
10534 -    {
10535 -          Tcl_SetResult (interp, (char *)"Ng_SurfaceMeshSize needs arguments", TCL_STATIC);
10536 -          return TCL_ERROR;
10537 -    }
10538 -
10539 -    OCCGeometry * occgeometry = dynamic_cast<OCCGeometry*> (ng_geometry.Ptr());
10540 -    if (!occgeometry)
10541 -    {
10542 -      Tcl_SetResult (interp, (char *)"Ng_SurfaceMeshSize currently supports only OCC (STEP/IGES) Files", TCL_STATIC);
10543 -          return TCL_ERROR;
10544 -    }
10545 -
10546 -    // Update the face mesh sizes to reflect the global maximum mesh size
10547 -    for(int i = 1; i <= occgeometry->NrFaces(); i++)
10548 -    {
10549 -           if(!occgeometry->GetFaceMaxhModified(i))
10550 -           {
10551 -              occgeometry->SetFaceMaxH(i, mparam.maxh);
10552 -           }   
10553 -    }
10554 -
10555 -    if (strcmp (argv[1], "setsurfms") == 0)
10556 -    {
10557 -          int facenr = atoi (argv[2]);
10558 -          double surfms = atof (argv[3]);
10559 -          if (occgeometry && facenr >= 1 && facenr <= occgeometry->NrFaces())
10560 -            occgeometry->SetFaceMaxH(facenr, surfms);
10561 -
10562 -    }
10563 -
10564 -    if (strcmp (argv[1], "setall") == 0)
10565 -    {
10566 -          double surfms = atof (argv[2]);
10567 -          if (occgeometry)
10568 -          {
10569 -            int nrFaces = occgeometry->NrFaces();
10570 -            for (int i = 1; i <= nrFaces; i++)
10571 -             occgeometry->SetFaceMaxH(i, surfms);
10572 -          }
10573 -    }
10574 -
10575 -    if (strcmp (argv[1], "getsurfms") == 0)
10576 -    {
10577 -          int facenr = atoi (argv[2]);
10578 -          if (occgeometry && facenr >= 1 && facenr <= occgeometry->NrFaces())
10579 -          {
10580 -            sprintf (buf, "%5.2f", occgeometry->GetFaceMaxH(facenr));
10581 -          }
10582 -          else
10583 -          {
10584 -            sprintf (buf, "%5.2f", mparam.maxh);
10585 -          }
10586 -          Tcl_SetResult (interp, buf, TCL_STATIC);
10587 -    }
10588 -
10589 -    if (strcmp (argv[1], "getactive") == 0)
10590 -    {
10591 -          sprintf (buf, "%d", occgeometry->SelectedFace());
10592 -          Tcl_SetResult (interp, buf, TCL_STATIC);
10593 -    }
10594 -
10595 -    if (strcmp (argv[1], "setactive") == 0)
10596 -    {
10597 -          int facenr = atoi (argv[2]);
10598 -          if (occgeometry && facenr >= 1 && facenr <= occgeometry->NrFaces())
10599 -          {
10600 -            occgeometry->SetSelectedFace (facenr);
10601 -
10602 -        occgeometry->LowLightAll();
10603 -        occgeometry->fvispar[facenr-1].Highlight();
10604 -        occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
10605 -          }
10606 -    }
10607 -
10608 -    if (strcmp (argv[1], "getnfd") == 0)
10609 -    {
10610 -          if (occgeometry)
10611 -            sprintf (buf, "%d", occgeometry->NrFaces());
10612 -          else
10613 -            sprintf (buf, "0");
10614 -          Tcl_SetResult (interp, buf, TCL_STATIC);
10615 -    }
10616 -    return TCL_OK;
10617 -#else // No OCCGEOMETRY 
10618 -
10619 -    Tcl_SetResult (interp, (char *)"Ng_SurfaceMeshSize currently supports only OCC (STEP/IGES) Files", TCL_STATIC);
10620 -    return TCL_ERROR;
10621 -    
10622 -#endif // OCCGEOMETRY
10623 -  }
10624 -
10625 -
10626 -
10627 -  // Philippose - 25/07/2010
10628 -  // TCL interface function for extracting and eventually 
10629 -  // setting or editing the current colours present in the mesh
10630 -  int Ng_CurrentFaceColours (ClientData clientData,
10631 -                             Tcl_Interp * interp,
10632 -                             int argc, tcl_const char *argv[])
10633 -  {
10634 -     if(argc < 1)
10635 -     {
10636 -        Tcl_SetResult (interp, (char *)"Ng_GetCurrentFaceColours needs arguments", TCL_STATIC);
10637 -        return TCL_ERROR;
10638 -     }
10639 -
10640 -     if(!mesh.Ptr())
10641 -     {
10642 -        Tcl_SetResult (interp, (char *)"Ng_GetCurrentFaceColours: Valid netgen mesh required...please mesh the Geometry first", TCL_STATIC);
10643 -            return TCL_ERROR;
10644 -     }
10645 -
10646 -     if(strcmp(argv[1], "getcolours") == 0)
10647 -     {
10648 -        stringstream outVar;
10649 -        Array<Vec3d> face_colours;
10650 -        GetFaceColours(*mesh, face_colours);
10651 -
10652 -        for(int i = 0; i < face_colours.Size();i++)
10653 -        {
10654 -           outVar << "{ " << face_colours[i].X(1)
10655 -                  << " "  << face_colours[i].X(2)
10656 -                  << " "  << face_colours[i].X(3)
10657 -                  << " } ";
10658 -        }
10659 -
10660 -        tcl_const char * valuevar = argv[2];
10661 -        Tcl_SetVar  (interp, valuevar, (char*)outVar.str().c_str(), 0);
10662 -     }
10663 -
10664 -     if(strcmp(argv[1], "showalso") == 0)
10665 -     {
10666 -        Array<Vec3d> face_colours;
10667 -        GetFaceColours(*mesh,face_colours);
10668 -
10669 -        int colourind = atoi (argv[2]);
10670 -
10671 -        for(int i = 1; i <= mesh->GetNFD(); i++)
10672 -        {
10673 -           Array<SurfaceElementIndex> surfElems;
10674 -           mesh->GetSurfaceElementsOfFace(i,surfElems);
10675 -
10676 -           if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour()))
10677 -           {
10678 -              for(int j = 0; j < surfElems.Size(); j++)
10679 -              {
10680 -                 mesh->SurfaceElement(surfElems[j]).Visible(1);
10681 -              }
10682 -           }
10683 -        }
10684 -
10685 -        mesh->SetNextTimeStamp();
10686 -     }
10687 -
10688 -     if(strcmp(argv[1], "hidealso") == 0)
10689 -     {
10690 -        Array<Vec3d> face_colours;
10691 -        GetFaceColours(*mesh,face_colours);
10692 -
10693 -        int colourind = atoi (argv[2]);
10694 -
10695 -        for(int i = 1; i <= mesh->GetNFD(); i++)
10696 -        {
10697 -           Array<SurfaceElementIndex> surfElems;
10698 -           mesh->GetSurfaceElementsOfFace(i,surfElems);
10699 -
10700 -           if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour()))
10701 -           {
10702 -              for(int j = 0; j < surfElems.Size(); j++)
10703 -              {
10704 -                 mesh->SurfaceElement(surfElems[j]).Visible(0);
10705 -              }
10706 -           }
10707 -        }
10708 -
10709 -        mesh->SetNextTimeStamp();
10710 -     }
10711 -
10712 -     if(strcmp(argv[1], "showonly") == 0)
10713 -     {
10714 -        Array<Vec3d> face_colours;
10715 -        GetFaceColours(*mesh,face_colours);
10716 -
10717 -        int colourind = atoi (argv[2]);
10718 -
10719 -        for(int i = 1; i <= mesh->GetNFD(); i++)
10720 -        {
10721 -           Array<SurfaceElementIndex> surfElems;
10722 -           mesh->GetSurfaceElementsOfFace(i,surfElems);
10723 -
10724 -           if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour()))
10725 -           {
10726 -              for(int j = 0; j < surfElems.Size(); j++)
10727 -              {
10728 -                 mesh->SurfaceElement(surfElems[j]).Visible(1);
10729 -              }
10730 -           }
10731 -           else
10732 -           {
10733 -              for(int j = 0; j < surfElems.Size(); j++)
10734 -              {
10735 -                 mesh->SurfaceElement(surfElems[j]).Visible(0);
10736 -              }
10737 -           }
10738 -        }
10739 -
10740 -        mesh->SetNextTimeStamp();
10741 -     }
10742 -
10743 -     if(strcmp(argv[1], "hideonly") == 0)
10744 -     {
10745 -        Array<Vec3d> face_colours;
10746 -        GetFaceColours(*mesh,face_colours);
10747 -
10748 -        int colourind = atoi (argv[2]);
10749 -
10750 -        for(int i = 1; i <= mesh->GetNFD(); i++)
10751 -        {
10752 -           Array<SurfaceElementIndex> surfElems;
10753 -           mesh->GetSurfaceElementsOfFace(i,surfElems);
10754 -
10755 -           if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour()))
10756 -           {
10757 -              for(int j = 0; j < surfElems.Size(); j++)
10758 -              {
10759 -                 mesh->SurfaceElement(surfElems[j]).Visible(0);
10760 -              }
10761 -           }
10762 -           else
10763 -           {
10764 -              for(int j = 0; j < surfElems.Size(); j++)
10765 -              {
10766 -                 mesh->SurfaceElement(surfElems[j]).Visible(1);
10767 -              }
10768 -           }
10769 -        }
10770 -
10771 -        mesh->SetNextTimeStamp();
10772 -     }
10773 -
10774 -     if(strcmp(argv[1], "showall") == 0)
10775 -     {
10776 -        for(int i = 1; i <= mesh->GetNSE(); i++)
10777 -        {
10778 -           mesh->SurfaceElement(i).Visible(1);
10779 -        }
10780 -
10781 -        mesh->SetNextTimeStamp();
10782 -     }
10783 -
10784 -     if(strcmp(argv[1], "hideall") == 0)
10785 -     {
10786 -        for(int i = 1; i <= mesh->GetNSE(); i++)
10787 -        {
10788 -           mesh->SurfaceElement(i).Visible(0);
10789 -        }
10790 -
10791 -        mesh->SetNextTimeStamp();
10792 -     }
10793 -
10794 -     return TCL_OK;
10795 -  }
10796 -
10797 -
10798 -
10799 -
10800 -  // Philippose - 10/03/2009
10801 -  // TCL interface function for the Automatic Colour-based
10802 -  // definition of boundary conditions for OCC Geometry
10803 -  int Ng_AutoColourBcProps (ClientData clientData,
10804 -                                     Tcl_Interp * interp,
10805 -                                     int argc, tcl_const char *argv[])
10806 -  {
10807 -     if(argc < 1)
10808 -     {
10809 -        Tcl_SetResult (interp, (char *)"Ng_AutoColourBcProps needs arguments", TCL_STATIC);
10810 -        return TCL_ERROR;
10811 -     }
10812 -
10813 -     if(!mesh.Ptr())
10814 -     {
10815 -        Tcl_SetResult (interp, (char *)"Ng_AutoColourBcProps: Valid netgen mesh required...please mesh the Geometry first", TCL_STATIC);
10816 -            return TCL_ERROR;
10817 -     }
10818 -
10819 -     if(strcmp(argv[1], "auto") == 0)
10820 -     {
10821 -        AutoColourBcProps(*mesh, 0);
10822 -     }
10823 -
10824 -     if(strcmp(argv[1], "profile") == 0)
10825 -     {
10826 -        AutoColourBcProps(*mesh, argv[2]);
10827 -     }
10828 -
10829 -     return TCL_OK;
10830 -  }
10831 -
10832 -
10833 -  int Ng_SetOCCParameters  (ClientData clientData,
10834 -                           Tcl_Interp * interp,
10835 -                           int argc, tcl_const char *argv[])
10836 -  {
10837 -    OCCGeometryRegister reg;
10838 -    reg.SetParameters (interp);
10839 -    /*
10840 -    occparam.resthcloseedgefac =
10841 -      atof (Tcl_GetVar (interp, "::stloptions.resthcloseedgefac", 0));
10842 -
10843 -    occparam.resthcloseedgeenable =
10844 -      atoi (Tcl_GetVar (interp, "::stloptions.resthcloseedgeenable", 0));
10845 -    */
10846 -    return TCL_OK;
10847 -  }
10848 -
10849 -
10850 -
10851 -
10852 -  NetgenGeometry *  OCCGeometryRegister :: Load (string filename) const
10853 -  {
10854 -    const char * lgfilename = filename.c_str();
10855 -
10856 -
10857 -    /*
10858 -    if (strcmp (&cfilename[strlen(cfilename)-3], "geo") == 0)
10859 -      {
10860 -       PrintMessage (1, "Load OCCG geometry file ", cfilename);
10861 -       
10862 -       extern OCCGeometry * ParseOCCG (istream & istr);
10863 -
10864 -       ifstream infile(cfilename);
10865 -
10866 -       OCCGeometry * hgeom = ParseOCCG (infile);
10867 -       if (!hgeom)
10868 -         throw NgException ("geo-file should start with 'algebraic3d'");
10869 -
10870 -       hgeom -> FindIdenticSurfaces(1e-8 * hgeom->MaxSize()); 
10871 -       return hgeom;
10872 -      }
10873 -    */
10874 -
10875 -
10876 -    if ((strcmp (&lgfilename[strlen(lgfilename)-4], "iges") == 0) ||
10877 -       (strcmp (&lgfilename[strlen(lgfilename)-3], "igs") == 0) ||
10878 -       (strcmp (&lgfilename[strlen(lgfilename)-3], "IGS") == 0) ||
10879 -       (strcmp (&lgfilename[strlen(lgfilename)-4], "IGES") == 0))
10880 -      {
10881 -       PrintMessage (1, "Load IGES geometry file ", lgfilename);
10882 -       OCCGeometry * occgeometry = LoadOCC_IGES (lgfilename);
10883 -       return occgeometry;
10884 -      }
10885 -
10886 -    else if ((strcmp (&lgfilename[strlen(lgfilename)-4], "step") == 0) ||
10887 -                    (strcmp (&lgfilename[strlen(lgfilename)-3], "stp") == 0) ||
10888 -                    (strcmp (&lgfilename[strlen(lgfilename)-3], "STP") == 0) ||
10889 -                    (strcmp (&lgfilename[strlen(lgfilename)-4], "STEP") == 0))
10890 -      {
10891 -       PrintMessage (1, "Load STEP geometry file ", lgfilename);
10892 -       OCCGeometry * occgeometry = LoadOCC_STEP (lgfilename);
10893 -       return occgeometry;    
10894 -      }
10895 -    else if ((strcmp (&lgfilename[strlen(lgfilename)-4], "brep") == 0) ||
10896 -            (strcmp (&lgfilename[strlen(lgfilename)-4], "Brep") == 0) ||
10897 -            (strcmp (&lgfilename[strlen(lgfilename)-4], "BREP") == 0))
10898 -      {
10899 -       PrintMessage (1, "Load BREP geometry file ", lgfilename);
10900 -       OCCGeometry * occgeometry = LoadOCC_BREP (lgfilename);
10901 -       return occgeometry;
10902 -      }
10903 -    
10904 -    return NULL;
10905 -  }
10906 -
10907 -
10908 -  static VisualSceneOCCGeometry vsoccgeom;
10909 -
10910 -  VisualScene * OCCGeometryRegister :: GetVisualScene (const NetgenGeometry * geom) const
10911 -  {
10912 -    OCCGeometry * geometry = dynamic_cast<OCCGeometry*> (ng_geometry.Ptr());
10913 -    if (geometry)
10914 -      {
10915 -       vsoccgeom.SetGeometry (geometry);
10916 -       return &vsoccgeom;
10917 -      }
10918 -    return NULL;
10919 -  }
10920 -
10921 -
10922 -
10923 -}
10924 -
10925 -
10926 -
10927 -using namespace netgen;
10928 -
10929 -int Ng_occ_Init (Tcl_Interp * interp)
10930 -{
10931 -  geometryregister.Append (new OCCGeometryRegister);
10932 -
10933 -
10934 -    Tcl_CreateCommand (interp, "Ng_SetOCCVisParameters",
10935 -                      Ng_SetOCCVisParameters,
10936 -                      (ClientData)NULL,
10937 -                      (Tcl_CmdDeleteProc*) NULL);
10938 -
10939 -    Tcl_CreateCommand (interp, "Ng_GetOCCData",
10940 -                      Ng_GetOCCData,
10941 -                      (ClientData)NULL,
10942 -                      (Tcl_CmdDeleteProc*) NULL);
10943 -
10944 -    /*
10945 -#ifdef OCCGEOMETRY
10946 -    Tcl_CreateCommand (interp, "Ng_OCCConstruction",
10947 -                      Ng_OCCConstruction,
10948 -                      (ClientData)NULL,
10949 -                      (Tcl_CmdDeleteProc*) NULL);
10950 -#endif
10951 -    */
10952 -
10953 -    Tcl_CreateCommand (interp, "Ng_OCCCommand",
10954 -                      Ng_OCCCommand,
10955 -                      (ClientData)NULL,
10956 -                      (Tcl_CmdDeleteProc*) NULL);
10957 -
10958 -
10959 -    Tcl_CreateCommand (interp, "Ng_SetOCCParameters", Ng_SetOCCParameters,
10960 -                      (ClientData)NULL,
10961 -                      (Tcl_CmdDeleteProc*) NULL);
10962 -
10963 -
10964 -
10965 -    // Philippose - 30/01/2009
10966 -    // Register the TCL Interface Command for local face mesh size
10967 -    // definition
10968 -    Tcl_CreateCommand (interp, "Ng_SurfaceMeshSize", Ng_SurfaceMeshSize,
10969 -                      (ClientData)NULL,
10970 -                      (Tcl_CmdDeleteProc*) NULL);
10971 -
10972 -    Tcl_CreateCommand (interp, "Ng_AutoColourBcProps", Ng_AutoColourBcProps,
10973 -                      (ClientData)NULL,
10974 -                      (Tcl_CmdDeleteProc*) NULL);
10975 -
10976 -    // Philippose - 25/07/2010
10977 -    // Register the TCL Interface Command for handling the face colours 
10978 -    // present in the mesh
10979 -    Tcl_CreateCommand(interp, "Ng_CurrentFaceColours", Ng_CurrentFaceColours,
10980 -                      (ClientData)NULL,
10981 -                      (Tcl_CmdDeleteProc*) NULL);
10982 -
10983 -
10984 -  return TCL_OK;
10985 -}
10986 -
10987 -#endif
10988 -
10989 +#ifdef OCCGEOMETRY
10990 +
10991 +#include <mystdlib.h>
10992 +#include <myadt.hpp>
10993 +#include <linalg.hpp>
10994 +#include <csg.hpp>
10995 +#include <occgeom.hpp>
10996 +
10997 +
10998 +#include <incvis.hpp>
10999 +#include <visual.hpp>
11000 +
11001 +#include "../meshing/bcfunctions.hpp"
11002 +
11003 +#include "vsocc.hpp"
11004 +
11005 +
11006 +extern "C" int Ng_occ_Init (Tcl_Interp * interp);
11007 +
11008 +
11009 +
11010 +namespace netgen
11011 +{
11012 +  extern AutoPtr<NetgenGeometry> ng_geometry;
11013 +  extern AutoPtr<Mesh> mesh;
11014
11015 +  char * err_needsoccgeometry = (char*) "This operation needs an OCC geometry";
11016 +  extern char * err_needsmesh;
11017 +  extern char * err_jobrunning;
11018 +
11019 +
11020 +
11021 +                          
11022 +  class OCCGeometryRegister : public GeometryRegister
11023 +  {
11024 +  public:
11025 +    virtual NetgenGeometry * Load (string filename) const;
11026 +    virtual VisualScene * GetVisualScene (const NetgenGeometry * geom) const;
11027 +
11028 +    virtual void SetParameters (Tcl_Interp * interp) 
11029 +    {
11030 +      occparam.resthcloseedgefac =
11031 +       atof (Tcl_GetVar (interp, "::stloptions.resthcloseedgefac", 0));
11032 +      occparam.resthcloseedgeenable =
11033 +       atoi (Tcl_GetVar (interp, "::stloptions.resthcloseedgeenable", 0));
11034 +         occparam.resthminedgelen = 
11035 +       atof (Tcl_GetVar (interp, "::stloptions.resthminedgelen", 0));
11036 +         occparam.resthminedgelenenable = 
11037 +       atoi (Tcl_GetVar (interp, "::stloptions.resthminedgelenenable", 0));
11038 +    }
11039 +  };
11040 +
11041 +
11042 +
11043 +
11044 +  int Ng_SetOCCVisParameters  (ClientData clientData,
11045 +                              Tcl_Interp * interp,
11046 +                              int argc, tcl_const char *argv[])
11047 +  {
11048 +#ifdef OCCGEOMETRY
11049 +    int showvolume;
11050 +       OCCGeometry * occgeometry = dynamic_cast<OCCGeometry*> (ng_geometry.Ptr());
11051 +
11052 +    showvolume = atoi (Tcl_GetVar (interp, "::occoptions.showvolumenr", 0));
11053 +
11054 +    if (occgeometry)
11055 +      if (showvolume != vispar.occshowvolumenr)
11056 +       {
11057 +         if (showvolume < 0 || showvolume > occgeometry->NrSolids())
11058 +           {
11059 +             char buf[20];
11060 +             sprintf (buf, "%5i", vispar.occshowvolumenr);
11061 +             Tcl_SetVar (interp, "::occoptions.showvolumenr", buf, 0);
11062 +           }
11063 +         else
11064 +           {
11065 +             vispar.occshowvolumenr = showvolume;
11066 +             if (occgeometry)
11067 +               occgeometry -> changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11068 +           }
11069 +       }
11070 +    
11071 +    int temp;
11072 +
11073 +    temp = atoi (Tcl_GetVar (interp, "::occoptions.visproblemfaces", 0));
11074 +
11075 +    if ((bool) temp != vispar.occvisproblemfaces)
11076 +      {
11077 +       vispar.occvisproblemfaces = temp;
11078 +       if (occgeometry)
11079 +         occgeometry -> changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11080 +      }
11081 +
11082 +    vispar.occshowsurfaces = atoi (Tcl_GetVar (interp, "::occoptions.showsurfaces", 0));
11083 +    vispar.occshowedges = atoi (Tcl_GetVar (interp, "::occoptions.showedges", 0));
11084 +    vispar.occzoomtohighlightedentity = atoi (Tcl_GetVar (interp, "::occoptions.zoomtohighlightedentity", 0));
11085 +    vispar.occdeflection = pow(10.0,-1-atof (Tcl_GetVar (interp, "::occoptions.deflection", 0)));
11086 +
11087 +#endif
11088 +
11089 +
11090 +
11091 +
11092 +
11093 +#ifdef ACIS
11094 +    vispar.ACISshowfaces = atoi (Tcl_GetVar (interp, "::occoptions.showsurfaces", 0));
11095 +    vispar.ACISshowedges = atoi (Tcl_GetVar (interp, "::occoptions.showedges", 0));
11096 +    vispar.ACISshowsolidnr = atoi (Tcl_GetVar (interp, "::occoptions.showsolidnr", 0));
11097 +    vispar.ACISshowsolidnr2 = atoi (Tcl_GetVar (interp, "::occoptions.showsolidnr2", 0));
11098 +
11099 +#endif
11100 +
11101 +
11102 +
11103 +    return TCL_OK;
11104 +  }  
11105 +
11106 +
11107 +
11108 +
11109 +  int Ng_GetOCCData (ClientData clientData,
11110 +                    Tcl_Interp * interp,
11111 +                    int argc, tcl_const char *argv[])
11112 +  {
11113 +#ifdef OCCGEOMETRY
11114 +    OCCGeometry * occgeometry = dynamic_cast<OCCGeometry*> (ng_geometry.Ptr());
11115 +
11116 +    static char buf[1000];
11117 +    buf[0] = 0;
11118 +    stringstream str;
11119 +
11120 +    if (argc >= 2)
11121 +      {
11122 +       if (strcmp (argv[1], "getentities") == 0)
11123 +         {
11124 +           if (occgeometry)
11125 +             {
11126 +               occgeometry->GetTopologyTree(str);
11127 +             }
11128 +         }
11129 +      }
11130 +
11131 +    Tcl_SetResult (interp, (char*)str.str().c_str(), TCL_VOLATILE);
11132 +
11133 +#endif
11134 +    return TCL_OK;
11135 +  }
11136 +
11137 +  
11138 +
11139 +  int Ng_OCCCommand (ClientData clientData,
11140 +                    Tcl_Interp * interp,
11141 +                    int argc, tcl_const char *argv[])
11142 +  {
11143 +#ifdef OCCGEOMETRY
11144 +    OCCGeometry * occgeometry = dynamic_cast<OCCGeometry*> (ng_geometry.Ptr());
11145 +
11146 +    stringstream str;
11147 +    if (argc >= 2)
11148 +      {
11149 +       if (strcmp (argv[1], "isoccgeometryloaded") == 0)
11150 +         {
11151 +           if (occgeometry)
11152 +             str << "1 " << flush;
11153 +           else str << "0 " << flush;
11154 +
11155 +           Tcl_SetResult (interp, (char*)str.str().c_str(), TCL_VOLATILE);
11156 +         }
11157 +       if (occgeometry)
11158 +         {
11159 +           if (strcmp (argv[1], "buildvisualizationmesh") == 0)
11160 +             {
11161 +               occgeometry->BuildVisualizationMesh(vispar.occdeflection);
11162 +               occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11163 +             }
11164 +           if (strcmp (argv[1], "mesherror") == 0)
11165 +             {
11166 +               if (occgeometry->ErrorInSurfaceMeshing())
11167 +                 str << 1;
11168 +               else
11169 +                 str << 0;
11170 +             }
11171 +           if (strcmp (argv[1], "sewfaces") == 0)
11172 +             {
11173 +               cout << "Before operation:" << endl;
11174 +               occgeometry->PrintNrShapes();
11175 +               occgeometry->SewFaces();
11176 +               occgeometry->BuildFMap();
11177 +               cout << endl << "After operation:" << endl;
11178 +               occgeometry->PrintNrShapes();
11179 +               occgeometry->BuildVisualizationMesh(vispar.occdeflection);
11180 +               occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11181 +             }
11182 +           if (strcmp (argv[1], "makesolid") == 0)
11183 +             {
11184 +               cout << "Before operation:" << endl;
11185 +               occgeometry->PrintNrShapes();
11186 +               occgeometry->MakeSolid();
11187 +               occgeometry->BuildFMap();
11188 +               cout << endl << "After operation:" << endl;
11189 +               occgeometry->PrintNrShapes();
11190 +               occgeometry->BuildVisualizationMesh(vispar.occdeflection);
11191 +               occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11192 +             }
11193 +           if (strcmp (argv[1], "upgradetopology") == 0)
11194 +             {
11195 +               cout << "Before operation:" << endl;
11196 +               occgeometry->PrintNrShapes();
11197 +               occgeometry->SewFaces();
11198 +               occgeometry->MakeSolid();
11199 +               occgeometry->BuildFMap();
11200 +               cout << endl << "After operation:" << endl;
11201 +               occgeometry->PrintNrShapes();
11202 +               occgeometry->BuildVisualizationMesh(vispar.occdeflection);
11203 +               occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11204 +             }
11205 +           if (strcmp (argv[1], "shapehealing") == 0)
11206 +             {
11207 +               occgeometry->tolerance =
11208 +                 atof (Tcl_GetVar (interp, "::occoptions.tolerance", 0));
11209 +               occgeometry->fixsmalledges =
11210 +                 atoi (Tcl_GetVar (interp, "::occoptions.fixsmalledges", 0));
11211 +               occgeometry->fixspotstripfaces =
11212 +                 atoi (Tcl_GetVar (interp, "::occoptions.fixspotstripfaces", 0));
11213 +               occgeometry->sewfaces =
11214 +                 atoi (Tcl_GetVar (interp, "::occoptions.sewfaces", 0));
11215 +               occgeometry->makesolids =
11216 +                 atoi (Tcl_GetVar (interp, "::occoptions.makesolids", 0));
11217 +               occgeometry->splitpartitions =
11218 +                 atoi (Tcl_GetVar (interp, "::occoptions.splitpartitions", 0));
11219 +
11220 +               //            cout << "Before operation:" << endl;
11221 +               //            occgeometry->PrintNrShapes();
11222 +               occgeometry->HealGeometry();
11223 +               occgeometry->BuildFMap();
11224 +               //            cout << endl << "After operation:" << endl;
11225 +               //            occgeometry->PrintNrShapes();
11226 +               occgeometry->BuildVisualizationMesh(vispar.occdeflection);
11227 +               occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11228 +             }
11229 +
11230 +
11231 +           if (strcmp (argv[1], "highlightentity") == 0)
11232 +             {
11233 +               if (strcmp (argv[2], "Face") == 0)
11234 +                 {
11235 +                   int nr = atoi (argv[3]);
11236 +                   occgeometry->LowLightAll();
11237 +
11238 +                   occgeometry->fvispar[nr-1].Highlight();
11239 +                   if (vispar.occzoomtohighlightedentity)
11240 +                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
11241 +                   else
11242 +                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11243 +                 }
11244 +               if (strcmp (argv[2], "Shell") == 0)
11245 +                 {
11246 +                   int nr = atoi (argv[3]);
11247 +                   occgeometry->LowLightAll();
11248 +
11249 +                   TopExp_Explorer exp;
11250 +                   for (exp.Init (occgeometry->shmap(nr), TopAbs_FACE);
11251 +                        exp.More(); exp.Next())
11252 +                     {
11253 +                       int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
11254 +                       occgeometry->fvispar[i-1].Highlight();
11255 +                     }
11256 +                   if (vispar.occzoomtohighlightedentity)
11257 +                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
11258 +                   else
11259 +                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11260 +                 }
11261 +               if (strcmp (argv[2], "Solid") == 0)
11262 +                 {
11263 +                   int nr = atoi (argv[3]);
11264 +                   occgeometry->LowLightAll();
11265 +
11266 +                   TopExp_Explorer exp;
11267 +                   for (exp.Init (occgeometry->somap(nr), TopAbs_FACE);
11268 +                        exp.More(); exp.Next())
11269 +                     {
11270 +                       int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
11271 +                       occgeometry->fvispar[i-1].Highlight();
11272 +                     }
11273 +                   if (vispar.occzoomtohighlightedentity)
11274 +                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
11275 +                   else
11276 +                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11277 +                 }
11278 +               /*
11279 +                 if (strcmp (argv[2], "CompSolid") == 0)
11280 +                 {
11281 +                 int nr = atoi (argv[3]);
11282 +                 occgeometry->LowLightAll();
11283 +
11284 +                 TopExp_Explorer exp;
11285 +                 for (exp.Init (occgeometry->cmap(nr), TopAbs_FACE);
11286 +                 exp.More(); exp.Next())
11287 +                 {
11288 +                 int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
11289 +                 occgeometry->fvispar[i-1].Highlight();
11290 +                 }
11291 +                 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11292 +                 }
11293 +               */
11294 +
11295 +               if (strcmp (argv[2], "Edge") == 0)
11296 +                 {
11297 +                   int nr = atoi (argv[3]);
11298 +                   occgeometry->LowLightAll();
11299 +
11300 +                   occgeometry->evispar[nr-1].Highlight();
11301 +                   if (vispar.occzoomtohighlightedentity)
11302 +                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
11303 +                   else
11304 +                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11305 +                 }
11306 +               if (strcmp (argv[2], "Wire") == 0)
11307 +                 {
11308 +                   int nr = atoi (argv[3]);
11309 +                   occgeometry->LowLightAll();
11310 +
11311 +                   TopExp_Explorer exp;
11312 +                   for (exp.Init (occgeometry->wmap(nr), TopAbs_EDGE);
11313 +                        exp.More(); exp.Next())
11314 +                     {
11315 +                       int i = occgeometry->emap.FindIndex (TopoDS::Edge(exp.Current()));
11316 +                       occgeometry->evispar[i-1].Highlight();
11317 +                     }
11318 +                   if (vispar.occzoomtohighlightedentity)
11319 +                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
11320 +                   else
11321 +                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11322 +                 }
11323 +
11324 +               if (strcmp (argv[2], "Vertex") == 0)
11325 +                 {
11326 +                   int nr = atoi (argv[3]);
11327 +                   occgeometry->LowLightAll();
11328 +
11329 +                   occgeometry->vvispar[nr-1].Highlight();
11330 +                   if (vispar.occzoomtohighlightedentity)
11331 +                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONFULLCHANGE;
11332 +                   else
11333 +                     occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11334 +                 }
11335 +
11336 +             }
11337 +
11338 +
11339 +
11340 +           if (strcmp (argv[1], "show") == 0)
11341 +             {
11342 +               int nr = atoi (argv[3]);
11343 +               occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11344 +
11345 +               if (strcmp (argv[2], "Face") == 0)
11346 +                 {
11347 +                   occgeometry->fvispar[nr-1].Show();
11348 +                 }
11349 +               if (strcmp (argv[2], "Shell") == 0)
11350 +                 {
11351 +                   TopExp_Explorer exp;
11352 +                   for (exp.Init (occgeometry->shmap(nr), TopAbs_FACE);
11353 +                        exp.More(); exp.Next())
11354 +                     {
11355 +                       int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
11356 +                       occgeometry->fvispar[i-1].Show();
11357 +                     }
11358 +                 }
11359 +               if (strcmp (argv[2], "Solid") == 0)
11360 +                 {
11361 +                   TopExp_Explorer exp;
11362 +                   for (exp.Init (occgeometry->somap(nr), TopAbs_FACE);
11363 +                        exp.More(); exp.Next())
11364 +                     {
11365 +                       int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
11366 +                       occgeometry->fvispar[i-1].Show();
11367 +                     }
11368 +                 }
11369 +               if (strcmp (argv[2], "Edge") == 0)
11370 +                 {
11371 +                   occgeometry->evispar[nr-1].Show();
11372 +                 }
11373 +               if (strcmp (argv[2], "Wire") == 0)
11374 +                 {
11375 +                   TopExp_Explorer exp;
11376 +                   for (exp.Init (occgeometry->wmap(nr), TopAbs_EDGE);
11377 +                        exp.More(); exp.Next())
11378 +                     {
11379 +                       int i = occgeometry->emap.FindIndex (TopoDS::Edge(exp.Current()));
11380 +                       occgeometry->evispar[i-1].Show();
11381 +                     }
11382 +                 }
11383 +             }
11384 +
11385 +
11386 +           if (strcmp (argv[1], "hide") == 0)
11387 +             {
11388 +               int nr = atoi (argv[3]);
11389 +               occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11390 +
11391 +               if (strcmp (argv[2], "Face") == 0)
11392 +                 {
11393 +                   occgeometry->fvispar[nr-1].Hide();
11394 +                 }
11395 +               if (strcmp (argv[2], "Shell") == 0)
11396 +                 {
11397 +                   TopExp_Explorer exp;
11398 +                   for (exp.Init (occgeometry->shmap(nr), TopAbs_FACE);
11399 +                        exp.More(); exp.Next())
11400 +                     {
11401 +                       int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
11402 +                       occgeometry->fvispar[i-1].Hide();
11403 +                     }
11404 +                 }
11405 +               if (strcmp (argv[2], "Solid") == 0)
11406 +                 {
11407 +                   TopExp_Explorer exp;
11408 +                   for (exp.Init (occgeometry->somap(nr), TopAbs_FACE);
11409 +                        exp.More(); exp.Next())
11410 +                     {
11411 +                       int i = occgeometry->fmap.FindIndex (TopoDS::Face(exp.Current()));
11412 +                       occgeometry->fvispar[i-1].Hide();
11413 +                     }
11414 +                 }
11415 +               if (strcmp (argv[2], "Edge") == 0)
11416 +                 {
11417 +                   occgeometry->evispar[nr-1].Hide();
11418 +                 }
11419 +               if (strcmp (argv[2], "Wire") == 0)
11420 +                 {
11421 +                   TopExp_Explorer exp;
11422 +                   for (exp.Init (occgeometry->wmap(nr), TopAbs_EDGE);
11423 +                        exp.More(); exp.Next())
11424 +                     {
11425 +                       int i = occgeometry->emap.FindIndex (TopoDS::Edge(exp.Current()));
11426 +                       occgeometry->evispar[i-1].Hide();
11427 +                     }
11428 +                 }
11429 +             }
11430 +
11431 +
11432 +
11433 +           if (strcmp (argv[1], "findsmallentities") == 0)
11434 +             {
11435 +               stringstream str("");
11436 +               occgeometry->CheckIrregularEntities(str);
11437 +               Tcl_SetResult (interp, (char*)str.str().c_str(), TCL_VOLATILE);
11438 +             }
11439 +           if (strcmp (argv[1], "getunmeshedfaceinfo") == 0)
11440 +             {
11441 +               occgeometry->GetUnmeshedFaceInfo(str);
11442 +               Tcl_SetResult (interp, (char*)str.str().c_str(), TCL_VOLATILE);
11443 +             }
11444 +           if (strcmp (argv[1], "getnotdrawablefaces") == 0)
11445 +             {
11446 +               occgeometry->GetNotDrawableFaces(str);
11447 +               Tcl_SetResult (interp, (char*)str.str().c_str(), TCL_VOLATILE);
11448 +             }
11449 +           if (strcmp (argv[1], "redrawstatus") == 0)
11450 +             {
11451 +               int i = atoi (argv[2]);
11452 +               occgeometry->changed = i;
11453 +             }
11454 +           if (strcmp (argv[1], "swaporientation") == 0)
11455 +             {
11456 +               IGESControl_Writer writer("millimeters", 1);
11457 +               writer.AddShape (occgeometry->shape);
11458 +               writer.Write ("1.igs");
11459 +               /*
11460 +                 int nr = atoi (argv[3]);
11461 +
11462 +                 //          const_cast<TopoDS_Shape&> (occgeometry->fmap(nr)).Reverse();
11463 +
11464 +                 Handle_ShapeBuild_ReShape rebuild = new ShapeBuild_ReShape;
11465 +                 rebuild->Apply(occgeometry->shape);
11466 +
11467 +                 TopoDS_Shape sh;
11468 +
11469 +                 //          if (strcmp (argv[2], "CompSolid") == 0) sh = occgeometry->cmap(nr);
11470 +                 if (strcmp (argv[2], "Solid") == 0) sh = occgeometry->somap(nr);
11471 +                 if (strcmp (argv[2], "Shell") == 0) sh = occgeometry->shmap(nr);
11472 +                 if (strcmp (argv[2], "Face") == 0) sh = occgeometry->fmap(nr);
11473 +                 if (strcmp (argv[2], "Wire") == 0) sh = occgeometry->wmap(nr);
11474 +                 if (strcmp (argv[2], "Edge") == 0) sh = occgeometry->emap(nr);
11475 +
11476 +                 rebuild->Replace(sh, sh.Reversed());
11477 +
11478 +                 TopoDS_Shape newshape = rebuild->Apply(occgeometry->shape, TopAbs_SHELL, 1);
11479 +                 occgeometry->shape = newshape;
11480 +
11481 +                 occgeometry->BuildFMap();
11482 +                 occgeometry->BuildVisualizationMesh();
11483 +                 occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11484 +               */
11485 +             }
11486 +           if (strcmp (argv[1], "marksingular") == 0)
11487 +             {
11488 +               int nr = atoi (argv[3]);
11489 +               cout << "marking " << argv[2] << " " << nr << endl;
11490 +               char buf[2]; buf[0] = '0'; buf[1] = 0;
11491 +               bool sing = false;
11492 +               if (strcmp (argv[2], "Face") == 0)
11493 +                 sing = occgeometry->fsingular[nr-1] = !occgeometry->fsingular[nr-1];
11494 +               if (strcmp (argv[2], "Edge") == 0)
11495 +                 sing = occgeometry->esingular[nr-1] = !occgeometry->esingular[nr-1];
11496 +               if (strcmp (argv[2], "Vertex") == 0)
11497 +                 sing = occgeometry->vsingular[nr-1] = !occgeometry->vsingular[nr-1];
11498 +
11499 +               if (sing) buf[0] = '1';
11500 +
11501 +                Tcl_SetVar (interp, "::ismarkedsingular", buf, 0);
11502 +
11503 +               stringstream str;
11504 +               occgeometry->GetTopologyTree (str);
11505 +
11506 +               char* cstr = (char*)str.str().c_str();
11507 +
11508 +               (*testout) << cstr << endl;
11509 +
11510 +               char helpstr[1000];
11511 +
11512 +               while (strchr (cstr, '}'))
11513 +                 {
11514 +                   strncpy (helpstr, cstr+2, strlen(strchr(cstr+2, '}')));
11515 +                   (*testout) << "***" << cstr << "***" << endl;
11516 +                   cstr = strchr (cstr, '}');
11517 +                 } 
11518 +             }
11519 +         }
11520 +      }
11521 +
11522 +#endif
11523 +    return TCL_OK;
11524 +  }
11525 +
11526 +
11527 +
11528 +#ifdef OCCGEOMETRY
11529 +  /*
11530 +  void OCCConstructGeometry (OCCGeometry & geom);
11531 +
11532 +  int Ng_OCCConstruction (ClientData clientData,
11533 +                         Tcl_Interp * interp,
11534 +                         int argc, tcl_const char *argv[])
11535 +  {
11536 +    if (occgeometry)
11537 +      OCCConstructGeometry (*occgeometry);
11538 +    return TCL_OK;
11539 +  }
11540 +  */
11541 +#endif
11542 +
11543 +
11544 +
11545 +
11546 +  // Philippose - 30/01/2009
11547 +  // TCL interface function for the Local Face Mesh size
11548 +  // definition functionality
11549 +  int Ng_SurfaceMeshSize (ClientData clientData,
11550 +                                   Tcl_Interp * interp,
11551 +                                   int argc, tcl_const char *argv[])
11552 +  {
11553 +#ifdef OCCGEOMETRY
11554 +
11555 +    static char buf[100];
11556 +
11557 +    if (argc < 2)
11558 +    {
11559 +          Tcl_SetResult (interp, (char *)"Ng_SurfaceMeshSize needs arguments", TCL_STATIC);
11560 +          return TCL_ERROR;
11561 +    }
11562 +
11563 +    OCCGeometry * occgeometry = dynamic_cast<OCCGeometry*> (ng_geometry.Ptr());
11564 +    if (!occgeometry)
11565 +    {
11566 +      Tcl_SetResult (interp, (char *)"Ng_SurfaceMeshSize currently supports only OCC (STEP/IGES) Files", TCL_STATIC);
11567 +          return TCL_ERROR;
11568 +    }
11569 +
11570 +    // Update the face mesh sizes to reflect the global maximum mesh size
11571 +    for(int i = 1; i <= occgeometry->NrFaces(); i++)
11572 +    {
11573 +           if(!occgeometry->GetFaceMaxhModified(i))
11574 +           {
11575 +              occgeometry->SetFaceMaxH(i, mparam.maxh);
11576 +           }   
11577 +    }
11578 +
11579 +    if (strcmp (argv[1], "setsurfms") == 0)
11580 +    {
11581 +          int facenr = atoi (argv[2]);
11582 +          double surfms = atof (argv[3]);
11583 +          if (occgeometry && facenr >= 1 && facenr <= occgeometry->NrFaces())
11584 +            occgeometry->SetFaceMaxH(facenr, surfms);
11585 +
11586 +    }
11587 +
11588 +    if (strcmp (argv[1], "setall") == 0)
11589 +    {
11590 +          double surfms = atof (argv[2]);
11591 +          if (occgeometry)
11592 +          {
11593 +            int nrFaces = occgeometry->NrFaces();
11594 +            for (int i = 1; i <= nrFaces; i++)
11595 +             occgeometry->SetFaceMaxH(i, surfms);
11596 +          }
11597 +    }
11598 +
11599 +    if (strcmp (argv[1], "getsurfms") == 0)
11600 +    {
11601 +          int facenr = atoi (argv[2]);
11602 +          if (occgeometry && facenr >= 1 && facenr <= occgeometry->NrFaces())
11603 +          {
11604 +            sprintf (buf, "%5.2f", occgeometry->GetFaceMaxH(facenr));
11605 +          }
11606 +          else
11607 +          {
11608 +            sprintf (buf, "%5.2f", mparam.maxh);
11609 +          }
11610 +          Tcl_SetResult (interp, buf, TCL_STATIC);
11611 +    }
11612 +
11613 +    if (strcmp (argv[1], "getactive") == 0)
11614 +    {
11615 +          sprintf (buf, "%d", occgeometry->SelectedFace());
11616 +          Tcl_SetResult (interp, buf, TCL_STATIC);
11617 +    }
11618 +
11619 +    if (strcmp (argv[1], "setactive") == 0)
11620 +    {
11621 +          int facenr = atoi (argv[2]);
11622 +          if (occgeometry && facenr >= 1 && facenr <= occgeometry->NrFaces())
11623 +          {
11624 +            occgeometry->SetSelectedFace (facenr);
11625 +
11626 +        occgeometry->LowLightAll();
11627 +        occgeometry->fvispar[facenr-1].Highlight();
11628 +        occgeometry->changed = OCCGEOMETRYVISUALIZATIONHALFCHANGE;
11629 +          }
11630 +    }
11631 +
11632 +    if (strcmp (argv[1], "getnfd") == 0)
11633 +    {
11634 +          if (occgeometry)
11635 +            sprintf (buf, "%d", occgeometry->NrFaces());
11636 +          else
11637 +            sprintf (buf, "0");
11638 +          Tcl_SetResult (interp, buf, TCL_STATIC);
11639 +    }
11640 +    return TCL_OK;
11641 +#else // No OCCGEOMETRY 
11642 +
11643 +    Tcl_SetResult (interp, (char *)"Ng_SurfaceMeshSize currently supports only OCC (STEP/IGES) Files", TCL_STATIC);
11644 +    return TCL_ERROR;
11645 +    
11646 +#endif // OCCGEOMETRY
11647 +  }
11648 +
11649 +
11650 +
11651 +  // Philippose - 25/07/2010
11652 +  // TCL interface function for extracting and eventually 
11653 +  // setting or editing the current colours present in the mesh
11654 +  int Ng_CurrentFaceColours (ClientData clientData,
11655 +                             Tcl_Interp * interp,
11656 +                             int argc, tcl_const char *argv[])
11657 +  {
11658 +     if(argc < 1)
11659 +     {
11660 +        Tcl_SetResult (interp, (char *)"Ng_GetCurrentFaceColours needs arguments", TCL_STATIC);
11661 +        return TCL_ERROR;
11662 +     }
11663 +
11664 +     if(!mesh.Ptr())
11665 +     {
11666 +        Tcl_SetResult (interp, (char *)"Ng_GetCurrentFaceColours: Valid netgen mesh required...please mesh the Geometry first", TCL_STATIC);
11667 +            return TCL_ERROR;
11668 +     }
11669 +
11670 +     if(strcmp(argv[1], "getcolours") == 0)
11671 +     {
11672 +        stringstream outVar;
11673 +        Array<Vec3d> face_colours;
11674 +        GetFaceColours(*mesh, face_colours);
11675 +
11676 +        for(int i = 0; i < face_colours.Size();i++)
11677 +        {
11678 +           outVar << "{ " << face_colours[i].X(1)
11679 +                  << " "  << face_colours[i].X(2)
11680 +                  << " "  << face_colours[i].X(3)
11681 +                  << " } ";
11682 +        }
11683 +
11684 +        tcl_const char * valuevar = argv[2];
11685 +        Tcl_SetVar  (interp, valuevar, (char*)outVar.str().c_str(), 0);
11686 +     }
11687 +
11688 +     if(strcmp(argv[1], "showalso") == 0)
11689 +     {
11690 +        Array<Vec3d> face_colours;
11691 +        GetFaceColours(*mesh,face_colours);
11692 +
11693 +        int colourind = atoi (argv[2]);
11694 +
11695 +        for(int i = 1; i <= mesh->GetNFD(); i++)
11696 +        {
11697 +           Array<SurfaceElementIndex> surfElems;
11698 +           mesh->GetSurfaceElementsOfFace(i,surfElems);
11699 +
11700 +           if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour()))
11701 +           {
11702 +              for(int j = 0; j < surfElems.Size(); j++)
11703 +              {
11704 +                 mesh->SurfaceElement(surfElems[j]).Visible(1);
11705 +              }
11706 +           }
11707 +        }
11708 +
11709 +        mesh->SetNextTimeStamp();
11710 +     }
11711 +
11712 +     if(strcmp(argv[1], "hidealso") == 0)
11713 +     {
11714 +        Array<Vec3d> face_colours;
11715 +        GetFaceColours(*mesh,face_colours);
11716 +
11717 +        int colourind = atoi (argv[2]);
11718 +
11719 +        for(int i = 1; i <= mesh->GetNFD(); i++)
11720 +        {
11721 +           Array<SurfaceElementIndex> surfElems;
11722 +           mesh->GetSurfaceElementsOfFace(i,surfElems);
11723 +
11724 +           if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour()))
11725 +           {
11726 +              for(int j = 0; j < surfElems.Size(); j++)
11727 +              {
11728 +                 mesh->SurfaceElement(surfElems[j]).Visible(0);
11729 +              }
11730 +           }
11731 +        }
11732 +
11733 +        mesh->SetNextTimeStamp();
11734 +     }
11735 +
11736 +     if(strcmp(argv[1], "showonly") == 0)
11737 +     {
11738 +        Array<Vec3d> face_colours;
11739 +        GetFaceColours(*mesh,face_colours);
11740 +
11741 +        int colourind = atoi (argv[2]);
11742 +
11743 +        for(int i = 1; i <= mesh->GetNFD(); i++)
11744 +        {
11745 +           Array<SurfaceElementIndex> surfElems;
11746 +           mesh->GetSurfaceElementsOfFace(i,surfElems);
11747 +
11748 +           if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour()))
11749 +           {
11750 +              for(int j = 0; j < surfElems.Size(); j++)
11751 +              {
11752 +                 mesh->SurfaceElement(surfElems[j]).Visible(1);
11753 +              }
11754 +           }
11755 +           else
11756 +           {
11757 +              for(int j = 0; j < surfElems.Size(); j++)
11758 +              {
11759 +                 mesh->SurfaceElement(surfElems[j]).Visible(0);
11760 +              }
11761 +           }
11762 +        }
11763 +
11764 +        mesh->SetNextTimeStamp();
11765 +     }
11766 +
11767 +     if(strcmp(argv[1], "hideonly") == 0)
11768 +     {
11769 +        Array<Vec3d> face_colours;
11770 +        GetFaceColours(*mesh,face_colours);
11771 +
11772 +        int colourind = atoi (argv[2]);
11773 +
11774 +        for(int i = 1; i <= mesh->GetNFD(); i++)
11775 +        {
11776 +           Array<SurfaceElementIndex> surfElems;
11777 +           mesh->GetSurfaceElementsOfFace(i,surfElems);
11778 +
11779 +           if(ColourMatch(face_colours[colourind],mesh->GetFaceDescriptor(i).SurfColour()))
11780 +           {
11781 +              for(int j = 0; j < surfElems.Size(); j++)
11782 +              {
11783 +                 mesh->SurfaceElement(surfElems[j]).Visible(0);
11784 +              }
11785 +           }
11786 +           else
11787 +           {
11788 +              for(int j = 0; j < surfElems.Size(); j++)
11789 +              {
11790 +                 mesh->SurfaceElement(surfElems[j]).Visible(1);
11791 +              }
11792 +           }
11793 +        }
11794 +
11795 +        mesh->SetNextTimeStamp();
11796 +     }
11797 +
11798 +     if(strcmp(argv[1], "showall") == 0)
11799 +     {
11800 +        for(int i = 1; i <= mesh->GetNSE(); i++)
11801 +        {
11802 +           mesh->SurfaceElement(i).Visible(1);
11803 +        }
11804 +
11805 +        mesh->SetNextTimeStamp();
11806 +     }
11807 +
11808 +     if(strcmp(argv[1], "hideall") == 0)
11809 +     {
11810 +        for(int i = 1; i <= mesh->GetNSE(); i++)
11811 +        {
11812 +           mesh->SurfaceElement(i).Visible(0);
11813 +        }
11814 +
11815 +        mesh->SetNextTimeStamp();
11816 +     }
11817 +
11818 +     return TCL_OK;
11819 +  }
11820 +
11821 +
11822 +
11823 +
11824 +  // Philippose - 10/03/2009
11825 +  // TCL interface function for the Automatic Colour-based
11826 +  // definition of boundary conditions for OCC Geometry
11827 +  int Ng_AutoColourBcProps (ClientData clientData,
11828 +                                     Tcl_Interp * interp,
11829 +                                     int argc, tcl_const char *argv[])
11830 +  {
11831 +     if(argc < 1)
11832 +     {
11833 +        Tcl_SetResult (interp, (char *)"Ng_AutoColourBcProps needs arguments", TCL_STATIC);
11834 +        return TCL_ERROR;
11835 +     }
11836 +
11837 +     if(!mesh.Ptr())
11838 +     {
11839 +        Tcl_SetResult (interp, (char *)"Ng_AutoColourBcProps: Valid netgen mesh required...please mesh the Geometry first", TCL_STATIC);
11840 +            return TCL_ERROR;
11841 +     }
11842 +
11843 +     if(strcmp(argv[1], "auto") == 0)
11844 +     {
11845 +        AutoColourBcProps(*mesh, 0);
11846 +     }
11847 +
11848 +     if(strcmp(argv[1], "profile") == 0)
11849 +     {
11850 +        AutoColourBcProps(*mesh, argv[2]);
11851 +     }
11852 +
11853 +     return TCL_OK;
11854 +  }
11855 +
11856 +
11857 +  int Ng_SetOCCParameters  (ClientData clientData,
11858 +                           Tcl_Interp * interp,
11859 +                           int argc, tcl_const char *argv[])
11860 +  {
11861 +    OCCGeometryRegister reg;
11862 +    reg.SetParameters (interp);
11863 +    /*
11864 +    occparam.resthcloseedgefac =
11865 +      atof (Tcl_GetVar (interp, "::stloptions.resthcloseedgefac", 0));
11866 +
11867 +    occparam.resthcloseedgeenable =
11868 +      atoi (Tcl_GetVar (interp, "::stloptions.resthcloseedgeenable", 0));
11869 +    */
11870 +    return TCL_OK;
11871 +  }
11872 +
11873 +
11874 +
11875 +
11876 +  NetgenGeometry *  OCCGeometryRegister :: Load (string filename) const
11877 +  {
11878 +    const char * lgfilename = filename.c_str();
11879 +
11880 +
11881 +    /*
11882 +    if (strcmp (&cfilename[strlen(cfilename)-3], "geo") == 0)
11883 +      {
11884 +       PrintMessage (1, "Load OCCG geometry file ", cfilename);
11885 +       
11886 +       extern OCCGeometry * ParseOCCG (istream & istr);
11887 +
11888 +       ifstream infile(cfilename);
11889 +
11890 +       OCCGeometry * hgeom = ParseOCCG (infile);
11891 +       if (!hgeom)
11892 +         throw NgException ("geo-file should start with 'algebraic3d'");
11893 +
11894 +       hgeom -> FindIdenticSurfaces(1e-8 * hgeom->MaxSize()); 
11895 +       return hgeom;
11896 +      }
11897 +    */
11898 +
11899 +
11900 +    if ((strcmp (&lgfilename[strlen(lgfilename)-4], "iges") == 0) ||
11901 +       (strcmp (&lgfilename[strlen(lgfilename)-3], "igs") == 0) ||
11902 +       (strcmp (&lgfilename[strlen(lgfilename)-3], "IGS") == 0) ||
11903 +       (strcmp (&lgfilename[strlen(lgfilename)-4], "IGES") == 0))
11904 +      {
11905 +       PrintMessage (1, "Load IGES geometry file ", lgfilename);
11906 +       OCCGeometry * occgeometry = LoadOCC_IGES (lgfilename);
11907 +       return occgeometry;
11908 +      }
11909 +
11910 +    else if ((strcmp (&lgfilename[strlen(lgfilename)-4], "step") == 0) ||
11911 +                    (strcmp (&lgfilename[strlen(lgfilename)-3], "stp") == 0) ||
11912 +                    (strcmp (&lgfilename[strlen(lgfilename)-3], "STP") == 0) ||
11913 +                    (strcmp (&lgfilename[strlen(lgfilename)-4], "STEP") == 0))
11914 +      {
11915 +       PrintMessage (1, "Load STEP geometry file ", lgfilename);
11916 +       OCCGeometry * occgeometry = LoadOCC_STEP (lgfilename);
11917 +       return occgeometry;    
11918 +      }
11919 +    else if ((strcmp (&lgfilename[strlen(lgfilename)-4], "brep") == 0) ||
11920 +            (strcmp (&lgfilename[strlen(lgfilename)-4], "Brep") == 0) ||
11921 +            (strcmp (&lgfilename[strlen(lgfilename)-4], "BREP") == 0))
11922 +      {
11923 +       PrintMessage (1, "Load BREP geometry file ", lgfilename);
11924 +       OCCGeometry * occgeometry = LoadOCC_BREP (lgfilename);
11925 +       return occgeometry;
11926 +      }
11927 +    
11928 +    return NULL;
11929 +  }
11930 +
11931 +
11932 +  static VisualSceneOCCGeometry vsoccgeom;
11933 +
11934 +  VisualScene * OCCGeometryRegister :: GetVisualScene (const NetgenGeometry * geom) const
11935 +  {
11936 +    OCCGeometry * geometry = dynamic_cast<OCCGeometry*> (ng_geometry.Ptr());
11937 +    if (geometry)
11938 +      {
11939 +       vsoccgeom.SetGeometry (geometry);
11940 +       return &vsoccgeom;
11941 +      }
11942 +    return NULL;
11943 +  }
11944 +
11945 +
11946 +
11947 +}
11948 +
11949 +
11950 +
11951 +using namespace netgen;
11952 +
11953 +int Ng_occ_Init (Tcl_Interp * interp)
11954 +{
11955 +  geometryregister.Append (new OCCGeometryRegister);
11956 +
11957 +
11958 +    Tcl_CreateCommand (interp, "Ng_SetOCCVisParameters",
11959 +                      Ng_SetOCCVisParameters,
11960 +                      (ClientData)NULL,
11961 +                      (Tcl_CmdDeleteProc*) NULL);
11962 +
11963 +    Tcl_CreateCommand (interp, "Ng_GetOCCData",
11964 +                      Ng_GetOCCData,
11965 +                      (ClientData)NULL,
11966 +                      (Tcl_CmdDeleteProc*) NULL);
11967 +
11968 +    /*
11969 +#ifdef OCCGEOMETRY
11970 +    Tcl_CreateCommand (interp, "Ng_OCCConstruction",
11971 +                      Ng_OCCConstruction,
11972 +                      (ClientData)NULL,
11973 +                      (Tcl_CmdDeleteProc*) NULL);
11974 +#endif
11975 +    */
11976 +
11977 +    Tcl_CreateCommand (interp, "Ng_OCCCommand",
11978 +                      Ng_OCCCommand,
11979 +                      (ClientData)NULL,
11980 +                      (Tcl_CmdDeleteProc*) NULL);
11981 +
11982 +
11983 +    Tcl_CreateCommand (interp, "Ng_SetOCCParameters", Ng_SetOCCParameters,
11984 +                      (ClientData)NULL,
11985 +                      (Tcl_CmdDeleteProc*) NULL);
11986 +
11987 +
11988 +
11989 +    // Philippose - 30/01/2009
11990 +    // Register the TCL Interface Command for local face mesh size
11991 +    // definition
11992 +    Tcl_CreateCommand (interp, "Ng_SurfaceMeshSize", Ng_SurfaceMeshSize,
11993 +                      (ClientData)NULL,
11994 +                      (Tcl_CmdDeleteProc*) NULL);
11995 +
11996 +    Tcl_CreateCommand (interp, "Ng_AutoColourBcProps", Ng_AutoColourBcProps,
11997 +                      (ClientData)NULL,
11998 +                      (Tcl_CmdDeleteProc*) NULL);
11999 +
12000 +    // Philippose - 25/07/2010
12001 +    // Register the TCL Interface Command for handling the face colours 
12002 +    // present in the mesh
12003 +    Tcl_CreateCommand(interp, "Ng_CurrentFaceColours", Ng_CurrentFaceColours,
12004 +                      (ClientData)NULL,
12005 +                      (Tcl_CmdDeleteProc*) NULL);
12006 +
12007 +
12008 +  return TCL_OK;
12009 +}
12010 +
12011 +#endif
12012 +
12013 --- netgen_ref/libsrc/occ/utilities.h
12014 +++ netgen/libsrc/occ/utilities.h
12015 @@ -33,6 +33,7 @@
12016  
12017  #include <string>
12018  #include <iostream>
12019 +#include <iomanip>
12020  #include <cstdlib>
12021  // #include "SALOME_Log.hxx"
12022  
12023 --- netgen_ref/libsrc/stlgeom/Makefile.am
12024 +++ netgen/libsrc/stlgeom/Makefile.am
12025 @@ -4,10 +4,10 @@
12026  AM_CPPFLAGS = -I$(top_srcdir)/libsrc/include $(TCL_INCLUDES)
12027  METASOURCES = AUTO
12028  
12029 -lib_LTLIBRARIES = libstl.la 
12030 +noinst_LTLIBRARIES = libstl.la 
12031  
12032  if NGGUI
12033 -lib_LTLIBRARIES += libstlvis.la 
12034 +lib_LTLIBRARIES = libstlvis.la 
12035  endif
12036  
12037  libstl_la_SOURCES = meshstlsurface.cpp stlgeom.cpp stlgeomchart.cpp \
12038 @@ -16,6 +16,5 @@
12039  
12040  libstlvis_la_SOURCES = stlpkg.cpp vsstl.cpp
12041  libstlvis_la_LIBADD = libstl.la
12042 -libstl_la_LIBADD =  $(top_builddir)/libsrc/meshing/libmesh.la
12043  # libstlvis_la_LIBADD = libstl.la $(top_builddir)/libsrc/linalg/libla.la 
12044  
12045 --- netgen_ref/libsrc/stlgeom/stlgeom.cpp
12046 +++ netgen/libsrc/stlgeom/stlgeom.cpp
12047 @@ -250,7 +250,7 @@
12048  
12049           if (!nbt)
12050             {
12051 -             cerr << "ERROR: stlgeom::Smoothnormals, nbt = 0" << endl;
12052 +             std::cerr << "ERROR: stlgeom::Smoothnormals, nbt = 0" << std::endl;
12053             }
12054  
12055           // smoothed normal
12056 --- netgen_ref/libsrc/stlgeom/stlgeom.hpp
12057 +++ netgen/libsrc/stlgeom/stlgeom.hpp
12058 @@ -38,7 +38,7 @@
12059      return true;
12060    }
12061    
12062 -  extern DLL_HEADER MeshingParameters mparam;
12063 +  DLL_HEADER extern MeshingParameters mparam;
12064    
12065  
12066  
12067 --- /dev/null
12068 +++ netgen/nglib/CMakeLists.txt
12069 @@ -0,0 +1,252 @@
12070 +# Copyright (C) 2016 OPEN CASCADE
12071 +#
12072 +# This library is free software; you can redistribute it and/or
12073 +# modify it under the terms of the GNU Lesser General Public
12074 +# License as published by the Free Software Foundation; either
12075 +# version 2.1 of the License, or (at your option) any later version.
12076 +#
12077 +# This library is distributed in the hope that it will be useful,
12078 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
12079 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12080 +# Lesser General Public License for more details.
12081 +#
12082 +# You should have received a copy of the GNU Lesser General Public
12083 +# License along with this library; if not, write to the Free Software
12084 +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
12085 +#
12086 +# See http://www.salome-platform.org/ or email : webmaster.salome@opencascade.com
12087 +#
12088 +INCLUDE_DIRECTORIES(
12089 +    ${CMAKE_CURRENT_SOURCE_DIR}
12090 +    ${PROJECT_SOURCE_DIR}/libsrc/include
12091 +    ${ZLIB_INCLUDE_DIRS}
12092 +    ${CAS_INCLUDE_DIRS}
12093 +)
12094 +
12095 +
12096 +# CGS
12097 +SET(CGS_SOURCES 
12098 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/algprim.cpp 
12099 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/brick.cpp
12100 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/bspline2d.cpp 
12101 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/csgeom.cpp 
12102 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/csgparser.cpp 
12103 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/curve2d.cpp 
12104 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/edgeflw.cpp       
12105 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/explicitcurve2d.cpp 
12106 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/extrusion.cpp 
12107 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/gencyl.cpp 
12108 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/genmesh.cpp 
12109 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/identify.cpp  
12110 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/manifold.cpp 
12111 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/meshsurf.cpp 
12112 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/polyhedra.cpp 
12113 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/revolution.cpp 
12114 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/singularref.cpp 
12115 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/solid.cpp 
12116 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/specpoin.cpp 
12117 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/spline3d.cpp 
12118 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/surface.cpp 
12119 +    ${PROJECT_SOURCE_DIR}/libsrc/csg/triapprox.cpp)
12120 +
12121 +# GENERAL
12122 +SET(GENERAL_SOURCES 
12123 +   ${PROJECT_SOURCE_DIR}/libsrc/general/array.cpp 
12124 +   ${PROJECT_SOURCE_DIR}/libsrc/general/bitarray.cpp 
12125 +   ${PROJECT_SOURCE_DIR}/libsrc/general/dynamicmem.cpp 
12126 +   ${PROJECT_SOURCE_DIR}/libsrc/general/flags.cpp 
12127 +   ${PROJECT_SOURCE_DIR}/libsrc/general/hashtabl.cpp 
12128 +   ${PROJECT_SOURCE_DIR}/libsrc/general/mystring.cpp 
12129 +   ${PROJECT_SOURCE_DIR}/libsrc/general/ngexception.cpp 
12130 +   ${PROJECT_SOURCE_DIR}/libsrc/general/optmem.cpp 
12131 +   ${PROJECT_SOURCE_DIR}/libsrc/general/parthreads.cpp 
12132 +   ${PROJECT_SOURCE_DIR}/libsrc/general/profiler.cpp 
12133 +   ${PROJECT_SOURCE_DIR}/libsrc/general/seti.cpp 
12134 +   ${PROJECT_SOURCE_DIR}/libsrc/general/sort.cpp 
12135 +   ${PROJECT_SOURCE_DIR}/libsrc/general/spbita2d.cpp 
12136 +   ${PROJECT_SOURCE_DIR}/libsrc/general/symbolta.cpp 
12137 +   ${PROJECT_SOURCE_DIR}/libsrc/general/table.cpp 
12138 +   ${PROJECT_SOURCE_DIR}/libsrc/general/mpi_interface.cpp 
12139 +   ${PROJECT_SOURCE_DIR}/libsrc/general/gzstream.cpp)
12140 +
12141 +FILE(GLOB GENERAL_INCLUDES "${PROJECT_SOURCE_DIR}/libsrc/general/*.hpp")
12142 +LIST(APPEND GENERAL_INCLUDES ${PROJECT_SOURCE_DIR}/libsrc/general/gzstream.h)
12143 +
12144 +# GEOM2D
12145 +SET (GEOM2D_SOURCES 
12146 +     ${PROJECT_SOURCE_DIR}/libsrc/geom2d/genmesh2d.cpp 
12147 +     ${PROJECT_SOURCE_DIR}/libsrc/geom2d/geom2dmesh.cpp 
12148 +     ${PROJECT_SOURCE_DIR}/libsrc/geom2d/geometry2d.cpp)
12149 +
12150 +# GPRIM
12151 +SET(GPRIM_SOURCES 
12152 +    ${PROJECT_SOURCE_DIR}/libsrc/gprim/adtree.cpp 
12153 +    ${PROJECT_SOURCE_DIR}/libsrc/gprim/geom2d.cpp 
12154 +    ${PROJECT_SOURCE_DIR}/libsrc/gprim/geom3d.cpp 
12155 +    ${PROJECT_SOURCE_DIR}/libsrc/gprim/geomfuncs.cpp 
12156 +    ${PROJECT_SOURCE_DIR}/libsrc/gprim/geomtest3d.cpp 
12157 +    ${PROJECT_SOURCE_DIR}/libsrc/gprim/transform3d.cpp 
12158 +    ${PROJECT_SOURCE_DIR}/libsrc/gprim/spline.cpp 
12159 +    ${PROJECT_SOURCE_DIR}/libsrc/gprim/splinegeometry.cpp)
12160 +
12161 +FILE(GLOB GPRIM_INCLUDES "${PROJECT_SOURCE_DIR}/libsrc/gprim/*.hpp")
12162 +
12163 +# INCLUDE
12164 +SET(INCLUDE_INCLUDES 
12165 +    ${PROJECT_SOURCE_DIR}/libsrc/include/nginterface.h
12166 +    ${PROJECT_SOURCE_DIR}/libsrc/include/nginterface_v2.hpp
12167 +    ${PROJECT_SOURCE_DIR}/libsrc/include/mystdlib.h
12168 +    ${PROJECT_SOURCE_DIR}/libsrc/include/mydefs.hpp)
12169 +
12170 +# INTERFACE
12171 +SET(INTERFACE_SOURCES 
12172 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/nginterface.cpp 
12173 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/nginterface_v2.cpp
12174 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/read_fnf_mesh.cpp 
12175 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/readtetmesh.cpp 
12176 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/readuser.cpp 
12177 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/writeabaqus.cpp 
12178 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/writediffpack.cpp 
12179 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/writedolfin.cpp 
12180 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/writeelmer.cpp 
12181 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/writefeap.cpp 
12182 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/writefluent.cpp 
12183 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/writegmsh.cpp 
12184 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/writejcm.cpp 
12185 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/writepermas.cpp 
12186 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/writetecplot.cpp 
12187 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/writetet.cpp 
12188 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/writetochnog.cpp 
12189 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/writeuser.cpp 
12190 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/wuchemnitz.cpp 
12191 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/writegmsh2.cpp 
12192 +    ${PROJECT_SOURCE_DIR}/libsrc/interface/writeOpenFOAM15x.cpp)
12193 +
12194 +# LINALG
12195 +SET (LINALG_SOURCES 
12196 +     ${PROJECT_SOURCE_DIR}/libsrc/linalg/densemat.cpp 
12197 +     ${PROJECT_SOURCE_DIR}/libsrc/linalg/polynomial.cpp 
12198 +     ${PROJECT_SOURCE_DIR}/libsrc/linalg/bfgs.cpp 
12199 +     ${PROJECT_SOURCE_DIR}/libsrc/linalg/linopt.cpp 
12200 +     ${PROJECT_SOURCE_DIR}/libsrc/linalg/linsearch.cpp)
12201 +
12202 +FILE(GLOB LINALG_INCLUDES "${PROJECT_SOURCE_DIR}/libsrc/linalg/*.hpp")
12203 +
12204 +# MESHING
12205 +SET(MESHING_SOURCES 
12206 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/adfront2.cpp 
12207 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/adfront3.cpp
12208 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/bisect.cpp 
12209 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/boundarylayer.cpp 
12210 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/clusters.cpp      
12211 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/curvedelems.cpp 
12212 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/delaunay.cpp 
12213 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/delaunay2d.cpp 
12214 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/geomsearch.cpp 
12215 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/global.cpp     
12216 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/hprefinement.cpp 
12217 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/improve2.cpp 
12218 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/improve2gen.cpp 
12219 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/improve3.cpp 
12220 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/localh.cpp 
12221 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/meshclass.cpp 
12222 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/meshfunc.cpp 
12223 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/meshfunc2d.cpp 
12224 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/meshing2.cpp 
12225 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/meshing3.cpp 
12226 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/meshtool.cpp 
12227 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/meshtype.cpp 
12228 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/msghandler.cpp 
12229 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/netrule2.cpp 
12230 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/netrule3.cpp 
12231 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/parser2.cpp 
12232 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/parser3.cpp 
12233 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/prism2rls.cpp 
12234 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/pyramid2rls.cpp 
12235 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/pyramidrls.cpp 
12236 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/quadrls.cpp 
12237 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/refine.cpp    
12238 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/ruler2.cpp 
12239 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/ruler3.cpp 
12240 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/secondorder.cpp 
12241 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/smoothing2.5.cpp 
12242 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/smoothing2.cpp 
12243 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/smoothing3.cpp 
12244 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/specials.cpp 
12245 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/tetrarls.cpp 
12246 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/topology.cpp 
12247 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/triarls.cpp 
12248 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/validate.cpp 
12249 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/zrefine.cpp 
12250 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/bcfunctions.cpp 
12251 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/parallelmesh.cpp 
12252 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/paralleltop.cpp 
12253 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/paralleltop.hpp 
12254 +    ${PROJECT_SOURCE_DIR}/libsrc/meshing/basegeom.cpp)
12255 +
12256 +FILE(GLOB MESHING_INCLUDES "${PROJECT_SOURCE_DIR}/libsrc/meshing/*.hpp")
12257 +
12258 +# OCC
12259 +SET(OCC_SOURCES 
12260 +    ${PROJECT_SOURCE_DIR}/libsrc/occ/Partition_Inter2d.cxx 
12261 +    ${PROJECT_SOURCE_DIR}/libsrc/occ/Partition_Inter3d.cxx 
12262 +    ${PROJECT_SOURCE_DIR}/libsrc/occ/Partition_Loop.cxx 
12263 +    ${PROJECT_SOURCE_DIR}/libsrc/occ/Partition_Loop2d.cxx 
12264 +    ${PROJECT_SOURCE_DIR}/libsrc/occ/Partition_Loop3d.cxx 
12265 +    ${PROJECT_SOURCE_DIR}/libsrc/occ/Partition_Spliter.cxx 
12266 +    ${PROJECT_SOURCE_DIR}/libsrc/occ/occconstruction.cpp 
12267 +    ${PROJECT_SOURCE_DIR}/libsrc/occ/occgenmesh.cpp 
12268 +    ${PROJECT_SOURCE_DIR}/libsrc/occ/occgeom.cpp 
12269 +    ${PROJECT_SOURCE_DIR}/libsrc/occ/occmeshsurf.cpp)
12270 +
12271 +SET(OCC_INCLUDES ${PROJECT_SOURCE_DIR}/libsrc/occ/occgeom.hpp ${PROJECT_SOURCE_DIR}/libsrc/occ/occmeshsurf.hpp)
12272 +
12273 +# STLGEOM
12274 +SET(STLGEOM_SOURCES 
12275 +    ${PROJECT_SOURCE_DIR}/libsrc/stlgeom/meshstlsurface.cpp 
12276 +    ${PROJECT_SOURCE_DIR}/libsrc/stlgeom/stlgeom.cpp 
12277 +    ${PROJECT_SOURCE_DIR}/libsrc/stlgeom/stlgeomchart.cpp 
12278 +    ${PROJECT_SOURCE_DIR}/libsrc/stlgeom/stlgeommesh.cpp 
12279 +    ${PROJECT_SOURCE_DIR}/libsrc/stlgeom/stlline.cpp 
12280 +    ${PROJECT_SOURCE_DIR}/libsrc/stlgeom/stltool.cpp 
12281 +    ${PROJECT_SOURCE_DIR}/libsrc/stlgeom/stltopology.cpp)
12282 +
12283 +# NGLIB
12284 +SET(NGLIB_SOURCES nglib.cpp)
12285 +ADD_LIBRARY(nglib SHARED 
12286 +            ${NGLIB_SOURCES}
12287 +            ${CGS_SOURCES} 
12288 +            ${GENERAL_SOURCES}
12289 +            ${GPRIM_SOURCES}
12290 +            ${GEOM2D_SOURCES}
12291 +            ${INTERFACE_SOURCES} 
12292 +            ${LINALG_SOURCES} 
12293 +            ${MESHING_SOURCES} 
12294 +            ${OCC_SOURCES}
12295 +            ${STLGEOM_SOURCES})
12296 +
12297 +TARGET_LINK_LIBRARIES(nglib ${OCCLIBS} ${PLATFORM_LIBADD} ${ZLIB_LIBRARIES})
12298 +INSTALL(TARGETS nglib DESTINATION ${NETGEN_INSTALL_LIBS}) 
12299 +
12300 +# Install headers
12301 +INSTALL(FILES ${GENERAL_INCLUDES} 
12302 +              ${INCLUDE_INCLUDES}
12303 +              ${GPRIM_INCLUDES} 
12304 +              ${LINALG_INCLUDES} 
12305 +              ${MESHING_INCLUDES} 
12306 +              ${OCC_INCLUDES} 
12307 +              nglib.h 
12308 +              DESTINATION ${NETGEN_INSTALL_HEADERS})
12309 +
12310 +
12311 +# NG_VOL
12312 +SET(NG_VOL_SOURCES ng_vol.cpp)
12313 +ADD_EXECUTABLE(ng_vol ${NG_VOL_SOURCES})
12314 +TARGET_LINK_LIBRARIES(ng_vol nglib)
12315 +INSTALL(TARGETS ng_vol  DESTINATION ${NETGEN_INSTALL_BINS})
12316 +
12317 +# NG_STL
12318 +SET(NG_STL_SOURCES ng_stl.cpp)
12319 +ADD_EXECUTABLE(ng_stl ${NG_STL_SOURCES})
12320 +TARGET_LINK_LIBRARIES(ng_stl nglib)
12321 +INSTALL(TARGETS ng_stl  DESTINATION ${NETGEN_INSTALL_BINS})
12322 --- netgen_ref/nglib/Makefile.am
12323 +++ netgen/nglib/Makefile.am
12324 @@ -14,6 +14,9 @@
12325         $(top_builddir)/libsrc/stlgeom/libstl.la \
12326         $(top_builddir)/libsrc/occ/libocc.la \
12327         $(top_builddir)/libsrc/meshing/libmesh.la \
12328 +       $(top_builddir)/libsrc/general/libgen.la \
12329 +       $(top_builddir)/libsrc/gprim/libgprim.la \
12330 +       $(top_builddir)/libsrc/linalg/libla.la
12331         $(OCCLIBS) $(MPI_LIBS)
12332  
12333  libnglib_la_LDFLAGS = -avoid-version
12334 --- netgen_ref/nglib/nglib.cpp
12335 +++ netgen/nglib/nglib.cpp
12336 @@ -1,1242 +1,1243 @@
12337 -/**************************************************************************/
12338 -/* File:   nglib.cpp                                                      */
12339 -/* Author: Joachim Schoeberl                                              */
12340 -/* Date:   7. May. 2000                                                   */
12341 -/**************************************************************************/
12342 -
12343 -/*
12344 -  
12345 -  Interface to the netgen meshing kernel
12346 -  
12347 -*/
12348 -#include <mystdlib.h>
12349 -#include <myadt.hpp>
12350 -
12351 -#include <linalg.hpp>
12352 -#include <csg.hpp>
12353 -#include <stlgeom.hpp>
12354 -#include <geometry2d.hpp>
12355 -#include <meshing.hpp>
12356 -#include <../visualization/soldata.hpp>
12357 -
12358 -#ifdef OCCGEOMETRY
12359 -#include <occgeom.hpp>
12360 -#endif
12361 -
12362 -#include <nginterface.h>
12363 -
12364 -
12365 -namespace netgen {
12366 -   extern void MeshFromSpline2D (SplineGeometry2d & geometry,
12367 -                                 Mesh *& mesh, 
12368 -                                 MeshingParameters & mp);
12369 -}
12370 -
12371 -
12372 -
12373 -#ifdef PARALLEL
12374 -#include <mpi.h>
12375 -
12376 -namespace netgen
12377 -{
12378 -  // int id = 0, ntasks = 1;
12379 -  MPI_Comm mesh_comm;
12380 -}
12381 -#endif
12382 -
12383 -
12384 -namespace netgen
12385 -{
12386 -  int id = 0, ntasks = 1;
12387 -}
12388 -
12389 -
12390 -
12391 -/*
12392 -// should not be needed (occ currently requires it)
12393 -namespace netgen {
12394 -#include "../libsrc/visualization/vispar.hpp"
12395 -  VisualizationParameters vispar;
12396 -  VisualizationParameters :: VisualizationParameters() { ; }
12397 -}
12398 -*/
12399 -
12400 -
12401 -namespace nglib {
12402 -#include "nglib.h"
12403 -}
12404 -
12405 -using namespace netgen;
12406 -
12407 -// constants and types:
12408 -
12409 -namespace nglib
12410 -{
12411 -   // initialize, deconstruct Netgen library:
12412 -   DLL_HEADER void Ng_Init ()
12413 -   {
12414 -      mycout = &cout;
12415 -      myerr = &cerr;
12416 -      // netgen::testout->SetOutStream (new ofstream ("test.out"));
12417 -      testout = new ofstream ("test.out");
12418 -   }
12419 -
12420 -
12421 -
12422 -
12423 -   // Clean-up functions before ending usage of nglib
12424 -   DLL_HEADER void Ng_Exit ()
12425 -   {
12426 -      ;
12427 -   }
12428 -
12429 -
12430 -
12431 -
12432 -   // Create a new netgen mesh object
12433 -   DLL_HEADER Ng_Mesh * Ng_NewMesh ()
12434 -   {
12435 -      Mesh * mesh = new Mesh;  
12436 -      mesh->AddFaceDescriptor (FaceDescriptor (1, 1, 0, 1));
12437 -      return (Ng_Mesh*)(void*)mesh;
12438 -   }
12439 -
12440 -
12441 -
12442 -
12443 -   // Delete an existing netgen mesh object
12444 -   DLL_HEADER void Ng_DeleteMesh (Ng_Mesh * mesh)
12445 -   {
12446 -      if(mesh != NULL)
12447 -      {
12448 -         // Delete the Mesh structures
12449 -         ((Mesh*)mesh)->DeleteMesh();
12450 -
12451 -         // Now delete the Mesh class itself
12452 -         delete (Mesh*)mesh;
12453 -
12454 -         // Set the Ng_Mesh pointer to NULL
12455 -         mesh = NULL;
12456 -      }
12457 -   }
12458 -
12459 -
12460 -
12461 -
12462 -   // Save a netgen mesh in the native VOL format 
12463 -   DLL_HEADER void Ng_SaveMesh(Ng_Mesh * mesh, const char* filename)
12464 -   {
12465 -      ((Mesh*)mesh)->Save(filename);
12466 -   }
12467 -
12468 -
12469 -
12470 -
12471 -   // Load a netgen native VOL mesh from a given file
12472 -   DLL_HEADER Ng_Mesh * Ng_LoadMesh(const char* filename)
12473 -   {
12474 -      Mesh * mesh = new Mesh;
12475 -      mesh->Load(filename);
12476 -      return ( (Ng_Mesh*)mesh );
12477 -   }
12478 -
12479 -
12480 -
12481 -
12482 -   // Merge another mesh file into the currently loaded one
12483 -   DLL_HEADER Ng_Result Ng_MergeMesh( Ng_Mesh* mesh, const char* filename)
12484 -   {
12485 -      Ng_Result status = NG_OK;
12486 -
12487 -      ifstream infile(filename);
12488 -      Mesh * m = (Mesh*)mesh;
12489 -
12490 -      if(!infile.good())
12491 -      {
12492 -         status = NG_FILE_NOT_FOUND;
12493 -      }
12494 -
12495 -      if(!m)
12496 -      {
12497 -         status = NG_ERROR;
12498 -      }
12499 -
12500 -      if(status == NG_OK)
12501 -      {
12502 -         const int num_pts = m->GetNP();
12503 -         const int face_offset = m->GetNFD();
12504 -
12505 -         m->Merge(infile, face_offset);
12506 -
12507 -         if(m->GetNP() > num_pts)
12508 -         {
12509 -            status = NG_OK;
12510 -         }
12511 -         else
12512 -         {
12513 -            status = NG_ERROR;
12514 -         }
12515 -      }
12516 -
12517 -      return status;
12518 -   }
12519 -
12520 -
12521 -
12522 -
12523 -   // Merge another mesh file into the currently loaded one
12524 -   DLL_HEADER Ng_Result Ng_MergeMesh( Ng_Mesh* mesh1, Ng_Mesh* mesh2)
12525 -   {
12526 -      return NG_ERROR;
12527 -   }
12528 -
12529 -
12530 -
12531 -
12532 -   // Manually add a point to an existing mesh object
12533 -   DLL_HEADER void Ng_AddPoint (Ng_Mesh * mesh, double * x)
12534 -   {
12535 -      Mesh * m = (Mesh*)mesh;
12536 -      m->AddPoint (Point3d (x[0], x[1], x[2]));
12537 -   }
12538 -
12539 -
12540 -
12541 -
12542 -   // Manually add a surface element of a given type to an existing mesh object
12543 -   DLL_HEADER void Ng_AddSurfaceElement (Ng_Mesh * mesh, Ng_Surface_Element_Type et,
12544 -                                         int * pi)
12545 -   {
12546 -      Mesh * m = (Mesh*)mesh;
12547 -      Element2d el (3);
12548 -      el.SetIndex (1);
12549 -      el.PNum(1) = pi[0];
12550 -      el.PNum(2) = pi[1];
12551 -      el.PNum(3) = pi[2];
12552 -      m->AddSurfaceElement (el);
12553 -   }
12554 -
12555 -
12556 -
12557 -
12558 -   // Manually add a volume element of a given type to an existing mesh object
12559 -   DLL_HEADER void Ng_AddVolumeElement (Ng_Mesh * mesh, Ng_Volume_Element_Type et,
12560 -                                        int * pi)
12561 -   {
12562 -      Mesh * m = (Mesh*)mesh;
12563 -      Element el (4);
12564 -      el.SetIndex (1);
12565 -      el.PNum(1) = pi[0];
12566 -      el.PNum(2) = pi[1];
12567 -      el.PNum(3) = pi[2];
12568 -      el.PNum(4) = pi[3];
12569 -      m->AddVolumeElement (el);
12570 -   }
12571 -
12572 -
12573 -
12574 -
12575 -   // Obtain the number of points in the mesh
12576 -   DLL_HEADER int Ng_GetNP (Ng_Mesh * mesh)
12577 -   {
12578 -      return ((Mesh*)mesh) -> GetNP();
12579 -   }
12580 -
12581 -
12582 -
12583 -
12584 -   // Obtain the number of surface elements in the mesh
12585 -   DLL_HEADER int Ng_GetNSE (Ng_Mesh * mesh)
12586 -   {
12587 -      return ((Mesh*)mesh) -> GetNSE();
12588 -   }
12589 -
12590 -
12591 -
12592 -
12593 -   // Obtain the number of volume elements in the mesh
12594 -   DLL_HEADER int Ng_GetNE (Ng_Mesh * mesh)
12595 -   {
12596 -      return ((Mesh*)mesh) -> GetNE();
12597 -   }
12598 -
12599 -
12600 -
12601 -
12602 -   //  Return point coordinates of a given point index in the mesh
12603 -   DLL_HEADER void Ng_GetPoint (Ng_Mesh * mesh, int num, double * x)
12604 -   {
12605 -      const Point3d & p = ((Mesh*)mesh)->Point(num);
12606 -      x[0] = p.X();
12607 -      x[1] = p.Y();
12608 -      x[2] = p.Z();
12609 -   }
12610 -
12611 -
12612 -
12613 -
12614 -   // Return the surface element at a given index "pi"
12615 -   DLL_HEADER Ng_Surface_Element_Type 
12616 -      Ng_GetSurfaceElement (Ng_Mesh * mesh, int num, int * pi)
12617 -   {
12618 -      const Element2d & el = ((Mesh*)mesh)->SurfaceElement(num);
12619 -      for (int i = 1; i <= el.GetNP(); i++)
12620 -         pi[i-1] = el.PNum(i);
12621 -      Ng_Surface_Element_Type et;
12622 -      switch (el.GetNP())
12623 -      {
12624 -      case 3: et = NG_TRIG; break;
12625 -      case 4: et = NG_QUAD; break;
12626 -      case 6: 
12627 -         switch (el.GetNV())
12628 -         {
12629 -         case 3: et = NG_TRIG6; break;
12630 -         case 4: et = NG_QUAD6; break;
12631 -         default:
12632 -            et = NG_TRIG6; break;
12633 -         }
12634 -         break;
12635 -      case 8: et = NG_QUAD8; break;
12636 -      default:
12637 -         et = NG_TRIG; break; // for the compiler
12638 -      }
12639 -      return et;
12640 -   }
12641 -
12642 -
12643 -
12644 -
12645 -   // Return the volume element at a given index "pi"
12646 -   DLL_HEADER Ng_Volume_Element_Type
12647 -      Ng_GetVolumeElement (Ng_Mesh * mesh, int num, int * pi)
12648 -   {
12649 -      const Element & el = ((Mesh*)mesh)->VolumeElement(num);
12650 -      for (int i = 1; i <= el.GetNP(); i++)
12651 -         pi[i-1] = el.PNum(i);
12652 -      Ng_Volume_Element_Type et;
12653 -      switch (el.GetNP())
12654 -      {
12655 -      case 4: et = NG_TET; break;
12656 -      case 5: et = NG_PYRAMID; break;
12657 -      case 6: et = NG_PRISM; break;
12658 -      case 10: et = NG_TET10; break;
12659 -      default:
12660 -         et = NG_TET; break; // for the compiler
12661 -      }
12662 -      return et;
12663 -   }
12664 -
12665 -
12666 -
12667 -
12668 -   // Set a global limit on the maximum mesh size allowed
12669 -   DLL_HEADER void Ng_RestrictMeshSizeGlobal (Ng_Mesh * mesh, double h)
12670 -   {
12671 -      ((Mesh*)mesh) -> SetGlobalH (h);
12672 -   }
12673 -
12674 -
12675 -
12676 -
12677 -   // Set a local limit on the maximum mesh size allowed around the given point
12678 -   DLL_HEADER void Ng_RestrictMeshSizePoint (Ng_Mesh * mesh, double * p, double h)
12679 -   {
12680 -      ((Mesh*)mesh) -> RestrictLocalH (Point3d (p[0], p[1], p[2]), h);
12681 -   }
12682 -
12683 -
12684 -
12685 -
12686 -   // Set a local limit on the maximum mesh size allowed within a given box region
12687 -   DLL_HEADER void Ng_RestrictMeshSizeBox (Ng_Mesh * mesh, double * pmin, double * pmax, double h)
12688 -   {
12689 -      for (double x = pmin[0]; x < pmax[0]; x += h)
12690 -         for (double y = pmin[1]; y < pmax[1]; y += h)
12691 -            for (double z = pmin[2]; z < pmax[2]; z += h)
12692 -               ((Mesh*)mesh) -> RestrictLocalH (Point3d (x, y, z), h);
12693 -   }
12694 -
12695 -
12696 -
12697 -
12698 -   // Generates volume mesh from an existing surface mesh
12699 -   DLL_HEADER Ng_Result Ng_GenerateVolumeMesh (Ng_Mesh * mesh, Ng_Meshing_Parameters * mp)
12700 -   {
12701 -      Mesh * m = (Mesh*)mesh;
12702 -
12703 -      // Philippose - 30/08/2009
12704 -      // Do not locally re-define "mparam" here... "mparam" is a global 
12705 -      // object 
12706 -      //MeshingParameters mparam;
12707 -      mp->Transfer_Parameters();
12708 -
12709 -      m->CalcLocalH(mparam.grading);
12710 -
12711 -      MeshVolume (mparam, *m);
12712 -      RemoveIllegalElements (*m);
12713 -      OptimizeVolume (mparam, *m);
12714 -
12715 -      return NG_OK;
12716 -   }
12717 -
12718 -
12719 -
12720 -
12721 -   /* ------------------ 2D Meshing Functions ------------------------- */
12722 -   DLL_HEADER void Ng_AddPoint_2D (Ng_Mesh * mesh, double * x)
12723 -   {
12724 -      Mesh * m = (Mesh*)mesh;
12725 -
12726 -      m->AddPoint (Point3d (x[0], x[1], 0));
12727 -   }
12728 -
12729 -
12730 -
12731 -
12732 -   DLL_HEADER void Ng_AddBoundarySeg_2D (Ng_Mesh * mesh, int pi1, int pi2)
12733 -   {
12734 -      Mesh * m = (Mesh*)mesh;
12735 -
12736 -      Segment seg;
12737 -      seg[0] = pi1;
12738 -      seg[1] = pi2;
12739 -      m->AddSegment (seg);
12740 -   }
12741 -
12742 -
12743 -
12744 -
12745 -   DLL_HEADER int Ng_GetNP_2D (Ng_Mesh * mesh)
12746 -   {
12747 -      Mesh * m = (Mesh*)mesh;
12748 -      return m->GetNP();
12749 -   }
12750 -
12751 -
12752 -
12753 -
12754 -   DLL_HEADER int Ng_GetNE_2D (Ng_Mesh * mesh)
12755 -   {
12756 -      Mesh * m = (Mesh*)mesh;
12757 -      return m->GetNSE();
12758 -   }
12759 -
12760 -
12761 -
12762 -
12763 -   DLL_HEADER int Ng_GetNSeg_2D (Ng_Mesh * mesh)
12764 -   {
12765 -      Mesh * m = (Mesh*)mesh;
12766 -      return m->GetNSeg();
12767 -   }
12768 -
12769 -
12770 -
12771 -
12772 -   DLL_HEADER void Ng_GetPoint_2D (Ng_Mesh * mesh, int num, double * x)
12773 -   {
12774 -      Mesh * m = (Mesh*)mesh;
12775 -
12776 -      Point<3> & p = m->Point(num);
12777 -      x[0] = p(0);
12778 -      x[1] = p(1);
12779 -   }
12780 -
12781 -
12782 -
12783 -
12784 -   DLL_HEADER Ng_Surface_Element_Type
12785 -      Ng_GetElement_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum)
12786 -   {
12787 -      const Element2d & el = ((Mesh*)mesh)->SurfaceElement(num);
12788 -      for (int i = 1; i <= el.GetNP(); i++)
12789 -         pi[i-1] = el.PNum(i);
12790 -
12791 -      Ng_Surface_Element_Type et;
12792 -      switch (el.GetNP())
12793 -      {
12794 -      case 3: et = NG_TRIG; break;
12795 -      case 4: et = NG_QUAD; break;
12796 -      case 6: 
12797 -         switch (el.GetNV())
12798 -         {
12799 -         case 3: et = NG_TRIG6; break;
12800 -         case 4: et = NG_QUAD6; break;
12801 -         default:
12802 -            et = NG_TRIG6; break;
12803 -         }
12804 -         break;
12805 -      case 8: et = NG_QUAD8; break;
12806 -      default:
12807 -         et = NG_TRIG; break; // for the compiler
12808 -      }
12809 -
12810 -      if (matnum)
12811 -         *matnum = el.GetIndex();
12812 -
12813 -      return et;
12814 -   }
12815 -
12816 -
12817 -
12818 -
12819 -   DLL_HEADER void Ng_GetSegment_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum)
12820 -   {
12821 -      const Segment & seg = ((Mesh*)mesh)->LineSegment(num);
12822 -      pi[0] = seg[0];
12823 -      pi[1] = seg[1];
12824 -
12825 -      if (matnum)
12826 -         *matnum = seg.edgenr;
12827 -   }
12828 -
12829 -
12830 -
12831 -
12832 -   DLL_HEADER Ng_Geometry_2D * Ng_LoadGeometry_2D (const char * filename)
12833 -   {
12834 -      SplineGeometry2d * geom = new SplineGeometry2d();
12835 -      geom -> Load (filename);
12836 -      return (Ng_Geometry_2D *)geom;
12837 -   }
12838 -
12839 -
12840 -
12841 -
12842 -   DLL_HEADER Ng_Result Ng_GenerateMesh_2D (Ng_Geometry_2D * geom,
12843 -                                            Ng_Mesh ** mesh,
12844 -                                            Ng_Meshing_Parameters * mp)
12845 -   {
12846 -      // use global variable mparam
12847 -      //  MeshingParameters mparam;  
12848 -      mp->Transfer_Parameters();
12849 -
12850 -      Mesh * m;
12851 -      MeshFromSpline2D (*(SplineGeometry2d*)geom, m, mparam);
12852 -
12853 -      cout << m->GetNSE() << " elements, " << m->GetNP() << " points" << endl;
12854 -
12855 -      *mesh = (Ng_Mesh*)m;
12856 -      return NG_OK;
12857 -   }
12858 -
12859 -
12860 -
12861 -
12862 -   DLL_HEADER void Ng_HP_Refinement (Ng_Geometry_2D * geom,
12863 -      Ng_Mesh * mesh,
12864 -      int levels)
12865 -   {
12866 -      Refinement2d ref(*(SplineGeometry2d*)geom);
12867 -      HPRefinement (*(Mesh*)mesh, &ref, levels);
12868 -   }
12869 -
12870 -
12871 -
12872 -
12873 -   DLL_HEADER void Ng_HP_Refinement (Ng_Geometry_2D * geom,
12874 -      Ng_Mesh * mesh,
12875 -      int levels, double parameter)
12876 -   {
12877 -      Refinement2d ref(*(SplineGeometry2d*)geom);
12878 -      HPRefinement (*(Mesh*)mesh, &ref, levels, parameter);
12879 -   }
12880 -
12881 -
12882 -
12883 -
12884 -   Array<STLReadTriangle> readtrias; //only before initstlgeometry
12885 -   Array<Point<3> > readedges; //only before init stlgeometry
12886 -
12887 -   // loads geometry from STL file
12888 -   DLL_HEADER Ng_STL_Geometry * Ng_STL_LoadGeometry (const char * filename, int binary)
12889 -   {
12890 -      int i;
12891 -      STLGeometry geom;
12892 -      STLGeometry* geo;
12893 -      ifstream ist(filename);
12894 -
12895 -      if (binary)
12896 -      {
12897 -         geo = geom.LoadBinary(ist);
12898 -      }
12899 -      else
12900 -      {
12901 -         geo = geom.Load(ist);
12902 -      }
12903 -
12904 -      readtrias.SetSize(0);
12905 -      readedges.SetSize(0);
12906 -
12907 -      Point3d p;
12908 -      Vec3d normal;
12909 -      double p1[3];
12910 -      double p2[3];
12911 -      double p3[3];
12912 -      double n[3];
12913 -
12914 -      Ng_STL_Geometry * geo2 = Ng_STL_NewGeometry();
12915 -
12916 -      for (i = 1; i <= geo->GetNT(); i++)
12917 -      {
12918 -         const STLTriangle& t = geo->GetTriangle(i);
12919 -         p = geo->GetPoint(t.PNum(1));
12920 -         p1[0] = p.X(); p1[1] = p.Y(); p1[2] = p.Z(); 
12921 -         p = geo->GetPoint(t.PNum(2));
12922 -         p2[0] = p.X(); p2[1] = p.Y(); p2[2] = p.Z(); 
12923 -         p = geo->GetPoint(t.PNum(3));
12924 -         p3[0] = p.X(); p3[1] = p.Y(); p3[2] = p.Z();
12925 -         normal = t.Normal();
12926 -         n[0] = normal.X(); n[1] = normal.Y(); n[2] = normal.Z();
12927 -
12928 -         Ng_STL_AddTriangle(geo2, p1, p2, p3, n);
12929 -      }
12930 -
12931 -      return geo2;
12932 -   }
12933 -
12934 -
12935 -
12936 -
12937 -   // generate new STL Geometry
12938 -   DLL_HEADER Ng_STL_Geometry * Ng_STL_NewGeometry ()
12939 -   {
12940 -      return (Ng_STL_Geometry*)(void*)new STLGeometry;
12941 -   } 
12942 -
12943 -
12944 -
12945 -
12946 -   // after adding triangles (and edges) initialize
12947 -   DLL_HEADER Ng_Result Ng_STL_InitSTLGeometry (Ng_STL_Geometry * geom)
12948 -   {
12949 -      STLGeometry* geo = (STLGeometry*)geom;
12950 -      geo->InitSTLGeometry(readtrias);
12951 -      readtrias.SetSize(0);
12952 -
12953 -      if (readedges.Size() != 0)
12954 -      {
12955 -         /*
12956 -         for (int i = 1; i <= readedges.Size(); i+=2)
12957 -         {
12958 -         cout << "e(" << readedges.Get(i) << "," << readedges.Get(i+1) << ")" << endl;
12959 -         }
12960 -         */
12961 -         geo->AddEdges(readedges);
12962 -      }
12963 -
12964 -      if (geo->GetStatus() == STLTopology::STL_GOOD || geo->GetStatus() == STLTopology::STL_WARNING) return NG_OK;
12965 -      return NG_SURFACE_INPUT_ERROR;
12966 -   }
12967 -
12968 -
12969 -
12970 -
12971 -   // automatically generates edges:
12972 -   DLL_HEADER Ng_Result Ng_STL_MakeEdges (Ng_STL_Geometry * geom,
12973 -                                          Ng_Mesh* mesh,
12974 -                                          Ng_Meshing_Parameters * mp)
12975 -   {
12976 -      STLGeometry* stlgeometry = (STLGeometry*)geom;
12977 -      Mesh* me = (Mesh*)mesh;
12978 -
12979 -      // Philippose - 27/07/2009
12980 -      // Do not locally re-define "mparam" here... "mparam" is a global 
12981 -      // object 
12982 -      //MeshingParameters mparam;
12983 -      mp->Transfer_Parameters();
12984 -
12985 -      me -> SetGlobalH (mparam.maxh);
12986 -      me -> SetLocalH (stlgeometry->GetBoundingBox().PMin() - Vec3d(10, 10, 10),
12987 -                       stlgeometry->GetBoundingBox().PMax() + Vec3d(10, 10, 10),
12988 -                       0.3);
12989 -
12990 -      me -> LoadLocalMeshSize (mp->meshsize_filename);
12991 -      /*
12992 -      if (mp->meshsize_filename)
12993 -      {
12994 -      ifstream infile (mp->meshsize_filename);
12995 -      if (!infile.good()) return NG_FILE_NOT_FOUND;
12996 -      me -> LoadLocalMeshSize (infile);
12997 -      }
12998 -      */
12999 -
13000 -      STLMeshing (*stlgeometry, *me);
13001 -
13002 -      stlgeometry->edgesfound = 1;
13003 -      stlgeometry->surfacemeshed = 0;
13004 -      stlgeometry->surfaceoptimized = 0;
13005 -      stlgeometry->volumemeshed = 0;
13006 -
13007 -      return NG_OK;
13008 -   }
13009 -
13010 -
13011 -
13012 -
13013 -   // generates mesh, empty mesh be already created.
13014 -   DLL_HEADER Ng_Result Ng_STL_GenerateSurfaceMesh (Ng_STL_Geometry * geom,
13015 -                                                    Ng_Mesh* mesh,
13016 -                                                    Ng_Meshing_Parameters * mp)
13017 -   {
13018 -      STLGeometry* stlgeometry = (STLGeometry*)geom;
13019 -      Mesh* me = (Mesh*)mesh;
13020 -
13021 -      // Philippose - 27/07/2009
13022 -      // Do not locally re-define "mparam" here... "mparam" is a global 
13023 -      // object
13024 -      //MeshingParameters mparam;
13025 -      mp->Transfer_Parameters();
13026 -
13027 -
13028 -      /*
13029 -      me -> SetGlobalH (mparam.maxh);
13030 -      me -> SetLocalH (stlgeometry->GetBoundingBox().PMin() - Vec3d(10, 10, 10),
13031 -      stlgeometry->GetBoundingBox().PMax() + Vec3d(10, 10, 10),
13032 -      0.3);
13033 -      */
13034 -      /*
13035 -      STLMeshing (*stlgeometry, *me);
13036 -
13037 -      stlgeometry->edgesfound = 1;
13038 -      stlgeometry->surfacemeshed = 0;
13039 -      stlgeometry->surfaceoptimized = 0;
13040 -      stlgeometry->volumemeshed = 0;
13041 -      */  
13042 -      int retval = STLSurfaceMeshing (*stlgeometry, *me);
13043 -      if (retval == MESHING3_OK)
13044 -      {
13045 -         (*mycout) << "Success !!!!" << endl;
13046 -         stlgeometry->surfacemeshed = 1;
13047 -         stlgeometry->surfaceoptimized = 0;
13048 -         stlgeometry->volumemeshed = 0;
13049 -      } 
13050 -      else if (retval == MESHING3_OUTERSTEPSEXCEEDED)
13051 -      {
13052 -         (*mycout) << "ERROR: Give up because of too many trials. Meshing aborted!" << endl;
13053 -      }
13054 -      else if (retval == MESHING3_TERMINATE)
13055 -      {
13056 -         (*mycout) << "Meshing Stopped!" << endl;
13057 -      }
13058 -      else
13059 -      {
13060 -         (*mycout) << "ERROR: Surface meshing not successful. Meshing aborted!" << endl;
13061 -      }
13062 -
13063 -
13064 -      STLSurfaceOptimization (*stlgeometry, *me, mparam);
13065 -
13066 -      return NG_OK;
13067 -   }
13068 -
13069 -
13070 -
13071 -
13072 -   // fills STL Geometry
13073 -   // positive orientation
13074 -   // normal vector may be null-pointer
13075 -   DLL_HEADER void Ng_STL_AddTriangle (Ng_STL_Geometry * geom, 
13076 -                                       double * p1, double * p2, double * p3, 
13077 -                                       double * nv)
13078 -   {
13079 -      Point<3> apts[3];
13080 -      apts[0] = Point<3>(p1[0],p1[1],p1[2]);
13081 -      apts[1] = Point<3>(p2[0],p2[1],p2[2]);
13082 -      apts[2] = Point<3>(p3[0],p3[1],p3[2]);
13083 -
13084 -      Vec<3> n;
13085 -      if (!nv)
13086 -         n = Cross (apts[0]-apts[1], apts[0]-apts[2]);
13087 -      else
13088 -         n = Vec<3>(nv[0],nv[1],nv[2]);
13089 -
13090 -      readtrias.Append(STLReadTriangle(apts,n));
13091 -   }
13092 -
13093 -   // add (optional) edges:
13094 -   DLL_HEADER void Ng_STL_AddEdge (Ng_STL_Geometry * geom, 
13095 -      double * p1, double * p2)
13096 -   {
13097 -      readedges.Append(Point3d(p1[0],p1[1],p1[2]));
13098 -      readedges.Append(Point3d(p2[0],p2[1],p2[2]));
13099 -   }
13100 -
13101 -
13102 -
13103 -
13104 -#ifdef OCCGEOMETRY
13105 -   // --------------------- OCC Geometry / Meshing Utility Functions -------------------
13106 -   // Create new OCC Geometry Object
13107 -   DLL_HEADER Ng_OCC_Geometry * Ng_OCC_NewGeometry ()
13108 -   {
13109 -      return (Ng_OCC_Geometry*)(void*)new OCCGeometry;
13110 -   } 
13111 -
13112 -
13113 -
13114 -
13115 -   // Delete the OCC Geometry Object
13116 -   DLL_HEADER Ng_Result Ng_OCC_DeleteGeometry(Ng_OCC_Geometry * geom)
13117 -   {
13118 -      if (geom != NULL)
13119 -      {
13120 -         delete (OCCGeometry*)geom;
13121 -         geom = NULL;
13122 -         return NG_OK;
13123 -      }
13124 -      
13125 -      return NG_ERROR;
13126 -   }
13127 -
13128 -
13129 -
13130 -   
13131 -   // Loads geometry from STEP File
13132 -   DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_STEP (const char * filename)
13133 -   {
13134 -      // Call the STEP File Load function. Note.. the geometry class 
13135 -      // is created and instantiated within the load function
13136 -      OCCGeometry * occgeo = LoadOCC_STEP(filename);
13137 -
13138 -      return ((Ng_OCC_Geometry *)occgeo);
13139 -   }
13140 -
13141 -
13142 -
13143 -   
13144 -   // Loads geometry from IGES File
13145 -   DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_IGES (const char * filename)
13146 -   {
13147 -      // Call the IGES File Load function. Note.. the geometry class 
13148 -      // is created and instantiated within the load function
13149 -      OCCGeometry * occgeo = LoadOCC_IGES(filename);
13150 -
13151 -      return ((Ng_OCC_Geometry *)occgeo);
13152 -   }
13153 -
13154 -
13155 -
13156 -   
13157 -   // Loads geometry from BREP File
13158 -   DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_BREP (const char * filename)
13159 -   {
13160 -      // Call the BREP File Load function. Note.. the geometry class 
13161 -      // is created and instantiated within the load function
13162 -      OCCGeometry * occgeo = LoadOCC_BREP(filename);
13163 -
13164 -      return ((Ng_OCC_Geometry *)occgeo);
13165 -   }
13166 -
13167 -
13168 -
13169 -
13170 -   // Locally limit the size of the mesh to be generated at various points 
13171 -   // based on the topology of the geometry
13172 -   DLL_HEADER Ng_Result Ng_OCC_SetLocalMeshSize (Ng_OCC_Geometry * geom,
13173 -                                                 Ng_Mesh * mesh,
13174 -                                                 Ng_Meshing_Parameters * mp)
13175 -   {
13176 -      OCCGeometry * occgeom = (OCCGeometry*)geom;
13177 -      Mesh * me = (Mesh*)mesh;
13178 -
13179 -      me->geomtype = Mesh::GEOM_OCC;
13180 -
13181 -      mp->Transfer_Parameters();
13182 -      
13183 -      occparam.resthcloseedgeenable = mp->closeedgeenable;
13184 -      occparam.resthcloseedgefac = mp->closeedgefact;
13185 -
13186 -      // Delete the mesh structures in order to start with a clean 
13187 -      // slate
13188 -      me->DeleteMesh();
13189 -
13190 -      OCCSetLocalMeshSize(*occgeom, *me);
13191 -
13192 -      return(NG_OK);
13193 -   }
13194 -
13195 -
13196 -
13197 -   
13198 -   // Mesh the edges and add Face descriptors to prepare for surface meshing
13199 -   DLL_HEADER Ng_Result Ng_OCC_GenerateEdgeMesh (Ng_OCC_Geometry * geom,
13200 -                                                 Ng_Mesh * mesh,
13201 -                                                 Ng_Meshing_Parameters * mp)
13202 -   {
13203 -      OCCGeometry * occgeom = (OCCGeometry*)geom;
13204 -      Mesh * me = (Mesh*)mesh;
13205 -
13206 -      mp->Transfer_Parameters();
13207 -
13208 -      OCCFindEdges(*occgeom, *me);
13209 -
13210 -      if((me->GetNP()) && (me->GetNFD()))
13211 -      {
13212 -         return NG_OK;
13213 -      }
13214 -      else
13215 -      {
13216 -         return NG_ERROR;
13217 -      }
13218 -   }
13219 -
13220 -
13221 -
13222 -   
13223 -   // Mesh the edges and add Face descriptors to prepare for surface meshing
13224 -   DLL_HEADER Ng_Result Ng_OCC_GenerateSurfaceMesh (Ng_OCC_Geometry * geom,
13225 -                                                    Ng_Mesh * mesh,
13226 -                                                    Ng_Meshing_Parameters * mp)
13227 -   {
13228 -      int numpoints = 0;
13229 -
13230 -      OCCGeometry * occgeom = (OCCGeometry*)geom;
13231 -      Mesh * me = (Mesh*)mesh;
13232 -
13233 -      // Set the internal meshing parameters structure from the nglib meshing 
13234 -      // parameters structure
13235 -      mp->Transfer_Parameters();
13236 -
13237 -
13238 -      // Only go into surface meshing if the face descriptors have already been added
13239 -      if(!me->GetNFD())
13240 -         return NG_ERROR;
13241 -
13242 -      numpoints = me->GetNP();
13243 -
13244 -      // Initially set up only for surface meshing without any optimisation
13245 -      int perfstepsend = MESHCONST_MESHSURFACE;
13246 -
13247 -      // Check and if required, enable surface mesh optimisation step
13248 -      if(mp->optsurfmeshenable)
13249 -      {
13250 -         perfstepsend = MESHCONST_OPTSURFACE;
13251 -      }
13252 -
13253 -      OCCMeshSurface(*occgeom, *me, perfstepsend);
13254 -
13255 -      me->CalcSurfacesOfNode();
13256 -      
13257 -      if(me->GetNP() <= numpoints)
13258 -         return NG_ERROR;
13259 -
13260 -      if(me->GetNSE() <= 0)
13261 -         return NG_ERROR;
13262 -
13263 -      return NG_OK;
13264 -   }
13265 -
13266 -
13267 -
13268 -
13269 -   // Extract the face map from the OCC geometry
13270 -   // The face map basically gives an index to each face in the geometry, 
13271 -   // which can be used to access a specific face
13272 -   DLL_HEADER Ng_Result Ng_OCC_GetFMap(Ng_OCC_Geometry * geom, 
13273 -                                       Ng_OCC_TopTools_IndexedMapOfShape * FMap)
13274 -   {
13275 -      OCCGeometry* occgeom = (OCCGeometry*)geom;
13276 -      TopTools_IndexedMapOfShape *occfmap = (TopTools_IndexedMapOfShape *)FMap;
13277 -
13278 -      // Copy the face map from the geometry to the given variable
13279 -      occfmap->Assign(occgeom->fmap);
13280 -
13281 -      if(occfmap->Extent())
13282 -      {
13283 -         return NG_OK;
13284 -      }
13285 -      else
13286 -      {
13287 -         return NG_ERROR;
13288 -      }
13289 -   }
13290 -
13291 -   // ------------------ End - OCC Geometry / Meshing Utility Functions ----------------
13292 -#endif
13293 -
13294 -
13295 -
13296 -
13297 -   // ------------------ Begin - Meshing Parameters related functions ------------------
13298 -   // Constructor for the local nglib meshing parameters class
13299 -   DLL_HEADER Ng_Meshing_Parameters :: Ng_Meshing_Parameters()
13300 -   {
13301 -      uselocalh = 1;
13302 -
13303 -      maxh = 1000;
13304 -      minh = 0.0;
13305 -
13306 -      fineness = 0.5;
13307 -      grading = 0.3;
13308 -
13309 -      elementsperedge = 2.0;
13310 -      elementspercurve = 2.0;
13311 -
13312 -      closeedgeenable = 0;
13313 -      closeedgefact = 2.0;
13314 -
13315 -         minedgelenenable = 0;
13316 -         minedgelen = 1e-4;
13317 -
13318 -      second_order = 0;
13319 -      quad_dominated = 0;
13320 -
13321 -      meshsize_filename = 0;
13322 -
13323 -      optsurfmeshenable = 1;
13324 -      optvolmeshenable = 1;
13325 -
13326 -      optsteps_2d = 3;
13327 -      optsteps_3d = 3;
13328 -
13329 -      invert_tets = 0;
13330 -      invert_trigs = 0;
13331 -
13332 -      check_overlap = 1;
13333 -      check_overlapping_boundary = 1;
13334 -   }
13335 -
13336 -
13337 -
13338 -
13339 -   // Reset the local meshing parameters to the default values
13340 -   DLL_HEADER void Ng_Meshing_Parameters :: Reset_Parameters()
13341 -   {
13342 -      uselocalh = 1;
13343 -
13344 -      maxh = 1000;
13345 -      minh = 0;
13346 -
13347 -      fineness = 0.5;
13348 -      grading = 0.3;
13349 -
13350 -      elementsperedge = 2.0;
13351 -      elementspercurve = 2.0;
13352 -
13353 -      closeedgeenable = 0;
13354 -      closeedgefact = 2.0;
13355 -
13356 -         minedgelenenable = 0;
13357 -         minedgelen = 1e-4;
13358 -
13359 -      second_order = 0;
13360 -      quad_dominated = 0;
13361 -
13362 -      meshsize_filename = 0;
13363 -
13364 -      optsurfmeshenable = 1;
13365 -      optvolmeshenable = 1;
13366 -
13367 -      optsteps_2d = 3;
13368 -      optsteps_3d = 3;
13369 -
13370 -      invert_tets = 0;
13371 -      invert_trigs = 0;
13372 -
13373 -      check_overlap = 1;
13374 -      check_overlapping_boundary = 1;
13375 -   }
13376 -
13377 -
13378 -
13379 -
13380 -   // 
13381 -   DLL_HEADER void Ng_Meshing_Parameters :: Transfer_Parameters()
13382 -   {
13383 -      mparam.uselocalh = uselocalh;
13384 -      
13385 -      mparam.maxh = maxh;
13386 -      mparam.minh = minh;
13387 -
13388 -      mparam.grading = grading;
13389 -      mparam.curvaturesafety = elementspercurve;
13390 -      mparam.segmentsperedge = elementsperedge;
13391 -
13392 -      mparam.secondorder = second_order;
13393 -      mparam.quad = quad_dominated;
13394 -
13395 -      mparam.meshsizefilename = meshsize_filename;
13396 -
13397 -      mparam.optsteps2d = optsteps_2d;
13398 -      mparam.optsteps3d = optsteps_3d;
13399 -
13400 -      mparam.inverttets = invert_tets;
13401 -      mparam.inverttrigs = invert_trigs;
13402 -
13403 -      mparam.checkoverlap = check_overlap;
13404 -      mparam.checkoverlappingboundary = check_overlapping_boundary;
13405 -   }
13406 -   // ------------------ End - Meshing Parameters related functions --------------------
13407 -
13408 -
13409 -
13410 -
13411 -   // ------------------ Begin - Second Order Mesh generation functions ----------------
13412 -   DLL_HEADER void Ng_Generate_SecondOrder(Ng_Mesh * mesh)
13413 -   {
13414 -      Refinement ref;
13415 -      ref.MakeSecondOrder(*(Mesh*) mesh);
13416 -   }
13417 -
13418 -
13419 -
13420 -
13421 -   DLL_HEADER void Ng_2D_Generate_SecondOrder(Ng_Geometry_2D * geom,
13422 -                                         Ng_Mesh * mesh)
13423 -   {
13424 -      ( (SplineGeometry2d*)geom ) -> GetRefinement().MakeSecondOrder( * (Mesh*) mesh );
13425 -   }
13426 -
13427 -
13428 -
13429 -
13430 -   DLL_HEADER void Ng_STL_Generate_SecondOrder(Ng_STL_Geometry * geom,
13431 -                                          Ng_Mesh * mesh)
13432 -   {
13433 -      ((STLGeometry*)geom)->GetRefinement().MakeSecondOrder(*(Mesh*) mesh);
13434 -   }
13435 -
13436 -
13437 -
13438 -
13439 -   DLL_HEADER void Ng_CSG_Generate_SecondOrder (Ng_CSG_Geometry * geom,
13440 -                                          Ng_Mesh * mesh)
13441 -   {
13442 -      ((CSGeometry*)geom)->GetRefinement().MakeSecondOrder(*(Mesh*) mesh);
13443 -   }
13444 -
13445 -
13446 -
13447 -
13448 -#ifdef OCCGEOMETRY
13449 -   DLL_HEADER void Ng_OCC_Generate_SecondOrder (Ng_OCC_Geometry * geom,
13450 -                  Ng_Mesh * mesh)
13451 -   {
13452 -      ((OCCGeometry*)geom )->GetRefinement().MakeSecondOrder(*(Mesh*) mesh);
13453 -   }
13454 -#endif
13455 -   // ------------------ End - Second Order Mesh generation functions ------------------
13456 -
13457 -
13458 -
13459 -
13460 -   // ------------------ Begin - Uniform Mesh Refinement functions ---------------------
13461 -   DLL_HEADER void Ng_Uniform_Refinement (Ng_Mesh * mesh)
13462 -   {
13463 -      Refinement ref;
13464 -      ref.Refine ( * (Mesh*) mesh );
13465 -   }
13466 -
13467 -
13468 -
13469 -
13470 -   DLL_HEADER void Ng_2D_Uniform_Refinement (Ng_Geometry_2D * geom,
13471 -      Ng_Mesh * mesh)
13472 -   {
13473 -      ( (SplineGeometry2d*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh );
13474 -   }
13475 -
13476 -
13477 -
13478 -
13479 -   DLL_HEADER void Ng_STL_Uniform_Refinement (Ng_STL_Geometry * geom,
13480 -      Ng_Mesh * mesh)
13481 -   {
13482 -      ( (STLGeometry*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh );
13483 -   }
13484 -
13485 -
13486 -
13487 -
13488 -   DLL_HEADER void Ng_CSG_Uniform_Refinement (Ng_CSG_Geometry * geom,
13489 -      Ng_Mesh * mesh)
13490 -   {
13491 -      ( (CSGeometry*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh );
13492 -   }
13493 -
13494 -
13495 -
13496 -
13497 -#ifdef OCCGEOMETRY
13498 -   DLL_HEADER void Ng_OCC_Uniform_Refinement (Ng_OCC_Geometry * geom,
13499 -      Ng_Mesh * mesh)
13500 -   {
13501 -      ( (OCCGeometry*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh );
13502 -   }
13503 -#endif
13504 -   // ------------------ End - Uniform Mesh Refinement functions -----------------------
13505 -} // End of namespace nglib
13506 -
13507 -
13508 -
13509 -
13510 -// compatibility functions:
13511 -namespace netgen 
13512 -{
13513 -   char geomfilename[255];
13514 -
13515 -   DLL_HEADER void MyError (const char * ch)
13516 -   {
13517 -      cerr << ch;
13518 -   }
13519 -
13520 -
13521 -
13522 -
13523 -   //Destination for messages, errors, ...
13524 -   DLL_HEADER void Ng_PrintDest(const char * s)
13525 -   {
13526 -#ifdef PARALLEL
13527 -     int id = 0;
13528 -     MPI_Comm_rank(MPI_COMM_WORLD, &id);
13529 -     if (id != 0) return;
13530 -#endif
13531 -     (*mycout) << s << flush;
13532 -   }
13533 -
13534 -
13535 -
13536 -
13537 -   DLL_HEADER double GetTime ()
13538 -   {
13539 -      return 0;
13540 -   }
13541 -
13542 -
13543 -
13544 -
13545 -   void ResetTime ()
13546 -   {
13547 -      ;
13548 -   }
13549 -
13550 -
13551 -
13552 -
13553 -   void MyBeep (int i)
13554 -   {
13555 -      ;
13556 -   }
13557 -
13558 -
13559 -
13560 -
13561 -   void Render()
13562 -   {
13563 -      ; 
13564 -   }
13565 -} // End of namespace netgen
13566 -
13567 -
13568 -
13569 -
13570 -void Ng_Redraw () { ; }
13571 -void Ng_ClearSolutionData () { ; }
13572 -void Ng_SetSolutionData (Ng_SolutionData * soldata) 
13573 -{ 
13574 -  delete soldata->solclass;
13575 -}
13576 -void Ng_InitSolutionData (Ng_SolutionData * soldata) { ; }
13577 -
13578 -
13579 +/**************************************************************************/
13580 +/* File:   nglib.cpp                                                      */
13581 +/* Author: Joachim Schoeberl                                              */
13582 +/* Date:   7. May. 2000                                                   */
13583 +/**************************************************************************/
13584 +
13585 +/*
13586 +  
13587 +  Interface to the netgen meshing kernel
13588 +  
13589 +*/
13590 +#include <mystdlib.h>
13591 +#include <myadt.hpp>
13592 +
13593 +#include <linalg.hpp>
13594 +#include <csg.hpp>
13595 +#include <stlgeom.hpp>
13596 +#include <geometry2d.hpp>
13597 +#include <meshing.hpp>
13598 +#include <../visualization/soldata.hpp>
13599 +
13600 +#ifdef OCCGEOMETRY
13601 +#include <occgeom.hpp>
13602 +#endif
13603 +
13604 +#include <nginterface.h>
13605 +
13606 +
13607 +namespace netgen {
13608 +   extern void MeshFromSpline2D (SplineGeometry2d & geometry,
13609 +                                 Mesh *& mesh, 
13610 +                                 MeshingParameters & mp);
13611 +}
13612 +
13613 +
13614 +
13615 +#ifdef PARALLEL
13616 +#include <mpi.h>
13617 +
13618 +namespace netgen
13619 +{
13620 +  // int id = 0, ntasks = 1;
13621 +  MPI_Comm mesh_comm;
13622 +}
13623 +#endif
13624 +
13625 +
13626 +namespace netgen
13627 +{
13628 +  int id = 0, ntasks = 1;
13629 +}
13630 +
13631 +
13632 +
13633 +/*
13634 +// should not be needed (occ currently requires it)
13635 +namespace netgen {
13636 +#include "../libsrc/visualization/vispar.hpp"
13637 +  VisualizationParameters vispar;
13638 +  VisualizationParameters :: VisualizationParameters() { ; }
13639 +}
13640 +*/
13641 +
13642 +
13643 +namespace nglib {
13644 +#include "nglib.h"
13645 +}
13646 +
13647 +using namespace netgen;
13648 +using namespace std;
13649 +// constants and types:
13650 +
13651 +namespace nglib
13652 +{
13653 +   // initialize, deconstruct Netgen library:
13654 +   DLL_HEADER void Ng_Init ()
13655 +   {
13656 +      mycout = &std::cout;
13657 +      myerr = &cerr;
13658 +      // netgen::testout->SetOutStream (new ofstream ("test.out"));
13659 +      testout = new ofstream ("test.out");
13660 +   }
13661 +
13662 +
13663 +
13664 +
13665 +   // Clean-up functions before ending usage of nglib
13666 +   DLL_HEADER void Ng_Exit ()
13667 +   {
13668 +       delete testout;
13669 +       testout = 0;
13670 +   }
13671 +
13672 +
13673 +
13674 +
13675 +   // Create a new netgen mesh object
13676 +   DLL_HEADER Ng_Mesh * Ng_NewMesh ()
13677 +   {
13678 +      Mesh * mesh = new Mesh;  
13679 +      mesh->AddFaceDescriptor (FaceDescriptor (1, 1, 0, 1));
13680 +      return (Ng_Mesh*)(void*)mesh;
13681 +   }
13682 +
13683 +
13684 +
13685 +
13686 +   // Delete an existing netgen mesh object
13687 +   DLL_HEADER void Ng_DeleteMesh (Ng_Mesh * mesh)
13688 +   {
13689 +      if(mesh != NULL)
13690 +      {
13691 +         // Delete the Mesh structures
13692 +         ((Mesh*)mesh)->DeleteMesh();
13693 +
13694 +         // Now delete the Mesh class itself
13695 +         delete (Mesh*)mesh;
13696 +
13697 +         // Set the Ng_Mesh pointer to NULL
13698 +         mesh = NULL;
13699 +      }
13700 +   }
13701 +
13702 +
13703 +
13704 +
13705 +   // Save a netgen mesh in the native VOL format 
13706 +   DLL_HEADER void Ng_SaveMesh(Ng_Mesh * mesh, const char* filename)
13707 +   {
13708 +      ((Mesh*)mesh)->Save(filename);
13709 +   }
13710 +
13711 +
13712 +
13713 +
13714 +   // Load a netgen native VOL mesh from a given file
13715 +   DLL_HEADER Ng_Mesh * Ng_LoadMesh(const char* filename)
13716 +   {
13717 +      Mesh * mesh = new Mesh;
13718 +      mesh->Load(filename);
13719 +      return ( (Ng_Mesh*)mesh );
13720 +   }
13721 +
13722 +
13723 +
13724 +
13725 +   // Merge another mesh file into the currently loaded one
13726 +   DLL_HEADER Ng_Result Ng_MergeMesh( Ng_Mesh* mesh, const char* filename)
13727 +   {
13728 +      Ng_Result status = NG_OK;
13729 +
13730 +      ifstream infile(filename);
13731 +      Mesh * m = (Mesh*)mesh;
13732 +
13733 +      if(!infile.good())
13734 +      {
13735 +         status = NG_FILE_NOT_FOUND;
13736 +      }
13737 +
13738 +      if(!m)
13739 +      {
13740 +         status = NG_ERROR;
13741 +      }
13742 +
13743 +      if(status == NG_OK)
13744 +      {
13745 +         const int num_pts = m->GetNP();
13746 +         const int face_offset = m->GetNFD();
13747 +
13748 +         m->Merge(infile, face_offset);
13749 +
13750 +         if(m->GetNP() > num_pts)
13751 +         {
13752 +            status = NG_OK;
13753 +         }
13754 +         else
13755 +         {
13756 +            status = NG_ERROR;
13757 +         }
13758 +      }
13759 +
13760 +      return status;
13761 +   }
13762 +
13763 +
13764 +
13765 +
13766 +   // Merge another mesh file into the currently loaded one
13767 +   DLL_HEADER Ng_Result Ng_MergeMesh( Ng_Mesh* mesh1, Ng_Mesh* mesh2)
13768 +   {
13769 +      return NG_ERROR;
13770 +   }
13771 +
13772 +
13773 +
13774 +
13775 +   // Manually add a point to an existing mesh object
13776 +   DLL_HEADER void Ng_AddPoint (Ng_Mesh * mesh, double * x)
13777 +   {
13778 +      Mesh * m = (Mesh*)mesh;
13779 +      m->AddPoint (Point3d (x[0], x[1], x[2]));
13780 +   }
13781 +
13782 +
13783 +
13784 +
13785 +   // Manually add a surface element of a given type to an existing mesh object
13786 +   DLL_HEADER void Ng_AddSurfaceElement (Ng_Mesh * mesh, Ng_Surface_Element_Type et,
13787 +                                         int * pi)
13788 +   {
13789 +      Mesh * m = (Mesh*)mesh;
13790 +      Element2d el (3);
13791 +      el.SetIndex (1);
13792 +      el.PNum(1) = pi[0];
13793 +      el.PNum(2) = pi[1];
13794 +      el.PNum(3) = pi[2];
13795 +      m->AddSurfaceElement (el);
13796 +   }
13797 +
13798 +
13799 +
13800 +
13801 +   // Manually add a volume element of a given type to an existing mesh object
13802 +   DLL_HEADER void Ng_AddVolumeElement (Ng_Mesh * mesh, Ng_Volume_Element_Type et,
13803 +                                        int * pi)
13804 +   {
13805 +      Mesh * m = (Mesh*)mesh;
13806 +      Element el (4);
13807 +      el.SetIndex (1);
13808 +      el.PNum(1) = pi[0];
13809 +      el.PNum(2) = pi[1];
13810 +      el.PNum(3) = pi[2];
13811 +      el.PNum(4) = pi[3];
13812 +      m->AddVolumeElement (el);
13813 +   }
13814 +
13815 +
13816 +
13817 +
13818 +   // Obtain the number of points in the mesh
13819 +   DLL_HEADER int Ng_GetNP (Ng_Mesh * mesh)
13820 +   {
13821 +      return ((Mesh*)mesh) -> GetNP();
13822 +   }
13823 +
13824 +
13825 +
13826 +
13827 +   // Obtain the number of surface elements in the mesh
13828 +   DLL_HEADER int Ng_GetNSE (Ng_Mesh * mesh)
13829 +   {
13830 +      return ((Mesh*)mesh) -> GetNSE();
13831 +   }
13832 +
13833 +
13834 +
13835 +
13836 +   // Obtain the number of volume elements in the mesh
13837 +   DLL_HEADER int Ng_GetNE (Ng_Mesh * mesh)
13838 +   {
13839 +      return ((Mesh*)mesh) -> GetNE();
13840 +   }
13841 +
13842 +
13843 +
13844 +
13845 +   //  Return point coordinates of a given point index in the mesh
13846 +   DLL_HEADER void Ng_GetPoint (Ng_Mesh * mesh, int num, double * x)
13847 +   {
13848 +      const Point3d & p = ((Mesh*)mesh)->Point(num);
13849 +      x[0] = p.X();
13850 +      x[1] = p.Y();
13851 +      x[2] = p.Z();
13852 +   }
13853 +
13854 +
13855 +
13856 +
13857 +   // Return the surface element at a given index "pi"
13858 +   DLL_HEADER Ng_Surface_Element_Type 
13859 +      Ng_GetSurfaceElement (Ng_Mesh * mesh, int num, int * pi)
13860 +   {
13861 +      const Element2d & el = ((Mesh*)mesh)->SurfaceElement(num);
13862 +      for (int i = 1; i <= el.GetNP(); i++)
13863 +         pi[i-1] = el.PNum(i);
13864 +      Ng_Surface_Element_Type et;
13865 +      switch (el.GetNP())
13866 +      {
13867 +      case 3: et = NG_TRIG; break;
13868 +      case 4: et = NG_QUAD; break;
13869 +      case 6: 
13870 +         switch (el.GetNV())
13871 +         {
13872 +         case 3: et = NG_TRIG6; break;
13873 +         case 4: et = NG_QUAD6; break;
13874 +         default:
13875 +            et = NG_TRIG6; break;
13876 +         }
13877 +         break;
13878 +      case 8: et = NG_QUAD8; break;
13879 +      default:
13880 +         et = NG_TRIG; break; // for the compiler
13881 +      }
13882 +      return et;
13883 +   }
13884 +
13885 +
13886 +
13887 +
13888 +   // Return the volume element at a given index "pi"
13889 +   DLL_HEADER Ng_Volume_Element_Type
13890 +      Ng_GetVolumeElement (Ng_Mesh * mesh, int num, int * pi)
13891 +   {
13892 +      const Element & el = ((Mesh*)mesh)->VolumeElement(num);
13893 +      for (int i = 1; i <= el.GetNP(); i++)
13894 +         pi[i-1] = el.PNum(i);
13895 +      Ng_Volume_Element_Type et;
13896 +      switch (el.GetNP())
13897 +      {
13898 +      case 4: et = NG_TET; break;
13899 +      case 5: et = NG_PYRAMID; break;
13900 +      case 6: et = NG_PRISM; break;
13901 +      case 10: et = NG_TET10; break;
13902 +      default:
13903 +         et = NG_TET; break; // for the compiler
13904 +      }
13905 +      return et;
13906 +   }
13907 +
13908 +
13909 +
13910 +
13911 +   // Set a global limit on the maximum mesh size allowed
13912 +   DLL_HEADER void Ng_RestrictMeshSizeGlobal (Ng_Mesh * mesh, double h)
13913 +   {
13914 +      ((Mesh*)mesh) -> SetGlobalH (h);
13915 +   }
13916 +
13917 +
13918 +
13919 +
13920 +   // Set a local limit on the maximum mesh size allowed around the given point
13921 +   DLL_HEADER void Ng_RestrictMeshSizePoint (Ng_Mesh * mesh, double * p, double h)
13922 +   {
13923 +      ((Mesh*)mesh) -> RestrictLocalH (Point3d (p[0], p[1], p[2]), h);
13924 +   }
13925 +
13926 +
13927 +
13928 +
13929 +   // Set a local limit on the maximum mesh size allowed within a given box region
13930 +   DLL_HEADER void Ng_RestrictMeshSizeBox (Ng_Mesh * mesh, double * pmin, double * pmax, double h)
13931 +   {
13932 +      for (double x = pmin[0]; x < pmax[0]; x += h)
13933 +         for (double y = pmin[1]; y < pmax[1]; y += h)
13934 +            for (double z = pmin[2]; z < pmax[2]; z += h)
13935 +               ((Mesh*)mesh) -> RestrictLocalH (Point3d (x, y, z), h);
13936 +   }
13937 +
13938 +
13939 +
13940 +
13941 +   // Generates volume mesh from an existing surface mesh
13942 +   DLL_HEADER Ng_Result Ng_GenerateVolumeMesh (Ng_Mesh * mesh, Ng_Meshing_Parameters * mp)
13943 +   {
13944 +      Mesh * m = (Mesh*)mesh;
13945 +
13946 +      // Philippose - 30/08/2009
13947 +      // Do not locally re-define "mparam" here... "mparam" is a global 
13948 +      // object 
13949 +      //MeshingParameters mparam;
13950 +      mp->Transfer_Parameters();
13951 +
13952 +      m->CalcLocalH(mparam.grading);
13953 +
13954 +      MeshVolume (mparam, *m);
13955 +      RemoveIllegalElements (*m);
13956 +      OptimizeVolume (mparam, *m);
13957 +
13958 +      return NG_OK;
13959 +   }
13960 +
13961 +
13962 +
13963 +
13964 +   /* ------------------ 2D Meshing Functions ------------------------- */
13965 +   DLL_HEADER void Ng_AddPoint_2D (Ng_Mesh * mesh, double * x)
13966 +   {
13967 +      Mesh * m = (Mesh*)mesh;
13968 +
13969 +      m->AddPoint (Point3d (x[0], x[1], 0));
13970 +   }
13971 +
13972 +
13973 +
13974 +
13975 +   DLL_HEADER void Ng_AddBoundarySeg_2D (Ng_Mesh * mesh, int pi1, int pi2)
13976 +   {
13977 +      Mesh * m = (Mesh*)mesh;
13978 +
13979 +      Segment seg;
13980 +      seg[0] = pi1;
13981 +      seg[1] = pi2;
13982 +      m->AddSegment (seg);
13983 +   }
13984 +
13985 +
13986 +
13987 +
13988 +   DLL_HEADER int Ng_GetNP_2D (Ng_Mesh * mesh)
13989 +   {
13990 +      Mesh * m = (Mesh*)mesh;
13991 +      return m->GetNP();
13992 +   }
13993 +
13994 +
13995 +
13996 +
13997 +   DLL_HEADER int Ng_GetNE_2D (Ng_Mesh * mesh)
13998 +   {
13999 +      Mesh * m = (Mesh*)mesh;
14000 +      return m->GetNSE();
14001 +   }
14002 +
14003 +
14004 +
14005 +
14006 +   DLL_HEADER int Ng_GetNSeg_2D (Ng_Mesh * mesh)
14007 +   {
14008 +      Mesh * m = (Mesh*)mesh;
14009 +      return m->GetNSeg();
14010 +   }
14011 +
14012 +
14013 +
14014 +
14015 +   DLL_HEADER void Ng_GetPoint_2D (Ng_Mesh * mesh, int num, double * x)
14016 +   {
14017 +      Mesh * m = (Mesh*)mesh;
14018 +
14019 +      Point<3> & p = m->Point(num);
14020 +      x[0] = p(0);
14021 +      x[1] = p(1);
14022 +   }
14023 +
14024 +
14025 +
14026 +
14027 +   DLL_HEADER Ng_Surface_Element_Type
14028 +      Ng_GetElement_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum)
14029 +   {
14030 +      const Element2d & el = ((Mesh*)mesh)->SurfaceElement(num);
14031 +      for (int i = 1; i <= el.GetNP(); i++)
14032 +         pi[i-1] = el.PNum(i);
14033 +
14034 +      Ng_Surface_Element_Type et;
14035 +      switch (el.GetNP())
14036 +      {
14037 +      case 3: et = NG_TRIG; break;
14038 +      case 4: et = NG_QUAD; break;
14039 +      case 6: 
14040 +         switch (el.GetNV())
14041 +         {
14042 +         case 3: et = NG_TRIG6; break;
14043 +         case 4: et = NG_QUAD6; break;
14044 +         default:
14045 +            et = NG_TRIG6; break;
14046 +         }
14047 +         break;
14048 +      case 8: et = NG_QUAD8; break;
14049 +      default:
14050 +         et = NG_TRIG; break; // for the compiler
14051 +      }
14052 +
14053 +      if (matnum)
14054 +         *matnum = el.GetIndex();
14055 +
14056 +      return et;
14057 +   }
14058 +
14059 +
14060 +
14061 +
14062 +   DLL_HEADER void Ng_GetSegment_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum)
14063 +   {
14064 +      const Segment & seg = ((Mesh*)mesh)->LineSegment(num);
14065 +      pi[0] = seg[0];
14066 +      pi[1] = seg[1];
14067 +
14068 +      if (matnum)
14069 +         *matnum = seg.edgenr;
14070 +   }
14071 +
14072 +
14073 +
14074 +
14075 +   DLL_HEADER Ng_Geometry_2D * Ng_LoadGeometry_2D (const char * filename)
14076 +   {
14077 +      SplineGeometry2d * geom = new SplineGeometry2d();
14078 +      geom -> Load (filename);
14079 +      return (Ng_Geometry_2D *)geom;
14080 +   }
14081 +
14082 +
14083 +
14084 +
14085 +   DLL_HEADER Ng_Result Ng_GenerateMesh_2D (Ng_Geometry_2D * geom,
14086 +                                            Ng_Mesh ** mesh,
14087 +                                            Ng_Meshing_Parameters * mp)
14088 +   {
14089 +      // use global variable mparam
14090 +      //  MeshingParameters mparam;  
14091 +      mp->Transfer_Parameters();
14092 +
14093 +      Mesh * m;
14094 +      MeshFromSpline2D (*(SplineGeometry2d*)geom, m, mparam);
14095 +
14096 +      std::cout << m->GetNSE() << " elements, " << m->GetNP() << " points" << std::endl;
14097 +
14098 +      *mesh = (Ng_Mesh*)m;
14099 +      return NG_OK;
14100 +   }
14101 +
14102 +
14103 +
14104 +
14105 +   DLL_HEADER void Ng_HP_Refinement (Ng_Geometry_2D * geom,
14106 +      Ng_Mesh * mesh,
14107 +      int levels)
14108 +   {
14109 +      Refinement2d ref(*(SplineGeometry2d*)geom);
14110 +      HPRefinement (*(Mesh*)mesh, &ref, levels);
14111 +   }
14112 +
14113 +
14114 +
14115 +
14116 +   DLL_HEADER void Ng_HP_Refinement (Ng_Geometry_2D * geom,
14117 +      Ng_Mesh * mesh,
14118 +      int levels, double parameter)
14119 +   {
14120 +      Refinement2d ref(*(SplineGeometry2d*)geom);
14121 +      HPRefinement (*(Mesh*)mesh, &ref, levels, parameter);
14122 +   }
14123 +
14124 +
14125 +
14126 +
14127 +   Array<STLReadTriangle> readtrias; //only before initstlgeometry
14128 +   Array<Point<3> > readedges; //only before init stlgeometry
14129 +
14130 +   // loads geometry from STL file
14131 +   DLL_HEADER Ng_STL_Geometry * Ng_STL_LoadGeometry (const char * filename, int binary)
14132 +   {
14133 +      int i;
14134 +      STLGeometry geom;
14135 +      STLGeometry* geo;
14136 +      ifstream ist(filename);
14137 +
14138 +      if (binary)
14139 +      {
14140 +         geo = geom.LoadBinary(ist);
14141 +      }
14142 +      else
14143 +      {
14144 +         geo = geom.Load(ist);
14145 +      }
14146 +
14147 +      readtrias.SetSize(0);
14148 +      readedges.SetSize(0);
14149 +
14150 +      Point3d p;
14151 +      Vec3d normal;
14152 +      double p1[3];
14153 +      double p2[3];
14154 +      double p3[3];
14155 +      double n[3];
14156 +
14157 +      Ng_STL_Geometry * geo2 = Ng_STL_NewGeometry();
14158 +
14159 +      for (i = 1; i <= geo->GetNT(); i++)
14160 +      {
14161 +         const STLTriangle& t = geo->GetTriangle(i);
14162 +         p = geo->GetPoint(t.PNum(1));
14163 +         p1[0] = p.X(); p1[1] = p.Y(); p1[2] = p.Z(); 
14164 +         p = geo->GetPoint(t.PNum(2));
14165 +         p2[0] = p.X(); p2[1] = p.Y(); p2[2] = p.Z(); 
14166 +         p = geo->GetPoint(t.PNum(3));
14167 +         p3[0] = p.X(); p3[1] = p.Y(); p3[2] = p.Z();
14168 +         normal = t.Normal();
14169 +         n[0] = normal.X(); n[1] = normal.Y(); n[2] = normal.Z();
14170 +
14171 +         Ng_STL_AddTriangle(geo2, p1, p2, p3, n);
14172 +      }
14173 +
14174 +      return geo2;
14175 +   }
14176 +
14177 +
14178 +
14179 +
14180 +   // generate new STL Geometry
14181 +   DLL_HEADER Ng_STL_Geometry * Ng_STL_NewGeometry ()
14182 +   {
14183 +      return (Ng_STL_Geometry*)(void*)new STLGeometry;
14184 +   } 
14185 +
14186 +
14187 +
14188 +
14189 +   // after adding triangles (and edges) initialize
14190 +   DLL_HEADER Ng_Result Ng_STL_InitSTLGeometry (Ng_STL_Geometry * geom)
14191 +   {
14192 +      STLGeometry* geo = (STLGeometry*)geom;
14193 +      geo->InitSTLGeometry(readtrias);
14194 +      readtrias.SetSize(0);
14195 +
14196 +      if (readedges.Size() != 0)
14197 +      {
14198 +         /*
14199 +         for (int i = 1; i <= readedges.Size(); i+=2)
14200 +         {
14201 +         cout << "e(" << readedges.Get(i) << "," << readedges.Get(i+1) << ")" << endl;
14202 +         }
14203 +         */
14204 +         geo->AddEdges(readedges);
14205 +      }
14206 +
14207 +      if (geo->GetStatus() == STLTopology::STL_GOOD || geo->GetStatus() == STLTopology::STL_WARNING) return NG_OK;
14208 +      return NG_SURFACE_INPUT_ERROR;
14209 +   }
14210 +
14211 +
14212 +
14213 +
14214 +   // automatically generates edges:
14215 +   DLL_HEADER Ng_Result Ng_STL_MakeEdges (Ng_STL_Geometry * geom,
14216 +                                          Ng_Mesh* mesh,
14217 +                                          Ng_Meshing_Parameters * mp)
14218 +   {
14219 +      STLGeometry* stlgeometry = (STLGeometry*)geom;
14220 +      Mesh* me = (Mesh*)mesh;
14221 +
14222 +      // Philippose - 27/07/2009
14223 +      // Do not locally re-define "mparam" here... "mparam" is a global 
14224 +      // object 
14225 +      //MeshingParameters mparam;
14226 +      mp->Transfer_Parameters();
14227 +
14228 +      me -> SetGlobalH (mparam.maxh);
14229 +      me -> SetLocalH (stlgeometry->GetBoundingBox().PMin() - Vec3d(10, 10, 10),
14230 +                       stlgeometry->GetBoundingBox().PMax() + Vec3d(10, 10, 10),
14231 +                       0.3);
14232 +
14233 +      me -> LoadLocalMeshSize (mp->meshsize_filename);
14234 +      /*
14235 +      if (mp->meshsize_filename)
14236 +      {
14237 +      ifstream infile (mp->meshsize_filename);
14238 +      if (!infile.good()) return NG_FILE_NOT_FOUND;
14239 +      me -> LoadLocalMeshSize (infile);
14240 +      }
14241 +      */
14242 +
14243 +      STLMeshing (*stlgeometry, *me);
14244 +
14245 +      stlgeometry->edgesfound = 1;
14246 +      stlgeometry->surfacemeshed = 0;
14247 +      stlgeometry->surfaceoptimized = 0;
14248 +      stlgeometry->volumemeshed = 0;
14249 +
14250 +      return NG_OK;
14251 +   }
14252 +
14253 +
14254 +
14255 +
14256 +   // generates mesh, empty mesh be already created.
14257 +   DLL_HEADER Ng_Result Ng_STL_GenerateSurfaceMesh (Ng_STL_Geometry * geom,
14258 +                                                    Ng_Mesh* mesh,
14259 +                                                    Ng_Meshing_Parameters * mp)
14260 +   {
14261 +      STLGeometry* stlgeometry = (STLGeometry*)geom;
14262 +      Mesh* me = (Mesh*)mesh;
14263 +
14264 +      // Philippose - 27/07/2009
14265 +      // Do not locally re-define "mparam" here... "mparam" is a global 
14266 +      // object
14267 +      //MeshingParameters mparam;
14268 +      mp->Transfer_Parameters();
14269 +
14270 +
14271 +      /*
14272 +      me -> SetGlobalH (mparam.maxh);
14273 +      me -> SetLocalH (stlgeometry->GetBoundingBox().PMin() - Vec3d(10, 10, 10),
14274 +      stlgeometry->GetBoundingBox().PMax() + Vec3d(10, 10, 10),
14275 +      0.3);
14276 +      */
14277 +      /*
14278 +      STLMeshing (*stlgeometry, *me);
14279 +
14280 +      stlgeometry->edgesfound = 1;
14281 +      stlgeometry->surfacemeshed = 0;
14282 +      stlgeometry->surfaceoptimized = 0;
14283 +      stlgeometry->volumemeshed = 0;
14284 +      */  
14285 +      int retval = STLSurfaceMeshing (*stlgeometry, *me);
14286 +      if (retval == MESHING3_OK)
14287 +      {
14288 +         (*mycout) << "Success !!!!" << std::endl;
14289 +         stlgeometry->surfacemeshed = 1;
14290 +         stlgeometry->surfaceoptimized = 0;
14291 +         stlgeometry->volumemeshed = 0;
14292 +      } 
14293 +      else if (retval == MESHING3_OUTERSTEPSEXCEEDED)
14294 +      {
14295 +         (*mycout) << "ERROR: Give up because of too many trials. Meshing aborted!" << std::endl;
14296 +      }
14297 +      else if (retval == MESHING3_TERMINATE)
14298 +      {
14299 +         (*mycout) << "Meshing Stopped!" << std::endl;
14300 +      }
14301 +      else
14302 +      {
14303 +         (*mycout) << "ERROR: Surface meshing not successful. Meshing aborted!" << std::endl;
14304 +      }
14305 +
14306 +
14307 +      STLSurfaceOptimization (*stlgeometry, *me, mparam);
14308 +
14309 +      return NG_OK;
14310 +   }
14311 +
14312 +
14313 +
14314 +
14315 +   // fills STL Geometry
14316 +   // positive orientation
14317 +   // normal vector may be null-pointer
14318 +   DLL_HEADER void Ng_STL_AddTriangle (Ng_STL_Geometry * geom, 
14319 +                                       double * p1, double * p2, double * p3, 
14320 +                                       double * nv)
14321 +   {
14322 +      Point<3> apts[3];
14323 +      apts[0] = Point<3>(p1[0],p1[1],p1[2]);
14324 +      apts[1] = Point<3>(p2[0],p2[1],p2[2]);
14325 +      apts[2] = Point<3>(p3[0],p3[1],p3[2]);
14326 +
14327 +      Vec<3> n;
14328 +      if (!nv)
14329 +         n = Cross (apts[0]-apts[1], apts[0]-apts[2]);
14330 +      else
14331 +         n = Vec<3>(nv[0],nv[1],nv[2]);
14332 +
14333 +      readtrias.Append(STLReadTriangle(apts,n));
14334 +   }
14335 +
14336 +   // add (optional) edges:
14337 +   DLL_HEADER void Ng_STL_AddEdge (Ng_STL_Geometry * geom, 
14338 +      double * p1, double * p2)
14339 +   {
14340 +      readedges.Append(Point3d(p1[0],p1[1],p1[2]));
14341 +      readedges.Append(Point3d(p2[0],p2[1],p2[2]));
14342 +   }
14343 +
14344 +
14345 +
14346 +
14347 +#ifdef OCCGEOMETRY
14348 +   // --------------------- OCC Geometry / Meshing Utility Functions -------------------
14349 +   // Create new OCC Geometry Object
14350 +   DLL_HEADER Ng_OCC_Geometry * Ng_OCC_NewGeometry ()
14351 +   {
14352 +      return (Ng_OCC_Geometry*)(void*)new OCCGeometry;
14353 +   } 
14354 +
14355 +
14356 +
14357 +
14358 +   // Delete the OCC Geometry Object
14359 +   DLL_HEADER Ng_Result Ng_OCC_DeleteGeometry(Ng_OCC_Geometry * geom)
14360 +   {
14361 +      if (geom != NULL)
14362 +      {
14363 +         delete (OCCGeometry*)geom;
14364 +         geom = NULL;
14365 +         return NG_OK;
14366 +      }
14367 +      
14368 +      return NG_ERROR;
14369 +   }
14370 +
14371 +
14372 +
14373 +   
14374 +   // Loads geometry from STEP File
14375 +   DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_STEP (const char * filename)
14376 +   {
14377 +      // Call the STEP File Load function. Note.. the geometry class 
14378 +      // is created and instantiated within the load function
14379 +      OCCGeometry * occgeo = LoadOCC_STEP(filename);
14380 +
14381 +      return ((Ng_OCC_Geometry *)occgeo);
14382 +   }
14383 +
14384 +
14385 +
14386 +   
14387 +   // Loads geometry from IGES File
14388 +   DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_IGES (const char * filename)
14389 +   {
14390 +      // Call the IGES File Load function. Note.. the geometry class 
14391 +      // is created and instantiated within the load function
14392 +      OCCGeometry * occgeo = LoadOCC_IGES(filename);
14393 +
14394 +      return ((Ng_OCC_Geometry *)occgeo);
14395 +   }
14396 +
14397 +
14398 +
14399 +   
14400 +   // Loads geometry from BREP File
14401 +   DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_BREP (const char * filename)
14402 +   {
14403 +      // Call the BREP File Load function. Note.. the geometry class 
14404 +      // is created and instantiated within the load function
14405 +      OCCGeometry * occgeo = LoadOCC_BREP(filename);
14406 +
14407 +      return ((Ng_OCC_Geometry *)occgeo);
14408 +   }
14409 +
14410 +
14411 +
14412 +
14413 +   // Locally limit the size of the mesh to be generated at various points 
14414 +   // based on the topology of the geometry
14415 +   DLL_HEADER Ng_Result Ng_OCC_SetLocalMeshSize (Ng_OCC_Geometry * geom,
14416 +                                                 Ng_Mesh * mesh,
14417 +                                                 Ng_Meshing_Parameters * mp)
14418 +   {
14419 +      OCCGeometry * occgeom = (OCCGeometry*)geom;
14420 +      Mesh * me = (Mesh*)mesh;
14421 +
14422 +      me->geomtype = Mesh::GEOM_OCC;
14423 +
14424 +      mp->Transfer_Parameters();
14425 +      
14426 +      occparam.resthcloseedgeenable = mp->closeedgeenable;
14427 +      occparam.resthcloseedgefac = mp->closeedgefact;
14428 +
14429 +      // Delete the mesh structures in order to start with a clean 
14430 +      // slate
14431 +      me->DeleteMesh();
14432 +
14433 +      OCCSetLocalMeshSize(*occgeom, *me);
14434 +
14435 +      return(NG_OK);
14436 +   }
14437 +
14438 +
14439 +
14440 +   
14441 +   // Mesh the edges and add Face descriptors to prepare for surface meshing
14442 +   DLL_HEADER Ng_Result Ng_OCC_GenerateEdgeMesh (Ng_OCC_Geometry * geom,
14443 +                                                 Ng_Mesh * mesh,
14444 +                                                 Ng_Meshing_Parameters * mp)
14445 +   {
14446 +      OCCGeometry * occgeom = (OCCGeometry*)geom;
14447 +      Mesh * me = (Mesh*)mesh;
14448 +
14449 +      mp->Transfer_Parameters();
14450 +
14451 +      OCCFindEdges(*occgeom, *me);
14452 +
14453 +      if((me->GetNP()) && (me->GetNFD()))
14454 +      {
14455 +         return NG_OK;
14456 +      }
14457 +      else
14458 +      {
14459 +         return NG_ERROR;
14460 +      }
14461 +   }
14462 +
14463 +
14464 +
14465 +   
14466 +   // Mesh the edges and add Face descriptors to prepare for surface meshing
14467 +   DLL_HEADER Ng_Result Ng_OCC_GenerateSurfaceMesh (Ng_OCC_Geometry * geom,
14468 +                                                    Ng_Mesh * mesh,
14469 +                                                    Ng_Meshing_Parameters * mp)
14470 +   {
14471 +      int numpoints = 0;
14472 +
14473 +      OCCGeometry * occgeom = (OCCGeometry*)geom;
14474 +      Mesh * me = (Mesh*)mesh;
14475 +
14476 +      // Set the internal meshing parameters structure from the nglib meshing 
14477 +      // parameters structure
14478 +      mp->Transfer_Parameters();
14479 +
14480 +
14481 +      // Only go into surface meshing if the face descriptors have already been added
14482 +      if(!me->GetNFD())
14483 +         return NG_ERROR;
14484 +
14485 +      numpoints = me->GetNP();
14486 +
14487 +      // Initially set up only for surface meshing without any optimisation
14488 +      int perfstepsend = MESHCONST_MESHSURFACE;
14489 +
14490 +      // Check and if required, enable surface mesh optimisation step
14491 +      if(mp->optsurfmeshenable)
14492 +      {
14493 +         perfstepsend = MESHCONST_OPTSURFACE;
14494 +      }
14495 +
14496 +      OCCMeshSurface(*occgeom, *me, perfstepsend);
14497 +
14498 +      me->CalcSurfacesOfNode();
14499 +      
14500 +      if(me->GetNP() <= numpoints)
14501 +         return NG_ERROR;
14502 +
14503 +      if(me->GetNSE() <= 0)
14504 +         return NG_ERROR;
14505 +
14506 +      return NG_OK;
14507 +   }
14508 +
14509 +
14510 +
14511 +
14512 +   // Extract the face map from the OCC geometry
14513 +   // The face map basically gives an index to each face in the geometry, 
14514 +   // which can be used to access a specific face
14515 +   DLL_HEADER Ng_Result Ng_OCC_GetFMap(Ng_OCC_Geometry * geom, 
14516 +                                       Ng_OCC_TopTools_IndexedMapOfShape * FMap)
14517 +   {
14518 +      OCCGeometry* occgeom = (OCCGeometry*)geom;
14519 +      TopTools_IndexedMapOfShape *occfmap = (TopTools_IndexedMapOfShape *)FMap;
14520 +
14521 +      // Copy the face map from the geometry to the given variable
14522 +      occfmap->Assign(occgeom->fmap);
14523 +
14524 +      if(occfmap->Extent())
14525 +      {
14526 +         return NG_OK;
14527 +      }
14528 +      else
14529 +      {
14530 +         return NG_ERROR;
14531 +      }
14532 +   }
14533 +
14534 +   // ------------------ End - OCC Geometry / Meshing Utility Functions ----------------
14535 +#endif
14536 +
14537 +
14538 +
14539 +
14540 +   // ------------------ Begin - Meshing Parameters related functions ------------------
14541 +   // Constructor for the local nglib meshing parameters class
14542 +   DLL_HEADER Ng_Meshing_Parameters :: Ng_Meshing_Parameters()
14543 +   {
14544 +      uselocalh = 1;
14545 +
14546 +      maxh = 1000;
14547 +      minh = 0.0;
14548 +
14549 +      fineness = 0.5;
14550 +      grading = 0.3;
14551 +
14552 +      elementsperedge = 2.0;
14553 +      elementspercurve = 2.0;
14554 +
14555 +      closeedgeenable = 0;
14556 +      closeedgefact = 2.0;
14557 +
14558 +         minedgelenenable = 0;
14559 +         minedgelen = 1e-4;
14560 +
14561 +      second_order = 0;
14562 +      quad_dominated = 0;
14563 +
14564 +      meshsize_filename = 0;
14565 +
14566 +      optsurfmeshenable = 1;
14567 +      optvolmeshenable = 1;
14568 +
14569 +      optsteps_2d = 3;
14570 +      optsteps_3d = 3;
14571 +
14572 +      invert_tets = 0;
14573 +      invert_trigs = 0;
14574 +
14575 +      check_overlap = 1;
14576 +      check_overlapping_boundary = 1;
14577 +   }
14578 +
14579 +
14580 +
14581 +
14582 +   // Reset the local meshing parameters to the default values
14583 +   DLL_HEADER void Ng_Meshing_Parameters :: Reset_Parameters()
14584 +   {
14585 +      uselocalh = 1;
14586 +
14587 +      maxh = 1000;
14588 +      minh = 0;
14589 +
14590 +      fineness = 0.5;
14591 +      grading = 0.3;
14592 +
14593 +      elementsperedge = 2.0;
14594 +      elementspercurve = 2.0;
14595 +
14596 +      closeedgeenable = 0;
14597 +      closeedgefact = 2.0;
14598 +
14599 +         minedgelenenable = 0;
14600 +         minedgelen = 1e-4;
14601 +
14602 +      second_order = 0;
14603 +      quad_dominated = 0;
14604 +
14605 +      meshsize_filename = 0;
14606 +
14607 +      optsurfmeshenable = 1;
14608 +      optvolmeshenable = 1;
14609 +
14610 +      optsteps_2d = 3;
14611 +      optsteps_3d = 3;
14612 +
14613 +      invert_tets = 0;
14614 +      invert_trigs = 0;
14615 +
14616 +      check_overlap = 1;
14617 +      check_overlapping_boundary = 1;
14618 +   }
14619 +
14620 +
14621 +
14622 +
14623 +   // 
14624 +   DLL_HEADER void Ng_Meshing_Parameters :: Transfer_Parameters()
14625 +   {
14626 +      mparam.uselocalh = uselocalh;
14627 +      
14628 +      mparam.maxh = maxh;
14629 +      mparam.minh = minh;
14630 +
14631 +      mparam.grading = grading;
14632 +      mparam.curvaturesafety = elementspercurve;
14633 +      mparam.segmentsperedge = elementsperedge;
14634 +
14635 +      mparam.secondorder = second_order;
14636 +      mparam.quad = quad_dominated;
14637 +
14638 +      mparam.meshsizefilename = meshsize_filename;
14639 +
14640 +      mparam.optsteps2d = optsteps_2d;
14641 +      mparam.optsteps3d = optsteps_3d;
14642 +
14643 +      mparam.inverttets = invert_tets;
14644 +      mparam.inverttrigs = invert_trigs;
14645 +
14646 +      mparam.checkoverlap = check_overlap;
14647 +      mparam.checkoverlappingboundary = check_overlapping_boundary;
14648 +   }
14649 +   // ------------------ End - Meshing Parameters related functions --------------------
14650 +
14651 +
14652 +
14653 +
14654 +   // ------------------ Begin - Second Order Mesh generation functions ----------------
14655 +   DLL_HEADER void Ng_Generate_SecondOrder(Ng_Mesh * mesh)
14656 +   {
14657 +      Refinement ref;
14658 +      ref.MakeSecondOrder(*(Mesh*) mesh);
14659 +   }
14660 +
14661 +
14662 +
14663 +
14664 +   DLL_HEADER void Ng_2D_Generate_SecondOrder(Ng_Geometry_2D * geom,
14665 +                                         Ng_Mesh * mesh)
14666 +   {
14667 +      ( (SplineGeometry2d*)geom ) -> GetRefinement().MakeSecondOrder( * (Mesh*) mesh );
14668 +   }
14669 +
14670 +
14671 +
14672 +
14673 +   DLL_HEADER void Ng_STL_Generate_SecondOrder(Ng_STL_Geometry * geom,
14674 +                                          Ng_Mesh * mesh)
14675 +   {
14676 +      ((STLGeometry*)geom)->GetRefinement().MakeSecondOrder(*(Mesh*) mesh);
14677 +   }
14678 +
14679 +
14680 +
14681 +
14682 +   DLL_HEADER void Ng_CSG_Generate_SecondOrder (Ng_CSG_Geometry * geom,
14683 +                                          Ng_Mesh * mesh)
14684 +   {
14685 +      ((CSGeometry*)geom)->GetRefinement().MakeSecondOrder(*(Mesh*) mesh);
14686 +   }
14687 +
14688 +
14689 +
14690 +
14691 +#ifdef OCCGEOMETRY
14692 +   DLL_HEADER void Ng_OCC_Generate_SecondOrder (Ng_OCC_Geometry * geom,
14693 +                  Ng_Mesh * mesh)
14694 +   {
14695 +      ((OCCGeometry*)geom )->GetRefinement().MakeSecondOrder(*(Mesh*) mesh);
14696 +   }
14697 +#endif
14698 +   // ------------------ End - Second Order Mesh generation functions ------------------
14699 +
14700 +
14701 +
14702 +
14703 +   // ------------------ Begin - Uniform Mesh Refinement functions ---------------------
14704 +   DLL_HEADER void Ng_Uniform_Refinement (Ng_Mesh * mesh)
14705 +   {
14706 +      Refinement ref;
14707 +      ref.Refine ( * (Mesh*) mesh );
14708 +   }
14709 +
14710 +
14711 +
14712 +
14713 +   DLL_HEADER void Ng_2D_Uniform_Refinement (Ng_Geometry_2D * geom,
14714 +      Ng_Mesh * mesh)
14715 +   {
14716 +      ( (SplineGeometry2d*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh );
14717 +   }
14718 +
14719 +
14720 +
14721 +
14722 +   DLL_HEADER void Ng_STL_Uniform_Refinement (Ng_STL_Geometry * geom,
14723 +      Ng_Mesh * mesh)
14724 +   {
14725 +      ( (STLGeometry*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh );
14726 +   }
14727 +
14728 +
14729 +
14730 +
14731 +   DLL_HEADER void Ng_CSG_Uniform_Refinement (Ng_CSG_Geometry * geom,
14732 +      Ng_Mesh * mesh)
14733 +   {
14734 +      ( (CSGeometry*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh );
14735 +   }
14736 +
14737 +
14738 +
14739 +
14740 +#ifdef OCCGEOMETRY
14741 +   DLL_HEADER void Ng_OCC_Uniform_Refinement (Ng_OCC_Geometry * geom,
14742 +      Ng_Mesh * mesh)
14743 +   {
14744 +      ( (OCCGeometry*)geom ) -> GetRefinement().Refine ( * (Mesh*) mesh );
14745 +   }
14746 +#endif
14747 +   // ------------------ End - Uniform Mesh Refinement functions -----------------------
14748 +} // End of namespace nglib
14749 +
14750 +
14751 +
14752 +
14753 +// compatibility functions:
14754 +namespace netgen 
14755 +{
14756 +   char geomfilename[255];
14757 +
14758 +   DLL_HEADER void MyError (const char * ch)
14759 +   {
14760 +      cerr << ch;
14761 +   }
14762 +
14763 +
14764 +
14765 +
14766 +   //Destination for messages, errors, ...
14767 +   DLL_HEADER void Ng_PrintDest(const char * s)
14768 +   {
14769 +#ifdef PARALLEL
14770 +     int id = 0;
14771 +     MPI_Comm_rank(MPI_COMM_WORLD, &id);
14772 +     if (id != 0) return;
14773 +#endif
14774 +     (*mycout) << s << std::flush;
14775 +   }
14776 +
14777 +
14778 +
14779 +
14780 +   DLL_HEADER double GetTime ()
14781 +   {
14782 +      return 0;
14783 +   }
14784 +
14785 +
14786 +
14787 +
14788 +   void ResetTime ()
14789 +   {
14790 +      ;
14791 +   }
14792 +
14793 +
14794 +
14795 +
14796 +   void MyBeep (int i)
14797 +   {
14798 +      ;
14799 +   }
14800 +
14801 +
14802 +
14803 +
14804 +   void Render()
14805 +   {
14806 +      ; 
14807 +   }
14808 +} // End of namespace netgen
14809 +
14810 +
14811 +
14812 +
14813 +void Ng_Redraw () { ; }
14814 +void Ng_ClearSolutionData () { ; }
14815 +void Ng_SetSolutionData (Ng_SolutionData * soldata) 
14816 +{ 
14817 +  delete soldata->solclass;
14818 +}
14819 +void Ng_InitSolutionData (Ng_SolutionData * soldata) { ; }
14820 +
14821 +
14822 --- netgen_ref/nglib/nglib.h
14823 +++ netgen/nglib/nglib.h
14824 @@ -1,747 +1,747 @@
14825 -#ifndef NGLIB
14826 -#define NGLIB
14827 -
14828 -/**************************************************************************/
14829 -/* File:   nglib.h                                                        */
14830 -/* Author: Joachim Schoeberl                                              */
14831 -/* Date:   7. May. 2000                                                   */
14832 -/**************************************************************************/
14833 -
14834 -/*!
14835 -   \file nglib.h
14836 -   \brief Library interface to the netgen meshing kernel
14837 -   \author Joachim Schoeberl
14838 -   \date 7. May 2000
14839 -
14840 -   This header file provides access to the core functionality of the Netgen 
14841 -   Mesher via a library interface, without an interactive User Interface.
14842 -
14843 -   The intention of providing these set of functions is to allow system 
14844 -   developers to integrate Netgen into top-level code, to act as the low 
14845 -   level mesh generation / optimisation kernel.  
14846 -*/
14847 -
14848 -// Philippose - 14.02.2009
14849 -// Modifications for creating a DLL in Windows
14850 -#ifdef WIN32
14851 -   #ifdef NGLIB_EXPORTS || nglib_EXPORTS
14852 -      #define DLL_HEADER   __declspec(dllexport)
14853 -   #else
14854 -      #define DLL_HEADER   __declspec(dllimport)
14855 -   #endif
14856 -#else
14857 -   #define DLL_HEADER 
14858 -#endif
14859 -
14860 -
14861 -
14862 -// ** Constants used within Netgen *********************
14863 -/// Maximum allowed number of nodes per volume element
14864 -#define NG_VOLUME_ELEMENT_MAXPOINTS 10
14865 -
14866 -/// Maximum allowed number of nodes per surface element
14867 -#define NG_SURFACE_ELEMENT_MAXPOINTS 8
14868 -
14869 -
14870 -
14871 -// *** Data-types for accessing Netgen functionality ***
14872 -/// Data type for NETGEN mesh
14873 -typedef void * Ng_Mesh;
14874 -
14875 -/// Data type for NETGEN CSG geometry
14876 -typedef void * Ng_CSG_Geometry;
14877 -
14878 -/// Data type for NETGEN 2D geometry
14879 -typedef void * Ng_Geometry_2D;
14880 -
14881 -/// Data type for NETGEN STL geometry
14882 -typedef void * Ng_STL_Geometry;
14883 -
14884 -#ifdef OCCGEOMETRY
14885 -/// Data type for NETGEN OpenCascade geometry
14886 -typedef void * Ng_OCC_Geometry;
14887 -typedef void * Ng_OCC_TopTools_IndexedMapOfShape;
14888 -#endif
14889 -
14890 -
14891 -// *** Special Enum types used within Netgen ***********
14892 -/// Currently implemented surface element types
14893 -enum Ng_Surface_Element_Type 
14894 -   { NG_TRIG = 1, NG_QUAD = 2, NG_TRIG6 = 3, NG_QUAD6 = 4, NG_QUAD8 = 5 };
14895 -
14896 -/// Currently implemented volume element types
14897 -enum Ng_Volume_Element_Type 
14898 -   { NG_TET = 1, NG_PYRAMID = 2, NG_PRISM = 3, NG_TET10 = 4 };
14899 -
14900 -/// Values returned by Netgen functions
14901 -enum Ng_Result 
14902 -   { 
14903 -     NG_ERROR               = -1,   
14904 -     NG_OK                  = 0, 
14905 -     NG_SURFACE_INPUT_ERROR = 1,
14906 -     NG_VOLUME_FAILURE      = 2, 
14907 -     NG_STL_INPUT_ERROR     = 3,
14908 -     NG_SURFACE_FAILURE     = 4,
14909 -     NG_FILE_NOT_FOUND      = 5 
14910 -   };
14911 -
14912 -
14913 -
14914 -// *** Classes required for use within Netgen **********
14915 -/// Netgen Meshing Parameters class
14916 -class Ng_Meshing_Parameters 
14917 -{
14918 -public:
14919 -   int uselocalh;                      //!< Switch to enable / disable usage of local mesh size modifiers
14920 -
14921 -   double maxh;                        //!< Maximum global mesh size allowed
14922 -   double minh;                        //!< Minimum global mesh size allowed
14923 -
14924 -   double fineness;                    //!< Mesh density: 0...1 (0 => coarse; 1 => fine)
14925 -   double grading;                     //!< Mesh grading: 0...1 (0 => uniform mesh; 1 => aggressive local grading)
14926 -
14927 -   double elementsperedge;             //!< Number of elements to generate per edge of the geometry
14928 -   double elementspercurve;            //!< Elements to generate per curvature radius
14929 -
14930 -   int closeedgeenable;                //!< Enable / Disable mesh refinement at close edges
14931 -   double closeedgefact;               //!< Factor to use for refinement at close edges (larger => finer)
14932 -
14933 -   int minedgelenenable;                          //!< Enable / Disable user defined minimum edge length for edge subdivision
14934 -   double minedgelen;                  //!< Minimum edge length to use while subdividing the edges (default = 1e-4)
14935 -
14936 -   int second_order;                   //!< Generate second-order surface and volume elements
14937 -   int quad_dominated;                 //!< Creates a Quad-dominated mesh 
14938 -
14939 -   char * meshsize_filename;           //!< Optional external mesh size file 
14940 -
14941 -   int optsurfmeshenable;              //!< Enable / Disable automatic surface mesh optimization
14942 -   int optvolmeshenable;               //!< Enable / Disable automatic volume mesh optimization
14943 -
14944 -   int optsteps_3d;                     //!< Number of optimize steps to use for 3-D mesh optimization
14945 -   int optsteps_2d;                     //!< Number of optimize steps to use for 2-D mesh optimization
14946 -
14947 -   // Philippose - 13/09/2010
14948 -   // Added a couple more parameters into the meshing parameters list 
14949 -   // from Netgen into Nglib
14950 -   int invert_tets;                    //!< Invert all the volume elements
14951 -   int invert_trigs;                   //!< Invert all the surface triangle elements
14952 -
14953 -   int check_overlap;                  //!< Check for overlapping surfaces during Surface meshing
14954 -   int check_overlapping_boundary;     //!< Check for overlapping surface elements before volume meshing
14955 -
14956 -
14957 -   /*!
14958 -      Default constructor for the Mesh Parameters class
14959 -
14960 -      Note: This constructor initialises the variables in the 
14961 -      class with the following default values
14962 -      - #uselocalh: 1
14963 -      - #maxh: 1000.0
14964 -      - #fineness: 0.5
14965 -      - #grading: 0.3
14966 -      - #elementsperedge: 2.0
14967 -      - #elementspercurve: 2.0
14968 -      - #closeedgeenable: 0
14969 -      - #closeedgefact: 2.0
14970 -      - #secondorder: 0
14971 -      - #meshsize_filename: null
14972 -      - #quad_dominated: 0
14973 -      - #optsurfmeshenable: 1
14974 -      - #optvolmeshenable: 1
14975 -      - #optsteps_2d: 3
14976 -      - #optsteps_3d: 3
14977 -      - #invert_tets: 0
14978 -      - #invert_trigs:0 
14979 -      - #check_overlap: 1
14980 -      - #check_overlapping_boundary: 1
14981 -   */
14982 -   DLL_HEADER Ng_Meshing_Parameters();
14983 -
14984 -
14985 -
14986 -   /*!
14987 -       Reset the meshing parameters to their defaults
14988 -
14989 -       This member function resets all the meshing parameters 
14990 -       of the object to the default values
14991 -   */
14992 -   DLL_HEADER void Reset_Parameters();
14993 -
14994 -
14995 -
14996 -   /*!
14997 -       Transfer local meshing parameters to internal meshing parameters
14998 -
14999 -       This member function transfers all the meshing parameters 
15000 -       defined in the local meshing parameters structure of nglib into 
15001 -       the internal meshing parameters structure used by the Netgen core
15002 -   */
15003 -   DLL_HEADER void Transfer_Parameters();
15004 -};
15005 -
15006 -
15007 -
15008 -
15009 -// *** Functions Exported by this Library *************
15010 -
15011 -// ------------------------------------------------------------------
15012 -// Netgen library initialisation / destruction functions
15013 -
15014 -/*! \brief Initialise the Netgen library and prepare for use
15015 -
15016 -    This function needs to be called by the third-party 
15017 -    program before beginning to use the other Netgen 
15018 -    specific functions.
15019 -*/
15020 -DLL_HEADER void Ng_Init ();
15021 -
15022 -
15023 -/*! \brief Exit the Netgen meshing kernel in a clean manner
15024 -
15025 -    Use this function to exit the meshing sub-system in 
15026 -    a clean and orderly manner.
15027 -*/
15028 -DLL_HEADER void Ng_Exit ();
15029 -  
15030 -
15031 -/*! \brief Create a new (and empty) Netgen Mesh Structure
15032 -
15033 -    This function creates a new Netgen Mesh, initialises 
15034 -    it, and returns a pointer to the created mesh structure. 
15035 -
15036 -    Use the returned pointer for subsequent operations 
15037 -    which involve mesh operations.
15038 -
15039 -    \return Ng_Mesh Pointer to a Netgen Mesh type #Ng_Mesh
15040 -*/
15041 -DLL_HEADER  Ng_Mesh * Ng_NewMesh ();
15042 -
15043 -
15044 -/*! \brief Delete an existing Netgen Mesh Structure
15045 -
15046 -    Use this function to delete an existing Netgen mesh 
15047 -    structure and release the used memory. 
15048 -
15049 -    \param mesh Pointer to an existing Netgen Mesh structure 
15050 -                of type #Ng_Mesh
15051 -*/
15052 -DLL_HEADER void Ng_DeleteMesh (Ng_Mesh * mesh);
15053 -
15054 -
15055 -/*! \brief Save a Netgen Mesh to disk
15056 -
15057 -    This function allows a generated mesh structure to be saved 
15058 -    to disk.
15059 -
15060 -    A Mesh saved using this function, will be written to disk 
15061 -    in the Netgen VOL file format.
15062 -
15063 -    \param mesh    Pointer to an existing Netgen Mesh structure 
15064 -                   of type #Ng_Mesh
15065 -    \param filename Pointer to a character array containing the 
15066 -                    name of the file to which the mesh should 
15067 -                    be saved
15068 -*/
15069 -DLL_HEADER void Ng_SaveMesh(Ng_Mesh * mesh, const char* filename);
15070 -
15071 -
15072 -/*! \brief Load a Netgen VOL Mesh from disk into memory
15073 -
15074 -    A Netgen mesh saved in the internal VOL format can be loaded 
15075 -    into a Netgen Mesh structure using this function. 
15076 -
15077 -    \param filename Pointer to a character array containing the 
15078 -                    name of the file to load
15079 -    \return Ng_Mesh Pointer to a Netgen Mesh type #Ng_Mesh containing 
15080 -                    the mesh loaded from disk
15081 -*/
15082 -DLL_HEADER Ng_Mesh * Ng_LoadMesh(const char* filename);
15083 -
15084 -
15085 -/*! \brief Merge a Netgen VOL Mesh from disk into an existing mesh in memory
15086 -
15087 -    A Netgen mesh saved in the internal VOL format can be merged 
15088 -    into an existing Netgen Mesh structure using this function. 
15089 -
15090 -    \param mesh       Name of the Mesh structure already existent in memory
15091 -    \param filename   Pointer to a character array containing the 
15092 -                      name of the file to load
15093 -    \return Ng_Result Status of the merge operation
15094 -*/
15095 -DLL_HEADER Ng_Result Ng_MergeMesh(Ng_Mesh * mesh, const char* filename);
15096 -
15097 -
15098 -/*! \brief Merge one Netgen Mesh into another Netgen Mesh in the case 
15099 -    when both are already in memory
15100 -
15101 -    (NOTE: FUNCTION STILL WORK IN PROGRESS!!!)
15102 -
15103 -    This function can be used to merge two Netgen meshes already present 
15104 -    in memory.
15105 -
15106 -    \param mesh1      Parent Mesh structure into which the second mesh 
15107 -                      will be merged
15108 -    \param mesh2      Child mesh structure which will get merged into 
15109 -                      the parent mesh
15110 -    \return Ng_Result Status of the merge operation
15111 -*/
15112 -DLL_HEADER Ng_Result Ng_MergeMesh(Ng_Mesh * mesh1, Ng_Mesh * mesh2);
15113 -// ------------------------------------------------------------------
15114 -
15115 -
15116 -
15117 -// ------------------------------------------------------------------
15118 -// Basic Meshing functions for manually adding points, surface elements 
15119 -// and volume elements to a Netgen Mesh structure
15120 -
15121 -/*! \brief Add a point to a given Netgen Mesh Structure
15122 -
15123 -    This function allows points to be directly added to a Netgen 
15124 -    mesh structure by providing the co-ordinates.
15125 -
15126 -    Each call to the function allows only one point to be added.
15127 -
15128 -    \param mesh Pointer to an existing Netgen Mesh structure of 
15129 -                type #Ng_Mesh
15130 -    \param x    Pointer to an array of type double containing the co-ordinates 
15131 -                of the point to be added in the form: \n
15132 -                - x[0] = X co-ordinate
15133 -                - x[1] = Y co-ordinate
15134 -                - x[2] = Z co-ordinate
15135 -*/
15136 -DLL_HEADER void Ng_AddPoint (Ng_Mesh * mesh, double * x);
15137 -
15138 -
15139 -/*! \brief Add a surface element to a given Netgen Mesh Structure
15140 -
15141 -    This function allows the top-level code to directly add individual 
15142 -    Surface Elements to a Netgen Mesh Structure by providing the type of 
15143 -    element to be added and the indices of the points which constitute the 
15144 -    element.
15145 -
15146 -    <i>Note:</i> 
15147 -    - The points referred to by the surface elements must have been
15148 -      added prior to calling this function. 
15149 -    - Currently only triangular elements are supported, and the Surface Element 
15150 -      Type argument is not used.
15151 -
15152 -    \param mesh Pointer to an existing Netgen Mesh structure of 
15153 -                type #Ng_Mesh
15154 -    \param et   Surface Element type provided via the enumerated type 
15155 -                #Ng_Surface_Element_Type 
15156 -    \param pi   Pointer to an array of integers containing the indices of the 
15157 -                points which constitute the surface element being added
15158 -*/
15159 -DLL_HEADER void Ng_AddSurfaceElement (Ng_Mesh * mesh, Ng_Surface_Element_Type et, int * pi);
15160 -
15161 -
15162 -/*! \brief Add a volume element to a given Netgen Mesh Structure
15163 -
15164 -    This function allows the top-level code to directly add individual 
15165 -    Volume Elements to a Netgen Mesh Structure by providing the type of 
15166 -    element to be added and the indices of the points which constitute the 
15167 -    element.
15168 -
15169 -    <i>Note:</i> 
15170 -    - The points referred to by the volume elements must have been
15171 -      added prior to calling this function. 
15172 -    - Currently only tetrahedral elements are supported, and the Volume Element 
15173 -      Type argument is not used.
15174 -
15175 -    \param mesh Pointer to an existing Netgen Mesh structure of 
15176 -                type #Ng_Mesh
15177 -    \param et   Volume Element type provided via the enumerated type 
15178 -                #Ng_Volume_Element_Type 
15179 -    \param pi   Pointer to an array of integers containing the indices of the 
15180 -                points which constitute the volume element being added
15181 -
15182 -*/
15183 -DLL_HEADER void Ng_AddVolumeElement (Ng_Mesh * mesh, Ng_Volume_Element_Type et, int * pi);
15184 -  
15185 -// ------------------------------------------------------------------
15186 -
15187 -
15188 -
15189 -// ------------------------------------------------------------------
15190 -// Local Mesh Size restriction / limiting utilities
15191 -
15192 -/*! \brief Apply a global restriction on mesh element size
15193 -
15194 -    This utility allows the user to apply a global mesh element 
15195 -    size limitation. 
15196 -
15197 -    During mesh creation, in the absence of an explicit local 
15198 -    size restriction around the neighbourhood of a point within 
15199 -    the meshing domain, this global size restriction will be 
15200 -    utilised.
15201 -
15202 -    <b>Note</b>: This function only limits the <b>Maximum</b> 
15203 -    size of an element within the mesh.
15204 -
15205 -    \param mesh Pointer to an existing Netgen Mesh structure of 
15206 -                type #Ng_Mesh
15207 -    \param h    Variable of type <i>double</i>, specifying the maximum
15208 -                allowable mesh size
15209 -*/
15210 -DLL_HEADER void Ng_RestrictMeshSizeGlobal (Ng_Mesh * mesh, double h);
15211 -
15212 -
15213 -/*! \brief Locally restrict the mesh element size at the given point
15214 -
15215 -    Unlike the function #Ng_RestrictMeshSizeGlobal, this function 
15216 -    allows the user to locally restrict the maximum allowable mesh 
15217 -    size at a given point.
15218 -
15219 -    The point is specified via its three cartesian co-ordinates.
15220 -
15221 -    <b>Note</b>: This function only limits the <b>Maximum</b> size 
15222 -    of the elements around the specified point.
15223 -
15224 -    \param mesh Pointer to an existing Netgen Mesh structure of 
15225 -                type #Ng_Mesh
15226 -    \param p    Pointer to an Array of type <i>double</i>, containing 
15227 -                the three co-ordinates of the point in the form: \n
15228 -                - p[0] = X co-ordinate
15229 -                - p[1] = Y co-ordinate
15230 -                - p[2] = Z co-ordinate
15231 -    \param h    Variable of type <i>double</i>, specifying the maximum
15232 -                allowable mesh size at that point
15233 -*/
15234 -DLL_HEADER void Ng_RestrictMeshSizePoint (Ng_Mesh * mesh, double * p, double h);
15235 -
15236 -
15237 -/*! \brief Locally restrict the mesh element size within a specified box
15238 -
15239 -    Similar to the function #Ng_RestrictMeshSizePoint, this function 
15240 -    allows the size of elements within a mesh to be locally limited.
15241 -
15242 -    However, rather than limit the mesh size at a single point, this 
15243 -    utility restricts the local mesh size within a 3D Box region, specified 
15244 -    via the co-ordinates of the two diagonally opposite points of a cuboid.
15245 -
15246 -    <b>Note</b>: This function only limits the <b>Maximum</b> size 
15247 -    of the elements within the specified region.
15248 -
15249 -    \param mesh Pointer to an existing Netgen Mesh structure of 
15250 -                type #Ng_Mesh
15251 -    \param pmin Pointer to an Array of type <i>double</i>, containing 
15252 -                the three co-ordinates of the first point of the cuboid: \n
15253 -                - pmin[0] = X co-ordinate
15254 -                - pmin[1] = Y co-ordinate
15255 -                - pmin[2] = Z co-ordinate
15256 -    \param pmax Pointer to an Array of type <i>double</i>, containing 
15257 -                the three co-ordinates of the opposite point of the 
15258 -                cuboid: \n
15259 -                - pmax[0] = X co-ordinate
15260 -                - pmax[1] = Y co-ordinate
15261 -                - pmax[2] = Z co-ordinate
15262 -    \param h    Variable of type <i>double</i>, specifying the maximum
15263 -                allowable mesh size at that point
15264 -*/
15265 -DLL_HEADER void Ng_RestrictMeshSizeBox (Ng_Mesh * mesh, double * pmin, double * pmax, double h);
15266 -
15267 -// ------------------------------------------------------------------
15268 -
15269 -
15270 -
15271 -// ------------------------------------------------------------------
15272 -// 3D Mesh Generation functions
15273 -
15274 -/*! \brief Create a 3D Volume Mesh given a Surface Mesh
15275 -
15276 -    After creating a surface mesh, this function can be utilised 
15277 -    to automatically generate the corresponding 3D Volume Mesh.
15278 -
15279 -    Mesh generation parameters (such as grading, maximum element size, 
15280 -    etc.) are specified via the meshing parameters class which also 
15281 -    needs to be passed to this function.
15282 -
15283 -    <b>Note</b>: Currently, Netgen generates pure tetrahedral volume 
15284 -    meshes.
15285 -
15286 -    \param mesh Pointer to an existing Netgen Mesh structure of 
15287 -                type #Ng_Mesh
15288 -    \param mp   Pointer to a copy of the Meshing Parameters class
15289 -                (#Ng_Meshing_Parameters), filled up with the 
15290 -                required values
15291 -
15292 -    \return Ng_Result Status of the Mesh Generation routine. More 
15293 -                      details regarding the return value can be 
15294 -                      found in the description of #Ng_Result
15295 -*/
15296 -DLL_HEADER Ng_Result Ng_GenerateVolumeMesh (Ng_Mesh * mesh, Ng_Meshing_Parameters * mp);
15297 -
15298 -// ------------------------------------------------------------------
15299 -
15300 -
15301 -
15302 -// ------------------------------------------------------------------
15303 -// Basic Mesh information functions
15304 -
15305 -/*! \brief Returns the Number of Points present in the specified Mesh
15306 -
15307 -    Given an already existent Netgen Mesh Structure, this function 
15308 -    returns the number of points currently present within the Mesh.
15309 -
15310 -    \param mesh Pointer to an existing Netgen Mesh structure of 
15311 -                type #Ng_Mesh
15312 -    \return 
15313 -                Integer Data-type with the number of points in the Mesh
15314 -*/
15315 -DLL_HEADER int Ng_GetNP (Ng_Mesh * mesh);
15316 -
15317 -
15318 -/*! \brief Returns the Number of Surface Elements present in the specified Mesh
15319 -
15320 -    Given an already existent Netgen Mesh Structure, this function 
15321 -    returns the number of surface elements currently present within 
15322 -    the Mesh.
15323 -
15324 -    \param mesh Pointer to an existing Netgen Mesh structure of 
15325 -                type #Ng_Mesh
15326 -    \return 
15327 -                Integer Data-type with the number of surface elements in the Mesh
15328 -*/
15329 -DLL_HEADER int Ng_GetNSE (Ng_Mesh * mesh);
15330 -
15331 -
15332 -/*! \brief Returns the Number of Volume Elements present in the specified Mesh
15333 -
15334 -    Given an already existent Netgen Mesh Structure, this function 
15335 -    returns the number of volume elements currently present within 
15336 -    the Mesh.
15337 -
15338 -    \param mesh Pointer to an existing Netgen Mesh structure of 
15339 -                type #Ng_Mesh
15340 -    \return 
15341 -                Integer Data-type with the number of volume elements in the Mesh
15342 -*/
15343 -DLL_HEADER int Ng_GetNE (Ng_Mesh * mesh);
15344 -
15345 -// ------------------------------------------------------------------
15346 -
15347 -
15348 -
15349 -// ------------------------------------------------------------------
15350 -// Mesh Topology functions
15351 -// Use these functions to extract points, surface / volume elements, 
15352 -// perform topological searches, etc..etc...
15353 -  
15354 -//  Return the Point Coordinates of a specified Point
15355 -// The x, y and z co-ordinates are returned in the array pointer as 
15356 -// x[0] = x ; x[1] = y ; x[2] = z
15357 -DLL_HEADER void Ng_GetPoint (Ng_Mesh * mesh, int num, double * x);
15358 -
15359 -
15360 -
15361 -// return surface and volume element in pi
15362 -DLL_HEADER Ng_Surface_Element_Type 
15363 -Ng_GetSurfaceElement (Ng_Mesh * mesh, int num, int * pi);
15364 -
15365 -DLL_HEADER Ng_Volume_Element_Type
15366 -Ng_GetVolumeElement (Ng_Mesh * mesh, int num, int * pi);
15367 -
15368 -// ------------------------------------------------------------------
15369 -
15370 -
15371 -
15372 -
15373 -// **********************************************************
15374 -// **   2D Meshing                                         **
15375 -// **********************************************************
15376 -
15377 -
15378 -// feeds points and boundary to mesh
15379 -
15380 -DLL_HEADER void Ng_AddPoint_2D (Ng_Mesh * mesh, double * x);
15381 -DLL_HEADER void Ng_AddBoundarySeg_2D (Ng_Mesh * mesh, int pi1, int pi2);
15382 -  
15383 -// ask for number of points, elements and boundary segments
15384 -DLL_HEADER int Ng_GetNP_2D (Ng_Mesh * mesh);
15385 -DLL_HEADER int Ng_GetNE_2D (Ng_Mesh * mesh);
15386 -DLL_HEADER int Ng_GetNSeg_2D (Ng_Mesh * mesh);
15387 -  
15388 -//  return point coordinates
15389 -DLL_HEADER void Ng_GetPoint_2D (Ng_Mesh * mesh, int num, double * x);
15390 -
15391 -// return 2d elements
15392 -DLL_HEADER Ng_Surface_Element_Type 
15393 -Ng_GetElement_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum = NULL);
15394 -
15395 -// return 2d boundary segment
15396 -DLL_HEADER void Ng_GetSegment_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum = NULL);
15397 -
15398 -
15399 -// load 2d netgen spline geometry
15400 -DLL_HEADER Ng_Geometry_2D * Ng_LoadGeometry_2D (const char * filename);
15401 -
15402 -// generate 2d mesh, mesh is allocated by function
15403 -DLL_HEADER Ng_Result Ng_GenerateMesh_2D (Ng_Geometry_2D * geom,
15404 -                                         Ng_Mesh ** mesh,
15405 -                                         Ng_Meshing_Parameters * mp);
15406 -  
15407 -DLL_HEADER void Ng_HP_Refinement (Ng_Geometry_2D * geom,
15408 -                                  Ng_Mesh * mesh,
15409 -                                  int levels);
15410 -  
15411 -
15412 -
15413 -
15414 -
15415 -// **********************************************************
15416 -// **   STL Meshing                                        **
15417 -// **********************************************************
15418 -
15419 -
15420 -// loads geometry from STL file
15421 -DLL_HEADER Ng_STL_Geometry * Ng_STL_LoadGeometry (const char * filename, int binary = 0);
15422 -
15423 -
15424 -// generate new STL Geometry
15425 -DLL_HEADER Ng_STL_Geometry * Ng_STL_NewGeometry ();
15426 -  
15427 -
15428 -// fills STL Geometry
15429 -// positive orientation
15430 -// normal vector may be null-pointer
15431 -DLL_HEADER void Ng_STL_AddTriangle (Ng_STL_Geometry * geom, 
15432 -                         double * p1, double * p2, double * p3, 
15433 -                         double * nv = NULL);
15434 -
15435 -// add (optional) edges :
15436 -DLL_HEADER void Ng_STL_AddEdge (Ng_STL_Geometry * geom, 
15437 -                     double * p1, double * p2);
15438 -
15439 -// after adding triangles (and edges) initialize
15440 -DLL_HEADER Ng_Result Ng_STL_InitSTLGeometry (Ng_STL_Geometry * geom);
15441 -
15442 -// automatically generates edges:
15443 -DLL_HEADER Ng_Result Ng_STL_MakeEdges (Ng_STL_Geometry * geom,
15444 -                            Ng_Mesh* mesh,
15445 -                            Ng_Meshing_Parameters * mp);
15446 -
15447 -
15448 -// generates mesh, empty mesh must be already created.
15449 -DLL_HEADER Ng_Result Ng_STL_GenerateSurfaceMesh (Ng_STL_Geometry * geom,
15450 -                                                 Ng_Mesh * mesh,
15451 -                                                 Ng_Meshing_Parameters * mp);
15452 -
15453 -
15454 -#ifdef ACIS
15455 -
15456 -// **********************************************************
15457 -// **   ACIS Meshing                                       **
15458 -// **********************************************************
15459 -
15460 -/// Data type for NETGEN STL geomty
15461 -typedef void * Ng_ACIS_Geometry;
15462 -
15463 -// loads geometry from STL file
15464 -DLL_HEADER Ng_ACIS_Geometry * Ng_ACIS_LoadGeometry (const char * filename);
15465 -  
15466 -// generates mesh, empty mesh must be already created.
15467 -DLL_HEADER Ng_Result Ng_ACIS_GenerateSurfaceMesh (Ng_ACIS_Geometry * geom,
15468 -                                                  Ng_Mesh * mesh,
15469 -                                                  Ng_Meshing_Parameters * mp);
15470 -
15471 -
15472 -#endif
15473 -
15474 -
15475 -
15476 -#ifdef OCCGEOMETRY
15477 -
15478 -// **********************************************************
15479 -// **   OpenCascade Geometry / Meshing Utilities           **
15480 -// **********************************************************
15481 -
15482 -// Create new OCC Geometry Object
15483 -DLL_HEADER Ng_OCC_Geometry * Ng_OCC_NewGeometry ();
15484 -
15485 -// Delete an OCC Geometry Object
15486 -DLL_HEADER Ng_Result Ng_OCC_DeleteGeometry (Ng_OCC_Geometry * geom);
15487 -
15488 -// Loads geometry from STEP file
15489 -DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_STEP (const char * filename);
15490 -
15491 -// Loads geometry from IGES file
15492 -DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_IGES (const char * filename);
15493 -
15494 -// Loads geometry from BREP file
15495 -DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_BREP (const char * filename);
15496 -
15497 -// Set the local mesh size based on geometry / topology
15498 -DLL_HEADER Ng_Result Ng_OCC_SetLocalMeshSize (Ng_OCC_Geometry * geom,
15499 -                                              Ng_Mesh * mesh,
15500 -                                              Ng_Meshing_Parameters * mp);
15501 -
15502 -// Mesh the edges and add Face descriptors to prepare for surface meshing
15503 -DLL_HEADER Ng_Result Ng_OCC_GenerateEdgeMesh (Ng_OCC_Geometry * geom,
15504 -                                              Ng_Mesh * mesh,
15505 -                                              Ng_Meshing_Parameters * mp);
15506 -
15507 -// Mesh the surfaces of an OCC geometry
15508 -DLL_HEADER Ng_Result Ng_OCC_GenerateSurfaceMesh (Ng_OCC_Geometry * geom,
15509 -                                                 Ng_Mesh * mesh,
15510 -                                                 Ng_Meshing_Parameters * mp); 
15511 -
15512 -// Get the face map of an already loaded OCC geometry
15513 -DLL_HEADER Ng_Result Ng_OCC_GetFMap(Ng_OCC_Geometry * geom, 
15514 -                                    Ng_OCC_TopTools_IndexedMapOfShape * FMap);
15515 -
15516 -#endif // OCCGEOMETRY
15517 -
15518 -
15519 -
15520 -// **********************************************************
15521 -// **   Mesh refinement algorithms                         **
15522 -// **********************************************************
15523 -
15524 -// uniform mesh refinement
15525 -DLL_HEADER void Ng_Uniform_Refinement (Ng_Mesh * mesh);
15526 -
15527 -
15528 -// uniform mesh refinement with geometry adaption:
15529 -
15530 -DLL_HEADER void Ng_2D_Uniform_Refinement (Ng_Geometry_2D * geom,
15531 -                                         Ng_Mesh * mesh);
15532 -
15533 -DLL_HEADER void Ng_STL_Uniform_Refinement (Ng_STL_Geometry * geom,
15534 -                                          Ng_Mesh * mesh);
15535 -
15536 -DLL_HEADER void Ng_CSG_Uniform_Refinement (Ng_CSG_Geometry * geom,
15537 -                                          Ng_Mesh * mesh);
15538 -
15539 -#ifdef OCCGEOMETRY
15540 -DLL_HEADER void Ng_OCC_Uniform_Refinement (Ng_OCC_Geometry * geom,
15541 -                                          Ng_Mesh * mesh);
15542 -#endif
15543 -
15544 -
15545 -
15546 -// **********************************************************
15547 -// **   Second Order mesh algorithms                       **
15548 -// **********************************************************
15549 -
15550 -// convert mesh to second order
15551 -DLL_HEADER void Ng_Generate_SecondOrder (Ng_Mesh * mesh);
15552 -
15553 -
15554 -// convert mesh to second order with geometry adaption:
15555 -
15556 -DLL_HEADER void Ng_2D_Generate_SecondOrder (Ng_Geometry_2D * geom,
15557 -                                         Ng_Mesh * mesh);
15558 -
15559 -DLL_HEADER void Ng_STL_Generate_SecondOrder (Ng_STL_Geometry * geom,
15560 -                                          Ng_Mesh * mesh);
15561 -
15562 -DLL_HEADER void Ng_CSG_Generate_SecondOrder (Ng_CSG_Geometry * geom,
15563 -                                          Ng_Mesh * mesh);
15564 -
15565 -#ifdef OCCGEOMETRY
15566 -DLL_HEADER void Ng_OCC_Generate_SecondOrder (Ng_OCC_Geometry * geom,
15567 -                                          Ng_Mesh * mesh);
15568 -#endif
15569 -
15570 -
15571 -#endif // NGLIB
15572 +#ifndef NGLIB
15573 +#define NGLIB
15574 +
15575 +/**************************************************************************/
15576 +/* File:   nglib.h                                                        */
15577 +/* Author: Joachim Schoeberl                                              */
15578 +/* Date:   7. May. 2000                                                   */
15579 +/**************************************************************************/
15580 +
15581 +/*!
15582 +   \file nglib.h
15583 +   \brief Library interface to the netgen meshing kernel
15584 +   \author Joachim Schoeberl
15585 +   \date 7. May 2000
15586 +
15587 +   This header file provides access to the core functionality of the Netgen 
15588 +   Mesher via a library interface, without an interactive User Interface.
15589 +
15590 +   The intention of providing these set of functions is to allow system 
15591 +   developers to integrate Netgen into top-level code, to act as the low 
15592 +   level mesh generation / optimisation kernel.  
15593 +*/
15594 +
15595 +// Philippose - 14.02.2009
15596 +// Modifications for creating a DLL in Windows
15597 +#ifdef WIN32
15598 +   #if defined NGLIB_EXPORTS || defined nglib_EXPORTS
15599 +      #define DLL_HEADER   __declspec(dllexport)
15600 +   #else
15601 +      #define DLL_HEADER   __declspec(dllimport)
15602 +   #endif
15603 +#else
15604 +   #define DLL_HEADER 
15605 +#endif
15606 +
15607 +
15608 +
15609 +// ** Constants used within Netgen *********************
15610 +/// Maximum allowed number of nodes per volume element
15611 +#define NG_VOLUME_ELEMENT_MAXPOINTS 10
15612 +
15613 +/// Maximum allowed number of nodes per surface element
15614 +#define NG_SURFACE_ELEMENT_MAXPOINTS 8
15615 +
15616 +
15617 +
15618 +// *** Data-types for accessing Netgen functionality ***
15619 +/// Data type for NETGEN mesh
15620 +typedef void * Ng_Mesh;
15621 +
15622 +/// Data type for NETGEN CSG geometry
15623 +typedef void * Ng_CSG_Geometry;
15624 +
15625 +/// Data type for NETGEN 2D geometry
15626 +typedef void * Ng_Geometry_2D;
15627 +
15628 +/// Data type for NETGEN STL geometry
15629 +typedef void * Ng_STL_Geometry;
15630 +
15631 +#ifdef OCCGEOMETRY
15632 +/// Data type for NETGEN OpenCascade geometry
15633 +typedef void * Ng_OCC_Geometry;
15634 +typedef void * Ng_OCC_TopTools_IndexedMapOfShape;
15635 +#endif
15636 +
15637 +
15638 +// *** Special Enum types used within Netgen ***********
15639 +/// Currently implemented surface element types
15640 +enum Ng_Surface_Element_Type 
15641 +   { NG_TRIG = 1, NG_QUAD = 2, NG_TRIG6 = 3, NG_QUAD6 = 4, NG_QUAD8 = 5 };
15642 +
15643 +/// Currently implemented volume element types
15644 +enum Ng_Volume_Element_Type 
15645 +   { NG_TET = 1, NG_PYRAMID = 2, NG_PRISM = 3, NG_TET10 = 4 };
15646 +
15647 +/// Values returned by Netgen functions
15648 +enum Ng_Result 
15649 +   { 
15650 +     NG_ERROR               = -1,   
15651 +     NG_OK                  = 0, 
15652 +     NG_SURFACE_INPUT_ERROR = 1,
15653 +     NG_VOLUME_FAILURE      = 2, 
15654 +     NG_STL_INPUT_ERROR     = 3,
15655 +     NG_SURFACE_FAILURE     = 4,
15656 +     NG_FILE_NOT_FOUND      = 5 
15657 +   };
15658 +
15659 +
15660 +
15661 +// *** Classes required for use within Netgen **********
15662 +/// Netgen Meshing Parameters class
15663 +class Ng_Meshing_Parameters 
15664 +{
15665 +public:
15666 +   int uselocalh;                      //!< Switch to enable / disable usage of local mesh size modifiers
15667 +
15668 +   double maxh;                        //!< Maximum global mesh size allowed
15669 +   double minh;                        //!< Minimum global mesh size allowed
15670 +
15671 +   double fineness;                    //!< Mesh density: 0...1 (0 => coarse; 1 => fine)
15672 +   double grading;                     //!< Mesh grading: 0...1 (0 => uniform mesh; 1 => aggressive local grading)
15673 +
15674 +   double elementsperedge;             //!< Number of elements to generate per edge of the geometry
15675 +   double elementspercurve;            //!< Elements to generate per curvature radius
15676 +
15677 +   int closeedgeenable;                //!< Enable / Disable mesh refinement at close edges
15678 +   double closeedgefact;               //!< Factor to use for refinement at close edges (larger => finer)
15679 +
15680 +   int minedgelenenable;                          //!< Enable / Disable user defined minimum edge length for edge subdivision
15681 +   double minedgelen;                  //!< Minimum edge length to use while subdividing the edges (default = 1e-4)
15682 +
15683 +   int second_order;                   //!< Generate second-order surface and volume elements
15684 +   int quad_dominated;                 //!< Creates a Quad-dominated mesh 
15685 +
15686 +   char * meshsize_filename;           //!< Optional external mesh size file 
15687 +
15688 +   int optsurfmeshenable;              //!< Enable / Disable automatic surface mesh optimization
15689 +   int optvolmeshenable;               //!< Enable / Disable automatic volume mesh optimization
15690 +
15691 +   int optsteps_3d;                     //!< Number of optimize steps to use for 3-D mesh optimization
15692 +   int optsteps_2d;                     //!< Number of optimize steps to use for 2-D mesh optimization
15693 +
15694 +   // Philippose - 13/09/2010
15695 +   // Added a couple more parameters into the meshing parameters list 
15696 +   // from Netgen into Nglib
15697 +   int invert_tets;                    //!< Invert all the volume elements
15698 +   int invert_trigs;                   //!< Invert all the surface triangle elements
15699 +
15700 +   int check_overlap;                  //!< Check for overlapping surfaces during Surface meshing
15701 +   int check_overlapping_boundary;     //!< Check for overlapping surface elements before volume meshing
15702 +
15703 +
15704 +   /*!
15705 +      Default constructor for the Mesh Parameters class
15706 +
15707 +      Note: This constructor initialises the variables in the 
15708 +      class with the following default values
15709 +      - #uselocalh: 1
15710 +      - #maxh: 1000.0
15711 +      - #fineness: 0.5
15712 +      - #grading: 0.3
15713 +      - #elementsperedge: 2.0
15714 +      - #elementspercurve: 2.0
15715 +      - #closeedgeenable: 0
15716 +      - #closeedgefact: 2.0
15717 +      - #secondorder: 0
15718 +      - #meshsize_filename: null
15719 +      - #quad_dominated: 0
15720 +      - #optsurfmeshenable: 1
15721 +      - #optvolmeshenable: 1
15722 +      - #optsteps_2d: 3
15723 +      - #optsteps_3d: 3
15724 +      - #invert_tets: 0
15725 +      - #invert_trigs:0 
15726 +      - #check_overlap: 1
15727 +      - #check_overlapping_boundary: 1
15728 +   */
15729 +   DLL_HEADER Ng_Meshing_Parameters();
15730 +
15731 +
15732 +
15733 +   /*!
15734 +       Reset the meshing parameters to their defaults
15735 +
15736 +       This member function resets all the meshing parameters 
15737 +       of the object to the default values
15738 +   */
15739 +   DLL_HEADER void Reset_Parameters();
15740 +
15741 +
15742 +
15743 +   /*!
15744 +       Transfer local meshing parameters to internal meshing parameters
15745 +
15746 +       This member function transfers all the meshing parameters 
15747 +       defined in the local meshing parameters structure of nglib into 
15748 +       the internal meshing parameters structure used by the Netgen core
15749 +   */
15750 +   DLL_HEADER void Transfer_Parameters();
15751 +};
15752 +
15753 +
15754 +
15755 +
15756 +// *** Functions Exported by this Library *************
15757 +
15758 +// ------------------------------------------------------------------
15759 +// Netgen library initialisation / destruction functions
15760 +
15761 +/*! \brief Initialise the Netgen library and prepare for use
15762 +
15763 +    This function needs to be called by the third-party 
15764 +    program before beginning to use the other Netgen 
15765 +    specific functions.
15766 +*/
15767 +DLL_HEADER void Ng_Init ();
15768 +
15769 +
15770 +/*! \brief Exit the Netgen meshing kernel in a clean manner
15771 +
15772 +    Use this function to exit the meshing sub-system in 
15773 +    a clean and orderly manner.
15774 +*/
15775 +DLL_HEADER void Ng_Exit ();
15776 +  
15777 +
15778 +/*! \brief Create a new (and empty) Netgen Mesh Structure
15779 +
15780 +    This function creates a new Netgen Mesh, initialises 
15781 +    it, and returns a pointer to the created mesh structure. 
15782 +
15783 +    Use the returned pointer for subsequent operations 
15784 +    which involve mesh operations.
15785 +
15786 +    \return Ng_Mesh Pointer to a Netgen Mesh type #Ng_Mesh
15787 +*/
15788 +DLL_HEADER  Ng_Mesh * Ng_NewMesh ();
15789 +
15790 +
15791 +/*! \brief Delete an existing Netgen Mesh Structure
15792 +
15793 +    Use this function to delete an existing Netgen mesh 
15794 +    structure and release the used memory. 
15795 +
15796 +    \param mesh Pointer to an existing Netgen Mesh structure 
15797 +                of type #Ng_Mesh
15798 +*/
15799 +DLL_HEADER void Ng_DeleteMesh (Ng_Mesh * mesh);
15800 +
15801 +
15802 +/*! \brief Save a Netgen Mesh to disk
15803 +
15804 +    This function allows a generated mesh structure to be saved 
15805 +    to disk.
15806 +
15807 +    A Mesh saved using this function, will be written to disk 
15808 +    in the Netgen VOL file format.
15809 +
15810 +    \param mesh    Pointer to an existing Netgen Mesh structure 
15811 +                   of type #Ng_Mesh
15812 +    \param filename Pointer to a character array containing the 
15813 +                    name of the file to which the mesh should 
15814 +                    be saved
15815 +*/
15816 +DLL_HEADER void Ng_SaveMesh(Ng_Mesh * mesh, const char* filename);
15817 +
15818 +
15819 +/*! \brief Load a Netgen VOL Mesh from disk into memory
15820 +
15821 +    A Netgen mesh saved in the internal VOL format can be loaded 
15822 +    into a Netgen Mesh structure using this function. 
15823 +
15824 +    \param filename Pointer to a character array containing the 
15825 +                    name of the file to load
15826 +    \return Ng_Mesh Pointer to a Netgen Mesh type #Ng_Mesh containing 
15827 +                    the mesh loaded from disk
15828 +*/
15829 +DLL_HEADER Ng_Mesh * Ng_LoadMesh(const char* filename);
15830 +
15831 +
15832 +/*! \brief Merge a Netgen VOL Mesh from disk into an existing mesh in memory
15833 +
15834 +    A Netgen mesh saved in the internal VOL format can be merged 
15835 +    into an existing Netgen Mesh structure using this function. 
15836 +
15837 +    \param mesh       Name of the Mesh structure already existent in memory
15838 +    \param filename   Pointer to a character array containing the 
15839 +                      name of the file to load
15840 +    \return Ng_Result Status of the merge operation
15841 +*/
15842 +DLL_HEADER Ng_Result Ng_MergeMesh(Ng_Mesh * mesh, const char* filename);
15843 +
15844 +
15845 +/*! \brief Merge one Netgen Mesh into another Netgen Mesh in the case 
15846 +    when both are already in memory
15847 +
15848 +    (NOTE: FUNCTION STILL WORK IN PROGRESS!!!)
15849 +
15850 +    This function can be used to merge two Netgen meshes already present 
15851 +    in memory.
15852 +
15853 +    \param mesh1      Parent Mesh structure into which the second mesh 
15854 +                      will be merged
15855 +    \param mesh2      Child mesh structure which will get merged into 
15856 +                      the parent mesh
15857 +    \return Ng_Result Status of the merge operation
15858 +*/
15859 +DLL_HEADER Ng_Result Ng_MergeMesh(Ng_Mesh * mesh1, Ng_Mesh * mesh2);
15860 +// ------------------------------------------------------------------
15861 +
15862 +
15863 +
15864 +// ------------------------------------------------------------------
15865 +// Basic Meshing functions for manually adding points, surface elements 
15866 +// and volume elements to a Netgen Mesh structure
15867 +
15868 +/*! \brief Add a point to a given Netgen Mesh Structure
15869 +
15870 +    This function allows points to be directly added to a Netgen 
15871 +    mesh structure by providing the co-ordinates.
15872 +
15873 +    Each call to the function allows only one point to be added.
15874 +
15875 +    \param mesh Pointer to an existing Netgen Mesh structure of 
15876 +                type #Ng_Mesh
15877 +    \param x    Pointer to an array of type double containing the co-ordinates 
15878 +                of the point to be added in the form: \n
15879 +                - x[0] = X co-ordinate
15880 +                - x[1] = Y co-ordinate
15881 +                - x[2] = Z co-ordinate
15882 +*/
15883 +DLL_HEADER void Ng_AddPoint (Ng_Mesh * mesh, double * x);
15884 +
15885 +
15886 +/*! \brief Add a surface element to a given Netgen Mesh Structure
15887 +
15888 +    This function allows the top-level code to directly add individual 
15889 +    Surface Elements to a Netgen Mesh Structure by providing the type of 
15890 +    element to be added and the indices of the points which constitute the 
15891 +    element.
15892 +
15893 +    <i>Note:</i> 
15894 +    - The points referred to by the surface elements must have been
15895 +      added prior to calling this function. 
15896 +    - Currently only triangular elements are supported, and the Surface Element 
15897 +      Type argument is not used.
15898 +
15899 +    \param mesh Pointer to an existing Netgen Mesh structure of 
15900 +                type #Ng_Mesh
15901 +    \param et   Surface Element type provided via the enumerated type 
15902 +                #Ng_Surface_Element_Type 
15903 +    \param pi   Pointer to an array of integers containing the indices of the 
15904 +                points which constitute the surface element being added
15905 +*/
15906 +DLL_HEADER void Ng_AddSurfaceElement (Ng_Mesh * mesh, Ng_Surface_Element_Type et, int * pi);
15907 +
15908 +
15909 +/*! \brief Add a volume element to a given Netgen Mesh Structure
15910 +
15911 +    This function allows the top-level code to directly add individual 
15912 +    Volume Elements to a Netgen Mesh Structure by providing the type of 
15913 +    element to be added and the indices of the points which constitute the 
15914 +    element.
15915 +
15916 +    <i>Note:</i> 
15917 +    - The points referred to by the volume elements must have been
15918 +      added prior to calling this function. 
15919 +    - Currently only tetrahedral elements are supported, and the Volume Element 
15920 +      Type argument is not used.
15921 +
15922 +    \param mesh Pointer to an existing Netgen Mesh structure of 
15923 +                type #Ng_Mesh
15924 +    \param et   Volume Element type provided via the enumerated type 
15925 +                #Ng_Volume_Element_Type 
15926 +    \param pi   Pointer to an array of integers containing the indices of the 
15927 +                points which constitute the volume element being added
15928 +
15929 +*/
15930 +DLL_HEADER void Ng_AddVolumeElement (Ng_Mesh * mesh, Ng_Volume_Element_Type et, int * pi);
15931 +  
15932 +// ------------------------------------------------------------------
15933 +
15934 +
15935 +
15936 +// ------------------------------------------------------------------
15937 +// Local Mesh Size restriction / limiting utilities
15938 +
15939 +/*! \brief Apply a global restriction on mesh element size
15940 +
15941 +    This utility allows the user to apply a global mesh element 
15942 +    size limitation. 
15943 +
15944 +    During mesh creation, in the absence of an explicit local 
15945 +    size restriction around the neighbourhood of a point within 
15946 +    the meshing domain, this global size restriction will be 
15947 +    utilised.
15948 +
15949 +    <b>Note</b>: This function only limits the <b>Maximum</b> 
15950 +    size of an element within the mesh.
15951 +
15952 +    \param mesh Pointer to an existing Netgen Mesh structure of 
15953 +                type #Ng_Mesh
15954 +    \param h    Variable of type <i>double</i>, specifying the maximum
15955 +                allowable mesh size
15956 +*/
15957 +DLL_HEADER void Ng_RestrictMeshSizeGlobal (Ng_Mesh * mesh, double h);
15958 +
15959 +
15960 +/*! \brief Locally restrict the mesh element size at the given point
15961 +
15962 +    Unlike the function #Ng_RestrictMeshSizeGlobal, this function 
15963 +    allows the user to locally restrict the maximum allowable mesh 
15964 +    size at a given point.
15965 +
15966 +    The point is specified via its three cartesian co-ordinates.
15967 +
15968 +    <b>Note</b>: This function only limits the <b>Maximum</b> size 
15969 +    of the elements around the specified point.
15970 +
15971 +    \param mesh Pointer to an existing Netgen Mesh structure of 
15972 +                type #Ng_Mesh
15973 +    \param p    Pointer to an Array of type <i>double</i>, containing 
15974 +                the three co-ordinates of the point in the form: \n
15975 +                - p[0] = X co-ordinate
15976 +                - p[1] = Y co-ordinate
15977 +                - p[2] = Z co-ordinate
15978 +    \param h    Variable of type <i>double</i>, specifying the maximum
15979 +                allowable mesh size at that point
15980 +*/
15981 +DLL_HEADER void Ng_RestrictMeshSizePoint (Ng_Mesh * mesh, double * p, double h);
15982 +
15983 +
15984 +/*! \brief Locally restrict the mesh element size within a specified box
15985 +
15986 +    Similar to the function #Ng_RestrictMeshSizePoint, this function 
15987 +    allows the size of elements within a mesh to be locally limited.
15988 +
15989 +    However, rather than limit the mesh size at a single point, this 
15990 +    utility restricts the local mesh size within a 3D Box region, specified 
15991 +    via the co-ordinates of the two diagonally opposite points of a cuboid.
15992 +
15993 +    <b>Note</b>: This function only limits the <b>Maximum</b> size 
15994 +    of the elements within the specified region.
15995 +
15996 +    \param mesh Pointer to an existing Netgen Mesh structure of 
15997 +                type #Ng_Mesh
15998 +    \param pmin Pointer to an Array of type <i>double</i>, containing 
15999 +                the three co-ordinates of the first point of the cuboid: \n
16000 +                - pmin[0] = X co-ordinate
16001 +                - pmin[1] = Y co-ordinate
16002 +                - pmin[2] = Z co-ordinate
16003 +    \param pmax Pointer to an Array of type <i>double</i>, containing 
16004 +                the three co-ordinates of the opposite point of the 
16005 +                cuboid: \n
16006 +                - pmax[0] = X co-ordinate
16007 +                - pmax[1] = Y co-ordinate
16008 +                - pmax[2] = Z co-ordinate
16009 +    \param h    Variable of type <i>double</i>, specifying the maximum
16010 +                allowable mesh size at that point
16011 +*/
16012 +DLL_HEADER void Ng_RestrictMeshSizeBox (Ng_Mesh * mesh, double * pmin, double * pmax, double h);
16013 +
16014 +// ------------------------------------------------------------------
16015 +
16016 +
16017 +
16018 +// ------------------------------------------------------------------
16019 +// 3D Mesh Generation functions
16020 +
16021 +/*! \brief Create a 3D Volume Mesh given a Surface Mesh
16022 +
16023 +    After creating a surface mesh, this function can be utilised 
16024 +    to automatically generate the corresponding 3D Volume Mesh.
16025 +
16026 +    Mesh generation parameters (such as grading, maximum element size, 
16027 +    etc.) are specified via the meshing parameters class which also 
16028 +    needs to be passed to this function.
16029 +
16030 +    <b>Note</b>: Currently, Netgen generates pure tetrahedral volume 
16031 +    meshes.
16032 +
16033 +    \param mesh Pointer to an existing Netgen Mesh structure of 
16034 +                type #Ng_Mesh
16035 +    \param mp   Pointer to a copy of the Meshing Parameters class
16036 +                (#Ng_Meshing_Parameters), filled up with the 
16037 +                required values
16038 +
16039 +    \return Ng_Result Status of the Mesh Generation routine. More 
16040 +                      details regarding the return value can be 
16041 +                      found in the description of #Ng_Result
16042 +*/
16043 +DLL_HEADER Ng_Result Ng_GenerateVolumeMesh (Ng_Mesh * mesh, Ng_Meshing_Parameters * mp);
16044 +
16045 +// ------------------------------------------------------------------
16046 +
16047 +
16048 +
16049 +// ------------------------------------------------------------------
16050 +// Basic Mesh information functions
16051 +
16052 +/*! \brief Returns the Number of Points present in the specified Mesh
16053 +
16054 +    Given an already existent Netgen Mesh Structure, this function 
16055 +    returns the number of points currently present within the Mesh.
16056 +
16057 +    \param mesh Pointer to an existing Netgen Mesh structure of 
16058 +                type #Ng_Mesh
16059 +    \return 
16060 +                Integer Data-type with the number of points in the Mesh
16061 +*/
16062 +DLL_HEADER int Ng_GetNP (Ng_Mesh * mesh);
16063 +
16064 +
16065 +/*! \brief Returns the Number of Surface Elements present in the specified Mesh
16066 +
16067 +    Given an already existent Netgen Mesh Structure, this function 
16068 +    returns the number of surface elements currently present within 
16069 +    the Mesh.
16070 +
16071 +    \param mesh Pointer to an existing Netgen Mesh structure of 
16072 +                type #Ng_Mesh
16073 +    \return 
16074 +                Integer Data-type with the number of surface elements in the Mesh
16075 +*/
16076 +DLL_HEADER int Ng_GetNSE (Ng_Mesh * mesh);
16077 +
16078 +
16079 +/*! \brief Returns the Number of Volume Elements present in the specified Mesh
16080 +
16081 +    Given an already existent Netgen Mesh Structure, this function 
16082 +    returns the number of volume elements currently present within 
16083 +    the Mesh.
16084 +
16085 +    \param mesh Pointer to an existing Netgen Mesh structure of 
16086 +                type #Ng_Mesh
16087 +    \return 
16088 +                Integer Data-type with the number of volume elements in the Mesh
16089 +*/
16090 +DLL_HEADER int Ng_GetNE (Ng_Mesh * mesh);
16091 +
16092 +// ------------------------------------------------------------------
16093 +
16094 +
16095 +
16096 +// ------------------------------------------------------------------
16097 +// Mesh Topology functions
16098 +// Use these functions to extract points, surface / volume elements, 
16099 +// perform topological searches, etc..etc...
16100 +  
16101 +//  Return the Point Coordinates of a specified Point
16102 +// The x, y and z co-ordinates are returned in the array pointer as 
16103 +// x[0] = x ; x[1] = y ; x[2] = z
16104 +DLL_HEADER void Ng_GetPoint (Ng_Mesh * mesh, int num, double * x);
16105 +
16106 +
16107 +
16108 +// return surface and volume element in pi
16109 +DLL_HEADER Ng_Surface_Element_Type 
16110 +Ng_GetSurfaceElement (Ng_Mesh * mesh, int num, int * pi);
16111 +
16112 +DLL_HEADER Ng_Volume_Element_Type
16113 +Ng_GetVolumeElement (Ng_Mesh * mesh, int num, int * pi);
16114 +
16115 +// ------------------------------------------------------------------
16116 +
16117 +
16118 +
16119 +
16120 +// **********************************************************
16121 +// **   2D Meshing                                         **
16122 +// **********************************************************
16123 +
16124 +
16125 +// feeds points and boundary to mesh
16126 +
16127 +DLL_HEADER void Ng_AddPoint_2D (Ng_Mesh * mesh, double * x);
16128 +DLL_HEADER void Ng_AddBoundarySeg_2D (Ng_Mesh * mesh, int pi1, int pi2);
16129 +  
16130 +// ask for number of points, elements and boundary segments
16131 +DLL_HEADER int Ng_GetNP_2D (Ng_Mesh * mesh);
16132 +DLL_HEADER int Ng_GetNE_2D (Ng_Mesh * mesh);
16133 +DLL_HEADER int Ng_GetNSeg_2D (Ng_Mesh * mesh);
16134 +  
16135 +//  return point coordinates
16136 +DLL_HEADER void Ng_GetPoint_2D (Ng_Mesh * mesh, int num, double * x);
16137 +
16138 +// return 2d elements
16139 +DLL_HEADER Ng_Surface_Element_Type 
16140 +Ng_GetElement_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum = NULL);
16141 +
16142 +// return 2d boundary segment
16143 +DLL_HEADER void Ng_GetSegment_2D (Ng_Mesh * mesh, int num, int * pi, int * matnum = NULL);
16144 +
16145 +
16146 +// load 2d netgen spline geometry
16147 +DLL_HEADER Ng_Geometry_2D * Ng_LoadGeometry_2D (const char * filename);
16148 +
16149 +// generate 2d mesh, mesh is allocated by function
16150 +DLL_HEADER Ng_Result Ng_GenerateMesh_2D (Ng_Geometry_2D * geom,
16151 +                                         Ng_Mesh ** mesh,
16152 +                                         Ng_Meshing_Parameters * mp);
16153 +  
16154 +DLL_HEADER void Ng_HP_Refinement (Ng_Geometry_2D * geom,
16155 +                                  Ng_Mesh * mesh,
16156 +                                  int levels);
16157 +  
16158 +
16159 +
16160 +
16161 +
16162 +// **********************************************************
16163 +// **   STL Meshing                                        **
16164 +// **********************************************************
16165 +
16166 +
16167 +// loads geometry from STL file
16168 +DLL_HEADER Ng_STL_Geometry * Ng_STL_LoadGeometry (const char * filename, int binary = 0);
16169 +
16170 +
16171 +// generate new STL Geometry
16172 +DLL_HEADER Ng_STL_Geometry * Ng_STL_NewGeometry ();
16173 +  
16174 +
16175 +// fills STL Geometry
16176 +// positive orientation
16177 +// normal vector may be null-pointer
16178 +DLL_HEADER void Ng_STL_AddTriangle (Ng_STL_Geometry * geom, 
16179 +                         double * p1, double * p2, double * p3, 
16180 +                         double * nv = NULL);
16181 +
16182 +// add (optional) edges :
16183 +DLL_HEADER void Ng_STL_AddEdge (Ng_STL_Geometry * geom, 
16184 +                     double * p1, double * p2);
16185 +
16186 +// after adding triangles (and edges) initialize
16187 +DLL_HEADER Ng_Result Ng_STL_InitSTLGeometry (Ng_STL_Geometry * geom);
16188 +
16189 +// automatically generates edges:
16190 +DLL_HEADER Ng_Result Ng_STL_MakeEdges (Ng_STL_Geometry * geom,
16191 +                            Ng_Mesh* mesh,
16192 +                            Ng_Meshing_Parameters * mp);
16193 +
16194 +
16195 +// generates mesh, empty mesh must be already created.
16196 +DLL_HEADER Ng_Result Ng_STL_GenerateSurfaceMesh (Ng_STL_Geometry * geom,
16197 +                                                 Ng_Mesh * mesh,
16198 +                                                 Ng_Meshing_Parameters * mp);
16199 +
16200 +
16201 +#ifdef ACIS
16202 +
16203 +// **********************************************************
16204 +// **   ACIS Meshing                                       **
16205 +// **********************************************************
16206 +
16207 +/// Data type for NETGEN STL geomty
16208 +typedef void * Ng_ACIS_Geometry;
16209 +
16210 +// loads geometry from STL file
16211 +DLL_HEADER Ng_ACIS_Geometry * Ng_ACIS_LoadGeometry (const char * filename);
16212 +  
16213 +// generates mesh, empty mesh must be already created.
16214 +DLL_HEADER Ng_Result Ng_ACIS_GenerateSurfaceMesh (Ng_ACIS_Geometry * geom,
16215 +                                                  Ng_Mesh * mesh,
16216 +                                                  Ng_Meshing_Parameters * mp);
16217 +
16218 +
16219 +#endif
16220 +
16221 +
16222 +
16223 +#ifdef OCCGEOMETRY
16224 +
16225 +// **********************************************************
16226 +// **   OpenCascade Geometry / Meshing Utilities           **
16227 +// **********************************************************
16228 +
16229 +// Create new OCC Geometry Object
16230 +DLL_HEADER Ng_OCC_Geometry * Ng_OCC_NewGeometry ();
16231 +
16232 +// Delete an OCC Geometry Object
16233 +DLL_HEADER Ng_Result Ng_OCC_DeleteGeometry (Ng_OCC_Geometry * geom);
16234 +
16235 +// Loads geometry from STEP file
16236 +DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_STEP (const char * filename);
16237 +
16238 +// Loads geometry from IGES file
16239 +DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_IGES (const char * filename);
16240 +
16241 +// Loads geometry from BREP file
16242 +DLL_HEADER Ng_OCC_Geometry * Ng_OCC_Load_BREP (const char * filename);
16243 +
16244 +// Set the local mesh size based on geometry / topology
16245 +DLL_HEADER Ng_Result Ng_OCC_SetLocalMeshSize (Ng_OCC_Geometry * geom,
16246 +                                              Ng_Mesh * mesh,
16247 +                                              Ng_Meshing_Parameters * mp);
16248 +
16249 +// Mesh the edges and add Face descriptors to prepare for surface meshing
16250 +DLL_HEADER Ng_Result Ng_OCC_GenerateEdgeMesh (Ng_OCC_Geometry * geom,
16251 +                                              Ng_Mesh * mesh,
16252 +                                              Ng_Meshing_Parameters * mp);
16253 +
16254 +// Mesh the surfaces of an OCC geometry
16255 +DLL_HEADER Ng_Result Ng_OCC_GenerateSurfaceMesh (Ng_OCC_Geometry * geom,
16256 +                                                 Ng_Mesh * mesh,
16257 +                                                 Ng_Meshing_Parameters * mp); 
16258 +
16259 +// Get the face map of an already loaded OCC geometry
16260 +DLL_HEADER Ng_Result Ng_OCC_GetFMap(Ng_OCC_Geometry * geom, 
16261 +                                    Ng_OCC_TopTools_IndexedMapOfShape * FMap);
16262 +
16263 +#endif // OCCGEOMETRY
16264 +
16265 +
16266 +
16267 +// **********************************************************
16268 +// **   Mesh refinement algorithms                         **
16269 +// **********************************************************
16270 +
16271 +// uniform mesh refinement
16272 +DLL_HEADER void Ng_Uniform_Refinement (Ng_Mesh * mesh);
16273 +
16274 +
16275 +// uniform mesh refinement with geometry adaption:
16276 +
16277 +DLL_HEADER void Ng_2D_Uniform_Refinement (Ng_Geometry_2D * geom,
16278 +                                         Ng_Mesh * mesh);
16279 +
16280 +DLL_HEADER void Ng_STL_Uniform_Refinement (Ng_STL_Geometry * geom,
16281 +                                          Ng_Mesh * mesh);
16282 +
16283 +DLL_HEADER void Ng_CSG_Uniform_Refinement (Ng_CSG_Geometry * geom,
16284 +                                          Ng_Mesh * mesh);
16285 +
16286 +#ifdef OCCGEOMETRY
16287 +DLL_HEADER void Ng_OCC_Uniform_Refinement (Ng_OCC_Geometry * geom,
16288 +                                          Ng_Mesh * mesh);
16289 +#endif
16290 +
16291 +
16292 +
16293 +// **********************************************************
16294 +// **   Second Order mesh algorithms                       **
16295 +// **********************************************************
16296 +
16297 +// convert mesh to second order
16298 +DLL_HEADER void Ng_Generate_SecondOrder (Ng_Mesh * mesh);
16299 +
16300 +
16301 +// convert mesh to second order with geometry adaption:
16302 +
16303 +DLL_HEADER void Ng_2D_Generate_SecondOrder (Ng_Geometry_2D * geom,
16304 +                                         Ng_Mesh * mesh);
16305 +
16306 +DLL_HEADER void Ng_STL_Generate_SecondOrder (Ng_STL_Geometry * geom,
16307 +                                          Ng_Mesh * mesh);
16308 +
16309 +DLL_HEADER void Ng_CSG_Generate_SecondOrder (Ng_CSG_Geometry * geom,
16310 +                                          Ng_Mesh * mesh);
16311 +
16312 +#ifdef OCCGEOMETRY
16313 +DLL_HEADER void Ng_OCC_Generate_SecondOrder (Ng_OCC_Geometry * geom,
16314 +                                          Ng_Mesh * mesh);
16315 +#endif
16316 +
16317 +
16318 +#endif // NGLIB