Skip to content

Commit

Permalink
Initial testing of GetGridSurface with mocked data
Browse files Browse the repository at this point in the history
  • Loading branch information
jorgenherje committed Feb 19, 2024
1 parent a8e1c8e commit 9eec4e6
Show file tree
Hide file tree
Showing 15 changed files with 396 additions and 25 deletions.
15 changes: 15 additions & 0 deletions Fwk/AppFwk/CommonCode/cvfStructGridGeometryGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,21 @@ ref<DrawableGeo> StructGridGeometryGenerator::generateSurface()
return geo;
}

//--------------------------------------------------------------------------------------------------
///
//--------------------------------------------------------------------------------------------------
cvf::ref<cvf::Vec3fArray> StructGridGeometryGenerator::getOrCreateVertices()
{
if ( m_vertices.isNull() || m_vertices->size() == 0 )
{
computeArrays();
}

CVF_ASSERT( m_vertices.notNull() );

return m_vertices;
}

//--------------------------------------------------------------------------------------------------
/// Generates simplified mesh as line drawing
/// Must call generateSurface first
Expand Down
2 changes: 2 additions & 0 deletions Fwk/AppFwk/CommonCode/cvfStructGridGeometryGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ class StructGridGeometryGenerator : public Object
ref<DrawableGeo> createMeshDrawable();
ref<DrawableGeo> createOutlineMeshDrawable( double creaseAngle );

cvf::ref<cvf::Vec3fArray> getOrCreateVertices();

static ref<DrawableGeo> createMeshDrawableFromSingleCell( const StructGridInterface* grid, size_t cellIndex );

