[vtkusers] How does vtkGeometryFilter handle 2D cells overlaid on a 3D cell?

Matt Sutton matt.sutton at padtinc.com
Wed Sep 12 09:58:23 EDT 2012


Hello,
   I'm replying to my own post which I hope is kosher with the list, but I determined from my test case that indeed vtkGeometryFilter seems to show preference to 2D cells overlaid on "external" faces of 3D cells during the extraction process.  For what it is worth, here is my test function.

int geometry_extraction_test(int argc, char *argv[])
{
	VTK_CREATE(vtkUnstructuredGrid, pMesh);
	VTK_CREATE(vtkPoints, pPoints);
	VTK_CREATE(vtkIdTypeArray, pNodeIds);
	VTK_CREATE(vtkIdTypeArray, pElementIds);
	VTK_CREATE(vtkIdTypeArray, pElemPedigreeIds);
	VTK_CREATE(vtkIdTypeArray, pNodePedigreeIds);

	// Use an offset node number so we can test passing
	// those through the filters.
	vtkIdType node_num = 1;
	std::vector<vtkIdType> node_ids;
	node_ids.push_back(pPoints->InsertNextPoint(0,0,0));
	pNodeIds->InsertNextValue(node_num++);
	pNodePedigreeIds->InsertNextValue(0);
	node_ids.push_back(pPoints->InsertNextPoint(1,0,0));
	pNodeIds->InsertNextValue(node_num++);
	pNodePedigreeIds->InsertNextValue(0);
	node_ids.push_back(pPoints->InsertNextPoint(1,1,0));
	pNodeIds->InsertNextValue(node_num++);
	pNodePedigreeIds->InsertNextValue(0);
	node_ids.push_back(pPoints->InsertNextPoint(0,1,0));
	pNodeIds->InsertNextValue(node_num++);
	pNodePedigreeIds->InsertNextValue(0);
	node_ids.push_back(pPoints->InsertNextPoint(0,0,1));
	pNodeIds->InsertNextValue(node_num++);
	pNodePedigreeIds->InsertNextValue(0);
	node_ids.push_back(pPoints->InsertNextPoint(1,0,1));
	pNodeIds->InsertNextValue(node_num++);
	pNodePedigreeIds->InsertNextValue(0);
	node_ids.push_back(pPoints->InsertNextPoint(1,1,1));
	pNodeIds->InsertNextValue(node_num++);
	pNodePedigreeIds->InsertNextValue(0);
	node_ids.push_back(pPoints->InsertNextPoint(0,1,1));
	pNodeIds->InsertNextValue(node_num++);
	pNodePedigreeIds->InsertNextValue(0);
	node_ids.push_back(pPoints->InsertNextPoint(0,0,2));
	pNodeIds->InsertNextValue(node_num++);
	pNodePedigreeIds->InsertNextValue(0);
	node_ids.push_back(pPoints->InsertNextPoint(1,0,2));
	pNodeIds->InsertNextValue(node_num++);
	pNodePedigreeIds->InsertNextValue(0);
	node_ids.push_back(pPoints->InsertNextPoint(1,1,2));
	pNodeIds->InsertNextValue(node_num++);
	pNodePedigreeIds->InsertNextValue(0);
	node_ids.push_back(pPoints->InsertNextPoint(0,1,2));
	pNodeIds->InsertNextValue(node_num++);
	pNodePedigreeIds->InsertNextValue(0);

	pElemPedigreeIds->InsertNextValue(0);
	pElemPedigreeIds->InsertNextValue(0);
	pElemPedigreeIds->InsertNextValue(2);
	pElemPedigreeIds->InsertNextValue(2);

	// Create 2 hexas
	vtkIdType vtkHexaIds[8];
	for(int i = 0; i < 8; i++) {
		vtkHexaIds[i] = node_ids[i];
	}
	pMesh->InsertNextCell(VTK_HEXAHEDRON, 8, vtkHexaIds);
	pElementIds->InsertNextValue(3);

	for(int i = 0; i < 8; i++) {
		vtkHexaIds[i] = node_ids[i+4];
	}
	pMesh->InsertNextCell(VTK_HEXAHEDRON, 8, vtkHexaIds);
	pElementIds->InsertNextValue(4);

	// Create 2 quads
	vtkIdType vtkQuadIds[4];
	vtkQuadIds[0] = node_ids[1];
	vtkQuadIds[1] = node_ids[0];
	vtkQuadIds[2] = node_ids[3];
	vtkQuadIds[3] = node_ids[2];
	pMesh->InsertNextCell(VTK_QUAD, 4, vtkQuadIds);
	pElementIds->InsertNextValue(32);

	for(int i = 0; i < 4; i++) {
		vtkQuadIds[i] = node_ids[i+8];
	}
	pMesh->InsertNextCell(VTK_QUAD, 4, vtkQuadIds);
	pElementIds->InsertNextValue(33);

	pMesh->SetPoints(pPoints);
	pMesh->GetPointData()->SetGlobalIds(pNodeIds);
	pMesh->GetPointData()->SetPedigreeIds(pNodePedigreeIds);
	pMesh->GetCellData()->SetGlobalIds(pElementIds);
	pMesh->GetCellData()->SetPedigreeIds(pElemPedigreeIds);
	pMesh->Squeeze();
	pMesh->GetPointData()->CopyGlobalIdsOn();
	pMesh->GetPointData()->CopyPedigreeIdsOn();
	pMesh->GetCellData()->CopyGlobalIdsOn();
	pMesh->GetCellData()->CopyPedigreeIdsOn();

	// Now, extract the geometry
	VTK_CREATE(vtkGeometryFilter, pGeomFilter);
	pGeomFilter->SetInput(pMesh);
	pGeomFilter->Update();

	vtkPolyData *pPolys = pGeomFilter->GetOutput();
	pPolys->GetPolys()->InitTraversal();
	vtkIdType npts = 0;
	vtkIdType *pnts = nullptr;
	int cell_count = 0;
	vtkIdTypeArray *pGlobalIds = nullptr;
	pGlobalIds = vtkIdTypeArray::SafeDownCast(pPolys->GetPointData()->GetGlobalIds());

	while(pPolys->GetPolys()->GetNextCell(npts, pnts) != 0) {
		cell_count++;
		std::cout << "Number of points in cell: " << npts << endl;
		std::cout << "\tMesh ids: ";
		for(int i = 0; i < npts; i++) {
			std::cout << pnts[i] << " ";
		}
		std::cout << std::endl;
		std::cout << "\tGlobal ids: ";
		for(int i = 0; i < npts; i++) {
			std::cout << pGlobalIds->GetValue(pnts[i]) << " ";
		}
		std::cout << std::endl;
	}
	std::cout << "Total Number of cells: " << cell_count << std::endl;

	vtkIdTypeArray *pPedigreeIds   = nullptr;
	vtkIdTypeArray *pCellGlobalIds = nullptr;
	pPedigreeIds   = vtkIdTypeArray::SafeDownCast(pPolys->GetCellData()->GetPedigreeIds());
	pCellGlobalIds = vtkIdTypeArray::SafeDownCast(pPolys->GetCellData()->GetGlobalIds());
	for(vtkIdType i = 0; i < pPolys->GetNumberOfCells(); i++) {
		std::cout << "Cell " << i << " PedigreeID: " << pPedigreeIds->GetValue(i) << std::endl;
		std::cout << "Cell " << i << " GlobalID:   " << pCellGlobalIds->GetValue(i) << std::endl;
	}

	std::cout << std::endl << std::endl;
	std::cout << "Selection Logic" << std::endl << std::endl;

	//////////////////////////////////////////////////////////////////////
	// Test the selection logic in VTK
	
	VTK_CREATE(vtkSelection, pSelection);
	VTK_CREATE(vtkSelectionNode, pNode);
	VTK_CREATE(vtkExtractSelection, pExtractor);
	pNode->SetContentType(vtkSelectionNode::GLOBALIDS);
	pNode->SetFieldType(vtkSelectionNode::POINT);
	VTK_CREATE(vtkIdTypeArray, pSelArray);
	pSelArray->InsertNextValue(1);
	pSelArray->InsertNextValue(2);
	pSelArray->InsertNextValue(5);
	pSelArray->InsertNextValue(6);
	pSelArray->InsertNextValue(9);
	pSelArray->InsertNextValue(10);
	pNode->SetSelectionList(pSelArray);
	pNode->GetProperties()->Set(vtkSelectionNode::CONTAINING_CELLS(), 1);
	pNode->GetProperties()->Set(vtkSelectionNode::INVERSE(), 1);
	pSelection->AddNode(pNode);
	
	pExtractor->SetInput(0, pPolys);
	pExtractor->SetInput(1, pSelection);
	pExtractor->Update();
	vtkUnstructuredGrid *pGrid = vtkUnstructuredGrid::SafeDownCast(pExtractor->GetOutput());
	cell_count = 0;
	vtkIdTypeArray *pSelMeshGIDs = vtkIdTypeArray::SafeDownCast(pGrid->GetPointData()->GetGlobalIds());
	if(pGrid != nullptr) {
		for(int i = 0; i < pGrid->GetNumberOfCells(); i++) {
			std::cout << "Cell: " << i << " Points GIDs: ";
			for(int j = 0; j < pGrid->GetCell(i)->GetNumberOfPoints(); j++) {
				std::cout << pSelMeshGIDs->GetValue(pGrid->GetCell(i)->GetPointId(j)) << " ";
			}
			std::cout << std::endl;
		}
		std::cout << "Total Number of cells: " << pGrid->GetNumberOfCells() << std::endl;
	}
	
    return 0;
}

