[vtkusers] Fwd: Re: AND-filter for vtkPolyData (was extract/selectcoincident points/cells)

Dr. Roman Grothausmann grothausmann.roman at mh-hannover.de
Mon Sep 17 09:33:44 EDT 2012


Dear Alex, dear Jothy,


Many thanks for Your hint to use vtkBooleanOperationPolyDataFilter for 
this. It basically works but it seems not completely exact. I've 
attached an image that shows two touching blobs (raw meshes generated by 
discreteMarchingCubes, in attached tbz), one is rendered yellow, the 
other as wire frame. The intersection result (code below) of 
vtkBooleanOperationPolyDataFilter is rendered in blue, therefore it 
looks grey where it overlaps with the yellow faces. As you can see, one 
triangle is blue nonetheless. It exists on the blob rendered as wire 
frame but has no counter part on the yellow one, therefore does not 
belong to the set of coincident faces nor does the one corner point 
belong to the set of coincident vertices.
Since I do not really need a boolean operation (including surface 
intersections) and since Cory Quammen's publication on 
vtkBooleanOperationPolyDataFilter mentions that coplanar face are 
problematic and not treated specially, I thought that 
vtkDistancePolyDataFilter combined with a ThresholdBetween(0.0,0.0) on 
the point-data "Distance" would do the trick. However, I realized from a 
test, that there can be coincident vertices that do not belong to 
coincident faces. Now, I would need a method to find all faces in the 
second mesh which are made up completely by all the vertices from the 
first mesh with "Distance"==0. (Using GetPointCells for all verts with 
"Distance"==0 seems not to help here, since this way "border" 
cells/triangles incorporating only one ore two of the verts are selected 
as well.)
Using "Distance"==0 for the cell-data, does not work either because it 
contains cell-to-point distance (not cell-to-cell distance). Therefore, 
it needs a ThresholdBetween(0.0, t) where t is slightly greater than 0 
(I used t=0.01 in the code below). As the two meshes originate from 
marching-cubes, I guess an upper limit for t could be deduced from the 
theory which would still grantee that only coincident faces are selected 
this way, but I do not know for sure how to deduce this upper limit for t.

Do You have any ideas how to solve this problem?

Thanks for Your help or hints.
Roman

/////find and extract coincident vertices and faces of two marching 
cubes meshes

#include <vtkXMLPolyDataReader.h>//for vtp-files
// #include <vtkPolyDataReader.h>//for vtk-files
#include <vtkBooleanOperationPolyDataFilter.h>
#include <vtkXMLPolyDataWriter.h>//for vtp-files

int main(int argc, char* argv[]){
     if( argc <= 3 )
	{
	std::cerr << "Usage: " << argv[0];
	std::cerr << " inputMesh0";
	std::cerr << " inputMesh1";
	std::cerr << " outputMesh";
	std::cerr << std::endl;
	return EXIT_FAILURE;
	}

     if(!(strcasestr(argv[1],".vtp"))) {
	std::cout << "The input should end with .vtp" << std::endl;
	return -1;
	}

     if(!(strcasestr(argv[2],".vtp"))) {
	std::cout << "The input should end with .vtp" << std::endl;
	return -1;
	}

     //vtkPolyDataReader *reader = vtkPolyDataReader::New(); //*.vtk
     vtkXMLPolyDataReader *reader0 = vtkXMLPolyDataReader::New(); //*.vtp

     reader0->SetFileName(argv[1]);
     reader0->Update();

     vtkXMLPolyDataReader *reader1 = vtkXMLPolyDataReader::New(); //*.vtp

     reader1->SetFileName(argv[2]);
     reader1->Update();

     vtkBooleanOperationPolyDataFilter *boolean= 
vtkBooleanOperationPolyDataFilter::New();
     boolean->SetInputConnection(0, reader0->GetOutputPort());
     boolean->SetInputConnection(1, reader1->GetOutputPort());
     boolean->SetOperationToIntersection();

     vtkXMLPolyDataWriter *Pwriter = vtkXMLPolyDataWriter::New();
     //vtkDataSetWriter *Pwriter = vtkDataSetWriter::New();

     Pwriter->SetFileName(argv[3]);
     Pwriter->SetInputConnection(boolean->GetOutputPort(0));
     Pwriter->Update();


     return EXIT_SUCCESS;
     }

