Skip to content

Commit

Permalink
Added jmesh
Browse files Browse the repository at this point in the history
  • Loading branch information
pierotofy committed Feb 13, 2022
1 parent af2f4a7 commit bcf69b3
Show file tree
Hide file tree
Showing 45 changed files with 11,438 additions and 8 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,12 @@ endif()
# Add source directory
aux_source_directory("./src" SRC_LIST)

add_subdirectory("vendor/jmeshlib")
include_directories("vendor/jmeshlib/include")

# Add exectuteable
add_executable(${PROJECT_NAME} ${SRC_LIST})

target_link_libraries(${PROJECT_NAME} ${GDAL_LIBRARY})
target_link_libraries(${PROJECT_NAME} ${GDAL_LIBRARY} jmeshlib)

install(TARGETS ${PROJECT_NAME} RUNTIME DESTINATION bin)
50 changes: 43 additions & 7 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ along with dem2mesh. If not, see <https://www.gnu.org/licenses/>.
#include "CmdLineParser.h"
#include "Logger.h"
#include "Simplify.h"
#include "tin.h"

#include "gdal_priv.h"
#include "cpl_conv.h" // for CPLMalloc()
Expand Down Expand Up @@ -76,13 +77,16 @@ cmdLineParameter< int >
Aggressiveness ( "aggressiveness" ) ,
BandNum ( "bandNum" ) ,
MaxConcurrency ( "maxConcurrency" );
cmdLineParameter< float >
EdgeSwapThreshold ( "edgeSwapThreshold" );
cmdLineReadable
Rtc ( "rtc" ),
Verbose( "verbose" );

