コード例 #1
0
ファイル: VtkVisTabWidget.cpp プロジェクト: LEONOB2014/ogs
void VtkVisTabWidget::on_arrayResetPushButton_clicked()
{
	VtkAlgorithmProperties* props = _item->getVtkProperties();
	const QString selected_array_name = this->activeScalarComboBox->currentText();
	props->RemoveLookupTable(selected_array_name);
	_item->SetActiveAttribute(selected_array_name);
}
コード例 #2
0
ファイル: VtkVisPipelineView.cpp プロジェクト: envinf/ogs
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());
	}
}
コード例 #3
0
void VtkVisPipelineView::contextMenuEvent( QContextMenuEvent* event )
{
	QModelIndex index = selectionModel()->currentIndex();
	if (index.isValid())
	{
		// check object type
		VtkVisPipelineItem* item = static_cast<VtkVisPipelineItem*>(static_cast<VtkVisPipeline*>(
			this->model())->getItem(this->selectionModel()->currentIndex()));
		int objectType = item->algorithm()->GetOutputDataObject(0)->GetDataObjectType();
		VtkAlgorithmProperties* vtkProps = item->getVtkProperties();
		bool isSourceItem =
		        (this->selectionModel()->currentIndex().parent().isValid()) ? 0 : 1;

		QMenu menu;
		QAction* addFilterAction = menu.addAction("Add filter...");

		QAction* addLUTAction(NULL);
		QAction* addMeshingAction(NULL);
		if (objectType == VTK_IMAGE_DATA)
		{
			// this exception is needed as image object are only displayed in the vis-pipeline
			isSourceItem = false;
			addMeshingAction = menu.addAction("Convert Image to Mesh...");
			connect(addMeshingAction, SIGNAL(triggered()), this,
			        SLOT(showImageToMeshConversionDialog()));
		}
		else
		{
			addLUTAction = menu.addAction("Add color table...");
			connect(addLUTAction, SIGNAL(triggered()), this, SLOT(addColorTable()));
		}

		QAction* addConvertToMeshAction(NULL);
		if (objectType == VTK_UNSTRUCTURED_GRID)
		{
			addConvertToMeshAction = menu.addAction("Convert to Mesh...");
			connect(addConvertToMeshAction, SIGNAL(triggered()), this,
			        SLOT(convertVTKToOGSMesh()));
		}
		menu.addSeparator();
		QAction* exportVtkAction = menu.addAction("Export as VTK");
		QAction* exportOsgAction = menu.addAction("Export as OpenSG");
		QAction* removeAction = NULL;
		if (!isSourceItem || vtkProps->IsRemovable())
		{
			removeAction = menu.addAction("Remove");
			connect(removeAction, SIGNAL(triggered()), this,
			        SLOT(removeSelectedPipelineItem()));
		}

		connect(addFilterAction, SIGNAL(triggered()), this, SLOT(addPipelineFilterItem()));
		connect(exportVtkAction, SIGNAL(triggered()), this,
		        SLOT(exportSelectedPipelineItemAsVtk()));
		connect(exportOsgAction, SIGNAL(triggered()), this,
		        SLOT(exportSelectedPipelineItemAsOsg()));

		menu.exec(event->globalPos());
	}
}
コード例 #4
0
ファイル: VtkVisPipeline.cpp プロジェクト: JobstM/ogs
QModelIndex VtkVisPipeline::addPipelineItem( vtkAlgorithm* source,
                                      QModelIndex parent /* = QModelindex() */)
{
	TreeItem* parentItem = getItem(parent);

	QList<QVariant> itemData;
	QString itemName;
	if (!parent.isValid()) // if source object
	{
		vtkGenericDataObjectReader* reader =
		        dynamic_cast<vtkGenericDataObjectReader*>(source);
		vtkImageReader2* imageReader = dynamic_cast<vtkImageReader2*>(source);
		VtkAlgorithmProperties* props = dynamic_cast<VtkAlgorithmProperties*>(source);
		if (reader)
		{
			QFileInfo fi(QString(reader->GetFileName()));
			itemName = fi.fileName();
		}
		else if (imageReader)
		{
			QFileInfo fi(QString(imageReader->GetFileName()));
			itemName = fi.fileName();
		}
		else if (props)
		{
			QFileInfo fi(props->GetName());
			itemName = fi.fileName();
		}
		else
			itemName = QString(source->GetClassName());
	}
	else
		itemName = QString(source->GetClassName());
	itemData << itemName << true;

	VtkVisPipelineItem* item(NULL);
	vtkImageAlgorithm* alg = dynamic_cast<vtkImageAlgorithm*>(source);
	if (alg)
		item = new VtkVisImageItem(source, parentItem, itemData);
	else
		item = new VtkVisPointSetItem(source, parentItem, itemData);
	return this->addPipelineItem(item, parent);
}
コード例 #5
0
ファイル: VtkVisPipeline.cpp プロジェクト: Yonghui56/ogs6
QModelIndex VtkVisPipeline::addPipelineItem( vtkAlgorithm* source, QModelIndex parent /* = QModelindex() */)
{
    std::string itemName;

    if (!parent.isValid()) // if source object
    {
        vtkGenericDataObjectReader* old_reader = dynamic_cast<vtkGenericDataObjectReader*>(source);
        vtkXMLReader* new_reader = dynamic_cast<vtkXMLReader*>(source);
        vtkImageReader2* image_reader = dynamic_cast<vtkImageReader2*>(source);
        VtkAlgorithmProperties* props = dynamic_cast<VtkAlgorithmProperties*>(source);
        InSituLib::VtkMappedMeshSource* meshSource =
            dynamic_cast<InSituLib::VtkMappedMeshSource*>(source);
        if (old_reader)
            itemName = old_reader->GetFileName();
        else if (new_reader)
            itemName = new_reader->GetFileName();
        else if (image_reader)
            itemName = image_reader->GetFileName();
        else if (props)
            itemName = props->GetName().toStdString();
        else if (meshSource)
            itemName = meshSource->GetMesh()->getName();
    }

    if (itemName.length() == 0)
        itemName = source->GetClassName();

    QList<QVariant> itemData;
    itemData << QString::fromStdString(itemName) << true;

    VtkVisPipelineItem* item(NULL);
    if (dynamic_cast<vtkImageAlgorithm*>(source))
        item = new VtkVisImageItem(source, getItem(parent), itemData);
    else
        item = new VtkVisPointSetItem(source, getItem(parent), itemData);
    return this->addPipelineItem(item, parent);
}
コード例 #6
0
ファイル: VtkVisTabWidget.cpp プロジェクト: LEONOB2014/ogs
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;
			}
		}
	}
