[vtkusers] VtkImplicitBoolean Usage

DavidNg david.ng.dev at gmail.com
Sun Nov 24 05:47:58 EST 2013


Hi all,
    I have two vtkPolydata and converted into vtkImageData necessarily.
    I would union their and export as new vtkPolyData so i using
vtkImplicitBoolean
    But it don't work.
    Here is original polydata :
<http://vtk.1045678.n5.nabble.com/file/n5724598/bottle_repaired_clipping0.gif> 
<http://vtk.1045678.n5.nabble.com/file/n5724598/bottle_repaired_clipping1.gif> 

   Here is except result:
<http://vtk.1045678.n5.nabble.com/file/n5724598/bottle_repaired.gif> 

   How can i make correcting union operation??
   Following is my source code:
        
        self.readerFactory.src = mashModel;
        mashupData = self.readerFactory.getReader().GetOutput();
        volumeConvertor = myVTK.VolumeConverter();
        volumeConvertor.src = self.srcData;
        volumeOne = volumeConvertor.convert();
        volumeOneSize = volumeConvertor.getSize();
        volumeConvertor.src = mashupData;
        volumeTwo = volumeConvertor.convert();
        volumeTwoSize = volumeConvertor.getSize();
        
        newSize = [];
        for i in range(0,3):
            newSize.append(int(round(volumeOneSize[i] + volumeTwoSize[i])));
        sampleDimesions = [];
        for i in range(0,3):
            sampleDimesions.append(int(round(newSize[i]
/volumeConvertor.spacing[i])));
        newBox =
[0.0-newSize[0]/2.0,0.0+newSize[0]/2.0,0.0-newSize[1]/2.0,0.0+newSize[1]/2.0,0.0-newSize[2]/2.0,0.0+newSize[2]/2.0];

        print("Volume One Number of cell : {}\r\nNumber Of Point:{}
\r\n\r\n".format(volumeOne.GetNumberOfCells(),volumeOne.GetNumberOfPoints()));
        print("Volume Two Number of cell : {}\r\nNumber Of Point:{}
\r\n\r\n".format(volumeTwo.GetNumberOfCells(),volumeTwo.GetNumberOfPoints()));
        print("Size of volume one : {}".format(volumeOneSize));
        print("Size of volume two : {}".format(volumeTwoSize));
        print("Size of volume after union:{}".format(newSize));
        print("Sample dimesion after union:{}\r\n".format(sampleDimesions));
        
        #Transform vtkImageData to ImplicitFunction
        vOneImp = vtk.vtkImplicitVolume();
        vTwoImp = vtk.vtkImplicitVolume();
        vOneImp.SetVolume(volumeOne);
        vTwoImp.SetVolume(volumeTwo);
        
        #Union volumeOne and volumeTwo
        mashupHelper = vtk.vtkImplicitBoolean();
        mashupHelper.AddFunction(vTwoImp);
        mashupHelper.AddFunction(vOneImp);
        #mashupHelper.SetOperationTypeToDifference();
        #mashupHelper.SetOperationTypeToIntersection();
        #mashupHelper.SetOperationTypeToUnionOfMagnitudes();
        mashupHelper.SetOperationTypeToUnion();


        mashSample = vtk.vtkSampleFunction();
        mashSample.SetImplicitFunction(mashupHelper);
        mashSample.SetOutputScalarTypeToUnsignedChar();
        mashSample.SetSampleDimensions(*sampleDimesions);
        mashSample.SetModelBounds(*newBox);
        mashSample.CappingOn();

        #Back to poltdata by taking volume Isosurface
        surfaceConverter = vtk.vtkContourFilter();
        surfaceConverter.SetInputConnection(mashSample.GetOutputPort());
        surfaceConverter.GenerateValues(1, 1, 1);
        surfaceConverter.Update();
        
        result = surfaceConverter.GetOutput();
        print("Result Number of cell : {}\r\nNumber Of
Point:{}".format(result.GetNumberOfCells(),result.GetNumberOfPoints()));
        print("Size of Result : {}".format(result.GetBounds()));
        
        display = Displayer.ModelDisplay();
        
        #Try display transferred volume.
        #display.addPolyData(volumeOne);
        #display.addPolyData(volumeTwo);

        display.addPolyData(result);

        display.display();

I don't know following can helping debug or not.
Here is console output:
PLY file type = 3
PLY file type = 3
Interactive BBox:[-0.0, 26.53, 4.43, 89.19, -13.67, 13.59]
Poly Auto BBox :(-6.661338147750939e-16, 26.52680015563965,
4.426000118255615, 89.19232940673828, -13.669400215148926,
13.588500022888184)

Volume Auto BBox :(0.25, 26.75, 4.25, 88.75, -13.75, 13.75)

26.50
84.50
27.50
Interactive BBox:[-26.57, 0.0, 4.43, 89.19, -13.64, 13.55]
Poly Auto BBox :(-26.574800491333008, 1.7763568394002505e-15,
4.426000118255615, 89.19239807128906, -13.635358810424805,
13.554666519165039)

Volume Auto BBox :(-26.75, -0.25, 4.25, 88.75, -13.75, 13.75)

26.50
84.50
27.50
Volume One Number of cell : 492635
Number Of Point:514080 


Volume Two Number of cell : 492635
Number Of Point:514080 


Size of volume one : [26.5, 84.5, 27.5]
Size of volume two : [26.5, 84.5, 27.5]
Size of volume after union:[53, 169, 55]
Sample dimension after union:[106, 338, 110]

Result Number of cell : 0
Number Of Point:0
Size of Result : (1.0, -1.0, 1.0, -1.0, 1.0, -1.0)
Add Item to win

Anyone know how to do union??
 



--
View this message in context: http://vtk.1045678.n5.nabble.com/VtkImplicitBoolean-Usage-tp5724598.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list