___________________________________________________________________


/////find and extract coincident vertices and faces of two marching 
cubes meshes
//// there can be coincident verts that do not belong to coincident 
faces!!!


#include <vtkXMLPolyDataReader.h>//for vtp-files
// #include <vtkPolyDataReader.h>//for vtk-files
//#include <vtkBooleanOperationPolyDataFilter.h>
#include <vtkDistancePolyDataFilter.h>
#include <vtkThreshold.h>
#include <vtkGeometryFilter.h>
#include <vtkXMLPolyDataWriter.h>//for vtp-files

int main(int argc, char* argv[]){
     if( argc != 4 )
	{
	std::cerr << "Usage: " << argv[0];
	std::cerr << " inputMesh0";
	std::cerr << " inputMesh1";
	std::cerr << " outputMesh";
	std::cerr << std::endl;
	return EXIT_FAILURE;
	}

     if(!(strcasestr(argv[1],".vtp"))) {
	std::cout << "The input should end with .vtp" << std::endl;
	return -1;
	}

     if(!(strcasestr(argv[2],".vtp"))) {
	std::cout << "The input should end with .vtp" << std::endl;
	return -1;
	}

     if(!(strcasestr(argv[3],".vtp"))) {
	std::cout << "The input should end with .vtp" << std::endl;
	return -1;
	}

     //vtkPolyDataReader *reader = vtkPolyDataReader::New(); //*.vtk
     vtkXMLPolyDataReader *reader0 = vtkXMLPolyDataReader::New(); //*.vtp

     reader0->SetFileName(argv[1]);
     reader0->Update();

     vtkXMLPolyDataReader *reader1 = vtkXMLPolyDataReader::New(); //*.vtp

     reader1->SetFileName(argv[2]);
     reader1->Update();

     vtkDistancePolyDataFilter *polydist= vtkDistancePolyDataFilter::New();
     polydist->SetInputConnection(0, reader0->GetOutputPort());
     polydist->SetInputConnection(1, reader1->GetOutputPort());
     polydist->SignedDistanceOff();
     //polydist->ComputeSecondDistanceOff(); //causes:
         /*
	  ERROR: In 
/home/grothama/sda8/programme/VTK/Filtering/vtkExecutive.cxx, line 756
	  vtkStreamingDemandDrivenPipeline (0x1d2a800): Algorithm 
vtkDistancePolyDataFilter(0x1d29890) returned failure for request: 
vtkInformation (0x1d4e040)
	  Debug: Off
	  Modified Time: 757
	  Reference Count: 1
	  Registered Events: (none)
	  Request: REQUEST_DATA
	  ALGORITHM_AFTER_FORWARD: 1
	  FROM_OUTPUT_PORT: 0
	  FORWARD_DIRECTION: 0
         */
     polydist->Update();

     vtkThreshold *thresh= vtkThreshold::New();
     thresh->SetInputConnection(polydist->GetOutputPort());
     //thresh->SetInputArrayToProcess(0, 0, 0, 
vtkDataObject::FIELD_ASSOCIATION_POINTS, "Distance"); // 
FIELD_ASSOCIATION_VERTICES
     //thresh->SetInputArrayToProcess(0, 0, 0, 
