Commit 8331b2c7 authored by Nicolas Van der Noot's avatar Nicolas Van der Noot
Browse files

adapt java for more generic

parent b3bd65c0
......@@ -46,15 +46,25 @@ if ( FLAG_SEPARATE_USER_FCT )
# plot-visu options
option (FLAG_PLOT "Real time" OFF)
option (FLAG_VISU "Real time" OFF)
option (FLAG_JAVA "Real time" OFF)
option (FLAG_OPEN_GL "Real time" OFF)
if(FLAG_PLOT)
add_definitions( -DSDL )
endif( )
if(FLAG_VISU)
add_definitions( -DVISU_3D )
endif( )
if(FLAG_JAVA)
add_definitions( -DJAVA )
endif( )
if(FLAG_OPEN_GL)
add_definitions( -DOPEN_GL )
endif( )
endif ( )
endif ( )
......
......@@ -22,7 +22,7 @@
* * options->t0: initial simulation time [s] (default: 0.0)
* * options->tf: final simulation time [s] (default: mbs_dirdyn->options->tf)
* * options->dt0: simulation time step [s] (default: mbs_dirdyn->options->dt0)
* * options->buffer_size: size of the buffer for java and sdl (default: -1).
* * options->buffer_size: size of the buffer for 3D visualization and sdl (default: -1).
* This size corresponds to the number of time steps saved to analyze what happened
* back in time. When the buffers are full, they erase the oldest values with the new
* ones (rotating buffer). If you put a value <= 0, the size is automatically computed
......@@ -76,7 +76,7 @@
* reallocate it to a size of 'nb_models'.
* * options->start_viewpoint: initial visualization viewpoint ID, defined in the .mbs file (default: 0).
* Use -1 to start with the default viewpoint when opening MBSysPad.
* * options->fqc_visu: frequence of the java visualization refreshment [Hz] (default: 30.0)
* * options->fqc_visu: frequence of the 3D visualization refreshment [Hz] (default: 30.0)
*
* example:
* options->y_min_init = 0.0;
......
......@@ -209,9 +209,14 @@ else ( )
endif ( )
# Java external library
if (FLAG_VISU)
if (FLAG_JAVA)
target_link_libraries ( ${Executable} ${JNI_LIBRARIES} )
endif ( )
# OpenGL external library
if (FLAG_OPEN_GL)
endif ( )
add_definitions( -DMBSYSC_MODULE_STATIC_DEFINE)
......
......@@ -85,7 +85,7 @@ int main(int argc, char const *argv[])
mbs_dirdyn->options->save2file = 1;
mbs_dirdyn->options->respath = PROJECT_SOURCE_DIR"/../resultsR";
mbs_dirdyn->options->animpath = PROJECT_SOURCE_DIR"/../animationR";
mbs_dirdyn->options->realtime = 0;
mbs_dirdyn->options->realtime = 1;
mbs_run_dirdyn(mbs_dirdyn, mbs_data);
......
......@@ -37,8 +37,14 @@ function(mbsysc_specific_flags) # flag for lib_mbsysC only (not set by project)
# use the SDL library to plot real-time graphs and to handle the user inputs (keyboard...)
cmake_dependent_option(FLAG_PLOT "Enable realtime plots (need SDL)" ON "FLAG_REAL_TIME" OFF)
# use the Java or OpenGL libraries to display in real-time the animation
cmake_dependent_option(FLAG_VISU "Enable 3D visualization (need Java or OpenGL)" ON "FLAG_REAL_TIME" OFF)
# use the Java library to display in real-time the animation
cmake_dependent_option(FLAG_VISU "Enable 3D visualization (need Java)" ON "FLAG_REAL_TIME" OFF)
cmake_dependent_option(FLAG_JAVA "Enable 3D visualization (need Java)" ON "FLAG_VISU" OFF)
# use the OpenGL library to display in real-time the animation
cmake_dependent_option(FLAG_OPEN_GL "Enable 3D visualization (need OpenGL)" OFF "FLAG_VISU" OFF)
endfunction()
......@@ -69,6 +75,19 @@ function(flags_check)
if (NOT FLAG_REAL_TIME)
set( FLAG_PLOT OFF )
set( FLAG_VISU OFF )
set( FLAG_JAVA OFF )
set( FLAG_OPEN_GL OFF )
endif( )
# 3D visu
if (NOT FLAG_VISU)
set( FLAG_JAVA OFF )
set( FLAG_OPEN_GL OFF )
endif( )
# OpenGL only if no Java
if (FLAG_JAVA)
set( FLAG_OPEN_GL OFF )
endif( )
# separate build
......@@ -90,6 +109,8 @@ function(flags_check)
set( FLAG_REAL_TIME ${FLAG_REAL_TIME} PARENT_SCOPE )
set( FLAG_PLOT ${FLAG_PLOT} PARENT_SCOPE )
set( FLAG_VISU ${FLAG_VISU} PARENT_SCOPE )
set( FLAG_JAVA ${FLAG_JAVA} PARENT_SCOPE )
set( FLAG_OPEN_GL ${FLAG_OPEN_GL} PARENT_SCOPE )
set( FLAG_SHARED_LIB ${FLAG_SHARED_LIB} PARENT_SCOPE )
set( FLAG_SEPARATE_BUILD ${FLAG_SEPARATE_BUILD} PARENT_SCOPE )
set( FLAG_SEPARATE_SYMBOLIC ${FLAG_SEPARATE_SYMBOLIC} PARENT_SCOPE )
......@@ -112,6 +133,8 @@ function(flags_clean)
unset(FLAG_REAL_TIME )
unset(FLAG_PLOT CACHE)
unset(FLAG_VISU CACHE)
unset(FLAG_JAVA CACHE)
unset(FLAG_OPEN_GL CACHE)
unset(JNI_INCLUDE_JNI CACHE)
unset(JNI_INCLUDE_JNI_MD CACHE)
unset(SDL2_LIBRARIES_SDL2 CACHE)
......@@ -168,9 +191,19 @@ function(definitions)
endif( )
if(FLAG_VISU)
add_definitions( -DVISU_3D )
set(LIB_MBSYSC_DEFINITIONS ${LIB_MBSYSC_DEFINITIONS} -DVISU_3D)
endif( )
if(FLAG_JAVA)
add_definitions( -DJAVA )
set(LIB_MBSYSC_DEFINITIONS ${LIB_MBSYSC_DEFINITIONS} -DJAVA)
endif( )
if(FLAG_OPEN_GL)
add_definitions( -DOPEN_GL )
set(LIB_MBSYSC_DEFINITIONS ${LIB_MBSYSC_DEFINITIONS} -DOPEN_GL)
endif( )
set(LIB_MBSYSC_DEFINITIONS ${LIB_MBSYSC_DEFINITIONS} PARENT_SCOPE)
endfunction()
......@@ -36,7 +36,9 @@ echo " FLAG_SEPARATE_BUILD : $3"
echo " FLAG_RELEASE : $4"
echo " FLAG_REAL_TIME : $5"
echo " FLAG_PLOT : $6"
echo " FLAG_VISU : $7\n"
echo " FLAG_VISU : $7"
echo " FLAG_JAVA : $8"
echo " FLAG_OPEN_GL : $9\n"
# compilation
make
......
......@@ -39,7 +39,9 @@ echo " $BUILD_FOLDER"
echo " with the following options:"
echo " FLAG_REAL_TIME : $3"
echo " FLAG_PLOT : $4"
echo " FLAG_VISU : $5\n"
echo " FLAG_VISU : $5"
echo " FLAG_JAVA : $6"
echo " FLAG_OPEN_GL : $7\n"
# compilation
make
......
......@@ -56,6 +56,8 @@ SET(FLAG_PRJ_FCT_PTR @FLAG_PRJ_FCT_PTR@)
SET(FLAG_REAL_TIME @FLAG_REAL_TIME@)
SET(FLAG_PLOT @FLAG_PLOT@)
SET(FLAG_VISU @FLAG_VISU@)
SET(FLAG_JAVA @FLAG_JAVA@)
SET(FLAG_OPEN_GL @FLAG_OPEN_GL@)
# Shared lib compilation
SET(FLAG_SHARED_LIB @FLAG_SHARED_LIB@)
......
......@@ -201,8 +201,8 @@ void mbs_load_user_functions(MbsData* mbs_data, const char* mbs_filename, const
mbs_data->fct.user.user_joystick_buttons = (user_joystick_buttons_ptr) mbs_load_function(userLibInfo, "user_joystick_buttons");
#endif
#ifdef JAVA
mbs_data->fct.user.user_realtime_visu = (user_realtime_visu_ptr) mbs_load_function(userLibInfo, "user_realtime_visu");
#ifdef VISU_3D
mbs_data->fct.user.user_realtime_visu = (user_realtime_visu_ptr) mbs_load_function(userLibInfo, "user_realtime_visu");
#endif
#endif
......
......@@ -139,9 +139,9 @@ void mbs_run_dirdyn(MbsDirdyn* dd, MbsData* mbs_data)
void mbs_dirdyn_save(MbsDirdyn* dd, MbsData *mbs_data, double t){
int i;
#ifdef JAVA
#ifdef VISU_3D
Simu_realtime *realtime;
Realtime_java *java;
Realtime_visu *visu;
#endif
for (i=0 ; i < dd->bufferNb ; i++){
......@@ -152,15 +152,15 @@ void mbs_dirdyn_save(MbsDirdyn* dd, MbsData *mbs_data, double t){
if (dd->options->save_visu)
{
#ifdef JAVA
#ifdef VISU_3D
realtime = (Simu_realtime*) mbs_data->realtime;
java = realtime->ext->java;
visu = realtime->ext->visu;
user_realtime_visu(mbs_data, java->nb_models, java->nb_q, java->anim_q);
user_realtime_visu(mbs_data, visu->nb_models, visu->nb_q, visu->anim_q);
for(i=0; i<realtime->options->nb_models; i++)
{
mbs_buffer_save(dd->buffer_visu[i], t, java->anim_q[i]);
mbs_buffer_save(dd->buffer_visu[i], t, visu->anim_q[i]);
}
#endif
}
......@@ -170,9 +170,9 @@ void mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data)
{
int i;
#ifdef JAVA
#ifdef VISU_3D
Simu_realtime *realtime;
Realtime_java *java;
Realtime_visu *visu;
#endif
// INITIALIZATION
......@@ -362,7 +362,7 @@ void mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data)
if (dd->options->save_visu)
{
#ifdef JAVA
#ifdef VISU_3D
if (!dd->options->realtime)
{
printf("Error: real-time features must be activated to set 'save_visu' to 1 ! \n");
......@@ -376,7 +376,7 @@ void mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data)
printf("Error: flag_visu must be set to 1 to set 'save_value' to 1 ! \n");
}
java = realtime->ext->java;
visu = realtime->ext->visu;
dd->buffer_visu = (MbsBuffer**) malloc(realtime->options->nb_models*sizeof(MbsBuffer*));
for(i=0; i<realtime->options->nb_models; i++)
......@@ -384,7 +384,7 @@ void mbs_dirdyn_init(MbsDirdyn* dd, MbsData* mbs_data)
sprintf(f, "%s/visu_%d_q.res", respath, i);
sprintf(f_anim, "%s/visu_%d_q.anim", animpath, i);
dd->buffer_visu[i] = mbs_new_buffer(f, f_anim, java->nb_q[i], dd->options->buffersize, BUFFER_VISU, dd->options->save_anim, dd->options->save_visu, 1./(double)dd->options->framerate);
dd->buffer_visu[i] = mbs_new_buffer(f, f_anim, visu->nb_q[i], dd->options->buffersize, BUFFER_VISU, dd->options->save_anim, dd->options->save_visu, 1./(double)dd->options->framerate);
}
#else
......
......@@ -331,9 +331,9 @@ void mbs_equil_save(MbsEquil* eq, MbsData *mbs_data, int n)
/* int i;
#ifdef JAVA
#ifdef VISU_3D
Simu_realtime *realtime;
Realtime_java *java;
Realtime_visu *visu;
#endif
for (i=0 ; i < dd->bufferNb ; i++){
......@@ -344,12 +344,12 @@ void mbs_equil_save(MbsEquil* eq, MbsData *mbs_data, int n)
if (dd->options->save_visu)
{
#ifdef JAVA
#ifdef VISU_3D
realtime = (Simu_realtime*) mbs_data->realtime;
java = realtime->ext->java;
visu = realtime->ext->visu;
user_realtime_visu(mbs_data, java->nb_q, java->anim_q);
mbs_buffer_save(dd->buffer_visu, t, java->anim_q);
user_realtime_visu(mbs_data, visu->nb_q, visu->anim_q);
mbs_buffer_save(dd->buffer_visu, t, visu->anim_q);
#endif
}*/
}
......
......@@ -39,7 +39,7 @@ if (FLAG_PLOT)
endif ()
# Get java lib and add java functions to src
if (FLAG_VISU)
if (FLAG_JAVA)
# find java and java 3d
java_lib(mbs_realtime)
......@@ -62,6 +62,11 @@ if (FLAG_VISU)
include_directories ("${PROJECT_BINARY_DIR}/conf")
endif ()
# Get OpenGL lib
if (FLAG_OPEN_GL)
endif ()
# list include directories (to find headers)
init_include()
set(INCLUDE_DIR ${INCLUDE_DIR} ${PROJECT_SOURCE_DIR}/realtime PARENT_SCOPE)
......@@ -96,10 +101,15 @@ if (FLAG_PLOT)
endif ( )
# Java external library: linkage
if (FLAG_VISU)
if (FLAG_JAVA)
target_link_libraries (${LIB_MBSYSC_REALTIME} ${JNI_LIBRARIES})
endif ( )
# OpenGl external library: linkage
if (FLAG_OPEN_GL)
endif ( )
set(LIB_MBSYSC_REALTIME_PATH ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
# include directories
......
......@@ -220,13 +220,13 @@ void start_jni(JNI_in_out *jni_in_out)
/*! \brief initialize the JNI structure
*
* \param[out] java realtime Java structure
* \param[out] visu realtime 3D structure
* \param[in] nb_models number of models
* \param[in] nb_q number of joints in the .mbs file
* \param[in] q_vec vector of size nb_q with the initial values for q
* \param[in] mbs_file path and name of the .mbs file used for visualization
*/
void init_jni(Realtime_java *java, int nb_models, int *nb_q, double **q_vec, char **mbs_file, int start_viewpoint)
void init_jni(Realtime_visu *visu, int nb_models, int *nb_q, double **q_vec, char **mbs_file, int start_viewpoint)
{
JNI_in_out jni_in_out;
......@@ -281,7 +281,7 @@ void init_jni(Realtime_java *java, int nb_models, int *nb_q, double **q_vec, cha
close(pipe_viewpoint[1]);
// save JNI adress
java->jni_struct = jni_in_out.jni_struct;
visu->visu_class = jni_in_out.jni_struct;
// JNI run
if (pthread_create(&thr, NULL, start_jni, &jni_in_out))
......@@ -304,26 +304,28 @@ void init_jni(Realtime_java *java, int nb_models, int *nb_q, double **q_vec, cha
read(pipe_ready[0], &flag_ready, sizeof(int));
read(pipe_nb_viewpoint[0], &nb_viewpoint, sizeof(int));
java->nb_viewpoint = nb_viewpoint;
visu->nb_viewpoint = nb_viewpoint;
}
#else
// JNI initialization
start_jni(&jni_in_out);
java->nb_viewpoint = jni_in_out.nb_viewpoint;
visu->nb_viewpoint = jni_in_out.nb_viewpoint;
// save JNI adress
java->jni_struct = jni_in_out.jni_struct;
visu->visu_class = jni_in_out.jni_struct;
#endif
}
/*! \brief Release memory
*
* \param[out] jni_struct JNI structure to release
* \param[out] visu_class JNI structure to release
*/
void free_jni(JNI_struct *jni_struct)
void free_jni(void *visu_class)
{
JNI_struct *jni_struct;
#ifdef APPLE_VISU
int flag_finish, flag_close;
......@@ -334,6 +336,8 @@ void free_jni(JNI_struct *jni_struct)
read(pipe_close[0], &flag_close, sizeof(int));
}
#else
jni_struct = (JNI_struct*) visu_class;
free(jni_struct->doubleArrayArgs);
free(jni_struct);
#endif
......@@ -345,16 +349,19 @@ void free_jni(JNI_struct *jni_struct)
*/
void update_java(Simu_realtime *realtime)
{
Realtime_java *java;
Realtime_visu *visu;
MbsData* mbs_data;
JNI_struct *jni_struct;
#ifdef APPLE_VISU
int flag_finish;
#endif
java = realtime->ext->java;
visu = realtime->ext->visu;
mbs_data = realtime->ext->mbs_data;
jni_struct = (JNI_struct*) visu->visu_class;
#ifdef APPLE_VISU
if(pid_fork) // father, in charge of all simulation, except visualization
{
......@@ -367,43 +374,43 @@ void update_java(Simu_realtime *realtime)
}
#endif
user_realtime_visu(mbs_data, java->nb_models, java->nb_q, java->cur_q);
user_realtime_visu(mbs_data, visu->nb_models, visu->nb_q, visu->cur_q);
if (java->visu_past_flag)
if (visu->visu_past_flag)
{
java->visu_past_flag = 0;
java->last_past_q_flag = 1;
visu->visu_past_flag = 0;
visu->last_past_q_flag = 1;
update_jni(java->jni_struct, java, java->nb_models, java->nb_q, java->past_q);
update_jni(jni_struct, visu, visu->nb_models, visu->nb_q, visu->past_q);
}
else if (java->change_viewpoint)
else if (visu->change_viewpoint)
{
if (java->last_past_q_flag)
if (visu->last_past_q_flag)
{
update_jni(java->jni_struct, java, java->nb_models, java->nb_q, java->past_q);
update_jni(jni_struct, visu, visu->nb_models, visu->nb_q, visu->past_q);
}
else
{
update_jni(java->jni_struct, java, java->nb_models, java->nb_q, java->cur_q);
update_jni(jni_struct, visu, visu->nb_models, visu->nb_q, visu->cur_q);
}
}
else
{
java->last_past_q_flag = 0;
visu->last_past_q_flag = 0;
update_jni(java->jni_struct, java, java->nb_models, java->nb_q, java->cur_q);
update_jni(jni_struct, visu, visu->nb_models, visu->nb_q, visu->cur_q);
}
}
/*! \brief update the 3D view with JNI
*
* \param[in] jni_struct JNI structure
* \param[in] java Java real-time structure
* \param[in] visu 3D real-time structure
* \param[in] nb_models number of models
* \param[in] nb_q number of joints to update for the visualization
* \param[in] q_vec vector of size nb_q with the current values to plot
*/
void update_jni(JNI_struct *jni_struct, Realtime_java *java, int nb_models, int *nb_q, double **q_vec)
void update_jni(JNI_struct *jni_struct, Realtime_visu *visu, int nb_models, int *nb_q, double **q_vec)
{
int i;
......@@ -425,21 +432,21 @@ void update_jni(JNI_struct *jni_struct, Realtime_java *java, int nb_models, int
#endif
// adapt the viewpoint
if (java->change_viewpoint)
if (visu->change_viewpoint)
{
java->change_viewpoint = 0;
visu->change_viewpoint = 0;
java->cur_viewpoint++;
visu->cur_viewpoint++;
if (java->cur_viewpoint >= java->nb_viewpoint)
if (visu->cur_viewpoint >= visu->nb_viewpoint)
{
java->cur_viewpoint = START_VIEWPOINT;
visu->cur_viewpoint = START_VIEWPOINT;
}
#ifdef APPLE_VISU
flag_viewpoint = java->cur_viewpoint;
flag_viewpoint = visu->cur_viewpoint;
#else
(*env)->CallObjectMethod(env, jni_struct->obj, jni_struct->setVpMethod, java->cur_viewpoint);
(*env)->CallObjectMethod(env, jni_struct->obj, jni_struct->setVpMethod, visu->cur_viewpoint);
#endif
}
#ifdef APPLE_VISU
......
......@@ -55,7 +55,7 @@ typedef struct JNI_in_out
// functions prototypes
JNIEnv* create_vm(void);
void init_jni(Realtime_java *java, int nb_models, int *nb_q, double **q_vec, char **mbs_file, int start_viewpoint);
void init_jni(Realtime_visu *visu, int nb_models, int *nb_q, double **q_vec, char **mbs_file, int start_viewpoint);
#ifdef APPLE_VISU
void run_java_mac_os(JNI_struct *jni_struct, int nb_models, int *nb_q);
......@@ -64,8 +64,8 @@ void* start_jni(void *args);
void start_jni(JNI_in_out *jni_in_out);
#endif
void update_jni(JNI_struct *jni_struct, Realtime_java *java, int nb_models, int *nb_q, double **q_vec);
void free_jni(JNI_struct *jni_struct);
void update_jni(JNI_struct *jni_struct, Realtime_visu *visu, int nb_models, int *nb_q, double **q_vec);
void free_jni(void *visu_class);
void update_java(Simu_realtime *realtime);
#endif
......
......@@ -27,25 +27,25 @@ void update_past_visu(Simu_realtime *realtime, double tsim)
double **cur_q;
double ***q_save;
Realtime_java *java;
Realtime_visu *visu;
MbsData* mbs_data;
// variables initialization
java = realtime->ext->java;
visu = realtime->ext->visu;
mbs_data = realtime->ext->mbs_data;
nb_models = java->nb_models;
nb_models = visu->nb_models;
nb_q = java->nb_q;
nb_q = visu->nb_q;
min_tsim_index = java->min_tsim_index;
min_tsim_index = visu->min_tsim_index;
tsim_save = java->tsim_save;
q_save = java->q_save;
tsim_save = visu->tsim_save;
q_save = visu->q_save;
buffer_size = java->buffer_size;
buffer_size = visu->buffer_size;
cur_q = java->cur_q;
cur_q = visu->cur_q;
// update the time
tsim_save[min_tsim_index] = tsim;
......@@ -62,21 +62,21 @@ void update_past_visu(Simu_realtime *realtime, double tsim)
}
// update indexes
java->max_tsim_index = min_tsim_index;
visu->max_tsim_index = min_tsim_index;
min_tsim_index++;
if (min_tsim_index >= buffer_size)
{
min_tsim_index = 0;
java->flag_buffer_round = 1;
visu->flag_buffer_round = 1;
}
java->min_tsim_index = min_tsim_index;
visu->min_tsim_index = min_tsim_index;
// update min-max
java->min_tsim = tsim_save[min_tsim_index];
java->max_tsim = tsim;
visu->min_tsim = tsim_save[min_tsim_index];
visu->max_tsim = tsim;
}
/*! \brief update the requested q past visualization vector
......@@ -98,28 +98,28 @@ void q_past_vector(Simu_realtime *realtime)
double **past_q;
double *tsim_save;
Realtime_java *java;
Realtime_visu *visu;
// variables initialization
java = realtime->ext->java;
visu = realtime->ext->visu;
nb_models = java->nb_models;
nb_models = visu->nb_models;
q_save = java->q_save;
past_q = java->past_q;
q_save = visu->q_save;
past_q = visu->past_q;
tsim_save = java->tsim_save;
tsim_save = visu->tsim_save;