#include "vtkDefOrgViewerWithKW.h" #include "vtkKWDialog.h" //debug #include "BYUToMeta.h" #include #include "vtkDataSetMapper.h" #include "vtkRenderer.h" #include "vtkKWCheckButton.h" #include "vtkKWPushButton.h" #include "vtkKWLoadSaveDialog.h" #include "vtkKWLoadSaveButton.h" #include "vtkKWTkUtilities.h" #include "vtkColorTransferFunction.h" #include "vtkKWScaleWithEntry.h" #include "vtkVolumeProperty.h" #include "vtkVolumeRayCastCompositeFunction.h" #include "vtkVolumeRayCastMIPFunction.h" #include "vtkVolumeRayCastMapper.h" #include "vtkVolume.h" #include "vtkKWApplication.h" #include "vtkKWMessageDialog.h" #include "vtkKWColorTransferFunctionEditor.h" #include "vtkKWHistogram.h" #include "vtkKWLabel.h" #include "vtkKWFramewithScrollbar.h" #include "vtkKWVolumePropertyWidget.h" #include "vtkPolyDataMapper.h" #include "vtkVolumeProperty.h" #include "vtkPiecewiseFunction.h" #include "vtkActor.h" #include "vtkKWSurfaceMaterialPropertyWidget.h" #include "vtkXMLPolyDataReader.h" #include "vtkCornerAnnotation.h" #include "vtkImageData.h" #include "vtkImageViewer2.h" #include "vtkKWApplication.h" #include "vtkKWFrame.h" #include "vtkKWFrameWithLabel.h" #include "vtkKWMenuButton.h" #include "vtkKWMenuButtonWithSpinButtons.h" #include "vtkKWMenuButtonWithSpinButtonsWithLabel.h" #include "vtkKWTextWithScrollbars.h" #include "vtkKWText.h" #include "vtkKWNotebook.h" #include "vtkKWRenderWidget.h" #include "vtkKWScale.h" #include "vtkKWSimpleAnimationWidget.h" #include "vtkKWWindow.h" #include "vtkKWWindowLevelPresetSelector.h" #include "vtkObjectFactory.h" #include "vtkRenderWindow.h" #include "vtkKWTopLevel.h" #include "vtkRenderWindowInteractor.h" #include "vtkXMLImageDataReader.h" #include "vtkKWMenu.h" #include "vtkKWWidgetsPaths.h" #include "vtkToolkits.h" #include "DefOrgViewerAdapterDynamicLoader.h" #include "vtkGenerateDefOrgDialog.h" #include "vtkKWSplashScreen.h" #include "vtkMath.h" #include "vtkKWComboBoxWithLabel.h" #include "vtkKWComboBox.h" #include "vtkBoxWidget.h" #include "vtkTransform.h" #include #include #include #include #include "vtkCommand.h" #include "vtkMultiThreader.h" //this has to be global variable in here because SOViewer has namespace conflicts //and cannot be put into a class typedef sov::VTKRenderer3D::Pointer SOViewerPointer; class vtkMyCallback : public vtkCommand { public: static vtkMyCallback *New() { return new vtkMyCallback; } vtkMyCallback():m_instance(NULL){ } virtual void SetApplicationInstance(vtkDefOrgViewerWithKW* instance){ m_instance=instance; } virtual void Execute(vtkObject *caller, unsigned long eventId, void*) { vtkTransform *t = vtkTransform::New(); vtkBoxWidget *widget = reinterpret_cast(caller); widget->GetTransform(t); widget->GetProp3D()->SetUserTransform(t); if (m_instance!=NULL){ m_instance->GetCurrDefOrg()->HandleUserMouseInteraction(t); } t->Delete(); } private: vtkDefOrgViewerWithKW* m_instance; }; //---------------------------------------------------------------------------- vtkStandardNewMacro( vtkDefOrgViewerWithKW ); vtkCxxRevisionMacro(vtkDefOrgViewerWithKW, "$Revision: 1.2 $"); //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::InitializeState(vtkKWWindow* win){ //some initializations m_organismRunning=false; StopSimulation(); m_currState = new vtkDefOrgViewerWithKWState(); DefOrgViewerAdapterBase* theDefOrg = m_currState->DynamicLoader.LoadLibrary(this->LoadDefOrgButton->GetFileName()); if (theDefOrg!=NULL) SetCurrDefOrg(theDefOrg); else throw "Error loading DefOrg"; viewerWindows = new vtkKWTopLevel*[GetCurrDefOrg()->MaxNumberOfOutputImages()-1]; // Create a volume reader for (int i=0;iMaxNumberOfOutputImages();i++){ vtkImageImport* newImagePointer = vtkImageImport::New(); GetCurrDefOrg()->AddOutputImages(newImagePointer,i); vtkImageViewer2* newImageViewerPointer = vtkImageViewer2::New(); this->m_currState->SetImageViewer(newImagePointer,newImageViewerPointer); if (i==0){ this->m_currState->SetImageViewerRenderWidget(newImagePointer,this->RenderWidget); } else{ vtkKWApplication *app = this->GetApplication(); //vtkKWTopLevel *win2 = vtkKWTopLevel::New(); viewerWindows[i-1] = vtkKWTopLevel::New(); viewerWindows[i-1]->SetParent(win); viewerWindows[i-1]->Create(); viewerWindows[i-1]->SetTitle(GetCurrDefOrg()->m_OutputImages[i].windowName.c_str()); viewerWindows[i-1]->Display(); vtkKWRenderWidget* newRenderWidget = vtkKWRenderWidget::New(); newRenderWidget->SetParent(viewerWindows[i-1]); newRenderWidget->Create(); newRenderWidget->CornerAnnotationVisibilityOn(); app->Script("pack %s -expand y -fill both -anchor c -expand y", newRenderWidget->GetWidgetName()); this->m_currState->SetImageViewerRenderWidget(newImagePointer,newRenderWidget); this->m_currState->m_OpenedWindows.push_back(viewerWindows[i-1]); newRenderWidget->Delete(); } } //Create SOViewers for (int i=0;iMaxNumberOfOutputItkSpatialObjects();i++){ itkScenePointer newItkScenePointer = itk::SceneSpatialObject<3>::New(); GetCurrDefOrg()->AddOutputItkSpatialObjects(newItkScenePointer); this->m_currState->SetSOViewer(newItkScenePointer,sov::VTKRenderer3D::New()); if (i==0){ this->m_currState->SetSOViewerRenderWidget(newItkScenePointer,this->RenderWidget); } else{ vtkKWApplication *app = this->GetApplication(); vtkKWTopLevel *win2 = vtkKWTopLevel::New(); win2->SetParent(win); win2->Create(); win2->SetTitle("Secondary Mesh Viewer"); win2->Display(); vtkKWRenderWidget* newRenderWidget = vtkKWRenderWidget::New(); newRenderWidget->SetParent(win2); newRenderWidget->Create(); newRenderWidget->CornerAnnotationVisibilityOn(); app->Script("pack %s -expand y -fill both -anchor c -expand y", newRenderWidget->GetWidgetName()); this->m_currState->SetSOViewerRenderWidget(newItkScenePointer,newRenderWidget); newRenderWidget->Delete(); this->m_currState->m_OpenedWindows.push_back(win2); } } } //---------------------------------------------------------------------------- int vtkDefOrgViewerWithKW::Run(int argc, char *argv[]) { // Set up a file stream //ofstream output("d:\\defOrgDebug.txt"); // Redirect "cout" to file stream "output" //cout.rdbuf(output.rdbuf()); // Create the application // Restore the settings that have been saved to the registry, like // the geometry of the user interface so far. vtkKWApplication *app = this->GetApplication(); app->SetName("DefOrgViewer"); // Set a help link. Can be a remote link (URL), or a local file app->SupportSplashScreenOn(); app->SplashScreenVisibilityOn(); app->GetSplashScreen()->ReadImage("SplashScreen.png"); app->GetSplashScreen()->Display(); app->SetHelpDialogStartingPage("http://mial.fas.sfu.ca"); app->RestoreApplicationSettingsFromRegistry(); m_threader = vtkMultiThreader::New(); // Add a window // Set 'SupportHelp' to automatically add a menu entry for the help link vtkKWWindow *win = vtkKWWindow::New(); MainWindow = win; m_currState = new vtkDefOrgViewerWithKWState(); //win->SupportHelpOn(); app->AddWindow(win); app->PromptBeforeExitOff(); win->Create(); win->SecondaryPanelVisibilityOff(); //win->GetFileMenu()->AddCommand("Load Organism",this,"LoadDefOrgDialogCallback","Load Organism"); win->GetFileMenu()->InsertCommand(0,"Generate Organism",this,"GenerateDefOrgDialogCallback","Generate Organism"); // Add a render widget, attach it to the view frame, and pack this->RenderWidget = vtkKWRenderWidget::New(); this->RenderWidget->SetParent(win->GetViewFrame()); this->RenderWidget->Create(); this->RenderWidget->CornerAnnotationVisibilityOn(); /* vtkMyCallback *callback = vtkMyCallback::New(); callback->SetApplicationInstance(this); this->RenderWidget->GetRenderWindow()->GetInteractor()->AddObserver(vtkCommand::AnyEvent, callback);*/ /*this->RenderWidget->GetRenderWindow()->GetInteractor()->AddObserver(vtkCommand::StartPickEvent, callback); this->RenderWidget->GetRenderWindow()->GetInteractor()->AddObserver(vtkCommand::PickEvent, callback); this->RenderWidget->GetRenderWindow()->GetInteractor()->AddObserver(vtkCommand::EndPickEvent, callback);*/ app->Script("pack %s -expand y -fill both -anchor c -expand y", this->RenderWidget->GetWidgetName()); // Create a scale to control the slice this->SliceScale = vtkKWScale::New(); this->SliceScale->SetParent(win->GetViewPanelFrame()); this->SliceScale->Create(); this->SliceScale->SetCommand(this, "SetSliceFromScaleCallback"); app->Script("pack %s -side top -expand n -fill x -padx 2 -pady 2", this->SliceScale->GetWidgetName()); int organismPageCookie = win->GetMainNotebook()->AddPage("Organism"); CreateOrganismDataFrame(organismPageCookie, win); MeshBoxWidget = vtkBoxWidget::New(); // Start the application int ret = 0; win->Display(); app->Start(argc, argv); ret = app->GetExitStatus(); win->Close(); // Deallocate and exit m_organismRunning=false; delete m_currState; if (this->SliceScale) this->SliceScale->Delete(); if (this->WindowLevelPresetSelector) this->WindowLevelPresetSelector->Delete(); if (this->RenderWidget) this->RenderWidget->Delete(); win->Delete(); //output.flush(); return ret; } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::ForcePrimaryRender(){ this->RenderWidget->Render(); } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::SetSliceFromScaleCallback( double value) { if (this->m_currState->isDefOrgSet()){ this->m_currState->GetCurrentImageViewer()->SetSlice((int)value); this->RenderWidget->Render(); } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::SetSliceCallback(int slice) { if (this->m_currState->isDefOrgSet()){ this->m_currState->GetCurrentImageViewer()->SetSlice(slice); this->RenderWidget->Render(); } } //---------------------------------------------------------------------------- int vtkDefOrgViewerWithKW::GetSliceCallback() { if (this->m_currState->isDefOrgSet()){ return this->m_currState->GetCurrentImageViewer()->GetSlice(); } return 0; } //---------------------------------------------------------------------------- int vtkDefOrgViewerWithKW::GetSliceMinCallback() { if (this->m_currState->isDefOrgSet()){ return this->m_currState->GetCurrentImageViewer()->GetSliceMin(); } return 0; } //---------------------------------------------------------------------------- int vtkDefOrgViewerWithKW::GetSliceMaxCallback() { if (this->m_currState->isDefOrgSet()){ return this->m_currState->GetCurrentImageViewer()->GetSliceMax(); } return 0; } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::UpdateSliceScale() { if (this->m_currState->isDefOrgSet()){ this->SliceScale->SetRange( this->m_currState->GetCurrentImageViewer()->GetSliceMin(), this->m_currState->GetCurrentImageViewer()->GetSliceMax()); this->SliceScale->SetValue(this->m_currState->GetCurrentImageViewer()->GetSlice()); } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::SetSliceOrientationToXYCallback() { if (this->m_currState->isDefOrgSet()){ this->m_currState->GetCurrentImageViewer()->SetSliceOrientationToXY(); this->UpdateSliceScale(); } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::SetSliceOrientationToXZCallback() { if (this->m_currState->isDefOrgSet()){ this->m_currState->GetCurrentImageViewer()->SetSliceOrientationToXZ(); this->UpdateSliceScale(); } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::SetSliceOrientationToYZCallback() { if (this->m_currState->isDefOrgSet()){ this->m_currState->GetCurrentImageViewer()->SetSliceOrientationToYZ(); this->UpdateSliceScale(); } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::WindowLevelPresetApplyCallback( int id) { if (this->m_currState->isDefOrgSet()){ if (this->WindowLevelPresetSelector->HasPreset(id)) { this->m_currState->GetCurrentImageViewer()->SetColorWindow( this->WindowLevelPresetSelector->GetPresetWindow(id)); this->m_currState->GetCurrentImageViewer()->SetColorLevel( this->WindowLevelPresetSelector->GetPresetLevel(id)); this->m_currState->GetCurrentImageViewer()->Render(); } } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::WindowLevelPresetAddCallback() { if (this->m_currState->isDefOrgSet()){ this->WindowLevelPresetUpdateCallback( this->WindowLevelPresetSelector->AddPreset()); } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::WindowLevelPresetUpdateCallback( int id) { if (this->m_currState->isDefOrgSet()){ this->WindowLevelPresetSelector->SetPresetWindow( id, this->m_currState->GetCurrentImageViewer()->GetColorWindow()); this->WindowLevelPresetSelector->SetPresetLevel( id, this->m_currState->GetCurrentImageViewer()->GetColorLevel()); this->WindowLevelPresetHasChangedCallback(id); } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::WindowLevelPresetHasChangedCallback( int id) { if (this->m_currState->isDefOrgSet()){ this->WindowLevelPresetSelector-> BuildPresetThumbnailAndScreenshotFromRenderWindow( id, this->RenderWidget->GetRenderWindow()); } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::SetSOColorCallback(double r, double g, double b){ if (!this->m_currState->isDefOrgSet()) return; vtkActorCollection* SOViewerActors = this->m_currState->GetCurrentSOViewer()->GetVTKRenderer()->GetActors(); SOViewerActors->InitTraversal(); vtkActor* actor = SOViewerActors->GetNextActor(); this->SOMatieralPropertyWidget->SetMaterialColor(r,g,b); if (actor) { actor->GetProperty()->SetColor(r,g,b); } this->m_currState->GetCurrentSOViewerRenderWidget()->Render(); } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::CreateImageDataFrame(int imagePageCookie, vtkKWWindow *win) { vtkKWApplication *app = this->GetApplication(); // Create a menu button to control the orientation vtkKWMenuButtonWithSpinButtonsWithLabel *orientation_menubutton = vtkKWMenuButtonWithSpinButtonsWithLabel::New(); orientation_menubutton->SetParent(win->GetMainNotebook()->GetFrame(imagePageCookie)); orientation_menubutton->Create(); orientation_menubutton->SetLabelText("Orientation:"); orientation_menubutton->SetPadX(2); orientation_menubutton->SetPadY(2); orientation_menubutton->SetBorderWidth(2); orientation_menubutton->SetReliefToGroove(); app->Script("pack %s -side top -anchor nw -expand n -fill x", orientation_menubutton->GetWidgetName()); vtkKWMenuButton *mb = orientation_menubutton->GetWidget()->GetWidget(); mb->AddRadioButton("X-Y", this, "SetSliceOrientationToXYCallback"); mb->AddRadioButton("X-Z", this, "SetSliceOrientationToXZCallback"); mb->AddRadioButton("Y-Z", this, "SetSliceOrientationToYZCallback"); mb->SetValue("X-Y"); // Create a window/level preset selector vtkKWFrameWithLabel *wl_frame = vtkKWFrameWithLabel::New(); wl_frame->SetParent(win->GetMainNotebook()->GetFrame(imagePageCookie)); wl_frame->Create(); wl_frame->SetLabelText("Window/Level Presets"); app->Script("pack %s -side top -anchor nw -expand n -fill x -pady 2", wl_frame->GetWidgetName()); this->WindowLevelPresetSelector = vtkKWWindowLevelPresetSelector::New(); this->WindowLevelPresetSelector->SetParent(wl_frame->GetFrame()); this->WindowLevelPresetSelector->Create(); this->WindowLevelPresetSelector->ThumbnailColumnVisibilityOn(); this->WindowLevelPresetSelector->SetPresetAddCommand( this, "WindowLevelPresetAddCallback"); this->WindowLevelPresetSelector->SetPresetApplyCommand( this, "WindowLevelPresetApplyCallback"); this->WindowLevelPresetSelector->SetPresetUpdateCommand( this, "WindowLevelPresetUpdateCallback"); this->WindowLevelPresetSelector->SetPresetHasChangedCommand( this, "WindowLevelPresetHasChangedCallback"); app->Script("pack %s -side top -anchor nw -expand n -fill x", this->WindowLevelPresetSelector->GetWidgetName()); // Create a simple animation widget vtkKWFrameWithLabel *animation_frame = vtkKWFrameWithLabel::New(); animation_frame->SetParent(win->GetMainNotebook()->GetFrame(imagePageCookie)); animation_frame->Create(); animation_frame->SetLabelText("Movie Creator"); app->Script("pack %s -side top -anchor nw -expand n -fill x -pady 2", animation_frame->GetWidgetName()); vtkKWSimpleAnimationWidget *animation_widget = vtkKWSimpleAnimationWidget::New(); animation_widget->SetParent(animation_frame->GetFrame()); animation_widget->Create(); animation_widget->SetRenderWidget(this->RenderWidget); animation_widget->SetAnimationTypeToSlice(); animation_widget->SetSliceSetCommand(this, "SetSliceCallback"); animation_widget->SetSliceGetCommand(this, "GetSliceCallback"); animation_widget->SetSliceGetMinAndMaxCommands( this, "GetSliceMinCallback", "GetSliceMaxCallback"); app->Script("pack %s -side top -anchor nw -expand n -fill x", animation_widget->GetWidgetName()); orientation_menubutton->Delete(); animation_frame->Delete(); animation_widget->Delete(); wl_frame->Delete(); } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::CreateSpatialObjectFrame(int polyPageCookie, vtkKWWindow *win) { // Create a material property editor vtkKWApplication *app = this->GetApplication(); SOMatieralPropertyWidget = vtkKWSurfaceMaterialPropertyWidget::New(); SOMatieralPropertyWidget->SetParent(win->GetMainNotebook()->GetFrame(polyPageCookie)); SOMatieralPropertyWidget->Create(); SOMatieralPropertyWidget->SetPropertyChangedCommand(this->RenderWidget, "Render"); SOMatieralPropertyWidget->SetPropertyChangingCommand(this->RenderWidget, "Render"); app->Script("pack %s -side top -anchor nw -expand n -fill x", SOMatieralPropertyWidget->GetWidgetName()); SOMatieralPropertyWidget->Delete(); SOColorWidget = vtkKWHSVColorSelector::New(); SOColorWidget->SetParent(win->GetMainNotebook()->GetFrame(polyPageCookie)); SOColorWidget->Create(); SOColorWidget->InvokeCommandsWithRGBOn(); SOColorWidget->SetSelectionChangedCommand(this, "SetSOColorCallback"); SOColorWidget->SetSelectionChangingCommand(this, "SetSOColorCallback"); app->Script("pack %s -side top -anchor nw -expand n -fill x", SOColorWidget->GetWidgetName()); SOColorWidget->Delete(); } void vtkDefOrgViewerWithKW::LayerComboCallback(int id, const char* choice){ this->GetCurrDefOrg()->m_LayerBag[id].chosenOption=choice; } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::CreateOrganismDataFrame(int organismPageCookie, vtkKWWindow* win){ vtkKWApplication *app = this->GetApplication(); vtkKWFrameWithScrollbar* vScrollBar_frame = vtkKWFrameWithScrollbar::New(); vScrollBar_frame->SetParent(win->GetMainNotebook()->GetFrame(organismPageCookie)); vScrollBar_frame->Create(); app->Script("pack %s -side top -anchor nw -expand n -fill x -pady 2", vScrollBar_frame->GetWidgetName()); LoadDefOrgButton = vtkKWLoadSaveButton::New(); LoadDefOrgButton->SetParent(vScrollBar_frame->GetFrame()); LoadDefOrgButton->Create(); LoadDefOrgButton->SetCommand(this, "LoadDefOrgDialogCallback"); LoadDefOrgButton->SetText("Load Deformable Organism"); vtkKWLoadSaveDialog *loadDefOrgDlg = LoadDefOrgButton->GetLoadSaveDialog(); #ifdef _WIN32 loadDefOrgDlg->SetDefaultExtension("*.dll"); loadDefOrgDlg->SetFileTypes("{{Shared Library} {.dll}}"); #else loadDefOrgDlg->SetDefaultExtension("*.*"); loadDefOrgDlg->SetFileTypes("{{Shared Library} {.*}}"); #endif loadDefOrgDlg->SaveDialogOff(); this->Script("pack %s -side top -expand n -fill x -padx 2 -pady 2", LoadDefOrgButton->GetWidgetName()); if (!this->m_currState->isDefOrgSet()) return; vtkKWFrameWithLabel *organismPropertyFrame = vtkKWFrameWithLabel::New(); organismPropertyFrame->SetParent(vScrollBar_frame->GetFrame()); organismPropertyFrame->Create(); organismPropertyFrame->SetLabelText("Organism Initialization Properties"); app->Script("pack %s -side top -anchor nw -expand n -fill x -pady 2", organismPropertyFrame->GetWidgetName()); LoadImageButton = vtkKWLoadSaveButton::New(); LoadImageButton->SetParent(organismPropertyFrame->GetFrame()); LoadImageButton->Create(); LoadImageButton->SetCommand(this, "LoadImageDialogCallback"); LoadImageButton->SetText("Load Image"); vtkKWLoadSaveDialog *loadImageDlg = LoadImageButton->GetLoadSaveDialog(); loadImageDlg->SetDefaultExtension("*.*"); loadImageDlg->SetFileTypes("{{ITK Supported Image File} {.*}}"); loadImageDlg->SaveDialogOff(); this->Script("pack %s -side top -expand n -fill x -padx 2 -pady 2", LoadImageButton->GetWidgetName()); LoadScheduleButton = vtkKWLoadSaveButton::New(); LoadScheduleButton->SetParent(organismPropertyFrame->GetFrame()); LoadScheduleButton->Create(); LoadScheduleButton->SetCommand(this, "LoadScheduleDialogCallback"); LoadScheduleButton->SetText("Load Schedule"); vtkKWLoadSaveDialog *loadScheduleDlg = LoadScheduleButton->GetLoadSaveDialog(); loadScheduleDlg->SetDefaultExtension("*.txt"); loadScheduleDlg->SetFileTypes("{{Schedule Files} {.txt}}"); loadScheduleDlg->SaveDialogOff(); this->Script("pack %s -side top -expand n -fill x -padx 2 -pady 2", LoadScheduleButton->GetWidgetName()); LoadMeshButton = vtkKWLoadSaveButton::New(); LoadMeshButton->SetParent(organismPropertyFrame->GetFrame()); LoadMeshButton->Create(); LoadMeshButton->SetCommand(this, "LoadMeshDialogCallback"); LoadMeshButton->SetText("Load Mesh"); vtkKWLoadSaveDialog *loadMeshDlg = LoadMeshButton->GetLoadSaveDialog(); loadMeshDlg->SetDefaultExtension("*.meta"); loadMeshDlg->SetFileTypes("{{META} {.meta}} {{BYU} {.byu}}"); loadMeshDlg->SaveDialogOff(); this->Script("pack %s -side top -expand n -fill x -padx 2 -pady 2", LoadMeshButton->GetWidgetName()); std::vector< DefOrgLayerStruct >::iterator layerProp = this->GetCurrDefOrg()->m_LayerBag.begin(); int i=0; for (;layerProp!=this->GetCurrDefOrg()->m_LayerBag.end();layerProp++){ vtkKWComboBoxWithLabel* layerCombo = vtkKWComboBoxWithLabel::New(); layerCombo->SetParent(organismPropertyFrame->GetFrame()); layerCombo->Create(); layerCombo->SetLabelText(layerProp->layerName); std::vector::iterator choicesIt = (layerProp->options).begin(); layerCombo->GetWidget()->SetValue((*choicesIt)); layerProp->chosenOption = (*choicesIt); for (; choicesIt!=(layerProp->options).end(); choicesIt++) { layerCombo->GetWidget()->AddValue( (*choicesIt) ); } layerCombo->GetWidget()->ReadOnlyOn(); //(this->m_currState->m_LayerComboBoxes).push_back(layerCombo); char buffer[255]; sprintf(buffer, "LayerComboCallback %d",i); layerCombo->GetWidget()->SetCommand(this, buffer); app->Script( "pack %s -side top -anchor nw -expand n -fill x -padx 2 -pady 6", layerCombo->GetWidgetName()); layerCombo->Delete(); i++; } std::map::iterator orgProp = this->GetCurrDefOrg()->m_PropertyBag.begin(); for (;orgProp!=this->GetCurrDefOrg()->m_PropertyBag.end();orgProp++){ char buffer[50]; vtkKWScaleWithEntry *propertyScale = vtkKWScaleWithEntry::New(); propertyScale->SetParent(organismPropertyFrame->GetFrame()); propertyScale->Create(); propertyScale->SetRange((orgProp->second).lowerBound, (orgProp->second).upperBound); propertyScale->SetValue((orgProp->second).defaultValue); propertyScale->SetResolution((orgProp->second).resolution); // scale2->GetScale()->SetLength(350); propertyScale->RangeVisibilityOn(); sprintf(buffer, "%s :", (orgProp->first).c_str()); propertyScale->SetLabelText(buffer); propertyScale->SetBalloonHelpString((orgProp->second).helpString.c_str()); app->Script( "pack %s -side top -anchor nw -expand n -fill x -padx 2 -pady 6", propertyScale->GetWidgetName()); this->m_currState->m_DefOrgPropertyScaleMap[orgProp->first]=propertyScale; propertyScale->Delete(); } InitOrganismButton = vtkKWPushButton::New(); InitOrganismButton->SetParent(organismPropertyFrame->GetFrame()); InitOrganismButton->Create(); InitOrganismButton->SetCommand(this, "InitOrganismButtonCallback"); InitOrganismButton->SetText("Initialize/Setup Organism"); InitOrganismButton->EnabledOff(); this->Script("pack %s -side top -expand n -fill x -padx 2 -pady 2", InitOrganismButton->GetWidgetName()); SimulateOrganismButton = vtkKWPushButton::New(); SimulateOrganismButton->SetParent(vScrollBar_frame->GetFrame()); SimulateOrganismButton->Create(); SimulateOrganismButton->SetCommand(this, "SimulateOrganismButtonCallback"); SimulateOrganismButton->SetText("Simulate Organism"); SimulateOrganismButton->EnabledOff(); this->Script("pack %s -side top -expand n -fill x -padx 2 -pady 2", SimulateOrganismButton->GetWidgetName()); StepOrganismButton = vtkKWPushButton::New(); StepOrganismButton->SetParent(vScrollBar_frame->GetFrame()); StepOrganismButton->Create(); StepOrganismButton->SetCommand(this, "StepOrganismButtonCallback"); StepOrganismButton->SetText("Step Organism"); StepOrganismButton->EnabledOff(); this->Script("pack %s -side top -expand n -fill x -padx 2 -pady 2", StepOrganismButton->GetWidgetName()); OrganismTextIOFrame = vtkKWFrameWithLabel::New(); OrganismTextIOFrame->SetParent(vScrollBar_frame->GetFrame()); OrganismTextIOFrame->Create(); OrganismTextIOFrame->SetLabelText("Organism Input/Output"); app->Script("pack %s -side top -anchor nw -expand n -fill x -pady 2", OrganismTextIOFrame->GetWidgetName()); vtkKWLabel *OrgOutputTextLabel = vtkKWLabel::New(); OrgOutputTextLabel->SetParent(OrganismTextIOFrame->GetFrame()); OrgOutputTextLabel->Create(); OrgOutputTextLabel->SetText("Output from Organism:"); app->Script( "pack %s -side top -anchor nw -expand n -padx 2 -pady 2", OrgOutputTextLabel->GetWidgetName()); OrganismOutputTextbox = vtkKWTextWithScrollbars::New(); OrganismOutputTextbox->SetParent(OrganismTextIOFrame->GetFrame()); OrganismOutputTextbox->Create(); OrganismOutputTextbox->GetWidget()->SetText(""); OrganismOutputTextbox->GetWidget()->QuickFormattingOff(); OrganismOutputTextbox->GetWidget()->ReadOnlyOn(); OrganismOutputTextbox->SetBalloonHelpString( "Output from Organism"); app->Script( "pack %s -side top -expand n -fill x -padx 2 -pady 6", OrganismOutputTextbox->GetWidgetName()); vtkKWPushButton* RefreshOrganismOutputButton = vtkKWPushButton::New(); RefreshOrganismOutputButton->SetParent(OrganismTextIOFrame->GetFrame()); RefreshOrganismOutputButton->Create(); RefreshOrganismOutputButton->SetCommand(this, "UpdateOrganismTextOutputCallback"); RefreshOrganismOutputButton->SetText("Refresh Output from Organism"); RefreshOrganismOutputButton->EnabledOn(); this->Script("pack %s -side top -anchor nw -expand n -padx 2 -pady 2", RefreshOrganismOutputButton->GetWidgetName()); vtkKWLabel *OrgInputTextLabel = vtkKWLabel::New(); OrgInputTextLabel->SetParent(OrganismTextIOFrame->GetFrame()); OrgInputTextLabel->Create(); OrgInputTextLabel->SetText("Message to Organism:"); app->Script( "pack %s -side top -anchor nw -expand n -padx 2 -pady 2", OrgInputTextLabel->GetWidgetName()); OrganismInputTextbox = vtkKWTextWithScrollbars::New(); OrganismInputTextbox->SetParent(OrganismTextIOFrame->GetFrame()); OrganismInputTextbox->Create(); OrganismInputTextbox->GetWidget()->SetText(""); OrganismInputTextbox->GetWidget()->QuickFormattingOff(); OrganismInputTextbox->GetWidget()->SetHeight(2); OrganismInputTextbox->GetWidget()->SetWidth(20); OrganismInputTextbox->GetWidget()->ReadOnlyOff(); OrganismInputTextbox->SetBalloonHelpString( "Message to Organism"); app->Script( "pack %s -side top -expand n -fill x -padx 2 -pady 6", OrganismInputTextbox->GetWidgetName()); SendOrganismMessageButton = vtkKWPushButton::New(); SendOrganismMessageButton->SetParent(OrganismTextIOFrame->GetFrame()); SendOrganismMessageButton->Create(); SendOrganismMessageButton->SetCommand(this, "SendOrganismMessageCallback"); SendOrganismMessageButton->SetText("Send message to organism"); SendOrganismMessageButton->EnabledOn(); this->Script("pack %s -side top -anchor nw -expand n -padx 2 -pady 2", SendOrganismMessageButton->GetWidgetName()); vtkKWFrameWithLabel *animation_frame = vtkKWFrameWithLabel::New(); animation_frame->SetParent(vScrollBar_frame->GetFrame()); animation_frame->Create(); animation_frame->SetLabelText("Record Simulation"); app->Script("pack %s -side top -anchor nw -expand n -fill x -pady 2", animation_frame->GetWidgetName()); vtkKWSimpleAnimationWidget *animation_widget = vtkKWSimpleAnimationWidget::New(); animation_widget->SetParent(animation_frame->GetFrame()); animation_widget->Create(); animation_widget->SetRenderWidget(this->RenderWidget); animation_widget->SetAnimationTypeToSlice(); animation_widget->SetSliceSetCommand(this, "NoOp2"); animation_widget->SetSliceGetCommand(this, "NoOp"); animation_widget->SetSliceGetMinAndMaxCommands( this, "NoOp", "NoOp"); app->Script("pack %s -side top -anchor nw -expand n -fill x", animation_widget->GetWidgetName()); animation_frame->Delete(); animation_widget->Delete(); OrgOutputTextLabel->Delete(); OrgInputTextLabel->Delete(); OrganismOutputTextbox->Delete(); OrganismInputTextbox->Delete(); SendOrganismMessageButton->Delete(); vScrollBar_frame->Delete(); LoadDefOrgButton->Delete(); organismPropertyFrame->Delete(); LoadImageButton->Delete(); LoadScheduleButton->Delete(); LoadMeshButton->Delete(); InitOrganismButton->Delete(); SimulateOrganismButton->Delete(); StepOrganismButton->Delete(); OrganismTextIOFrame->Delete(); } //---------------------------------------------------------------------------- int vtkDefOrgViewerWithKW::NoOp(){ return 1; } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::NoOp2(int i){ if (i>0) StepOrganismButtonCallback(); } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::AddActorsFromSOViewers(bool flushAll){ for (int i=0;iMaxNumberOfOutputItkSpatialObjects();i++){ if ((this->GetCurrDefOrg()->m_OutputItkSpatialObjects[i]).isModified||flushAll){ itkScenePointer tempItkScenePtr = (this->GetCurrDefOrg()->m_OutputItkSpatialObjects[i]).theItkScene; vtkActorCollection* SOViewerActors = this->m_currState->GetSOViewer(tempItkScenePtr)->GetVTKRenderer()->GetActors(); SOViewerActors->InitTraversal(); vtkActor* actor; while (actor = SOViewerActors->GetNextActor()) { /* vtkMyCallback *callback = vtkMyCallback::New(); actor->AddObserver(vtkCommand::AnyEvent,callback);*/ MeshBoxWidget->SetInteractor(this->RenderWidget->GetRenderWindow()->GetInteractor()); MeshBoxWidget->SetPlaceFactor(1.25); MeshBoxWidget->SetProp3D(actor); MeshBoxWidget->PlaceWidget(); vtkMyCallback *callback = vtkMyCallback::New(); callback->SetApplicationInstance(this); MeshBoxWidget->AddObserver(vtkCommand::InteractionEvent, callback); callback->Delete(); this->SOMatieralPropertyWidget->SetProperty(actor->GetProperty()); double rgb[3]; double* actorColor = this->SOColorWidget->GetSelectedColor(); vtkMath::HSVToRGB(actorColor,rgb); //actor->GetProperty()->SetColor(this->SOColorWidget->GetSelectedColor()); actor->GetProperty()->SetColor(rgb); this->m_currState->GetSOViewerRenderWidget(tempItkScenePtr)->AddViewProp(actor); } } } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::SetScenesToSOViewers(bool flushAll){ for (int i=0;iMaxNumberOfOutputItkSpatialObjects();i++){ if ((this->GetCurrDefOrg()->m_OutputItkSpatialObjects[i]).isModified||flushAll){ itkScenePointer tempItkScenePtr = (this->GetCurrDefOrg()->m_OutputItkSpatialObjects[i]).theItkScene; this->m_currState->GetSOViewer(tempItkScenePtr)->SetScene((this->GetCurrDefOrg()->m_OutputItkSpatialObjects[i]).theItkScene); this->m_currState->GetSOViewer(tempItkScenePtr)->Update(); } } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::RemoveActorsFromSOViewers(bool flushAll){ for (int i=0;iMaxNumberOfOutputItkSpatialObjects();i++){ if ((this->GetCurrDefOrg()->m_OutputItkSpatialObjects[i]).isModified||flushAll){ itkScenePointer tempItkScenePtr = (this->GetCurrDefOrg()->m_OutputItkSpatialObjects[i]).theItkScene; vtkActorCollection* SOViewerActors = this->m_currState->GetSOViewer(tempItkScenePtr)->GetVTKRenderer()->GetActors(); if (SOViewerActors){ SOViewerActors->InitTraversal(); vtkActor* actor; while (actor = SOViewerActors->GetNextActor()) { this->m_currState->GetSOViewerRenderWidget(tempItkScenePtr)->RemoveViewProp(actor); } //m_scene = itk::SceneSpatialObject<3>::New(); //this->m_currState->SetPrimarySOViewer(sov::VTKRenderer3D::New()); //this->m_currState->SetSOViewer(tempItkScenePtr, sov::VTKRenderer3D::New()); } } } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::RenderSOViewers(bool flushAll){ for (int i=0;iMaxNumberOfOutputItkSpatialObjects();i++){ if ((this->GetCurrDefOrg()->m_OutputItkSpatialObjects[i]).isModified||flushAll){ (this->GetCurrDefOrg()->m_OutputItkSpatialObjects[i]).isModified=false; itkScenePointer tempItkScenePtr = (this->GetCurrDefOrg()->m_OutputItkSpatialObjects[i]).theItkScene; vtkKWRenderWidget* sovRenderWidget= this->m_currState->GetSOViewerRenderWidget(tempItkScenePtr); sovRenderWidget->ResetCamera(); sovRenderWidget->Render(); } } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::SendOrganismMessageCallback(){ this->GetCurrDefOrg()->theDefOrgTextInput << OrganismInputTextbox->GetWidget()->GetText(); OrganismInputTextbox->GetWidget()->SetText(""); } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::UpdateOrganismTextOutputCallback(){ if (!(OrganismTextIOFrame->IsFrameCollapsed())){ (this->GetCurrDefOrg()->theDefOrgTextOutput).flush(); this->OrganismOutputTextbox->GetWidget()->AppendText((this->GetCurrDefOrg()->theDefOrgTextOutput).str().c_str()); (this->GetCurrDefOrg()->theDefOrgTextOutput).str(""); } vtkKWTkUtilities::ProcessPendingEvents(this->GetApplication()); } VTK_THREAD_RETURN_TYPE SimulateOrganism( void *arg ){ int threadID = ((vtkMultiThreader::ThreadInfo *)(arg))->ThreadID; int threadCount = ((vtkMultiThreader::ThreadInfo *)(arg))->NumberOfThreads; vtkDefOrgViewerWithKW *me = (vtkDefOrgViewerWithKW *)((vtkMultiThreader::ThreadInfo *)arg)->UserData; me->GetCurrDefOrg()->UpdateOrganism(); me->m_updateOrganismResults=true; return VTK_THREAD_RETURN_VALUE; } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::StepOrganism(){ if (m_updateOrganismResults){ this->m_threader->TerminateThread(m_currThreadID); m_currThreadID=0; RemoveActorsFromSOViewers(); SetScenesToSOViewers(); AddActorsFromSOViewers(); RenderSOViewers(); UpdateImageViewers(); UpdateOrganismTextOutputCallback(); } if (m_currThreadID==0){ m_updateOrganismResults=false; m_currThreadID = this->m_threader->SpawnThread ( SimulateOrganism, (void *)this); } /*this->RenderWidget->ResetCamera(); this->RenderWidget->Render();*/ } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::StepOrganismButtonCallback(){ this->GetCurrDefOrg()->UpdateOrganism(); RemoveActorsFromSOViewers(); SetScenesToSOViewers(); AddActorsFromSOViewers(); RenderSOViewers(); UpdateImageViewers(); UpdateOrganismTextOutputCallback(); } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::InitOrganismButtonCallback(){ StepOrganismButton->EnabledOff(); //this->GetCurrDefOrg()->theDefOrgTextOutputCallBack = &UpdateOrganismTextOutputCallback; this->InitOrganismButton->SetText("Setting up Organism"); this->InitOrganismButton->EnabledOff(); this->SimulateOrganismButton->EnabledOff(); this->StepOrganismButton->EnabledOff(); //Start the organism vtkKWTkUtilities::ProcessPendingEvents(this->GetApplication()); std::map::iterator orgProp = this->GetCurrDefOrg()->m_PropertyBag.begin(); for (;orgProp!=this->GetCurrDefOrg()->m_PropertyBag.end();orgProp++){ std::map::iterator curr = this->m_currState->m_DefOrgPropertyScaleMap.find(orgProp->first); if (this->m_currState->m_DefOrgPropertyScaleMap.end()!=curr){ //a matching scale button exists for this property (orgProp->second).currentValue = (curr->second)->GetValue(); } } this->GetCurrDefOrg()->SetupOrganism(); this->InitOrganismButton->SetText("Initialize/Setup Organism"); this->InitOrganismButton->EnabledOn(); this->SimulateOrganismButton->EnabledOn(); this->StepOrganismButton->EnabledOn(); UpdateOrganismTextOutputCallback(); vtkKWTkUtilities::ProcessPendingEvents(this->GetApplication()); } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::StopSimulation(){ if (m_organismRunning){ m_organismRunning=false; this->SimulateOrganismButton->SetText("Simulate Organism"); if (m_currThreadID!=0) m_threader->TerminateThread(m_currThreadID); m_currThreadID=0; m_updateOrganismResults=false; } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::SimulateOrganismButtonCallback(){ if (!m_organismRunning && this->GetCurrDefOrg()->IsAllInputFilesSet()) { m_organismRunning=true; StepOrganismButton->EnabledOff(); this->SimulateOrganismButton->SetText("Stop Simulating Organism"); while (this->m_organismRunning){ StepOrganism(); vtkKWTkUtilities::ProcessPendingEvents(this->GetApplication()); if (this->GetApplication()->GetInExit()) m_organismRunning=false; } } else if (m_organismRunning){ //stop the organism StopSimulation(); StepOrganismButton->EnabledOn(); } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::UpdateImageViewers(bool flushAll){ for (int i=0;iMaxNumberOfOutputImages();i++){ if ((this->GetCurrDefOrg()->m_OutputImages[i]).isModified||flushAll){ (this->GetCurrDefOrg()->m_OutputImages[i]).isModified=false; vtkImageImport* imageVol = (this->GetCurrDefOrg()->m_OutputImages[i]).theImageVolume; vtkImageViewer2* imageViewer = this->m_currState->GetImageViewer(imageVol); vtkKWRenderWidget* renderWidget = this->m_currState->GetImageViewerRenderWidget(imageVol); if (!((this->GetCurrDefOrg()->m_OutputImages[i]).isInitialized)){ imageViewer->SetRenderWindow(renderWidget->GetRenderWindow()); imageViewer->SetRenderer(renderWidget->GetRenderer()); imageViewer->SetInput(imageVol->GetOutput()); if (i!=0) imageViewer->SetupInteractor(renderWidget->GetRenderWindow()->GetInteractor()); } if (i!=0){ renderWidget->ResetCameraClippingRange(); renderWidget->ResetCamera(); renderWidget->Render(); } } } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::LoadImageDialogCallback() { StopSimulation(); const char *filename = this->LoadImageButton->GetFileName(); if (filename){ this->GetCurrDefOrg()->SetImageFileName(filename); vtkImageImport* tempVtkImporter = (GetCurrDefOrg()->m_OutputImages[0]).theImageVolume; this->GetCurrDefOrg()->PopulateVtkImage(); tempVtkImporter->UpdateWholeExtent(); SetupImageViewerPipeline(); UpdateImageViewers(true); this->RenderWidget->ResetCameraClippingRange(); this->RenderWidget->ResetCamera(); this->RenderWidget->Render(); if (this->MainWindow->GetMainNotebook()->HasPage("Image",0)) this->MainWindow->GetMainNotebook()->RemovePage("Image"); int imagePageCookie = this->MainWindow->GetMainNotebook()->AddPage("Image"); CreateImageDataFrame(imagePageCookie, this->MainWindow); if (this->GetCurrDefOrg()->IsAllInputFilesSet()) { this->InitOrganismButton->EnabledOn(); this->SimulateOrganismButton->EnabledOff(); this->StepOrganismButton->EnabledOff(); } } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::LoadScheduleDialogCallback() { StopSimulation(); const char *filename = this->LoadScheduleButton->GetFileName(); if (filename){ this->GetCurrDefOrg()->SetScheduleFileName(filename); if (this->GetCurrDefOrg()->IsAllInputFilesSet()) { this->InitOrganismButton->EnabledOn(); this->SimulateOrganismButton->EnabledOff(); this->StepOrganismButton->EnabledOff(); } } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::GenerateDefOrgDialogCallback() { vtkGenerateDefOrgDialog* dlg = vtkGenerateDefOrgDialog::New(); dlg->SetParent(this->MainWindow); dlg->Create(this->GetApplication()); dlg->SetMasterWindow(this->MainWindow); dlg->SetTitle("Generate DefOrg"); if ( dlg->Invoke() ) { //ghostLevel = dlg->GetGhostLevel(); vtkKWMessageDialog::PopupMessage(this->GetApplication(), this->MainWindow,"Operation Complete","Operation Complete"); } else{ vtkKWMessageDialog::PopupMessage(this->GetApplication(), this->MainWindow,"Operation Failed","Operation Failed"); } dlg->Delete(); } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::LoadDefOrgDialogCallback() { bool firstTime=!this->m_currState->isDefOrgSet(); vtkDefOrgViewerWithKWState* oldstate = m_currState; try{ InitializeState(this->MainWindow); } catch (...){ vtkKWMessageDialog::PopupMessage(this->GetApplication(), this->MainWindow,"Invalid DefOrg","Invalid DefOrg"); return; } if (firstTime && this->m_currState->isDefOrgSet()){ int polyPageCookie = this->MainWindow->GetMainNotebook()->AddPage("Spatial Object"); int volumeRenderPageCookie = this->MainWindow->GetMainNotebook()->AddPage("Volume Rendering"); CreateSpatialObjectFrame(polyPageCookie, this->MainWindow); CreateVolumeRenderingFrame(volumeRenderPageCookie, this->MainWindow); } this->RenderWidget->RemoveAllViewProps(); this->MainWindow->GetMainNotebook()->RemovePage("Organism"); int organismPageCookie = this->MainWindow->GetMainNotebook()->AddPage("Organism"); CreateOrganismDataFrame(organismPageCookie, this->MainWindow); delete oldstate; //_CrtDumpMemoryLeaks(); } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::LoadMeshDialogCallback() { StopSimulation(); const char *filename = this->LoadMeshButton->GetFileName(); if (filename){ if (0==vtksys::SystemTools::GetFilenameLastExtension(filename).compare(".byu")|| 0==vtksys::SystemTools::GetFilenameLastExtension(filename).compare(".BYU")) { std::string convertedFname = vtksys::SystemTools::GetFilenameWithoutLastExtension(filename); convertedFname=vtksys::SystemTools::GetCurrentWorkingDirectory()+convertedFname+".meta"; int errorFlag = BYUToMeta( filename, convertedFname ); if (errorFlag>=0){ this->GetCurrDefOrg()->SetMeshFileName(convertedFname.c_str()); } } else{ this->GetCurrDefOrg()->SetMeshFileName(filename); } RemoveActorsFromSOViewers(true); for (int i=0;iMaxNumberOfOutputItkSpatialObjects();i++){ itkScenePointer tempItkScenePtr = (this->GetCurrDefOrg()->m_OutputItkSpatialObjects[i]).theItkScene; tempItkScenePtr->Clear(); tempItkScenePtr->Modified(); this->m_currState->SetSOViewer(tempItkScenePtr, sov::VTKRenderer3D::New()); } this->GetCurrDefOrg()->PopulateItkScene(); SetScenesToSOViewers(true); AddActorsFromSOViewers(true); RenderSOViewers(); /*this->RenderWidget->ResetCamera(); this->RenderWidget->Render();*/ /* vtkUnstructuredGrid* vtkGrid = vtkUnstructuredGrid::New(); this->m_DefOrg->PopulateVtkUnstructuredGrid(vtkGrid); vtkDataSetMapper* meshMapper = vtkDataSetMapper::New(); meshMapper->SetInput( vtkGrid ); vtkActor* meshActor = vtkActor::New(); meshActor->SetMapper( meshMapper ); // TEMP: SET THE RGB VALUE OF THE MESH SURFACE HERE: meshActor->GetProperty()->SetColor( 0.3, 1.0, 0.4 ); // e.g. green this->RenderWidget->AddViewProp(meshActor); this->RenderWidget->ResetCamera(); this->RenderWidget->Render(); */ if (this->GetCurrDefOrg()->IsAllInputFilesSet()) { this->InitOrganismButton->EnabledOn(); this->SimulateOrganismButton->EnabledOff(); this->StepOrganismButton->EnabledOff(); } } } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::CreateVolumeRenderingFrame(int volumeRenderingPageCookie, vtkKWWindow* win){ vtkKWApplication *app = this->GetApplication(); vtkKWFrameWithLabel* vpw_frame = vtkKWFrameWithLabel::New(); vpw_frame->SetParent(win->GetMainNotebook()->GetFrame(volumeRenderingPageCookie)); vpw_frame->Create(); vpw_frame->SetLabelText("Volume Rendering"); app->Script("pack %s -side top -anchor nw -expand n -fill x -pady 2", vpw_frame->GetWidgetName()); //Create the array of volume renderers RenderVolume = new vtkVolume*[GetCurrDefOrg()->MaxNumberOfOutputImages()]; VolumeRenderToggles = new int[GetCurrDefOrg()->MaxNumberOfOutputImages()]; //Add a combo box to select which window to control vtkKWComboBox *volumeRenderControlBox = vtkKWComboBox::New(); volumeRenderControlBox->SetParent(vpw_frame->GetFrame()); volumeRenderControlBox->Create(); volumeRenderControlBox->SetBalloonHelpString("Select the window to control"); for(int i=0; i< GetCurrDefOrg()->MaxNumberOfOutputImages();i++) { if(GetCurrDefOrg()->m_OutputImages[i].dimension ==3) { if(i==0) { volumeRenderControlBox->AddValue("Main Window"); } else { volumeRenderControlBox->AddValue(viewerWindows[i-1]->GetTitle()); } VolumeRenderToggles[i]=0; } } this->OutputImageOffset=0; app->Script( "pack %s -side top -anchor nw -expand n -padx 2 -pady 2", volumeRenderControlBox->GetWidgetName()); volumeRenderControlBox->SetCommand(this,"SetVolumeRenderingControlBoxCallback"); VolumeRenderingCheckButton = vtkKWCheckButton::New(); VolumeRenderingCheckButton->SetParent(vpw_frame->GetFrame()); VolumeRenderingCheckButton->Create(); VolumeRenderingCheckButton->SetText("Perform Volume Rendering"); VolumeRenderingCheckButton->SetCommand(this,"SetVolumeRenderingCallback"); app->Script( "pack %s -side top -anchor nw -expand n -padx 2 -pady 2", VolumeRenderingCheckButton->GetWidgetName()); // Create a volume property widget vtkKWFrameWithScrollbar* vScrollBar_frame = vtkKWFrameWithScrollbar::New(); vScrollBar_frame->SetParent(win->GetMainNotebook()->GetFrame(volumeRenderingPageCookie)); vScrollBar_frame->Create(); app->Script("pack %s -side top -anchor nw -expand n -fill x -pady 2", vScrollBar_frame->GetWidgetName()); VRVolumePropertyWidget = vtkKWVolumePropertyWidget::New(); VRVolumePropertyWidget->SetVolumePropertyChangedCommand(this->RenderWidget, "Render"); //VRVolumePropertyWidget->SetVolumePropertyChangedCommand(this,"SetVolumePropertyChangedCallback"); VRVolumePropertyWidget->SetParent(vScrollBar_frame->GetFrame()); VRVolumePropertyWidget->Create(); app->Script("pack %s -side top -anchor nw -expand n -fill x -pady 2", VRVolumePropertyWidget->GetWidgetName()); } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::SetVolumeRenderingControlBoxCallback(char * val) { for(int i=0; i< GetCurrDefOrg()->MaxNumberOfOutputImages();i++) { if(GetCurrDefOrg()->m_OutputImages[i].dimension ==3) { if(i==0) { if(~strcmp(val,"Main Window"))//If its the main window this->OutputImageOffset =i; } else { if(~strcmp(val,viewerWindows[i-1]->GetTitle()))//If its the right viewer window this->OutputImageOffset =i; } } } VolumeRenderingCheckButton->SetSelectedState(VolumeRenderToggles[this->OutputImageOffset]); } //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::SetVolumeRenderingCallback(int id) { if (!this->m_currState->isDefOrgSet()) return; if (id==1) //changed to check { VolumeRenderToggles[this->OutputImageOffset] = 1; vtkVolumeRayCastMapper* volumeMapper = vtkVolumeRayCastMapper::New(); vtkVolumeRayCastCompositeFunction* compositeFunction = vtkVolumeRayCastCompositeFunction::New(); volumeMapper->SetVolumeRayCastFunction( compositeFunction ); volumeMapper->SetInput( ((GetCurrDefOrg()->m_OutputImages[this->OutputImageOffset]).theImageVolume)->GetOutput() ); RenderVolume[this->OutputImageOffset] = vtkVolume::New(); RenderVolume[this->OutputImageOffset]->SetMapper( volumeMapper ); RenderVolume[this->OutputImageOffset]->SetProperty( this->VRVolumePropertyWidget->GetVolumeProperty() ); RenderVolume[this->OutputImageOffset]->VisibilityOn(); this->m_currState->GetImageViewerRenderWidget((GetCurrDefOrg()->m_OutputImages[this->OutputImageOffset]).theImageVolume)->GetRenderer()->AddVolume(RenderVolume[this->OutputImageOffset]); this->m_currState->GetImageViewerRenderWidget((GetCurrDefOrg()->m_OutputImages[this->OutputImageOffset]).theImageVolume)->Render(); } else{ VolumeRenderToggles[this->OutputImageOffset] = 0; this->m_currState->GetImageViewerRenderWidget((GetCurrDefOrg()->m_OutputImages[this->OutputImageOffset]).theImageVolume)->GetRenderer()->RemoveVolume(RenderVolume[this->OutputImageOffset]); RenderVolume[this->OutputImageOffset]->Delete(); this->m_currState->GetImageViewerRenderWidget((GetCurrDefOrg()->m_OutputImages[this->OutputImageOffset]).theImageVolume)->Render(); } } /*void vtkDefOrgViewerWithKW::SetVolumePropertyChangedCallback(){ this->RenderWidget->Render(); }*/ //---------------------------------------------------------------------------- void vtkDefOrgViewerWithKW::SetupImageViewerPipeline(){ vtkImageImport* tempVtkImporter = (GetCurrDefOrg()->m_OutputImages[0]).theImageVolume; // Use the render window and renderer of the renderwidget this->m_currState->GetCurrentImageViewer()->SetRenderWindow(this->RenderWidget->GetRenderWindow()); this->m_currState->GetCurrentImageViewer()->SetRenderer(this->RenderWidget->GetRenderer()); this->m_currState->GetCurrentImageViewer()->SetInput(tempVtkImporter->GetOutput()); //this->m_currState->GetCurrentImageViewer()->SetupInteractor(this->RenderWidget->GetRenderWindow()->GetInteractor()); this->UpdateSliceScale(); // Reset the window/level and the camera double *range = tempVtkImporter->GetOutput()->GetScalarRange(); this->m_currState->GetCurrentImageViewer()->SetColorWindow(range[1] - range[0]); this->m_currState->GetCurrentImageViewer()->SetColorLevel(0.5 * (range[1] + range[0])); // The corner annotation has the ability to parse "tags" and fill // them with information gathered from other objects. // For example, let's display the slice and window/level in one corner // by connecting the corner annotation to our image actor and // image mapper vtkCornerAnnotation *ca = this->RenderWidget->GetCornerAnnotation(); ca->SetImageActor(this->m_currState->GetCurrentImageViewer()->GetImageActor()); ca->SetWindowLevel(this->m_currState->GetCurrentImageViewer()->GetWindowLevel()); ca->SetText(2, ""); ca->SetText(3, "\n"); // Create a volume property and assign it // We need color tfuncs, opacity, and gradient vtkVolumeProperty* VRVolumeProperty = vtkVolumeProperty::New(); VRVolumeProperty->SetIndependentComponents(1); vtkColorTransferFunction *vpw_cfun = vtkColorTransferFunction::New(); vpw_cfun->SetColorSpaceToHSV(); vpw_cfun->AddHSVSegment(0.0, 0.2, 1.0, 1.0, 255.0, 0.8, 1.0, 1.0); vtkPiecewiseFunction *vpw_ofun = vtkPiecewiseFunction::New(); vpw_ofun->AddSegment(range[0], 0.2, range[1], 0.8); vpw_ofun->AddSegment((range[1] + range[0])/3, 0.9, (range[1] + range[0])*2/3, 0.1); vtkPiecewiseFunction *vpw_gfun = vtkPiecewiseFunction::New(); vpw_gfun->AddSegment(range[0], 0.2, range[1], 0.4); VRVolumeProperty->SetColor(0, vpw_cfun); VRVolumeProperty->SetScalarOpacity(0, vpw_ofun); VRVolumeProperty->SetGradientOpacity(0, vpw_gfun); VRVolumePropertyWidget->SetVolumeProperty(VRVolumeProperty); VRVolumePropertyWidget->SetWindowLevel(128, 128); //vpw->MergeScalarOpacityAndColorEditors(); VRVolumeProperty->Delete(); vpw_cfun->Delete(); vpw_ofun->Delete(); vpw_gfun->Delete(); }