This commit is contained in:
Guillaume Damiand 2012-03-30 11:00:40 +00:00
parent d2160fd6ce
commit c61f107354
7 changed files with 107 additions and 98 deletions

View File

@ -21,13 +21,15 @@
#include "typedefs.h"
#include <QApplication>
#include <CGAL/Qt/resources.h>
#include <CGAL/assertions_behaviour.h>
// Global random
CGAL::Random myrandom;
int main(int argc, char** argv)
{
std::cout<<"Size of dart: "<<sizeof(LCC::Dart)<<std::endl;
// std::cout<<"Size of dart: "<<sizeof(LCC::Dart)<<std::endl;
CGAL::set_error_behaviour(CGAL::ABORT);
QApplication application(argc,argv);

View File

@ -42,19 +42,22 @@ MainWindow::MainWindow (QWidget * parent):CGAL::Qt::DemosMainWindow (parent),
Qt::LeftDockWidgetArea);
volumeList = new QTableWidget(0,4,volumeListDock);
volumeList->verticalHeader()->hide();
volumeList->setColumnHidden(4,true);
volumeList->setColumnHidden(3,true);
QObject::connect(this->volumeList, SIGNAL(cellChanged(int,int)),
this, SLOT(onCellChanged(int,int)));
QStringList labels(QString(tr("Volume color")));
QStringList labels(QString(tr("Color")));
labels.append(QString(tr("Filled")));
labels.append(QString(tr("Hidden")));
volumeList->setHorizontalHeaderLabels(labels);
// volumeList->resizeColumnsToContents();
volumeList->setFixedWidth(170);
//volumeList->resizeColumnsToContents();
volumeList->setFixedWidth(175);
/* volumeList->setColumnWidth(0,85);
volumeList->setColumnWidth(1,35);
volumeList->setColumnWidth(2,35);*/
volumeList->horizontalHeader()->setResizeMode(QHeaderView::Stretch);
// volumeList->setSelectionMode(QAbstractItemView::SingleSelection);
volumeList->setSelectionBehavior(QAbstractItemView::SelectRows);
volumeList->setSelectionMode(QAbstractItemView::NoSelection);
//volumeList->setSelectionBehavior(QAbstractItemView::SelectRows);
volumeListDock->setWidget(volumeList);
addDockWidget(Qt::RightDockWidgetArea,volumeListDock);
menuView->addAction(volumeListDock->toggleViewAction());
@ -149,6 +152,15 @@ void MainWindow::onSceneChanged ()
statusMessage->setText (os.str().c_str ());
}
void MainWindow::clear_all()
{
scene.lcc->clear();
nbcube=0;
volumeList->clearContents();
volumeList->setRowCount(0);
}
void MainWindow::on_new_volume(Dart_handle adart)
{
assert( adart->attribute<3>()==NULL);
@ -210,8 +222,7 @@ void MainWindow::load_off (const QString & fileName, bool clear)
{
QApplication::setOverrideCursor (Qt::WaitCursor);
if (clear)
this->on_actionClear_triggered(false);
if (clear) this->clear_all();
std::ifstream ifs (qPrintable (fileName));
@ -234,8 +245,7 @@ void MainWindow::load_3DTDS (const QString & fileName, bool clear)
{
QApplication::setOverrideCursor (Qt::WaitCursor);
if (clear)
this->on_actionClear_triggered(false);
if (clear) this->clear_all();
typedef CGAL::Delaunay_triangulation_3 < LCC::Traits > Triangulation;
Triangulation T;
@ -331,7 +341,7 @@ void MainWindow::on_actionCreate2Volumes_triggered ()
statusBar ()->showMessage (QString ("2 volumes were created"),
DELAY_STATUSMSG);
emit (sceneChanged ());
emit (sceneChanged());
}
void MainWindow::on_actionCreate_mesh_triggered ()
@ -364,19 +374,11 @@ void MainWindow::on_actionSubdivide_triggered ()
DELAY_STATUSMSG);
}
void MainWindow::on_actionClear_triggered(bool msg)
void MainWindow::on_actionClear_triggered()
{
scene.lcc->clear();
nbcube=0;
volumeList->clearContents();
volumeList->setRowCount(0);
if (msg)
{
statusBar ()->showMessage (QString ("Scene was cleared"), DELAY_STATUSMSG);
emit (sceneChanged ());
}
clear_all();
statusBar ()->showMessage (QString ("Scene cleared"), DELAY_STATUSMSG);
emit (sceneChanged ());
}
void MainWindow::on_actionCompute_Voronoi_3D_triggered ()
@ -388,7 +390,7 @@ void MainWindow::on_actionCompute_Voronoi_3D_triggered ()
if (fileName.isEmpty ()) return;
this->on_actionClear_triggered(false);
this->clear_all();
typedef CGAL::Delaunay_triangulation_3 < LCC::Traits > Triangulation;
Triangulation T;
@ -477,7 +479,7 @@ void MainWindow::on_actionDual_3_triggered ()
LCC* duallcc = new LCC;
scene.lcc->dual_points_at_barycenter(*duallcc);
this->on_actionClear_triggered(false);
this->clear_all();
delete scene.lcc;
scene.lcc = duallcc;
this->viewer->setScene(&scene);
@ -492,7 +494,8 @@ void MainWindow::on_actionClose_volume_triggered()
if ( scene.lcc->close(3) > 0 )
{
init_all_new_volumes();
statusBar ()->showMessage (QString ("All volume(s) closed"), DELAY_STATUSMSG);
statusBar ()->showMessage (QString ("All volume(s) closed"),
DELAY_STATUSMSG);
emit (sceneChanged ());
}
else
@ -705,7 +708,7 @@ void MainWindow::recreate_whole_volume_list()
for (LCC::Attribute_range<3>::type::iterator
it=scene.lcc->attributes<3>().begin(),
itend=scene.lcc->attributes<3>().end(); it!=itend; )
itend=scene.lcc->attributes<3>().end(); it!=itend; ++it)
update_volume_list_add(it->dart());
}
@ -749,19 +752,38 @@ void MainWindow::onHeaderClicked(int col)
{
case(Qt::ShiftModifier):
if (col==1) ptr->info().set_filled(false);
else if (col==2) ptr->info().set_visible(true);
else if (col==2)
{
ptr->info().set_visible(true);
volumeList->item(i,1)->setFlags
(volumeList->item(i,1)->flags()|Qt::ItemIsEnabled);
}
volumeList->item(i,col)->setCheckState(Qt::Unchecked);
break;
case(Qt::ControlModifier):
if (col==1) ptr->info().negate_filled();
else if (col==2) ptr->info().negate_visible();
else if (col==2)
{
ptr->info().negate_visible();
if ( !ptr->info().is_visible() )
volumeList->item(i,1)->setFlags
(volumeList->item(i,1)->flags()^Qt::ItemIsEnabled);
else
volumeList->item(i,1)->setFlags
(volumeList->item(i,1)->flags()|Qt::ItemIsEnabled);
}
volumeList->item(i,col)->
setCheckState(volumeList->item(i,col)->checkState() ?
Qt::Unchecked: Qt::Checked);
break;
default:
if (col==1) ptr->info().set_filled(true);
else if (col==2) ptr->info().set_visible(false);
else if (col==2)
{
ptr->info().set_visible(false);
volumeList->item(i,1)->setFlags
(volumeList->item(i,1)->flags()^Qt::ItemIsEnabled);
}
volumeList->item(i,col)->setCheckState(Qt::Checked);
break;
}
@ -1185,21 +1207,21 @@ void MainWindow::process_full_slice(Dart_handle init,
int markVols)
{
Dart_handle d[12];
d[0]=init->beta(1)->beta(2)->beta(3);
d[1]=d[0]->beta(1)->beta(2)->beta(1);
d[2]=d[1]->beta(1)->beta(2)->beta(1)->beta(3);
d[3]=d[2]->beta(1)->beta(2)->beta(1)->beta(3);
d[0]=init->beta(1)->beta(2); //->beta(3);
d[1]=d[0]->beta(3)->beta(1)->beta(2)->beta(1);
d[2]=d[1]->beta(1)->beta(2)->beta(1); //->beta(3);
d[3]=d[2]->beta(3)->beta(1)->beta(2)->beta(1); //->beta(3);
d[4]=init->beta(1)->beta(1)->beta(2)->beta(3);
d[5]=d[4]->beta(0)->beta(2)->beta(0);
d[6]=d[5]->beta(0)->beta(2)->beta(0)->beta(3);
d[4]=init->beta(1)->beta(1)->beta(2); //->beta(3);
d[5]=d[4]->beta(3)->beta(0)->beta(2)->beta(0);
d[6]=d[5]->beta(0)->beta(2)->beta(0); //->beta(3);
d[7]=d[6]->beta(0)->beta(2)->beta(0)->beta(3);
d[8]=d[7]->beta(0)->beta(2)->beta(0);
d[9]=d[8]->beta(0)->beta(2)->beta(0)->beta(3);
d[7]=d[6]->beta(3)->beta(0)->beta(2)->beta(0); //->beta(3);
d[8]=d[7]->beta(3)->beta(0)->beta(2)->beta(0);
d[9]=d[8]->beta(0)->beta(2)->beta(0); //->beta(3);
d[10]=d[9]->beta(0)->beta(2)->beta(0)->beta(3);
d[11]=d[10]->beta(0)->beta(2)->beta(0);
d[10]=d[9]->beta(3)->beta(0)->beta(2)->beta(0); //->beta(3);
d[11]=d[10]->beta(3)->beta(0)->beta(2)->beta(0);
for (unsigned int j=0; j<12; ++j)
{
@ -1226,15 +1248,15 @@ void MainWindow::process_inter_slice(Dart_handle init,
d[6]=d[5]->beta(1)->beta(1)->beta(2)->beta(3)->beta(2);
d[7]=d[6]->beta(0)->beta(2)->beta(3)->beta(2)->beta(0);
init = init->beta(3)->beta(2)->beta(1)->beta(1)->beta(2)->beta(3);
init = init->beta(3)->beta(2)->beta(1)->beta(1)->beta(2); //->beta(3);
d[8]=init;
d[9]=d[8]->beta(1)->beta(2)->beta(3)->beta(2)->beta(1);
d[10]=d[9]->beta(1)->beta(2)->beta(3)->beta(2)->beta(1);
d[11]=d[10]->beta(0)->beta(0)->beta(2)->beta(3)->beta(2);
d[12]=d[11]->beta(0)->beta(0)->beta(2)->beta(3)->beta(2);
d[13]=d[8]->beta(0)->beta(0)->beta(2)->beta(3)->beta(2);
d[14]=d[13]->beta(0)->beta(0)->beta(2)->beta(3)->beta(2);
d[15]=d[14]->beta(1)->beta(2)->beta(3)->beta(2)->beta(1);
d[9]=d[8]->beta(3)->beta(1)->beta(2)->beta(3)->beta(2)->beta(1);
d[10]=d[9]->beta(1)->beta(2)->beta(3)->beta(2)->beta(1)->beta(3);
d[11]=d[10]->beta(3)->beta(0)->beta(0)->beta(2)->beta(3)->beta(2);
d[12]=d[11]->beta(0)->beta(0)->beta(2)->beta(3)->beta(2)->beta(3);
d[13]=d[8]->beta(3)->beta(0)->beta(0)->beta(2)->beta(3)->beta(2);
d[14]=d[13]->beta(0)->beta(0)->beta(2)->beta(3)->beta(2)->beta(3);
d[15]=d[14]->beta(3)->beta(1)->beta(2)->beta(3)->beta(2)->beta(1);
d[16]=d[0]->beta(3)->beta(1)->beta(2);
d[17]=d[0]->beta(3)->beta(1)->beta(1)->beta(2);
@ -1264,6 +1286,10 @@ void MainWindow::onMengerDec()
{
this->mengerLevel--;
// We know here the number of Menger volume: 2^mengerLevel
// thus we can directly "cut" the std::vector to the correct size.
mengerVolumes.resize(pow(20,mengerLevel));
int markVols = (scene.lcc)->get_new_mark();
int markVertices = (scene.lcc)->get_new_mark();
@ -1292,7 +1318,7 @@ void MainWindow::onMengerDec()
CGAL::remove_cell<LCC,2>(*scene.lcc, faces[i]);
}
faces.clear();
// Now we remove edges.
for ( std::vector<Dart_handle>::iterator itvol=mengerVolumes.begin();
itvol!=mengerVolumes.end(); ++itvol)

View File

@ -74,7 +74,7 @@ public slots:
void on_actionAddOFF_triggered();
void on_actionImport3DTDS_triggered();
void on_actionCompute_Voronoi_3D_triggered();
void on_actionClear_triggered(bool msg=true);
void on_actionClear_triggered();
// Creations menu
Dart_handle on_actionCreate_cube_triggered();
@ -119,6 +119,7 @@ signals:
void sceneChanged();
protected:
void clear_all();
void on_new_volume(Dart_handle adart);
void on_delete_volume(Dart_handle adart);
void init_all_new_volumes();
@ -158,9 +159,6 @@ protected:
DialogMenger dialogmenger;
int mengerLevel;
// TODO : replace the following std::vector by a
// std::vector<Attribute_handle<3>::type> => simplify the add/removal
// of a volume
std::vector<Dart_handle> mengerVolumes;
QDockWidget* volumeListDock;

View File

@ -56,12 +56,12 @@
</property>
<addaction name="actionSubdivide"/>
<addaction name="actionTriangulate_all_facets"/>
<addaction name="actionSew3_same_facets"/>
<addaction name="actionUnsew3_all"/>
<addaction name="actionMerge_all_volumes"/>
<addaction name="actionRemove_filled_volumes"/>
<addaction name="separator"/>
<addaction name="actionClose_volume"/>
<addaction name="actionSew3_same_facets"/>
<addaction name="actionDual_3"/>
</widget>
<widget class="QMenu" name="menuCreations">
@ -106,7 +106,7 @@
</action>
<action name="actionSubdivide">
<property name="text">
<string>&amp;Subdivide</string>
<string>&amp;Subdivide volumes</string>
</property>
</action>
<action name="actionCreate3Cubes">
@ -119,11 +119,6 @@
<string>Import 3D&amp;TS</string>
</property>
</action>
<action name="actionDisplayInfo">
<property name="text">
<string>Display info</string>
</property>
</action>
<action name="actionClear">
<property name="text">
<string>&amp;Clear</string>
@ -176,12 +171,7 @@
</action>
<action name="actionUnsew3_all">
<property name="text">
<string>&amp;Unsew3</string>
</property>
</action>
<action name="actionRemove_selected_volume">
<property name="text">
<string>Remove selected &amp;volume</string>
<string>&amp;Unsew3 volumes</string>
</property>
</action>
<action name="actionVolume_list">
@ -197,11 +187,6 @@
<string>Extend &amp;filled volumes</string>
</property>
</action>
<action name="actionExtend_wireframe_volumes">
<property name="text">
<string>Extend &amp;wireframe volumes</string>
</property>
</action>
<action name="actionExtend_hidden_volumes">
<property name="text">
<string>Extend &amp;hidden volumes</string>

View File

@ -28,26 +28,26 @@ CGAL::Bbox_3 Viewer::bbox()
{
CGAL::Bbox_3 bb;
if ( scene->lcc->is_empty() )
bool empty = true;
for (LCC::Attribute_range<3>::type::iterator
it=scene->lcc->attributes<3>().begin(),
itend=scene->lcc->attributes<3>().end(); it!=itend; ++it )
{
if ( it->info().is_visible() )
{
empty = false;
for( LCC::Dart_of_cell_range<3>::iterator
it2=scene->lcc->darts_of_cell<3>(it->dart()).begin();
it2.cont(); ++it2)
bb = bb + LCC::point(it2).bbox();
}
}
if ( empty )
{
bb = LCC::Point(CGAL::ORIGIN).bbox();
bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer
}
else
{
for (LCC::Attribute_range<3>::type::iterator
it=scene->lcc->attributes<3>().begin(),
itend=scene->lcc->attributes<3>().end(); it!=itend; ++it )
{
if ( it->info().is_visible() )
{
for( LCC::Dart_of_cell_range<3>::iterator
it2=scene->lcc->darts_of_cell<3>(it->dart()).begin();
it2.cont(); ++it2)
bb = bb + LCC::point(it2).bbox();
}
}
}
return bb;
}
@ -212,8 +212,6 @@ void Viewer::init()
setKeyDescription(Qt::Key_F, "Toggles flat shading display");
setKeyDescription(Qt::Key_E, "Toggles edges display");
setKeyDescription(Qt::Key_V, "Toggles vertices display");
setKeyDescription(Qt::Key_Z, "Next mode filled facet");
setKeyDescription(Qt::Key_R, "Select next volume, used for filled facet");
// Light default parameters
::glLineWidth(1.4f);

View File

@ -35,8 +35,6 @@ class Viewer : public QGLViewer
bool flatShading;
bool edges;
bool vertices;
unsigned int modeFilledFacet;
int selectedVolumeIndex;
typedef LCC::Dart_handle Dart_handle;
typedef LCC::Dart_const_handle Dart_const_handle;
@ -45,7 +43,7 @@ class Viewer : public QGLViewer
public:
Viewer(QWidget* parent)
: QGLViewer(parent), wireframe(false), flatShading(true),
edges(true), vertices(true), modeFilledFacet(0)
edges(true), vertices(true)
{}
void setScene(Scene* scene_)

View File

@ -75,9 +75,11 @@ public:
std::string color_name() const
{
std::stringstream ss;
ss << "#" << std::hex << m_color.red()<< m_color.green()<<m_color.blue();
return std::string(ss.str());
std::ostringstream ss;
ss<<std::setfill('0');
ss<<"#"<<std::hex<<std::setw(2)<<(int)m_color.red()
<<std::setw(2)<<(int)m_color.green()<<std::setw(2)<<(int)m_color.blue();
return ss.str();
}
bool is_visible() const