Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions apps/pythonapi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ endfunction()

copy(vapor ${PYTHON_API_DIR} EXCLUDE cmake.py __pycache__ widget.js jquery.js)
copy(setup.py ${PYTHON_API_DIR})
copy(examples ${PYTHON_API_DIR} EXCLUDE CMakeLists.txt)
add_subdirectory (examples)
copy(example_scripts ${PYTHON_API_DIR} EXCLUDE CMakeLists.txt)
add_subdirectory (example_scripts)

add_custom_command(
OUTPUT "${PYTHON_API_DIR}/vapor/widget.js"
Expand Down
122 changes: 122 additions & 0 deletions apps/pythonapi/example_scripts/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
set(ALL_NOTEBOOKS "")
set(ALL_MARIMO_NOTEBOOKS "")

function(NOTEBOOK FILE OUT)
include(CMakeParseArguments)
cmake_parse_arguments(PARSE_ARGV 2
"NOTEBOOK"
""
""
""
)

get_filename_component(FILE "${FILE}" REALPATH)

add_custom_command(
OUTPUT "${OUT}"
DEPENDS "${FILE}"
COMMAND cat "${FILE}" | jupytext --to ipynb > "${OUT}"
)

list(APPEND ALL_NOTEBOOKS "${OUT}")
set(ALL_NOTEBOOKS "${ALL_NOTEBOOKS}" PARENT_SCOPE)
endfunction()


function(CONV_MARIMO FILE OUT)
include(CMakeParseArguments)
cmake_parse_arguments(PARSE_ARGV 2
"CONV_MARIMO"
""
""
""
)

get_filename_component(FILE "${FILE}" REALPATH)

add_custom_command(
OUTPUT "${OUT}"
DEPENDS "${FILE}"
COMMAND marimo -q -y convert "${FILE}" -o "${OUT}"
)

list(APPEND ALL_MARIMO_NOTEBOOKS "${OUT}")
set(ALL_MARIMO_NOTEBOOKS "${ALL_MARIMO_NOTEBOOKS}" PARENT_SCOPE)
endfunction()


# copy(vapor ${PYTHON_API_DIR} EXCLUDE cmake.py __pycache__)
# copy(setup.py ${PYTHON_API_DIR})

find_program(JUPYTEXT "jupytext")
if (JUPYTEXT)
set(EXAMPLE_NOTEBOOK_OUT_DIR "${PYTHON_API_DIR}/example_jupyter_notebooks")
file(MAKE_DIRECTORY ${EXAMPLE_NOTEBOOK_OUT_DIR})

copy(example_utils.py ${EXAMPLE_NOTEBOOK_OUT_DIR})
notebook(numpy_example.py ${EXAMPLE_NOTEBOOK_OUT_DIR}/numpy_example.ipynb)
notebook(xarray_example.py ${EXAMPLE_NOTEBOOK_OUT_DIR}/xarray_example.ipynb)
notebook(dataset_example.py ${EXAMPLE_NOTEBOOK_OUT_DIR}/dataset_example.ipynb)
notebook(flow_example.py ${EXAMPLE_NOTEBOOK_OUT_DIR}/flow_example.ipynb)
notebook(annotation_example.py ${EXAMPLE_NOTEBOOK_OUT_DIR}/annotation_example.ipynb)
notebook(camera_example.py ${EXAMPLE_NOTEBOOK_OUT_DIR}/camera_example.ipynb)
notebook(transfer_function_example.py ${EXAMPLE_NOTEBOOK_OUT_DIR}/transfer_function_example.ipynb)
notebook(workflow_example.py ${EXAMPLE_NOTEBOOK_OUT_DIR}/workflow_example.ipynb)
notebook(animation_example.py ${EXAMPLE_NOTEBOOK_OUT_DIR}/animation_example.ipynb)
notebook(visualizer_widget_example.py ${EXAMPLE_NOTEBOOK_OUT_DIR}/visualizer_widget_example.ipynb)
notebook(rotate_video.py ${EXAMPLE_NOTEBOOK_OUT_DIR}/rotate_video.ipynb)

add_custom_target(
example_notebooks
ALL
DEPENDS ${ALL_NOTEBOOKS}
)
else()
message(WARNING "jupytext not found")
message(WARNING "Skipping generation of jupyter notebooks")
endif()

find_program(MARIMO "marimo")
if (JUPYTEXT AND MARIMO)
set(EXAMPLE_MARIMO_OUT_DIR "${PYTHON_API_DIR}/example_marimo_notebooks")
file(MAKE_DIRECTORY ${EXAMPLE_MARIMO_OUT_DIR})

copy(example_utils.py ${EXAMPLE_MARIMO_OUT_DIR})
conv_marimo(${EXAMPLE_NOTEBOOK_OUT_DIR}/numpy_example.ipynb ${EXAMPLE_MARIMO_OUT_DIR}/numpy_example.py)
conv_marimo(${EXAMPLE_NOTEBOOK_OUT_DIR}/xarray_example.ipynb ${EXAMPLE_MARIMO_OUT_DIR}/xarray_example.py)
conv_marimo(${EXAMPLE_NOTEBOOK_OUT_DIR}/dataset_example.ipynb ${EXAMPLE_MARIMO_OUT_DIR}/dataset_example.py)
conv_marimo(${EXAMPLE_NOTEBOOK_OUT_DIR}/flow_example.ipynb ${EXAMPLE_MARIMO_OUT_DIR}/flow_example.py)
conv_marimo(${EXAMPLE_NOTEBOOK_OUT_DIR}/annotation_example.ipynb ${EXAMPLE_MARIMO_OUT_DIR}/annotation_example.py)
conv_marimo(${EXAMPLE_NOTEBOOK_OUT_DIR}/camera_example.ipynb ${EXAMPLE_MARIMO_OUT_DIR}/camera_example.py)
conv_marimo(${EXAMPLE_NOTEBOOK_OUT_DIR}/transfer_function_example.ipynb ${EXAMPLE_MARIMO_OUT_DIR}/transfer_function_example.py)
conv_marimo(${EXAMPLE_NOTEBOOK_OUT_DIR}/workflow_example.ipynb ${EXAMPLE_MARIMO_OUT_DIR}/workflow_example.py)
conv_marimo(${EXAMPLE_NOTEBOOK_OUT_DIR}/animation_example.ipynb ${EXAMPLE_MARIMO_OUT_DIR}/animation_example.py)
conv_marimo(${EXAMPLE_NOTEBOOK_OUT_DIR}/visualizer_widget_example.ipynb ${EXAMPLE_MARIMO_OUT_DIR}/visualizer_widget_example.py)
conv_marimo(${EXAMPLE_NOTEBOOK_OUT_DIR}/rotate_video.ipynb ${EXAMPLE_MARIMO_OUT_DIR}/rotate_video.py)

add_custom_target(
example_marimo_notebooks
ALL
DEPENDS ${ALL_MARIMO_NOTEBOOKS}
)
else()
message(WARNING "marimo (or jupytext) not found")
message(WARNING "Skipping generation of marimo notebooks")
endif()

if (CONDA_BUILD)
set(CONDA_SITE_PACKAGE_DIR "$ENV{SP_DIR}")
install(
DIRECTORY "${PYTHON_API_DIR}/example_scripts"
DESTINATION "${CONDA_SITE_PACKAGE_DIR}/vapor"
COMPONENT Dependencies
)
if (JUPYTEXT)
install(
DIRECTORY "${EXAMPLE_NOTEBOOK_OUT_DIR}"
DESTINATION "${CONDA_SITE_PACKAGE_DIR}/vapor"
COMPONENT Dependencies
)
endif()
endif()

72 changes: 0 additions & 72 deletions apps/pythonapi/examples/CMakeLists.txt

This file was deleted.

4 changes: 2 additions & 2 deletions apps/pythonapi/vapor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
link.include('vapor/MyPython.h')
link.Wasp.MyPython.IsRunningFromPython = True

link.include('vapor/GLContextProvider.h')
ctx = link.GLContextProvider.CreateContext()
link.include('vapor/RenderManager.h')
ctx = link.RenderManager.GetOSGLContext()
print("OpenGL", ctx.GetVersion())

13 changes: 13 additions & 0 deletions apps/pythonapi/vapor/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,3 +106,16 @@ def IsRunningFromIPython():
return True
except NameError:
return False


def IsRunningFromMarimo():
try:
import marimo as mo
return mo.app_meta().mode in ("edit", "run")
except:
return False


def IsRunningFromNotebook():
return IsRunningFromIPython() or IsRunningFromMarimo()

4 changes: 2 additions & 2 deletions apps/pythonapi/vapor/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
@link.FixModuleOwnership
class Session(link.Session):
def __init__(self):
super().__init__()
super().__init__(True)
self.ce = super()._controlExec

def NewRenderer(self, Class:Renderer, datasetName:str) -> Renderer:
Expand Down Expand Up @@ -85,7 +85,7 @@ def Show(self):

img = self.RenderToImage()

if config.IsRunningFromIPython():
if config.IsRunningFromNotebook():
display(img)
else:
img.show()
Expand Down
1 change: 1 addition & 0 deletions conda/vapor/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ requirements:
- jupytext=1.13.8 # Generate notebooks
- doxygen=1.9.1
- esbuild
- git
# Both
# (Needs to be specified manually in both rather than just in host because otherwise conda will install multiple versions of some packages and break the install)
# ==========================================
Expand Down
1 change: 0 additions & 1 deletion lib/render/WireFrameRenderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ void WireFrameRenderer::_drawCell(const GLuint *cellNodeIndices, int n, bool lay
//
void WireFrameRenderer::_buildCacheVertices(const Grid *grid, const Grid *heightGrid, vector<GLuint> &nodeMap, bool *GPUOutOfMemory) const
{
WireFrameParams* wfp = (WireFrameParams *)GetActiveParams();
double mv = grid->GetMissingValue();
auto tmp = grid->GetDimensions();
auto dims = std::vector<size_t>{tmp[0], tmp[1], tmp[2]};
Expand Down
17 changes: 16 additions & 1 deletion lib/vapi/RenderManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@
#include <vapor/Framebuffer.h>

#include <vapor/GLInclude.h>
#include <vapor/GLContextProvider.h>

#define INCLUDE_DEPRECATED_LEGACY_VECTOR_MATH
#include <vapor/LegacyVectorMath.h>


using namespace VAPoR;

RenderManager::RenderManager(ControlExec *ce) : _controlExec(ce) {}
GLContext *RenderManager::_glContext = nullptr;


RenderManager::RenderManager(ControlExec *ce, bool useOSGLContext) : _controlExec(ce), _useOSGLContext(useOSGLContext) {}

RenderManager::~RenderManager()
{
Expand Down Expand Up @@ -193,6 +197,9 @@ void RenderManager::setUpModelViewMatrix()

int RenderManager::Render(String imagePath, bool fast)
{
if (_useOSGLContext)
GetOSGLContext()->MakeCurrent();

_controlExec->SyncWithParams();

// GL_ERR_BREAK();
Expand Down Expand Up @@ -263,4 +270,12 @@ String RenderManager::GetWinName() const
return names[0];
}

GLContext *RenderManager::GetOSGLContext()
{
if (_glContext == nullptr)
_glContext = GLContextProvider::CreateContext();
return _glContext;
}


VAPoR::ViewpointParams *RenderManager::getViewpointParams() const { return _controlExec->GetParamsMgr()->GetViewpointParams(GetWinName()); }
6 changes: 5 additions & 1 deletion lib/vapi/RenderManager.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include <vapor/VPCommon.h>
#include <vapor/GLContext.h>

//! \class RenderManager
//! \ingroup VAPI
Expand All @@ -9,14 +10,17 @@
class RenderManager {
ControlExec *_controlExec;
GLManager * _glManager = nullptr;
bool _useOSGLContext = false;
static GLContext * _glContext;

public:
RenderManager(ControlExec *ce);
RenderManager(ControlExec *ce, bool useOSGLContext = false);
~RenderManager();
int Render(String imagePath, bool fast=false);
void SetResolution(int width, int height);
vector<int> GetResolution() const;
String GetWinName() const;
static GLContext *GetOSGLContext();

private:
void getNearFarDist(const double posVec[3], const double dirVec[3], double &boxNear, double &boxFar);
Expand Down
5 changes: 3 additions & 2 deletions lib/vapi/Session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@

using namespace VAPoR;

Session::Session()
Session::Session(bool useOSGLContext)
: _useOSGLContext(useOSGLContext)
{
vector<string> myParams;
myParams.push_back(GUIStateParams::GetClassType());
Expand Down Expand Up @@ -148,7 +149,7 @@ void Session::Reset()


if (_renderManager) delete _renderManager;
_renderManager = new RenderManager(_controlExec);
_renderManager = new RenderManager(_controlExec, _useOSGLContext);

_controlExec->GetParamsMgr()->UndoRedoClear();
}
Expand Down
3 changes: 2 additions & 1 deletion lib/vapi/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,9 @@ class Session {
public:
ControlExec * _controlExec = nullptr;
RenderManager *_renderManager = nullptr;
bool _useOSGLContext = false;

Session();
Session(bool useOSGLContext = false);
virtual ~Session();
void CloseDataset(String name);
void CloseAllDatasets();
Expand Down