Commit 54a54d61 authored by Nicolas Van der Noot's avatar Nicolas Van der Noot

mbsyscopy update

parent db32788d
......@@ -30,6 +30,10 @@ function(optionnal_modules_flags)
# MBS-LMGC interaction
option (FLAG_ADDON_MBSLMGC "Including MBS-LMGC Addon" OFF)
## -- Application for generating vtk/paraview files --##
# paraview output
option (FLAG_VTK_OUTPUT "Build the application to generate VTK/ParaView files" OFF)
## -- Application for generating user files --##
option (FLAG_APP_USERFILES "Application for generating project specific user files" ON)
......
#
# author: Nicolas Docquier, starting from the FindOpenGL file of
# Nicolas Van der Noot
#
# This file finds the include folders (header files) of the glm library
# (math utilities for open gl). It is is useful when we want to use
# glm but not open gl (for instance for the vtk output.
#
# OPEN_GL_FOUND : 1 if all required files found (0 otherwise)
# OPEN_GL_INCLUDE_PATH : include paths (for the header files) -> for compilation
# OPEN_GL_LIBS : libraries -> for linkage
#
if (UNIX)
if (APPLE)
## ---- MAC OS ---- ##
# possible paths for: 'glm.hpp'
set(TRIAL_PATHS_GLM
/usr/local/include/glm/
)
find_path(PATH_GLM glm.hpp ${TRIAL_PATHS_GLM} )
set(GLM_INCLUDE_PATH ${PATH_GLM} )
## ---------------- ##
else (APPLE)
## ---- LINUX ---- ##
# possible paths for: 'glm.hpp'
set(TRIAL_PATHS_GLM
/usr/include/glm/
)
find_path(PATH_GLM glm.hpp ${TRIAL_PATHS_GLM} )
set(GLM_INCLUDE_PATH ${PATH_GLM} )
## --------------- ##
endif (APPLE)
else (UNIX)
## ---- WINDOWS ---- ##
# possible paths for: 'glm.hpp'
set(TRIAL_PATHS_GLM
${ROBOTRAN_SOURCE_DIR}/${WIN_LIB_DIRECTORY}/include/glm
)
find_path(PATH_GLM glm.hpp ${TRIAL_PATHS_GLM} )
set(GLM_INCLUDE_PATH ${PATH_GLM} )
## ----------------- ##
endif (UNIX)
# flag put to 1 if all required files are found
if (GLM_INCLUDE_PATH)
set(GLM_FOUND 1)
else ( )
set(GLM_FOUND 0)
endif ( )
# outputs
mark_as_advanced(
GLM_FOUND
GLM_INCLUDE_PATH
)
#
# author: Nicolas Van der Noot
#
# Visualization project for Robotran, with OpenGL
#
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# PROJECT MAIN CONFIGURATIONS
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# CMake minimum version
cmake_minimum_required(VERSION 2.8.12)
# project name
project (TestVrml)
# message to display the project name
message(STATUS "Processing ${PROJECT_NAME}")
# for Unix: display all the warnings, except the ones related to /* -- */
if (UNIX)
set(CMAKE_C_FLAGS "-g -Wall -Wno-comment")
endif (UNIX)
# configure header files to pass some of the CMake settings to the source code
set (ROBOTRAN_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../..")
# additional CMake functions
set(CMAKE_AUX ${ROBOTRAN_SOURCE_DIR}/cmake_aux)
set(CMAKE_AUX_BIN ${PROJECT_BINARY_DIR}/cmake_aux)
add_subdirectory ( ${CMAKE_AUX}/listing/ ${CMAKE_AUX_BIN}/listing/ )
add_subdirectory ( ${CMAKE_AUX}/libraries/ ${CMAKE_AUX_BIN}/libraries/ )
# Windows M_PI definitions
if (WIN32)
add_definitions(-D _USE_MATH_DEFINES)
endif (WIN32)
# project own definition
add_definitions(-D OPEN_GL)
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# USER ABSOLUTE PATHS
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
configure_file (
"${ROBOTRAN_SOURCE_DIR}/conf/cmake_config.h.in"
"${PROJECT_BINARY_DIR}/conf/cmake_config.h"
)
set(OPEN_GL_FILES_PATH ${PROJECT_SOURCE_DIR}/../mbs_common/mbs_realtime/open_gl/)
configure_file (
"${ROBOTRAN_SOURCE_DIR}/mbs_common/mbs_realtime/open_gl/conf/cmake_open_gl_config.h.in"
"${PROJECT_BINARY_DIR}/conf/cmake_open_gl_config.h"
)
# 'cmake_config.h.in' and 'cmake_open_gl_config.h.in' is in the 'conf' folder
include_directories (${PROJECT_BINARY_DIR}/conf)
include_directories ("/usr/include/glm/")
include_directories (${ROBOTRAN_SOURCE_DIR}/mbs_common/mbs_realtime/open_gl/loader/vrml)
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# EXTERNAL LIBRARIES
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../conf)
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# CONFIGURE EXECUTABLE
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# include these directories
include_directories (${INCLUDE_DIR})
# name of the executable
set (Executable Exec)
# generate the executable
add_executable (${Executable} ./src/main.cc ${ROBOTRAN_SOURCE_DIR}/mbs_common/mbs_realtime/open_gl/loader/vrml/VrmlLoader.cc)
# link library: Libxml2
target_link_libraries ( ${Executable} ${LIBXML2_LIBRARIES} )
# link library: OpenGL
target_link_libraries ( ${Executable} ${OPEN_GL_LIBS})
# math external library (for Unix): linkage
if (UNIX)
target_link_libraries (${Executable} m)
endif (UNIX)
#include "VrmlLoader.hh"
#include <vector>
/*! \brief Test file for the VRML loader. Simply try to parse the vrml,
* and to retrieve the triangles
*/
int main(int argc, char **argv)
{
// get the shader flag and the mutlisampling option from .mbs file
OpenGLMbs::VrmlLoader loader;
int success = 0;
//success = loader.ParseVRML("../vrml/Arm2.wrl");
//success = loader.ParseVRML("../vrml/pendulum2.wrl");
//success = loader.ParseVRML("../vrml/ElmeBoard.wrl");
//success = loader.ParseVRML("../vrml/Chassis2.wrl");
success = loader.ParseVRML("../vrml/Chassis_ML.wrl");
std::cout << "Parsing finished with returned value: " <<success<< std::endl;
std::vector<glm::vec3> vert;
std::vector<glm::vec3> col;
loader.PushVertices(vert, col);
}
#
# author: Nicolas Van der Noot
#
# Visualization project for Robotran, with OpenGL
#
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# PROJECT MAIN CONFIGURATIONS
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# CMake minimum version
cmake_minimum_required(VERSION 2.8.12)
# project name
project (VtkOutput)
# Retriev the MBsysC base directory
set (ROBOTRAN_SOURCE_DIR "${PROJECT_SOURCE_DIR}/../..")
# message to display the project name
message(STATUS "Processing ${PROJECT_NAME}")
# for Unix: display all the warnings, except the ones related to /* -- */
if (UNIX)
set(CMAKE_C_FLAGS "-g -Wall -Wno-comment")
endif (UNIX)
# copy dll files used for Windows
# these dll files are copied in the Executable directory (Debug or Release)
if (WIN32)
# avoid warnings
if(COMMAND cmake_policy AND ${CMAKE_VERSION} VERSION_GREATER "3.1")
cmake_policy(SET CMP0054 NEW)
endif()
# Visual studio version
if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
if (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 18.0)
message("Visual Studio version set to VS2012 (${CMAKE_CXX_COMPILER_VERSION})")
set(MSVC_VERSION lib-vc2012)
elseif (${CMAKE_CXX_COMPILER_VERSION} VERSION_LESS 19.0)
message("Visual Studio version set to VS2013 (${CMAKE_CXX_COMPILER_VERSION})")
set(MSVC_VERSION lib-vc2013)
else ( )
message("Visual Studio version set to VS2015 (${CMAKE_CXX_COMPILER_VERSION})")
set(MSVC_VERSION lib-vc2015)
endif ( )
else ( )
message(FATAL_ERROR "CMake error: only Visual Studio projects can currently be used on Windows !")
endif ( )
# WIN32 or WIN64 detetction
if( CMAKE_SIZEOF_VOID_P EQUAL 8 ) # 64bit Windows
SET(WIN_LIB_DIRECTORY win64_include_lib)
else( ) # 32bit Windows
SET(WIN_LIB_DIRECTORY win32_include_lib)
endif( )
# common dll
file(COPY ${ROBOTRAN_SOURCE_DIR}/${WIN_LIB_DIRECTORY}/dll/ DESTINATION ${CMAKE_BINARY_DIR}/Debug)
file(COPY ${ROBOTRAN_SOURCE_DIR}/${WIN_LIB_DIRECTORY}/dll/ DESTINATION ${CMAKE_BINARY_DIR}/Release)
# GLFW
file(COPY ${ROBOTRAN_SOURCE_DIR}/${WIN_LIB_DIRECTORY}/dll/GLFW/${MSVC_VERSION}/ DESTINATION ${CMAKE_BINARY_DIR}/Debug)
file(COPY ${ROBOTRAN_SOURCE_DIR}/${WIN_LIB_DIRECTORY}/dll/GLFW/${MSVC_VERSION}/ DESTINATION ${CMAKE_BINARY_DIR}/Release)
endif ( )
# additional CMake functions
set(CMAKE_AUX ${ROBOTRAN_SOURCE_DIR}/cmake_aux)
set(CMAKE_AUX_BIN ${PROJECT_BINARY_DIR}/cmake_aux)
add_subdirectory ( ${CMAKE_AUX}/listing/ ${CMAKE_AUX_BIN}/listing/ )
add_subdirectory ( ${CMAKE_AUX}/libraries/ ${CMAKE_AUX_BIN}/libraries/ )
# Windows M_PI definitions
if (WIN32)
add_definitions(-D _USE_MATH_DEFINES)
endif (WIN32)
# project own definition
add_definitions(-D SEPARATE_OPEN_GL)
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# USER ABSOLUTE PATHS
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# configure header files to pass some of the CMake settings to the source code
configure_file (
"${ROBOTRAN_SOURCE_DIR}/conf/cmake_config.h.in"
"${PROJECT_BINARY_DIR}/conf/cmake_config.h"
)
set(OPEN_GL_FILES_PATH ${ROBOTRAN_SOURCE_DIR}/mbs_common/mbs_realtime/open_gl/)
configure_file (
"${OPEN_GL_FILES_PATH}/conf/cmake_open_gl_config.h.in"
"${PROJECT_BINARY_DIR}/conf/cmake_open_gl_config.h"
)
# 'cmake_config.h.in' and 'cmake_open_gl_config.h.in' is in the 'conf' folder
include_directories (${PROJECT_BINARY_DIR}/conf)
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# EXTERNAL LIBRARIES
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
set(CMAKE_MODULE_PATH ${ROBOTRAN_SOURCE_DIR}/conf)
# Libxml2
xml_lib(main)
# VTK
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
# Glm
find_package(Glm REQUIRED)
include_directories("${GLM_INCLUDE_PATH}/")
message("Glm ${GLM_INCLUDE_PATH}")
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# LIST FILES
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# list source files to compile
init_src()
increment_src("${PROJECT_SOURCE_DIR}/src/renderer")
increment_src("${OPEN_GL_FILES_PATH}/anim_read")
increment_src("${OPEN_GL_FILES_PATH}/components")
increment_src("${OPEN_GL_FILES_PATH}/lights")
increment_src("${OPEN_GL_FILES_PATH}/lights/specific")
increment_src("${OPEN_GL_FILES_PATH}/loader")
increment_src("${OPEN_GL_FILES_PATH}/mbs_read")
increment_src("${OPEN_GL_FILES_PATH}/shapes")
increment_src("${OPEN_GL_FILES_PATH}/viewpoint")
increment_src("${OPEN_GL_FILES_PATH}/renderer/default")
set(SOURCE_FILES ${SOURCE_FILES} "${OPEN_GL_FILES_PATH}/world/MbsWorld3D.cc")
set(SOURCE_FILES ${SOURCE_FILES} src/MbsVtkOutputter.cc)
# list include directories (to find headers)
init_include()
increment_include("${PROJECT_SOURCE_DIR}/src/")
increment_include("${PROJECT_SOURCE_DIR}/src/renderer")
include_directories("${OPEN_GL_FILES_PATH}/")
include_directories("${OPEN_GL_FILES_PATH}/anim_read")
include_directories("${OPEN_GL_FILES_PATH}/components")
include_directories("${OPEN_GL_FILES_PATH}/lights")
include_directories("${OPEN_GL_FILES_PATH}/lights/specific")
include_directories("${OPEN_GL_FILES_PATH}/loader")
include_directories("${OPEN_GL_FILES_PATH}/loader/vrml")
include_directories("${OPEN_GL_FILES_PATH}/loader/obj")
include_directories("${OPEN_GL_FILES_PATH}/loader/stl")
include_directories("${OPEN_GL_FILES_PATH}/mbs_read")
include_directories("${OPEN_GL_FILES_PATH}/shaders")
include_directories("${OPEN_GL_FILES_PATH}/shapes")
include_directories("${OPEN_GL_FILES_PATH}/shapes/specific")
include_directories("${OPEN_GL_FILES_PATH}/viewpoint")
include_directories("${OPEN_GL_FILES_PATH}/viewpoint/specific")
include_directories("${OPEN_GL_FILES_PATH}/world")
include_directories("${OPEN_GL_FILES_PATH}/renderer")
include_directories("${OPEN_GL_FILES_PATH}/renderer/default")
include_directories("${OPEN_GL_FILES_PATH}/window")
add_definitions( -DOPEN_GL )
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# CONFIGURE main library
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# include these directories
include_directories (${INCLUDE_DIR})
# name of the libraryr
set (LibMbsVtk MbsVtk)
add_library(${LibMbsVtk} SHARED ${SOURCE_FILES})
target_link_libraries ( ${LibMbsVtk} ${LIBXML2_LIBRARIES} ${VTK_LIBRARIES})
# math external library (for Unix): linkage
if (UNIX)
target_link_libraries (${LibMbsVtk} m)
endif (UNIX)
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# CONFIGURE standalone executable
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# name of the executable
set (Executable Vtk_output)
# generate the executable
add_executable (${Executable} src/main.cc)
# link library: Libxml2
target_link_libraries ( ${Executable} ${LibMbsVtk} ${LIBXML2_LIBRARIES} ${VTK_LIBRARIES})
# math external library (for Unix): linkage
if (UNIX)
target_link_libraries (${Executable} m)
endif (UNIX)
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
# Python interface
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
find_package(Python REQUIRED)
include_directories(${PYTHON_INCLUDE_DIR}
${NUMPY_INCLUDE_DIR}
${CMAKE_CURRENT_SOURCE_DIR}
)
# Set library extension
if(UNIX)
set(IPY_LIB_EXT ".so")
elseif(WIN32)
set(IPY_LIB_EXT ".pyd")
else()
message("Unknow operating system, extension for cython library arbitrary choosen: .so")
set(IPY_LIB_EXT ".so")
endif()
set( cxx_arg "--cplus" )
set( pyx_lang "CXX" )
set(LibPyMbsVtk CyMbsVtk)
file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/CyMbsVtk.cpp)
add_custom_command(OUTPUT CyMbsVtk.cpp
COMMAND ${CYTHON_EXECUTABLE} -f ${CMAKE_CURRENT_SOURCE_DIR}/src/CyMbsVtk.pyx -o ${CMAKE_CURRENT_BINARY_DIR}/CyMbsVtk.cpp
ARGS ${cxx_arg}
IMPLICIT_DEPENDS ${pyx_lang}
DEPENDS src/CyMbsVtk.pyx
)
add_library(${LibPyMbsVtk} SHARED ${CMAKE_CURRENT_BINARY_DIR}/CyMbsVtk.cpp)
set_target_properties(${LibPyMbsVtk} PROPERTIES PREFIX "" )
set_target_properties(${LibPyMbsVtk} PROPERTIES SUFFIX "${IPY_LIB_EXT}" )
target_link_libraries(${LibPyMbsVtk} ${LibMbsVtk} ${LIBXML2_LIBRARIES} m ${VTK_LIBRARIES} ${PYTHON_LIBRARIES})
# distutils: language = c++
# distutils: sources = CyMbsVtk.cpp
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
from libcpp.string cimport string
cimport numpy as np
np.import_array() # initialize C API to call PyArray_SimpleNewFromData
#cdef public api tonumpyarray(double* data, long long size) with gil:
# if not (data and size >= 0): raise ValueError
# cdef np.npy_intp dims = size
# #NOTE: it doesn't take ownership of `data`. You must free `data` yourself
# return np.PyArray_SimpleNewFromData(1, &dims, np.NPY_DOUBLE, <void*>data)
# * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
from libcpp.vector cimport vector
cdef extern from "MbsVtkOutputter.hh":
cdef cppclass MbsVtkOutputter:
MbsVtkOutputter(string)
void SetOutputDirectory(string)
void SetOutputFilename(string)
void SetFrameStep(int)
void PrintFiles(string)
void InitPvd()
void WriteDisplayFiles(int, double, double*)
void FinalizePvd()
cdef class CyMbsVtkOutputter:
cdef MbsVtkOutputter *thisptr
def __cinit__(self, mbsfile, outputDir=None, outputName=None, fs=None):
self.thisptr = new MbsVtkOutputter(mbsfile)
if outputDir:
self.thisptr.SetOutputDirectory(outputDir)
if outputName:
self.thisptr.SetOutputFilename(outputName)
if fs:
self.thisptr.SetFrameStep(fs)
def __dealloc__(self):
del self.thisptr
def SetOutputDirectory(self, directory):
self.thisptr.SetOutputDirectory(directory)
def SetOutputFilename(self, name):
self.thisptr.SetOutputFilename(name)
def SetFrameStep(self, fs):
self.thisptr.SetFrameStep(fs)
def PrintFiles(self, animfile):
self.thisptr.PrintFiles(animfile)
\ No newline at end of file
/*!
* \author Nicolas Docquier
*/
#include "MbsVtkOutputter.hh"
#include "MbsWorld3D.hh"
#include "AnimReader.hh"
#include "VtkWorldRenderer.hh"
#include <sstream>
#define MBS_ID 0
/*! \brief constructor
*
* \param[in] mbs_file name of the *.mbs file from which to load
* the model
*
*
*/
MbsVtkOutputter::MbsVtkOutputter(std::string mbs_file){
// initialize the world renderer
world_renderer = new OpenGLMbs::VtkWorldRenderer();
// main window for 3D world
world_3d = new OpenGLMbs::MbsWorld3D(1024, 768, 0, 0, glm::vec3(0.0, 0.0, 0.0),
world_renderer);
// load mbs file
world_3d->AddMbs(mbs_file.c_str());
// initialize the joint vec
joint_vec = new double[world_3d->GetNbJoints(MBS_ID)];
// default number of frame between two files
frame_step = 100;
// initialize the counter
outfileCounter = 0;
//default output name
output_name = "anim";
}
/*! \brief destructor
*/
MbsVtkOutputter::~MbsVtkOutputter(){
delete[] joint_vec;
delete world_3d;
delete world_renderer;
}
/*! \brief set the directory in which to put the output files
*
* \param[in] dir the directory
*
*/
void MbsVtkOutputter::SetOutputDirectory(std::string dir){
output_dir = dir;
}
/*! \brief set the name of the output files. Will be extended with an
* index and the appropriate file extension.
*
* \param[in] dir the name
*
*/
void MbsVtkOutputter::SetOutputFilename(std::string name){
output_name = name;
}
void MbsVtkOutputter::SetFrameStep(int fs){
frame_step = fs;
}
/*! \brief Read the animation file and write the paraview files.
*
* \param[in] anim_file name of the *.anim or *.res file from which
* to load the results to animate
*
*/
void MbsVtkOutputter::PrintFiles(std::string anim_filename){
// Initialize and read animamtion
OpenGLMbs::AnimReader* anim_reader;
anim_reader = new OpenGLMbs::AnimReader(anim_filename.c_str());
// get the number of joint
int nb_joints = world_3d->GetNbJoints(MBS_ID);
//re-init file counter
outfileCounter=0;
// open the ParaView’s native data file format (PVD)
std::ostringstream pvdname;
pvdname << output_dir << "/" << output_name << ".pvd";
ofstream fpvd(pvdname.str().c_str(), ios::trunc);
// initialize the pvd file
fpvd << "<?xml version=\"1.0\"?>" << endl;
fpvd << "<VTKFile type=\"Collection\" version=\"0.1\" byte_order=\"LittleEndian\">"<< endl;
fpvd << "<Collection>"<< endl;
// loop
for(int i=0; i<anim_reader->getNbStep(); i+=frame_step)
{
// increment file counter
outfileCounter++;
// fill Q values by reading the anim
anim_reader->FillQIndex(i, nb_joints, joint_vec);
// update joints
world_3d->UpdateJoints(MBS_ID, nb_joints, joint_vec);
// set the filename
std::ostringstream filename;
filename << output_dir << "/" << output_name << outfileCounter << ".vtu";
world_renderer->SetOutputPath(filename.str());
// write the vtp file
world_3d->Update();
// update the pvd file
fpvd<< "<DataSet timestep=\""<<anim_reader->getTime(i)<<"\" group=\"\" part=\"0\" file=\""<< filename.str() <<"\"/>" << endl;
}
// finalyze the pvd file
fpvd<< "</Collection>"<< endl;
fpvd<< "</VTKFile>";
fpvd.close();
// Freeing
delete anim_reader;
}
/*! \brief Write the header of the *.pvd file.
*
*/
void MbsVtkOutputter::InitPvd(){