Add operations on polygon : Duplicate, exportCsv, exportPol and simplify

SimplfyPolygon applies an operation on polygon to reduce the number of points in a way that the shape of the polygon is conserved.
This commit is contained in:
Magne Sjaastad
2024-03-04 07:28:04 +01:00
parent 5217ab5c8b
commit 3689cccae7
19 changed files with 621 additions and 19 deletions

View File

@@ -18,6 +18,10 @@
#include "RimPolygonTools.h"
#include "RiaPreferences.h"
#include "RifCsvDataTableFormatter.h"
#include "RimGridView.h"
#include "RimOilField.h"
#include "RimPolygon.h"
@@ -28,10 +32,13 @@
#include "Riu3DMainWindowTools.h"
#include <QFile>
#include <QTextStream>
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonTools::selectAndActivatePolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject )
void RimPolygonTools::activate3dEditOfPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject )
{
auto polygonInView = findPolygonInView( polygon, sourceObject );
if ( polygonInView )
@@ -41,6 +48,109 @@ void RimPolygonTools::selectAndActivatePolygonInView( RimPolygon* polygon, caf::
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
void RimPolygonTools::selectPolygonInView( RimPolygon* polygon, caf::PdmObject* sourceObject )
{
auto polygonInView = findPolygonInView( polygon, sourceObject );
if ( polygonInView )
{
Riu3DMainWindowTools::selectAsCurrentItem( polygonInView );
}
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPolygonTools::exportPolygonCsv( const RimPolygon* polygon, const QString& filePath )
{
if ( !polygon ) return false;
QFile file( filePath );
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) )
{
return false;
}
QTextStream out( &file );
QString fieldSeparator = RiaPreferences::current()->csvTextExportFieldSeparator;
RifCsvDataTableFormatter formatter( out, fieldSeparator );
const int precision = 2;
std::vector<RifTextDataTableColumn> header;
header.emplace_back( "X", RifTextDataTableDoubleFormatting( RIF_FLOAT, precision ) );
header.emplace_back( "Y", RifTextDataTableDoubleFormatting( RIF_FLOAT, precision ) );
header.emplace_back( "Z", RifTextDataTableDoubleFormatting( RIF_FLOAT, precision ) );
formatter.header( header );
for ( const auto& point : polygon->pointsInDomainCoords() )
{
formatter.add( point.x() );
formatter.add( point.y() );
formatter.add( -point.z() );
formatter.rowCompleted();
}
formatter.tableCompleted();
file.close();
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RimPolygonTools::exportPolygonPol( const RimPolygon* polygon, const QString& filePath )
{
if ( !polygon ) return false;
QFile file( filePath );
if ( !file.open( QIODevice::WriteOnly | QIODevice::Text ) ) return false;
QTextStream out( &file );
QString fieldSeparator = " ";
RifCsvDataTableFormatter formatter( out, fieldSeparator );
const int precision = 2;
std::vector<RifTextDataTableColumn> header;
header.emplace_back( " ", RifTextDataTableDoubleFormatting( RIF_FLOAT, precision ) );
header.emplace_back( " ", RifTextDataTableDoubleFormatting( RIF_FLOAT, precision ) );
header.emplace_back( " ", RifTextDataTableDoubleFormatting( RIF_FLOAT, precision ) );
formatter.header( header );
for ( const auto& point : polygon->pointsInDomainCoords() )
{
formatter.add( point.x() );
formatter.add( point.y() );
formatter.add( -point.z() );
formatter.rowCompleted();
}
const double endOfPolygon = 999.0;
formatter.add( endOfPolygon );
formatter.add( endOfPolygon );
formatter.add( endOfPolygon );
formatter.rowCompleted();
formatter.tableCompleted();
file.close();
return true;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
QString RimPolygonTools::polygonCacheName()
{
return "POLYGON";
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------