diff --git a/modules/CMakeLists.txt b/modules/CMakeLists.txt index 5786f461..9f71d7dd 100644 --- a/modules/CMakeLists.txt +++ b/modules/CMakeLists.txt @@ -9,6 +9,7 @@ add_subdirectory(odm_georef) add_subdirectory(odm_meshing) add_subdirectory(odm_orthophoto) add_subdirectory(odm_25dmeshing) +add_subdirectory(odm_cleanmesh) if (ODM_BUILD_SLAM) add_subdirectory(odm_slam) endif () diff --git a/modules/odm_cleanmesh/CMakeLists.txt b/modules/odm_cleanmesh/CMakeLists.txt index 52da4a2e..af97ab51 100644 --- a/modules/odm_cleanmesh/CMakeLists.txt +++ b/modules/odm_cleanmesh/CMakeLists.txt @@ -4,12 +4,10 @@ cmake_minimum_required(VERSION 2.8) set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}) set (CMAKE_CXX_STANDARD 11) -#set(VTK_DIR "/data/packages/VTK-7.1.1-build") find_package(VTK REQUIRED) include(${VTK_USE_FILE}) # Add compiler options. -#add_definitions(-Wall -Wextra -O0 -g3) add_definitions(-Wall -Wextra) # Add source directory @@ -18,4 +16,4 @@ aux_source_directory("./src" SRC_LIST) # Add exectuteable add_executable(${PROJECT_NAME} ${SRC_LIST}) -target_link_libraries(odm_cleanmesh ${VTK_LIBRARIES}) +target_link_libraries(${PROJECT_NAME} ${VTK_LIBRARIES}) diff --git a/modules/odm_cleanmesh/src/main.cpp b/modules/odm_cleanmesh/src/main.cpp index 72419f83..f9ecee76 100644 --- a/modules/odm_cleanmesh/src/main.cpp +++ b/modules/odm_cleanmesh/src/main.cpp @@ -5,22 +5,24 @@ #include #include #include +#include +#include #include "CmdLineParser.h" #include "Logger.h" -#define IS_BIG_ENDIAN (*(uint16_t *)"\0\xff" < 0x100) - Logger logWriter; cmdLineParameter< char* > InputFile( "inputFile" ) , - OutputFile( "outputFile" ); + OutputFile( "outputFile" ); +cmdLineParameter< int > + DecimateMesh( "decimateMesh" ); cmdLineReadable + RemoveIslands( "removeIslands" ) , Verbose( "verbose" ); -cmdLineReadable* params[] = -{ - &InputFile , &OutputFile , &Verbose , +cmdLineReadable* params[] = { + &InputFile , &OutputFile , &DecimateMesh, &RemoveIslands, &Verbose , NULL }; @@ -33,12 +35,15 @@ void help(char *ex){ std::cout << "Usage: " << ex << std::endl << "\t -" << InputFile.name << " " << std::endl << "\t -" << OutputFile.name << " " << std::endl + << "\t [-" << DecimateMesh.name << " ]" << std::endl + << "\t [-" << RemoveIslands.name << "]" << std::endl + << "\t [-" << Verbose.name << "]" << std::endl; exit(EXIT_FAILURE); } -void logParams(){ +void logArgs(cmdLineReadable* params[], Logger& logWriter){ logWriter("Running with parameters:\n"); char str[1024]; for( int i=0 ; params[i] ; i++ ){ @@ -53,28 +58,59 @@ void logParams(){ int main(int argc, char **argv) { cmdLineParse( argc-1 , &argv[1] , params ); - if( !InputFile.set || !OutputFile.set ) help( argv[0] ); + if( !InputFile.set || !OutputFile.set ) help(argv[0]); + if( !RemoveIslands.set && !DecimateMesh.set ) help (argv[0]); + logWriter.verbose = Verbose.set; logWriter.outputFile = "odm_cleanmesh_log.txt"; - logParams(); + logArgs(params, logWriter); vtkSmartPointer reader = vtkSmartPointer::New(); reader->SetFileName ( InputFile.value ); + reader->Update(); - vtkSmartPointer connectivityFilter = + vtkPolyData *nextOutput = reader->GetOutput(); + + vtkSmartPointer connectivityFilter = vtkSmartPointer::New(); - connectivityFilter->SetInputConnection(reader->GetOutputPort()); - connectivityFilter->SetExtractionModeToLargestRegion(); + connectivityFilter->SetExtractionModeToLargestRegion(); + + vtkSmartPointer decimationFilter = + vtkSmartPointer::New(); + + if (RemoveIslands.set){ + logWriter("Removing islands\n"); + connectivityFilter->SetInputData(nextOutput); + connectivityFilter->Update(); + nextOutput = connectivityFilter->GetOutput(); + } + + if (DecimateMesh.set){ + logWriter("Decimating mesh\n"); + + int vertexCount = nextOutput->GetNumberOfPoints(); + logWriter("Current vertex count: %d\n", vertexCount); + logWriter("Wanted vertex count: %d\n", DecimateMesh.value); + + if (vertexCount > DecimateMesh.value){ + decimationFilter->SetTargetReduction(static_cast(DecimateMesh.value) / static_cast(nextOutput->GetNumberOfPolys())); + decimationFilter->SetInputData(nextOutput); + decimationFilter->Update(); + nextOutput = decimationFilter->GetOutput(); + }else{ + logWriter("Skipping decimation\n"); + } + } logWriter("Saving cleaned mesh to file... \n"); vtkSmartPointer plyWriter = vtkSmartPointer::New(); plyWriter->SetFileName(OutputFile.value); - plyWriter->SetInputConnection(connectivityFilter->GetOutputPort()); plyWriter->SetFileTypeToBinary(); + plyWriter->SetInputData(nextOutput); plyWriter->Write(); logWriter("OK\n");