diff --git a/CMakeLists.txt b/CMakeLists.txt index 22ccd6c..f694a0e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,6 +21,10 @@ endif(NOT STIM_INCLUDE_DIRS) #find BOOST find_package(Boost REQUIRED) +#find the GLUT library for visualization +find_package(OpenGL REQUIRED) +find_package(GLUT REQUIRED) + #find the pthreads package find_package(Threads) @@ -37,8 +41,10 @@ if ( MSVC ) endif ( MSVC ) include_directories( + ${OpenGL_INCLUDE_DIRS} + ${GLUT_INCLUDE_DIR} ${STIM_INCLUDE_DIRS} - ${ANN_INCLUDE_DIR} + ${ANN_INCLUDE_DIR} ${Boost_INCLUDE_DIR} ) @@ -54,8 +60,10 @@ add_executable(netmets #set the link libraries target_link_libraries(netmets + ${OpenGL_LIBRARIES} + ${GLUT_LIBRARIES} ${CMAKE_THREAD_LIBS_INIT} - ${ANN_LIBRARY} + ${ANN_LIBRARY} ${X11_LIBRARIES} ) diff --git a/FindGLUT.cmake b/FindGLUT.cmake new file mode 100644 index 0000000..906ef26 --- /dev/null +++ b/FindGLUT.cmake @@ -0,0 +1,175 @@ +#.rst: +# FindGLUT +# -------- +# +# try to find glut library and include files. +# +# IMPORTED Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines the :prop_tgt:`IMPORTED` targets: +# +# ``GLUT::GLUT`` +# Defined if the system has GLUT. +# +# Result Variables +# ^^^^^^^^^^^^^^^^ +# +# This module sets the following variables: +# +# :: +# +# GLUT_INCLUDE_DIR, where to find GL/glut.h, etc. +# GLUT_LIBRARIES, the libraries to link against +# GLUT_FOUND, If false, do not try to use GLUT. +# +# Also defined, but not for general use are: +# +# :: +# +# GLUT_glut_LIBRARY = the full path to the glut library. +# GLUT_Xmu_LIBRARY = the full path to the Xmu library. +# GLUT_Xi_LIBRARY = the full path to the Xi Library. + +#============================================================================= +# Copyright 2001-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 distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +if (WIN32) + find_path( GLUT_INCLUDE_DIR NAMES GL/glut.h + PATHS $ENV{GLUT_ROOT_PATH}/include ) + find_library( GLUT_glut_LIBRARY NAMES glut glut32 freeglut + PATHS + ${OPENGL_LIBRARY_DIR} + $ENV{GLUT_ROOT_PATH}/lib + ) +else () + + if (APPLE) + find_path(GLUT_INCLUDE_DIR glut.h ${OPENGL_LIBRARY_DIR}) + find_library(GLUT_glut_LIBRARY GLUT DOC "GLUT library for OSX") + find_library(GLUT_cocoa_LIBRARY Cocoa DOC "Cocoa framework for OSX") + + if(GLUT_cocoa_LIBRARY AND NOT TARGET GLUT::Cocoa) + add_library(GLUT::Cocoa UNKNOWN IMPORTED) + # Cocoa should always be a Framework, but we check to make sure. + if(GLUT_cocoa_LIBRARY MATCHES "/([^/]+)\\.framework$") + set_target_properties(GLUT::Cocoa PROPERTIES + IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}/${CMAKE_MATCH_1}") + else() + set_target_properties(GLUT::Cocoa PROPERTIES + IMPORTED_LOCATION "${GLUT_cocoa_LIBRARY}") + endif() + endif() + else () + + if (BEOS) + + set(_GLUT_INC_DIR /boot/develop/headers/os/opengl) + set(_GLUT_glut_LIB_DIR /boot/develop/lib/x86) + + else() + + find_library( GLUT_Xi_LIBRARY Xi + /usr/openwin/lib + ) + + find_library( GLUT_Xmu_LIBRARY Xmu + /usr/openwin/lib + ) + + if(GLUT_Xi_LIBRARY AND NOT TARGET GLUT::Xi) + add_library(GLUT::Xi UNKNOWN IMPORTED) + set_target_properties(GLUT::Xi PROPERTIES + IMPORTED_LOCATION "${GLUT_Xi_LIBRARY}") + endif() + + if(GLUT_Xmu_LIBRARY AND NOT TARGET GLUT::Xmu) + add_library(GLUT::Xmu UNKNOWN IMPORTED) + set_target_properties(GLUT::Xmu PROPERTIES + IMPORTED_LOCATION "${GLUT_Xmu_LIBRARY}") + endif() + + endif () + + find_path( GLUT_INCLUDE_DIR GL/glut.h + /usr/include/GL + /usr/openwin/share/include + /usr/openwin/include + /opt/graphics/OpenGL/include + /opt/graphics/OpenGL/contrib/libglut + ${_GLUT_INC_DIR} + ) + + find_library( GLUT_glut_LIBRARY glut + /usr/openwin/lib + ${_GLUT_glut_LIB_DIR} + ) + + unset(_GLUT_INC_DIR) + unset(_GLUT_glut_LIB_DIR) + + endif () + +endif () + +FIND_PACKAGE_HANDLE_STANDARD_ARGS(GLUT REQUIRED_VARS GLUT_glut_LIBRARY GLUT_INCLUDE_DIR) + +if (GLUT_FOUND) + # Is -lXi and -lXmu required on all platforms that have it? + # If not, we need some way to figure out what platform we are on. + set( GLUT_LIBRARIES + ${GLUT_glut_LIBRARY} + ${GLUT_Xmu_LIBRARY} + ${GLUT_Xi_LIBRARY} + ${GLUT_cocoa_LIBRARY} + ) + + if(NOT TARGET GLUT::GLUT) + add_library(GLUT::GLUT UNKNOWN IMPORTED) + set_target_properties(GLUT::GLUT PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${GLUT_INCLUDE_DIR}") + if(GLUT_glut_LIBRARY MATCHES "/([^/]+)\\.framework$") + set_target_properties(GLUT::GLUT PROPERTIES + IMPORTED_LOCATION "${GLUT_glut_LIBRARY}/${CMAKE_MATCH_1}") + else() + set_target_properties(GLUT::GLUT PROPERTIES + IMPORTED_LOCATION "${GLUT_glut_LIBRARY}") + endif() + + if(TARGET GLUT::Xmu) + set_property(TARGET GLUT::GLUT APPEND + PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xmu) + endif() + + if(TARGET GLUT::Xi) + set_property(TARGET GLUT::GLUT APPEND + PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Xi) + endif() + + if(TARGET GLUT::Cocoa) + set_property(TARGET GLUT::GLUT APPEND + PROPERTY INTERFACE_LINK_LIBRARIES GLUT::Cocoa) + endif() + endif() + + #The following deprecated settings are for backwards compatibility with CMake1.4 + set (GLUT_LIBRARY ${GLUT_LIBRARIES}) + set (GLUT_INCLUDE_PATH ${GLUT_INCLUDE_DIR}) +endif() + +mark_as_advanced( + GLUT_INCLUDE_DIR + GLUT_glut_LIBRARY + GLUT_Xmu_LIBRARY + GLUT_Xi_LIBRARY + ) diff --git a/main.cpp b/main.cpp index 257dd53..22b5be1 100644 --- a/main.cpp +++ b/main.cpp @@ -2,44 +2,220 @@ #include #include #include -#include +//OpenGL includes +#include + +//STIM includes +#include +#include +#include +#include + +//ANN includes #include + +//BOOST includes #include -using namespace stim; -//template -network* network1; +stim::gl_aabb bb; +stim::camera cam; + +stim::gl_network GT; +stim::gl_network T; + +//hard-coded parameters +float resample_rate = 0.5; + +//mouse position tracking +int mouse_x; +int mouse_y; + +void glut_render(void) { + + glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); + + glMatrixMode(GL_MODELVIEW); + glLoadIdentity(); + stim::vec eye = cam.getPosition(); + stim::vec focus = cam.getLookAt(); + stim::vec up = cam.getUp(); + + gluLookAt(eye[0], eye[1], eye[2], focus[0], focus[1], focus[2], up[0], up[1], up[2]); + + + + // render the bounding box + glColor3f(0.0, 0.0, 1.0); + glBegin(GL_LINE_LOOP); + bb.glPointsCW(); + glEnd(); + + //render the GT network (red) + glColor3f(1.0, 0.0, 0.0); + GT.glCenterline(); + + //render the T network (green) + glColor3f(0.0, 1.0, 0.0); + T.glCenterline(); + + glutSwapBuffers(); +} + +// defines camera motion based on mouse dragging +void glut_motion(int x, int y){ + float factor = 0.01; + + float theta = factor * (mouse_x - x); + float phi = factor * (y - mouse_y); + + cam.OrbitFocus(theta, phi); + + mouse_x = x; + mouse_y = y; + + glutPostRedisplay(); +} + +// sets the mouse position when clicked +void glut_mouse(int button, int state, int x, int y){ + mouse_x = x; + mouse_y = y; +} + +// re-calculates the projection matrix if the window is reshaped +void glut_reshape(int x, int y){ + + glMatrixMode(GL_PROJECTION); + glLoadIdentity(); + glViewport(0, 0, x, y); + float aspect = (float)x / (float)y; + gluPerspective(60, aspect, 0.1, 1000000); + +} + +void advertise(){ + //output advertisement + std::cout< cGT = GT.compare(T, sigma); + stim::network cT = T.compare(GT, sigma); + + //calculate the metrics + float FPR = cGT.average(1); + float FNR = cT.average(1); + // print false alarms and misses + std::cout << "FNR: " << FPR << std::endl; + std::cout << "FPR: " << FNR << std::endl; +} + +void glut_initialize(){ + float factor = 1.2; + + // init GLUT and create Window + int myargc = 1; + char* myargv[1]; + myargv [0]=strdup ("netmets"); + + glutInit(&myargc, myargv); + glutInitDisplayMode(GLUT_DEPTH | GLUT_DOUBLE | GLUT_RGBA); + glutInitWindowPosition(100,100); + glutInitWindowSize(320,320); + glutCreateWindow("Lighthouse3D- GLUT Tutorial"); + + + // register callbacks + glutDisplayFunc(glut_render); + glutMouseFunc(glut_mouse); + glutMotionFunc(glut_motion); + glutReshapeFunc(glut_reshape); + + //set up the camera + stim::vec c = bb.center(); + //place the camera along the z-axis at a distance determined by the network size along x and y + cam.setPosition(c + stim::vec(0, 0, factor * std::max(bb.size()[0], bb.size()[1]))); + cam.LookAt(c[0], c[1], c[2]); //look at the center + +} + +void display(){ + + + //generate a bounding volume + bb = GT.boundingbox(); + + std::cout<= 1){ + GT.load_obj(args.arg(0)); + } - float sigma = atof(argv[3]); - stim::network GT;stim::network T; - // load obj files to 3D network class - - //load the ground truth and test case networks - GT.load_obj(argv[1]); - T.load_obj(argv[2]); + //if two files are provided, compare them + if(args.nargs() == 2){ + float sigma = args["sigma"].as_float(); //get the sigma value from the user + T.load_obj(args.arg(1)); //load the second (test) network - // resample the loaded networks - stim::network resampled_GT; - stim::network resampled_T; + GT = GT.resample(resample_rate * sigma); //resample both networks based on the sigma value + T = T.resample(resample_rate * sigma); - resampled_GT = GT.resample(sigma * resample_rate); - resampled_T = T.resample(sigma * resample_rate); + compare(sigma); //run the comparison algorithm + } - // compare ground truth with truth and viceversa - float gFPR, gFNR; - gFPR = resampled_GT.compare(resampled_T, sigma); - gFNR = resampled_T.compare(resampled_GT, sigma); - // print false alarms and misses - std::cout << "False postive rate is " << gFPR << std::endl; - std::cout << "False negative rate is " << gFNR << std::endl; + //if a GUI is requested, display the network using OpenGL + if(args["gui"].is_set()) + display(); + + + } \ No newline at end of file -- libgit2 0.21.4