Skip to content

Commit

Permalink
Merge pull request #183 from PauloCarvalhoRJ/Issues20180519
Browse files Browse the repository at this point in the history
Issues20180519
  • Loading branch information
PauloCarvalhoRJ authored May 19, 2018
2 parents 08fe64b + eb9f06a commit f75aa0a
Show file tree
Hide file tree
Showing 16 changed files with 452 additions and 95 deletions.
2 changes: 1 addition & 1 deletion GammaRay.pro
Original file line number Diff line number Diff line change
Expand Up @@ -577,7 +577,7 @@ win32 {
# The application version
# Don't forget to update the Util::importSettingsFromPreviousVersion() method to
# enable the import of registry/user settings of previous versions.
VERSION = 4.3
VERSION = 4.3.3

# Define a preprocessor macro so we can get the application version in application code.
DEFINES += APP_VERSION=\\\"$$VERSION\\\"
Expand Down
5 changes: 5 additions & 0 deletions dialogs/sgsimdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,11 @@ void SGSIMDialog::preview()
//the number of realizations.
m_cg_simulation->setNReal( m_gpf_sgsim->getParameter<GSLibParUInt*>(14)->_value );

if( m_cg_simulation->getChildCount() < 1 ){
QMessageBox::critical( this, "Error", "SGSIM yielded a file without data. It is possible that SGSIM crashed. Check the message panel. Aborted.");
return;
}

//get the variable with the simulated values (normally the first)
Attribute* est_var = (Attribute*)m_cg_simulation->getChildByIndex( 0 );

Expand Down
Binary file modified docs/GammaRayManual.docx
Binary file not shown.
Binary file modified docs/figures.pptx
Binary file not shown.
2 changes: 1 addition & 1 deletion domain/cartesiangrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ int CartesianGrid::getVariableIndexByName(QString variableName)
IJAbstractVariable *CartesianGrid::getVariableByName(QString variableName)
{
ProjectComponent* pc = getChildByName( variableName );
if( pc->isAttribute() )
if( pc && pc->isAttribute() )
return dynamic_cast<Attribute*>(pc);
else
return nullptr;
Expand Down
158 changes: 156 additions & 2 deletions imagejockey/svd/svdanalysisdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
#include "ui_svdanalysisdialog.h"
#include "svdfactortree.h"
#include "spectral/svd.h"
#include <QFileDialog>
#include <QMenu>
#include <QMessageBox>
#include <QProgressDialog>
#include <QtCore>
#include "svdfactorsel/svdfactorsselectiondialog.h"
#include "../widgets/ijgridviewerwidget.h"
#include "../imagejockeyutils.h"
Expand Down Expand Up @@ -147,7 +149,10 @@ void SVDAnalysisDialog::onFactorContextMenu(const QPoint &mouse_location)
if( parents_are_the_same ){
m_factorContextMenu->addAction("Aggregate selected factors", this, SLOT(onAggregate()));
}
}
m_factorContextMenu->addAction("Check selected", this, SLOT(onCheckSelected()));
m_factorContextMenu->addAction("Uncheck selected", this, SLOT(onUncheckSelected()));
m_factorContextMenu->addAction("Invert check of selected", this, SLOT(onInvertCheckOfSelected()));
}

//show the context menu under the mouse cursor.
if( m_factorContextMenu->actions().size() > 0 )
Expand Down Expand Up @@ -316,6 +321,8 @@ void SVDAnalysisDialog::onPreviewRFFT()
progressDialog.setLabelText("Computing RFFT...");
QCoreApplication::processEvents(); //let Qt repaint widgets
spectral::backward( outputData, dataReady );
//fftw3's RFFT requires that the result be divided by the number of cells to be in right scale.
outputData = outputData * (1.0/(exampleFactor->getNI()*exampleFactor->getNJ()*exampleFactor->getNK()));
}

//Construct a displayable object from the result.
Expand Down Expand Up @@ -373,7 +380,154 @@ void SVDAnalysisDialog::onSaveAFactor()
{
spectral::array *oneFactorData = new spectral::array( m_right_clicked_factor->getFactorData() );
//reuse the signal to save a single factor data
emit sumOfFactorsComputed( oneFactorData );
emit sumOfFactorsComputed( oneFactorData );
}

