Decimation parameters, island removal optional

Former-commit-id: e0c2b16a66
pull/1161/head
Piero Toffanin 2018-06-12 11:56:17 -04:00
rodzic 38325a5d2c
commit 4d13d1a2d4
3 zmienionych plików z 51 dodań i 16 usunięć

Wyświetl plik

@ -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 ()

Wyświetl plik

@ -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})

Wyświetl plik

@ -5,22 +5,24 @@
#include <vtkSmartPointer.h>
#include <vtkPLYReader.h>
#include <vtkPLYWriter.h>
#include <vtkAlgorithmOutput.h>
#include <vtkQuadricDecimation.h>
#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 << " <input polygon mesh>" << std::endl
<< "\t -" << OutputFile.name << " <output polygon mesh>" << std::endl
<< "\t [-" << DecimateMesh.name << " <target number of polygons>]" << 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<vtkPLYReader> reader =
vtkSmartPointer<vtkPLYReader>::New();
reader->SetFileName ( InputFile.value );
reader->Update();
vtkSmartPointer<vtkPolyDataConnectivityFilter> connectivityFilter =
vtkPolyData *nextOutput = reader->GetOutput();
vtkSmartPointer<vtkPolyDataConnectivityFilter> connectivityFilter =
vtkSmartPointer<vtkPolyDataConnectivityFilter>::New();
connectivityFilter->SetInputConnection(reader->GetOutputPort());
connectivityFilter->SetExtractionModeToLargestRegion();
connectivityFilter->SetExtractionModeToLargestRegion();
vtkSmartPointer<vtkQuadricDecimation> decimationFilter =
vtkSmartPointer<vtkQuadricDecimation>::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<double>(DecimateMesh.value) / static_cast<double>(nextOutput->GetNumberOfPolys()));
decimationFilter->SetInputData(nextOutput);
decimationFilter->Update();
nextOutput = decimationFilter->GetOutput();
}else{
logWriter("Skipping decimation\n");
}
}
logWriter("Saving cleaned mesh to file... \n");
vtkSmartPointer<vtkPLYWriter> plyWriter =
vtkSmartPointer<vtkPLYWriter>::New();
plyWriter->SetFileName(OutputFile.value);
plyWriter->SetInputConnection(connectivityFilter->GetOutputPort());
plyWriter->SetFileTypeToBinary();
plyWriter->SetInputData(nextOutput);
plyWriter->Write();
logWriter("OK\n");