GithubHelp home page GithubHelp logo

zippy84 / vtkbool Goto Github PK

View Code? Open in Web Editor NEW
149.0 17.0 37.0 4.63 MB

A new boolean operations filter for VTK

License: Apache License 2.0

C++ 78.99% Python 18.68% CMake 2.33%
vtk paraview boolean-operations meshes graphics-library 3d c-plus-plus python scientific-computing mesh-csg mesh-boolean csg pytest

vtkbool's Introduction

vtkbool CMake codecov DOI

About

This is an extension of the graphics library VTK. The goal of the extension is to equip the library with boolean operations on polygonal meshes. I started the project at the end of my studies in mechanical engineering at the University of Applied Sciences (HTWK) in Leipzig. I used VTK to develop a program, which I had to create for a paper. At this time I would have wished, that this feature already exists. There was several implementations from third parties, but after some tests, I came to the conclusion, that none of them worked correct. I decided to start with my own implementation. This library is the result of my efforts.

Features

  • based on VTK
  • 4 operation types available (union, intersection, difference and difference2 - difference with interchanged operands)
  • triangulation is not needed
  • all types of polygonal cells are supported (triangles, quads, polygons, triangle-strips)
  • triangle-strips and quads will be transformed into triangles (quads only if their points are not on the same plane)
  • non-convex polygons are allowed
  • meshes can be stacked (coplanar polygons are right handled)
  • the meshes don’t need to be watertight
  • CellData is passed (attached by the rules of vtkAppendPolyData)
  • contact-lines are available in the 3th output
  • the filter is able to embed holes
  • compileable as ParaView plugin
  • Python wrapped

Limitations

  • the filter assumes well defined triangles, quads and polygons
  • PointData is not preserved - you have to do your own mapping (use OrigCellIdsA and OrigCellIdsB)

Requirements

  • CMake >= 3.12
  • VTK >= 9.0
  • C++17 compiler

Optional

  • ParaView >= 5.0
  • Python 3.x

Library

To include vtkbool into your program, you have to compile it as a library. All you need is an installation of VTK with header files. If you have installed VTK over your package manager, CMake is able to find the required files. Otherwise you have to set VTK_DIR manually. It must be a path like /home/zippy/VTK9/lib/cmake/vtk-9.1 or C:/Users/zippy/VTK9/lib/cmake/vtk-9.1.

The usage of the library is very simple. Look at the example in the section below. You can set the operation mode by calling one of the named methods:

  • SetOperModeToNone
  • SetOperModeToUnion
  • SetOperModeToIntersection
  • SetOperModeToDifference
  • SetOperModeToDifference2

The alternative is the more generic SetOperMode. The method must be called with the number of the desired operation, an integer between 0 and 4, with the same meaning as mentioned before. The default is Union.

C++ Example

Create a directory somewhere in your file system, download vtkbool and unpack it into that.

mkdir example
cd example
git clone https://github.com/zippy84/vtkbool.git

Then create the following two files:

test.cxx

#include <vtkSmartPointer.h>
#include <vtkCubeSource.h>
#include <vtkCylinderSource.h>
#include <vtkPolyDataWriter.h>

#include "vtkPolyDataBooleanFilter.h"

int main (int argc, char *argv[]) {
    auto cube = vtkSmartPointer<vtkCubeSource>::New();
    cube->SetYLength(.5);

    auto cyl = vtkSmartPointer<vtkCylinderSource>::New();
    cyl->SetResolution(32);
    cyl->SetHeight(.5);
    cyl->SetCenter(0, .5, 0);

    auto bf = vtkSmartPointer<vtkPolyDataBooleanFilter>::New();
    bf->SetInputConnection(0, cube->GetOutputPort());
    bf->SetInputConnection(1, cyl->GetOutputPort());
    bf->SetOperModeToDifference();

    auto writer = vtkSmartPointer<vtkPolyDataWriter>::New();
    writer->SetInputConnection(bf->GetOutputPort());
    writer->SetFileName("result.vtk");
    writer->Update();

    return 0;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.12 FATAL_ERROR)
project(test)

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

# find_package(VTK REQUIRED COMPONENTS FiltersSources IOLegacy)

find_package(VTK REQUIRED COMPONENTS FiltersSources IOLegacy FiltersExtraction FiltersGeometry FiltersModeling FiltersFlowPaths WrappingPythonCore)

if(VTK_FOUND)
    include_directories(vtkbool)
    add_subdirectory(vtkbool)

    add_executable(test test.cxx)
    target_link_libraries(test PRIVATE vtkBool ${VTK_LIBRARIES})

    vtk_module_autoinit(
        TARGETS test
        MODULES ${VTK_LIBRARIES}
    )
endif(VTK_FOUND)

Inside the example directory, create a subdirectory called build and cd into it. You should have a directory structure that looks something like this:

example
├── build
├── CMakeLists.txt
├── test.cxx
└── vtkbool
    ├── CMakeLists.txt
    ├── ...
    └── vtkPolyDataContactFilter.h

From inside the build directory, run ccmake .., follow the instructions, and finally type make.

Running ./test will now produce the result.vtk file.

ParaView Plugin

To build the plugin you have to compile ParaView from source. Download the current version from http://www.paraview.org and follow the compilation instructions. As soon as ParaView is compiled, it may take a while, you can build the plugin by activating the VTKBOOL_PARAVIEW option within CMake. In CMake you also have to point to ParaView_DIR if CMake can't found it and it is not installed in a common location like /usr/lib or /usr/local/lib. Make sure PARAVIEW_INSTALL_DEVELOPMENT_FILES is set.

When everything has been compiled successfully, you can install the plugin.

Python

The Python module will be generated automatically, if three conditions are met:

  • vtkbool is configured as a library
  • Python 3 is installed with header files
  • VTK itself is wrapped to Python

After a successful compilation, the module can be used as follows:

import sys
sys.path.append('/path/to/your/build/directory') # also look into the python files in the testing directory

from vtkmodules.vtkFiltersSources import vtkCubeSource, vtkSphereSource
from vtkmodules.vtkIOLegacy import vtkPolyDataWriter
from vtkBool import vtkPolyDataBooleanFilter

cube = vtkCubeSource()

sphere = vtkSphereSource()
sphere.SetCenter(.5, .5, .5)
sphere.SetThetaResolution(20)
sphere.SetPhiResolution(20)

boolean = vtkPolyDataBooleanFilter()
boolean.SetInputConnection(0, cube.GetOutputPort())
boolean.SetInputConnection(1, sphere.GetOutputPort())
boolean.SetOperModeToDifference()

# write the result, if you want ...

writer = vtkPolyDataWriter()
writer.SetInputConnection(boolean.GetOutputPort())
writer.SetFileName('result.vtk')

writer.Update()

Conda

The library is also available at conda-forge. In your virtual environment you can install the package with:

conda install -c conda-forge vtkbool

Unlike in the python example, you need to import it like this:

from vtkbool.vtkBool import vtkPolyDataBooleanFilter

Errors and their meaning

  • Bad shaped cells detected.

    At least one cell has a bad shape. For a cell with more than three points: not all points lie on the plane defined by the calculated surface normal.

  • First/Second input has non-manifold edges.

    The contact goes through a non-manifold edge. A non-manifold edge is an edge that is shared by three or more cells. In general this is not a problem, unless they are part of the intersection.

  • There is no contact.

    What it says.

  • Contact ends suddenly.

    The intersection is incomplete. That is, an intersection line ends in the middle of a cell. The cell cannot be divided.

  • Strips are invalid.

    There are two reasons for that kind of error:

    1. at least two intersection lines intersect each other - the input, one of them, contains an assembly
    2. there are different intersection points with the same capturing point - normally a capturing point will be used by only one point of the intersection lines
  • CutCells failed.

    Will be printed out only, if some holes couldn't be merged into their outer cells.

  • Boolean operation failed.

    A boolean operation can fail at the end, if some of the intersection lines are not part of the result.

