Git Product home page Git Product logo

Comments (6)

ShihaoWang avatar ShihaoWang commented on August 26, 2024 1

Never mind, I guess that I have already figured it out with the modification of the input options to the ConvexHull3f constructor. If I set the simplicial_facets to be false and the merge_tol to be a reasonable tolerance, the coplanar issue is addressed effectively.

from cilantro.

kzampog avatar kzampog commented on August 26, 2024

That sounds right!

If all your points are known to lie on a plane, you could consider having a look at FlatConvexHull3, which computes the 2D convex hull of a PCA projection.

from cilantro.

ShihaoWang avatar ShihaoWang commented on August 26, 2024

Thanks for the reply. Can I ask one more question? The mentioned approach can compute the convex hull for 3D data points with coplanar points inside. However, when I want to show the visualization of this convex hull, a memory leakage or double delete error is triggered.

*** Error in `/home/shihao/Desktop/Humanoid-and-RMP/build/MyApp': invalid fastbin entry (free): 0x00000000030e75a0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7ffff384f7e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x8037a)[0x7ffff385837a]
/lib/x86_64-linux-gnu/libc.so.6(+0x82d52)[0x7ffff385ad52]
/lib/x86_64-linux-gnu/libc.so.6(posix_memalign+0x11d)[0x7ffff385f71d]
/home/shihao/cilantro/build/libcilantro.so(_ZN8cilantro8colormapIfEEN5Eigen6MatrixIfLi3ELin1ELi0ELi3ELin1EEERKNS_18ConstDataMatrixMapIT_Ll1EEERKNS_12ColormapTypeES5_S5_+0x10b)[0x7ffff48cc4fb]
/home/shihao/cilantro/build/libcilantro.so(_ZN8cilantro22TriangleMeshRenderable16updateGPUBuffersERNS_16GPUBufferObjectsE+0x125e)[0x7ffff48cb30e]
/home/shihao/cilantro/build/libcilantro.so(_ZN8cilantro10Visualizer6renderEv+0x425)[0x7ffff48c1cf5]
/home/shihao/cilantro/build/libcilantro.so(_ZN8cilantro10Visualizer8spinOnceEv+0x11)[0x7ffff48c1e31]
/home/shihao/cilantro/build/libcilantro.so(_ZN8cilantro10Visualizer4spinEv+0x18)[0x7ffff48c1e58]
/home/shihao/Desktop/Humanoid-and-RMP/build/MyApp(_Z19ConvxHullGenerationRKSt6vectorIN6Math3D7Vector3ESaIS1_EE+0xfea)[0x59887a]
/home/shihao/Desktop/Humanoid-and-RMP/build/MyApp(main+0x63d)[0x57cf3d]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7ffff37f8830]
/home/shihao/Desktop/Humanoid-and-RMP/build/MyApp(_start+0x29)[0x580a29]

After the debug, I find that the code that causes this error is actually viz.spin . Is there sth I can do to solve this problem?

My whole code is

void ConvxHullGeneration(const std::vector<Vector3>& _SPVertices)
{
  // This function is used to generate the convex hull given the vertices
  std::vector<Eigen::Vector3f> Vertices;
  for (int i = 0; i < _SPVertices.size(); i++)
  {
    Vertices.emplace_back(_SPVertices[i].x,_SPVertices[i].y,_SPVertices[i].z);
  }
  Vertices.emplace_back(0, 0, 1);

  cilantro::PointCloud3f cloud(Vertices);
  cilantro::ConvexHull3f ch(cloud.points, true, false, eps_dist);
  cilantro::PointCloud3f hull_cloud(cloud, ch.getVertexPointIndices());

  cilantro::VectorSet3f vertex_colors(3, ch.getVertices().cols());
  std::vector<float> vertex_values(ch.getVertices().cols());
  for (size_t i = 0; i < ch.getVertices().cols(); i++) {
      if (i%3 == 0) vertex_colors.col(i) = Eigen::Vector3f(1,0,0);
      if (i%3 == 1) vertex_colors.col(i) = Eigen::Vector3f(0,1,0);
      if (i%3 == 2) vertex_colors.col(i) = Eigen::Vector3f(0,0,1);
      vertex_values[i] = ch.getVertices().col(i).norm();
  }

  std::cout<<ch.getFacetVertexIndices().size()<<endl;
  cilantro::VectorSet3f face_colors(3, ch.getFacetVertexIndices().size());
  std::vector<float> face_values(ch.getFacetVertexIndices().size());
  for (size_t i = 0; i < ch.getFacetVertexIndices().size(); i++) {
      if (i%3 == 0) face_colors.col(i) = Eigen::Vector3f(1,0,0);
      if (i%3 == 1) face_colors.col(i) = Eigen::Vector3f(0,1,0);
      if (i%3 == 2) face_colors.col(i) = Eigen::Vector3f(0,0,1);
      face_values[i] = (ch.getVertices().col(ch.getFacetVertexIndices()[i][0]) +
                   ch.getVertices().col(ch.getFacetVertexIndices()[i][1]) +
                   ch.getVertices().col(ch.getFacetVertexIndices()[i][2])).rowwise().mean().norm();
  }

  cilantro::Visualizer viz("3D convex hull", "disp");
  viz.addObject<cilantro::PointCloudRenderable>("cloud", cloud, cilantro::RenderingProperties().setOpacity(1.0));
  viz.addObject<cilantro::TriangleMeshRenderable>("mesh", ch.getVertices(), ch.getFacetVertexIndices())
          ->setVertexNormals(hull_cloud.normals).setVertexColors(vertex_colors).setVertexValues(vertex_values)
           .setFaceColors(face_colors).setFaceValues(face_values);

  cilantro::RenderingProperties rp = viz.getRenderingProperties("mesh");
  rp.setUseFaceNormals(true).setUseFaceColors(false).setOpacity(0.8).setColormapType(cilantro::ColormapType::BLUE2RED);
  viz.setRenderingProperties("mesh", rp);

  viz.spin();
  return;
}

from cilantro.

kzampog avatar kzampog commented on August 26, 2024

I think this is due to a Visualizer limitation. At the moment, it can only render triangle meshes.

The code above sets the simplicial_facets parameter to false, so computed faces are not guaranteed to be triangles.

Would simplicial_facets = true with a reasonable merge_tol produce a reasonable (and visualizable) result?

from cilantro.

ShihaoWang avatar ShihaoWang commented on August 26, 2024

Yeah, this will yield a correct visualization but facet with more than 3 vertices are not merged.
I think that my solution is that if I want to have a visualization result, I can set the simplicial_facets to true and if I just want to have facets without duplicative sub-facets, I can set the simplicial_facets to false.

from cilantro.

kzampog avatar kzampog commented on August 26, 2024

Sounds good! I should then just add some polygon mesh rendering capabilities at some point :)

from cilantro.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.