本文整理汇总了C++中ofMesh::getIndex方法的典型用法代码示例。如果您正苦于以下问题:C++ ofMesh::getIndex方法的具体用法?C++ ofMesh::getIndex怎么用?C++ ofMesh::getIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ofMesh
的用法示例。
在下文中一共展示了ofMesh::getIndex方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setNormals
void PyramidBrush::setNormals(ofMesh& mesh) {
int nV = mesh.getNumVertices();
int nT = mesh.getNumIndices() / 3;
vector<ofPoint> norm(nV);
for(int t=0; t < nT; t++) {
int i1 = mesh.getIndex(3*t);
int i2 = mesh.getIndex(3*t + 1);
int i3 = mesh.getIndex(3*t + 2);
const ofPoint &v1 = mesh.getVertex(i1);
const ofPoint &v2 = mesh.getVertex(i2);
const ofPoint &v3 = mesh.getVertex(i3);
ofPoint dir = ( (v2 - v1).crossed(v3 - v1)).normalized();
norm[i1] += dir;
norm[i2] += dir;
norm[i3] += dir;
}
for(int i = 0; i < nV; i++) {
norm[i].normalize();
}
mesh.clearNormals();
mesh.addNormals(norm);
}
示例2: setNormals
//Universal function which sets normals for the triangle mesh
void ofxOcean::setNormals( ofMesh &mesh ){
//The number of the vertices
int nV = mesh.getNumVertices();
//The number of the triangles
int nT = mesh.getNumIndices() / 3;
vector<ofPoint> norm( nV ); //Array for the normals
//Scan all the triangles. For each triangle add its
//normal to norm's vectors of triangle's vertices
for (int t=0; t<nT; t++) {
//Get indices of the triangle t
int i1 = mesh.getIndex( 3 * t );
int i2 = mesh.getIndex( 3 * t + 1 );
int i3 = mesh.getIndex( 3 * t + 2 );
//Get vertices of the triangle
const ofPoint &v1 = mesh.getVertex( i1 );
const ofPoint &v2 = mesh.getVertex( i2 );
const ofPoint &v3 = mesh.getVertex( i3 );
//Compute the triangle's normal
ofPoint dir = ( (v2 - v1).getCrossed( v3 - v1 ) ).getNormalized();
//Accumulate it to norm array for i1, i2, i3
norm[ i1 ] += dir;
norm[ i2 ] += dir;
norm[ i3 ] += dir;
}
//Normalize the normal's length
for (int i=0; i<nV; i++) {
norm[i].normalize();
}
//Set the normals to mesh
mesh.clearNormals();
mesh.addNormals( norm );
}
示例3: setNormals
//--------------------------------------------------------------
//Universal function which sets normals for the triangle mesh
void setNormals( ofMesh &mesh ){
int nV = mesh.getNumVertices();//640
int nT = mesh.getNumIndices() / 3;//213
vector<ofPoint> norm( nV );
for (int t=0; t<nT; t++) {
int i1 = mesh.getIndex( 3 * t );
int i2 = mesh.getIndex( 3 * t + 1 );
int i3 = mesh.getIndex( 641 );
const ofPoint &v1 = mesh.getVertex( i1 );
const ofPoint &v2 = mesh.getVertex( i2 );
const ofPoint &v3 = mesh.getVertex( i3 );
//Compute the triangle's normal
ofPoint dir = ( (v2 - v1).crossed( v3 - v1 ) ).normalized();
norm[ i1 ] += dir;
norm[ i2 ] += dir;
norm[ i3 ] += dir;
}
//Normalize the normal's length
for (int i=0; i<nV; i++) {
norm[i].normalize();
}
//Set the normals to mesh
mesh.clearNormals();
mesh.addNormals( norm );
}
示例4: fuseNeighbours
void MeshHelper::fuseNeighbours( ofMesh& mesh, float fuseDistance )
{
//@todo tex coords, normals
assert( mesh.getMode() == OF_PRIMITIVE_TRIANGLES );
int oldNumVerts = mesh.getNumVertices();
int oldNumIndices = mesh.getNumIndices();
if ( fuseDistance < 0 )
{
// fuse close-enough vertices
// first define 'close enough' as 1/10000 of smallest dimension of the bounding box width/height/depth
ofVec3f tlb, brf; // top left back, bottom right front
calculateAABoundingBox( mesh, tlb, brf );
float minDimension = min(brf.x-tlb.x,min(brf.y-tlb.y, brf.z-tlb.z));
fuseDistance = minDimension * 0.00001f;
}
// now fuse
map<ofIndexType,ofIndexType> fused;
vector<ofVec3f> newVertices;
vector<ofIndexType> remove;
for ( ofIndexType i=0; i<mesh.getNumVertices(); i++ )
{
const ofVec3f& vertex = mesh.getVertex(i);
// look at all the earlier vertices
bool didFuse = false;
for ( ofIndexType j=0; j<newVertices.size(); j++ ) {
if ( (vertex-newVertices[j]).length()<fuseDistance ) {
// fuse i to j
fused[i] = j;
remove.push_back(i);
didFuse = true;
break;
}
}
if ( !didFuse ) {
newVertices.push_back( vertex );
fused[i] = newVertices.size()-1;
}
}
// update indices
for ( int i=0; i<mesh.getNumIndices(); i++ ) {
ofIndexType originalIndex = mesh.getIndex(i);
assert( fused.find( originalIndex ) != fused.end() );
if ( fused.find(originalIndex) != fused.end() ) {
mesh.getIndices()[i] = fused[originalIndex];
}
}
// remove the fused
for ( int i=remove.size()-1; i>=0; i-- ) {
mesh.removeVertex( remove[i] );
}
ofLogNotice("MeshHelper") << "fuseNeighbours inplace: input " << oldNumVerts << " vertices/" << oldNumIndices << " indices, output " << mesh.getNumVertices() << " vertices/" << mesh.getNumIndices() << " indices";
}
示例5: check_triangle_intersections
// Returns true iff the mesh contains two index defined traingles that intersect.
bool check_triangle_intersections(ofMesh &mesh)
{
int len = mesh.getNumIndices();
for(int i = 0; i < len; i += 3)
{
ofVec3f v1 = mesh.getVertex(mesh.getIndex(i));
ofVec3f v2 = mesh.getVertex(mesh.getIndex(i + 1));
ofVec3f v3 = mesh.getVertex(mesh.getIndex(i + 2));
for(int j = 0; j < len; j += 3)
{
ofVec3f p1 = mesh.getVertex(mesh.getIndex(j));
ofVec3f p2 = mesh.getVertex(mesh.getIndex(j + 1));
ofVec3f p3 = mesh.getVertex(mesh.getIndex(j + 2));
int b = Intersecting(p1, p2, v1, v2, v3);
int b2 = Intersecting(p2, p3, v1, v2, v3);
int b3 = Intersecting(p3, p1, v1, v2, v3);
if(b == 1 || b2 == 1 || b3 == 1)
{
return true;
}
if(point_triangle_intersection(v1, v2, v3, p1)||
point_triangle_intersection(v1, v2, v3, p2)||
point_triangle_intersection(v1, v2, v3, p3))
{
return true;
}
}
}
return false;
}
示例6:
// adjacency list of triangulation
vector< set<size_t> > ofxDelaunay2D::adjacencyForTriMesh(ofMesh &triMesh) {
vector< set<size_t> > adjacency; adjacency.reserve(triMesh.getNumVertices());
for(size_t i=0; i<(size_t)(triMesh.getNumVertices()); ++i) {
adjacency.push_back(set<size_t>());
}
for(int i0=0; i0<(int)triMesh.getIndices().size() - 2; i0+=3) {
size_t i = triMesh.getIndex(i0);
size_t j = triMesh.getIndex(i0 + 1);
size_t k = triMesh.getIndex(i0 + 2);
adjacency[i].insert(j);
adjacency[j].insert(i);
adjacency[i].insert(k);
adjacency[k].insert(i);
adjacency[j].insert(k);
adjacency[k].insert(j);
}
return adjacency;
}
示例7: draw
void ofCairoRenderer::draw(ofMesh & primitive, bool useColors, bool useTextures, bool useNormals){
if(primitive.getNumVertices() == 0){
return;
}
if(primitive.getNumIndices() == 0){
ofMesh indexedMesh = primitive;
indexedMesh.setupIndicesAuto();
draw(indexedMesh, useColors, useTextures, useNormals);
return;
}
pushMatrix();
cairo_matrix_init_identity(getCairoMatrix());
cairo_new_path(cr);
int i = 1;
ofVec3f v = transform(primitive.getVertex(primitive.getIndex(0)));
ofVec3f v2;
cairo_move_to(cr,v.x,v.y);
if(primitive.getMode()==OF_PRIMITIVE_TRIANGLE_STRIP){
v = transform(primitive.getVertex(primitive.getIndex(1)));
cairo_line_to(cr,v.x,v.y);
v = transform(primitive.getVertex(primitive.getIndex(2)));
cairo_line_to(cr,v.x,v.y);
i=2;
}
for(; i<primitive.getNumIndices(); i++){
v = transform(primitive.getVertex(primitive.getIndex(i)));
switch(primitive.getMode()){
case(OF_PRIMITIVE_TRIANGLES):
if((i+1)%3==0){
cairo_line_to(cr,v.x,v.y);
v2 = transform(primitive.getVertex(primitive.getIndex(i-2)));
cairo_line_to(cr,v2.x,v2.y);
cairo_move_to(cr,v.x,v.y);
}else if((i+3)%3==0){
cairo_move_to(cr,v.x,v.y);
}else{
cairo_line_to(cr,v.x,v.y);
}
break;
case(OF_PRIMITIVE_TRIANGLE_STRIP):
v2 = transform(primitive.getVertex(primitive.getIndex(i-2)));
cairo_line_to(cr,v.x,v.y);
cairo_line_to(cr,v2.x,v2.y);
cairo_move_to(cr,v.x,v.y);
break;
case(OF_PRIMITIVE_TRIANGLE_FAN):
/*triangles.addIndex((GLuint)0);
triangles.addIndex((GLuint)1);
triangles.addIndex((GLuint)2);
for(int i = 2; i < primitive.getNumVertices()-1;i++){
triangles.addIndex((GLuint)0);
triangles.addIndex((GLuint)i);
triangles.addIndex((GLuint)i+1);
}*/
break;
default:break;
}
}
cairo_move_to(cr,primitive.getVertex(primitive.getIndex(primitive.getNumIndices()-1)).x,primitive.getVertex(primitive.getIndex(primitive.getNumIndices()-1)).y);
if(ofGetStyle().lineWidth>0){
cairo_stroke( cr );
}
popMatrix();
}
示例8: draw
void ofCairoRenderer::draw(const ofMesh & primitive, ofPolyRenderMode mode, bool useColors, bool useTextures, bool useNormals) const{
if(useColors || useTextures || useNormals){
ofLogWarning("ofCairoRenderer") << "draw(): cairo mesh rendering doesn't support colors, textures, or normals. drawing wireframe ...";
}
if(primitive.getNumVertices() == 0){
return;
}
if(primitive.getNumIndices() == 0){
ofMesh indexedMesh = primitive;
indexedMesh.setupIndicesAuto();
draw(indexedMesh, mode, useColors, useTextures, useNormals);
return;
}
cairo_new_path(cr);
cairo_matrix_t matrix;
cairo_matrix_init_identity(&matrix);
cairo_new_path(cr);
std::size_t i = 1;
ofVec3f v = transform(primitive.getVertex(primitive.getIndex(0)));
ofVec3f v2;
cairo_move_to(cr,v.x,v.y);
if(primitive.getMode()==OF_PRIMITIVE_TRIANGLE_STRIP){
v = transform(primitive.getVertex(primitive.getIndex(1)));
cairo_line_to(cr,v.x,v.y);
v = transform(primitive.getVertex(primitive.getIndex(2)));
cairo_line_to(cr,v.x,v.y);
i=2;
}
for(; i<primitive.getNumIndices(); i++){
v = transform(primitive.getVertex(primitive.getIndex(i)));
switch(primitive.getMode()){
case(OF_PRIMITIVE_TRIANGLES):
if((i+1)%3==0){
cairo_line_to(cr,v.x,v.y);
v2 = transform(primitive.getVertex(primitive.getIndex(i-2)));
cairo_line_to(cr,v2.x,v2.y);
cairo_move_to(cr,v.x,v.y);
}else if((i+3)%3==0){
cairo_move_to(cr,v.x,v.y);
}else{
cairo_line_to(cr,v.x,v.y);
}
break;
case(OF_PRIMITIVE_TRIANGLE_STRIP):
v2 = transform(primitive.getVertex(primitive.getIndex(i-2)));
cairo_line_to(cr,v.x,v.y);
cairo_line_to(cr,v2.x,v2.y);
cairo_move_to(cr,v.x,v.y);
break;
case(OF_PRIMITIVE_TRIANGLE_FAN):
/*triangles.addIndex((GLuint)0);
triangles.addIndex((GLuint)1);
triangles.addIndex((GLuint)2);
for(int i = 2; i < primitive.getNumVertices()-1;i++){
triangles.addIndex((GLuint)0);
triangles.addIndex((GLuint)i);
triangles.addIndex((GLuint)i+1);
}*/
break;
default:break;
}
}
cairo_move_to(cr,primitive.getVertex(primitive.getIndex(primitive.getNumIndices()-1)).x,primitive.getVertex(primitive.getIndex(primitive.getNumIndices()-1)).y);
if(currentStyle.lineWidth>0){
cairo_stroke( cr );
}
}
示例9: getIndexSpacePoint
// Return position pos in local grid index space for polygon n and vertex v
void getIndexSpacePoint(size_t n, size_t v, openvdb::Vec3d& pos) const {
ofVec3f pt = mesh->getVertex(mesh->getIndex(n * 3 + v));
pos[0] = pt.x;
pos[1] = pt.y;
pos[2] = pt.z;
}
示例10: draw
void ofCairoRenderer::draw(ofMesh & primitive){
if(primitive.getNumVertices()==0) return;
pushMatrix();
cairo_matrix_init_identity(getCairoMatrix());
cairo_new_path(cr);
//if(indices.getNumIndices()){
int i = 1;
ofVec3f v = transform(primitive.getVertex(primitive.getIndex(0)));
ofVec3f v2;
cairo_move_to(cr,v.x,v.y);
if(primitive.getMode()==OF_TRIANGLE_STRIP_MODE){
v = transform(primitive.getVertex(primitive.getIndex(1)));
cairo_line_to(cr,v.x,v.y);
v = transform(primitive.getVertex(primitive.getIndex(2)));
cairo_line_to(cr,v.x,v.y);
i=2;
}
for(; i<primitive.getNumIndices(); i++){
v = transform(primitive.getVertex(primitive.getIndex(i)));
switch(primitive.getMode()){
case(OF_TRIANGLES_MODE):
if((i+1)%3==0){
cairo_line_to(cr,v.x,v.y);
v2 = transform(primitive.getVertex(primitive.getIndex(i-2)));
cairo_line_to(cr,v2.x,v2.y);
cairo_move_to(cr,v.x,v.y);
}else if((i+3)%3==0){
cairo_move_to(cr,v.x,v.y);
}else{
cairo_line_to(cr,v.x,v.y);
}
break;
case(OF_TRIANGLE_STRIP_MODE):
v2 = transform(primitive.getVertex(primitive.getIndex(i-2)));
cairo_line_to(cr,v.x,v.y);
cairo_line_to(cr,v2.x,v2.y);
cairo_move_to(cr,v.x,v.y);
break;
case(OF_TRIANGLE_FAN_MODE):
/*triangles.addIndex((GLuint)0);
triangles.addIndex((GLuint)1);
triangles.addIndex((GLuint)2);
for(int i = 2; i < primitive.getNumVertices()-1;i++){
triangles.addIndex((GLuint)0);
triangles.addIndex((GLuint)i);
triangles.addIndex((GLuint)i+1);
}*/
break;
default:break;
}
}
cairo_move_to(cr,primitive.getVertex(primitive.getIndex(primitive.getNumIndices()-1)).x,primitive.getVertex(primitive.getIndex(primitive.getNumIndices()-1)).y);
if(ofGetStyle().lineWidth>0){
cairo_stroke( cr );
}
popMatrix();
}
示例11: r
vector<pair<btVector3, btConvexHullShape*> > ofxBulletConvexDecomposer::decompose(const ofMesh &meshToDecompose, btVector3 scale )
{
assert( meshToDecompose.getMode() == OF_TRIANGLES_MODE );
vector<pair<btVector3, btConvexHullShape*> > convexShapes;
int tcount = meshToDecompose.getNumIndices()/3;
if ( tcount == 0 )
// nothing to do
return convexShapes;
// adapted from bullet-2.81-rev2613/Demos/ConvexDecompositionDemo/ConvexDecompositionDemo.cpp
/*
unsigned int depth = 5;
float cpercent = 5;
float ppercent = 15;
unsigned int maxv = 16;
float skinWidth = 0.0;
// ConvexDecomposition::WavefrontObj wo;
ConvexDecomposition::DecompDesc desc;
desc.mVcount = meshToDecompose.getNumVertices();
desc.mVertices = (float*)(meshToDecompose.getVerticesPointer());
desc.mTcount = meshToDecompose.getNumIndices()/3;
desc.mIndices = meshToDecompose.getIndexPointer();
desc.mDepth = depth;
desc.mCpercent = cpercent;
desc.mPpercent = ppercent;
desc.mMaxVertices = maxv;
desc.mSkinWidth = skinWidth;
desc.mCallback = this;
*/
//-----------------------------------------------
// HACD
//-----------------------------------------------
std::vector< HACD::Vec3<HACD::Real> > points;
std::vector< HACD::Vec3<long> > triangles;
for(int i=0; i<meshToDecompose.getNumVertices(); i++ )
{
ofVec3f meshVert = meshToDecompose.getVertex(i);
HACD::Vec3<HACD::Real> vertex( meshVert.x, meshVert.y, meshVert.z );
points.push_back(vertex);
}
for(int i=0;i<meshToDecompose.getNumIndices(); i+=3 )
{
HACD::Vec3<long> triangle(meshToDecompose.getIndex(i), meshToDecompose.getIndex(i+1), meshToDecompose.getIndex(i+2) );
triangles.push_back(triangle);
}
assert(triangles.size()==tcount);
HACD::HACD myHACD;
myHACD.SetPoints(&points[0]);
myHACD.SetNPoints(points.size());
myHACD.SetTriangles(&triangles[0]);
myHACD.SetNTriangles(triangles.size());
myHACD.SetCompacityWeight(0.1);
myHACD.SetVolumeWeight(0.0);
// HACD parameters
// Recommended parameters: 2 100 0 0 0 0
size_t nClusters = 2;
double concavity = 100;
bool invert = false;
bool addExtraDistPoints = false;
bool addNeighboursDistPoints = false;
bool addFacesPoints = false;
myHACD.SetNClusters(nClusters); // minimum number of clusters
myHACD.SetNVerticesPerCH(100); // max of 100 vertices per convex-hull
myHACD.SetConcavity(concavity); // maximum concavity
myHACD.SetAddExtraDistPoints(addExtraDistPoints);
myHACD.SetAddNeighboursDistPoints(addNeighboursDistPoints);
myHACD.SetAddFacesPoints(addFacesPoints);
myHACD.SetCallBack( hacdCallback );
myHACD.Compute();
nClusters = myHACD.GetNClusters();
int totalTriangles = 0;
int totalPoints = 0;
for (int c=0;c<nClusters;c++)
{
//generate convex result
size_t nPoints = myHACD.GetNPointsCH(c);
size_t nTriangles = myHACD.GetNTrianglesCH(c);
ofLogVerbose("ofxBulletConvexDecomposer") << "cluster " << c <<"/" << nClusters << " points " << nPoints << " triangles " << nTriangles;
float* vertices = new float[nPoints*3];
unsigned int* triangles = new unsigned int[nTriangles*3];
HACD::Vec3<HACD::Real> * pointsCH = new HACD::Vec3<HACD::Real>[nPoints];
HACD::Vec3<long> * trianglesCH = new HACD::Vec3<long>[nTriangles];
//.........这里部分代码省略.........