From bca21193c32f9b903b48d4d8a192577ce3325211 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Wed, 8 Aug 2012 14:25:01 +0000 Subject: [PATCH] paysages : Heightmap editor - Added resolution control. git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@404 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 6 +++- gui_qt/dialogheightmap.cpp | 66 ++++++++++++++++++++++++++++++++++++++ gui_qt/dialogheightmap.h | 4 +++ 3 files changed, 75 insertions(+), 1 deletion(-) diff --git a/TODO b/TODO index 731b504..8478596 100644 --- a/TODO +++ b/TODO @@ -10,7 +10,11 @@ Technology Preview 2 : - Improve previews. => Add user markers on OSD. => Add areas marking. -- Start a terrain editor (see mockup). +- Improve terrain canvas editor. + => Add GeoArea editor. + => Apply GeoArea to revertToTerrain. + => Resample map on changing resolution. + => Map loading should not choose arbitrary resolution. - Improve textures (current model is greatly incorrect). => Separate models (basic texture and covering texture). => Covering texture height should inpact terrain height. diff --git a/gui_qt/dialogheightmap.cpp b/gui_qt/dialogheightmap.cpp index 0ec694f..2a732da 100644 --- a/gui_qt/dialogheightmap.cpp +++ b/gui_qt/dialogheightmap.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "../lib_paysages/terrain.h" #include "../lib_paysages/scenery.h" @@ -76,6 +77,14 @@ DialogHeightMap::DialogHeightMap(QWidget* parent, HeightMap* heightmap, TerrainC button = new QPushButton(tr("Load from picture file"), panel); connect(button, SIGNAL(clicked()), this, SLOT(loadFromFile())); panel->layout()->addWidget(button); + + button = new QPushButton(tr("Change resolution"), panel); + connect(button, SIGNAL(clicked()), this, SLOT(changeResolution())); + panel->layout()->addWidget(button); + + _resolution_label = new QLabel("", panel); + panel->layout()->addWidget(_resolution_label); + updateResolutionLabel(); combobox = new QComboBox(panel); combobox->addItem(tr("Raise / lower")); @@ -148,6 +157,7 @@ void DialogHeightMap::revert() { heightmapCopy(_value_original, &_value_modified); _3dview->revert(); + updateResolutionLabel(); } void DialogHeightMap::angleHChanged(int value) @@ -187,6 +197,7 @@ void DialogHeightMap::loadFromFile() { heightmapImportFromPicture(&_value_modified, (char*) filepath.toStdString().c_str()); _3dview->revert(); + updateResolutionLabel(); } } @@ -206,3 +217,58 @@ void DialogHeightMap::resetToTerrain() _3dview->revert(); } } + +void DialogHeightMap::changeResolution() +{ + QString result; + QStringList items; + int current; + + items << QString("64 x 64") << QString("128 x 128") << QString("256 x 256") << QString("512 x 512"); + current = 1; + if (_value_modified.resolution_x == 64 && _value_modified.resolution_z == 64) + { + current = 0; + } + else if (_value_modified.resolution_x == 256 && _value_modified.resolution_z == 256) + { + current = 2; + } + else if (_value_modified.resolution_x == 512 && _value_modified.resolution_z == 512) + { + current = 3; + } + result = QInputDialog::getItem(this, tr("Paysages 3D - Change heightmap resolution"), tr("Choose the new heightmap resolution. Beware that lowering the resolution may imply a loss of accuracy."), items, current, false); + if (!result.isEmpty()) + { + int new_res_x, new_res_y; + if (result == QString("64 x 64")) + { + new_res_x = new_res_y = 64; + } + else if (result == QString("256 x 256")) + { + new_res_x = new_res_y = 256; + } + else if (result == QString("512 x 512")) + { + new_res_x = new_res_y = 512; + } + else + { + new_res_x = new_res_y = 128; + } + + if (new_res_x != _value_modified.resolution_x or new_res_y != _value_modified.resolution_z) + { + heightmapChangeResolution(&_value_modified, 64, 64); + _3dview->revert(); + updateResolutionLabel(); + } + } +} + +void DialogHeightMap::updateResolutionLabel() +{ + _resolution_label->setText(tr("Map resolution : %1 x %2").arg(_value_modified.resolution_x).arg(_value_modified.resolution_z)); +} diff --git a/gui_qt/dialogheightmap.h b/gui_qt/dialogheightmap.h index e7c0b96..757e624 100644 --- a/gui_qt/dialogheightmap.h +++ b/gui_qt/dialogheightmap.h @@ -1,6 +1,7 @@ #ifndef _PAYSAGES_QT_DIALOGHEIGHTMAP_H_ #define _PAYSAGES_QT_DIALOGHEIGHTMAP_H_ +#include #include "tools.h" #include "widgetheightmap.h" #include "../lib_paysages/heightmap.h" @@ -26,11 +27,14 @@ private slots: void brushStrengthChanged(int value); void loadFromFile(); void resetToTerrain(); + void changeResolution(); + void updateResolutionLabel(); private: HeightMap* _value_original; HeightMap _value_modified; WidgetHeightMap* _3dview; + QLabel* _resolution_label; TerrainCanvas* _canvas; };