cmdLineReadable* params[] = {
&InputFile , &OutputFile ,
&MaxVertexCount , &MaxTileLength, &Aggressiveness, &BandNum, &MaxConcurrency,
&EdgeSwapThreshold,
&Rtc, &Verbose ,
NULL
};
Expand All @@ -96,6 +100,7 @@ void help(char *ex){
<< "\t [-" << Aggressiveness.name << " <simplification aggressiveness factor. Higher values simplify the mesh more aggressively but can decrease the fidelity of the mesh. ([1-10] Default: 5)]" << std::endl
<< "\t [-" << BandNum.name << " <Band number> (Default: 1)]" << std::endl
<< "\t [-" << MaxConcurrency.name << " <threads> (Default: all cpus)]" << std::endl
<< "\t [-" << EdgeSwapThreshold.name << " <dot product threshold (between 0-1) to perform edge collapses. Performing edge collapses can violate the 2.5D constraints, but leads to better triangles for vertical structures> (Default: disabled)]" << std::endl
<< "\t [-" << Rtc.name << "]" << std::endl
<< "\t [-" << Verbose.name << "]" << std::endl;
exit(EXIT_FAILURE);
Expand Down Expand Up @@ -196,6 +201,40 @@ void writeBin(const std::string &filename, int blockWidth, int blockHeight, int
}


void saveFinal(const std::string &filename, int thread, float edgeSwapThreshold){
if (edgeSwapThreshold == -1.0){
logWriter("Writing to file... ");
writePly(filename, thread);
logWriter(" done!\n");
}else{
// Before saving to PLY, we perform edge collapses
JMesh::init();
Triangulation tin;

unsigned long nv = Simplify::vertices[thread]->size();

for(Simplify::Vertex &v : *Simplify::vertices[thread]){
tin.V.appendTail(new Vertex(v.p.x,v.p.y,v.p.z));
}

Vertex *v;
Node *n;
int i = 0;
ExtVertex **var = (ExtVertex **)malloc(sizeof(ExtVertex *)*nv);

TIN_FOREACHVERTEX(v, n) var[i++] = new ExtVertex(v);

for(Simplify::Triangle &t : *Simplify::triangles[thread]){
tin.CreateIndexedTriangle(var, t.v[0], t.v[1], t.v[2]);
}

tin.eulerUpdate();

tin.saveOBJ("/data/drone/brighton2/odm_meshing/tmp/out.obj");
logWriter("SAVED OBJ!\n");
}
}

// Keep track of edge points's vertex IDs
// During the merge step we need to replace
// duplicate points with existing point's vertex IDs
Expand Down Expand Up @@ -333,6 +372,7 @@ int main(int argc, char **argv) {
if ( !BandNum.set ) BandNum.value = 1;
if ( !MaxConcurrency.set ) MaxConcurrency.value = omp_get_max_threads();
if ( MaxConcurrency.value == 0 ) MaxConcurrency.value = 1;
if ( !EdgeSwapThreshold.set ) EdgeSwapThreshold.value = -1.0;

Aggressiveness.value = std::min(10, std::max(1, Aggressiveness.value));
logWriter.verbose = Verbose.set;
Expand Down Expand Up @@ -484,16 +524,14 @@ int main(int argc, char **argv) {
if (qtreeLevels == 0){
transform(extent, t);
logWriter("Single quad tree level, saving to PLY\n");
logWriter("Writing to file...");
writePly(OutputFile.value, t);
saveFinal(OutputFile.value, t, EdgeSwapThreshold.value);
}else{
logWriter("Writing to binary file...");
std::stringstream ss;
ss << OutputFile.value << "." << blockX << "-" << blockY << ".bin";
writeBin(ss.str(), blockSizeX + blockXPad, blockSizeY + blockYPad, t);
logWriter(" done!\n");
}

logWriter(" done!\n");
}
}

Expand Down Expand Up @@ -531,9 +569,7 @@ int main(int argc, char **argv) {
int target_count = std::min(MaxVertexCount.value * 2, static_cast<int>(Simplify::triangles[0]->size()));
simplify(target_count, 0);
transform(extent, 0);
logWriter("Writing to file... ");
writePly(OutputFile.value, 0);
logWriter(" done!\n");
saveFinal(OutputFile.value, 0, EdgeSwapThreshold.value);
}

Simplify::cleanup();
Expand Down
49 changes: 49 additions & 0 deletions vendor/jmeshlib/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
cmake_minimum_required(VERSION 3.1)
project(jmeshlib)

set (CMAKE_CXX_STANDARD 11)

include_directories(./include)

if (NOT MSVC)
add_compile_options(-fpermissive)
endif()

set(HEADERS
./include/binTree.h
./include/clusterGraph.h
./include/dijkstraGraph.h
./include/edge.h
./include/graph.h
./include/heap.h
./include/j_mesh.h
./include/jmesh.h
./include/jqsort.h
./include/list.h
./include/matrix.h
./include/point.h
./include/tin.h
./include/triangle.h
./include/vertex.h
)

set(SOURCES
./src/MESH_STRUCTURE/io.cpp
./src/MESH_STRUCTURE/point.cpp
./src/MESH_STRUCTURE/tin.cpp
./src/MESH_STRUCTURE/triangle.cpp
./src/MESH_STRUCTURE/vertex.cpp
./src/MESH_STRUCTURE/edge.cpp
./src/MESH_STRUCTURE/checkAndRepair.cpp
./src/JMESH/jmesh.cpp
./src/PRIMITIVES/dijkstraGraph.cpp
./src/PRIMITIVES/graph.cpp
./src/PRIMITIVES/list.cpp
./src/PRIMITIVES/matrix.cpp
./src/PRIMITIVES/binTree.cpp
./src/PRIMITIVES/clusterGraph.cpp
./src/PRIMITIVES/jqsort.cpp
./src/PRIMITIVES/heap.cpp
)

add_library(jmeshlib STATIC ${SOURCES} ${HEADERS})
25 changes: 25 additions & 0 deletions vendor/jmeshlib/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
include makeconf

SOURCEDIR = src
TESTDIR = test

#-------------------- RULES --------------------------------------

# Always remake everything if make is called from this top-level directory

all: clean depend
$(MAKE) -C $(SOURCEDIR) lib
$(MAKE) -C $(TESTDIR)

distclean: clean
$(RM) -f lib/libjmesh.a

clean:
$(MAKE) -C $(SOURCEDIR) clean
$(MAKE) -C $(TESTDIR) clean

depend:
$(MAKE) -C $(SOURCEDIR) depend

backup :
$(MAKE) -C $(SOURCEDIR) backup
93 changes: 93 additions & 0 deletions vendor/jmeshlib/README.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
----------------------------
JMeshLib - Version 1.2
----------------------------

by Marco Attene

Consiglio Nazionale delle Ricerche
Istituto di Matematica Applicata e Tecnologie Informatiche
Sezione di Genova
IMATI-GE / CNR

JMeshLib provides a framework to work with manifold triangle meshes.
It implements an edge-based data structure with all its fundamental
functionalities (i.e., file I/O, mesh construction/destruction, traversal).
It is written in C++ and includes support for reading and writing the
following file formats:
OFF (http://shape.cs.princeton.edu/benchmark/documentation/off_format.html)
PLY (http://www.cs.unc.edu/~geom/Powerplant/Ply.doc)
STL (http://www.sdsc.edu/tmf/Stl-specs/stl.html)
VER-TRI (proprietary format used at IMATI-GE / CNR)
and partially:
IV 2.1, VRML 1.0, VRML 2.0, OBJ.

In contrast to other generic libraries dealing with surface meshes,
JMeshLib includes tools to automatically fix the most common problems
present in surface meshes coming from laser scanning (conversion to
oriented manifold, topological noise detection, hole filling, removal
of degenerate faces, ...) through a clear and easy-to-learn C++ API.

This package provides pre-compiled static libraries Windows only (lib/jmesh.lib).
For Linux you must compile the source tree yourself.

See the comments within the source files for details or use doxygen to
produce documentation in a more readable format.
The file "tin.h" is a good starting point.

-------------------
System Rrequirements
--------------------

JMeshLib v1.0 has been extensively tested on 32 bit PCs running either:
- ELF Linux with standard development tools (gcc/g++)
- Windows OS with MSVC 8.0 (Visual C++ 2005)

From version 1.1 it should compile and work properly on 64-bit Linux
machines too. Uncomment the proper line in the 'makeconf' to create
64-bit-enabled binaries.

-------------------
Building the tree
-------------------

On WINDOWS: double-click on minJMeshLib.vcproj and press F7.
On Linux: type 'make' on the command line.

On Linux systems you need the command 'makedepend'. If you
don't have it installed on your system, you may need to
download and install the 'imake' package.

-------------------
Using the library
-------------------

On WINDOWS:
Add the path to jmesh's include dir to your project's include path
AND
add the path to jmesh.lib to your linker's command line

On Linux:
Add the path to jmesh's include dir to your project's include path
AND
add the path to jmesh.a to your linker's command line

---------
Copyright
---------

JMeshLib is

Copyright(C) 2006-2011: IMATI-GE / CNR

All rights reserved.

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
for more details.
54 changes: 54 additions & 0 deletions vendor/jmeshlib/changes.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
From 1.1 to 1.2

- dijkstraGraph
- added methods getNodes() and getNumNodes()

----------------------------------------------------------------------

From 1.0 to 1.1

- SymMatrix3x3
- added == and != operators
- added method 'determinant'
- added = operator
- added trace method
- added /= operator
- added lrMultiply for different vectors

- Matrix3x3
- added constructor from vector product
- added lrMultiply for different vectors
- added = operator
- added /= operator
- added transpose

- SymMatrix4x4
- added == and != operators

- List
- Added method 'popTail()'
- Corrected List::joinTailList(l) (buggy when l was empty)
- removeNode now returns the index of the removed element
- Added method 'getNode'

- Triangulation
- Clone constructor does no longer destroy info fields
- Clone constructor allows to clone info fiels too (setting non-default second par)
- CreateEdge modified. e0 pointer for vertices now points to new edge after creation.
- CheckConnectivity does no longer exit in case of error. Now it returns the error string.

- I/O
- Updates for 64bit systems (to be checked carefully !)
- Small bug-fix in ply loader

- selectConnectedComponent and selectBoundaryTriangles return the # of selected tris
- growSelection returns the # of newly selected tris

- Point.cpp
- getAngle() does no longer exit with error. Warning + return -1 now.

- splitTriangle
- Bug-fix: when splitEdge was invoked for robustness the method crashed

- JMesh
- added 'quiet' field to prevent message reporting
Loading

0 comments on commit bcf69b3

Please sign in to comment.