Exemplo n.º 1
0
void VtkVisPipelineView::convertVTKToOGSMesh()
{
	VtkVisPipelineItem* item = static_cast<VtkVisPipelineItem*>(
		static_cast<VtkVisPipeline*>(this->model())->getItem(this->selectionModel()->currentIndex()));
	vtkSmartPointer<vtkAlgorithm> algorithm = item->algorithm();


	vtkUnstructuredGrid* grid(NULL);
	vtkUnstructuredGridAlgorithm* ugAlg = vtkUnstructuredGridAlgorithm::SafeDownCast(algorithm);
	if (ugAlg)
		grid = ugAlg->GetOutput();
	else
	{
		// for old filetypes
		vtkGenericDataObjectReader* dataReader = vtkGenericDataObjectReader::SafeDownCast(algorithm);
		if (dataReader)
			grid = vtkUnstructuredGrid::SafeDownCast(dataReader->GetOutput());
		else
		{
			// for new filetypes
			vtkXMLUnstructuredGridReader* xmlReader = vtkXMLUnstructuredGridReader::SafeDownCast(algorithm);
			grid = vtkUnstructuredGrid::SafeDownCast(xmlReader->GetOutput());
		}
	}
	MeshLib::Mesh* mesh = MeshLib::VtkMeshConverter::convertUnstructuredGrid(grid);
	mesh->setName(item->data(0).toString().toStdString());
	emit meshAdded(mesh);
}
Exemplo n.º 2
0
void MeshEditor::addMesh(pg::Geometry geom)
{
	pg::Plant *plant = editor->getPlant();
	QString qname = QString::fromStdString(geom.getName());
	plant->addLeafMesh(geom);
	meshBox->addItem(qname, QVariant(geom.getId()));
	meshBox->setCurrentIndex(meshBox->findText(qname));
	emit meshChanged(geom);
	emit meshAdded(geom);
}
Exemplo n.º 3
0
void VtkVisPipelineView::constructMeshFromImage(QString msh_name, MshElemType::type element_type, UseIntensityAs::type intensity_type)
{
	vtkSmartPointer<vtkAlgorithm> algorithm =
	        static_cast<VtkVisPipelineItem*>(static_cast<VtkVisPipeline*>(this->model())->
	                                         getItem(this->selectionModel()->currentIndex()))->algorithm();

	vtkSmartPointer<VtkGeoImageSource> imageSource = VtkGeoImageSource::SafeDownCast(algorithm);
	double origin[3];
	imageSource->GetOutput()->GetOrigin(origin);
	double spacing[3];
	imageSource->GetOutput()->GetSpacing(spacing);

	MeshLib::Mesh* mesh = VtkMeshConverter::convertImgToMesh(imageSource->GetOutput(), origin, spacing[0], element_type, intensity_type);
	mesh->setName(msh_name.toStdString());
	emit meshAdded(mesh);
}
Exemplo n.º 4
0
void MeshElementRemovalDialog::accept()
{
    if (this->newMeshNameEdit->text().size()==0)
    {
        OGSError::box("Please enter name for new mesh.");
        return;
    }

    bool anything_checked (false);

    const MeshLib::Mesh* msh = _project.getMesh(this->meshNameComboBox->currentText().toStdString());
    MeshLib::ElementSearch ex(*msh);
    if (this->elementTypeCheckBox->isChecked())
    {
        QList<QListWidgetItem*> items = this->elementTypeListWidget->selectedItems();
        for (auto& item : items)
            ex.searchByElementType(
                MeshLib::String2MeshElemType(item->text().toStdString()));
        anything_checked = true;
    }
    if (this->scalarArrayCheckBox->isChecked())
    {
        std::string const array_name = this->scalarArrayComboBox->currentText().toStdString();
        double min_val, max_val;
        bool outside = this->outsideButton->isChecked();
        if (outside)
        {
            min_val = this->outsideScalarMinEdit->text().toDouble();
            max_val = this->outsideScalarMaxEdit->text().toDouble();
        }
        else
        {
            min_val = this->insideScalarMinEdit->text().toDouble();
            max_val = this->insideScalarMaxEdit->text().toDouble();
        }
        std::size_t n_marked_elements =
            ex.searchByPropertyValueRange<double>(array_name, min_val, max_val, outside);

        if (n_marked_elements == 0)
            n_marked_elements =
                ex.searchByPropertyValueRange<int>(array_name, min_val, max_val, outside);

        if (n_marked_elements > 0)
            anything_checked = true;
    }
    if (this->boundingBoxCheckBox->isChecked())
    {
        std::vector<MeshLib::Node*> const& nodes (_project.getMesh(this->meshNameComboBox->currentText().toStdString())->getNodes());
        GeoLib::AABB const aabb(nodes.begin(), nodes.end());
        auto minAABB = aabb.getMinPoint();
        auto maxAABB = aabb.getMaxPoint();

        // only extract bounding box parameters that have been edited (otherwise there will be rounding errors!)
        minAABB[0] = (aabb_edits[0]) ? this->xMinEdit->text().toDouble() : (minAABB[0]);
        maxAABB[0] = (aabb_edits[1]) ? this->xMaxEdit->text().toDouble() : (maxAABB[0]);
        minAABB[1] = (aabb_edits[2]) ? this->yMinEdit->text().toDouble() : (minAABB[1]);
        maxAABB[1] = (aabb_edits[3]) ? this->yMaxEdit->text().toDouble() : (maxAABB[1]);
        minAABB[2] = (aabb_edits[4]) ? this->zMinEdit->text().toDouble() : (minAABB[2]);
        maxAABB[2] = (aabb_edits[5]) ? this->zMaxEdit->text().toDouble() : (maxAABB[2]);
        std::vector<MathLib::Point3d> extent;
        extent.push_back(minAABB);
        extent.push_back(maxAABB);
        const GeoLib::AABB updated_aabb(extent.begin(), extent.end());
        ex.searchByBoundingBox(updated_aabb);
        anything_checked = true;
    }

    if (this->zeroVolumeCheckBox->isChecked())
    {
        ex.searchByContent();
        anything_checked = true;
    }

    if (anything_checked)
    {
        MeshLib::Mesh* new_mesh = MeshLib::removeElements(*msh, ex.getSearchedElementIDs(), this->newMeshNameEdit->text().toStdString());
        if (new_mesh)
            emit meshAdded(new_mesh);
        else
        {
            if (new_mesh == nullptr)
                OGSError::box("The current selection removes ALL mesh elements.\nPlease change the selection.");
            if (ex.getSearchedElementIDs().empty())
                OGSError::box("The current selection removes NO mesh elements.");
            delete new_mesh;
            return;
        }
    }
    else
    {
        OGSError::box("No condition set for elements to remove.");
        return;
    }

    this->done(QDialog::Accepted);
}
Exemplo n.º 5
0
void CreateStructuredGridDialog::accept()
{
    if (inputIsEmpty())
        return;

    if ((this->xLengthEdit->text().toDouble() <= 0) ||
        (this->yLengthEdit->text().toDouble() <= 0) ||
        (this->zLengthEdit->text().toDouble() <= 0))
    {
        OGSError::box("Length needs to be larger than 0.");
        return;
    }

    if ((this->xElemEdit->text().toDouble() <= 0) ||
        (this->yElemEdit->text().toDouble() <= 0) ||
        (this->zElemEdit->text().toDouble() <= 0))
    {
        OGSError::box("Number of elements needs to be larger than 0.");
        return;
    }

    GeoLib::Point const origin(this->xOriginEdit->text().toDouble(),
                               this->yOriginEdit->text().toDouble(),
                               this->zOriginEdit->text().toDouble());
    std::string const name (this->meshNameEdit->text().toStdString());
    MeshLib::Mesh* mesh (nullptr);
    if (this->lineButton->isChecked())
        if (this->meshExtentButton->isChecked())
            mesh = MeshLib::MeshGenerator::generateLineMesh(
                this->xLengthEdit->text().toDouble(), this->xElemEdit->text().toInt(), origin, name);
        else
            mesh = MeshLib::MeshGenerator::generateLineMesh(
                this->xElemEdit->text().toInt(), this->xLengthEdit->text().toDouble(), origin, name);
    else if (this->triButton->isChecked())
        if (this->meshExtentButton->isChecked())
            mesh = MeshLib::MeshGenerator::generateRegularTriMesh(
                this->xLengthEdit->text().toDouble(), this->yLengthEdit->text().toDouble(),
                this->xElemEdit->text().toInt(), this->yElemEdit->text().toInt(),
                origin, name);
        else
            mesh = MeshLib::MeshGenerator::generateRegularTriMesh(
                this->xElemEdit->text().toInt(), this->yElemEdit->text().toInt(),
                this->xLengthEdit->text().toDouble(), this->yLengthEdit->text().toDouble(),
                origin, name);
    else if (this->quadButton->isChecked())
        if (this->meshExtentButton->isChecked())
            mesh = MeshLib::MeshGenerator::generateRegularQuadMesh(
                this->xLengthEdit->text().toDouble(), this->yLengthEdit->text().toDouble(),
                this->xElemEdit->text().toInt(), this->yElemEdit->text().toInt(),
                origin, name);
        else
            mesh = MeshLib::MeshGenerator::generateRegularQuadMesh(
                this->xElemEdit->text().toInt(), this->yElemEdit->text().toInt(),
                this->xLengthEdit->text().toDouble(), this->yLengthEdit->text().toDouble(),
                origin, name);
    else if (this->prismButton->isChecked())
        if (this->meshExtentButton->isChecked())
            mesh = MeshLib::MeshGenerator::generateRegularPrismMesh(
                this->xLengthEdit->text().toDouble(), this->yLengthEdit->text().toDouble(),
                this->zLengthEdit->text().toDouble(), this->xElemEdit->text().toInt(),
                this->yElemEdit->text().toInt(), this->zElemEdit->text().toInt(),
                origin, name);
        else
            mesh = MeshLib::MeshGenerator::generateRegularPrismMesh(
                this->xLengthEdit->text().toDouble(), this->yLengthEdit->text().toDouble(),
                this->zLengthEdit->text().toDouble(), this->xElemEdit->text().toInt(),
                this->yElemEdit->text().toInt(), this->zElemEdit->text().toInt(),
                origin, name);
    else if (this->hexButton->isChecked())
        if (this->meshExtentButton->isChecked())
            mesh = MeshLib::MeshGenerator::generateRegularHexMesh(
                this->xLengthEdit->text().toDouble(), this->yLengthEdit->text().toDouble(),
                this->zLengthEdit->text().toDouble(), this->xElemEdit->text().toInt(),
                this->yElemEdit->text().toInt(), this->zElemEdit->text().toInt(),
                origin, name);
        else
            mesh = MeshLib::MeshGenerator::generateRegularHexMesh(
                this->xElemEdit->text().toInt(), this->yElemEdit->text().toInt(),
                this->zElemEdit->text().toInt(), this->xLengthEdit->text().toDouble(),
                this->yLengthEdit->text().toDouble(), this->zLengthEdit->text().toDouble(),
                origin, name);

    if (mesh == nullptr)
    {
        OGSError::box("Error creating mesh.");
        return;
    }

    boost::optional<MeshLib::PropertyVector<int>&> mat_ids (
        mesh->getProperties().createNewPropertyVector<int>("MaterialIDs", MeshLib::MeshItemType::Cell));
    mat_ids->reserve(mesh->getNumberOfElements());
    std::fill_n(std::back_inserter(*mat_ids), mesh->getNumberOfElements(), 0);
    emit meshAdded(mesh);
    this->done(QDialog::Accepted);
}