Sphere::Sphere( float radius, unsigned tesselationLevel, D3D::GraphicDevice device, float freq, const Material& material ) : device_(device), vertexDeclaration_(device, DefaultVertexDeclaration), vertexBuffer_(device), indexBuffer_(device), shader_(device, L"sphere.vsh"), radius_(radius), tesselationLevel_(tesselationLevel), freq_(freq), material_(material) { Vertices vertices; Indices indices; InitVertices(tesselationLevel, radius*sqrtf(2), vertices, indices); nVertices_ = vertices.size(); nPrimitives_ = indices.size()/3; vertexBuffer_.SetVertices( &vertices[0], vertices.size() ); indexBuffer_.SetIndices( &indices[0], indices.size() ); SetPositionMatrix( UnityMatrix() ); SetViewMatrix( UnityMatrix() ); SetProjectiveMatrix( UnityMatrix() ); }
void color_sort(Vertices &R){ int j = 0, maxno = 1, min_k = max((int)QMAX.size() - (int)Q.size() + 1, 1); C[1].clear(), C[2].clear(); for(int i = 0; i < (int)R.size(); i++) { int pi = R[i].i, k = 1; while(cut1(pi, C[k])) k++; if(k > maxno) maxno = k, C[maxno + 1].clear(); C[k].push_back(pi); if(k < min_k) R[j++].i = pi; } if(j > 0) R[j - 1].d = 0; for(int k = min_k; k <= maxno; k++) for(int i = 0; i < (int)C[k].size(); i++) R[j].i = C[k][i], R[j++].d = k; }
bool SpatialModelMaximalRepulsion3D<CoordType>::checkHardcoreDistances( const Vector<CoordType>& vertex, const int v, const Vertices<CoordType>& vertices) const { const Vector<CoordType>& hardcoreDistances = this->getHardcoreDistances(); Vector<CoordType> triMeshVertex; if ( this->getTriMeshQuery().closestPoint(vertex,triMeshVertex) < hardcoreDistances[v] ) return false; for (int i = 0; i < vertices.getNumVertices(); ++i) if ( i != v && vertices[i].distance(vertex) < hardcoreDistances[i] + hardcoreDistances[v] ) return false; return true; }
bool BufferPrograms::insert(Vertices &vertices) { SCOPE_profile_cpu_function("RenderTimer"); if (vertices.nbr_buffer() != _types.size()) { return (false); } for (auto index = 0ull; index < vertices.nbr_buffer(); ++index) { if (_types[index] != vertices.get_type(index)) { return (false); } } for (auto &buffer_targeted : _buffers) { vertices.set_block_memory(buffer_targeted->push_back(vertices.transfer_data(buffer_targeted->name())), buffer_targeted->name()); } vertices.set_indices_block_memory(_indices_buffer.push_back(vertices.transfer_indices_data())); return (true); }
void writeToLog(Logging::Log* plog) { std::stringstream logmessage; using std::endl; using std::cout; logmessage << "MeshData:: " << std::endl << "Vertices : " << std::endl; for (int i = 0; i < m_Vertices.size(); i++) { logmessage << i << ": " << m_Vertices[i] << endl; } logmessage << "Indices & Normals : " << endl; for (int i = 0; i < m_Faces.size(); i++) { logmessage << i << ": " << m_Faces[i] << "\t n:" << m_Normals[i] << std::endl; } plog->logMessage(logmessage.str()); };
/** * Add all the outgoing edges from the vertex v to the horizon edges. * Also, update the conflict graph for the newly added faces. */ void addCone(Arrangement &arr, Vertex *v, Edges &horizon, Vertices &vertices) { int n = horizon.size(); Edges spokes1; Edges spokes2; for (int i = 0; i < n; ++i) { Edge *e0 = horizon[i]; Edge *e1 = arr.addHalfEdge(e0->tail, NULL, NULL, false); e1->id = edge_id++; Edge *e2 = arr.addHalfEdge(v, NULL, NULL, false); e2->id = edge_id++; e1->twin = e2; e2->twin = e1; spokes1.push_back(e1); spokes2.push_back(e2); } // order the edges around the vertex, i.e. set the next pointer correctly for (int i = 0; i < n; ++i) { Edge *e = horizon[i]; e->twin->next = spokes1[(i + 1) % n]; spokes1[i]->next = e; spokes2[i]->next = spokes2[(i - 1 + n) % n]; } // Add the corresponding faces for (int i = 0; i < n; ++i) { Face *f = new Face; arr.faces.push_back(f); f->id = face_id++; arr.addBoundary(horizon[i], f); // Also, update the conflict graph for added faces. for (int j = 0; j < vertices.size(); ++j) { if (f->visible(vertices[j])) { f->visibleVertices.push_back(vertices[j]); vertices[j]->visibleFaces.push_back(f); } } } }
/** * List up all the vertices that have to be tested for the conflict graph. */ void listUpdateVertices(Arrangement &arr, Vertex *v, Edges &horizon, Vertices &vertices) { map<Vertex*, bool> hashtable; for (int i = 0; i < horizon.size(); ++i) { Face* f1 = horizon[i]->face; Face* f2 = horizon[i]->twin->face; for (int j = 0; j < f1->visibleVertices.size(); ++j) { if (f1->visibleVertices[j] != v) { hashtable[f1->visibleVertices[j]] = true; } } for (int j = 0; j < f2->visibleVertices.size(); ++j) { if (f2->visibleVertices[j] != v) { hashtable[f2->visibleVertices[j]] = true; } } } for (map<Vertex*, bool>::iterator it = hashtable.begin(); it != hashtable.end(); ++it) { vertices.push_back((*it).first); } }
void expand_dyn(Vertices &R){// diff -> diff with no dyn S[level].i1 = S[level].i1 + S[level - 1].i1 - S[level].i2;//diff S[level].i2 = S[level - 1].i1;//diff while((int)R.size()) { if((int)Q.size() + R.back().d > (int)QMAX.size()){ Q.push_back(R.back().i); Vertices Rp; cut2(R, Rp); if((int)Rp.size()){ if((float)S[level].i1 / ++pk < Tlimit) degree_sort(Rp);//diff color_sort(Rp); S[level].i1++, level++;//diff expand_dyn(Rp); level--;//diff } else if((int)Q.size() > (int)QMAX.size()) QMAX = Q; Q.pop_back(); } else return; R.pop_back(); } }
void gnuplot_print_vertices(std::ostream& out, const Vertices& vertices) { for (Vertex_iterator it = vertices.begin(); it != vertices.end(); ++it) out << (*it) << " " << it->unique_id() << endl; }
void QTessellatorPrivate::addIntersection(const Edge *e1, const Edge *e2) { const IntersectionLink emptyLink = {-1, -1}; int next = vertices.nextPos(vertices[e1->edge]); if (e2->edge == next) return; int prev = vertices.prevPos(vertices[e1->edge]); if (e2->edge == prev) return; Q27Dot5 yi; bool det_positive; bool isect = e1->intersect(*e2, &yi, &det_positive); QDEBUG("checking edges %d and %d", e1->edge, e2->edge); if (!isect) { QDEBUG() << " no intersection"; return; } // don't emit an intersection if it's at the start of a line segment or above us if (yi <= y) { if (!det_positive) return; QDEBUG() << " ----->>>>>> WRONG ORDER!"; yi = y; } QDEBUG() << " between edges " << e1->edge << "and" << e2->edge << "at point (" << Q27Dot5ToDouble(yi) << ')'; Intersection i1; i1.y = yi; i1.edge = e1->edge; IntersectionLink link1 = intersections.value(i1, emptyLink); Intersection i2; i2.y = yi; i2.edge = e2->edge; IntersectionLink link2 = intersections.value(i2, emptyLink); // new pair of edges if (link1.next == -1 && link2.next == -1) { link1.next = link1.prev = i2.edge; link2.next = link2.prev = i1.edge; } else if (link1.next == i2.edge || link1.prev == i2.edge || link2.next == i1.edge || link2.prev == i1.edge) { #ifdef DEBUG checkLinkChain(intersections, i1); checkLinkChain(intersections, i2); Q_ASSERT(edgeInChain(i1, i2.edge)); #endif return; } else if (link1.next == -1 || link2.next == -1) { if (link2.next == -1) { qSwap(i1, i2); qSwap(link1, link2); } Q_ASSERT(link1.next == -1); #ifdef DEBUG checkLinkChain(intersections, i2); #endif // only i2 in list link1.next = i2.edge; link1.prev = link2.prev; link2.prev = i1.edge; Intersection other; other.y = yi; other.edge = link1.prev; IntersectionLink link = intersections.value(other, emptyLink); Q_ASSERT(link.next == i2.edge); Q_ASSERT(link.prev != -1); link.next = i1.edge; intersections.insert(other, link); } else { bool connected = edgeInChain(i1, i2.edge); if (connected) return; #ifdef DEBUG checkLinkChain(intersections, i1); checkLinkChain(intersections, i2); #endif // both already in some list. Have to make sure they are connected // this can be done by cutting open the ring(s) after the two eges and // connecting them again Intersection other1; other1.y = yi; other1.edge = link1.next; IntersectionLink linko1 = intersections.value(other1, emptyLink); Intersection other2; other2.y = yi; other2.edge = link2.next; IntersectionLink linko2 = intersections.value(other2, emptyLink); linko1.prev = i2.edge; link2.next = other1.edge; linko2.prev = i1.edge; link1.next = other2.edge; intersections.insert(other1, linko1); intersections.insert(other2, linko2); } intersections.insert(i1, link1); intersections.insert(i2, link2); #ifdef DEBUG checkLinkChain(intersections, i1); checkLinkChain(intersections, i2); Q_ASSERT(edgeInChain(i1, i2.edge)); #endif return; }
void QTessellatorPrivate::cancelCoincidingEdges() { Vertex **vv = vertices.sorted; QCoincidingEdge *tl = 0; int tlSize = 0; for (int i = 0; i < vertices.nPoints - 1; ++i) { Vertex *v = vv[i]; int testListSize = 0; while (i < vertices.nPoints - 1) { Vertex *n = vv[i]; if (v->x != n->x || v->y != n->y) break; if (testListSize > tlSize - 2) { tlSize = qMax(tlSize*2, 16); tl = q_check_ptr((QCoincidingEdge *)realloc(tl, tlSize*sizeof(QCoincidingEdge))); } if (n->flags & (LineBeforeStarts|LineBeforeHorizontal)) { tl[testListSize].start = n; tl[testListSize].end = vertices.prev(n); tl[testListSize].used = false; tl[testListSize].before = true; ++testListSize; } if (n->flags & (LineAfterStarts|LineAfterHorizontal)) { tl[testListSize].start = n; tl[testListSize].end = vertices.next(n); tl[testListSize].used = false; tl[testListSize].before = false; ++testListSize; } ++i; } if (!testListSize) continue; qSort(tl, tl + testListSize); for (int j = 0; j < testListSize; ++j) { if (tl[j].used) continue; for (int k = j + 1; k < testListSize; ++k) { if (tl[j].end->x != tl[k].end->x || tl[j].end->y != tl[k].end->y || tl[k].used) break; if (!winding || tl[j].before != tl[k].before) { cancelEdges(tl[j], tl[k]); break; } ++k; } ++j; } } free(tl); }
pcl::simulation::TriangleMeshModel::TriangleMeshModel (pcl::PolygonMesh::Ptr plg) { Vertices vertices; Indices indices; bool found_rgb = false; for (size_t i=0; i < plg->cloud.fields.size () ; ++i) if (plg->cloud.fields[i].name.compare ("rgb") == 0) found_rgb = true; if (found_rgb) { pcl::PointCloud<pcl::PointXYZRGB> newcloud; pcl::fromROSMsg (plg->cloud, newcloud); PCL_DEBUG("RGB Triangle mesh: "); PCL_DEBUG("Mesh polygons: %ld", plg->polygons.size ()); PCL_DEBUG("Mesh points: %ld", newcloud.points.size ()); Eigen::Vector4f tmp; for(size_t i=0; i< plg->polygons.size (); ++i) { // each triangle/polygon pcl::Vertices apoly_in = plg->polygons[i]; for(size_t j = 0; j < apoly_in.vertices.size (); ++j) { // each point uint32_t pt = apoly_in.vertices[j]; tmp = newcloud.points[pt].getVector4fMap(); vertices.push_back (Vertex (Eigen::Vector3f (tmp (0), tmp (1), tmp (2)), Eigen::Vector3f (newcloud.points[pt].r/255.0f, newcloud.points[pt].g/255.0f, newcloud.points[pt].b/255.0f))); indices.push_back (indices.size ()); } } } else { pcl::PointCloud<pcl::PointXYZ> newcloud; pcl::fromROSMsg (plg->cloud, newcloud); Eigen::Vector4f tmp; for(size_t i=0; i< plg->polygons.size (); i++) { // each triangle/polygon pcl::Vertices apoly_in = plg->polygons[i]; for(size_t j=0; j< apoly_in.vertices.size (); j++) { // each point uint32_t pt = apoly_in.vertices[j]; tmp = newcloud.points[pt].getVector4fMap(); vertices.push_back (Vertex (Eigen::Vector3f (tmp (0), tmp (1), tmp (2)), Eigen::Vector3f (1.0, 1.0, 1.0))); indices.push_back (indices.size ()); } } } PCL_DEBUG("Vertices: %ld", vertices.size ()); PCL_DEBUG("Indices: %ld", indices.size ()); glGenBuffers (1, &vbo_); glBindBuffer (GL_ARRAY_BUFFER, vbo_); glBufferData (GL_ARRAY_BUFFER, vertices.size () * sizeof (vertices[0]), &(vertices[0]), GL_STATIC_DRAW); glBindBuffer (GL_ARRAY_BUFFER, 0); glGenBuffers (1, &ibo_); glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, ibo_); glBufferData (GL_ELEMENT_ARRAY_BUFFER, indices.size () * sizeof (indices[0]), &(indices[0]), GL_STATIC_DRAW); glBindBuffer (GL_ELEMENT_ARRAY_BUFFER, 0); if (indices.size () > std::numeric_limits<GLuint>::max ()) PCL_THROW_EXCEPTION(PCLException, "Too many vertices"); size_ = static_cast<GLuint>(indices.size ()); }
void MDAL::Driver3Di::populateFacesAndVertices( Vertices &vertices, Faces &faces ) { assert( vertices.empty() ); size_t faceCount = mDimensions.size( CFDimensions::Face2D ); faces.resize( faceCount ); size_t verticesInFace = mDimensions.size( CFDimensions::MaxVerticesInFace ); size_t arrsize = faceCount * verticesInFace; std::map<std::string, size_t> xyToVertex2DId; // X coordinate int ncidX = mNcFile.getVarId( "Mesh2DContour_x" ); double fillX = mNcFile.getFillValue( ncidX ); std::vector<double> faceVerticesX( arrsize ); if ( nc_get_var_double( mNcFile.handle(), ncidX, faceVerticesX.data() ) ) throw MDAL_Status::Err_UnknownFormat; // Y coordinate int ncidY = mNcFile.getVarId( "Mesh2DContour_y" ); double fillY = mNcFile.getFillValue( ncidY ); std::vector<double> faceVerticesY( arrsize ); if ( nc_get_var_double( mNcFile.handle(), ncidY, faceVerticesY.data() ) ) throw MDAL_Status::Err_UnknownFormat; // now populate create faces and backtrack which vertices // are used in multiple faces for ( size_t faceId = 0; faceId < faceCount; ++faceId ) { Face face; for ( size_t faceVertexId = 0; faceVertexId < verticesInFace; ++faceVertexId ) { size_t arrId = faceId * verticesInFace + faceVertexId; Vertex vertex; vertex.x = faceVerticesX[arrId]; vertex.y = faceVerticesY[arrId]; vertex.z = 0; if ( MDAL::equals( vertex.x, fillX ) || MDAL::equals( vertex.y, fillY ) ) break; size_t vertexId; std::string key = std::to_string( vertex.x ) + "," + std::to_string( vertex.y ); const auto it = xyToVertex2DId.find( key ); if ( it == xyToVertex2DId.end() ) { // new vertex vertexId = vertices.size(); xyToVertex2DId[key] = vertexId; vertices.push_back( vertex ); } else { // existing vertex vertexId = it->second; } face.push_back( vertexId ); } faces[faceId] = face; } // Only now we have number of vertices, since we identified vertices that // are used in multiple faces mDimensions.setDimension( CFDimensions::Vertex2D, vertices.size() ); }
int main(int argc, char** argv) { if(argc != 3) return usage(argv[0]); mark_tag vertex_index(1), vertex_x(2), vertex_y(3), vertex_z(4); sregex tface_re = bos >> *space >> "TFACE" >> *space >> eos; sregex vertex_re = bos >> *space >> "VRTX" >> +space >> (vertex_index=+_d) >> +space >> (vertex_x=+(digit|'-'|'+'|'.')) >> +space >> (vertex_y=+(digit|'-'|'+'|'.')) >> +space >> (vertex_z=+(digit|'-'|'+'|'.')) >> eos; sregex triangle_re = bos >> *space >> "TRGL" >> +space >> (s1=+digit) >> +space >> (s2=+digit) >> +space >> (s3=+digit) >> eos; sregex end_re = bos >> *space >> "END" >> *space >> eos; std::ifstream input(argv[1]); std::ofstream output(argv[2]); if(!input) { std::cerr << "Cannot read \"" << argv[1] << "\"!\n"; return EXIT_FAILURE; } if(!output) { std::cerr << "Cannot write to \"" << argv[2] << "\"!\n"; return EXIT_FAILURE; } std::string line; std::getline(input, line); smatch results; while(input && ! regex_match(line, tface_re)) // search line "TFACE" { std::getline(input, line); } std::getline(input, line); while(input && regex_match(line, results, vertex_re)) { vertices.push_back(boost::make_tuple(results[vertex_x], results[vertex_y], results[vertex_z])); std::getline(input, line); } while(input && regex_match(line, results, triangle_re)) { std::stringstream s; int i, j, k; s << results[1] << " " << results[2] << " " << results[3]; s >> i >> j >> k; faces.push_back(boost::make_tuple(i, j, k)); std::getline(input, line); } if(!input || !regex_match(line, end_re)) return incorrect_input("premature end of file!"); output << "OFF " << vertices.size() << " " << faces.size() << " " << "0\n"; for(Vertices::const_iterator vit = vertices.begin(), vend = vertices.end(); vit != vend; ++vit) output << boost::get<0>(*vit) << " " << boost::get<1>(*vit) << " " << boost::get<2>(*vit) << "\n"; for(Faces::const_iterator fit = faces.begin(), fend = faces.end(); fit != fend; ++fit) output << "3 " << boost::get<0>(*fit) << " " << boost::get<1>(*fit) << " " << boost::get<2>(*fit) << "\n"; if(output) return EXIT_SUCCESS; else return EXIT_FAILURE; };
CoordSystem3 Quadrangle3::getCoordinateSystem(const Vertices& vertices) const { auto newX = (vertices.at(1) - vertices.at(0)).ort(); auto newY = (vertices.at(3) - vertices.at(0)).ort(); auto newZ = (newX & newY).ort(); return {vertices.at(0), newX, newY, newZ}; }
/// Read an event and fill a vector of MCParticles. Geant4EventReader::EventReaderStatus Geant4EventReaderGuineaPig::readParticles(int /* event_number */, Vertices& vertices, vector<Particle*>& particles) { // if no number of particles per event set, we will read the whole file if ( m_part_num < 0 ) m_part_num = std::numeric_limits<int>::max() ; // First check the input file status if ( m_input.eof() ) { return EVENT_READER_EOF; } else if ( !m_input.good() ) { return EVENT_READER_IO_ERROR; } double Energy; double betaX; double betaY; double betaZ; double posX; double posY; double posZ; // Loop over particles for( int counter = 0; counter < m_part_num ; ++counter ){ // need to check for NAN as not all ifstream implementations can handle this directly std::string lineStr ; std::getline( m_input, lineStr ) ; if( m_input.eof() ) { if( counter==0 ) { return EVENT_READER_IO_ERROR ; // reading first particle of event failed } else{ ++m_currEvent; return EVENT_READER_OK ; // simply EOF } } std::transform(lineStr.begin(), lineStr.end(), lineStr.begin(), ::tolower); if( lineStr.find("nan") != std::string::npos){ printout(WARNING,"EventReader","### Read line with 'nan' entries - particle will be ignored ! " ) ; continue ; } std::stringstream m_input_str( lineStr ) ; m_input_str >> Energy >> betaX >> betaY >> betaZ >> posX >> posY >> posZ ; // printf(" ------- %e %e %e %e %e %e %e \n", Energy,betaX, betaY,betaZ,posX,posY,posZ ) ; // // Create a MCParticle and fill it from stdhep info Particle* p = new Particle(counter); PropertyMask status(p->status); // PDGID: If Energy positive (negative) particle is electron (positron) p->pdgID = 11; p->charge = -1; if(Energy < 0.0) { p->pdgID = -11; p->charge = +1; } // Momentum vector p->pex = p->psx = betaX*TMath::Abs(Energy)*GeV; p->pey = p->psy = betaY*TMath::Abs(Energy)*GeV; p->pez = p->psz = betaZ*TMath::Abs(Energy)*GeV; // Mass p->mass = 0.0005109989461*GeV; // // Creation time (note the units [1/c_light]) // ( not information in GuineaPig files ) p->time = 0.0; p->properTime = 0.0; // Vertex p->vsx = posX*nm; p->vsy = posY*nm; p->vsz = posZ*nm; Vertex* vtx = new Vertex ; vtx->x = p->vsx ; vtx->y = p->vsy ; vtx->z = p->vsz ; vtx->time = p->time ; vtx->out.insert( p->id ); // // Generator status // Simulator status 0 until simulator acts on it p->status = 0; status.set(G4PARTICLE_GEN_STABLE); // Add the particle to the collection vector particles.push_back(p); // create a new vertex for this particle vertices.push_back( vtx) ; } // End loop over particles ++m_currEvent; return EVENT_READER_OK; }
void degree_sort(Vertices &R){ set_degrees(R); sort(R.begin(), R.end(), desc_degree); }
double CalcIntegral(Surfaces &s, PointsXYZ &m){ //return; int ns=s.size(); // число треугольников CoordXYZ x[3]; for (int i = 0; i < 3; i++) x[i].resize(3); //============= init =================== vrt.Init(m.size(),p_DeltaT); CoordXYZ w(3); CoordXYZ control_point(3); CoordXYZ position_of_source(3); w[0] = 0; w[1] = 0; w[2] = 0; position_of_source[0] = e_x0; position_of_source[1] = e_y0; position_of_source[2] = e_z0; control_point[0] = p_control_x; control_point[1] = p_control_y; control_point[2] = p_control_z; double omega = p_omega; SourceOfNoise source_of_noise(omega, position_of_source,w);//,control_point); //========== end of init =============== double Sintegral; // for(double z=90.;z<100.;z+=(100.-90.)/200.) double T=0.; // for(;T<110.;T+=(110.-90.)/230.) { for (int i = 0; i < 3; ++i) IntN[i]=0; S_Surf=0.; // control_point[2]=z; Sintegral=0; for(int j=0;j<ns;j++) { int err; Sintegral+=CalcIntegralOfFullTrg(s[j],m,T,source_of_noise, control_point,err); if(err) { cout << " ERROR 3_ ret=" << err << " j= " << j << endl; return 0.; } } { static int ugu=0; if(!ugu) cout << " S_Surf=" << S_Surf << " (" << S_Surf/(4.*M_PI*kva(p_Rsphere)) << ") IntN " << IntN[0] << " " << IntN[1] << " " << IntN[2] << endl<< endl; ugu=1; } // cout << control_point[2] << " " << Sintegral << " " << source_of_noise.GetRho(control_point,T) << endl; if(!isbp) cout << T << "\t" << source_of_noise.GetRho(control_point,T) << " " << Sintegral << endl; } if(isbp) { vrt.PutData("koeff.txt"); // следует выполнить свёртку! int nk=150,ik; double dt=(p_T2-p_T1)/nk; for(ik=0,T=p_T1;ik<=nk;ik++,T+=dt) { Sintegral=vrt.Svertka(s,m,source_of_noise,T); cout << T << "\t" << source_of_noise.GetRho(control_point,T) << " " << Sintegral << endl; } } cout << endl; cout << " S_Surf=" << S_Surf << " (" << S_Surf/(4.*M_PI*kva(p_Rsphere)) << ") Int_N " << IntN[0] << " " << IntN[1] << " " << IntN[2] << endl; return Sintegral; }
int main() { /* #Graph The following class hierarchy exists: BidirectionalGraph -------- Incience ---------+ | Adjacency --------+ | VertexAndEdgeList ----+---- VertexList -------+---- Graph | | +---- EdgeList ---------+ | AdjacenyMatrix ---+ */ { /* #properties Properties are values associated to edges and vertices. */ { /* There are a few predefined properties which you should use whenever possible as they are already used in many algorithms, but you can also define your own properties. Predefined properties include: - `edge_weight_t`. Used for most algorithms that have a single value associated to each edge such as Dijikstra. - `vertex_name_t` */ { typedef boost::property<boost::vertex_name_t, std::string> VertexProperties; typedef boost::property<boost::edge_weight_t, int> EdgeProperties; } /* Multiple properties can be specified either by: - using a custom class as the property type. TODO is there any limitation to this? - chaining multile properties */ { } /* The absense of a property is speficied by boost::no_property. */ { typedef boost::no_property VertexProperties; } } typedef boost::property<boost::vertex_name_t, std::string> VertexProperties; typedef boost::property<boost::edge_weight_t, int> EdgeProperties; typedef boost::adjacency_list< // Data structure to represent the out edges for each vertex. // Possibilities: // // #vecS selects std::vector. // #listS selects std::list. // #slistS selects std::slist. // #setS selects std::set. // #multisetS selects std::multiset. // #hash_setS selects std::hash_set. // // `S` standas for Selector. boost::vecS, // Data structure to represent the vertex set. boost::vecS, // Directed type. // #bidirectionalS: directed graph with access to in and out edges // #directedS: directed graph with access only to out-edges // #undirectedS: undirected graph boost::bidirectionalS, // Optional. VertexProperties, // Optional. EdgeProperties > Graph; //typedef boost::graph_traits<Graph>::vertex_iterator VertexIter; //typedef boost::graph_traits<Graph>::vertex_descriptor Vertex; //typedef boost::property_map<Graph, boost::vertex_index_t>::type IndexMap; // Fix number of vertices, and add one edge at a time. int num_vertices = 3; Graph g(num_vertices); boost::add_edge(0, 1, g); boost::add_edge(1, 2, g); // Fix number of vertices, and add one edge array. { int num_vertices = 3; typedef std::pair<int, int> Edge; std::vector<Edge> edges{ {0, 1}, {1, 2}, }; Graph g(edges.data(), edges.data() + edges.size(), num_vertices); } // It is also possible to add vertices with #add_vertex. //#vertices { // Number of vertices. boost::graph_traits<Graph>::vertices_size_type num_vertices = boost::num_vertices(g); assert(num_vertices == 3u); //#vertices() Returns a begin() end() vertex iterator pair so we know where to stop. { typedef std::vector<boost::graph_traits<Graph>::vertex_descriptor> Vertices; Vertices vertices; vertices.reserve(num_vertices); //IndexMap auto index = boost::get(boost::vertex_index, g); //std::pair<vertex_iter, vertex_iter> vp for (auto vp = boost::vertices(g); vp.first != vp.second; ++vp.first) { // Vertex auto v = *vp.first; vertices.push_back(index[v]); } assert((vertices == Vertices{0, 1, 2})); } // The iterator is a ranom access iterator. { auto index = boost::get(boost::vertex_index, g); auto it = boost::vertices(g).first; assert(index[it[2]] == 2); assert(index[it[1]] == 1); } } //#edges { // It seems that only AdjencyMatrix has a method to get an edge given two vertices: //edge(u, v, g) } } //#source is also a global function: <http://stackoverflow.com/questions/16114616/why-is-boost-graph-librarys-source-a-global-function> //#dijikstra std::cout << "#dijkstra" << std::endl; { typedef boost::adjacency_list< boost::listS, boost::vecS, boost::directedS, boost::no_property, boost::property<boost::edge_weight_t, int> > Graph; typedef boost::graph_traits<Graph>::vertex_descriptor vertex_descriptor; typedef boost::graph_traits<Graph>::edge_descriptor edge_descriptor; typedef std::pair<int, int> Edge; // Model inputs. const int num_nodes = 5; const int sorce = 0; std::vector<Edge> edges{ {0, 2}, {1, 1}, {1, 3}, {1, 4}, {2, 1}, {2, 3}, {3, 4}, {4, 0}, {4, 1} }; std::vector<int> weights{ 1, 2, 1, 2, 7, 3, 1, 1, 1 }; // Solve. Graph g(edges.data(), edges.data() + edges.size(), weights.data(), num_nodes); std::vector<vertex_descriptor> p(num_vertices(g)); std::vector<int> d(num_vertices(g)); vertex_descriptor s = vertex(sorce, g); dijkstra_shortest_paths(g, s, predecessor_map(boost::make_iterator_property_map( p.begin(), boost::get(boost::vertex_index, g) )).distance_map(boost::make_iterator_property_map( d.begin(), boost::get(boost::vertex_index, g) )) ); // Print solution to stdout. std::cout << "node | distance from source | parent" << std::endl; boost::graph_traits<Graph>::vertex_iterator vi, vend; for (boost::tie(vi, vend) = vertices(g); vi != vend; ++vi) std::cout << *vi << " " << d[*vi] << " " << p[*vi] << std::endl; std::cout <<std::endl; // Generate a .dot graph file with shortest path highlighted. // To PNG with: dot -Tpng -o outfile.png input.dot boost::property_map<Graph, boost::edge_weight_t>::type weightmap = boost::get(boost::edge_weight, g); std::ofstream dot_file("dijkstra.dot"); dot_file << "digraph D {\n" << " rankdir=LR\n" << " size=\"4,3\"\n" << " ratio=\"fill\"\n" << " edge[style=\"bold\"]\n" << " node[shape=\"circle\"]\n"; boost::graph_traits <Graph>::edge_iterator ei, ei_end; for (std::tie(ei, ei_end) = boost::edges(g); ei != ei_end; ++ei) { edge_descriptor e = *ei; boost::graph_traits<Graph>::vertex_descriptor u = boost::source(e, g), v = boost::target(e, g); dot_file << u << " -> " << v << "[label=\"" << boost::get(weightmap, e) << "\""; if (p[v] == u) dot_file << ", color=\"black\""; else dot_file << ", color=\"grey\""; dot_file << "]"; } dot_file << "}"; // Construct forward path to a destination. int dest = 4; int cur = dest; std::vector<int> path; path.push_back(cur); while(cur != sorce) { cur = p[cur]; path.push_back(cur); } std::reverse(path.begin(), path.end()); // Print. std::cout << "Path to node " << std::to_string(dest) << ":" << std::endl; for(auto& node : path) { std::cout << node << std::endl; } } }
void cut2(const Vertices &A, Vertices &B){ for(int i = 0; i < (int)A.size() - 1; i++) if(e[A.back().i][A[i].i]) B.push_back(A[i].i); }
void set_degrees(Vertices &v){ for(int i = 0, j; i < (int)v.size(); i++) for(v[i].d = j = 0; j < int(v.size()); j++) v[i].d += e[v[i].i][v[j].i]; }
void init_colors(Vertices &v){ const int max_degree = v[0].d; for(int i = 0; i < (int)v.size(); i++) v[i].d = min(i, max_degree) + 1; }
void reRender(REid render) { // initialize variables Render* r = (Render*)render; if(r == null) return; //error if(r->scene == null) return; //error GlRasScene& scene = *(GlRasScene*)r->scene; //todo: scene.background.render() glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // temporary: render everything in white glColor3f(1.0f, 1.0f, 1.0f); // set up window { glViewport(0, 0, 800, 600); } //todo: set up camera { glMatrixMode(GL_PROJECTION); if(r->camera) //if(false) { Matrix4 transformation; r->camera->getTransform(transformation); glLoadMatrixf(transformation); } else { //TEMP: glLoadIdentity(); gluPerspective(45.0f, 800.0f/600.0f,0.1f,100.0f); // todo: replace with custom function //todo: set backplane to world max and front plane to geom closest to camera??? (This will allow best z-buffer precision) /*float rotX, rotY, rotZ; camera.rotation.get(rotX, rotY, rotZ); glRotatef(-rotX*180.0/PI, 1.0f, 0.0f, 0.0f); glRotatef(-rotY*180.0/PI, 0.0f, 1.0f, 0.0f); glRotatef(-rotZ*180.0/PI, 0.0f, 0.0f, 1.0f);*/ /*float locX, locY, locZ; camera.location.get(locX, locY, locZ); glTranslatef(-locX, -locY, -locZ);*/ glTranslatef(0.0f, -0.0f, -20.0f); } } // todo: set up world glMatrixMode(GL_MODELVIEW); glLoadIdentity(); //// render test quad //{ // glColor3f(0.5f, 0.5f, 0.5f); // glBegin(GL_QUADS); // glVertex3f(-1.0f, 1.0f, 0.0f); // glVertex3f( 1.0f, 1.0f, 0.0f); // glVertex3f( 1.0f,-1.0f, 0.0f); // glVertex3f(-1.0f,-1.0f, 0.0f); // glEnd(); // glColor3f(1.0f, 1.0f, 1.0f); //} // render scene { // enable render options glEnable(GL_DEPTH_TEST); // clear background & zbuffer glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); } // old: precalculate ambient occlusion data (now done in endscene) for(list<Geometry*>::iterator i = scene.geometry.begin(); i != scene.geometry.end(); ++i) { // initialize variables if((*i)->type != MESH_GEOMETRY) continue; Mesh& geometry = *(Mesh*)*i; Points* points = geometry.points; Vertices* vertices = geometry.vertices; Edges* edges = geometry.edges; Primitives* primitives = geometry.primitives; Map* map = geometry.map; if(vertices == null) continue; // error - no vertices // retrieve attributes GlRasElements* locationElements = null, * indexElements = null, * normAreaElements = null; GlStream* vertexStream = null, * indexStream = null, * normAreaStream = null; if(points) locationElements = (GlRasElements*)points->getAttributes(RE_LOCATION); if(locationElements != null) { indexElements = (GlRasElements*)vertices->getAttributes(RE_INDEX); normAreaElements = (GlRasElements*)vertices->getAttributes(RE_EXT_BENT_NORMAL_AREA); } else { locationElements = (GlRasElements*)vertices->getAttributes(RE_LOCATION); if(locationElements == null) return; //error normAreaElements = (GlRasElements*)vertices->getAttributes(RE_EXT_BENT_NORMAL_AREA); indexElements = null; } vertexStream = locationElements->getStream(); if(indexElements) indexStream = indexElements->getStream(); if(normAreaElements) normAreaStream = normAreaElements->getStream(); // calculate ambient occlusion GlStream occlusionStream; if(normAreaStream) { // create occlusion stream (one occlusion value per vertex) occlusionStream.create(vertexStream->getLength(), VEC4_FLOAT16_STREAM, null); //FLOAT16_STREAM? // create (& bind) occlusion kernel GlKernel kernel; kernel.build(fsCalculateDiscOcclusion1Pass, vsTexCoord1); kernel.bind(); // set kernel parameters kernel.setUniform1i("vertices", 0); kernel.setUniform1i("normDiscs", 1); kernel.setUniform1f("nEmitters", (float)vertexStream->getLength()); // bind vertices, vertex normals & disc area vertexStream->bindTexture(0); normAreaStream->bindTexture(1); // create & bind render target GlRenderTarget renderTarget; renderTarget.create(); renderTarget.bind(); // bind occlusion values as output occlusionStream.bindOutput(0); // execute kernel kernel.execute(); // unbind occlusion values from output occlusionStream.unbindOutput(0); // unbind & destroy render target renderTarget.unbind(); renderTarget.destroy(); // unbind discs and vertices normAreaStream->unbindTexture(1); vertexStream->unbindTexture(0); // destroy kernel //GlKernel::restoreFixedFunction(); kernel.unbind(); kernel.destroy(); } // render scene geometry { // temporary: disable textures (shouldn't be needed once shaders are used) glActiveTexture(GL_TEXTURE1); glDisable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); glDisable(GL_TEXTURE_2D); glColor4f(1.0f, 1.0f, 1.0f, 1.0f); // create (& bind) shader program GlShader shader; uint occlusionAttributeIndex = 0; if(normAreaStream) { shader.build(fsRenderAO, vsRenderAO); shader.bind(); // get shader parameters occlusionAttributeIndex = shader.getAttribute("occlusion"); } // bind vertices GLuint VBO = vertexStream->bindVertexBuffer(); glVertexPointer(3, GL_FLOAT, 0, (char*)null); glEnableClientState(GL_VERTEX_ARRAY); // bind normals /* todo: GLuint NBO = normalStream->bindVertexBuffer(); glNormalPointer(GL_FLOAT, 0, (char*)null); glEnableClientState(GL_NORMAL_ARRAY);*/ // bind occlusion values if(normAreaStream) { GLuint ABO = occlusionStream.bindVertexAttributeBuffer(); glVertexAttribPointer(occlusionAttributeIndex, 4, GL_FLOAT, GL_FALSE, 0, (char*)null); glEnableVertexAttribArray(occlusionAttributeIndex); } // bind indices GLuint IBO = indexStream->bindIndexBuffer(); //todo: is this correct?? /*NOT SUPPORTED BY OPENGL: if(indexStream->getInternElementSize() == 4) glIndexPointer(GL_UNSIGNED_INT, 0, (char*)null); else*/ glIndexPointer(GL_UNSIGNED_SHORT, 0, (char*)null); glEnableClientState(GL_INDEX_ARRAY); //enable lighting (temporary) { glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); float pos[4] = { 4.0, 4.0, 5.0, 1.0 }; glLightfv(GL_LIGHT0, GL_POSITION, pos); glLightf(GL_LIGHT0, GL_CONSTANT_ATTENUATION, 1.0f); glLightf(GL_LIGHT0, GL_LINEAR_ATTENUATION, 0.0f); glLightf(GL_LIGHT0, GL_QUADRATIC_ATTENUATION, 0.0f); } // draw triangles /*NOT SUPPORTED BY OPENGL: if(indexStream->getInternElementSize() == 4) glDrawElements(GL_TRIANGLES, indexStream->getLength(), GL_UNSIGNED_INT, null); else*/ glDrawElements(GL_TRIANGLES, indexStream->getLength(), GL_UNSIGNED_SHORT, null); //glDrawElements(GL_TRIANGLES, 42, GL_UNSIGNED_SHORT, null); // unbind buffers if(normAreaStream) glDisableVertexAttribArray(occlusionAttributeIndex); //todo: glDisableClientState(GL_NORMAL_ARRAY); glDisableClientState(GL_INDEX_ARRAY); glDisableClientState(GL_VERTEX_ARRAY); if(normAreaStream) occlusionStream.unbindVertexAttributeBuffer(); indexStream->unbindIndexBuffer(); vertexStream->unbindVertexBuffer(); // unbind shader program if(normAreaStream) { shader.unbind(); shader.destroy(); } } } // disable render options { glEnable(GL_DEPTH_TEST); } /*Old: GlStream occlusionStream; { // create occlusion stream (one occlusion value per vertex) occlusionStream.create(scene.geometry.vertexStream.getLength(), VEC4_FLOAT16_STREAM, null); //FLOAT16_STREAM? // create (& bind) occlusion kernel GlKernel kernel; kernel.build(fsCalculateDiscOcclusion1Pass, vsTexCoord1); kernel.bind(); // set kernel parameters kernel.setUniform1i("vertices", 0); kernel.setUniform1i("normDiscs", 1); kernel.setUniform1f("nEmitters", (float)scene.geometry.vertexStream.getLength()); // bind vertices, vertex normals & disc area scene.geometry.vertexStream.bindTexture(0); scene.geometry.normDiscStream.bindTexture(1); // create & bind render target GlRenderTarget renderTarget; renderTarget.create(); renderTarget.bind(); // bind occlusion values as output occlusionStream.bindOutput(0); // execute kernel kernel.execute(); // unbind occlusion values from output occlusionStream.unbindOutput(0); // unbind & destroy render target renderTarget.unbind(); renderTarget.destroy(); // unbind discs and vertices scene.geometry.normDiscStream.unbindTexture(1); scene.geometry.vertexStream.unbindTexture(0); // destroy kernel //GlKernel::restoreFixedFunction(); kernel.unbind(); kernel.destroy(); }*/ // Debug: Render streams /*{ glMatrixMode(GL_PROJECTION); glViewport(0, 0, 800, 600); glPushMatrix(); glLoadIdentity(); glTranslatef(-1.0f, -1.0f, 0.0f); glScalef(2.0f, 2.0f, 0.0f); float vertices[] = { 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f }; float texcoords[] = { 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 1.0f }; //scene.geometry.vertexStream.bindTexture(0); //scene.geometry.normDiscStream.bindTexture(0); occlusionStream.bindTexture(0); //temp: glColor4f(1.0f, 1.0f, 1.0f, 1.0f); glEnableClientState(GL_VERTEX_ARRAY); glClientActiveTexture(GL_TEXTURE0); glEnable(GL_TEXTURE_2D); glEnableClientState(GL_TEXTURE_COORD_ARRAY); glTexCoordPointer(2, GL_FLOAT, 0, texcoords); glVertexPointer(2, GL_FLOAT, 0, vertices); glDrawArrays(GL_QUADS, 0, 4); glDisableClientState(GL_VERTEX_ARRAY); // restore transform glPopMatrix(); glViewport(0, 0, 800, 600); glMatrixMode(GL_MODELVIEW); }*/ }
Maxclique(const BB* conn, const int sz, const float tt = 0.025) \ : pk(0), level(1), Tlimit(tt){ for(int i = 0; i < sz; i++) V.push_back(Vertex(i)); e = conn, C.resize(sz + 1), S.resize(sz + 1); }
Vertices<CoordType> SpatialModelMaximalRepulsion3D<CoordType>::drawSample(const int numPoints) { ENTER("Vertices<CoordType> SpatialModelMaximalRepulsion3D<CoordType>::drawSample(const int)"); const int outerSteps = getNumMonteCarloCycles(); const int innerSteps = numPoints; const CoordType beta = computeBeta(); const CoordType maxRadius = this->getTriMesh().equivalentRadius() / 50.0; Vertices<CoordType> vertices = SpatialModelHardcoreDistance3D<CoordType>::drawSample( numPoints ); RandomGenerator& randomGenerator = this->getRandomGenerator(); CoordType currentEnergy, newEnergy, deltaEnergy; Vector<CoordType> vertex; bool acceptTransition; int i, j, v; ConvergenceTest<CoordType> convergenceTest; CoordType sumEnergy; bool converged = false; _energyProfile.setZeros( outerSteps ); convergenceTest.setData( _energyProfile ); convergenceTest.setRange( 100 ); for (i = 0; !converged && i < outerSteps; ++i) { #if 0 if ( (i%20)==0 ) { string filename = "max-repulsion-vertices-" + StringTools::toString(i,4,'0') + ".vx"; vertices.save( filename, true ); } #endif for (j = 0, sumEnergy = 0.0; j < innerSteps; ++j) { v = randomGenerator.uniformL( numPoints ); vertex = vertices[v]; if ( j == 0 ) currentEnergy = energy( vertices ); moveVertex( vertices, v, maxRadius ); newEnergy = energy( vertices ); deltaEnergy = newEnergy - currentEnergy; acceptTransition = deltaEnergy <= .0 || randomGenerator.uniformLF() < exp( -beta*deltaEnergy ); if ( acceptTransition ) currentEnergy = newEnergy; else vertices[v] = vertex; sumEnergy += currentEnergy; } _energyProfile[i] = sumEnergy / innerSteps; converged = convergenceTest.isPositive( i ); } if ( !converged ) { Exception exception; exception.setWhere( "Vertices<CoordType> SpatialModelMaximalRepulsion3D<CoordType>::drawSample(const int)" ); exception.setWhat( "Convergence not reached after " + StringTools::toString(outerSteps) + " iterations" ); throw exception; } LEAVE(); return vertices; }
void ConvertOutlineToTriangles(Vertices &ioOutline,const QuickVec<int> &inSubPolys) { // Order polygons ... int subs = inSubPolys.size(); if (subs<1) return; QuickVec<SubInfo> subInfo; QuickVec<EdgePoint> edges(ioOutline.size()); int index = 0; int groupId = 0; for(int sub=0;sub<subs;sub++) { SubInfo info; info.p0 = sub>0?inSubPolys[sub-1]:0; info.size = inSubPolys[sub] - info.p0; if (ioOutline[info.p0] == ioOutline[info.p0+info.size-1]) info.size--; if (info.size>2) { UserPoint *p = &ioOutline[info.p0]; double area = 0.0; for(int i=2;i<info.size;i++) { UserPoint v_prev = p[i-1] - p[0]; UserPoint v_next = p[i] - p[0]; area += v_prev.Cross(v_next); } bool reverse = area < 0; int parent = -1; for(int prev=subInfo.size()-1; prev>=0 && parent==-1; prev--) { if (subInfo[prev].contains(p[0])) { int prev_p0 = subInfo[prev].p0; int prev_size = subInfo[prev].size; int inside = PIP_MAYBE; for(int test_point = 0; test_point<info.size && inside==PIP_MAYBE; test_point++) { inside = PointInPolygon( p[test_point], &ioOutline[prev_p0], prev_size); if (inside==PIP_YES) parent = prev; } } } if (parent==-1 || subInfo[parent].is_internal ) { info.group = groupId++; info.is_internal = false; } else { info.group = subInfo[parent].group; info.is_internal = true; } info.first = &edges[index]; AddSubPoly(info.first,p,info.size,reverse!=info.is_internal); if (sub<subs-1) info.calcExtent(); index += info.size; subInfo.push_back(info); } } Vertices triangles; for(int group=0;group<groupId;group++) { int first = -1; int size = 0; for(int sub=0;sub<subInfo.size();sub++) { SubInfo &info = subInfo[sub]; if (info.group==group) { if (first<0) { first = sub; size = info.size; } else { LinkSubPolys(subInfo[first].first,info.first, info.link); size += info.size + 2; } } } ConvertOutlineToTriangles(subInfo[first].first, size,triangles); } ioOutline.swap(triangles); }
CoordType SpatialModelMaximalRepulsion3D<CoordType>::energy(const Vertices<CoordType>& vertices) const { Vector<CoordType> minDistances = vertices.squareNearestNeighborDistances(); minDistances.apply( sqrt ); return 1.0 / minDistances.mean(); }
double CalcIntegralOfSmallTrgBp(CoordXYZ xtrg[3], double time, BasePoints &bp, CoordXYZ &control_point) { double cell_square; CoordXYZ cell_normal(3), cell_mass_centre(3); if (GetCellParams(xtrg, cell_square, cell_normal,cell_mass_centre)){ return 0; } CoordXYZ R(3); for (int i = 0; i < 3; ++i) R[i] = control_point[i] - cell_mass_centre[i]; double norma_R = GetVectorNorma1(R); if (!norma_R){ cout << " Error 1 : norma_r=0" << endl; exit(1); } double SUM = 0; double t = ModifyTimeByPosition(R, time); CoordXYZ f(kbase); for(int i=0;i<kbase;i++) f[i]=0; // double rez[kbase]; // найдём отклик от каждой вершины // этот фрагмент следует вычислять для каждого узла пирамиды // и для каждой функции отдельно double rho=0, rho_der=0, u_der[3]; for(int nonZeroNode=0; nonZeroNode<4; nonZeroNode++) // по каждой вершине { f[nonZeroNode]=1; double rez=bp.GetVal(cell_mass_centre,ip,f); // величина отклика от вершины, без учета функциональной зависимости f[nonZeroNode]=0; for(int nonZeroFunc=0; nonZeroFunc<5; nonZeroFunc++) { /* Эти функции равны 0 или 1 в зависимости от nonZeroFunc CoordXYZ u_der = bp.GetUDerivative(cell_mass_centre, t); double rho_der = bp.GetRhoDerivative(cell_mass_centre, t); double rho = bp.GetRho(cell_mass_centre, t); */ switch(nonZeroFunc) { case 0: rho=1; rho_der=0; u_der[0]=0; u_der[1]=0; u_der[2]=0; break; case 1: rho=0; rho_der=1; u_der[0]=0; u_der[1]=0; u_der[2]=0; break; case 2: rho=0; rho_der=0; u_der[0]=1; u_der[1]=0; u_der[2]=0; break; case 3: rho=0; rho_der=0; u_der[0]=0; u_der[1]=1; u_der[2]=0; break; case 4: rho=0; rho_der=0; u_der[0]=0; u_der[1]=0; u_der[2]=1; break; } SUM=0.; for (int i = 0; i < 3; ++i) { SUM += 1./(4*PI)* ( u_der[i]/norma_R + R[i]/kva(norma_R)*(rho_der + rho/norma_R) ) *cell_normal[i] *cell_square; } int err=vrt.AddData(ip[nonZeroNode],nonZeroFunc,SUM*rez,t); if(err) exit(0); } } // Расчет инвариантов S_Surf+=cell_square; for (int i = 0; i < 3; ++i) IntN[i]+=(cell_square*cell_normal[i]); return SUM; }
int ParticleSystem::createVAO(Shader newShader, Vertices vtx, Indices ind) { int rc = 0; GLint location; // location of the attributes in the shader; shader = newShader; //create vertex array object glGenVertexArrays(1, &vao); glBindVertexArray(vao); //create vertex buffer object glGenBuffers(1, &vtxVBO); glBindBuffer(GL_ARRAY_BUFFER, vtxVBO); glBufferData(GL_ARRAY_BUFFER, vtx.size() * sizeof(Vertex), vtx.data(), GL_STATIC_DRAW); //copy the vertex position location = glGetAttribLocation(shader.getProgId(), "vtxPos"); if (location == -1) { rc = -1; goto err; } glEnableVertexAttribArray(location); glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, pos)); //copy the vertex color location = glGetAttribLocation(shader.getProgId(), "vtxCol"); // if (location == -1) { // rc = -2; //goto err; //} glEnableVertexAttribArray(location); glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, col)); //copy the vertex normal location = glGetAttribLocation(shader.getProgId(), "vtxNorm"); // if (location == -1) { // rc = -2; //goto err; //} glEnableVertexAttribArray(location); glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, norm)); // copy the texture coords location = glGetAttribLocation(shader.getProgId(), "texCoord"); // if (location == -1) { // rc = -2; //goto err; //} glEnableVertexAttribArray(location); glVertexAttribPointer(location, 4, GL_FLOAT, GL_FALSE, sizeof(Vertex), (void*)offsetof(Vertex, texCoord)); //create index buffer glGenBuffers(1, &indVBO); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, indVBO); glBufferData(GL_ELEMENT_ARRAY_BUFFER, ind.size() * sizeof(GLuint), ind.data(), GL_STATIC_DRAW); // store the number of indices numIndices = vtx.size(); //numIndices = ind.size(); //end creation glBindVertexArray(0); err: return(rc); }
void mcqdyn(int* maxclique, int &sz){ set_degrees(V); sort(V.begin(),V.end(), desc_degree); init_colors(V); for(int i = 0; i < (int)V.size() + 1; i++) S[i].i1 = S[i].i2 = 0; expand_dyn(V); sz = (int)QMAX.size(); for(int i = 0; i < (int)QMAX.size(); i++) maxclique[i] = QMAX[i]; }