Skip to content

Commit

Permalink
Merge pull request #29 from KAHR-Alpha/feature/CLI_Selene_anaylsis
Browse files Browse the repository at this point in the history
Basic CLI Selene anaylsis
  • Loading branch information
KAHR-Alpha authored Feb 20, 2024
2 parents e591a26 + b231045 commit 085cef0
Show file tree
Hide file tree
Showing 8 changed files with 141 additions and 7 deletions.
1 change: 1 addition & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Todo:

0.14
- The FDTD structure designer can use parameters and variables
- Basic Lua bindings to the analysis tools

0.13
- Selene can optimize against target hit counts
Expand Down
13 changes: 7 additions & 6 deletions src/Selene/selene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -346,14 +346,15 @@ void Selene::render()
for(i=0;i<Nlight;i++) total_power+=light_arr[i]->get_power();

ray_power=total_power/Nr_tot;
Nr_tot=0;

int run_Nr_tot=0;

light_N_rays.resize(Nlight);
light_Nr_disp.resize(Nlight);
for(i=0;i<Nlight;i++)
{
light_N_rays[i]=std::floor(light_arr[i]->get_power()/ray_power)+1;
Nr_tot+=light_N_rays[i];
light_N_rays[i]=std::max(static_cast<int>(light_arr[i]->get_power()/ray_power),1);
run_Nr_tot+=light_N_rays[i];

light_Nr_disp[i]=std::floor(Nr_disp*light_arr[i]->get_power()/total_power);
}
Expand All @@ -374,7 +375,7 @@ void Selene::render()
ray_path=request_job();
Nr_cast++;

while(ray_path.complete==false && Nr_cast<=Nr_tot)
while(ray_path.complete==false && Nr_cast<=run_Nr_tot)
{
request_raytrace(ray_path);

Expand Down Expand Up @@ -427,7 +428,7 @@ void Selene::render()
file.open(output_directory / ("selene_render_"+std::to_string(render_number)),
std::ios::out|std::ios::trunc);

file<<"total_rays("<<Nr_tot<<")\n\n";
file<<"total_rays("<<run_Nr_tot<<")\n\n";

for(int i=0;i<Nlight;i++)
file<<"source_power("<<std::to_string(i)<<","<<std::to_string(light_arr[i]->power)<<")\n";
Expand All @@ -441,7 +442,7 @@ void Selene::render()

render_number++;
chk_var(trace_calls);

timer.toc();

chk_var(timer()/trace_calls);
Expand Down
1 change: 1 addition & 0 deletions src/base.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,7 @@ int mode_choice(lua_State *L)
LuaUI::Selene_create_base_metatable(L);
LuaUI::Selene_create_light_metatable(L);
LuaUI::Selene_create_object_metatable(L);
LuaUI::selene_create_raycounter_metatable(L);
LuaUI::selene_create_target_metatable(L);

//#########################
Expand Down
1 change: 1 addition & 0 deletions src/lua/interface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ set(lua_src lua_interface.cpp
lua_multilayers.cpp
lua_optim.cpp
lua_selene.cpp
lua_selene_analysis.cpp
lua_selene_element.cpp
lua_selene_light.cpp
lua_selene_target.cpp)
Expand Down
22 changes: 21 additions & 1 deletion src/lua/interface/lua_selene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ void Selene_Mode::optimize(OptimEngine *engine)
}

void Selene_Mode::render() { selene.render(); rendered=true; }
void Selene_Mode::set_max_ray_bounces(int max_ray_bounces) { selene.set_max_ray_bounces(max_ray_bounces); }
void Selene_Mode::set_N_rays_disp(int Nr_disp) { selene.set_N_rays_disp(Nr_disp); }
void Selene_Mode::set_N_rays_total(int Nr_tot) { selene.set_N_rays_total(Nr_tot); }
void Selene_Mode::set_output_directory(std::string const &output_directory) { selene.set_output_directory(output_directory); }
Expand Down Expand Up @@ -508,6 +509,7 @@ namespace LuaUI
lua_register(L,"Selene_IRF",&LuaUI::create_selene_IRF);
lua_register(L,"Selene_light",&LuaUI::create_selene_light);
lua_register(L,"Selene_target",&LuaUI::create_selene_target);
lua_register(L,"Selene_raycounter",&LuaUI::create_selene_raycounter);
}

void Selene_create_base_metatable(lua_State *L)
Expand All @@ -516,6 +518,7 @@ namespace LuaUI

metatable_add_func(L,"add_object",&LuaUI::selene_mode_add_object);
metatable_add_func(L,"add_light",&LuaUI::selene_mode_add_light);
metatable_add_func(L,"max_ray_bounces",&LuaUI::selene_mode_set_max_ray_bounces);
metatable_add_func(L,"N_rays_disp",&LuaUI::selene_mode_set_N_rays_disp);
metatable_add_func(L,"N_rays_total",&LuaUI::selene_mode_set_N_rays_total);
metatable_add_func(L,"optimize",&LuaUI::selene_mode_optimize);
Expand Down Expand Up @@ -622,7 +625,7 @@ namespace LuaUI
metatable_add_func(L,"faces_group_up_mat",&LuaUI::selene_object_set_faces_group_up_mat);
metatable_add_func(L,"faces_group_up_tangent",&LuaUI::selene_object_set_faces_group_up_tangent);

//
// - General

