Ejemplo n.º 1
0
void MshEditor::get2DSurfaceElements(const std::vector<MeshLib::Element*> &all_elements, std::vector<MeshLib::Element*> &sfc_elements, const double* dir, unsigned mesh_dimension)
{
	bool complete_surface (true);
	if (dir)
		complete_surface = ((dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2]) == 0) ? true : false;

	const size_t nElements (all_elements.size());

	if (mesh_dimension == 2 )
	{
		for (unsigned i=0; i<nElements; ++i)
		{
			if (complete_surface)
				sfc_elements.push_back(all_elements[i]);
			else
			{
				MeshLib::Face* face = dynamic_cast<MeshLib::Face*>(all_elements[i]);
				double normal[3];
				face->getSurfaceNormal(normal);
				if (MathLib::scpr(normal, dir, 3) > 0)
					sfc_elements.push_back(static_cast<MeshLib::Element*>(face));
			}
		}
	}
	else if (mesh_dimension == 3)
	{
		for (unsigned i=0; i<nElements; ++i)
		{
			if (all_elements[i]->getDimension()==3)
			{
				const MeshLib::Cell* cell = static_cast<MeshLib::Cell*>(all_elements[i]);
				if (cell->isOnSurface())
				{
					const unsigned nFaces (cell->getNFaces());
					for (unsigned j=0; j<nFaces; ++j)
					{
						if (cell->getNeighbor(j) == NULL)
						{
							const MeshLib::Face* face = static_cast<const MeshLib::Face*>(cell->getFace(j));
							if (!complete_surface)
							{
								double normal[3];
								face->getSurfaceNormal(normal);
								if (MathLib::scpr<double,3>(normal, dir) <= 0)
									continue;
							}

							if (face->getType() == MshElemType::TRIANGLE)
								sfc_elements.push_back(new MeshLib::Tri(*static_cast<const MeshLib::Tri*>(face)));
							else
								sfc_elements.push_back(new MeshLib::Quad(*static_cast<const MeshLib::Quad*>(face)));
						}
					}
				}
			}
		}
	}
}
Ejemplo n.º 2
0
void MeshSurfaceExtraction::get2DSurfaceElements(const std::vector<MeshLib::Element*> &all_elements, std::vector<MeshLib::Element*> &sfc_elements, const MathLib::Vector3 &dir, unsigned mesh_dimension)
{
	if (mesh_dimension<2 || mesh_dimension>3)
		ERR("Cannot handle meshes of dimension %i", mesh_dimension);

	bool complete_surface (true);
	if (MathLib::scalarProduct(dir, dir) != 0)
		complete_surface = false;

	for (auto elem = all_elements.begin(); elem != all_elements.end(); ++elem)
	{
		const unsigned element_dimension ((*elem)->getDimension());
		if (element_dimension < mesh_dimension)
			continue;

		if (element_dimension == 2)
		{
			if (!complete_surface)
			{
				MeshLib::Face* face = dynamic_cast<MeshLib::Face*>(*elem);

				if (MathLib::scalarProduct(face->getSurfaceNormal(), dir) <= 0)
					continue;	
			}
			sfc_elements.push_back(*elem);
		}
		else
		{
			const MeshLib::Cell* cell = static_cast<MeshLib::Cell*>(*elem);
			if (!cell->isOnSurface())
				continue;
			const unsigned nFaces (cell->getNFaces());
			for (unsigned j=0; j<nFaces; ++j)
			{
				if (cell->getNeighbor(j) != nullptr)
					continue;

				const MeshLib::Face* face = static_cast<const MeshLib::Face*>(cell->getFace(j));
				if (!complete_surface)
					if (MathLib::scalarProduct(face->getSurfaceNormal(), dir) <= 0)
					{
						delete face;
						continue;
					}
				if (face->getGeomType() == MeshElemType::TRIANGLE)
					sfc_elements.push_back(new MeshLib::Tri(*static_cast<const MeshLib::Tri*>(face)));
				else
					sfc_elements.push_back(new MeshLib::Quad(*static_cast<const MeshLib::Quad*>(face)));
			}
		}
	}
}
Ejemplo n.º 3
0
MeshLib::Mesh* MshEditor::getMeshSurface(const MeshLib::Mesh &mesh, const double* dir)
{
	std::cout << "Extracting mesh surface..." << std::endl;

	const std::vector<MeshLib::Element*> elements = mesh.getElements();
	std::vector<MeshLib::Element*> new_elements;
	const size_t nElements (mesh.getNElements());

	bool complete_surface = ((dir[0]*dir[0] + dir[1]*dir[1] + dir[2]*dir[2]) == 0) ? true : false;

	// 2D meshes
	if (mesh.getDimension() == 2 )
	{
		if (complete_surface) return new MeshLib::Mesh(mesh); // simply copy the mesh
		else	// check only surface normal directions of all elements
		{
			for (unsigned i=0; i<nElements; i++)
			{
				MeshLib::Face* face = dynamic_cast<MeshLib::Face*>(elements[i]);
				double normal[3];
				face->getSurfaceNormal(normal);
				if (MathLib::scpr(normal, dir, 3) > 0)
					new_elements.push_back(static_cast<MeshLib::Element*>(face));
			}
		}
	}
	// 3D meshes
	else if (mesh.getDimension() == 3)	//
	{
		for (unsigned i=0; i<nElements; i++)
		{
			if (const MeshLib::Cell* cell = dynamic_cast<MeshLib::Cell*>(elements[i]))
			{
				if (cell->isOnSurface())
				{
					const unsigned nFaces (cell->getNFaces());
					for (unsigned j=0; j<nFaces; j++)
					{
						if (cell->getNeighbor(i) == NULL)
						{
							const MeshLib::Face* face = static_cast<const MeshLib::Face*>(cell->getFace(i));
							if (!complete_surface)
							{
								double normal[3];
								face->getSurfaceNormal(normal);
								if (MathLib::scpr<double,3>(normal, dir) <= 0)
									continue;
							}

							if (face->getType() == MshElemType::TRIANGLE)
								new_elements.push_back(new MeshLib::Tri(*static_cast<const MeshLib::Tri*>(face)));
							else
								new_elements.push_back(new MeshLib::Quad(*static_cast<const MeshLib::Quad*>(face)));
						}
					}
				}
			}
		}

		// now copy nodes
		const size_t nNewElements (new_elements.size());
		std::vector<const MeshLib::Node*> tmp_nodes(mesh.getNNodes(), NULL);
		const size_t nNodes (tmp_nodes.size());
		for (unsigned i=0; i<nNewElements; i++)
		{
			const MeshLib::Element* elem (new_elements[i]);
			for (unsigned j=0; j<elem->getNNodes(); j++)
			{
				const MeshLib::Node* node (elem->getNode(i));
				tmp_nodes[node->getID()] = node;
			}
		}
		std::vector<MeshLib::Node*> new_nodes;
		for (unsigned i=0; i<nNodes; i++)
			if (tmp_nodes[i])
				new_nodes.push_back(new MeshLib::Node(tmp_nodes[i]->getCoords()));
	}


}