-----Original Message-----
From: Matt Sutton [mailto:matt.sutton at padtinc.com] 
Sent: Tuesday, September 11, 2012 8:17 AM
To: vtkusers at vtk.org
Subject: [vtkusers] How does vtkGeometryFilter handle 2D cells overlaid on a 3D cell?

Hello,
   I realize I can create a test case to determine the behavior, but I thought I would ask the list first.  How does the vtkGeometryFilter handle the case where you have a vtkUnstructuredGrid consisting of 3D cells (Hexas or Tets) that have 2D cells (Quads or tris) paved on their outer surface already?  Will it extract a single 2D cell for this face comprising the existing overlaid 2D cell, or will it extract two 2D cells; one for the existing and one for the 3D face?  If it does the latter, is there a clean way to get at only one of these faces?  For my case, I don't think it would matter which one, but perhaps I would preferentially choose to keep the existing 2D cell.  Maybe this is where pedigreeIDs are helpful?  I have to admit, I'm still trying to get my head around those.
Thanks,
Matt



We Bring Dimension To Your Ideas
Matthew Sutton
Lead Engineer, Software Development
Specialist Engineer
Phoenix Analysis & Design Technologies
7755 S. Research Dr, Suite 110
Tempe, AZ  85284
matt.sutton at padtinc.com
480-813-4884 x106 W
480-326-7940 M
480-813-4807 F
Simulation - Product Development - Rapid Prototyping www.PADTINC.com CONFIDENTIALITY NOTICE: This e-mail message and any attachments are for the sole use of the intended recipient(s) and may contain confidential and/or privileged information.  Unless you are the intended recipient, you are hereby notified that copying, forwarding, printing or otherwise disseminating the information contained in or attached to this e-mail is strictly prohibited. If you are not the intended recipient, please notify the sender by telephone, and immediately and permanently delete and destroy all copies and printouts of this e-mail message and/or attachments.  


_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Follow this link to subscribe/unsubscribe:
http://www.vtk.org/mailman/listinfo/vtkusers



More information about the vtkusers mailing list