static ref<DrawableGeo> createMeshDrawableFromSingleCell( const StructGridInterface* grid,
Expand Down
20 changes: 18 additions & 2 deletions GrpcInterface/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ set(SOURCE_GROUP_HEADER_FILES
RiaGrpcNNCPropertiesService.h
RiaGrpcPdmObjectService.h
RiaGrpcApplicationInterface.h
RiaGrpcGridGeometryExtractionService.h
)

set(SOURCE_GROUP_SOURCE_FILES
Expand All @@ -64,7 +65,9 @@ set(SOURCE_GROUP_SOURCE_FILES
RiaGrpcPropertiesService.cpp
RiaGrpcNNCPropertiesService.cpp
RiaGrpcPdmObjectService.cpp
RiaGrpcApplicationInterface.cpp)
RiaGrpcApplicationInterface.cpp
RiaGrpcGridGeometryExtractionService.cpp
)

# Find Protobuf installation Looks for protobuf-config.cmake file installed by
# Protobuf's cmake installation.
Expand Down Expand Up @@ -136,7 +139,20 @@ set(_LINK_LIBRARIES
ApplicationLibCode)

# Proto files
file(GLOB GRPC_PROTO_FILES GrpcProtos/*.proto)
set(GRPC_PROTO_FILES
${CMAKE_CURRENT_SOURCE_DIR}/GrpcProtos/App.proto
${CMAKE_CURRENT_SOURCE_DIR}/GrpcProtos/Case.proto
${CMAKE_CURRENT_SOURCE_DIR}/GrpcProtos/Commands.proto
${CMAKE_CURRENT_SOURCE_DIR}/GrpcProtos/Definitions.proto
${CMAKE_CURRENT_SOURCE_DIR}/GrpcProtos/Grid.proto
${CMAKE_CURRENT_SOURCE_DIR}/GrpcProtos/GridGeometryExtraction.proto
${CMAKE_CURRENT_SOURCE_DIR}/GrpcProtos/NNCProperties.proto
${CMAKE_CURRENT_SOURCE_DIR}/GrpcProtos/PdmObject.proto
${CMAKE_CURRENT_SOURCE_DIR}/GrpcProtos/Project.proto
${CMAKE_CURRENT_SOURCE_DIR}/GrpcProtos/Properties.proto
${CMAKE_CURRENT_SOURCE_DIR}/GrpcProtos/SimulationWell.proto
${CMAKE_CURRENT_SOURCE_DIR}/GrpcProtos/VectorDefines.proto
)

set(GRPC_PYTHON_SOURCE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/Python")

Expand Down
1 change: 1 addition & 0 deletions GrpcInterface/GrpcProtos/Case.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";

import "PdmObject.proto";
import "Definitions.proto";
import "VectorDefines.proto";

package rips;

Expand Down
14 changes: 2 additions & 12 deletions GrpcInterface/GrpcProtos/Definitions.proto
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
syntax = "proto3";

import "VectorDefines.proto";

package rips;

message Empty
Expand All @@ -11,18 +13,6 @@ message ClientToServerStreamReply
int64 accepted_value_count = 1;
}

message Vec3i {
int32 i = 1;
int32 j = 2;
int32 k = 3;
}

message Vec3d
{
double x = 1;
double y = 2;
double z = 3;
}

message CellCenters
{
Expand Down
1 change: 1 addition & 0 deletions GrpcInterface/GrpcProtos/Grid.proto
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ syntax = "proto3";
package rips;

import "Definitions.proto";
import "VectorDefines.proto";
import "Case.proto";

service Grid
Expand Down
76 changes: 76 additions & 0 deletions GrpcInterface/GrpcProtos/GridGeometryExtraction.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
syntax = "proto3";

import "Grid.proto";
import "VectorDefines.proto";

// Will this work if we import only part of the protos?
package rips;

service GridGeometryExtraction
{
rpc GetGridSurface(GetGridSurfaceRequest) returns (GetGridSurfaceResponse);
rpc CutAlongPolyline(CutAlongPolylineRequest) returns (CutAlongPolylineResponse);
}

message IJKIndexFilter
{
int32 iMin = 1;
int32 iMax = 2;
int32 jMin = 3;
int32 jMax = 4;
int32 kMin = 5;
int32 kMax = 6;
}

message CellIndexFilter
{
repeated fixed32 cellIndicesArr = 1;
}

message PropertyFilter
{
// Timestep ??
string propertyFilename = 1;
float valueMin = 2;
float valueMax = 3;
}

message GetGridSurfaceRequest
{
string gridFilename = 1;
IJKIndexFilter ijkIndexFilter = 2;
CellIndexFilter cellIndexFilter = 3;
PropertyFilter propertyFilter = 4;
}

message GetGridSurfaceResponse
{
repeated float vertexArray = 1;
repeated fixed32 quadIndicesArr = 2; // 4*NumQuads long
repeated fixed32 sourceCellIndicesArr = 3; // The originating cell index per quad, longnumQuads long
GridDimensions gridDimensions = 5;
Vec3d originUtm = 6;
}

message CutAlongPolylineRequest
{
string gridFilename = 1;
repeated double fencePolylineUtmXY = 2;
}

message FenceMeshSection
{
// U-axis defined by vector from start to end, Z is global Z
repeated float vertexArrayUZ = 1;
repeated fixed32 polyIndicesArr = 2;
repeated fixed32 verticesPerPolygonArr = 3; // Number of vertices per polygon, numPolygons long
repeated fixed32 sourceCellIndicesArr = 4; // The originating cell index per polygon, numPolygons long
Vec2d startUtmXY = 6;
Vec2d endUtmXY = 7;
}

message CutAlongPolylineResponse
{
repeated FenceMeshSection feceMeshSections = 1;
GridDimensions gridDimensions = 2;
}
8 changes: 0 additions & 8 deletions GrpcInterface/GrpcProtos/GridWebviz.proto

This file was deleted.

1 change: 1 addition & 0 deletions GrpcInterface/GrpcProtos/NNCProperties.proto
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ syntax = "proto3";

import "Case.proto";
import "Definitions.proto";
import "VectorDefines.proto";

package rips;

Expand Down
1 change: 1 addition & 0 deletions GrpcInterface/GrpcProtos/SimulationWell.proto
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
syntax = "proto3";

import "Definitions.proto";
import "VectorDefines.proto";

package rips;

Expand Down
22 changes: 22 additions & 0 deletions GrpcInterface/GrpcProtos/VectorDefines.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
syntax = "proto3";

package rips;

message Vec3i {
int32 i = 1;
int32 j = 2;
int32 k = 3;
}

message Vec2d
{
double x = 1;
double y = 2;
}

message Vec3d
{
double x = 1;
double y = 2;
double z = 3;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import sys
import os

import numpy as np

import plotly.graph_objects as go

sys.path.insert(1, os.path.join(sys.path[0], "../"))

from rips.instance import *
from rips.generated.GridGeometryExtraction_pb2_grpc import *
from rips.generated.GridGeometryExtraction_pb2 import *

rips_instance = Instance.find()
grid_geometry_extraction_stub = GridGeometryExtractionStub(rips_instance.channel)

get_grid_surface_request = GridGeometryExtraction__pb2.GetGridSurfaceRequest(gridFilename=None, ijkIndexFilter=None,cellIndexFilter=None,propertyFilter=None)
get_grid_surface_response: GridGeometryExtraction__pb2.GetGridSurfaceResponse = grid_geometry_extraction_stub.GetGridSurface(get_grid_surface_request)

get_grid_surface_response.gridDimensions
vertex_array = get_grid_surface_response.vertexArray
quad_indices_array = get_grid_surface_response.quadIndicesArr

num_vertex_coords = 3 # [x, y, z]
num_vertices_per_quad = 4 # [v1, v2, v3, v4]
num_quads = len(vertex_array) /(num_vertex_coords * num_vertices_per_quad)

x_array = []
y_array = []
z_array = []

# Create x-, y-, and z-arrays
for i in range(0, len(vertex_array), num_vertex_coords):
x_array.append(vertex_array[i])
y_array.append(vertex_array[i+1])
z_array.append(vertex_array[i+2])

# Create triangular mesh
i_array = []
j_array = []
k_array = []
for i in range(0, len(quad_indices_array), num_vertices_per_quad):
# Set the indices of the vertices of the triangles
i_array.extend([i, i])
j_array.extend([i+1, i+2])
k_array.extend([i+2, i+3])



fig = go.Figure(data=[go.Mesh3d(
x=x_array,
y=y_array,
z=z_array,
i=i_array,
j=j_array,
k=k_array,
intensity = np.linspace(-5, 5, 1000, endpoint=True),
showscale=True,
colorscale=[[0, 'gold'],[0.5, 'mediumturquoise'],[1.0, 'magenta']]
)])

print(fig.data)

fig.show()

6 changes: 3 additions & 3 deletions GrpcInterface/Python/rips/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Case_pb2
import Grid_pb2
import Grid_pb2_grpc
import Definitions_pb2
import VectorDefines_pb2

from typing import Tuple, Optional, List
from grpc import Channel
Expand All @@ -30,7 +30,7 @@ def __init__(self, index: int, case: Case, channel: Channel) -> None:
self.index: int = index
self.cached_dimensions = None

def dimensions(self) -> Optional[Definitions_pb2.Vec3i]:
def dimensions(self) -> Optional[VectorDefines_pb2.Vec3i]:
"""The dimensions in i, j, k direction
Returns:
Expand Down Expand Up @@ -58,7 +58,7 @@ def cell_centers_async(self):
for chunk in chunks:
yield chunk

def cell_centers(self) -> List[Definitions_pb2.Vec3d]:
def cell_centers(self) -> List[VectorDefines_pb2.Vec3d]:
"""The cell center for all cells in given grid
Returns:
Expand Down
Loading

0 comments on commit 9eec4e6

Please sign in to comment.