示例#1
0
void VtkVisTabWidget::on_diffuseColorPickerButton_colorPicked( QColor color )
{
	static_cast<vtkActor*>(_item->actor())->GetProperty()->SetDiffuseColor(
	        color.redF(), color.greenF(), color.blueF());

	emit requestViewUpdate();
}
示例#2
0
void VtkVisTabWidget::on_scaleZ_textChanged(const QString &text)
{
	bool ok = true;
	double scale = text.toDouble(&ok);

	// If z scale becomes zero, the object becomes invisible
	if (ok && scale != 0.0)
	{
		_item->setScale(1.0, 1.0, scale);

		for (int i = 0; i < _item->childCount(); i++)
		{
			VtkVisPipelineItem* childItem = _item->child(i);
			if (childItem)
			{
				VtkCompositeColorByHeightFilter* colorFilter =
				        dynamic_cast<VtkCompositeColorByHeightFilter*>
				        (childItem->compositeFilter());
				if (colorFilter)
					VtkColorByHeightFilter::SafeDownCast(
					        colorFilter->GetOutputAlgorithm())->
					SetTableRangeScaling(scale);
			}
		}

		emit requestViewUpdate();
	}
}
示例#3
0
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 VtkCustomInteractorStyle::OnRightButtonDown()
{
    if (!_data)
        return vtkInteractorStyleTrackballCamera::OnRightButtonDown();

    if (_alternateMouseActions)
    {
        // Get the location of the click (in window coordinates)
        int* pos = this->GetInteractor()->GetEventPosition();

        vtkSmartPointer<vtkCellPicker> picker =
                vtkSmartPointer<vtkCellPicker>::New();
        picker->SetTolerance(0.0005);

        // Pick from this location.
        picker->Pick(pos[0], pos[1], 0, this->GetDefaultRenderer());

        double* worldPosition = picker->GetPickPosition();
        INFO("Cell id is: %d", picker->GetCellId());

        if(picker->GetCellId() != -1)
        {
            vtkRenderer* renderer =
                    this->Interactor->GetRenderWindow()->GetRenderers()->
                    GetFirstRenderer();
            vtkCamera* cam = renderer->GetActiveCamera();
            cam->SetFocalPoint(worldPosition);
            emit requestViewUpdate();
        }
    }
    else
        // Forward events
        vtkInteractorStyleTrackballCamera::OnRightButtonDown();
}
示例#5
0
VtkVisTabWidget::VtkVisTabWidget( QWidget* parent /*= 0*/ )
	: QWidget(parent), _item(nullptr)
{
	setupUi(this);

	this->scaleZ->setValidator(new QDoubleValidator(0, 100, 8, this));

	this->transX->setValidator(new QDoubleValidator(this));
	this->transY->setValidator(new QDoubleValidator(this));
	this->transZ->setValidator(new QDoubleValidator(this));

	connect(this->vtkVisPipelineView, SIGNAL(requestViewUpdate()),
	        this, SIGNAL(requestViewUpdate()));

	connect(this->vtkVisPipelineView, SIGNAL(itemSelected(VtkVisPipelineItem*)),
	        this, SLOT(setActiveItem(VtkVisPipelineItem*)));

	connect(this->activeScalarComboBox, SIGNAL(currentIndexChanged(const QString &)),
	        this, SLOT(SetActiveAttributeOnItem(const QString &)));
}
示例#6
0
void VtkVisTabWidget::translateItem()
{
	bool okX(true), okY(true), okZ(true);
	double trans[3];

	trans[0] = transX->text().toDouble(&okX);
	trans[1] = transY->text().toDouble(&okY);
	trans[2] = transZ->text().toDouble(&okZ);

	if (okX && okY && okZ)
	{
		_item->setTranslation(trans[0], trans[1], trans[2]);
		emit requestViewUpdate();
	}
}
示例#7
0
void VtkVisTabWidget::on_visibleEdgesCheckBox_stateChanged( int state )
{
	if (state == Qt::Checked)
	{
		static_cast<vtkActor*>(_item->actor())->GetProperty()->SetEdgeVisibility(1);
		edgeColorPickerButton->setEnabled(true);
	}
	else
	{
		static_cast<vtkActor*>(_item->actor())->GetProperty()->SetEdgeVisibility(0);
		edgeColorPickerButton->setEnabled(false);
	}

	emit requestViewUpdate();
}
示例#8
0
void VtkVisTabWidget::setActiveItem( VtkVisPipelineItem* item )
{
	if (item)
	{
		_item = item;
		transformTabWidget->setEnabled(true);

		vtkTransformFilter* transform_filter = dynamic_cast<vtkTransformFilter*>(_item->transformFilter());
		if (transform_filter) // if data set
		{
			actorPropertiesGroupBox->setEnabled(true);
			vtkProperty* vtkProps = static_cast<vtkActor*>(_item->actor())->GetProperty();
			diffuseColorPickerButton->setColor(vtkProps->GetDiffuseColor());
			visibleEdgesCheckBox->setChecked(vtkProps->GetEdgeVisibility());
			edgeColorPickerButton->setColor(vtkProps->GetEdgeColor());
			opacitySlider->setValue((int)(vtkProps->GetOpacity() * 100.0));

			vtkTransform* transform =
			        static_cast<vtkTransform*>(transform_filter->GetTransform());
			if (transform)
			{
				double scale[3];
				transform->GetScale(scale);
				double trans[3];
				transform->GetPosition(trans);

				//switch signals off for just filling in text-boxes after clicking on an item
				this->scaleZ->blockSignals(true);
				this->transX->blockSignals(true);
				this->transY->blockSignals(true);
				this->transZ->blockSignals(true);
				this->scaleZ->setText(QString::number(scale[2]));
				this->transX->setText(QString::number(trans[0] / scale[0]));
				this->transY->setText(QString::number(trans[1] / scale[1]));
				this->transZ->setText(QString::number(trans[2] / scale[2]));
				this->scaleZ->blockSignals(false);
				this->transX->blockSignals(false);
				this->transY->blockSignals(false);
				this->transZ->blockSignals(false);
				//switch signals back on
			}
			this->buildScalarArrayComboBox(_item);

			// Set to last active attribute
			QString activeAttribute = _item->GetActiveAttribute();
			if (activeAttribute.length() > 0)
				for (int i = 0; i < this->activeScalarComboBox->count(); i++)
				{
					QString itemText = this->activeScalarComboBox->itemText(i);
					if (itemText.compare(activeAttribute) == 0)
					{
						this->activeScalarComboBox->setCurrentIndex(i);
						break;
					}
				}
		}
		else // if image
		{
			const VtkVisImageItem* img = static_cast<VtkVisImageItem*>(_item);
			actorPropertiesGroupBox->setEnabled(false);
			vtkImageChangeInformation* transform = static_cast<vtkImageChangeInformation*>(img->transformFilter());
			double trans[3];
			transform->GetOriginTranslation(trans);
			this->transX->blockSignals(true);
			this->transY->blockSignals(true);
			this->transZ->blockSignals(true);
			this->transX->setText(QString::number(trans[0]));
			this->transY->setText(QString::number(trans[1]));
			this->transZ->setText(QString::number(trans[2]));
			this->transX->blockSignals(false);
			this->transY->blockSignals(false);
			this->transZ->blockSignals(false);
		}

		this->buildProportiesDialog(item);

		emit requestViewUpdate();
	}
	else
	{
		actorPropertiesGroupBox->setEnabled(false);
		transformTabWidget->setEnabled(false);
		this->activeScalarComboBox->clear();
	}
}
示例#9
0
void VtkVisTabWidget::buildProportiesDialog(VtkVisPipelineItem* item)
{
	QFormLayout* layout = static_cast<QFormLayout*>(this->scrollAreaWidgetContents->layout());
	while(layout->count())
		delete layout->takeAt(0)->widget();

	QMap<QString, QVariant>* propMap = NULL;
	QMap<QString, QList<QVariant> >* propVecMap = NULL;
	VtkAlgorithmProperties* algProps = NULL;

	// Retrieve algorithm properties
	if (item->compositeFilter())
	{
		algProps = item->compositeFilter();
		propMap = item->compositeFilter()->GetAlgorithmUserProperties();
		propVecMap = item->compositeFilter()->GetAlgorithmUserVectorProperties();
	}
	else
	{
		algProps = dynamic_cast<VtkAlgorithmProperties*>(item->algorithm());
		if (algProps)
		{
			propMap = algProps->GetAlgorithmUserProperties();
			propVecMap = algProps->GetAlgorithmUserVectorProperties();
		}
	}

	// Select appropriate GUI element and set connect for each property
	if (propMap && algProps)
	{
		QMapIterator<QString, QVariant> i(*propMap);
		while (i.hasNext())
		{
			i.next();
			QString key = i.key();
			QVariant value = i.value();

			VtkAlgorithmPropertyLineEdit* lineEdit;
			VtkAlgorithmPropertyCheckbox* checkbox;
			switch (value.type())
			{
			case QVariant::Double:
				lineEdit =
				        new VtkAlgorithmPropertyLineEdit(QString::number(
				                                                 value.toDouble()),
				                                         key, QVariant::Double,
				                                         algProps);
				connect(lineEdit, SIGNAL(editingFinished()), this,
				        SIGNAL(requestViewUpdate()));
				layout->addRow(key, lineEdit);
				break;

			case QVariant::Int:
				lineEdit =
				        new VtkAlgorithmPropertyLineEdit(QString::number(
				                                                 value.toInt()),
				                                         key, QVariant::Int,
				                                         algProps);
				connect(lineEdit, SIGNAL(editingFinished()), this,
				        SIGNAL(requestViewUpdate()));
				layout->addRow(key, lineEdit);
				break;

			case QVariant::Bool:
				checkbox = new VtkAlgorithmPropertyCheckbox(
				        value.toBool(), key, algProps);
				connect(checkbox, SIGNAL(stateChanged(int)), this,
				        SIGNAL(requestViewUpdate()));
				layout->addRow(key, checkbox);
				break;

			default:
				break;
			}
		}
	}
示例#10
0
void VtkVisTabWidget::on_opacitySlider_sliderMoved( int value )
{
	static_cast<vtkActor*>(_item->actor())->GetProperty()->SetOpacity(value / 100.0);
	emit requestViewUpdate();
}
示例#11
0
// From http://www.vtk.org/Wiki/VTK/Examples/Cxx/Picking/CellPicking
void VtkCustomInteractorStyle::OnLeftButtonDown()
{
    if (!_data)
        return vtkInteractorStyleTrackballCamera::OnLeftButtonDown();

    if (_alternateMouseActions)
    {
        // Get the location of the click (in window coordinates)
        int* pos = this->GetInteractor()->GetEventPosition();

        vtkSmartPointer<vtkCellPicker> picker =
                vtkSmartPointer<vtkCellPicker>::New();
        picker->SetTolerance(0.0005);

        // Pick from this location.
        picker->Pick(pos[0], pos[1], 0, this->GetDefaultRenderer());

        double* worldPosition = picker->GetPickPosition();
        INFO("Cell id is: %d", picker->GetCellId());

        if(picker->GetCellId() != -1)
        {
            INFO("Pick position is: %f %f %f", worldPosition[0], worldPosition[1], worldPosition[2]);

            vtkSmartPointer<vtkIdTypeArray> ids =
                    vtkSmartPointer<vtkIdTypeArray>::New();
            ids->SetNumberOfValues(1);
            ids->SetValue(0, picker->GetCellId());

            vtkSmartPointer<vtkSelectionNode> selectionNode =
                    vtkSmartPointer<vtkSelectionNode>::New();
            selectionNode->SetFieldType(vtkSelectionNode::CELL);
            selectionNode->SetContentType(vtkSelectionNode::INDICES);
            selectionNode->SetSelectionList(ids);

            vtkSmartPointer<vtkSelection> selection =
                    vtkSmartPointer<vtkSelection>::New();
            selection->AddNode(selectionNode);

            vtkSmartPointer<vtkExtractSelection> extractSelection =
                    vtkSmartPointer<vtkExtractSelection>::New();
            extractSelection->SetInputData(0, _data);
            extractSelection->SetInputData(1, selection);
            extractSelection->Update();

            // In selection
            vtkSmartPointer<vtkUnstructuredGrid> selected =
                    vtkSmartPointer<vtkUnstructuredGrid>::New();
            selected->ShallowCopy(extractSelection->GetOutput());

            INFO("There are %d points in the selection.", selected->GetNumberOfPoints());
            INFO("There are %d cells in the selection.", selected->GetNumberOfCells());

            // check if the underlying object is a mesh and if so, send a signal to the element model for display of information about the picked element.
            vtkAlgorithm* data_set = picker->GetActor()->GetMapper()->GetInputConnection(0, 0)->GetProducer()->GetInputConnection(0,0)->GetProducer();
            vtkUnstructuredGridAlgorithm* source = dynamic_cast<vtkUnstructuredGridAlgorithm*>(data_set);
            if (source)
                emit elementPicked(source, static_cast<unsigned>(picker->GetCellId()));
            else
                emit clearElementView();
            _selectedMapper->SetInputData(selected);

            this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->
            AddActor(_selectedActor);
            //_highlightActor = true;
        }
        else
            this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->
            RemoveActor(_selectedActor);
        emit requestViewUpdate();
    }
    else
        // Forward events
        vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}
示例#12
0
void VtkVisTabWidget::SetActiveAttributeOnItem( const QString &name )
{
    _item->SetActiveAttribute(name);
    emit requestViewUpdate();
}
示例#13
0
// From http://www.vtk.org/Wiki/VTK/Examples/Cxx/Picking/CellPicking
void VtkCustomInteractorStyle::OnLeftButtonDown()
{
	if (!Data)
		return vtkInteractorStyleTrackballCamera::OnLeftButtonDown();

	if (_alternateMouseActions)
	{
		// Get the location of the click (in window coordinates)
		int* pos = this->GetInteractor()->GetEventPosition();

		vtkSmartPointer<vtkCellPicker> picker =
		        vtkSmartPointer<vtkCellPicker>::New();
		picker->SetTolerance(0.0005);

		// Pick from this location.
		picker->Pick(pos[0], pos[1], 0, this->GetDefaultRenderer());

		double* worldPosition = picker->GetPickPosition();
		std::cout << "Cell id is: " << picker->GetCellId() << std::endl;

		if(picker->GetCellId() != -1)
		{
			std::cout << "Pick position is: " << worldPosition[0] << " " <<
			worldPosition[1]
			          << " " << worldPosition[2] << endl;

			vtkSmartPointer<vtkIdTypeArray> ids =
			        vtkSmartPointer<vtkIdTypeArray>::New();
			ids->SetNumberOfComponents(1);
			ids->InsertNextValue(picker->GetCellId());

			vtkSmartPointer<vtkSelectionNode> selectionNode =
			        vtkSmartPointer<vtkSelectionNode>::New();
			selectionNode->SetFieldType(vtkSelectionNode::CELL);
			selectionNode->SetContentType(vtkSelectionNode::INDICES);
			selectionNode->SetSelectionList(ids);

			vtkSmartPointer<vtkSelection> selection =
			        vtkSmartPointer<vtkSelection>::New();
			selection->AddNode(selectionNode);

			vtkSmartPointer<vtkExtractSelection> extractSelection =
			        vtkSmartPointer<vtkExtractSelection>::New();
			extractSelection->SetInput(0, this->Data);
			extractSelection->SetInput(1, selection);
			extractSelection->Update();

			// In selection
			vtkSmartPointer<vtkUnstructuredGrid> selected =
			        vtkSmartPointer<vtkUnstructuredGrid>::New();
			selected->ShallowCopy(extractSelection->GetOutput());

			std::cout << "There are " << selected->GetNumberOfPoints()
			          << " points in the selection." << std::endl;
			std::cout << "There are " << selected->GetNumberOfCells()
			          << " cells in the selection." << std::endl;

			// check if the underlying object is a mesh and if so, send a signal to the element model for display of information about the picked element.
			vtkAlgorithm* data_set =
			        picker->GetActor()->GetMapper()->GetInputConnection(0,
			                                                            0)->GetProducer()
			        ->GetInputConnection(0,0)->GetProducer();
			VtkMeshSource* source = dynamic_cast<VtkMeshSource*>(data_set);
			if (source)
				emit elementPicked(source->GetMesh(), picker->GetCellId());

			selectedMapper->SetInputConnection(selected->GetProducerPort());

			this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->
			AddActor(selectedActor);
		}
		else
			this->Interactor->GetRenderWindow()->GetRenderers()->GetFirstRenderer()->
			RemoveActor(selectedActor);
		emit requestViewUpdate();
	}
	else
		// Forward events
		vtkInteractorStyleTrackballCamera::OnLeftButtonDown();
}