Libigl, cra sh при вызове "unproject_onto_me sh" - PullRequest
0 голосов
/ 18 марта 2020

Я установил очень простую программу, используя библиотеку libigl, которая опирается на Eigen.

Я не могу понять, что я делаю неправильно.

#include <igl/readOBJ.h>
#include <igl/unproject_onto_mesh.h>
#include <Eigen/Dense>

using std::string;
using Eigen::MatrixXi;
using Eigen::MatrixXd;
using std::ofstream;
using std::cout;
using std::endl;

int main(int argc, char *argv[])
{

    string meshFilename(argv[1]);

    MatrixXi faceList;
    MatrixXd vertexList;
    igl::readOBJ(meshFilename, vertexList, faceList);

    Eigen::Matrix4f model;
    Eigen::Matrix4f projection;
    Eigen::Vector4f viewport;
    Eigen::Vector2f screenCoordinates;
    int faceId;
    Eigen::Vector2f baricentricCoordinate;

    model <<
    -0.197834, -0.783464, -0.589105, -27.707,
    -0.239861, 0.621405, -0.74587, -33.58,
    0.950436, -0.00625538, -0.310858, -48.7152,
    0, 0, 0, 1;

    projection <<
    0.07189, 0, -0.000333553, 0,
    0, 0.0479267, 2.74298e-05, 0,
    0, 0, -1, -248.452,
    0, 0, -1, 0;

    viewport << -1728.58, -2591.93, 1727.42, 2592.07;

    screenCoordinates << 1885.0, 1284.0;

    igl::unproject_onto_mesh(screenCoordinates, model, projection, viewport, vertexList, faceList,
                        faceId, baricentricCoordinate);

    return 0;
}

Ошибка:

libigl/external/eigen/Eigen/src/Core/PlainObjectBase.h:241: void Eigen::PlainObjectBase<Derived>::resize(Eigen::PlainObjectBase<Derived>::Index, Eigen::PlainObjectBase<Derived>::Index) [with Derived = Eigen::Matrix<double, 1, 3>; Eigen::PlainObjectBase<Derived>::Index = long int]: Assertion `(!(RowsAtCompileTime!=Dynamic) || (nbRows==RowsAtCompileTime)) && (!(ColsAtCompileTime!=Dynamic) || (nbCols==ColsAtCompileTime)) && (!(RowsAtCompileTime==Dynamic && MaxRowsAtCompileTime!=Dynamic) || (nbRows<=MaxRowsAtCompileTime)) && (!(ColsAtCompileTime==Dynamic && MaxColsAtCompileTime!=Dynamic) || (nbCols<=MaxColsAtCompileTime)) && nbRows>=0 && nbCols>=0 && "Invalid sizes when resizing a matrix or array."' failed.

Я пытался отследить стек вызовов, и кажется, что проблема связана с переменной "screenCoordinates", но я не совсем уверен, что я делаю неправильно. Ниже приведена информация об отладке, которая может быть полезна для понимания происходящего.

#0  Eigen::PlainObjectBase<Eigen::Matrix<float, 1, 3, 1, 1, 3> >::resize (this=0x7fff94fec5e0, rows=1, cols=3) at projection/../third_party/libigl/external/eigen/Eigen/src/Core/PlainObjectBase.h:281
#1  0x000000000040cdb9 in igl::unproject<Eigen::Matrix<float, 1, 3, 1, 1, 3>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::Matrix<float, 1, 3, 1, 1, 3> > (win=..., model=..., proj=..., viewport=..., scene=...) at projection/../third_party/libigl/include/igl/unproject.cpp:37
#2  0x000000000040ab8f in igl::unproject<Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> > (win=..., model=..., proj=..., viewport=..., scene=...) at projection/../third_party/libigl/include/igl/unproject.cpp:31
#3  0x0000000000408e6e in igl::unproject_ray<Eigen::Matrix<float, 2, 1, 0, 2, 1>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 4, 0, 4, 4>, Eigen::Matrix<float, 4, 1, 0, 4, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> > (pos=..., model=..., proj=..., viewport=..., s=..., dir=...) at projection/../third_party/libigl/include/igl/unproject_ray.cpp:34
#4  0x00000000004061be in igl::unproject_onto_mesh<Eigen::Matrix<float, 3, 1, 0, 3, 1> >(Eigen::Matrix<float, 2, 1, 0, 2, 1> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, std::function<bool (Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, Eigen::Matrix<float, 3, 1, 0, 3, 1> const&, igl::Hit&)> const&, int&, Eigen::PlainObjectBase<Eigen::Matrix<float, 3, 1, 0, 3, 1> >&) (pos=..., model=..., proj=..., viewport=..., shoot_ray=..., fid=@0x7fff94fec90c: -992472433, bc=...) at projection/../third_party/libigl/include/igl/unproject_onto_mesh.cpp:61
#5  0x00000000004051c9 in igl::unproject_onto_mesh<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<float, 3, 1, 0, 3, 1> > (pos=..., model=..., proj=..., viewport=..., V=..., F=..., fid=@0x7fff94fec90c: -992472433, bc=...) at projection/../third_party/libigl/include/igl/unproject_onto_mesh.cpp:40
#6  0x0000000000403adb in main_tmp (argc=4, argv=0x7fff94feced8) at projection/src/main.cpp:55
#7  0x0000000000403c5a in main (argc=4, argv=0x7fff94feced8) at projection/src/main.cpp:62
#8  0x00007fa68746f830 in __libc_start_main (main=0x403c1c <main(int, char**)>, argc=4, argv=0x7fff94feced8, init=<optimised out>, fini=<optimised out>, rtld_fini=<optimised out>, stack_end=0x7fff94fecec8) at ../csu/libc-start.c:291
#9  0x00000000004032f9 in _start ()
...