| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /* | ||
| 2 | * Copyright (c) 2000-2022 Inria | ||
| 3 | * All rights reserved. | ||
| 4 | * | ||
| 5 | * Redistribution and use in source and binary forms, with or without | ||
| 6 | * modification, are permitted provided that the following conditions are met: | ||
| 7 | * | ||
| 8 | * * Redistributions of source code must retain the above copyright notice, | ||
| 9 | * this list of conditions and the following disclaimer. | ||
| 10 | * * Redistributions in binary form must reproduce the above copyright notice, | ||
| 11 | * this list of conditions and the following disclaimer in the documentation | ||
| 12 | * and/or other materials provided with the distribution. | ||
| 13 | * * Neither the name of the ALICE Project-Team nor the names of its | ||
| 14 | * contributors may be used to endorse or promote products derived from this | ||
| 15 | * software without specific prior written permission. | ||
| 16 | * | ||
| 17 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
| 18 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
| 19 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
| 20 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
| 21 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
| 22 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
| 23 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
| 24 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
| 25 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
| 26 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
| 27 | * POSSIBILITY OF SUCH DAMAGE. | ||
| 28 | * | ||
| 29 | * Contact: Bruno Levy | ||
| 30 | * | ||
| 31 | * https://www.inria.fr/fr/bruno-levy | ||
| 32 | * | ||
| 33 | * Inria, | ||
| 34 | * Domaine de Voluceau, | ||
| 35 | * 78150 Le Chesnay - Rocquencourt | ||
| 36 | * FRANCE | ||
| 37 | * | ||
| 38 | */ | ||
| 39 | |||
| 40 | #include <geogram_gfx/lua/lua_simple_application.h> | ||
| 41 | #include <geogram_gfx/gui/simple_application.h> | ||
| 42 | #include <geogram/lua/lua_wrap.h> | ||
| 43 | #include <geogram/basic/stopwatch.h> | ||
| 44 | |||
| 45 | namespace { | ||
| 46 | using namespace GEO; | ||
| 47 | |||
| 48 | namespace LUAGLUPVIEWERImpl { | ||
| 49 | static double t0 = 0.0; | ||
| 50 | |||
| 51 | ✗ | static int ElapsedTime(lua_State* L) { | |
| 52 | ✗ | if(lua_gettop(L) != 0) { | |
| 53 | ✗ | return luaL_error( | |
| 54 | L, "'GLUP.ElapsedTime()' invalid number of arguments" | ||
| 55 | ✗ | ); | |
| 56 | } | ||
| 57 | double result = 0.0; | ||
| 58 | ✗ | result = GEO::Stopwatch::now() - t0; | |
| 59 | ✗ | lua_pushnumber(L,double(result)); | |
| 60 | ✗ | return 1; | |
| 61 | } | ||
| 62 | |||
| 63 | ✗ | static int ResetViewer(lua_State* L) { | |
| 64 | ✗ | if(lua_gettop(L) != 0) { | |
| 65 | ✗ | return luaL_error( | |
| 66 | L, "'GLUP.ResetViewer()' invalid number of arguments" | ||
| 67 | ✗ | ); | |
| 68 | } | ||
| 69 | |||
| 70 | GEO::SimpleApplication* app = GEO::SimpleApplication::instance(); | ||
| 71 | ✗ | if(app != nullptr) { | |
| 72 | ✗ | app->home(); | |
| 73 | app->set_lighting(true); | ||
| 74 | } | ||
| 75 | |||
| 76 | ✗ | t0 = GEO::Stopwatch::now(); | |
| 77 | ✗ | return 0; | |
| 78 | } | ||
| 79 | |||
| 80 | ✗ | static int ArcadeStyle(lua_State* L) { | |
| 81 | ✗ | if(lua_gettop(L) != 0) { | |
| 82 | ✗ | return luaL_error( | |
| 83 | L, "'GLUP.ArcadeStyle()' invalid number of arguments" | ||
| 84 | ✗ | ); | |
| 85 | } | ||
| 86 | |||
| 87 | GEO::SimpleApplication* app = GEO::SimpleApplication::instance(); | ||
| 88 | ✗ | if(app != nullptr) { | |
| 89 | ✗ | app->home(); | |
| 90 | app->set_lighting(false); | ||
| 91 | app->set_background_color(vec4f(0.0, 0.0, 0.0, 1.0)); | ||
| 92 | } | ||
| 93 | |||
| 94 | return 0; | ||
| 95 | } | ||
| 96 | |||
| 97 | ✗ | static int SetRegionOfInterest(lua_State* L) { | |
| 98 | ✗ | if(lua_gettop(L) != 6) { | |
| 99 | ✗ | return luaL_error( | |
| 100 | L, | ||
| 101 | "'GLUP.SetRegionOfInterest()' invalid number of arguments" | ||
| 102 | ✗ | ); | |
| 103 | } | ||
| 104 | if( | ||
| 105 | ✗ | !lua_isnumber(L,1) || | |
| 106 | ✗ | !lua_isnumber(L,2) || | |
| 107 | ✗ | !lua_isnumber(L,3) || | |
| 108 | ✗ | !lua_isnumber(L,4) || | |
| 109 | ✗ | !lua_isnumber(L,5) || | |
| 110 | ✗ | !lua_isnumber(L,6) | |
| 111 | ) { | ||
| 112 | ✗ | return luaL_error( | |
| 113 | L, | ||
| 114 | "'GLUP.SetRegionOfInterest()' arguments should be numbers" | ||
| 115 | ✗ | ); | |
| 116 | } | ||
| 117 | GEO::SimpleApplication* app = GEO::SimpleApplication::instance(); | ||
| 118 | ✗ | if(app != nullptr) { | |
| 119 | ✗ | app->set_region_of_interest( | |
| 120 | lua_tonumber(L,1), | ||
| 121 | lua_tonumber(L,2), | ||
| 122 | lua_tonumber(L,3), | ||
| 123 | lua_tonumber(L,4), | ||
| 124 | lua_tonumber(L,5), | ||
| 125 | lua_tonumber(L,6) | ||
| 126 | ); | ||
| 127 | } | ||
| 128 | return 0; | ||
| 129 | } | ||
| 130 | |||
| 131 | ✗ | static int GetRegionOfInterest(lua_State* L) { | |
| 132 | ✗ | if(lua_gettop(L) != 0) { | |
| 133 | ✗ | return luaL_error( | |
| 134 | L, | ||
| 135 | "'GLUP.GetRegionOfInterest()' invalid number of arguments" | ||
| 136 | ✗ | ); | |
| 137 | } | ||
| 138 | |||
| 139 | GEO::SimpleApplication* app = GEO::SimpleApplication::instance(); | ||
| 140 | ✗ | if(app != nullptr) { | |
| 141 | double xm,ym,zm,xM,yM,zM; | ||
| 142 | ✗ | app->get_region_of_interest( | |
| 143 | xm, ym, zm, xM, yM, zM | ||
| 144 | ); | ||
| 145 | ✗ | lua_pushnumber(L,xm); | |
| 146 | ✗ | lua_pushnumber(L,ym); | |
| 147 | ✗ | lua_pushnumber(L,zm); | |
| 148 | ✗ | lua_pushnumber(L,xM); | |
| 149 | ✗ | lua_pushnumber(L,yM); | |
| 150 | ✗ | lua_pushnumber(L,zM); | |
| 151 | } | ||
| 152 | return 6; | ||
| 153 | } | ||
| 154 | } | ||
| 155 | } | ||
| 156 | |||
| 157 | ✗ | void init_lua_simple_application(lua_State* L) { | |
| 158 | ✗ | lua_getglobal(L,"GLUP"); | |
| 159 | ✗ | geo_assert(!lua_isnil(L,-1)); // Make sure GLUP was registered before. | |
| 160 | ✗ | GEO::lua_bindwrapper(L,LUAGLUPVIEWERImpl::ElapsedTime); | |
| 161 | ✗ | GEO::lua_bindwrapper(L,LUAGLUPVIEWERImpl::ResetViewer); | |
| 162 | ✗ | GEO::lua_bindwrapper(L,LUAGLUPVIEWERImpl::ArcadeStyle); | |
| 163 | ✗ | GEO::lua_bindwrapper(L,LUAGLUPVIEWERImpl::SetRegionOfInterest); | |
| 164 | ✗ | GEO::lua_bindwrapper(L,LUAGLUPVIEWERImpl::GetRegionOfInterest); | |
| 165 | ✗ | lua_pop(L,1); | |
| 166 | ✗ | } | |
| 167 |