#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 #include #include #include #include #include #include #include #include //---------------------------------------------------------------------------- vtkStandardNewMacro( vtkKWMeshTools ); vtkCxxRevisionMacro( vtkKWMeshTools, "$Revision: 1.0 $"); //---------------------------------------------------------------------------- vtkKWMeshTools::vtkKWMeshTools() { this->ButtonProject = vtkKWPushButtonWithLabel::New(); this->ButtonCrop = vtkKWPushButtonWithLabel::New(); this->ButtonColorByVectors = vtkKWPushButtonWithLabel::New(); this->ButtonColorByTensors = vtkKWPushButtonWithLabel::New(); this->ButtonTransform = vtkKWPushButtonWithLabel::New(); this->VectorManager = vtkVectorVisuManager::New(); this->FiberManager = vtkFibersManager::New(); this->TensorManager = vtkTensorVisuManager::New(); } //---------------------------------------------------------------------------- vtkKWMeshTools::~vtkKWMeshTools() { this->ButtonProject->Delete(); this->ButtonCrop->Delete(); this->ButtonColorByVectors->Delete(); this->ButtonColorByTensors->Delete(); this->ButtonTransform->Delete(); this->VectorManager->Delete(); this->FiberManager->Delete(); this->TensorManager->Delete(); } //---------------------------------------------------------------------------- void vtkKWMeshTools::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->SetLabelText ("Mesh Tools"); this->CreateButtons(); // Update according to the current metadataset this->Update(); // Pack this->Pack(); } //---------------------------------------------------------------------------- void vtkKWMeshTools::CreateButtons() { this->ButtonProject->SetParent(this); this->ButtonProject->Create(); this->ButtonProject->GetWidget()->SetImageToPixels(image_projectdataset, image_projectdataset_width, image_projectdataset_height, image_projectdataset_pixel_size, image_projectdataset_length); this->ButtonProject->GetWidget()->SetCommand(this, "ButtonProjectCallBack"); this->ButtonProject->GetWidget()->SetBalloonHelpString("Project DataSet in 2D"); this->ButtonProject->SetLabelText("Project Dataset"); this->ButtonProject->SetLabelPositionToRight(); this->ButtonCrop->SetParent(this); this->ButtonCrop->Create(); this->ButtonCrop->GetWidget()->SetImageToPixels(image_cropdataset, image_cropdataset_width, image_cropdataset_height, image_cropdataset_pixel_size, image_cropdataset_length); this->ButtonCrop->GetWidget()->SetCommand(this, "ButtonCropCallBack"); this->ButtonCrop->GetWidget()->SetBalloonHelpString("Crop the dataset with a box"); this->ButtonCrop->SetLabelText("Crop Dataset"); this->ButtonCrop->SetLabelPositionToRight(); this->ButtonColorByVectors->SetParent(this); this->ButtonColorByVectors->Create(); this->ButtonColorByVectors->GetWidget()->SetImageToPixels(image_processvectors, image_processvectors_width, image_processvectors_height, image_processvectors_pixel_size, image_processvectors_length); this->ButtonColorByVectors->GetWidget()->SetCommand(this, "ButtonColorByVectorsCallBack"); this->ButtonColorByVectors->GetWidget()->SetBalloonHelpString("color by the vectors..."); this->ButtonColorByVectors->SetLabelText("See Vectors"); this->ButtonColorByVectors->SetLabelPositionToRight(); this->ButtonColorByTensors->SetParent(this); this->ButtonColorByTensors->Create(); this->ButtonColorByTensors->GetWidget()->SetImageToPixels(image_processvectors, image_processvectors_width, image_processvectors_height, image_processvectors_pixel_size, image_processvectors_length); this->ButtonColorByTensors->GetWidget()->SetCommand(this, "ButtonColorByTensorsCallBack"); this->ButtonColorByTensors->GetWidget()->SetBalloonHelpString("color by the tensors..."); this->ButtonColorByTensors->SetLabelText("See Tensors"); this->ButtonColorByTensors->SetLabelPositionToRight(); this->ButtonTransform->SetParent(this); this->ButtonTransform->Create(); this->ButtonTransform->GetWidget()->SetImageToPixels(image_movedataset, image_movedataset_width, image_movedataset_height, image_movedataset_pixel_size, image_movedataset_length); this->ButtonTransform->GetWidget()->SetCommand(this, "ButtonTransformCallBack"); this->ButtonTransform->GetWidget()->SetBalloonHelpString("Move the dataset in the 3D view..."); this->ButtonTransform->SetLabelText("Move Dataset"); this->ButtonTransform->SetLabelPositionToRight(); } //---------------------------------------------------------------------------- void vtkKWMeshTools::Pack() { if (this->ButtonProject->IsCreated()) { this->Script( "grid %s -sticky nw -column 0 -row 0 -padx 5 -pady 5", this->ButtonProject->GetWidgetName()); } if (this->ButtonCrop->IsCreated()) { this->Script( "grid %s -sticky nw -column 0 -row 1 -padx 5 -pady 5", this->ButtonCrop->GetWidgetName()); } // if (this->ButtonColorByVectors->IsCreated()) // { // this->Script( "grid %s -sticky nw -column 1 -row 0 -padx 5 -pady 5", // this->ButtonColorByVectors->GetWidgetName()); // } // if (this->ButtonColorByTensors->IsCreated()) // { // this->Script( "grid %s -sticky nw -column 2 -row 0 -padx 5 -pady 5", // this->ButtonColorByTensors->GetWidgetName()); // } if (this->ButtonTransform->IsCreated()) { this->Script( "grid %s -sticky nw -column 0 -row 2 -padx 5 -pady 5", this->ButtonTransform->GetWidgetName()); } this->Script("grid rowconfigure %s 0 -weight 1", this->GetWidgetName()); this->Script("grid rowconfigure %s 1 -weight 1", this->GetWidgetName()); this->Script("grid rowconfigure %s 2 -weight 1", this->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()); // this->Script("grid columnconfigure %s 3 -weight 1", this->GetWidgetName()); } void vtkKWMeshTools::ButtonColorByVectorsCallBack() { if (!this->MetaDataSet || !this->MetaDataSet->GetDataSet() || ( !this->MetaDataSet->GetDataSet()->GetPointData()->GetVectors() && !this->MetaDataSet->GetDataSet()->GetCellData()->GetVectors()) || !this->ParentObject) return; vtkKWPageView* page = this->ParentObject->GetPage(this->MetaDataSet->GetTag()); if (!page) return; vtkProperty* property = vtkProperty::SafeDownCast (this->MetaDataSet->GetProperty()); if (property) property->SetOpacity(0.15); this->VectorManager->SetRenderWindowInteractor (page->GetView4()->GetRenderWindowInteractor()); this->VectorManager->SetInput(this->MetaDataSet->GetDataSet()); this->VectorManager->SetBoxWidget (true); std::vector list = page->AddPolyData (this->VectorManager->GetOutput2(), NULL, 1.5); for (unsigned int i=0; iSetProperty(this->VectorManager->GetActor()->GetProperty()); } page->GetView4()->AddActor (this->VectorManager->GetActor()); page->Render(); } void vtkKWMeshTools::ButtonColorByTensorsCallBack() { } void vtkKWMeshTools::ButtonProjectCallBack() { if (!this->MetaDataSet || !this->MetaDataSet->GetDataSet() || !this->ParentObject) return; vtkKWPageView* page = this->ParentObject->GetPage(this->MetaDataSet->GetTag()); if (!page) return; if (page->GetView1()->GetImage()) { vtkKWMessageDialog* dialog = vtkKWMessageDialog::New(); dialog->SetApplication (this->GetApplication()); dialog->SetStyleToYesNo (); dialog->Create(); dialog->SetTitle("Warning !"); dialog->SetText("There is already an image, \nOverride it ?"); if ( dialog->Invoke () != 1 ) { dialog->Delete(); return; } dialog->Delete(); } vtkDatasetToImageGenerator* imagegenerator = vtkDatasetToImageGenerator::New(); imagegenerator->SetInput (this->MetaDataSet->GetDataSet()); imagegenerator->Update(); page->AddDataSet(imagegenerator->GetOutput(), NULL); page->GetView4()->SetVisibility (false); std::vector list = page->AddDataSet(this->MetaDataSet->GetDataSet(), vtkProperty::SafeDownCast (this->MetaDataSet->GetProperty())); for (unsigned int j=0; jMetaDataSet->AddActor (list[j]); page->GetView4()->SyncResetPosition(); page->GetView4()->SyncResetZoom(); page->Render(); imagegenerator->Delete(); } void vtkKWMeshTools::ButtonCropCallBack() { if (!this->MetaDataSet || !this->MetaDataSet->GetDataSet() || !this->ParentObject) return; vtkKWPageView* page = this->ParentObject->GetPage(this->MetaDataSet->GetTag()); if (!page) return; this->VectorManager->SetRenderWindowInteractor (page->GetView4()->GetRenderWindowInteractor()); this->VectorManager->SetInput(this->MetaDataSet->GetDataSet()); this->VectorManager->SetBoxWidget (true); page->RemoveDataSet(this->MetaDataSet->GetDataSet()); //this->MetaDataSet->SetDataSet(this->VectorManager->GetOutput()); //page->AddDataSet(this->MetaDataSet->GetDataSet(), vtkProperty::SafeDownCast(this->MetaDataSet->GetProperty())); std::vector list = page->AddDataSet (this->VectorManager->GetOutput(), vtkProperty::SafeDownCast (this->MetaDataSet->GetProperty())); for (unsigned int j=0; jMetaDataSet->AddActor (list[j]); page->Render(); } void vtkKWMeshTools::ButtonTransformCallBack() { if (!this->MetaDataSet || !this->MetaDataSet->GetDataSet() || !this->ParentObject) return; vtkKWPageView* page = this->ParentObject->GetPage(this->MetaDataSet->GetTag()); if (!page) return; vtkActor* actor = page->GetView4()->GetDataSetActor(this->MetaDataSet->GetDataSet()); vtkPointSet* pointset = vtkPointSet::SafeDownCast (this->MetaDataSet->GetDataSet()); if (!pointset || !actor) { std::cout<<"returning home"<GetPoints(); double position1[4] = {0,0,0, 1}; double position2[4] = {0,0,0, 1}; vtkMatrix4x4* matrix = actor->GetMatrix(); vtkPoints* newpoints = vtkPoints::New(); newpoints->SetNumberOfPoints(points->GetNumberOfPoints()); int i=0; while(iGetNumberOfPoints()) { position1[0] = points->GetPoint (i)[0]; position1[1] = points->GetPoint (i)[1]; position1[2] = points->GetPoint (i)[2]; matrix->MultiplyPoint(position1, position2); newpoints->SetPoint (i, position2[0], position2[1], position2[2]); i++; } pointset->SetPoints (newpoints); newpoints->Delete(); this->MetaDataSet->GetDataSet()->Modified(); this->MetaDataSet->Modified(); matrix->Identity(); page->Render(); }