Skip to content

Commit bcb9395

Browse files
pshriwiseGuySten
andauthored
SolidRayTracePlot CAPI (#3789)
Co-authored-by: GuySten <62616591+GuySten@users.noreply.github.com>
1 parent b145fdd commit bcb9395

7 files changed

Lines changed: 1402 additions & 28 deletions

File tree

docs/source/capi/index.rst

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,279 @@ Functions
580580
:return: Return status (negative if an error occurs)
581581
:rtype: int
582582
583+
.. c:function:: int openmc_get_plot_index(int32_t id, int32_t* index)
584+
585+
Get the index in the plots array for a plot with a given ID.
586+
587+
:param int32_t id: Plot ID
588+
:param int32_t* index: Index in the plots array
589+
:return: Return status (negative if an error occurred)
590+
:rtype: int
591+
592+
.. c:function:: int openmc_plot_get_id(int32_t index, int32_t* id)
593+
594+
Get the ID of a plot.
595+
596+
:param int32_t index: Index in the plots array
597+
:param int32_t* id: Plot ID
598+
:return: Return status (negative if an error occurred)
599+
:rtype: int
600+
601+
.. c:function:: int openmc_plot_set_id(int32_t index, int32_t id)
602+
603+
Set the ID of a plot.
604+
605+
:param int32_t index: Index in the plots array
606+
:param int32_t id: Plot ID
607+
:return: Return status (negative if an error occurred)
608+
:rtype: int
609+
610+
.. c:function:: size_t openmc_plots_size()
611+
612+
Number of plots currently allocated.
613+
614+
:return: Number of plots in the plots array
615+
:rtype: size_t
616+
617+
.. c:function:: int openmc_solidraytrace_plot_create(int32_t* index)
618+
619+
Create a new solid raytrace plot.
620+
621+
:param int32_t* index: Index of the newly created plot
622+
:return: Return status (negative if an error occurred)
623+
:rtype: int
624+
625+
.. c:function:: int openmc_solidraytrace_plot_get_pixels(int32_t index, int32_t* width, int32_t* height)
626+
627+
Get output pixel dimensions for a solid raytrace plot.
628+
629+
:param int32_t index: Index in the plots array
630+
:param int32_t* width: Image width in pixels
631+
:param int32_t* height: Image height in pixels
632+
:return: Return status (negative if an error occurred)
633+
:rtype: int
634+
635+
.. c:function:: int openmc_solidraytrace_plot_set_pixels(int32_t index, int32_t width, int32_t height)
636+
637+
Set output pixel dimensions for a solid raytrace plot.
638+
639+
:param int32_t index: Index in the plots array
640+
:param int32_t width: Image width in pixels
641+
:param int32_t height: Image height in pixels
642+
:return: Return status (negative if an error occurred)
643+
:rtype: int
644+
645+
.. c:function:: int openmc_solidraytrace_plot_get_color_by(int32_t index, int32_t* color_by)
646+
647+
Get the domain type used for coloring (0=materials, 1=cells).
648+
649+
:param int32_t index: Index in the plots array
650+
:param int32_t* color_by: Coloring mode
651+
:return: Return status (negative if an error occurred)
652+
:rtype: int
653+
654+
.. c:function:: int openmc_solidraytrace_plot_set_color_by(int32_t index, int32_t color_by)
655+
656+
Set the domain type used for coloring (0=materials, 1=cells).
657+
658+
:param int32_t index: Index in the plots array
659+
:param int32_t color_by: Coloring mode
660+
:return: Return status (negative if an error occurred)
661+
:rtype: int
662+
663+
.. c:function:: int openmc_solidraytrace_plot_set_default_colors(int32_t index)
664+
665+
Set default random colors for the current ``color_by`` mode.
666+
667+
:param int32_t index: Index in the plots array
668+
:return: Return status (negative if an error occurred)
669+
:rtype: int
670+
671+
.. c:function:: int openmc_solidraytrace_plot_set_all_opaque(int32_t index)
672+
673+
Mark all domains in the current ``color_by`` mode as opaque.
674+
675+
:param int32_t index: Index in the plots array
676+
:return: Return status (negative if an error occurred)
677+
:rtype: int
678+
679+
.. c:function:: int openmc_solidraytrace_plot_set_opaque(int32_t index, int32_t id, bool visible)
680+
681+
Set whether a specific domain ID is opaque (visible) in the rendered image.
682+
683+
:param int32_t index: Index in the plots array
684+
:param int32_t id: Cell/material ID (based on ``color_by``)
685+
:param bool visible: Whether the domain is opaque
686+
:return: Return status (negative if an error occurred)
687+
:rtype: int
688+
689+
.. c:function:: int openmc_solidraytrace_plot_set_color(int32_t index, int32_t id, uint8_t r, uint8_t g, uint8_t b)
690+
691+
Set RGB color for a specific domain ID.
692+
693+
:param int32_t index: Index in the plots array
694+
:param int32_t id: Cell/material ID (based on ``color_by``)
695+
:param uint8_t r: Red channel
696+
:param uint8_t g: Green channel
697+
:param uint8_t b: Blue channel
698+
:return: Return status (negative if an error occurred)
699+
:rtype: int
700+
701+
.. c:function:: int openmc_solidraytrace_plot_get_color(int32_t index, int32_t id, uint8_t* r, uint8_t* g, uint8_t* b)
702+
703+
Get RGB color for a specific domain ID.
704+
705+
:param int32_t index: Index in the plots array
706+
:param int32_t id: Cell/material ID (based on ``color_by``)
707+
:param uint8_t* r: Red channel
708+
:param uint8_t* g: Green channel
709+
:param uint8_t* b: Blue channel
710+
:return: Return status (negative if an error occurred)
711+
:rtype: int
712+
713+
.. c:function:: int openmc_solidraytrace_plot_get_camera_position(int32_t index, double* x, double* y, double* z)
714+
715+
Get camera position.
716+
717+
:param int32_t index: Index in the plots array
718+
:param double* x: X coordinate
719+
:param double* y: Y coordinate
720+
:param double* z: Z coordinate
721+
:return: Return status (negative if an error occurred)
722+
:rtype: int
723+
724+
.. c:function:: int openmc_solidraytrace_plot_set_camera_position(int32_t index, double x, double y, double z)
725+
726+
Set camera position.
727+
728+
:param int32_t index: Index in the plots array
729+
:param double x: X coordinate
730+
:param double y: Y coordinate
731+
:param double z: Z coordinate
732+
:return: Return status (negative if an error occurred)
733+
:rtype: int
734+
735+
.. c:function:: int openmc_solidraytrace_plot_get_look_at(int32_t index, double* x, double* y, double* z)
736+
737+
Get camera target point.
738+
739+
:param int32_t index: Index in the plots array
740+
:param double* x: X coordinate
741+
:param double* y: Y coordinate
742+
:param double* z: Z coordinate
743+
:return: Return status (negative if an error occurred)
744+
:rtype: int
745+
746+
.. c:function:: int openmc_solidraytrace_plot_set_look_at(int32_t index, double x, double y, double z)
747+
748+
Set camera target point.
749+
750+
:param int32_t index: Index in the plots array
751+
:param double x: X coordinate
752+
:param double y: Y coordinate
753+
:param double z: Z coordinate
754+
:return: Return status (negative if an error occurred)
755+
:rtype: int
756+
757+
.. c:function:: int openmc_solidraytrace_plot_get_up(int32_t index, double* x, double* y, double* z)
758+
759+
Get the camera up vector.
760+
761+
:param int32_t index: Index in the plots array
762+
:param double* x: X component
763+
:param double* y: Y component
764+
:param double* z: Z component
765+
:return: Return status (negative if an error occurred)
766+
:rtype: int
767+
768+
.. c:function:: int openmc_solidraytrace_plot_set_up(int32_t index, double x, double y, double z)
769+
770+
Set the camera up vector.
771+
772+
:param int32_t index: Index in the plots array
773+
:param double x: X component
774+
:param double y: Y component
775+
:param double z: Z component
776+
:return: Return status (negative if an error occurred)
777+
:rtype: int
778+
779+
.. c:function:: int openmc_solidraytrace_plot_get_light_position(int32_t index, double* x, double* y, double* z)
780+
781+
Get light source position.
782+
783+
:param int32_t index: Index in the plots array
784+
:param double* x: X coordinate
785+
:param double* y: Y coordinate
786+
:param double* z: Z coordinate
787+
:return: Return status (negative if an error occurred)
788+
:rtype: int
789+
790+
.. c:function:: int openmc_solidraytrace_plot_set_light_position(int32_t index, double x, double y, double z)
791+
792+
Set light source position.
793+
794+
:param int32_t index: Index in the plots array
795+
:param double x: X coordinate
796+
:param double y: Y coordinate
797+
:param double z: Z coordinate
798+
:return: Return status (negative if an error occurred)
799+
:rtype: int
800+
801+
.. c:function:: int openmc_solidraytrace_plot_get_fov(int32_t index, double* fov)
802+
803+
Get horizontal field of view in degrees.
804+
805+
:param int32_t index: Index in the plots array
806+
:param double* fov: Field of view in degrees
807+
:return: Return status (negative if an error occurred)
808+
:rtype: int
809+
810+
.. c:function:: int openmc_solidraytrace_plot_set_fov(int32_t index, double fov)
811+
812+
Set horizontal field of view in degrees.
813+
814+
:param int32_t index: Index in the plots array
815+
:param double fov: Field of view in degrees
816+
:return: Return status (negative if an error occurred)
817+
:rtype: int
818+
819+
.. c:function:: int openmc_solidraytrace_plot_get_diffuse_fraction(int32_t index, double* diffuse_fraction)
820+
821+
Get diffuse-light fraction.
822+
823+
:param int32_t index: Index in the plots array
824+
:param double* diffuse_fraction: Diffuse fraction in [0, 1]
825+
:return: Return status (negative if an error occurred)
826+
:rtype: int
827+
828+
.. c:function:: int openmc_solidraytrace_plot_set_diffuse_fraction(int32_t index, double diffuse_fraction)
829+
830+
Set diffuse-light fraction.
831+
832+
:param int32_t index: Index in the plots array
833+
:param double diffuse_fraction: Diffuse fraction in [0, 1]
834+
:return: Return status (negative if an error occurred)
835+
:rtype: int
836+
837+
.. c:function:: int openmc_solidraytrace_plot_update_view(int32_t index)
838+
839+
Recompute internal camera/view transforms after camera changes.
840+
841+
:param int32_t index: Index in the plots array
842+
:return: Return status (negative if an error occurred)
843+
:rtype: int
844+
845+
.. c:function:: int openmc_solidraytrace_plot_create_image(int32_t index, uint8_t* data_out, int32_t width, int32_t height)
846+
847+
Render the plot to an RGB image buffer.
848+
849+
:param int32_t index: Index in the plots array
850+
:param uint8_t* data_out: Output buffer of shape ``height*width*3``
851+
:param int32_t width: Image width in pixels
852+
:param int32_t height: Image height in pixels
853+
:return: Return status (negative if an error occurred)
854+
:rtype: int
855+
583856
.. c:function:: int openmc_reset()
584857
585858
Resets all tally scores

docs/source/pythonapi/capi.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ Classes
8888
SpatialLegendreFilter
8989
SphericalHarmonicsFilter
9090
SphericalMesh
91+
SolidRayTracePlot
9192
SurfaceFilter
9293
Tally
9394
TemporarySession
@@ -125,6 +126,12 @@ Data
125126

126127
:type: dict
127128

129+
.. data:: plots
130+
131+
Mapping of plot ID to :class:`openmc.lib.SolidRayTracePlot` instances.
132+
133+
:type: dict
134+
128135
.. data:: nuclides
129136

130137
Mapping of nuclide name to :class:`openmc.lib.Nuclide` instances.

include/openmc/capi.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,49 @@ int openmc_nuclide_name(int index, const char** name);
125125
int openmc_plot_geometry();
126126
int openmc_id_map(const void* slice, int32_t* data_out);
127127
int openmc_property_map(const void* slice, double* data_out);
128+
int openmc_get_plot_index(int32_t id, int32_t* index);
129+
int openmc_plot_get_id(int32_t index, int32_t* id);
130+
int openmc_plot_set_id(int32_t index, int32_t id);
131+
int openmc_solidraytrace_plot_create(int32_t* index);
132+
int openmc_solidraytrace_plot_get_pixels(
133+
int32_t index, int32_t* width, int32_t* height);
134+
int openmc_solidraytrace_plot_set_pixels(
135+
int32_t index, int32_t width, int32_t height);
136+
int openmc_solidraytrace_plot_get_color_by(int32_t index, int32_t* color_by);
137+
int openmc_solidraytrace_plot_set_color_by(int32_t index, int32_t color_by);
138+
int openmc_solidraytrace_plot_set_default_colors(int32_t index);
139+
int openmc_solidraytrace_plot_set_all_opaque(int32_t index);
140+
int openmc_solidraytrace_plot_set_opaque(
141+
int32_t index, int32_t id, bool visible);
142+
int openmc_solidraytrace_plot_set_color(
143+
int32_t index, int32_t id, uint8_t r, uint8_t g, uint8_t b);
144+
int openmc_solidraytrace_plot_get_camera_position(
145+
int32_t index, double* x, double* y, double* z);
146+
int openmc_solidraytrace_plot_set_camera_position(
147+
int32_t index, double x, double y, double z);
148+
int openmc_solidraytrace_plot_get_look_at(
149+
int32_t index, double* x, double* y, double* z);
150+
int openmc_solidraytrace_plot_set_look_at(
151+
int32_t index, double x, double y, double z);
152+
int openmc_solidraytrace_plot_get_up(
153+
int32_t index, double* x, double* y, double* z);
154+
int openmc_solidraytrace_plot_set_up(
155+
int32_t index, double x, double y, double z);
156+
int openmc_solidraytrace_plot_get_light_position(
157+
int32_t index, double* x, double* y, double* z);
158+
int openmc_solidraytrace_plot_set_light_position(
159+
int32_t index, double x, double y, double z);
160+
int openmc_solidraytrace_plot_get_fov(int32_t index, double* fov);
161+
int openmc_solidraytrace_plot_set_fov(int32_t index, double fov);
162+
int openmc_solidraytrace_plot_update_view(int32_t index);
163+
int openmc_solidraytrace_plot_create_image(
164+
int32_t index, uint8_t* data_out, int32_t width, int32_t height);
165+
int openmc_solidraytrace_plot_get_color(
166+
int32_t index, int32_t id, uint8_t* r, uint8_t* g, uint8_t* b);
167+
int openmc_solidraytrace_plot_get_diffuse_fraction(
168+
int32_t index, double* diffuse_fraction);
169+
int openmc_solidraytrace_plot_set_diffuse_fraction(
170+
int32_t index, double diffuse_fraction);
128171
int openmc_rectilinear_mesh_get_grid(int32_t index, double** grid_x, int* nx,
129172
double** grid_y, int* ny, double** grid_z, int* nz);
130173
int openmc_rectilinear_mesh_set_grid(int32_t index, const double* grid_x,
@@ -219,6 +262,7 @@ int openmc_weight_windows_set_weight_cutoff(int32_t index, double cutoff);
219262
int openmc_weight_windows_get_max_split(int32_t index, int* max_split);
220263
int openmc_weight_windows_set_max_split(int32_t index, int max_split);
221264
size_t openmc_weight_windows_size();
265+
size_t openmc_plots_size();
222266
int openmc_weight_windows_export(const char* filename = nullptr);
223267
int openmc_weight_windows_import(const char* filename = nullptr);
224268
int openmc_zernike_filter_get_order(int32_t index, int* order);

0 commit comments

Comments
 (0)