void SVDAnalysisDialog::onCheckSelected()
{
QModelIndexList selected_indexes = ui->svdFactorTreeView->selectionModel()->selectedIndexes();
//for each of the selected factors...
for( int i = 0; i < selected_indexes.size(); ++i){
//get its tree widget index
QModelIndex index = selected_indexes.at(i);
if( index.isValid() ){
//retrieve the object pointer
SVDFactor* selected_factor = static_cast<SVDFactor*>( index.internalPointer() );
selected_factor->setSelected( true );
}
}
}

void SVDAnalysisDialog::onUncheckSelected()
{
QModelIndexList selected_indexes = ui->svdFactorTreeView->selectionModel()->selectedIndexes();
//for each of the selected factors...
for( int i = 0; i < selected_indexes.size(); ++i){
//get its tree widget index
QModelIndex index = selected_indexes.at(i);
if( index.isValid() ){
//retrieve the object pointer
SVDFactor* selected_factor = static_cast<SVDFactor*>( index.internalPointer() );
selected_factor->setSelected( false );
}
}
}

void SVDAnalysisDialog::onInvertCheckOfSelected()
{
QModelIndexList selected_indexes = ui->svdFactorTreeView->selectionModel()->selectedIndexes();
//for each of the selected factors...
for( int i = 0; i < selected_indexes.size(); ++i){
//get its tree widget index
QModelIndex index = selected_indexes.at(i);
if( index.isValid() ){
//retrieve the object pointer
SVDFactor* selected_factor = static_cast<SVDFactor*>( index.internalPointer() );
selected_factor->setSelected( ! selected_factor->isSelected() );
}
}
}

void SVDAnalysisDialog::onCustomAnalysis()
{
typedef std::vector< double > Line;
typedef std::vector< Line > Table;
QString fileName = QFileDialog::getOpenFileName(this, "Open text file with factor weights");

std::vector< SVDFactor* > selectedFactors = m_tree->getSelectedFactors();

//Loads the files with custom weights:
//
// Example of file contents:
//
// 1.00 0.00
// 1.00 0.00
// 0.50 0.50
// 0.00 1.00
//
// The example above creates two images:
//
// 1st = 100% of 1st fundamental factor +
// 100% of 2nd fundamental factor +
// 50% of 3rd fundamental factor +
// 0% of 4th fundamental factor
//
// 2nd = 0% of 1st fundamental factor +
// 0% of 2nd fundamental factor +
// 50% of 3rd fundamental factor +
// 100% of 4th fundamental factor
//
// Lines are read until matching the number of fundamental factors.
// For example, if there are 40 fundamental factors, only the first 40 lines of the file are read.
Table table;
uint nFields = 0;
{
QFile file( fileName );
file.open( QFile::ReadOnly | QFile::Text );
QTextStream in(&file);
for (int i = 0; !in.atEnd() && i < selectedFactors.size() ; ++i)
{
QString line = in.readLine();
QStringList fields = line.split(QRegExp("[\\s]"), QString::SplitBehavior::SkipEmptyParts);
if( ! nFields )
nFields = fields.size();
Line values;
QStringList::iterator it = fields.begin();
for(; it != fields.end(); ++it) {
values.push_back( (*it).toDouble() );
}
table.push_back( values );
}
file.close();
}


//Make all-zeros geological factors (one per column in the supplied data file)
SVDFactor* geoFactors[nFields];
{
SVDFactor* exampleFactor = m_tree->getOneTopLevelFactor( 0 );
uint nI = exampleFactor->getNI();
uint nJ = exampleFactor->getNJ();
uint nK = exampleFactor->getNK();
double x0 = exampleFactor->getOriginX();
double y0 = exampleFactor->getOriginY();
double z0 = exampleFactor->getOriginZ();
double dx = exampleFactor->getCellSizeI();
double dy = exampleFactor->getCellSizeJ();
double dz = exampleFactor->getCellSizeK();
for( int i = 0; i < nFields; ++i ){
spectral::array zeros( (spectral::index) nI, (spectral::index)nJ, (spectral::index)nK );
geoFactors[i] = new SVDFactor( std::move(zeros), i+1, 1.0, x0, y0, z0, dx, dy, dz, 0.0 );
}
}

//compute the geological factors
Table::iterator itRows = table.begin();
for(int iRow = 0; itRows != table.end(); ++itRows, ++iRow ){
Line::iterator itCols = (*itRows).begin();
for(int iCol = 0; itCols != (*itRows).end(); ++itCols, ++iCol ){
geoFactors[iCol]->sum( selectedFactors[iRow]->getFactorData() * *itCols );
}
}

//display the geological factors for investigation
QWidget* window = new QWidget();
window->setWindowTitle("Geological factors");
window->setAttribute(Qt::WA_DeleteOnClose);
QHBoxLayout* layout = new QHBoxLayout();
for( int i = 0; i < nFields; ++i ){
IJGridViewerWidget* wid = new IJGridViewerWidget( true );
geoFactors[i]->setCustomName( "Geological factor #" + QString::number(i+1) );
wid->setFactor( geoFactors[i] );
layout->addWidget( wid );
}
window->setLayout( layout );
window->show();

//delete the geological factors (deleted by the dialogs before)
// for( int i = 0; i < nFields; ++i )
// delete geoFactors[i];

}