コード例 #7
0
ファイル: VtkVisPointSetItem.cpp プロジェクト: Doublle/ogs
void VtkVisPointSetItem::Initialize(vtkRenderer* renderer)
{
    // TODO vtkTransformFilter creates a new copy of the point coordinates which
    // conflicts with VtkMappedMeshSource. Find a workaround!
    _transformFilter = vtkTransformFilter::New();
    vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
    transform->Identity();
    _transformFilter->SetTransform(transform);

    _transformFilter->SetInputConnection(_algorithm->GetOutputPort());
    _transformFilter->Update();

    _renderer = renderer;
    _mapper = QVtkDataSetMapper::New();
    _mapper->InterpolateScalarsBeforeMappingOff();
    _mapper->SetColorModeToMapScalars();

    _mapper->SetInputConnection(_transformFilter->GetOutputPort());
    _actor = vtkActor::New();
    static_cast<vtkActor*>(_actor)->SetMapper(_mapper);
    _renderer->AddActor(_actor);

    // Determine the right pre-set properties
    // Order is: _algorithm, _compositeFilter, create a new one with props copied from parent
    VtkAlgorithmProperties* vtkProps = dynamic_cast<VtkAlgorithmProperties*>(_algorithm);
    if (!vtkProps)
    {
        vtkProps = dynamic_cast<VtkAlgorithmProperties*>(_compositeFilter);

        // Copy properties from parent or create a new VtkAlgorithmProperties
        if (!vtkProps)
        {
            VtkVisPipelineItem* parentItem = dynamic_cast<VtkVisPipelineItem*>(this->parentItem());
            while (parentItem)
            {
                VtkAlgorithmProperties* parentProps = nullptr;
                if(dynamic_cast<VtkVisPointSetItem*>(parentItem))
                    parentProps = dynamic_cast<VtkVisPointSetItem*>(parentItem)->getVtkProperties();
                if (parentProps)
                {
                    vtkProps = new VtkAlgorithmProperties(); // TODO memory leak?
                    vtkProps->SetScalarVisibility(parentProps->GetScalarVisibility());
                    vtkProps->SetTexture(parentProps->GetTexture());
                    vtkProps->SetActiveAttribute(parentProps->GetActiveAttribute());
                    parentItem = nullptr;
                }
                else
                    parentItem = dynamic_cast<VtkVisPipelineItem*>(parentItem->parentItem());
            }

            // Has no parents
            if (!vtkProps)
                vtkProps = new VtkAlgorithmProperties(); // TODO memory leak?
        }
    }
    _vtkProps = vtkProps;

    if (vtkProps->GetActiveAttribute().length() == 0)
    {
        // Get first scalar and set it to active
        QStringList arrayNames = this->getScalarArrayNames();
        if (arrayNames.length() > 0)
            vtkProps->SetActiveAttribute(arrayNames[0]);
        else
            vtkProps->SetActiveAttribute("Solid Color");
    }
    this->setVtkProperties(vtkProps);
    this->SetActiveAttribute(vtkProps->GetActiveAttribute());


    // Set global backface culling
    QSettings settings;
    bool backfaceCulling = settings.value("globalCullBackfaces", 0).toBool();
    this->setBackfaceCulling(backfaceCulling);

    // Set the correct threshold range
    if (dynamic_cast<VtkCompositeThresholdFilter*>(this->_compositeFilter) )
    {
        double range[2];
        this->GetRangeForActiveAttribute(range);
        QList<QVariant> thresholdRangeList;
        thresholdRangeList.push_back(range[0]);
        thresholdRangeList.push_back(range[1]);
        dynamic_cast<VtkCompositeFilter*>(this->_compositeFilter)
            ->SetUserVectorProperty("Range", thresholdRangeList);
    }

    // Show edges on meshes
    if (dynamic_cast<MeshLib::VtkMappedMeshSource*>(this->_algorithm))
        _vtkProps->GetProperties()->SetEdgeVisibility(1);
}
コード例 #8
0
ファイル: VtkVisImageItem.cpp プロジェクト: dahunhun/ogs-1
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");
		}
	}
}