kopia lustrzana https://github.com/OpenDroneMap/ODM
rodzic
38325a5d2c
commit
4d13d1a2d4
|
@ -9,6 +9,7 @@ add_subdirectory(odm_georef)
|
||||||
add_subdirectory(odm_meshing)
|
add_subdirectory(odm_meshing)
|
||||||
add_subdirectory(odm_orthophoto)
|
add_subdirectory(odm_orthophoto)
|
||||||
add_subdirectory(odm_25dmeshing)
|
add_subdirectory(odm_25dmeshing)
|
||||||
|
add_subdirectory(odm_cleanmesh)
|
||||||
if (ODM_BUILD_SLAM)
|
if (ODM_BUILD_SLAM)
|
||||||
add_subdirectory(odm_slam)
|
add_subdirectory(odm_slam)
|
||||||
endif ()
|
endif ()
|
||||||
|
|
|
@ -4,12 +4,10 @@ cmake_minimum_required(VERSION 2.8)
|
||||||
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR})
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR})
|
||||||
|
|
||||||
set (CMAKE_CXX_STANDARD 11)
|
set (CMAKE_CXX_STANDARD 11)
|
||||||
#set(VTK_DIR "/data/packages/VTK-7.1.1-build")
|
|
||||||
find_package(VTK REQUIRED)
|
find_package(VTK REQUIRED)
|
||||||
include(${VTK_USE_FILE})
|
include(${VTK_USE_FILE})
|
||||||
|
|
||||||
# Add compiler options.
|
# Add compiler options.
|
||||||
#add_definitions(-Wall -Wextra -O0 -g3)
|
|
||||||
add_definitions(-Wall -Wextra)
|
add_definitions(-Wall -Wextra)
|
||||||
|
|
||||||
# Add source directory
|
# Add source directory
|
||||||
|
@ -18,4 +16,4 @@ aux_source_directory("./src" SRC_LIST)
|
||||||
# Add exectuteable
|
# Add exectuteable
|
||||||
add_executable(${PROJECT_NAME} ${SRC_LIST})
|
add_executable(${PROJECT_NAME} ${SRC_LIST})
|
||||||
|
|
||||||
target_link_libraries(odm_cleanmesh ${VTK_LIBRARIES})
|
target_link_libraries(${PROJECT_NAME} ${VTK_LIBRARIES})
|
||||||
|
|
|
@ -5,22 +5,24 @@
|
||||||
#include <vtkSmartPointer.h>
|
#include <vtkSmartPointer.h>
|
||||||
#include <vtkPLYReader.h>
|
#include <vtkPLYReader.h>
|
||||||
#include <vtkPLYWriter.h>
|
#include <vtkPLYWriter.h>
|
||||||
|
#include <vtkAlgorithmOutput.h>
|
||||||
|
#include <vtkQuadricDecimation.h>
|
||||||
#include "CmdLineParser.h"
|
#include "CmdLineParser.h"
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
|
||||||
#define IS_BIG_ENDIAN (*(uint16_t *)"\0\xff" < 0x100)
|
|
||||||
|
|
||||||
Logger logWriter;
|
Logger logWriter;
|
||||||
|
|
||||||
cmdLineParameter< char* >
|
cmdLineParameter< char* >
|
||||||
InputFile( "inputFile" ) ,
|
InputFile( "inputFile" ) ,
|
||||||
OutputFile( "outputFile" );
|
OutputFile( "outputFile" );
|
||||||
|
cmdLineParameter< int >
|
||||||
|
DecimateMesh( "decimateMesh" );
|
||||||
cmdLineReadable
|
cmdLineReadable
|
||||||
|
RemoveIslands( "removeIslands" ) ,
|
||||||
Verbose( "verbose" );
|
Verbose( "verbose" );
|
||||||
|
|
||||||
cmdLineReadable* params[] =
|
cmdLineReadable* params[] = {
|
||||||
{
|
&InputFile , &OutputFile , &DecimateMesh, &RemoveIslands, &Verbose ,
|
||||||
&InputFile , &OutputFile , &Verbose ,
|
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -33,12 +35,15 @@ void help(char *ex){
|
||||||
std::cout << "Usage: " << ex << std::endl
|
std::cout << "Usage: " << ex << std::endl
|
||||||
<< "\t -" << InputFile.name << " <input polygon mesh>" << std::endl
|
<< "\t -" << InputFile.name << " <input polygon mesh>" << std::endl
|
||||||
<< "\t -" << OutputFile.name << " <output 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;
|
<< "\t [-" << Verbose.name << "]" << std::endl;
|
||||||
exit(EXIT_FAILURE);
|
exit(EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void logParams(){
|
void logArgs(cmdLineReadable* params[], Logger& logWriter){
|
||||||
logWriter("Running with parameters:\n");
|
logWriter("Running with parameters:\n");
|
||||||
char str[1024];
|
char str[1024];
|
||||||
for( int i=0 ; params[i] ; i++ ){
|
for( int i=0 ; params[i] ; i++ ){
|
||||||
|
@ -53,28 +58,59 @@ void logParams(){
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
cmdLineParse( argc-1 , &argv[1] , params );
|
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.verbose = Verbose.set;
|
||||||
logWriter.outputFile = "odm_cleanmesh_log.txt";
|
logWriter.outputFile = "odm_cleanmesh_log.txt";
|
||||||
logParams();
|
logArgs(params, logWriter);
|
||||||
|
|
||||||
vtkSmartPointer<vtkPLYReader> reader =
|
vtkSmartPointer<vtkPLYReader> reader =
|
||||||
vtkSmartPointer<vtkPLYReader>::New();
|
vtkSmartPointer<vtkPLYReader>::New();
|
||||||
reader->SetFileName ( InputFile.value );
|
reader->SetFileName ( InputFile.value );
|
||||||
|
reader->Update();
|
||||||
|
|
||||||
vtkSmartPointer<vtkPolyDataConnectivityFilter> connectivityFilter =
|
vtkPolyData *nextOutput = reader->GetOutput();
|
||||||
|
|
||||||
|
vtkSmartPointer<vtkPolyDataConnectivityFilter> connectivityFilter =
|
||||||
vtkSmartPointer<vtkPolyDataConnectivityFilter>::New();
|
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");
|
logWriter("Saving cleaned mesh to file... \n");
|
||||||
|
|
||||||
vtkSmartPointer<vtkPLYWriter> plyWriter =
|
vtkSmartPointer<vtkPLYWriter> plyWriter =
|
||||||
vtkSmartPointer<vtkPLYWriter>::New();
|
vtkSmartPointer<vtkPLYWriter>::New();
|
||||||
plyWriter->SetFileName(OutputFile.value);
|
plyWriter->SetFileName(OutputFile.value);
|
||||||
plyWriter->SetInputConnection(connectivityFilter->GetOutputPort());
|
|
||||||
plyWriter->SetFileTypeToBinary();
|
plyWriter->SetFileTypeToBinary();
|
||||||
|
plyWriter->SetInputData(nextOutput);
|
||||||
plyWriter->Write();
|
plyWriter->Write();
|
||||||
|
|
||||||
logWriter("OK\n");
|
logWriter("OK\n");
|
||||||
|
|
Ładowanie…
Reference in New Issue