void MeshData::triangulate(int idx) { auto copy0 = std::unique_ptr<Surface_mesh> {new Surface_mesh(get_mesh(0))}; auto copy1 = std::unique_ptr<Surface_mesh> {new Surface_mesh(get_mesh(1))}; qDebug() << "Triangulating mesh" << idx; if (idx == 0) { copy0->triangulate(); } else { copy1->triangulate(); } history_push({std::move(copy0), std::move(copy1)}); emit_updated_signal(); }
void ofxDelaunay::setPointAtIndex(ofPoint p, int index){ if (index >= 0 && index < vertices.size()){ XYZI pp; pp.x = p.x; pp.y = p.y; pp.z = p.z; pp.i = index; vertices[index] = pp; } triangulate(); }
void SoftwareRendererImp::draw_polygon(Polygon& polygon) { Color c; // draw fill c = polygon.style.fillColor; if (c.a != 0) { // triangulate vector < Vector2D > triangles; triangulate(polygon, triangles); // draw as triangles for (size_t i = 0; i < triangles.size(); i += 3) { Vector2D p0 = transform(triangles[i + 0]); Vector2D p1 = transform(triangles[i + 1]); Vector2D p2 = transform(triangles[i + 2]); rasterize_triangle(p0.x, p0.y, p1.x, p1.y, p2.x, p2.y, c); } } // draw outline c = polygon.style.strokeColor; if (c.a != 0) { int nPoints = polygon.points.size(); for (int i = 0; i < nPoints; i++) { Vector2D p0 = transform(polygon.points[(i + 0) % nPoints]); Vector2D p1 = transform(polygon.points[(i + 1) % nPoints]); rasterize_line(p0.x, p0.y, p1.x, p1.y, c); } } }
// Triangulate a polygon void glc::triangulate(QList<GLC_Point2d>& polygon, QList<int>& index, QList<int>& tList) { const int size= polygon.size(); if (size == 3) { tList << index[0] << index[1] << index[2]; return; } int i0= 0; int i1= 1; int i2= 2; while(i0 < size) { if (isDiagonal(polygon, i0, i2)) { // Add the triangle before removing the ear. tList << index[i0] << index[i1] << index[i2]; // Remove the ear from polygon and index lists polygon.removeAt(i1); index.removeAt(i1); // recurse to the new polygon triangulate(polygon, index, tList); return; } ++i0; i1= (i1 + 1) % size; i2= (i2 + 1) % size; } }
QModelIndex cast( NifModel * nif, const QModelIndex & index ) { QModelIndex iData = getShapeData( nif, index ); QVector<Vector3> verts = nif->getArray<Vector3>( iData, "Vertices" ); QVector<Triangle> triangles; QModelIndex iPoints = nif->getIndex( iData, "Points" ); if ( iPoints.isValid() ) { QList< QVector< quint16 > > strips; for ( int r = 0; r < nif->rowCount( iPoints ); r++ ) strips.append( nif->getArray<quint16>( iPoints.child( r, 0 ) ) ); triangles = triangulate( strips ); } else { triangles = nif->getArray<Triangle>( iData, "Triangles" ); } QVector<Vector3> norms( verts.count() ); foreach ( Triangle tri, triangles ) { Vector3 a = verts[ tri[0] ]; Vector3 b = verts[ tri[1] ]; Vector3 c = verts[ tri[2] ]; Vector3 fn = Vector3::crossproduct( b - a, c - a ); norms[ tri[0] ] += fn; norms[ tri[1] ] += fn; norms[ tri[2] ] += fn; }
/* triangulate: * Triangulates the given polygon. * Throws an exception if no diagonal exists. */ static void triangulate(Ppoint_t ** pointp, int pointn, void (*fn) (void *, Ppoint_t *), void *vc) { int i, ip1, ip2, j; Ppoint_t A[3]; if (pointn > 3) { for (i = 0; i < pointn; i++) { ip1 = (i + 1) % pointn; ip2 = (i + 2) % pointn; if (dpd_isdiagonal(i, ip2, pointp, pointn)) { A[0] = *pointp[i]; A[1] = *pointp[ip1]; A[2] = *pointp[ip2]; fn(vc, A); j = 0; for (i = 0; i < pointn; i++) if (i != ip1) pointp[j++] = pointp[i]; triangulate(pointp, pointn - 1, fn, vc); return; } } longjmp(jbuf,1); } else { A[0] = *pointp[0]; A[1] = *pointp[1]; A[2] = *pointp[2]; fn(vc, A); } }
int main(int argc, char *argv[]) { QApplication a(argc, argv); DrawingArea *area = new DrawingArea(); QPushButton *triangualteBut = new QPushButton(); triangualteBut->setText("Triangulate"); QVBoxLayout *lay = new QVBoxLayout(); lay->addWidget(area); //lay->addWidget(triangualteBut); QWidget window; window.setLayout(lay); window.show(); Triangulator *t = new Triangulator(area); QObject::connect(triangualteBut,SIGNAL(clicked()),t,SLOT(triangulate())); t->triangulate(); return a.exec(); }
void EditorPoint::onUpdate(unsigned int p_timeElapsed) { setMinAndMaxShiftPoint(m_impl->m_selectedIndex); if (m_impl->m_selectedIndex >= 0 && (m_ctrl || m_alt)) { int set = 0; bool isSet = false; if (isSecondKey(CL_KEY_ADD)) { set = 1; isSet = true; } else if (isSecondKey(CL_KEY_SUBTRACT)) { set = -1; isSet = true; } if (isSet) { if (m_alt) set *= 2; setRadius(m_impl->m_selectedIndex, set); triangulate(m_impl->m_selectedIndex, false); } } }
void PointCloud::initPointGraph(double distance_threshold) { if (distance_threshold == point_graph_threshold_ && boost::num_edges(*point_graph_) != 0) return; triangulate(); point_graph_threshold_ = distance_threshold; boost::PointGraph& g_point = *point_graph_; g_point = boost::PointGraph(points_num_); size_t t = 8; for (CGAL::Delaunay::Finite_edges_iterator it = triangulation_->finite_edges_begin(); it != triangulation_->finite_edges_end(); ++ it) { const CGAL::Delaunay::Cell_handle& cell_handle = it->first; const CGAL::Delaunay::Vertex_handle& source_handle = cell_handle->vertex(it->second); const CGAL::Delaunay::Vertex_handle& target_handle = cell_handle->vertex(it->third); double distance_L1 = std::sqrt(CGAL::squared_distance(source_handle->point(), target_handle->point())); if (distance_L1 > point_graph_threshold_) continue; size_t source_id = source_handle->info(); size_t target_id = target_handle->info(); assert (source_id < points_num_ && target_id < points_num_); WeightedEdge weighted_edge(distance_L1); boost::add_edge(source_id, target_id, weighted_edge, g_point); } return; }
void init_star_mesh(GLShape& mesh) { Vector2 center(0.0f, 0.2f); std::vector<Vector2> shape = circle(center, 0.2f, 16); for (int i = 1; i < 16; i+=2) { shape[i] += 0.5f * (center - shape[i]); } mesh = to_xy(triangulate(shape)); }
void ofxDelaunay::setPointAtIndex(ofPoint p, int index,bool shouldTriangulate){ if (index >= 0 && index < vertices.size()){ XYZI pp; pp.x = p.x+ ofRandom(0.01); pp.y = p.y; pp.z = p.z; pp.i = index; vertices[index] = pp; } if(shouldTriangulate)triangulate(); }
void pcl::EarClipping::performProcessing (PolygonMesh& output) { output.polygons.clear (); output.cloud = input_mesh_->cloud; for (int i = 0; i < (int) input_mesh_->polygons.size (); ++i) triangulate (input_mesh_->polygons[i], output); }
// --- Construction and Destruction ---------------------------------------- // /// Creates a new delaunay triangulation for \p points. DelaunayTriangulation::DelaunayTriangulation(const std::vector<Point3> &points) : d(new DelaunayTriangulationPrivate) { d->vertices = points; d->alphaShapeCalculated = false; triangulate(false); }
void VoronoiSegment:: discretize( NodeMap& fixedNodes, NodeMap& allNodes, std::list< Element* >& allElements ) { triangulate(); removeBoundaryConnectors(); generate(); exportNodes( allNodes, allElements ); }
void triangulate(PolygonMesh& output) { output.polygons.clear(); output.cloud = polygon_->cloud; for (int i = 0; i < polygon_->polygons.size(); ++i) { triangulate(polygon_->polygons[i], output); } }
void ofxDelaunayExtra::triangulateExtra(vector<ofVec2f*>& pts) { reset(); for(int i=0; i < pts.size(); i++){ addPoint(pts[i]->x, pts[i]->y); } triangulate(); }
void VisualOdometry::confirmTrials() { // empty check if (trials.empty()) return; // triangulate landmarks // prepare points cv::Mat pts1(2, trials.size(), cv::DataType<float>::type), pts2(2, trials.size(), cv::DataType<float>::type); int col = 0; for (auto it = trials.begin(); it != trials.end(); it++) { cv::KeyPoint k1, k2; it->firstPointPair(k1, k2); pts1.at<float>(0, col) = k1.pt.x; pts1.at<float>(1, col) = k1.pt.y; pts2.at<float>(0, col) = k2.pt.x; pts2.at<float>(1, col) = k2.pt.y; col++; } cv::Mat pts3D; triangulate(pts1, pts2, pts3D); // convert to world coordinate int sframe = trials.back().getStartFrame(); cv::Mat posR, posT; graph.getPose(sframe, posR, posT); cv::Mat posRT = fullRT(posR, posT); pts3D = posRT * pts3D; int colcount = 0; for (auto it = trials.begin(); it != trials.end(); it++) { // add location to landmark data structure cv::Point3f p = cv::Point3f(pts3D.at<float>(0, colcount), pts3D.at<float>(1, colcount), pts3D.at<float>(2, colcount)); it->setLocation(p); colcount++; // add initial value of land mark to factor graph data structure graph.addLandMark(landmarkID, p); // move from trail to true landmarks landmarks[landmarkID] = *it; // add factors int curframe = it->getStartFrame(); for (int i = 0; i < it->getTraceSize(); i++) { cv::KeyPoint p1, p2; it->getPointPair(i, p1, p2); graph.addStereo(curframe, landmarkID, p1.pt, p2.pt); curframe++; } landmarkID++; } trials.clear(); }
boost::python::numeric::array pypolyhedron::py_get_triangles(){ polyhedron tri = triangulate(); boost::python::list tmp; for( int i=0; i<tri.num_faces(); i++ ){ int vtx_id[3]; tri.get_face_vertices( i, vtx_id ); tmp.append( boost::python::make_tuple( vtx_id[0], vtx_id[1], vtx_id[2] ) ); } return boost::python::numeric::array( tmp ); }
InteractionGraph get_triangulated(const InteractionGraph &ig) { InteractionGraph cig; boost::copy_graph(ig, cig); /*std::cout << "Input graph is " << std::endl; IMP::internal::show_as_graphviz(ig, std::cout);*/ triangulate(cig); IMP_LOG_VERBOSE("Triangulated graph is " << std::endl); IMP_LOG_WRITE(VERBOSE, show_as_graphviz(cig, IMP_STREAM)); return cig; }
xtTrianglePLSG::xtTrianglePLSG( std::vector<xtTriPnt2> &verts, std::vector<xtSeg2WithMarker> &segs, std::vector<xtTriIndexO> &tris) { mIn = new triangulateio; mOut = new triangulateio; mIn->numberofpoints = verts.size(); mIn->numberofpointattributes = 0; mIn->pointlist = (REAL *) malloc (mIn->numberofpoints *2 *sizeof(REAL)); for ( int nodeidx=0; nodeidx<mIn->numberofpoints; ++nodeidx ) { mIn->pointlist[nodeidx*2] = verts[nodeidx].p[0]; mIn->pointlist[nodeidx*2+1] = verts[nodeidx].p[1]; } mIn->numberofsegments = segs.size(); mIn->segmentlist = (int*) malloc(mIn->numberofsegments*2*sizeof(int)); mIn->segmentmarkerlist = (int*) malloc(mIn->numberofsegments*sizeof(int)); for ( int segidx=0; segidx<mIn->numberofsegments; ++segidx ) { mIn->segmentlist[2*segidx] = segs[segidx].seg[0]; mIn->segmentlist[2*segidx+1] = segs[segidx].seg[1]; mIn->segmentmarkerlist[segidx] = segs[segidx].marker; } mIn->numberofholes = 0; mIn->holelist = (REAL*)NULL; mIn->numberofregions = 0; mIn->pointmarkerlist = (int*) NULL; mOut->pointlist = (REAL*)NULL; mOut->pointmarkerlist = (int*) NULL; mOut->trianglelist = (int*) NULL; mOut->segmentlist = (int*) NULL; mOut->segmentmarkerlist = (int*) NULL; std::string paras = "pzQ"; triangulate(const_cast<char *>(paras.c_str()), mIn, mOut, (struct triangulateio*) NULL); report(mOut,1, 1, 0, 0, 0, 0); xtTriIndexO tri; for ( int triidx=0; triidx<mOut->numberoftriangles; ++triidx ) { for ( int i=0; i<3; ++i ) { tri.idx[i] = mOut->trianglelist[3*triidx+i]; } tris.push_back(tri); } //report(mIn,0, 1, 0, 1, 0, 0); }
void init_decal_mesh(GLShape& mesh) { float x0 = 0.05f; float y0 = 0.023f; Vector2 p0(-x0, 0.0f); Vector2 p1(x0, 0.0f); Vector2 p2(x0, y0); Vector2 p3(-x0, y0); mesh = to_xy(triangulate({p0, p1, p2, p3})); }
void GeomPerfectMatching::InitDelaunay() { if (node_num < 16) return; if (options.verbose) printf("adding edges in Delaunay triangulation\n"); int k; struct triangulateio in, out, vorout; in.numberofpoints = node_num; in.numberofpointattributes = 0; in.pointlist = (REAL *) malloc(in.numberofpoints * 2 * sizeof(REAL)); for (k=0; k<2*node_num; k++) in.pointlist[k] = coords[k]; in.pointattributelist = NULL; in.pointmarkerlist = NULL; in.numberofsegments = 0; in.numberofholes = 0; in.numberofregions = 0; in.regionlist = 0; out.pointlist = (REAL *) NULL; out.pointattributelist = (REAL *) NULL; out.pointmarkerlist = (int *) NULL; out.trianglelist = (int *) NULL; out.triangleattributelist = (REAL *) NULL; out.neighborlist = (int *) NULL; out.segmentlist = (int *) NULL; out.segmentmarkerlist = (int *) NULL; out.edgelist = (int *) NULL; out.edgemarkerlist = (int *) NULL; vorout.pointlist = (REAL *) NULL; vorout.pointattributelist = (REAL *) NULL; vorout.edgelist = (int *) NULL; vorout.normlist = (REAL *) NULL; triangulate("pczAevn", &in, &out, &vorout); free(in.pointlist); free(out.pointlist); free(out.pointmarkerlist); free(out.trianglelist); free(out.neighborlist); free(out.segmentlist); free(out.segmentmarkerlist); free(out.edgemarkerlist); free(vorout.pointlist); free(vorout.pointattributelist); free(vorout.edgelist); free(vorout.normlist); for (k=0; k<out.numberofedges; k++) AddInitialEdge(out.edgelist[2*k], out.edgelist[2*k+1]); free(out.edgelist); }
/// Use geometry of the views to compute a putative structure from features and descriptors. void run( SfM_Data & sfm_data, const Pair_Set & pairs, const std::shared_ptr<Regions_Provider> & regions_provider) { sfm_data.structure.clear(); match(sfm_data, pairs, regions_provider); filter(sfm_data, pairs, regions_provider); triangulate(sfm_data, regions_provider); }
Triangles & EdgeCell::triangles(Time time) { int nSixtiethOfFrame = std::floor(time.floatTime() * 60 + 0.5); if(!triangles_.contains(nSixtiethOfFrame)) { triangles_[nSixtiethOfFrame] = Triangles(); triangulate(time, triangles_[nSixtiethOfFrame]); } return triangles_[nSixtiethOfFrame]; }
/** Extract rotation (R) and translation (t) from a given essential matrix and triangulate feature matches. * @param Eigen::Matrix3f essential matrix * @param std::vector<Match> vector with matches * @param Eigen::Matrix3f output rotation matrix * @param Eigen::Vector3f output translation vector * @param Eigen::Matrix<float, 4, Eigen::Dynamic> output matrix with computed 3D points * @return void */ void MonoOdometer5::E2Rt(Eigen::Matrix3f E, std::vector<Match> matches, Eigen::Matrix3f &R, Eigen::Vector3f &t, Eigen::Matrix<float, 4, Eigen::Dynamic> &points3D) { Eigen::Matrix3f W, Z; W << 0, -1, 0, 1, 0, 0, 0, 0, 1; Z << 0, 1, 0, -1, 0, 0, 0, 0, 0; // singular values decomposition of E Eigen::JacobiSVD<Eigen::Matrix3f> svdE(E, Eigen::ComputeFullU | Eigen::ComputeFullV); // get skew symmetric matrix of translation vector Eigen::Matrix3f S = svdE.matrixU() * Z * (svdE.matrixU()).transpose(); // get possible rotation matrices Eigen::Matrix3f Ra = svdE.matrixU() * W * (svdE.matrixV()).transpose(); Eigen::Matrix3f Rb = svdE.matrixU() * W.transpose() * (svdE.matrixV()).transpose(); // get translation vetor from skew symmetric matrix t << S(2, 1), S(0, 2), S(1, 0); // correct signal of both rotation matrices if(Ra.determinant() < 0) { Ra = -Ra; } if(Rb.determinant() < 0) { Rb = -Rb; } // 4 possible combinations of R,t std::vector<Eigen::Matrix3f> solutionsR; std::vector<Eigen::Vector3f> solutionst; solutionsR.push_back(Ra); solutionst.push_back(t); solutionsR.push_back(Ra); solutionst.push_back(-t); solutionsR.push_back(Rb); solutionst.push_back(t); solutionsR.push_back(Rb); solutionst.push_back(-t); // test Chirality constraint for all 4 solutions Eigen::Matrix<float, 4, Eigen::Dynamic> points3DCurr; int maxInliers = 0; for(int i=0; i<4; i++) { int nInliers = triangulate(matches, solutionsR[i], solutionst[i], points3DCurr); // solution with the most inliers wins if(nInliers > maxInliers) { maxInliers = nInliers; points3D = points3DCurr; R = solutionsR[i]; t = solutionst[i]; } } }
meteorite_t::meteorite_t(const vec2& pos, const vec2& size, std::shared_ptr<physics::world_t> world) : physic_element_if(pos, size, world), is_descedant(false) { set_collision_group(physics::COLLISION_GROUP_2); std::uniform_int_distribution<size_t> verices_count_roll(7, 23); size_t verices_count = verices_count_roll(my_random_generator()); auto polygon = polygon_t::create_random(verices_count, vec2(100, 100)); _vertices = polygon.triangulate(); }
void Surface_mesh:: triangulate() { /* The iterators will stay valid, even though new faces are added, because they are now implemented index-based instead of pointer-based. */ Face_iterator fit=faces_begin(), fend=faces_end(); for (; fit!=fend; ++fit) triangulate(fit); }
void init_indicator_mesh(GLShape& mesh) { float x0 = 0.05f; float y0 = 0.1f; float y1 = 0.15f; Vector2 p0(0.0f, 0.0f); Vector2 p1(x0, y1); Vector2 p2(0.0f, y0); Vector2 p3(-x0, y1); mesh = to_xy(triangulate({p0, p1, p2, p3})); }
void EditorPoint::onHandleInput() { if (isFirstKey(CL_MOUSE_LEFT)) { if (m_impl->m_state == EditorPointImpl::Point) { m_impl->m_selectedIndex = m_impl->m_lightIndex; } else { m_impl->m_selectedIndex = m_impl->m_lightIndex = -1; } } else if (isFirstKey(CL_KEY_DELETE) || isFirstKey(CL_KEY_D)) { if (m_impl->m_selectedIndex >= 0 && m_track.getPointCount() > 3) { m_track.removePoint(m_impl->m_selectedIndex); m_impl->m_selectedIndex -= 1; if (m_impl->m_selectedIndex < 0) m_impl->m_selectedIndex = m_track.getPointCount() - 1; triangulate(m_impl->m_selectedIndex, true); } } else if (isFirstKey(CL_MOUSE_MIDDLE) || (isFirstKey(CL_KEY_CONTROL) && isSecondKey(CL_MOUSE_LEFT))) { int index = 0; if (m_impl->m_selectedIndex >= 0 && m_impl->m_selectedIndex < m_track.getPointCount()) index = ++m_impl->m_selectedIndex; else index = m_impl->m_selectedIndex = m_track.getPointCount(); m_track.addPoint(m_mousePos, DEFAULT_RADIUS, DEFAULT_SHIFT, index); triangulate(m_impl->m_selectedIndex, true); } }
void OffLoader::loadFile(QString fileName) throw(std::logic_error, std::ios_base::failure) { _fileLoaded=fileName; double vertexNumber, polygonNumber; QFile file(fileName); QString line; QStringList stringList; QTextStream textStream(&file); //First, we try to open the file given in parameter if(!file.open(QIODevice::ReadOnly | QIODevice::Text)) throw std::ios_base::failure("Cannot open file"); else{ line = textStream.readLine(); //We check that the file given in parameter is //in the off format. if(line.toLower() != "off") { file.close(); throw std::logic_error("The file is not in the off format."); } //Reading the number of vertexes and triangles. stringList = readLine(textStream); vertexNumber=stringList[0].toDouble(); polygonNumber=stringList[1].toDouble(); //Reading and adding vertexes of the mesh. for(double i=0; i<vertexNumber; ++i) { stringList = readLine(textStream); this->addVertex(stringList[0].toDouble(), stringList[1].toDouble(), stringList[2].toDouble()); } //Reading and adding triangles of the mesh. for(double i=0;i<polygonNumber; ++i) { stringList=readLine(textStream); QList<int> vertices; Color color; for (unsigned int j =1;j<=stringList[0].toInt();++j) vertices.push_back(stringList[j].toInt()); for (unsigned int j =stringList[0].toInt()+1;j<stringList.size();++j) color.push_back(stringList[j].toFloat()); triangulate(vertices,color); } file.close(); this->computeNormalsT(); this->computeNormalsV(); this->normalize(); } }