metatable_add_func(L,"location",&LuaUI::selene_frame_set_displacement);
metatable_add_func(L,"name",&LuaUI::selene_frame_set_name);
Expand All @@ -636,6 +639,12 @@ namespace LuaUI
metatable_add_func(L,"sensor",&LuaUI::selene_object_set_sensor);
metatable_add_func(L,"translation_frame",&LuaUI::selene_frame_set_translation_frame);

// - Geometry

metatable_add_func(L,"conic_section_parameters",&LuaUI::selene_object_set_conic_parameters);

// IRF

create_obj_metatable(L,"metatable_selene_irf");

metatable_add_func(L,"add_layer",&LuaUI::selene_irf_add_layer);
Expand Down Expand Up @@ -685,6 +694,17 @@ namespace LuaUI
return 0;
}


int selene_mode_set_max_ray_bounces(lua_State *L)
{
Selene_Mode *p_mode=lua_get_metapointer<Selene_Mode>(L,1);

p_mode->set_max_ray_bounces(lua_tointeger(L,2));

return 0;
}


int selene_mode_set_N_rays_disp(lua_State *L)
{
Selene_Mode *p_mode=*(reinterpret_cast<Selene_Mode**>(lua_touserdata(L,1)));
Expand Down
13 changes: 13 additions & 0 deletions src/lua/interface/lua_selene.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ class Selene_Mode: public base_mode
void optimize(OptimEngine *engine);
void process() override;
void render();
void set_max_ray_bounces(int max_ray_bounces);
void set_N_rays_disp(int Nr_disp);
void set_N_rays_total(int Nr_tot);
void set_output_directory(std::string const &output_directory);
Expand Down Expand Up @@ -73,6 +74,8 @@ namespace LuaUI
int selene_object_set_default_out_irf(lua_State *L);
int selene_object_set_default_out_mat(lua_State *L);

int selene_object_set_conic_parameters(lua_State *L);

// - Faces

int selene_object_set_face_down_irf(lua_State *L);
Expand Down Expand Up @@ -144,8 +147,18 @@ namespace LuaUI
int selene_mode_optimize(lua_State *L);
int selene_mode_output_directory(lua_State *L);
int selene_mode_render(lua_State *L);
int selene_mode_set_max_ray_bounces(lua_State *L);
int selene_mode_set_N_rays_disp(lua_State *L);
int selene_mode_set_N_rays_total(lua_State *L);

// Analysis

int create_selene_raycounter(lua_State *L);
void selene_create_raycounter_metatable(lua_State *L);
int selene_raycounter_set_sensor(lua_State *L);
int selene_raycounter_get_hit_count(lua_State *L);
int selene_raycounter_get_angular_spread(lua_State *L);
int selene_raycounter_get_spatial_spread(lua_State *L);
}

#endif // LUA_SELENE_H_INCLUDED
81 changes: 81 additions & 0 deletions src/lua/interface/lua_selene_analysis.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*Copyright 2008-2024 - Loïc Le Cunff
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.*/

#include <lua_selene.h>

namespace LuaUI
{
int create_selene_raycounter(lua_State *L)
{
Sel::RayCounter *counter=new Sel::RayCounter();
lua_set_metapointer<Sel::RayCounter>(L,"metatable_selene_raycounter",counter);

return 1;
}


void selene_create_raycounter_metatable(lua_State *L)
{
create_obj_metatable(L,"metatable_selene_raycounter");

metatable_add_func(L,"angular_spread",&LuaUI::selene_raycounter_get_angular_spread);
metatable_add_func(L,"hit_count",&LuaUI::selene_raycounter_get_hit_count);
metatable_add_func(L,"spatial_spread",&LuaUI::selene_raycounter_get_spatial_spread);
metatable_add_func(L,"sensor",&LuaUI::selene_raycounter_set_sensor);
}


int selene_raycounter_get_hit_count(lua_State *L)
{
Sel::RayCounter *counter=lua_get_metapointer<Sel::RayCounter>(L,1);

int hit_count=counter->compute_hit_count();
lua_pushinteger(L,hit_count);

return 1;
}


int selene_raycounter_get_angular_spread(lua_State *L)
{
Sel::RayCounter *counter=lua_get_metapointer<Sel::RayCounter>(L,1);

double spread=counter->compute_angular_spread();
lua_pushnumber(L,spread);

return 1;
}


int selene_raycounter_get_spatial_spread(lua_State *L)
{
Sel::RayCounter *counter=lua_get_metapointer<Sel::RayCounter>(L,1);

double spread=counter->compute_spatial_spread();
lua_pushnumber(L,spread);

return 1;
}


int selene_raycounter_set_sensor(lua_State *L)
{
Sel::RayCounter *counter=lua_get_metapointer<Sel::RayCounter>(L,1);
Sel::Object *sensor=lua_get_metapointer<Sel::Object>(L,2);

counter->set_sensor(sensor);

return 0;
}
}
16 changes: 16 additions & 0 deletions src/lua/interface/lua_selene_element.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,22 @@ namespace LuaUI
return 1;
}


int selene_object_set_conic_parameters(lua_State *L)
{
Sel::Object *p_object=get_object_cast_metapointer(L);

p_object->conic_R=lua_tonumber(L,2);
p_object->conic_K=lua_tonumber(L,3);
p_object->conic_in_radius=lua_tonumber(L,4);
p_object->conic_out_radius=lua_tonumber(L,5);

p_object->set_conic_section();

return 0;
}


int selene_object_set_default_in_irf(lua_State *L)
{
Sel::Object *p_object=get_object_cast_metapointer(L);
Expand Down

0 comments on commit 085cef0

Please sign in to comment.