vtkDataObject::FIELD_ASSOCIATION_POINTS, vtkDataSetAttributes::SCALARS); 
// FIELD_ASSOCIATION_VERTICES
     thresh->SetInputArrayToProcess(0, 0, 0, 
vtkDataObject::FIELD_ASSOCIATION_CELLS, "Distance"); // 
FIELD_ASSOCIATION_VERTICES
     //thresh->SetAttributeModeToUsePointData();
     thresh->ThresholdBetween(0.0,0.01);

     vtkGeometryFilter *usg2poly= vtkGeometryFilter::New();
     usg2poly->SetInputConnection(thresh->GetOutputPort());

     vtkXMLPolyDataWriter *Pwriter = vtkXMLPolyDataWriter::New();
     //vtkDataSetWriter *Pwriter = vtkDataSetWriter::New();

     Pwriter->SetFileName(argv[3]);
     //Pwriter->SetInputConnection(polydist->GetOutputPort());
     Pwriter->SetInputConnection(usg2poly->GetOutputPort());
     Pwriter->Update();


     return EXIT_SUCCESS;
     }



On 17/09/12 10:10, Roman Grothausmann wrote:
>
>
>
> -------- Original Message --------
> Subject: Re: [vtkusers] AND-filter for vtkPolyData (was
> extract/selectcoincident points/cells)
> Date: Wed, 5 Sep 2012 10:49:20 +0200
> From: Roman Grothausmann <roman.grothausmann at helmholtz-berlin.de>
> To: alex Dowson <alexdowson at hotmail.com>, VTK Mailing List
> <vtkusers at vtk.org>
>
> Hello Alex,
>
>
> Many thanks for the hint, I had not thought of boolean operation for
> this since the only overlap, ie the union, would consist only of a
> surface, not a volume. I'll give it a try and see if it results in what
> I need. It could work since for the meshes I look at I can rule out that
> they could also have volume unions.
>
> Thanks again for Your hint
> Roman
>
> On 05.09.2012 09:15, alex Dowson wrote:
>> Hi
>>
>> Have you tried CSG Boolean filter in VTK ? Check this class
>>
>> http://www.vtk.org/doc/nightly/html/classvtkBooleanOperationPolyDataFilter.html
>>
>>
>>
>> Also you can use implicit boolean operation filter for that.
>>
>>
>>
>>
>> -----Original Message----- From: Roman Grothausmann
>> Sent: Wednesday, September 05, 2012 12:42 PM
>> To: VTK Mailing List
>> Subject: [vtkusers] AND-filter for vtkPolyData (was
>> extract/selectcoincident points/cells)
>>
>> Dear mailing list members,
>>
>>
>> Is there a kind of AND-filter for vtkPolyData-meshes which I could use
>> to extract/select coincident points/cells of two meshes?
>>
>> Thanks for any hints or help
>> Roman
>>
>> On 31.08.2012 14:53, Roman Grothausmann wrote:
>>> Dear mailing list members,
>>>
>>>
>>> There are many filters in VTK to clean/merge coincident points but I
>>> could not find a single filter that extracts/selects coincident
>>> points/cells.
>>> I would need it to extract the sub-mesh of two or more
>>> vtkPolyData-meshes where these meshes overlap, e.g. when a
>>> vtkDiscreteMarchingCubes surface is generated of two or more labels that
>>> directly touch each other in voxel space.
>>> Or is there a way to just generate a mesh of the area where both labels
>>> touch?
>>>
>>> Any help or hints are very much appreciated
>>> Roman
>>>
>>
>

-- 
Dr. Roman Grothausmann

Tomographie und Digitale Bildverarbeitung
Tomography and Digital Image Analysis

Institut für Funktionelle und Angewandte Anatomie, OE 4120
Medizinische Hochschule Hannover
Carl-Neuberg-Str. 1
30625 Hannover

Tel. +49 511 532-9574
-------------- next part --------------
A non-text attachment was scrubbed...
Name: coincident_test.tbz
Type: application/x-bzip-compressed-tar
Size: 32865 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120917/c7386a9e/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: intersec_3284-3307_raw_03_01.png
Type: image/png
Size: 110743 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20120917/c7386a9e/attachment.png>


More information about the vtkusers mailing list