├── hints ├── Wrapping ├── hints └── Tcl │ ├── vtkbioeng │ └── vtkbioeng.tcl │ ├── MakePackages.tcl │ └── pkgIndex.tcl.in ├── Testing ├── CMakeLists.txt ├── Cxx │ ├── CMakeLists.txt │ ├── TestCollisionDetection1.cxx │ └── TestCollisionDetection.cxx └── Tcl │ ├── TestRemoveCellsFilter.tcl │ └── TestBufferOutputWindow.tcl ├── Utilities ├── CMakeLists.txt └── Doxygen │ ├── CMakeLists.txt │ ├── doxyfile.in │ └── doc_makeall.sh.in ├── vtkWrapperInit.data.in ├── JavaDependencies.cmake.in ├── vtkBioengConfigure.h.in ├── vtkSelectCellsFilter.cxx ├── LICENSE.md ├── vtkRemoveCellsFilter.cxx ├── vtkSelectCellsFilter.h ├── vtkBufferOutputWindow.cxx ├── vtkBufferOutputWindow.h ├── vtkRemoveCellsFilter.h ├── vtkTesselateBoundaryLoops.h ├── vtkTesselateBoundaryLoops.cxx ├── vtkCellsFilter.h ├── CMakeLists.txt ├── vtkCellsFilter.cxx ├── vtkCollisionDetectionFilter.h └── vtkCollisionDetectionFilter.cxx /hints: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Wrapping/hints: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /Testing/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SUBDIRs(Cxx) -------------------------------------------------------------------------------- /Utilities/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | SUBDIRS(Doxygen) 2 | -------------------------------------------------------------------------------- /vtkWrapperInit.data.in: -------------------------------------------------------------------------------- 1 | @VTK_WRAPPER_INIT_DATA@ 2 | -------------------------------------------------------------------------------- /Wrapping/Tcl/vtkbioeng/vtkbioeng.tcl: -------------------------------------------------------------------------------- 1 | # Here's the place to add some tcl procs to the vtkbioeng package 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /JavaDependencies.cmake.in: -------------------------------------------------------------------------------- 1 | # This file is automatically generated by CMake VTK_WRAP_JAVA 2 | SET(VTK_JAVA_DEPENDENCIES ${VTK_JAVA_DEPENDENCIES} 3 | @VTK_JAVA_DEPENDENCIES_FILE@ 4 | ) 5 | -------------------------------------------------------------------------------- /Wrapping/Tcl/MakePackages.tcl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env tclsh 2 | 3 | # Execute this script each time you add a new directory or file. 4 | 5 | # Packages 6 | pkg_mkIndex -direct -verbose vtkbioeng 7 | 8 | exit -------------------------------------------------------------------------------- /Testing/Cxx/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | ADD_EXECUTABLE(TestCollisionDetection TestCollisionDetection.cxx) 2 | ADD_EXECUTABLE(TestCollisionDetection1 TestCollisionDetection1.cxx) 3 | 4 | TARGET_LINK_LIBRARIES(TestCollisionDetection vtkRendering vtkBioeng) 5 | TARGET_LINK_LIBRARIES(TestCollisionDetection1 vtkRendering vtkBioeng) -------------------------------------------------------------------------------- /Wrapping/Tcl/pkgIndex.tcl.in: -------------------------------------------------------------------------------- 1 | package ifneeded {vtkbioeng} {@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@} { 2 | if {@VTKBIOENG_BUILD_SHARED_LIBS_CONFIG@} { 3 | package require -exact vtkinit {@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@} 4 | foreach kit {@VTKBIOENG_KITS@} { 5 | package require -exact "${kit}TCL" {@VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@} 6 | } 7 | ::vtk::init::load_library_package {@PROJECT_NAME@TCL} {@VTKBIOENG_TCL_LIBRARY_DIR@} 8 | } else { 9 | error {Error loading @PROJECT_NAME@TCL. @PROJECT_NAME@ must be built\ 10 | with shared libraries for loading as a Tcl package.} 11 | } 12 | 13 | if {[catch {source [file join @PROJECT_BINARY_DIR@ Wrapping tcl vtkbioeng vtkbioeng.tcl]} errorMessage]} { 14 | puts $errorMessage 15 | } else { 16 | package provide vtkbioeng @VTK_MAJOR_VERSION@.@VTK_MINOR_VERSION@ 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /vtkBioengConfigure.h.in: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | This source has no copyright. It is intended to be copied by users 3 | wishing to create their own VTK classes locally. 4 | =========================================================================*/ 5 | #ifndef __Configure_h 6 | #define __Configure_h 7 | 8 | // Define @PROJECT_NAME@_SHARED if the library was built shared. 9 | #if @VTKBIOENG_BUILD_SHARED_LIBS_CONFIG@ 10 | # define @PROJECT_NAME@_SHARED 11 | #endif 12 | 13 | #if defined(_MSC_VER) && defined(vtkBioeng_SHARED) 14 | # pragma warning ( disable : 4275 ) 15 | #endif 16 | 17 | #if defined(_WIN32) && defined(vtkBioeng_SHARED) 18 | # if defined(vtkBioeng_EXPORTS) 19 | # define VTK_BIOENG_EXPORT __declspec( dllexport ) 20 | # else 21 | # define VTK_BIOENG_EXPORT __declspec( dllimport ) 22 | # endif 23 | #else 24 | # define VTK_BIOENG_EXPORT 25 | #endif 26 | 27 | #endif // __vtkBioengConfigure_h 28 | -------------------------------------------------------------------------------- /Utilities/Doxygen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Build the documentation 3 | # 4 | 5 | INCLUDE (${CMAKE_ROOT}/Modules/Documentation.cmake OPTIONAL) 6 | 7 | IF (BUILD_DOCUMENTATION) 8 | OPTION (DOCUMENTATION_DOWNLOAD_VTK_TAGFILE 9 | "Download the VTK tag file." ON) 10 | MARK_AS_ADVANCED ( 11 | DOCUMENTATION_DOWNLOAD_VTK_TAGFILE 12 | ) 13 | 14 | SET(VTKBIOENG_SOURCE_DIR ${PROJECT_SOURCE_DIR}) 15 | SET(VTKBIOENG_BINARY_DIR ${PROJECT_BINARY_DIR}) 16 | 17 | # 18 | # Configure the script and the doxyfile, then add target 19 | # 20 | IF(NOT DOT_PATH) 21 | GET_FILENAME_COMPONENT(DOT_PATH ${DOT} PATH) 22 | ENDIF(NOT DOT_PATH) 23 | 24 | CONFIGURE_FILE( 25 | ${VTKBIOENG_SOURCE_DIR}/Utilities/Doxygen/doxyfile.in 26 | ${VTKBIOENG_BINARY_DIR}/Utilities/Doxygen/doxyfile) 27 | 28 | CONFIGURE_FILE( 29 | ${VTKBIOENG_SOURCE_DIR}/Utilities/Doxygen/doc_makeall.sh.in 30 | ${VTKBIOENG_BINARY_DIR}/Utilities/Doxygen/doc_makeall.sh) 31 | 32 | ADD_CUSTOM_TARGET(vtkBioengDoxygenDoc 33 | ${BASH} 34 | ${VTKBIOENG_BINARY_DIR}/Utilities/Doxygen/doc_makeall.sh) 35 | 36 | ENDIF (BUILD_DOCUMENTATION) 37 | -------------------------------------------------------------------------------- /vtkSelectCellsFilter.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | 3 | Program: Visualization Toolkit 4 | Module: vtkSelectCellsFilter.cxx 5 | Language: C++ 6 | Version: $Id$ 7 | 8 | Copyright (c) 2004 Goodwin Lawlor 9 | All rights reserved. 10 | 11 | This software is distributed WITHOUT ANY WARRANTY; without even 12 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 13 | PURPOSE. 14 | 15 | =========================================================================*/ 16 | #include "vtkSelectCellsFilter.h" 17 | #include "vtkIdList.h" 18 | #include "vtkObjectFactory.h" 19 | 20 | vtkCxxRevisionMacro(vtkSelectCellsFilter, "$Revision$"); 21 | vtkStandardNewMacro(vtkSelectCellsFilter); 22 | 23 | void vtkSelectCellsFilter::RemoveUnmarkedCells() 24 | { 25 | 26 | vtkIdType numIds = this->CellIdList->GetNumberOfIds(); 27 | vtkIdType id; 28 | 29 | for (vtkIdType i = 0; i < numIds; i++) 30 | { 31 | id = this->CellIdList->GetId(i); 32 | if (this->MarkedCellIdList->IsId(id) == -1) 33 | { 34 | this->CellIdList->DeleteId(id); 35 | } 36 | } 37 | 38 | this->InitializeScalars(); 39 | this->Modified(); 40 | } 41 | 42 | void vtkSelectCellsFilter::PrintSelf(ostream& os, vtkIndent indent) 43 | { 44 | this->Superclass::PrintSelf(os,indent); 45 | 46 | os << indent << "Number of cells removed: " 47 | << this->GetNumberOfRemovedCells() 48 | << "\n"; 49 | } 50 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006, Goodwin Lawlor 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 5 | 6 | * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. 7 | 8 | * Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. 9 | 10 | * Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. 11 | 12 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 13 | -------------------------------------------------------------------------------- /Testing/Tcl/TestRemoveCellsFilter.tcl: -------------------------------------------------------------------------------- 1 | # A tcl script to test vtkRemoveCellsFilter 2 | # Press "p" to remove cells 3 | # Pres "u" to restore removed cells 4 | package require vtk 5 | package require vtkinteraction 6 | package require vtkbioeng 7 | 8 | wm withdraw . 9 | 10 | vtkSpherePuzzle puzzle 11 | 12 | vtkStripper stripper 13 | stripper SetInput [puzzle GetOutput] 14 | 15 | vtkRemoveCellsFilter remove 16 | remove SetInput [stripper GetOutput] 17 | remove SetUnmarkedColor 0.8 0.8 0.9 18 | remove SetMarkedColor 1 0 0 19 | #remove SetMarkedOpacity 0 20 | 21 | vtkPolyDataMapper mapper 22 | mapper SetInput [remove GetOutput] 23 | mapper SetScalarModeToUseCellData 24 | 25 | vtkActor actor 26 | actor SetMapper mapper 27 | [actor GetProperty] BackfaceCullingOn 28 | [actor GetProperty] SetColor 0.8 0.8 0.9 29 | 30 | vtkCellPicker cpick 31 | cpick AddObserver EndPickEvent ToggleCell 32 | cpick SetTolerance 0.001 33 | 34 | vtkRenderer ren 35 | ren AddActor actor 36 | ren SetBackground 1 1 1 37 | vtkRenderWindow renwin 38 | renwin AddRenderer ren 39 | vtkRenderWindowInteractor iren 40 | iren SetRenderWindow renwin 41 | iren AddObserver UserEvent {remove RemoveMarkedCells; renwin Render} 42 | iren SetPicker cpick 43 | iren Initialize 44 | 45 | proc ToggleCell {} { 46 | set id [cpick GetCellId] 47 | puts "Picked cell $id\n" 48 | puts "Number of cells deleted: [remove GetNumberOfDeletedCells]" 49 | remove ToggleCell $id 50 | renwin Render 51 | } 52 | 53 | proc MarkCell {} { 54 | set id [cpick GetCellId] 55 | puts "Picked cell $id\n" 56 | puts "Number of cells deleted: [remove GetNumberOfDeletedCells]" 57 | remove MarkCell $id 58 | renwin Render 59 | } 60 | 61 | 62 | proc RemoveCell {} { 63 | set id [cpick GetCellId] 64 | puts "Picked cell $id\n" 65 | puts "Number of cells deleted: [remove GetNumberOfDeletedCells]" 66 | remove RemoveCell $id 67 | renwin Render 68 | } 69 | 70 | 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /vtkRemoveCellsFilter.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | 3 | Program: Visualization Toolkit 4 | Module: vtkRemoveCellsFilter.cxx 5 | Language: C++ 6 | Version: $Id$ 7 | 8 | Copyright (c) 2003-2004 Goodwin Lawlor 9 | All rights reserved. 10 | 11 | This software is distributed WITHOUT ANY WARRANTY; without even 12 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 13 | PURPOSE. 14 | 15 | =========================================================================*/ 16 | #include "vtkRemoveCellsFilter.h" 17 | #include "vtkIdList.h" 18 | #include "vtkObjectFactory.h" 19 | 20 | vtkCxxRevisionMacro(vtkRemoveCellsFilter, "$Revision$"); 21 | vtkStandardNewMacro(vtkRemoveCellsFilter); 22 | 23 | 24 | void vtkRemoveCellsFilter::RemoveMarkedCells() 25 | { 26 | vtkIdType numIds = this->MarkedCellIdList->GetNumberOfIds(); 27 | 28 | for (vtkIdType i = 0; i < numIds; i++) 29 | { 30 | this->CellIdList->DeleteId(this->MarkedCellIdList->GetId(i)); 31 | } 32 | 33 | this->InitializeScalars(); 34 | this->Modified(); 35 | } 36 | 37 | 38 | void vtkRemoveCellsFilter::RemoveCell(vtkIdType cellid_at_output) 39 | { 40 | vtkIdType cellid_at_input; 41 | 42 | if (!this->IsInitialized) 43 | { 44 | this->Initialize(); 45 | } 46 | 47 | // Because vtkIdList reorders its id list in the same manner that vtkCellArray 48 | // reorders its cell list, CellIdList can be used to find out what cellid a cell has 49 | // at the filter input... as cells are deleted from the middle of the cell array, 50 | // ids are reorder so they're monotonic increasing (1,2,3,4,...) 51 | cellid_at_input = this->CellIdList->GetId(cellid_at_output); 52 | 53 | this->CellIdList->DeleteId(cellid_at_input); 54 | this->Modified(); 55 | } 56 | 57 | void vtkRemoveCellsFilter::PrintSelf(ostream& os, vtkIndent indent) 58 | { 59 | this->Superclass::PrintSelf(os,indent); 60 | 61 | os << indent << "Number of cells removed: " 62 | << this->GetNumberOfRemovedCells() 63 | << "\n"; 64 | 65 | } 66 | -------------------------------------------------------------------------------- /Testing/Tcl/TestBufferOutputWindow.tcl: -------------------------------------------------------------------------------- 1 | package require vtk 2 | package require vtkbioeng 3 | 4 | wm withdraw . 5 | 6 | vtkBufferOutputWindow buffer 7 | buffer SetInstance buffer 8 | buffer AddObserver ErrorEvent UpdateText 9 | buffer AddObserver WarningEvent UpdateText 10 | # UserEvent is observed since there's no DebugEvent 11 | buffer AddObserver UserEvent UpdateText 12 | 13 | vtkTextProperty txtProp 14 | txtProp AntiAliasingOff 15 | txtProp SetFontSize 16 16 | 17 | vtkTextActor txtActor 18 | txtActor SetTextProperty txtProp 19 | 20 | vtkConeSource cone 21 | cone DebugOn 22 | 23 | vtkPolyDataMapper cMapper 24 | cMapper SetInput [cone GetOutput] 25 | vtkActor cActor 26 | cActor SetMapper cMapper 27 | 28 | 29 | 30 | vtkRenderer ren 31 | ren AddActor cActor 32 | ren AddActor2D txtActor 33 | 34 | vtkRenderWindow renWin 35 | renWin AddRenderer ren 36 | vtkRenderWindowInteractor iren 37 | iren SetRenderWindow renWin 38 | iren AddObserver UserEvent {console show} 39 | [iren GetPicker] DebugOn 40 | iren Initialize 41 | 42 | 43 | 44 | proc UpdateText {} { 45 | 46 | # Format the text depending on its type 47 | switch [buffer GetLastOutputTextTypeAsString] { 48 | "Error Text" { 49 | txtProp SetColor 1 0 0 50 | txtProp BoldOn 51 | txtProp ItalicOff 52 | } 53 | "Warning Text" { 54 | txtProp SetColor 0 0 1 55 | txtProp BoldOff 56 | txtProp ItalicOn 57 | } 58 | "Generic Warning Text" { 59 | txtProp SetColor 0 0 1 60 | txtProp BoldOff 61 | txtProp ItalicOn 62 | } 63 | "Debug Text" { 64 | txtProp SetColor 1 1 1 65 | txtProp BoldOff 66 | txtProp ItalicOff 67 | } 68 | } 69 | 70 | # Strip away the output text preceding the final colon 71 | set txt [buffer GetLastOutputText] 72 | # Get the index of the final colon 73 | set index [expr [string last : $txt] +1] 74 | # Get the string from the colon onwards 75 | set txt [string range $txt $index end] 76 | txtActor SetInput $txt 77 | renWin Render 78 | 79 | 80 | } 81 | 82 | # Provoke some debug text 83 | renWin Render 84 | cone SetHeight 3 85 | after 2000 86 | ren ResetCamera 87 | renWin Render 88 | 89 | 90 | 91 | 92 | 93 | -------------------------------------------------------------------------------- /vtkSelectCellsFilter.h: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | 3 | Program: Visualization Toolkit 4 | Module: vtkSelectCellsFilter.h 5 | Language: C++ 6 | Version: $Id$ 7 | 8 | Copyright (c) Goodwin Lawlor 2004 9 | All rights reserved. 10 | 11 | This software is distributed WITHOUT ANY WARRANTY; without even 12 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 13 | PURPOSE. See the above copyright notice for more information. 14 | 15 | =========================================================================*/ 16 | // .NAME vtkSelectCellsFilter- actually remove a cell from a vtkPolyData object 17 | // .SECTION Description 18 | // vtkSelectCellsFilter allows you to mark cells (be they polygons, lines etc.) that will be exclusively 19 | // passed to the output of the filter by removing the unmarked cells. 20 | 21 | // .SECTION Thanks 22 | // Goodwin Lawlor, University College Dublin 23 | 24 | 25 | #ifndef __vtkSelectCellsFilter_h 26 | #define __vtkSelectCellsFilter_h 27 | 28 | #include "vtkCellsFilter.h" 29 | #include "vtkBioengConfigure.h" // Include configuration header. 30 | 31 | class vtkLookupTable; 32 | 33 | class VTK_BIOENG_EXPORT vtkSelectCellsFilter : public vtkCellsFilter 34 | { 35 | public: 36 | // Description: 37 | // Constructs with initial values of zero. 38 | static vtkSelectCellsFilter *New(); 39 | 40 | vtkTypeRevisionMacro(vtkSelectCellsFilter, vtkCellsFilter); 41 | void PrintSelf(ostream& os, vtkIndent indent); 42 | 43 | // Description: 44 | // Remove everything but the cells marked by MarkCell(cellid) or ToggleCells(cellid) 45 | void RemoveUnmarkedCells(); 46 | 47 | // Description: 48 | // Undo all the remove operations 49 | void UndoRemoveCells(){this->Initialize(); this->Modified();} 50 | 51 | // Desciption: 52 | // Get the number of cells that have been removed. GetNumberOfDeletedCells should be depreciated. 53 | int GetNumberOfDeletedCells(){return this->GetPolyDataInput(0)->GetNumberOfCells() - vtkPolyData::SafeDownCast(this->GetOutput())->GetNumberOfCells();} 54 | int GetNumberOfRemovedCells(){return this->GetPolyDataInput(0)->GetNumberOfCells() - vtkPolyData::SafeDownCast(this->GetOutput())->GetNumberOfCells();} 55 | 56 | 57 | 58 | protected: 59 | vtkSelectCellsFilter(){}; 60 | ~vtkSelectCellsFilter(){}; 61 | 62 | 63 | private: 64 | vtkSelectCellsFilter(const vtkSelectCellsFilter&); // Not implemented. 65 | void operator=(const vtkSelectCellsFilter&); // Not implemented. 66 | }; 67 | 68 | #endif 69 | 70 | 71 | -------------------------------------------------------------------------------- /vtkBufferOutputWindow.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | 3 | Program: Visualization Toolkit 4 | Module: vtkBufferOutputWindow.cxx 5 | Language: C++ 6 | RCS: $Id$ 7 | 8 | Copyright (c) 2003 Goodwin Lawlor 9 | 10 | =========================================================================*/ 11 | #include "vtkBufferOutputWindow.h" 12 | #include "vtkObjectFactory.h" 13 | #include "vtkCommand.h" 14 | 15 | vtkCxxRevisionMacro(vtkBufferOutputWindow, "$Revision$"); 16 | vtkStandardNewMacro(vtkBufferOutputWindow); 17 | 18 | vtkBufferOutputWindow::vtkBufferOutputWindow() 19 | { 20 | this->LastOutputText = NULL; 21 | this->LastOutputTextType = NULL; 22 | } 23 | 24 | vtkBufferOutputWindow::~vtkBufferOutputWindow() 25 | { 26 | delete [] this->LastOutputText; 27 | this->LastOutputText = NULL; 28 | this->LastOutputTextType = NULL; 29 | } 30 | 31 | 32 | void vtkBufferOutputWindow::DisplayText(const char* text) 33 | { 34 | this->LastOutputTextType = TEXT; 35 | if (this->LastOutputText) 36 | { 37 | delete [] this->LastOutputText; 38 | } 39 | this->LastOutputText = new char[strlen(text)+1]; 40 | strcpy(this->LastOutputText, text); 41 | 42 | } 43 | 44 | void vtkBufferOutputWindow::DisplayErrorText(const char* text) 45 | { 46 | this->LastOutputTextType = ERROR_TEXT; 47 | if (this->LastOutputText) 48 | { 49 | delete [] this->LastOutputText; 50 | } 51 | this->LastOutputText = new char[strlen(text)+1]; 52 | strcpy(this->LastOutputText, text); 53 | 54 | if (this->HasObserver(vtkCommand::ErrorEvent) ) 55 | { 56 | this->InvokeEvent(vtkCommand::ErrorEvent); 57 | } 58 | } 59 | 60 | void vtkBufferOutputWindow::DisplayWarningText(const char* text) 61 | { 62 | this->LastOutputTextType = WARNING_TEXT; 63 | if (this->LastOutputText) 64 | { 65 | delete [] this->LastOutputText; 66 | } 67 | this->LastOutputText = new char[strlen(text)+1]; 68 | strcpy(this->LastOutputText, text); 69 | 70 | if (this->HasObserver(vtkCommand::WarningEvent) ) 71 | { 72 | this->InvokeEvent(vtkCommand::WarningEvent); 73 | } 74 | } 75 | 76 | void vtkBufferOutputWindow::DisplayGenericWarningText(const char* text) 77 | { 78 | this->LastOutputTextType = GENERIC_WARNING_TEXT; 79 | if (this->LastOutputText) 80 | { 81 | delete [] this->LastOutputText; 82 | } 83 | this->LastOutputText = new char[strlen(text)+1]; 84 | strcpy(this->LastOutputText, text); 85 | 86 | if (this->HasObserver(vtkCommand::WarningEvent) ) 87 | { 88 | this->InvokeEvent(vtkCommand::WarningEvent); 89 | } 90 | } 91 | 92 | void vtkBufferOutputWindow::DisplayDebugText(const char* text) 93 | { 94 | this->LastOutputTextType = DEBUG_TEXT; 95 | if (this->LastOutputText) 96 | { 97 | delete [] this->LastOutputText; 98 | } 99 | this->LastOutputText = new char[strlen(text)+1]; 100 | strcpy(this->LastOutputText, text); 101 | 102 | // this is a "DebugEvent" 103 | if (this->HasObserver(vtkCommand::UserEvent) ) 104 | { 105 | this->InvokeEvent(vtkCommand::UserEvent); 106 | } 107 | 108 | } 109 | -------------------------------------------------------------------------------- /vtkBufferOutputWindow.h: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | 3 | Program: Visualization Toolkit 4 | Module: vtkBufferOutputWindow.h 5 | Language: C++ 6 | RCS: $Id$ 7 | 8 | Copyright (c) 2004 Goodwin Lawlor 9 | 10 | =========================================================================*/ 11 | // .NAME vtkBufferOutputWindow - 12 | // .SECTION Description 13 | // Writes debug/warning/error output to a buffer (a class variable) which can be accessed from a 14 | // wrapped language (tcl etc.). The class invokes ErrorEvent, WarningEvent, GenericWarningEvent and 15 | // UserEvent (ie DebugEvent doesn't exist) which can be observed and a callback triggered to get the 16 | // output text. 17 | // 18 | // To use this class, instantiate it and then call SetInstance(this). 19 | 20 | 21 | #ifndef __vtkBufferOutputWindow_h 22 | #define __vtkBufferOutputWindow_h 23 | 24 | #include "vtkOutputWindow.h" 25 | #include "vtkBioengConfigure.h" // Include configuration header. 26 | 27 | 28 | class VTK_BIOENG_EXPORT vtkBufferOutputWindow : public vtkOutputWindow 29 | { 30 | public: 31 | vtkTypeRevisionMacro(vtkBufferOutputWindow, vtkOutputWindow); 32 | 33 | static vtkBufferOutputWindow* New(); 34 | 35 | //BTX 36 | enum TextType 37 | { 38 | TEXT, 39 | WARNING_TEXT, 40 | ERROR_TEXT, 41 | GENERIC_WARNING_TEXT, 42 | DEBUG_TEXT 43 | }; 44 | //ETX 45 | 46 | // Description: 47 | // Get the last text type: 0 = TEXT; 1 = WARNING_TEXT; 2 = ERROR_TEXT; 48 | // 3 = GENERIC_WARNING_TEXT; 4 = DEBUG_TEXT 49 | vtkGetMacro(LastOutputTextType, int); 50 | 51 | // Description: 52 | // the output window api 53 | virtual void DisplayText(const char*); 54 | virtual void DisplayErrorText(const char*); 55 | virtual void DisplayWarningText(const char*); 56 | virtual void DisplayGenericWarningText(const char*); 57 | virtual void DisplayDebugText(const char*); 58 | 59 | 60 | // Description: 61 | // Get the last message 62 | vtkGetStringMacro(LastOutputText); 63 | 64 | // Description: 65 | // Get the last message type... error, warning etc. 66 | char *GetLastOutputTextTypeAsString(); 67 | 68 | 69 | protected: 70 | vtkBufferOutputWindow(); 71 | virtual ~vtkBufferOutputWindow(); 72 | 73 | char *LastOutputText; 74 | int LastOutputTextType; 75 | 76 | private: 77 | vtkBufferOutputWindow(const vtkBufferOutputWindow&); // Not implemented. 78 | void operator=(const vtkBufferOutputWindow&); // Not implemented. 79 | }; 80 | 81 | inline char *vtkBufferOutputWindow::GetLastOutputTextTypeAsString(void) 82 | { 83 | if ( this->LastOutputTextType == TEXT ) 84 | { 85 | return (char *)"Text"; 86 | } 87 | else if ( this->LastOutputTextType == ERROR_TEXT ) 88 | { 89 | return (char *)"Error Text"; 90 | } 91 | else if ( this->LastOutputTextType == WARNING_TEXT ) 92 | { 93 | return (char *)"Warning Text"; 94 | } 95 | else if ( this->LastOutputTextType == GENERIC_WARNING_TEXT ) 96 | { 97 | return (char *)"Generic Warning Text"; 98 | } 99 | else 100 | { 101 | return (char *)"Debug Text"; 102 | } 103 | } 104 | 105 | #endif 106 | -------------------------------------------------------------------------------- /vtkRemoveCellsFilter.h: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | 3 | Program: Visualization Toolkit 4 | Module: vtkRemoveCellsFilter.h 5 | Language: C++ 6 | Version: $Id$ 7 | 8 | Copyright (c) Goodwin Lawlor 2003-2004 9 | All rights reserved. 10 | 11 | This software is distributed WITHOUT ANY WARRANTY; without even 12 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 13 | PURPOSE. See the above copyright notice for more information. 14 | 15 | =========================================================================*/ 16 | // .NAME vtkRemoveCellsFilter- actually remove a cell from a vtkPolyData object 17 | // .SECTION Description 18 | // vtkRemoveCellsFilter removes cells one at a time. vtkCellPicker could be used to get the CellId of the cell to 19 | // be removed. Then call the RemoveCell method with the CellId. The UndoRemoveCells method restores the 20 | // PolyData to it original state. Alternatively, you can mark cells with MarkCell and remove them all in one go 21 | // with RemoveMarkedCells. This is much more efficient for large datasets since the filter only has to execute 22 | // once. 23 | 24 | // .SECTION Caveats 25 | // Trying to remove the last remaining cell in a dataset will restore all the removed cells! 26 | // Any filter between this filter and the vtkPolyDataMapper should not alter the cell order 27 | 28 | 29 | // .SECTION Thanks 30 | // Goodwin Lawlor, University College Dublin 31 | 32 | 33 | #ifndef __vtkRemoveCellsFilter_h 34 | #define __vtkRemoveCellsFilter_h 35 | 36 | #include "vtkCellsFilter.h" 37 | // #include "vtkIdList.h" 38 | // #include "vtkCharArray.h" 39 | // #include "vtkPolyData.h" 40 | #include "vtkBioengConfigure.h" // Include configuration header. 41 | 42 | class vtkLookupTable; 43 | 44 | class VTK_BIOENG_EXPORT vtkRemoveCellsFilter : public vtkCellsFilter 45 | { 46 | public: 47 | // Description: 48 | // Constructs with initial values of zero. 49 | static vtkRemoveCellsFilter *New(); 50 | 51 | vtkTypeRevisionMacro(vtkRemoveCellsFilter, vtkCellsFilter); 52 | void PrintSelf(ostream& os, vtkIndent indent); 53 | 54 | // Description: 55 | // Remove a cell from the input polydata. cellid is a cell id from the input to the filter 56 | // A recursive trick remaps the new cellids (from the output) to the old cellids (at the input) 57 | // so that the cellid returned by vtkCellPicker is the correct one to use. 58 | void RemoveCell(vtkIdType cellid); 59 | 60 | // Description: 61 | // Remove the cells marked by MarkCell(cellid) 62 | void RemoveMarkedCells(); 63 | 64 | // // Description: 65 | // // Remove everything but the cells marked by MarkCell(cellid) or ToggleCells(cellid) 66 | // void RemoveUnmarkedCells(); 67 | 68 | // Description: 69 | // Undo all the remove operations 70 | void UndoRemoveCells(){this->Initialize(); this->Modified();} 71 | 72 | 73 | // Desciption: 74 | // Get the number of cells that have been removed. GetNumberOfDeletedCells should be depreciated. 75 | int GetNumberOfDeletedCells(){return this->GetPolyDataInput(0)->GetNumberOfCells() - vtkPolyData::SafeDownCast(this->GetOutput())->GetNumberOfCells();} 76 | int GetNumberOfRemovedCells(){return this->GetPolyDataInput(0)->GetNumberOfCells() - vtkPolyData::SafeDownCast(this->GetOutput())->GetNumberOfCells();} 77 | 78 | 79 | 80 | protected: 81 | vtkRemoveCellsFilter(){}; 82 | ~vtkRemoveCellsFilter(){}; 83 | 84 | 85 | private: 86 | vtkRemoveCellsFilter(const vtkRemoveCellsFilter&); // Not implemented. 87 | void operator=(const vtkRemoveCellsFilter&); // Not implemented. 88 | }; 89 | 90 | #endif 91 | 92 | 93 | -------------------------------------------------------------------------------- /vtkTesselateBoundaryLoops.h: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | 3 | Program: Visualization Toolkit 4 | Module: vtkTesselateBoundaryLoops.h 5 | Language: C++ 6 | Version: $Id$ 7 | 8 | Copyright (c) 2004 Goodwin Lawlor 9 | All rights reserved. 10 | 11 | This software is distributed WITHOUT ANY WARRANTY; without even 12 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 13 | PURPOSE. See the above copyright notice for more information. 14 | 15 | =========================================================================*/ 16 | // .NAME vtkTesselateBoundaryLoops - tesselate boundary loops, aka, fill in surface holes. 17 | // .SECTION Description 18 | // This filter will convert boundary edges that form a closed loop into tesselated polygons. It will not 19 | // smoothly interpolate over a surface hole. 20 | 21 | 22 | 23 | #ifndef __vtkTesselateBoundaryLoops_h 24 | #define __vtkTesselateBoundaryLoops_h 25 | 26 | #include "vtkPolyDataAlgorithm.h" 27 | #include "vtkBioengConfigure.h" // Include configuration header. 28 | class vtkFeatureEdges; 29 | class vtkCleanPolyData; 30 | class vtkStripper; 31 | class vtkPolyData; 32 | class vtkTriangleFilter; 33 | class vtkAppendPolyData; 34 | class vtkReverseSense; 35 | 36 | 37 | 38 | class VTK_BIOENG_EXPORT vtkTesselateBoundaryLoops : public vtkPolyDataAlgorithm 39 | { 40 | public: 41 | vtkTypeRevisionMacro(vtkTesselateBoundaryLoops,vtkPolyDataAlgorithm); 42 | void PrintSelf(ostream& os, vtkIndent indent); 43 | 44 | // Description: 45 | // Constructor 46 | static vtkTesselateBoundaryLoops *New(); 47 | 48 | // Description: 49 | // Set the tolerance for point merging of line verts... if line verts aren't exactly coincident 50 | // they wont be joined up into a loop. With a tolerance they can be incouraged to be coincident. 51 | vtkSetMacro(Tolerance, float); 52 | vtkGetMacro(Tolerance, float); 53 | 54 | // Description: 55 | // Set the maximum number of lines in a loop. Default is 1000; 56 | vtkSetMacro(MaximumLength, int); 57 | vtkGetMacro(MaximumLength, int); 58 | 59 | //Description: 60 | // Append the tesselated loops to the input dataset. Default is Off. 61 | vtkSetMacro(AppendTesselationToInput, int); 62 | vtkGetMacro(AppendTesselationToInput, int); 63 | vtkBooleanMacro(AppendTesselationToInput,int); 64 | 65 | // Description: 66 | // Reverse the sense (front/back face) of the loops being tesselated 67 | vtkSetMacro(ReverseSense, int); 68 | vtkGetMacro(ReverseSense, int); 69 | vtkBooleanMacro(ReverseSense, int); 70 | 71 | // Description: 72 | // Sometimes boundary edges are non-manifold and need to be included 73 | vtkSetMacro(NonManifoldEdges, int); 74 | vtkGetMacro(NonManifoldEdges, int); 75 | vtkBooleanMacro(NonManifoldEdges, int); 76 | 77 | // Description: 78 | // Get the number of boundary loops 79 | vtkGetMacro(NumberOfLoops, int); 80 | 81 | protected: 82 | vtkTesselateBoundaryLoops(); 83 | ~vtkTesselateBoundaryLoops(); 84 | 85 | vtkFeatureEdges *FeatureEdges; 86 | vtkCleanPolyData *Clean; 87 | vtkStripper *Stripper; 88 | vtkPolyData *tmpPolyData; 89 | vtkReverseSense *Reverse; 90 | vtkTriangleFilter *Tesselator; 91 | vtkAppendPolyData *Append; 92 | vtkCleanPolyData *Clean2; 93 | 94 | float Tolerance; 95 | int AppendTesselationToInput; 96 | int ReverseSense; 97 | int MaximumLength; 98 | int NumberOfLoops; 99 | int NonManifoldEdges; 100 | 101 | // Usual data generation method 102 | int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); 103 | 104 | private: 105 | vtkTesselateBoundaryLoops(const vtkTesselateBoundaryLoops&); // Not implemented. 106 | void operator=(const vtkTesselateBoundaryLoops&); // Not implemented. 107 | 108 | }; 109 | 110 | #endif 111 | 112 | -------------------------------------------------------------------------------- /vtkTesselateBoundaryLoops.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | 3 | Program: Visualization Toolkit 4 | Module: vtkTesselateBoundaryLoops.cxx 5 | Language: C++ 6 | Version: $Id$ 7 | 8 | Copyright (c) 2004 Goodwin Lawlor 9 | All rights reserved. 10 | 11 | This software is distributed WITHOUT ANY WARRANTY; without even 12 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 13 | PURPOSE. See the above copyright notice for more information. 14 | 15 | =========================================================================*/ 16 | #include "vtkTesselateBoundaryLoops.h" 17 | #include "vtkObjectFactory.h" 18 | #include "vtkInformation.h" 19 | #include "vtkInformationVector.h" 20 | #include "vtkFeatureEdges.h" 21 | #include "vtkCleanPolyData.h" 22 | #include "vtkStripper.h" 23 | #include "vtkPolyData.h" 24 | #include "vtkTriangleFilter.h" 25 | #include "vtkAppendPolyData.h" 26 | #include "vtkReverseSense.h" 27 | #include "vtkInformation.h" 28 | #include "vtkInformationVector.h" 29 | 30 | 31 | 32 | vtkCxxRevisionMacro(vtkTesselateBoundaryLoops, "$Revision$"); 33 | vtkStandardNewMacro(vtkTesselateBoundaryLoops); 34 | 35 | vtkTesselateBoundaryLoops::vtkTesselateBoundaryLoops() 36 | { 37 | this->Tolerance = 0.0; 38 | this->AppendTesselationToInput = 0; 39 | this->ReverseSense = 0; 40 | this->MaximumLength = 1000; 41 | this->NumberOfLoops = 0; 42 | this->NonManifoldEdges = 0; 43 | 44 | // setup the pipeline 45 | this->FeatureEdges = vtkFeatureEdges::New(); 46 | this->FeatureEdges->BoundaryEdgesOn(); 47 | this->FeatureEdges->FeatureEdgesOff(); 48 | this->Clean = vtkCleanPolyData::New(); 49 | this->Clean->SetInput(this->FeatureEdges->GetOutput()); 50 | this->Stripper = vtkStripper::New(); 51 | this->Stripper->SetInput(Clean->GetOutput()); 52 | this->tmpPolyData = vtkPolyData::New(); 53 | this->Reverse = vtkReverseSense::New(); 54 | this->Reverse->SetInput(tmpPolyData); 55 | this->Tesselator = vtkTriangleFilter::New(); 56 | this->Tesselator->SetInput(this->Reverse->GetOutput()); 57 | this->Append = vtkAppendPolyData::New(); 58 | this->Append->AddInput(this->Tesselator->GetOutput()); 59 | this->Clean2 = vtkCleanPolyData::New(); 60 | this->Clean2->SetInput(this->Append->GetOutput()); 61 | } 62 | 63 | vtkTesselateBoundaryLoops::~vtkTesselateBoundaryLoops() 64 | { 65 | this->FeatureEdges->Delete(); 66 | this->Clean->Delete(); 67 | this->Stripper->Delete(); 68 | this->tmpPolyData->Delete(); 69 | this->Reverse->Delete(); 70 | this->Tesselator->Delete(); 71 | this->Append->Delete(); 72 | this->Clean2->Delete(); 73 | } 74 | 75 | 76 | int vtkTesselateBoundaryLoops::RequestData( 77 | vtkInformation *vtkNotUsed(request), 78 | vtkInformationVector **inputVector, 79 | vtkInformationVector *outputVector) 80 | { 81 | // get the info objects 82 | vtkInformation *inInfo = inputVector[0]->GetInformationObject(0); 83 | vtkInformation *outInfo = outputVector->GetInformationObject(0); 84 | 85 | // get the input and ouptut 86 | vtkPolyData *input = vtkPolyData::SafeDownCast( 87 | inInfo->Get(vtkDataObject::DATA_OBJECT())); 88 | vtkPolyData *output = vtkPolyData::SafeDownCast( 89 | outInfo->Get(vtkDataObject::DATA_OBJECT())); 90 | 91 | this->FeatureEdges->SetInput(input); 92 | // sometimes a boundary edge is non-manifold. 93 | this->FeatureEdges->SetNonManifoldEdges(this->NonManifoldEdges); 94 | 95 | this->Clean->SetTolerance(this->Tolerance); 96 | 97 | this->Stripper->SetMaximumLength(this->MaximumLength); 98 | this->Stripper->Update(); 99 | this->NumberOfLoops = this->Stripper->GetOutput()->GetNumberOfLines(); 100 | 101 | this->tmpPolyData->SetPolys(this->Stripper->GetOutput()->GetLines()); 102 | this->tmpPolyData->SetPoints(this->Stripper->GetOutput()->GetPoints()); 103 | 104 | this->Reverse->SetReverseCells(this->ReverseSense); 105 | 106 | vtkPolyData *last; 107 | 108 | if (this->AppendTesselationToInput) 109 | { 110 | this->Append->AddInput(input); 111 | this->Clean2->Update(); 112 | last = this->Clean2->GetOutput(); 113 | } 114 | else 115 | { 116 | this->Tesselator->Update(); 117 | last = this->Tesselator->GetOutput(); 118 | } 119 | 120 | output->SetPoints(last->GetPoints()); 121 | output->SetPolys(last->GetPolys()); 122 | 123 | vtkDebugMacro(<< "Finished tesselation"); 124 | 125 | return 1; 126 | 127 | } 128 | 129 | void vtkTesselateBoundaryLoops::PrintSelf(ostream& os, vtkIndent indent) 130 | { 131 | this->Superclass::PrintSelf(os,indent); 132 | 133 | } -------------------------------------------------------------------------------- /vtkCellsFilter.h: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | 3 | Program: Visualization Toolkit 4 | Module: vtkCellsFilter.h 5 | Language: C++ 6 | RCS: $Id$ 7 | 8 | Copyright (c) Goodwin Lawlor 2004 9 | All rights reserved. 10 | 11 | This software is distributed WITHOUT ANY WARRANTY; without even 12 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 13 | PURPOSE. See the above copyright notice for more information. 14 | 15 | =========================================================================*/ 16 | // .NAME vtkCellsFilter- abstract superclass for removing/selecting cells. 17 | // .SECTION Description 18 | // vtkCellsFilter is an abstract superclass for classes the remove or select cells.r 19 | 20 | 21 | // .SECTION Thanks 22 | // Goodwin Lawlor, University College Dublin 23 | 24 | 25 | #ifndef __vtkCellsFilter_h 26 | #define __vtkCellsFilter_h 27 | 28 | #include "vtkPolyDataAlgorithm.h" 29 | #include "vtkIdList.h" 30 | #include "vtkCharArray.h" 31 | #include "vtkPolyData.h" 32 | #include "vtkBioengConfigure.h" // Include configuration header. 33 | 34 | class vtkLookupTable; 35 | 36 | class VTK_BIOENG_EXPORT vtkCellsFilter : public vtkPolyDataAlgorithm 37 | { 38 | public: 39 | 40 | vtkTypeRevisionMacro(vtkCellsFilter, vtkPolyDataAlgorithm); 41 | void PrintSelf(ostream& os, vtkIndent indent); 42 | 43 | // Description: 44 | // Remove a cell from the input polydata. cellid is a cell id from the input to the filter 45 | // A recursive trick remaps the new cellids (from the output) to the old cellids (at the input) 46 | // so that the cellid returned by vtkCellPicker is the correct one to use. 47 | //void RemoveCell(vtkIdType cellid); 48 | 49 | // Description: 50 | // Mark a cell to be removed by RemoveMarkedCells later. 51 | void MarkCell(vtkIdType cellid); 52 | 53 | // Description: 54 | // Unmark any cell that has been marked already 55 | void UnmarkCell(vtkIdType cellid); 56 | 57 | // Description: 58 | // If a cells is unmarked- mark it... if its marked- unmark it. 59 | void ToggleCell(vtkIdType cellid); 60 | 61 | // Description: 62 | // Remove the cells marked by MarkCell(cellid) 63 | //void RemoveMarkedCells(); 64 | 65 | // Description: 66 | // Remove everything but the cells marked by MarkCell(cellid) or ToggleCells(cellid) 67 | //void RemoveUnmarkedCells(); 68 | 69 | // Description: 70 | // Undo all the remove operations 71 | //void UndoRemoveCells(){this->Initialize(); this->Modified();} 72 | 73 | // Description: 74 | // Undo all the marks made on cells 75 | void UndoMarks(){this->InitializeScalars(); this->MarkedCellIdList->Reset(); this->Scalars->Modified();} 76 | 77 | //int GetNumberOfDeletedCells(){return this->GetInput()->GetNumberOfCells() - this->GetOutput()->GetNumberOfCells();} 78 | 79 | // Description: 80 | // Set/Get the marked color... default is red 81 | void SetMarkedColor(double r, double g, double b); 82 | void SetMarkedColor(double rgb[3]) {this->SetMarkedColor(rgb[0], rgb[1], rgb[2]);}; 83 | vtkGetVector3Macro(MarkedColor, double); 84 | 85 | 86 | // Description: 87 | // Set/Get the umarked color... default is white. You could set this to the same color as the vtkProperty 88 | // and users won't know they are seeing scalars. 89 | void SetUnmarkedColor(double r, double g, double b); 90 | void SetUnmarkedColor(double rgb[3]) {this->SetUnmarkedColor(rgb[0], rgb[1], rgb[2]);}; 91 | vtkGetVector3Macro(UnmarkedColor, double); 92 | 93 | 94 | // Description: 95 | // Set/Get the marked opacity... default is 1.0 By setting this to 0.0 you can temporally remove the cells 96 | // and then permanently remove them with RemoveMarkedCells 97 | void SetMarkedOpacity(double opacity); 98 | vtkGetMacro(MarkedOpacity, double); 99 | 100 | 101 | protected: 102 | vtkCellsFilter(); 103 | ~vtkCellsFilter(); 104 | 105 | vtkIdList *CellIdList; 106 | vtkIdList *MarkedCellIdList; 107 | 108 | int IsInitialized; 109 | int IsScalarsInitialized; 110 | 111 | vtkCharArray *Scalars; 112 | vtkLookupTable *LUT; 113 | 114 | void Initialize(); 115 | void InitializeScalars(); 116 | 117 | double MarkedColor[3]; 118 | double UnmarkedColor[3]; 119 | double MarkedOpacity; 120 | 121 | // Usual data generation method 122 | virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); 123 | 124 | private: 125 | vtkCellsFilter(const vtkCellsFilter&); // Not implemented. 126 | void operator=(const vtkCellsFilter&); // Not implemented. 127 | }; 128 | 129 | #endif 130 | 131 | 132 | -------------------------------------------------------------------------------- /Testing/Cxx/TestCollisionDetection1.cxx: -------------------------------------------------------------------------------- 1 | #include "vtkProperty.h" 2 | #include "vtkPolyDataMapper.h" 3 | #include "vtkActor.h" 4 | #include "vtkRenderWindow.h" 5 | #include "vtkRenderWindowInteractor.h" 6 | #include "vtkRenderer.h" 7 | #include "vtkCamera.h" 8 | #include "vtkSphereSource.h" 9 | #include "vtkMatrix4x4.h" 10 | #include "vtkCollisionDetectionFilter.h" 11 | #include "vtkInteractorStyleJoystickCamera.h" 12 | #include "vtkCleanPolyData.h" 13 | #include "vtkStripper.h" 14 | #include "vtkClipPolyData.h" 15 | #include "vtkSelectPolyData.h" 16 | #include "vtkCellArray.h" 17 | #include "vtkAppendPolyData.h" 18 | #include "vtkSmartPointer.h" 19 | 20 | int main() 21 | { 22 | vtkSphereSource *sphere0 = vtkSphereSource::New(); 23 | sphere0->SetPhiResolution(3); 24 | sphere0->SetThetaResolution(3); 25 | sphere0->SetCenter(-0.0, 0, 0); 26 | 27 | vtkSphereSource *sphere1 = vtkSphereSource::New(); 28 | sphere1->SetPhiResolution(30); 29 | sphere1->SetThetaResolution(30); 30 | sphere1->SetRadius(0.3); 31 | 32 | vtkMatrix4x4 *matrix0 = vtkMatrix4x4::New(); 33 | vtkMatrix4x4 *matrix1 = vtkMatrix4x4::New(); 34 | 35 | vtkCollisionDetectionFilter *collide = vtkCollisionDetectionFilter::New(); 36 | //collide->DebugOn(); 37 | collide->SetInputConnection(0, sphere0->GetOutputPort()); 38 | collide->SetMatrix(0, matrix0); 39 | collide->SetInputConnection(1, sphere1->GetOutputPort()); 40 | collide->SetMatrix(1, matrix1); 41 | collide->SetBoxTolerance(0.0); 42 | collide->SetCellTolerance(0.0); 43 | collide->SetNumberOfCellsPerNode(2); 44 | collide->SetCollisionModeToAllContacts(); 45 | collide->GenerateScalarsOn(); 46 | 47 | vtkCleanPolyData *clean = vtkCleanPolyData::New(); 48 | clean->SetInputConnection(collide->GetContactsOutputPort()); 49 | 50 | vtkStripper *stripper = vtkStripper::New(); 51 | stripper->SetInputConnection(clean->GetOutputPort()); 52 | stripper->Update(); 53 | 54 | vtkSelectPolyData *select = vtkSelectPolyData::New(); 55 | select->SetInputConnection(sphere1->GetOutputPort()); 56 | select->GenerateSelectionScalarsOn(); 57 | select->SetSelectionModeToSmallestRegion(); 58 | 59 | vtkClipPolyData *clip = vtkClipPolyData::New(); 60 | clip->SetInputConnection(select->GetOutputPort()); 61 | clip->InsideOutOn(); 62 | 63 | vtkAppendPolyData *append = vtkAppendPolyData::New(); 64 | vtkSmartPointer clipped; 65 | 66 | vtkCellArray *lines = stripper->GetOutput()->GetLines(); 67 | vtkPoints *allPoints = stripper->GetOutput()->GetPoints(); 68 | vtkIdType numPts, *pts; 69 | vtkPoints *points = vtkPoints::New(); 70 | 71 | for (lines->InitTraversal(); lines->GetNextCell(numPts, pts); ) 72 | { 73 | points->Reset(); 74 | // don't close the loop by inserting the last point... 75 | // vtkSelectPolyData does it for you (and crashes if you do it) 76 | for (int i =0; iInsertNextPoint(allPoints->GetPoint(pts[i])); 79 | } 80 | select->SetLoop(points); 81 | select->Modified(); 82 | clip->Update(); 83 | clipped = vtkSmartPointer::New(); 84 | clipped->DeepCopy(clip->GetOutput()); 85 | append->AddInput(clipped); 86 | } 87 | 88 | vtkPolyDataMapper *mapper1 = vtkPolyDataMapper::New(); 89 | mapper1->SetInputConnection(collide->GetOutputPort(0)); 90 | vtkActor *actor1 = vtkActor::New(); 91 | actor1->SetMapper(mapper1); 92 | (actor1->GetProperty())->BackfaceCullingOn(); 93 | 94 | vtkPolyDataMapper *mapper2 = vtkPolyDataMapper::New(); 95 | mapper2->SetInputConnection(append->GetOutputPort()); 96 | vtkActor *actor2 = vtkActor::New(); 97 | actor2->SetMapper(mapper2); 98 | actor2->SetScale(2); 99 | 100 | vtkPolyDataMapper *mapper3 = vtkPolyDataMapper::New(); 101 | mapper3->SetInputConnection(stripper->GetOutputPort()); 102 | vtkActor *actor3 = vtkActor::New(); 103 | actor3->SetMapper(mapper3); 104 | (actor3->GetProperty())->SetColor(0,0,0); 105 | (actor3->GetProperty())->SetLineWidth(3.0); 106 | 107 | 108 | vtkRenderer *ren = vtkRenderer::New(); 109 | ren->AddActor(actor1); 110 | ren->AddActor(actor2); 111 | ren->AddActor(actor3); 112 | ren->SetBackground(1.0,1.0,1.0); 113 | 114 | vtkRenderWindow *renWin = vtkRenderWindow::New(); 115 | renWin->AddRenderer(ren); 116 | 117 | vtkInteractorStyleJoystickCamera *istyle = vtkInteractorStyleJoystickCamera::New(); 118 | vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); 119 | iren->SetRenderWindow(renWin); 120 | iren->SetInteractorStyle(istyle); 121 | 122 | 123 | renWin->Render(); 124 | iren->Start(); 125 | 126 | sphere0->Delete(); 127 | sphere1->Delete(); 128 | matrix0->Delete(); 129 | matrix1->Delete(); 130 | collide->Delete(); 131 | clean->Delete(); 132 | stripper->Delete(); 133 | select->Delete(); 134 | clip->Delete(); 135 | mapper1->Delete(); 136 | mapper2->Delete(); 137 | mapper3->Delete(); 138 | actor1->Delete(); 139 | actor2->Delete(); 140 | actor3->Delete(); 141 | ren->Delete(); 142 | renWin->Delete(); 143 | istyle->Delete(); 144 | } 145 | -------------------------------------------------------------------------------- /Testing/Cxx/TestCollisionDetection.cxx: -------------------------------------------------------------------------------- 1 | #include "vtkProperty.h" 2 | #include "vtkPolyDataMapper.h" 3 | #include "vtkActor.h" 4 | #include "vtkRenderWindow.h" 5 | #include "vtkRenderWindowInteractor.h" 6 | #include "vtkRenderer.h" 7 | #include "vtkCamera.h" 8 | #include "vtkSphereSource.h" 9 | #include "vtkMatrix4x4.h" 10 | #include "vtkCollisionDetectionFilter.h" 11 | #include "vtkGlyph3D.h" 12 | #include "vtkInteractorStyleJoystickActor.h" 13 | #include "vtkTextActor.h" 14 | #include "vtkCommand.h" 15 | #include 16 | //#include "vtkFileOutputWindow.h" 17 | 18 | class vtkCollisionCallback : public vtkCommand 19 | { 20 | public: 21 | static vtkCollisionCallback *New() 22 | { return new vtkCollisionCallback; } 23 | 24 | void SetTextActor(vtkTextActor *txt) 25 | { 26 | this->TextActor = txt; 27 | } 28 | void SetRenderWindow(vtkRenderWindow *renWin) 29 | { 30 | this->RenWin = renWin; 31 | } 32 | 33 | virtual void Execute(vtkObject *caller, unsigned long, void*) 34 | { 35 | vtkCollisionDetectionFilter *collide = reinterpret_cast(caller); 36 | if (collide->GetNumberOfContacts() > 0) 37 | { 38 | sprintf(this->TextBuff, "Number Of Contacts: %d", collide->GetNumberOfContacts()); 39 | } 40 | else 41 | { 42 | sprintf(this->TextBuff, "No Contacts"); 43 | } 44 | this->TextActor->SetInput(this->TextBuff); 45 | this->RenWin->Render(); 46 | } 47 | protected: 48 | vtkTextActor *TextActor; 49 | vtkRenderWindow *RenWin; 50 | char TextBuff[128]; 51 | }; 52 | 53 | int main() 54 | { 55 | //vtkFileOutputWindow *fout = vtkFileOutputWindow::New(); 56 | // fout->SetFileName("squawks.txt"); 57 | // fout->SetInstance(fout); 58 | 59 | vtkSphereSource *sphere0 = vtkSphereSource::New(); 60 | sphere0->SetPhiResolution(3); 61 | sphere0->SetThetaResolution(3); 62 | sphere0->SetCenter(-0.0, 0, 0); 63 | 64 | vtkSphereSource *sphere1 = vtkSphereSource::New(); 65 | sphere1->SetPhiResolution(30); 66 | sphere1->SetThetaResolution(30); 67 | sphere1->SetRadius(0.3); 68 | 69 | vtkMatrix4x4 *matrix0 = vtkMatrix4x4::New(); 70 | vtkMatrix4x4 *matrix1 = vtkMatrix4x4::New(); 71 | 72 | vtkCollisionDetectionFilter *collide = vtkCollisionDetectionFilter::New(); 73 | //collide->DebugOn(); 74 | collide->SetInputConnection(0, sphere0->GetOutputPort()); 75 | collide->SetMatrix(0, matrix0); 76 | collide->SetInputConnection(1, sphere1->GetOutputPort()); 77 | collide->SetMatrix(1, matrix1); 78 | collide->SetBoxTolerance(0.0); 79 | collide->SetCellTolerance(0.0); 80 | collide->SetNumberOfCellsPerNode(2); 81 | collide->SetCollisionModeToAllContacts(); 82 | collide->GenerateScalarsOn(); 83 | 84 | vtkPolyDataMapper *mapper1 = vtkPolyDataMapper::New(); 85 | mapper1->SetInputConnection(collide->GetOutputPort(0)); 86 | vtkActor *actor1 = vtkActor::New(); 87 | actor1->SetMapper(mapper1); 88 | (actor1->GetProperty())->BackfaceCullingOn(); 89 | actor1->SetUserMatrix(matrix0); 90 | 91 | vtkPolyDataMapper *mapper2 = vtkPolyDataMapper::New(); 92 | mapper2->SetInputConnection(collide->GetOutputPort(1)); 93 | vtkActor *actor2 = vtkActor::New(); 94 | actor2->SetMapper(mapper2); 95 | (actor2->GetProperty())->BackfaceCullingOn(); 96 | actor2->SetUserMatrix(matrix1); 97 | 98 | vtkPolyDataMapper *mapper3 = vtkPolyDataMapper::New(); 99 | mapper3->SetInputConnection(collide->GetContactsOutputPort()); 100 | mapper3->SetResolveCoincidentTopologyToPolygonOffset(); 101 | vtkActor *actor3 = vtkActor::New(); 102 | actor3->SetMapper(mapper3); 103 | (actor3->GetProperty())->SetColor(0,0,0); 104 | (actor3->GetProperty())->SetLineWidth(3.0); 105 | 106 | vtkTextActor *txt = vtkTextActor::New(); 107 | 108 | vtkRenderer *ren = vtkRenderer::New(); 109 | ren->AddActor(actor1); 110 | ren->AddActor(actor2); 111 | ren->AddActor(actor3); 112 | ren->AddActor(txt); 113 | ren->SetBackground(0.5,0.5,0.5); 114 | 115 | vtkRenderWindow *renWin = vtkRenderWindow::New(); 116 | renWin->AddRenderer(ren); 117 | 118 | vtkInteractorStyleJoystickActor *istyle = vtkInteractorStyleJoystickActor::New(); 119 | vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); 120 | iren->SetRenderWindow(renWin); 121 | iren->SetInteractorStyle(istyle); 122 | 123 | vtkCollisionCallback *cbCollide = vtkCollisionCallback::New(); 124 | cbCollide->SetTextActor(txt); 125 | cbCollide->SetRenderWindow(renWin); 126 | collide->AddObserver(vtkCommand::EndEvent, cbCollide); 127 | 128 | renWin->Render(); 129 | iren->Start(); 130 | 131 | sphere0->Delete(); 132 | sphere1->Delete(); 133 | matrix0->Delete(); 134 | matrix1->Delete(); 135 | collide->Delete(); 136 | //point->Delete(); 137 | //points->Delete(); 138 | mapper1->Delete(); 139 | mapper2->Delete(); 140 | mapper3->Delete(); 141 | actor1->Delete(); 142 | actor2->Delete(); 143 | actor3->Delete(); 144 | txt->Delete(); 145 | ren->Delete(); 146 | cbCollide->Delete(); 147 | renWin->Delete(); 148 | istyle->Delete(); 149 | iren->Delete(); 150 | 151 | 152 | 153 | 154 | } 155 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | CMAKE_MINIMUM_REQUIRED(VERSION 2.4) 2 | 3 | # Set the project/library name here. Classes should be declared as 4 | # "class VTK_BIOENG_EXPORT vtkFoo" 5 | # project set here. 6 | PROJECT(vtkBioeng) 7 | 8 | # Set your list of sources here. Do not change the name of the 9 | # vtkLocal_SRCS variable. 10 | SET(vtkBioeng_SRCS 11 | vtkBufferOutputWindow.cxx 12 | vtkCollisionDetectionFilter.cxx 13 | vtkCellsFilter.cxx 14 | vtkRemoveCellsFilter.cxx 15 | vtkSelectCellsFilter.cxx 16 | vtkTesselateBoundaryLoops.cxx 17 | ) 18 | 19 | SET_SOURCE_FILES_PROPERTIES( 20 | vtkCellsFilter 21 | ABSTRACT 22 | ) 23 | 24 | # List the kits from VTK that are needed by this project. 25 | SET(vtkBioeng_LIBS 26 | vtkCommon 27 | vtkFiltering 28 | vtkGraphics 29 | vtkRendering 30 | ) 31 | 32 | #----------------------------------------------------------------------------- 33 | # Most users should not need to change anything below this line. 34 | 35 | # Need to include class headers and the configuration header. 36 | INCLUDE_DIRECTORIES(${PROJECT_SOURCE_DIR}) 37 | INCLUDE_DIRECTORIES(${PROJECT_BINARY_DIR}) 38 | 39 | # Setup output paths. 40 | SET (LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH 41 | "Single output directory for building all libraries.") 42 | SET (EXECUTABLE_OUTPUT_PATH ${PROJECT_BINARY_DIR}/bin CACHE PATH 43 | "Single output directory for building all executables.") 44 | MARK_AS_ADVANCED(LIBRARY_OUTPUT_PATH EXECUTABLE_OUTPUT_PATH) 45 | 46 | # Find and load VTK settings. 47 | FIND_PACKAGE(VTK REQUIRED) 48 | INCLUDE(${VTK_USE_FILE}) 49 | 50 | # Give user option of building shared or static libraries. Default to 51 | # the choice made for VTK. 52 | OPTION(BUILD_SHARED_LIBS "Build with shared libraries." 53 | ${VTK_BUILD_SHARED_LIBS}) 54 | 55 | # Set VTKBIOENG_BUILD_SHARED_LIBS to 1 or 0 for use in creating the 56 | # configuration header. 57 | IF(BUILD_SHARED_LIBS) 58 | SET(VTKBIOENG_BUILD_SHARED_LIBS_CONFIG 1) 59 | ELSE(BUILD_SHARED_LIBS) 60 | SET(VTKBIOENG_BUILD_SHARED_LIBS_CONFIG 0) 61 | ENDIF(BUILD_SHARED_LIBS) 62 | 63 | IF(VTK_FOUND) 64 | # If this is a build tree, provide an option for putting this 65 | # project's executables and libraries in with VTK's. 66 | IF (EXISTS ${VTK_DIR}/bin) 67 | OPTION(USE_VTK_OUTPUT_PATHS 68 | "Use VTK's output directory for this project's executables and libraries." 69 | OFF) 70 | MARK_AS_ADVANCED (USE_VTK_OUTPUT_PATHS) 71 | IF (USE_VTK_OUTPUT_PATHS) 72 | SET (LIBRARY_OUTPUT_PATH ${VTK_DIR}/bin) 73 | SET (EXECUTABLE_OUTPUT_PATH ${VTK_DIR}/bin) 74 | ENDIF (USE_VTK_OUTPUT_PATHS) 75 | ENDIF (EXISTS ${VTK_DIR}/bin) 76 | 77 | # Create the header to configure the classes. 78 | CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/vtkBioengConfigure.h.in 79 | ${PROJECT_BINARY_DIR}/${PROJECT_NAME}Configure.h 80 | @ONLY IMMEDIATE) 81 | 82 | # Create the instantiator for these classes. 83 | SET(VTK_USE_INSTANTIATOR_NEW 1) 84 | VTK_MAKE_INSTANTIATOR3("${PROJECT_NAME}Instantiator" 85 | vtkBioengInstantiator_SRCS 86 | "${vtkBioeng_SRCS}" 87 | "VTK_BIOENG_EXPORT" 88 | ${PROJECT_BINARY_DIR} 89 | "${PROJECT_NAME}Configure.h") 90 | 91 | # Create the library. 92 | ADD_LIBRARY(${PROJECT_NAME} ${vtkBioeng_SRCS} ${vtkBioengInstantiator_SRCS}) 93 | TARGET_LINK_LIBRARIES(${PROJECT_NAME} ${vtkBioeng_LIBS}) 94 | 95 | # Create Tcl wrappers if VTK is wrapped in Tcl. 96 | IF(VTK_WRAP_TCL) 97 | INCLUDE(${VTK_CMAKE_DIR}/vtkWrapTcl.cmake) 98 | SET(VTK_WRAP_TCL2_INIT_DIR "${PROJECT_SOURCE_DIR}") 99 | VTK_WRAP_TCL2(${PROJECT_NAME}TCL vtkBioengTCL_SRCS ${vtkBioeng_SRCS} ${Kit_TCL_EXTRA_CMDS}) 100 | ADD_LIBRARY(${PROJECT_NAME}TCL ${vtkBioengTCL_SRCS}) 101 | TARGET_LINK_LIBRARIES(${PROJECT_NAME}TCL ${PROJECT_NAME}) 102 | FOREACH(c ${vtkBioeng_LIBS}) 103 | TARGET_LINK_LIBRARIES(${PROJECT_NAME}TCL ${c}TCL) 104 | ENDFOREACH(c) 105 | 106 | # Create the list of kits that are required. 107 | SET(VTKBIOENG_KITS "") 108 | FOREACH(c ${vtkBioeng_LIBS}) 109 | SET(VTKBIOENG_KITS "${VTKBIOENG_KITS} ${c}") 110 | ENDFOREACH(c) 111 | FOREACH(c ${vtkBioeng_SRCS}) 112 | GET_FILENAME_COMPONENT(VTKBIOENG_LAST_CLASS ${c} NAME_WE) 113 | ENDFOREACH(c) 114 | 115 | IF(CMAKE_CONFIGURATION_TYPES) 116 | FOREACH(config ${CMAKE_CONFIGURATION_TYPES}) 117 | SET(VTKBIOENG_TCL_LIBRARY_DIR "${LIBRARY_OUTPUT_PATH}/${config}") 118 | CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/Wrapping/tcl/pkgIndex.tcl.in 119 | ${PROJECT_BINARY_DIR}/Wrapping/tcl/${config}/pkgIndex.tcl 120 | @ONLY IMMEDIATE) 121 | CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/Wrapping/tcl/vtkbioeng/vtkbioeng.tcl 122 | ${PROJECT_BINARY_DIR}/Wrapping/tcl/vtkbioeng/vtkbioeng.tcl 123 | @ONLY IMMEDIATE) 124 | ENDFOREACH(config) 125 | ELSE(CMAKE_CONFIGURATION_TYPES) 126 | SET(VTKBIOENG_TCL_LIBRARY_DIR "${LIBRARY_OUTPUT_PATH}") 127 | CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/Wrapping/tcl/pkgIndex.tcl.in 128 | ${PROJECT_BINARY_DIR}/Wrapping/tcl/pkgIndex.tcl.in 129 | @ONLY IMMEDIATE) 130 | CONFIGURE_FILE(${PROJECT_SOURCE_DIR}/Wrapping/tcl/vtkbioeng/vtkbioeng.tcl 131 | ${PROJECT_BINARY_DIR}/Wrapping/tcl/vtkbioeng/vtkbioeng.tcl 132 | @ONLY IMMEDIATE) 133 | ENDIF(CMAKE_CONFIGURATION_TYPES) 134 | 135 | ENDIF(VTK_WRAP_TCL) 136 | 137 | # Create Python wrappers if VTK is wrapped in Python. 138 | IF(VTK_WRAP_PYTHON) 139 | INCLUDE(${VTK_CMAKE_DIR}/vtkWrapPython.cmake) 140 | VTK_WRAP_PYTHON3(${PROJECT_NAME}Python vtkBioengPYTHON_SRCS "${vtkBioeng_SRCS}") 141 | ADD_LIBRARY(${PROJECT_NAME}PythonD ${vtkBioengPYTHON_SRCS}) 142 | ADD_LIBRARY(${PROJECT_NAME}Python MODULE ${PROJECT_NAME}PythonInit.cxx) 143 | TARGET_LINK_LIBRARIES(${PROJECT_NAME}PythonD ${PROJECT_NAME}) 144 | FOREACH(c ${vtkBioeng_LIBS}) 145 | TARGET_LINK_LIBRARIES(${PROJECT_NAME}PythonD ${c}PythonD) 146 | ENDFOREACH(c) 147 | TARGET_LINK_LIBRARIES(${PROJECT_NAME}Python ${PROJECT_NAME}PythonD) 148 | ENDIF(VTK_WRAP_PYTHON) 149 | 150 | SUBDIRS(Testing) 151 | SUBDIRS(Utilities) 152 | ENDIF(VTK_FOUND) 153 | -------------------------------------------------------------------------------- /Utilities/Doxygen/doxyfile.in: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------- 2 | # doxyfile for vtkMy 3 | # modified by S. Barre (Time-stamp: <2002-02-13 18:24:35 barre> 4 | # ------------------------------------------------------------------------- 5 | 6 | PROJECT_NAME = vtkBioeng 7 | 8 | FULL_PATH_NAMES = YES 9 | WARN_IF_UNDOCUMENTED = NO 10 | 11 | GENERATE_TREEVIEW = NO 12 | GENERATE_TODOLIST = YES 13 | GENERATE_BUGLIST = YES 14 | GENERATE_HTML = YES 15 | GENERATE_HTMLHELP = YES 16 | GENERATE_LATEX = NO 17 | GENERATE_MAN = NO 18 | GENERATE_RTF = NO 19 | GENERATE_TAGFILE = "@VTKBIOENG_BINARY_DIR@/Utilities/Doxygen/vtkBioeng.tag" 20 | 21 | HAVE_DOT = YES 22 | #HAVE_DOT = NO 23 | DOT_PATH = "@DOT_PATH@" 24 | CLASS_GRAPH = YES 25 | COLLABORATION_GRAPH = YES 26 | TEMPLATE_RELATIONS = YES 27 | INCLUDE_GRAPH = YES 28 | INCLUDED_BY_GRAPH = YES 29 | CLASS_DIAGRAMS = YES 30 | GENERATE_LEGEND = YES 31 | GRAPHICAL_HIERARCHY = YES 32 | 33 | ALLEXTERNALS = NO 34 | 35 | IMAGE_PATH = "@VTKBIOENG_SOURCE_DIR@/Utilities/Doxygen" 36 | 37 | OUTPUT_DIRECTORY = "@VTKBIOENG_BINARY_DIR@/Utilities/Doxygen/doc" 38 | 39 | INPUT = \ 40 | "@VTKBIOENG_BINARY_DIR@/Utilities/Doxygen/dox" 41 | "@VTKBIOENG_BINARY_DIR@/Utilities/Doxygen/dox/doc_vtkBioeng_index.dox" 42 | 43 | EXCLUDE_PATTERNS = 44 | EXCLUDE = 45 | 46 | TAGFILES = "@VTKBIOENG_BINARY_DIR@/Utilities/Doxygen/vtkNightlyDoc.tag=http://www.vtk.org/doc/nightly/html" 47 | 48 | EXTRACT_ALL = YES 49 | EXTRACT_PRIVATE = NO 50 | EXTRACT_STATIC = YES 51 | EXTRACT_LOCAL_CLASSES = NO 52 | HIDE_UNDOC_MEMBERS = NO 53 | HIDE_UNDOC_CLASSES = YES 54 | ALWAYS_DETAILED_SEC = NO 55 | SOURCE_BROWSER = YES 56 | INLINE_SOURCES = NO 57 | CASE_SENSE_NAMES = YES 58 | VERBATIM_HEADERS = NO 59 | SHOW_INCLUDE_FILES = YES 60 | JAVADOC_AUTOBRIEF = YES 61 | SORT_MEMBER_DOCS = NO 62 | DISTRIBUTE_GROUP_DOC = YES 63 | TAB_SIZE = 3 64 | DETAILS_AT_TOP = YES 65 | 66 | FILE_PATTERNS = *.h 67 | RECURSIVE = NO 68 | 69 | HTML_ALIGN_MEMBERS = YES 70 | ALPHABETICAL_INDEX = YES 71 | COLS_IN_ALPHA_INDEX = 3 72 | IGNORE_PREFIX = vtkBioeng vtk 73 | 74 | ENABLE_PREPROCESSING = YES 75 | MACRO_EXPANSION = YES 76 | SEARCH_INCLUDES = YES 77 | INCLUDE_PATH = 78 | EXPAND_ONLY_PREDEF = YES 79 | PREDEFINED = "vtkSetMacro(name,type)= \ 80 | virtual void Set##name (type);" \ 81 | "vtkGetMacro(name,type)= \ 82 | virtual type Get##name ();" \ 83 | "vtkSetStringMacro(name)= \ 84 | virtual void Set##name (const char*);" \ 85 | "vtkGetStringMacro(name)= \ 86 | virtual char* Get##name ();" \ 87 | "vtkSetClampMacro(name,type,min,max)= \ 88 | virtual void Set##name (type);" \ 89 | "vtkSetObjectMacro(name,type)= \ 90 | virtual void Set##name (type*);" \ 91 | "vtkGetObjectMacro(name,type)= \ 92 | virtual type *Get##name ();" \ 93 | "vtkBooleanMacro(name,type)= \ 94 | virtual void name##On (); \ 95 | virtual void name##Off ();" \ 96 | "vtkSetVector2Macro(name,type)= \ 97 | virtual void Set##name (type, type); \ 98 | void Set##name (type [2]);" \ 99 | "vtkGetVector2Macro(name,type)= \ 100 | virtual type *Get##name (); \ 101 | virtual void Get##name (type &, type &); \ 102 | virtual void Get##name (type [2]);" \ 103 | "vtkSetVector3Macro(name,type)= \ 104 | virtual void Set##name (type, type, type); \ 105 | virtual void Set##name (type [3]);" \ 106 | "vtkGetVector3Macro(name,type)= \ 107 | virtual type *Get##name (); \ 108 | virtual void Get##name (type &, type &, type &); \ 109 | virtual void Get##name (type [3]);" \ 110 | "vtkSetVector4Macro(name,type)= \ 111 | virtual void Set##name (type, type, type, type); \ 112 | virtual void Set##name (type [4]);" \ 113 | "vtkGetVector4Macro(name,type)= \ 114 | virtual type *Get##name (); \ 115 | virtual void Get##name (type &, type &, type &, type &); \ 116 | virtual void Get##name (type [4]);" \ 117 | "vtkSetVector6Macro(name,type)= \ 118 | virtual void Set##name (type, type, type, type, \ 119 | type, type); \ 120 | virtual void Set##name (type [6]);" \ 121 | "vtkGetVector6Macro(name,type)= \ 122 | virtual type *Get##name (); \ 123 | virtual void Get##name (type &, type &, type &, \ 124 | type &, type &, type &); \ 125 | virtual void Get##name (type [6]);" \ 126 | "vtkSetVectorMacro(name,type,count)= \ 127 | virtual void Set##name(type data[]);" \ 128 | "vtkGetVectorMacro(name,type,count)= \ 129 | virtual type *Get##name (); \ 130 | virtual void Get##name(type data[##count]);" \ 131 | "vtkWorldCoordinateMacro(name)= \ 132 | virtual vtkCoordinate *Get##name##Coordinate (); \ 133 | virtual void Set##name(float x[3]); \ 134 | virtual void Set##name(float x, float y, float z); \ 135 | virtual float *Get##name();" \ 136 | "vtkViewportCoordinateMacro(name)= \ 137 | virtual vtkCoordinate *Get##name##Coordinate (); \ 138 | virtual void Set##name(float x[2]); \ 139 | virtual void Set##name(float x, float y); \ 140 | virtual float *Get##name();" \ 141 | "vtkTypeMacro(thisClass,superclass)= \ 142 | virtual const char *GetClassName(); \ 143 | static int IsTypeOf(const char *type); \ 144 | virtual int IsA(const char *type); \ 145 | static thisClass* SafeDownCast(vtkObject *o);" 146 | 147 | 148 | -------------------------------------------------------------------------------- /vtkCellsFilter.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | 3 | Program: Visualization Toolkit 4 | Module: vtkCellsFilter.cxx 5 | Language: C++ 6 | Version: $Id$ 7 | 8 | Copyright (c) 2004 Goodwin Lawlor 9 | All rights reserved. 10 | 11 | This software is distributed WITHOUT ANY WARRANTY; without even 12 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 13 | PURPOSE. 14 | 15 | =========================================================================*/ 16 | #include "vtkCellsFilter.h" 17 | #include "vtkIdList.h" 18 | #include "vtkObjectFactory.h" 19 | #include "vtkPolyData.h" 20 | #include "vtkCellArray.h" 21 | #include "vtkPointData.h" 22 | #include "vtkCellData.h" 23 | #include "vtkCellArray.h" 24 | #include "vtkCharArray.h" 25 | #include "vtkLookupTable.h" 26 | #include "vtkInformation.h" 27 | #include "vtkInformationVector.h" 28 | 29 | vtkCxxRevisionMacro(vtkCellsFilter, "$Revision$"); 30 | 31 | 32 | // Constructs with initial values. 33 | vtkCellsFilter::vtkCellsFilter() 34 | { 35 | this->CellIdList= vtkIdList::New(); 36 | this->MarkedCellIdList = vtkIdList::New(); 37 | this->IsInitialized = 0; 38 | this->IsScalarsInitialized = 0; 39 | this->Scalars = vtkCharArray::New(); 40 | this->Scalars->SetNumberOfComponents(1); 41 | this->Scalars->SetName("MarkedCells"); 42 | this->MarkedColor[0] = 1.0; 43 | this->MarkedColor[0] = 0.0; 44 | this->MarkedColor[0] = 0.0; 45 | this->UnmarkedColor[0] = 1.0; 46 | this->UnmarkedColor[0] = 1.0; 47 | this->UnmarkedColor[0] = 1.0; 48 | this->MarkedOpacity = 1.0; 49 | this->LUT = vtkLookupTable::New(); 50 | this->LUT->SetNumberOfColors(2); 51 | this->LUT->SetTableValue(0, 1.0, 1.0, 1.0, 1.0); 52 | this->LUT->SetTableValue(1, 1.0, 0.0, 0.0, 1.0); 53 | this->LUT->Build(); 54 | this->Scalars->SetLookupTable(this->LUT); 55 | } 56 | 57 | // Destroy any allocated memory. 58 | vtkCellsFilter::~vtkCellsFilter() 59 | { 60 | this->CellIdList->Delete(); 61 | this->MarkedCellIdList->Delete(); 62 | this->Scalars->Delete(); 63 | this->LUT->Delete(); 64 | } 65 | 66 | void vtkCellsFilter::SetMarkedColor(double r, double g, double b) 67 | { 68 | this->LUT->SetTableValue(1, r, g, b, this->MarkedOpacity); 69 | this->MarkedColor[0] = r; 70 | this->MarkedColor[0] = g; 71 | this->MarkedColor[0] = b; 72 | this->LUT->Build(); 73 | 74 | } 75 | 76 | void vtkCellsFilter::SetUnmarkedColor(double r, double g, double b) 77 | { 78 | this->LUT->SetTableValue(0, r, g, b, 1.0); 79 | this->UnmarkedColor[0] = r; 80 | this->UnmarkedColor[0] = g; 81 | this->UnmarkedColor[0] = b; 82 | this->LUT->Build(); 83 | 84 | } 85 | 86 | void vtkCellsFilter::SetMarkedOpacity(double opacity) 87 | { 88 | double rgba[4]; 89 | this->LUT->GetTableValue(1, rgba); 90 | this->LUT->SetTableValue(1, rgba[0], rgba[1], rgba[2], opacity); 91 | this->MarkedOpacity = opacity; 92 | this->LUT->Build(); 93 | } 94 | 95 | 96 | // Description: 97 | // Perform cell removal 98 | int vtkCellsFilter::RequestData( 99 | vtkInformation *vtkNotUsed(request), 100 | vtkInformationVector **inputVector, 101 | vtkInformationVector *outputVector) 102 | { 103 | if (!this->IsInitialized) 104 | { 105 | this->Initialize(); 106 | } 107 | 108 | // get the info objects 109 | vtkInformation *inInfo = inputVector[0]->GetInformationObject(0); 110 | vtkInformation *outInfo = outputVector->GetInformationObject(0); 111 | 112 | // get the input and ouptut 113 | vtkPolyData *input = vtkPolyData::SafeDownCast( 114 | inInfo->Get(vtkDataObject::DATA_OBJECT())); 115 | vtkPolyData *output = vtkPolyData::SafeDownCast( 116 | outInfo->Get(vtkDataObject::DATA_OBJECT())); 117 | 118 | // num of cells that will be in the output 119 | vtkIdType numCells = this->CellIdList->GetNumberOfIds(); 120 | // dont know how many points... cant be more than the input 121 | vtkIdType numPts = input->GetNumberOfPoints(); 122 | 123 | vtkPointData *outPD = output->GetPointData(); 124 | outPD->CopyAllocate(input->GetPointData(), numPts); 125 | vtkCellData *outCD = output->GetCellData(); 126 | outCD->CopyAllocate(input->GetCellData(),numCells); 127 | output->Allocate(input,numCells); 128 | 129 | // Copy unremoved cells to the output... 130 | output->CopyCells(input, this->CellIdList); 131 | 132 | return 1; 133 | 134 | } 135 | 136 | void vtkCellsFilter::Initialize() 137 | { 138 | // This updates the pipeline upstream so that we can get the number 139 | // of cells... horrific vtk filter design, but what else will work? I could 140 | // document to explicitly call ->Update() on previous filter. It wont 141 | // matter if the user lets the vtk pipeline execute once first and heads 142 | // into the event loop like the filter was intended to do originally. 143 | 144 | // This also gets around the problem when the user is in the event 145 | // loop but some filter has been modified upstream, changing the data. 146 | this->GetPolyDataInput(0)->Update(); 147 | 148 | vtkIdType numCells = this->GetPolyDataInput(0)->GetNumberOfCells(); 149 | this->CellIdList->SetNumberOfIds(numCells); 150 | 151 | for (vtkIdType i=0; i < numCells; i++) 152 | { 153 | this->CellIdList->SetId(i,i); 154 | } 155 | 156 | this->IsInitialized = 1; 157 | } 158 | 159 | void vtkCellsFilter::InitializeScalars() 160 | { 161 | // CellIdList will have been initialized first 162 | vtkIdType numCells = this->CellIdList->GetNumberOfIds(); 163 | this->Scalars->SetNumberOfValues(numCells); 164 | 165 | 166 | 167 | for (vtkIdType i=0; i < numCells; i++) 168 | { 169 | this->Scalars->SetValue(i,0); 170 | } 171 | 172 | this->MarkedCellIdList->Reset(); 173 | this->GetOutput()->GetCellData()->SetScalars(this->Scalars); 174 | this->IsScalarsInitialized = 1; 175 | } 176 | 177 | void vtkCellsFilter::ToggleCell(vtkIdType cellid_at_output) 178 | { 179 | vtkIdType cellid_at_input; 180 | 181 | // If the input to the filter has changed since the last execution 182 | // we need 183 | 184 | if (!this->IsInitialized) 185 | { 186 | this->Initialize(); 187 | } 188 | 189 | // only initialize scalars if MarkCell or ToggleCells is used 190 | if (!this->IsScalarsInitialized) 191 | { 192 | this->InitializeScalars(); 193 | } 194 | 195 | cellid_at_input = this->CellIdList->GetId(cellid_at_output); 196 | 197 | 198 | 199 | if (this->MarkedCellIdList->IsId(cellid_at_input) == -1) 200 | { 201 | this->MarkedCellIdList->InsertNextId(cellid_at_input); 202 | this->Scalars->SetValue(cellid_at_output, 1); 203 | } 204 | else 205 | { 206 | this->MarkedCellIdList->DeleteId(cellid_at_input); 207 | this->Scalars->SetValue(cellid_at_output, 0); 208 | } 209 | 210 | //do this here to avoid re-executing this filter... 211 | this->GetOutput()->GetCellData()->SetScalars(this->Scalars); 212 | this->Scalars->Modified(); 213 | 214 | } 215 | 216 | void vtkCellsFilter::UnmarkCell(vtkIdType cellid_at_output) 217 | { 218 | vtkIdType cellid_at_input; 219 | 220 | // check if anything has been marked first 221 | if (!this->IsScalarsInitialized) 222 | { 223 | return; 224 | } 225 | 226 | // see comment below 227 | cellid_at_input = this->CellIdList->GetId(cellid_at_output); 228 | 229 | 230 | this->MarkedCellIdList->DeleteId(cellid_at_input); 231 | this->Scalars->SetValue(cellid_at_output, 0); 232 | 233 | //do this here to avoid re-executing this filter... 234 | this->Scalars->Modified(); 235 | 236 | } 237 | 238 | void vtkCellsFilter::MarkCell(vtkIdType cellid_at_output) 239 | { 240 | vtkIdType cellid_at_input; 241 | 242 | if (!this->IsInitialized) 243 | { 244 | this->Initialize(); 245 | } 246 | 247 | // only initialize scalars if MarkCell is used 248 | if (!this->IsScalarsInitialized) 249 | { 250 | this->InitializeScalars(); 251 | } 252 | 253 | // see comment below 254 | cellid_at_input = this->CellIdList->GetId(cellid_at_output); 255 | 256 | 257 | this->MarkedCellIdList->InsertNextId(cellid_at_input); 258 | this->Scalars->SetValue(cellid_at_output, 1); 259 | 260 | //do this here to avoid re-executing this filter... 261 | this->GetOutput()->GetCellData()->SetScalars(this->Scalars); 262 | this->Scalars->Modified(); 263 | 264 | } 265 | 266 | 267 | void vtkCellsFilter::PrintSelf(ostream& os, vtkIndent indent) 268 | { 269 | this->Superclass::PrintSelf(os,indent); 270 | 271 | } 272 | -------------------------------------------------------------------------------- /vtkCollisionDetectionFilter.h: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | 3 | Program: Visualization Toolkit 4 | Module: vtkCollisionDetectionFilter.h 5 | Language: C++ 6 | RCS: $Id$ 7 | 8 | Copyright (c) 2003 and onwards, Goodwin Lawlor 9 | All rights reserved. 10 | 11 | http://www.bioengineering-research.com/copyright.html for copyright details 12 | 13 | =========================================================================*/ 14 | // .NAME vtkCollisionDetectionFilter - performs collision determination between two polyhedral surfaces 15 | // .SECTION Description 16 | // vtkCollisionDetectionFilter performs collision determination between two polyhedral surfaces using 17 | // two instances of vtkOBBTree. Set the polydata inputs, the tolerance and transforms or matrices. If 18 | // CollisionMode is set to AllContacts, the Contacts output will be lines of contact. 19 | // If CollisionMode is FirstContact or HalfContacts then the Contacts output will be vertices. 20 | // See below for an explanation of these options. 21 | // 22 | // This class can be used to clip one polydata surface with another, using the Contacts output as a loop 23 | // set in vtkSelectPolyData 24 | 25 | // .SECTION Caveats 26 | // Currently only triangles are processed. Use vtkTriangleFilter to 27 | // convert any strips or polygons to triangles. 28 | 29 | // .SECTION Thanks 30 | // Goodwin Lawlor , University College Dublin, who wrote this class. 31 | // Thanks to Peter C. Everett for vtkOBBTree::IntersectWithOBBTree() in particular, 32 | // and all those who contributed to vtkOBBTree in general. 33 | 34 | 35 | // .SECTION See Also 36 | // vtkTriangleFilter, vtkSelectPolyData, vtkOBBTree 37 | 38 | #ifndef __vtkCollisionDetectionFilter_h 39 | #define __vtkCollisionDetectionFilter_h 40 | 41 | #include "vtkPolyDataAlgorithm.h" 42 | #include "vtkBioengConfigure.h" // Include configuration header. 43 | 44 | #include "vtkLinearTransform.h" 45 | #include "vtkIdTypeArray.h" 46 | #include "vtkFieldData.h" 47 | 48 | class vtkOBBTree; 49 | class vtkPolyData; 50 | class vtkPoints; 51 | class vtkMatrix4x4; 52 | 53 | // If you are compiling this class as an addition to VTK/Graphics change VTK_BIOENG_EXPORTS 54 | // to VTK_GRAPHICS_EXPORT on the next line and delete 55 | // "#include "vtkBioengConfigure.h" // Include configuration header." above. 56 | 57 | class VTK_BIOENG_EXPORT vtkCollisionDetectionFilter : public vtkPolyDataAlgorithm 58 | { 59 | public: 60 | vtkTypeRevisionMacro(vtkCollisionDetectionFilter, vtkPolyDataAlgorithm); 61 | void PrintSelf(ostream& os, vtkIndent indent); 62 | 63 | //BTX 64 | enum CollisionModes 65 | { 66 | VTK_ALL_CONTACTS = 0, 67 | VTK_FIRST_CONTACT = 1, 68 | VTK_HALF_CONTACTS = 2 69 | }; 70 | //ETX 71 | 72 | // Description: 73 | // Set the collision mode to VTK_ALL_CONTACTS to find all the contacting cell pairs with 74 | // two points per collision, or VTK_HALF_CONTACTS to find all the contacting cell pairs 75 | // with one point per collision, or VTK_FIRST_CONTACT to quickly find the first contact 76 | // point. 77 | vtkSetClampMacro(CollisionMode,int,VTK_ALL_CONTACTS,VTK_HALF_CONTACTS); 78 | vtkGetMacro(CollisionMode,int); 79 | void SetCollisionModeToAllContacts() {this->SetCollisionMode(VTK_ALL_CONTACTS);}; 80 | void SetCollisionModeToFirstContact() {this->SetCollisionMode(VTK_FIRST_CONTACT);}; 81 | void SetCollisionModeToHalfContacts() {this->SetCollisionMode(VTK_HALF_CONTACTS);}; 82 | const char *GetCollisionModeAsString(); 83 | 84 | // Description: 85 | // Constructs with initial values. 86 | static vtkCollisionDetectionFilter *New(); 87 | 88 | // Description: 89 | // Intersect two polygons, return x1 and x2 as the twp points of intersection. If 90 | // CollisionMode = VTK_ALL_CONTACTS, both contact points are found. If 91 | // CollisionMode = VTK_FIRST_CONTACT or VTK_HALF_CONTACTS, only 92 | // one contact point is found. 93 | int IntersectPolygonWithPolygon(int npts, double *pts, double bounds[6], 94 | int npts2, double *pts2, 95 | double bounds2[6], double tol2, 96 | double x1[2], double x2[3], 97 | int CollisionMode); 98 | 99 | // Description: 100 | // Set and Get the input vtk polydata models 101 | void SetInput(int i, vtkPolyData *model); 102 | vtkPolyData *GetInput(int i); 103 | 104 | 105 | // Description: 106 | // Get an array of the contacting cells. This is a convenience method to access 107 | // the "ContactCells" field array in outputs 0 and 1. These arrays index contacting 108 | // cells (eg) index 50 of array 0 points to a cell (triangle) which contacts/intersects 109 | // a cell at index 50 of array 1. This method is equivalent to 110 | // GetOutput(i)->GetFieldData()->GetArray("ContactCells") 111 | vtkIdTypeArray *GetContactCells(int i); 112 | 113 | // Description: 114 | // Get the output with the points where the contacting cells intersect. This method is 115 | // is equivalent to GetOutputPort(2)/GetOutput(2) 116 | vtkAlgorithmOutput *GetContactsOutputPort() {return this->GetOutputPort(2);} 117 | vtkPolyData *GetContactsOutput() {return this->GetOutput(2);} 118 | 119 | // Description: 120 | // Specify the transform object used to transform models. Alternatively, matrices 121 | // can be set instead. 122 | void SetTransform(int i, vtkLinearTransform *transform); 123 | vtkLinearTransform *GetTransform(int i) {return this->Transform[i];} 124 | 125 | // Description: 126 | // Specify the matrix object used to transform models. 127 | void SetMatrix(int i, vtkMatrix4x4 *matrix); 128 | vtkMatrix4x4 *GetMatrix(int i); 129 | 130 | //Description: 131 | // Set and Get the obb tolerance (absolute value, in world coords). Default is 0.001 132 | vtkSetMacro(BoxTolerance, float); 133 | vtkGetMacro(BoxTolerance, float); 134 | 135 | //Description: 136 | // Set and Get the cell tolerance (squared value). Default is 0.0 137 | vtkSetMacro(CellTolerance, double); 138 | vtkGetMacro(CellTolerance, double); 139 | 140 | //Description: 141 | // Set and Get the the flag to visualize the contact cells. If set the contacting cells 142 | // will be coloured from red through to blue, with collisions first determined coloured red. 143 | vtkSetMacro(GenerateScalars, int); 144 | vtkGetMacro(GenerateScalars, int); 145 | vtkBooleanMacro(GenerateScalars,int); 146 | 147 | //Description: 148 | // Get the number of contacting cell pairs 149 | int GetNumberOfContacts() 150 | {return this->GetOutput(0)->GetFieldData()->GetArray("ContactCells")->GetNumberOfTuples();} 151 | 152 | //Description: 153 | // Get the number of box tests 154 | vtkGetMacro(NumberOfBoxTests, int); 155 | 156 | //Description: 157 | // Set and Get the number of cells in each OBB. Default is 2 158 | vtkSetMacro(NumberOfCellsPerNode, int); 159 | vtkGetMacro(NumberOfCellsPerNode, int); 160 | 161 | //Description: 162 | // Set and Get the opacity of the polydata output when a collision takes place. 163 | // Default is 1.0 164 | vtkSetClampMacro(Opacity, float, 0.0, 1.0); 165 | vtkGetMacro(Opacity, float); 166 | 167 | // Description: 168 | // Return the MTime also considering the transform. 169 | unsigned long GetMTime(); 170 | 171 | protected: 172 | vtkCollisionDetectionFilter(); 173 | ~vtkCollisionDetectionFilter(); 174 | 175 | // Usual data generation method 176 | virtual int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *); 177 | 178 | vtkOBBTree *tree0; 179 | vtkOBBTree *tree1; 180 | 181 | vtkLinearTransform *Transform[2]; 182 | vtkMatrix4x4 *Matrix[2]; 183 | 184 | int NumberOfBoxTests; 185 | 186 | int NumberOfCellsPerNode; 187 | 188 | int GenerateScalars; 189 | 190 | float BoxTolerance; 191 | float CellTolerance; 192 | float Opacity; 193 | 194 | int CollisionMode; 195 | 196 | private: 197 | 198 | vtkCollisionDetectionFilter(const vtkCollisionDetectionFilter&); // Not implemented. 199 | void operator=(const vtkCollisionDetectionFilter&); // Not implemented. 200 | }; 201 | 202 | //BTX 203 | 204 | inline const char *vtkCollisionDetectionFilter::GetCollisionModeAsString(void) 205 | { 206 | if ( this->CollisionMode == VTK_ALL_CONTACTS ) 207 | { 208 | return (char *)"AllContacts"; 209 | } 210 | else if (this->CollisionMode == VTK_FIRST_CONTACT) 211 | { 212 | return (char *)"FirstContact"; 213 | } 214 | else 215 | { 216 | return (char *)"HalfContacts"; 217 | } 218 | } 219 | 220 | //ETX 221 | #endif 222 | -------------------------------------------------------------------------------- /Utilities/Doxygen/doc_makeall.sh.in: -------------------------------------------------------------------------------- 1 | # ------------------------------------------------------------------------- 2 | # Doxygen documentation batch 3 | # modified by S. Barre (Time-stamp: <2003-01-16 14:04:41 barre> 4 | # ------------------------------------------------------------------------- 5 | 6 | # Path to several tools (_PROG to avoid the typical GZIP env var pb) 7 | # Example: 8 | # DOXYGEN_PROG=@DOXYGEN@ (INCLUDE(FindDoxygen.cmake)) 9 | # GZIP_PROG=@GZIP@ (INCLUDE(FindCygwin.cmake)) 10 | # HHC_PROG=@HTML_HELP_COMPILER@ (INCLUDE(FindHTMLHelp.cmake)) 11 | # MV_PROG=@MV@ (INCLUDE(FindCygwin.cmake)) 12 | # PERL_PROG=@PERL@ (INCLUDE(FindPerl.cmake)) 13 | # RM_PROG=@RM@ (INCLUDE(FindCygwin.cmake)) 14 | # TAR_PROG=@TAR@ (INCLUDE(FindCygwin.cmake)) 15 | # WGET_PROG=@WGET@ (INCLUDE(FindWget.cmake)) 16 | # 17 | export DOXYGEN_PROG="@DOXYGEN@" # Doxygen 18 | export GZIP_PROG="@GZIP@" # gzip (Unix-like 'gzip compressor') 19 | export GNUPLOT_PROG="@GNUPLOT@" # gnuplot (data plotting program) 20 | export HHC_PROG="@HTML_HELP_COMPILER@" # HTML Help Compiler 21 | export MV_PROG="@MV@" # mv (Unix-like 'move/rename files') 22 | export PERL_PROG="@PERL@" # Perl 23 | export RM_PROG="@RM@" # rm (Unix-like 'remove files') 24 | export TAR_PROG="@TAR@" # tar (Unix-like 'archiver') 25 | export WGET_PROG="@WGET@" # wget (remote file retrieval) 26 | 27 | # PROJECT_NAME: 28 | # Documentation/project name. Used in some of the resulting file names and 29 | # xrefs to uniquify two or more projects linked together through their 30 | # Doxygen's tag files. Mandatory for each documentation set. 31 | # Note: might be the same as the doxyfile's PROJECT_NAME 32 | # Example: 33 | # PROJECT_NAME=VTK 34 | # 35 | export PROJECT_NAME=vtkBioeng 36 | 37 | # PATH_TO_VTK_DOX_SCRIPTS: 38 | # Path to the directory holding the Perl scripts used to produce the VTK doc 39 | # in Doxygen format. You need the VTK source files or a local copy of 40 | # these scripts. 41 | # Example: 42 | # PATH_TO_VTK_DOX_SCRIPTS=@VTK_SOURCE_DIR@/Utilities/Doxygen 43 | # 44 | export PATH_TO_VTK_DOX_SCRIPTS="@VTK_SOURCE_DIR@/Utilities/Doxygen" 45 | 46 | # SOURCE_DIR: 47 | # Source directory. The top directory of the source files. 48 | # Example: 49 | # SOURCE_DIR=@VTKMY_SOURCE_DIR@ 50 | # 51 | export SOURCE_DIR="@VTKBIOENG_SOURCE_DIR@" 52 | 53 | # REL_PATH_TO_TOP: 54 | # Relative path from the top directory of the source files to the directory 55 | # (or top directory) holding the files to document. Useful if several parts 56 | # of the same source directory should be documented separately. 57 | # Example: 58 | # REL_PATH_TO_TOP=. 59 | # REL_PATH_TO_TOP=framework/src 60 | # 61 | export REL_PATH_TO_TOP=. 62 | 63 | # INTERMEDIATE_DOX_DIR: 64 | # Directory where the intermediate Doxygen files should be stored (mainly 65 | # these headers files converted from the VTK format to the Doxygen format). 66 | # This directory is erased at the end of this script, unless you comment 67 | # the corresponding line. 68 | # DOXTEMP might be used to simplify the syntax. 69 | # Example: 70 | # DOXTEMP=DOXTEMP=@VTKMY_BINARY_DIR@/Utilities/Doxygen 71 | # INTERMEDIATE_DOX_DIR=$DOXTEMP/dox 72 | # 73 | export DOXTEMP="@VTKBIOENG_BINARY_DIR@/Utilities/Doxygen" 74 | export INTERMEDIATE_DOX_DIR="$DOXTEMP/dox" 75 | 76 | # CVSWEB_CHECKOUT, CVSWEB_CHECKOUT_SUFFIX: 77 | # URL to the CVSWeb of the project, in checkout mode (i.e. appending a file 78 | # name to this URL will retrieve the contents of the file). In the same way 79 | # CVSWEB_CHECKOUT_SUFFIX is appended to the result. 80 | # Example: 81 | # CVSWEB_CHECKOUT=http://public.kitware.com/cgi-bin/cvsweb.cgi/~checkout~/VTK 82 | # CVSWEB_CHECKOUT_SUFFIX=?cvsroot=CMake 83 | # 84 | export CVSWEB_CHECKOUT="file://c:/src/Bioeng" 85 | export CVSWEB_CHECKOUT_SUFFIX="" 86 | 87 | # DATA_ROOT: 88 | # Data directory. The root directory of the data files. 89 | # Example: 90 | # DATA_ROOT=@VTK_DATA_ROOT@ 91 | # 92 | export DATA_ROOT="@VTK_DATA_ROOT@" 93 | 94 | # DOXYFILE: 95 | # Path to the Doxygen configuration file (i.e. doxyfile). 96 | # Example: 97 | # DOXYFILE=$DOXTEMP/doxyfile 98 | # 99 | export DOXYFILE="$DOXTEMP/doxyfile" 100 | 101 | # OUTPUT_DIRECTORY ALLOW_ERASE_OUTPUT_DIRECTORY: 102 | # Path to the Doxygen output directory (where the resulting doc is stored). 103 | # Note: should be the same as your doxyfile's OUTPUT_DIRECTORY 104 | # If ON, allows the output directory to be erased when some advanced output 105 | # file have been produced (HTML Help, or TAR archive for example). 106 | # Example: 107 | # OUTPUT_DIRECTORY=$DOXTEMP/doc 108 | # ALLOW_ERASE_OUTPUT_DIRECTORY=ON 109 | # 110 | export OUTPUT_DIRECTORY="$DOXTEMP/doc" 111 | export ALLOW_ERASE_OUTPUT_DIRECTORY=ON 112 | 113 | # COMPILE_HTML_HELP RESULTING_HTML_HELP_FILE: 114 | # Compile the CHM (Compressed HTML) HTML Help file, name of the resulting 115 | # file. If set to ON and name is non-empty these options will actually 116 | # trigger the HTML-Help compiler to create the CHM. The resulting 117 | # file (usually index.chm) will be renamed to this name. 118 | # Note: if ON, the whole $OUTPUT_DIRECTORY will be erased at the end of 119 | # this script, since this file is considered to be one of the 120 | # advanced final output, unless ALLOW_ERASE_OUTPUT_DIRECTORY is OFF 121 | # Note: your doxyfile should be configured to enable HTML Help creation 122 | # (using GENERATE_HTML = YES, GENERATE_HTMLHELP = YES) 123 | # Example: 124 | # COMPILE_HTML_HELP=ON 125 | # COMPILE_HTML_HELP=@DOCUMENTATION_HTML_HELP@ 126 | # RESULTING_HTML_HELP_FILE=$DOXTEMP/vtk4.chm 127 | # 128 | export COMPILE_HTML_HELP=@DOCUMENTATION_HTML_HELP@ 129 | export RESULTING_HTML_HELP_FILE="$DOXTEMP/$PROJECT_NAME.chm" 130 | 131 | # CREATE_HTML_TARZ_ARCHIVE RESULTING_HTML_TARZ_ARCHIVE_FILE: 132 | # Create a compressed (gzip) tar archive of the html directory (located 133 | # under the OUTPUT_DIRECTORY), and name of the resulting archive file. 134 | # Note: your doxyfile should be configured to enable HTML creation 135 | # (using GENERATE_HTML = YES) 136 | # Example: 137 | # CREATE_HTML_TARZ_ARCHIVE=ON 138 | # CREATE_HTML_TARZ_ARCHIVE=@DOCUMENTATION_HTML_TARZ@ 139 | # RESULTING_HTML_TARZ_ARCHIVE_FILE=$DOXTEMP/vtk4-html.tar.gz 140 | # 141 | export CREATE_HTML_TARZ_ARCHIVE=@DOCUMENTATION_HTML_TARZ@ 142 | export RESULTING_HTML_TARZ_ARCHIVE_FILE="$DOXTEMP/$PROJECT_NAME-html.tar.gz" 143 | 144 | # DOWNLOAD_VTK_TAGFILE VTK_TAGFILE VTK_TAGFILE_REMOTE_DIR VTK_TAGFILE_DEST_DIR: 145 | # Download the VTK tag file, name, remote location and destination dir of this 146 | # tag file. If set to ON, the tag file is retrieved from its remote location 147 | # using wget and stored in the destination dir. 148 | # The tag file is expected to be compressed using gzip, but DO NOT include 149 | # the .gz extension in VTK_TAGFILE. 150 | # Note: your doxyfile must be tailored to make use-of or create this tag file. 151 | # (using TAGFILES = vtk4-nightly.tag=http://www.vtk.org/doc/nightly/html 152 | # or GENERATE_TAGFILE = "@FOO_BINARY_DIR@/Utilities/Doxygen/vtk4.tag") 153 | # Example: 154 | # DOWNLOAD_VTK_TAGFILE=OFF 155 | # VTK_TAGFILE=vtk4-nightly.tag 156 | # VTK_TAGFILE_REMOTE_DIR=http://www.vtk.org/doc/nightly/html 157 | # VTK_TAGFILE_DEST_DIR=$DOXTEMP 158 | # 159 | export DOWNLOAD_VTK_TAGFILE=@DOCUMENTATION_DOWNLOAD_VTK_TAGFILE@ 160 | export VTK_TAGFILE=vtkNightlyDoc.tag 161 | export VTK_TAGFILE_REMOTE_DIR="http://www.vtk.org/files/nightly" 162 | export VTK_TAGFILE_DEST_DIR="$DOXTEMP" 163 | 164 | # ---------------------------------------------------------------------------- 165 | # Convert the VTKBIOENG headers to the Doxygen format. 166 | 167 | if test "x$PERL_PROG" != "xNOTFOUND" ; then 168 | $PERL_PROG "$PATH_TO_VTK_DOX_SCRIPTS/doc_header2doxygen.pl" \ 169 | --to "$INTERMEDIATE_DOX_DIR" \ 170 | --relativeto "$SOURCE_DIR/$REL_PATH_TO_TOP" \ 171 | "$SOURCE_DIR/$REL_PATH_TO_TOP/" 172 | fi 173 | 174 | # ---------------------------------------------------------------------------- 175 | # Build the full-text index. 176 | 177 | if test "x$PERL_PROG" != "xNOTFOUND" ; then 178 | $PERL_PROG "$PATH_TO_VTK_DOX_SCRIPTS/doc_index.pl" \ 179 | --project "$PROJECT_NAME" \ 180 | --stop "$PATH_TO_VTK_DOX_SCRIPTS/doc_index.stop" \ 181 | --store "doc_""$PROJECT_NAME""_index.dox" \ 182 | --to "$INTERMEDIATE_DOX_DIR" \ 183 | "$SOURCE_DIR/$REL_PATH_TO_TOP/" 184 | fi 185 | 186 | # ---------------------------------------------------------------------------- 187 | # Retrieve the (gziped) VTK 4 tag file and decompress it 188 | 189 | if test "x$DOWNLOAD_VTK_TAGFILE" == "xON" ; then 190 | if test "x$VTK_TAGFILE" != "x" ; then 191 | if test "x$WGET_PROG" != "xNOTFOUND" ; then 192 | $WGET_PROG -nd -nH \ 193 | "$VTK_TAGFILE_REMOTE_DIR/$VTK_TAGFILE.gz" \ 194 | -O "$VTK_TAGFILE_DEST_DIR/$VTK_TAGFILE.gz" 195 | if test "x$GZIP_PROG" != "xNOTFOUND" ; then 196 | $GZIP_PROG -d "$VTK_TAGFILE_DEST_DIR/$VTK_TAGFILE.gz" 197 | fi 198 | fi 199 | fi 200 | fi 201 | 202 | # ---------------------------------------------------------------------------- 203 | # Create the Doxygen doc. 204 | 205 | if test "x$DOXYGEN_PROG" != "xNOTFOUND" ; then 206 | 207 | if test "x$RM_PROG" != "xNOTFOUND" ; then 208 | $RM_PROG -fr "$OUTPUT_DIRECTORY" 209 | fi 210 | 211 | $DOXYGEN_PROG "$DOXYFILE" 212 | fi 213 | 214 | # ---------------------------------------------------------------------------- 215 | # Clean the HTML pages to remove the path to the intermediate Doxygen dir. 216 | 217 | if test "x$PERL_PROG" != "xNOTFOUND" ; then 218 | $PERL_PROG "$PATH_TO_VTK_DOX_SCRIPTS/doc_rmpath.pl" \ 219 | --to "$INTERMEDIATE_DOX_DIR" \ 220 | --html "$OUTPUT_DIRECTORY/html" 221 | fi 222 | 223 | # ---------------------------------------------------------------------------- 224 | # clean the HTML pages to remove layout pbs 225 | # 226 | #if test "x$PERL_PROG" != "xNOTFOUND" ; then 227 | # $PERL_PROG $PATH_TO_VTK_DOX_SCRIPTS/doc_cleanhtml.pl \ 228 | # --html "$OUTPUT_DIRECTORY/html" 229 | #fi 230 | 231 | # ---------------------------------------------------------------------------- 232 | # Create the CHM HTML HELP doc. 233 | 234 | if test "x$COMPILE_HTML_HELP" == "xON" ; then 235 | if test "x$RESULTING_HTML_HELP_FILE" != "x" ; then 236 | cd "$OUTPUT_DIRECTORY/html" 237 | if test "x$HHC_PROG" != "xNOTFOUND" ; then 238 | $HHC_PROG index.hhp 239 | if test "x$MV_PROG" != "xNOTFOUND" ; then 240 | $MV_PROG -f index.chm "$RESULTING_HTML_HELP_FILE" 241 | fi 242 | fi 243 | fi 244 | fi 245 | 246 | # ---------------------------------------------------------------------------- 247 | # Create the compressed tar archive. 248 | 249 | if test "x$CREATE_HTML_TARZ_ARCHIVE" == "xON" ; then 250 | if test "x$RESULTING_HTML_TARZ_ARCHIVE_FILE" != "x" ; then 251 | cd "$OUTPUT_DIRECTORY" 252 | if test "x$TAR_PROG" != "xNOTFOUND" ; then 253 | if test "x$RM_PROG" != "xNOTFOUND" ; then 254 | $RM_PROG -f html.tar 255 | fi 256 | $TAR_PROG -cf html.tar html 257 | if test "x$GZIP_PROG" != "xNOTFOUND" ; then 258 | if test "x$RM_PROG" != "xNOTFOUND" ; then 259 | $RM_PROG -f html.tar.gz 260 | fi 261 | $GZIP_PROG html.tar 262 | $MV_PROG -f html.tar.gz "$RESULTING_HTML_TARZ_ARCHIVE_FILE" 263 | fi 264 | fi 265 | fi 266 | fi 267 | 268 | # ---------------------------------------------------------------------------- 269 | # Clean-up. 270 | 271 | if test "x$RM_PROG" != "xNOTFOUND" ; then 272 | $RM_PROG -fr "$INTERMEDIATE_DOX_DIR" 273 | 274 | if test "x$DOWNLOAD_VTK_TAGFILE" == "xON" ; then 275 | if test "x$VTK_TAGFILE" != "x" ; then 276 | $RM_PROG -f "$VTK_TAGFILE_DEST_DIR/$VTK_TAGFILE" 277 | fi 278 | fi 279 | 280 | if test "x$COMPILE_HTML_HELP" == "xON" ; then 281 | if test "x$RESULTING_HTML_HELP_FILE" != "x" ; then 282 | if test "x$ALLOW_ERASE_OUTPUT_DIRECTORY" == "xON" ; then 283 | $RM_PROG -fr "$OUTPUT_DIRECTORY" 284 | fi 285 | fi 286 | fi 287 | fi 288 | -------------------------------------------------------------------------------- /vtkCollisionDetectionFilter.cxx: -------------------------------------------------------------------------------- 1 | /*========================================================================= 2 | 3 | Program: Visualization Toolkit 4 | Module: vtkCollisionDetectionFilter.cxx 5 | Language: C++ 6 | RCS: $Id$ 7 | 8 | Copyright (c) 2003-2004 Goodwin Lawlor 9 | All rights reserved. 10 | 11 | This software is distributed WITHOUT ANY WARRANTY; without even 12 | the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 13 | PURPOSE. 14 | 15 | =========================================================================*/ 16 | #include "vtkCollisionDetectionFilter.h" 17 | #include "vtkObjectFactory.h" 18 | #include "vtkOBBTree.h" 19 | #include "vtkMatrix4x4.h" 20 | #include "vtkIdList.h" 21 | #include "vtkPolyData.h" 22 | #include "vtkPolygon.h" 23 | #include "vtkCommand.h" 24 | #include "vtkPoints.h" 25 | #include "vtkLookupTable.h" 26 | #include "vtkUnsignedCharArray.h" 27 | #include "vtkIdTypeArray.h" 28 | #include "vtkCellData.h" 29 | #include "vtkBox.h" 30 | #include "vtkTriangle.h" 31 | #include "vtkLine.h" 32 | #include "vtkPlane.h" 33 | #include "vtkMath.h" 34 | #include "vtkCommand.h" 35 | #include "vtkInformation.h" 36 | #include "vtkInformationVector.h" 37 | #include "vtkPointData.h" 38 | #include "vtkStreamingDemandDrivenPipeline.h" 39 | #include "vtkMatrixToLinearTransform.h" 40 | #include "vtkTransform.h" 41 | #include "vtkSmartPointer.h" 42 | #include "vtkCellArray.h" 43 | 44 | vtkCxxRevisionMacro(vtkCollisionDetectionFilter, "$Revision$"); 45 | vtkStandardNewMacro(vtkCollisionDetectionFilter); 46 | 47 | // Constructs with initial 0 values. 48 | vtkCollisionDetectionFilter::vtkCollisionDetectionFilter() 49 | { 50 | vtkDebugMacro(<< "Initializing object"); 51 | 52 | // Ask the superclass to set the number of connections. 53 | this->SetNumberOfInputPorts(2); 54 | this->SetNumberOfInputConnections(0,1); 55 | this->SetNumberOfInputConnections(1,1); 56 | this->SetNumberOfOutputPorts(3); 57 | this->Transform[0] = NULL; 58 | this->Transform[1] = NULL; 59 | this->Matrix[0] = NULL; 60 | this->Matrix[1] = NULL; 61 | this->NumberOfBoxTests = 0; 62 | this->BoxTolerance = 0.0; 63 | this->CellTolerance = 0.0; 64 | this->NumberOfCellsPerNode = 2; 65 | this->tree0 = vtkOBBTree::New(); 66 | this->tree1 = vtkOBBTree::New(); 67 | this->GenerateScalars = 0; 68 | this->CollisionMode = VTK_ALL_CONTACTS; 69 | this->Opacity = 1.0; 70 | } 71 | 72 | // Destroy any allocated memory. 73 | vtkCollisionDetectionFilter::~vtkCollisionDetectionFilter() 74 | { 75 | if (this->tree0 != NULL) 76 | { 77 | this->tree0->Delete(); 78 | } 79 | if (this->tree1 != NULL) 80 | { 81 | this->tree1->Delete(); 82 | } 83 | 84 | if (this->Matrix[0]) 85 | { 86 | this->Matrix[0]->UnRegister(this); 87 | this->Matrix[0] = NULL; 88 | } 89 | if (this->Matrix[1]) 90 | { 91 | this->Matrix[1]->UnRegister(this); 92 | this->Matrix[1] = NULL; 93 | } 94 | if (this->Transform[0]) 95 | { 96 | this->Transform[0]->UnRegister(this); 97 | this->Transform[0] = NULL; 98 | } 99 | if (this->Transform[1]) 100 | { 101 | this->Transform[1]->UnRegister(this); 102 | this->Transform[1] = NULL; 103 | } 104 | 105 | } 106 | 107 | 108 | // Description: 109 | // Set and Get the input data... 110 | void vtkCollisionDetectionFilter::SetInput(int idx, vtkPolyData *input) 111 | { 112 | 113 | if (2 <= idx || idx < 0) 114 | { 115 | vtkErrorMacro(<< "Index " << idx 116 | << " is out of range in SetInput. Only two inputs allowed!"); 117 | } 118 | 119 | // Ask the superclass to connect the input. 120 | this->SetNthInputConnection(idx, 0, input? input->GetProducerPort() : 0); 121 | } 122 | 123 | 124 | 125 | 126 | //---------------------------------------------------------------------------- 127 | vtkPolyData *vtkCollisionDetectionFilter::GetInput(int idx) 128 | { 129 | if (2 <= idx || idx < 0) 130 | { 131 | vtkErrorMacro(<< "Index " << idx 132 | << " is out of range in GetInput. Only two inputs allowed!"); 133 | return NULL; 134 | } 135 | 136 | return vtkPolyData::SafeDownCast( 137 | this->GetExecutive()->GetInputData(idx, 0)); 138 | } 139 | 140 | vtkIdTypeArray *vtkCollisionDetectionFilter::GetContactCells(int i) 141 | { 142 | if (2 <= i || i < 0) 143 | { 144 | vtkErrorMacro(<< "Index " << i 145 | << " is out of range in GetContactCells. There are only two contact cells arrays!"); 146 | return NULL; 147 | } 148 | 149 | return vtkIdTypeArray::SafeDownCast( 150 | this->GetOutput(i)->GetFieldData()->GetArray("ContactCells")); 151 | 152 | } 153 | 154 | void vtkCollisionDetectionFilter::SetTransform(int i, vtkLinearTransform *transform) 155 | { 156 | if (i > 1 || i < 0) 157 | { 158 | vtkErrorMacro(<< "Index " << i 159 | << " is out of range in SetTransform. Only two transforms allowed!"); 160 | } 161 | 162 | if (transform == this->Transform[i]) 163 | { 164 | return; 165 | } 166 | 167 | if(this->Transform[i]) 168 | { 169 | this->Transform[i]->Delete(); 170 | this->Transform[i] = NULL; 171 | } 172 | 173 | if (this->Matrix[i]) 174 | { 175 | this->Matrix[i]->Delete(); 176 | this->Matrix[i] = NULL; 177 | } 178 | 179 | if(transform) 180 | { 181 | this->Transform[i] = transform; 182 | this->Transform[i]->Register(this); 183 | this->Matrix[i] = transform->GetMatrix(); 184 | this->Matrix[i]->Register(this); 185 | } 186 | 187 | this->Modified(); 188 | } 189 | 190 | 191 | 192 | void vtkCollisionDetectionFilter::SetMatrix(int i, vtkMatrix4x4 *matrix) 193 | { 194 | if (i > 1 || i < 0) 195 | { 196 | vtkErrorMacro(<< "Index " << i 197 | << " is out of range in SetMatrix. Only two matrices allowed!"); 198 | } 199 | 200 | if (matrix == this->Matrix[i]) 201 | { 202 | return; 203 | } 204 | 205 | if (this->Transform[i]) 206 | { 207 | this->Transform[i]->Delete(); 208 | this->Transform[i] = NULL; 209 | } 210 | 211 | if(this->Matrix[i]) 212 | { 213 | this->Matrix[i]->Delete(); 214 | this->Matrix[i] = NULL; 215 | } 216 | 217 | vtkDebugMacro(<< "Setting matrix: " << i << " to point to " << matrix << endl); 218 | 219 | if(matrix) 220 | { 221 | this->Matrix[i] = matrix; 222 | matrix->Register(this); 223 | vtkMatrixToLinearTransform *transform = vtkMatrixToLinearTransform::New(); 224 | // Consistent Register and UnRegisters. 225 | transform->Register(this); 226 | transform->Delete(); 227 | transform->SetInput(matrix); 228 | this->Transform[i] = transform; 229 | vtkDebugMacro(<< "Setting Transform " << i << " to points to: " << transform << endl); 230 | } 231 | this->Modified(); 232 | } 233 | 234 | vtkMatrix4x4* vtkCollisionDetectionFilter::GetMatrix(int i) 235 | { 236 | if (this->Transform[i]) 237 | { 238 | this->Transform[i]->Update(); 239 | } 240 | return this->Matrix[i]; 241 | } 242 | 243 | static int ComputeCollisions(vtkOBBNode *nodeA, vtkOBBNode *nodeB, vtkMatrix4x4 *Xform, void *clientdata) 244 | { 245 | // This is hard-coded for triangles but could be easily changed to allow for allow n-sided polygons 246 | int numIdsA, numIdsB; 247 | vtkIdList *IdsA, *IdsB, *pointIdsA, *pointIdsB; 248 | vtkCellArray *cells; 249 | vtkIdType cellPtIds[2]; 250 | vtkIdTypeArray *contactcells1, *contactcells2; 251 | vtkPoints *contactpoints; 252 | IdsA = nodeA->Cells; 253 | IdsB = nodeB->Cells; 254 | numIdsA = IdsA->GetNumberOfIds(); 255 | numIdsB = IdsB->GetNumberOfIds(); 256 | 257 | // clientdata is a pointer to this object... need to cast it as such 258 | vtkCollisionDetectionFilter* self = reinterpret_cast( clientdata ); 259 | 260 | // Turn off debugging here if its on... otherwise there's squawks every update/box test 261 | int DebugWasOn = 0; 262 | int FirstContact = 0; 263 | if (self->GetDebug()) 264 | { 265 | self->DebugOff(); 266 | DebugWasOn = 1; 267 | } 268 | vtkPolyData *inputA = vtkPolyData::SafeDownCast(self->GetInput(0)); 269 | vtkPolyData *inputB = vtkPolyData::SafeDownCast(self->GetInput(1)); 270 | contactcells1 = self->GetContactCells(0); 271 | contactcells2 = self->GetContactCells(1); 272 | contactpoints = self->GetOutput(2)->GetPoints(); 273 | 274 | if (self->GetCollisionMode() == vtkCollisionDetectionFilter::VTK_ALL_CONTACTS) 275 | { 276 | cells = self->GetOutput(2)->GetLines(); 277 | } 278 | else 279 | { 280 | cells = self->GetOutput(2)->GetVerts(); 281 | } 282 | 283 | float Tolerance = self->GetCellTolerance(); 284 | if (self->GetCollisionMode() == vtkCollisionDetectionFilter::VTK_FIRST_CONTACT) 285 | { 286 | FirstContact = 1; 287 | } 288 | 289 | 290 | vtkIdType cellIdA, cellIdB; 291 | 292 | double x1[4], x2[4], xnew[4]; 293 | double ptsA[9], ptsB[9]; 294 | double boundsA[6], boundsB[6]; 295 | vtkIdType i,j,k,m,n,p,v; 296 | double *point, in[4], out[4]; 297 | 298 | // Loop thru the cells/points in IdsA 299 | for (i = 0; i < numIdsA; i++) 300 | { 301 | cellIdA = IdsA->GetId(i); 302 | pointIdsA = inputA->GetCell(cellIdA)->GetPointIds(); 303 | inputA->GetCellBounds(cellIdA, boundsA); 304 | 305 | // Initialize ptsA 306 | // It might speed things up if ptsA and ptsB only had to be an 307 | // array of pointers to the cell vertices, rather than allocating here. 308 | for (j=0; j<3; j++) 309 | { 310 | for (k=0; k<3; k++) 311 | { 312 | ptsA[j*3+k] = inputA->GetPoints()->GetPoint(pointIdsA->GetId(j))[k]; 313 | } 314 | } 315 | 316 | // Loop thru each cell IdsB and test for collision 317 | for (m = 0; m < numIdsB; m++) 318 | { 319 | cellIdB = IdsB->GetId(m); 320 | pointIdsB = inputB->GetCell(cellIdB)->GetPointIds(); 321 | inputB->GetCellBounds(cellIdB, boundsB); 322 | 323 | // Initialize ptsB 324 | for (n=0; n<3; n++) 325 | { 326 | point = inputB->GetPoints()->GetPoint(pointIdsB->GetId(n)); 327 | // transform the vertex 328 | in[0] = point[0]; in[1] = point[1]; in[2] = point[2]; in[3] = 1.0; 329 | Xform->MultiplyPoint( in, out ); 330 | out[0] = out[0]/out[3]; 331 | out[1] = out[1]/out[3]; 332 | out[2] = out[2]/out[3]; 333 | for (p=0; p<3; p++) 334 | { 335 | ptsB[n*3+p] = out[p]; 336 | } 337 | } 338 | 339 | //Calculate the bounds for the xformed cell 340 | boundsB[0] = boundsB[2] = boundsB[4] = VTK_LARGE_FLOAT; 341 | boundsB[1] = boundsB[3] = boundsB[5] = -VTK_LARGE_FLOAT; 342 | for (v=0; v < 9; v=v+3) 343 | { 344 | if (ptsB[v] < boundsB[0]) boundsB[0] = ptsB[v]; 345 | if (ptsB[v] > boundsB[1]) boundsB[1] = ptsB[v]; 346 | if (ptsB[v+1] < boundsB[2]) boundsB[2] = ptsB[v+1]; 347 | if (ptsB[v+1] > boundsB[3]) boundsB[3] = ptsB[v+1]; 348 | if (ptsB[v+2] < boundsB[4]) boundsB[4] = ptsB[v+2]; 349 | if (ptsB[v+2] > boundsB[5]) boundsB[5] = ptsB[v+2]; 350 | } 351 | 352 | // Test for intersection 353 | if (self->IntersectPolygonWithPolygon(3, ptsA, boundsA, 3, ptsB, boundsB, 354 | Tolerance, x1, x2, self->GetCollisionMode())) 355 | { 356 | contactcells1->InsertNextValue(cellIdA); 357 | contactcells2->InsertNextValue(cellIdB); 358 | //transform x back to "world space" 359 | // could speed this up by testing for identity matrix 360 | // and skipping the next transform. 361 | x1[3] = x2[3] = 1.0; 362 | self->GetMatrix(0)->MultiplyPoint(x1,xnew); 363 | xnew[0] = xnew[0]/xnew[3]; 364 | xnew[1] = xnew[1]/xnew[3]; 365 | xnew[2] = xnew[2]/xnew[3]; 366 | cellPtIds[0] = contactpoints->InsertNextPoint(xnew); 367 | if (self->GetCollisionMode() == vtkCollisionDetectionFilter::VTK_ALL_CONTACTS) 368 | { 369 | self->GetMatrix(0)->MultiplyPoint(x2,xnew); 370 | xnew[0] = xnew[0]/xnew[3]; 371 | xnew[1] = xnew[1]/xnew[3]; 372 | xnew[2] = xnew[2]/xnew[3]; 373 | cellPtIds[1] = contactpoints->InsertNextPoint(xnew); 374 | // insert a new line 375 | cells->InsertNextCell(2, cellPtIds); 376 | } 377 | else 378 | { 379 | // insert a new vert 380 | cells->InsertNextCell(1, cellPtIds); 381 | } 382 | 383 | 384 | if (FirstContact) 385 | { 386 | // return the negative of the number of box tests to find first contact 387 | // this will call a halt to the proceedings 388 | if (DebugWasOn) self->DebugOn(); 389 | return (-1 - self->GetNumberOfBoxTests()); 390 | } 391 | } 392 | 393 | } 394 | } 395 | if (DebugWasOn) self->DebugOn(); 396 | return 1; 397 | } 398 | 399 | // Description: 400 | // Perform a collision detection 401 | int vtkCollisionDetectionFilter::RequestData( 402 | vtkInformation *vtkNotUsed(request), 403 | vtkInformationVector **inputVector, 404 | vtkInformationVector *outputVector) 405 | { 406 | // get the info objects 407 | vtkDebugMacro(<< "Beginning execution..."); 408 | 409 | // inputs and outputs 410 | vtkPolyData *input[2]; 411 | vtkPolyData *output[3]; 412 | 413 | // copy inputs to outputs 414 | vtkInformation *inInfo, *outInfo; 415 | for (int i=0; i<2; i++) 416 | { 417 | inInfo = inputVector[i]->GetInformationObject(0); 418 | input[i] = vtkPolyData::SafeDownCast( 419 | inInfo->Get(vtkDataObject::DATA_OBJECT())); 420 | 421 | outInfo = outputVector->GetInformationObject(i); 422 | output[i] = vtkPolyData::SafeDownCast( 423 | outInfo->Get(vtkDataObject::DATA_OBJECT())); 424 | 425 | output[i]->CopyStructure(input[i]); 426 | output[i]->GetPointData()->PassData(input[i]->GetPointData()); 427 | output[i]->GetCellData()->PassData(input[i]->GetCellData()); 428 | output[i]->GetFieldData()->PassData(input[i]->GetFieldData()); 429 | } 430 | 431 | // set up the contacts polydata output on port index 2 432 | outInfo = outputVector->GetInformationObject(2); 433 | output[2] = vtkPolyData::SafeDownCast( 434 | outInfo->Get(vtkDataObject::DATA_OBJECT())); 435 | vtkPoints *contactsPoints = vtkPoints::New(); 436 | output[2]->SetPoints(contactsPoints); 437 | contactsPoints->Delete(); 438 | 439 | if (this->CollisionMode == vtkCollisionDetectionFilter::VTK_ALL_CONTACTS) 440 | {//then create a lines cell array 441 | vtkCellArray *lines = vtkCellArray::New(); 442 | output[2]->SetLines(lines); 443 | lines->Delete(); 444 | } 445 | else 446 | {//else create a verts cell array 447 | vtkCellArray *verts = vtkCellArray::New(); 448 | output[2]->SetVerts(verts); 449 | verts->Delete(); 450 | } 451 | 452 | //Allocate arrays for the contact cells lists 453 | vtkSmartPointer contactcells0 = 454 | vtkSmartPointer::New(); 455 | contactcells0->SetName("ContactCells"); 456 | output[0]->GetFieldData()->AddArray(contactcells0); 457 | 458 | vtkSmartPointer contactcells1 = 459 | vtkSmartPointer::New(); 460 | contactcells1->SetName("ContactCells"); 461 | output[1]->GetFieldData()->AddArray(contactcells1); 462 | 463 | // make sure input is available 464 | if ( ! input[0] ) 465 | { 466 | vtkWarningMacro(<< "Input 1 hasn't been added... can't execute!"); 467 | return 1; 468 | } 469 | 470 | // make sure input is available 471 | if ( ! input[1] ) 472 | { 473 | vtkWarningMacro(<< "Input 2 hasn't been added... can't execute!"); 474 | return 1; 475 | } 476 | 477 | // The transformations... 478 | vtkMatrix4x4 *matrix = vtkMatrix4x4::New(); 479 | vtkMatrix4x4 *tmpMatrix = vtkMatrix4x4::New(); 480 | 481 | if (this->Transform[0] != NULL || this->Transform[1] != NULL) 482 | { 483 | vtkMatrix4x4::Invert(this->Transform[0]->GetMatrix(), tmpMatrix); 484 | // the sequence of multiplication is significant 485 | vtkMatrix4x4::Multiply4x4(tmpMatrix, this->Transform[1]->GetMatrix(), matrix); 486 | } 487 | else 488 | { 489 | vtkWarningMacro(<< "Set two transforms or two matrices"); 490 | return 1; 491 | } 492 | 493 | this->InvokeEvent(vtkCommand::StartEvent, NULL); 494 | 495 | 496 | // rebuild the obb trees... they do their own mtime checking with input data 497 | tree0->SetDataSet(input[0]); 498 | tree0->AutomaticOn(); 499 | tree0->SetNumberOfCellsPerNode(this->NumberOfCellsPerNode); 500 | tree0->BuildLocator(); 501 | 502 | tree1->SetDataSet(input[1]); 503 | tree1->AutomaticOn(); 504 | tree1->SetNumberOfCellsPerNode(this->NumberOfCellsPerNode); 505 | tree1->BuildLocator(); 506 | 507 | // Set the Box Tolerance 508 | tree0->SetTolerance(this->BoxTolerance); 509 | tree1->SetTolerance(this->BoxTolerance); 510 | 511 | 512 | 513 | 514 | // Do the collision detection... 515 | vtkIdType BoxTests = 516 | tree0->IntersectWithOBBTree(tree1, matrix, ComputeCollisions, this); 517 | 518 | matrix->Delete(); 519 | tmpMatrix->Delete(); 520 | 521 | vtkDebugMacro(<< "Collision detection finished"); 522 | this->NumberOfBoxTests = abs(BoxTests); 523 | 524 | // Generate the scalars if needed 525 | if (GenerateScalars) 526 | { 527 | 528 | for (int idx =0; idx < 2; idx++) 529 | { 530 | 531 | vtkUnsignedCharArray *scalars = vtkUnsignedCharArray::New(); 532 | output[idx]->GetCellData()->SetScalars(scalars); 533 | vtkIdType numCells = input[idx]->GetNumberOfCells(); 534 | scalars->SetNumberOfComponents(4); 535 | scalars->SetNumberOfTuples(numCells); 536 | vtkIdTypeArray *contactcells = this->GetContactCells(idx); 537 | vtkIdType numContacts = this->GetNumberOfContacts(); 538 | 539 | // Fill the array with blanks... 540 | // Maybe this should change, to alpha set to Opacity 541 | // regardless if there are contact or not. 542 | float alpha; 543 | if (numContacts > 0) 544 | { 545 | alpha = this->Opacity*255.0; 546 | } 547 | else 548 | { 549 | alpha = 255.0; 550 | } 551 | float blank[4] = {255.0,255.0,255.0,alpha}; 552 | 553 | for (vtkIdType i = 0; i < numCells; i++) 554 | { 555 | scalars->SetTuple(i, blank); 556 | } 557 | 558 | // Now color the intersecting cells 559 | vtkLookupTable *lut = vtkLookupTable::New(); 560 | if (numContacts>0) 561 | { 562 | if (this->CollisionMode == VTK_ALL_CONTACTS) 563 | { 564 | lut->SetTableRange(0, numContacts-1); 565 | lut->SetNumberOfTableValues(numContacts); 566 | } 567 | else // VTK_FIRST_CONTACT 568 | { 569 | lut->SetTableRange(0, 1); 570 | lut->SetNumberOfTableValues(numContacts+1); 571 | } 572 | lut->Build(); 573 | } 574 | double *RGBA; 575 | float RGB[4]; 576 | 577 | for (vtkIdType id, i = 0; i < numContacts; i++) 578 | { 579 | id = contactcells->GetValue(i); 580 | RGBA = lut->GetTableValue(i); 581 | RGB[0] = 255.0*RGBA[0]; 582 | RGB[1] = 255.0*RGBA[1]; 583 | RGB[2] = 255.0*RGBA[2]; 584 | RGB[3] = 255.0; 585 | scalars->SetTuple(id, RGB); 586 | } 587 | 588 | lut->Delete(); 589 | scalars->Delete(); 590 | vtkDebugMacro(<< "Created scalars on output " << idx); 591 | } 592 | } 593 | 594 | this->InvokeEvent(vtkCommand::EndEvent, NULL); 595 | 596 | return 1; 597 | 598 | } 599 | 600 | // Method intersects two polygons. You must supply the number of points and 601 | // point coordinates (npts, *pts) and the bounding box (bounds) of the two 602 | // polygons. Also supply a tolerance squared for controlling 603 | // error. The method returns 1 if there is an intersection, and 0 if 604 | // not. A single point of intersection x[3] is also returned if there 605 | // is an intersection. 606 | int vtkCollisionDetectionFilter::IntersectPolygonWithPolygon(int npts, double *pts, double bounds[6], 607 | int npts2, double *pts2, 608 | double bounds2[6], double tol2, 609 | double x1[3], double x2[3], int CollisionMode) 610 | { 611 | double n[3], n2[3], coords[3]; 612 | int i, j; 613 | double *p1, *p2, *q1, ray[3], ray2[3]; 614 | double t,u,v; 615 | double *x[2]; 616 | int Num = 0; 617 | x[0] = x1; 618 | x[1] = x2; 619 | 620 | // Intersect each edge of first polygon against second 621 | // 622 | vtkPolygon::ComputeNormal(npts2, pts2, n2); 623 | vtkPolygon::ComputeNormal(npts, pts, n); 624 | 625 | int parallel_edges=0; 626 | for (i=0; i3 645 | && vtkPolygon::PointInPolygon(x[Num],npts2,pts2,bounds2,n2) 646 | == 1)) 647 | { 648 | Num++; 649 | if (CollisionMode != vtkCollisionDetectionFilter::VTK_ALL_CONTACTS || 650 | Num == 2) 651 | { 652 | return 1; 653 | } 654 | } 655 | } 656 | else 657 | { 658 | // cout << "Test for overlapping" << endl; 659 | // test to see if cells are coplanar and overlapping... 660 | parallel_edges++; 661 | if (parallel_edges >1) // cells are parallel then... 662 | { 663 | //cout << "cells are parallel" << endl; 664 | // test to see if they are coplanar 665 | q1 = pts2; 666 | for (j=0; j<3; j++) 667 | { 668 | ray2[j] = p1[j] - q1[j]; 669 | } 670 | if (vtkMath::Dot(n,ray2) == 0.0) // cells are coplanar 671 | { 672 | //cout << "cells are coplanar" << endl; 673 | // test to see if coplanar cells overlap 674 | // ie, if one of the tris has a vertex in the other 675 | for (int ii=0; ii < npts; ii++) 676 | { 677 | for (int jj=0; jj < npts2; jj++) 678 | { 679 | if (vtkLine::Intersection(pts+3*ii,pts+3*((ii+1)%npts), 680 | pts2+3*jj,pts2+3*((jj+1)%npts2),u,v) == 2) 681 | { 682 | //cout << "Found an overlapping one!!!" << endl; 683 | for (int k=0;k<3;k++) 684 | { 685 | x[Num][k] = pts[k+3*ii] + u*(pts[k+(3*((ii+1)%npts))]-pts[k+3*ii]); 686 | } 687 | Num++; 688 | if (CollisionMode != vtkCollisionDetectionFilter::VTK_ALL_CONTACTS || 689 | Num == 2) 690 | { 691 | return 1; 692 | } 693 | } 694 | } 695 | } 696 | 697 | } // end if cells are coplanar 698 | } // end if cells are parallel 699 | } // end else 700 | } 701 | 702 | 703 | // Intersect each edge of second polygon against first 704 | // 705 | 706 | for (i=0; i3 && vtkPolygon::PointInPolygon(x[Num],npts,pts,bounds,n) 725 | == 1)) 726 | { 727 | Num++; 728 | if (CollisionMode != vtkCollisionDetectionFilter::VTK_ALL_CONTACTS || 729 | Num == 2) 730 | { 731 | return 1; 732 | } 733 | } 734 | } 735 | } 736 | 737 | //if we get through to here then there's no collision. 738 | return 0; 739 | } 740 | 741 | 742 | // Description: 743 | // Make sure filter executes if transform are changed 744 | unsigned long vtkCollisionDetectionFilter::GetMTime() 745 | { 746 | unsigned long mTime=this->MTime.GetMTime(); 747 | unsigned long transMTime, matrixMTime; 748 | 749 | if ( this->Transform[0] ) 750 | { 751 | transMTime = this->Transform[0]->GetMTime(); 752 | mTime = ( transMTime > mTime ? transMTime : mTime ); 753 | } 754 | 755 | if ( this->Transform[1] ) 756 | { 757 | transMTime = this->Transform[1]->GetMTime(); 758 | mTime = ( transMTime > mTime ? transMTime : mTime ); 759 | } 760 | 761 | if ( this->Matrix[0] ) 762 | { 763 | matrixMTime = this->Matrix[0]->GetMTime(); 764 | mTime = ( matrixMTime > mTime ? matrixMTime : mTime ); 765 | } 766 | 767 | if ( this->Matrix[1] ) 768 | { 769 | matrixMTime = this->Matrix[1]->GetMTime(); 770 | mTime = ( matrixMTime > mTime ? matrixMTime : mTime ); 771 | } 772 | 773 | return mTime; 774 | } 775 | 776 | 777 | void vtkCollisionDetectionFilter::PrintSelf(ostream& os, vtkIndent indent) 778 | { 779 | this->Superclass::PrintSelf(os,indent); 780 | 781 | os << indent << "Box Tolerance: " << this->BoxTolerance << "\n"; 782 | os << indent << "Cell Tolerance: " << this->CellTolerance << "\n"; 783 | os << indent << "Number of cells per Node: " << this->NumberOfCellsPerNode << "\n"; 784 | 785 | } 786 | --------------------------------------------------------------------------------