From 25ff7685d1e49fe6364f1c7415125ffe37acd27f Mon Sep 17 00:00:00 2001 From: Priscille De Dumast Date: Thu, 3 Nov 2016 15:32:48 -0400 Subject: [PATCH 1/5] ENH: Add SEMMacroBuild --- src/CMakeLists.txt | 4 +++ wrapper/CMakeLists.txt | 21 +++++++++++++ wrapper/SurfRemesh.cxx | 50 +++++++++++++++++++++++++++++ wrapper/SurfRemesh.xml | 71 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 146 insertions(+) create mode 100644 src/CMakeLists.txt create mode 100644 wrapper/CMakeLists.txt create mode 100644 wrapper/SurfRemesh.cxx create mode 100644 wrapper/SurfRemesh.xml diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000..c03ab18 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,4 @@ + +add_library(Remesh_SOURCES + STATIC + SurfaceRemeshing.cpp) \ No newline at end of file diff --git a/wrapper/CMakeLists.txt b/wrapper/CMakeLists.txt new file mode 100644 index 0000000..1395e97 --- /dev/null +++ b/wrapper/CMakeLists.txt @@ -0,0 +1,21 @@ +if(UNIX) + set( INSTALL_RUNTIME_DESTINATION bin) + set( INSTALL_LIBRARY_DESTINATION lib) + set( INSTALL_ARCHIVE_DESTINATION lib) +endif() + + +SEMMacroBuildCLI( + NAME SurfRemesh + EXECUTABLE_ONLY + TARGET_LIBRARIES ${LAPACK_LIBRARIES} Mesh Remesh_SOURCES + INCLUDE_DIRECTORIES ${CMAKE_CURRENT_SOURCE_DIR} + RUNTIME_OUTPUT_DIRECTORY ${CMAKE_RUNTIME_OUTPUT_DIRECTORY} + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_LIBRARY_OUTPUT_DIRECTORY} + ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_ARCHIVE_OUTPUT_DIRECTORY} + INSTALL_RUNTIME_DESTINATION ${INSTALL_RUNTIME_DESTINATION} + INSTALL_LIBRARY_DESTINATION ${INSTALL_LIBRARY_DESTINATION} + INSTALL_ARCHIVE_DESTINATION ${INSTALL_ARCHIVE_DESTINATION} +) + +install(TARGETS SurfRemesh RUNTIME DESTINATION ${INSTALL_RUNTIME_DESTINATION}) \ No newline at end of file diff --git a/wrapper/SurfRemesh.cxx b/wrapper/SurfRemesh.cxx new file mode 100644 index 0000000..a38061f --- /dev/null +++ b/wrapper/SurfRemesh.cxx @@ -0,0 +1,50 @@ +#include + +#include "SurfRemeshCLP.h" +#include "SurfaceRemeshing.h" + +int main(int argc, char* argv[]) +{ + PARSE_ARGS; + + if (argc < 2) + { + std::cout << "Usage: " << argv[0] << " --help" << std::endl; + return -1; + } + + char *subject = (char *) input.c_str(); + char *dfield = NULL; + if (!coeff.empty()) dfield = (char *) coeff.c_str(); + char *sphere = (char *) temp.c_str(); + char *reference = NULL; + if (!ref.empty()) reference = (char *) ref.c_str(); + char *dsphere = NULL; + if (!deform.empty()) dsphere = (char *) deform.c_str(); + char *colormap = NULL; + if (!color.empty()) colormap = (char *) color.c_str(); + SurfaceRemeshing *SR; + +/* int id = 963368; + char subject[1024]; sprintf(subject, "/home/hmali/Example/surface/stx_noscale_%d_V12_t1w_label_pp_surf_tMeanSPHARM_procalign.vtk", id); + char sphere[1024] = "/home/hmali/Example/sphere/stx_noscale_996312_V12_t1w_label_pp_surf_tMeanSPHARM_procalign.sphere.vtk"; + char dfield[1024]; sprintf(dfield, "/NIRAL/work/ilwoolyu/GROUPS-build/result/stx_noscale_%d_V12_t1w_label_pp_surf_tMeanSPHARM_procalign.coeff.txt", id); + char output[1024]; sprintf(output, "/NIRAL/work/ilwoolyu/SurfRemesh/build/result/stx_noscale_%d_V12_t1w_label_pp_surf_tMeanSPHARM_procalign.vtk", id); */ + + cout << "subject: " << subject << endl; + cout << "sphere: " << sphere << endl; + if (!coeff.empty()) cout << "deformation: " << dfield << endl; + cout << "reference: " << reference << endl; + + SR = new SurfaceRemeshing(subject, sphere, dfield, keepC, reference, colormap, property); + + cout << "Write output surface model..\n"; + if (!output.empty()) SR->saveDeformedSurface(output.c_str()); + if (dsphere != NULL) SR->saveDeformedSphere(dsphere); + if (!outputProp.empty()) SR->saveDeformedProperty(outputProp.c_str(), !noheader); + + delete SR; + + return 0; +} + diff --git a/wrapper/SurfRemesh.xml b/wrapper/SurfRemesh.xml new file mode 100644 index 0000000..9bd8b5c --- /dev/null +++ b/wrapper/SurfRemesh.xml @@ -0,0 +1,71 @@ + + +Surface Remeshing Tool +1.0 +Ilwoo Lyu +xml for Surface Remeshing Tool + + + keepColor + keepC + Keep color of the template model + + + tempModel + t + temp + Template model (unit sphere) used for the spherical parameterization + + + input + i + input + Subject surface model + + + coeff + c + coeff + Spherical harmonic coefficients + + + output + o + output + + + outputProperty + outputProp + + Output of properties after remeshing + + + ref + r + ref + Reference model (unit sphere) for the final surface remeshing + + + deform + deform + Deformed sphere by the given deformation field + + + color + color + Color map of the reference model that will assign the same color to the generated surface + + + noheader + noheader + disables header in the generated property map + 0 + + + property + p + property + Properties that are included in the resulting mesh file + + + From 321418355b08e7d39544b964aaaed2aed9845111 Mon Sep 17 00:00:00 2001 From: Priscille De Dumast Date: Tue, 8 Nov 2016 17:17:34 -0500 Subject: [PATCH 2/5] ENH: Change construction order of triangles vertices --- src/SurfaceRemeshing.cpp | 17 +++++++++++------ wrapper/SRemesh.cxx | 2 ++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/SurfaceRemeshing.cpp b/src/SurfaceRemeshing.cpp index 0b59430..86bc3cc 100644 --- a/src/SurfaceRemeshing.cpp +++ b/src/SurfaceRemeshing.cpp @@ -102,6 +102,7 @@ SurfaceRemeshing::SurfaceRemeshing(const char *subject, const char *sphere, cons m_coeff[0] = 0; m_coeff[1] = 0; } + float phi, theta; Coordinate::cart2sph(m_pole, &phi, &theta); @@ -137,7 +138,7 @@ SurfaceRemeshing::SurfaceRemeshing(const char *subject, const char *sphere, cons if (fabs(phi - phi_) < eps && fabs(theta - theta_) < eps) continue; SphericalHarmonics::basis(m_degree, (float *)v->fv(), Y); reconsCoord(v->fv(), v1, Y, m_coeff, m_degree, m_pole); - MathVector V(v1); V.unit(); + MathVector V(v1); V.unit(); v->setVertex(V.fv()); } } @@ -194,6 +195,7 @@ SurfaceRemeshing::SurfaceRemeshing(const char *subject, const char *sphere, cons } } + void SurfaceRemeshing::reconsCoord(const float *v0, float *v1, float *Y, float *coeff, int degree, float *pole) { // spharm basis @@ -244,8 +246,8 @@ void SurfaceRemeshing::reconsCoord(const float *v0, float *v1, float *Y, float * // inverse rotation Coordinate::rotPoint(rv, rot, v1); } - -/*void SurfaceRemeshing::reconsCoord(const float *v0, float *v1, float *Y, float *coeff, float degree, float *pole) +/* +void SurfaceRemeshing::reconsCoord(const float *v0, float *v1, float *Y, float *coeff, float degree, float *pole) { // spharm basis int n = (degree + 1) * (degree + 1); @@ -351,10 +353,13 @@ void SurfaceRemeshing::deformSurface() float d_v[3]; if (m_interpolation) { - d_v[0] = dataInterpolation(m_x, id, coeff, m_sphere_subj); + // d_v[0] = dataInterpolation(m_x, id, coeff, m_sphere_subj); + // d_v[1] = dataInterpolation(m_y, id, coeff, m_sphere_subj); + // d_v[2] = dataInterpolation(m_z, id, coeff, m_sphere_subj); + d_v[2] = dataInterpolation(m_x, id, coeff, m_sphere_subj); d_v[1] = dataInterpolation(m_y, id, coeff, m_sphere_subj); - d_v[2] = dataInterpolation(m_z, id, coeff, m_sphere_subj); - + d_v[0] = dataInterpolation(m_z, id, coeff, m_sphere_subj); + if (m_keepColor) { int *d_c = new int[3]; diff --git a/wrapper/SRemesh.cxx b/wrapper/SRemesh.cxx index 68af043..07b6cfe 100644 --- a/wrapper/SRemesh.cxx +++ b/wrapper/SRemesh.cxx @@ -7,6 +7,8 @@ int main(int argc, char* argv[]) { PARSE_ARGS; + std::cout< Date: Wed, 16 Nov 2016 13:52:53 -0500 Subject: [PATCH 3/5] STYLE: Delete unused old files --- wrapper/SurfRemesh.cxx | 50 ----------------------------- wrapper/SurfRemesh.xml | 71 ------------------------------------------ 2 files changed, 121 deletions(-) delete mode 100644 wrapper/SurfRemesh.cxx delete mode 100644 wrapper/SurfRemesh.xml diff --git a/wrapper/SurfRemesh.cxx b/wrapper/SurfRemesh.cxx deleted file mode 100644 index a38061f..0000000 --- a/wrapper/SurfRemesh.cxx +++ /dev/null @@ -1,50 +0,0 @@ -#include - -#include "SurfRemeshCLP.h" -#include "SurfaceRemeshing.h" - -int main(int argc, char* argv[]) -{ - PARSE_ARGS; - - if (argc < 2) - { - std::cout << "Usage: " << argv[0] << " --help" << std::endl; - return -1; - } - - char *subject = (char *) input.c_str(); - char *dfield = NULL; - if (!coeff.empty()) dfield = (char *) coeff.c_str(); - char *sphere = (char *) temp.c_str(); - char *reference = NULL; - if (!ref.empty()) reference = (char *) ref.c_str(); - char *dsphere = NULL; - if (!deform.empty()) dsphere = (char *) deform.c_str(); - char *colormap = NULL; - if (!color.empty()) colormap = (char *) color.c_str(); - SurfaceRemeshing *SR; - -/* int id = 963368; - char subject[1024]; sprintf(subject, "/home/hmali/Example/surface/stx_noscale_%d_V12_t1w_label_pp_surf_tMeanSPHARM_procalign.vtk", id); - char sphere[1024] = "/home/hmali/Example/sphere/stx_noscale_996312_V12_t1w_label_pp_surf_tMeanSPHARM_procalign.sphere.vtk"; - char dfield[1024]; sprintf(dfield, "/NIRAL/work/ilwoolyu/GROUPS-build/result/stx_noscale_%d_V12_t1w_label_pp_surf_tMeanSPHARM_procalign.coeff.txt", id); - char output[1024]; sprintf(output, "/NIRAL/work/ilwoolyu/SurfRemesh/build/result/stx_noscale_%d_V12_t1w_label_pp_surf_tMeanSPHARM_procalign.vtk", id); */ - - cout << "subject: " << subject << endl; - cout << "sphere: " << sphere << endl; - if (!coeff.empty()) cout << "deformation: " << dfield << endl; - cout << "reference: " << reference << endl; - - SR = new SurfaceRemeshing(subject, sphere, dfield, keepC, reference, colormap, property); - - cout << "Write output surface model..\n"; - if (!output.empty()) SR->saveDeformedSurface(output.c_str()); - if (dsphere != NULL) SR->saveDeformedSphere(dsphere); - if (!outputProp.empty()) SR->saveDeformedProperty(outputProp.c_str(), !noheader); - - delete SR; - - return 0; -} - diff --git a/wrapper/SurfRemesh.xml b/wrapper/SurfRemesh.xml deleted file mode 100644 index 9bd8b5c..0000000 --- a/wrapper/SurfRemesh.xml +++ /dev/null @@ -1,71 +0,0 @@ - - -Surface Remeshing Tool -1.0 -Ilwoo Lyu -xml for Surface Remeshing Tool - - - keepColor - keepC - Keep color of the template model - - - tempModel - t - temp - Template model (unit sphere) used for the spherical parameterization - - - input - i - input - Subject surface model - - - coeff - c - coeff - Spherical harmonic coefficients - - - output - o - output - - - outputProperty - outputProp - - Output of properties after remeshing - - - ref - r - ref - Reference model (unit sphere) for the final surface remeshing - - - deform - deform - Deformed sphere by the given deformation field - - - color - color - Color map of the reference model that will assign the same color to the generated surface - - - noheader - noheader - disables header in the generated property map - 0 - - - property - p - property - Properties that are included in the resulting mesh file - - - From 6384026a7bafd2483d52987965a1dea3e6954044 Mon Sep 17 00:00:00 2001 From: Priscille De Dumast Date: Mon, 20 Mar 2017 15:09:45 -0400 Subject: [PATCH 4/5] STYLE: Add ReadMe --- Common.cmake | 6 +++--- README.md | 1 + src/SurfaceRemeshing.cpp | 8 +++----- 3 files changed, 7 insertions(+), 8 deletions(-) create mode 100644 README.md diff --git a/Common.cmake b/Common.cmake index bb41ca1..958ca3c 100644 --- a/Common.cmake +++ b/Common.cmake @@ -18,9 +18,9 @@ if(NOT COMMAND SETIFEMPTY) endif() #----------------------------------------------------------------------------- -SETIFEMPTY(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PRIMARY_PROJECT_NAME}-build/lib) -SETIFEMPTY(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PRIMARY_PROJECT_NAME}-build/lib) -SETIFEMPTY(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PRIMARY_PROJECT_NAME}-build/bin) +SETIFEMPTY(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PRIMARY_PROJECT_NAME}build/lib) +SETIFEMPTY(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PRIMARY_PROJECT_NAME}build/lib) +SETIFEMPTY(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${PRIMARY_PROJECT_NAME}build/bin) #----------------------------------------------------------------------------- SETIFEMPTY(CMAKE_INSTALL_LIBRARY_DESTINATION lib) diff --git a/README.md b/README.md new file mode 100644 index 0000000..80c3bb1 --- /dev/null +++ b/README.md @@ -0,0 +1 @@ +## Surface Remesh \ No newline at end of file diff --git a/src/SurfaceRemeshing.cpp b/src/SurfaceRemeshing.cpp index 86bc3cc..517418e 100644 --- a/src/SurfaceRemeshing.cpp +++ b/src/SurfaceRemeshing.cpp @@ -353,12 +353,9 @@ void SurfaceRemeshing::deformSurface() float d_v[3]; if (m_interpolation) { - // d_v[0] = dataInterpolation(m_x, id, coeff, m_sphere_subj); - // d_v[1] = dataInterpolation(m_y, id, coeff, m_sphere_subj); - // d_v[2] = dataInterpolation(m_z, id, coeff, m_sphere_subj); - d_v[2] = dataInterpolation(m_x, id, coeff, m_sphere_subj); + d_v[0] = dataInterpolation(m_x, id, coeff, m_sphere_subj); d_v[1] = dataInterpolation(m_y, id, coeff, m_sphere_subj); - d_v[0] = dataInterpolation(m_z, id, coeff, m_sphere_subj); + d_v[2] = dataInterpolation(m_z, id, coeff, m_sphere_subj); if (m_keepColor) { @@ -377,6 +374,7 @@ void SurfaceRemeshing::deformSurface() d_v[2] = dataMedian(m_z, id, m_sphere_subj); } Vertex *new_v = (Vertex *)m_remesh->vertex(i); + new_v->setVertex(d_v); } } From 8e5050eb11533de83d833646eba7c8204b2e8db7 Mon Sep 17 00:00:00 2001 From: Priscille De Dumast Date: Mon, 20 Mar 2017 16:09:37 -0400 Subject: [PATCH 5/5] STYLE: Update README --- README.md | 61 ++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 60 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 80c3bb1..f14ee28 100644 --- a/README.md +++ b/README.md @@ -1 +1,60 @@ -## Surface Remesh \ No newline at end of file +## Surface Remesh + +## Description + +Surface reconstruction from rotated spheres (after RigidAlignment) or from coefficients (after GROUPS). + + +## Build + +#### Requirements + +Building SurfRemesh requires to have built previously: + +* MeshLib (https://github.com/pdedumast/MeshLib) +* SlicerExecutionModel + +SurfRemesh can either be built from GROUPS SuperBuild. + + +###### Linux or MacOSX + +Consider this tree of repertories: +``` +~/Project/SurfRemesh + /SurfRemesh-build +``` + +Start a terminal. +First change your current working directory to the build directory ```SurfRemesh-build``` +``` +cd ~/Project/SurfRemesh-build +``` + +Generate the project using ```cmake``` +``` +cmake -DMeshLib_DIR:PATH=path/to/MeshLib -DSlicerExecutionModel:PATH=path/to/SlicerExecutionModel ../SurfRemesh +make +``` + + +## Usage + +Reconstruction from new rotated sphere, after RigidAlignment: +Output surface will have the same parametrization with one specified by the reference sphere. +``` +./SurfRemesh --input [ input surface model] --tempModel [ rotate sphere] +--ref [ common sphere model (same as refSphere in RigidAlignment)] +--output [ reconstructed surface] +``` + +Reconstruction from coefficients, after GROUPS: +``` +./SurfRemesh --input [ input surface model] --tempModel [ sphere model used in GROUPS] +--ref [ common sphere model] --coeff [ Coefficients file from GROUPS] +--output [ reconstructed surface] +``` + +## Licence + +See LICENSE.txt for information on using and contributing. \ No newline at end of file