Open Inventor Release 2024.1.3
 
Loading...
Searching...
No Matches
MedicalHelper.h
1// Open Inventor Medical Helper functions
2
4//
5// This class is part of the Open Inventor Medical utility library.
6//
7// The medical utility classes are provided as a prebuilt library named
8// "fei_inventor_medical", that can be used directly in an Open Inventor
9// application. The classes in the prebuilt library are documented and
10// supported by Thermo Fisher Scientific. These classes are also provided as source code.
11//
12// Please see $OIVHOME/include/Medical/InventorMedical.h for the full text.
13//
15
16#ifndef _INVENTOR_MEDICAL_HELPER_H_
17#define _INVENTOR_MEDICAL_HELPER_H_
18
19#include <Medical/InventorMedical.h>
20#include <Inventor/nodes/SoNode.h>
21#include <Inventor/actions/SoSearchPathAction.h>
22
23// SoDialogViz.h must be included before this file in order for
24// DialogViz-related functions to be available.
25// This is to avoid linking DialogViz with the Medical library
26// so that the user code can decide which DialogViz library to use
27// with their application.
28#if defined(__DIALOGVIZLIB)
29#include <DialogViz/dialog/SoTopLevelDialog.h>
30#include <DialogViz/dialog/SoDialogCustom.h>
31#endif
32
33#include <Inventor/Axis.h>
34
35#include <Inventor/STL/vector>
36
37class SoCamera;
38class SoDataRange;
40class SoImageDataAdapter;
41class SoMemoryDataAdapter;
42class SoOrthoSlice;
44class SoVolumeData;
47
146class INVENTORMEDICAL_API MedicalHelper {
147public:
148
151 enum Axis {
153 AXIAL = 2,
155 TRANSVERSE = 2,
157 CORONAL = 1,
159 SAGITTAL = 0
160 };
161
205 const SoVolumeData* volume = NULL, float slack = 1.01 );
206
230 static SbBool dicomAdjustVolume( SoVolumeData* volume, SbBool useImagePosition = TRUE );
231
252 static SbBool dicomAdjustVolume( SoVolumeData* volume, SoMatrixTransform* imgToPatient );
253
260 static SbBool dicomAdjustDataRange( SoDataRange* rangeNode, const SoVolumeData* volume );
261
279 SbBool forceReverse = FALSE );
280
292 static SbBool dicomGetImagePosition( const SoVolumeData* volume, SbVec3f& imagePos );
293
306 static SbBool dicomGetWindowCenterWidth( const SoVolumeData* volume, SbVec2f& winCW );
307
312
317 static SbBool dicomSetWindowCenterWidth( SoDataRange* dataRange, const SbVec2f& winCW );
318
343 static int dicomFindFilesbySeries( const SbString& firstFile, std::vector<SbString>& files );
344
350 static int dicomFindFilesbySeries( const SbString& firstFile, SbStringList& files );
351
378 static void dollyZoom( float value, SoCamera* camera );
379
386 static SbBool setFilenameList( SoVRDicomFileReader& reader, const std::vector<SbString>& list );
387
392 SbVec3f getVoxelSize( const SoVolumeData* volume ) const;
393
398 SbVec3f getPhysicalSize( const SoVolumeData* volume ) const;
399
409 SbVec3f getDicomOrigin( const SoVolumeData* volume ) const;
410
434 static SoMemoryDataAdapter* getImageDataAdapter( const SoVolumeData* volume );
435
450 static SoVolumeData* getVolumeData( const SoImageDataAdapter* adapter );
451
461
472 static SoSeparator* buildSliceScaleBars( const SoCamera* camera );
473
484 const SoOrthoSlice* sliceNode,
485 const SbString* dicomFilename );
486
490 static const SbVec2s& exampleWindowSize();
491
499
505 static SoNode* exampleDicomAnnotation( const SbString& filename );
506
560
573
584
596 static openinventor::inventor::Axis::Type ViewAxisFromMedicalAxis(Axis medicalAxis, const SbMatrix& orientationMatrix);
597
598 //------------------------------------------------------------------------------
600 template <typename NodeType>
601 static NodeType*
602 find(SoNode* root, const SbString& nodeName = SbString(), const bool okIfNotFound = false)
603 {
604 if (root == NULL)
605 return NULL;
606
607 SoSearchAction* spa = NULL;
608 if (!nodeName.isEmpty())
609 {
610 spa = new SoSearchPathAction;
611 ((SoSearchPathAction*)spa)->setSearchString(nodeName.getString());
612 }
613 else
614 {
615 spa = new SoSearchAction;
616 }
617 spa->setSearchingAll(TRUE);
618 spa->setType(NodeType::getClassTypeId());
619
620 // Make sure the action doesn't destroy this node...
621 // Do not unref until _after_ the action is destroyed!
622 // Apply() will ref and unref, but root will also be ref'd by the resulting SoPath.
623 root->ref();
624 spa->apply(root);
625
626 if (spa->getPath() == NULL)
627 {
628 delete spa;
629 if (!okIfNotFound)
630 std::cerr << "Cannot find \"" << nodeName << "\" of type \"" << NodeType::getClassTypeId().getName() << "\" in scene graph." << std::endl;
631 return NULL;
632 }
633
634 NodeType* node = dynamic_cast<NodeType*>(spa->getPath()->getTail());
635 if (node == NULL)
636 {
637 delete spa;
638 if (!okIfNotFound)
639 std::cerr << "Cannot find \"" << nodeName << "\" of type \"" << NodeType::getClassTypeId().getName() << "\" in scene graph." << std::endl;
640 return NULL;
641 }
642
643 delete spa; // This will also destroy the SoPath, which will unref 'root'.
644 root->unrefNoDelete(); // Finally, remove our safety ref from 'root'
645 return node;
646 }
647
648 //------------------------------------------------------------------------------
650 template <typename NodeType>
651 static std::vector<NodeType*>findNodes(SoNode* scene)
652 {
654 sa->setType(NodeType::getClassTypeId());
656
657 scene->ref(); // Make sure action does not destroy this node...
658 sa->apply(scene);
659 scene->unrefNoDelete();
660
661 std::vector<NodeType*> ret;
662
663 const SoPathList& path = sa->getPaths();
664 if (path.getLength() == 0)
665 {
666 std::cerr << NodeType::getClassTypeId().getName().getString() << " not found" << std::endl;
667 return ret;
668 }
669
670 for (int i = 0; i < path.getLength(); i++)
671 ret.push_back(dynamic_cast<NodeType*>(path[i]->getTail()));
672
673 delete sa;
674
675 return ret;
676 }
677
678#if defined(__DIALOGVIZLIB)
679 //------------------------------------------------------------------------------
685 template <typename NodeType>
686 static NodeType*
687 find(SoTopLevelDialog* root, const SbString& auditorId = SbString(), bool exitIfNotFound = true)
688 {
689 if (root == NULL)
690 return NULL;
691
692 NodeType* node = dynamic_cast<NodeType*>(root->searchForAuditorId(auditorId));
693 if (node == NULL)
694 {
695 std::cerr << "Cannot find " << auditorId << " of type " << NodeType::getClassTypeId().getName() << " in interface." << std::endl;
696 if (exitIfNotFound)
697 exit(1);
698 }
699
700 return node;
701 }
702#endif /* __DIALOGVIZLIB */
703
704 //------------------------------------------------------------------------------
709
710 //------------------------------------------------------------------------------
713 static SoSeparator* createCube(const SbBox3f& bbox);
714
715 //------------------------------------------------------------------------------
718 static SoSeparator* createBoundingBox(const SbBox3f& bbox, SbColor* color = NULL);
719
720 //------------------------------------------------------------------------------
723 static SoSeparator* readFile(const char *filename);
724
725#if defined(__DIALOGVIZLIB)
726 //------------------------------------------------------------------------------
732 template<typename WidgetType>
733 static WidgetType
734 buildInterface(WidgetType window, const char* filename, const char* viewerName, SoTopLevelDialog** topLevelDialog)
735 {
736 SoInput myInput;
737 if (!myInput.openFile(filename))
738 return NULL;
739
740 SoGroup *myGroup = SoDB::readAll(&myInput);
741 myInput.closeFile();
742 if (!myGroup)
743 return NULL;
744
745 *topLevelDialog = (SoTopLevelDialog *)myGroup->getChild(0);
746
747 SoDialogCustom *customNode = (SoDialogCustom *)(*topLevelDialog)->searchForAuditorId(SbString(viewerName));
748
749 (*topLevelDialog)->buildDialog(window, customNode != NULL);
750 (*topLevelDialog)->show();
751
752 return customNode ? customNode->getWidget() : window;
753 }
754#endif /* __DIALOGVIZLIB */
755};
756
757#endif
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> (Preview feature...
static Axis MedicalAxisFromViewAxis(openinventor::inventor::Axis::Type viewAxis, const SoVolumeData *volData)
Returns the medical axis (AXIAL, CORONAL, SAGITTAL) corresponding to the specified view axis (X,...
static SoNode * exampleLogoNode()
Returns a logo image node for Open Inventor medical examples.
static SoSeparator * buildSliceOrientationMarkers(const SoOrthoSlice *orthoSlice)
Build a scene graph to display slice orientation markers.
static SbBool dicomGetWindowCenterWidth(const SoVolumeData *volume, SbVec2f &winCW)
Get the window center (level) and width values from a DICOM volume.
static SoSeparator * readFile(const char *filename)
Convenience function to read a .iv file and return pointer to the root of the created scenegraph.
static Axis MedicalAxisFromViewAxis(openinventor::inventor::Axis::Type viewAxis, const SbMatrix &orientationMatrix)
Returns the medical axis (AXIAL, CORONAL, SAGITTAL) corresponding to the specified view axis (X,...
static int dicomFindFilesbySeries(const SbString &firstFile, std::vector< SbString > &files)
Get files in DICOM series.
SbVec3f getDicomOrigin(const SoVolumeData *volume) const
Returns the DICOM volume origin in 3D space.
static NodeType * find(SoNode *root, const SbString &nodeName=SbString(), const bool okIfNotFound=false)
Convenience function to find first specified node in specified scene graph.
static openinventor::inventor::Axis::Type ViewAxisFromMedicalAxis(Axis medicalAxis, const SoVolumeData *volData)
Returns the view axis (X, Y, Z) corresponding to the specified medical axis (AXIAL,...
static SbBool dicomAdjustVolume(SoVolumeData *volume, SbBool useImagePosition=TRUE)
Optimize volume data node for DICOM volumes.
static int dicomFindFilesbySeries(const SbString &firstFile, SbStringList &files)
Get files in DICOM series.
static SoVolumeData * getVolumeData(const SoImageDataAdapter *adapter)
Make an ImageViz data set available in VolumeViz.
static SbBool orientView(MedicalHelper::Axis axis, SoCamera *camera, const SoVolumeData *volume=NULL, float slack=1.01)
Orient view.
static SoNode * exampleDicomAnnotation(const SbString &filename)
Returns a collection of DicomInfo annotation nodes for Open Inventor medical examples.
static SbBool dicomCheckMonochrome1(SoTransferFunction *cmapNode, const SoVolumeData *volume, SbBool forceReverse=FALSE)
Automatically adjusts the color map (transferFunction) if the specified volume is a DICOM data set (r...
static void dollyZoom(float value, SoCamera *camera)
Make the scene appear larger or smaller.
static SbBool setFilenameList(SoVRDicomFileReader &reader, const std::vector< SbString > &list)
Set filename list using a list of strings (file names).
static SoSeparator * createCube(const SbBox3f &bbox)
Convenience function to draw a cube representing the specified bounding box.
Axis
Medical axis names.
static std::vector< NodeType * > findNodes(SoNode *scene)
Convenience function to find all node of specified type in specified graph.
static SbBool dicomSetWindowCenterWidth(SoDataRange *dataRange, const SbVec2f &winCW)
Set an SoDataRange node from the window center (level) and width values.
SbVec3f getVoxelSize(const SoVolumeData *volume) const
Returns the voxel size in 3D space.
static SoSeparator * createBoundingBox(const SbBox3f &bbox, SbColor *color=NULL)
Convenience function to draw a wireframe box representing the specified bounding box.
static const SbVec2s & exampleWindowSize()
Returns standard window size for Open Inventor medical examples.
static openinventor::inventor::Axis::Type ViewAxisFromMedicalAxis(Axis medicalAxis, const SbMatrix &orientationMatrix)
Returns the view axis (X, Y, Z) corresponding to the specified medical axis (AXIAL,...
static SbBool dicomGetImagePosition(const SoVolumeData *volume, SbVec3f &imagePos)
Get the "Image Position (Patient)" attribute (0020,0032) from a DICOM volume.
static SoSeparator * buildSliceAnnotation(const SoCamera *camera, const SoOrthoSlice *sliceNode, const SbString *dicomFilename)
Slice viewer annotations.
static SoSeparator * buildSliceScaleBars(const SoCamera *camera)
Build a scene graph to display dynamic scale bars for slice viewing.
static SbBool dicomAdjustDataRange(SoDataRange *rangeNode, const SoVolumeData *volume)
Adjust data range based on values in the DICOM file, i.e.
static SbVec2f dicomGetWindowCenterWidth(const SoDataRange *dataRange)
Get the window center (level) and width values from an SoDataRange node.
static SbBool dicomAdjustVolume(SoVolumeData *volume, SoMatrixTransform *imgToPatient)
Similar to dicomAdjustVolume( SoVolumeData*, SbBool ) above but returns an SoMatrixTransform that can...
SbVec3f getPhysicalSize(const SoVolumeData *volume) const
Returns the volume's physical size in 3D space.
static SbBox3f getBoundingBox(SoNode *node)
Convenience function to retrieve bounding box of specified node.
static SoMemoryDataAdapter * getImageDataAdapter(const SoVolumeData *volume)
Make a VolumeViz data set available in ImageViz.
3D box class.
Definition SbBox.h:649
Color vector class.
Definition SbColor.h:82
4x4 matrix class.
Definition SbMatrix.h:309
int getLength() const
Returns number of pointers in list.
Definition SbPList.h:125
Class for smart character strings.
Definition SbString.h:202
Maintains a list of pointers to SbString instances.
2D vector class.
Definition SbVec.h:76
2D vector class.
Definition SbVec.h:700
3D vector class.
Definition SbVec.h:932
virtual void apply(SoNode *node)
Initiates an action on the graph defined by a node.
Abstract base class for camera nodes.
Definition SoCamera.h:188
static SoSeparator * readAll(SoInput *in)
Reads all graphs and paths from the file specified by the given SoInput.
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Range of...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Dialog Custom no...
SoWidget getWidget()
Returns the custom base widget.
Base class for all group nodes.
Definition SoGroup.h:122
virtual SoNode * getChild(int index) const
Returns pointer the child node with the given index.
Image background node.
Used to read Open Inventor data files.
Definition SoInput.h:363
virtual SoNONUNICODE SbBool openFile(const char *fileName, SbBool okIfNotFound=FALSE, SbBool aSync=FALSE)
Opens named file, sets file pointer to result.
virtual void closeFile()
Closes all files on stack opened with openFile() or pushFile().
Node that specifies a 3D geometric transformation as a matrix.
Abstract base class for all database nodes.
Definition SoNode.h:145
<a href="IconLegend.html"><img src="extVR.gif" alt="VolumeViz" border="0"></a> Ortho slice shape nod...
SoNode * getTail() const
Returns the last node in a path chain.
Maintains a list of pointers to paths.
Definition SoPathList.h:81
void unrefNoDelete() const
unrefNoDelete() should be called when it is desired to decrement the reference count,...
void ref() const
Adds a reference to an instance.
Searches for nodes in a scene graph.
void setType(SoType t, SbBool derivedIsOk=TRUE)
Sets the node type to search for.
@ ALL
Return all paths found.
SoPathList & getPaths()
Returns resulting path list.
SoPath * getPath() const
Returns resulting path, or NULL if no path was found.
const SbName & getName() const
Returns the name of the node to search for.
void setInterest(Interest i)
Sets which paths to return.
void setSearchingAll(SbBool flag)
Sets whether searching uses regular traversal or whether it traverses every single node.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Searches for a n...
void setSearchString(const char *searchString)
Sets the search path string.
Group node that saves and restores traversal state.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Top Level Dialog...
SoDialogViz * searchForAuditorId(SbString id)
Retrieves the DialogViz object from the specified auditorID field in an SoTopLevelDialog structure.
<a href="IconLegend.html"><img src="extLDM.gif" alt="Large Data Management" border="0"></a> Describe...
<a href="IconLegend.html"><img src="extVR.gif" alt="VolumeViz" border="0"></a> DICOM file reader.
<a href="IconLegend.html"><img src="extVR.gif" alt="VolumeViz" border="0"></a> Volume data property ...
Type
Specification of either an X, a Y or a Z axis.
Definition Axis.h:51
int SbBool
Boolean type.
Definition SbBase.h:87