@@ -477,7 +477,7 @@ def __create_cc_viewmat() -> "Matrix44":
477477 - -8 degrees around z-axis
478478 3. Adds a small translation for better centering
479479 """
480- from whippersnappy . gl . views import ViewType , get_view_matrix
480+ from whippersnappy import ViewType , get_view_matrix
481481
482482 if not HAS_PYRR :
483483 raise ImportError ("Pyrr not installed, install pyrr with `pip install pyrr`." )
@@ -511,12 +511,14 @@ def snap_cc_picture(
511511 ----------
512512 output_path : Path, str
513513 Path where to save the snapshot image.
514- ref_header : Path, str, nibabelImage , optional
515- Path to reference image to use for tkr creation. If None, ignores the file for saving.
514+ ref_header : Path, str, nibabelHeader , optional
515+ Path to reference image header to use for tkr creation. If None, ignores the file for saving.
516516
517517 Raises
518518 ------
519- Warning
519+ ImportError
520+ If whippersnappy is not installed or if the version is too old.
521+ ValueError
520522 If the mesh has no faces and cannot create a snapshot.
521523 """
522524 from packaging .version import parse
@@ -539,20 +541,26 @@ def snap_cc_picture(
539541 )
540542 # Skip snapshot if there are no faces
541543 if len (self .t ) == 0 :
542- logger .warning ("Cannot create snapshot - no faces in mesh" )
543- return
544+ raise ValueError ("Cannot create snapshot - no faces in mesh" )
544545
545546 self .__make_parent_folder (output_path )
546547
547- if ref_header is not None :
548- v = apply_affine (ref_header .get_vox2ras_tkr (), self .v )
549- else :
548+ if ref_header is None :
550549 v = self .v
550+ else :
551+ from nibabel .freesurfer .mghformat import MGHHeader
552+
553+ # if header is a file, load its header from the file
554+ if isinstance (ref_header , (str , Path )):
555+ ref_header = nib .load (ref_header ).header
556+ # if header is not already an MGHHeader, convert it to MGHHeader, so we have the get_vox2ras_tkr function
557+ mgh_header = ref_header if isinstance (ref_header , MGHHeader ) else MGHHeader .from_header (ref_header )
558+ v = apply_affine (mgh_header .get_vox2ras_tkr (), self .v )
559+
551560 whippersnappy .snap1 (
552561 mesh = (v , self .t ),
553562 overlay = self .mesh_vertex_colors ,
554- view = None ,
555- viewmat = self .__create_cc_viewmat (),
563+ view = self .__create_cc_viewmat (),
556564 width = 3 * 500 ,
557565 height = 3 * 300 ,
558566 outpath = str (output_path ),
0 commit comments