Copyright

2012-2024 Ronald Römer

License

Apache License, Version 2.0

vtkbool's People

Contributors

calumfreeman avatar zippy84 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

vtkbool's Issues

Long road to version 3.0

There are still a few tasks that must be done:

  • a solution for the sandclock problem
  • it is possible that the Merger can't find a second connection in some cases
  • inaccurate normals must be handled - sometimes the inaccuracy is not a problem, sometimes it is - especially in GetStripPoints

Boolean operation between two planar surface

Is it possibile to support boolean operation between surfaces instead of closed volume?
image

#include <vtkCubeSource.h>
#include <vtkCylinderSource.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkXMLPolyDataWriter.h>

#include "vtkPolyDataBooleanFilter.h"

int Point::_tag = 0; // important

int main(int argc, char* argv[]) {
    vtkSmartPointer<vtkXMLPolyDataReader> reader1 =
        vtkSmartPointer<vtkXMLPolyDataReader>::New();
    reader1->SetFileName("obj1.vtp");
    reader1->Update();

    vtkSmartPointer<vtkXMLPolyDataReader> reader2 =
        vtkSmartPointer<vtkXMLPolyDataReader>::New();
    reader2->SetFileName("obj2.vtp");
    reader2->Update();

    vtkPolyDataBooleanFilter* bf = vtkPolyDataBooleanFilter::New();
    bf->SetInputData(0, reader1->GetOutput());
    bf->SetInputData(1, reader2->GetOutput());
    bf->SetOperModeToDifference();
    bf->Update();

    WriteVTK("test1.vtk", bf->GetOutput(0));

    vtkSmartPointer<vtkXMLPolyDataWriter> writer =
        vtkSmartPointer<vtkXMLPolyDataWriter>::New();
    writer->SetInputData(bf->GetOutput());
    writer->SetFileName("test2.vtp");
    writer->Write();

    bf->Delete();
    reader1->Delete();
    reader2->Delete();

    return 0;
}

surface_meshes.zip

Union does not work for disjoint meshes

vtkPolyDataBooleanFilter in union mode only works if the two input meshes intersect. Can you change it to also support disjoint meshes? Currently I have to choose vtkPolyDataBooleanFilter or vtkAppendPolyData based on whether they intersect.

Problem with boolean operations on a model

Hello,
when I try to e.g. create the difference from "Skull.vtp" and "Cut Object.vtp", I don't get the expected result. Can you have a look at it? As you can see in the attached file "Result.vtp", there is no cut being done. Instead the objects are fused together. The other operations don't seem to work either.

The files used are in here:
VTK Objects.zip

Update:
I tested with debug build and I get an assert:
"vtkPolyDataBooleanFilter.cxx:1797: void vtkPolyDataBooleanFilter::MergePoints(vtkPolyData*, PolyStripsType&): Assertion `numPts > 0' failed."

Update2:
Upon further testing I discovered that the size is a problem. If I scale the models down it seems to work, but I have to use the difference2 operator instead of difference to get the result I need.

Crash when computing difference for certain meshes

First of all, thank you very much for this library. We are trying to use it for creating surgical guides for fibula flap reconstructions and it seems to work very well for most of the cases.

Unfortunately, sometimes the code crashes in this line:

