00001
00002
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00015
00016 #ifndef _INVENTOR_MEDICAL_HELPER_H_
00017 #define _INVENTOR_MEDICAL_HELPER_H_
00018
00019 #include <Medical/InventorMedical.h>
00020 #include <Inventor/nodes/SoNode.h>
00021 #if !defined(OIV_HEADLESS)
00022 #include <DialogViz/dialog/SoTopLevelDialog.h>
00023 #include <DialogViz/dialog/SoDialogCustom.h>
00024 #else
00025 #include <Inventor/nodes/SoMatrixTransform.h>
00026 #include <Inventor/actions/SoGetBoundingBoxAction.h>
00027 #endif
00028 #include <Inventor/actions/SoSearchPathAction.h>
00029
00030 #include <Inventor/Axis.h>
00031
00032 #include <Inventor/STL/vector>
00033
00034 class SoCamera;
00035 class SoDataRange;
00036 class SoImageBackground;
00037 class SoImageDataAdapter;
00038 class SoMemoryDataAdapter;
00039 class SoOrthoSlice;
00040 class SoTransferFunction;
00041 class SoVolumeData;
00042 class SoVRDicomFileReader;
00043
00142 class INVENTORMEDICAL_API MedicalHelper {
00143 public:
00144
00147 enum Axis {
00149 AXIAL = 2,
00151 TRANSVERSE = 2,
00153 CORONAL = 1,
00155 SAGITTAL = 0
00156 };
00157
00200 static SbBool orientView( MedicalHelper::Axis axis, SoCamera* camera,
00201 const SoVolumeData* volume = NULL, float slack = 1.01 );
00202
00226 static SbBool dicomAdjustVolume( SoVolumeData* volume, SbBool useImagePosition = TRUE );
00227
00248 static SbBool dicomAdjustVolume( SoVolumeData* volume, SoMatrixTransform* imgToPatient );
00249
00256 static SbBool dicomAdjustDataRange( SoDataRange* rangeNode, const SoVolumeData* volume );
00257
00274 static SbBool dicomCheckMonochrome1( SoTransferFunction* cmapNode, const SoVolumeData* volume,
00275 SbBool forceReverse = FALSE );
00276
00288 static SbBool dicomGetImagePosition( const SoVolumeData* volume, SbVec3f& imagePos );
00289
00302 static SbBool dicomGetWindowCenterWidth( const SoVolumeData* volume, SbVec2f& winCW );
00303
00307 static SbVec2f dicomGetWindowCenterWidth( const SoDataRange* dataRange );
00308
00313 static SbBool dicomSetWindowCenterWidth( SoDataRange* dataRange, const SbVec2f& winCW );
00314
00339 static int dicomFindFilesbySeries( const SbString& firstFile, std::vector<SbString>& files );
00340
00346 static int dicomFindFilesbySeries( const SbString& firstFile, SbStringList& files );
00347
00374 static void dollyZoom( float value, SoCamera* camera );
00375
00382 static SbBool setFilenameList( SoVRDicomFileReader& reader, const std::vector<SbString>& list );
00383
00388 SbVec3f getVoxelSize( const SoVolumeData* volume ) const;
00389
00394 SbVec3f getPhysicalSize( const SoVolumeData* volume ) const;
00395
00405 SbVec3f getDicomOrigin( const SoVolumeData* volume ) const;
00406
00430 static SoMemoryDataAdapter* getImageDataAdapter( const SoVolumeData* volume );
00431
00446 static SoVolumeData* getVolumeData( const SoImageDataAdapter* adapter );
00447
00456 static SoSeparator* buildSliceOrientationMarkers( const SoOrthoSlice* orthoSlice );
00457
00468 static SoSeparator* buildSliceScaleBars( const SoCamera* camera );
00469
00479 static SoSeparator* buildSliceAnnotation( const SoCamera* camera,
00480 const SoOrthoSlice* sliceNode,
00481 const SbString* dicomFilename );
00482
00486 static const SbVec2s& exampleWindowSize();
00487
00494 static SoNode* exampleLogoNode();
00495
00501 static SoNode* exampleDicomAnnotation( const SbString& filename );
00502
00555 static Axis MedicalAxisFromViewAxis(openinventor::inventor::Axis::Type viewAxis, const SoVolumeData* volData);
00556
00568 static Axis MedicalAxisFromViewAxis(openinventor::inventor::Axis::Type viewAxis, const SbMatrix& orientationMatrix);
00569
00579 static openinventor::inventor::Axis::Type ViewAxisFromMedicalAxis(Axis medicalAxis, const SoVolumeData* volData);
00580
00592 static openinventor::inventor::Axis::Type ViewAxisFromMedicalAxis(Axis medicalAxis, const SbMatrix& orientationMatrix);
00593
00594
00596 template <typename NodeType>
00597 static NodeType*
00598 find(SoNode* root, const SbString& nodeName = SbString(), const bool okIfNotFound = false)
00599 {
00600 if (root == NULL)
00601 return NULL;
00602
00603 SoSearchAction* spa = NULL;
00604 if (!nodeName.isEmpty())
00605 {
00606 spa = new SoSearchPathAction;
00607 ((SoSearchPathAction*)spa)->setSearchString(nodeName.getString());
00608 }
00609 else
00610 {
00611 spa = new SoSearchAction;
00612 }
00613 spa->setSearchingAll(TRUE);
00614 spa->setType(NodeType::getClassTypeId());
00615
00616
00617
00618
00619 root->ref();
00620 spa->apply(root);
00621
00622 if (spa->getPath() == NULL)
00623 {
00624 delete spa;
00625 if (!okIfNotFound)
00626 std::cerr << "Cannot find \"" << nodeName << "\" of type \"" << NodeType::getClassTypeId().getName() << "\" in scene graph." << std::endl;
00627 return NULL;
00628 }
00629
00630 NodeType* node = dynamic_cast<NodeType*>(spa->getPath()->getTail());
00631 if (node == NULL)
00632 {
00633 delete spa;
00634 if (!okIfNotFound)
00635 std::cerr << "Cannot find \"" << nodeName << "\" of type \"" << NodeType::getClassTypeId().getName() << "\" in scene graph." << std::endl;
00636 return NULL;
00637 }
00638
00639 delete spa;
00640 root->unrefNoDelete();
00641 return node;
00642 }
00643
00644
00646 template <typename NodeType>
00647 static std::vector<NodeType*>findNodes(SoNode* scene)
00648 {
00649 SoSearchAction* sa = new SoSearchAction;
00650 sa->setType(NodeType::getClassTypeId());
00651 sa->setInterest(SoSearchAction::ALL);
00652
00653 scene->ref();
00654 sa->apply(scene);
00655 scene->unrefNoDelete();
00656
00657 std::vector<NodeType*> ret;
00658
00659 const SoPathList& path = sa->getPaths();
00660 if (path.getLength() == 0)
00661 {
00662 std::cerr << NodeType::getClassTypeId().getName().getString() << " not found" << std::endl;
00663 return ret;
00664 }
00665
00666 for (int i = 0; i < path.getLength(); i++)
00667 ret.push_back(dynamic_cast<NodeType*>(path[i]->getTail()));
00668
00669 delete sa;
00670
00671 return ret;
00672 }
00673
00674
00676 #if !defined(OIV_HEADLESS)
00677 template <typename NodeType>
00678 static NodeType*
00679 find(SoTopLevelDialog* root, const SbString& auditorId = SbString(), bool exitIfNotFound = true)
00680 {
00681 if (root == NULL)
00682 return NULL;
00683
00684 NodeType* node = dynamic_cast<NodeType*>(root->searchForAuditorId(auditorId));
00685 if (node == NULL)
00686 {
00687 std::cerr << "Cannot find " << auditorId << " of type " << NodeType::getClassTypeId().getName() << " in interface." << std::endl;
00688 if (exitIfNotFound)
00689 exit(1);
00690 }
00691
00692 return node;
00693 }
00694 #endif
00695
00696
00700 static SbBox3f getBoundingBox(SoNode* node);
00701
00702
00705 static SoSeparator* createCube(const SbBox3f& bbox);
00706
00707
00710 static SoSeparator* createBoundingBox(const SbBox3f& bbox, SbColor* color = NULL);
00711
00712
00715 static SoSeparator* readFile(const char *filename);
00716
00717
00721 #if !defined(OIV_HEADLESS)
00722
00723
00724
00725 template<typename TopLevelDialog>
00726 static Widget
00727 buildInterface( Widget window, const char* filename, const char* viewerName, TopLevelDialog** topLevelDialog)
00728 {
00729 SoInput myInput;
00730 if (!myInput.openFile(filename))
00731 return NULL;
00732
00733 SoGroup *myGroup = SoDB::readAll(&myInput);
00734 myInput.closeFile();
00735 if (!myGroup)
00736 return NULL;
00737
00738 *topLevelDialog = (TopLevelDialog *)myGroup->getChild(0);
00739
00740 SoDialogCustom *customNode = (SoDialogCustom *)(*topLevelDialog)->searchForAuditorId(SbString(viewerName));
00741
00742 (*topLevelDialog)->buildDialog(window, customNode != NULL);
00743 (*topLevelDialog)->show();
00744
00745 return customNode ? customNode->getWidget() : window;
00746 }
00747 #endif
00748 };
00749
00750 #endif
00751