void SVDAnalysisDialog::saveTreeUIState()
Expand Down
4 changes: 4 additions & 0 deletions imagejockey/svd/svdanalysisdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ private slots:
void onDeleteChildren();
void onAggregate();
void onSaveAFactor();
void onCheckSelected();
void onUncheckSelected();
void onInvertCheckOfSelected();
void onCustomAnalysis();
};

#endif // SVDANALYSISDIALOG_H
72 changes: 30 additions & 42 deletions imagejockey/svd/svdanalysisdialog.ui
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,7 @@
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -57,16 +48,7 @@
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>0</number>
</property>
<item>
Expand All @@ -92,16 +74,7 @@
<enum>QFrame::Raised</enum>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>0</number>
</property>
<item>
Expand Down Expand Up @@ -140,16 +113,7 @@
<enum>QFrame::Raised</enum>
</property>
<layout class="QHBoxLayout" name="horizontalLayout">
<property name="leftMargin">
<number>0</number>
</property>
<property name="topMargin">
<number>0</number>
</property>
<property name="rightMargin">
<number>0</number>
</property>
<property name="bottomMargin">
<property name="margin">
<number>0</number>
</property>
<item>
Expand All @@ -173,6 +137,13 @@
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="btnCustomAnalysis">
<property name="text">
<string>Custom Analysis</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
Expand Down Expand Up @@ -246,8 +217,8 @@
<slot>onSave()</slot>
<hints>
<hint type="sourcelabel">
<x>237</x>
<y>491</y>
<x>264</x>
<y>490</y>
</hint>
<hint type="destinationlabel">
<x>107</x>
Expand Down Expand Up @@ -287,11 +258,28 @@
</hint>
</hints>
</connection>
<connection>
<sender>btnCustomAnalysis</sender>
<signal>clicked()</signal>
<receiver>SVDAnalysisDialog</receiver>
<slot>onCustomAnalysis()</slot>
<hints>
<hint type="sourcelabel">
<x>357</x>
<y>482</y>
</hint>
<hint type="destinationlabel">
<x>411</x>
<y>495</y>
</hint>
</hints>
</connection>
</connections>
<slots>
<slot>onFactorClicked(QModelIndex)</slot>
<slot>onSave()</slot>
<slot>onPreview()</slot>
<slot>onPreviewRFFT()</slot>
<slot>onCustomAnalysis()</slot>
</slots>
</ui>
18 changes: 17 additions & 1 deletion imagejockey/svd/svdfactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ double SVDFactor::getSVDFactorTreeSplitThreshold(bool reset)
//ask the user once for the default tree split threshold
bool ok;
int percentage = QInputDialog::getInt(nullptr, "Further SVD factoring threshold",
"Split information content in percentage parts (%):", 50, 1, 50, 5, &ok);
"Split information content in percentage parts (%):", 50, 0, 50, 5, &ok);
if (ok)
setting = percentage / 100.0;
else
Expand Down Expand Up @@ -428,6 +428,22 @@ bool SVDFactor::setSlice(SVDFactor * slice)
return true;
}

void SVDFactor::getSelectedChildFactors(std::vector<SVDFactor *> & selectedFactors)
{
std::vector<SVDFactor*>::iterator it = m_childFactors.begin();
for(; it != m_childFactors.end(); ++it){
if( (*it)->isSelected() ){
selectedFactors.push_back( *it );
(*it)->getSelectedChildFactors( selectedFactors );
}
}
}

void SVDFactor::sum(const spectral::array & valuesToSum)
{
(*m_factorData) += valuesToSum;
}

SVDFactor *SVDFactor::getChildByIndex(uint index)
{
return m_childFactors[index];
Expand Down
Loading

0 comments on commit f75aa0a

Please sign in to comment.