Minor cleanup - WIP

This commit is contained in:
Jørgen Herje
2024-03-08 15:25:00 +01:00
parent 6a10b6f326
commit 0ed0d81765
12 changed files with 278 additions and 381 deletions

View File

@@ -109,7 +109,7 @@ void RicPointTangentManipulatorPartMgr::originAndTangent( cvf::Vec3d* origin, cv
//--------------------------------------------------------------------------------------------------
void RicPointTangentManipulatorPartMgr::setPolyline( const std::vector<cvf::Vec3d>& polyline )
{
m_polylineUtm = polyline;
m_polyline = polyline;
}
//--------------------------------------------------------------------------------------------------
@@ -192,10 +192,10 @@ void RicPointTangentManipulatorPartMgr::updateManipulatorFromRay( const cvf::Ray
double closestDistance = std::numeric_limits<double>::max();
cvf::Vec3d closestPoint;
for ( size_t i = 1; i < m_polylineUtm.size(); i++ )
for ( size_t i = 1; i < m_polyline.size(); i++ )
{
const auto& p1 = m_polylineUtm[i];
const auto& p2 = m_polylineUtm[i - 1];
const auto& p1 = m_polyline[i];
const auto& p2 = m_polyline[i - 1];
double normalizedIntersection;
const auto pointOnLine = cvf::GeometryTools::projectPointOnLine( p1, p2, newOrigin, &normalizedIntersection );
@@ -256,7 +256,7 @@ void RicPointTangentManipulatorPartMgr::endManipulator()
//--------------------------------------------------------------------------------------------------
void RicPointTangentManipulatorPartMgr::recreateAllGeometryAndParts()
{
if ( m_polylineUtm.empty() )
if ( m_polyline.empty() )
{
createHorizontalPlaneHandle();
createVerticalAxisHandle();
@@ -272,7 +272,7 @@ void RicPointTangentManipulatorPartMgr::recreateAllGeometryAndParts()
//--------------------------------------------------------------------------------------------------
void RicPointTangentManipulatorPartMgr::createGeometryOnly()
{
if ( m_polylineUtm.empty() )
if ( m_polyline.empty() )
{
m_handleParts[HandleType::HORIZONTAL_PLANE]->setDrawable( createHorizontalPlaneGeo().p() );
m_handleParts[HandleType::VERTICAL_AXIS]->setDrawable( createVerticalAxisGeo().p() );

View File

@@ -102,7 +102,7 @@ private:
double m_handleSize;
bool m_isGeometryUpdateNeeded;
std::vector<cvf::Vec3d> m_polylineUtm;
std::vector<cvf::Vec3d> m_polyline;
HandleType m_activeHandle;
cvf::Vec3d m_initialPickPoint;

View File

@@ -40,17 +40,10 @@ void PolygonVertexWelder::reserveVertices( cvf::uint vertexCount )
}
//--------------------------------------------------------------------------------------------------
///
/// Add a vertex to the welder. If the vertex is within the tolerance of an existing vertex, the existing
// vertex index is returned
//--------------------------------------------------------------------------------------------------
std::vector<cvf::uint> PolygonVertexWelder::weldVerticesAndGetIndices( const std::vector<cvf::Vec3f>& vertices )
{
return {};
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::uint PolygonVertexWelder::weldVertexAndGetIndex( const cvf::Vec3f& vertex )
cvf::uint PolygonVertexWelder::weldVertexAndGetIndex( const cvf::Vec3d& vertex )
{
// Call function to step through linked list of bucket, testing
// if vertex is within the epsilon of one of the vertices in the bucket
@@ -69,7 +62,7 @@ cvf::uint PolygonVertexWelder::weldVertexAndGetIndex( const cvf::Vec3f& vertex )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const cvf::Vec3f& PolygonVertexWelder::vertex( cvf::uint index ) const
const cvf::Vec3d& PolygonVertexWelder::vertex( cvf::uint index ) const
{
return m_vertex[index];
}
@@ -77,22 +70,22 @@ const cvf::Vec3f& PolygonVertexWelder::vertex( cvf::uint index ) const
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::Vec3fArray> PolygonVertexWelder::createVertexArray() const
cvf::ref<cvf::Vec3dArray> PolygonVertexWelder::createVertexArray() const
{
cvf::ref<cvf::Vec3fArray> vertexArray = new cvf::Vec3fArray( m_vertex );
cvf::ref<cvf::Vec3dArray> vertexArray = new cvf::Vec3dArray( m_vertex );
return vertexArray;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::uint PolygonVertexWelder::locateVertexInPolygon( const cvf::Vec3f& vertex ) const
cvf::uint PolygonVertexWelder::locateVertexInPolygon( const cvf::Vec3d& vertex ) const
{
cvf::uint currentIndex = m_first;
while ( currentIndex != cvf::UNDEFINED_UINT )
{
// Weld point within tolerance
float distanceSquared = ( m_vertex[currentIndex] - vertex ).lengthSquared();
const auto distanceSquared = ( m_vertex[currentIndex] - vertex ).lengthSquared();
if ( distanceSquared < m_epsilonSquared )
{
return currentIndex;
@@ -107,7 +100,7 @@ cvf::uint PolygonVertexWelder::locateVertexInPolygon( const cvf::Vec3f& vertex )
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::uint PolygonVertexWelder::addVertexToPolygon( const cvf::Vec3f& vertex )
cvf::uint PolygonVertexWelder::addVertexToPolygon( const cvf::Vec3d& vertex )
{
// Add vertex and update linked list
m_vertex.push_back( vertex );
@@ -131,7 +124,7 @@ cvf::uint PolygonVertexWelder::addVertexToPolygon( const cvf::Vec3f& vertex )
//--------------------------------------------------------------------------------------------------
RivEnclosingPolygonGenerator::RivEnclosingPolygonGenerator()
: m_polygonVertexWelder( 1e-6 )
: m_polygonVertexWelder( 1e-3 )
{
}
@@ -169,6 +162,7 @@ void RivEnclosingPolygonGenerator::constructEnclosingPolygon()
for ( const auto& edgeKey : m_allEdgeKeys )
{
// If edge is already in the set, it occurs more than once and is not a boundary edge
// Assuming no degenerate triangles, i.e. triangle with two or more vertices at the same position
if ( edgeKeysAndCount.contains( edgeKey ) )
{
edgeKeysAndCount[edgeKey]++;
@@ -255,7 +249,7 @@ cvf::EdgeKey RivEnclosingPolygonGenerator::findNextEdge( cvf::uint vertexIndex,
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<cvf::Vec3f> RivEnclosingPolygonGenerator::getPolygonVertices() const
std::vector<cvf::Vec3d> RivEnclosingPolygonGenerator::getPolygonVertices() const
{
return m_polygonVertices;
}
@@ -269,14 +263,22 @@ bool RivEnclosingPolygonGenerator::isValidPolygon() const
}
//--------------------------------------------------------------------------------------------------
/// Add triangle vertices to the polygon. The vertices are welded to prevent duplicated vertices
///
/// Assumes that the vertices are given in counter-clockwise order
//--------------------------------------------------------------------------------------------------
void RivEnclosingPolygonGenerator::addTriangleVertices( const cvf::Vec3f& p0, const cvf::Vec3f& p1, const cvf::Vec3f& p2 )
void RivEnclosingPolygonGenerator::addTriangleVertices( const cvf::Vec3d& p0, const cvf::Vec3d& p1, const cvf::Vec3d& p2 )
{
cvf::uint i0 = m_polygonVertexWelder.weldVertexAndGetIndex( p0 );
cvf::uint i1 = m_polygonVertexWelder.weldVertexAndGetIndex( p1 );
cvf::uint i2 = m_polygonVertexWelder.weldVertexAndGetIndex( p2 );
// Verify three unique vertices - i.e. no degenerate triangle
if ( i0 == i1 || i0 == i2 || i1 == i2 )
{
return;
}
// Add edges keys to list of all edges
m_allEdgeKeys.emplace_back( cvf::EdgeKey( i0, i1 ).toKeyVal() );
m_allEdgeKeys.emplace_back( cvf::EdgeKey( i1, i2 ).toKeyVal() );

View File

@@ -37,24 +37,21 @@ public:
void reserveVertices( cvf::uint vertexCount );
// Add a vertex to the welder. If the vertex is within the tolerance of an existing vertex, the existing vertex index is returned
// Size of returned index array is equal size of input array
std::vector<cvf::uint> weldVerticesAndGetIndices( const std::vector<cvf::Vec3f>& vertices ); // TODO: Remove?
cvf::uint weldVertexAndGetIndex( const cvf::Vec3f& vertex );
cvf::uint weldVertexAndGetIndex( const cvf::Vec3d& vertex );
const cvf::Vec3f& vertex( cvf::uint index ) const;
cvf::ref<cvf::Vec3fArray> createVertexArray() const;
const cvf::Vec3d& vertex( cvf::uint index ) const;
cvf::ref<cvf::Vec3dArray> createVertexArray() const;
private:
cvf::uint locateVertexInPolygon( const cvf::Vec3f& vertex ) const;
cvf::uint addVertexToPolygon( const cvf::Vec3f& vertex );
cvf::uint locateVertexInPolygon( const cvf::Vec3d& vertex ) const;
cvf::uint addVertexToPolygon( const cvf::Vec3d& vertex );
private:
const double m_epsilonSquared; // Tolerance for vertex welding, radius around vertex defining welding neighborhood
cvf::uint m_first; // Start of linked list
std::vector<cvf::uint> m_next; // Links each vertex to next in linked list. Always numVertices long, will grow as vertices are added
std::vector<cvf::Vec3f> m_vertex; // Unique vertices within tolerance
std::vector<cvf::Vec3d> m_vertex; // Unique vertices within tolerance
};
/*
@@ -70,11 +67,11 @@ class RivEnclosingPolygonGenerator
public:
RivEnclosingPolygonGenerator();
std::vector<cvf::Vec3f> getPolygonVertices() const;
std::vector<cvf::Vec3d> getPolygonVertices() const;
bool isValidPolygon() const;
void addTriangleVertices( const cvf::Vec3f& p0, const cvf::Vec3f& p1, const cvf::Vec3f& p2 );
void addTriangleVertices( const cvf::Vec3d& p0, const cvf::Vec3d& p1, const cvf::Vec3d& p2 );
void constructEnclosingPolygon();
private:
@@ -83,5 +80,5 @@ private:
private:
PolygonVertexWelder m_polygonVertexWelder; // Add and weld vertices for a polygon, provides vertex index
std::vector<cvf::int64> m_allEdgeKeys; // Create edge defined by vertex indices when adding triangle. Using cvf::EdgeKey::toKeyVal()
std::vector<cvf::Vec3f> m_polygonVertices; // List polygon vertices counter clock-wise
std::vector<cvf::Vec3d> m_polygonVertices; // List polygon vertices counter clock-wise
};

View File

@@ -31,9 +31,9 @@
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
RivPolylineIntersectionGeometryGenerator::RivPolylineIntersectionGeometryGenerator( std::vector<cvf::Vec3d>& polylineUtm,
RivPolylineIntersectionGeometryGenerator::RivPolylineIntersectionGeometryGenerator( const std::vector<cvf::Vec2d>& polylineUtmXy,
RivIntersectionHexGridInterface* grid )
: m_polylineUtm( polylineUtm )
: m_polylineUtm( initializePolylineUtmFromPolylineUtmXy( polylineUtmXy ) )
, m_hexGrid( grid )
{
m_polygonVertices = new cvf::Vec3fArray;
@@ -46,45 +46,29 @@ RivPolylineIntersectionGeometryGenerator::~RivPolylineIntersectionGeometryGenera
{
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
std::vector<cvf::Vec3d>
RivPolylineIntersectionGeometryGenerator::initializePolylineUtmFromPolylineUtmXy( const std::vector<cvf::Vec2d>& polylineUtmXy )
{
std::vector<cvf::Vec3d> polylineUtm;
polylineUtm.reserve( polylineUtmXy.size() );
const double zValue = 0.0;
for ( const auto& xy : polylineUtmXy )
{
polylineUtm.push_back( cvf::Vec3d( xy.x(), xy.y(), zValue ) );
}
return polylineUtm;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
bool RivPolylineIntersectionGeometryGenerator::isAnyGeometryPresent() const
{
return m_polygonVertices->size() > 0;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<size_t>& RivPolylineIntersectionGeometryGenerator::triangleToCellIndex() const
{
// Not implemented - not in use
CVF_ASSERT( false );
return m_emptyTriangleToCellIdxMap;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const cvf::Vec3fArray* RivPolylineIntersectionGeometryGenerator::triangleVxes() const
{
// Not implemented - not in use
CVF_ASSERT( false );
return nullptr;
}
//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
const std::vector<RivIntersectionVertexWeights>& RivPolylineIntersectionGeometryGenerator::triangleVxToCellCornerInterpolationWeights() const
{
// Not implemented - not in use
CVF_ASSERT( false );
return m_emptyTriVxToCellCornerWeights;
return m_polylineSegmentsMeshData.size() > 0;
}
//--------------------------------------------------------------------------------------------------
@@ -136,36 +120,18 @@ void RivPolylineIntersectionGeometryGenerator::generateIntersectionGeometry( cvf
//--------------------------------------------------------------------------------------------------
void RivPolylineIntersectionGeometryGenerator::calculateArrays( cvf::UByteArray* visibleCells )
{
if ( m_polygonVertices->size() != 0 || m_hexGrid.isNull() ) return;
if ( m_hexGrid.isNull() || m_polylineSegmentsMeshData.size() != 0 ) return;
std::vector<cvf::Vec3f> calculatedPolygonVertices;
std::vector<PolylineSegmentMeshData> polylineSegmentMeshData = {}; // Mesh data per polyline segment
// Mesh data per polyline segment
std::vector<PolylineSegmentMeshData> polylineSegmentMeshData = {};
std::vector<cvf::Vec3f> calculatedPolygonVertices = {};
cvf::BoundingBox gridBBox = m_hexGrid->boundingBox();
const double topDepth = gridBBox.max().z();
const double bottomDepth = gridBBox.min().z();
std::array<cvf::Vec3d, 8> corners;
gridBBox.cornerVertices( corners.data() );
cvf::Vec3d p1_low( corners[0].x(), corners[0].y(), bottomDepth );
cvf::Vec3d p2_low( corners[1].x(), corners[1].y(), bottomDepth );
cvf::Vec3d p3_low( corners[2].x(), corners[2].y(), bottomDepth );
cvf::Plane lowPlane;
lowPlane.setFromPoints( p1_low, p2_low, p3_low );
cvf::Vec3d p1_high( p1_low.x(), p1_low.y(), topDepth );
cvf::Vec3d p2_high( p2_low.x(), p2_low.y(), topDepth );
cvf::Vec3d p3_high( p3_low.x(), p3_low.y(), topDepth );
cvf::Plane highPlane;
highPlane.setFromPoints( p1_high, p2_high, p3_high );
highPlane.flip();
const auto zAxisDirection = -cvf::Vec3d::Z_AXIS; // NOTE: Negative or positive direction?
const cvf::Vec3d maxHeightVec = zAxisDirection * gridBBox.radius();
if ( m_polylineUtm.size() > 1 )
{
const size_t numPoints = m_polylineUtm.size();
@@ -221,10 +187,8 @@ void RivPolylineIntersectionGeometryGenerator::calculateArrays( cvf::UByteArray*
size_t cornerIndices[8];
// Mesh data for polyline segment
std::vector<cvf::Vec2f> polygonVerticesUz = {};
std::vector<float> polygonVerticesUz = {};
std::vector<cvf::uint> verticesPerPolygon = {};
const cvf::Vec3f p1_f( p1 );
// Handle triangles per cell
for ( const auto globalCellIdx : columnCellCandidates )
@@ -267,16 +231,19 @@ void RivPolylineIntersectionGeometryGenerator::calculateArrays( cvf::UByteArray*
size_t clippedTriangleCount = clippedTriangleVxes.size() / 3;
for ( size_t triangleIdx = 0; triangleIdx < clippedTriangleCount; ++triangleIdx )
{
// Get triangle vertices
const size_t vxIdx0 = triangleIdx * 3;
const size_t vxIdx1 = vxIdx0 + 1;
const size_t vxIdx2 = vxIdx0 + 2;
const auto& vx0 = clippedTriangleVxes[vxIdx0 + 0].vx;
const auto& vx1 = clippedTriangleVxes[vxIdx0 + 1].vx;
const auto& vx2 = clippedTriangleVxes[vxIdx0 + 2].vx;
// Convert points from UTM to "local" coordinates
// NOTE: Do not subtract z-values. The z-values are used for the uz-coordinates
// and not provided as additional UTM info with response
const cvf::Vec3f point0( clippedTriangleVxes[vxIdx0].vx - p1 );
const cvf::Vec3f point1( clippedTriangleVxes[vxIdx1].vx - p1 );
const cvf::Vec3f point2( clippedTriangleVxes[vxIdx2].vx - p1 );
// Convert to local coordinates, where p1 is origin.
// The z-values are global z-values in the uz-coordinates.
const cvf::Vec3d point0( vx0.x() - p1.x(), vx0.y() - p1.y(), vx0.z() );
const cvf::Vec3d point1( vx1.x() - p1.x(), vx1.y() - p1.y(), vx1.z() );
const cvf::Vec3d point2( vx2.x() - p1.x(), vx2.y() - p1.y(), vx2.z() );
// TODO: Ensure counter clockwise order of vertices point0, point1, point2?
// Add triangle to enclosing polygon line handler
enclosingPolygonGenerator.addTriangleVertices( point0, point1, point2 );
@@ -293,31 +260,39 @@ void RivPolylineIntersectionGeometryGenerator::calculateArrays( cvf::UByteArray*
const auto& vertices = enclosingPolygonGenerator.getPolygonVertices();
// Construct local uz-coordinates using Pythagoras theorem
for ( const auto& vertex : vertices )
{
// Convert to local uz-coordinates
// NOTE: Can welding provide drifting of vertex positions?
// TODO: Project (x,y) into plane instead?
//
// Convert to local uz-coordinates, u is the distance along the normalized U-axis
const auto u = std::sqrt( vertex.x() * vertex.x() + vertex.y() * vertex.y() );
const auto z = vertex.z();
polygonVerticesUz.push_back( cvf::Vec2f( u, z ) ); // u = x, z = y
polygonVerticesUz.push_back( u );
polygonVerticesUz.push_back( z );
// Keep old code for debugging purposes
calculatedPolygonVertices.push_back( vertex + p1_f );
calculatedPolygonVertices.push_back( cvf::Vec3f( vertex + p1 ) );
}
verticesPerPolygon.push_back( static_cast<cvf::uint>( vertices.size() ) );
// Keep old code for debugging purposes
m_verticesPerPolygon.push_back( vertices.size() );
m_polygonToCellIdxMap.push_back( globalCellIdx );
m_verticesPerPolygon.push_back( vertices.size() ); // TODO: Remove when not needed for debug
m_polygonToCellIdxMap.push_back( globalCellIdx ); // TODO: Remove when not needed for debug
}
// Create polygon indices array
std::vector<cvf::uint> polygonIndices( polygonVerticesUz.size() );
std::iota( polygonIndices.begin(), polygonIndices.end(), 0 );
// Construct polyline segment mesh data
PolylineSegmentMeshData polylineSegmentData;
polylineSegmentData.startUtmXY = cvf::Vec2d( p1.x(), p1.y() );
polylineSegmentData.endUtmXY = cvf::Vec2d( p2.x(), p2.y() );
polylineSegmentData.vertexArrayUZ.assign( polygonVerticesUz );
polylineSegmentData.vertexArrayUZ = polygonVerticesUz;
polylineSegmentData.verticesPerPolygon = verticesPerPolygon;
polylineSegmentData.polygonIndices = {}; // TODO: Add indices or remove from struct?
polylineSegmentData.polygonIndices = polygonIndices;
// Add polyline segment mesh data to list
m_polylineSegmentsMeshData.push_back( polylineSegmentData );
@@ -327,7 +302,7 @@ void RivPolylineIntersectionGeometryGenerator::calculateArrays( cvf::UByteArray*
}
}
m_polygonVertices->assign( calculatedPolygonVertices );
m_polygonVertices->assign( calculatedPolygonVertices ); // TODO: Remove when not needed for debug
}
//--------------------------------------------------------------------------------------------------

View File

@@ -19,14 +19,9 @@
#pragma once
#include "cafPdmPointer.h"
#include "RivIntersectionGeometryGeneratorInterface.h"
#include "cvfArray.h"
#include "cvfBoundingBox.h"
#include "cvfObject.h"
#include "cvfVector3.h"
#include <vector>
@@ -47,8 +42,8 @@ class DrawableGeo;
struct PolylineSegmentMeshData
{
// Naming things? FenceMeshSection/PolylineMeshSection?
cvf::Vec2fArray vertexArrayUZ; // Consider std::vector<cvf::uint> instead, as access methods of Vec2f is .x() and .y()
// U-axis defined by the unit length vector from start (x,y) to end (x,y), Z is global Z
std::vector<float> vertexArrayUZ; // U coordinate is length along U-axis. Array [u0,z0,u1,z1,...,ui,zi]
std::vector<cvf::uint> polygonIndices; // Not needed when vertices/nodes are not shared between polygons?
std::vector<cvf::uint> verticesPerPolygon;
std::vector<cvf::uint> polygonToCellIndexMap;
@@ -56,26 +51,22 @@ struct PolylineSegmentMeshData
cvf::Vec2d endUtmXY;
};
// TODO: Remove inheritance from RivIntersectionGeometryGeneratorInterface? As we do not use triangles
class RivPolylineIntersectionGeometryGenerator : public cvf::Object, public RivIntersectionGeometryGeneratorInterface
class RivPolylineIntersectionGeometryGenerator
{
public:
RivPolylineIntersectionGeometryGenerator( std::vector<cvf::Vec3d>& polylineUtm, RivIntersectionHexGridInterface* grid );
~RivPolylineIntersectionGeometryGenerator() override;
RivPolylineIntersectionGeometryGenerator( const std::vector<cvf::Vec2d>& polylineUtmXy, RivIntersectionHexGridInterface* grid );
~RivPolylineIntersectionGeometryGenerator();
void generateIntersectionGeometry( cvf::UByteArray* visibleCells );
bool isAnyGeometryPresent() const;
// TODO: Remove after testing?
const cvf::Vec3fArray* polygonVxes() const;
const std::vector<size_t>& vertiesPerPolygon() const;
const std::vector<size_t>& polygonToCellIndex() const;
const std::vector<PolylineSegmentMeshData>& polylineSegmentsMeshData() const;
// GeomGen Interface
bool isAnyGeometryPresent() const override;
const std::vector<size_t>& triangleToCellIndex() const override;
const std::vector<RivIntersectionVertexWeights>& triangleVxToCellCornerInterpolationWeights() const override;
const cvf::Vec3fArray* triangleVxes() const override;
private:
void calculateArrays( cvf::UByteArray* visibleCells );
static std::vector<size_t> createPolylineSegmentCellCandidates( const RivIntersectionHexGridInterface& hexGrid,
@@ -85,18 +76,17 @@ private:
const double topDepth,
const double bottomDepth );
static std::vector<cvf::Vec3d> initializePolylineUtmFromPolylineUtmXy( const std::vector<cvf::Vec2d>& polylineUtmXy );
private:
cvf::ref<RivIntersectionHexGridInterface> m_hexGrid;
const std::vector<cvf::Vec3d> m_polylineUtm;
// Output arrays
// Output
std::vector<PolylineSegmentMeshData> m_polylineSegmentsMeshData;
// TMP Output arrays for debug
std::vector<size_t> m_polygonToCellIdxMap;
cvf::ref<cvf::Vec3fArray> m_polygonVertices;
std::vector<size_t> m_verticesPerPolygon;
std::vector<PolylineSegmentMeshData> m_polylineSegmentsMeshData;
// Dummy vectors for GeomGen Interface
const std::vector<size_t> m_emptyTriangleToCellIdxMap = {};
const std::vector<RivIntersectionVertexWeights> m_emptyTriVxToCellCornerWeights = {};
};

View File

@@ -59,8 +59,8 @@ message CutAlongPolylineRequest
message FenceMeshSection
{
// U-axis defined by vector from start to end, Z is global Z
repeated float vertexArrayUZ = 1;
// U-axis defined by the unit length vector from start to end, Z is global Z
repeated float vertexArrayUZ = 1; // U coordinate is length along U-axis
repeated fixed32 polyIndicesArr = 2; // Note: Redundant if no shared nodes?
repeated fixed32 verticesPerPolygonArr = 3; // Number of vertices per polygon, numPolygons long
repeated fixed32 sourceCellIndicesArr = 4; // The originating cell index per polygon, numPolygons long

View File

@@ -13,7 +13,7 @@ from rips.generated.GridGeometryExtraction_pb2 import *
rips_instance = Instance.find()
grid_geometry_extraction_stub = GridGeometryExtractionStub(rips_instance.channel)
grid_file_name = None
grid_file_name = "MOCKED_TEST_GRID"
grid_file_name = (
"D:\\Git\\resinsight-tutorials\\model-data\\norne\\NORNE_ATW2013_RFTPLT_V2.EGRID"
)
@@ -43,7 +43,7 @@ norne_case_single_segment_poly_line_utm_xy = [457150, 7.32106e06, 456885, 7.3217
norne_case_single_segment_poly_line_gap_utm_xy = [460877, 7.3236e06, 459279, 7.32477e06]
fence_poly_line_utm_xy = norne_case_single_segment_poly_line_utm_xy
fence_poly_line_utm_xy = norne_case_fence_poly_line_utm_xy
cut_along_polyline_request = GridGeometryExtraction__pb2.CutAlongPolylineRequest(
gridFilename=grid_file_name,
@@ -55,102 +55,59 @@ cut_along_polyline_response: GridGeometryExtraction__pb2.CutAlongPolylineRespons
fence_mesh_sections = cut_along_polyline_response.feceMeshSections
print(f"Number of fence mesh sections: {len(fence_mesh_sections)}")
# for section in fence_mesh_sections:
section_mesh_3d = []
section_polygon_edges_3d = []
# Use first segment start (x,y) as origin
x_origin = fence_mesh_sections[0].startUtmXY.x if len(fence_mesh_sections) > 0 else 0
y_origin = fence_mesh_sections[0].startUtmXY.y if len(fence_mesh_sections) > 0 else 0
for section in fence_mesh_sections:
# Continue to next section
polygon_vertex_array_uz = section.vertexArrayUZ
vertices_per_polygon = section.verticesPerPolygonArr
start = section.startUtmXY
end = section.endUtmXY
# Get start and end coordinates (local coordinates)
start_x = section.startUtmXY.x - x_origin
start_y = section.startUtmXY.y - y_origin
end_x = section.endUtmXY.x - x_origin
end_y = section.endUtmXY.y - y_origin
# Create directional vector from start to end
direction_vector = [end[0] - start[0], end[1] - start[1]]
direction_vector = [end_x - start_x, end_y - start_y]
# Normalize the directional vector
length = np.sqrt(direction_vector[0] ** 2 + direction_vector[1] ** 2)
direction_vector_norm = [direction_vector[0] / length, direction_vector[1] / length]
# Decompose the polygon vertex array into x, y, z arrays
x_array = []
y_array = []
z_array = []
# 2 coordinates per vertex (u, v)
for i in range(0, len(polygon_vertex_array_uz), 2):
u = polygon_vertex_array_uz[i]
z = polygon_vertex_array_uz[i + 1]
# Calculate x, y from u and directional vector,
# where u is the length along the direction vector
x = start[0] + u * direction_vector[0]
y = start[1] + u * direction_vector[1]
x_array.append(x)
y_array.append(y)
z_array.append(z)
# ******************************************
# ******************************************
#
# TODO: CONTINUE FROM HERE
#
# ******************************************
# ******************************************
polygon_vertex_array_org = (
cut_along_polyline_response.polylineTestResponse.polygonVertexArray
)
vertices_per_polygon = (
cut_along_polyline_response.polylineTestResponse.verticesPerPolygonArr
)
source_cell_indices = (
cut_along_polyline_response.polylineTestResponse.sourceCellIndicesArr
)
x_start = polygon_vertex_array_org[0]
y_start = polygon_vertex_array_org[1]
z_start = polygon_vertex_array_org[2]
# Subtract x_start, y_start, z_start from all x, y, z coordinates
polygon_vertex_array = []
for i in range(0, len(polygon_vertex_array_org), 3):
polygon_vertex_array.extend(
[
polygon_vertex_array_org[i] - x_start,
polygon_vertex_array_org[i + 1] - y_start,
polygon_vertex_array_org[i + 2] - z_start,
]
)
num_vertex_coords = 3 # [x, y, z]
vertex_step = 2
# Create x-, y-, and z-arrays
x_array = []
y_array = []
z_array = []
for i in range(0, len(polygon_vertex_array), num_vertex_coords):
# vertex array is provided as a single array of x, y, z coordinates
# i.e. [x1, y1, z1, x2, y2, z2, x3, y3, z3, ... , xn, yn, zn]
x_array.append(polygon_vertex_array[i + 0])
y_array.append(polygon_vertex_array[i + 1])
z_array.append(polygon_vertex_array[i + 2])
for i in range(0, len(polygon_vertex_array_uz), vertex_step):
u = polygon_vertex_array_uz[i]
z = polygon_vertex_array_uz[i + 1]
# Create triangular mesh
vertices = np.array(polygon_vertex_array).reshape(-1, 3)
# Calculate x, y from u and directional vector,
# where u is the length along the direction vector
x = start_x + u * direction_vector_norm[0]
y = start_y + u * direction_vector_norm[1]
x_array.append(x)
y_array.append(y)
z_array.append(z)
# Create mesh data
x, y, z = vertices.T
i = []
j = []
k = []
# Create edges between points in triangles
triangle_edges_x = []
triangle_edges_y = []
triangle_edges_z = []
# Populate i, j, k based on vertices_per_polygon
# Create triangles from each polygon
# A quad with vertex [0,1,2,3] will be split into two triangles [0,1,2] and [0,2,3]
# A hexagon with vertex [0,1,2,3,4,5] will be split into four triangles [0,1,2], [0,2,3], [0,3,4], [0,4,5]
polygon_v0_idx = 0 # Index of vertex 0 in the polygon
for vertex_count in vertices_per_polygon:
# Must have at least one triangle
@@ -172,41 +129,6 @@ for vertex_count in vertices_per_polygon:
j.append(triangle_v1_idx)
k.append(triangle_v2_idx)
# Create edge between vertices in triangle with x,y,z coordinates, coordinates per vertex is 3
coordinate_step = 3 # step per vertex
triangle_v0_global_idx = triangle_v0_idx * coordinate_step
triangle_v1_global_idx = triangle_v1_idx * coordinate_step
triangle_v2_global_idx = triangle_v2_idx * coordinate_step
# Add x,y,z coordinates for the triangle vertices (closing triangle with 'None')
triangle_edges_x.extend(
[
polygon_vertex_array[triangle_v0_global_idx + 0],
polygon_vertex_array[triangle_v1_global_idx + 0],
polygon_vertex_array[triangle_v2_global_idx + 0],
polygon_vertex_array[triangle_v0_global_idx + 0],
None,
]
)
triangle_edges_y.extend(
[
polygon_vertex_array[triangle_v0_global_idx + 1],
polygon_vertex_array[triangle_v1_global_idx + 1],
polygon_vertex_array[triangle_v2_global_idx + 1],
polygon_vertex_array[triangle_v0_global_idx + 1],
None,
]
)
triangle_edges_z.extend(
[
polygon_vertex_array[triangle_v0_global_idx + 2],
polygon_vertex_array[triangle_v1_global_idx + 2],
polygon_vertex_array[triangle_v2_global_idx + 2],
polygon_vertex_array[triangle_v0_global_idx + 2],
None,
]
)
# Move to next polygon
polygon_v0_idx += vertex_count
@@ -214,49 +136,47 @@ for vertex_count in vertices_per_polygon:
polygon_edges_x = []
polygon_edges_y = []
polygon_edges_z = []
polygon_global_start_index = 0
coordinate_step = 3 # step per vertex
polygon_start_index = 0
for vertex_count in vertices_per_polygon:
# Must have at least a triangle
if vertex_count < 3:
polygon_global_start_index += vertex_count * coordinate_step
polygon_start_index += vertex_count
continue
for vertex_idx in range(0, vertex_count):
vertex_global_idx = polygon_global_start_index + vertex_idx * coordinate_step
polygon_edges_x.append(polygon_vertex_array[vertex_global_idx + 0])
polygon_edges_y.append(polygon_vertex_array[vertex_global_idx + 1])
polygon_edges_z.append(polygon_vertex_array[vertex_global_idx + 2])
vertex_global_idx = polygon_start_index + vertex_idx
polygon_edges_x.append(x_array[vertex_global_idx])
polygon_edges_y.append(y_array[vertex_global_idx])
polygon_edges_z.append(z_array[vertex_global_idx])
# Close the polygon
polygon_edges_x.append(polygon_vertex_array[polygon_global_start_index + 0])
polygon_edges_y.append(polygon_vertex_array[polygon_global_start_index + 1])
polygon_edges_z.append(polygon_vertex_array[polygon_global_start_index + 2])
polygon_edges_x.append(x_array[polygon_start_index])
polygon_edges_y.append(y_array[polygon_start_index])
polygon_edges_z.append(z_array[polygon_start_index])
polygon_edges_x.append(None)
polygon_edges_y.append(None)
polygon_edges_z.append(None)
polygon_global_start_index += vertex_count * coordinate_step
polygon_start_index += vertex_count
# Create mesh
mesh_3D = go.Mesh3d(
x=x, y=y, z=z, i=i, j=j, k=k, opacity=0.8, color="rgba(244,22,100,0.6)"
# Add section mesh
section_mesh_3d.append(
go.Mesh3d(
x=x_array,
y=y_array,
z=z_array,
i=i,
j=j,
k=k,
opacity=0.8,
color="rgba(244,22,100,0.6)",
)
)
# Create edge lines for triangles
triangle_edges_3d = go.Scatter3d(
x=triangle_edges_x,
y=triangle_edges_y,
z=triangle_edges_z,
mode="lines",
name="",
line=dict(color="rgb(0,0,0)", width=1),
)
# Create outer edge lines for polygon
polygon_edges_3d = go.Scatter3d(
# Add section polygon edges
section_polygon_edges_3d.append(
go.Scatter3d(
x=polygon_edges_x,
y=polygon_edges_y,
z=polygon_edges_z,
@@ -264,15 +184,12 @@ polygon_edges_3d = go.Scatter3d(
name="",
line=dict(color="rgb(0,0,0)", width=1),
)
fig = go.Figure(
data=[
mesh_3D,
# triangle_edges_3d,
polygon_edges_3d,
]
)
figure_data = section_mesh_3d + section_polygon_edges_3d
fig = go.Figure(data=figure_data)
# print(f"j array: {j_array}")
# print(f"Number of vertices: {len(vertex_array) / 3}")
# print(f"Number of traingles: {num_triangles}")

View File

@@ -13,7 +13,7 @@ from rips.generated.GridGeometryExtraction_pb2 import *
rips_instance = Instance.find()
grid_geometry_extraction_stub = GridGeometryExtractionStub(rips_instance.channel)
grid_file_name = None
grid_file_name = "MOCKED_TEST_GRID"
grid_file_name = (
"D:\\Git\\resinsight-tutorials\\model-data\\norne\\NORNE_ATW2013_RFTPLT_V2.EGRID"
)
@@ -43,7 +43,7 @@ norne_case_single_segment_poly_line_utm_xy = [457150, 7.32106e06, 456885, 7.3217
norne_case_single_segment_poly_line_gap_utm_xy = [460877, 7.3236e06, 459279, 7.32477e06]
fence_poly_line_utm_xy = norne_case_single_segment_poly_line_utm_xy
fence_poly_line_utm_xy = norne_case_fence_poly_line_utm_xy
cut_along_polyline_request = GridGeometryExtraction__pb2.CutAlongPolylineRequest(
gridFilename=grid_file_name,

View File

@@ -13,7 +13,7 @@ from rips.generated.GridGeometryExtraction_pb2 import *
rips_instance = Instance.find()
grid_geometry_extraction_stub = GridGeometryExtractionStub(rips_instance.channel)
grid_file_name = None
grid_file_name = "MOCKED_TEST_GRID"
fence_poly_line_utm_xy = [11.2631, 11.9276, 14.1083, 18.2929, 18.3523, 10.9173]
cut_along_polyline_request = GridGeometryExtraction__pb2.CutAlongPolylineRequest(

View File

@@ -9,9 +9,13 @@ from rips.generated.GridGeometryExtraction_pb2 import *
rips_instance = Instance.find()
grid_geometry_extraction_stub = GridGeometryExtractionStub(rips_instance.channel)
grid_file_name = None
grid_file_name = "MOCKED_TEST_GRID"
# grid_file_name = (
# "D:\\Git\\resinsight-tutorials\\model-data\\norne\\NORNE_ATW2013_RFTPLT_V2.EGRID"
# )
ijk_index_filter = GridGeometryExtraction__pb2.IJKIndexFilter(
iMin=0, iMax=1, jMin=1, jMax=3, kMin=0, kMax=3
iMin=0, iMax=1, jMin=1, jMax=3, kMin=3, kMax=3
)
# ijk_index_filter = None

View File

@@ -181,14 +181,12 @@ grpc::Status RiaGrpcGridGeometryExtractionService::CutAlongPolyline( grpc::Serve
}
// Convert polyline to vector of cvf::Vec3d
std::vector<cvf::Vec3d> polyline;
const double zValue = 0.0;
std::vector<cvf::Vec2d> polylineUtmXy;
for ( int i = 0; i < fencePolyline.size(); i += 2 )
{
const double xValue = fencePolyline.Get( i );
const double yValue = fencePolyline.Get( i + 1 );
cvf::Vec3d point = cvf::Vec3d( xValue, yValue, zValue );
polyline.push_back( point );
polylineUtmXy.push_back( cvf::Vec2d( xValue, yValue ) );
}
RigActiveCellInfo* activeCellInfo = nullptr; // No active cell info for grid
@@ -196,7 +194,8 @@ grpc::Status RiaGrpcGridGeometryExtractionService::CutAlongPolyline( grpc::Serve
RivEclipseIntersectionGrid* eclipseIntersectionGrid =
new RivEclipseIntersectionGrid( m_eclipseView->mainGrid(), activeCellInfo, showInactiveCells );
auto* polylineIntersectionGenerator = new RivPolylineIntersectionGeometryGenerator( polyline, eclipseIntersectionGrid );
auto* polylineIntersectionGenerator =
new RivPolylineIntersectionGeometryGenerator( polylineUtmXy, eclipseIntersectionGrid );
// Handle cell visibilities
const int firstTimeStep = 0;
@@ -238,11 +237,22 @@ grpc::Status RiaGrpcGridGeometryExtractionService::CutAlongPolyline( grpc::Serve
endUtmXY->set_y( segment.endUtmXY.y() );
fenceMeshSection->set_allocated_endutmxy( endUtmXY );
// Fill the vertext array
for ( const auto& vertex : segment.vertexArrayUZ )
// Fill the vertext array with coordinates
for ( const auto& coord : segment.vertexArrayUZ )
{
fenceMeshSection->add_vertexarrayuz( vertex.x() );
fenceMeshSection->add_vertexarrayuz( vertex.y() );
fenceMeshSection->add_vertexarrayuz( coord );
}
// Fill vertices per polygon array
for ( const auto& verticesPerPolygon : segment.verticesPerPolygon )
{
fenceMeshSection->add_verticesperpolygonarr( static_cast<google::protobuf::uint32>( verticesPerPolygon ) );
}
// Fill polygon indices array
for ( const auto& polygonIndex : segment.polygonIndices )
{
fenceMeshSection->add_polyindicesarr( static_cast<google::protobuf::uint32>( polygonIndex ) );
}
// Fill the source cell indices array
@@ -252,7 +262,8 @@ grpc::Status RiaGrpcGridGeometryExtractionService::CutAlongPolyline( grpc::Serve
}
}
// Add test response
// Add temporary test response
{
rips::PolylineTestResponse* polylineTestResponse = new rips::PolylineTestResponse;
// Polygon vertices
@@ -284,6 +295,7 @@ grpc::Status RiaGrpcGridGeometryExtractionService::CutAlongPolyline( grpc::Serve
}
response->set_allocated_polylinetestresponse( polylineTestResponse );
}
return grpc::Status::OK;
}