diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 00000000..a0b6bf56 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,97 @@ +cmake_minimum_required (VERSION 2.6.4) + +include (CheckFunctionExists) +include (CheckCSourceCompiles) +include (CheckCXXSourceCompiles) +include (CheckIncludeFile) +include (CPack) + +project(TerraGear) + +set(CMAKE_DEBUG_POSTFIX "d" CACHE STRING "add a postfix, usually d on windows") +set(CMAKE_RELEASE_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows") +set(CMAKE_RELWITHDEBINFO_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows") +set(CMAKE_MINSIZEREL_POSTFIX "" CACHE STRING "add a postfix, usually empty on windows") + +# We have some custom .cmake scripts not in the official distribution. +set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/CMakeModules;${CMAKE_MODULE_PATH}") + +# Change the default build type to something fast +if(NOT CMAKE_BUILD_TYPE) + set(CMAKE_BUILD_TYPE Release CACHE STRING + "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." + FORCE) +endif(NOT CMAKE_BUILD_TYPE) + +# check required dependencies +find_package(Boost REQUIRED) +find_package(ZLIB REQUIRED) +find_package(Threads REQUIRED) +find_package(SimGear 2.5.0 REQUIRED) +find_package(TIFF) # needed for SRTM +find_package(NewMat11) + +check_include_file(unistd.h HAVE_UNISTD_H) +check_include_file(sys/time.h HAVE_SYS_TIME_H) +check_include_file(windows.h HAVE_WINDOWS_H) + +set(PKGDATADIR ${PREFIX}/share) + +if(CMAKE_COMPILER_IS_GNUCXX) + set(WARNING_FLAGS -Wall) +endif(CMAKE_COMPILER_IS_GNUCXX) + +if(WIN32) + + if(MSVC) + # turn off various warnings + # foreach(warning 4244 4251 4267 4275 4290 4786 4305 4996) + # SET(WARNING_FLAGS "${WARNING_FLAGS} /wd${warning}") + # endforeach(warning) + + set(MSVC_FLAGS "-DNOMINMAX -D_USE_MATH_DEFINES -D_CRT_SECURE_NO_WARNINGS -D_SCL_SECURE_NO_WARNINGS -D__CRT_NONSTDC_NO_WARNINGS") + if (${MSVC_VERSION} EQUAL 1600) + set( MSVC_LD_FLAGS "/FORCE:MULTIPLE" ) + endif (${MSVC_VERSION} EQUAL 1600) + endif(MSVC) + + set(NOMINMAX 1) +endif(WIN32) + +set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT") +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS} ${MSVC_FLAGS} -D_REENTRANT") +set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} ${MSVC_LD_FLAGS}") + +include_directories( + ${Boost_INCLUDE_DIRS} + ${ZLIB_INCLUDE_DIR} + ${SIMGEAR_INCLUDE_DIR} + ) + +include_directories(${PROJECT_SOURCE_DIR}/src) +include_directories(${PROJECT_BINARY_DIR}/src/Include) + +add_definitions(-DHAVE_CONFIG_H) + +#check_function_exists(mkfifo HAVE_MKFIFO) + +# configure a header file to pass some of the CMake settings +# to the source code +configure_file ( + "${PROJECT_SOURCE_DIR}/src/Include/config_cmake.h.in" + "${PROJECT_BINARY_DIR}/src/Include/config.h" + ) + +add_subdirectory(src) +#add_subdirectory(gismodules) + +#----------------------------------------------------------------------------- +### uninstall target +#----------------------------------------------------------------------------- +CONFIGURE_FILE( + "${CMAKE_CURRENT_SOURCE_DIR}/CMakeModules/cmake_uninstall.cmake.in" + "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake" + IMMEDIATE @ONLY) +ADD_CUSTOM_TARGET(uninstall + "${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake") + diff --git a/CMakeModules/FindNewMat11.cmake b/CMakeModules/FindNewMat11.cmake new file mode 100644 index 00000000..ed7788a4 --- /dev/null +++ b/CMakeModules/FindNewMat11.cmake @@ -0,0 +1,25 @@ + +FIND_PATH(NEWMAT_INCLUDE_DIR newmat/newmat.h + HINTS $ENV{NEWMAT_DIR} + PATH_SUFFIXES include + PATHS + /usr/local + /usr + /opt +) + + +FIND_LIBRARY(NEWMAT_LIBRARY + NAMES newmat + HINTS + $ENV{NEWMAT_DIR} + PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 + PATHS + /usr/local + /usr + /opt +) + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(newmat DEFAULT_MSG + NEWMAT_LIBRARY NEWMAT_INCLUDE_DIR) diff --git a/CMakeModules/FindSimGear.cmake b/CMakeModules/FindSimGear.cmake new file mode 100644 index 00000000..cd966f0d --- /dev/null +++ b/CMakeModules/FindSimGear.cmake @@ -0,0 +1,219 @@ +# Locate SimGear +# This module defines +# SIMGEAR_LIBRARIES +# SIMGEAR_FOUND, if false, do not try to link to SimGear +# SIMGEAR_INCLUDE_DIR, where to find the headers +# +# $SIMGEAR_DIR is an environment variable that would +# correspond to the ./configure --prefix=$SIMGEAR_DIR +# used in building SimGear. +# +# Created by James Turner. This was influenced by the FindOpenAL.cmake module. + +#============================================================================= +# Copyright 2005-2009 Kitware, Inc. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distributed this file outside of CMake, substitute the full +# License text for the above reference.) + +# Per my request, CMake should search for frameworks first in +# the following order: +# ~/Library/Frameworks/SimGear.framework/Headers +# /Library/Frameworks/SimGear.framework/Headers +# /System/Library/Frameworks/SimGear.framework/Headers +# +# On OS X, this will prefer the Framework version (if found) over others. +# People will have to manually change the cache values of +# SimGear_LIBRARIES to override this selection or set the CMake environment +# CMAKE_INCLUDE_PATH to modify the search paths. + +include(SelectLibraryConfigurations) + +FIND_PATH(SIMGEAR_INCLUDE_DIR simgear/math/SGMath.hxx + HINTS $ENV{SIMGEAR_DIR} + PATH_SUFFIXES include + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /opt +) + +message(STATUS ${SIMGEAR_INCLUDE_DIR}) + +# check for dynamic framework/library +FIND_LIBRARY(SIMGEAR_LIBRARIES + NAMES simgear SimGear + HINTS + $ENV{SIMGEAR_DIR} + PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 + PATHS + ~/Library/Frameworks + /Library/Frameworks + /usr/local + /usr + /opt +) + +# dependent packages +find_package(ZLIB REQUIRED) +find_package(Threads REQUIRED) + +macro(find_sg_component comp libs) + set(compLib "sg${comp}") + string(TOUPPER "SIMGEAR_${comp}" compLibBase) + set( compLibName ${compLibBase}_LIBRARY ) + + FIND_LIBRARY(${compLibName}_DEBUG + NAMES ${compLib}${CMAKE_DEBUG_POSTFIX} + HINTS $ENV{SIMGEAR_DIR} + PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 + PATHS + /usr/local + /usr + /opt + ) + FIND_LIBRARY(${compLibName}_RELEASE + NAMES ${compLib}${CMAKE_RELEASE_POSTFIX} + HINTS $ENV{SIMGEAR_DIR} + PATH_SUFFIXES lib64 lib libs64 libs libs/Win32 libs/Win64 + PATHS + /usr/local + /usr + /opt + ) + select_library_configurations( ${compLibBase} ) + + set(componentLibRelease ${${compLibName}_RELEASE}) + #message(STATUS "Simgear ${compLibName}_RELEASE ${componentLibRelease}") + set(componentLibDebug ${${compLibName}_DEBUG}) + #message(STATUS "Simgear ${compLibName}_DEBUG ${componentLibDebug}") + if (NOT ${compLibName}_DEBUG) + if (NOT ${compLibName}_RELEASE) + #message(STATUS "found ${componentLib}") + list(APPEND ${libs} ${componentLibRelease}) + endif() + else() + list(APPEND ${libs} optimized ${componentLibRelease} debug ${componentLibDebug}) + endif() +endmacro() + + +if(${SIMGEAR_LIBRARIES} STREQUAL "SIMGEAR_LIBRARIES-NOTFOUND") + set(SIMGEAR_LIBRARIES "") # clear value + set(SIMGEAR_CORE_LIBRARIES "") # clear value + + # note the order here affects the order Simgear libraries are + # linked in, and hence ability to link when using a traditional + # linker such as GNU ld on Linux + set(comps + tsync + environment + nasal + bucket + bvh + util + route + timing + io + serial + sound + structure + props + xml + misc + threads + debug + magvar + math) + + set(scene_comps + ephem + sky + material + tgdb + model + screen) + + foreach(component ${comps}) + find_sg_component(${component} SIMGEAR_CORE_LIBRARIES) + endforeach() + + foreach(component ${scene_comps}) + find_sg_component(${component} SIMGEAR_LIBRARIES) + endforeach() + + # again link order matters - scene libraires depend on core ones + list(APPEND SIMGEAR_LIBRARIES ${SIMGEAR_CORE_LIBRARIES}) + + set(SIMGEAR_CORE_LIBRARY_DEPENDENCIES + ${CMAKE_THREAD_LIBS_INIT} + ${ZLIB_LIBRARY}) + + if(WIN32) + list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES ws2_32.lib) + endif(WIN32) + + if(NOT MSVC) + # basic timing routines on non windows systems, may be also cygwin?! + check_function_exists(clock_gettime clock_gettime_in_libc) + if(NOT clock_gettime_in_libc) + check_library_exists(rt clock_gettime "" have_rt) + if(have_rt) + list(APPEND SIMGEAR_CORE_LIBRARY_DEPENDENCIES rt) + endif(have_rt) + endif(NOT clock_gettime_in_libc) + endif(NOT MSVC) + +endif() + +# now we've found SimGear, check its version + +include(CheckCXXSourceRuns) + +message(STATUS "looking for version: ${SimGear_FIND_VERSION}") + +SET(CMAKE_REQUIRED_INCLUDES ${SIMGEAR_INCLUDE_DIR}) + +check_cxx_source_runs( + "#include + #include \"simgear/version.h\" + + #define xstr(s) str(s) + #define str(s) #s + + #define MIN_MAJOR ${SimGear_FIND_VERSION_MAJOR} + #define MIN_MINOR ${SimGear_FIND_VERSION_MINOR} + #define MIN_MICRO ${SimGear_FIND_VERSION_PATCH} + + int main() { + int major, minor, micro; + + /* printf(%d.%d.%d or greater, , MIN_MAJOR, MIN_MINOR, MIN_MICRO); */ + printf(\"found %s ... \", xstr(SIMGEAR_VERSION)); + + sscanf( xstr(SIMGEAR_VERSION), \"%d.%d.%d\", &major, &minor, µ ); + + if ( (major < MIN_MAJOR) || + (major == MIN_MAJOR && minor < MIN_MINOR) || + (major == MIN_MAJOR && minor == MIN_MINOR && micro < MIN_MICRO) ) { + return -1; + } + + return 0; + } + " + SIMGEAR_VERSION_OK) + +include(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(SimGear DEFAULT_MSG + SIMGEAR_LIBRARIES SIMGEAR_INCLUDE_DIR SIMGEAR_VERSION_OK) + diff --git a/CMakeModules/cmake_uninstall.cmake.in b/CMakeModules/cmake_uninstall.cmake.in new file mode 100644 index 00000000..3b6a9d03 --- /dev/null +++ b/CMakeModules/cmake_uninstall.cmake.in @@ -0,0 +1,22 @@ +IF(NOT EXISTS "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt") + MESSAGE(FATAL_ERROR "Cannot find install manifest: \"@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt\"") +ENDIF() + +FILE(READ "@CMAKE_CURRENT_BINARY_DIR@/install_manifest.txt" files) +STRING(REGEX REPLACE "\n" ";" files "${files}") + +FOREACH(file ${files}) + MESSAGE(STATUS "Uninstalling \"${file}\"") + IF(EXISTS "${file}") + EXEC_PROGRAM( + "@CMAKE_COMMAND@" ARGS "-E remove \"${file}\"" + OUTPUT_VARIABLE rm_out + RETURN_VALUE rm_retval + ) + IF(NOT "${rm_retval}" STREQUAL 0) + MESSAGE(FATAL_ERROR "Problem when removing \"${file}\"") + ENDIF() + ELSE() + MESSAGE(STATUS "File \"${file}\" does not exist.") + ENDIF() +ENDFOREACH() diff --git a/src/Airports/CMakeLists.txt b/src/Airports/CMakeLists.txt new file mode 100644 index 00000000..d72a6bdb --- /dev/null +++ b/src/Airports/CMakeLists.txt @@ -0,0 +1,6 @@ +include_directories(${PROJECT_SOURCE_DIR}/src/Lib) +include_directories(${PROJECT_SOURCE_DIR}/src/BuildTiles) + +if (NEWMAT_FOUND) +add_subdirectory(GenAirports) +endif (NEWMAT_FOUND) \ No newline at end of file diff --git a/src/Airports/GenAirports/CMakeLists.txt b/src/Airports/GenAirports/CMakeLists.txt new file mode 100644 index 00000000..9f4c3b8c --- /dev/null +++ b/src/Airports/GenAirports/CMakeLists.txt @@ -0,0 +1,31 @@ + + +add_executable(genapts + apt_surface.hxx apt_surface.cxx + build.cxx build.hxx + convex_hull.cxx convex_hull.hxx + elevations.cxx elevations.hxx + global.hxx + lights.hxx lights.cxx + main.cxx + point2d.cxx point2d.hxx + poly_extra.cxx poly_extra.hxx + runway.cxx runway.hxx + rwy_common.cxx rwy_common.hxx + rwy_nonprec.cxx rwy_nonprec.hxx + rwy_prec.cxx rwy_prec.hxx + rwy_simple.cxx rwy_simple.hxx + rwy_visual.cxx rwy_visual.hxx + taxiway.cxx taxiway.hxx + texparams.hxx + ) + +target_link_libraries(genapts + Polygon Geometry + Array Optimize Output poly2tri + TriangleJRS + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} + genpolyclip + ${NEWMAT_LIBRARY}) + diff --git a/src/Airports/GenAirports/build.cxx b/src/Airports/GenAirports/build.cxx index 5c3237cf..b7160d3f 100644 --- a/src/Airports/GenAirports/build.cxx +++ b/src/Airports/GenAirports/build.cxx @@ -843,7 +843,6 @@ void build_airport( string airport_id, float alt_m, rwy_polys[i].set_tris( tri ); rwy_polys[i].set_texcoords( tc ); - rwy_polys[i].set_tri_mode( GL_TRIANGLES ); } SG_LOG(SG_GENERAL, SG_DEBUG, "Tesselating base"); diff --git a/src/BuildTiles/CMakeLists.txt b/src/BuildTiles/CMakeLists.txt new file mode 100644 index 00000000..1f6072d3 --- /dev/null +++ b/src/BuildTiles/CMakeLists.txt @@ -0,0 +1,11 @@ + + +include_directories(${PROJECT_SOURCE_DIR}/src/Lib) +include_directories(${PROJECT_SOURCE_DIR}/src/BuildTiles) + +add_subdirectory(Osgb36) +add_subdirectory(Triangulate) +add_subdirectory(Clipper) +add_subdirectory(GenOutput) +add_subdirectory(Match) +add_subdirectory(Main) diff --git a/src/BuildTiles/Clipper/CMakeLists.txt b/src/BuildTiles/Clipper/CMakeLists.txt new file mode 100644 index 00000000..25b53a74 --- /dev/null +++ b/src/BuildTiles/Clipper/CMakeLists.txt @@ -0,0 +1,13 @@ + + +add_library(Clipper STATIC + clipper.cxx clipper.hxx priorities.cxx priorities.hxx +) + +add_executable(testclipper testclipper.cxx) + +target_link_libraries(testclipper + Clipper Osgb36 Triangulate Polygon Geometry + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} + genpolyclip) diff --git a/src/BuildTiles/GenOutput/CMakeLists.txt b/src/BuildTiles/GenOutput/CMakeLists.txt new file mode 100644 index 00000000..ef32931c --- /dev/null +++ b/src/BuildTiles/GenOutput/CMakeLists.txt @@ -0,0 +1,5 @@ + + +add_library(GenOutput STATIC + genobj.cxx genobj.hxx +) diff --git a/src/BuildTiles/Main/CMakeLists.txt b/src/BuildTiles/Main/CMakeLists.txt new file mode 100644 index 00000000..02e09df7 --- /dev/null +++ b/src/BuildTiles/Main/CMakeLists.txt @@ -0,0 +1,28 @@ + + +add_executable(fgfs-construct + construct.cxx construct.hxx + usgs.cxx main.cxx) + +set_target_properties(fgfs-construct PROPERTIES + COMPILE_DEFINITIONS + "DEFAULT_USGS_MAPFILE=\"${PKGDATADIR}/usgsmap.txt\";DEFAULT_PRIORITIES_FILE=\"${PKGDATADIR}/default_priorities.txt\"" ) + +target_link_libraries(fgfs-construct + Clipper Osgb36 Triangulate GenOutput + Match + Polygon Geometry + Array Optimize Output landcover poly2tri + TriangleJRS + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} + genpolyclip) + + +add_executable(fgfs-master + master.cxx) + +target_link_libraries(fgfs-master + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} + ) \ No newline at end of file diff --git a/src/BuildTiles/Main/main.cxx b/src/BuildTiles/Main/main.cxx index 032e6644..43eae2ab 100644 --- a/src/BuildTiles/Main/main.cxx +++ b/src/BuildTiles/Main/main.cxx @@ -39,11 +39,14 @@ #include #include -#include - #include #include #include +#include +#include +#include + +#include #include #include @@ -82,50 +85,35 @@ double nudge=0.0; // Scan a directory and load polygon files. -static int actual_load_polys( const string& dir, +static int actual_load_polys( const SGPath& dir, TGConstruct& c, TGClipper& clipper ) { int counter = 0; - string base = c.get_bucket().gen_base_path(); - string tile_str = c.get_bucket().gen_index_str(); - string ext; - string file, f_index, full_path; - int pos; + // string base = c.get_bucket().gen_base_path(); + //string tile_str = c.get_bucket().gen_index_str(); - ulDir *d; - struct ulDirEnt *de; - - if ( (d = ulOpenDir( dir.c_str() )) == NULL ) { - cout << "cannot open directory " << dir << "\n"; - return 0; + simgear::Dir d(dir); + if (!d.exists()) { + cout << "directory not found:" << dir.str() << "\n"; + return 0; } - - // load all matching polygon files - while ( (de = ulReadDir(d)) != NULL ) { - file = de->d_name; - pos = file.find("."); - f_index = file.substr(0, pos); - - if ( tile_str == f_index ) { - ext = file.substr(pos + 1); - cout << file << " " << f_index << " '" << ext << "'" << endl; - full_path = dir + "/" + file; - if ( (ext == "arr") || (ext == "arr.gz") || - (ext == "fit") || (ext == "fit.gz") || (ext == "ind") ) { - // skip - } else if (ext == "osgb36") { - cout << "Loading osgb36 poly definition file\n"; - clipper.load_osgb36_polys( full_path ); - ++counter; - } else { - cout << "ext = '" << ext << "'" << endl; - clipper.load_polys( full_path ); - ++counter; - } + + BOOST_FOREACH(const SGPath& p, d.children(simgear::Dir::TYPE_FILE)) { + string lext = p.complete_lower_extension(); + if ((lext == "arr") || (lext == "arr.gz") || + (lext == "fit") || (lext == "fit.gz") || (lext == "ind")) + { + // skipped! + } else if (lext == "osgb36") { + cout << "Loading osgb36 poly definition file\n"; + clipper.load_osgb36_polys( p.str() ); + ++counter; + } else { + cout << "ext = '" << lext << "'" << endl; + clipper.load_polys( p.str() ); + ++counter; } - } - - ulCloseDir(d); + } // of directory file children return counter; } @@ -745,7 +733,7 @@ static double tri_ele_area( const TGConstruct& c, const TGTriEle tri ) { // caclulate the normal for the specified triangle face static Point3D calc_normal( TGConstruct& c, int i ) { - sgVec3 v1, v2, normal; + SGVec3d v1, v2, normal; point_list wgs84_nodes = c.get_wgs84_nodes(); triele_list tri_elements = c.get_tri_elements(); @@ -786,19 +774,16 @@ static Point3D calc_normal( TGConstruct& c, int i ) { } if ( degenerate ) { - sgSetVec3( normal, p1.x(), p1.y(), p1.z() ); - sgNormalizeVec3( normal ); - cout << "Degenerate tri!" << endl; + normal = normalize(SGVec3d(p1.x(), p1.y(), p1.z())); + cout << "Degenerate tri!" << endl; } else { - v1[0] = p2.x() - p1.x(); - v1[1] = p2.y() - p1.y(); - v1[2] = p2.z() - p1.z(); - v2[0] = p3.x() - p1.x(); - v2[1] = p3.y() - p1.y(); - v2[2] = p3.z() - p1.z(); - - sgVectorProductVec3( normal, v1, v2 ); - sgNormalizeVec3( normal ); + v1[0] = p2.x() - p1.x(); + v1[1] = p2.y() - p1.y(); + v1[2] = p2.z() - p1.z(); + v2[0] = p3.x() - p1.x(); + v2[1] = p3.y() - p1.y(); + v2[2] = p3.z() - p1.z(); + normal = normalize(cross(v1, v2)); } return Point3D( normal[0], normal[1], normal[2] ); diff --git a/src/BuildTiles/Match/CMakeLists.txt b/src/BuildTiles/Match/CMakeLists.txt new file mode 100644 index 00000000..86efd725 --- /dev/null +++ b/src/BuildTiles/Match/CMakeLists.txt @@ -0,0 +1,5 @@ + + +add_library(Match STATIC + match.cxx match.hxx +) diff --git a/src/BuildTiles/Osgb36/CMakeLists.txt b/src/BuildTiles/Osgb36/CMakeLists.txt new file mode 100644 index 00000000..a8a91bf8 --- /dev/null +++ b/src/BuildTiles/Osgb36/CMakeLists.txt @@ -0,0 +1,8 @@ + + +add_library(Osgb36 STATIC + osgb36.cxx osgb36.hxx osgbtc.cxx osgbtc.hxx uk.cxx uk.hxx +) + +add_executable(testosgb36 testosgb36.cxx) +target_link_libraries(testosgb36 Osgb36) diff --git a/src/BuildTiles/Triangulate/CMakeLists.txt b/src/BuildTiles/Triangulate/CMakeLists.txt new file mode 100644 index 00000000..4b99f448 --- /dev/null +++ b/src/BuildTiles/Triangulate/CMakeLists.txt @@ -0,0 +1,6 @@ + + +add_library(Triangulate STATIC + triangle.cxx triangle.hxx + trieles.cxx trieles.hxx +) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 00000000..0fb464e6 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,6 @@ + + +add_subdirectory(Prep) +add_subdirectory(Lib) +add_subdirectory(Airports) +add_subdirectory(BuildTiles) \ No newline at end of file diff --git a/src/Include/config_cmake.h.in b/src/Include/config_cmake.h.in new file mode 100644 index 00000000..1a5b6567 --- /dev/null +++ b/src/Include/config_cmake.h.in @@ -0,0 +1,4 @@ +#cmakedefine HAVE_SYS_TIME_H +#cmakedefine HAVE_WINDOWS_H + + diff --git a/src/Lib/Array/CMakeLists.txt b/src/Lib/Array/CMakeLists.txt new file mode 100644 index 00000000..290abe55 --- /dev/null +++ b/src/Lib/Array/CMakeLists.txt @@ -0,0 +1,12 @@ + + +add_library(Array STATIC + array.cxx array.hxx +) + +add_executable(test_array testarray.cxx) + +target_link_libraries(test_array + Array + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}) diff --git a/src/Lib/CMakeLists.txt b/src/Lib/CMakeLists.txt new file mode 100644 index 00000000..c8cc4e94 --- /dev/null +++ b/src/Lib/CMakeLists.txt @@ -0,0 +1,20 @@ + +include_directories(${PROJECT_SOURCE_DIR}/src/Lib) + +# seems unfortunate that lib depends on other dirs +include_directories(${PROJECT_SOURCE_DIR}/src/BuildTiles) + +add_subdirectory(Array) +add_subdirectory(Dem) +add_subdirectory(Geometry) +add_subdirectory(HGT) +add_subdirectory(Optimize) +add_subdirectory(Output) +add_subdirectory(Polygon) +add_subdirectory(TriangleJRS) +add_subdirectory(e00) +add_subdirectory(landcover) +add_subdirectory(poly2tri) +add_subdirectory(shapelib) +add_subdirectory(vpf) + diff --git a/src/Lib/DEM/CMakeLists.txt b/src/Lib/DEM/CMakeLists.txt new file mode 100644 index 00000000..b85a54e9 --- /dev/null +++ b/src/Lib/DEM/CMakeLists.txt @@ -0,0 +1,5 @@ + + +add_library(DEM STATIC + dem.cxx dem.hxx +) diff --git a/src/Lib/Geometry/CMakeLists.txt b/src/Lib/Geometry/CMakeLists.txt new file mode 100644 index 00000000..bbf8bba8 --- /dev/null +++ b/src/Lib/Geometry/CMakeLists.txt @@ -0,0 +1,19 @@ + + +add_library(Geometry STATIC + contour_tree.cxx + line.cxx + poly_support.cxx + rectangle.cxx + trinodes.cxx + trisegs.cxx + util.cxx + contour_tree.hxx + line.hxx + point3d.hxx + poly_support.hxx + rectangle.hxx + trinodes.hxx + trisegs.hxx + util.hxx +) diff --git a/src/Lib/HGT/CMakeLists.txt b/src/Lib/HGT/CMakeLists.txt new file mode 100644 index 00000000..7d3bf27d --- /dev/null +++ b/src/Lib/HGT/CMakeLists.txt @@ -0,0 +1,13 @@ + + +add_library(HGT STATIC + hgt.cxx hgt.hxx + srtmbase.cxx srtmbase.hxx +) + +add_executable(test_hgt testhgt.cxx) + +target_link_libraries(test_hgt + HGT + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}) diff --git a/src/Lib/HGT/hgt.cxx b/src/Lib/HGT/hgt.cxx index 96216333..66e887d1 100644 --- a/src/Lib/HGT/hgt.cxx +++ b/src/Lib/HGT/hgt.cxx @@ -42,8 +42,9 @@ #include #include +#include -#include +#include #include "hgt.hxx" @@ -81,7 +82,7 @@ TGHgt::open ( const SGPath &f ) { // open input file (or read from stdin) if ( file_name.str() == "-" ) { - cout << "Loading HGT data file: stdin" << endl; + cout << "Loading HGT data file: stdin" << endl; if ( (fd = gzdopen(0, "r")) == NULL ) { // 0 == STDIN_FILENO cout << "ERROR: opening stdin" << endl; return false; @@ -90,31 +91,24 @@ TGHgt::open ( const SGPath &f ) { if ( file_name.extension() == "zip" ) { // extract the .zip file to /tmp and point the file name // to the extracted file - SGPath tmp_dir = string( tempnam( 0, "hgt" ) ); - tmp_dir.append( "dummy" ); - tmp_dir.create_dir( 0700 ); - cout << "Extracting " << file_name.str() << " to " << tmp_dir.dir() << endl; - string command = "unzip -d \"" + tmp_dir.dir() + "\" " + file_name.base(); - system( command.c_str() ); - - file_name = tmp_dir.dir(); - ulDir *dir = ulOpenDir( tmp_dir.dir().c_str() ); - if ( dir ) { - ulDirEnt *de; - while ( ( de = ulReadDir( dir ) ) != 0 ) { - if ( !strcmp(de->d_name,".") || !strcmp(de->d_name,"..") || de->d_isdir ) { - continue; - } - SGPath file( de->d_name ); - string ext = file.extension(); - if ( ext == "HGT" || ext == "hgt" ) { - file_name.append( de->d_name ); - break; - } - } - ulCloseDir( dir ); - } + SGPath tmp_dir_path = string( tempnam( 0, "hgt" ) ); + simgear::Dir tmp_dir(tmp_dir_path); + + SGPath dummy = tmp_dir.file( "dummy" ); + dummy.create_dir( 0700 ); + cout << "Extracting " << file_name.str() << " to " << tmp_dir_path.str() << endl; + string command = "unzip -d \"" + tmp_dir_path.str() + "\" " + file_name.base(); + system( command.c_str() ); + simgear::PathList files = tmp_dir.children(simgear::Dir::TYPE_FILE | simgear::Dir::NO_DOT_OR_DOTDOT); + BOOST_FOREACH(const SGPath& file, files) { + string ext = file.extension(); + if ( ext == "HGT" || ext == "hgt" ) { + file_name = file; + break; + } + } + remove_tmp_file = true; remove_file_name = file_name.str(); @@ -203,19 +197,12 @@ TGHgt::~TGHgt() { delete [] data; delete [] output_data; if ( remove_tmp_file ) { - ulDir *dir = ulOpenDir( remove_file_name.dir().c_str() ); - if ( dir ) { - ulDirEnt *de; - while ( ( de = ulReadDir( dir ) ) != 0 ) { - if ( !strcmp(de->d_name,".") || !strcmp(de->d_name,"..") || de->d_isdir ) { - continue; - } - SGPath file( remove_file_name.dir() ); - file.append( de->d_name ); - unlink( file.c_str() ); - } - ulCloseDir( dir ); - } + simgear::Dir dir(remove_file_name.dir()); + simgear::PathList files = dir.children(simgear::Dir::TYPE_FILE | simgear::Dir::NO_DOT_OR_DOTDOT); + BOOST_FOREACH(const SGPath& file, files) { + unlink( file.c_str() ); + } + rmdir( remove_file_name.dir().c_str() ); } } diff --git a/src/Lib/Optimize/CMakeLists.txt b/src/Lib/Optimize/CMakeLists.txt new file mode 100644 index 00000000..6011eb70 --- /dev/null +++ b/src/Lib/Optimize/CMakeLists.txt @@ -0,0 +1,9 @@ + + +add_library(Optimize STATIC + genfans.cxx + genfans.hxx + genstrips.cxx + genstrips.hxx +) + diff --git a/src/Lib/Output/CMakeLists.txt b/src/Lib/Output/CMakeLists.txt new file mode 100644 index 00000000..9e836a20 --- /dev/null +++ b/src/Lib/Output/CMakeLists.txt @@ -0,0 +1,5 @@ + + +add_library(Output STATIC + output.cxx output.hxx +) diff --git a/src/Lib/Polygon/CMakeLists.txt b/src/Lib/Polygon/CMakeLists.txt new file mode 100644 index 00000000..e006a243 --- /dev/null +++ b/src/Lib/Polygon/CMakeLists.txt @@ -0,0 +1,16 @@ + + +add_library(Polygon STATIC + chop-bin.cxx + index.cxx + polygon.cxx + simple_clip.cxx + superpoly.cxx + chop.hxx + index.hxx + names.hxx + point2d.hxx + polygon.hxx + simple_clip.hxx + superpoly.hxx +) \ No newline at end of file diff --git a/src/Lib/Polygon/superpoly.cxx b/src/Lib/Polygon/superpoly.cxx index f83f8c8a..65b5d6e7 100644 --- a/src/Lib/Polygon/superpoly.cxx +++ b/src/Lib/Polygon/superpoly.cxx @@ -43,5 +43,4 @@ void TGSuperPoly::erase() { normals.erase(); texcoords.erase(); tris.erase(); - tri_mode = (GLenum)0; } diff --git a/src/Lib/Polygon/superpoly.hxx b/src/Lib/Polygon/superpoly.hxx index c08d7895..1f54de92 100644 --- a/src/Lib/Polygon/superpoly.hxx +++ b/src/Lib/Polygon/superpoly.hxx @@ -36,11 +36,6 @@ #include #include -#ifdef _MSC_VER -# include -#endif -#include - #include "polygon.hxx" class TGSuperPoly { @@ -52,7 +47,6 @@ private: TGPolygon normals; // corresponding normals TGPolygon texcoords; // corresponding texture coordinates TGPolygon tris; // triangulation - GLenum tri_mode; // GL_TRIANGLE, GL_FAN, GL_TRISTRIP, etc. std::string flag; // For various potential record keeping needs public: @@ -76,9 +70,6 @@ public: inline TGPolygon get_tris() const { return tris; } inline void set_tris( const TGPolygon &p ) { tris = p; } - inline GLenum get_tri_mode() const { return tri_mode; } - inline void set_tri_mode( const GLenum &m ) { tri_mode = m; } - inline std::string get_flag() const { return flag; } inline void set_flag( const std::string f ) { flag = f; } diff --git a/src/Lib/TriangleJRS/CMakeLists.txt b/src/Lib/TriangleJRS/CMakeLists.txt new file mode 100644 index 00000000..7108d4d9 --- /dev/null +++ b/src/Lib/TriangleJRS/CMakeLists.txt @@ -0,0 +1,16 @@ + + +add_library(TriangleJRS STATIC + tri_support.c + tri_support.h + triangle.c + triangle.h +) + +set_target_properties(TriangleJRS PROPERTIES + COMPILE_DEFINITIONS TRILIBRARY ) + +add_executable(test_triangle test_triangle.c) + +target_link_libraries(test_triangle + TriangleJRS) diff --git a/src/Lib/e00/CMakeLists.txt b/src/Lib/e00/CMakeLists.txt new file mode 100644 index 00000000..3fcb563c --- /dev/null +++ b/src/Lib/e00/CMakeLists.txt @@ -0,0 +1,12 @@ + + +add_library(e00 STATIC + e00.hxx e00.cxx +) + +add_executable(teste00 teste00.cxx) + +target_link_libraries(teste00 + e00 + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}) diff --git a/src/Lib/landcover/CMakeLists.txt b/src/Lib/landcover/CMakeLists.txt new file mode 100644 index 00000000..34cea562 --- /dev/null +++ b/src/Lib/landcover/CMakeLists.txt @@ -0,0 +1,10 @@ + + +add_library(landcover STATIC + landcover.cxx landcover.hxx +) + +add_executable(test_landcover test-landcover.cxx) + +target_link_libraries(test_landcover + landcover) diff --git a/src/Lib/poly2tri/CMakeLists.txt b/src/Lib/poly2tri/CMakeLists.txt new file mode 100644 index 00000000..489117b4 --- /dev/null +++ b/src/Lib/poly2tri/CMakeLists.txt @@ -0,0 +1,11 @@ + + +add_library(poly2tri STATIC + construct.c + interface.h + misc.c + monotone.c + tri.c + triangulate.h +) + diff --git a/src/Lib/shapelib/CMakeLists.txt b/src/Lib/shapelib/CMakeLists.txt new file mode 100644 index 00000000..9875c2ba --- /dev/null +++ b/src/Lib/shapelib/CMakeLists.txt @@ -0,0 +1,22 @@ + + +add_library(shape STATIC + dbfopen.c shpopen.c shapefil.h +) + +foreach( c + shpcreate + shpadd + shpdump + shputils + shptest + dbfdump + dbfadd + dbfcreate + ) + + add_executable(${c} ${c}.c) + target_link_libraries(${c} shape) +endforeach( c ) + + diff --git a/src/Lib/vpf/CMakeLists.txt b/src/Lib/vpf/CMakeLists.txt new file mode 100644 index 00000000..1ebb362f --- /dev/null +++ b/src/Lib/vpf/CMakeLists.txt @@ -0,0 +1,44 @@ + + +add_library(vpf STATIC + component.cxx + component.hxx + contour.cxx + contour.hxx + coverage.cxx + coverage.hxx + database.cxx + database.hxx + feature.cxx + feature.hxx + label.cxx + label.hxx + library.cxx + library.hxx + line.cxx + line.hxx + polygon.cxx + polygon.hxx + property.cxx + property.hxx + table.cxx + table.hxx + tablemgr.cxx + tablemgr.hxx + tile.cxx + tile.hxx + value.cxx + value.hxx + vpf.hxx + vpfbase.cxx + vpfbase.hxx +) + +add_executable(vpf-dump vpf-dump.cxx) +target_link_libraries(vpf-dump vpf) + +add_executable(vpf-summary vpf-summary.cxx) +target_link_libraries(vpf-summary vpf) + +add_executable(vpf-topology vpf-topology.cxx) +target_link_libraries(vpf-topology vpf) diff --git a/src/Prep/CMakeLists.txt b/src/Prep/CMakeLists.txt new file mode 100644 index 00000000..dc8aa368 --- /dev/null +++ b/src/Prep/CMakeLists.txt @@ -0,0 +1,18 @@ + + +include_directories(${PROJECT_SOURCE_DIR}/src/Lib) + +# seems unfortunate that lib depends on other dirs +#include_directories(${PROJECT_SOURCE_DIR}/src/BuildTiles) + +add_subdirectory(GSHHS) +add_subdirectory(DemChop) +add_subdirectory(E00Lines) +add_subdirectory(ShapeFile) +add_subdirectory(TGVPF) +add_subdirectory(Terra) +add_subdirectory(TerraFit) + + + + diff --git a/src/Prep/DemChop/CMakeLists.txt b/src/Prep/DemChop/CMakeLists.txt new file mode 100644 index 00000000..49ba5704 --- /dev/null +++ b/src/Prep/DemChop/CMakeLists.txt @@ -0,0 +1,37 @@ + +add_executable(demchop demchop.cxx point2d.hxx) + +target_link_libraries(demchop + DEM + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}) + +add_executable(hgtchop hgtchop.cxx point2d.hxx) + +target_link_libraries(hgtchop + HGT + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}) + +if(TIFF_FOUND) +add_executable(srtmchop srtmchop.cxx point2d.hxx) +target_link_libraries(srtmchop + HGT + ${TIFF_LIBRARIES} + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}) + +endif(TIFF_FOUND) + +add_executable(fillvoids fillvoids.cxx) +target_link_libraries(fillvoids + Array + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}) + +add_executable(testassem testassem.cxx) +target_link_libraries(testassem + Array + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}) + \ No newline at end of file diff --git a/src/Prep/DemChop/srtmchop.cxx b/src/Prep/DemChop/srtmchop.cxx index f05d4a27..0d15507b 100644 --- a/src/Prep/DemChop/srtmchop.cxx +++ b/src/Prep/DemChop/srtmchop.cxx @@ -40,13 +40,14 @@ #include #include #include +#include + +#include #include #include -#include - #include #include @@ -105,14 +106,14 @@ TGSrtmTiff::TGSrtmTiff( const SGPath &file, LoadKind lk ) { remove_tmp_file = false; output_data = 0; if ( lkind == BottomLeft ) { - data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE]; - output_data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE]; + data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE]; + output_data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE]; } else if ( lkind == TopLeft ) { - data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE]; + data = new short int[MAX_HGT_SIZE][MAX_HGT_SIZE]; } else if ( lkind == BottomRight ) { - data = new short int[1][MAX_HGT_SIZE]; + data = new short int[1][MAX_HGT_SIZE]; } else /* if ( lkind == TopRight ) */ { - data = new short int[1][MAX_HGT_SIZE]; + data = new short int[1][MAX_HGT_SIZE]; } TGSrtmTiff::open( file ); } @@ -121,38 +122,31 @@ TGSrtmTiff::~TGSrtmTiff() { delete[] data; delete[] output_data; if ( remove_tmp_file ) { - ulDir *dir = ulOpenDir( remove_file_name.dir().c_str() ); - if ( dir ) { - ulDirEnt *de; - while ( ( de = ulReadDir( dir ) ) != 0 ) { - if ( !strcmp(de->d_name,".") || !strcmp(de->d_name,"..") || de->d_isdir ) { - continue; - } - SGPath file( remove_file_name.dir() ); - file.append( de->d_name ); - unlink( file.c_str() ); - } - ulCloseDir( dir ); - } + simgear::Dir dir(remove_file_name.dir()); + simgear::PathList files = dir.children(simgear::Dir::TYPE_FILE | simgear::Dir::NO_DOT_OR_DOTDOT); + BOOST_FOREACH(const SGPath& file, files) { + unlink( file.c_str() ); + } + rmdir( remove_file_name.dir().c_str() ); } if ( tif ) - TIFFClose( tif ); + TIFFClose( tif ); } bool TGSrtmTiff::pos_from_name( string name, string &pfx, int &x, int &y ) { size_t p = name.find( '_' ); if ( p == string::npos ) - return false; + return false; pfx = name.substr( 0, p ); name.erase( 0, p + 1 ); p = name.find( '.' ); if ( p == string::npos ) - return false; + return false; name.erase( p ); p = name.find( '_' ); if ( p == string::npos ) - return false; + return false; x = atoi( name.substr( 0, p ).c_str() ); y = atoi( name.substr( p+1 ).c_str() ); @@ -168,31 +162,23 @@ bool TGSrtmTiff::open( const SGPath &f ) { if ( ext == "zip" ) { // extract the .zip file to /tmp and point the file name // to the extracted file - SGPath tmp_dir = string( tempnam( 0, "hgt" ) ); - tmp_dir.append( "dummy" ); - tmp_dir.create_dir( 0700 ); - cout << "Extracting " << file_name.str() << " to " << tmp_dir.dir() << endl; - string command = "unzip -d \"" + tmp_dir.dir() + "\" " + file_name.str(); + SGPath tmp_dir_path = string( tempnam( 0, "srtm" ) ); + simgear::Dir tmp_dir(tmp_dir_path); + SGPath dummy = tmp_dir.file( "dummy" ); + dummy.create_dir( 0700 ); + cout << "Extracting " << file_name.str() << " to " << tmp_dir_path.str() << endl; + string command = "unzip -d \"" + tmp_dir_path.str() + "\" " + file_name.base(); system( command.c_str() ); - file_name = tmp_dir.dir(); - ulDir *dir = ulOpenDir( tmp_dir.dir().c_str() ); - if ( dir ) { - ulDirEnt *de; - while ( ( de = ulReadDir( dir ) ) != 0 ) { - if ( !strcmp(de->d_name,".") || !strcmp(de->d_name,"..") || de->d_isdir ) { - continue; - } - SGPath file( de->d_name ); - string ext = file.extension(); - if ( ext == "TIF" || ext == "tif" ) { - file_name.append( de->d_name ); - break; - } - } - ulCloseDir( dir ); - } - + simgear::PathList files = tmp_dir.children(simgear::Dir::TYPE_FILE | simgear::Dir::NO_DOT_OR_DOTDOT); + BOOST_FOREACH(const SGPath& file, files) { + string ext = file.extension(); + if ( ext == "TIF" || ext == "tif" ) { + file_name = file; + break; + } + } + remove_tmp_file = true; remove_file_name = file_name.str(); @@ -232,122 +218,122 @@ bool TGSrtmTiff::load() { tdata_t buf = _TIFFmalloc( TIFFScanlineSize( tif ) ); if ( lkind == BottomLeft ) { - uint32 row = 0; - for ( ; row < h; row++ ) { - TIFFReadScanline( tif, buf, row ); - uint32 col = 0; - for ( ; col < w; col++ ) { - int16 v = ((int16*)buf)[col]; - if ( v == -32768 ) - v = 0; - data[col][6000-1-row] = v; - } - for ( ; col < 6000; col++ ) { - data[col][6000-1-row] = 0; - } - } - for ( ; row < 6000; row++ ) { - uint32 col = 0; - for ( ; col < 6000; col++ ) { - data[col][6000-1-row] = 0; - } - } - int x1 = int( originx / 18000.0 ) + 37, - y1 = int( 12 - ( originy / 18000.0 ) ), - x2 = x1 + 1, - y2 = y1 - 1; - if ( x2 > 72 ) - x2 -= 72; - { - ostringstream name; - name << prefix << "_" << std::setfill( '0' ) << std::setw( 2 ) << x2 << "_" << std::setfill( '0' ) << std::setw( 2 ) << y1 << "." << ext; - SGPath f = dir; - f.append( name.str() ); - if ( f.exists() ) { - TGSrtmTiff s( f.str(), BottomRight ); - s.load(); - s.close(); - for ( int i = 0; i < 6000; ++i ) { - data[6000][i] = s.data[0][i]; - } - } else { - for ( int i = 0; i < 6000; ++i ) { - data[6000][i] = 0; - } - } - } - if ( y2 != 0 ) { - ostringstream name; - name << prefix << "_" << std::setfill( '0' ) << std::setw( 2 ) << x1 << "_" << std::setfill( '0' ) << std::setw( 2 ) << y2 << "." << ext; - SGPath f = dir; - f.append( name.str() ); - if ( f.exists() ) { - TGSrtmTiff s( f.str(), TopLeft ); - s.load(); - s.close(); - for ( int i = 0; i < 6000; ++i ) { - data[i][6000] = s.data[i][0]; - } - } else { - for ( int i = 0; i < 6000; ++i ) { - data[i][6000] = 0; - } - } - } else { - for ( int i = 0; i < 6000; ++i ) { - data[i][6000] = data[i][6000-1]; - } - } - if ( y2 != 0 ) { - ostringstream name; - name << prefix << "_" << std::setfill( '0' ) << std::setw( 2 ) << x2 << "_" << std::setfill( '0' ) << std::setw( 2 ) << y2 << "." << ext; - SGPath f = dir; - f.append( name.str() ); - if ( f.exists() ) { - TGSrtmTiff s( f.str(), TopRight ); - s.load(); - s.close(); - data[6000][6000] = s.data[0][0]; - } else { - data[6000][6000] = 0; - } - } else { - data[6000][6000] = data[6000][6000-1]; - } + uint32 row = 0; + for ( ; row < h; row++ ) { + TIFFReadScanline( tif, buf, row ); + uint32 col = 0; + for ( ; col < w; col++ ) { + int16 v = ((int16*)buf)[col]; + if ( v == -32768 ) + v = 0; + data[col][6000-1-row] = v; + } + for ( ; col < 6000; col++ ) { + data[col][6000-1-row] = 0; + } + } + for ( ; row < 6000; row++ ) { + uint32 col = 0; + for ( ; col < 6000; col++ ) { + data[col][6000-1-row] = 0; + } + } + int x1 = int( originx / 18000.0 ) + 37, + y1 = int( 12 - ( originy / 18000.0 ) ), + x2 = x1 + 1, + y2 = y1 - 1; + if ( x2 > 72 ) + x2 -= 72; + { + ostringstream name; + name << prefix << "_" << std::setfill( '0' ) << std::setw( 2 ) << x2 << "_" << std::setfill( '0' ) << std::setw( 2 ) << y1 << "." << ext; + SGPath f = dir; + f.append( name.str() ); + if ( f.exists() ) { + TGSrtmTiff s( f.str(), BottomRight ); + s.load(); + s.close(); + for ( int i = 0; i < 6000; ++i ) { + data[6000][i] = s.data[0][i]; + } + } else { + for ( int i = 0; i < 6000; ++i ) { + data[6000][i] = 0; + } + } + } + if ( y2 != 0 ) { + ostringstream name; + name << prefix << "_" << std::setfill( '0' ) << std::setw( 2 ) << x1 << "_" << std::setfill( '0' ) << std::setw( 2 ) << y2 << "." << ext; + SGPath f = dir; + f.append( name.str() ); + if ( f.exists() ) { + TGSrtmTiff s( f.str(), TopLeft ); + s.load(); + s.close(); + for ( int i = 0; i < 6000; ++i ) { + data[i][6000] = s.data[i][0]; + } + } else { + for ( int i = 0; i < 6000; ++i ) { + data[i][6000] = 0; + } + } + } else { + for ( int i = 0; i < 6000; ++i ) { + data[i][6000] = data[i][6000-1]; + } + } + if ( y2 != 0 ) { + ostringstream name; + name << prefix << "_" << std::setfill( '0' ) << std::setw( 2 ) << x2 << "_" << std::setfill( '0' ) << std::setw( 2 ) << y2 << "." << ext; + SGPath f = dir; + f.append( name.str() ); + if ( f.exists() ) { + TGSrtmTiff s( f.str(), TopRight ); + s.load(); + s.close(); + data[6000][6000] = s.data[0][0]; + } else { + data[6000][6000] = 0; + } + } else { + data[6000][6000] = data[6000][6000-1]; + } } else if ( lkind == TopLeft ) { - TIFFReadScanline( tif, buf, 0 ); - uint32 col = 0; - for ( ; col < w; col++ ) { - int16 v = ((int16*)buf)[col]; - if ( v == -32768 ) - v = 0; - data[col][0] = v; - } - for ( ; col < 6000; col++ ) { - data[col][0] = 0; - } + TIFFReadScanline( tif, buf, 0 ); + uint32 col = 0; + for ( ; col < w; col++ ) { + int16 v = ((int16*)buf)[col]; + if ( v == -32768 ) + v = 0; + data[col][0] = v; + } + for ( ; col < 6000; col++ ) { + data[col][0] = 0; + } } else if ( lkind == BottomRight ) { - uint32 row = 0; - for ( ; row < h; row++ ) { - TIFFReadScanline( tif, buf, row ); - int16 v = ((int16*)buf)[0]; - if ( v == -32768 ) - v = 0; - data[0][6000-1-row] = v; - } - for ( ; row < 6000; row++ ) { - data[0][6000-1-row] = 0; - } + uint32 row = 0; + for ( ; row < h; row++ ) { + TIFFReadScanline( tif, buf, row ); + int16 v = ((int16*)buf)[0]; + if ( v == -32768 ) + v = 0; + data[0][6000-1-row] = v; + } + for ( ; row < 6000; row++ ) { + data[0][6000-1-row] = 0; + } } else /* if ( lkind == TopRight ) */ { - if ( h == 6000 ) { - TIFFReadScanline( tif, buf, h-1 ); - int16 v = ((int16*)buf)[0]; - if ( v == -32768 ) - v = 0; - data[0][0] = v; - } else { - data[0][0] = 0; - } + if ( h == 6000 ) { + TIFFReadScanline( tif, buf, h-1 ); + int16 v = ((int16*)buf)[0]; + if ( v == -32768 ) + v = 0; + data[0][0] = v; + } else { + data[0][0] = 0; + } } _TIFFfree(buf); @@ -356,7 +342,7 @@ bool TGSrtmTiff::load() { bool TGSrtmTiff::close() { if ( tif ) - TIFFClose( tif ); + TIFFClose( tif ); tif = 0; return true; } @@ -365,10 +351,10 @@ int main(int argc, char **argv) { sglog().setLogLevels( SG_ALL, SG_WARN ); if ( argc != 3 ) { - cout << "Usage " << argv[0] << " " + cout << "Usage " << argv[0] << " " << endl; cout << endl; - exit(-1); + exit(-1); } string hgt_name = argv[1]; @@ -388,32 +374,32 @@ int main(int argc, char **argv) { SGBucket b_min( min.x, min.y ); max.x = (hgt.get_originx() + hgt.get_cols() * hgt.get_col_step()) / 3600.0 - - SG_HALF_BUCKET_SPAN; + - SG_HALF_BUCKET_SPAN; max.y = (hgt.get_originy() + hgt.get_rows() * hgt.get_row_step()) / 3600.0 - - SG_HALF_BUCKET_SPAN; + - SG_HALF_BUCKET_SPAN; SGBucket b_max( max.x, max.y ); if ( b_min == b_max ) { - hgt.write_area( work_dir, b_min ); + hgt.write_area( work_dir, b_min ); } else { - SGBucket b_cur; - int dx, dy, i, j; + SGBucket b_cur; + int dx, dy, i, j; - sgBucketDiff(b_min, b_max, &dx, &dy); - cout << "HGT file spans tile boundaries (ok)" << endl; - cout << " dx = " << dx << " dy = " << dy << endl; + sgBucketDiff(b_min, b_max, &dx, &dy); + cout << "HGT file spans tile boundaries (ok)" << endl; + cout << " dx = " << dx << " dy = " << dy << endl; - if ( (dx > 50) || (dy > 50) ) { - cout << "somethings really wrong!!!!" << endl; - exit(-1); - } + if ( (dx > 50) || (dy > 50) ) { + cout << "somethings really wrong!!!!" << endl; + exit(-1); + } - for ( j = 0; j <= dy; j++ ) { - for ( i = 0; i <= dx; i++ ) { - b_cur = sgBucketOffset(min.x, min.y, i, j); - hgt.write_area( work_dir, b_cur ); - } - } + for ( j = 0; j <= dy; j++ ) { + for ( i = 0; i <= dx; i++ ) { + b_cur = sgBucketOffset(min.x, min.y, i, j); + hgt.write_area( work_dir, b_cur ); + } + } } return 0; diff --git a/src/Prep/E00Lines/CMakeLists.txt b/src/Prep/E00Lines/CMakeLists.txt new file mode 100644 index 00000000..a9946639 --- /dev/null +++ b/src/Prep/E00Lines/CMakeLists.txt @@ -0,0 +1,11 @@ + +add_executable(e00lines + main.cxx) + +target_link_libraries(e00lines + e00 + Polygon Geometry Output poly2tri TriangleJRS vpf + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} + genpolyclip) + diff --git a/src/Prep/GSHHS/CMakeLists.txt b/src/Prep/GSHHS/CMakeLists.txt new file mode 100644 index 00000000..8202aa0a --- /dev/null +++ b/src/Prep/GSHHS/CMakeLists.txt @@ -0,0 +1,21 @@ + +add_executable(gshhs + main.cxx + gshhs.h + gshhs_split.cxx gshhs_split.hxx) + +target_link_libraries(gshhs + Polygon Geometry Output poly2tri + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} + genpolyclip) + +add_executable(gshhs_debug + debug.cxx) + +target_link_libraries(gshhs_debug + Polygon Geometry Output poly2tri + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} + genpolyclip) + diff --git a/src/Prep/ShapeFile/CMakeLists.txt b/src/Prep/ShapeFile/CMakeLists.txt new file mode 100644 index 00000000..fafcea48 --- /dev/null +++ b/src/Prep/ShapeFile/CMakeLists.txt @@ -0,0 +1,18 @@ + + +add_executable(shape-decode shape-decode.cxx) + +target_link_libraries(shape-decode + shape Polygon Geometry Output poly2tri TriangleJRS vpf + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} + genpolyclip) + +add_executable(noaa-decode noaa-decode.cxx) + +target_link_libraries(noaa-decode + shape Polygon Geometry Output poly2tri TriangleJRS vpf + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} + genpolyclip) + diff --git a/src/Prep/TGVPF/CMakeLists.txt b/src/Prep/TGVPF/CMakeLists.txt new file mode 100644 index 00000000..b74ab766 --- /dev/null +++ b/src/Prep/TGVPF/CMakeLists.txt @@ -0,0 +1,9 @@ + +add_executable(tgvpf tgvpf.cxx) + +target_link_libraries(tgvpf + Polygon Geometry Output poly2tri TriangleJRS vpf + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES} + genpolyclip) + diff --git a/src/Prep/Terra/CMakeLists.txt b/src/Prep/Terra/CMakeLists.txt new file mode 100644 index 00000000..44926f94 --- /dev/null +++ b/src/Prep/Terra/CMakeLists.txt @@ -0,0 +1,17 @@ + + +add_library(Terra STATIC + Array.h Geom.h + GreedyInsert.cc GreedyInsert.h + Heap.cc Heap.h + Map.cc Map.h + Mask.cc Mask.h + Quadedge.cc Quadedge.h + Subdivision.cc Subdivision.h + Vec2.h Vec3.h +) + +add_executable(terra_bin + cmdline.cc getopt.c getopt.h greedy.cc output.cc terra.cc terra.h version.h) + +target_link_libraries(terra_bin Terra) diff --git a/src/Prep/TerraFit/CMakeLists.txt b/src/Prep/TerraFit/CMakeLists.txt new file mode 100644 index 00000000..b32c8e90 --- /dev/null +++ b/src/Prep/TerraFit/CMakeLists.txt @@ -0,0 +1,8 @@ + +add_executable(terrafit terrafit.cc) + +target_link_libraries(terrafit + Array Terra + ${SIMGEAR_CORE_LIBRARIES} + ${SIMGEAR_CORE_LIBRARY_DEPENDENCIES}) + diff --git a/src/Prep/TerraFit/terrafit.cc b/src/Prep/TerraFit/terrafit.cc index d3514107..6e73c0a8 100644 --- a/src/Prep/TerraFit/terrafit.cc +++ b/src/Prep/TerraFit/terrafit.cc @@ -42,9 +42,10 @@ #include #include #include +#include #include -#include +#include #include @@ -209,35 +210,21 @@ void fit_file(const std::string& path) { gzclose(fp); } -void walk_path(const std::string& path) { - struct stat statbuf; - if (stat(path.c_str(),&statbuf)!=0) { - SG_LOG(SG_GENERAL, SG_ALERT ,"ERROR: Unable to stat '" << path << "':" << strerror(errno)); - return; - } - - if (endswith(path,".arr.gz") || endswith(path,".arr")) { - fit_file(path); - } else if (S_ISDIR(statbuf.st_mode)) { - ulDir* dir=ulOpenDir(path.c_str()); - if (!dir) { - SG_LOG(SG_GENERAL, SG_ALERT ,"ERROR: Unable to open directory '" << path << "':" << strerror(errno)); - return; - } - - struct ulDirEnt* dirent; - - while ((dirent=ulReadDir(dir))) { - if (!strcmp(dirent->d_name,".") || !strcmp(dirent->d_name,"..")) { - continue; // skip . and .. - } - SGPath subpath(path); - subpath.append(dirent->d_name); - walk_path(subpath.str()); - } - - ulCloseDir(dir); +void walk_path(const SGPath& path) { + if (!path.exists()) { + SG_LOG(SG_GENERAL, SG_ALERT ,"ERROR: Unable to stat '" << path.str() << "':" << strerror(errno)); + return; + } + + if ((path.lower_extension() == "arr") || (path.complete_lower_extension() == "arr.gz")) { + fit_file(path.str()); + } else if (path.isDir()) { + simgear::Dir d(path); + simgear::PathList subdirs = d.children(simgear::Dir::TYPE_DIR | simgear::Dir::NO_DOT_OR_DOTDOT); + BOOST_FOREACH(const SGPath& p, subdirs) { + walk_path(p); } + } } void usage(char* progname, const std::string& msg) { @@ -311,7 +298,7 @@ int main(int argc, char** argv) { SG_LOG(SG_GENERAL, SG_INFO, "Max error = " << error_threshold); if (optind