Commit 3e67b53f authored by Thery Sylvain's avatar Thery Sylvain

Merge cgogn:CGoGN

parents 77c64075 f49ba1e9
...@@ -330,6 +330,7 @@ void MyQT::cb_mousePress(int button, int x, int y) ...@@ -330,6 +330,7 @@ void MyQT::cb_mousePress(int button, int x, int y)
{ {
if (d != Dart::nil()) if (d != Dart::nil())
m_selected = d; m_selected = d;
std::cout << myMap.edgeCanCollapse(d) << std::endl;
} }
if (button == Qt::RightButton) if (button == Qt::RightButton)
{ {
...@@ -650,11 +651,14 @@ void MyQT::importMesh(std::string& filename) ...@@ -650,11 +651,14 @@ void MyQT::importMesh(std::string& filename)
else else
{ {
std::cerr << "could not import " << filename << std::endl ; std::cerr << "could not import " << filename << std::endl ;
return ;
} }
m_selected = NIL; m_selected = NIL;
m_selected2 = NIL; m_selected2 = NIL;
m_render_topo->updateData<PFP>(myMap, position, m_ex1,m_ex2,m_ex3, nb);
bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ; bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position) ;
setParamObject(bb.maxSize(), bb.center().data()) ; setParamObject(bb.maxSize(), bb.center().data()) ;
m_shift = bb.maxSize()/200.0f; m_shift = bb.maxSize()/200.0f;
......
...@@ -92,7 +92,7 @@ private: ...@@ -92,7 +92,7 @@ private:
// Assigne un nouveau plongement au sommet. Les anciens plongements sont libérés. // Assigne un nouveau plongement au sommet. Les anciens plongements sont libérés.
void newVertex(Dart d) { void newVertex(Dart d) {
embedNewCell<VERTEX>(d); setOrbitEmbeddingOnNewCell<VERTEX>(d);
} }
public: public:
......
...@@ -88,6 +88,15 @@ AttributeHandler<PFP::VEC3> normal; ...@@ -88,6 +88,15 @@ AttributeHandler<PFP::VEC3> normal;
class QuadMesh : public EmbeddedMap2 class QuadMesh : public EmbeddedMap2
{ {
private: private:
// 3 brins de la carte
Dart d_carre;
Dart d_tri;
Dart d_multiFaces;
// Assigne un nouveau plongement au sommet. Les anciens plongements sont libérés.
void newVertex(Dart d) {
setOrbitEmbeddingOnNewCell(VERTEX,d);
}
public: public:
void createMesh() { void createMesh() {
......
cmake_minimum_required(VERSION 2.8)
project(SCHNApps)
SET( QT_USE_QTXML TRUE )
SET( QT_USE_QTDESIGNER TRUE )
SET( QT_USE_QTGUI TRUE )
SET( QT_USE_QTPLUGIN TRUE )
#========CGoGN========#
SET(CGoGN_ROOT_DIR ${CMAKE_SOURCE_DIR}/.. CACHE STRING "CGoGN root dir")
INCLUDE(${CGoGN_ROOT_DIR}/apps_cmake.txt)
#=======QGLViewer=========#
find_package(QGLViewer REQUIRED)
#======SCHNApps=======#
SET(SCHNApps_ROOT_DIR ${CGoGN_ROOT_DIR}/SCHNApps)
SET(EXECUTABLE_OUTPUT_PATH ${SCHNApps_ROOT_DIR}/bin)
SET(LIBRARY_OUTPUT_PATH ${SCHNApps_ROOT_DIR}/plugins/lib)
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/Release Release)
IF (NOT WIN32)
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/Debug Debug)
ENDIF (NOT WIN32)
configure_file(${CMAKE_SOURCE_DIR}/settings/state_save.xml ${EXECUTABLE_OUTPUT_PATH}/state_save.xml @ONLY)
#======Documentation=======#
find_package(Doxygen)
if(DOXYGEN_FOUND)
configure_file(${CMAKE_SOURCE_DIR}/doc/Doxyfile.in ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile @ONLY)
add_custom_target(doc
${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
WORKING_DIRECTORY ${CMAKE_SOURCE_DIR}/Doc
COMMENT "Generating API documentation with Doxygen" VERBATIM
)
endif(DOXYGEN_FOUND)
cmake_minimum_required(VERSION 2.8)
SET(CMAKE_BUILD_TYPE Debug)
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)
INCLUDE_DIRECTORIES(
${CGoGN_ROOT_DIR}/include
${COMMON_INCLUDES}
${CMAKE_CURRENT_SOURCE_DIR}
${CMAKE_CURRENT_BINARY_DIR}
${QGLVIEWER_INCLUDE_DIR}
${SCHNApps_ROOT_DIR}/include
)
file(
GLOB
SCHNApps_SRC_FILES
${SCHNApps_ROOT_DIR}/src/main.cpp
${SCHNApps_ROOT_DIR}/src/interface/*.cpp
${SCHNApps_ROOT_DIR}/src/visualization/*.cpp
${SCHNApps_ROOT_DIR}/src/dialogs/*.cpp
)
SET(SCHNApps_H_OBJECT_FILES
${SCHNApps_ROOT_DIR}/include/interface/window.h
${SCHNApps_ROOT_DIR}/include/interface/system.h
${SCHNApps_ROOT_DIR}/include/interface/viewButtonArea.h
${SCHNApps_ROOT_DIR}/include/interface/splitArea.h
${SCHNApps_ROOT_DIR}/include/visualization/view.h
${SCHNApps_ROOT_DIR}/include/visualization/scene.h
${SCHNApps_ROOT_DIR}/include/dialogs/newSceneDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/sceneSelector.h
${SCHNApps_ROOT_DIR}/include/dialogs/cameraViewDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/cameraOptionDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/cameraSceneDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/globalCameraDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/pluginDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/linkViewDialog.h
${SCHNApps_ROOT_DIR}/include/dialogs/mapPluginDialog.h
)
file(
GLOB
SCHNApps_FORM_FILES
${SCHNApps_ROOT_DIR}/forms/*.ui
)
QT4_WRAP_UI( UI_H_FILES
${SCHNApps_FORM_FILES}
)
QT4_WRAP_CPP( MOC_FILES
${SCHNApps_H_OBJECT_FILES}
)
QT4_ADD_RESOURCES( RCC_FILES
${SCHNApps_ROOT_DIR}/resources/resources.qrc
)
ADD_EXECUTABLE( SCHNAppsD
${SCHNApps_SRC_FILES}
${UI_H_FILES}
${MOC_FILES}
${RCC_FILES}
)
TARGET_LINK_LIBRARIES( SCHNAppsD
${CGoGN_LIBS_D}
${COMMON_LIBS}
${QGLVIEWER_LIBRARIES}
)
ADD_SUBDIRECTORY(${SCHNApps_ROOT_DIR}/Plugins PluginsD)
cmake_minimum_required(VERSION 2.8)
ADD_SUBDIRECTORY(firstPlugin)
cmake_minimum_required(VERSION 2.8)
INCLUDE_DIRECTORIES(
${SCHNApps_ROOT_DIR}/include
${SCHNApps_ROOT_DIR}/Plugins/firstPlugin/include
${CMAKE_CURRENT_BINARY_DIR}
)
SET( FIRSTPLUGIN_PLUGIN_SRC
${SCHNApps_ROOT_DIR}/src/plugins/visualPlugin.cpp
${SCHNApps_ROOT_DIR}/Plugins/firstPlugin/src/firstPlugin.cpp
)
SET( FIRSTPLUGIN_PLUGIN_H
${SCHNApps_ROOT_DIR}/include/plugins/visualPlugin.h
${SCHNApps_ROOT_DIR}/Plugins/firstPlugin/include/firstPlugin.h
)
IF( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
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_CPP( FIRSTPLUGIN_MOC ${FIRSTPLUGIN_PLUGIN_H} )
ADD_LIBRARY( FirstPluginD SHARED
${FIRSTPLUGIN_PLUGIN_SRC}
${FIRSTPLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( FirstPluginD
${CGoGN_LIBS_D}
${COMMON_LIBS}
${QGLVIEWER_INCLUDE_LIBRARY}
)
ADD_DEPENDENCIES( FirstPluginD SCHNAppsD )
SET_TARGET_PROPERTIES( FirstPluginD 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_CPP( FIRSTPLUGIN_MOC ${FIRSTPLUGIN_PLUGIN_H} )
ADD_LIBRARY( FirstPlugin SHARED
${FIRSTPLUGIN_PLUGIN_SRC}
${FIRSTPLUGIN_MOC}
)
TARGET_LINK_LIBRARIES( FirstPlugin
${CGoGN_LIBS_R}
${COMMON_LIBS}
${QGLVIEWER_INCLUDE_LIBRARY}
)
ADD_DEPENDENCIES( FirstPlugin SCHNApps )
ENDIF ( ${CMAKE_BUILD_TYPE} STREQUAL Debug )
#ifndef FIRSTPLUGIN_H_
#define FIRSTPLUGIN_H_
#include "plugins/visualPlugin.h"
/**---CGoGN includes **/
#include "Utils/Qt/qtSimple.h"
#include "Utils/cgognStream.h"
#include "Topology/generic/parameters.h"
#ifdef USE_GMAP
#include "Topology/gmap/embeddedGMap2.h"
#else
#include "Topology/map/embeddedMap2.h"
#endif
#include "Algo/Render/GL2/topoRender.h"
/**---CGoGN includes **/
/**---Definitions specific to CGoGN ---*/
using namespace CGoGN ;
/**
* Struct that contains some informations about the types of the manipulated objects
* Mainly here to be used by the algorithms that are parameterized by it
*/
struct PFP: public PFP_STANDARD
{
// definition of the type of the map
#ifdef USE_GMAP
typedef EmbeddedGMap2 MAP;
#else
typedef EmbeddedMap2 MAP;
#endif
};
typedef PFP::MAP MAP;
typedef PFP::VEC3 VEC3;
/**---Definitions specific to CGoGN ---*/
/**
* This class is a basic minimal plugin.
* All the methods in this class are overloaded methods.
* In order to create a valid plugin, all the method in this
* needs to be declared (they are actually overloaded methods
* from VisualPlugin), even if your plugin doesn't make any
* drawing.
*/
/**
* Our plugin must inherit from VisualPlugin,
* that is a class that itself is an implementation
* of the Plugin interface (virtual class). It contains
* many useful and essantial methods.
*/
class FirstPlugin : public VisualPlugin
{
/**
* Essential Qt macros.
*/
Q_OBJECT
Q_INTERFACES(Plugin)
public:
FirstPlugin() {}
~FirstPlugin() {}
/**
* The classical call back for the initGL method
* When a scene will be link to this plugin, it will call
* back this method with itself as a parameter.
*/
void cb_initGL(Scene* scene);
/**
* The drawing method that needs to be overloaded.
* Each time a scene (that is to say, at least one of the
* views that is contains) needs to be refresh, it calls back
* this method with itself as a parameter
*/
void cb_redraw(Scene* scene);
/**
* The plugin's activation method
* Each time the main application loads this plugin,
* it call this method. Writing this method is
* the occasion to initialize the plugin and check certain
* conditions.
* If this methods return 'false', the plugin load will be aborted.
*/
bool activate();
/**
* The plugin's disabling method
* Each time the main application will unload the plugin
* it will call this method.
*/
void disable();
protected:
/** Attributes that are specific to this plugin **/
MAP myMap;
// attribute for vertices positions
VertexAttribute<VEC3> position;
// render (for the topo)
Algo::Render::GL2::TopoRender* m_render_topo;
// just for more compact writing
inline Dart PHI1(Dart d) { return myMap.phi1(d); }
inline Dart PHI_1(Dart d) { return myMap.phi_1(d); }
inline Dart PHI2(Dart d) { return myMap.phi2(d); }
template<int X>
Dart PHI(Dart d) { return myMap.phi<X>(d); }
/** Attributes that are specific to this plugin **/
};
#endif /* FIRSTPLUGIN_H_ */
#include "firstPlugin.h"
#include "Algo/Geometry/boundingbox.h"
void FirstPlugin::cb_initGL(Scene* scene)
{
if(scene)
{
// we fit the first (possibly the only) view of the newly liked
// scene to the content of our map
// bounding box of scene
Geom::BoundingBox<PFP::VEC3> bb = Algo::Geometry::computeBoundingBox<PFP>(myMap, position);
scene->firstViewFitSphere(bb.center()[0], bb.center()[1], bb.center()[2], bb.maxSize());
m_render_topo = new Algo::Render::GL2::TopoRender() ;
// render the topo of the map without boundary darts
SelectorDartNoBoundary<PFP::MAP> nb(myMap);
m_render_topo->updateData<PFP>(myMap, position, 0.9f, 0.9f, nb);
}
}
void FirstPlugin::cb_redraw(Scene* scene)
{
m_render_topo->drawTopo();
}
bool FirstPlugin::activate()
{
// creation of 2 new faces: 1 triangle and 1 square
Dart d1 = myMap.newFace(3);
Dart d2 = myMap.newFace(4);
// sew these faces along one of their edge
myMap.sewFaces(d1, d2);
// creation of a new attribute on vertices of type 3D vector for position.
// a handler to this attribute is returned
position = myMap.addAttribute<VEC3, VERTEX>("position");
// affect position by moving in the map
position[d1] = VEC3(0, 0, 0);
position[PHI1(d1)] = VEC3(2, 0, 0);
position[PHI_1(d1)] = VEC3(1, 2, 0);
position[PHI<11>(d2)] = VEC3(0, -2, 0);
position[PHI_1(d2)] = VEC3(2, -2, 0);
m_render_topo=NULL;
return true;
}
void FirstPlugin::disable()
{
if(m_render_topo)
{
delete m_render_topo;
}
}
/**
* If we want to compile this plugin in debug mode,
* we also define a DEBUG macro at the compilation
*/
#ifndef DEBUG
// essential Qt function:
// arguments are
// - the complied name of the plugin
// - the main class of our plugin (that extends VisualPlugin)
Q_EXPORT_PLUGIN2(FirstPlugin, FirstPlugin)
#else
Q_EXPORT_PLUGIN2(FirstPluginD, FirstPlugin)
#endif
#ifndef _IMPORTMAP_H_
#define _IMPORTMAP_H_
#include "visualPlugin.h"
#include "Topology/generic/parameters.h"
#include "Topology/map/embeddedMap2.h"
#include "Geometry/vector_gen.h"
#include "Geometry/matrix.h"
#include "Algo/Import/import.h"
#include "Algo/Export/export.h"
#include "Algo/Render/GL2/mapRender.h"
#include "Algo/Render/GL2/topoRender.h"
#include "Utils/Shaders/shaderPhong.h"
#include "Utils/Shaders/shaderFlat.h"
#include "Utils/Shaders/shaderSimpleColor.h"
#include "Utils/Shaders/shaderVectorPerVertex.h"
#include "Utils/pointSprite.h"
#include "Utils/text3d.h"
#include "Utils/vboRender.h"
#include "Utils/Qt/qtInputs.h"
#include "Algo/Geometry/boundingbox.h"
#include "Algo/Geometry/normal.h"
using namespace CGoGN ;
struct PFP: public PFP_STANDARD
{
// definition of the map
typedef EmbeddedMap2 MAP ;
};
class ImportMap : public VisualPlugin{
Q_OBJECT
Q_INTERFACES(Plugin)
public:
ImportMap();
~ImportMap();
void cb_updateMatrix(View* view){}
void cb_redraw(Scene* scene){}
void cb_initGL(Scene* scene){}
bool activate();
void disable();
protected:
bool importMap(QString filename);
protected slots:
void saveMap();
};
#endif
#include "import.h"
#include <QMessageBox>
ImportMap::ImportMap(){}
ImportMap::~ImportMap(){}
bool ImportMap::activate(){
QAction* action= new QAction( m_window);
action->setIcon(QIcon(":icon/map.png"));
QObject::connect(action, SIGNAL(triggered()), this, SLOT(saveMap()));
addMenuAction("Visu;Imorter une Map", action);
addToolbarAction(action);
waitingForScene(0);
return true;
}
void ImportMap::disable(){}
bool ImportMap::importMap(QString filename){
QFileInfo fileInfo(filename);
QString extension= fileInfo.suffix();
PFP::MAP* myMap= new PFP::MAP();
VertexAttribute<PFP::VEC3> position;
VertexAttribute<PFP::VEC3> normal;
if (extension == "map")
{
myMap->loadMapBin(filename.toStdString());
position = myMap->getAttribute<PFP::VEC3, VERTEX>("position") ;
}
else
{
std::vector<std::string> attrNames ;
if(!Algo::Import::importMesh<PFP>(*myMap, filename.toStdString().c_str(), attrNames))
{
return false;
}
position = myMap->getAttribute<PFP::VEC3, VERTEX>(attrNames[0]) ;
std::cout << "import map position ok? " << ((myMap->getAttribute<PFP::VEC3, VERTEX>(attrNames[0]).isValid())?"yes":"no") << std::endl;
std::cout << "import map position ok? " << ((myMap->getAttribute<PFP::VEC3, VERTEX>("position").isValid())?"yes":"no") << std::endl;
}
normal = myMap->getAttribute<PFP::VEC3, VERTEX>("normal") ;
if(!normal.isValid())
normal = myMap->addAttribute<PFP::VEC3, VERTEX>("normal") ;
Algo::Geometry::computeNormalVertices<PFP>(*myMap, position, normal) ;
std::cout << "import map normal ok? " << ((myMap->getAttribute<PFP::VEC3, VERTEX>("normal").isValid())?"yes":"no") << std::endl;
MapHandler* vizuHandler= new MapHandler(myMap);
if(!addReferencedMap(fileInfo.baseName()+"_map", vizuHandler)){
System::Error::showError();
delete vizuHandler;
return false;
}
// myMap->check();
return true;
}
void ImportMap::saveMap(){
QString fileName= QFileDialog::getOpenFileName(m_window, System::app_path+"../files", tr("3D files (*)"));
if(!fileName.isEmpty()){
if(!importMap(fileName)){