alecjacobson / gptoolbox

Matlab toolbox for Geometry Processing.
MIT License
628 stars 166 forks source link

mexw64 compiling 'signed_distance' [persistent precomputation data feature request] #1

Closed alecjacobson closed 9 years ago

alecjacobson commented 9 years ago

Alec: pasted from email:

Dear Alec Jacobson,

I would like to use the function signed_distance of your matlab toolbox gptoolbox for my research. Unfortunately, I have been unsuccessful in mexw64 compiling. Hopefully you can give me some help.

If you already have a mexw64 compiled version of this function, it is probably easiest to just send me this file. Otherwise, this is in short what I have done so far:

  •    I followed the standard installation instructions on the gptoolbox github site;
  •    I tried to follow the full installation instructions on the gptoolbox github as well though didn’t succeed:

o I downloaded and extracted libigl and eigen3;

o I followed the instructions for compiling libigl as a static library with visual studio. Compilation failed with many errors. Though, I am uncertain if it is necessary to compile a static library of libigl for the function signed_distance.

  • In matlab, I tried the following line and got multiple errors:

o mex -v -largeArrayDims -DMEX -IC:\libigl\include -IC:\eigen3 -O signed_distance.m signed_distance.cpp

Kind Regards, JM

alecjacobson commented 9 years ago

I've just pushed a readme for the gptoolbox/mex directory that hopefully helps a bit.

