diff --git a/Apps/Examples/volumeExplorer.cpp b/Apps/Examples/volumeExplorer.cpp index 4885eaa8ddcf6ba4e964085f05f5a57e80831cd9..8e3c25a2a6fccd26ca4d46ba662996aef4d447c1 100644 --- a/Apps/Examples/volumeExplorer.cpp +++ b/Apps/Examples/volumeExplorer.cpp @@ -144,52 +144,28 @@ void MyQT::cb_Open() size_t pos = filename.rfind("."); // position of "." in filename std::string extension = filename.substr(pos); - if(extension == std::string(".tet")) - { - if(!Algo::Volume::Import::importTet(myMap,filename,attrNames)) - { - CGoGNerr << "could not import " << filename << CGoGNendl ; - return; - } - else - position = myMap.getAttribute(attrNames[0]) ; - } - - if(extension == std::string(".node")) + if(extension == std::string(".off")) { - if(!Algo::Volume::Import::importMeshV(myMap, filename, attrNames, Algo::Volume::Import::NODE)) + if(!Algo::Volume::Import::importMeshToExtrude(myMap, filename, attrNames)) { std::cerr << "could not import " << filename << std::endl ; return ; } else - position = myMap.getAttribute(attrNames[0]) ; - } - - if(extension == std::string(".ts")) - { - if(!Algo::Volume::Import::importMeshV(myMap, filename, attrNames, Algo::Volume::Import::TS)) { - std::cerr << "could not import " << filename << std::endl ; - return ; + position = myMap.getAttribute(attrNames[0]) ; + myMap.closeMap(); } - else - position = myMap.getAttribute(attrNames[0]) ; } - - - if(extension == std::string(".off")) + else { - if(!Algo::Volume::Import::importMeshToExtrude(myMap, filename, attrNames)) + if(!Algo::Volume::Import::importMesh(myMap, filename, attrNames)) { std::cerr << "could not import " << filename << std::endl ; return ; } else - { - position = myMap.getAttribute(attrNames[0]) ; - myMap.closeMap(); - } + position = myMap.getAttribute(attrNames[0]) ; } color = myMap.addAttribute("color"); @@ -397,31 +373,22 @@ int main(int argc, char **argv) size_t pos = filename.rfind("."); // position of "." in filename std::string extension = filename.substr(pos); - if(extension == std::string(".tet")) + if(extension == std::string(".off")) { - if(!Algo::Volume::Import::importTet(myMap,argv[1],attrNames)) + if(!Algo::Volume::Import::importMeshToExtrude(myMap, filename, attrNames)) { - CGoGNerr << "could not import " << argv[1] << CGoGNendl ; + std::cerr << "could not import " << filename << std::endl ; return 1; } else - position = myMap.getAttribute(attrNames[0]) ; - } - - if(extension == std::string(".node")) - { - if(!Algo::Volume::Import::importMeshV(myMap, argv[1], attrNames, Algo::Volume::Import::NODE)) { - std::cerr << "could not import " << argv[1] << std::endl ; - return 1; + position = myMap.getAttribute(attrNames[0]) ; + myMap.closeMap(); } - else - position = myMap.getAttribute(attrNames[0]) ; } - - if(extension == std::string(".ts")) + else { - if(!Algo::Volume::Import::importMeshV(myMap, filename, attrNames, Algo::Volume::Import::TS)) + if(!Algo::Volume::Import::importMesh(myMap, filename, attrNames)) { std::cerr << "could not import " << filename << std::endl ; return 1; @@ -430,20 +397,6 @@ int main(int argc, char **argv) position = myMap.getAttribute(attrNames[0]) ; } - if(extension == std::string(".off")) - { - if(!Algo::Volume::Import::importMeshToExtrude(myMap, argv[1], attrNames)) - { - std::cerr << "could not import " << std::endl ; - return 1; - } - else - { - position = myMap.getAttribute(attrNames[0]) ; - myMap.closeMap(); - } - } - color = myMap.addAttribute("color"); TraversorCell tra(myMap); diff --git a/Apps/Tuto/tuto_dual3.cpp b/Apps/Tuto/tuto_dual3.cpp index d402c9a1b4972d95a5e9b5e70ee82d89657ebbd0..51eeeeff41ba4e1855d6d70bdff899d59852456a 100644 --- a/Apps/Tuto/tuto_dual3.cpp +++ b/Apps/Tuto/tuto_dual3.cpp @@ -61,7 +61,7 @@ int main(int argc, char **argv) PFP::MAP myMap; std::vector attrNames ; - Algo::Volume::Import::importMeshV(myMap, argv[1], attrNames, Algo::Volume::Import::NODE); + Algo::Volume::Import::importMesh(myMap, argv[1], attrNames); // get a handler to the 3D vector attribute created by the import VertexAttribute position = myMap.getAttribute(attrNames[0]); diff --git a/Apps/Tuto/tuto_oper3.cpp b/Apps/Tuto/tuto_oper3.cpp index 05551d897934eeab4a6e4dc0e9e9cdc375ba6032..c0c282fec0b1b8ebc86dc3ff835a5376dc005bf7 100644 --- a/Apps/Tuto/tuto_oper3.cpp +++ b/Apps/Tuto/tuto_oper3.cpp @@ -612,47 +612,20 @@ void MyQT::importMesh(std::string& filename) size_t pos = filename.rfind("."); // position of "." in filename std::string extension = filename.substr(pos); + std::vector attrNames ; if (extension == std::string(".map")) { myMap.loadMapBin(filename); position = myMap.getAttribute("position") ; } - else if (extension == std::string(".node")) - { - std::vector attrNames ; - if(!Algo::Volume::Import::importMeshV(myMap, filename, attrNames, Algo::Volume::Import::NODE)) - { - std::cerr << "could not import " << filename << std::endl ; - return ; - } - position = myMap.getAttribute(attrNames[0]) ; - } - else if(extension == std::string(".tet")) - { - std::vector attrNames ; - if(!Algo::Volume::Import::importMeshV(myMap, filename, attrNames, Algo::Volume::Import::TET)) - { - std::cerr << "could not import " << filename << std::endl ; - return ; - } - position = myMap.getAttribute(attrNames[0]) ; - } - else if(extension == std::string(".off")) - { - std::vector attrNames ; - if(!Algo::Volume::Import::importMeshV(myMap, filename, attrNames, Algo::Volume::Import::OFF)) - { - std::cerr << "could not import " << filename << std::endl ; - return ; - } - position = myMap.getAttribute(attrNames[0]) ; - } - else + else if(!Algo::Volume::Import::importMesh(myMap, filename, attrNames)) { std::cerr << "could not import " << filename << std::endl ; return ; } + else + position = myMap.getAttribute(attrNames[0]) ; m_selected = NIL; m_selected2 = NIL; diff --git a/SCHNApps/Plugins/CMakeLists.txt b/SCHNApps/Plugins/CMakeLists.txt index 429a1cea89215ea878fc22ba497aa344dcf49bc7..512bc2e23f9fb81b339e88325a04cd1c4878a580 100644 --- a/SCHNApps/Plugins/CMakeLists.txt +++ b/SCHNApps/Plugins/CMakeLists.txt @@ -1,6 +1,7 @@ cmake_minimum_required(VERSION 2.8) ADD_SUBDIRECTORY(importSurface) +ADD_SUBDIRECTORY(importVolume) ADD_SUBDIRECTORY(differentialProperties) ADD_SUBDIRECTORY(render) ADD_SUBDIRECTORY(renderVector) diff --git a/SCHNApps/Plugins/importVolume/CMakeLists.txt b/SCHNApps/Plugins/importVolume/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..8f55142ba917bacca2bf286a99f9962e28474348 --- /dev/null +++ b/SCHNApps/Plugins/importVolume/CMakeLists.txt @@ -0,0 +1,71 @@ +cmake_minimum_required(VERSION 2.8) + +INCLUDE_DIRECTORIES( + ${SCHNApps_ROOT_DIR}/include + ${SCHNApps_ROOT_DIR}/Plugins/importVolume + ${CMAKE_CURRENT_BINARY_DIR} +) + +SET( PLUGIN_SRC + ${SCHNApps_ROOT_DIR}/Plugins/importVolume/importVolume.cpp +) + +SET( PLUGIN_H + ${SCHNApps_ROOT_DIR}/Plugins/importVolume/importVolume.h +) + +IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug ) + + ADD_DEFINITIONS(-DDEBUG) + + IF(WIN32) + link_directories( ${CGoGN_ROOT_DIR}/lib/Release ) + ELSE (WIN32) + link_directories( ${CGoGN_ROOT_DIR}/lib/Debug ${CGoGN_ROOT_DIR}/lib/Release ) + ENDIF (WIN32) + +# QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} ) + QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} ) + + ADD_LIBRARY( ImportVolumePluginD SHARED + ${PLUGIN_SRC} + ${PLUGIN_UI} + ${PLUGIN_MOC} + ) + + TARGET_LINK_LIBRARIES( ImportVolumePluginD + ${CGoGN_LIBS_D} + ${COMMON_LIBS} + ${QGLVIEWER_LIBRARIES} + ) + + ADD_DEPENDENCIES( ImportVolumePluginD SCHNAppsD ) + + SET_TARGET_PROPERTIES( ImportVolumePluginD PROPERTIES COMPILE_DEFINITIONS "DEBUG" ) + +ELSE ( ${CMAKE_BUILD_TYPE} STREQUAL Debug ) + + IF(WIN32) + link_directories( ${CGoGN_ROOT_DIR}/lib/Release ) + ELSE (WIN32) + link_directories( ${CGoGN_ROOT_DIR}/lib/Release ) + ENDIF (WIN32) + +# QT4_WRAP_UI( PLUGIN_UI ${PLUGIN_FORM} ) + QT4_WRAP_CPP( PLUGIN_MOC ${PLUGIN_H} ) + + ADD_LIBRARY( ImportVolumePlugin SHARED + ${PLUGIN_SRC} + ${PLUGIN_UI} + ${PLUGIN_MOC} + ) + + TARGET_LINK_LIBRARIES( ImportVolumePlugin + ${CGoGN_LIBS_R} + ${COMMON_LIBS} + ${QGLVIEWER_LIBRARIES} + ) + + ADD_DEPENDENCIES( ImportVolumePlugin SCHNApps ) + +ENDIF ( ${CMAKE_BUILD_TYPE} STREQUAL Debug ) diff --git a/SCHNApps/Plugins/importVolume/importVolume.cpp b/SCHNApps/Plugins/importVolume/importVolume.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1b6711f387afbf492287986ec184db61f6055124 --- /dev/null +++ b/SCHNApps/Plugins/importVolume/importVolume.cpp @@ -0,0 +1,54 @@ +#include "importVolume.h" + +#include "mapHandler.h" + +#include "Algo/Import/import.h" + +#include +#include + +bool ImportVolumePlugin::enable() +{ + importAction = new QAction("import", this); + addMenuAction("Volume;Import", importAction); + connect(importAction, SIGNAL(triggered()), this, SLOT(cb_import())); + return true; +} + +void ImportVolumePlugin::cb_import() +{ + QString fileName = QFileDialog::getOpenFileName(m_window, "Import file", m_window->getAppPath(), "Mesh Files (*.node *.ts *.off *.tet)"); + QFileInfo fi(fileName); + + if(fi.exists()) + { + GenericMap* m = m_window->createMap(3); + PFP3::MAP* map = static_cast(m); + MapHandler* h = new MapHandler(fi.baseName(), m_window, map); + + std::vector attrNames ; + Algo::Volume::Import::importMesh(*map, fileName.toUtf8().constData(), attrNames); + + // get vertex position attribute + VertexAttribute position = map->getAttribute(attrNames[0]); + + // create VBO for vertex position attribute + h->createVBO(position); + + // compute map bounding box + h->updateBB(position); + + // compute primitive connectivity VBOs + h->updatePrimitives(Algo::Render::GL2::POINTS); + h->updatePrimitives(Algo::Render::GL2::LINES); + h->updatePrimitives(Algo::Render::GL2::TRIANGLES); + + m_window->addMap(h); + } +} + +#ifndef DEBUG +Q_EXPORT_PLUGIN2(ImportVolumePlugin, ImportVolumePlugin) +#else +Q_EXPORT_PLUGIN2(ImportVolumePluginD, ImportVolumePlugin) +#endif diff --git a/SCHNApps/Plugins/importVolume/importVolume.h b/SCHNApps/Plugins/importVolume/importVolume.h new file mode 100644 index 0000000000000000000000000000000000000000..c693343c3a9d21f1bb9ec11e08efd94d79dba53f --- /dev/null +++ b/SCHNApps/Plugins/importVolume/importVolume.h @@ -0,0 +1,51 @@ +#ifndef _IMPORTSURFACE_PLUGIN_H_ +#define _IMPORTSURFACE_PLUGIN_H_ + +#include "plugin.h" + + +using namespace CGoGN; +using namespace SCHNApps; + + +class ImportVolumePlugin : public Plugin +{ + Q_OBJECT + Q_INTERFACES(CGoGN::SCHNApps::Plugin) + +public: + ImportVolumePlugin() + { + setProvidesRendering(false); + } + + ~ImportVolumePlugin() + {} + + virtual bool enable(); + virtual void disable() {} + + virtual void redraw(View *view) {} + + virtual void keyPress(View* view, int key) {} + virtual void keyRelease(View* view, int key) {} + virtual void mousePress(View* view, int button, int x, int y) {} + virtual void mouseRelease(View* view, int button, int x, int y) {} + virtual void mouseMove(View* view, int buttons, int x, int y) {} + virtual void wheelEvent(View* view, int delta, int x, int y) {} + + virtual void viewLinked(View* view) {} + virtual void viewUnlinked(View* view) {} + virtual void currentViewChanged(View* view) {} + + virtual void mapLinked(View* view, MapHandlerGen* m) {} + virtual void mapUnlinked(View* view, MapHandlerGen* m) {} + +public slots: + void cb_import(); + +private: + QAction* importAction; +}; + +#endif diff --git a/include/Algo/Import/import.h b/include/Algo/Import/import.h index b40da78184e21c51555e12c49e4f1272cacd7056..b9a270c1203b855d33aa453164987e5ecf5ca743 100644 --- a/include/Algo/Import/import.h +++ b/include/Algo/Import/import.h @@ -84,7 +84,7 @@ namespace Import * @return a boolean indicating if import was successful */ template -bool importMeshV(typename PFP::MAP& map, const std::string& filename, std::vector& attrNames, bool mergeCloseVertices = false); +bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector& attrNames, bool mergeCloseVertices = false); /** * import a mesh and extrude it diff --git a/include/Algo/Import/importMesh.hpp b/include/Algo/Import/importMesh.hpp index 2c9d27b5feb2b97af679c281151e2f6fcd9c57df..4fb93c403db9bb875aed307cc345661a63d05907 100644 --- a/include/Algo/Import/importMesh.hpp +++ b/include/Algo/Import/importMesh.hpp @@ -507,7 +507,7 @@ bool importMesh(typename PFP::MAP& map, MeshTablesVolume& mtv) template -bool importMeshV(typename PFP::MAP& map, const std::string& filename, std::vector& attrNames, bool mergeCloseVertices) +bool importMesh(typename PFP::MAP& map, const std::string& filename, std::vector& attrNames, bool mergeCloseVertices) { ImportType kind = Volume::Import::UNKNOWNVOLUME;