void VtkVisPipelineView::addColorTable() { VtkVisPipelineItem* item ( static_cast<VtkVisPipelineItem*>(static_cast<VtkVisPipeline*>(this->model())-> getItem(this->selectionModel()->currentIndex())) ); const QString array_name = item->GetActiveAttribute(); QSettings settings; QString filename = QFileDialog::getOpenFileName(this, "Select color table", settings.value("lastOpenedLutFileDirectory"). toString(), "Color table files (*.xml);;"); QFileInfo fi(filename); if (fi.suffix().toLower() == "xml") { VtkVisPointSetItem* pointSetItem = dynamic_cast<VtkVisPointSetItem*>(item); if (pointSetItem) { VtkAlgorithmProperties* props = pointSetItem->getVtkProperties(); if (props) { props->SetLookUpTable(array_name, filename); item->SetActiveAttribute(array_name); emit requestViewUpdate(); } } else QMessageBox::warning(NULL, "Color lookup table could not be applied.", "Color lookup tables can only be applied to VtkVisPointSetItem."); QDir dir = QDir(filename); settings.setValue("lastOpenedLutFileDirectory", dir.absolutePath()); } }
void VtkVisImageItem::Initialize(vtkRenderer* renderer) { vtkImageAlgorithm* img = dynamic_cast<vtkImageAlgorithm*>(_algorithm); img->Update(); //VtkGeoImageSource* img = dynamic_cast<VtkGeoImageSource*>(_algorithm); double origin[3]; double spacing[3]; double range[2]; img->GetOutput()->GetOrigin(origin); img->GetOutput()->GetSpacing(spacing); //img->getRange(range); img->GetOutput()->GetPointData()->GetScalars()->GetRange(range); vtkImageShiftScale* scale = vtkImageShiftScale::New(); scale->SetOutputScalarTypeToUnsignedChar(); scale->SetInputConnection(img->GetOutputPort()); scale->SetShift(-range[0]); scale->SetScale(255.0/(range[1]-range[0])); _transformFilter = vtkImageChangeInformation::New(); _transformFilter->SetInputConnection(scale->GetOutputPort()); //double origin[3]; //img->getOrigin(origin); //double spacing = img->getSpacing(); //_transformFilter->SetOutputOrigin(origin2); //_transformFilter->SetOutputSpacing(spacing2); _transformFilter->Update(); _renderer = renderer; // Use a special vtkImageActor instead of vtkActor vtkImageActor* imageActor = vtkImageActor::New(); imageActor->SetInput(_transformFilter->GetOutput()); _actor = imageActor; _renderer->AddActor(_actor); // Set pre-set properties VtkAlgorithmProperties* vtkProps = dynamic_cast<VtkAlgorithmProperties*>(_algorithm); if (vtkProps) setVtkProperties(vtkProps); VtkVisPipelineItem* parentItem = dynamic_cast<VtkVisPipelineItem*>(this->parentItem()); while (parentItem) { VtkAlgorithmProperties* parentProps = dynamic_cast<VtkAlgorithmProperties*>(parentItem->algorithm()); if (parentProps) { VtkAlgorithmProperties* newProps = new VtkAlgorithmProperties(); newProps->SetScalarVisibility(parentProps->GetScalarVisibility()); newProps->SetTexture(parentProps->GetTexture()); setVtkProperties(newProps); vtkProps = newProps; parentItem = NULL; } else parentItem = dynamic_cast<VtkVisPipelineItem*>(parentItem->parentItem()); } // Set active scalar to the desired one from VtkAlgorithmProperties // or to match those of the parent. if (vtkProps) { if (vtkProps->GetActiveAttribute().length() > 0) this->SetActiveAttribute(vtkProps->GetActiveAttribute()); else { VtkVisPipelineItem* visParentItem = dynamic_cast<VtkVisPipelineItem*>(this->parentItem()); if (visParentItem) this->SetActiveAttribute(visParentItem->GetActiveAttribute()); if (vtkProps->GetTexture() != NULL) this->SetActiveAttribute("Solid Color"); } } }