In your particular case, the signed_distance function depends on: Eigen, libigl, and CGAL (and boost).`

I'm not a windows user, so I'm not sure about the best way to install CGAL, but once you do you'll need to link to the CGAL and CGAL_Core libraries. In general, try to mimic the mex call in the comments at the top of signed_distance.cpp

Libigl is by default header only. So you don't need to compile the static library. Just add it to the include path is enough.

If you have further issues, paste exactly the output of your mex calls.

JoostM commented 9 years ago

Ok, I have now installed CGAL and boost as well.

This is the new code I have tried for compiling the mex in Matlab:

mex -v -largeArrayDims -DMEX ...
  -IC:\libigl\include ...
  -IC:\eigen3 ...
  -IC:\dev\CGAL-4.5\include ...
  -IC:\dev\CGAL-4.5\build\include\ ...
  -IC:\dev\CGAL-4.5\auxiliary\gmp\include ...
  -IC:\local\boost_1_57_0\ ...
  -LC:\dev\CGAL-4.5\build\lib\ -lCGAL-vc120-mt-4.5 -lCGAL_Core-vc120-mt-4.5 ...
  -LC:\dev\CGAL-4.5\auxiliary\gmp\lib -llibgmp-10 -llibmpfr-4 ...
  -LC:\local\boost_1_57_0\lib64-msvc-12.0 -lboost_thread-vc120-mt-1_57 -lboost_system-vc120-mt-1_57 ...
  -O signed_distance.m signed_distance.cpp

I have changed the "-o" option into a capital "-O", because the former didn't work. Capital "-O" optimizes the object code.

Compiling failed and this is the output in the command window:

-> Default options filename found in C:\Users\Joost\AppData\Roaming\MathWorks\MATLAB\R2013b 
---------------------------------------------------------------- 
->    Options file           = C:\Users\Joost\AppData\Roaming\MathWorks\MATLAB\R2013b\mexopts.bat 
      MATLAB                 = C:\Program Files\MATLAB\R2013b 
->    COMPILER               = cl 
->    Compiler flags: 
         COMPFLAGS           = /c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD 
         OPTIMFLAGS          = /O2 /Oy- /DNDEBUG 
         DEBUGFLAGS          = /Z7 
         arguments           =  -DMEX -IC:\libigl\include -IC:\eigen3 -IC:\dev\CGAL-4.5\include -IC:\dev\CGAL-4.5\build\include\ -IC:\dev\CGAL-4.5\auxiliary\gmp\include -IC:\local\boost_1_57_0\ 
         Name switch         = /Fo 
->    Pre-linking commands   =  
->    LINKER                 = link 
->    Link directives: 
         LINKFLAGS           = /dll /export:mexFunction /LIBPATH:"C:\Program Files\MATLAB\R2013b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /MACHINE:X64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\Joost\AppData\Local\Temp\mex_qicAr4\templib.x" /MAP:"signed_distance.mexw64.map" 
         LINKDEBUGFLAGS      = /debug /PDB:"signed_distance.mexw64.pdb" 
         LINKFLAGSPOST       =  
         Name directive      = /out:"signed_distance.mexw64" 
         File link directive =  
         Lib. link directive =  
         Rsp file indicator  = @ 
->    Resource Compiler      = rc /fo "mexversion.res" 
->    Resource Linker        =  
---------------------------------------------------------------- 

--> cl  -DMEX -IC:\libigl\include -IC:\eigen3 -IC:\dev\CGAL-4.5\include -IC:\dev\CGAL-4.5\build\include\ -IC:\dev\CGAL-4.5\auxiliary\gmp\include -IC:\local\boost_1_57_0\ /c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD /FoC:\Users\Joost\AppData\Local\Temp\mex_qicAr4\signed_distance.obj -I"C:\Program Files\MATLAB\R2013b\extern\include" -I"C:\Program Files\MATLAB\R2013b\simulink\include" /O2 /Oy- /DNDEBUG signed_distance.cpp 

signed_distance.cpp 
c:\libigl\include\igl\exterior_edges.cpp(81) : error C2143: syntax error : missing ',' before ':' 
c:\libigl\include\igl\exterior_edges.cpp(81) : error C2530: 'cit' : references must be initialized 
c:\libigl\include\igl\exterior_edges.cpp(81) : error C3531: 'cit': a symbol whose type contains 'auto' must have an initializer 
c:\libigl\include\igl\exterior_edges.cpp(82) : error C2143: syntax error : missing ';' before '{' 
c:\libigl\include\igl\exterior_edges.cpp(84) : error C2228: left of '.second' must have class/struct/union 
        type is 'int' 
c:\libigl\include\igl\exterior_edges.cpp(86) : error C2228: left of '.first' must have class/struct/union 
        type is 'int' 
c:\libigl\include\igl\exterior_edges.cpp(87) : error C2228: left of '.second' must have class/struct/union 
        type is 'int' 
c:\libigl\include\igl\exterior_edges.cpp(89) : error C2228: left of '.first' must have class/struct/union 
        type is 'int' 
c:\libigl\include\igl\exterior_edges.cpp(90) : error C2228: left of '.second' must have class/struct/union 
        type is 'int' 
c:\libigl\include\igl\exterior_edges.cpp(92) : error C2044: illegal continue 
c:\libigl\include\igl\exterior_edges.cpp(94) : error C2228: left of '.second' must have class/struct/union 
        type is 'int' 
c:\eigen3\eigen\src/SparseCore/SparseDenseProduct.h(316) : error C2244: 'Eigen::SparseMatrixBase<Derived>::operator *' : unable to match function definition to an existing declaration 
        definition 
        'const SparseDenseProductReturnType<Derived,OtherDerived>::Type Eigen::SparseMatrixBase<Derived>::operator *(const Eigen::MatrixBase<OtherDerived> &) const' 
        existing declarations 
        'const SparseDenseProductReturnType<Derived,OtherDerived>::Type Eigen::SparseMatrixBase<Derived>::operator *(const Eigen::MatrixBase<OtherDerived> &) const' 
        'const Eigen::SparseDiagonalProduct<Derived,OtherDerived> Eigen::SparseMatrixBase<Derived>::operator *(const Eigen::DiagonalBase<DiagonalDerived> &) const' 
        'const SparseSparseProductReturnType<Derived,OtherDerived>::Type Eigen::SparseMatrixBase<Derived>::operator *(const Eigen::SparseMatrixBase<OtherDerived> &) const' 
        'const Eigen::CwiseUnaryOp<Eigen::internal::scalar_multiple2_op<internal::traits<T>::Scalar,std::complex<internal::traits<T>::Scalar>>,const Derived> Eigen::SparseMatrixBase<Derived>::operator *(const std::complex<internal::traits<T>::Scalar> &) const' 
        'const Eigen::CwiseUnaryOp<Eigen::internal::scalar_multiple_op<internal::traits<T>::Scalar>,const Derived> Eigen::SparseMatrixBase<Derived>::operator *(const internal::traits<T>::Scalar &) const' 
c:\libigl\include\igl\winding_number.cpp(26) : warning C4244: 'argument' : conversion from '__int64' to 'const int', possible loss of data 
c:\libigl\include\igl\winding_number.cpp(26) : warning C4244: 'argument' : conversion from '__int64' to 'const int', possible loss of data 
c:\libigl\include\igl\winding_number.cpp(26) : warning C4244: 'argument' : conversion from '__int64' to 'const int', possible loss of data 
c:\libigl\include\igl\winding_number.cpp(32) : warning C4244: 'initializing' : conversion from '__int64' to 'const int', possible loss of data 
signed_distance.cpp(38) : warning C4267: 'initializing' : conversion from 'size_t' to 'const int', possible loss of data 
signed_distance.cpp(63) : error C2660: 'mexErrMsgTxt' : function does not take 2 arguments 
signed_distance.cpp(69) : error C2660: 'mexErrMsgTxt' : function does not take 2 arguments 

  C:\PROGRA~1\MATLAB\R2013B\BIN\MEX.PL: Error: Compile of 'signed_distance.cpp' failed. 

Unable to complete successfully.

Error in mymex (line 1)
mex -v -largeArrayDims -DMEX ...
alecjacobson commented 9 years ago

First off, I think you can remove the -O signed_distance.m. Previously the little o -o signed_distance was just telling matlab how to name the output file. I'm not sure what matlab will try to do with -O signed_distance.m.

Are you using Visual Studio 2010? It looks like your cl compiler is throwing up on the range-based for loop which are only supported with Visual Studio 2012 or later. Can you upgrade to a modern compiler?

I can't understand the SparseMatrix errors. This seems to be an error inside Eigen, but I can't figure out where in the libigl or signed_distance.cpp this is stemming from.

The last error makes it seem like using namespace igl; does not apply to the lambda's scope with your compile. I pushed a change to call igl::mexErrMsgTxt directly. If you git pull on gptoolbox hopefully this goes away (might also go away when you upgrade VS).

Hope this helps.

On Sun, Nov 16, 2014 at 8:30 AM, JoostM notifications@github.com wrote:

Ok, I have now installed CGAL and boost as well.

This is the new code I have tried for compiling the mex in Matlab:

mex -v -largeArrayDims -DMEX ... -IC:\libigl\include ... -IC:\eigen3 ... -IC:\dev\CGAL-4.5\include ... -IC:\dev\CGAL-4.5\build\include\ ... -IC:\dev\CGAL-4.5\auxiliary\gmp\include ... -IC:\local\boost_1_57_0\ ... -LC:\dev\CGAL-4.5\build\lib\ -lCGAL-vc120-mt-4.5 -lCGAL_Core-vc120-mt-4.5 ... -LC:\dev\CGAL-4.5\auxiliary\gmp\lib -llibgmp-10 -llibmpfr-4 ... -LC:\local\boost_1_57_0\lib64-msvc-12.0 -lboost_thread-vc120-mt-1_57 -lboost_system-vc120-mt-1_57 ... -O signed_distance.m signed_distance.cpp

I have changed the "-o" option into a capital "-O", because the former didn't work. Capital "-O" optimizes the object code.

Compiling failed and this is the output in the command window:

-> Default options filename found in C:\Users\Joost\AppData\Roaming\MathWorks\MATLAB\R2013b

-> Options file = C:\Users\Joost\AppData\Roaming\MathWorks\MATLAB\R2013b\mexopts.bat MATLAB = C:\Program Files\MATLAB\R2013b -> COMPILER = cl -> Compiler flags: COMPFLAGS = /c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD OPTIMFLAGS = /O2 /Oy- /DNDEBUG DEBUGFLAGS = /Z7 arguments = -DMEX -IC:\libigl\include -IC:\eigen3 -IC:\dev\CGAL-4.5\include -IC:\dev\CGAL-4.5\build\include\ -IC:\dev\CGAL-4.5\auxiliary\gmp\include -IC:\local\boost_1_57_0\ Name switch = /Fo -> Pre-linking commands = -> LINKER = link -> Link directives: LINKFLAGS = /dll /export:mexFunction /LIBPATH:"C:\Program Files\MATLAB\R2013b\extern\lib\win64\microsoft" libmx.lib libmex.lib libmat.lib /MACHINE:X64 kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib /nologo /manifest /incremental:NO /implib:"C:\Users\Joost\AppData\Local\Temp\mex_qicAr4\templib.x" /MAP:"signed_distance.mexw64.map" LINKDEBUGFLAGS = /debug /PDB:"signed_distance.mexw64.pdb" LINKFLAGSPOST = Name directive = /out:"signed_distance.mexw64" File link directive = Lib. link directive = Rsp file indicator = @ -> Resource Compiler = rc /fo "mexversion.res"

-> Resource Linker =

--> cl -DMEX -IC:\libigl\include -IC:\eigen3 -IC:\dev\CGAL-4.5\include -IC:\dev\CGAL-4.5\build\include\ -IC:\dev\CGAL-4.5\auxiliary\gmp\include -IC:\local\boost_1_57_0\ /c /GR /W3 /EHs /D_CRT_SECURE_NO_DEPRECATE /D_SCL_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /DMATLAB_MEX_FILE /nologo /MD /FoC:\Users\Joost\AppData\Local\Temp\mex_qicAr4\signed_distance.obj -I"C:\Program Files\MATLAB\R2013b\extern\include" -I"C:\Program Files\MATLAB\R2013b\simulink\include" /O2 /Oy- /DNDEBUG signed_distance.cpp

signed_distance.cpp c:\libigl\include\igl\exterior_edges.cpp(81) : error C2143: syntax error : missing ',' before ':' c:\libigl\include\igl\exterior_edges.cpp(81) : error C2530: 'cit' : references must be initialized c:\libigl\include\igl\exterior_edges.cpp(81) : error C3531: 'cit': a symbol whose type contains 'auto' must have an initializer c:\libigl\include\igl\exterior_edges.cpp(82) : error C2143: syntax error : missing ';' before '{' c:\libigl\include\igl\exterior_edges.cpp(84) : error C2228: left of '.second' must have class/struct/union type is 'int' c:\libigl\include\igl\exterior_edges.cpp(86) : error C2228: left of '.first' must have class/struct/union type is 'int' c:\libigl\include\igl\exterior_edges.cpp(87) : error C2228: left of '.second' must have class/struct/union type is 'int' c:\libigl\include\igl\exterior_edges.cpp(89) : error C2228: left of '.first' must have class/struct/union type is 'int' c:\libigl\include\igl\exterior_edges.cpp(90) : error C2228: left of '.second' must have class/struct/union type is 'int' c:\libigl\include\igl\exterior_edges.cpp(92) : error C2044: illegal continue c:\libigl\include\igl\exterior_edges.cpp(94) : error C2228: left of '.second' must have class/struct/union type is 'int' c:\eigen3\eigen\src/SparseCore/SparseDenseProduct.h(316) : error C2244: 'Eigen::SparseMatrixBase::operator ' : unable to match function definition to an existing declaration definition 'const SparseDenseProductReturnType<Derived,OtherDerived>::Type Eigen::SparseMatrixBase::operator (const Eigen::MatrixBase &) const' existing declarations 'const SparseDenseProductReturnType<Derived,OtherDerived>::Type Eigen::SparseMatrixBase::operator (const Eigen::MatrixBase &) const' 'const Eigen::SparseDiagonalProduct<Derived,OtherDerived> Eigen::SparseMatrixBase::operator (const Eigen::DiagonalBase &) const' 'const SparseSparseProductReturnType<Derived,OtherDerived>::Type Eigen::SparseMatrixBase::operator (const Eigen::SparseMatrixBase &) const' 'const Eigen::CwiseUnaryOpEigen::internal::scalar_multiple2_op<internal::traits<T::Scalar,std::complexinternal::traits>,const Derived> Eigen::SparseMatrixBase::operator (const std::complexinternal::traits &) const' 'const Eigen::CwiseUnaryOpEigen::internal::scalar_multiple_op<internal::traits,const Derived> Eigen::SparseMatrixBase::operator *(const internal::traits::Scalar &) const' c:\libigl\include\igl\winding_number.cpp(26) : warning C4244: 'argument' : conversion from 'int64' to 'const int', possible loss of data c:\libigl\include\igl\winding_number.cpp(26) : warning C4244: 'argument' : conversion from '__int64' to 'const int', possible loss of data c:\libigl\include\igl\winding_number.cpp(26) : warning C4244: 'argument' : conversion from 'int64' to 'const int', possible loss of data c:\libigl\include\igl\winding_number.cpp(32) : warning C4244: 'initializing' : conversion from '__int64' to 'const int', possible loss of data signed_distance.cpp(38) : warning C4267: 'initializing' : conversion from 'size_t' to 'const int', possible loss of data signed_distance.cpp(63) : error C2660: 'mexErrMsgTxt' : function does not take 2 arguments signed_distance.cpp(69) : error C2660: 'mexErrMsgTxt' : function does not take 2 arguments

C:\PROGRA~1\MATLAB\R2013B\BIN\MEX.PL: Error: Compile of 'signed_distance.cpp' failed.

Unable to complete successfully.

Error in mymex (line 1) mex -v -largeArrayDims -DMEX ...

— Reply to this email directly or view it on GitHub https://github.com/alecjacobson/gptoolbox/issues/1#issuecomment-63218949 .

JoostM commented 9 years ago

Great! It's working now!

This is what I've done. I installed VS2012. When mex compiling, Matlab was still giving errors and was asking for VS2012 versions of boost and CGAL. So, I got a VS2012 version of boost and build a VS2012 version of CGAL.

Matlab kept asking for a few other boost libraries, so I added these to the mex code below:

mex -v -largeArrayDims -DMEX ...
  -IC:\dev\libigl\include ...
  -IC:\dev\eigen3 ...
  -IC:\dev\CGAL-4.5\include ...
  -IC:\dev\CGAL-4.5\build\include\ ...
  -IC:\dev\CGAL-4.5\auxiliary\gmp\include ...
  -IC:\dev\boost_1_57_0\ ...
  -LC:\dev\CGAL-4.5\build\lib\ -lCGAL-vc110-mt-4.5 -lCGAL_Core-vc110-mt-4.5 ...
  -LC:\dev\CGAL-4.5\auxiliary\gmp\lib -llibgmp-10 -llibmpfr-4 ...
  -LC:\dev\boost_1_57_0\lib64-msvc-11.0 ...
  -lboost_thread-vc110-mt-1_57 -lboost_system-vc110-mt-1_57 ...
  -llibboost_thread-vc110-mt-1_57 -llibboost_system-vc110-mt-1_57 ...
  -llibboost_date_time-vc110-mt-1_57 ...
  -llibboost_chrono-vc110-mt-1_57 ...
  signed_distance.cpp

With this code I was able to compile the signed_distance.mexw64. Though, signed_distance.mexw64 itself still gave an error when ran:

The specified module could not be found.

I had to install and run dependency walker to find out that the following dll's could not be found:

boost_chrono-vc110-mt-1_57.dll
boost_system-vc110-mt-1_57.dll
boost_thread-vc110-mt-1_57.dll

I copied the dll's to the same folder as signed_distance.mexw64 and now the function is working well. Even when I delete the dll's afterwards and recompile.

Thanks for your help!

I have a follow-up question as well. I guess the pseudonormals are calculated every time you run the function. This might be insufficient when the function is called repeatedly with the same triangular surface as input. Is it possible to pre-calculate the pseudonormals and have them as an additional input for signed_distance.mexw64?

alecjacobson commented 9 years ago

Great! I’m glad you got it to work and thanks for posting your solution.

Regarding the pseudonormals, yes, they’re recomputed each call. I guess I’m assuming that building the CGAL acceleration data-structure will be the bottleneck O(n log n) rather than computing the normals O(n). Unfortunately, matlab makes it very difficult to return raw C++ classes from mex functions to maintain persistency across multiple calls. I tried something similar once by serializing the C++ class and saw only modest returns.

The normals would be easy to maintain, though. I’ll quickly profile and see if computing normals has an effect on the time. If so, I’ll make a todo to add that feature. If not, it might be a while before trying to maintain the full search data-structure. If your code badly needs this, you might consider moving your pipeline to C++.

The raw libigl signed_distance_pseudonormal https://github.com/libigl/libigl/blob/master/include/igl/cgal/signed_distance.h function does expose the normals and search data structures, so in C++ it would be straightforward to avoid recomputing these. ​

On Tue, Nov 18, 2014 at 8:34 AM, JoostM notifications@github.com wrote:

Great! It's working now!

This is what I've done. I installed VS2012. When mex compiling, Matlab was still giving errors and was asking for VS2012 versions of boost and CGAL. So, I got a VS2012 version of boost and build a VS2012 version of CGAL.

Matlab kept asking for a few other boost libraries, so I added these to the mex code below:

mex -v -largeArrayDims -DMEX ... -IC:\dev\libigl\include ... -IC:\dev\eigen3 ... -IC:\dev\CGAL-4.5\include ... -IC:\dev\CGAL-4.5\build\include\ ... -IC:\dev\CGAL-4.5\auxiliary\gmp\include ... -IC:\dev\boost_1_57_0\ ... -LC:\dev\CGAL-4.5\build\lib\ -lCGAL-vc110-mt-4.5 -lCGAL_Core-vc110-mt-4.5 ... -LC:\dev\CGAL-4.5\auxiliary\gmp\lib -llibgmp-10 -llibmpfr-4 ... -LC:\dev\boost_1_57_0\lib64-msvc-11.0 ... -lboost_thread-vc110-mt-1_57 -lboost_system-vc110-mt-1_57 ... -llibboost_thread-vc110-mt-1_57 -llibboost_system-vc110-mt-1_57 ... -llibboost_date_time-vc110-mt-1_57 ... -llibboost_chrono-vc110-mt-1_57 ... signed_distance.cpp

With this code I was able to compile the signed_distance.mexw64. Though, signed_distance.mexw64 itself still gave an error when ran:

The specified module could not be found.

I had to install and run dependency walker to find out that the following dll's could not be found:

boost_chrono-vc110-mt-1_57.dll boost_system-vc110-mt-1_57.dll boost_thread-vc110-mt-1_57.dll

I copied the dll's to the same folder as signed_distance.mexw64 and now the function is working well. Even when I delete the dll's afterwards and recompile.

Thanks for your help!

I have a follow-up question as well. I guess the pseudonormals are calculated every time you run the function. This might be insufficient when the function is called repeatedly with the same triangular surface as input. Is it possible to pre-calculate the pseudonormals and have them as an additional input for signed_distance.mexw64?

— Reply to this email directly or view it on GitHub https://github.com/alecjacobson/gptoolbox/issues/1#issuecomment-63471113 .

alecjacobson commented 9 years ago

I profiled and did a tiny bit of performance optimization. Computing the normals is about 1/4 the cost of rebuilding the AABB search tree. I also found out some disturbing things about the CGAL search tree, which make me less enthusiastic about trying to serialize it. So as it stands I will not support the feature of persistent precomputed data and data structures for signed_distance.

Again, it's easy to avoid recomputation if you switch to C++ and libigl. If you badly want to stay in matlab-world, there are various hacks you could try. For example, write a signed_distance_precompute mex function which allocates all the data as globals on the heap and returns memory addresses. Then change my function to accept memory addresses and find your globals. Then you ought to also write a signed_distance_cleanup to avoid leaking memory. Starts to make matlab feel like C++...

JoostM commented 9 years ago

I guess it does make matlab feel more like C++ :) I can't really tell though, as I have no C++ experience. Thus, for now I will stick with matlab and use your function as it is. In the (near) future I will possibly ask one of my co-workers to help me in implementing the C++ code as you suggested.

One issue arrised with the last update of 'gptoolbox' and the 'signed_distance' function. When the 'SignedDistanceType' is set to 'pseudonormal', the smallest signed distances S and the closest normals N are not computed.

alecjacobson commented 9 years ago

Uh oh. Looks like I broke something. I'll quickly fix it.

alecjacobson commented 9 years ago

Fixed. Please git pull on libigl. Thanks for noticing that.

JoostM commented 9 years ago

Great! My code (mainly dependent on your function) is now 1/4 faster!

amiralinjm commented 7 years ago

Dr. Jacobson,

Thank you for your fantastic toolbox. I am a Materials science PhD student and I can easily use it, however, I encountered the same problem compiling 'signed_distance' and 'point_mesh_squared_distance' .

If you already have a mexw64 or mexmaci64 (as I have acess to OS X platform) compiled version of these functions, I greatly appreciate of you send me thses files.

However trying to compile on my Windows: I am running Windows10 / MATLAB 2016b / VS2015 Version: Boost: 1_64 CGAL: 4.7 Eigen: 3.3.3 libigl: https://github.com/libigl/libigl/tree/4ccac53005994f695eea123cd85e92be27caecb2

I used the same code format on this post:

mex -v -largeArrayDims -DMEX ... -IC:\dev\libigl\include ... -IC:\dev\eigen ... -IC:\dev\CGAL-4.7\include ... -IC:\dev\CGAL-4.7\build\include\ ... -IC:\dev\CGAL-4.7\auxiliary\gmp\include ... -IC:\dev\boost_1_64_0\ ... -LC:\dev\CGAL-4.7\build\lib\ -lCGAL-vc110-mt-4.7 -lCGAL_Core-vc110-mt-4.7 ... -LC:\dev\CGAL-4.7\auxiliary\gmp\lib -llibgmp-10 -llibmpfr-4 ... -LC:\dev\boost_1_64_0\lib64-msvc-11.0 ... -lboost_thread-vc110-mt-1_64 -lboost_system-vc110-mt-1_64 ... -llibboost_thread-vc110-mt-1_64 -llibboost_system-vc110-mt-1_64 ... -llibboost_date_time-vc110-mt-1_64 ... -llibboost_chrono-vc110-mt-1_64 ... signed_distance.cpp Errors: C4305,C4267,C4244: c:\dev\libigl\include\igl\EPS.h(16): warning C4305: 'initializing': truncation from 'double' to 'float' c:\dev\libigl\include\igl\EPS.h(17): warning C4305: 'initializing': truncation from 'double' to 'float' c:\dev\libigl\include\igl\exterior_edges.cpp(91): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data c:\dev\libigl\include\igl\exterior_edges.cpp(92): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data c:\dev\libigl\include\igl\winding_number.cpp(34): warning C4244: 'argument': conversion from 'Eigen::EigenBase<Derived>::Index' to 'const int', possible loss of data with [ Derived=Eigen::Matrix<double,-1,-1,0,-1,-1> ] c:\dev\libigl\include\igl\winding_number.cpp(34): warning C4244: 'argument': conversion from 'Eigen::EigenBase<Derived>::Index' to 'const int', possible loss of data with [ Derived=Eigen::Matrix<int,-1,-1,0,-1,-1> ] c:\dev\libigl\include\igl\winding_number.cpp(40): warning C4244: 'initializing': conversion from 'Eigen::EigenBase<Derived>::Index' to 'int', possible loss of data with [ Derived=Eigen::Matrix<double,-1,-1,0,-1,-1> ] c:\dev\libigl\include\igl\winding_number.cpp(40): warning C4244: 'initializing': conversion from 'Eigen::EigenBase<Derived>::Index' to 'const int', possible loss of data with [ Derived=Eigen::Matrix<double,-1,-1,0,-1,-1> ] c:\dev\libigl\include\igl\signed_distance.cpp(29): warning C4244: 'initializing': conversion from 'Eigen::EigenBase<Derived>::Index' to 'int', possible loss of data with [ Derived=Eigen::Matrix<double,-1,-1,0,-1,-1> ] c:\dev\libigl\include\igl\signed_distance.cpp(29): warning C4244: 'initializing': conversion from 'Eigen::EigenBase<Derived>::Index' to 'const int', possible loss of data with [ Derived=Eigen::Matrix<double,-1,-1,0,-1,-1> ] c:\dev\libigl\include\igl\signed_distance.cpp(325): warning C4244: 'argument': conversion from 'Eigen::EigenBase<Derived>::Index' to 'const int', possible loss of data with [ Derived=Eigen::Matrix<int,-1,-1,0,-1,-1> ] c:\dev\libigl\include\igl\signed_distance.cpp(325): warning C4244: 'argument': conversion from 'Eigen::EigenBase<Derived>::Index' to 'const int', possible loss of data with [ Derived=Eigen::Matrix<double,-1,-1,0,-1,-1> ] C:\Users\user\Documents\MATLAB\gptoolbox_full\mex\signed_distance.cpp(37): warning C4267: 'initializing': conversion from 'size_t' to 'int', possible loss of data C:\Users\user\Documents\MATLAB\gptoolbox_full\mex\signed_distance.cpp(37): warning C4267: 'initializing': conversion from 'size_t' to 'const int', possible loss of data C:\Users\user\Documents\MATLAB\gptoolbox_full\mex\signed_distance.cpp(183): error C2665: 'igl::signed_distance_winding_number': none of the 3 overloads could convert all the argument types c:\dev\libigl\include\igl\signed_distance.cpp(293): note: could be 'void igl::signed_distance_winding_number(const igl::AABB<Eigen::MatrixXd,3> &,const Eigen::MatrixXd &,const Eigen::MatrixXi &,const igl::WindingNumberAABB<Eigen::Vector3d> &,const Eigen::Matrix<double,1,3,1,1,3> &,double &,double &,int &,Eigen::Matrix<double,1,3,1,1,3> &)' C:\Users\user\Documents\MATLAB\gptoolbox_full\mex\signed_distance.cpp(183): note: while trying to match the argument list '(igl::AABB<Eigen::MatrixXd,3>, Eigen::MatrixXd, Eigen::MatrixXi, igl::WindingNumberAABB<Eigen::RowVector3d>, const Eigen::RowVector3d, double, double, int, Eigen::RowVector3d)'

I followed exactly same instructions on this post, could you please help me with this.

Regards, AN