Commit 6a779de9 authored by untereiner's avatar untereiner

[CGoGN] import files cleaning (most volumetric part)

[CGoGN] begin adding tetgen for tetrahedral mesh generation
[SCHNApps] add volume import plugin
[SCHNApps] add volume render plugin
parent c7452130
......@@ -790,36 +790,27 @@ void Clipping::importMesh(std::string& filename)
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<PFP>(myMap,filename.c_str(),attrNames))
{
CGoGNerr << "could not import " << filename << CGoGNendl ;
return;
}
else
position = myMap.getAttribute<VEC3, VERTEX>(attrNames[0]) ;
}
else if(extension == std::string(".ts"))
{
if(!Algo::Volume::Import::importTs<PFP>(myMap,filename.c_str(),attrNames))
{
CGoGNerr << "could not import " << filename << CGoGNendl ;
return;
}
else
position = myMap.getAttribute<VEC3, VERTEX>(attrNames[0]) ;
}
if(extension == std::string(".map"))
{
if(!myMap.loadMapBin(filename))
{
CGoGNerr << "could not import " << filename << CGoGNendl ;
return;
}
else
position = myMap.getAttribute<VEC3, VERTEX>("position") ;
}
if(extension == std::string(".map"))
{
if(!myMap.loadMapBin(filename))
{
CGoGNerr << "could not import " << filename << CGoGNendl ;
return;
}
else
position = myMap.getAttribute<VEC3, VERTEX>("position") ;
}
else
{
if(!Algo::Volume::Import::importMesh<PFP>(myMap, filename, attrNames))
{
std::cerr << "could not import " << filename << std::endl ;
return ;
}
else
position = myMap.getAttribute<PFP::VEC3,VERTEX>(attrNames[0]) ;
}
updateVBOprimitives(Algo::Render::GL2::TRIANGLES | Algo::Render::GL2::LINES | Algo::Render::GL2::POINTS) ;
......
......@@ -136,7 +136,7 @@ void MyQT::slider_released()
void MyQT::cb_Open()
{
std::string filters("all (*.*);; trian (*.trian);; ctm (*.ctm);; off (*.off);; ply (*.ply)") ;
std::string filters("all (*.*)") ;
std::string filename = selectFile("Open Mesh", "", filters) ;
if (filename.empty())
return ;
......@@ -145,8 +145,8 @@ void MyQT::cb_Open()
std::vector<std::string> attrNames ;
size_t pos = filename.rfind("."); // position of "." in filename
std::string extension = filename.substr(pos);
//size_t pos = filename.rfind("."); // position of "." in filename
//std::string extension = filename.substr(pos);
// if(extension == std::string(".off"))
// {
......
......@@ -10,3 +10,6 @@ ADD_SUBDIRECTORY(surface_subdivision)
ADD_SUBDIRECTORY(surface_selection)
ADD_SUBDIRECTORY(surface_deformation)
ADD_SUBDIRECTORY(surface_modelisation)
ADD_SUBDIRECTORY(volume_import)
ADD_SUBDIRECTORY(volume_render)
cmake_minimum_required(VERSION 2.8)
SET( PLUGIN_NAME ImportVolume )
SET( PLUGIN_NAME Volume_Import )
SET( PLUGIN_ROOT_DIR ${SCHNApps_ROOT_DIR}/Plugins/importVolume )
SET( PLUGIN_ROOT_DIR ${SCHNApps_ROOT_DIR}/Plugins/volume_import )
INCLUDE_DIRECTORIES(
${PLUGIN_ROOT_DIR}/include
......@@ -25,7 +25,7 @@ file(
SET(
PLUGIN_QOBJECT_FILES
${PLUGIN_ROOT_DIR}/include/importVolume.h
${PLUGIN_ROOT_DIR}/include/volume_import.h
)
include( ${SCHNApps_ROOT_DIR}/Plugins/plugins_cmake.txt )
#ifndef _IMPORTVOLUME_PLUGIN_H_
#define _IMPORTVOLUME_PLUGIN_H_
#include "plugin.h"
#ifndef _VOLUME_IMPORT_PLUGIN_H_
#define _VOLUME_IMPORT_PLUGIN_H_
#include "plugin_processing.h"
namespace CGoGN
{
......@@ -10,32 +9,22 @@ namespace CGoGN
namespace SCHNApps
{
class ImportVolumePlugin : public Plugin
class Volume_Import_Plugin : public PluginProcessing
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public:
ImportVolumePlugin()
{
setProvidesRendering(false);
}
Volume_Import_Plugin()
{}
~ImportVolumePlugin()
~Volume_Import_Plugin()
{}
private:
virtual bool enable();
virtual void disable() {}
virtual void redraw(View *view) {}
virtual void keyPress(View* view, QKeyEvent* event) {}
virtual void keyRelease(View* view, QKeyEvent* event) {}
virtual void mousePress(View* view, QMouseEvent* event) {}
virtual void mouseRelease(View* view, QMouseEvent* event) {}
virtual void mouseMove(View* view, QMouseEvent* event) {}
virtual void wheelEvent(View* view, QWheelEvent* event) {}
public slots:
MapHandlerGen* importFromFile(const QString& fileName);
void importFromFileDialog();
......
#include "importVolume.h"
#include "volume_import.h"
#include "schnapps.h"
#include "mapHandler.h"
#include "Algo/Import/import.h"
......@@ -13,20 +14,20 @@ namespace CGoGN
namespace SCHNApps
{
bool ImportVolumePlugin::enable()
bool Volume_Import_Plugin::enable()
{
importAction = new QAction("import", this);
addMenuAction("Volume;Import", importAction);
m_schnapps->addMenuAction(this, "Volume;Import", importAction);
connect(importAction, SIGNAL(triggered()), this, SLOT(importFromFileDialog()));
return true;
}
MapHandlerGen* ImportVolumePlugin::importFromFile(const QString& fileName)
MapHandlerGen* Volume_Import_Plugin::importFromFile(const QString& fileName)
{
QFileInfo fi(fileName);
if(fi.exists())
{
MapHandlerGen* mhg = m_window->addMap(fi.baseName(), 3);
MapHandlerGen* mhg = m_schnapps->addMap(fi.baseName(), 3);
if(mhg)
{
MapHandler<PFP3>* mh = static_cast<MapHandler<PFP3>*>(mhg);
......@@ -39,9 +40,6 @@ MapHandlerGen* ImportVolumePlugin::importFromFile(const QString& fileName)
VertexAttribute<PFP3::VEC3> position = map->getAttribute<PFP3::VEC3, VERTEX>(attrNames[0]);
mh->registerAttribute(position);
// create position VBO
mh->createVBO(position);
// update corresponding VBO & emit attribute update signal
mh->notifyAttributeModification(position);
......@@ -54,9 +52,9 @@ MapHandlerGen* ImportVolumePlugin::importFromFile(const QString& fileName)
return NULL;
}
void ImportVolumePlugin::importFromFileDialog()
void Volume_Import_Plugin::importFromFileDialog()
{
QStringList fileNames = QFileDialog::getOpenFileNames(m_window, "Import volumes", m_window->getAppPath(), "Volume mesh Files (*.node *.ts *.off *.tet)");
QStringList fileNames = QFileDialog::getOpenFileNames(m_schnapps, "Import volumes", m_schnapps->getAppPath(), "Volume mesh Files (*.msh *.vtu *.nas *.vbgz *.tetmesh *.node *.ts *.off *.tet)");
QStringList::Iterator it = fileNames.begin();
while(it != fileNames.end()) {
importFromFile(*it);
......@@ -65,9 +63,9 @@ void ImportVolumePlugin::importFromFileDialog()
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(ImportVolumePlugin, ImportVolumePlugin)
Q_EXPORT_PLUGIN2(Volume_Import_Plugin, Volume_Import_Plugin)
#else
Q_EXPORT_PLUGIN2(ImportVolumePluginD, ImportVolumePlugin)
Q_EXPORT_PLUGIN2(Volume_Import_PluginD, Volume_Import_Plugin)
#endif
} // namespace SCHNApps
......
cmake_minimum_required(VERSION 2.8)
SET( PLUGIN_NAME RenderExplod )
SET( PLUGIN_NAME Volume_Render )
SET( PLUGIN_ROOT_DIR ${SCHNApps_ROOT_DIR}/Plugins/renderExplod )
SET( PLUGIN_ROOT_DIR ${SCHNApps_ROOT_DIR}/Plugins/volume_render )
INCLUDE_DIRECTORIES(
${PLUGIN_ROOT_DIR}/include
......@@ -25,8 +25,8 @@ file(
SET(
PLUGIN_QOBJECT_FILES
${PLUGIN_ROOT_DIR}/include/renderExplod.h
${PLUGIN_ROOT_DIR}/include/renderExplodDockTab.h
${PLUGIN_ROOT_DIR}/include/volume_render.h
${PLUGIN_ROOT_DIR}/include/volume_render_dockTab.h
)
include( ${SCHNApps_ROOT_DIR}/Plugins/plugins_cmake.txt )
#ifndef _VOLUME_RENDER_PLUGIN_H_
#define _VOLUME_RENDER_PLUGIN_H_
#include "plugin_interaction.h"
#include "volume_render_dockTab.h"
#include "Algo/Render/GL2/explodeVolumeRender.h"
namespace CGoGN
{
namespace SCHNApps
{
class MapHandlerGen;
struct MapParameters
{
enum FaceShadingStyle
{
FLAT = 0,
SMOOTH = 1
};
MapParameters():
m_renderExplod(NULL),
facesScaleFactor(1.0f),
volumesScaleFactor(1.0f),
renderEdges(false),
renderFaces(true),
faceStyle(FLAT)
{}
Algo::Render::GL2::ExplodeVolumeRender* m_renderExplod;
// VertexAttribute<PFP3::VEC3> positionAttribute;
// VolumeAttribute<PFP3::VEC3> colorAttribute;
float facesScaleFactor;
float volumesScaleFactor;
bool renderEdges;
bool renderFaces;
FaceShadingStyle faceStyle;
// void updateRender();
};
class Volume_Render_Plugin : public Plugin
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
friend class Volume_Render_DockTab;
public:
Volume_Render_Plugin()
{}
~Volume_Render_Plugin()
{}
private:
virtual bool enable();
virtual void disable();
virtual void redraw(View *view);
virtual void drawMap(View* view, MapHandlerGen* map);
virtual void keyPress(View* view, QKeyEvent* event) {}
virtual void keyRelease(View* view, QKeyEvent* event) {}
virtual void mousePress(View* view, QMouseEvent* event) {}
virtual void mouseRelease(View* view, QMouseEvent* event) {}
virtual void mouseMove(View* view, QMouseEvent* event) {}
virtual void wheelEvent(View* view, QWheelEvent* event) {}
virtual void viewLinked(View *view) {}
virtual void viewUnlinked(View *view) {}
private slots:
// slots called from SCHNApps signals
void selectedViewChanged(View* prev, View* cur);
void selectedMapChanged(MapHandlerGen* prev, MapHandlerGen* cur);
void mapAdded(MapHandlerGen* map);
void mapRemoved(MapHandlerGen* map);
public slots:
// slots for Python calls
void changeVerticesScaleFactor(const QString&view, const QString& map, float f);
void changeRenderEdges(const QString& view, const QString& map, bool b);
void changeRenderFaces(const QString& view, const QString& map, bool b);
void changeFacesStyle(const QString& view, const QString& map, MapParameters::FaceShadingStyle style);
protected:
Volume_Render_DockTab* m_dockTab;
QHash<View*, QHash<MapHandlerGen*, MapParameters> > h_viewParameterSet;
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#ifndef _VOLUME_RENDER_DOCK_TAB_H_
#define _VOLUME_RENDER_DOCK_TAB_H_
#include "ui_volume_render.h"
namespace CGoGN
{
namespace SCHNApps
{
class SCHNApps;
class Volume_Render_Plugin;
struct MapParameters;
class Volume_Render_DockTab : public QWidget, public Ui::Volume_Render_TabWidget
{
Q_OBJECT
friend class Volume_Render_Plugin;
public:
Volume_Render_DockTab(SCHNApps* s, Surface_Render_Plugin* p);
private:
SCHNApps* m_schnapps;
Volume_Render_Plugin* m_plugin;
bool b_updatingUI;
private slots:
void positionAttributeChanged(int index);
void colorAttributeChanged(int index);
void facesScaleFactorChanged(int i);
void volumesScaleFactorChanged(int i);
void renderEdgesChanged(bool b);
void renderFacesChanged(bool b);
void faceStyleChanged(QAbstractButton* b);
private:
void updateMapParameters();
};
} // namespace SCHNApps
} // namespace CGoGN
#endif
#include "volume_render.h"
#include "mapHandler.h"
namespace CGoGN
{
namespace SCHNApps
{
//PerMapParameterSet::PerMapParameterSet(MapHandlerGen* m) :
// mh(m),
// facesScaleFactor(1.0f),
// volumesScaleFactor(1.0f),
// renderEdges(false),
// renderFaces(true),
// faceStyle(FLAT)
//{
// m_renderExplod = new Algo::Render::GL2::ExplodeVolumeRender(false, false, false);
// m_renderExplod->setNoClippingPlane();
// m_renderExplod->setExplodeVolumes(1.0f);
// m_renderExplod->setExplodeFaces(1.0f);
// QString positionName;
// QString vec3TypeName = QString::fromStdString(nameOfType(PFP3::VEC3()));
// const AttributeHash& attribs = mh->getAttributesList(VERTEX);
// for(AttributeHash::const_iterator i = attribs.constBegin(); i != attribs.constEnd(); ++i)
// {
// if(i.value() == vec3TypeName)
// {
// if(positionName != "position") // try to select an attribute named "position"
// positionName = i.key(); // or anything else if not found
// }
// }
// positionAttribute = mh->getAttribute<PFP3::VEC3, VERTEX>(positionName);
// colorAttribute = mh->getAttribute<PFP3::VEC3, VOLUME>("color");
// updateRender();
//}
//PerMapParameterSet::~PerMapParameterSet()
//{
// delete m_renderExplod;
//}
//void PerMapParameterSet::updateRender()
//{
// PFP3::MAP* m = static_cast<MapHandler<PFP3>*>(mh)->getMap();
// //if(!color.isValid())
// m_renderExplod->updateData<PFP3>(*m, positionAttribute);
//}
bool Volume_Render_Plugin::enable()
{
m_dockTab = new RenderExplodDockTab(m_window, this);
addTabInDock(m_dockTab, "RenderExplod");
connect(m_window, SIGNAL(viewAndPluginLinked(View*, Plugin*)), this, SLOT(viewLinked(View*, Plugin*)));
connect(m_window, SIGNAL(viewAndPluginUnlinked(View*, Plugin*)), this, SLOT(viewUnlinked(View*, Plugin*)));
connect(m_window, SIGNAL(currentViewChanged(View*)), this, SLOT(currentViewChanged(View*)));
return true;
}
void Volume_Render_Plugin::disable()
{
}
void Volume_Render_Plugin::drawMap(View* view, MapHandlerGen* map)
{
}
void Volume_Render_Plugin::selectedViewChanged(View *prev, View *cur)
{
}
void Volume_Render_Plugin::selectedMapChanged(MapHandlerGen *prev, MapHandlerGen *cur)
{
}
void Volume_Render_Plugin::mapAdded(MapHandlerGen *map)
{
}
void Volume_Render_Plugin::mapRemoved(MapHandlerGen *map)
{
}
void Volume_Render_Plugin::changeVerticesScaleFactor(const QString& view, const QString& map, float f)
{
}
void Volume_Render_Plugin::changeRenderEdges(const QString& view, const QString& map, bool b)
{
}
void Volume_Render_Plugin::changeRenderFaces(const QString& view, const QString& map, bool b)
{
}
void Volume_Render_Plugin::changeFacesStyle(const QString& view, const QString& map, MapParameters::FaceShadingStyle style)
{
}
#ifndef DEBUG
Q_EXPORT_PLUGIN2(Volume_Render_Plugin, Volume_Render_Plugin)
#else
Q_EXPORT_PLUGIN2(Volume_Render_PluginD, Volume_Render_Plugin)
#endif
} // namespace SCHNApps
} // namespace CGoGN
#include "volume_render_dockTab.h"
#include "volume_render.h"
#include "schnapps.h"
#include "mapHandler.h"
namespace CGoGN
{
namespace SCHNApps
{
Volume_Render_DockTab::Volume_Render_DockTab(SCHNApps* s, Surface_Render_Plugin* p) :
m_schnapps(s),
m_plugin(p),
b_updatingUI(false)
{
setupUi(this);
}
void Volume_Render_DockTab::positionAttributeChanged(int index)
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = m_currentParams->selectedMap;
if(map)
m_plugin->changePositionAttribute(view, map, map->getAttribute<PFP2::VEC3, VERTEX>(combo_positionAttribute->currentText()), true);
}
}
void Volume_Render_DockTab::colorAttributeChanged(int index)
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = m_currentParams->selectedMap;
if(map)
m_plugin->changeColorAttribute(view, map, map->getAttribute<PFP2::VEC3, VERTEX>(combo_colorAttribute->currentText()), true);
}
}
void Volume_Render_DockTab::facesScaleFactorChanged(int i)
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = m_currentParams->selectedMap;
if(map)
m_plugin->changeFacesScaleFactor(view, map, i, true);
}
}
void Volume_Render_DockTab::volumesScaleFactorChanged(int i)
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = m_currentParams->selectedMap;
if(map)
m_plugin->changeVolumesScaleFactor(view, map, i, true);
}
}
void Volume_Render_DockTab::renderEdgesChanged(bool b)
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = m_currentParams->selectedMap;
if(map)
m_plugin->changeRenderEdges(view, map, b, true);
}
}
void Volume_Render_DockTab::renderFacesChanged(bool b)
{
if(!b_refreshingUI)
{
View* view = m_window->getCurrentView();
MapHandlerGen* map = m_currentParams->selectedMap;
if(map)
m_plugin->changeRenderFaces(view, map, b, true);
}
}
void Volume_Render_DockTab::faceStyleChanged(QAbstractButton* b)
{
if(!b_updatingUI)
{
View* view = m_schnapps->getSelectedView();
MapHandlerGen* map = m_schnapps->getSelectedMap();
if(view && map)
{
if(radio_flatShading->isChecked())
m_plugin->h_viewParameterSet[view][map].faceStyle = MapParameters::FLAT;
else if(radio_smoothShading->isChecked())
m_plugin->h_viewParameterSet[view][map].faceStyle = MapParameters::SMOOTH;
view->updateGL();
}
}
}
} // namespace SCHNApps
} // namespace CGoGN
#ifndef _RENDER_PLUGIN_H_
#define _RENDER_PLUGIN_H_
#include "plugin.h"
#include "renderExplodDockTab.h"
#include "Algo/Render/GL2/explodeVolumeRender.h"
namespace CGoGN
{
namespace SCHNApps
{
enum FaceShadingStyle
{
FLAT = 0,
SMOOTH = 1
};
struct PerMapParameterSet
{
PerMapParameterSet(MapHandlerGen* mh);
~PerMapParameterSet();
void updateRender();
MapHandlerGen* mh;
Algo::Render::GL2::ExplodeVolumeRender* m_renderExplod;
VertexAttribute<PFP3::VEC3> positionAttribute;
VolumeAttribute<PFP3::VEC3> colorAttribute;
float facesScaleFactor;
float volumesScaleFactor;
bool renderEdges;
bool renderFaces;
FaceShadingStyle faceStyle;
};
struct ParameterSet
{
ParameterSet() : selectedMap(NULL)
{}
QHash<QString, PerMapParameterSet*> perMap;
MapHandlerGen* selectedMap;
};
class RenderExplodPlugin : public Plugin
{
Q_OBJECT
Q_INTERFACES(CGoGN::SCHNApps::Plugin)
public:
RenderExplodPlugin()
{
setProvidesRendering(true);