if ((*(_s.begin()) == 1) ^ TestCW(_poly)) {

because _s vector is empty.

If you want to reproduce it: subtract DrillHole-dec.vtk from Plate-dec.vtk (the files are available here).

Do you have any suggestion for at least how to avoid the crash? Should we just add a if (!_s.empty()) {} check so that p.dir remains Dir::UNDEFINED?

conda-forge packaging

Is there any interest in packaging this up as a conda package on conda-forge? I have this almost-working on some non-public CI, but this could be easily translated to conda-forge.

The Python module should be relatively easy. Not sure about the ParaView extension, as I don't use those.

One prerequisite would be to set up official versions and releases of this project.

SetOperModeToDifference result missing components

Issue

The result missing components when the input model has mult components.

Preview

Input A B preview
Output preview

Input Model

input A
input B

Test code

#include "stdafx.h"
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPolyDataMapper.h"
#include "vtkActor.h"
#include "vtkProperty.h"
#include "vtkCamera.h"
#include "vtkSTLReader.h"
#include "vtkPolyDataBooleanFilter.h" 
#include "vtkNew.h"

int main()
{
  vtkNew<vtkSTLReader> pReaderA;
  pReaderA->SetFileName("../bunny.stl"); 
  pReaderA->Update();

  vtkNew<vtkSTLReader> pReaderB ;
  pReaderB->SetFileName("../punching.stl"); 
  pReaderB->Update();

  vtkNew<vtkPolyDataBooleanFilter> bf;
  bf->SetInputData(0, pReaderA->GetOutput());
  bf->SetInputData(1, pReaderB->GetOutput());
  bf->SetOperModeToDifference();
  bf->Update();

  vtkNew<vtkPolyDataMapper> polyDataMapper;
  polyDataMapper->SetInputData(bf->GetOutput());

  vtkNew<vtkActor> polyDataActor;
  polyDataActor->SetMapper(polyDataMapper);
  polyDataActor->GetProperty()->SetColor(1.0000, 0.3882, 0.2784);

  vtkNew<vtkRenderer> ren1;
  vtkNew<vtkRenderWindow> renWin;
  renWin->AddRenderer(ren1);
  vtkNew<vtkRenderWindowInteractor> iren;
  iren->SetRenderWindow(renWin);

  ren1->AddActor(polyDataActor);

  ren1->SetBackground(0.1, 0.2, 0.4);
  renWin->SetSize(200, 200);

  ren1->ResetCamera();
  ren1->GetActiveCamera()->Zoom(1.5);
  renWin->Render();

  // This starts the event loop and as a side effect causes an initial render.
  iren->Start();

  return 0;
}

get an assertion on a model

Hello,
When I try to get the intersection of test1.vtk and test2.vtk, I get an assertion:
vtkPolyDataBooleanFileter.cxx:2160:PolyPair GetEdgePolys(vtkPolyData*, vtkIdList*, vtkIdList*):Assertion 'opp.size() == 2'.
Could you please have a look at the problem? The file is attached:
test.zip

Thank you.

Way to turn off the console script.

Hello, zippy84

May I have a question for turning off the debug script during boolean operation?
during the boolean, I watched so much lines in my console window.
I'd like to control it to check the performance of my app.

the below is a part of script shown. Please review.

GetEdgePolys()
polyId 88, ptIdA 115, ptIdB 112
polyId 89, ptIdA 377, ptIdB 378
GetEdgePolys()
polyId 4762, ptIdA 473, ptIdB 474
polyId 4763, ptIdA 2577, ptIdB 2582
GetLoc() -> polyId 88, cA 2, cB 2
GetLoc() -> polyId 89, cA 2, cB 2
GetLoc() -> polyId 4762, cA 2, cB 2
GetLoc() -> polyId 4763, cA 2, cB 2
polyId 88, sA 0, loc 1
polyId 89, sA 1, loc 2
polyId 4762, sB 0, loc 1
polyId 4763, sB 1, loc 2
line 53
GetEdgePolys()
polyId 88, ptIdA 114, ptIdB 115
polyId 89, ptIdA 378, ptIdB 379
GetEdgePolys()
polyId 4764, ptIdA 474, ptIdB 475
polyId 4765, ptIdA 2576, ptIdB 2577
GetLoc() -> polyId 88, cA 2, cB 2
GetLoc() -> polyId 89, cA 2, cB 2
GetLoc() -> polyId 4764, cA 2, cB 2
GetLoc() -> polyId 4765, cA 2, cB 2
polyId 88, sA 0, loc 1
polyId 89, sA 1, loc 2
polyId 4764, sB 0, loc 1
polyId 4765, sB 1, loc 2
line 54

Issues compiling the library

Hi,

Thank you for your library. I tried to compile the library but i got many errors. First in cmake as i am not using python i had to delete all the vtkWrappingPythonCore references , otherwise i got an error. I also deleted this line string(REPLACE "/" "\" vtk_lib ${VTK_INSTALL_PREFIX}) as it was causing me an error saying that it requires 4 parameters. Doing this, I was able to generate the project linking with my vtk binary bolder. I am using windows withn vs2105.

The problem came when i built the project. I got many errors of missing libraries ans also some functions as back_inserts is not member of std and also some more error of linkage.

Coud you tell me what i am doing wrong with the installation?. i think it might be for something i deleted but i do not want to install python and the replace line does not work and i do not understand why.

Thank you

The cmake modified

cmake_minimum_required(VERSION 3.1)
project(vtkbool VERSION 2.6)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(MSVC)
set(CMAKE_CXX_FLAGS "/EHsc")
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
else()
set(CMAKE_CXX_FLAGS "-Wno-deprecated -fPIC -Wunused")
endif()

option(BUILD_PARAVIEW_PLUGIN "" OFF)
option(BUILD_AS_DEBUG "" OFF)
option(BUILD_TESTING "" OFF)

mark_as_advanced(BUILD_AS_DEBUG)

set(srcs
vtkPolyDataBooleanFilter.cxx
vtkPolyDataContactFilter.cxx
Utilities.cxx)

include_directories(".")

if(BUILD_AS_DEBUG)
add_definitions(-DDEBUG)
endif()

if(BUILD_PARAVIEW_PLUGIN)
set(BUILD_TESTING OFF CACHE BOOL "" FORCE)

add_subdirectory(paraview_plugin ${CMAKE_BINARY_DIR}/paraview_plugin)

else()

#unset(VTK_DIR CACHE)

find_package(VTK REQUIRED COMPONENTS vtkFiltersSources vtkIOLegacy vtkFiltersExtraction vtkFiltersGeometry vtkFiltersModeling vtkRenderingFreeType  NO_MODULE)

if(VTK_FOUND)
    include(${VTK_USE_FILE})

    add_subdirectory(libs)

    include_directories(libs/merger libs/decomp libs/vp libs/aabb)

    add_library(${PROJECT_NAME} SHARED ${srcs})
    target_link_libraries(${PROJECT_NAME} ${VTK_LIBRARIES} decomp merger)

   

    if(BUILD_TESTING)
        enable_testing()

        add_executable(testing testing/testing.cxx)
        target_link_libraries(testing ${PROJECT_NAME} ${VTK_LIBRARIES})

        foreach(i RANGE 19)
            add_test(NAME Test_${i} COMMAND testing ${i})

            if(WIN32)
                set_property(TEST Test_${i} PROPERTY ENVIRONMENT "PATH=${vtk_lib}\\bin")
            endif()

        endforeach()

    endif()

    if(VTK_WRAP_PYTHON)

        set(ENV{LD_LIBRARY_PATH} "${VTK_INSTALL_PREFIX}/lib")

        execute_process(COMMAND "${VTK_INSTALL_PREFIX}/bin/vtkpython" -c "import sys; sys.stdout.write('.'.join(map(str, sys.version_info[:2])))" OUTPUT_VARIABLE py_version)

        if(CMAKE_VERSION VERSION_LESS "3.12")
            find_package(PythonInterp "${py_version}")
            find_package(PythonLibs "${py_version}")

            if(PYTHONLIBS_FOUND)

                include_directories(${PYTHON_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR})

                include(vtkWrapPython)

                vtk_wrap_python3(${PROJECT_NAME}Python ${PROJECT_NAME}Python_srcs vtkPolyDataBooleanFilter.cxx)

                add_library(${PROJECT_NAME}PythonD ${${PROJECT_NAME}Python_srcs})
                target_link_libraries(${PROJECT_NAME}PythonD ${PROJECT_NAME}  vtkCommonExecutionModelPythonD)

                python_add_module(${PROJECT_NAME}Python PyInit.cxx ${PROJECT_NAME}PythonInit.cxx)
                target_link_libraries(${PROJECT_NAME}Python PRIVATE ${PROJECT_NAME}PythonD)

                if(BUILD_TESTING)
                    add_test(NAME Test_Py COMMAND ${PYTHON_EXECUTABLE}
                        ${CMAKE_SOURCE_DIR}/testing/test_py_module.py
                        ${VTK_INSTALL_PREFIX}/lib/python${py_version}/site-packages
                        ${CMAKE_BINARY_DIR}
                        $<CONFIG>)

                    if(WIN32)
                        set_property(TEST Test_Py PROPERTY ENVIRONMENT "PATH=${vtk_lib}\\bin")
                    else()
                        set_property(TEST Test_Py PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${VTK_INSTALL_PREFIX}/lib")
                    endif()
                endif()

            endif()

        else()
            if (py_version MATCHES "^3")
                find_package(Python3 COMPONENTS Interpreter Development)

                if(Python3_Development_FOUND)

                    include_directories(${PYTHON_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR})

                    include(vtkWrapPython)

                    vtk_wrap_python3(${PROJECT_NAME}Python ${PROJECT_NAME}Python_srcs vtkPolyDataBooleanFilter.cxx)

                    add_library(${PROJECT_NAME}PythonD ${${PROJECT_NAME}Python_srcs})
                    target_link_libraries(${PROJECT_NAME}PythonD ${PROJECT_NAME}  vtkCommonExecutionModelPythonD)

                    Python3_add_library(${PROJECT_NAME}Python MODULE PyInit.cxx ${PROJECT_NAME}PythonInit.cxx)
                    target_link_libraries(${PROJECT_NAME}Python PRIVATE ${PROJECT_NAME}PythonD)

                    if(BUILD_TESTING)
                        add_test(NAME Test_Py COMMAND ${Python3_EXECUTABLE}
                            ${CMAKE_SOURCE_DIR}/testing/test_py_module.py
                            ${VTK_PYTHONPATH}
                            ${CMAKE_BINARY_DIR}
                            $<CONFIG>)

                        if(WIN32)
                            set_property(TEST Test_Py PROPERTY ENVIRONMENT "PATH=${vtk_lib}\\bin")
                        else()
                            set_property(TEST Test_Py PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${VTK_INSTALL_PREFIX}/lib")
                        endif()
                    endif()
                endif()

            elseif(py_version EQUAL "2.7")
                find_package(Python2 COMPONENTS Interpreter Development)

                if(Python2_Development_FOUND)

                    include_directories(${PYTHON_INCLUDE_DIRS} ${PROJECT_SOURCE_DIR})

                    include(vtkWrapPython)

                    vtk_wrap_python3(${PROJECT_NAME}Python ${PROJECT_NAME}Python_srcs vtkPolyDataBooleanFilter.cxx)

                    add_library(${PROJECT_NAME}PythonD ${${PROJECT_NAME}Python_srcs})
                    target_link_libraries(${PROJECT_NAME}PythonD ${PROJECT_NAME}  vtkCommonExecutionModelPythonD)

                    Python2_add_library(${PROJECT_NAME}Python MODULE PyInit.cxx ${PROJECT_NAME}PythonInit.cxx)
                    target_link_libraries(${PROJECT_NAME}Python PRIVATE ${PROJECT_NAME}PythonD)

                    if(BUILD_TESTING)
                        add_test(NAME Test_Py COMMAND ${Python2_EXECUTABLE}
                            ${CMAKE_SOURCE_DIR}/testing/test_py_module.py
                            ${VTK_PYTHONPATH}
                            ${CMAKE_BINARY_DIR}
                            $<CONFIG>)

                        if(WIN32)
                            set_property(TEST Test_Py PROPERTY ENVIRONMENT "PATH=${vtk_lib}\\bin")
                        else()
                            set_property(TEST Test_Py PROPERTY ENVIRONMENT "LD_LIBRARY_PATH=${VTK_INSTALL_PREFIX}/lib")
                        endif()
                    endif()
                endif()

            endif()

        endif()

    endif()

endif(VTK_FOUND)

endif()

Console spam from union

This program seems to produce the correct output, but vtkPolyDataBooleanFilter spamming the console with warnings:

Exception on M0.961699,-3.62496 1.16723,-3.59148 2.0933,-3.21335 2.38779,-3.0101 2.42476,-2.99417 3.03956,-3.6255 0.960441,-3.6255 Z, Exception (Simplify, failed)
Exception on M0.961699,-2.74498 1.16723,-2.71151 2.0933,-2.33337 2.38779,-2.13013 2.42476,-2.11419 3.03956,-2.74553 0.960441,-2.74553 Z, Exception (Simplify, failed)
Exception on M0.961699,-1.86501 1.16723,-1.83154 2.0933,-1.4534 2.38779,-1.25016 2.42476,-1.23422 3.03956,-1.86556 0.960441,-1.86556 Z, Exception (Simplify, failed)
Exception on M0.961699,-0.985037 1.16723,-0.951563 2.0933,-0.573427 2.38779,-0.370182 2.42476,-0.354246 3.03956,-0.985579 0.960441,-0.985579 Z, Exception (Simplify, failed)
Exception on M0.961699,-0.105064 1.16723,-0.07159 2.0933,0.306546 2.38779,0.509791 2.42476,0.525727 3.03956,-0.105606 0.960441,-0.105606 Z, Exception (Simplify, failed)
Exception on M0.961699,0.774916 1.16723,0.808389 2.0933,1.18653 2.38779,1.38977 2.42476,1.40571 3.03956,0.774373 0.960441,0.774373 Z, Exception (Simplify, failed)
Exception on M0.961699,1.65487 1.16723,1.68835 2.0933,2.06648 2.38779,2.26973 2.42476,2.28566 3.03956,1.65433 0.960441,1.65433 Z, Exception (Simplify, failed)
Exception on M0.961699,2.53485 1.16723,2.56832 2.0933,2.94646 2.38779,3.1497 2.42476,3.16564 3.03956,2.5343 0.960441,2.5343 Z, Exception (Simplify, failed)
Exception on M0.961699,3.41484 1.16723,3.44831 2.0933,3.82645 2.38779,4.02969 2.42476,4.04563 3.03956,3.41429 0.960441,3.41429 Z, Exception (Simplify, failed)
Exception on M0.961699,4.29481 1.16723,4.32828 2.0933,4.70642 2.38779,4.90967 2.42476,4.9256 3.03956,4.29427 0.960441,4.29427 Z, Exception (Simplify, failed)
Exception on M0.961699,5.17478 1.16723,5.20826 2.0933,5.58639 2.38779,5.78964 2.42476,5.80558 3.03956,5.17424 0.960441,5.17424 Z, Exception (Simplify, failed)
Exception on M0.961699,6.05471 1.16723,6.08818 2.0933,6.46632 2.38779,6.66956 2.42476,6.6855 3.03956,6.05417 0.960441,6.05417 Z, Exception (Simplify, failed)
Exception on M0.961699,-3.62496 1.16723,-3.59148 1.31631,-3.53061 2.0933,-3.21335 2.38779,-3.0101 2.42476,-2.99417 3.03956,-3.6255 0.960441,-3.6255 Z, Exception (Simplify, failed)
Exception on M0.961699,-2.74498 1.16723,-2.71151 1.35068,-2.6366 2.0933,-2.33337 2.38779,-2.13013 2.42476,-2.11419 3.03956,-2.74553 0.960441,-2.74553 Z, Exception (Simplify, failed)
Exception on M0.961699,-1.86501 1.14202,-1.83564 1.16723,-1.83154 1.35585,-1.75452 2.0933,-1.4534 2.38779,-1.25016 2.42476,-1.23422 3.03956,-1.86556 0.960441,-1.86556 Z, Exception (Simplify, failed)
Exception on M0.961699,-0.985037 1.14202,-0.955668 1.16723,-0.951563 1.35585,-0.874543 2.0933,-0.573427 2.38779,-0.370182 2.42476,-0.354246 3.03956,-0.985579 0.960441,-0.985579 Z, Exception (Simplify, failed)
Exception on M0.961699,-0.105064 1.14202,-0.0756951 1.16723,-0.07159 1.35585,0.00542999 2.0933,0.306546 2.38779,0.509791 2.42476,0.525727 3.03956,-0.105606 0.960441,-0.105606 Z, Exception (Simplify, failed)
Exception on M0.961699,0.774916 1.14202,0.804284 1.16723,0.808389 1.35585,0.88541 2.0933,1.18653 2.38779,1.38977 2.42476,1.40571 3.03956,0.774373 0.960441,0.774373 Z, Exception (Simplify, failed)
Exception on M0.961699,1.65487 1.14202,1.68424 1.16723,1.68835 1.35585,1.76537 2.0933,2.06648 2.38779,2.26973 2.42476,2.28566 3.03956,1.65433 0.960441,1.65433 Z, Exception (Simplify, failed)
Exception on M0.961699,2.53485 1.14202,2.56422 1.16723,2.56832 1.35585,2.64534 2.0933,2.94646 2.38779,3.1497 2.42476,3.16564 3.03956,2.5343 0.960441,2.5343 Z, Exception (Simplify, failed)
Exception on M0.961699,3.41484 1.14202,3.44421 1.16723,3.44831 1.35585,3.52533 2.0933,3.82645 2.38779,4.02969 2.42476,4.04563 3.03956,3.41429 0.960441,3.41429 Z, Exception (Simplify, failed)
Exception on M0.961699,4.29481 1.14202,4.32418 1.16723,4.32828 1.35585,4.4053 2.0933,4.70642 2.38779,4.90967 2.42476,4.9256 3.03956,4.29427 0.960441,4.29427 Z, Exception (Simplify, failed)
Exception on M0.961699,5.17478 1.14202,5.20415 1.16723,5.20826 1.35585,5.28528 2.0933,5.58639 2.38779,5.78964 2.42476,5.80558 3.03956,5.17424 0.960441,5.17424 Z, Exception (Simplify, failed)
Exception on M0.961699,6.05471 1.14202,6.08408 1.16723,6.08818 1.35585,6.1652 2.0933,6.46632 2.38779,6.66956 2.42476,6.6855 3.03956,6.05417 0.960441,6.05417 Z, Exception (Simplify, failed)
Exception on M2.07124,8.08013 2.07205,8.08001 1.52347,5.26169 1.51743,5.26169 Z, Exception (Simplify, failed)
Exception on M3.345,14.624 3.34581,14.6239 2.79723,11.8055 2.79118,11.8055 Z, Exception (Simplify, failed)
Exception on M-1.13254,-13.7513 -1.12657,-13.7504 -1.26561,-16.6194 -1.26643,-16.6194 Z, Exception (Simplify, failed)
Exception on M-0.821677,-7.0919 -0.815699,-7.09103 -0.95474,-9.96 -0.955563,-9.96 Z, Exception (Simplify, failed)
Exception on M-0.899395,-8.75676 -0.893418,-8.75588 -1.03246,-11.6248 -1.03328,-11.6248 Z, Exception (Simplify, failed)
Exception on M-0.588526,-2.09734 -0.582548,-2.09646 -0.721589,-4.96543 -0.722412,-4.96543 Z, Exception (Simplify, failed)
Exception on M-1.21027,-15.4162 -1.20429,-15.4153 -1.34333,-18.2843 -1.34415,-18.2843 Z, Exception (Simplify, failed)
Exception on M-0.666243,-3.76219 -0.660265,-3.76132 -0.799306,-6.63029 -0.800128,-6.63029 Z, Exception (Simplify, failed)
Exception on M-0.977111,-10.4216 -0.971134,-10.4207 -1.11017,-13.2897 -1.111,-13.2897 Z, Exception (Simplify, failed)

Please add a flag to disable these warnings.

Crash on combining certain models

Hello, I have been using vtkbool extensively through Slicer's "Combine Models" wrapper. Mostly, it works very well and is very helpful. However, I have run into a case where when I try to find the union of two overlapping models vtkbool crashes. I have tried using Slicer surface toolbox's "Clean" and "Compute Normals" with auto-orientation to clean up any coincident points and fix any problematic normal vectors (I believe these use vtkCleanPolyData an vtkPolyDataNormals under the hood), but these pre-processing steps do not help. The models which cause the crash are available at https://www.dropbox.com/sh/ael0c6hw8xs7nb8/AABuDKGnZUGQ0o47gjTzQlsRa?dl=0
I'm not sure how to diagnose what might be going wrong, vtkbool usually "just works". There are no error messages which are logged in Slicer, the application just crashes.

Crash On CombineRegions( ) method when execute SetOperModeToDifference

Hi Ronald. Firstly, thank you very much for your excellent work.
Recently I've been using vtkbool to do difference operation of two vtkPolyData. When the program run to CombineRegions() method, it will crash. And I found that the crash happened at Line2894~Line2895 in vtkPolyDataBooleanFilter.cxx file. When the crash happens, the number of 'regsB->GetNumberOfCells()' is larger than the number of 'scalarsB->GetSize()', so when the iteration variable 'i' is larger than the number of 'scalarsB->GetSize()', access violation occurs. I tried to change the code to avoid the access violation problem, and the program can run and get the output vtkPolyData, but the result vtkPolyData seems to be the result of Union instead of Difference. And if I use SetOperModeToUnion, the result seems to be result of Difference instead of Union, very strange behavior.
Can you give any help about this problem?
I've created a repository for my test program and test data used in my code. You can find the repository by the following link : vtkboolTest.

Thanks again for your great library!

Output mesh is fragmented

Hello. There is a case with finding intersection between 2 toruses.

image
Input: 2 toruses with a shifting. Quality of the mesh is pretty high (40Mb stl binary), holes between parts have approximately 1-2 triangles in the width.
Also, execution time is close to 5min on modern PC. Union and difference finished in ~15 minutes with the same result.

please help install

can you please add instructions on how to install for a general newbie?

Can I use my pip installed version of VTK? Do I have to build from source? Where is my VTK_DIR?

I'm getting this error msg when trying to install using cmake.. I have VTK installed via pip

image

Disconnected faces after connected components

Hello, I found a weird behaviour after applying a subtraction using your library.

I am trying to subtract two polydatas and if i do not apply connected components, the result looks ok, but if I apply the connected components filter to get the largest region, the result is a small subset of faces of what it should be the whole component. I show this issue in images

Result of the boolean subtraction without connected components is ok
rhino_guide

Result of the boolean subtraction with connected components fails
resultAfterconnectedComponent

The code seems ok to me. So I wonder if it is a bug in the way to connect faces. I wonder if there is a way to solve this issue.

     vtkSmartPointer<vtkTriangleFilter> tri1 =
		vtkSmartPointer<vtkTriangleFilter>::New();
	tri1->SetInputData(splint);
	vtkSmartPointer<vtkCleanPolyData> clean1 =
		vtkSmartPointer<vtkCleanPolyData>::New();
	clean1->SetInputConnection(tri1->GetOutputPort());
	clean1->Update();
	vtkSmartPointer<vtkStripper> strip1 =
		vtkSmartPointer<vtkStripper>::New();
	strip1->SetInputConnection(clean1->GetOutputPort());
	strip1->Update();
	vtkNew<vtkPolyDataNormals> normal1;
	normal1->SetInputData(strip1->GetOutput());
	normal1->ComputePointNormalsOn();
	normal1->ComputeCellNormalsOff();
	normal1->Update();
	auto input1 = normal1->GetOutput();

	vtkSmartPointer<vtkTriangleFilter> tri2 =
		vtkSmartPointer<vtkTriangleFilter>::New();
	tri2->SetInputData(polydataToSubstractToSplint);
	tri2->Update();
	vtkSmartPointer<vtkCleanPolyData> clean2 =
		vtkSmartPointer<vtkCleanPolyData>::New();
	clean2->SetInputConnection(tri2->GetOutputPort());
	clean2->Update();
	vtkSmartPointer<vtkStripper> strip2 =
		vtkSmartPointer<vtkStripper>::New();
	strip2->SetInputConnection(clean2->GetOutputPort());
	strip2->Update();
	vtkNew<vtkPolyDataNormals> normal2;
	normal2->SetInputData(strip2->GetOutput());
	normal2->ComputePointNormalsOn();
	normal2->ComputeCellNormalsOff();
	normal2->Update();
	auto input2 = normal2->GetOutput();
	vtkPolyDataBooleanFilter *bf2 = vtkPolyDataBooleanFilter::New();
	bf2->SetInputData(0, input1);
	bf2->SetInputData(1, input2);
	bf2->SetOperModeToDifference();
	try {
		bf2->Update();
	}

I attach some polydatas for testing in case this issue is unknown.

https://we.tl/t-STIpdaCFNQ

Thanks

Intersection of meshes gives sometimes an empty mesh

Hi Ronald. Thank you very much for your work. With our opensource free Slicer module BoneReconstructionPlanner virtual surgical planning of mandibular reconstruction using fibula is possible. But using your library we are able to take the plan to the operating room with patient-specific surgical guides.

Here are some examples of what we achieved using your library (already used on clinical cases):

111072265-8bd87600-84b8-11eb-8087-6cdee7cd40bc
108536826-a8b7ca00-72bb-11eb-9ca1-a4a7703f7ae1

Right now we are trying to get the intersection of fibula bone pieces but the result is an empty mesh when it shouldn't be that way.

Here are meshes to replicate this behaviour:
Meshes.zip

The operations that fail are:
"Fibula Segment 0A-0B.vtk" intersection "Fibula Segment 1A-1B.vtk"
"Fibula Segment 1A-1B.vtk" intersection "Fibula Segment 2A-2B.vtk"

Hope you can help. Thank you again for this great library

Cannot compile on Mac

Hi,

I am unable to compile the library on Mac, I have vtk5.10 installed thorought macports. The error I get when running make is ....
Scanning dependencies of target vtkbool
[ 8%] Building CXX object CMakeFiles/vtkbool.dir/vtkPolyDataBooleanFilter.cxx.o
[ 16%] Building CXX object CMakeFiles/vtkbool.dir/vtkPolyDataContactFilter.cxx.o
[ 25%] Building CXX object CMakeFiles/vtkbool.dir/GeomHelper.cxx.o
[ 33%] Linking CXX shared library libvtkbool.dylib
[ 33%] Built target vtkbool
[ 41%] Python Wrapping - generating vtkboolPythonInit.cxx
[ 50%] Python Wrapping - generating vtkPolyDataBooleanFilterPython.cxx
Scanning dependencies of target vtkboolPythonD
[ 58%] Building CXX object CMakeFiles/vtkboolPythonD.dir/vtkPolyDataBooleanFilterPython.cxx.o
[ 66%] Building CXX object CMakeFiles/vtkboolPythonD.dir/vtkboolPythonInit.cxx.o
[ 75%] Linking CXX static library libvtkboolPythonD.a
[ 75%] Built target vtkboolPythonD
Scanning dependencies of target vtkboolPython
[ 83%] Building CXX object CMakeFiles/vtkboolPython.dir/vtkboolPythonInit.cxx.o
[ 91%] Linking CXX shared module libvtkboolPython.so
Undefined symbols for architecture x86_64:
"_PyBool_FromLong", referenced from:
vtkPythonArgs::BuildValue(bool) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"_PyDict_SetItemString", referenced from:
_PyVTKAddFile_vtkPolyDataBooleanFilter in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"_PyErr_Occurred", referenced from:
vtkPythonArgs::ErrorOccurred() in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"_PyInt_FromLong", referenced from:
vtkPythonArgs::BuildValue(int) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"PyModule_GetDict", referenced from:
real_initvtkboolPython(char const
) in vtkboolPythonInit.cxx.o
"PyString_FromString", referenced from:
vtkPythonArgs::BuildValue(char const
) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"_PyVTKClass_New", referenced from:
_PyVTKClass_vtkPolyDataBooleanFilterNew in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"PyVTKClass_Type", referenced from:
vtkPythonArgs::GetSelfPointer(object, object) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
vtkPythonArgs::vtkPythonArgs(object, object, char const
) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"PyVTKClass_vtkPolyDataAlgorithmNew", referenced from:
PyVTKClass_vtkPolyDataBooleanFilterNew in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"PyVTKObject_GetObject", referenced from:
PyvtkPolyDataBooleanFilter_NewInstance(object, object) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"PyVTKObject_SetFlag", referenced from:
PyvtkPolyDataBooleanFilter_NewInstance(object, object) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"PyVTKObject_Type", referenced from:
PyvtkPolyDataBooleanFilter_NewInstance(object, object) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"Py_FatalError", referenced from:
real_initvtkboolPython(char const
) in vtkboolPythonInit.cxx.o
"Py_InitModule4_64", referenced from:
real_initvtkboolPython(char const
) in vtkboolPythonInit.cxx.o
"Py_NoneStruct", referenced from:
vtkPythonArgs::BuildValue(char const
) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
vtkPythonArgs::BuildNone() in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"vtkPythonArgs::ArgCountError(int, int)", referenced from:
vtkPythonArgs::CheckArgCount(int) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"vtkPythonArgs::GetArgAsVTKObject(char const
, bool&)", referenced from:
bool vtkPythonArgs::GetVTKObject(vtkObject
&, char const
) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"vtkPythonArgs::GetSelfFromFirstArg(object, object)", referenced from:
vtkPythonArgs::GetSelfPointer(object, object) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"vtkPythonArgs::GetValue(char
&)", referenced from:
PyvtkPolyDataBooleanFilter_IsA(object, object) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"vtkPythonArgs::GetValue(bool&)", referenced from:
PyvtkPolyDataBooleanFilter_SetMergeAll(object, object) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"vtkPythonArgs::GetValue(int&)", referenced from:
PyvtkPolyDataBooleanFilter_SetOperMode(object, object) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
"vtkPythonUtil::GetObjectFromPointer(vtkObjectBase
)", referenced from:
vtkPythonArgs::BuildVTKObject(void const
) in libvtkboolPythonD.a(vtkPolyDataBooleanFilterPython.cxx.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[2]: *** [libvtkboolPython.so] Error 1
make[1]: *** [CMakeFiles/vtkboolPython.dir/all] Error 2
make: *** [all] Error 2

Cannot run python example code

Hi,
I have compiled vtkbool successfully. I can import it. When I try the python example in README.md, I got an error.
Screenshot from 2020-03-10 11-36-21
Message of error:
Screenshot from 2020-03-10 11-38-02

SetOperModeToDifference not working on a simple case

Hello,

I tried SetOperModeToDifference on these two inputs, but it didn't work.
Basically I want to subtract "bottomBox.ply" from "frontAndBackBoxes.ply". My code is like this:

// Subtract bottom box
auto subtractOperation = vtkSmartPointer<vtkPolyDataBooleanFilter>::New();
subtractOperation->SetOperModeToDifference();
subtractOperation->SetInputData(0, frontAndBackBoxes);
subtractOperation->SetInputData(1, bottomBox);
subtractOperation->Update();

The output has zero cells.
I then tried with CGAL demo app and it worked fine there.
Could you please check this case?

Thanks,
Truong

Inputs.zip

How to build vtkbool for Python

Thanks for your excellent work. I am working on a project to construct a large 3D mesh from multiple small parts and find vtkbool might be a good solution. However, I cannot figure out how to build vtkbool for python. I have installed VTK using anaconda and it works well. However, I cannot find a path like '/home/zippy/VTK9/lib/cmake/vtk-9.1' in my computer since it is required to build vtkbool as described in README. Furthermore, the following instructions made me confused: 1. vtkbool is configured as a library, 2. Python 3 is installed with header files, 3.VTK itself is wrapped to Python. Could you please provide a detailed instruction on how to build vtkbool for python. Thanks!

Question on vtkbool - the way to find error code

Hello, zippy84

I am enjoying to use yours.
I have a question fo using vtkbool.

during the run of my app, I saw the below message during the boolean for two objects.

I'd like to get this code with a flag variable. is it possible to get?
or I need to check with another function?

actually this is the issue for No contact between two polydata during the boolean.
if possible to get the flag in vtkbool, I'd like to use it. Could you review my question?

ERROR: In vtkPolyDataBooleanFilter.cxx, line 163
vtkPolyDataBooleanFilter (00000258A7796B20): Inputs have no contact.

Thanks

Difference of meshes sometimes an empty mesh

In some cases we get an error message like "Contact ends suddenly at point ..." and the resulting mesh is empty.

For example:

  • subtracting fibula.vtk from guide.vtk results in an empty mesh
  • subtracting fibula-dec.vtk from guide-dec.vtk (decimated versions of the two larger data sets) results in an empty mesh

Download meshes from here.

Union still does not work for disjoint meshes

I filed #26, which got duped to #19. #19 was marked as fixed, but the union of disjoint objects still isn't working for me. I still get this error:

ERROR: In /home/kyle/nrf/vtk_print_examples/vtkbool/vtkPolyDataBooleanFilter.cxx, line 186
vtkPolyDataBooleanFilter (0x18fa280): Inputs have no contact.

Cannot compile on mac with vtk 8.1.1

Hi, I tried to compile vtkbool but I've got some issues.
I could generate the xcode project but I had to delete pythronWrapper from CMakelists.txt (I'm gonna use c++ so I don't really care) and I had to comment the replace line on the if (vtk_found)
After those two changes I'm able to build xcode, but I'm not able to build the project because of vp that includes and xcode says that it has invalid operations and not matching functions (?)
image
Is there any way to fix those errors? or that someone could share their compiled libraries with me?

Cutting surfaces

Hi, do you think this library could be used to cut one open surface PolyData (cells are triangles) with another one? For cutting I mean obtaining the intersection line, adding this line to the PolyData, and cutting it in parts along the line.

Thanks!

returning value

int vtkPolyDataContactFilter::IntersectOBBNodes (vtkOBBNode *nodeA, vtkOBBNode *nodeB, vtkMatrix4x4 *mat, void *caller) {
    vtkPolyDataContactFilter *self = reinterpret_cast<vtkPolyDataContactFilter*>(caller);

    vtkIdList *cellsA = nodeA->Cells;
    vtkIdList *cellsB = nodeB->Cells;

    for (int i = 0; i < cellsA->GetNumberOfIds(); i++) {
        vtkIdType ci = cellsA->GetId(i);

        for (int j = 0; j < cellsB->GetNumberOfIds(); j++) {
            vtkIdType cj = cellsB->GetId(j);

            self->IntersectPolys(ci, cj);
        }
    }
}

for this function what will IntersectOBBNodes return? it doesnt compile with msvc 2012 because of this problem

Get an error when build the project

Hello developer, I get a problem when I use the vtkbool. I copy the dir in my project and add add_subdirectory(vtkbool-2.5.2) in the root CMakeLists.txt. When I build my project, I get an error.

In file included from /home/wzx/CLionProjects/tube_connect/test/util/../../util/../vtkbool-2.5.2/vtkPolyDataBooleanFilter.h:30,
                 from /home/wzx/CLionProjects/tube_connect/test/util/../../util/TubeUtil.h:21,
                 from /home/wzx/CLionProjects/tube_connect/test/util/TubeUtilTest.cpp:7:
/home/wzx/CLionProjects/tube_connect/test/util/../../util/../vtkbool-2.5.2/Utilities.h:27:10: Fatal error:Tools.h:No such file or directory
 #include "Tools.h"
          ^~~~~~~~~

Proper interface to allow generation of python wrappers.

HI Zippy

I gave it a brief try. The many templated classes without exports and explicit exports for the different types gave me a lot of trouble. Would it be of interest to hide away InterPolys in an inner class and only let the implementations know of the templated types. The algorithms seems very input -> output, so it could be done.

In this way, it can be added as an external module to VTK and also allow wrapping in python using wheels.

Let me know, if this has any interest.... Is the module mature enough for this?

Undefined symbols for architecture x86_64: "Point::_tag", referenced in MAC using xcode

Hello,

Congratulations for your excellent work. I am trying to compile your library in MAC. I wonder if it is compatible with MAC.
I got the following error:

Undefined symbols for architecture x86_64:
"Point::_tag", referenced from:
Point::Point(double, double, int) in vtkPolyDataBooleanFilter.o
Point::Point(double, double, int) in libmerger.a(Merger.o)
Point::Point(double, double, int) in libvp.a(VisPoly.o)
Point::Point(double, double, int) in libvp.a(RmTrivials.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)

I also commented:
//#ifdef _WIN32
//int Point::_tag;
//#endif

but it shouldn't be necessary.

Thank you very much

sometimes it does not work when connect some tubes

Hello developer. I get an error when I use vtkPolyDataBooleanFilter to connect some tubes.

    array<double, 3> point1{0.001,10.122,100.000};
    array<double, 3> point2{-0.000,-10.128,100.000};

    array<double, 3> point3{10.125,-0.003,99.995};
    array<double, 3> point4{-10.124,-0.002,100.005};

    array<double, 3> point5{7.160,7.157,100.000};
    array<double, 3> point6{-7.159,-7.162,100.000};

    auto line1 = vtkSmartPointer<vtkLineSource>::New();
    line1->SetPoint1(point1.data());
    line1->SetPoint2(point2.data());

    auto line2 = vtkSmartPointer<vtkLineSource>::New();
    line2->SetPoint1(point3.data());
    line2->SetPoint2(point4.data());

    auto line3 = vtkSmartPointer<vtkLineSource>::New();
    line3->SetPoint1(point5.data());
    line3->SetPoint2(point6.data());

    auto tube1 = vtkSmartPointer<vtkTubeFilter>::New();
    tube1->SetRadius(3);
    tube1->SetNumberOfSides(30);
    tube1->SetInputConnection(line1->GetOutputPort());

    auto tube2 = vtkSmartPointer<vtkTubeFilter>::New();
    tube2->SetRadius(3);
    tube2->SetNumberOfSides(30);
    tube2->SetInputConnection(line2->GetOutputPort());

    auto tube3 = vtkSmartPointer<vtkTubeFilter>::New();
    tube3->SetRadius(3);
    tube3->SetNumberOfSides(30);
    tube3->SetInputConnection(line3->GetOutputPort());

    auto booleanFilter1 = vtkSmartPointer<vtkPolyDataBooleanFilter>::New();
    booleanFilter1->SetInputConnection(0,tube1->GetOutputPort());
    booleanFilter1->SetInputConnection(1, tube2->GetOutputPort());
    booleanFilter1->SetOperModeToUnion();

    auto booleanFilter2 = vtkSmartPointer<vtkPolyDataBooleanFilter>::New();
    booleanFilter2->SetInputConnection(0,booleanFilter1->GetOutputPort());
    booleanFilter2->SetInputConnection(1, tube3->GetOutputPort());
    booleanFilter2->SetOperModeToUnion();

    booleanFilter2->Update();

These three tubes clearly have a common intersection at the origin and do not overlap, but the program does not give the expected result. It output

tube_connect_test: /home/wzx/CLionProjects/tube_connect/vtkbool-2.5.2/vtkPolyDataBooleanFilter.cxx:1997: void vtkPolyDataBooleanFilter::MergePoints(vtkPolyData*, PolyStripsType&): Assertion `numPts > 0' failed.

The strange thing is When I remove the last digit of the decimal, It works

    array<double, 3> point1{0.00,10.12,100.00};
    array<double, 3> point2{-0.00,-10.128,100.00};

    array<double, 3> point3{10.12,-0.00,99.99};
    array<double, 3> point4{-10.12,-0.00,100.00};

    array<double, 3> point5{7.16,7.15,100.00};
    array<double, 3> point6{-7.15,-7.16,100.00};

Boolean operation issue.

I'm trying to use boolean operation(union, intersection, difference)
However, when I executed the operation my qt application got this error.

예외가 throw됨: 읽기 액세스 위반입니다.
_Pnext이(가) 0x1A400000008였습니다.
image
image

What am I doing wrong?

vtkSmartPointer MeshEditor::BooleanOperation(BooleanOperationMode mode,vtkSmartPointer data1, vtkSmartPointer data2) {

vtkSmartPointer<vtkBooleanOperationPolyDataFilter> booleanOperation = vtkSmartPointer<vtkBooleanOperationPolyDataFilter>::New();
vtkPolyDataBooleanFilter *booleanOperation2 = vtkPolyDataBooleanFilter::New();
switch (mode) {
case BooleanOperationMode::UNION:
	booleanOperation->SetOperationToUnion();
	booleanOperation2->SetOperModeToUnion();
	break;
case BooleanOperationMode::INTERSECTION:
	booleanOperation->SetOperationToIntersection();
	booleanOperation2->SetOperModeToIntersection();
	break;
case BooleanOperationMode::DIFFERENCE:
	booleanOperation->SetOperationToDifference();
	booleanOperation2->SetOperModeToDifference();
	break;
}

booleanOperation->SetInputData(0, data1);
booleanOperation->SetInputData(1, data2);
booleanOperation->Update();

vtkSmartPointer<vtkTriangleFilter> triangleFilter = vtkSmartPointer<vtkTriangleFilter>::New();
triangleFilter->SetInputData(data1);
triangleFilter->Update();
vtkSmartPointer<vtkTriangleFilter> triangleFilter2 = vtkSmartPointer<vtkTriangleFilter>::New();
triangleFilter2->SetInputData(data2);
triangleFilter2->Update();

booleanOperation2->SetInputConnection(0, triangleFilter->GetOutputPort());
booleanOperation2->SetInputConnection(1, triangleFilter2->GetOutputPort());
booleanOperation2->SetOperModeToUnion();
booleanOperation2->Update();

vtkSmartPointer<vtkPolyDataNormals> normalGenerator = vtkSmartPointer<vtkPolyDataNormals>::New();
normalGenerator->SetInputData(booleanOperation2->GetOutput());
normalGenerator->ComputePointNormalsOn();
normalGenerator->ComputeCellNormalsOn();
normalGenerator->Update();

return normalGenerator->GetOutput();

}

Python work with Conda ModuleNotFoundError: No module named 'vtkBool' or ImportError: Initialization failed for vtkBool, not compatible with vtkmodules.vtkCommonCore

Hi zippy,
Great thanks for your contribution! I work fine with C++ following your tips in the readme, but when it comes to Python I traped in it.
my conda env
conda 22.9.0
Python 3.7.9
VTK 9.2.6
I compile VTK9.2.6 and build vtkBool successfully,
(
cmake ..

...
-- Found Python3: /home/yangyixuan/anaconda3/envs/tool/bin/python3.7 (found suitable version "3.7.9", minimum required is "3.7") found components: Interpreter Development.Module Development.Embed
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_VISIBILITY - Success
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY
-- Performing Test COMPILER_HAS_HIDDEN_INLINE_VISIBILITY - Success
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR
-- Performing Test COMPILER_HAS_DEPRECATED_ATTR - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /media/yangyixuan/yyx/tool/Tool/tool/vtkbool/build

cmake --build .

...
[ 70%] Building CXX object CMakeFiles/vtkBoolPython.dir/CMakeFiles/vtkBoolPython/vtkPolyDataBooleanFilterPython.o
[ 76%] Building CXX object CMakeFiles/vtkBoolPython.dir/CMakeFiles/vtkBoolPython/vtkPolyDataContactFilterPython.o
[ 82%] Building CXX object CMakeFiles/vtkBoolPython.dir/CMakeFiles/vtkBoolPython/vtkBoolModulePython.o
[ 88%] Building CXX object CMakeFiles/vtkBoolPython.dir/CMakeFiles/vtkBoolPythonPython/vtkBoolPythonInit.o
[ 94%] Building CXX object CMakeFiles/vtkBoolPython.dir/CMakeFiles/vtkBoolPythonPython/vtkBoolPythonInitImpl.o
[100%] Linking CXX shared module lib/python3.7/site-packages/vtkbool/vtkBool.so
[100%] Built target vtkBoolPython

)
But sys.path.append doesn't work when I run the Python demo code, it gives out Error
sys.path.append('/media/yangyixuan/yyx/tool/Tool/tool/vtkbool/build')

ModuleNotFoundError: No module named 'vtkBool'

Then I put vtkBool.so in to conda env dir
media/yangyixuan/DATA/anaconda3/envs/tool/lib/python3.7, it gives out Error

ImportError: Initialization failed for vtkBool, not compatible with vtkmodules.vtkCommonCore

Could you please help me out, I can't find a solution on google...great thanks, and really appreciate your contribution!

Python Wrappings with Ubuntu 18

Hi,
I've been trying unsuccessfully to get the vtkbool Python bindings to work with Python3, VTK7 on Ubuntu 18. I have to use Python3, but flexible on what VTK version to use.

As a sanity check, I've been following the steps from https://ci.appveyor.com/project/zippy84/vtkbool/builds/28398290/job/ikr5mvvms5eh1tip
I've removed VTK from my system via "apt purge" and pip on my machine.

I then run the commands:

sudo apt-get install -y libvtk7.1 libvtk7-dev python3-vtk7
ls /usr/bin/vtk*  # prints the same files as link above
mkdir build
cd build
cmake -DVTKBOOL_TESTING=ON -DCMAKE_BUILD_TYPE=Release ..
make
ctest

When I run the cmake, I get the same messages and warnings as the test and the same passes as ctest. However, there is no Test_Py created, same as the link above.

I think it's because there's no ${_vtk}/bin/vtkpython command/file here in CMakeLists.txt on my machine. When I manually set this to "3.6", the version working with my VTK Python wrappings, everything builds and compiles, but the test results in a seg fault.

Here's the print out from the failing ctest: https://pastebin.com/hRvMd7jG
I've tried importing vtkBoolPython in an interactive python session but still getting a seg fault.

Any help on getting the python bindings to work would be greatly appreciated!

Build error with vtk_wrap_hierarchy with VTK9

With VTK-9.0.1 that comes default in Fedora 34, I'm getting a compilation error building vtkbool.

CMake Error at vtkbool/CMakeLists.txt:113 (include):
  include could not find load file:

    vtkWrapHierarchy


CMake Error at vtkbool/CMakeLists.txt:114 (vtk_wrap_hierarchy):
  Unknown CMake command "vtk_wrap_hierarchy".

It's because vtkWrapHierarchy was removed in Kitware/VTK@8d61ac6.

I'm not using the PythonWrapper. Maybe you could disable it by default in VTK 9 until this problem is fixed?

-        if(VTK_WRAP_PYTHON)
+        if(VTK_WRAP_PYTHON AND ${VTK_MAJOR_VERSION} LESS 9)

Head does not build on Fedora

I can build the 2.7.2 branch, but the head of vtkbool (26575b8) does not build for me:

make[2]: *** No rule to make target 'vtkbool/vtkboolHierarchy.txt', needed by 'vtkbool/vtkPolyDataBooleanFilterPython.cxx'.  Stop.
make[1]: *** [CMakeFiles/Makefile2:521: vtkbool/CMakeFiles/vtkboolPythonD.dir/all] Error 2
make: *** [Makefile:84: all] Error 2

I'm using Fedora 30 with vtk-8.1.1-5.fc30.x86_64.

This is my build file.

boolean error

Hi zippy84,
first of all thank you very much for this great project.
I'm testing some boolean operation: the filter perform ok, but sometimes it fails. I attach a testcase with a minimal code and 2 test polydata.
The error is: vtkPolyDataBooleanFilter (000001CE689D23D0): Contact is ambiguous or incomplete (at line 33).
Can you have some suggestion to avoid this kind of errors?
Thank you very much in advance.

boolean_test.zip

can not compile in VS2015

Hello, code can not compile in vs 2015
VS does not allow this: double pts_[numPts][3], double [num][3] in vtkPolyDataBooleanFilter.cxx
Variable Length Array is not standard in C++

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.