#include #include "vtkObjectFactory.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include //---------------------------------------------------------------------------- vtkStandardNewMacro( vtkKWLandmarkManagerWidget ); vtkCxxRevisionMacro( vtkKWLandmarkManagerWidget, "$Revision: 1.0 $"); //---------------------------------------------------------------------------- vtkKWLandmarkManagerWidget::vtkKWLandmarkManagerWidget() { this->ButtonAdd = vtkKWPushButton::New(); this->ButtonDelete = vtkKWPushButton::New(); this->LandmarkListBox = vtkKWComboBox::New(); this->HSVColorSelector = vtkKWHSVColorSelector::New(); this->ScalingScale = vtkKWScale::New(); this->LandmarkManager = NULL; this->LandmarkChangedCommand = NULL; } //---------------------------------------------------------------------------- vtkKWLandmarkManagerWidget::~vtkKWLandmarkManagerWidget() { std::cout<<"deleting l-manager-widget"<ButtonAdd->Delete(); this->ButtonDelete->Delete(); this->LandmarkListBox->Delete(); this->HSVColorSelector->Delete(); this->ScalingScale->Delete(); if (this->LandmarkManager) this->LandmarkManager->Delete(); } //---------------------------------------------------------------------------- void vtkKWLandmarkManagerWidget::InvokeObjectMethodCommand(const char *command) { this->Superclass::InvokeObjectMethodCommand(command); } //---------------------------------------------------------------------------- void vtkKWLandmarkManagerWidget::SetLandmarkChangedCommand( vtkObject *object, const char *method) { this->SetObjectMethodCommand( &this->LandmarkChangedCommand, object, method); } //---------------------------------------------------------------------------- void vtkKWLandmarkManagerWidget::InvokeLandmarkChangedCommand() { this->InvokeObjectMethodCommand(this->LandmarkChangedCommand); } //---------------------------------------------------------------------------- void vtkKWLandmarkManagerWidget::CreateWidget() { // Check if already created if (this->IsCreated()) { vtkErrorMacro("class already created"); return; } // Call the superclass to create the whole widget this->Superclass::CreateWidget(); this->CreateButtons(); // Update according to the current metadataset this->Update(); // Pack this->Pack(); } //---------------------------------------------------------------------------- void vtkKWLandmarkManagerWidget::CreateButtons() { this->ButtonAdd->SetParent(this); this->ButtonAdd->Create(); this->ButtonAdd->SetImageToPixels(image_loadattributes, image_loadattributes_width, image_loadattributes_height, image_loadattributes_pixel_size, image_loadattributes_length); this->ButtonAdd->SetCommand(this, "ButtonAddCallback"); this->ButtonAdd->SetBalloonHelpString("Add a landmark\nCreates a landmark in the visible views."); this->ButtonDelete->SetParent(this); this->ButtonDelete->Create(); this->ButtonDelete->SetImageToPixels(image_applyattributes, image_applyattributes_width, image_applyattributes_height, image_applyattributes_pixel_size, image_applyattributes_length); this->ButtonDelete->SetCommand(this, "ButtonDeleteCallback"); this->ButtonDelete->SetBalloonHelpString("color by the selected data..."); this->HSVColorSelector->SetParent(this); this->HSVColorSelector->Create(); this->HSVColorSelector->SetHueSatWheelRadius (20); this->HSVColorSelector->SetBalloonHelpString("Color"); this->HSVColorSelector->SetSelectionChangingCommand (this, "ColorChangingCallback"); this->HSVColorSelector->InvokeCommandsWithRGBOn(); this->ScalingScale->SetParent (this); this->ScalingScale->Create(); this->ScalingScale->SetOrientationToHorizontal(); this->ScalingScale->SetLabelText("Scaling:"); this->ScalingScale->SetRange (0,20); this->ScalingScale->SetResolution (1); this->ScalingScale->SetLength (95); this->ScalingScale->SetSliderLength (10); this->ScalingScale->SetActiveBackgroundColor (0.9,0.2,0.4); this->ScalingScale->SetBalloonHelpString("Scaling"); this->ScalingScale->SetValue (5); this->ScalingScale->SetCommand (this, "ScalingChangingCallback"); this->LandmarkListBox->SetParent (this); this->LandmarkListBox->Create(); this->LandmarkListBox->SetWidth (20); this->LandmarkListBox->ReadOnlyOn(); this->LandmarkListBox->SetValue("No Landmark"); this->LandmarkListBox->SetCommand(this, "SelectionChangedCallback"); } //---------------------------------------------------------------------------- void vtkKWLandmarkManagerWidget::PropertyChangeOff() { this->Script ("grid remove %s", this->HSVColorSelector->GetWidgetName()); this->Script ("grid remove %s", this->ScalingScale->GetWidgetName()); } //---------------------------------------------------------------------------- void vtkKWLandmarkManagerWidget::Pack() { if (this->LandmarkListBox->IsCreated()) { this->Script( "grid %s -sticky nw -column 0 -row 0 -columnspan 2 -padx 5 -pady 20", this->LandmarkListBox->GetWidgetName()); } if (this->ButtonAdd->IsCreated()) { this->Script( "grid %s -sticky nw -column 2 -row 0 -padx 5 -pady 20", this->ButtonAdd->GetWidgetName()); } if (this->HSVColorSelector->IsCreated()) { this->Script( "grid %s -sticky nw -column 0 -row 1 -padx 5 -pady 5", this->HSVColorSelector->GetWidgetName()); } if (this->ScalingScale->IsCreated()) { this->Script( "grid %s -sticky nw -column 1 -row 1 -padx 5 -pady 5", this->ScalingScale->GetWidgetName()); } if (this->ButtonDelete->IsCreated()) { this->Script( "grid %s -sticky nw -column 2 -row 1 -padx 5 -pady 5", this->ButtonDelete->GetWidgetName()); } this->Script("grid columnconfigure %s 0 -weight 1", this->GetWidgetName()); this->Script("grid columnconfigure %s 1 -weight 1", this->GetWidgetName()); this->Script("grid columnconfigure %s 2 -weight 1", this->GetWidgetName()); } //---------------------------------------------------------------------------- void vtkKWLandmarkManagerWidget::Update() { if (!this->LandmarkManager) return; this->LandmarkListBox->DeleteAllValues (); for (int i=0; iLandmarkManager->GetNumberOfLandmarks(); i++) { std::ostringstream os; os<LandmarkManager->GetLandmark(i)->GetName(); this->LandmarkListBox->AddValue (os.str().c_str()); } if (this->LandmarkManager->GetCurrentLandmark ()) { vtkProperty* prop = this->LandmarkManager->GetCurrentLandmark ()->GetProperty(); this->HSVColorSelector->SetSelectedColor (vtkMath::RGBToHSV (prop->GetColor())); this->ScalingScale->SetValue ((double)(prop->GetLineWidth())); this->LandmarkListBox->SetValue (this->LandmarkManager->GetCurrentLandmark ()->GetName()); } } void vtkKWLandmarkManagerWidget::ScalingChangingCallback(double op) { if (!this->LandmarkManager || !this->LandmarkManager->GetCurrentLandmark ()) return; vtkProperty* prop = this->LandmarkManager->GetCurrentLandmark ()->GetProperty(); prop->SetLineWidth(op); prop->SetPointSize(op); this->InvokeLandmarkChangedCommand(); } void vtkKWLandmarkManagerWidget::ColorChangingCallback(double r, double g, double b) { if (!this->LandmarkManager || !this->LandmarkManager->GetCurrentLandmark ()) return; vtkProperty* prop = this->LandmarkManager->GetCurrentLandmark ()->GetProperty(); prop->SetColor(r, g, b); this->InvokeLandmarkChangedCommand(); } void vtkKWLandmarkManagerWidget::SelectionChangedCallback (const char* value) { std::string name = this->LandmarkListBox->GetValue(); this->LandmarkManager->SelectLandmark(name.c_str()); this->InvokeLandmarkChangedCommand(); } void vtkKWLandmarkManagerWidget::ButtonAddCallback() { if (!this->LandmarkManager) return; this->LandmarkManager->AddLandmark(); this->Update(); this->InvokeLandmarkChangedCommand(); } //---------------------------------------------------------------------------- void vtkKWLandmarkManagerWidget::ButtonDeleteCallback() { const char* name = this->LandmarkListBox->GetValue(); this->LandmarkManager->RemoveLandmark (name); this->Update(); this->InvokeLandmarkChangedCommand(); }