Skip to content

Commit f0f36fb

Browse files
committed
Add dvr.replicate
1 parent f9296e7 commit f0f36fb

7 files changed

Lines changed: 99 additions & 64 deletions

File tree

examples/cells.ipynb

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"id": "59e8a2c3",
1717
"metadata": {
1818
"execution": {
19-
"iopub.execute_input": "2025-05-06T11:09:07.871228Z",
20-
"iopub.status.busy": "2025-05-06T11:09:07.870789Z",
21-
"iopub.status.idle": "2025-05-06T11:09:08.283035Z",
22-
"shell.execute_reply": "2025-05-06T11:09:08.282708Z"
19+
"iopub.execute_input": "2025-05-06T12:53:52.433387Z",
20+
"iopub.status.busy": "2025-05-06T12:53:52.433284Z",
21+
"iopub.status.idle": "2025-05-06T12:53:52.838642Z",
22+
"shell.execute_reply": "2025-05-06T12:53:52.838256Z"
2323
},
2424
"vscode": {
2525
"languageId": "plaintext"
@@ -45,10 +45,10 @@
4545
"id": "97c2c4ed",
4646
"metadata": {
4747
"execution": {
48-
"iopub.execute_input": "2025-05-06T11:09:08.285447Z",
49-
"iopub.status.busy": "2025-05-06T11:09:08.285288Z",
50-
"iopub.status.idle": "2025-05-06T11:09:08.354286Z",
51-
"shell.execute_reply": "2025-05-06T11:09:08.353835Z"
48+
"iopub.execute_input": "2025-05-06T12:53:52.840419Z",
49+
"iopub.status.busy": "2025-05-06T12:53:52.840251Z",
50+
"iopub.status.idle": "2025-05-06T12:53:52.908551Z",
51+
"shell.execute_reply": "2025-05-06T12:53:52.908213Z"
5252
},
5353
"vscode": {
5454
"languageId": "plaintext"
@@ -90,10 +90,10 @@
9090
"id": "ed16156a",
9191
"metadata": {
9292
"execution": {
93-
"iopub.execute_input": "2025-05-06T11:09:08.356977Z",
94-
"iopub.status.busy": "2025-05-06T11:09:08.356805Z",
95-
"iopub.status.idle": "2025-05-06T11:09:09.280148Z",
96-
"shell.execute_reply": "2025-05-06T11:09:09.279613Z"
93+
"iopub.execute_input": "2025-05-06T12:53:52.909905Z",
94+
"iopub.status.busy": "2025-05-06T12:53:52.909639Z",
95+
"iopub.status.idle": "2025-05-06T12:53:53.802389Z",
96+
"shell.execute_reply": "2025-05-06T12:53:53.802016Z"
9797
},
9898
"vscode": {
9999
"languageId": "plaintext"
@@ -158,10 +158,10 @@
158158
"id": "d35452de",
159159
"metadata": {
160160
"execution": {
161-
"iopub.execute_input": "2025-05-06T11:09:09.281688Z",
162-
"iopub.status.busy": "2025-05-06T11:09:09.281581Z",
163-
"iopub.status.idle": "2025-05-06T11:09:09.752165Z",
164-
"shell.execute_reply": "2025-05-06T11:09:09.751618Z"
161+
"iopub.execute_input": "2025-05-06T12:53:53.803620Z",
162+
"iopub.status.busy": "2025-05-06T12:53:53.803512Z",
163+
"iopub.status.idle": "2025-05-06T12:53:54.175648Z",
164+
"shell.execute_reply": "2025-05-06T12:53:54.175188Z"
165165
},
166166
"vscode": {
167167
"languageId": "plaintext"
@@ -210,10 +210,10 @@
210210
"id": "c33d38bc",
211211
"metadata": {
212212
"execution": {
213-
"iopub.execute_input": "2025-05-06T11:09:09.754113Z",
214-
"iopub.status.busy": "2025-05-06T11:09:09.754004Z",
215-
"iopub.status.idle": "2025-05-06T11:09:09.759556Z",
216-
"shell.execute_reply": "2025-05-06T11:09:09.759080Z"
213+
"iopub.execute_input": "2025-05-06T12:53:54.177667Z",
214+
"iopub.status.busy": "2025-05-06T12:53:54.177557Z",
215+
"iopub.status.idle": "2025-05-06T12:53:54.182771Z",
216+
"shell.execute_reply": "2025-05-06T12:53:54.182383Z"
217217
},
218218
"vscode": {
219219
"languageId": "plaintext"
@@ -240,10 +240,10 @@
240240
"id": "ea6ed2dd",
241241
"metadata": {
242242
"execution": {
243-
"iopub.execute_input": "2025-05-06T11:09:09.760904Z",
244-
"iopub.status.busy": "2025-05-06T11:09:09.760797Z",
245-
"iopub.status.idle": "2025-05-06T11:09:10.215679Z",
246-
"shell.execute_reply": "2025-05-06T11:09:10.215145Z"
243+
"iopub.execute_input": "2025-05-06T12:53:54.183812Z",
244+
"iopub.status.busy": "2025-05-06T12:53:54.183709Z",
245+
"iopub.status.idle": "2025-05-06T12:53:54.637973Z",
246+
"shell.execute_reply": "2025-05-06T12:53:54.637524Z"
247247
},
248248
"vscode": {
249249
"languageId": "plaintext"
@@ -304,10 +304,10 @@
304304
"id": "b00a9d85",
305305
"metadata": {
306306
"execution": {
307-
"iopub.execute_input": "2025-05-06T11:09:10.218461Z",
308-
"iopub.status.busy": "2025-05-06T11:09:10.218352Z",
309-
"iopub.status.idle": "2025-05-06T11:09:10.778906Z",
310-
"shell.execute_reply": "2025-05-06T11:09:10.778475Z"
307+
"iopub.execute_input": "2025-05-06T12:53:54.639078Z",
308+
"iopub.status.busy": "2025-05-06T12:53:54.638962Z",
309+
"iopub.status.idle": "2025-05-06T12:53:55.175731Z",
310+
"shell.execute_reply": "2025-05-06T12:53:55.175281Z"
311311
},
312312
"vscode": {
313313
"languageId": "plaintext"

examples/cthead.ipynb

Lines changed: 27 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@
1616
"id": "94b5ef80",
1717
"metadata": {
1818
"execution": {
19-
"iopub.execute_input": "2025-05-06T11:09:12.363669Z",
20-
"iopub.status.busy": "2025-05-06T11:09:12.363256Z",
21-
"iopub.status.idle": "2025-05-06T11:09:12.785727Z",
22-
"shell.execute_reply": "2025-05-06T11:09:12.785241Z"
19+
"iopub.execute_input": "2025-05-06T12:53:56.722433Z",
20+
"iopub.status.busy": "2025-05-06T12:53:56.722333Z",
21+
"iopub.status.idle": "2025-05-06T12:53:57.143081Z",
22+
"shell.execute_reply": "2025-05-06T12:53:57.142695Z"
2323
},
2424
"vscode": {
2525
"languageId": "plaintext"
@@ -51,10 +51,10 @@
5151
"id": "1ee080d3",
5252
"metadata": {
5353
"execution": {
54-
"iopub.execute_input": "2025-05-06T11:09:12.787635Z",
55-
"iopub.status.busy": "2025-05-06T11:09:12.787464Z",
56-
"iopub.status.idle": "2025-05-06T11:09:12.910468Z",
57-
"shell.execute_reply": "2025-05-06T11:09:12.910032Z"
54+
"iopub.execute_input": "2025-05-06T12:53:57.144813Z",
55+
"iopub.status.busy": "2025-05-06T12:53:57.144650Z",
56+
"iopub.status.idle": "2025-05-06T12:53:57.270116Z",
57+
"shell.execute_reply": "2025-05-06T12:53:57.269740Z"
5858
},
5959
"vscode": {
6060
"languageId": "plaintext"
@@ -112,10 +112,10 @@
112112
"id": "7af5a922",
113113
"metadata": {
114114
"execution": {
115-
"iopub.execute_input": "2025-05-06T11:09:12.911688Z",
116-
"iopub.status.busy": "2025-05-06T11:09:12.911456Z",
117-
"iopub.status.idle": "2025-05-06T11:09:13.839195Z",
118-
"shell.execute_reply": "2025-05-06T11:09:13.838833Z"
115+
"iopub.execute_input": "2025-05-06T12:53:57.271162Z",
116+
"iopub.status.busy": "2025-05-06T12:53:57.271023Z",
117+
"iopub.status.idle": "2025-05-06T12:53:58.218631Z",
118+
"shell.execute_reply": "2025-05-06T12:53:58.218128Z"
119119
},
120120
"vscode": {
121121
"languageId": "plaintext"
@@ -180,10 +180,10 @@
180180
"id": "493f1153",
181181
"metadata": {
182182
"execution": {
183-
"iopub.execute_input": "2025-05-06T11:09:13.840368Z",
184-
"iopub.status.busy": "2025-05-06T11:09:13.840261Z",
185-
"iopub.status.idle": "2025-05-06T11:09:14.331764Z",
186-
"shell.execute_reply": "2025-05-06T11:09:14.331288Z"
183+
"iopub.execute_input": "2025-05-06T12:53:58.220264Z",
184+
"iopub.status.busy": "2025-05-06T12:53:58.220096Z",
185+
"iopub.status.idle": "2025-05-06T12:53:58.718057Z",
186+
"shell.execute_reply": "2025-05-06T12:53:58.717598Z"
187187
},
188188
"vscode": {
189189
"languageId": "plaintext"
@@ -234,10 +234,10 @@
234234
"id": "6e7f236c",
235235
"metadata": {
236236
"execution": {
237-
"iopub.execute_input": "2025-05-06T11:09:14.333216Z",
238-
"iopub.status.busy": "2025-05-06T11:09:14.332889Z",
239-
"iopub.status.idle": "2025-05-06T11:09:15.152651Z",
240-
"shell.execute_reply": "2025-05-06T11:09:15.152181Z"
237+
"iopub.execute_input": "2025-05-06T12:53:58.720462Z",
238+
"iopub.status.busy": "2025-05-06T12:53:58.720352Z",
239+
"iopub.status.idle": "2025-05-06T12:53:59.537730Z",
240+
"shell.execute_reply": "2025-05-06T12:53:59.537278Z"
241241
},
242242
"vscode": {
243243
"languageId": "plaintext"
@@ -293,14 +293,14 @@
293293
},
294294
{
295295
"cell_type": "code",
296-
"execution_count": 7,
296+
"execution_count": null,
297297
"id": "696c040a",
298298
"metadata": {
299299
"execution": {
300-
"iopub.execute_input": "2025-05-06T11:09:15.209816Z",
301-
"iopub.status.busy": "2025-05-06T11:09:15.209472Z",
302-
"iopub.status.idle": "2025-05-06T11:09:15.959127Z",
303-
"shell.execute_reply": "2025-05-06T11:09:15.958621Z"
300+
"iopub.execute_input": "2025-05-06T12:53:59.539558Z",
301+
"iopub.status.busy": "2025-05-06T12:53:59.539448Z",
302+
"iopub.status.idle": "2025-05-06T12:54:00.377743Z",
303+
"shell.execute_reply": "2025-05-06T12:54:00.377291Z"
304304
},
305305
"vscode": {
306306
"languageId": "plaintext"
@@ -316,7 +316,7 @@
316316
"<IPython.core.display.HTML object>"
317317
]
318318
},
319-
"execution_count": 7,
319+
"execution_count": 6,
320320
"metadata": {},
321321
"output_type": "execute_result"
322322
}
@@ -351,19 +351,13 @@
351351
" },\n",
352352
")\n",
353353
"\n",
354-
"# Render the scene\n",
355-
"dvr = libcarna.dvr(\n",
356-
" GEOMETRY_TYPE_VOLUME, sr=800, transl=1, diffuse=0.8,\n",
357-
")\n",
358-
"dvr.cmap.BrBG(ramp=0.5, rampdegree=2)\n",
359-
"\n",
360354
"libcarna.imshow(\n",
361355
" libcarna.animate(\n",
362356
" libcarna.animate.rotate_local(camera),\n",
363357
" n_frames=100,\n",
364358
" ).render(\n",
365359
" libcarna.renderer(600, 450, [\n",
366-
" dvr,\n",
360+
" dvr.replicate(),\n",
367361
" libcarna.opaque(GEOMETRY_TYPE_OPAQUE),\n",
368362
" ]),\n",
369363
" camera,\n",

misc/libcarna/_color_map_helper.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def _mpl_colormaps() -> Iterable[str]:
2727

2828
class color_map_helper:
2929

30-
def __init__(self, color_map: libcarna.base.ColorMap, cmap: str | None = None, default_n_samples: int = 50):
30+
def __init__(self, color_map: libcarna.base.ColorMap, cmap: str | libcarna.base.ColorMap | None = None, default_n_samples: int = 50):
3131
self.color_map = color_map
3232
self.cmap_choices = list()
3333
cmap = cmap or 'viridis'
@@ -45,7 +45,9 @@ def cmap_func(**kwargs):
4545
self.cmap_choices.append(cmap_name)
4646

4747
# Set the requested colormap
48-
if cmap in self.cmap_choices:
48+
if isinstance(cmap, libcarna.base.ColorMap):
49+
self.color_map.set(cmap)
50+
elif cmap in self.cmap_choices:
4951
getattr(self, cmap)()
5052
else:
5153
raise ValueError(f'Unknown color map: "{cmap}" (available: {", ".join(self.cmap_choices)})')

misc/libcarna/_dvr.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class dvr(libcarna.presets.DVRStage):
2222
def __init__(
2323
self,
2424
*args,
25-
cmap: str | None = None,
25+
cmap: str | libcarna.base.ColorMap | None = None,
2626
sr: int = libcarna.presets.VolumeRenderingStage.DEFAULT_SAMPLE_RATE,
2727
transl: float = libcarna.presets.DVRStage.DEFAULT_TRANSLUCENCY,
2828
diffuse: float = libcarna.presets.DVRStage.DEFAULT_DIFFUSE_LIGHT,
@@ -33,3 +33,15 @@ def __init__(
3333
self.sample_rate = sr
3434
self.translucency = transl
3535
self.diffuse_light = diffuse
36+
37+
def replicate(self):
38+
"""
39+
Replicate the DVR stage.
40+
"""
41+
return dvr(
42+
self.geometry_type,
43+
cmap=self.cmap.color_map,
44+
sr=self.sample_rate,
45+
transl=self.translucency,
46+
diffuse=self.diffuse_light,
47+
)

src/include/LibCarna/py/presets.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ class OpaqueRenderingStageView : public LibCarna::py::base::MeshRenderingStageVi
2828

2929
explicit OpaqueRenderingStageView( unsigned int geometryType );
3030

31+
LibCarna::presets::OpaqueRenderingStage& opaqueRenderingStage();
32+
3133
}; // OpaqueRenderingStageView
3234

3335

src/py/base.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,13 @@ PYBIND11_MODULE( base, m )
589589
.def_property_readonly(
590590
"color_list",
591591
VIEW_DELEGATE( ColorMapView, colorMap.getColorList() )
592+
)
593+
.def( "set",
594+
VIEW_DELEGATE_RETURN_SELF
595+
( const std::shared_ptr< ColorMapView >
596+
, get()->colorMap = other->colorMap
597+
, const std::shared_ptr< ColorMapView >& other ),
598+
"other"_a
592599
);
593600

594601
/*

src/py/presets.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ OpaqueRenderingStageView::OpaqueRenderingStageView( unsigned int geometryType )
4848
}
4949

5050

51+
LibCarna::presets::OpaqueRenderingStage& OpaqueRenderingStageView::opaqueRenderingStage()
52+
{
53+
return static_cast< LibCarna::presets::OpaqueRenderingStage& >( *renderStage );
54+
}
55+
56+
5157

5258
// ----------------------------------------------------------------------------------
5359
// VolumeRenderingStageView
@@ -182,6 +188,9 @@ PYBIND11_MODULE( presets, m )
182188
m, "OpaqueRenderingStage"
183189
)
184190
.def( py::init< unsigned int >(), "geometry_type"_a )
191+
.def_property_readonly( "geometry_type",
192+
VIEW_DELEGATE( OpaqueRenderingStageView, opaqueRenderingStage().LibCarna::base::MeshRenderingMixin::geometryType )
193+
)
185194
.doc() = R"(Renders *opaque meshes* in the scene.
186195
187196
.. literalinclude:: ../test/test_integration.py
@@ -200,6 +209,9 @@ PYBIND11_MODULE( presets, m )
200209
m, "VolumeRenderingStage"
201210
)
202211
.def_readonly_static( "DEFAULT_SAMPLE_RATE", &VolumeRenderingStageView::DEFAULT_SAMPLE_RATE )
212+
.def_property_readonly( "geometry_type",
213+
VIEW_DELEGATE( VolumeRenderingStageView, volumeRenderingStage().geometryType )
214+
)
203215
.def_property( "sample_rate",
204216
VIEW_DELEGATE( VolumeRenderingStageView, volumeRenderingStage().sampleRate() ),
205217
VIEW_DELEGATE( VolumeRenderingStageView, volumeRenderingStage().setSampleRate( sampleRate ), unsigned int sampleRate )
@@ -272,6 +284,12 @@ PYBIND11_MODULE( presets, m )
272284
.def_readonly_static( "DEFAULT_WINDOWING_WIDTH", &LibCarna::presets::CuttingPlanesStage::DEFAULT_WINDOWING_WIDTH )
273285
.def_readonly_static( "DEFAULT_WINDOWING_LEVEL", &LibCarna::presets::CuttingPlanesStage::DEFAULT_WINDOWING_LEVEL )
274286
.def( py::init< unsigned int, unsigned int >(), "volume_geometry_type"_a, "plane_geometry_type"_a )
287+
.def_property_readonly( "volume_geometry_type",
288+
VIEW_DELEGATE( CuttingPlanesStageView, cuttingPlanesStage().volumeGeometryType )
289+
)
290+
.def_property_readonly( "plane_geometry_type",
291+
VIEW_DELEGATE( CuttingPlanesStageView, cuttingPlanesStage().planeGeometryType )
292+
)
275293
.def_property(
276294
"windowing_width",
277295
VIEW_DELEGATE( CuttingPlanesStageView, cuttingPlanesStage().windowingWidth() ),

0 commit comments

Comments
 (0)