Open Inventor Release 2024.2.0
 
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
138class INVENTORMEDICAL_API MedicalHelper {
139public:
140
143 enum Axis {
145 AXIAL = 2,
147 TRANSVERSE = 2,
149 CORONAL = 1,
151 SAGITTAL = 0
152 };
153
197 const SoVolumeData* volume = NULL, float slack = 1.01 );
198
222 static SbBool dicomAdjustVolume( SoVolumeData* volume, SbBool useImagePosition = TRUE );
223
244 static SbBool dicomAdjustVolume( SoVolumeData* volume, SoMatrixTransform* imgToPatient );
245
252 static SbBool dicomAdjustDataRange( SoDataRange* rangeNode, const SoVolumeData* volume );
253
271 SbBool forceReverse = FALSE );
272
284 static SbBool dicomGetImagePosition( const SoVolumeData* volume, SbVec3f& imagePos );
285
298 static SbBool dicomGetWindowCenterWidth( const SoVolumeData* volume, SbVec2f& winCW );
299
304
309 static SbBool dicomSetWindowCenterWidth( SoDataRange* dataRange, const SbVec2f& winCW );
310
335 static int dicomFindFilesbySeries( const SbString& firstFile, std::vector<SbString>& files );
336
342 static int dicomFindFilesbySeries( const SbString& firstFile, SbStringList& files );
343
370 static void dollyZoom( float value, SoCamera* camera );
371
378 static SbBool setFilenameList( SoVRDicomFileReader& reader, const std::vector<SbString>& list );
379
384 SbVec3f getVoxelSize( const SoVolumeData* volume ) const;
385
390 SbVec3f getPhysicalSize( const SoVolumeData* volume ) const;
391
401 SbVec3f getDicomOrigin( const SoVolumeData* volume ) const;
402
412
423 static SoSeparator* buildSliceScaleBars( const SoCamera* camera );
424
435 const SoOrthoSlice* sliceNode,
436 const SbString* dicomFilename );
437
441 static const SbVec2s& exampleWindowSize();
442
450
456 static SoNode* exampleDicomAnnotation( const SbString& filename );
457
511
524
535
547 static openinventor::inventor::Axis::Type ViewAxisFromMedicalAxis(Axis medicalAxis, const SbMatrix& orientationMatrix);
548
549 //------------------------------------------------------------------------------
551 template <typename NodeType>
552 static NodeType*
553 find(SoNode* root, const SbString& nodeName = SbString(), const bool okIfNotFound = false)
554 {
555 if (root == NULL)
556 return NULL;
557
558 SoSearchAction* spa = NULL;
559 if (!nodeName.isEmpty())
560 {
561 spa = new SoSearchPathAction;
562 ((SoSearchPathAction*)spa)->setSearchString(nodeName.getString());
563 }
564 else
565 {
566 spa = new SoSearchAction;
567 }
568 spa->setSearchingAll(TRUE);
569 spa->setType(NodeType::getClassTypeId());
570
571 // Make sure the action doesn't destroy this node...
572 // Do not unref until _after_ the action is destroyed!
573 // Apply() will ref and unref, but root will also be ref'd by the resulting SoPath.
574 root->ref();
575 spa->apply(root);
576
577 if (spa->getPath() == NULL)
578 {
579 delete spa;
580 if (!okIfNotFound)
581 std::cerr << "Cannot find \"" << nodeName << "\" of type \"" << NodeType::getClassTypeId().getName() << "\" in scene graph." << std::endl;
582 return NULL;
583 }
584
585 NodeType* node = dynamic_cast<NodeType*>(spa->getPath()->getTail());
586 if (node == NULL)
587 {
588 delete spa;
589 if (!okIfNotFound)
590 std::cerr << "Cannot find \"" << nodeName << "\" of type \"" << NodeType::getClassTypeId().getName() << "\" in scene graph." << std::endl;
591 return NULL;
592 }
593
594 delete spa; // This will also destroy the SoPath, which will unref 'root'.
595 root->unrefNoDelete(); // Finally, remove our safety ref from 'root'
596 return node;
597 }
598
599 //------------------------------------------------------------------------------
601 template <typename NodeType>
602 static std::vector<NodeType*>findNodes(SoNode* scene)
603 {
605 sa->setType(NodeType::getClassTypeId());
607
608 scene->ref(); // Make sure action does not destroy this node...
609 sa->apply(scene);
610 scene->unrefNoDelete();
611
612 std::vector<NodeType*> ret;
613
614 const SoPathList& path = sa->getPaths();
615 if (path.getLength() == 0)
616 {
617 std::cerr << NodeType::getClassTypeId().getName().getString() << " not found" << std::endl;
618 return ret;
619 }
620
621 for (int i = 0; i < path.getLength(); i++)
622 ret.push_back(dynamic_cast<NodeType*>(path[i]->getTail()));
623
624 delete sa;
625
626 return ret;
627 }
628
629#if defined(__DIALOGVIZLIB)
630 //------------------------------------------------------------------------------
636 template <typename NodeType>
637 static NodeType*
638 find(SoTopLevelDialog* root, const SbString& auditorId = SbString(), bool exitIfNotFound = true)
639 {
640 if (root == NULL)
641 return NULL;
642
643 NodeType* node = dynamic_cast<NodeType*>(root->searchForAuditorId(auditorId));
644 if (node == NULL)
645 {
646 std::cerr << "Cannot find " << auditorId << " of type " << NodeType::getClassTypeId().getName() << " in interface." << std::endl;
647 if (exitIfNotFound)
648 exit(1);
649 }
650
651 return node;
652 }
653#endif /* __DIALOGVIZLIB */
654
655 //------------------------------------------------------------------------------
660
661 //------------------------------------------------------------------------------
664 static SoSeparator* createCube(const SbBox3f& bbox);
665
666 //------------------------------------------------------------------------------
669 static SoSeparator* createBoundingBox(const SbBox3f& bbox, SbColor* color = NULL);
670
671 //------------------------------------------------------------------------------
674 static SoSeparator* readFile(const char *filename);
675
676#if defined(__DIALOGVIZLIB)
677 //------------------------------------------------------------------------------
683 template<typename WidgetType>
684 static WidgetType
685 buildInterface(WidgetType window, const char* filename, const char* viewerName, SoTopLevelDialog** topLevelDialog)
686 {
687 SoInput myInput;
688 if (!myInput.openFile(filename))
689 return NULL;
690
691 SoGroup *myGroup = SoDB::readAll(&myInput);
692 myInput.closeFile();
693 if (!myGroup)
694 return NULL;
695
696 *topLevelDialog = (SoTopLevelDialog *)myGroup->getChild(0);
697
698 SoDialogCustom *customNode = (SoDialogCustom *)(*topLevelDialog)->searchForAuditorId(SbString(viewerName));
699
700 (*topLevelDialog)->buildDialog(window, customNode != NULL);
701 (*topLevelDialog)->show();
702
703 return customNode ? customNode->getWidget() : window;
704 }
705#endif /* __DIALOGVIZLIB */
706};
707
708#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 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.
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