Example #1
0
void VtkVisPipelineView::selectionChanged( const QItemSelection &selected,
                                           const QItemSelection &deselected )
{
	QTreeView::selectionChanged(selected, deselected);

	if (selected.empty())
		return;

	QModelIndex index = *selected.indexes().begin();
	if (index.isValid())
	{
		VtkVisPipelineItem* item = static_cast<VtkVisPipelineItem*>(index.internalPointer());
		emit actorSelected(item->actor());
		emit itemSelected(item);
		if (item->transformFilter())
			emit dataObjectSelected(vtkDataObject::SafeDownCast(
				item->transformFilter()->GetOutputDataObject(0)));
	}
	else
	{
		emit actorSelected(NULL);
		emit itemSelected(NULL);
		emit dataObjectSelected(NULL);
	}
}
Example #2
0
void VtkVisPipeline::showMeshElementQuality(
    InSituLib::VtkMappedMeshSource* source,
    MeshLib::MeshQualityType t, std::vector<double> const& quality)
{
    if (!source || quality.empty())
        return;

    int const nSources = this->_rootItem->childCount();
    for (int i = 0; i < nSources; i++)
    {
        VtkVisPipelineItem* parentItem =
                static_cast<VtkVisPipelineItem*>(_rootItem->child(i));
        if (parentItem->algorithm() != source)
            continue;

        QList<QVariant> itemData;
        itemData << "MeshQuality: " + QString::fromStdString(
                MeshQualityType2String(t)) << true;

        VtkCompositeFilter* filter =
            VtkFilterFactory::CreateCompositeFilter("VtkCompositeElementSelectionFilter",
                                                    parentItem->transformFilter());
        if (t == MeshLib::MeshQualityType::ELEMENTSIZE)
        {
            auto const range (std::minmax_element(quality.cbegin(), quality.cend()));
            static_cast<VtkCompositeElementSelectionFilter*>(filter)->setRange(*range.first, *range.second);
        }
        static_cast<VtkCompositeElementSelectionFilter*>(filter)->setSelectionArray("Selection", quality);
        VtkVisPointSetItem* item = new VtkVisPointSetItem(filter, parentItem, itemData);
        this->addPipelineItem(item, this->createIndex(i, 0, item));
        break;
    }
}
Example #3
0
void VtkVisPipeline::highlightMeshComponent(vtkUnstructuredGridAlgorithm const*const source, unsigned index, bool is_element)
{
    int nSources = this->_rootItem->childCount();
    for (int i = 0; i < nSources; i++)
    {
        VtkVisPipelineItem* parentItem = static_cast<VtkVisPipelineItem*>(_rootItem->child(i));
        if (parentItem->algorithm() == source)
        {
            QList<QVariant> itemData;
            itemData << "Selected Mesh Component" << true;
            QList<QVariant> selected_index;
            selected_index << index << index;

            VtkCompositeFilter* filter (nullptr);
            if (is_element)
            {
                filter = VtkFilterFactory::CreateCompositeFilter("VtkCompositeElementSelectionFilter",
                                                                  parentItem->transformFilter());
                static_cast<VtkCompositeElementSelectionFilter*>(filter)->setSelectionArray("vtkIdFilter_Ids");
                static_cast<VtkCompositeElementSelectionFilter*>(filter)->SetUserVectorProperty("Threshold Between", selected_index);
            }
            else
            {
                filter = VtkFilterFactory::CreateCompositeFilter("VtkCompositeNodeSelectionFilter",
                                                                  parentItem->transformFilter());
                std::vector<unsigned> indeces(1);
                indeces[0] = index;
                static_cast<VtkCompositeNodeSelectionFilter*>(filter)->setSelectionArray(indeces);
            }
            VtkVisPointSetItem* item = new VtkVisPointSetItem(filter, parentItem, itemData);
            QModelIndex parent_index = static_cast<TreeModel*>(this)->index(i, 0, QModelIndex());
            _highlighted_mesh_component = this->addPipelineItem(item, parent_index);
            break;
        }
    }
}
Example #4
0
void VtkVisPipeline::highlightGeoObject(const vtkPolyDataAlgorithm* source, int index)
{
	this->removeHighlightedGeoObject();
	int nSources = this->_rootItem->childCount();
	for (int i = 0; i < nSources; i++)
	{
		VtkVisPipelineItem* parentItem = static_cast<VtkVisPipelineItem*>(_rootItem->child(i));
		if (parentItem->algorithm() == source)
		{
			QList<QVariant> itemData;
			itemData << "Selected GeoObject" << true;

			VtkCompositeFilter* filter = VtkFilterFactory::CreateCompositeFilter(
															"VtkCompositeGeoObjectFilter",
															parentItem->transformFilter());
			static_cast<VtkCompositeGeoObjectFilter*>(filter)->SetIndex(index);
			VtkVisPointSetItem* item = new VtkVisPointSetItem(filter, parentItem, itemData);
			QModelIndex parent_index = static_cast<TreeModel*>(this)->index(i, 0, QModelIndex());
			_highlighted_geo_index = this->addPipelineItem(item, parent_index);
			break;
		}
	}
}
Example #5
0
void VtkVisPipeline::checkMeshQuality(VtkMeshSource* source, MshQualityType::type t)
{
	if (source)
	{
		const MeshLib::Mesh* mesh = source->GetMesh();
		MeshLib::MeshQualityChecker* checker (NULL);
		if (t == MshQualityType::EDGERATIO)
			checker = new MeshLib::MeshQualityShortestLongestRatio(mesh);
		else if (t == MshQualityType::AREA)
			checker = new MeshLib::MeshQualityArea(mesh);
		else if (t == MshQualityType::VOLUME)
			checker = new MeshLib::MeshQualityVolume(mesh);
		else if (t == MshQualityType::EQUIANGLESKEW)
			checker = new MeshLib::MeshQualityEquiAngleSkew(mesh);
		else
		{
			std::cout << "Error in VtkVisPipeline::checkMeshQuality() - Unknown MshQualityType..."
							<< std::endl;
			delete checker;
			return;
		}
		checker->check ();

		std::vector<double> quality (checker->getMeshQuality());
		// transform area and volume criterion values to [0, 1]
		if (t == MshQualityType::AREA || t == MshQualityType::VOLUME) {
			try {
				MathLib::LinearIntervalInterpolation<double> lin_intpol(checker->getMinValue(), checker->getMaxValue(), 0, 1);
				const size_t n_quality(quality.size());
				for (size_t k(0); k<n_quality; k++)
					quality[k] = lin_intpol(quality[k]);
			} catch (std::runtime_error& exception) {
				std::cout << "run time error: " << exception.what() << std::endl;
			}
		}

		int nSources = this->_rootItem->childCount();
		for (int i = 0; i < nSources; i++)
		{
			VtkVisPipelineItem* parentItem =
			        static_cast<VtkVisPipelineItem*>(_rootItem->child(i));
			if (parentItem->algorithm() == source)
			{
				QList<QVariant> itemData;
				itemData << "MeshQuality: " + QString::fromStdString(
				        MshQualityType2String(t)) << true;

				VtkCompositeFilter* filter =
				        VtkFilterFactory::CreateCompositeFilter(
				                "VtkCompositeSelectionFilter",
				                parentItem->transformFilter());
				static_cast<VtkCompositeSelectionFilter*>(filter)->
				setSelectionArray(quality);
				VtkVisPointSetItem* item = new VtkVisPointSetItem(filter,
				                                                  parentItem,
				                                                  itemData);
				this->addPipelineItem(item, this->createIndex(i, 0, item));
				break;
			}
		}

		// *** construct and write histogram
		// simple suggestion: number of classes with Sturges criterion
		size_t nclasses (static_cast<size_t>(1 + 3.3 * log (static_cast<float>(mesh->getNElements()))));
//			bool ok;
//			size_t size (static_cast<size_t>(QInputDialog::getInt(NULL, "OGS-Histogram", "number of histogram classes/spins (min: 1, max: 10000)", static_cast<int>(nclasses), 1, 10000, 1, &ok)));
//			if (ok) ...

		BASELIB::Histogram<double> histogram (checker->getHistogram(nclasses));
		std::ofstream out ("mesh_histogram.txt");
		if (out) {
			out << "# histogram depicts mesh quality criterion " << MshQualityType2String(t)
				<< " for mesh " << source->GetMesh()->getName() << std::endl;
			nclasses = histogram.getNrBins();
			std::vector<size_t> const& bin_cnts(histogram.getBinCounts());
			const double min (histogram.getMinimum());
			const double bin_width (histogram.getBinWidth());

			for (size_t k(0); k < nclasses; k++)
				out << min+k*bin_width << " " << bin_cnts[k] << std::endl;
			out.close ();
		} else {
			std::cerr << "could not open file mesh_histgram.txt" << std::endl;
		}

//		size_t size (100);
//		std::vector<size_t> histogram (size,0);
//		checker->getHistogram(histogram);
//		std::ofstream out ("mesh_histogram.txt");
//		const size_t histogram_size (histogram.size());
//		for (size_t k(0); k < histogram_size; k++)
//			out << k / static_cast<double>(histogram_size) << " " << histogram[k] <<
//			std::endl;
//		out.close ();

		delete checker;
	}
}